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(workbench): share setup for scan completion and result recovery (#1410)

mldangelo-oai032aa4a6aeaa
diff --git a/plugins/codex-security/tests/test_deep_scan_successful_publication.py b/plugins/codex-security/tests/test_deep_scan_successful_publication.py
index ef5eb6b44..9dcadb55e 100644
--- a/plugins/codex-security/tests/test_deep_scan_successful_publication.py
+++ b/plugins/codex-security/tests/test_deep_scan_successful_publication.py
@@ -8,7 +8,12 @@ from pathlib import Path
from types import SimpleNamespace
import pytest
-from workbench_test_support import write_checkpoint, write_completed_contract
+from workbench_test_support import (
+ saved_coverage,
+ saved_draft,
+ write_checkpoint,
+ write_completed_contract,
+)
@pytest.fixture
@@ -223,17 +228,7 @@ def test_deep_publication_ignores_empty_canceled_checkpoint(
result = add_worker(workbench_db, scan, status="canceled")
checkpoint = write_checkpoint(
result.parent / "checkpoints",
- {
- "scanId": scan.scan_id,
- "complete": False,
- "findings": [],
- "coverage": {
- "completeness": "partial",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [],
- },
- },
+ saved_draft(scan.scan_id, completeness="partial"),
)
source_bytes = checkpoint.read_bytes()
@@ -330,12 +325,7 @@ def test_stopped_deep_scan_still_salvages_saved_findings(
"findings": [later_finding],
}
if source == "standard-worker-checkpoint":
- saved["coverage"] = {
- "completeness": "partial",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [],
- }
+ saved["coverage"] = saved_coverage(completeness="partial")
if source == "deep-reducer-result":
checkpoint = None
result.write_text(json.dumps(saved))
diff --git a/plugins/codex-security/tests/test_saved_deferred_identity.py b/plugins/codex-security/tests/test_saved_deferred_identity.py
index a07be2187..31bfacf8e 100644
--- a/plugins/codex-security/tests/test_saved_deferred_identity.py
+++ b/plugins/codex-security/tests/test_saved_deferred_identity.py
@@ -13,7 +13,7 @@ from test_workbench_standard_deep_results import (
write_saved_parent,
)
from workbench_test_support import (
- run_workbench,
+ preserve_scan_results,
saved_discovery_worker,
saved_draft,
write_checkpoint,
@@ -144,14 +144,8 @@ def cancel_and_preserve(monkeypatch, saved_results, state, codex_home, scan_dir,
patch.setattr(saved_results, "_write_prepared_scan_finalization", fail_publication)
call_workbench(patch, state, codex_home, "cancel-scan", "--scan-id", scan_id)
assert len(prepared_coverage) == 1
- run_workbench(
- state,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment={"CODEX_HOME": str(codex_home)},
+ preserve_scan_results(
+ state, scan_id, "standard-worker-thread", environment={"CODEX_HOME": str(codex_home)}
)
return prepared_coverage[0], json.loads((scan_dir / "coverage.json").read_text())
diff --git a/plugins/codex-security/tests/test_saved_deferred_unicode.py b/plugins/codex-security/tests/test_saved_deferred_unicode.py
index 988e168de..c40cb2345 100644
--- a/plugins/codex-security/tests/test_saved_deferred_unicode.py
+++ b/plugins/codex-security/tests/test_saved_deferred_unicode.py
@@ -8,7 +8,7 @@ from pathlib import Path
import pytest
from test_saved_deferred_identity import recover, save_worker
from test_workbench_standard_deep_results import accepted_standard_worker, deep_scan_fixture
-from workbench_test_support import fail_deep_scan, run_workbench, saved_draft, write_checkpoint
+from workbench_test_support import fail_deep_scan, saved_draft, scan_command, write_checkpoint
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
import workbench_saved_results as saved
@@ -74,8 +74,6 @@ def test_stopped_publication_recovers_after_unicode_review_is_closed(
coverage = json.loads((scan_dir / "coverage.json").read_text(encoding="utf-8"))
assert {row["id"] for row in coverage["deferred"]} == {"scan-stopped"}
manifest = (scan_dir / "scan-manifest.json").read_bytes()
- recovered = run_workbench(
- state, "recover-scan-results", "--scan-id", scan_id, environment=environment
- )
+ recovered = scan_command(state, "recover-scan-results", scan_id, environment=environment)
assert recovered["scan"]["resultsRecoveryNeeded"] is False
assert (scan_dir / "scan-manifest.json").read_bytes() == manifest
diff --git a/plugins/codex-security/tests/test_workbench_checkpoint_heads.py b/plugins/codex-security/tests/test_workbench_checkpoint_heads.py
index 93ad43100..633a8b237 100644
--- a/plugins/codex-security/tests/test_workbench_checkpoint_heads.py
+++ b/plugins/codex-security/tests/test_workbench_checkpoint_heads.py
@@ -16,11 +16,14 @@ from test_workbench_standard_deep_results import (
from workbench_test_support import (
create_saved_workspace,
fail_deep_scan,
+ get_scan,
+ preserve_scan_results,
replay_saved_results,
run_workbench,
saved_binding,
saved_discovery_worker,
saved_draft,
+ scan_command,
start_delivered_scan,
write_checkpoint,
write_completed_contract,
@@ -78,41 +81,22 @@ def test_late_head_changes_require_explicit_recovery(
row["id"] == "review"
for row in json.loads((scan_dir / "coverage.json").read_text())["deferred"]
)
- assert (
- run_workbench(state, "get-scan", "--scan-id", scan_id)["scan"]["resultsRecoveryNeeded"]
- is False
- )
+ assert get_scan(state, scan_id)["scan"]["resultsRecoveryNeeded"] is False
select(result.parent, reopened if selection == "reopened" else completed, 300)
snapshots = list((result.parent / "checkpoint-heads").iterdir())
- assert (
- run_workbench(state, "get-scan", "--scan-id", scan_id)["scan"]["resultsRecoveryNeeded"]
- is True
- )
+ assert get_scan(state, scan_id)["scan"]["resultsRecoveryNeeded"] is True
assert list((result.parent / "checkpoint-heads").iterdir()) == snapshots
- run_workbench(
- state,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
- )
+ preserve_scan_results(state, scan_id, "standard-worker-thread", environment=environment)
assert manifest_path.read_bytes() == first_manifest
- recovered = run_workbench(
- state, "recover-scan-results", "--scan-id", scan_id, environment=environment
- )
+ recovered = scan_command(state, "recover-scan-results", scan_id, environment=environment)
assert recovered["scan"]["resultsRecoveryNeeded"] is False
coverage = json.loads((scan_dir / "coverage.json").read_text())
assert any(row["id"] == "review" for row in coverage["deferred"]) is (selection == "reopened")
published = manifest_path.read_bytes()
- run_workbench(state, "recover-scan-results", "--scan-id", scan_id, environment=environment)
+ scan_command(state, "recover-scan-results", scan_id, environment=environment)
assert manifest_path.read_bytes() == published
- assert (
- run_workbench(state, "get-scan", "--scan-id", scan_id)["scan"]["resultsRecoveryNeeded"]
- is False
- )
+ assert get_scan(state, scan_id)["scan"]["resultsRecoveryNeeded"] is False
@pytest.fixture
@@ -591,9 +575,9 @@ def test_completion_checks_selected_parent_checkpoint(
for path in (scan_dir / directory).glob("*.json")
}
- result = run_workbench(state, command, "--scan-id", scan_id, check=False)
+ result = scan_command(state, command, scan_id, check=False)
- scan = run_workbench(state, "get-scan", "--scan-id", scan_id)["scan"]
+ scan = get_scan(state, scan_id)["scan"]
if complete is False:
assert result["returncode"] != 0
assert "The latest saved scan draft is incomplete" in result["stderr"]
@@ -936,14 +920,8 @@ def test_parent_head_selection_matches_frozen_publication_retry(
patch.setattr(saved, "_write_prepared_scan_finalization", fail_publication)
call_workbench(patch, state, codex_home, "cancel-scan", "--scan-id", scan_id)
assert len(first) == 1
- run_workbench(
- state,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment={"CODEX_HOME": str(codex_home)},
+ preserve_scan_results(
+ state, scan_id, "standard-worker-thread", environment={"CODEX_HOME": str(codex_home)}
)
replay = (
json.loads((scan_dir / "findings.json").read_text()),
diff --git a/plugins/codex-security/tests/test_workbench_deep_scan.py b/plugins/codex-security/tests/test_workbench_deep_scan.py
index 0facbcda3..79d976f75 100644
--- a/plugins/codex-security/tests/test_workbench_deep_scan.py
+++ b/plugins/codex-security/tests/test_workbench_deep_scan.py
@@ -21,6 +21,7 @@ from workbench_test_support import (
commit_deep_dedup,
create_saved_workspace,
create_workspace,
+ fail_scan,
finish_deep_scan,
get_deep_scan,
get_scan,
@@ -28,6 +29,7 @@ from workbench_test_support import (
resume_deep_scan,
run_workbench,
save_workspace,
+ saved_draft,
scan_claim_command,
scan_command,
stable_target_id,
@@ -2425,16 +2427,11 @@ def test_maximum_one_discovery_run_allows_hard_cap_singleton_reducer(
)
reducer_id = str(uuid.uuid4())
reducer_prompt, reducer_dir, reducer_result = worker_paths(scan_dir, "singleton-reducer")
- claimed = run_workbench(
+ claimed = claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(reducer_prompt),
- "--artifact-dir",
str(reducer_dir),
"--input-worker-id",
worker_id,
@@ -2456,30 +2453,21 @@ def test_maximum_one_discovery_run_allows_hard_cap_singleton_reducer(
)
write_canonical_artifacts(scan_dir)
reducer_result.write_text("{}\n")
- committed = run_workbench(
+ committed = commit_deep_dedup(
state_dir,
- "commit-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--result-manifest-path",
str(reducer_result),
- "--new-findings-count",
"1",
environment=deep_environment(codex_home),
)["deepScan"]
assert committed["status"] == "running"
manifest = scan_dir / "coordinator-manifest.json"
manifest.write_text("{}\n")
- below_threshold = run_workbench(
+ below_threshold = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"saturated",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
@@ -2510,14 +2498,10 @@ def test_maximum_one_discovery_run_allows_hard_cap_singleton_reducer(
attempt=1,
error="Setup failed.",
)
- rejected = run_workbench(
+ rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
@@ -2525,16 +2509,8 @@ def test_maximum_one_discovery_run_allows_hard_cap_singleton_reducer(
assert "after a worker has failed" in str(rejected["stderr"])
with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
connection.execute("DELETE FROM deep_scan_workers WHERE id = ?", (failed_setup_id,))
- capped = run_workbench(
- state_dir,
- "finish-deep-scan",
- "--scan-id",
- scan_id,
- "--terminal-reason",
- "capped",
- "--manifest-path",
- str(manifest),
- environment=deep_environment(codex_home),
+ capped = finish_deep_scan(
+ state_dir, scan_id, "capped", str(manifest), environment=deep_environment(codex_home)
)["deepScan"]
assert capped["status"] == "succeeded"
assert capped["terminalReason"] == "capped"
@@ -2588,14 +2564,10 @@ def test_discovery_deadline_caps_after_reducing_a_single_discovery_result(
manifest = scan_dir / "coordinator-manifest.json"
manifest.write_text("{}\n")
- premature_completion = run_workbench(
+ premature_completion = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
@@ -2603,16 +2575,11 @@ def test_discovery_deadline_caps_after_reducing_a_single_discovery_result(
if not deadline_reached:
assert "before reaching its configured maximum" in str(premature_completion["stderr"])
reducer_prompt, reducer_dir, _ = worker_paths(scan_dir, "premature-reducer")
- premature_reducer = run_workbench(
+ premature_reducer = claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
str(uuid.uuid4()),
- "--prompt-path",
str(reducer_prompt),
- "--artifact-dir",
str(reducer_dir),
"--input-worker-id",
worker_id,
@@ -2638,16 +2605,8 @@ def test_discovery_deadline_caps_after_reducing_a_single_discovery_result(
existing_finding = '{"title": "Finding recorded before the deadline"}\n'
ledger_path.write_text(existing_finding)
- capped = run_workbench(
- state_dir,
- "finish-deep-scan",
- "--scan-id",
- scan_id,
- "--terminal-reason",
- "capped",
- "--manifest-path",
- str(manifest),
- environment=deep_environment(codex_home),
+ capped = finish_deep_scan(
+ state_dir, scan_id, "capped", str(manifest), environment=deep_environment(codex_home)
)["deepScan"]
assert capped["status"] == "succeeded"
assert capped["terminalReason"] == "capped"
@@ -2702,26 +2661,16 @@ def test_discovery_deadline_caps_without_a_completed_discovery(
attempt=1,
)
- running = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ running = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert running["status"] == "running"
assert running["canonicalArtifacts"] is None
if configured_hours > 1e-12:
- premature = run_workbench(
+ premature = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
@@ -2741,16 +2690,8 @@ def test_discovery_deadline_caps_without_a_completed_discovery(
),
)
- capped = run_workbench(
- state_dir,
- "finish-deep-scan",
- "--scan-id",
- scan_id,
- "--terminal-reason",
- "capped",
- "--manifest-path",
- str(manifest),
- environment=deep_environment(codex_home),
+ capped = finish_deep_scan(
+ state_dir, scan_id, "capped", str(manifest), environment=deep_environment(codex_home)
)["deepScan"]
assert capped["status"] == "succeeded"
assert capped["terminalReason"] == "capped"
@@ -2763,14 +2704,8 @@ def test_discovery_deadline_caps_without_a_completed_discovery(
["canceled"] if cancel_discovery else []
)
- persisted = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ persisted = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert persisted["canonicalArtifacts"] == capped["canonicalArtifacts"]
with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
@@ -2805,28 +2740,18 @@ def test_zero_discovery_deadline_rejects_nonempty_candidate_ledger(
((datetime.now(timezone.utc) - timedelta(hours=1)).isoformat(), scan_id),
)
- rejected = run_workbench(
+ rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
)
assert "without a successful dedup worker" in str(rejected["stderr"])
assert canonical["candidateLedgerPath"].read_text() == candidate_ledger
- running = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ running = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert running["status"] == "running"
assert running["canonicalArtifacts"] is None
@@ -2869,14 +2794,10 @@ def test_capped_completion_requires_canonical_artifacts(tmp_path: Path) -> None:
manifest = scan_dir / "coordinator-manifest.json"
manifest.write_text("{}\n")
- rejected = run_workbench(
+ rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
@@ -2929,28 +2850,20 @@ def test_capped_completion_rejects_buffered_workers_and_omissions(tmp_path: Path
manifest = scan_dir / "coordinator-manifest.json"
manifest.write_text("{}\n")
- buffered_rejected = run_workbench(
+ buffered_rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
)
assert "while discovery output remains buffered" in str(buffered_rejected["stderr"])
- omitted_rejected = run_workbench(
+ omitted_rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest),
"--omitted-worker-id",
buffered_id,
@@ -3116,28 +3029,15 @@ def test_late_worker_rejection_supersedes_stopped_checkpoint_finding(tmp_path: P
artifact_dir=artifact_dir,
attempt=1,
)
- checkpoint = {
- "scanId": scan_id,
- "complete": False,
- "findings": [provisional],
- "coverage": {
- "completeness": "partial",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [],
- },
- }
+ checkpoint = saved_draft(scan_id, completeness="partial", findings=[provisional])
encoded = json.dumps(checkpoint).encode()
checkpoint_dir = artifact_dir / "checkpoints"
checkpoint_dir.mkdir()
(checkpoint_dir / f"{hashlib.sha256(encoded).hexdigest()}.json").write_bytes(encoded)
- stopped = run_workbench(
+ stopped = fail_scan(
state_dir,
- "fail-scan",
- "--scan-id",
scan_id,
- "--message",
"Stopped after the provisional checkpoint.",
environment=deep_environment(codex_home),
)["scan"]
@@ -3145,37 +3045,25 @@ def test_late_worker_rejection_supersedes_stopped_checkpoint_finding(tmp_path: P
result_path.write_text(
json.dumps(
- {
- "scanId": scan_id,
- "complete": True,
- "findings": [],
- "coverage": {
- "completeness": "complete",
- "surfaces": [
- {
- "candidateId": "candidate-late-rejection",
- "label": "Late worker disposition",
- "disposition": "rejected",
- "receiptRefs": [],
- }
- ],
- "explicitExclusions": [],
- "deferred": [],
- },
- }
+ saved_draft(
+ scan_id,
+ surfaces=[
+ {
+ "candidateId": "candidate-late-rejection",
+ "label": "Late worker disposition",
+ "disposition": "rejected",
+ "receiptRefs": [],
+ }
+ ],
+ complete=True,
+ )
)
)
- recovery_needed = run_workbench(
- state_dir, "get-scan", "--scan-id", scan_id, environment=deep_environment(codex_home)
- )["scan"]
+ recovery_needed = get_scan(state_dir, scan_id, environment=deep_environment(codex_home))["scan"]
assert recovery_needed["resultsRecoveryNeeded"] is True
- recovered = run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment=deep_environment(codex_home),
+ recovered = scan_command(
+ state_dir, "recover-scan-results", scan_id, environment=deep_environment(codex_home)
)["scan"]
final_findings = json.loads(findings_path.read_text())["findings"]
final_coverage = json.loads(coverage_path.read_text())
@@ -3198,16 +3086,11 @@ def test_failure_capped_completion_recovers_canceled_reducer_inputs(tmp_path: Pa
)
reducer_id = str(uuid.uuid4())
reducer_prompt, reducer_dir, _ = worker_paths(scan_dir, "canceled-reducer")
- run_workbench(
+ claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(reducer_prompt),
- "--artifact-dir",
str(reducer_dir),
"--input-worker-id",
buffered_id,
@@ -3281,14 +3164,10 @@ def test_failure_capped_completion_rejects_unmarked_or_missing_canonical_coverag
if invalid_case != "missing_coverage":
coverage_path.write_text(json.dumps(coverage))
- rejected = run_workbench(
+ rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(scan_dir / "scan-manifest.json"),
environment=deep_environment(codex_home),
check=False,
@@ -3348,16 +3227,11 @@ def test_saturated_completion_rejects_merging_workers(tmp_path: Path) -> None:
)
reducer_id = str(uuid.uuid4())
reducer_prompt, reducer_dir, _ = worker_paths(scan_dir, "abandoned-reducer")
- run_workbench(
+ claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(reducer_prompt),
- "--artifact-dir",
str(reducer_dir),
"--input-worker-id",
merging_id,
@@ -3376,14 +3250,10 @@ def test_saturated_completion_rejects_merging_workers(tmp_path: Path) -> None:
manifest = scan_dir / "coordinator-manifest.json"
manifest.write_text("{}\n")
- rejected = run_workbench(
+ rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"saturated",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
@@ -3483,20 +3353,13 @@ def test_terminal_worker_updates_are_exact_idempotent_replays(tmp_path: Path) ->
replacement_result = artifact_dir / "replacement-result.json"
replacement_result.write_text("{}\n")
- replacement = run_workbench(
+ replacement = upsert_deep_worker(
state_dir,
- "upsert-deep-scan-worker",
- "--scan-id",
scan_id,
- "--worker-id",
worker_id,
- "--kind",
"discovery",
- "--status",
"succeeded",
- "--prompt-path",
str(prompt),
- "--artifact-dir",
str(artifact_dir),
"--result-manifest-path",
str(replacement_result),
@@ -3506,20 +3369,13 @@ def test_terminal_worker_updates_are_exact_idempotent_replays(tmp_path: Path) ->
check=False,
)
assert "terminal state is immutable" in str(replacement["stderr"])
- later_attempt = run_workbench(
+ later_attempt = upsert_deep_worker(
state_dir,
- "upsert-deep-scan-worker",
- "--scan-id",
scan_id,
- "--worker-id",
worker_id,
- "--kind",
"discovery",
- "--status",
"succeeded",
- "--prompt-path",
str(prompt),
- "--artifact-dir",
str(artifact_dir),
"--result-manifest-path",
str(result),
@@ -3582,16 +3438,11 @@ def test_discovery_buffer_prefix_dedup_and_saturation_are_transactional(
assert [worker["completionSequence"] for worker in ordered_workers] == [1, 2, 3]
reducer_id = str(uuid.uuid4())
reducer_prompt, reducer_dir, reducer_result = worker_paths(scan_dir, "reducer")
- claimed = run_workbench(
+ claimed = claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(reducer_prompt),
- "--artifact-dir",
str(reducer_dir),
*(item for worker in ordered_workers[:2] for item in ("--input-worker-id", worker["id"])),
environment=deep_environment(codex_home),
@@ -3611,16 +3462,11 @@ def test_discovery_buffer_prefix_dedup_and_saturation_are_transactional(
)
write_canonical_artifacts(scan_dir)
reducer_result.write_text("{}\n")
- committed = run_workbench(
+ committed = commit_deep_dedup(
state_dir,
- "commit-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--result-manifest-path",
str(reducer_result),
- "--new-findings-count",
"0",
environment=deep_environment(codex_home),
)
@@ -3641,16 +3487,11 @@ def test_discovery_buffer_prefix_dedup_and_saturation_are_transactional(
assert omitted["mergeState"] == "buffered"
second_reducer_id = str(uuid.uuid4())
second_prompt, second_dir, second_result = worker_paths(scan_dir, "second-reducer")
- run_workbench(
+ claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
second_reducer_id,
- "--prompt-path",
str(second_prompt),
- "--artifact-dir",
str(second_dir),
"--input-worker-id",
str(omitted["id"]),
@@ -3676,16 +3517,11 @@ def test_discovery_buffer_prefix_dedup_and_saturation_are_transactional(
name="late-worker",
succeed=False,
)
- saturated_reduction = run_workbench(
+ saturated_reduction = commit_deep_dedup(
state_dir,
- "commit-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
second_reducer_id,
- "--result-manifest-path",
str(second_result),
- "--new-findings-count",
"0",
environment=deep_environment(codex_home),
)
@@ -3721,27 +3557,19 @@ def test_discovery_buffer_prefix_dedup_and_saturation_are_transactional(
)
assert accepted_late_worker["mergeState"] == "buffered"
- omitted_rejected = run_workbench(
+ omitted_rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"saturated",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
)
assert "exactly identify all buffered discovery workers" in str(omitted_rejected["stderr"])
- finished = run_workbench(
+ finished = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"saturated",
- "--manifest-path",
str(manifest),
"--omitted-worker-id",
late_worker_id,
@@ -3750,28 +3578,20 @@ def test_discovery_buffer_prefix_dedup_and_saturation_are_transactional(
assert finished["deepScan"]["status"] == "succeeded"
assert finished["deepScan"]["terminalReason"] == "saturated"
assert finished["deepScan"]["manifestPath"] == str(manifest)
- replayed = run_workbench(
+ replayed = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"saturated",
- "--manifest-path",
str(manifest),
"--omitted-worker-id",
late_worker_id,
environment=deep_environment(codex_home),
)
assert replayed == finished
- mismatched_replay = run_workbench(
+ mismatched_replay = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"saturated",
- "--manifest-path",
str(manifest),
environment=deep_environment(codex_home),
check=False,
@@ -3849,14 +3669,8 @@ def test_get_deep_scan_does_not_invent_compact_artifacts_for_legacy_success(
(*map(str, legacy_files.values()), str(manifest), scan_id),
)
- persisted = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ persisted = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert persisted["status"] == "succeeded"
assert persisted["manifestPath"] == str(manifest)
@@ -3888,41 +3702,21 @@ def test_finish_preserves_legacy_succeeded_without_manifest_compatibility(
manifest = scan_dir / "legacy-coordinator-manifest.json"
manifest.write_text("{}\n")
- finished = run_workbench(
- state_dir,
- "finish-deep-scan",
- "--scan-id",
- scan_id,
- "--terminal-reason",
- "saturated",
- "--manifest-path",
- str(manifest),
- environment=deep_environment(codex_home),
+ finished = finish_deep_scan(
+ state_dir, scan_id, "saturated", str(manifest), environment=deep_environment(codex_home)
)
assert finished["deepScan"]["manifestPath"] == str(manifest)
- replayed = run_workbench(
- state_dir,
- "finish-deep-scan",
- "--scan-id",
- scan_id,
- "--terminal-reason",
- "saturated",
- "--manifest-path",
- str(manifest),
- environment=deep_environment(codex_home),
+ replayed = finish_deep_scan(
+ state_dir, scan_id, "saturated", str(manifest), environment=deep_environment(codex_home)
)
assert replayed == finished
replacement = scan_dir / "replacement-manifest.json"
replacement.write_text("{}\n")
- mismatched = run_workbench(
+ mismatched = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"saturated",
- "--manifest-path",
str(replacement),
environment=deep_environment(codex_home),
check=False,
@@ -3953,23 +3747,9 @@ def test_cancel_scan_cancels_coordinator_and_active_workers(tmp_path: Path) -> N
attempt=1,
)
- run_workbench(
- state_dir,
- "cancel-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
- )
- canceled = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ cancel_scan(state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home))
+ canceled = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert canceled["status"] == "canceled"
assert canceled["phase"] == "terminal"
@@ -3997,10 +3777,9 @@ def test_failure_manifest_is_confined_persisted_and_exactly_replayable(
)
outside_manifest = tmp_path / "outside-failure-manifest.json"
outside_manifest.write_text("{}\n")
- confined = run_workbench(
+ confined = scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
"--message",
"Coordinator failed.",
@@ -4013,10 +3792,9 @@ def test_failure_manifest_is_confined_persisted_and_exactly_replayable(
manifest = scan_dir / "failure-manifest.json"
manifest.write_text("{}\n")
- failed = run_workbench(
+ failed = scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
"--message",
"Coordinator failed.",
@@ -4031,20 +3809,13 @@ def test_failure_manifest_is_confined_persisted_and_exactly_replayable(
next(worker for worker in deep_scan["workers"] if worker["id"] == worker_id)["status"]
== "canceled"
)
- parent = run_workbench(
- state_dir,
- "get-scan",
- "--scan-id",
- scan_id,
- environment=deep_environment(codex_home),
- )["scan"]
+ parent = get_scan(state_dir, scan_id, environment=deep_environment(codex_home))["scan"]
assert parent["progress"]["status"] == "failed"
assert parent["failureMessage"] == "Coordinator failed."
- replayed = run_workbench(
+ replayed = scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
"--message",
"Coordinator failed.",
@@ -4068,10 +3839,9 @@ def test_failure_manifest_is_confined_persisted_and_exactly_replayable(
str(manifest),
),
):
- mismatched = run_workbench(
+ mismatched = scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
*extra_args,
environment=deep_environment(codex_home),
@@ -4084,10 +3854,9 @@ def test_failure_manifest_is_confined_persisted_and_exactly_replayable(
"UPDATE scans SET failure_message = 'Diverged parent failure.' WHERE id = ?",
(scan_id,),
)
- incoherent_parent = run_workbench(
+ incoherent_parent = scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
"--message",
"Coordinator failed.",
@@ -4124,34 +3893,14 @@ def test_cancel_scan_overrides_succeeded_deep_run_during_parent_tail(
(str(manifest) if with_manifest else None, scan_id),
)
- run_workbench(
- state_dir,
- "cancel-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
- )
- canceled = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ cancel_scan(state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home))
+ canceled = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert canceled["status"] == "canceled"
assert canceled["cancelRequested"] is True
assert canceled["manifestPath"] == (str(manifest) if with_manifest else None)
- scan = run_workbench(
- state_dir,
- "get-scan",
- "--scan-id",
- scan_id,
- environment=deep_environment(codex_home),
- )["scan"]
+ scan = get_scan(state_dir, scan_id, environment=deep_environment(codex_home))["scan"]
assert scan["progress"]["status"] == "canceled"
@@ -4178,10 +3927,9 @@ def test_saturated_run_without_manifest_can_be_marked_failed_or_interrupted(
)
message = f"The coordinator {deep_status} before its manifest was persisted."
- terminal = run_workbench(
+ terminal = scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
"--deep-status",
deep_status,
@@ -4191,13 +3939,7 @@ def test_saturated_run_without_manifest_can_be_marked_failed_or_interrupted(
)["deepScan"]
assert terminal["status"] == deep_status
assert terminal["error"] == message
- scan = run_workbench(
- state_dir,
- "get-scan",
- "--scan-id",
- scan_id,
- environment=deep_environment(codex_home),
- )["scan"]
+ scan = get_scan(state_dir, scan_id, environment=deep_environment(codex_home))["scan"]
assert scan["progress"]["status"] == "failed"
assert scan["failureMessage"] == terminal["error"]
@@ -4224,10 +3966,9 @@ def test_succeeded_run_with_manifest_cannot_be_marked_interrupted(tmp_path: Path
)
for deep_status in ("failed", "interrupted"):
- rejected = run_workbench(
+ rejected = scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
"--deep-status",
deep_status,
@@ -4237,14 +3978,8 @@ def test_succeeded_run_with_manifest_cannot_be_marked_interrupted(tmp_path: Path
check=False,
)
assert "Only a running Deep Scan" in str(rejected["stderr"])
- persisted = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ persisted = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert persisted["status"] == "succeeded"
assert persisted["manifestPath"] == str(manifest)
@@ -4258,25 +3993,16 @@ def test_succeeded_run_with_manifest_cannot_be_marked_interrupted(tmp_path: Path
""",
(scan_id,),
)
- completed_cancel = run_workbench(
+ completed_cancel = cancel_scan(
state_dir,
- "cancel-scan",
- "--scan-id",
scan_id,
- "--thread-id",
"thread-deep-scan",
environment=deep_environment(codex_home),
check=False,
)
assert "Only a running scan can be canceled" in str(completed_cancel["stderr"])
- unchanged = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "thread-deep-scan",
- environment=deep_environment(codex_home),
+ unchanged = get_deep_scan(
+ state_dir, scan_id, "thread-deep-scan", environment=deep_environment(codex_home)
)["deepScan"]
assert unchanged["status"] == "succeeded"
assert unchanged["manifestPath"] == str(manifest)
@@ -4289,10 +4015,8 @@ def test_invalid_user_configuration_fails_before_scan_creation(tmp_path: Path) -
target = tmp_path / "target"
target.mkdir()
- failed = run_workbench(
+ failed = begin_deep_scan(
state_dir,
- "begin-deep-scan",
- "--thread-id",
"thread-deep-scan",
"--target-path",
str(target),
diff --git a/plugins/codex-security/tests/test_workbench_saved_source_order.py b/plugins/codex-security/tests/test_workbench_saved_source_order.py
index 97dc8f1e8..ef45cbc95 100644
--- a/plugins/codex-security/tests/test_workbench_saved_source_order.py
+++ b/plugins/codex-security/tests/test_workbench_saved_source_order.py
@@ -11,9 +11,10 @@ from test_workbench_checkpoint_heads import drafts, select
from test_workbench_standard_deep_results import accepted_standard_worker, deep_scan_fixture
from workbench_test_support import (
fail_deep_scan,
- run_workbench,
+ get_scan,
saved_binding,
saved_discovery_worker,
+ scan_command,
write_checkpoint,
)
@@ -190,15 +191,8 @@ def test_order_metadata_is_not_new_evidence(tmp_path: Path) -> None:
manifest = (scan_dir / "scan-manifest.json").read_bytes()
orphan = scan_dir / "source-order" / ("0" * 64 + ".json")
orphan.write_text(json.dumps({"scanId": scan_id, "sources": {}}))
- assert (
- run_workbench(state, "get-scan", "--scan-id", scan_id)["scan"]["resultsRecoveryNeeded"]
- is False
- )
- run_workbench(
- state,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment={"CODEX_HOME": str(codex_home)},
+ assert get_scan(state, scan_id)["scan"]["resultsRecoveryNeeded"] is False
+ scan_command(
+ state, "recover-scan-results", scan_id, environment={"CODEX_HOME": str(codex_home)}
)
assert (scan_dir / "scan-manifest.json").read_bytes() == manifest
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 5de07a5b1..947bf8547 100644
--- a/plugins/codex-security/tests/test_workbench_standard_deep_results.py
+++ b/plugins/codex-security/tests/test_workbench_standard_deep_results.py
@@ -13,13 +13,26 @@ from pathlib import Path
import pytest
from workbench_test_support import (
+ begin_deep_scan,
+ cancel_scan,
+ claim_deep_scan_dedup,
+ commit_deep_dedup,
fail_deep_scan,
+ fail_scan,
+ finish_deep_scan,
+ get_deep_scan,
+ get_scan,
+ preserve_scan_results,
replay_saved_results,
run_workbench,
saved_binding,
+ saved_coverage,
saved_discovery_worker,
saved_draft,
+ scan_command,
+ upsert_deep_worker,
worker_paths,
+ workspace_command,
write_checkpoint,
write_completed_contract,
)
@@ -50,18 +63,15 @@ def test_stopped_deep_scan_ignores_late_worker_checkpoints_without_reducer(
"origin": "generated",
},
"findings": [finding],
- "coverage": {
- "completeness": "partial",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [
+ "coverage": saved_coverage(
+ deferred=[
{
"candidateId": "pending-query",
"reason": "Query validation remains pending.",
"paths": ["app.py"],
}
- ],
- },
+ ]
+ ),
}
checkpoint_dir = result_path.parent / "checkpoints"
write_checkpoint(checkpoint_dir, checkpoint)
@@ -79,19 +89,11 @@ def test_stopped_deep_scan_ignores_late_worker_checkpoints_without_reducer(
)
environment = {"CODEX_HOME": str(codex_home)}
if termination == "canceled":
- run_workbench(
- state_dir,
- "cancel-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
- )
+ cancel_scan(state_dir, scan_id, "standard-worker-thread", environment=environment)
else:
fail_deep_scan(state_dir, codex_home, scan_id, deep_status=termination)
- stopped = run_workbench(state_dir, "get-scan", "--scan-id", scan_id[:12])["scan"]
+ stopped = get_scan(state_dir, scan_id[:12])["scan"]
assert stopped["progress"]["status"] == ("canceled" if termination == "canceled" else "failed")
assert "threatModel" not in stopped
assert json.loads((scan_dir / "scan-manifest.json").read_text())["scan"]["threatModel"] == {
@@ -117,37 +119,17 @@ def test_stopped_deep_scan_ignores_late_worker_checkpoints_without_reducer(
late["findings"][0]["locations"][0]["endLine"] = 92
archived = result_path.parent / "attempts" / "attempt-01" / "checkpoints"
write_checkpoint(archived, late)
- recovery_needed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ recovery_needed = get_scan(state_dir, scan_id)["scan"]
assert recovery_needed["resultsRecoveryNeeded"] is (termination != "canceled")
if termination == "canceled":
- rejected = run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- check=False,
- )
+ rejected = scan_command(state_dir, "recover-scan-results", scan_id, check=False)
assert rejected["returncode"] != 0
assert "Canceled scans cannot recover" in str(rejected["stderr"])
- wrong_owner = run_workbench(
- state_dir,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "not-the-owner",
- check=False,
- )
+ wrong_owner = preserve_scan_results(state_dir, scan_id, "not-the-owner", check=False)
assert wrong_owner["returncode"] != 0
assert (scan_dir / "scan-manifest.json").read_bytes() == first_seal
- refreshed = run_workbench(
- state_dir,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
+ refreshed = preserve_scan_results(
+ state_dir, scan_id, "standard-worker-thread", environment=environment
)["scan"]
expected_count = 1
assert refreshed["findingCount"] == expected_count
@@ -155,10 +137,7 @@ def test_stopped_deep_scan_ignores_late_worker_checkpoints_without_reducer(
assert refreshed["findings"][0]["locations"][0]["startLine"] != 91
seal = (scan_dir / "scan-manifest.json").read_bytes()
assert seal == first_seal
- assert (
- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["findingCount"]
- == expected_count
- )
+ assert get_scan(state_dir, scan_id)["scan"]["findingCount"] == expected_count
assert (scan_dir / "scan-manifest.json").read_bytes() == seal
@@ -276,14 +255,8 @@ def test_stopped_model_selection_survives_publication_retry(
late = write_checkpoint(checkpoint_dir, checkpoint)
head_path.write_text(json.dumps({"checkpoint": late.name}))
environment = {"CODEX_HOME": str(codex_home)}
- retried = run_workbench(
- state_dir,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
+ retried = preserve_scan_results(
+ state_dir, scan_id, "standard-worker-thread", environment=environment
)["scan"]
manifest_path = scan_dir / "scan-manifest.json"
published = json.loads(manifest_path.read_text())["scan"]
@@ -300,19 +273,11 @@ def test_stopped_model_selection_survives_publication_retry(
"UPDATE scans SET retained_source_digests_json = ? WHERE id = ?",
(json.dumps(frozen["sources"]), scan_id),
)
- run_workbench(
- state_dir,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
- )
+ preserve_scan_results(state_dir, scan_id, "standard-worker-thread", environment=environment)
assert manifest_path.read_bytes() == first_seal
- recovered = run_workbench(
- state_dir, "recover-scan-results", "--scan-id", scan_id, environment=environment
- )["scan"]
+ recovered = scan_command(state_dir, "recover-scan-results", scan_id, environment=environment)[
+ "scan"
+ ]
published = json.loads(manifest_path.read_text())["scan"]
assert published["threatModel"] == {**checkpoint["threatModel"], "origin": "recovered"}
assert late.relative_to(scan_dir).as_posix() in published["preservedSources"]
@@ -329,7 +294,7 @@ def test_scan_reads_require_explicit_late_result_recovery(tmp_path: Path) -> Non
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")
- stopped = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ stopped = get_scan(state_dir, scan_id)["scan"]
assert stopped["resultsRecoveryNeeded"] is False
late = copy.deepcopy(checkpoint)
late["findings"][0]["locations"][0]["startLine"] = 91
@@ -345,28 +310,17 @@ def test_scan_reads_require_explicit_late_result_recovery(tmp_path: Path) -> Non
"SELECT workspace_id FROM scans WHERE id = ?", (scan_id,)
).fetchone()[0]
- reopened = run_workbench(
- state_dir,
- "get-workspace",
- "--workspace-id",
- workspace_id,
- environment={"CODEX_HOME": str(codex_home)},
+ reopened = workspace_command(
+ state_dir, "get-workspace", workspace_id, environment={"CODEX_HOME": str(codex_home)}
)
assert reopened["results"]["findingCount"] == 1
- stale = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ stale = get_scan(state_dir, scan_id)["scan"]
assert stale["findingCount"] == 1
assert stale["resultsRecoveryNeeded"] is True
- assert (
- run_workbench(state_dir, "list-findings", "--scan-id", scan_id)["findingsPage"]["total"]
- == 1
- )
+ assert scan_command(state_dir, "list-findings", scan_id)["findingsPage"]["total"] == 1
- recovered = run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment={"CODEX_HOME": str(codex_home)},
+ recovered = scan_command(
+ state_dir, "recover-scan-results", scan_id, environment={"CODEX_HOME": str(codex_home)}
)
assert recovered["scan"]["findingCount"] == 2
@@ -400,15 +354,11 @@ def test_explicit_recovery_rejects_changed_frozen_source(tmp_path: Path) -> None
late["findings"][0]["locations"][0]["startLine"] = 91
late["findings"][0]["locations"][0]["endLine"] = 92
write_checkpoint(result_path.parent / "attempts" / "attempt-01" / "checkpoints", late)
- assert (
- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["resultsRecoveryNeeded"]
- is True
- )
+ assert get_scan(state_dir, scan_id)["scan"]["resultsRecoveryNeeded"] is True
- rejected = run_workbench(
+ rejected = scan_command(
state_dir,
"recover-scan-results",
- "--scan-id",
scan_id,
environment={"CODEX_HOME": str(codex_home)},
check=False,
@@ -472,12 +422,8 @@ def test_explicit_recovery_preserves_unfrozen_parent_with_late_checkpoint(
late["findings"] = [late_finding]
write_checkpoint(result_path.parent / "checkpoints", late)
- recovered = run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment={"CODEX_HOME": str(codex_home)},
+ recovered = scan_command(
+ state_dir, "recover-scan-results", scan_id, environment={"CODEX_HOME": str(codex_home)}
)["scan"]
assert recovered["findingCount"] == 2
@@ -559,12 +505,8 @@ def test_explicit_recovery_preserves_sealed_parent_with_empty_source_map(
assert (scan_dir / "scan-manifest.json").read_bytes() == manifest_before_failed_recovery
assert (scan_dir / "findings.json").read_bytes() == findings_before_failed_recovery
- recovered = run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment={"CODEX_HOME": str(codex_home)},
+ recovered = scan_command(
+ state_dir, "recover-scan-results", scan_id, environment={"CODEX_HOME": str(codex_home)}
)["scan"]
assert recovered["findingCount"] == 2
@@ -582,12 +524,8 @@ def test_explicit_recovery_preserves_sealed_parent_with_empty_source_map(
later["findings"] = [later_finding]
write_checkpoint(result_path.parent / "attempts" / "attempt-02" / "checkpoints", later)
- recovered_again = run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment={"CODEX_HOME": str(codex_home)},
+ recovered_again = scan_command(
+ state_dir, "recover-scan-results", scan_id, environment={"CODEX_HOME": str(codex_home)}
)["scan"]
assert recovered_again["findingCount"] == 3
@@ -683,17 +621,10 @@ def test_explicit_recovery_retries_frozen_parent_after_write_failure(
).fetchone()
assert seal_digest is not None
assert json.loads(frozen_before)
- assert (
- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["resultsRecoveryNeeded"]
- is True
- )
+ assert get_scan(state_dir, scan_id)["scan"]["resultsRecoveryNeeded"] is True
- recovered = run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment={"CODEX_HOME": str(codex_home)},
+ recovered = scan_command(
+ state_dir, "recover-scan-results", scan_id, environment={"CODEX_HOME": str(codex_home)}
)["scan"]
assert recovered["resultsRecoveryNeeded"] is False
@@ -744,7 +675,7 @@ def test_unsealed_manifest_without_saved_results_does_not_offer_recovery(
(scan_id,),
)
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["resultsRecoveryNeeded"] is False
@@ -798,7 +729,7 @@ def test_unreadable_only_checkpoint_records_recovery_warning(tmp_path: Path) ->
result_path.write_text("{not-json")
fail_deep_scan(state_dir, codex_home, scan_id, deep_status="failed")
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert any("Preserved unreadable checkpoint" in warning for warning in failed["warnings"])
@@ -834,7 +765,7 @@ def test_malformed_current_finding_does_not_override_worker_rejection(tmp_path:
scan_id,
message="Stopped after rejecting a malformed current finding.",
)
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["findingCount"] == 0
coverage = json.loads((scan_dir / "coverage.json").read_text())
@@ -866,7 +797,7 @@ def test_stopped_recovery_accepts_trailing_slash_scope(tmp_path: Path) -> None:
connection.execute("UPDATE scans SET scope = 'src/' WHERE id = ?", (scan_id,))
fail_deep_scan(state_dir, codex_home, scan_id)
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["findingCount"] == 1
assert failed["findings"][0]["locations"][0]["path"] == "src/app.py"
@@ -918,14 +849,8 @@ def test_canceled_scan_retries_failed_publication_from_frozen_sources(
archived = result_path.parent / "attempts" / "attempt-01" / "checkpoints"
write_checkpoint(archived, late)
- preserved = run_workbench(
- state_dir,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment={"CODEX_HOME": str(codex_home)},
+ preserved = preserve_scan_results(
+ state_dir, scan_id, "standard-worker-thread", environment={"CODEX_HOME": str(codex_home)}
)["scan"]
assert preserved["findingCount"] == 1
assert preserved["findings"][0]["locations"][0]["startLine"] != 91
@@ -952,23 +877,16 @@ def test_existing_non_canceled_output_recovers_structured_publication_failure(
fail_deep_scan(state_dir, codex_home, scan_id, message=original, deep_status=deep_status)
if deep_status == "failed":
- run_workbench(
+ scan_command(
state_dir,
"record-deep-scan-publication-failure",
- "--scan-id",
scan_id,
"--message",
publication,
environment=environment,
)
- after_race = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
+ after_race = get_deep_scan(
+ state_dir, scan_id, "standard-worker-thread", environment=environment
)["deepScan"]
assert after_race["error"] == original
@@ -977,33 +895,15 @@ def test_existing_non_canceled_output_recovers_structured_publication_failure(
"UPDATE deep_scan_runs SET publication_error_message = ? WHERE scan_id = ?",
(publication, scan_id),
)
- before_recovery = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
+ before_recovery = get_deep_scan(
+ state_dir, scan_id, "standard-worker-thread", environment=environment
)["deepScan"]
assert publication in before_recovery["error"]
assert original in before_recovery["error"]
- run_workbench(
- state_dir,
- "recover-scan-results",
- "--scan-id",
- scan_id,
- environment=environment,
- )
- recovered = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment=environment,
+ scan_command(state_dir, "recover-scan-results", scan_id, environment=environment)
+ recovered = get_deep_scan(
+ state_dir, scan_id, "standard-worker-thread", environment=environment
)["deepScan"]
assert recovered["error"] == original
with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:
@@ -1044,12 +944,9 @@ def test_canceled_scan_reports_noop_coordinator_publication(tmp_path: Path) -> N
is None
)
- preserved = run_workbench(
+ preserved = preserve_scan_results(
state_dir,
- "preserve-scan-results",
- "--scan-id",
scan_id,
- "--thread-id",
"standard-worker-thread",
environment={"CODEX_HOME": str(codex_home)},
check=False,
@@ -1093,7 +990,7 @@ def test_canceled_scan_reseals_prepared_completion_with_frozen_sources(
"WHERE scan_id = ?",
(str(manifest_path), scan_id),
)
- run_workbench(state_dir, "prepare-scan-completion", "--scan-id", scan_id)
+ scan_command(state_dir, "prepare-scan-completion", scan_id)
assert json.loads(manifest_path.read_text())["scan"]["status"] == "completed"
wrapper = tmp_path / "fail_prepared_canceled_publication.py"
@@ -1113,14 +1010,8 @@ def test_canceled_scan_reseals_prepared_completion_with_frozen_sources(
assert canceled.returncode == 0, canceled.stderr
assert json.loads(manifest_path.read_text())["scan"]["status"] == "completed"
- run_workbench(
- state_dir,
- "preserve-scan-results",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment={"CODEX_HOME": str(codex_home)},
+ preserve_scan_results(
+ state_dir, scan_id, "standard-worker-thread", environment={"CODEX_HOME": str(codex_home)}
)
assert json.loads(manifest_path.read_text())["scan"]["status"] == "canceled"
@@ -1146,7 +1037,7 @@ def test_stopped_deep_scan_recovers_when_parent_manifest_has_no_scan(tmp_path: P
fail_deep_scan(state_dir, codex_home, scan_id, deep_status="failed")
- stopped = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ stopped = get_scan(state_dir, scan_id)["scan"]
assert stopped["findingCount"] == 1
assert any("has no scan object" in warning for warning in stopped["warnings"])
assert json.loads((scan_dir / "scan-manifest.json").read_text())["scan"]["status"] == ("failed")
@@ -1207,20 +1098,12 @@ def deep_scan_fixture(
),
)
scan_id = str(registered["scanId"])
- run_workbench(
- state_dir,
- "begin-deep-scan",
- "--thread-id",
- "standard-worker-thread",
- "--scan-id",
- scan_id,
- environment=environment,
+ begin_deep_scan(
+ state_dir, "standard-worker-thread", "--scan-id", scan_id, environment=environment
)
else:
- begun = run_workbench(
+ begun = begin_deep_scan(
state_dir,
- "begin-deep-scan",
- "--thread-id",
"standard-worker-thread",
"--target-path",
str(target),
@@ -1270,12 +1153,7 @@ def accepted_standard_worker(
{
"scanId": scan_id,
"findings": [],
- "coverage": {
- "completeness": "complete",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [],
- },
+ "coverage": saved_coverage(),
"threatModel": {"summary": "The ordinary Standard worker threat model."},
}
)
@@ -1310,52 +1188,30 @@ def committed_standard_reducer(
for worker_id in (discovery_worker_id, *additional_worker_ids)
for argument in ("--input-worker-id", worker_id)
]
- run_workbench(
+ claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(prompt_path),
- "--artifact-dir",
str(artifact_dir),
*input_worker_args,
environment=environment,
)
- run_workbench(
+ upsert_deep_worker(
state_dir,
- "upsert-deep-scan-worker",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--kind",
"dedup",
- "--status",
"running",
- "--prompt-path",
str(prompt_path),
- "--artifact-dir",
str(artifact_dir),
"--attempt",
"1",
environment=environment,
)
result_path.write_text(discovery_result.read_text())
- committed = run_workbench(
- state_dir,
- "commit-deep-scan-dedup",
- "--scan-id",
- scan_id,
- "--worker-id",
- reducer_id,
- "--result-manifest-path",
- str(result_path),
- "--new-findings-count",
- "0",
- environment=environment,
+ committed = commit_deep_dedup(
+ state_dir, scan_id, reducer_id, str(result_path), "0", environment=environment
)["deepScan"]
return reducer_id, result_path, committed
@@ -1401,7 +1257,7 @@ def test_failure_preserves_last_committed_reducer_without_parent_draft(tmp_path:
)
reducer_path.write_text(json.dumps(reduced))
fail_deep_scan(state_dir, codex_home, scan_id, message="Later reducer failed.")
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["progress"]["status"] == "failed"
assert failed["findingCount"] == 1
assert failed["findings"][0]["summary"] == reduced["findings"][0]["summary"]
@@ -1460,7 +1316,7 @@ def test_stopped_rejection_recovers_malformed_parent_surfaces(
state_dir, codex_home, scan_id, message="Stopped after rejecting a checkpointed candidate."
)
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["progress"]["status"] == "failed"
assert failed["findingCount"] == 1
coverage = json.loads((scan_dir / "coverage.json").read_text())
@@ -1488,16 +1344,13 @@ def test_stopped_scan_rebinds_prepared_completion_seal(tmp_path: Path) -> None:
"WHERE scan_id = ?",
(str(scan_dir / "scan-manifest.json"), scan_id),
)
- run_workbench(state_dir, "prepare-scan-completion", "--scan-id", scan_id)
+ scan_command(state_dir, "prepare-scan-completion", scan_id)
prepared_manifest = json.loads((scan_dir / "scan-manifest.json").read_text())
assert prepared_manifest["scan"]["status"] == "completed"
- run_workbench(
+ fail_scan(
state_dir,
- "fail-scan",
- "--scan-id",
scan_id,
- "--message",
"Completion was not accepted.",
environment={"CODEX_HOME": str(codex_home)},
)
@@ -1535,7 +1388,7 @@ def test_stopped_findings_cannot_enter_remediation(
result["findings"] = json.loads((contract_dir / "findings.json").read_text())["findings"]
result_path.write_text(json.dumps(result))
fail_deep_scan(state_dir, codex_home, scan_id, message="Stopped with a provisional finding.")
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["remediationAvailable"] is False
assert failed["remediationUnavailableReason"] == (
"Remediation is available only for successfully completed scans."
@@ -1583,10 +1436,9 @@ def test_complete_worker_model_uses_latest_terminal_source(
newer_head = head_time >= 2_000_000_000
os.utime(head_path, ns=(head_time, head_time))
- run_workbench(
+ scan_command(
state_dir,
"fail-deep-scan",
- "--scan-id",
scan_id,
"--message",
"Stopped after the worker completed.",
@@ -1617,9 +1469,8 @@ def test_complete_worker_supersedes_obsolete_checkpoint_coverage(tmp_path: Path)
"complete": False,
"threatModel": {"summary": "An obsolete worker model."},
"findings": [],
- "coverage": {
- "completeness": "partial",
- "surfaces": [
+ "coverage": saved_coverage(
+ surfaces=[
{
"id": "obsolete-surface",
"label": "Obsolete review",
@@ -1627,9 +1478,8 @@ def test_complete_worker_supersedes_obsolete_checkpoint_coverage(tmp_path: Path)
"receiptRefs": [],
}
],
- "explicitExclusions": [],
- "deferred": [{"id": "obsolete-work", "reason": "This was later completed."}],
- },
+ deferred=[{"id": "obsolete-work", "reason": "This was later completed."}],
+ ),
}
checkpoints = result_path.parent / "checkpoints"
head = write_checkpoint(checkpoints, checkpoint)
@@ -1717,35 +1567,23 @@ def test_canceled_reducer_checkpoint_supersedes_discovery_result(tmp_path: Path)
reducer_id = str(uuid.uuid4())
prompt_path, artifact_dir, reducer_result = worker_paths(scan_dir, "canceled-reducer")
environment = {"CODEX_HOME": str(codex_home)}
- run_workbench(
+ claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(prompt_path),
- "--artifact-dir",
str(artifact_dir),
"--input-worker-id",
worker_id,
environment=environment,
)
- run_workbench(
+ upsert_deep_worker(
state_dir,
- "upsert-deep-scan-worker",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--kind",
"dedup",
- "--status",
"running",
- "--prompt-path",
str(prompt_path),
- "--artifact-dir",
str(artifact_dir),
"--attempt",
"1",
@@ -1786,35 +1624,23 @@ def test_archived_reducer_checkpoint_supersedes_discovery_result(tmp_path: Path)
reducer_id = str(uuid.uuid4())
prompt_path, artifact_dir, reducer_result = worker_paths(scan_dir, "archived-reducer")
environment = {"CODEX_HOME": str(codex_home)}
- run_workbench(
+ claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(prompt_path),
- "--artifact-dir",
str(artifact_dir),
"--input-worker-id",
worker_id,
environment=environment,
)
- run_workbench(
+ upsert_deep_worker(
state_dir,
- "upsert-deep-scan-worker",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--kind",
"dedup",
- "--status",
"running",
- "--prompt-path",
str(prompt_path),
- "--artifact-dir",
str(artifact_dir),
"--attempt",
"2",
@@ -1922,16 +1748,11 @@ def test_failed_reducer_preserves_later_successful_worker_findings(tmp_path: Pat
reducer_id = str(uuid.uuid4())
prompt_path, artifact_dir, _ = worker_paths(scan_dir, "failed-reducer")
- run_workbench(
+ claim_deep_scan_dedup(
state_dir,
- "claim-deep-scan-dedup",
- "--scan-id",
scan_id,
- "--worker-id",
reducer_id,
- "--prompt-path",
str(prompt_path),
- "--artifact-dir",
str(artifact_dir),
"--input-worker-id",
second_worker_id,
@@ -1965,7 +1786,7 @@ def test_failed_reducer_preserves_later_successful_worker_findings(tmp_path: Pat
fail_deep_scan(state_dir, codex_home, scan_id, message="Later reducers failed.")
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["progress"]["status"] == "failed"
assert failed["findingCount"] == 2
assert {finding["identity"]["anchor"] for finding in failed["findings"]} == {
@@ -2019,7 +1840,7 @@ def test_recovery_does_not_promote_already_retained_historical_finding(
state_dir, codex_home, scan_id, message="Stopped after the canonical result was retained."
)
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["findingCount"] == 1
retained = json.loads((scan_dir / "findings.json").read_text())["findings"][0]
assert retained["locations"][0]["startLine"] == 2
@@ -2067,7 +1888,7 @@ def test_recovery_retains_same_worker_checkpoint_version_as_history(
state_dir, codex_home, scan_id, message="Stopped after the canonical result was retained."
)
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["findingCount"] == 1
retained = json.loads((scan_dir / "findings.json").read_text())["findings"][0]
assert retained["locations"][0]["startLine"] == 2
@@ -2087,20 +1908,13 @@ def test_independent_worker_candidate_ids_do_not_share_rejection(tmp_path: Path)
environment = {"CODEX_HOME": str(codex_home)}
for ordinal, name in enumerate(("rejecting", "reporting"), 1):
prompt, output, result = worker_paths(scan_dir, name)
- run_workbench(
+ upsert_deep_worker(
state_dir,
- "upsert-deep-scan-worker",
- "--scan-id",
scan_id,
- "--worker-id",
f"00000000-0000-4000-8000-{ordinal:012}",
- "--kind",
"discovery",
- "--status",
"running",
- "--prompt-path",
str(prompt),
- "--artifact-dir",
str(output),
"--attempt",
"1",
@@ -2111,9 +1925,8 @@ def test_independent_worker_candidate_ids_do_not_share_rejection(tmp_path: Path)
{
"scanId": scan_id,
"findings": [finding] if name == "reporting" else [],
- "coverage": {
- "completeness": "complete",
- "surfaces": []
+ "coverage": saved_coverage(
+ surfaces=[]
if name == "reporting"
else [
{
@@ -2122,15 +1935,13 @@ def test_independent_worker_candidate_ids_do_not_share_rejection(tmp_path: Path)
"disposition": "rejected",
"notes": "This route enforces containment.",
}
- ],
- "explicitExclusions": [],
- "deferred": [],
- },
+ ]
+ ),
}
)
)
fail_deep_scan(state_dir, codex_home, scan_id, message="Stopped.")
- failed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]
+ failed = get_scan(state_dir, scan_id)["scan"]
assert failed["findingCount"] == 1
canonical_findings = json.loads((scan_dir / "findings.json").read_text())["findings"]
assert canonical_findings[0]["extensions"]["candidateId"] == "candidate-1"
@@ -2161,14 +1972,8 @@ def test_standard_worker_results_commit_and_recover_without_discovery_ledgers(
assert workers[reducer_id]["resultManifestPath"] == str(reducer_result)
assert not (scan_dir / "artifacts" / "02_discovery").exists()
- recovered = run_workbench(
- state_dir,
- "get-deep-scan",
- "--scan-id",
- scan_id,
- "--thread-id",
- "standard-worker-thread",
- environment={"CODEX_HOME": str(codex_home)},
+ recovered = get_deep_scan(
+ state_dir, scan_id, "standard-worker-thread", environment={"CODEX_HOME": str(codex_home)}
)["deepScan"]
assert recovered["canonicalArtifacts"] is None
assert recovered["workers"] == committed["workers"]
@@ -2180,14 +1985,10 @@ def test_standard_worker_results_finish_with_only_canonical_parent_manifest(
state_dir, codex_home, target, scan_dir, scan_id = standard_parent_results_fixture(tmp_path)
manifest_path = scan_dir / "scan-manifest.json"
- finished = run_workbench(
+ finished = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest_path),
environment={"CODEX_HOME": str(codex_home)},
)["deepScan"]
@@ -2229,12 +2030,9 @@ def test_standard_worker_results_ignore_incidental_legacy_discovery_artifacts(
assert committed["canonicalArtifacts"] is None
def recovered() -> dict[str, object]:
- return run_workbench(
+ return get_deep_scan(
state_dir,
- "get-deep-scan",
- "--scan-id",
scan_id,
- "--thread-id",
"standard-worker-thread",
environment={"CODEX_HOME": str(codex_home)},
)["deepScan"]
@@ -2247,14 +2045,10 @@ def test_standard_worker_results_ignore_incidental_legacy_discovery_artifacts(
relative_path="app.py",
coverage_mode="deep_repository",
)
- finished = run_workbench(
+ finished = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(scan_dir / "scan-manifest.json"),
environment={"CODEX_HOME": str(codex_home)},
)["deepScan"]
@@ -2298,14 +2092,10 @@ def test_standard_worker_deadline_can_finish_without_any_completed_worker(
((datetime.now(timezone.utc) - timedelta(hours=97)).isoformat(), scan_id),
)
- finished = run_workbench(
+ finished = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest_path),
environment={"CODEX_HOME": str(codex_home)},
)["deepScan"]
@@ -2322,14 +2112,10 @@ def test_standard_worker_finish_preserves_running_state_when_parent_draft_is_inc
state_dir, codex_home, target, scan_dir, scan_id = standard_parent_results_fixture(tmp_path)
(scan_dir / "findings.json").unlink()
- rejected = run_workbench(
+ rejected = finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(scan_dir / "scan-manifest.json"),
environment={"CODEX_HOME": str(codex_home)},
check=False,
@@ -2349,23 +2135,18 @@ def test_budget_exhaustion_preserves_validated_standard_results_without_candidat
tmp_path, budget=True
)
manifest_path = scan_dir / "scan-manifest.json"
- run_workbench(
+ finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(manifest_path),
environment={"CODEX_HOME": str(codex_home)},
)
warning = "Scan stopped: estimated cost $0.00625 exceeded the $0.005 cost limit."
- completed = run_workbench(
+ completed = scan_command(
state_dir,
"complete-budget-exhausted-scan",
- "--scan-id",
scan_id,
"--cost-json",
json.dumps(
@@ -2403,23 +2184,18 @@ def test_budget_exhaustion_rejects_incomplete_standard_result_draft(tmp_path: Pa
state_dir, codex_home, target, scan_dir, scan_id = standard_parent_results_fixture(
tmp_path, budget=True
)
- run_workbench(
+ finish_deep_scan(
state_dir,
- "finish-deep-scan",
- "--scan-id",
scan_id,
- "--terminal-reason",
"capped",
- "--manifest-path",
str(scan_dir / "scan-manifest.json"),
environment={"CODEX_HOME": str(codex_home)},
)
(scan_dir / "findings.json").unlink()
- rejected = run_workbench(
+ rejected = scan_command(
state_dir,
"complete-budget-exhausted-scan",
- "--scan-id",
scan_id,
"--cost-json",
json.dumps(
@@ -2544,16 +2320,13 @@ def test_recovery_retains_generic_closures_without_a_canonical_write(
}
unresolved = {"id": "unavailable-library", "reason": "Source is unavailable."}
candidate = {"candidateId": "pending-candidate", "reason": "Validation remains."}
- coverage = {
- "completeness": "partial",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [
+ coverage = saved_coverage(
+ deferred=[
pending_closeout,
unresolved,
candidate,
- ],
- }
+ ]
+ )
initial = {"scanId": scan_id, "complete": False, "findings": [], "coverage": coverage}
if canonical_state != "missing":
scan = (
@@ -2748,12 +2521,7 @@ def test_recovery_rejects_closures_that_would_discard_saved_evidence(
"title": "Retained review evidence",
"evidence": "Unverified source trace.",
}
- coverage = {
- "completeness": "partial",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [pending],
- }
+ coverage = saved_coverage(deferred=[pending])
draft = {"scanId": scan_id, "complete": False, "findings": [], "coverage": coverage}
original = write_checkpoint(scan_dir / "checkpoints", draft)
os.utime(original, ns=(100, 100))
@@ -2870,12 +2638,7 @@ def test_recovery_uses_frozen_worker_head_for_identical_reclosure(
attempt = output if layout == "current" else worker_root / "attempts" / "attempt-01"
attempt.mkdir(parents=True, exist_ok=True)
pending = {"id": "review-closeout", "reason": "Reopened source review."}
- coverage = {
- "completeness": "partial",
- "surfaces": [],
- "explicitExclusions": [],
- "deferred": [pending],
- }
+ coverage = saved_coverage(deferred=[pending])
draft = {"scanId": scan_id, "complete": True, "findings": [], "coverage": coverage}
closed = write_checkpoint(
attempt / "checkpoints",
diff --git a/plugins/codex-security/tests/workbench_test_support.py b/plugins/codex-security/tests/workbench_test_support.py
index 47fef9d1a..6e685bd7b 100644
--- a/plugins/codex-security/tests/workbench_test_support.py
+++ b/plugins/codex-security/tests/workbench_test_support.py
@@ -350,6 +350,14 @@ def cancel_scan(state_dir: Path, scan_id: str, thread_id: str, **options: Any) -
return scan_command(state_dir, "cancel-scan", scan_id, "--thread-id", thread_id, **options)
+def preserve_scan_results(
+ state_dir: Path, scan_id: str, thread_id: str, **options: Any
+) -> dict[str, object]:
+ return scan_command(
+ state_dir, "preserve-scan-results", scan_id, "--thread-id", thread_id, **options
+ )
+
+
def start_scan_command(
state_dir: Path, workspace_id: str, *extra: str, **options: Any
) -> dict[str, object]: