OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
test(workbench): share setup for completing scans and exporting findings (#1413)
mldangelo-oai5e02abaff1a6
diff --git a/plugins/codex-security/tests/test_workbench_completion_binding.py b/plugins/codex-security/tests/test_workbench_completion_binding.pyindex 66abae97c..363702874 100644--- a/plugins/codex-security/tests/test_workbench_completion_binding.py+++ b/plugins/codex-security/tests/test_workbench_completion_binding.py@@ -16,14 +16,19 @@ from workbench_test_support import (create_saved_workspace,create_workspace,empty_target_scan,+ fail_scan,+ get_scan,initialize_git_repository,mark_deep_coordinator_succeeded,+ resume_deep_scan,run_workbench,save_workspace,+ scan_command,source_plugin_version,stable_target_id,start_delivered_scan,start_workspace_scan,+ workspace_command,write_checkpoint,write_completed_contract,)@@ -43,12 +48,9 @@ def _start_deep_scan_with_draft_findings(tmp_path: Path) -> tuple[Path, str, Patstate_dir, target, thread_id="thread-completion-binding", mode="deep")scan_id, scan_dir = start_workspace_scan(state_dir, str(saved["id"]), tmp_path / "scans")- run_workbench(+ resume_deep_scan(state_dir,- "begin-deep-scan",- "--scan-id",scan_id,- "--thread-id","thread-completion-binding",environment={"CODEX_HOME": str(tmp_path / "codex-home")},)@@ -96,10 +98,9 @@ def _start_diff_scan_with_draft(tmp_path: Path, kind: str) -> tuple[Path, Path,if kind == "commit":workspace_id = str(uuid.uuid4())for command in ("create-workspace", "save-workspace"):- run_workbench(+ workspace_command(state_dir,command,- "--workspace-id",workspace_id,"--target-path",str(target),@@ -189,7 +190,7 @@ def test_completion_binds_diff_snapshot_digest(manifest["scan"]["target"]["snapshotDigest"] = draft_digestmanifest_path.write_text(json.dumps(manifest))- prepared = run_workbench(state_dir, "prepare-scan-completion", "--scan-id", scan_id)+ prepared = scan_command(state_dir, "prepare-scan-completion", scan_id)assert prepared["scan"]["progress"]["status"] == "running"if kind == "working_tree":@@ -205,7 +206,7 @@ def test_completion_binds_diff_snapshot_digest(assert sealed_manifest["scan"]["sealedAt"]sealed_artifacts = _sealed_artifacts(scan_dir)for _ in range(2):- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert _sealed_artifacts(scan_dir) == sealed_artifacts@@ -217,7 +218,7 @@ def test_completion_preserves_legacy_sealed_diff_snapshot_digest(tmp_path: Path,_seal_draft(scan_dir, target)sealed_artifacts = _sealed_artifacts(scan_dir)for command in ("prepare-scan-completion", "complete-scan", "complete-scan"):- run_workbench(state_dir, command, "--scan-id", scan_id)+ scan_command(state_dir, command, scan_id)assert _sealed_artifacts(scan_dir) == sealed_artifacts@@ -238,7 +239,7 @@ def test_stopped_recovery_preserves_legacy_diff_snapshot(tmp_path: Path, kind: s(manifest["scan"]["completedAt"], "Scan stopped.", scan_id),)- recovered = run_workbench(state_dir, "recover-scan-results", "--scan-id", scan_id)+ recovered = scan_command(state_dir, "recover-scan-results", scan_id)assert recovered["scan"]["progress"]["status"] == "failed"manifest = json.loads(manifest_path.read_text())@@ -246,7 +247,7 @@ def test_stopped_recovery_preserves_legacy_diff_snapshot(tmp_path: Path, kind: sassert manifest["scan"]["preservedSources"]assert json.loads((scan_dir / "findings.json").read_text())["findings"] == original_findingssealed_artifacts = _sealed_artifacts(scan_dir)- run_workbench(state_dir, "recover-scan-results", "--scan-id", scan_id)+ scan_command(state_dir, "recover-scan-results", scan_id)assert _sealed_artifacts(scan_dir) == sealed_artifactslate_review = {"id": "late-review", "reason": "Review remains pending.", "paths": ["README.md"]}@@ -254,14 +255,14 @@ def test_stopped_recovery_preserves_legacy_diff_snapshot(tmp_path: Path, kind: sscan_dir / "checkpoints",{"scanId": scan_id, "findings": [], "coverage": {"deferred": [late_review]}},)- run_workbench(state_dir, "recover-scan-results", "--scan-id", scan_id)+ scan_command(state_dir, "recover-scan-results", scan_id)manifest = json.loads(manifest_path.read_text())assert manifest["scan"]["target"]["snapshotDigest"] == legacy_digestassert json.loads((scan_dir / "findings.json").read_text())["findings"] == original_findingsassert late_review in json.loads((scan_dir / "coverage.json").read_text())["deferred"]sealed_artifacts = _sealed_artifacts(scan_dir)- run_workbench(state_dir, "recover-scan-results", "--scan-id", scan_id)+ scan_command(state_dir, "recover-scan-results", scan_id)assert _sealed_artifacts(scan_dir) == sealed_artifacts@@ -319,7 +320,7 @@ def test_cli_scan_completes_when_draft_omits_registered_target(manifest_path.write_text(json.dumps(draft))(scan_dir / "report.md").unlink()- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -365,7 +366,7 @@ def test_cli_scan_completes_when_draft_omits_registered_scope(manifest_path.write_text(json.dumps(draft))(scan_dir / "report.md").unlink()- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -390,12 +391,7 @@ def test_prepared_completion_does_not_publish_scan_before_acceptance(tmp_path: Pscan_id = str(registered["scanId"])write_completed_contract(scan_dir, scan_id, target)- prepared = run_workbench(- state_dir,- "prepare-scan-completion",- "--scan-id",- scan_id,- )+ prepared = scan_command(state_dir, "prepare-scan-completion", scan_id)assert prepared["scan"]["progress"]["status"] == "running"manifest = json.loads((scan_dir / "scan-manifest.json").read_text())@@ -406,7 +402,7 @@ def test_prepared_completion_does_not_publish_scan_before_acceptance(tmp_path: P"SELECT status, seal_manifest_digest FROM scans WHERE id = ?", (scan_id,)).fetchone() == ("running", None)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:@@ -417,7 +413,7 @@ def test_prepared_completion_does_not_publish_scan_before_acceptance(tmp_path: Pdef test_incompatible_sealed_deep_scan_remains_recoverable(tmp_path: Path) -> None:state_dir, scan_id, scan_dir = _start_deep_scan_with_draft_findings(tmp_path)- run_workbench(state_dir, "prepare-scan-completion", "--scan-id", scan_id)+ scan_command(state_dir, "prepare-scan-completion", scan_id)manifest_path = scan_dir / "scan-manifest.json"manifest = json.loads(manifest_path.read_text())manifest["schemaVersion"] = "999.0"@@ -429,7 +425,7 @@ def test_incompatible_sealed_deep_scan_remains_recoverable(tmp_path: Path) -> Nowith sqlite3.connect(state_dir / "workbench.sqlite3") as connection:before = connection.execute("SELECT * FROM scans WHERE id = ?", (scan_id,)).fetchone()- rejected = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id, check=False)+ rejected = scan_command(state_dir, "complete-scan", scan_id, check=False)assert rejected["returncode"] != 0assert "schemaVersion" in str(rejected["stderr"])@@ -448,22 +444,10 @@ def test_rejected_prepared_completion_can_be_marked_failed(tmp_path: Path) -> Noregistered = register_cli_scan(state_dir, target, scan_dir)scan_id = str(registered["scanId"])write_completed_contract(scan_dir, scan_id, target)- run_workbench(- state_dir,- "prepare-scan-completion",- "--scan-id",- scan_id,- )+ scan_command(state_dir, "prepare-scan-completion", scan_id)(scan_dir / "findings.json").write_text("corrupted\n")- failed = run_workbench(- state_dir,- "fail-scan",- "--scan-id",- scan_id,- "--message",- "Sealed scan could not be accepted.",- )+ failed = fail_scan(state_dir, scan_id, "Sealed scan could not be accepted.")assert failed["scan"]["progress"]["status"] == "failed"with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:@@ -495,7 +479,7 @@ def test_cli_completion_accepts_sealed_clean_git_revision_without_snapshot_digesmanifest_path.write_text(json.dumps(manifest))_seal_draft(scan_dir, target)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"sealed_manifest = json.loads(manifest_path.read_text())@@ -527,12 +511,9 @@ def test_completion_populates_coverage_mode_from_selected_scan_mode(tmp_path: Pasave_workspace(state_dir, workspace_id, str(target), scope, mode)scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")if mode == "deep":- run_workbench(+ resume_deep_scan(state_dir,- "begin-deep-scan",- "--scan-id",scan_id,- "--thread-id","thread-completion-binding",environment={"CODEX_HOME": str(codex_home)},)@@ -556,7 +537,7 @@ def test_completion_populates_coverage_mode_from_selected_scan_mode(tmp_path: Painclude_paths=[scope],coverage_mode=wrong,)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"coverage = json.loads((scan_dir / "coverage.json").read_text())assert coverage["mode"] == expected@@ -629,7 +610,7 @@ def test_completion_populates_workbench_owned_unsealed_envelope((scan_dir / "findings.json").write_text(json.dumps(findings))(scan_dir / "coverage.json").write_text(json.dumps(coverage))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"sealed_manifest = json.loads((scan_dir / "scan-manifest.json").read_text())@@ -680,21 +661,15 @@ def test_completion_keeps_invalid_prewrite_drafts_resumable(manifest["scan"]["target"]["kind"] = "git_worktree"(scan_dir / "scan-manifest.json").write_text(json.dumps(manifest))- failed = run_workbench(- state_dir,- "complete-scan",- "--scan-id",- scan_id,- check=False,- )+ failed = scan_command(state_dir, "complete-scan", scan_id, check=False)assert failed["returncode"] != 0assert "target.kind" in str(failed["stderr"])- pending = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ pending = get_scan(state_dir, scan_id)["scan"]assert pending["progress"]["status"] == "running"manifest["scan"]["target"]["kind"] = target_kind(scan_dir / "scan-manifest.json").write_text(json.dumps(manifest))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["progress"]["status"] == "complete"assert completed["findingCount"] == 1@@ -714,22 +689,16 @@ def test_completion_keeps_recoverable_prewrite_failures_resumable(coverage["inventoryStrategy"] = invalid_inventorycoverage_path.write_text(json.dumps(coverage))- failed = run_workbench(- state_dir,- "complete-scan",- "--scan-id",- scan_id,- check=False,- )+ failed = scan_command(state_dir, "complete-scan", scan_id, check=False)assert failed["returncode"] != 0assert "inventoryStrategy" in str(failed["stderr"])assert not (scan_dir / "checkpoint-head.json").exists()- pending = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ pending = get_scan(state_dir, scan_id)["scan"]assert pending["progress"]["status"] == "running"coverage["inventoryStrategy"] = inventory_strategycoverage_path.write_text(json.dumps(coverage))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["progress"]["status"] == "complete"assert completed["findingCount"] == 1@@ -739,7 +708,7 @@ def test_completion_keeps_empty_coverage_defaults(tmp_path: Path) -> None:coverage_path = scan_dir / "coverage.json"coverage_path.write_text("{}")- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["progress"]["status"] == "complete"assert completed["findingCount"] == 1@@ -816,7 +785,7 @@ def test_rejected_completion_restores_parent_head_before_corrected_retry(path: path.read_bytes() for path in (manifest_path, findings_path, coverage_path)}- failed = run_workbench(state_dir, command, "--scan-id", scan_id, check=False)+ failed = scan_command(state_dir, command, scan_id, check=False)assert failed["returncode"] != 0assert ("target.kind" if defect == "target" else "coverage") in failed["stderr"]@@ -837,7 +806,7 @@ def test_rejected_completion_restores_parent_head_before_corrected_retry(coverage_path.write_text(json.dumps(coverage))os.utime(coverage_path, ns=(300, 300))assert findings_path.stat().st_mtime_ns == 200- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["progress"]["status"] == "complete"assert completed["findingCount"] == 1@@ -861,7 +830,7 @@ def test_deep_completion_derives_inventory_without_downgrading_coverage(coverage["inventoryStrategy"] = inventorycoverage_path.write_text(json.dumps(coverage))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -887,16 +856,16 @@ def test_deep_completion_rejects_invalid_target_even_with_recoverable_inventory(coverage["inventoryStrategy"] = ""coverage_path.write_text(json.dumps(coverage))- failed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id, check=False)+ failed = scan_command(state_dir, "complete-scan", scan_id, check=False)assert failed["returncode"] != 0assert "target.kind" in str(failed["stderr"])- recorded = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ recorded = get_scan(state_dir, scan_id)["scan"]assert recorded["progress"]["status"] == "failed"assert recorded["resultsRecoveryNeeded"] is Trueassert json.loads(coverage_path.read_text())["inventoryStrategy"] == ""- recovered = run_workbench(state_dir, "recover-scan-results", "--scan-id", scan_id)["scan"]+ recovered = scan_command(state_dir, "recover-scan-results", scan_id)["scan"]assert recovered["resultsRecoveryNeeded"] is Falsepreserved_coverage = json.loads(coverage_path.read_text())@@ -921,7 +890,7 @@ def test_completion_persists_optional_model_projection_warnings(manifest_path.write_text(json.dumps(manifest))document = scan_dir / "threatmodel.md"if already_completed:- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["warnings"] == []else:document.write_text("# Provisional model\n")@@ -932,7 +901,7 @@ def test_completion_persists_optional_model_projection_warnings(document.unlink()document.mkdir()- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["progress"]["status"] == "complete"assert completed["findingCount"] == 1@@ -945,13 +914,8 @@ def test_completion_persists_optional_model_projection_warnings(assert json.loads(manifest_path.read_text())["scan"]["threatModel"] == modelif already_completed:assert {name: (scan_dir / name).read_bytes() for name in before} == before- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["warnings"] == warnings- )- assert (- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]["warnings"]- == warnings- )+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == warnings+ assert scan_command(state_dir, "complete-scan", scan_id)["scan"]["warnings"] == warningsdef test_completion_recovers_malformed_finding_identity(tmp_path: Path) -> None:@@ -962,7 +926,7 @@ def test_completion_recovers_malformed_finding_identity(tmp_path: Path) -> None:findings["findings"][0]["identity"]["instance"] = "User Input #1"(scan_dir / "findings.json").write_text(json.dumps(findings))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -975,10 +939,7 @@ def test_completion_recovers_malformed_finding_identity(tmp_path: Path) -> None:"anchor": "archive-entry-write-without-containment","instance": "user-input-1",}- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["warnings"]- == (completed["scan"]["warnings"])- )+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == (completed["scan"]["warnings"])def test_completion_keeps_valid_findings_and_warns_about_bad_ones(tmp_path: Path) -> None:@@ -1012,7 +973,7 @@ def test_completion_keeps_valid_findings_and_warns_about_bad_ones(tmp_path: Path)(scan_dir / "findings.json").write_text(json.dumps(findings))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -1047,7 +1008,7 @@ def test_completion_recovers_unknown_optional_root_cause_evidence_reference(}findings_path.write_text(json.dumps(document))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["progress"]["status"] == "complete"assert completed["findingCount"] == 1@@ -1113,7 +1074,7 @@ def test_completion_retains_strongest_duplicate_finding_regardless_of_order(findings["findings"].append(finding)findings_path.write_text(json.dumps(findings))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete", caseassert completed["scan"]["findingCount"] == 1, case@@ -1172,7 +1133,7 @@ def test_completion_preserves_findings_with_invalid_or_duplicate_writeups(findings["findings"].append(finding)findings_path.write_text(json.dumps(findings))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 7@@ -1213,7 +1174,7 @@ def test_valid_checkpoint_survives_malformed_replacement_finding(tmp_path: Path)(scan_dir / "checkpoints" / ("a" * 64 + ".json")).write_text(json.dumps(checkpoint))findings["findings"][0]["summary"] = ""(scan_dir / "findings.json").write_text(json.dumps(findings))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["findingCount"] == 1assert completed["findings"][0]["summary"] == checkpoint["findings"][0]["summary"]@@ -1231,7 +1192,7 @@ def test_duplicate_finding_with_malformed_history_does_not_block_valid_results(strong["provenance"]["previousFindings"] = "malformed optional history"document["findings"].append(strong)path.write_text(json.dumps(document))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["findingCount"] == 1finding = json.loads(path.read_text())["findings"][0]assert finding["severity"]["level"] == "critical"@@ -1247,7 +1208,7 @@ def test_completion_succeeds_when_all_findings_are_malformed(tmp_path: Path) ->findings["findings"][0]["summary"] = ""(scan_dir / "findings.json").write_text(json.dumps(findings))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 0@@ -1285,7 +1246,7 @@ def test_completion_recovers_lone_surrogate_in_malformed_finding(tmp_path: Path)findings["findings"][0]["severity"]["changeConditions"] = ["\ud800"]findings_path.write_text(json.dumps(findings))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 0@@ -1314,7 +1275,7 @@ def test_completion_keeps_verified_receipts_and_downgrades_invalid_coverage(]coverage_path.write_text(json.dumps(coverage))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -1333,9 +1294,7 @@ def test_completion_keeps_verified_receipts_and_downgrades_invalid_coverage(assert sealed_coverage["surfaces"][0]["receiptRefs"] == [receipt_ref]sealed_manifest = json.loads((scan_dir / "scan-manifest.json").read_text())assert receipt_ref in {artifact["path"] for artifact in sealed_manifest["scan"]["artifacts"]}- assert run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["warnings"] == (- warnings- )+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == (warnings)assert (scan_dir / "report.md").is_file()@@ -1372,7 +1331,7 @@ def test_completion_recovers_malformed_coverage_rows(tmp_path: Path) -> None:]coverage_path.write_text(json.dumps(coverage))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -1410,7 +1369,7 @@ def test_completion_recovers_malformed_coverage_collections(tmp_path: Path) -> Ncoverage["deferred"] = "later"coverage_path.write_text(json.dumps(coverage))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["findingCount"] == 1@@ -1442,7 +1401,7 @@ def test_completion_recovers_malformed_hardening_portfolios(tmp_path: Path) -> Nportfolio.parent.mkdir(parents=True)portfolio.symlink_to(scan_dir / "report.md")- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete", caseassert completed["scan"]["findingCount"] == 1, casediff --git a/plugins/codex-security/tests/test_workbench_db.py b/plugins/codex-security/tests/test_workbench_db.pyindex 44c93f60e..b21d854e2 100644--- a/plugins/codex-security/tests/test_workbench_db.py+++ b/plugins/codex-security/tests/test_workbench_db.py@@ -644,17 +644,14 @@ def test_completion_warns_after_plain_directory_changes(tmp_path: Path) -> None:original_digest = started["results"]["contract"]["target"]["requiredSnapshotDigest"]source.write_text("version = 2\n")- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["warnings"] == [DIRECTORY_CHANGED_WARNING]assert completed["targetWarnings"] == [DIRECTORY_CHANGED_WARNING]manifest = json.loads((scan_dir / "scan-manifest.json").read_text())assert manifest["scan"]["target"]["snapshotDigest"] == original_digest- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["warnings"]- == completed["scan"]["warnings"]- )+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == completed["scan"]["warnings"]def test_completion_warns_when_scanned_directory_becomes_unavailable(tmp_path: Path) -> None:@@ -666,7 +663,7 @@ def test_completion_warns_when_scanned_directory_becomes_unavailable(tmp_path: Pwrite_completed_contract(scan_dir, scan_id, target, relative_path="app.py")target.rename(tmp_path / "moved-target")- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["warnings"] == [TARGET_UNAVAILABLE_WARNING]@@ -697,12 +694,7 @@ def test_workbench_serializes_concurrent_scan_completion(tmp_path: Path) -> Nonewith ThreadPoolExecutor(max_workers=2) as executor:results = list(executor.map(- lambda _: run_workbench(- state_dir,- "complete-scan",- "--scan-id",- scan_id,- ),+ lambda _: scan_command(state_dir, "complete-scan", scan_id),range(2),))@@ -955,7 +947,7 @@ def test_completed_findings_are_summarized_and_sorted_by_severity(tmp_path: Pathdocument["findings"] = [informational, low, high, critical]findings_path.write_text(json.dumps(document))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["severityCounts"] == {"critical": 1,"high": 1,@@ -2281,7 +2273,7 @@ def test_workbench_warns_after_working_tree_changes(tmp_path: Path) -> None:coverage_mode="working_tree",)(target / "new-file.txt").write_text("changed during scan\n")- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["warnings"] == [WORKTREE_CHANGED_WARNING]manifest = json.loads((scan_dir / "scan-manifest.json").read_text())@@ -2322,7 +2314,7 @@ def test_workbench_warns_after_working_tree_head_changes(subprocess.run(["git", "add", "new-file.txt"], cwd=target, check=True)subprocess.run(["git", "commit", "-qm", "Move HEAD"], cwd=target, check=True)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["warnings"] == [HEAD_CHANGED_WARNING]manifest = json.loads((scan_dir / "scan-manifest.json").read_text())@@ -2402,7 +2394,7 @@ def test_workbench_populates_manifest_with_working_tree_digest(tmp_path: Path) -diff_head_revision=str(diff_target["headRevision"]),coverage_mode="repository",)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"manifest = json.loads((scan_dir / "scan-manifest.json").read_text())coverage = json.loads((scan_dir / "coverage.json").read_text())@@ -2486,7 +2478,7 @@ def test_workbench_populates_completed_manifest_with_exact_diff_target(tmp_path:draft_target = draft_manifest["scan"]["target"]draft_target["revision"] = "stale-revision"(scan_dir / "scan-manifest.json").write_text(json.dumps(draft_manifest))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"manifest = json.loads((scan_dir / "scan-manifest.json").read_text())assert "revision" not in manifest["scan"]["target"]@@ -2882,7 +2874,7 @@ def test_workbench_preserves_scan_when_git_revision_cannot_be_rechecked(tmp_pathtarget,target_kind="git_worktree",)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["warnings"] == [GIT_UNAVAILABLE_WARNING]@@ -2934,10 +2926,10 @@ def test_completed_finding_projects_writeup_and_poc_artifact_paths(outside = tmp_path / "outside.txt"outside.write_text("must not be projected\n")(poc / "outside-link.txt").symlink_to(outside)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)if non_utf8_artifact:(poc / os.fsdecode(b"caf\xe9.txt")).write_text("Supplemental fixture.\n")- completed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)+ completed = get_scan(state_dir, scan_id)assert completed["scan"]["findings"][0]["artifactPaths"] == [report_path,f"findings/{slug}/poc/README.md",@@ -2979,7 +2971,7 @@ def test_workbench_populates_clean_git_scan_revision_with_large_source_excerpt(target_kind="git_revision",target_revision="wrong-revision",)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"manifest = json.loads((Path(str(started["results"]["scanDir"])) / "scan-manifest.json").read_text()@@ -2994,7 +2986,7 @@ def test_workbench_populates_clean_git_scan_revision_with_large_source_excerpt((target / "README.md").write_text("replacement source\n")subprocess.run(["git", "add", "README.md"], cwd=target, check=True)subprocess.run(["git", "commit", "-qm", "Replace source fixture"], cwd=target, check=True)- refreshed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)+ refreshed = get_scan(state_dir, scan_id)assert refreshed["scan"]["findings"][0]["sourceExcerpt"] == excerpt@@ -3128,7 +3120,7 @@ def test_workbench_preserves_in_flight_git_scan_during_migration_normalization(connection.execute("ALTER TABLE workspaces DROP COLUMN capability_preflight_json")run_workbench(state_dir, "database-info")- migrated = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)+ migrated = get_scan(state_dir, scan_id)assert migrated["scan"]["contract"]["target"]["allowedKinds"] == allowed_kindswrite_completed_contract(Path(str(started["results"]["scanDir"])),@@ -3137,7 +3129,7 @@ def test_workbench_preserves_in_flight_git_scan_during_migration_normalization(target_kind="git_revision",target_revision=revision,)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"@@ -3159,19 +3151,10 @@ def test_workbench_preserves_dirty_git_scan_after_worktree_changes(tmp_path: Pattarget_kind="git_revision",target_revision=revision,)- failed = run_workbench(- state_dir,- "complete-scan",- "--scan-id",- scan_id,- check=False,- )+ failed = scan_command(state_dir, "complete-scan", scan_id, check=False)assert failed["returncode"] != 0assert "scan.target.kind" in str(failed["stderr"])- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["progress"]["status"]- == "running"- )+ assert get_scan(state_dir, scan_id)["scan"]["progress"]["status"] == "running"started = start_delivered_scan(state_dir, "--workspace-id", str(saved["id"]))scan_id = str(started["results"]["scanId"])@@ -3186,7 +3169,7 @@ def test_workbench_preserves_dirty_git_scan_after_worktree_changes(tmp_path: Patsnapshot_digest=snapshot_digest,)(target / "README.md").write_text(f"{dirty_content}changed during scan\n")- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["warnings"] == [WORKTREE_CHANGED_WARNING]manifest = json.loads(@@ -3208,7 +3191,7 @@ def test_workbench_generates_reports_during_completion(tmp_path: Path) -> None:(scan_dir / "report.html").write_text("<p>Stale HTML report</p>")(scan_dir / "report.md").write_text("# Untrusted report\n")- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["progress"]["status"] == "complete"assert not (scan_dir / "report.html").exists()@@ -3226,7 +3209,7 @@ def test_workbench_omits_unsafe_symlink_source_path_without_hiding_finding(tmp_pstarted = start_delivered_scan(state_dir, "--workspace-id", str(saved["id"]))scan_id = str(started["results"]["scanId"])write_completed_contract(Path(str(started["results"]["scanDir"])), scan_id, target)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)location = completed["scan"]["findings"][0]["locations"][0]assert location["path"] == "src/extract.py"assert "absolutePath" not in location@@ -3241,10 +3224,10 @@ def test_workbench_hides_missing_artifact_on_reopen(tmp_path: Path) -> None:scan_id = str(started["results"]["scanId"])scan_dir = Path(str(started["results"]["scanDir"]))write_completed_contract(scan_dir, scan_id, target)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ completed = scan_command(state_dir, "complete-scan", scan_id)assert completed["scan"]["reportAvailable"] is True(scan_dir / "report.md").unlink()- reopened = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)+ reopened = get_scan(state_dir, scan_id)assert reopened["scan"]["reportAvailable"] is Falseassert "markdownReport" not in reopened["scan"]["artifacts"]diff --git a/plugins/codex-security/tests/test_workbench_db_exports.py b/plugins/codex-security/tests/test_workbench_db_exports.pyindex b63b21347..39f2f18b4 100644--- a/plugins/codex-security/tests/test_workbench_db_exports.py+++ b/plugins/codex-security/tests/test_workbench_db_exports.py@@ -20,18 +20,26 @@ from workbench_test_support import (create_saved_workspace,create_workspace,empty_target_scan,+ fail_scan,+ get_scan,initialize_git_repository,mark_deep_coordinator_succeeded,request_remediation,request_remediation_action,+ resume_deep_scan,run_workbench,save_workspace,+ saved_coverage,+ saved_draft,scan_command,set_remediation,set_triage,start_delivered_scan,start_saved_scan,+ start_scan_command,start_workspace_scan,+ update_progress,+ workspace_command,write_checkpoint,write_completed_contract,)@@ -44,9 +52,9 @@ def test_stopped_scan_keeps_saved_findings_and_exports(tmp_path: Path, terminatiextra = (("--message", "Stopped after recording a finding.") if termination == "fail-scan" else ())- run_workbench(state_dir, termination, "--scan-id", scan_id, *extra)+ scan_command(state_dir, termination, scan_id, *extra)- stopped = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ stopped = get_scan(state_dir, scan_id)["scan"]expected_status = "failed" if termination == "fail-scan" else "canceled"assert stopped["progress"]["status"] == expected_statusassert stopped["findingCount"] == 1@@ -58,14 +66,7 @@ def test_stopped_scan_keeps_saved_findings_and_exports(tmp_path: Path, terminati)assert json.loads((scan_dir / "coverage.json").read_text())["completeness"] == "partial"for export_format in ("json", "csv", "sarif"):- exported = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- export_format,- )+ exported = scan_command(state_dir, "export-findings", scan_id, "--format", export_format)assert Path(str(exported["export"]["path"])).is_file()assert exported["scan"]["progress"]["status"] == expected_statussarif = json.loads((scan_dir / "exports" / "results.sarif").read_text())@@ -73,15 +74,7 @@ def test_stopped_scan_keeps_saved_findings_and_exports(tmp_path: Path, terminatioriginal = (scan_dir / "scan-manifest.json").read_bytes()(scan_dir / "scan-manifest.json").write_bytes(original + b" ")- rejected = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "json",- check=False,- )+ rejected = scan_command(state_dir, "export-findings", scan_id, "--format", "json", check=False)assert rejected["returncode"] != 0assert "sealed scan manifest changed" in str(rejected["stderr"])@@ -99,8 +92,8 @@ def test_late_parent_draft_is_retained_without_mutating_frozen_stopped_seal(("coverage", "coverage.json"),)}- run_workbench(state_dir, "fail-scan", "--scan-id", scan_id, "--message", "Stopped.")- stopped = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ fail_scan(state_dir, scan_id, "Stopped.")+ stopped = get_scan(state_dir, scan_id)["scan"]seal = (scan_dir / "scan-manifest.json").read_bytes()documents["findings"]["findings"][0]["identity"]["anchor"] = "late-independent-finding"documents["coverage"]["completeness"] = "partial"@@ -118,20 +111,14 @@ def test_late_parent_draft_is_retained_without_mutating_frozen_stopped_seal(drafts.mkdir()staged = drafts / f"{uuid.uuid4()}.json"staged.write_text(json.dumps(documents))- rejected = run_workbench(- state_dir,- "write-scan-draft",- "--scan-id",- scan_id,- "--draft-path",- str(staged),- check=False,+ rejected = scan_command(+ state_dir, "write-scan-draft", scan_id, "--draft-path", str(staged), check=False)assert rejected["returncode"] != 0assert "saved checkpoint" in str(rejected["stderr"])assert (scan_dir / "scan-manifest.json").read_bytes() == sealassert checkpoint_path.read_bytes() == json.dumps(payload).encode()- recovered = run_workbench(state_dir, "recover-scan-results", "--scan-id", scan_id)["scan"]+ recovered = scan_command(state_dir, "recover-scan-results", scan_id)["scan"]assert recovered["findingCount"] == 2coverage = json.loads((scan_dir / "coverage.json").read_text())assert any(item.get("id") == "late-review" for item in coverage["deferred"])@@ -142,7 +129,7 @@ def test_late_parent_draft_is_retained_without_mutating_frozen_stopped_seal(json.loads((scan_dir / "scan-manifest.json").read_text())["scan"]["completedAt"]== json.loads(seal)["scan"]["completedAt"])- unchanged = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ unchanged = get_scan(state_dir, scan_id)["scan"]assert unchanged["progress"]["updatedAt"] == recovered["progress"]["updatedAt"]assert unchanged["updatedAt"] == recovered["updatedAt"]@@ -154,19 +141,14 @@ def test_canceled_scan_does_not_accept_checkpoints_written_after_cancellation(target = tmp_path / "target"target.mkdir()saved = create_saved_workspace(state_dir, target)- started = run_workbench(- state_dir,- "start-scan",- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),+ started = start_scan_command(+ state_dir, str(saved["id"]), "--scan-root", str(tmp_path / "scans"))["results"]scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "cancel-scan", "--scan-id", scan_id)- canceled = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ scan_command(state_dir, "cancel-scan", scan_id)+ canceled = get_scan(state_dir, scan_id)["scan"]sealed_manifest = (scan_dir / "scan-manifest.json").read_bytes()late_finding = json.loads((scan_dir / "findings.json").read_text())["findings"][0]late_finding["identity"]["anchor"] = "late-after-cancellation"@@ -178,7 +160,7 @@ def test_canceled_scan_does_not_accept_checkpoints_written_after_cancellation(}write_checkpoint(scan_dir / "checkpoints", checkpoint)- unchanged = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ unchanged = get_scan(state_dir, scan_id)["scan"]assert canceled["progress"]["status"] == "canceled"assert unchanged["findingCount"] == canceled["findingCount"] == 1@@ -203,20 +185,12 @@ def test_stopped_clean_git_checkpoint_uses_revision_target(tmp_path: Path) -> Noconnection.execute("UPDATE scans SET target_snapshot_digest = NULL WHERE id = ?", (scan_id,))- checkpoint = {- "scanId": scan_id,- "complete": False,- "findings": [],- "coverage": {- "completeness": "partial",- "surfaces": [],- "explicitExclusions": [],- "deferred": [{"id": "pending-review", "reason": "Review stopped early."}],- },- }+ checkpoint = saved_draft(+ scan_id, deferred=[{"id": "pending-review", "reason": "Review stopped early."}]+ )write_checkpoint(scan_dir / "checkpoints", checkpoint)- run_workbench(state_dir, "fail-scan", "--scan-id", scan_id, "--message", "Stopped.")+ fail_scan(state_dir, scan_id, "Stopped.")manifest = json.loads((scan_dir / "scan-manifest.json").read_text())assert manifest["scan"]["target"]["kind"] == "git_revision"@@ -243,20 +217,12 @@ def test_stopped_diff_checkpoint_uses_canonical_snapshot_digest(""",(diff_kind, base_revision, head_revision, scan_id),)- checkpoint = {- "scanId": scan_id,- "complete": False,- "findings": [],- "coverage": {- "completeness": "partial",- "surfaces": [],- "explicitExclusions": [],- "deferred": [{"id": "pending-review", "reason": "Review stopped early."}],- },- }+ checkpoint = saved_draft(+ scan_id, deferred=[{"id": "pending-review", "reason": "Review stopped early."}]+ )write_checkpoint(scan_dir / "checkpoints", checkpoint)- run_workbench(state_dir, "fail-scan", "--scan-id", scan_id, "--message", "Stopped.")+ fail_scan(state_dir, scan_id, "Stopped.")target_contract = json.loads((scan_dir / "scan-manifest.json").read_text())["scan"]["target"]expected = hashlib.sha256(@@ -275,8 +241,8 @@ def test_stopped_diff_checkpoint_uses_canonical_snapshot_digest(def test_frozen_stopped_results_ignore_late_index_field_changes(tmp_path: Path) -> None:state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "fail-scan", "--scan-id", scan_id, "--message", "Stopped.")- original = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["findings"][0]+ fail_scan(state_dir, scan_id, "Stopped.")+ original = get_scan(state_dir, scan_id)["scan"]["findings"][0]set_triage(state_dir,str(original["occurrenceId"]),@@ -317,7 +283,7 @@ def test_frozen_stopped_results_ignore_late_index_field_changes(tmp_path: Path)}write_checkpoint(scan_dir / "checkpoints", checkpoint)- refreshed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ refreshed = get_scan(state_dir, scan_id)["scan"]assert refreshed["findingCount"] == 1updated = refreshed["findings"][0]@@ -330,9 +296,7 @@ def test_frozen_stopped_results_ignore_late_index_field_changes(tmp_path: Path)assert updated["triage"]["closeReason"] == "wont_fix"assert updated["triage"]["note"] == ("Retain this review decision across checkpoint refreshes.")assert updated["triage"]["status"] == "closed"- exported = run_workbench(state_dir, "export-findings", "--scan-id", scan_id, "--format", "csv")[- "export"- ]+ exported = scan_command(state_dir, "export-findings", scan_id, "--format", "csv")["export"]with Path(str(exported["path"])).open(newline="") as source:row = next(csv.DictReader(source))assert row["title"] == original["title"]@@ -346,7 +310,7 @@ def test_frozen_stopped_results_ignore_late_index_field_changes(tmp_path: Path)def test_frozen_stopped_results_skip_late_checkpoint_reindexing(tmp_path: Path) -> None:state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "fail-scan", "--scan-id", scan_id, "--message", "Stopped.")+ fail_scan(state_dir, scan_id, "Stopped.")finding = json.loads((scan_dir / "findings.json").read_text())["findings"][0]finding["identity"]["anchor"] = "late-independent-finding"checkpoint = {@@ -404,7 +368,7 @@ def test_frozen_stopped_results_skip_late_checkpoint_reindexing(tmp_path: Path)== digest_before)assert checkpoint_path.exists()- refreshed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ refreshed = get_scan(state_dir, scan_id)["scan"]assert refreshed["findingCount"] == 1assert refreshed["reportAvailable"] is True@@ -412,7 +376,7 @@ def test_frozen_stopped_results_skip_late_checkpoint_reindexing(tmp_path: Path)def test_frozen_stopped_results_ignore_late_foreign_checkpoint_warning(tmp_path: Path) -> None:state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "fail-scan", "--scan-id", scan_id, "--message", "Stopped.")+ fail_scan(state_dir, scan_id, "Stopped.")foreign = {"scanId": str(uuid.uuid4()),"complete": False,@@ -421,14 +385,11 @@ def test_frozen_stopped_results_ignore_late_foreign_checkpoint_warning(tmp_path:}write_checkpoint(scan_dir / "checkpoints", foreign)- refreshed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ refreshed = get_scan(state_dir, scan_id)["scan"]assert all("belongs to a different scan" not in warning for warning in refreshed["warnings"])seal = (scan_dir / "scan-manifest.json").read_bytes()- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["warnings"]- == (refreshed["warnings"])- )+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == (refreshed["warnings"])assert (scan_dir / "scan-manifest.json").read_bytes() == seal@@ -438,17 +399,9 @@ def test_final_candidate_disposition_supersedes_pending_checkpoint() -> None:state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)- pending = {- "scanId": scan_id,- "complete": False,- "findings": [],- "coverage": {- "completeness": "partial",- "surfaces": [],- "explicitExclusions": [],- "deferred": [{"candidateId": "candidate-x", "reason": "Validation is pending."}],- },- }+ pending = saved_draft(+ scan_id, deferred=[{"candidateId": "candidate-x", "reason": "Validation is pending."}]+ )checkpoint = write_checkpoint(scan_dir / "checkpoints", pending)findings = json.loads((scan_dir / "findings.json").read_text())if disposition == "provenance-reported":@@ -466,7 +419,7 @@ def test_final_candidate_disposition_supersedes_pending_checkpoint((scan_dir / "coverage.json").write_text(json.dumps(coverage))for path in (checkpoint, scan_dir / "coverage.json"):os.utime(path, ns=(200, 200))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]final_coverage = json.loads((scan_dir / "coverage.json").read_text())assert completed["progress"]["status"] == "complete"assert final_coverage["completeness"] == "complete"@@ -485,13 +438,10 @@ def test_incomplete_parent_checkpoint_cannot_complete_scan(tmp_path: Path) -> Nomanifest = json.loads((scan_dir / "scan-manifest.json").read_text())manifest["scan"]["complete"] = False(scan_dir / "scan-manifest.json").write_text(json.dumps(manifest))- rejected = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id, check=False)+ rejected = scan_command(state_dir, "complete-scan", scan_id, check=False)assert rejected["returncode"] != 0assert "incomplete" in str(rejected["stderr"]).lower()- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["progress"]["status"]- == "running"- )+ assert get_scan(state_dir, scan_id)["scan"]["progress"]["status"] == "running"@pytest.mark.parametrize("termination", ["fail-scan", "cancel-scan"])@@ -511,7 +461,7 @@ def test_model_only_draft_is_available_before_findings_and_survives_stop(str(tmp_path / "scans"),)["results"]scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))- run_workbench(state_dir, "update-progress", "--scan-id", scan_id, "--phase", "threat_model")+ update_progress(state_dir, scan_id, "--phase", "threat_model")write_completed_contract(scan_dir, scan_id, target)documents = {key: json.loads((scan_dir / filename).read_text())@@ -533,10 +483,10 @@ def test_model_only_draft_is_available_before_findings_and_survives_stop(draft = scan_dir / "drafts" / f"{uuid.uuid4()}.json"draft.parent.mkdir()draft.write_text(json.dumps(documents))- run_workbench(state_dir, "write-scan-draft", "--scan-id", scan_id, "--draft-path", str(draft))- active = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ scan_command(state_dir, "write-scan-draft", scan_id, "--draft-path", str(draft))+ active = get_scan(state_dir, scan_id)["scan"]assert active["progress"]["phase"] == "threat_model"- workspace = run_workbench(state_dir, "get-workspace", "--workspace-id", str(saved["id"]))+ workspace = workspace_command(state_dir, "get-workspace", str(saved["id"]))assert "threatModel" not in workspace["results"]assert workspace["results"]["threatModelAvailable"] is Trueassert active["threatModelAvailable"] is True@@ -549,13 +499,11 @@ def test_model_only_draft_is_available_before_findings_and_survives_stop({"id": "pending-review", "reason": "A discovery review is pending."}]draft.write_text(json.dumps(documents))- run_workbench(state_dir, "write-scan-draft", "--scan-id", scan_id, "--draft-path", str(draft))- reviewing = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ scan_command(state_dir, "write-scan-draft", scan_id, "--draft-path", str(draft))+ reviewing = get_scan(state_dir, scan_id)["scan"]assert reviewing["progress"]["phase"] == "discovery"before = (scan_dir / "scan-manifest.json").read_bytes()- exported = run_workbench(- state_dir, "export-findings", "--scan-id", scan_id, "--artifact", "threat-model"- )+ exported = scan_command(state_dir, "export-findings", scan_id, "--artifact", "threat-model")assert exported["export"] == {"artifact": "threat-model","format": "md",@@ -567,8 +515,8 @@ def test_model_only_draft_is_available_before_findings_and_survives_stop(document.unlink()document.mkdir()extra = ("--message", "Stopped after saving the model.") if termination == "fail-scan" else ()- run_workbench(state_dir, termination, "--scan-id", scan_id, *extra)- stopped = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ scan_command(state_dir, termination, scan_id, *extra)+ stopped = get_scan(state_dir, scan_id)["scan"]assert "threatModel" not in stoppedassert json.loads((scan_dir / "scan-manifest.json").read_text())["scan"]["threatModel"] == modelassert stopped["threatModelProvenance"]["provisional"] is True@@ -579,21 +527,16 @@ def test_model_only_draft_is_available_before_findings_and_survives_stop(if projection_failure_at == "refresh":document.unlink()document.mkdir()- stopped = run_workbench(state_dir, "preserve-scan-results", "--scan-id", scan_id)["scan"]+ stopped = scan_command(state_dir, "preserve-scan-results", scan_id)["scan"]if projection_failure_at is not None:warnings = stopped["warnings"]assert len(warnings) == 1assert warnings[0].startswith("Automatic threat model save failed:")assert "threatModelPath" not in stoppedassert "threatModel" not in stopped["artifacts"]+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == warningsassert (- run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["warnings"]- == warnings- )- assert (- run_workbench(state_dir, "preserve-scan-results", "--scan-id", scan_id)["scan"][- "warnings"- ]+ scan_command(state_dir, "preserve-scan-results", scan_id)["scan"]["warnings"]== warnings)assert (scan_dir / "scan-manifest.json").read_bytes() == sealed@@ -609,7 +552,7 @@ def test_history_does_not_expose_a_model_from_changed_sealed_artifacts(manifest = json.loads(manifest_path.read_text())manifest["scan"]["threatModel"] = {"summary": "Original queue boundaries."}manifest_path.write_text(json.dumps(manifest))- complete = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ complete = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert complete["threatModelAvailable"] is Trueif changed_file == "scan-manifest.json":manifest = json.loads(manifest_path.read_text())@@ -618,7 +561,7 @@ def test_history_does_not_expose_a_model_from_changed_sealed_artifacts(else:path = scan_dir / changed_filepath.write_bytes(path.read_bytes() + b" ")- retained = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ retained = get_scan(state_dir, scan_id)["scan"]assert retained["progress"]["status"] == "complete"assert retained["threatModelAvailable"] is Falseassert "threatModel" not in retained@@ -669,10 +612,10 @@ def test_invalid_model_or_binding_keeps_history_available_for_semantic_repair((scan_dir / "threatmodel.md").write_text("# Earlier model\n")stored = {path: path.read_bytes() for path in scan_dir.rglob("*") if path.is_file()}- active = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ active = get_scan(state_dir, scan_id)["scan"]assert active["progress"]["status"] == "running"assert active["threatModelAvailable"] is False- reopened = run_workbench(state_dir, "get-workspace", "--workspace-id", str(saved["id"]))+ reopened = workspace_command(state_dir, "get-workspace", str(saved["id"]))assert reopened["results"]["scanId"] == scan_idassert reopened["results"]["threatModelAvailable"] is Falsefor result in (active, reopened["results"]):@@ -684,11 +627,9 @@ def test_invalid_model_or_binding_keeps_history_available_for_semantic_repair(draft = scan_dir / "drafts" / f"{uuid.uuid4()}.json"draft.parent.mkdir()draft.write_text(json.dumps(documents))- repaired = run_workbench(- state_dir, "write-scan-draft", "--scan-id", scan_id, "--draft-path", str(draft)- )+ repaired = scan_command(state_dir, "write-scan-draft", scan_id, "--draft-path", str(draft))assert repaired["status"] == "draft_written"- active = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ active = get_scan(state_dir, scan_id)["scan"]assert active["threatModelAvailable"] is Trueassert "threatModel" not in activeassert json.loads((scan_dir / "scan-manifest.json").read_text())["scan"]["threatModel"] == model@@ -701,7 +642,7 @@ def test_export_validation_checks_binding_without_writing_or_pinning_legacy_arti) -> None:state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ scan_command(state_dir, "complete-scan", scan_id)artifacts = {path: path.read_bytes() for path in scan_dir.rglob("*") if path.is_file()}with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.execute("UPDATE scans SET seal_manifest_digest = NULL WHERE id = ?", (scan_id,))@@ -757,44 +698,23 @@ def test_completed_findings_export_inside_scan_directory(tmp_path: Path) -> Nonesource.write_text("".join(f"line {line}\n" for line in range(1, 46)))scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["artifacts"]["sarifReport"] == str(scan_dir / "exports" / "results.sarif")sarif_path = scan_dir / "exports" / "results.sarif"sealed_sarif = sarif_path.read_bytes()source.write_text("".join(f"changed line {line}\n" for line in range(1, 46)))sarif_path.write_text("{}")- sarif_exported = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "sarif",- )+ sarif_exported = scan_command(state_dir, "export-findings", scan_id, "--format", "sarif")assert sarif_exported["export"] == {"format": "sarif", "path": str(sarif_path)}assert sarif_path.read_bytes() == sealed_sarif- exported = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "csv",- )+ exported = scan_command(state_dir, "export-findings", scan_id, "--format", "csv")csv_path = scan_dir / "exports" / "findings.csv"assert exported["export"] == {"format": "csv", "path": str(csv_path)}assert csv_path.read_text().startswith("occurrence_id,finding_id,title,summary")- json_exported = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "json",- )+ json_exported = scan_command(state_dir, "export-findings", scan_id, "--format", "json")assert json_exported["export"] == {"format": "json","path": str(scan_dir / "findings.json"),@@ -804,23 +724,11 @@ def test_completed_findings_export_inside_scan_directory(tmp_path: Path) -> Nonemutated_manifest = json.loads(sealed_manifest_bytes)mutated_manifest["scan"]["target"]["displayName"] = "forged-target"manifest_path.write_text(json.dumps(mutated_manifest))- repeated_completion = run_workbench(- state_dir,- "complete-scan",- "--scan-id",- scan_id,- check=False,- )+ repeated_completion = scan_command(state_dir, "complete-scan", scan_id, check=False)assert "sealed scan manifest changed after completion" in str(repeated_completion["stderr"])assert sarif_path.read_bytes() == sealed_sarif- mutated_export = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "json",- check=False,+ mutated_export = scan_command(+ state_dir, "export-findings", scan_id, "--format", "json", check=False)assert "sealed scan manifest changed after completion" in str(mutated_export["stderr"])assert sarif_path.read_bytes() == sealed_sarif@@ -836,29 +744,17 @@ def test_completed_findings_export_inside_scan_directory(tmp_path: Path) -> Noneif artifact["path"] == "findings.json":artifact["sha256"] = hashlib.sha256(mutated_findings_bytes).hexdigest()manifest_path.write_text(json.dumps(coordinated_manifest))- coordinated_export = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "json",- check=False,+ coordinated_export = scan_command(+ state_dir, "export-findings", scan_id, "--format", "json", check=False)assert "sealed scan manifest changed after completion" in str(coordinated_export["stderr"])- refreshed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)+ refreshed = get_scan(state_dir, scan_id)assert refreshed["scan"]["findings"][0]["summary"] != ("Coordinated post-completion rewrite")findings_path.write_bytes(sealed_findings_bytes)manifest_path.write_bytes(sealed_manifest_bytes)findings_path.write_text("{}")- tampered_json = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "json",- check=False,+ tampered_json = scan_command(+ state_dir, "export-findings", scan_id, "--format", "json", check=False)assert "sealed artifact changed" in str(tampered_json["stderr"])@@ -886,14 +782,8 @@ def test_deep_csv_export_adds_only_candidate_id_column()save_workspace(state_dir, workspace_id, str(target), ".", "deep")scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")- run_workbench(- state_dir,- "begin-deep-scan",- "--scan-id",- scan_id,- "--thread-id",- "thread-deep-export",- environment={"CODEX_HOME": str(codex_home)},+ resume_deep_scan(+ state_dir, scan_id, "thread-deep-export", environment={"CODEX_HOME": str(codex_home)})mark_deep_coordinator_succeeded(state_dir, scan_id, scan_dir)write_completed_contract(@@ -910,15 +800,8 @@ def test_deep_csv_export_adds_only_candidate_id_column(finding["extensions"] = extensionsfindings_path.write_text(json.dumps(findings_document))- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)- exported = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "csv",- )["export"]+ scan_command(state_dir, "complete-scan", scan_id)+ exported = scan_command(state_dir, "export-findings", scan_id, "--format", "csv")["export"]with Path(exported["path"]).open(newline="") as source:reader = csv.DictReader(source)rows = list(reader)@@ -957,15 +840,8 @@ def test_csv_export_escapes_newline_and_full_width_formula_prefixes(tmp_path: Pafinding["remediation"] = " \t+1+1"findings_path.write_text(json.dumps(findings_document))- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)- exported = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "csv",- )["export"]+ scan_command(state_dir, "complete-scan", scan_id)+ exported = scan_command(state_dir, "export-findings", scan_id, "--format", "csv")["export"]with Path(exported["path"]).open(newline="") as source:row = next(csv.DictReader(source))@@ -989,20 +865,13 @@ def test_completed_findings_are_returned_in_bounded_pages(tmp_path: Path) -> Nonfor index in range(75)]findings_path.write_text(json.dumps(document))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["findingCount"] == 75assert completed["findingsTruncated"] is Trueassert len(completed["findings"]) == 20embedded_occurrence_ids = {finding["occurrenceId"] for finding in completed["findings"]}- second_page = run_workbench(- state_dir,- "list-findings",- "--scan-id",- scan_id,- "--offset",- "20",- "--limit",- "50",+ second_page = scan_command(+ state_dir, "list-findings", scan_id, "--offset", "20", "--limit", "50")["findingsPage"]assert second_page["offset"] == 20assert second_page["nextOffset"] == 40@@ -1012,9 +881,7 @@ def test_completed_findings_are_returned_in_bounded_pages(tmp_path: Path) -> Nonfinding["occurrenceId"] for finding in second_page["findings"])off_prefix_occurrence_id = second_page["findings"][0]["occurrenceId"]- selected = run_workbench(- state_dir, "get-scan", "--scan-id", scan_id, "--occurrence-id", off_prefix_occurrence_id- )["scan"]+ selected = get_scan(state_dir, scan_id, "--occurrence-id", off_prefix_occurrence_id)["scan"]assert any(finding["occurrenceId"] == off_prefix_occurrence_id for finding in selected["findings"])@@ -1025,20 +892,15 @@ def test_embedded_and_paged_findings_bound_large_stored_fields(tmp_path: Path) -target = tmp_path / "target"target.mkdir()saved = create_saved_workspace(state_dir, target)- started = run_workbench(- state_dir,- "start-scan",- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),+ started = start_scan_command(+ state_dir, str(saved["id"]), "--scan-root", str(tmp_path / "scans"))scan_id = str(started["results"]["scanId"])scan_dir = Path(str(started["results"]["scanDir"]))with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.execute("UPDATE scans SET handoff_status = 'delivered' WHERE id = ?", (scan_id,))write_completed_contract(scan_dir, scan_id, target)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]occurrence_id = completed["findings"][0]["occurrenceId"]with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:details = json.loads(@@ -1069,10 +931,8 @@ def test_embedded_and_paged_findings_bound_large_stored_fields(tmp_path: Path) -"UPDATE finding_locations SET relative_path = ?, role = ? WHERE occurrence_id = ?",("p" * 4_097, "o" * 129, occurrence_id),)- embedded = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]["findings"]- paged = run_workbench(state_dir, "list-findings", "--scan-id", scan_id)["findingsPage"][- "findings"- ]+ embedded = get_scan(state_dir, scan_id)["scan"]["findings"]+ paged = scan_command(state_dir, "list-findings", scan_id)["findingsPage"]["findings"]assert embedded == pagedassert len(embedded) == 1finding = embedded[0]@@ -1091,7 +951,7 @@ def test_embedded_and_paged_findings_bound_large_stored_fields(tmp_path: Path) -connection.execute("UPDATE finding_locations SET role = NULL WHERE occurrence_id = ?", (occurrence_id,))- roleless = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)+ roleless = get_scan(state_dir, scan_id)assert roleless["scan"]["findings"][0]["locations"][0]["role"] is None@@ -1134,7 +994,7 @@ def test_embedded_and_paged_findings_normalize_scalar_attack_path_assessments(}findings_path.write_text(json.dumps(document))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert completed["findingCount"] == 22assert completed["findingsTruncated"] is Trueassert len(completed["findings"]) == 20@@ -1146,7 +1006,7 @@ def test_embedded_and_paged_findings_normalize_scalar_attack_path_assessments(assert returned_embedded_finding["attackPath"]["impact"] == {"level": "high"}assert returned_embedded_finding["attackPath"]["likelihood"] == {"level": "medium"}- refreshed = run_workbench(state_dir, "get-scan", "--scan-id", scan_id)["scan"]+ refreshed = get_scan(state_dir, scan_id)["scan"]refreshed_embedded_finding = next(findingfor finding in refreshed["findings"]@@ -1155,15 +1015,8 @@ def test_embedded_and_paged_findings_normalize_scalar_attack_path_assessments(assert refreshed_embedded_finding["attackPath"]["impact"] == {"level": "high"}assert refreshed_embedded_finding["attackPath"]["likelihood"] == {"level": "medium"}- second_page = run_workbench(- state_dir,- "list-findings",- "--scan-id",- scan_id,- "--offset",- "20",- "--limit",- "50",+ second_page = scan_command(+ state_dir, "list-findings", scan_id, "--offset", "20", "--limit", "50")["findingsPage"]assert second_page["offset"] == 20assert second_page["nextOffset"] is None@@ -1226,17 +1079,10 @@ def test_primary_location_prefers_root_control_in_bounded_and_csv_results(] + [{"path": "root.py", "startLine": 1, "role": "root_control"}]findings_path.write_text(json.dumps(document))- completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]+ completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]assert len(completed["findings"][0]["locations"]) == 8assert completed["findings"][0]["locations"][0]["path"] == "root.py"- exported = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "csv",- )["export"]+ exported = scan_command(state_dir, "export-findings", scan_id, "--format", "csv")["export"]with Path(exported["path"]).open(newline="") as source:row = next(csv.DictReader(source))assert row["path"] == "root.py"@@ -1297,19 +1143,11 @@ def test_csv_export_rejects_symlinked_exports_directory(tmp_path: Path) -> None:outside.mkdir()scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ scan_command(state_dir, "complete-scan", scan_id)(scan_dir / "exports" / "results.sarif").unlink()(scan_dir / "exports").rmdir()(scan_dir / "exports").symlink_to(outside, target_is_directory=True)- failed = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "csv",- check=False,- )+ failed = scan_command(state_dir, "export-findings", scan_id, "--format", "csv", check=False)assert "expected a regular directory inside the scan directory" in str(failed["stderr"])assert not (outside / "findings.csv").exists()@@ -1322,19 +1160,11 @@ def test_export_rejects_replaced_scan_directory(tmp_path: Path) -> None:outside.mkdir()scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ scan_command(state_dir, "complete-scan", scan_id)moved_scan_dir = scan_dir.with_name(f"{scan_dir.name}.moved")scan_dir.rename(moved_scan_dir)scan_dir.symlink_to(outside, target_is_directory=True)- failed = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "csv",- check=False,- )+ failed = scan_command(state_dir, "export-findings", scan_id, "--format", "csv", check=False)assert failed["returncode"] != 0assert not (outside / "exports" / "findings.csv").exists()@@ -1342,7 +1172,7 @@ def test_export_rejects_replaced_scan_directory(tmp_path: Path) -> None:def test_csv_export_rejects_replaced_scan_directory_ancestor(tmp_path: Path) -> None:state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)- run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)+ scan_command(state_dir, "complete-scan", scan_id)stored_parent = scan_dir.parentmoved_parent = stored_parent.with_name(f"{stored_parent.name}.moved")stored_parent.rename(moved_parent)@@ -1350,15 +1180,7 @@ def test_csv_export_rejects_replaced_scan_directory_ancestor(tmp_path: Path) ->shutil.copytree(moved_parent, replacement_parent)stored_parent.symlink_to(replacement_parent, target_is_directory=True)replacement_scan_dir = replacement_parent / scan_dir.name- failed = run_workbench(- state_dir,- "export-findings",- "--scan-id",- scan_id,- "--format",- "csv",- check=False,- )+ failed = scan_command(state_dir, "export-findings", scan_id, "--format", "csv", check=False)assert failed["returncode"] != 0assert not (replacement_scan_dir / "exports" / "findings.csv").exists()@@ -1369,7 +1191,7 @@ def test_completion_rejects_replaced_scan_directory(tmp_path: Path) -> None:moved_scan_dir = scan_dir.with_name(f"{scan_dir.name}.moved")scan_dir.rename(moved_scan_dir)scan_dir.symlink_to(moved_scan_dir, target_is_directory=True)- failed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id, check=False)+ failed = scan_command(state_dir, "complete-scan", scan_id, check=False)assert failed["returncode"] != 0assert not (moved_scan_dir / "exports" / "results.sarif").exists()@@ -1384,7 +1206,7 @@ def test_completion_rejects_replaced_scan_directory_ancestor(tmp_path: Path) ->shutil.copytree(moved_parent, replacement_parent)stored_parent.symlink_to(replacement_parent, target_is_directory=True)replacement_scan_dir = replacement_parent / scan_dir.name- failed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id, check=False)+ failed = scan_command(state_dir, "complete-scan", scan_id, check=False)assert failed["returncode"] != 0assert not (replacement_scan_dir / "exports" / "results.sarif").exists()@@ -1458,15 +1280,13 @@ def test_parent_draft_preserves_reconciled_candidate_identity_before_publicationraw = {"scanId": scan_id,"findings": [],- "coverage": {- "completeness": "partial",- "surfaces": [],- "explicitExclusions": [],- "deferred": [+ "coverage": saved_coverage(+ completeness="partial",+ deferred=[{key: value for key, value in row.items() if key != "id"}for row in documents["coverage"]["deferred"]],- },+ ),}drafts = scan_dir / "drafts"drafts.mkdir()