Skip to content

Commit 4dffb6f

Browse files
committed
Fail fast for source cache populate options
1 parent de21596 commit 4dffb6f

2 files changed

Lines changed: 60 additions & 12 deletions

File tree

scripts/streaming_reindex.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,18 @@ def main(argv: list[str]) -> int:
11351135
(OUTPUT_ROOT / str(tl)).mkdir(parents=True, exist_ok=True)
11361136
manifest = Manifest.load(MANIFEST_PATH)
11371137
resume = not args.no_resume
1138+
source_cache_dir = Path(args.source_cache_dir) if args.source_cache_dir else None
1139+
source_dir_roots = [Path(p) for p in args.source_dir_root]
1140+
if args.source_cache_only and source_cache_dir is None:
1141+
raise SystemExit("--source-cache-only requires --source-cache-dir")
1142+
if args.source_cache_populate_only and source_cache_dir is None:
1143+
raise SystemExit("--source-cache-populate-only requires --source-cache-dir")
1144+
if args.source_cache_populate_only and args.source_cache_only:
1145+
raise SystemExit("--source-cache-populate-only cannot be combined with --source-cache-only")
1146+
if args.source_cache_populate_only and args.commit_source:
1147+
raise SystemExit("--source-cache-populate-only is code-only; remove --commit-source")
1148+
if source_dir_roots and (source_cache_dir is not None or args.source_cache_only):
1149+
raise SystemExit("--source-dir-root cannot be combined with source cache flags")
11381150

11391151
# Shared global dedup db (cross-repo + cross-stream). FAIL LOUD up front:
11401152
# open it once here so a bad path / missing datasketch crashes before any
@@ -1223,18 +1235,6 @@ def main(argv: list[str]) -> int:
12231235
def should_process(repo: str) -> bool:
12241236
return is_code_worktree_repo(repo) and not (resume and manifest.is_done(repo))
12251237

1226-
source_cache_dir = Path(args.source_cache_dir) if args.source_cache_dir else None
1227-
source_dir_roots = [Path(p) for p in args.source_dir_root]
1228-
if args.source_cache_only and source_cache_dir is None:
1229-
raise SystemExit("--source-cache-only requires --source-cache-dir")
1230-
if args.source_cache_populate_only and source_cache_dir is None:
1231-
raise SystemExit("--source-cache-populate-only requires --source-cache-dir")
1232-
if args.source_cache_populate_only and args.source_cache_only:
1233-
raise SystemExit("--source-cache-populate-only cannot be combined with --source-cache-only")
1234-
if args.source_cache_populate_only and args.commit_source:
1235-
raise SystemExit("--source-cache-populate-only is code-only; remove --commit-source")
1236-
if source_dir_roots and (source_cache_dir is not None or args.source_cache_only):
1237-
raise SystemExit("--source-dir-root cannot be combined with source cache flags")
12381238
if args.source_cache_populate_only:
12391239
report = populate_source_cache(
12401240
work_root,

tests/test_streaming_reindex_run_checked.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,51 @@ def fake_stream(work_root, should_process, *, source_cache_dir, source_cache_onl
183183
"repos": [{"repo": "repo-a", "path": str(cache / "repo-a")}],
184184
"repo_count": 1,
185185
}
186+
187+
188+
def test_source_cache_populate_rejects_commit_source_before_processing(
189+
tmp_path,
190+
monkeypatch,
191+
) -> None:
192+
import streaming_reindex
193+
194+
commit_source = tmp_path / "commits.jsonl"
195+
commit_source.write_text("{}\n", encoding="utf-8")
196+
calls = []
197+
198+
def fake_process_one_commit_source(*args, **kwargs):
199+
calls.append((args, kwargs))
200+
raise AssertionError("commit source should not be processed")
201+
202+
monkeypatch.setattr(
203+
streaming_reindex,
204+
"OUTPUT_ROOT",
205+
tmp_path / "outputs" / "reindexed",
206+
)
207+
monkeypatch.setattr(
208+
streaming_reindex,
209+
"MANIFEST_PATH",
210+
tmp_path / "outputs" / "reindexed" / "_done.json",
211+
)
212+
monkeypatch.setattr(
213+
streaming_reindex,
214+
"process_one_commit_source",
215+
fake_process_one_commit_source,
216+
)
217+
218+
try:
219+
streaming_reindex.main(
220+
[
221+
"--source-cache-dir",
222+
str(tmp_path / "cache"),
223+
"--source-cache-populate-only",
224+
"--commit-source",
225+
f"sample={commit_source}",
226+
]
227+
)
228+
except SystemExit as exc:
229+
assert "--source-cache-populate-only is code-only" in str(exc)
230+
else: # pragma: no cover
231+
raise AssertionError("expected source-cache populate validation failure")
232+
233+
assert calls == []

0 commit comments

Comments
 (0)