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(plugin): reuse workbench fixtures and focus native coverage (#1980)
Michael D'Angelo0334c87c71f7
diff --git a/plugins/codex-security/tests/test_workbench_archive.py b/plugins/codex-security/tests/test_workbench_archive.pyindex 60984a903..a053e4445 100644--- a/plugins/codex-security/tests/test_workbench_archive.py+++ b/plugins/codex-security/tests/test_workbench_archive.py@@ -259,20 +259,6 @@ def test_commit_failure_restores_archived_output(workflow_scan, monkeypatch):assert workflow(state) == saved_workflow-def test_legacy_caller_can_supply_already_archived_output(previous_scan):- state, target, output, scan_id = previous_scan- mark_stopped(state, scan_id)- archive = output.with_name("scan.previous-fixture")- output.rename(archive)- output.mkdir(mode=0o700)- registered = register(- state, target, output, "--archive-existing", "--archived-scan-dir", str(archive)- )- assert registered["archivedScanDir"] == str(archive)- assert (archive / "report.md").read_text() == "previous scan\n"- assert stored_paths(state, scan_id) == (str(archive), str(archive / "report.md"))--def test_registration_does_not_archive_an_ancestor_of_its_repository(tmp_path):state = tmp_path / "state"output = tmp_path / "output"diff --git a/plugins/codex-security/tests/test_workbench_cli.py b/plugins/codex-security/tests/test_workbench_cli.pyindex 33116caed..c68c5c25f 100644--- a/plugins/codex-security/tests/test_workbench_cli.py+++ b/plugins/codex-security/tests/test_workbench_cli.py@@ -116,7 +116,13 @@ def test_context_stdin_is_not_read_before_argument_parsing(stdin.buffer.read.assert_not_called()[email protected]("command", CONTEXT_COMMANDS, ids=lambda args: args[0])+# These two commands declare their option groups separately. All other commands+# use the shared workbench declaration exercised by the parser tests above.+ "command",+ [args for args in CONTEXT_COMMANDS if args[0] in {"create-workspace", "begin-deep-scan"}],+ ids=lambda args: args[0],+)@pytest.mark.parametrize("flags, payload, diagnostic",[diff --git a/plugins/codex-security/tests/test_workbench_completion_binding.py b/plugins/codex-security/tests/test_workbench_completion_binding.pyindex 960c06ff0..69b0cd909 100644--- a/plugins/codex-security/tests/test_workbench_completion_binding.py+++ b/plugins/codex-security/tests/test_workbench_completion_binding.py@@ -862,28 +862,6 @@ def test_completion_populates_workbench_owned_unsealed_envelope(assert sealed_coverage["excludePaths"] == []-def test_completion_keeps_invalid_prewrite_drafts_resumable(- tmp_path: Path,-) -> None:- state_dir, scan_id, scan_dir = _start_scan_with_draft_findings(tmp_path)- manifest = json.loads((scan_dir / "scan-manifest.json").read_text())- # The workbench binding never owns the remote, so this stays a draft error.- manifest["scan"]["target"]["remote"] = "not-a-url"- (scan_dir / "scan-manifest.json").write_text(json.dumps(manifest))-- failed = scan_command(state_dir, "complete-scan", scan_id, check=False)-- assert failed["returncode"] != 0- assert "target.remote" in str(failed["stderr"])- pending = get_scan(state_dir, scan_id)["scan"]- assert pending["progress"]["status"] == "running"- del manifest["scan"]["target"]["remote"]- (scan_dir / "scan-manifest.json").write_text(json.dumps(manifest))- completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]- assert completed["progress"]["status"] == "complete"- assert completed["findingCount"] == 1--@pytest.mark.parametrize("invalid_inventory", [None, "", "invalid_strategy", 42])def test_completion_keeps_recoverable_prewrite_failures_resumable(tmp_path: Path,@@ -926,9 +904,15 @@ def test_completion_keeps_empty_coverage_defaults(tmp_path: Path) -> None:assert coverage["inventoryStrategy"] == "repository"[email protected]("command", ["complete-scan", "prepare-scan-completion"])[email protected]("defect", ["target", "unicode"])[email protected]("existing_head", [False, True])+ ("command", "defect", "existing_head"),+ [+ ("complete-scan", "target", False),+ ("prepare-scan-completion", "unicode", False),+ ("prepare-scan-completion", "target", True),+ ("complete-scan", "unicode", True),+ ],+)def test_rejected_completion_restores_parent_head_before_corrected_retry(tmp_path: Path, workbench_api, command: str, defect: str, existing_head: bool) -> None:@@ -997,6 +981,7 @@ def test_rejected_completion_restores_parent_head_before_corrected_retry(assert failed["returncode"] != 0assert ("target.remote" if defect == "target" else "coverage") in failed["stderr"]+ assert get_scan(state_dir, scan_id)["scan"]["progress"]["status"] == "running"assert head_state() == previous_headassert {path.name: (path.read_bytes(), path.stat().st_mtime_ns)@@ -1305,87 +1290,72 @@ def test_completion_rejects_unknown_optional_root_cause_evidence_reference(def test_stopped_recovery_retains_strongest_duplicate_finding_regardless_of_order(tmp_path: Path,) -> None:- cases = (- (- "severity-ascending",- (("informational", "high", 1), ("critical", "high", 1)),- ("critical", "high", 1),- ),- (- "severity-descending",- (("critical", "high", 1), ("informational", "high", 1)),- ("critical", "high", 1),- ),- (- "confidence-ascending",- (("critical", "low", 1), ("critical", "high", 1)),- ("critical", "high", 1),- ),- (- "confidence-descending",- (("critical", "high", 1), ("critical", "low", 1)),- ("critical", "high", 1),- ),- (- "evidence-ascending",- (("critical", "high", 1), ("critical", "high", 2)),- ("critical", "high", 2),- ),- (- "evidence-descending",- (("critical", "high", 2), ("critical", "high", 1)),- ("critical", "high", 2),- ),- )- for case, candidates, expected in cases:- case_dir = tmp_path / case- case_dir.mkdir()- state_dir, scan_id, scan_dir = _start_scan_with_draft_findings(case_dir)- findings_path = scan_dir / "findings.json"- findings = json.loads(findings_path.read_text())- baseline = findings["findings"][0]- findings["findings"] = []- for severity, confidence, evidence_count in candidates:- finding = copy.deepcopy(baseline)- finding["severity"]["level"] = severity- finding["confidence"]["level"] = confidence- if evidence_count == 2:- evidence = copy.deepcopy(finding["codeEvidence"][0])- evidence["id"] = "additional-evidence"- finding["codeEvidence"].append(evidence)- findings["findings"].append(finding)- findings_path.write_text(json.dumps(findings))-- rejected = scan_command(state_dir, "complete-scan", scan_id, check=False)- assert rejected["returncode"] != 0- assert "duplicate occurrence identity" in rejected["stderr"]- assert json.loads(findings_path.read_text()) == findings- fail_scan(state_dir, scan_id, "Duplicate findings could not be resolved.")- completed = get_scan(state_dir, scan_id)-- assert completed["scan"]["progress"]["status"] == "failed", case- assert completed["scan"]["findingCount"] == 1, case- assert len(completed["scan"]["warnings"]) == 1, case- assert "duplicate logical finding" in completed["scan"]["warnings"][0], case- recovered = json.loads(findings_path.read_text())["findings"][0]- assert (- recovered["severity"]["level"],- recovered["confidence"]["level"],- len(recovered["codeEvidence"]),- ) == expected, case- weaker = next(candidate for candidate in candidates if candidate != expected)- assert any(- (- original["severity"]["level"],- original["confidence"]["level"],- len(original["codeEvidence"]),- )- == weaker- for original in recovered["provenance"].get("previousFindings", [])- ), case- assert "### No findings" not in (scan_dir / "report.md").read_text(), case- sarif = json.loads((scan_dir / "exports/results.sarif").read_text())- assert sarif["runs"][0]["results"][0]["properties"]["severity"] == "critical", case+ state_dir, scan_id, scan_dir = _start_scan_with_draft_findings(tmp_path)+ findings_path = scan_dir / "findings.json"+ findings = json.loads(findings_path.read_text())+ template = findings["findings"][0]+ findings["findings"] = []+ expected = {}+ for dimension, weak, strong in (+ ("severity", ("informational", "high", 1), ("critical", "high", 1)),+ ("confidence", ("critical", "low", 1), ("critical", "high", 1)),+ ("evidence", ("critical", "high", 1), ("critical", "high", 2)),+ ):+ for order, candidates in (("ascending", (weak, strong)), ("descending", (strong, weak))):+ anchor = f"{dimension}-{order}"+ expected[anchor] = (strong, weak)+ pair = []+ for severity, confidence, evidence_count in candidates:+ finding = copy.deepcopy(template)+ finding["identity"]["anchor"] = anchor+ finding["title"] = f"Archive extraction: {anchor}"+ finding["severity"]["level"] = severity+ finding["confidence"]["level"] = confidence+ if evidence_count == 2:+ evidence = copy.deepcopy(finding["codeEvidence"][0])+ evidence["id"] = "additional-evidence"+ finding["codeEvidence"].append(evidence)+ pair.append(finding)++ draft = {**findings, "findings": pair}+ findings_path.write_text(json.dumps(draft))+ rejected = scan_command(state_dir, "complete-scan", scan_id, check=False)+ assert rejected["returncode"] != 0, anchor+ assert "duplicate occurrence identity" in rejected["stderr"], anchor+ assert json.loads(findings_path.read_text()) == draft, anchor+ findings["findings"].extend(pair)++ findings_path.write_text(json.dumps(findings))+ fail_scan(state_dir, scan_id, "Duplicate findings could not be resolved.")+ stopped = get_scan(state_dir, scan_id)["scan"]++ assert stopped["progress"]["status"] == "failed"+ assert stopped["findingCount"] == len(expected)+ assert len(stopped["warnings"]) == len(expected)+ assert all("duplicate logical finding" in warning for warning in stopped["warnings"])++ def strength(finding):+ return (+ finding["severity"]["level"],+ finding["confidence"]["level"],+ len(finding["codeEvidence"]),+ )++ recovered = {+ row["identity"]["anchor"]: row for row in json.loads(findings_path.read_text())["findings"]+ }+ assert recovered.keys() == expected.keys()+ report = (scan_dir / "report.md").read_text()+ for anchor, (strong, weak) in expected.items():+ winner = recovered[anchor]+ assert strength(winner) == strong, anchor+ assert weak in [strength(row) for row in winner["provenance"]["previousFindings"]], anchor+ assert f"\n| [Archive extraction: {anchor}](#finding-" in report, anchor+ results = json.loads((scan_dir / "exports/results.sarif").read_text())["runs"][0]["results"]+ assert len(results) == len(expected)+ assert {(row["properties"]["findingId"], row["properties"]["severity"]) for row in results} == {+ (winner["findingId"], "critical") for winner in recovered.values()+ }def test_stopped_recovery_preserves_findings_with_invalid_or_duplicate_writeups(diff --git a/plugins/codex-security/tests/test_workbench_db.py b/plugins/codex-security/tests/test_workbench_db.pyindex 0582c1a35..729b4013d 100644--- a/plugins/codex-security/tests/test_workbench_db.py+++ b/plugins/codex-security/tests/test_workbench_db.py@@ -234,6 +234,7 @@ def test_cost_limit_rejects_invalid_or_nonincreasing_totals(tmp_path: Path, limi+ "Synthetic diagnostic detail.\n" * 100+ "Final cost-limit diagnostic.",],+ ids=["short-diagnostic", "long-diagnostic"],)def test_budget_exhaustion_preserves_unvalidated_discovery_as_deferred_work(tmp_path: Path,@@ -981,19 +982,56 @@ def test_completed_findings_are_summarized_and_sorted_by_severity(tmp_path: Path][email protected]("line_ending", ["\n", "\r\n"], ids=["lf", "crlf"])[email protected]("patch_name", ["remediation.patch", " remediation.patch"])-def test_completed_finding_triage_and_remediation_persist(- tmp_path: Path, monkeypatch: pytest.MonkeyPatch, line_ending: str, patch_name: str-) -> None:+def git_autocrlf(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setenv("GIT_CONFIG_COUNT", "1")monkeypatch.setenv("GIT_CONFIG_KEY_0", "core.autocrlf")monkeypatch.setenv("GIT_CONFIG_VALUE_0", "true")++[email protected]("line_ending", [b"\n", b"\r\n"], ids=["lf", "crlf"])+ "patch_name", ["remediation.patch", " remediation.patch"], ids=["plain", "leading-space"]+)+def test_reviewed_patch_matches_unversioned_checkout_bytes(+ workbench_api, tmp_path: Path, git_autocrlf, line_ending: bytes, patch_name: str+) -> None:+ target = tmp_path / "target"+ target.mkdir()+ source = target / "source.txt"+ source.write_bytes(b"vulnerable" + line_ending)+ scan_dir = tmp_path / "scan"+ scan_dir.mkdir(mode=0o700)+ revision, original, _device, inode = workbench_api["scan_target_identity"](target, None)+ assert revision == "unversioned"+ scan = {+ "target_path": str(target),+ "target_inode": inode,+ "target_revision": revision,+ "scan_dir": str(scan_dir),+ }+ patch = scan_dir / patch_name+ write_remediation_patch(patch, newline="\n")+ if patch_name.startswith(" "):+ (scan_dir / patch_name.strip()).write_text("different patch contents\n")+ remediation = {+ "base_revision": revision,+ "base_content_digest": original,+ "patch_digest": f"sha256:{hashlib.sha256(patch.read_bytes()).hexdigest()}",+ }+ assert workbench_api["require_scan_relative_file"](scan, patch_name) == patch_name+ subprocess.run(["git", "apply", "--no-index", str(patch)], cwd=target, check=True)+ _, applied = workbench_api["remediation_checkout_snapshot"](scan)+ assert applied != original+ assert workbench_api["require_reviewed_patch_applied"](scan, remediation, patch_name) == applied+++def test_completed_finding_triage_and_remediation_persist(tmp_path: Path, git_autocrlf) -> None:state_dir = tmp_path / "state"target = tmp_path / "target"target.mkdir()source = target / "source.txt"- source.write_bytes(f"vulnerable{line_ending}".encode())+ source.write_bytes(b"vulnerable\r\n")scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target, relative_path=source.name)completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]@@ -1055,10 +1093,10 @@ def test_completed_finding_triage_and_remediation_persist(state_dir, occurrence_id, "closed", "--close-reason", "already_fixed", check=False)assert "pending remediation operation" in str(pending_close["stderr"])+ patch_name = " remediation.patch"patch_path = scan_dir / patch_namewrite_remediation_patch(patch_path, newline="\n")- if patch_name.startswith(" "):- (scan_dir / patch_name.strip()).write_text("different patch contents\n")+ (scan_dir / patch_name.strip()).write_text("different patch contents\n")generated = set_remediation(state_dir,occurrence_id,@@ -2036,7 +2074,7 @@ def test_workbench_roundtrips_literal_target_and_scope(tmp_path: Path, scope: stassert scan["contract"]["scope"]["requiredIncludePaths"] == [scope][email protected]("blank", ["", " \t\n", " " * 5000])[email protected]("blank", ["", " \t\n", " " * 5000], ids=["empty", "mixed", "long"])def test_workbench_keeps_blank_workspace_path_defaults(tmp_path: Path, blank: str) -> None:state_dir = tmp_path / "state"workspace_id = str(uuid.uuid4())diff --git a/plugins/codex-security/tests/test_workbench_db_exports.py b/plugins/codex-security/tests/test_workbench_db_exports.pyindex dda92c487..353d08499 100644--- a/plugins/codex-security/tests/test_workbench_db_exports.py+++ b/plugins/codex-security/tests/test_workbench_db_exports.py@@ -434,10 +434,11 @@ def test_incomplete_parent_checkpoint_cannot_complete_scan(tmp_path: Path) -> Noassert get_scan(state_dir, scan_id)["scan"]["progress"]["status"] == "running"[email protected]("termination", ["fail-scan", "cancel-scan"])[email protected]("projection_failure_at", [None, "stop", "refresh"])+ ("termination", "projection_failure_at"), [("fail-scan", "stop"), ("cancel-scan", "refresh")]+)def test_model_only_draft_is_available_before_findings_and_survives_stop(- tmp_path: Path, termination: str, projection_failure_at: str | None+ tmp_path: Path, termination: str, projection_failure_at: str) -> None:state_dir = tmp_path / "state"target = tmp_path / "target"@@ -504,25 +505,21 @@ def test_model_only_draft_is_available_before_findings_and_survives_stop(assert json.loads((scan_dir / "scan-manifest.json").read_text())["scan"]["threatModel"] == modelassert stopped["threatModelProvenance"]["provisional"] is Trueassert stopped["findingCount"] == 0- if projection_failure_at != "stop":- assert document.read_text().startswith(model["content"])sealed = (scan_dir / "scan-manifest.json").read_bytes()if projection_failure_at == "refresh":+ assert stopped["warnings"] == []+ assert document.read_text().startswith(model["content"])document.unlink()document.mkdir()stopped = scan_command(state_dir, "preserve-scan-results", scan_id)["scan"]- if projection_failure_at is not None:- warnings = stopped["warnings"]- assert len(warnings) == 1- assert warnings[0].startswith("Automatic threat model save failed:")- assert "threatModelPath" not in stopped- assert "threatModel" not in stopped["artifacts"]- assert get_scan(state_dir, scan_id)["scan"]["warnings"] == warnings- assert (- scan_command(state_dir, "preserve-scan-results", scan_id)["scan"]["warnings"]- == warnings- )- assert (scan_dir / "scan-manifest.json").read_bytes() == sealed+ warnings = stopped["warnings"]+ assert len(warnings) == 1+ assert warnings[0].startswith("Automatic threat model save failed:")+ assert "threatModelPath" not in stopped+ assert "threatModel" not in stopped["artifacts"]+ assert get_scan(state_dir, scan_id)["scan"]["warnings"] == warnings+ assert scan_command(state_dir, "preserve-scan-results", scan_id)["scan"]["warnings"] == warnings+ assert (scan_dir / "scan-manifest.json").read_bytes() == sealed@pytest.mark.parametrize("changed_file", ["scan-manifest.json", "findings.json"])@@ -735,21 +732,9 @@ def test_completed_findings_export_inside_scan_directory(tmp_path: Path) -> Noneassert "sealed artifact changed" in str(tampered_json["stderr"])- ("extensions", "expected_candidate_id"),- (- ({"candidateId": "DSS-145", "reportId": "DSS-145-rogue"}, "DSS-145"),- ({"candidateId": " ", "reportId": "DSS-145"}, "DSS-145"),- ({"reportId": "DSS-145", "ledgerRowId": "DSS-145-rogue"}, "DSS-145"),- ({"ledgerRowId": "DSS-145"}, "DSS-145"),- ),- ids=("candidate-id", "blank-candidate-id", "report-id", "ledger-row-id"),-)@pytest.mark.parametrize("replace_after_finalize", (False, True), ids=("saved", "replaced"))def test_deep_csv_export_adds_only_candidate_id_column(tmp_path: Path,- extensions: dict[str, str],- expected_candidate_id: str,replace_after_finalize: bool,monkeypatch: pytest.MonkeyPatch,workbench_api,@@ -776,16 +761,29 @@ def test_deep_csv_export_adds_only_candidate_id_column()findings_path = scan_dir / "findings.json"findings_document = json.loads(findings_path.read_text())- finding = findings_document["findings"][0]- original_title = "Unsafe archive extraction [DSS-145-rogue]"- finding["title"] = original_title- finding["extensions"] = extensions+ template = findings_document["findings"][0]+ cases = (+ ("candidate", {"candidateId": "DSS-145", "reportId": "DSS-999"}, "DSS-145"),+ ("blank", {"candidateId": " ", "reportId": "DSS-146"}, "DSS-146"),+ ("report", {"reportId": "DSS-147", "ledgerRowId": "DSS-999"}, "DSS-147"),+ ("ledger", {"ledgerRowId": "DSS-148"}, "DSS-148"),+ )+ findings_document["findings"] = [+ {+ **template,+ "identity": {"anchor": name},+ "title": f"{name} extraction [DSS-999]",+ "extensions": extensions,+ }+ for name, extensions, _ in cases+ ]findings_path.write_text(json.dumps(findings_document))completed = scan_command(state_dir, "complete-scan", scan_id)["scan"]+ closed_occurrence = completed["findings"][0]["occurrenceId"]set_triage(state_dir,- completed["findings"][0]["occurrenceId"],+ closed_occurrence,"closed","--close-reason","wont_fix",@@ -799,8 +797,9 @@ def test_deep_csv_export_adds_only_candidate_id_column(def replace_finalized_document(*args, **kwargs):result = finalize(*args, **kwargs)replacement = copy.deepcopy(result[1])- replacement["findings"][0]["extensions"] = {"candidateId": "DSS-replaced"}- replacement["findings"][0]["title"] = "Replaced title"+ for finding in replacement["findings"]:+ finding["extensions"] = {"candidateId": "DSS-replaced"}+ finding["title"] = "Replaced title"findings_path.write_text(json.dumps(replacement))return result@@ -834,13 +833,14 @@ def test_deep_csv_export_adds_only_candidate_id_column("start_line","end_line",]- assert len(rows) == 1- assert rows[0]["candidate_id"] == expected_candidate_id- assert rows[0]["title"] == original_title- assert rows[0]["status"] == "closed"- assert rows[0]["close_reason"] == "wont_fix"- assert "report_id" not in rows[0]- assert "detailed_writeup" not in rows[0]+ assert len(rows) == len(cases)+ assert {row["title"]: row["candidate_id"] for row in rows} == {+ f"{name} extraction [DSS-999]": candidate_id for name, _, candidate_id in cases+ }+ closed_rows = {+ row["occurrence_id"]: row["close_reason"] for row in rows if row["status"] == "closed"+ }+ assert closed_rows == {closed_occurrence: "wont_fix"}def test_csv_export_escapes_newline_and_full_width_formula_prefixes(tmp_path: Path) -> None:diff --git a/plugins/codex-security/tests/test_workbench_diagnostics.py b/plugins/codex-security/tests/test_workbench_diagnostics.pyindex 89d0f7af7..8731c364c 100644--- a/plugins/codex-security/tests/test_workbench_diagnostics.py+++ b/plugins/codex-security/tests/test_workbench_diagnostics.py@@ -40,7 +40,7 @@ def deep_scan(tmp_path: Path):return state_dir, str(started["scanId"]), Path(str(started["scanDir"])), environment[email protected]("message", [LONG_ERROR, LEGACY_ERROR])[email protected]("message", [LONG_ERROR, LEGACY_ERROR], ids=["long", "legacy-truncated"])def test_scan_failure_keeps_complete_diagnostic_and_existing_terminal_value(tmp_path: Path, message: str) -> None:@@ -66,7 +66,7 @@ def test_scan_failure_keeps_complete_diagnostic_and_existing_terminal_value(@pytest.mark.parametrize("status", ["failed", "canceled"])[email protected]("message", [LONG_ERROR, LEGACY_ERROR])[email protected]("message", [LONG_ERROR, LEGACY_ERROR], ids=["long", "legacy-truncated"])def test_worker_failure_keeps_complete_diagnostic_and_exact_terminal_replay(deep_scan, status: str, message: str) -> None:@@ -106,7 +106,7 @@ def test_worker_failure_keeps_complete_diagnostic_and_exact_terminal_replay(assert "terminal state is immutable" in rejected["stderr"][email protected]("message", [LONG_ERROR, LEGACY_ERROR])[email protected]("message", [LONG_ERROR, LEGACY_ERROR], ids=["long", "legacy-truncated"])def test_deep_failure_keeps_complete_diagnostic_and_existing_terminal_value(deep_scan, message: str) -> None:diff --git a/plugins/codex-security/tests/test_workbench_native_indexes.py b/plugins/codex-security/tests/test_workbench_native_indexes.pyindex 78ad8ed53..db44cb46a 100644--- a/plugins/codex-security/tests/test_workbench_native_indexes.py+++ b/plugins/codex-security/tests/test_workbench_native_indexes.py@@ -84,52 +84,16 @@ def test_later_scans_preserve_global_findings_and_repository_counts(include_paths=include_paths,)- findings = run_workbench(state_dir, "list-global-findings")["findings"]- assert len(findings) == 1- assert findings[0]["scanId"] == original["scanId"]- assert findings[0]["status"] == "open"+ page = run_workbench(state_dir, "list-global-findings", "--limit", "1")+ assert page["nextOffset"] is None+ (finding,) = page["findings"]+ assert finding["scanId"] == original["scanId"]+ assert finding["status"] == "open"assert (run_workbench(state_dir, "list-repositories")["repositories"][0]["openFindingsCount"] == 1)-def test_global_findings_apply_pagination_to_historical_findings(- tmp_path: Path,-) -> None:- state_dir = tmp_path / "state"- historical_target = tmp_path / "historical-repo"- first_active_target = tmp_path / "first-active-repo"- second_active_target = tmp_path / "second-active-repo"- for target in (historical_target, first_active_target, second_active_target):- target.mkdir()-- historical = complete_scan(state_dir, historical_target, identity_anchor="historical-finding")- complete_scan(state_dir, historical_target, identity_anchor="clean-scan", finding=False)- first_active = complete_scan(- state_dir, first_active_target, identity_anchor="first-active-finding"- )- second_active = complete_scan(- state_dir, second_active_target, identity_anchor="second-active-finding"- )-- first_page = run_workbench(state_dir, "list-global-findings", "--limit", "1")- second_page = run_workbench(state_dir, "list-global-findings", "--limit", "1", "--offset", "1")- third_page = run_workbench(state_dir, "list-global-findings", "--limit", "1", "--offset", "2")-- assert first_page["nextOffset"] == 1- assert second_page["nextOffset"] == 2- assert third_page["nextOffset"] is None- assert {- first_page["findings"][0]["scanId"],- second_page["findings"][0]["scanId"],- third_page["findings"][0]["scanId"],- } == {- historical["scanId"],- first_active["scanId"],- second_active["scanId"],- }--def test_global_findings_keep_latest_occurrence_and_stable_target_identity(tmp_path: Path) -> None:state_dir = tmp_path / "state"first_target = tmp_path / "first-repo"@@ -189,13 +153,17 @@ def test_global_findings_keep_latest_occurrence_and_stable_target_identity(tmp_p(distinct_first_occurrence,),).fetchone()[0]- first_page = run_workbench(state_dir, "list-global-findings", "--limit", "1")- second_page = run_workbench(state_dir, "list-global-findings", "--offset", "1", "--limit", "20")- assert first_page["limit"] == 1- assert first_page["nextOffset"] == 1- assert first_page["offset"] == 0- assert second_page["nextOffset"] is None- findings = first_page["findings"] + second_page["findings"]+ pages = [+ run_workbench(state_dir, "list-global-findings", "--limit", "1", "--offset", str(offset))+ for offset in range(3)+ ]+ assert [(page["offset"], page["limit"], page["nextOffset"]) for page in pages] == [+ (0, 1, 1),+ (1, 1, 2),+ (2, 1, None),+ ]+ assert all(len(page["findings"]) == 1 for page in pages)+ findings = [page["findings"][0] for page in pages]findings_by_identity = {(finding["targetId"], finding["findingId"]): finding for finding in findings}@@ -207,7 +175,6 @@ def test_global_findings_keep_latest_occurrence_and_stable_target_identity(tmp_p(second_target_id, str(latest_second["findings"][0]["findingId"]))]- assert len(findings) == 3assert first["scanId"] == latest_first["scanId"]assert first["occurrenceId"] == latest_first_occurrenceassert first["occurrenceCount"] == 2@@ -272,51 +239,28 @@ def test_repository_index_reports_latest_scan_open_findings_and_missing_checkoutassert second["scanCount"] == 1-def test_overlapping_scans_mark_findings_present_in_latest_started_scan(tmp_path: Path) -> None:- state_dir = tmp_path / "state"- target = tmp_path / "repo"- target.mkdir()- first = complete_scan(state_dir, target, identity_anchor="recurring-finding")- second = complete_scan(state_dir, target, identity_anchor="recurring-finding")- with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:- connection.execute(- "UPDATE scans SET started_at = ? WHERE id = ?",- ("2026-01-01T00:00:00Z", first["scanId"]),- )- connection.execute(- "UPDATE scans SET started_at = ? WHERE id = ?",- ("2026-01-02T00:00:00Z", second["scanId"]),- )- connection.execute(- "UPDATE finding_occurrences SET created_at = ? WHERE scan_id = ?",- ("2026-01-04T00:00:00Z", first["scanId"]),- )- connection.execute(- "UPDATE finding_occurrences SET created_at = ? WHERE scan_id = ?",- ("2026-01-03T00:00:00Z", second["scanId"]),- )- finding = run_workbench(state_dir, "list-global-findings")["findings"][0]- assert finding["confirmedInLatestScan"] is True- assert set(finding["knownScanIds"]) == {first["scanId"], second["scanId"]}--[email protected]("query", ["strasse", "STRAẞE", "éclair", "ÉCLAIR"])-def test_scan_and_finding_search_casefold_unicode(tmp_path: Path, query: str) -> None:+def test_scan_and_finding_search_casefold_unicode(tmp_path: Path) -> None:state_dir = tmp_path / "state"target = tmp_path / "Straße ÉCLAIR"target.mkdir()first = complete_scan(state_dir, target, identity_anchor="first-finding")- complete_scan(state_dir, target, identity_anchor="second-finding")+ second = complete_scan(state_dir, target, identity_anchor="second-finding")with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.execute("UPDATE finding_occurrences SET title = ?", ("Straße ÉCLAIR",))- page = run_workbench(state_dir, "list-scans", "--query", query, "--limit", "1")- assert len(page["scans"]) == 1- assert page["nextOffset"] == 1- next_page = run_workbench(- state_dir, "list-scans", "--query", query, "--limit", "1", "--offset", "1"- )- assert len(next_page["scans"]) == 1- findings = run_workbench(- state_dir, "list-findings", "--scan-id", str(first["scanId"]), "--query", query- )- assert len(findings["findingsPage"]["findings"]) == 1+ for query in ("strasse", "STRAẞE", "éclair", "ÉCLAIR"):+ page = run_workbench(state_dir, "list-scans", "--query", query, "--limit", "1")+ assert page["nextOffset"] == 1, query+ next_page = run_workbench(+ state_dir, "list-scans", "--query", query, "--limit", "1", "--offset", "1"+ )+ assert next_page["nextOffset"] is None, query+ (first_match,) = page["scans"]+ (second_match,) = next_page["scans"]+ assert {first_match["scanId"], second_match["scanId"]} == {+ first["scanId"],+ second["scanId"],+ }, query+ findings = run_workbench(+ state_dir, "list-findings", "--scan-id", str(first["scanId"]), "--query", query+ )+ assert len(findings["findingsPage"]["findings"]) == 1, querydiff --git a/plugins/codex-security/tests/test_workbench_progress.py b/plugins/codex-security/tests/test_workbench_progress.pyindex 9970117b5..56281fa46 100644--- a/plugins/codex-security/tests/test_workbench_progress.py+++ b/plugins/codex-security/tests/test_workbench_progress.py@@ -17,24 +17,7 @@ def test_usage_list_coverage_is_invalid(workbench_api):)-def test_validation_clears_discovery_finding_count(tmp_path: Path) -> None:- state_dir = tmp_path / "state"- target = tmp_path / "target"- target.mkdir()- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(state_dir, "--workspace-id", str(saved["id"]))- scan_id = str(started["results"]["scanId"])-- discovery = update_progress(- state_dir, scan_id, "--phase", "discovery", "--reportable-findings-count", "8"- )- assert discovery["scan"]["progress"]["candidates"] == {"reportable": 8}-- validation = update_progress(state_dir, scan_id, "--phase", "validation")- assert validation["scan"]["progress"]["candidates"] == {"reportable": 0}---def test_phase_progress_tracks_and_resets_phase_specific_receipts(tmp_path: Path) -> None:+def test_progress_preserves_phase_receipts_until_validation(tmp_path: Path) -> None:state_dir = tmp_path / "state"target = tmp_path / "target"target.mkdir()@@ -47,6 +30,8 @@ def test_phase_progress_tracks_and_resets_phase_specific_receipts(tmp_path: Pathscan_id,"--phase","discovery",+ "--reportable-findings-count",+ "8","--phase-items-total","6","--phase-items-completed",@@ -54,13 +39,19 @@ def test_phase_progress_tracks_and_resets_phase_specific_receipts(tmp_path: Path"--phase-progress-unit","review_receipts",)+ assert discovery["scan"]["progress"]["candidates"] == {"reportable": 8}assert discovery["scan"]["progress"]["phaseProgress"] == {"completed": 2,"total": 6,"unit": "review_receipts",}+ regressed = update_progress(state_dir, scan_id, "--phase-items-completed", "1", check=False)+ assert regressed["returncode"] != 0+ assert "Completed phase items cannot decrease" in str(regressed["stderr"])+validation = update_progress(state_dir, scan_id, "--phase", "validation")+ assert validation["scan"]["progress"]["candidates"] == {"reportable": 0}assert validation["scan"]["progress"]["phaseProgress"] == {"completed": 0,"total": 0,@@ -84,29 +75,6 @@ def test_phase_progress_tracks_and_resets_phase_specific_receipts(tmp_path: Path}-def test_phase_progress_rejects_regression_within_one_phase(tmp_path: Path) -> None:- state_dir = tmp_path / "state"- target = tmp_path / "target"- target.mkdir()- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(state_dir, "--workspace-id", str(saved["id"]))- scan_id = str(started["results"]["scanId"])- update_progress(- state_dir,- scan_id,- "--phase-items-total",- "3",- "--phase-items-completed",- "2",- "--phase-progress-unit",- "checks",- )-- regressed = update_progress(state_dir, scan_id, "--phase-items-completed", "1", check=False)- assert regressed["returncode"] != 0- assert "Completed phase items cannot decrease" in str(regressed["stderr"])--def test_historical_preflight_issues_survive_progress_updates(tmp_path: Path) -> None:state_dir = tmp_path / "state"target = tmp_path / "target"diff --git a/plugins/codex-security/tests/test_workbench_prompt_only_scan.py b/plugins/codex-security/tests/test_workbench_prompt_only_scan.pyindex 6b49cdf3b..d25f5eb59 100644--- a/plugins/codex-security/tests/test_workbench_prompt_only_scan.py+++ b/plugins/codex-security/tests/test_workbench_prompt_only_scan.py@@ -102,10 +102,18 @@ def test_headless_standard_scan_starts_without_setup_opt_out(tmp_path: Path) ->target.mkdir()(target / "fixture.py").write_text("print('fixture')\n")- started = start_headless_standard_scan(state_dir, target, tmp_path / "scans")+ user_context = (+ "Repository: https://github.com/example/security-review\n"+ "OAuth issuer: https://accounts.example.test"+ )+ started = start_headless_standard_scan(+ state_dir, target, tmp_path / "scans", user_context=user_context+ )scan = started["scan"]workspace = started["workspace"]assert started["startDisposition"] == "created"+ assert scan["userContext"] == user_context+ assert workspace["userContext"] == user_contextassert scan["mode"] == "standard"assert scan["progress"]["status"] == "running"assert scan["progress"]["phase"] == "preflight"@@ -116,27 +124,6 @@ def test_headless_standard_scan_starts_without_setup_opt_out(tmp_path: Path) ->assert workspace["results"]["scanId"] == scan["scanId"]-def test_headless_standard_scan_preserves_url_user_context(tmp_path: Path) -> None:- state_dir = tmp_path / "state"- target = tmp_path / "target"- target.mkdir()- (target / "fixture.py").write_text("print('fixture')\n")- user_context = (- "Repository: https://github.com/example/security-review\n"- "OAuth issuer: https://accounts.example.test"- )-- started = start_headless_standard_scan(- state_dir,- target,- tmp_path / "scans",- user_context=user_context,- )-- assert started["scan"]["userContext"] == user_context- assert started["workspace"]["userContext"] == user_context--def test_headless_standard_scan_joins_only_the_owning_thread(tmp_path: Path) -> None:state_dir = tmp_path / "state"target = tmp_path / "target"@@ -178,17 +165,6 @@ def test_headless_standard_scan_serializes_concurrent_starts(tmp_path: Path) ->assert len({result["scan"]["scanId"] for result in results}) == 1-def test_prompt_only_scan_starts_without_persisted_opt_out(- tmp_path: Path,-) -> None:- state_dir = tmp_path / "state"- target = tmp_path / "target"- target.mkdir()- scan_root = tmp_path / "scans"- started = start_prompt_only_scan(state_dir, target, scan_root)- assert started["startDisposition"] == "created"--def test_prompt_only_scan_creates_submitted_delivered_scan(tmp_path: Path,) -> None:diff --git a/plugins/codex-security/tests/test_workbench_scan_archive.py b/plugins/codex-security/tests/test_workbench_scan_archive.pyindex 059cb4619..b4c8822f7 100644--- a/plugins/codex-security/tests/test_workbench_scan_archive.py+++ b/plugins/codex-security/tests/test_workbench_scan_archive.py@@ -74,6 +74,8 @@ def test_archived_output_preserves_old_scan_and_allows_fresh_registration(assert current["scanId"] != previous["scanId"]assert current["scanDir"] == str(scan_dir)+ assert current["archivedScanDir"] == str(archived_scan_dir)+ assert (archived_scan_dir / "report.md").read_text() == "# Previous scan\n"assert (archived_scan_dir / "previous.txt").read_text() == "keep the previous scan\n"with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:assert connection.execute(diff --git a/plugins/codex-security/tests/test_workbench_scan_history.py b/plugins/codex-security/tests/test_workbench_scan_history.pyindex a577db980..688fe0975 100644--- a/plugins/codex-security/tests/test_workbench_scan_history.py+++ b/plugins/codex-security/tests/test_workbench_scan_history.py@@ -9,6 +9,7 @@ import subprocessimport sysimport uuidfrom argparse import Namespace+from contextlib import closingfrom pathlib import Pathfrom typing import Any@@ -964,6 +965,53 @@ def test_cli_scan_comparison_tracks_stable_findings_without_copying_triage(tmp_passert connection.execute("SELECT COUNT(*) FROM finding_occurrences").fetchone() == (2,)+def create_ordered_history(root: Path, anchors: tuple[str, ...]):+ repository = root / "repository"+ repository.mkdir()+ state_dir = root / "state"+ scans = sorted(+ (+ create_cli_scan(state_dir, root / "results", repository, identity_anchor=anchor)+ for anchor in anchors+ ),+ key=lambda scan: scan["scanId"],+ )+ return state_dir / "workbench.sqlite3", repository, scans++[email protected](scope="module")+def recurring_history(tmp_path_factory: pytest.TempPathFactory):+ return create_ordered_history(tmp_path_factory.mktemp("recurring-scans"), ("recurring",) * 2)++[email protected](scope="module")+def matched_history(tmp_path_factory: pytest.TempPathFactory):+ database, _repository, scans = create_ordered_history(+ tmp_path_factory.mktemp("matched-scans"), tuple(f"synthetic-{index}" for index in range(4))+ )+ findings = [get_scan(database.parent, scan["scanId"])["scan"]["findings"][0] for scan in scans]+ for left, right in ((0, 1), (1, 3)):+ save_scan_matches(+ database.parent,+ scans[left],+ scans[right],+ confirmed_match(findings[left]["occurrenceId"], findings[right]["occurrenceId"]),+ )+ return database, scans, [sorted(finding["findingId"] for finding in findings[:2])]+++def copy_history_state(database: Path, tmp_path: Path) -> Path:+ # Each case changes its own timestamps or matches. The sealed scan directories are read-only.+ state_dir = tmp_path / "state"+ state_dir.mkdir()+ with (+ closing(sqlite3.connect(database)) as source,+ closing(sqlite3.connect(state_dir / "workbench.sqlite3")) as destination,+ ):+ source.backup(destination)+ return state_dir++@pytest.mark.parametrize(("timestamps", "expected_order"),[@@ -974,15 +1022,10 @@ def test_cli_scan_comparison_tracks_stable_findings_without_copying_triage(tmp_pids=["mixed-offsets", "microseconds", "equal-instants"],)def test_finding_occurrence_history_uses_start_instants(- tmp_path: Path, timestamps: tuple[str, str], expected_order: tuple[int, int]+ tmp_path: Path, recurring_history, timestamps: tuple[str, str], expected_order: tuple[int, int]) -> None:- state_dir = tmp_path / "state"- repository = tmp_path / "repository"- repository.mkdir()- scans = sorted(- (create_cli_scan(state_dir, tmp_path / "results", repository) for _ in range(2)),- key=lambda scan: scan["scanId"],- )+ database, _repository, scans = recurring_history+ state_dir = copy_history_state(database, tmp_path)with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.executemany("UPDATE scans SET started_at = ? WHERE id = ?",@@ -1091,15 +1134,10 @@ def test_list_unmatched_scan_pairs_groups_pending_pairs_and_skips_saved_results(],)def test_automatic_matching_orders_instants_and_preserves_directed_cache(- tmp_path: Path, before_started: str, after_started: str+ tmp_path: Path, recurring_history, before_started: str, after_started: str) -> None:- state_dir = tmp_path / "state"- repository = tmp_path / "repository"- repository.mkdir()- before, after = sorted(- (create_cli_scan(state_dir, tmp_path / "results", repository) for _ in range(2)),- key=lambda scan: scan["scanId"],- )+ database, repository, (before, after) = recurring_history+ state_dir = copy_history_state(database, tmp_path)with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.executemany("UPDATE scans SET started_at = ? WHERE id = ?",@@ -1337,37 +1375,17 @@ def test_semantic_scan_comparison_caches_matches_and_exposes_related_findings(ids=["offsets", "microseconds", "equal-instants"],)def test_explicit_comparison_uses_chronological_matching_cutoff(- tmp_path: Path, monkeypatch: pytest.MonkeyPatch, timestamps: tuple[str, ...]+ tmp_path: Path, matched_history, monkeypatch: pytest.MonkeyPatch, timestamps: tuple[str, ...]) -> None:- state_dir = tmp_path / "state"- repository = tmp_path / "repository"- repository.mkdir()- scans = sorted(- (- create_cli_scan(- state_dir, tmp_path / "scans", repository, identity_anchor=f"synthetic-{index}"- )- for index in range(4)- ),- key=lambda scan: scan["scanId"],- )+ database, scans, expected = matched_history+ state_dir = copy_history_state(database, tmp_path)middle, after, future = scans[1:]- findings = [get_scan(state_dir, scan["scanId"])["scan"]["findings"][0] for scan in scans]- for left, right in ((0, 1), (1, 3)):- save_scan_matches(- state_dir,- scans[left],- scans[right],- confirmed_match(findings[left]["occurrenceId"], findings[right]["occurrenceId"]),- )with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.executemany("UPDATE scans SET started_at = ? WHERE id = ?",[(timestamp, scan["scanId"]) for timestamp, scan in zip(timestamps, scans)],)original = list(connection.iterdump())- expected = [sorted(finding["findingId"] for finding in findings[:2])]-for before_scan, after_scan in ((middle, after), (after, middle)):compared = compare_scan_pair(state_dir, before_scan, after_scan, "--include-matching-inputs"diff --git a/plugins/codex-security/tests/test_workbench_scan_usage.py b/plugins/codex-security/tests/test_workbench_scan_usage.pyindex b81a900a6..d9960d7c9 100644--- a/plugins/codex-security/tests/test_workbench_scan_usage.py+++ b/plugins/codex-security/tests/test_workbench_scan_usage.py@@ -26,8 +26,6 @@ from workbench_test_support import (write_completed_contract,)-pytestmark = pytest.mark.native_macos-@dataclass(frozen=True)class ScanFixture:@@ -723,6 +721,7 @@ def test_native_usage_preserves_partial_measurement_warnings(tmp_path: Path, fai}[email protected]_macos@pytest.mark.parametrize("mode", ["standard", "diff"])def test_completion_counts_only_scan_owned_parent_and_descendants(tmp_path: Path,@@ -755,8 +754,11 @@ def test_completion_counts_only_scan_owned_parent_and_descendants(parent_thread_id="scan-worker",)unrelated = _rollout(tmp_path, "unrelated", [_token_event(counted, 80_000, 20_000)])+ # The completion subprocess must open the spaced CODEX_HOME through its SQLite URI.+ fixture.environment["CODEX_HOME"] = str(tmp_path / "native home")+ fixture.environment["CODEX_SQLITE_HOME"] = ""_state_graph(- fixture.environment,+ {"CODEX_SQLITE_HOME": fixture.environment["CODEX_HOME"]},{"scan-parent": parent,"scan-worker": worker,@@ -1058,22 +1060,25 @@ def test_completion_marks_unverifiable_workers_partial(assert usage["totalTokens"] == 16[email protected]_platform@pytest.mark.parametrize("home_variable", ["CODEX_HOME", "CODEX_SQLITE_HOME"])@pytest.mark.parametrize("home_kind", ["absolute", "literal_tilde", "relative_home", "home"])-def test_completion_reads_usage_from_literal_home(- tmp_path: Path, home_variable: str, home_kind: str, monkeypatch: pytest.MonkeyPatch+def test_usage_finds_state_database_in_configured_home(+ tmp_path: Path,+ home_variable: str,+ home_kind: str,+ monkeypatch: pytest.MonkeyPatch,+ workbench_api,) -> None:- fixture = _start_scan(tmp_path)home = tmp_path / ("native home" if sys.platform == "win32" else "native home ")if home_kind == "literal_tilde":home = tmp_path / ("~ literal" if sys.platform == "win32" else "~ ")- fixture.environment["CODEX_SQLITE_HOME"] = str(home)- parent = _rollout(- tmp_path,- "scan-parent",- [_token_event(fixture.started_at + timedelta(microseconds=1), 12, 3)],- )- _state_graph(fixture.environment, {"scan-parent": parent}, [])+ home.mkdir()+ database = home / "state_5.sqlite"+ database.touch()+ monkeypatch.setenv("CODEX_STATE_DB", "")+ monkeypatch.setenv("CODEX_SQLITE_HOME", "")+ monkeypatch.setenv("CODEX_HOME", str(tmp_path / "unused"))configured_home = str(home)if home_kind == "literal_tilde":monkeypatch.chdir(tmp_path)@@ -1082,14 +1087,9 @@ def test_completion_reads_usage_from_literal_home(monkeypatch.setenv("HOME", str(home if home_kind == "home" else tmp_path))monkeypatch.setenv("USERPROFILE", str(home if home_kind == "home" else tmp_path))configured_home = "~" if home_kind == "home" else f"~/{home.name}"- fixture.environment[home_variable] = configured_home- if home_variable == "CODEX_HOME":- fixture.environment["CODEX_SQLITE_HOME"] = ""+ monkeypatch.setenv(home_variable, configured_home)- usage = _complete_scan(fixture)["scan"]["usage"]-- assert usage["coverage"] == "complete"- assert usage["totalTokens"] == 15+ assert workbench_api["scan_usage"]._codex_state_database() == database.resolve()def test_completion_reports_unavailable_without_fabricating_zero(tmp_path: Path) -> None:@@ -1186,6 +1186,7 @@ def test_missing_usage_preserves_measured_parent_or_descendant(assert _complete_scan(fixture)["scan"]["usage"].items() >= expected.items()[email protected]_macos@pytest.mark.skipif(sys.platform != "darwin", reason="macOS system path aliases")@pytest.mark.parametrize("temporary_root", [tempfile.gettempdir(), "/tmp"], ids=["var", "tmp"])def test_completion_accepts_macos_system_rollout_alias(@@ -1206,6 +1207,7 @@ def test_completion_accepts_macos_system_rollout_alias(assert usage["totalTokens"] == 13[email protected]_macosdef test_completion_rejects_non_system_rollout_symlink(tmp_path: Path) -> None:fixture = _start_scan(tmp_path)counted = fixture.started_at + timedelta(microseconds=1)@@ -1543,24 +1545,12 @@ def test_metadata_only_deep_owner_requires_direct_control_originator(}-def test_usage_is_returned_by_completion_without_an_extra_command(tmp_path: Path) -> None:- fixture = _start_scan(tmp_path)- counted = fixture.started_at + timedelta(microseconds=1)- _state_graph(- fixture.environment,- {"scan-parent": _rollout(tmp_path, "scan-parent", [_token_event(counted, 12, 4)])},- [],- )- assert _complete_scan(fixture)["scan"]["usage"]["totalTokens"] == 16- extra_command = scan_command(- fixture.state_dir,- "get-scan-usage",- fixture.scan_id,- check=False,- environment=fixture.environment,- )- assert extra_command["returncode"] != 0- assert "invalid choice" in str(extra_command["stderr"])+def test_usage_has_no_separate_workbench_command(workbench_api, monkeypatch, capsys) -> None:+ monkeypatch.setattr(sys, "argv", ["workbench_db.py", "get-scan-usage"])+ with pytest.raises(SystemExit) as rejected:+ workbench_api["parse_args"]("workbench")+ assert rejected.value.code == 2+ assert "invalid choice: 'get-scan-usage'" in capsys.readouterr().err@pytest.mark.parametrize("native", [False, True])@@ -1743,6 +1733,7 @@ def test_host_final_usage_preserves_missing_worker_warning()[email protected]_macosdef test_host_final_usage_retries_a_locked_native_database_without_losing_counts(tmp_path: Path,) -> None:@@ -2439,10 +2430,9 @@ def test_closed_turn_coverage_survives_later_success()[email protected]("receipt", [False, True])[email protected]("native", [False, True])[email protected]("receipt", [None, "legacy", "native"])def test_closed_turn_coverage_retains_before_window_receipt_evidence(- tmp_path: Path, receipt: bool, native: bool+ tmp_path: Path, receipt: str | None) -> None:started = datetime.fromisoformat("2026-01-01T00:00:01+00:00")before = started - timedelta(seconds=1)@@ -2450,7 +2440,7 @@ def test_closed_turn_coverage_retains_before_window_receipt_evidence(if receipt:events.append(_response_event(before, "scan-parent", "before", 20, 3, turn_id="first")- if native+ if receipt == "native"else _token_event(before, 20, 3))events.extend(diff --git a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py b/plugins/codex-security/tests/test_workbench_setup_and_migrations.pyindex 6bb09bd95..a8580249a 100644--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py@@ -2326,7 +2326,8 @@ def test_workbench_reconciles_legacy_execution_profile_migrations(connection.execute("UPDATE scans SET model = 'current-model' WHERE id = ?", (scan_id,))run_workbench(state_dir, "database-info")- run_workbench(state_dir, "database-info")+ # Creating, saving, starting and updating the new scan each reopen the migrated database.+ assert_new_scan_model_is_independent(state_dir, target, tmp_path / "current-scans")expected_migration_name = {11: "deep scan orchestration state",@@ -2356,8 +2357,6 @@ def test_workbench_reconciles_legacy_execution_profile_migrations().fetchone() == (legacy_model, legacy_effort)assert connection.execute("PRAGMA foreign_key_check").fetchall() == []- assert_new_scan_model_is_independent(state_dir, target, tmp_path / "current-scans")-@pytest.mark.parametrize("installed_history", ["main-scan-names", "source-excerpt-scopes"])def test_workbench_preserves_both_installed_migration_42_histories(@@ -2766,7 +2765,8 @@ def test_workbench_upgrades_legacy_execution_profile_migrations(connection.execute("UPDATE scans SET model = ? WHERE id = ?", ("gpt-current", scan_id))run_workbench(state_dir, "database-info")- run_workbench(state_dir, "database-info")+ # Creating, saving, starting and updating the new scan each reopen the migrated database.+ assert_new_scan_model_is_independent(state_dir, target, tmp_path / "current-scans")with sqlite3.connect(database) as connection:assert connection.execute(@@ -2803,8 +2803,6 @@ def test_workbench_upgrades_legacy_execution_profile_migrations().fetchone() == (model, reasoning_effort)assert connection.execute("PRAGMA foreign_key_check").fetchall() == []- assert_new_scan_model_is_independent(state_dir, target, tmp_path / "current-scans")-def test_workbench_rejects_unknown_execution_profile_migration_without_mutating_history() -> None:namespace = runpy.run_path(str(SCRIPT), run_name="codex_security_workbench_db")diff --git a/plugins/codex-security/tests/test_workbench_target.py b/plugins/codex-security/tests/test_workbench_target.pyindex ef6e804b2..acf82a32a 100644--- a/plugins/codex-security/tests/test_workbench_target.py+++ b/plugins/codex-security/tests/test_workbench_target.py@@ -935,6 +935,15 @@ def test_git_blob_samples_match_full_file_classification_with_bounded_reads(b"object blob invalid\n" + b"x" * (4 * 1024 * 1024),b"object blob 131072\n" + b"x" * (64 * 1024 + 1),],+ ids=[+ "unterminated-header",+ "invalid-size",+ "negative-size",+ "short-body",+ "invalid-terminator",+ "large-invalid-header",+ "truncated-large-body",+ ],)def test_git_blob_samples_reject_incomplete_framing(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, output: bytes