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): share workbench scan fixtures (#1223)
mldangelo-oai89aae2421363
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 3c742bd8c..01f0eac80 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@@ -1,50 +1,9 @@from __future__ import annotations-import json-import osimport sqlite3-import subprocess-import sys-import uuidfrom pathlib import Path-PLUGIN_DIR = Path(__file__).resolve().parent.parent-WORKBENCH_SCRIPT = PLUGIN_DIR / "scripts" / "workbench_db.py"---def run_workbench(state_dir: Path, *args: str) -> dict[str, object]:- completed = subprocess.run(- [sys.executable, str(WORKBENCH_SCRIPT), *args],- check=True,- capture_output=True,- env={**os.environ, "CODEX_SECURITY_STATE_DIR": str(state_dir)},- text=True,- )- return json.loads(completed.stdout)---def create_saved_workspace(state_dir: Path, target: Path, mode: str) -> dict[str, object]:- workspace_id = str(uuid.uuid4())- run_workbench(- state_dir,- "create-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- )- return run_workbench(- state_dir,- "save-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--scope",- ".",- "--mode",- mode,- )+from workbench_test_support import create_saved_git_workspace, run_workbenchdef test_scan_context_reports_only_other_running_deep_scans(tmp_path: Path) -> None:@@ -56,10 +15,10 @@ def test_scan_context_reports_only_other_running_deep_scans(tmp_path: Path) -> Ntarget.mkdir()workspaces = {- name: create_saved_workspace(+ name: create_saved_git_workspace(state_dir,target,- "standard" if name == "standard" else "deep",+ mode="standard" if name == "standard" else "deep",)for name, target in targets.items()}diff --git a/plugins/codex-security/tests/test_windows_report_e2e.py b/plugins/codex-security/tests/test_windows_report_e2e.pyindex fa52dab42..6a578a48d 100644--- a/plugins/codex-security/tests/test_windows_report_e2e.py+++ b/plugins/codex-security/tests/test_windows_report_e2e.py@@ -11,8 +11,7 @@ from unittest import mockfrom workbench_test_support import (SCRIPT,- create_saved_workspace,- start_delivered_scan,+ start_saved_scan,windows_file_backend,write_completed_contract,)@@ -31,16 +30,7 @@ def test_workbench_completion_and_exports_use_windows_file_backend(tmp_path: Patsource = target / "src" / "extract.py"source.parent.mkdir()source.write_text("".join(f"line {line}\n" for line in range(1, 46)))- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target)(scan_dir / "report.html").write_text("stale report")namespace = runpy.run_path(str(SCRIPT), run_name="codex_security_workbench_db")diff --git a/plugins/codex-security/tests/test_workbench_completion_binding.py b/plugins/codex-security/tests/test_workbench_completion_binding.pyindex b215f4da7..ff27188ad 100644--- a/plugins/codex-security/tests/test_workbench_completion_binding.py+++ b/plugins/codex-security/tests/test_workbench_completion_binding.py@@ -14,31 +14,21 @@ from typing import Anyimport pytestfrom workbench_test_support import (create_saved_workspace,+ empty_target_scan,initialize_git_repository,mark_deep_coordinator_succeeded,run_workbench,source_plugin_version,stable_target_id,start_delivered_scan,+ start_workspace_scan,write_checkpoint,write_completed_contract,)def _start_scan_with_draft_findings(tmp_path: Path) -> tuple[Path, str, Path]:- 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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)return state_dir, scan_id, scan_dir@@ -50,15 +40,7 @@ def _start_deep_scan_with_draft_findings(tmp_path: Path) -> tuple[Path, str, Patsaved = create_saved_workspace(state_dir, target, thread_id="thread-completion-binding", mode="deep")- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, str(saved["id"]), tmp_path / "scans")run_workbench(state_dir,"begin-deep-scan",@@ -554,15 +536,7 @@ def test_completion_populates_coverage_mode_from_selected_scan_mode(tmp_path: Pa"--mode",mode,)- started = start_delivered_scan(- state_dir,- "--workspace-id",- workspace_id,- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")if mode == "deep":run_workbench(state_dir,@@ -603,19 +577,7 @@ def test_completion_populates_coverage_mode_from_selected_scan_mode(tmp_path: Padef test_completion_populates_workbench_owned_unsealed_envelope(tmp_path: Path, omit_metadata: bool) -> 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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)manifest = json.loads((scan_dir / "scan-manifest.json").read_text())findings = json.loads((scan_dir / "findings.json").read_text())diff --git a/plugins/codex-security/tests/test_workbench_db.py b/plugins/codex-security/tests/test_workbench_db.pyindex 1c5954311..1a4cc9ad5 100644--- a/plugins/codex-security/tests/test_workbench_db.py+++ b/plugins/codex-security/tests/test_workbench_db.py@@ -17,10 +17,13 @@ from workbench_test_support import (SCRIPT,create_saved_git_workspace,create_saved_workspace,+ empty_target_scan,initialize_git_repository,run_workbench,stable_target_id,start_delivered_scan,+ start_saved_scan,+ start_workspace_scan,write_completed_contract,)@@ -637,15 +640,7 @@ def test_completion_normalizes_unsealed_deep_inventory_strategy_alias("--mode","deep",)- started = start_delivered_scan(- state_dir,- "--workspace-id",- workspace_id,- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")run_workbench(state_dir,"begin-deep-scan",@@ -721,16 +716,7 @@ def test_completion_warns_when_scanned_directory_becomes_unavailable(tmp_path: Ptarget = tmp_path / "target"target.mkdir()(target / "app.py").write_text("version = 1\n")- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target, relative_path="app.py")target.rename(tmp_path / "moved-target")@@ -765,19 +751,7 @@ def test_scan_start_rejects_artifact_root_inside_target(tmp_path: Path) -> None:def test_workbench_serializes_concurrent_scan_completion(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)with ThreadPoolExecutor(max_workers=2) as executor:@@ -1048,19 +1022,7 @@ def test_workbench_persists_progress_and_indexes_completed_findings(tmp_path: Padef test_completed_findings_are_summarized_and_sorted_by_severity(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)findings_path = scan_dir / "findings.json"@@ -1117,16 +1079,7 @@ def test_completed_finding_triage_and_remediation_persist(target.mkdir()source = target / "source.txt"source.write_bytes(f"vulnerable{line_ending}".encode())- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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 = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]scan_dir = Path(str(completed["scanDir"]))@@ -1695,15 +1648,7 @@ def test_completed_scan_disables_remediation_after_checkout_revision_changes(target = tmp_path / "target"revision = initialize_git_repository(target)saved = create_saved_git_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, str(saved["id"]), tmp_path / "scans")write_completed_contract(scan_dir,scan_id,@@ -1740,16 +1685,7 @@ def assert_completed_scan_disables_remediation_after_checkout_path_is_replaced(target = tmp_path / "target"target.mkdir()(target / "source.txt").write_text("vulnerable\n")- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target, relative_path="source.txt")completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]occurrence_id = str(completed["findings"][0]["occurrenceId"])@@ -1805,19 +1741,7 @@ def test_completed_scan_disables_remediation_after_checkout_symlink_is_replaced(def test_finding_management_rejects_invalid_state_transitions(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]scan_dir = Path(str(completed["scanDir"]))@@ -2202,19 +2126,7 @@ def test_finding_remediation_rejects_apply_after_checkout_changes(tmp_path: Pathdef test_finding_remediation_rejects_delayed_update_after_superseding_patch(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]scan_dir = Path(str(completed["scanDir"]))@@ -2292,16 +2204,7 @@ def test_finding_remediation_rejects_unversioned_directory_changes(tmp_path: Pattarget.mkdir()source = target / "source.txt"source.write_text("original\n")- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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 = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]scan_dir = Path(str(completed["scanDir"]))@@ -2967,11 +2870,23 @@ def test_workbench_resolves_structured_diff_target(tmp_path: Path) -> None:assert "must match the selected commit's parent" in rejected["stderr"]-def test_workbench_rejects_working_tree_target_after_head_moves(tmp_path: Path) -> None:- state_dir = tmp_path / "state"- target = tmp_path / "target"- revision = initialize_git_repository(target)- workspace_id = str(uuid.uuid4())+def create_saved_working_tree_workspace(+ state_dir: Path,+ target: Path,+ workspace_id: str,+ revision: str,+ *,+ head_revision: str | None = None,+) -> dict[str, object]:+ diff_arguments = (+ "--mode",+ "diff",+ "--diff-target-kind",+ "working_tree",+ "--diff-base-revision",+ revision,+ *(["--diff-head-revision", head_revision] if head_revision is not None else []),+ )run_workbench(state_dir,"create-workspace",@@ -2979,16 +2894,9 @@ def test_workbench_rejects_working_tree_target_after_head_moves(tmp_path: Path)workspace_id,"--target-path",str(target),- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- "--diff-head-revision",- revision,+ *diff_arguments,)- saved = run_workbench(+ return run_workbench(state_dir,"save-workspace","--workspace-id",@@ -2997,14 +2905,17 @@ def test_workbench_rejects_working_tree_target_after_head_moves(tmp_path: Path)str(target),"--scope",".",- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- "--diff-head-revision",- revision,+ *diff_arguments,+ )+++def test_workbench_rejects_working_tree_target_after_head_moves(tmp_path: Path) -> None:+ state_dir = tmp_path / "state"+ target = tmp_path / "target"+ revision = initialize_git_repository(target)+ workspace_id = str(uuid.uuid4())+ saved = create_saved_working_tree_workspace(+ state_dir, target, workspace_id, revision, head_revision=revision)assert saved["targetSummary"] == "Uncommitted changes"@@ -3028,36 +2939,7 @@ def test_workbench_rejects_working_tree_target_after_contents_change(tmp_path: Ptarget = tmp_path / "target"revision = initialize_git_repository(target)workspace_id = str(uuid.uuid4())- run_workbench(- state_dir,- "create-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )- saved = run_workbench(- state_dir,- "save-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--scope",- ".",- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )+ saved = create_saved_working_tree_workspace(state_dir, target, workspace_id, revision)assert str(saved["diffTarget"]["contentDigest"]).startswith("codex-security-snapshot/v1:sha256:")@@ -3080,36 +2962,7 @@ def test_workbench_warns_after_working_tree_changes(tmp_path: Path) -> None:revision = initialize_git_repository(target)(target / "new-file.txt").write_text("selected content\n")workspace_id = str(uuid.uuid4())- run_workbench(- state_dir,- "create-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )- run_workbench(- state_dir,- "save-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--scope",- ".",- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )+ create_saved_working_tree_workspace(state_dir, target, workspace_id, revision)started = start_delivered_scan(state_dir,"--workspace-id",@@ -3146,36 +2999,7 @@ def test_workbench_warns_after_working_tree_head_changes(target = tmp_path / "target"revision = initialize_git_repository(target)workspace_id = str(uuid.uuid4())- run_workbench(- state_dir,- "create-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )- run_workbench(- state_dir,- "save-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--scope",- ".",- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )+ create_saved_working_tree_workspace(state_dir, target, workspace_id, revision)started = start_delivered_scan(state_dir,"--workspace-id",@@ -3216,36 +3040,7 @@ def test_workbench_can_validate_legacy_nested_working_tree_scan(tmp_path: Path)nested_target = target / "nested"nested_target.mkdir()workspace_id = str(uuid.uuid4())- run_workbench(- state_dir,- "create-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )- run_workbench(- state_dir,- "save-workspace",- "--workspace-id",- workspace_id,- "--target-path",- str(target),- "--scope",- ".",- "--mode",- "diff",- "--diff-target-kind",- "working_tree",- "--diff-base-revision",- revision,- )+ create_saved_working_tree_workspace(state_dir, target, workspace_id, revision)started = start_delivered_scan(state_dir,"--workspace-id",@@ -3313,15 +3108,7 @@ def test_workbench_populates_manifest_with_working_tree_digest(tmp_path: Path) -"--diff-content-digest",str(diff_target["contentDigest"]),)- started = start_delivered_scan(- state_dir,- "--workspace-id",- workspace_id,- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")write_completed_contract(scan_dir,scan_id,@@ -3409,15 +3196,7 @@ def test_workbench_populates_completed_manifest_with_exact_diff_target(tmp_path:revision,)diff_target = saved["diffTarget"]- started = start_delivered_scan(- state_dir,- "--workspace-id",- workspace_id,- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")write_completed_contract(scan_dir,scan_id,diff --git a/plugins/codex-security/tests/test_workbench_db_exports.py b/plugins/codex-security/tests/test_workbench_db_exports.pyindex eff80d588..eda8075c7 100644--- a/plugins/codex-security/tests/test_workbench_db_exports.py+++ b/plugins/codex-security/tests/test_workbench_db_exports.py@@ -18,10 +18,13 @@ import pytestfrom workbench_test_support import (create_saved_git_workspace,create_saved_workspace,+ empty_target_scan,initialize_git_repository,mark_deep_coordinator_succeeded,run_workbench,start_delivered_scan,+ start_saved_scan,+ start_workspace_scan,write_checkpoint,write_completed_contract,)@@ -29,19 +32,7 @@ from workbench_test_support import (@pytest.mark.parametrize("termination", ["fail-scan", "cancel-scan"])def test_stopped_scan_keeps_saved_findings_and_exports(tmp_path: Path, termination: str) -> 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-root",- str(tmp_path / "scans"),- )["results"]- scan_id = str(started["scanId"])- scan_dir = Path(str(started["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)extra = (("--message", "Stopped after recording a finding.") if termination == "fail-scan" else ()@@ -91,18 +82,7 @@ def test_stopped_scan_keeps_saved_findings_and_exports(tmp_path: Path, terminatidef test_late_parent_draft_is_retained_without_mutating_frozen_stopped_seal(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-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)documents = {key: json.loads((scan_dir / filename).read_text())@@ -243,18 +223,7 @@ def test_stopped_clean_git_checkpoint_uses_revision_target(tmp_path: Path) -> Nodef test_stopped_diff_checkpoint_uses_canonical_snapshot_digest(tmp_path: Path, diff_kind: str, coverage_mode: str) -> 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-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)base_revision, head_revision = "base-revision", "head-revision"with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:connection.execute(@@ -297,18 +266,7 @@ 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 = 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-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ 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]@@ -382,18 +340,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 = 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-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ 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.")finding = json.loads((scan_dir / "findings.json").read_text())["findings"][0]@@ -459,18 +406,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 = 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-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ 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.")foreign = {@@ -496,18 +432,7 @@ def test_frozen_stopped_results_ignore_late_foreign_checkpoint_warning(tmp_path:def test_final_candidate_disposition_supersedes_pending_checkpoint(tmp_path: Path, disposition: str) -> 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-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)pending = {"scanId": scan_id,@@ -551,15 +476,7 @@ def test_final_candidate_disposition_supersedes_pending_checkpoint(def test_incomplete_parent_checkpoint_cannot_complete_scan(tmp_path: Path) -> None:state_dir, target = tmp_path / "state", tmp_path / "target"target.mkdir()- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target)manifest = json.loads((scan_dir / "scan-manifest.json").read_text())manifest["scan"]["complete"] = False@@ -682,14 +599,7 @@ def test_model_only_draft_is_available_before_findings_and_survives_stop(def test_history_does_not_expose_a_model_from_changed_sealed_artifacts(tmp_path: Path, changed_file: str) -> 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-root", str(tmp_path / "scans")- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)manifest_path = scan_dir / "scan-manifest.json"manifest = json.loads(manifest_path.read_text())@@ -785,14 +695,7 @@ def test_invalid_model_or_binding_keeps_history_available_for_semantic_repair(def test_export_validation_checks_binding_without_writing_or_pinning_legacy_artifacts(tmp_path: Path, artifact: str, format: str) -> 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-root", str(tmp_path / "scans")- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ 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)artifacts = {path: path.read_bytes() for path in scan_dir.rglob("*") if path.is_file()}@@ -848,16 +751,7 @@ def test_completed_findings_export_inside_scan_directory(tmp_path: Path) -> Nonesource = target / "src/extract.py"source.parent.mkdir()source.write_text("".join(f"line {line}\n" for line in range(1, 46)))- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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"]assert completed["artifacts"]["sarifReport"] == str(scan_dir / "exports" / "results.sarif")@@ -1005,15 +899,7 @@ def test_deep_csv_export_adds_only_candidate_id_column("--mode","deep",)- started = start_delivered_scan(- state_dir,- "--workspace-id",- workspace_id,- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")run_workbench(state_dir,"begin-deep-scan",@@ -1075,19 +961,7 @@ def test_deep_csv_export_adds_only_candidate_id_column(def test_csv_export_escapes_newline_and_full_width_formula_prefixes(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)findings_path = scan_dir / "findings.json"findings_document = json.loads(findings_path.read_text())@@ -1115,19 +989,7 @@ def test_csv_export_escapes_newline_and_full_width_formula_prefixes(tmp_path: Padef test_completed_findings_are_returned_in_bounded_pages(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)findings_path = scan_dir / "findings.json"document = json.loads(findings_path.read_text())@@ -1250,19 +1112,7 @@ def test_embedded_and_paged_findings_bound_large_stored_fields(tmp_path: Path) -def test_embedded_and_paged_findings_normalize_scalar_attack_path_assessments(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)findings_path = scan_dir / "findings.json"document = json.loads(findings_path.read_text())@@ -1376,16 +1226,7 @@ def test_primary_location_prefers_root_control_in_bounded_and_csv_results(for index in range(9):(target / f"support-{index}.py").write_text("support\n")(target / "root.py").write_text("vulnerable\n")- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target)findings_path = scan_dir / "findings.json"document = json.loads(findings_path.read_text())@@ -1421,16 +1262,7 @@ def test_csv_export_rejects_symlinked_exports_directory(tmp_path: Path) -> None:outside = tmp_path / "outside"target.mkdir()outside.mkdir()- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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_dir / "exports" / "results.sarif").unlink()@@ -1455,16 +1287,7 @@ def test_export_rejects_replaced_scan_directory(tmp_path: Path) -> None:outside = tmp_path / "outside"target.mkdir()outside.mkdir()- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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)moved_scan_dir = scan_dir.with_name(f"{scan_dir.name}.moved")@@ -1484,19 +1307,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 = 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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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)stored_parent = scan_dir.parent@@ -1520,19 +1331,7 @@ def test_csv_export_rejects_replaced_scan_directory_ancestor(tmp_path: Path) ->def test_completion_rejects_replaced_scan_directory(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)moved_scan_dir = scan_dir.with_name(f"{scan_dir.name}.moved")scan_dir.rename(moved_scan_dir)@@ -1543,19 +1342,7 @@ def test_completion_rejects_replaced_scan_directory(tmp_path: Path) -> None:def test_completion_rejects_replaced_scan_directory_ancestor(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)stored_parent = scan_dir.parentmoved_parent = stored_parent.with_name(f"{stored_parent.name}.moved")@@ -1570,19 +1357,7 @@ def test_completion_rejects_replaced_scan_directory_ancestor(tmp_path: Path) ->def test_remediation_apply_rejects_replaced_scan_directory_ancestor(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-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)write_completed_contract(scan_dir, scan_id, target)completed = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]occurrence_id = str(completed["findings"][0]["occurrenceId"])@@ -1654,15 +1429,7 @@ def test_parent_draft_preserves_reconciled_candidate_identity_before_publicationmonkeypatch.setenv("CODEX_SECURITY_STATE_DIR", str(state_dir))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-root",- str(tmp_path / "scans"),- )["results"]- scan_id, scan_dir = str(started["scanId"]), Path(str(started["scanDir"]))+ scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")write_completed_contract(scan_dir, scan_id, target)documents = {key: json.loads((scan_dir / filename).read_text())diff --git a/plugins/codex-security/tests/test_workbench_deep_scan.py b/plugins/codex-security/tests/test_workbench_deep_scan.pyindex c58a274e2..f32e9cdd9 100644--- a/plugins/codex-security/tests/test_workbench_deep_scan.py+++ b/plugins/codex-security/tests/test_workbench_deep_scan.py@@ -19,6 +19,7 @@ from workbench_test_support import (run_workbench,stable_target_id,start_delivered_scan,+ worker_paths,write_completed_contract,)@@ -27,6 +28,13 @@ def deep_environment(codex_home: Path) -> dict[str, str]:return {"CODEX_HOME": str(codex_home)}+def write_deep_config(codex_home: Path, content: str) -> Path:+ config_path = codex_home / "codex-security" / "config.toml"+ config_path.parent.mkdir(parents=True)+ config_path.write_text(content)+ return config_path++def begin_target_scan(state_dir: Path,codex_home: Path,@@ -86,15 +94,6 @@ def expire_deep_scan_coordinator(state_dir: Path, scan_id: str) -> None:)-def worker_paths(scan_dir: Path, name: str) -> tuple[Path, Path, Path]:- artifact_dir = scan_dir / "artifacts" / "deep_discovery" / name- artifact_dir.mkdir(parents=True)- prompt_path = artifact_dir / "prompt.md"- prompt_path.write_text(f"Prompt for {name}\n")- result_path = artifact_dir / "result.json"- return prompt_path, artifact_dir, result_path--def write_canonical_artifacts(scan_dir: Path) -> dict[str, Path]:discovery_dir = scan_dir / "artifacts" / "02_discovery"discovery_dir.mkdir(parents=True, exist_ok=True)@@ -371,10 +370,9 @@ def test_paused_discovery_resumes_after_restart_with_original_handoff_claim() -> None:state_dir, codex_home, target = tmp_path / "state", tmp_path / "codex-home", tmp_path / "target"target.mkdir()- config = codex_home / "codex-security" / "config.toml"- config.parent.mkdir(parents=True)- config.write_text(- "[deep_scan]\nworkers = 1\nsubagents = 0\nstop_after_no_new = 2\nmax_discovery_runs = 2\n"+ write_deep_config(+ codex_home,+ "[deep_scan]\nworkers = 1\nsubagents = 0\nstop_after_no_new = 2\nmax_discovery_runs = 2\n",)thread_id, handoff_claim_token = "track-c-continuation", str(uuid.uuid4())saved = create_saved_workspace(state_dir, target, thread_id="workspace-thread", mode="deep")@@ -680,10 +678,9 @@ def test_expired_generation_preserves_receipts_and_recovers_abandoned_workers(tmp_path: Path, reducer_status: str, replace_all_inputs: bool, should_finish: bool) -> None:state_dir, codex_home, target = tmp_path / "state", tmp_path / "codex-home", tmp_path / "target"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(- "[deep_scan]\nworkers = 3\nsubagents = 0\nstop_after_no_new = 1\nmax_discovery_runs = 4\n"+ write_deep_config(+ codex_home,+ "[deep_scan]\nworkers = 3\nsubagents = 0\nstop_after_no_new = 1\nmax_discovery_runs = 4\n",)target.mkdir()run = begin_target_scan(state_dir, codex_home, target, tmp_path / "scans")["deepScan"]@@ -1264,9 +1261,7 @@ def test_deep_scan_worker_defaults_do_not_depend_on_available_parallelism(state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"if workers_configuration is not None:- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text("[deep_scan]\n" + workers_configuration)+ write_deep_config(codex_home, "[deep_scan]\n" + workers_configuration)target = tmp_path / "target"target.mkdir()@@ -1299,9 +1294,7 @@ def test_deep_scan_worker_defaults_do_not_depend_on_available_parallelism(def test_deep_scan_prefers_explicit_config_path(tmp_path: Path) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- shared_config_path = codex_home / "codex-security" / "config.toml"- shared_config_path.parent.mkdir(parents=True)- shared_config_path.write_text("[deep_scan]\nworkers = 2\n")+ write_deep_config(codex_home, "[deep_scan]\nworkers = 2\n")isolated_config_path = tmp_path / "isolated-deep-scan.toml"isolated_config_path.write_text("[deep_scan]\nworkers = 7\n")target = tmp_path / "target"@@ -1332,15 +1325,14 @@ def test_deep_scan_prefers_explicit_config_path(tmp_path: Path) -> None:def test_target_begin_is_atomic_idempotent_and_snapshots_config(tmp_path: Path) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(+ config_path = write_deep_config(+ codex_home,"[deep_scan]\n"'workers = "auto"\n'"subagents = 2\n""stop_after_no_new = 4\n""max_discovery_runs = 12\n"- "max_time_hours = 2.5\n"+ "max_time_hours = 2.5\n",)target = tmp_path / "target"target.mkdir()@@ -1601,9 +1593,7 @@ def test_discovery_error_threshold_defaults_to_three_independently_of_no_new_thr) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(configuration)+ write_deep_config(codex_home, configuration)target = tmp_path / "target"target.mkdir()@@ -1620,11 +1610,10 @@ def test_deep_scan_snapshots_configured_discovery_time_limit() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(+ write_deep_config(+ codex_home,"[deep_scan]\n"- + ("" if configured_hours is None else f"max_time_hours = {configured_hours}\n")+ + ("" if configured_hours is None else f"max_time_hours = {configured_hours}\n"),)target = tmp_path / "target"target.mkdir()@@ -1709,10 +1698,9 @@ def test_failed_reducer_rebuffers_claimed_inputs_for_same_generation_replacement) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(- "[deep_scan]\nworkers = 3\nsubagents = 0\nstop_after_no_new = 6\nmax_discovery_runs = 6\n"+ write_deep_config(+ codex_home,+ "[deep_scan]\nworkers = 3\nsubagents = 0\nstop_after_no_new = 6\nmax_discovery_runs = 6\n",)target = tmp_path / "target"target.mkdir()@@ -1993,9 +1981,9 @@ def test_invalid_discovery_error_threshold_fails_before_scan_creation() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(f"[deep_scan]\nstop_after_consecutive_errors = {invalid_threshold}\n")+ write_deep_config(+ codex_home, f"[deep_scan]\nstop_after_consecutive_errors = {invalid_threshold}\n"+ )target = tmp_path / "target"target.mkdir()@@ -2025,9 +2013,7 @@ def test_invalid_discovery_time_limit_fails_before_scan_creation() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(f"[deep_scan]\nmax_time_hours = {invalid_hours}\n")+ write_deep_config(codex_home, f"[deep_scan]\nmax_time_hours = {invalid_hours}\n")target = tmp_path / "target"target.mkdir()@@ -2071,9 +2057,7 @@ def test_target_continuation_reuses_terminal_coordinator_across_threads(scan_id = str(first["deepScan"]["scanId"])scan_dir = Path(str(first["deepScan"]["scanDir"]))manifest = mark_deep_coordinator_succeeded(state_dir, scan_id, scan_dir)- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text("[deep_scan]\nsubagents = -1\n")+ write_deep_config(codex_home, "[deep_scan]\nsubagents = -1\n")continued = begin_target_scan(state_dir,@@ -2614,9 +2598,7 @@ def test_maximum_one_discovery_run_allows_hard_cap_singleton_reducer() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text("[deep_scan]\nworkers = 1\nmax_discovery_runs = 1\n")+ write_deep_config(codex_home, "[deep_scan]\nworkers = 1\nmax_discovery_runs = 1\n")target = tmp_path / "target"target.mkdir()begun = begin_target_scan(state_dir, codex_home, target, tmp_path / "scans")@@ -2787,11 +2769,10 @@ def test_discovery_deadline_caps_after_reducing_a_single_discovery_result() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(+ write_deep_config(+ codex_home,"[deep_scan]\nworkers = 1\nmax_discovery_runs = 3\n"- + ("" if configured_hours is None else f"max_time_hours = {configured_hours}\n")+ + ("" if configured_hours is None else f"max_time_hours = {configured_hours}\n"),)target = tmp_path / "target"target.mkdir()@@ -2894,10 +2875,9 @@ def test_discovery_deadline_caps_without_a_completed_discovery() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(- f"[deep_scan]\nworkers = 1\nmax_discovery_runs = 3\nmax_time_hours = {configured_hours}\n"+ write_deep_config(+ codex_home,+ f"[deep_scan]\nworkers = 1\nmax_discovery_runs = 3\nmax_time_hours = {configured_hours}\n",)target = tmp_path / "target"target.mkdir()@@ -3016,10 +2996,8 @@ def test_zero_discovery_deadline_rejects_nonempty_candidate_ledger() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(- "[deep_scan]\nworkers = 1\nmax_discovery_runs = 3\nmax_time_hours = 0.5\n"+ write_deep_config(+ codex_home, "[deep_scan]\nworkers = 1\nmax_discovery_runs = 3\nmax_time_hours = 0.5\n")target = tmp_path / "target"target.mkdir()@@ -3066,9 +3044,7 @@ def test_zero_discovery_deadline_rejects_nonempty_candidate_ledger(def test_capped_completion_requires_canonical_artifacts(tmp_path: Path) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text("[deep_scan]\nworkers = 1\nmax_discovery_runs = 1\n")+ write_deep_config(codex_home, "[deep_scan]\nworkers = 1\nmax_discovery_runs = 1\n")target = tmp_path / "target"target.mkdir()begun = begin_target_scan(state_dir, codex_home, target, tmp_path / "scans")@@ -3120,10 +3096,8 @@ def test_capped_completion_requires_canonical_artifacts(tmp_path: Path) -> None:def test_capped_completion_rejects_buffered_workers_and_omissions(tmp_path: Path) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(- "[deep_scan]\nworkers = 2\nstop_after_no_new = 10\nmax_discovery_runs = 3\n"+ write_deep_config(+ codex_home, "[deep_scan]\nworkers = 2\nstop_after_no_new = 10\nmax_discovery_runs = 3\n")target = tmp_path / "target"target.mkdir()@@ -3200,9 +3174,7 @@ def prepare_failure_capped_deep_scan() -> tuple[Path, Path, Path, str]:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text("[deep_scan]\nworkers = 2\nmax_discovery_runs = 10\n")+ write_deep_config(codex_home, "[deep_scan]\nworkers = 2\nmax_discovery_runs = 10\n")target = tmp_path / "target"target.mkdir()begun = begin_target_scan(state_dir, codex_home, target, tmp_path / "scans")@@ -3544,10 +3516,8 @@ def test_failure_capped_completion_rejects_unmarked_or_missing_canonical_coveragdef test_saturated_completion_rejects_merging_workers(tmp_path: Path) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(- "[deep_scan]\nworkers = 2\nstop_after_no_new = 2\nmax_discovery_runs = 3\n"+ write_deep_config(+ codex_home, "[deep_scan]\nworkers = 2\nstop_after_no_new = 2\nmax_discovery_runs = 3\n")target = tmp_path / "target"target.mkdir()@@ -3776,10 +3746,8 @@ def test_discovery_buffer_prefix_dedup_and_saturation_are_transactional() -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text(- "[deep_scan]\nworkers = 2\nstop_after_no_new = 3\nmax_discovery_runs = 4\n"+ write_deep_config(+ codex_home, "[deep_scan]\nworkers = 2\nstop_after_no_new = 3\nmax_discovery_runs = 4\n")target = tmp_path / "target"target.mkdir()@@ -4526,9 +4494,7 @@ def test_succeeded_run_with_manifest_cannot_be_marked_interrupted(tmp_path: Pathdef test_invalid_user_configuration_fails_before_scan_creation(tmp_path: Path) -> None:state_dir = tmp_path / "state"codex_home = tmp_path / "codex-home"- config_path = codex_home / "codex-security" / "config.toml"- config_path.parent.mkdir(parents=True)- config_path.write_text("[deep_scan]\nsubagents = -1\n")+ write_deep_config(codex_home, "[deep_scan]\nsubagents = -1\n")target = tmp_path / "target"target.mkdir()diff --git a/plugins/codex-security/tests/test_workbench_remediation_cancellation.py b/plugins/codex-security/tests/test_workbench_remediation_cancellation.pyindex 73beaa571..a7f6a6772 100644--- a/plugins/codex-security/tests/test_workbench_remediation_cancellation.py+++ b/plugins/codex-security/tests/test_workbench_remediation_cancellation.py@@ -6,9 +6,8 @@ import uuidfrom pathlib import Pathfrom workbench_test_support import (- create_saved_workspace,run_workbench,- start_delivered_scan,+ start_saved_scan,write_completed_contract,)@@ -19,16 +18,7 @@ def test_cancel_finding_remediation_request_restores_previous_state(tmp_path: Patarget.mkdir()source = target / "source.txt"source.write_text("vulnerable\n")- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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 = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]occurrence_id = str(completed["findings"][0]["occurrenceId"])diff --git a/plugins/codex-security/tests/test_workbench_remediation_retry.py b/plugins/codex-security/tests/test_workbench_remediation_retry.pyindex 8a033b4bc..399c07329 100644--- a/plugins/codex-security/tests/test_workbench_remediation_retry.py+++ b/plugins/codex-security/tests/test_workbench_remediation_retry.py@@ -8,9 +8,8 @@ from pathlib import Pathfrom typing import Anyfrom workbench_test_support import (- create_saved_workspace,run_workbench,- start_delivered_scan,+ start_saved_scan,write_completed_contract,)@@ -48,16 +47,7 @@ def test_failed_remediation_steps_can_retry_or_regenerate(tmp_path: Path) -> Nontarget.mkdir()source = target / "source.txt"source.write_text("vulnerable\n")- saved = create_saved_workspace(state_dir, target)- started = start_delivered_scan(- state_dir,- "--workspace-id",- str(saved["id"]),- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ 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 = run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)["scan"]occurrence_id = str(completed["findings"][0]["occurrenceId"])diff --git a/plugins/codex-security/tests/test_workbench_scan_history.py b/plugins/codex-security/tests/test_workbench_scan_history.pyindex 2ffcd7659..6ff29fddb 100644--- a/plugins/codex-security/tests/test_workbench_scan_history.py+++ b/plugins/codex-security/tests/test_workbench_scan_history.py@@ -2,7 +2,6 @@ from __future__ import annotationsimport copyimport json-import osimport shutilimport sqlite3import subprocess@@ -18,6 +17,7 @@ from test_workbench_prompt_only_scan import start_headless_standard_scan, start_from workbench_test_support import (initialize_git_repository,mark_deep_coordinator_succeeded,+ run_workbench,stable_target_id,write_completed_contract,)@@ -26,19 +26,6 @@ SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "workbench_db.py"FINALIZER = SCRIPT.with_name("finalize_scan_contract.py")-def run_workbench(state_dir: Path, *args: str, check: bool = True) -> dict[str, Any]:- completed = subprocess.run(- [sys.executable, str(SCRIPT), *args],- check=check,- capture_output=True,- env={**os.environ, "CODEX_SECURITY_STATE_DIR": str(state_dir)},- text=True,- )- if not check:- return {"returncode": completed.returncode, "stderr": completed.stderr}- return json.loads(completed.stdout)--def compare_scan_pair(state_dir: Path,before: dict[str, Any],diff --git a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py b/plugins/codex-security/tests/test_workbench_setup_and_migrations.pyindex 5cdaf00ca..4c059a54c 100644--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py@@ -23,6 +23,7 @@ from workbench_test_support import (initialize_git_repository,run_workbench,start_delivered_scan,+ start_workspace_scan,write_completed_contract,)@@ -401,15 +402,7 @@ def test_nested_target_name_is_a_literal_git_pathspec(tmp_path: Path) -> None:"--mode","standard",)- started = start_delivered_scan(- state_dir,- "--workspace-id",- workspace_id,- "--scan-root",- str(tmp_path / "scans"),- )- scan_id = str(started["results"]["scanId"])- scan_dir = Path(str(started["results"]["scanDir"]))+ scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")(repository / "outside.py").write_text("outside = 2\n")write_completed_contract(scan_dir,diff --git a/plugins/codex-security/tests/test_workbench_standard_deep_results.py b/plugins/codex-security/tests/test_workbench_standard_deep_results.pyindex cee35d993..5de07a5b1 100644--- a/plugins/codex-security/tests/test_workbench_standard_deep_results.py+++ b/plugins/codex-security/tests/test_workbench_standard_deep_results.py@@ -19,6 +19,7 @@ from workbench_test_support import (saved_binding,saved_discovery_worker,saved_draft,+ worker_paths,write_checkpoint,write_completed_contract,)@@ -1237,14 +1238,6 @@ def deep_scan_fixture(return state_dir, codex_home, target, scan_dir, scan_id-def worker_paths(scan_dir: Path, name: str) -> tuple[Path, Path, Path]:- artifact_dir = scan_dir / "artifacts" / "deep_discovery" / name- artifact_dir.mkdir(parents=True)- prompt_path = artifact_dir / "prompt.md"- prompt_path.write_text(f"Prompt for {name}\n")- return prompt_path, artifact_dir, artifact_dir / "result.json"--def accepted_standard_worker(state_dir: Path,codex_home: Path,@@ -1367,6 +1360,29 @@ def committed_standard_reducer(return reducer_id, result_path, committed+def standard_parent_results_fixture(+ tmp_path: Path, *, budget: bool = False+) -> tuple[Path, Path, Path, Path, str]:+ state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path, budget=budget)+ worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)+ committed_standard_reducer(+ state_dir,+ codex_home,+ scan_dir,+ scan_id,+ worker_id,+ worker_result,+ )+ write_completed_contract(+ scan_dir,+ scan_id,+ target,+ relative_path="app.py",+ coverage_mode="deep_repository",+ )+ return state_dir, codex_home, target, scan_dir, scan_id++def test_failure_preserves_last_committed_reducer_without_parent_draft(tmp_path: Path) -> None:state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)worker_id, result_path = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)@@ -2161,23 +2177,7 @@ def test_standard_worker_results_commit_and_recover_without_discovery_ledgers(def test_standard_worker_results_finish_with_only_canonical_parent_manifest(tmp_path: Path,) -> None:- state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)- worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)- committed_standard_reducer(- state_dir,- codex_home,- scan_dir,- scan_id,- worker_id,- worker_result,- )- write_completed_contract(- scan_dir,- scan_id,- target,- relative_path="app.py",- coverage_mode="deep_repository",- )+ state_dir, codex_home, target, scan_dir, scan_id = standard_parent_results_fixture(tmp_path)manifest_path = scan_dir / "scan-manifest.json"finished = run_workbench(@@ -2319,23 +2319,7 @@ def test_standard_worker_deadline_can_finish_without_any_completed_worker(def test_standard_worker_finish_preserves_running_state_when_parent_draft_is_incomplete(tmp_path: Path,) -> None:- state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)- worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)- committed_standard_reducer(- state_dir,- codex_home,- scan_dir,- scan_id,- worker_id,- worker_result,- )- write_completed_contract(- scan_dir,- scan_id,- target,- relative_path="app.py",- coverage_mode="deep_repository",- )+ state_dir, codex_home, target, scan_dir, scan_id = standard_parent_results_fixture(tmp_path)(scan_dir / "findings.json").unlink()rejected = run_workbench(@@ -2361,22 +2345,8 @@ def test_standard_worker_finish_preserves_running_state_when_parent_draft_is_incdef test_budget_exhaustion_preserves_validated_standard_results_without_candidate_ledgers(tmp_path: Path,) -> None:- state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path, budget=True)- worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)- committed_standard_reducer(- state_dir,- codex_home,- scan_dir,- scan_id,- worker_id,- worker_result,- )- write_completed_contract(- scan_dir,- scan_id,- target,- relative_path="app.py",- coverage_mode="deep_repository",+ state_dir, codex_home, target, scan_dir, scan_id = standard_parent_results_fixture(+ tmp_path, budget=True)manifest_path = scan_dir / "scan-manifest.json"run_workbench(@@ -2430,22 +2400,8 @@ def test_budget_exhaustion_preserves_validated_standard_results_without_candidatdef test_budget_exhaustion_rejects_incomplete_standard_result_draft(tmp_path: Path) -> None:- state_dir, codex_home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path, budget=True)- worker_id, worker_result = accepted_standard_worker(state_dir, codex_home, scan_dir, scan_id)- committed_standard_reducer(- state_dir,- codex_home,- scan_dir,- scan_id,- worker_id,- worker_result,- )- write_completed_contract(- scan_dir,- scan_id,- target,- relative_path="app.py",- coverage_mode="deep_repository",+ state_dir, codex_home, target, scan_dir, scan_id = standard_parent_results_fixture(+ tmp_path, budget=True)run_workbench(state_dir,diff --git a/plugins/codex-security/tests/workbench_test_support.py b/plugins/codex-security/tests/workbench_test_support.pyindex 454783b07..8bfb6cf56 100644--- a/plugins/codex-security/tests/workbench_test_support.py+++ b/plugins/codex-security/tests/workbench_test_support.py@@ -209,6 +209,30 @@ def start_delivered_scan(return started+def start_workspace_scan(state_dir: Path, workspace_id: str, scan_root: Path) -> tuple[str, Path]:+ started = start_delivered_scan(+ state_dir,+ "--workspace-id",+ workspace_id,+ "--scan-root",+ str(scan_root),+ )["results"]+ return str(started["scanId"]), Path(str(started["scanDir"]))+++def start_saved_scan(state_dir: Path, target: Path, scan_root: Path) -> tuple[str, Path]:+ saved = create_saved_workspace(state_dir, target)+ return start_workspace_scan(state_dir, str(saved["id"]), scan_root)+++def empty_target_scan(tmp_path: Path) -> tuple[Path, Path, str, Path]:+ state_dir = tmp_path / "state"+ target = tmp_path / "target"+ target.mkdir()+ scan_id, scan_dir = start_saved_scan(state_dir, target, tmp_path / "scans")+ return state_dir, target, scan_id, scan_dir++def initialize_git_repository(target: Path) -> str:target.mkdir()subprocess.run(["git", "init", "-q"], cwd=target, check=True)@@ -275,7 +299,9 @@ def create_saved_workspace()-def create_saved_git_workspace(state_dir: Path, target: Path) -> dict[str, object]:+def create_saved_git_workspace(+ state_dir: Path, target: Path, *, mode: str = "standard"+) -> dict[str, object]:workspace_id = str(uuid.uuid4())run_workbench(state_dir,@@ -295,10 +321,19 @@ def create_saved_git_workspace(state_dir: Path, target: Path) -> dict[str, objec"--scope",".","--mode",- "standard",+ mode,)+def worker_paths(scan_dir: Path, name: str) -> tuple[Path, Path, Path]:+ artifact_dir = scan_dir / "artifacts" / "deep_discovery" / name+ artifact_dir.mkdir(parents=True)+ prompt_path = artifact_dir / "prompt.md"+ prompt_path.write_text(f"Prompt for {name}\n")+ result_path = artifact_dir / "result.json"+ return prompt_path, artifact_dir, result_path++def mark_deep_coordinator_succeeded(state_dir: Path, scan_id: str, scan_dir: Path) -> Path:manifest = scan_dir / "artifacts" / "deep_discovery" / "coordinator-manifest.json"manifest.parent.mkdir(parents=True)