Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test: reuse workbench scan fixtures (#1450)

mldangelo-oai093856ce48aa
diff --git a/plugins/codex-security/tests/test_workbench_db_exports.py b/plugins/codex-security/tests/test_workbench_db_exports.py
index 00fbefe88..2c1a56140 100644
--- a/plugins/codex-security/tests/test_workbench_db_exports.py
+++ b/plugins/codex-security/tests/test_workbench_db_exports.py
@@ -1077,9 +1077,7 @@ def test_csv_export_preserves_a_sealed_export(tmp_path: Path, workbench_api) ->
run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)
sealed_manifest = manifest_path.read_bytes()
- rejected = run_workbench(
- state_dir, "export-findings", "--scan-id", scan_id, "--format", "csv", check=False
- )
+ rejected = scan_command(state_dir, "export-findings", scan_id, "--format", "csv", check=False)
assert rejected["returncode"] != 0
assert "CSV output path cannot overwrite a sealed scan artifact" in rejected["stderr"]
diff --git a/plugins/codex-security/tests/test_workbench_deep_scan.py b/plugins/codex-security/tests/test_workbench_deep_scan.py
index b8693a481..47c0f9d42 100644
--- a/plugins/codex-security/tests/test_workbench_deep_scan.py
+++ b/plugins/codex-security/tests/test_workbench_deep_scan.py
@@ -2377,26 +2377,12 @@ def test_maximum_one_discovery_run_allows_hard_cap_singleton_reducer(
assert deep_scan["config"]["maxDiscoveryRuns"] == 1
scan_id = str(deep_scan["scanId"])
scan_dir = Path(str(deep_scan["scanDir"]))
- worker_id = str(uuid.uuid4())
- prompt, artifact_dir, result = worker_paths(scan_dir, "singleton-worker")
- upsert_worker(
+ worker_id, prompt, artifact_dir, result = dispatch_discovery_worker(
state_dir,
codex_home,
scan_id=scan_id,
- worker_id=worker_id,
- prompt_path=prompt,
- artifact_dir=artifact_dir,
- )
- result.write_text("{}\n")
- upsert_worker(
- state_dir,
- codex_home,
- scan_id=scan_id,
- worker_id=worker_id,
- status="succeeded",
- prompt_path=prompt,
- artifact_dir=artifact_dir,
- result_path=result,
+ scan_dir=scan_dir,
+ name="singleton-worker",
)
reducer_id = str(uuid.uuid4())
reducer_prompt, reducer_dir, reducer_result = worker_paths(scan_dir, "singleton-reducer")
diff --git a/plugins/codex-security/tests/test_workbench_prompt_only_scan.py b/plugins/codex-security/tests/test_workbench_prompt_only_scan.py
index 630aa105e..6b49cdf3b 100644
--- a/plugins/codex-security/tests/test_workbench_prompt_only_scan.py
+++ b/plugins/codex-security/tests/test_workbench_prompt_only_scan.py
@@ -77,6 +77,25 @@ def start_headless_standard_scan(
)
+def prompt_scan_arguments(target: Path, root: Path) -> argparse.Namespace:
+ return argparse.Namespace(
+ thread_id="thread-fixture",
+ target_path=str(target),
+ scope=".",
+ mode="standard",
+ diff_target_kind=None,
+ diff_base_revision=None,
+ diff_head_revision=None,
+ diff_content_digest=None,
+ user_context=None,
+ user_context_stdin=False,
+ target_summary=None,
+ scan_root=str(root / "scans"),
+ model=None,
+ reasoning_effort=None,
+ )
+
+
def test_headless_standard_scan_starts_without_setup_opt_out(tmp_path: Path) -> None:
state_dir = tmp_path / "state"
target = tmp_path / "target"
@@ -233,22 +252,7 @@ def test_prompt_scan_revalidates_target_after_concurrent_database_write(
globals_ = start.__globals__
identity = globals_["scan_target_identity"]
calls = 0
- args = argparse.Namespace(
- thread_id="thread-fixture",
- target_path=str(target),
- scope=".",
- mode="standard",
- diff_target_kind=None,
- diff_base_revision=None,
- diff_head_revision=None,
- diff_content_digest=None,
- user_context=None,
- user_context_stdin=False,
- target_summary=None,
- scan_root=str(tmp_path / "scans"),
- model=None,
- reasoning_effort=None,
- )
+ args = prompt_scan_arguments(target, tmp_path)
def inspect_identity(*args, **kwargs):
nonlocal calls
@@ -307,22 +311,7 @@ def test_prompt_scan_revalidates_target_after_database_lock_wait(
globals_ = start.__globals__
identity = globals_["scan_target_identity"]
calls = 0
- args = argparse.Namespace(
- thread_id="thread-fixture",
- target_path=str(target),
- scope=".",
- mode="standard",
- diff_target_kind=None,
- diff_base_revision=None,
- diff_head_revision=None,
- diff_content_digest=None,
- user_context=None,
- user_context_stdin=False,
- target_summary=None,
- scan_root=str(tmp_path / "scans"),
- model=None,
- reasoning_effort=None,
- )
+ args = prompt_scan_arguments(target, tmp_path)
acquiring = Event()
@@ -414,22 +403,7 @@ def test_concurrent_prompt_scan_starts_join_the_winner(
identity = globals_["scan_target_identity"]
ready = Barrier(2)
caller = local()
- args = argparse.Namespace(
- thread_id="thread-fixture",
- target_path=str(target),
- scope=".",
- mode="standard",
- diff_target_kind=None,
- diff_base_revision=None,
- diff_head_revision=None,
- diff_content_digest=None,
- user_context=None,
- user_context_stdin=False,
- target_summary=None,
- scan_root=str(tmp_path / "scans"),
- model=None,
- reasoning_effort=None,
- )
+ args = prompt_scan_arguments(target, tmp_path)
def synchronized_identity(*args, **kwargs):
caller.calls = getattr(caller, "calls", 0) + 1
diff --git a/plugins/codex-security/tests/test_workbench_standard_deep_results.py b/plugins/codex-security/tests/test_workbench_standard_deep_results.py
index 254a5b21e..d49a1fc91 100644
--- a/plugins/codex-security/tests/test_workbench_standard_deep_results.py
+++ b/plugins/codex-security/tests/test_workbench_standard_deep_results.py
@@ -51,10 +51,7 @@ def test_stopped_deep_scan_ignores_late_worker_checkpoints_without_reducer(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
checkpoint = {
"scanId": scan_id,
"complete": False,
@@ -150,9 +147,7 @@ def test_stopped_model_selection_survives_publication_retry(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
checkpoint = json.loads(result_path.read_text())
checkpoint["complete"] = result_state == "complete"
checkpoint["findings"] = json.loads((contract_dir / "findings.json").read_text())["findings"]
@@ -176,36 +171,19 @@ def test_stopped_model_selection_survives_publication_retry(
os.utime(head_path, ns=(2_000_000_000, 2_000_000_000))
expected_model = {**json.loads(selected.read_text())["threatModel"], "origin": "recovered"}
- scripts_dir = Path(__file__).resolve().parents[1] / "scripts"
wrapper = tmp_path / "fail_model_publication.py"
- wrapper.write_text(
- "import sys\n"
- f"sys.path.insert(0, {str(scripts_dir)!r})\n"
- "import workbench_db\n"
- "import workbench_saved_results\n"
+ failed = run_workbench_with_fault(
+ wrapper,
+ state_dir,
+ codex_home,
"def fail_publication(*args, **kwargs):\n"
" raise OSError('injected publication failure')\n"
- "workbench_saved_results._write_prepared_scan_finalization = fail_publication\n"
- "raise SystemExit(workbench_db.main())\n"
- )
- failed = subprocess.run(
- [
- sys.executable,
- str(wrapper),
- "fail-deep-scan",
- "--scan-id",
- scan_id,
- "--message",
- "Worker stopped.",
- ],
- capture_output=True,
- env={
- **os.environ,
- "CODEX_HOME": str(codex_home),
- "CODEX_SECURITY_STATE_DIR": str(state_dir),
- },
- text=True,
- check=False,
+ "workbench_saved_results._write_prepared_scan_finalization = fail_publication\n",
+ "fail-deep-scan",
+ "--scan-id",
+ scan_id,
+ "--message",
+ "Worker stopped.",
)
assert failed.returncode == 0, failed.stderr
with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
@@ -288,10 +266,7 @@ def test_stopped_model_selection_survives_publication_retry(
def test_scan_reads_require_explicit_late_result_recovery(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
checkpoint = saved_draft(scan_id, findings=[finding], completeness="partial")
write_checkpoint(result_path.parent / "checkpoints", checkpoint)
fail_deep_scan(state_dir, codex_home, scan_id, deep_status="failed")
@@ -332,10 +307,7 @@ def test_scan_reads_require_explicit_late_result_recovery(tmp_path: Path) -> Non
def test_explicit_recovery_rejects_changed_frozen_source(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
checkpoint = saved_draft(scan_id, findings=[finding], completeness="partial")
write_checkpoint(result_path.parent / "checkpoints", checkpoint)
fail_deep_scan(state_dir, codex_home, scan_id, deep_status="failed")
@@ -384,9 +356,7 @@ def test_explicit_recovery_preserves_unfrozen_parent_with_late_checkpoint(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
for filename in ("findings.json", "coverage.json", "scan-manifest.json"):
(scan_dir / filename).write_bytes((contract_dir / filename).read_bytes())
parent_finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
@@ -697,10 +667,7 @@ def test_aggregate_queries_ignore_late_stopped_scan_checkpoints(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
checkpoint = saved_draft(scan_id, findings=[finding], completeness="partial")
write_checkpoint(result_path.parent / "checkpoints", checkpoint)
fail_deep_scan(state_dir, codex_home, scan_id, deep_status="failed")
@@ -738,10 +705,7 @@ def test_unreadable_only_checkpoint_records_recovery_warning(tmp_path: Path) ->
def test_malformed_current_finding_does_not_override_worker_rejection(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
finding["provenance"]["candidateId"] = "rejected-candidate"
checkpoint = json.loads(result_path.read_text())
checkpoint["complete"] = False
@@ -809,10 +773,7 @@ def test_canceled_scan_retries_failed_publication_from_frozen_sources(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
checkpoint = saved_draft(scan_id, findings=[finding], completeness="partial")
write_checkpoint(result_path.parent / "checkpoints", checkpoint)
result_path.write_text("{incomplete")
@@ -961,9 +922,7 @@ def test_canceled_scan_reseals_prepared_completion_with_frozen_sources(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
result = json.loads(result_path.read_text())
result["findings"] = json.loads((contract_dir / "findings.json").read_text())["findings"]
result_path.write_text(json.dumps(result))
@@ -1025,9 +984,7 @@ def test_canceled_scan_reseals_prepared_completion_with_frozen_sources(
def test_stopped_deep_scan_recovers_when_parent_manifest_has_no_scan(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
result = json.loads(result_path.read_text())
result["findings"] = [finding]
@@ -1064,6 +1021,18 @@ def run_workbench_with_fault(script_path, state_dir, codex_home, setup, *args):
)
+def standard_contract(tmp_path: Path, scan_id: str, target: Path) -> Path:
+ contract_dir = tmp_path / "contract"
+ contract_dir.mkdir()
+ write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ return contract_dir
+
+
+def standard_finding(tmp_path: Path, scan_id: str, target: Path) -> dict[str, object]:
+ contract_dir = standard_contract(tmp_path, scan_id, target)
+ return json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+
+
def deep_scan_fixture(
tmp_path: Path, *, budget: bool = False, workers: int = 1
) -> tuple[Path, Path, Path, Path, str]:
@@ -1171,18 +1140,19 @@ def accepted_standard_worker(
return worker_id, result_path
-def committed_standard_reducer(
+def running_standard_reducer(
state_dir: Path,
codex_home: Path,
scan_dir: Path,
scan_id: str,
discovery_worker_id: str,
- discovery_result: Path,
*,
+ name: str = "standard-reducer",
+ attempt: str = "1",
additional_worker_ids: tuple[str, ...] = (),
-) -> tuple[str, Path, dict[str, object]]:
+) -> tuple[str, Path]:
reducer_id = str(uuid.uuid4())
- prompt_path, artifact_dir, result_path = worker_paths(scan_dir, "standard-reducer")
+ prompt_path, artifact_dir, result_path = worker_paths(scan_dir, name)
environment = {"CODEX_HOME": str(codex_home)}
input_worker_args = [
argument
@@ -1207,9 +1177,31 @@ def committed_standard_reducer(
str(prompt_path),
str(artifact_dir),
"--attempt",
- "1",
+ attempt,
environment=environment,
)
+ return reducer_id, result_path
+
+
+def committed_standard_reducer(
+ state_dir: Path,
+ codex_home: Path,
+ scan_dir: Path,
+ scan_id: str,
+ discovery_worker_id: str,
+ discovery_result: Path,
+ *,
+ additional_worker_ids: tuple[str, ...] = (),
+) -> tuple[str, Path, dict[str, object]]:
+ reducer_id, result_path = running_standard_reducer(
+ state_dir,
+ codex_home,
+ scan_dir,
+ scan_id,
+ discovery_worker_id,
+ additional_worker_ids=additional_worker_ids,
+ )
+ environment = {"CODEX_HOME": str(codex_home)}
result_path.write_text(discovery_result.read_text())
committed = commit_deep_dedup(
state_dir, scan_id, reducer_id, str(result_path), "0", environment=environment
@@ -1243,9 +1235,7 @@ def standard_parent_results_fixture(
def test_failure_preserves_last_committed_reducer_without_parent_draft(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
draft = json.loads(result_path.read_text())
draft["findings"] = json.loads((contract_dir / "findings.json").read_text())["findings"]
result_path.write_text(json.dumps(draft))
@@ -1270,9 +1260,7 @@ def test_stopped_rejection_recovers_malformed_parent_surfaces(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
finding["extensions"] = {"candidateId": "rejected-candidate"}
finding["provenance"]["candidateId"] = "rejected-candidate"
@@ -1327,9 +1315,7 @@ def test_stopped_rejection_recovers_malformed_parent_surfaces(
def test_stopped_scan_rebinds_prepared_completion_seal(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
result = json.loads(result_path.read_text())
result["findings"] = json.loads((contract_dir / "findings.json").read_text())["findings"]
result_path.write_text(json.dumps(result))
@@ -1382,9 +1368,7 @@ def test_stopped_findings_cannot_enter_remediation(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
_, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
+ contract_dir = standard_contract(tmp_path, scan_id, target)
result = json.loads(result_path.read_text())
result["findings"] = json.loads((contract_dir / "findings.json").read_text())["findings"]
result_path.write_text(json.dumps(result))
@@ -1546,10 +1530,7 @@ def test_complete_partial_parent_supersedes_obsolete_checkpoint_questions(
def test_canceled_reducer_checkpoint_supersedes_discovery_result(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- baseline = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ baseline = standard_finding(tmp_path, scan_id, target)
baseline["extensions"] = {"candidateId": "candidate-reducer"}
baseline["provenance"]["candidateId"] = "candidate-reducer"
discovery = json.loads(worker_result.read_text())
@@ -1565,30 +1546,8 @@ def test_canceled_reducer_checkpoint_supersedes_discovery_result(tmp_path: Path)
]
worker_result.write_text(json.dumps(discovery))
- reducer_id = str(uuid.uuid4())
- prompt_path, artifact_dir, reducer_result = worker_paths(scan_dir, "canceled-reducer")
- environment = {"CODEX_HOME": str(codex_home)}
- claim_deep_scan_dedup(
- state_dir,
- scan_id,
- reducer_id,
- str(prompt_path),
- str(artifact_dir),
- "--input-worker-id",
- worker_id,
- environment=environment,
- )
- upsert_deep_worker(
- state_dir,
- scan_id,
- reducer_id,
- "dedup",
- "running",
- str(prompt_path),
- str(artifact_dir),
- "--attempt",
- "1",
- environment=environment,
+ reducer_id, reducer_result = running_standard_reducer(
+ state_dir, codex_home, scan_dir, scan_id, worker_id, name="canceled-reducer", attempt="1"
)
reduced = copy.deepcopy(discovery)
reduced["findings"][0]["summary"] = "The reducer retained stronger merged evidence."
@@ -1614,42 +1573,17 @@ def test_canceled_reducer_checkpoint_supersedes_discovery_result(tmp_path: Path)
def test_archived_reducer_checkpoint_supersedes_discovery_result(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
discovery = json.loads(worker_result.read_text())
discovery["findings"] = [finding]
worker_result.write_text(json.dumps(discovery))
- reducer_id = str(uuid.uuid4())
- prompt_path, artifact_dir, reducer_result = worker_paths(scan_dir, "archived-reducer")
- environment = {"CODEX_HOME": str(codex_home)}
- claim_deep_scan_dedup(
- state_dir,
- scan_id,
- reducer_id,
- str(prompt_path),
- str(artifact_dir),
- "--input-worker-id",
- worker_id,
- environment=environment,
- )
- upsert_deep_worker(
- state_dir,
- scan_id,
- reducer_id,
- "dedup",
- "running",
- str(prompt_path),
- str(artifact_dir),
- "--attempt",
- "2",
- environment=environment,
+ reducer_id, reducer_result = running_standard_reducer(
+ state_dir, codex_home, scan_dir, scan_id, worker_id, name="archived-reducer", attempt="2"
)
reduced = copy.deepcopy(discovery)
reduced["findings"][0]["summary"] = "The archived reducer retained the newest evidence."
- archived = artifact_dir / "attempts" / "attempt-01"
+ archived = reducer_result.parent / "attempts" / "attempt-01"
archived.mkdir(parents=True)
(archived / "result.json").write_text(json.dumps(reduced))
write_checkpoint(archived / "checkpoints", reduced)
@@ -1674,10 +1608,7 @@ def test_archived_reducer_checkpoint_supersedes_discovery_result(tmp_path: Path)
def test_recovery_selects_strongest_same_finding_checkpoint(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- weak = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ weak = standard_finding(tmp_path, scan_id, target)
weak["severity"]["level"] = "low"
weak["confidence"]["level"] = "low"
weak["summary"] = "Earlier weak checkpoint evidence."
@@ -1711,10 +1642,7 @@ def test_recovery_selects_strongest_same_finding_checkpoint(tmp_path: Path) -> N
def test_failed_reducer_preserves_later_successful_worker_findings(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path, workers=3)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- baseline = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ baseline = standard_finding(tmp_path, scan_id, target)
environment = {"CODEX_HOME": str(codex_home)}
first_worker_id, first_result = accepted_standard_worker(
@@ -1802,10 +1730,7 @@ def test_recovery_does_not_promote_already_retained_historical_finding(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- historical = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ historical = standard_finding(tmp_path, scan_id, target)
historical["extensions"] = {"candidateId": "candidate-refined-location"}
historical["provenance"]["candidateId"] = "candidate-refined-location"
historical["locations"][0]["startLine"] = 1
@@ -1855,10 +1780,7 @@ def test_recovery_retains_same_worker_checkpoint_version_as_history(
) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)
worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- checkpoint_finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ checkpoint_finding = standard_finding(tmp_path, scan_id, target)
checkpoint_finding["extensions"] = {"candidateId": "candidate-refined-location"}
checkpoint_finding["provenance"]["candidateId"] = "candidate-refined-location"
checkpoint_finding["locations"][0]["startLine"] = 1
@@ -1901,10 +1823,7 @@ def test_recovery_retains_same_worker_checkpoint_version_as_history(
def test_independent_worker_candidate_ids_do_not_share_rejection(tmp_path: Path) -> None:
state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path, workers=2)
- contract_dir = tmp_path / "contract"
- contract_dir.mkdir()
- write_completed_contract(contract_dir, scan_id, target, relative_path="app.py")
- finding = json.loads((contract_dir / "findings.json").read_text())["findings"][0]
+ finding = standard_finding(tmp_path, scan_id, target)
finding["extensions"] = {"candidateId": "candidate-1"}
environment = {"CODEX_HOME": str(codex_home)}
for ordinal, name in enumerate(("rejecting", "reporting"), 1):