22
33from __future__ import annotations
44
5+ import os
56import re
67import sys
78import types
2223)
2324
2425
26+ def _isolated_home_env (tmp_path : Path ) -> dict [str , str ]:
27+ """Redirect ~/.claude-code-chat-browser export state for subprocess CLI runs."""
28+ home = str (tmp_path / "home" )
29+ return {"HOME" : home , "USERPROFILE" : home }
30+
31+
2532def _export_args (tmp_path : Path , base : Path , out_dir : Path ) -> types .SimpleNamespace :
2633 return types .SimpleNamespace (
2734 base_dir = str (base ),
@@ -96,14 +103,8 @@ def test_since_last_early_return_invokes_exit_bulk_export(
96103
97104 def _track_exit (result : BulkExportResult ) -> None :
98105 exit_calls .append (result )
99- if result .failure_count > 0 :
100- raise SystemExit (1 )
101106
102- fake_result = BulkExportResult (
103- total_candidates = 3 ,
104- failure_count = 1 ,
105- latest_day = None ,
106- )
107+ fake_result = BulkExportResult (latest_day = None )
107108
108109 monkeypatch .setattr (export , "_exit_bulk_export" , _track_exit )
109110 monkeypatch .setattr (
@@ -124,13 +125,36 @@ def _track_exit(result: BulkExportResult) -> None:
124125 exclude_rules = None ,
125126 )
126127
127- with pytest .raises (SystemExit ) as exc_info :
128- export .cmd_export (args )
128+ export .cmd_export (args )
129129
130- assert exc_info .value .code == 1
131130 assert len (exit_calls ) == 1
132131 assert exit_calls [0 ] is fake_result
133- assert "no qualifying sessions" in capsys .readouterr ().out .lower ()
132+ captured = capsys .readouterr ()
133+ assert "no qualifying sessions" in captured .out .lower ()
134+ assert "Exported" not in captured .err
135+
136+
137+ def test_cli_export_incremental_noop_no_stderr_summary (tmp_path ):
138+ """Second incremental run after state is saved: exit 0, no stderr summary."""
139+ base = _seed_base_dir (tmp_path )
140+ out_dir = tmp_path / "out"
141+ home_env = _isolated_home_env (tmp_path )
142+ argv = [
143+ "export" ,
144+ "--base-dir" ,
145+ str (base ),
146+ "--no-zip" ,
147+ "--out" ,
148+ str (out_dir ),
149+ ]
150+ first = _run_cli ([* argv , "--since" , "all" ], env = home_env )
151+ assert first .returncode == 0 , first .stderr
152+ assert list (out_dir .rglob ("*.md" ))
153+
154+ second = _run_cli ([* argv , "--since" , "incremental" ], env = home_env )
155+ assert second .returncode == 0 , second .stderr
156+ assert "Exported" not in second .stderr
157+ assert "Nothing to export" in second .stdout
134158
135159
136160def test_cli_export_total_failure_exits_one (tmp_path , monkeypatch , capsys ):
0 commit comments