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 scan history and usage tests (#1409)
mldangelo-oaia31c5b32b4c2
diff --git a/plugins/codex-security/tests/test_deep_security_scan_concurrency_guard.py b/plugins/codex-security/tests/test_deep_security_scan_concurrency_guard.pyindex 01f0eac80..d8bdbc506 100644--- a/plugins/codex-security/tests/test_deep_security_scan_concurrency_guard.py+++ b/plugins/codex-security/tests/test_deep_security_scan_concurrency_guard.py@@ -3,7 +3,12 @@ from __future__ import annotationsimport sqlite3from pathlib import Path-from workbench_test_support import create_saved_git_workspace, run_workbench+from workbench_test_support import (+ create_saved_git_workspace,+ fail_scan,+ get_scan,+ start_scan_command,+)def test_scan_context_reports_only_other_running_deep_scans(tmp_path: Path) -> None:@@ -23,12 +28,7 @@ def test_scan_context_reports_only_other_running_deep_scans(tmp_path: Path) -> Nfor name, target in targets.items()}scans = {- name: run_workbench(- state_dir,- "start-scan",- "--workspace-id",- str(workspace["id"]),- )+ name: start_scan_command(state_dir, str(workspace["id"]))for name, workspace in workspaces.items()}@@ -39,14 +39,7 @@ def test_scan_context_reports_only_other_running_deep_scans(tmp_path: Path) -> N"UPDATE scans SET handoff_status = 'delivered' WHERE id IN (?, ?)",(failed_scan_id, other_scan_id),)- run_workbench(- state_dir,- "fail-scan",- "--scan-id",- failed_scan_id,- "--message",- "Stopped for the fixture.",- )+ fail_scan(state_dir, failed_scan_id, "Stopped for the fixture.")complete_scan_id = str(scans["complete"]["results"]["scanId"])with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.execute(@@ -59,7 +52,7 @@ def test_scan_context_reports_only_other_running_deep_scans(tmp_path: Path) -> N)current_scan_id = str(scans["current"]["results"]["scanId"])- context = run_workbench(state_dir, "get-scan", "--scan-id", current_scan_id)+ context = get_scan(state_dir, current_scan_id)assert context["otherRunningDeepScans"] == [{@@ -71,13 +64,6 @@ def test_scan_context_reports_only_other_running_deep_scans(tmp_path: Path) -> N}]- run_workbench(- state_dir,- "fail-scan",- "--scan-id",- other_scan_id,- "--message",- "Stopped for the fixture.",- )- context = run_workbench(state_dir, "get-scan", "--scan-id", current_scan_id)+ fail_scan(state_dir, other_scan_id, "Stopped for the fixture.")+ context = get_scan(state_dir, current_scan_id)assert context["otherRunningDeepScans"] == []diff --git a/plugins/codex-security/tests/test_workbench_prompt_only_scan.py b/plugins/codex-security/tests/test_workbench_prompt_only_scan.pyindex ea73d0a93..b7675d16a 100644--- a/plugins/codex-security/tests/test_workbench_prompt_only_scan.py+++ b/plugins/codex-security/tests/test_workbench_prompt_only_scan.py@@ -17,6 +17,7 @@ from test_workbench_db import (initialize_git_repository,run_workbench,)+from workbench_test_support import get_scan, scan_command, start_scan_command, update_progressdef start_prompt_only_scan(@@ -26,8 +27,6 @@ def start_prompt_only_scan(*,thread_id: str = "thread-prompt-only-scan",mode: str = "standard",- target_summary: str = "Prompt-only scan",- user_context: str = "Inspect authentication boundaries",extra_args: tuple[str, ...] = (),) -> dict[str, object]:return run_workbench(@@ -42,9 +41,9 @@ def start_prompt_only_scan("--mode",mode,"--target-summary",- target_summary,+ "Prompt-only scan","--user-context",- user_context,+ "Inspect authentication boundaries","--scan-root",str(scan_root),*extra_args,@@ -57,8 +56,6 @@ def start_headless_standard_scan(scan_root: Path,*,thread_id: str = "thread-headless-standard-scan",- scope: str = ".",- target_summary: str = "Headless standard scan",user_context: str = "Inspect authentication boundaries",) -> dict[str, object]:return run_workbench(@@ -69,9 +66,9 @@ def start_headless_standard_scan("--target-path",str(target),"--scope",- scope,+ ".","--target-summary",- target_summary,+ "Headless standard scan","--user-context",user_context,"--scan-root",@@ -202,10 +199,9 @@ def test_prompt_only_standard_phase_uses_latest_persisted_scan_context(started = start_prompt_only_scan(state_dir, target, tmp_path / "scans")scan_id = str(started["scan"]["scanId"])updated_context = "Prioritize password-reset token validation."- updated = run_workbench(+ updated = scan_command(state_dir,"update-scan-context",- "--scan-id",scan_id,"--thread-id","thread-prompt-only-scan",@@ -214,14 +210,7 @@ def test_prompt_only_standard_phase_uses_latest_persisted_scan_context()assert updated["scan"]["userContext"] == updated_context- next_phase = run_workbench(- state_dir,- "update-progress",- "--scan-id",- scan_id,- "--phase",- "discovery",- )+ next_phase = update_progress(state_dir, scan_id, "--phase", "discovery")assert next_phase["scan"]["progress"]["phase"] == "discovery"assert next_phase["scan"]["userContext"] == updated_context@@ -293,14 +282,7 @@ def test_prompt_only_scan_does_not_join_setup_owned_scans(tmp_path: Path) -> Nontarget,thread_id="thread-prompt-only-scan",)- pending = run_workbench(- state_dir,- "start-scan",- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(scan_root),- )+ pending = start_scan_command(state_dir, str(saved["id"]), "--scan-root", str(scan_root))assert pending["results"]["handoffStatus"] == "pending"prompt_only = start_prompt_only_scan(state_dir, target, scan_root)assert prompt_only["startDisposition"] == "created"@@ -382,7 +364,7 @@ def test_prompt_registration_keeps_existing_scans_readable(connection.close()def read_scans():- read = run_workbench(state_dir, "get-scan", "--scan-id", str(scan_id))+ read = get_scan(state_dir, str(scan_id))listed = run_workbench(state_dir, "list-scans")assert read["scan"]["scanId"] == scan_idassert any(scan["scanId"] == scan_id for scan in listed["scans"])diff --git a/plugins/codex-security/tests/test_workbench_scan_archive.py b/plugins/codex-security/tests/test_workbench_scan_archive.pyindex f7361bb05..b8066e772 100644--- a/plugins/codex-security/tests/test_workbench_scan_archive.py+++ b/plugins/codex-security/tests/test_workbench_scan_archive.py@@ -4,7 +4,7 @@ import jsonimport sqlite3from pathlib import Path-from workbench_test_support import run_workbench+from workbench_test_support import fail_scan, run_workbenchdef register_scan(@@ -39,14 +39,7 @@ def test_archived_output_preserves_old_scan_and_allows_fresh_registration(repository.mkdir()scan_dir.mkdir(mode=0o700)previous = register_scan(state_dir, repository, scan_dir)- run_workbench(- state_dir,- "fail-scan",- "--scan-id",- str(previous["scanId"]),- "--message",- "The previous scan was interrupted.",- )+ fail_scan(state_dir, str(previous["scanId"]), "The previous scan was interrupted.")(scan_dir / "previous.txt").write_text("keep the previous scan\n")report_path = scan_dir / "report.md"report_path.write_text("# Previous scan\n")@@ -98,13 +91,8 @@ def test_empty_failed_scan_can_be_archived_and_reused(tmp_path: Path) -> None:repository.mkdir()scan_dir.mkdir(mode=0o700)previous = register_scan(state_dir, repository, scan_dir)- run_workbench(- state_dir,- "fail-scan",- "--scan-id",- str(previous["scanId"]),- "--message",- "The previous scan failed before writing artifacts.",+ fail_scan(+ state_dir, str(previous["scanId"]), "The previous scan failed before writing artifacts.")current = register_scan(state_dir, repository, scan_dir, "--archive-existing")@@ -129,14 +117,7 @@ def test_archive_requires_previous_directory_when_artifacts_exist(tmp_path: Pathrepository.mkdir()scan_dir.mkdir(mode=0o700)previous = register_scan(state_dir, repository, scan_dir)- run_workbench(- state_dir,- "fail-scan",- "--scan-id",- str(previous["scanId"]),- "--message",- "The previous scan was interrupted.",- )+ fail_scan(state_dir, str(previous["scanId"]), "The previous scan was interrupted.")with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.execute("INSERT INTO scan_artifacts (scan_id, kind, path, created_at) VALUES (?, ?, ?, ?)",diff --git a/plugins/codex-security/tests/test_workbench_scan_history.py b/plugins/codex-security/tests/test_workbench_scan_history.pyindex 6ff29fddb..f99f5ae14 100644--- a/plugins/codex-security/tests/test_workbench_scan_history.py+++ b/plugins/codex-security/tests/test_workbench_scan_history.py@@ -15,9 +15,14 @@ from test_workbench_db import HEAD_CHANGED_WARNINGfrom test_workbench_deep_scan import begin_target_scanfrom test_workbench_prompt_only_scan import start_headless_standard_scan, start_prompt_only_scanfrom workbench_test_support import (+ fail_scan,+ get_scan,initialize_git_repository,mark_deep_coordinator_succeeded,+ resume_deep_scan,run_workbench,+ scan_command,+ set_triage,stable_target_id,write_completed_contract,)@@ -115,14 +120,7 @@ def create_cli_scan(if not complete:return launchedif mode == "deep":- run_workbench(- state_dir,- "begin-deep-scan",- "--scan-id",- launched["scanId"],- "--thread-id",- "thread-scan-history",- )+ resume_deep_scan(state_dir, launched["scanId"], "thread-scan-history")mark_deep_coordinator_succeeded(state_dir, launched["scanId"], scan_dir)coverage_mode = (@@ -175,50 +173,6 @@ def create_cli_scan(return launched-def insert_scan(- connection: sqlite3.Connection,- *,- workspace_id: str,- scan_id: str,- mode: str,- status: str,- phase: str,- timestamp: str,- seal: str | None = None,- failure: str | None = None,- canceled: bool = False,-) -> None:- connection.execute(- """- INSERT INTO scans (- id, workspace_id, target_path, target_revision, scope, mode,- scan_dir, status, phase, handoff_status, failure_message,- started_at, completed_at, created_at, updated_at, canceled_at,- seal_manifest_digest- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)- """,- (- scan_id,- workspace_id,- "/tmp/target",- "fixture-revision",- ".",- mode,- f"/tmp/scans/{scan_id}",- status,- phase,- "delivered",- failure,- timestamp,- timestamp if status != "running" else None,- timestamp,- timestamp,- timestamp if canceled else None,- seal,- ),- )--def test_cli_scan_lifecycle_persists_recipes_lineage_and_filtered_history(tmp_path: Path) -> None:state_dir = tmp_path / "state"repository = tmp_path / "repository"@@ -234,21 +188,22 @@ def test_cli_scan_lifecycle_persists_recipes_lineage_and_filtered_history(tmp_papaths=["src", "tests"],)failed = create_cli_scan(state_dir, root, repository, complete=False)- run_workbench(state_dir, "fail-scan", "--scan-id", failed["scanId"], "--message", "interrupted")+ fail_scan(state_dir, failed["scanId"], "interrupted")assert str(uuid.UUID(first["scanId"])) == first["scanId"]assert first["targetId"] == stable_target_id(repository)assert first["scanDir"].startswith(str(root))- detail = run_workbench(state_dir, "get-scan", "--scan-id", rerun["scanId"])+ detail = get_scan(state_dir, rerun["scanId"])assert detail["parentScanId"] == first["scanId"]assert detail["recipe"]["target"]["paths"] == ["src", "tests"]with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:assert connection.execute("SELECT parent_scan_id FROM scans WHERE id = ?", (rerun["scanId"],)).fetchone() == (first["scanId"],)- assert run_workbench(state_dir, "get-scan-recipe", "--scan-id", first["scanId"])["recipe"][- "config"- ] == {"model": "gpt-5.6-sol", "model_reasoning_effort": "high"}+ assert scan_command(state_dir, "get-scan-recipe", first["scanId"])["recipe"]["config"] == {+ "model": "gpt-5.6-sol",+ "model_reasoning_effort": "high",+ }other = tmp_path / "other"other.mkdir()@@ -271,21 +226,14 @@ def test_cli_scan_persists_its_continuation_thread(tmp_path: Path) -> None:repository = tmp_path / "repository"repository.mkdir()scan = create_cli_scan(state_dir, tmp_path / "results", repository, complete=False)- initial = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]+ initial = get_scan(state_dir, scan["scanId"])["scan"]assert initial["threadIds"] == []assert initial["executionThreadIds"] == []- result = run_workbench(- state_dir,- "set-scan-thread",- "--scan-id",- scan["scanId"],- "--thread-id",- "thread-1",- )+ result = scan_command(state_dir, "set-scan-thread", scan["scanId"], "--thread-id", "thread-1")assert result == {"scanId": scan["scanId"], "threadId": "thread-1"}- detail = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])+ detail = get_scan(state_dir, scan["scanId"])assert detail["scan"]["continuationThreadId"] == "thread-1"assert detail["scan"]["threadIds"] == ["thread-1"]assert detail["scan"]["executionThreadIds"] == ["thread-1"]@@ -299,7 +247,7 @@ def test_get_scan_keeps_desktop_standard_owners_out_of_execution_roots(tmp_path:started = start_scan(state_dir, repository, tmp_path / "results", thread_id="desktop-owner")["scan"]- detail = run_workbench(state_dir, "get-scan", "--scan-id", started["scanId"])["scan"]+ detail = get_scan(state_dir, started["scanId"])["scan"]assert detail["threadIds"] == ["desktop-owner"]assert detail["executionThreadIds"] == []if start_scan is start_headless_standard_scan:@@ -357,7 +305,7 @@ def test_get_scan_includes_desktop_deep_worker_threads_without_continuation(tmp_],)- detail = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]+ detail = get_scan(state_dir, scan["scanId"])["scan"]assert detail["continuationThreadId"] is Noneassert detail["threadIds"] == ["desktop-owner",@@ -382,7 +330,7 @@ def test_get_scan_includes_desktop_deep_worker_threads_without_continuation(tmp_"UPDATE scans SET continuation_thread_id = 'desktop-headless' WHERE id = ?",(scan["scanId"],),)- continued = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]+ continued = get_scan(state_dir, scan["scanId"])["scan"]assert continued["threadIds"] == ["desktop-headless", *detail["threadIds"]]assert continued["executionThreadIds"] == detail["executionThreadIds"]@@ -418,7 +366,7 @@ def test_cli_scan_preserves_original_revision_when_head_moves(tmp_path: Path) ->subprocess.run(["git", "-C", str(repository), "add", "README.md"], check=True)subprocess.run(["git", "-C", str(repository), "commit", "-qm", "Move HEAD"], check=True)- completed = run_workbench(state_dir, "complete-scan", "--scan-id", launched["scanId"])+ completed = scan_command(state_dir, "complete-scan", launched["scanId"])assert completed["scan"]["progress"]["status"] == "complete"assert completed["scan"]["targetRevision"] == revision@@ -468,7 +416,7 @@ def test_cli_scan_history_persists_per_scan_cost(tmp_path: Path, context_reportilisted = run_workbench(state_dir, "list-scans", "--repository", str(repository))assert listed["scans"][0]["cost"] == cost- assert run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]["cost"] == cost+ assert get_scan(state_dir, scan["scanId"])["scan"]["cost"] == costwith sqlite3.connect(state_dir / "workbench.sqlite3") as connection:stored = connection.execute("SELECT cost_json FROM scans WHERE id = ?", (scan["scanId"],)@@ -509,18 +457,13 @@ def test_cli_scan_completion_persists_authoritative_cost_after_plugin_completion),)- completed = run_workbench(- state_dir,- "complete-scan",- "--scan-id",- scan["scanId"],- "--cost-json",- json.dumps(cost),+ completed = scan_command(+ state_dir, "complete-scan", scan["scanId"], "--cost-json", json.dumps(cost))assert completed["scan"]["cost"] == costassert completed["scan"]["usage"]["inputTokens"] == 5_000- assert run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]["cost"] == cost+ assert get_scan(state_dir, scan["scanId"])["scan"]["cost"] == costdef test_failed_cli_scan_history_persists_measured_cost(tmp_path: Path) -> None:@@ -537,12 +480,9 @@ def test_failed_cli_scan_history_persists_measured_cost(tmp_path: Path) -> None:}scan = create_cli_scan(state_dir, tmp_path / "results", repository, complete=False)- failed = run_workbench(+ failed = fail_scan(state_dir,- "fail-scan",- "--scan-id",scan["scanId"],- "--message","Scan stopped: cost limit exceeded.","--cost-json",json.dumps(cost),@@ -551,7 +491,7 @@ def test_failed_cli_scan_history_persists_measured_cost(tmp_path: Path) -> None:assert failed["scan"]["cost"] == costassert failed["scan"]["progress"]["status"] == "failed"assert run_workbench(state_dir, "list-scans")["scans"][0]["cost"] == cost- assert run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]["cost"] == cost+ assert get_scan(state_dir, scan["scanId"])["scan"]["cost"] == costdef test_scan_failure_rejects_invalid_cost_without_stopping_the_scan(tmp_path: Path) -> None:@@ -560,26 +500,13 @@ def test_scan_failure_rejects_invalid_cost_without_stopping_the_scan(tmp_path: Prepository.mkdir()scan = create_cli_scan(state_dir, tmp_path / "results", repository, complete=False)- rejected = run_workbench(- state_dir,- "fail-scan",- "--scan-id",- scan["scanId"],- "--message",- "Scan stopped.",- "--cost-json",- "{}",- check=False,+ rejected = fail_scan(+ state_dir, scan["scanId"], "Scan stopped.", "--cost-json", "{}", check=False)assert rejected["returncode"] != 0assert "Scan cost" in rejected["stderr"]- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]["progress"][- "status"- ]- == "running"- )+ assert get_scan(state_dir, scan["scanId"])["scan"]["progress"]["status"] == "running"def test_scan_completion_rejects_invalid_cost_without_overwriting_history(tmp_path: Path) -> None:@@ -605,19 +532,13 @@ def test_scan_completion_rejects_invalid_cost_without_overwriting_history(tmp_pa]for value in invalid:- rejected = run_workbench(- state_dir,- "complete-scan",- "--scan-id",- scan["scanId"],- "--cost-json",- value,- check=False,+ rejected = scan_command(+ state_dir, "complete-scan", scan["scanId"], "--cost-json", value, check=False)assert rejected["returncode"] != 0assert "Scan cost" in rejected["stderr"]- assert "cost" not in run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]+ assert "cost" not in get_scan(state_dir, scan["scanId"])["scan"]def test_scan_history_resolves_unique_prefixes_and_rejects_ambiguity(tmp_path: Path) -> None:@@ -630,13 +551,8 @@ def test_scan_history_resolves_unique_prefixes_and_rejects_ambiguity(tmp_path: Pprefix = scan["scanId"][:8]after_prefix = after["scanId"][:8]- assert (- run_workbench(state_dir, "get-scan", "--scan-id", prefix)["scan"]["scanId"]- == scan["scanId"]- )- assert (- run_workbench(state_dir, "get-scan-recipe", "--scan-id", prefix)["scanId"] == scan["scanId"]- )+ assert get_scan(state_dir, prefix)["scan"]["scanId"] == scan["scanId"]+ assert scan_command(state_dir, "get-scan-recipe", prefix)["scanId"] == scan["scanId"]compared = run_workbench(state_dir,"compare-scans",@@ -669,14 +585,36 @@ def test_scan_history_resolves_unique_prefixes_and_rejects_ambiguity(tmp_path: Pworkspace_id = connection.execute("SELECT workspace_id FROM scans WHERE id = ?", (scan["scanId"],)).fetchone()[0]- insert_scan(- connection,- workspace_id=workspace_id,- scan_id=f"{prefix}-ffff-4000-8000-000000000000",- mode="standard",- status="complete",- phase="reporting",- timestamp="2026-07-24T00:00:00Z",+ ambiguous_scan_id = f"{prefix}-ffff-4000-8000-000000000000"+ timestamp = "2026-07-24T00:00:00Z"+ connection.execute(+ """+ INSERT INTO scans (+ id, workspace_id, target_path, target_revision, scope, mode,+ scan_dir, status, phase, handoff_status, failure_message,+ started_at, completed_at, created_at, updated_at, canceled_at,+ seal_manifest_digest+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)+ """,+ (+ ambiguous_scan_id,+ workspace_id,+ "/tmp/target",+ "fixture-revision",+ ".",+ "standard",+ f"/tmp/scans/{ambiguous_scan_id}",+ "complete",+ "reporting",+ "delivered",+ None,+ timestamp,+ timestamp,+ timestamp,+ timestamp,+ None,+ None,+ ),)for arguments in (@@ -702,10 +640,7 @@ def test_scan_history_resolves_unique_prefixes_and_rejects_ambiguity(tmp_path: Pambiguous = run_workbench(state_dir, *arguments, check=False)assert ambiguous["returncode"] != 0assert "matches multiple scans; use a longer prefix" in ambiguous["stderr"]- assert (- run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]["scanId"]- == scan["scanId"]- )+ assert get_scan(state_dir, scan["scanId"])["scan"]["scanId"] == scan["scanId"]def test_scan_list_includes_related_git_worktrees_and_clones(tmp_path: Path) -> None:@@ -795,16 +730,7 @@ def test_cli_scan_comparison_tracks_stable_findings_without_copying_triage(tmp_passert persisted["comparable"] is Trueassert persisted["summary"]["persisting"] == 1occurrence = persisted["findings"][0]["beforeOccurrenceId"]- run_workbench(- state_dir,- "set-finding-triage",- "--occurrence-id",- occurrence,- "--status",- "closed",- "--close-reason",- "already_fixed",- )+ set_triage(state_dir, occurrence, "closed", "--close-reason", "already_fixed")reopened = compare_scan_pair(state_dir, before, after)assert reopened["summary"]["reopened"] == 1assert reopened["findings"][0]["triage"] == {"closeReason": None, "status": "open"}@@ -834,8 +760,7 @@ def test_scan_comparison_requires_saved_matches_and_remains_read_only(tmp_path:known_since = connection.execute("SELECT MIN(started_at) FROM scans").fetchone()[0]before_finding, after_finding = (- run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]["findings"][0]- for scan in (before, after)+ get_scan(state_dir, scan["scanId"])["scan"]["findings"][0] for scan in (before, after))assert before_finding["findingId"] == after_finding["findingId"]for finding, other in ((before_finding, after_finding), (after_finding, before_finding)):@@ -948,9 +873,7 @@ def test_semantic_scan_comparison_caches_matches_and_exposes_related_findings(assert baseline["matchingCached"] is Falseassert baseline["summary"]["new"] == 1assert baseline["summary"]["resolved"] == 1- unmatched = run_workbench(state_dir, "get-scan", "--scan-id", before["scanId"])["scan"][- "findings"- ][0]+ unmatched = get_scan(state_dir, before["scanId"])["scan"]["findings"][0]assert "knownSince" not in unmatchedassert "knownScanIds" not in unmatchedprevious = baseline["matchingInputs"]["before"][0]@@ -990,12 +913,8 @@ def test_semantic_scan_comparison_caches_matches_and_exposes_related_findings(assert cached["matchingCached"] is Trueassert cached["matchingInputs"]["before"][0]["occurrenceId"] == previous["occurrenceId"]- before_finding = run_workbench(state_dir, "get-scan", "--scan-id", before["scanId"])["scan"][- "findings"- ][0]- after_finding = run_workbench(state_dir, "get-scan", "--scan-id", after["scanId"])["scan"][- "findings"- ][0]+ before_finding = get_scan(state_dir, before["scanId"])["scan"]["findings"][0]+ after_finding = get_scan(state_dir, after["scanId"])["scan"]["findings"][0]assert before_finding["matches"] == [{"findingId": current["findingId"],@@ -1027,9 +946,7 @@ def test_semantic_scan_comparison_caches_matches_and_exposes_related_findings(confirmed_match(current["occurrenceId"], latest_finding["occurrenceId"]),)for scan in (before, after, latest):- finding = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"][- "findings"- ][0]+ finding = get_scan(state_dir, scan["scanId"])["scan"]["findings"][0]assert finding["knownScanIds"] == [before["scanId"], latest["scanId"]]assert finding["knownSince"] == known_since@@ -1039,9 +956,7 @@ def test_semantic_scan_comparison_caches_matches_and_exposes_related_findings(latest,confirmed_match(previous["occurrenceId"], latest_finding["occurrenceId"]),)- latest_finding = run_workbench(state_dir, "get-scan", "--scan-id", latest["scanId"])["scan"][- "findings"- ][0]+ latest_finding = get_scan(state_dir, latest["scanId"])["scan"]["findings"][0]assert latest_finding["knownScanIds"] == [before["scanId"], latest["scanId"]]assert latest_finding["knownSince"] == known_since@@ -1100,12 +1015,9 @@ def test_semantic_scan_comparison_supports_one_to_many_without_copying_triage("UPDATE finding_occurrences SET severity = ? WHERE id = ?",(("low", current[0]["occurrenceId"]), ("critical", current[1]["occurrenceId"])),)- run_workbench(+ set_triage(state_dir,- "set-finding-triage",- "--occurrence-id",previous["occurrenceId"],- "--status","closed","--close-reason","false_positive",@@ -1131,13 +1043,11 @@ def test_semantic_scan_comparison_supports_one_to_many_without_copying_triage(assert set(saved["findings"][0]["afterOccurrenceIds"]) == {finding["occurrenceId"] for finding in current}- prior = run_workbench(state_dir, "get-scan", "--scan-id", before["scanId"])["scan"]["findings"][- 0- ]+ prior = get_scan(state_dir, before["scanId"])["scan"]["findings"][0]assert len(prior["matches"]) == 2assert prior["triage"]["closeReason"] == "false_positive"assert prior["triage"]["status"] == "closed"- later = run_workbench(state_dir, "get-scan", "--scan-id", after["scanId"])["scan"]["findings"]+ later = get_scan(state_dir, after["scanId"])["scan"]["findings"]assert all(finding["triage"]["status"] == "open" for finding in later)@@ -1173,9 +1083,7 @@ def test_uncertain_semantic_scan_matches_stay_separate(tmp_path: Path) -> None:assert compared["summary"]["persisting"] == 0assert all(finding["status"] == "unknown" for finding in compared["findings"])assert all("independently reachable" in finding["reason"] for finding in compared["findings"])- shown = run_workbench(state_dir, "get-scan", "--scan-id", after["scanId"])["scan"]["findings"][- 0- ]+ shown = get_scan(state_dir, after["scanId"])["scan"]["findings"][0]assert "matches" not in shownassert "knownSince" not in shownassert "knownScanIds" not in shown@@ -1206,9 +1114,7 @@ def test_semantic_scan_comparison_replaces_cached_matches_atomically(tmp_path: Pwith sqlite3.connect(state_dir / "workbench.sqlite3") as connection:assert connection.execute("SELECT COUNT(*) FROM scan_comparisons").fetchone() == (1,)assert connection.execute("SELECT COUNT(*) FROM scan_comparison_matches").fetchone() == (0,)- shown = run_workbench(state_dir, "get-scan", "--scan-id", before["scanId"])["scan"]["findings"][- 0- ]+ shown = get_scan(state_dir, before["scanId"])["scan"]["findings"][0]assert "matches" not in shown@@ -1378,18 +1284,8 @@ def test_cli_scan_comparison_requires_complete_matching_path_coverage(tmp_path:other_scope = create_cli_scan(state_dir, root, repository, finding=False, paths=["tests"])deep = create_cli_scan(state_dir, root, repository, mode="deep")explicit_root = create_cli_scan(state_dir, root, repository, paths=["."])- assert (- run_workbench(state_dir, "get-scan", "--scan-id", deep["scanId"])["scan"]["progress"][- "status"- ]- == "complete"- )- assert (- run_workbench(state_dir, "get-scan", "--scan-id", explicit_root["scanId"])["scan"][- "progress"- ]["status"]- == "complete"- )+ assert get_scan(state_dir, deep["scanId"])["scan"]["progress"]["status"] == "complete"+ assert get_scan(state_dir, explicit_root["scanId"])["scan"]["progress"]["status"] == "complete"for later in (partial, other_scope):compared = run_workbench(diff --git a/plugins/codex-security/tests/test_workbench_scan_usage.py b/plugins/codex-security/tests/test_workbench_scan_usage.pyindex f7db562dc..ea9fdeedd 100644--- a/plugins/codex-security/tests/test_workbench_scan_usage.py+++ b/plugins/codex-security/tests/test_workbench_scan_usage.py@@ -13,11 +13,15 @@ from typing import Anyimport pytestfrom workbench_test_support import (+ begin_deep_scan,create_saved_workspace,+ fail_scan,initialize_git_repository,mark_deep_coordinator_succeeded,run_workbench,+ scan_command,start_delivered_scan,+ upsert_deep_worker,write_completed_contract,)@@ -122,7 +126,6 @@ def _token_event(output_tokens: int,*,cached_input_tokens: int = 0,- reasoning_output_tokens: int = 0,) -> dict[str, Any]:return _event(timestamp,@@ -135,7 +138,7 @@ def _token_event("cached_input_tokens": cached_input_tokens,"cache_write_input_tokens": 0,"output_tokens": output_tokens,- "reasoning_output_tokens": reasoning_output_tokens,+ "reasoning_output_tokens": 0,"total_tokens": input_tokens + output_tokens,}},@@ -215,7 +218,6 @@ def _counts(input_tokens: int,cached_input_tokens: int,output_tokens: int,- reasoning_output_tokens: int = 0,*,cache_write_input_tokens: int = 0,) -> dict[str, int]:@@ -224,7 +226,7 @@ def _counts("cachedInputTokens": cached_input_tokens,"cacheWriteInputTokens": cache_write_input_tokens,"outputTokens": output_tokens,- "reasoningOutputTokens": reasoning_output_tokens,+ "reasoningOutputTokens": 0,"totalTokens": input_tokens + output_tokens,}@@ -248,12 +250,8 @@ def _complete_scan(fixture: ScanFixture) -> dict[str, Any]:fixture.target,**options,)- return run_workbench(- fixture.state_dir,- "complete-scan",- "--scan-id",- fixture.scan_id,- environment=fixture.environment,+ return scan_command(+ fixture.state_dir, "complete-scan", fixture.scan_id, environment=fixture.environment)@@ -538,10 +536,8 @@ def test_completion_counts_deep_sdk_workers_and_descendants(tmp_path: Path) -> N"CODEX_SQLITE_HOME": str(tmp_path / "codex-sqlite"),"CODEX_STATE_DB": "",}- deep = run_workbench(+ deep = begin_deep_scan(state_dir,- "begin-deep-scan",- "--thread-id","scan-parent","--target-path",str(target),@@ -572,20 +568,13 @@ def test_completion_counts_deep_sdk_workers_and_descendants(tmp_path: Path) -> Nartifact.mkdir(parents=True)prompt = artifact / "prompt.md"prompt.write_text("Review the fixture target.\n", encoding="utf-8")- run_workbench(+ upsert_deep_worker(state_dir,- "upsert-deep-scan-worker",- "--scan-id",scan_id,- "--worker-id",str(uuid.uuid4()),- "--kind","discovery",- "--status","running",- "--prompt-path",str(prompt),- "--artifact-dir",str(artifact),"--sdk-thread-id","sdk-worker",@@ -633,10 +622,9 @@ def test_completion_preserves_explicit_legacy_cost(tmp_path: Path) -> None:write_completed_contract(fixture.scan_dir, fixture.scan_id, fixture.target, relative_path="app.py")- completed = run_workbench(+ completed = scan_command(fixture.state_dir,"complete-scan",- "--scan-id",fixture.scan_id,"--cost-json",json.dumps(cost),@@ -655,10 +643,9 @@ def test_usage_is_returned_by_completion_without_an_extra_command(tmp_path: Path[],)assert _complete_scan(fixture)["scan"]["usage"]["totalTokens"] == 16- extra_command = run_workbench(+ extra_command = scan_command(fixture.state_dir,"get-scan-usage",- "--scan-id",fixture.scan_id,check=False,environment=fixture.environment,@@ -675,14 +662,8 @@ def test_failed_scan_preserves_legacy_failure_behavior(tmp_path: Path) -> None:{"scan-parent": _rollout(tmp_path, "scan-parent", [_token_event(counted, 21, 8)])},[],)- failed = run_workbench(- fixture.state_dir,- "fail-scan",- "--scan-id",- fixture.scan_id,- "--message",- "Fixture failure.",- environment=fixture.environment,+ failed = fail_scan(+ fixture.state_dir, fixture.scan_id, "Fixture failure.", environment=fixture.environment)["scan"]assert failed["progress"]["status"] == "failed"assert "usage" not in failed