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
fix(workbench): preserve archived deep scans and streamline progress reads (#2314)
Michael D'Angeloaba412dbc87f
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.tsindex 37b3e8c48..687f2a3c4 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts@@ -2367,7 +2367,7 @@ async function testComparisonStopCondition(mode: "quota" | "deadline") {async compareFindings(_prompt, _cwd, signal) {comparisons++;if (mode === "quota")- throw new DeepScanNonRetryableError(+ throw codexWorkerTurnError("Quota exceeded. Check your plan and billing details.",);await deadline.promise;diff --git a/plugins/codex-security/scripts/deep_scan_workbench.py b/plugins/codex-security/scripts/deep_scan_workbench.pyindex 1d42e4fcf..a73b8ac96 100644--- a/plugins/codex-security/scripts/deep_scan_workbench.py+++ b/plugins/codex-security/scripts/deep_scan_workbench.py@@ -16,7 +16,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))import workbench_saved_results as saved_resultsfrom deep_scan_config import resolve_deep_scan_setupfrom workbench.handoff import require_current_continuation-from workbench.storage import create_private_directory+from workbench.storage import archived_deep_path, create_private_directory, saved_deep_workersfrom workbench_constants import PHASESfrom workbench_source_scopes import capture_source_scopesfrom workbench_target import directory_snapshot_regular_file_count@@ -281,15 +281,7 @@ def canonical_discovery_artifacts(scan: sqlite3.Row) -> dict[str, str]:def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, Any]:run = require_deep_scan_run(connection, scan_id)scan = dependencies().require_scan(connection, run["scan_id"])- worker_rows = connection.execute(- """- SELECT *- FROM deep_scan_workers- WHERE scan_id = ?- ORDER BY created_at, id- """,- (run["scan_id"],),- )+ worker_rows = saved_deep_workers(connection, scan)input_rows = connection.execute("""SELECT dedup_worker_id, discovery_worker_id, input_order@@ -299,12 +291,13 @@ def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, A""",(run["scan_id"],),)+ manifest_path = archived_deep_path(Path(scan["scan_dir"]), run["manifest_path"])canonical_artifacts = Noneif (run["canonical_inventory_path"] is Noneand run["status"] == "succeeded"- and run["manifest_path"] is not None- and run["manifest_path"] != str(Path(scan["scan_dir"]) / "scan-manifest.json")+ and manifest_path is not None+ and manifest_path != str(Path(scan["scan_dir"]) / "scan-manifest.json")and (Path(scan["scan_dir"]) / "artifacts" / "02_discovery" / "in_scope_files.txt").exists()):canonical_artifacts = canonical_discovery_artifacts(scan)@@ -358,7 +351,7 @@ def deep_scan_state(connection: sqlite3.Connection, scan_id: str) -> dict[str, A"consecutiveErrors": run["consecutive_errors"],"cancelRequested": bool(run["cancel_requested"]),"canonicalArtifacts": canonical_artifacts,- "manifestPath": run["manifest_path"],+ "manifestPath": manifest_path,"terminalReason": run["terminal_reason"],"error": deep_scan_error(run),"createdAt": run["created_at"],@@ -1471,7 +1464,8 @@ def finish_deep_scan_locked(if run["status"] == "succeeded":if (run["terminal_reason"] != args.terminal_reason- or run["manifest_path"] not in {None, manifest_path}+ or archived_deep_path(Path(scan["scan_dir"]), run["manifest_path"])+ not in {None, manifest_path}or not omissions_match):raise SystemExit(@@ -1618,6 +1612,7 @@ def fail_deep_scan_locked(run = require_deep_scan_run(connection, scan_id)require_current_coordinator(run, args)scan = dependencies().require_scan(connection, scan_id)+ recorded_manifest = archived_deep_path(Path(scan["scan_dir"]), run["manifest_path"])manifest_path = Noneif args.manifest_path:manifest_path = (@@ -1630,14 +1625,14 @@ def fail_deep_scan_locked(kind="file",))- elif run["manifest_path"] == str(Path(scan["scan_dir"]) / "scan-manifest.json"):- manifest_path = run["manifest_path"]+ elif recorded_manifest == str(Path(scan["scan_dir"]) / "scan-manifest.json"):+ manifest_path = recorded_manifestif run["status"] in {"failed", "interrupted"} or scan["status"] == "failed":if (run["status"] == args.deep_statusand scan["status"] == "failed"and run["error_message"] == message- and run["manifest_path"] == manifest_path+ and recorded_manifest == manifest_pathand scan["failure_message"] == message):connection.commit()diff --git a/plugins/codex-security/scripts/workbench/storage.py b/plugins/codex-security/scripts/workbench/storage.pyindex 2584d646d..2a303cfa4 100644--- a/plugins/codex-security/scripts/workbench/storage.py+++ b/plugins/codex-security/scripts/workbench/storage.py@@ -3,7 +3,9 @@from __future__ import annotationsimport os+import sqlite3from pathlib import Path+from typing import Anydef state_dir(*, canonical: bool = True) -> Path:@@ -22,6 +24,40 @@ def resolve_scan_root(scan_root: str | None) -> Path:return Path(scan_root).expanduser().resolve() if scan_root else state_dir() / "scans"+def archived_deep_path(scan_dir: Path, value: str | None) -> str | None:+ """Resolve old archive rows that still name the original sibling output."""+ if value is None or ".previous-" not in scan_dir.name:+ return value+ path = Path(value)+ if not path.is_relative_to(scan_dir.parent):+ return value+ parts = path.relative_to(scan_dir.parent).parts+ if not parts or ".." in parts or not scan_dir.name.startswith(f"{parts[0]}.previous-"):+ return value+ # Keep missing files inside the archive too. Never follow the replacement scan's output.+ return str(scan_dir.joinpath(*parts[1:]))+++def saved_deep_workers(connection: sqlite3.Connection, scan: sqlite3.Row) -> list[Any]:+ workers = connection.execute(+ "SELECT * FROM deep_scan_workers WHERE scan_id = ? ORDER BY created_at, id",+ (scan["id"],),+ ).fetchall()+ scan_dir = Path(scan["scan_dir"])+ if ".previous-" not in scan_dir.name:+ return workers+ return [+ {+ **worker,+ **{+ key: archived_deep_path(scan_dir, worker[key])+ for key in ("artifact_dir", "prompt_path", "result_manifest_path")+ },+ }+ for worker in workers+ ]++def create_private_directory(path: Path) -> None:"""Create missing directories privately without changing existing permissions."""try:diff --git a/plugins/codex-security/scripts/workbench_cli.py b/plugins/codex-security/scripts/workbench_cli.pyindex e76911c93..e2d2cf10c 100644--- a/plugins/codex-security/scripts/workbench_cli.py+++ b/plugins/codex-security/scripts/workbench_cli.py@@ -187,7 +187,9 @@ def parse_args(description: str, *, inspection_only: bool = False) -> argparse.Npublication_failure.add_argument("--coordinator-generation", type=positive_int)get_scan = add_command("get-scan", "--scan-id")- get_scan.add_argument("--occurrence-id")+ detail = get_scan.add_mutually_exclusive_group()+ detail.add_argument("--occurrence-id")+ detail.add_argument("--progress-only", action="store_true")get_scan.add_argument("--check-target", action="store_true")add_command("rename-scan", "--scan-id", "--name")diff --git a/plugins/codex-security/scripts/workbench_db.py b/plugins/codex-security/scripts/workbench_db.pyindex a072ef0a6..aec50dbb6 100644--- a/plugins/codex-security/scripts/workbench_db.py+++ b/plugins/codex-security/scripts/workbench_db.py@@ -55,7 +55,12 @@ from finalize_scan_contract import ()from finding_preview import bounded_finding_detailsfrom workbench import handoff-from workbench.storage import create_private_directory, resolve_scan_root, state_dir+from workbench.storage import (+ create_private_directory,+ resolve_scan_root,+ saved_deep_workers,+ state_dir,+)from workbench_cli import parse_argsfrom workbench_constants import (ARTIFACTS,@@ -1253,10 +1258,7 @@ def complete_scan_locked(scan_dir,scan["id"],completion_binding,- connection.execute(- "SELECT * FROM deep_scan_workers WHERE scan_id = ? ORDER BY created_at, id",- (scan["id"],),- ).fetchall(),+ saved_deep_workers(connection, scan),warnings,stopped=False,scan_mode=scan["mode"],@@ -2472,6 +2474,20 @@ def scan_context(def get_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:+ if getattr(args, "progress_only", False):+ scan = connection.execute(+ """+ SELECT scans.id, scans.mode, scans.phase, scans.status, scans.canceled_at,+ progress.*, progress.updated_at AS progress_updated_at+ FROM scans JOIN scan_progress AS progress ON progress.scan_id = scans.id+ WHERE scans.id = ?+ """,+ (resolve_scan_id(connection, args.scan_id),),+ ).fetchone()+ if scan is None:+ raise SystemExit("Codex Security scan not found.")+ progress, _ = scan_progress_result(connection, scan)+ return {"scan": {"progress": progress}}result = scan_context(connection, args.scan_id, args.occurrence_id)if result["scan"]["progress"]["status"] != "running":scan = require_scan(connection, args.scan_id)@@ -2524,6 +2540,43 @@ def list_findings(connection: sqlite3.Connection, args: argparse.Namespace) -> d}+def scan_progress_result(+ connection: sqlite3.Connection, scan: sqlite3.Row+) -> tuple[dict[str, Any], str]:+ independent_reviews = (+ deep_scan.independent_review_progress(connection, scan["id"])+ if scan["mode"] == "deep"+ else None+ )+ progress_result = {+ "candidates": {"reportable": scan["reportable_findings_count"]},+ "coverage": {+ "closedRows": scan["review_items_completed"],+ "filesTotal": scan["scope_file_count"],+ "worklistRows": scan["review_items_total"],+ },+ "phase": scan["phase"],+ "phaseProgress": {+ "completed": scan["phase_items_completed"],+ "total": scan["phase_items_total"],+ "unit": scan["phase_progress_unit"],+ },+ "preflightProgress": {+ "completed": scan["preflight_checks_completed"],+ "total": scan["preflight_checks_total"],+ },+ "preflightIssues": json.loads(scan["preflight_issues_json"]),+ "reviewPass": scan["deep_review_pass"],+ "status": "canceled" if scan["canceled_at"] else scan["status"],+ "updatedAt": scan["progress_updated_at"],+ }+ review_updated_at = ""+ if independent_reviews is not None:+ review_updated_at = str(independent_reviews.pop("updatedAt"))+ progress_result["independentReviews"] = independent_reviews+ return progress_result, review_updated_at++def scan_result(connection: sqlite3.Connection,scan: sqlite3.Row,@@ -2575,37 +2628,7 @@ def scan_result()}remediation_available, remediation_unavailable_reason = remediation_availability(scan)- independent_reviews = (- deep_scan.independent_review_progress(connection, scan["id"])- if scan["mode"] == "deep"- else None- )- progress_result = {- "candidates": {"reportable": scan["reportable_findings_count"]},- "coverage": {- "closedRows": scan["review_items_completed"],- "filesTotal": scan["scope_file_count"],- "worklistRows": scan["review_items_total"],- },- "phase": scan["phase"],- "phaseProgress": {- "completed": scan["phase_items_completed"],- "total": scan["phase_items_total"],- "unit": scan["phase_progress_unit"],- },- "preflightProgress": {- "completed": scan["preflight_checks_completed"],- "total": scan["preflight_checks_total"],- },- "preflightIssues": json.loads(scan["preflight_issues_json"]),- "reviewPass": scan["deep_review_pass"],- "status": "canceled" if scan["canceled_at"] else scan["status"],- "updatedAt": scan["progress_updated_at"],- }- review_updated_at = ""- if independent_reviews is not None:- review_updated_at = str(independent_reviews.pop("updatedAt"))- progress_result["independentReviews"] = independent_reviews+ progress_result, review_updated_at = scan_progress_result(connection, scan)relations = scan_history.finding_relations(connection, scan["id"], (row["id"] for row in occurrence_rows))diff --git a/plugins/codex-security/scripts/workbench_saved_results.py b/plugins/codex-security/scripts/workbench_saved_results.pyindex 9394cc0f1..f9ac96ee2 100644--- a/plugins/codex-security/scripts/workbench_saved_results.py+++ b/plugins/codex-security/scripts/workbench_saved_results.py@@ -70,6 +70,7 @@ from workbench.saved_sources import (from workbench.saved_sources import (_digest as _digest,)+from workbench.storage import saved_deep_workersfrom workbench_constants import PHASESfrom workbench_coverage_receipts import (_generic_surface_updates as _generic_surface_updates,@@ -142,11 +143,7 @@ def _saved_results_changed(db: Any, connection: Any, scan: Any) -> bool:try:scan_dir = db.require_canonical_scan_directory(Path(scan["scan_dir"]))manifest_path = db.artifact_path(scan_dir, db.ARTIFACTS["manifest"], required=False)- workers = connection.execute(- "SELECT id, kind, status, completed_at, artifact_dir, result_manifest_path "- "FROM deep_scan_workers WHERE scan_id = ?",- (scan["id"],),- ).fetchall()+ workers = saved_deep_workers(connection, scan)paths = dict(_saved_result_paths(scan_dir, workers))frozen_sources = scan["retained_source_digests_json"]@@ -285,11 +282,7 @@ def _recovery_source_digests(else:include_parent = True- workers = connection.execute(- "SELECT id, kind, status, completed_at, artifact_dir, result_manifest_path "- "FROM deep_scan_workers WHERE scan_id = ?",- (scan["id"],),- ).fetchall()+ workers = saved_deep_workers(connection, scan)previous_heads = checkpoint_headsif previous_heads is None:previous_heads = _frozen_checkpoint_heads(scan_dir, scan["id"], frozen_sources or {})@@ -441,10 +434,7 @@ def preserve_deep_deadline_draft(scan_dir = db.require_canonical_scan_directory(Path(scan["scan_dir"]))warnings = json.loads(scan["completion_warnings_json"])binding = db.workbench_completion_binding(scan, db.now())- workers = connection.execute(- "SELECT * FROM deep_scan_workers WHERE scan_id = ? ORDER BY created_at, id",- (scan["id"],),- ).fetchall()+ workers = saved_deep_workers(connection, scan)if preserve_reduction:# Completed reviews already went through reduction. Only add evidence# from unfinished reviews; raw accepted drafts must not undo that result.@@ -771,10 +761,7 @@ def preserve_scan_results_locked(scan_dir,scan_id,binding,- connection.execute(- "SELECT * FROM deep_scan_workers WHERE scan_id = ? ORDER BY created_at, id",- (scan_id,),- ).fetchall(),+ saved_deep_workers(connection, scan),warnings,stopped=True,scan_mode=scan["mode"],diff --git a/plugins/codex-security/scripts/workbench_scan_start.py b/plugins/codex-security/scripts/workbench_scan_start.pyindex 96460f18f..03b09a41d 100644--- a/plugins/codex-security/scripts/workbench_scan_start.py+++ b/plugins/codex-security/scripts/workbench_scan_start.py@@ -139,12 +139,12 @@ def archive_scan(if previous_scan is None and not (args.archive_existing and has_contents):yield archived_scan_dirreturn- artifacts = (+ has_artifacts = (connection.execute(- "SELECT kind, path FROM scan_artifacts WHERE scan_id = ?", (previous_scan["id"],)- ).fetchall()+ "SELECT 1 FROM scan_artifacts WHERE scan_id = ? LIMIT 1", (previous_scan["id"],)+ ).fetchone()if previous_scan is not None- else []+ else None)moved = Falsetry:@@ -162,7 +162,7 @@ def archive_scan(raise SystemExit("Cannot archive output containing the workbench state or active database.")- if artifacts and not has_contents:+ if has_artifacts and not has_contents:raise SystemExit("The archived scan directory is required to preserve existing scan artifacts.")@@ -199,15 +199,42 @@ def archive_scan(str(scan_dir),),)- for artifact in artifacts:- try:- relative_path = Path(artifact["path"]).relative_to(scan_dir)- except ValueError:- continue- connection.execute(- "UPDATE scan_artifacts SET path = ? WHERE scan_id = ? AND kind = ?",- (str(archived_scan_dir / relative_path), previous_scan["id"], artifact["kind"]),- )++ def archive_path(value: str | None) -> str | None:+ if value is None or not Path(value).is_relative_to(scan_dir):+ return value+ return str(archived_scan_dir / Path(value).relative_to(scan_dir))++ connection.create_function("archive_path", 1, archive_path)+ try:+ for table, columns in (+ ("scan_artifacts", ("path",)),+ ("deep_scan_workers", ("prompt_path", "artifact_dir", "result_manifest_path")),+ (+ "deep_scan_runs",+ (+ "manifest_path",+ "canonical_inventory_path",+ "canonical_finding_report_path",+ "canonical_candidates_path",+ "dedupe_report_path",+ "seed_research_path",+ "work_ledger_path",+ "raw_candidates_path",+ "coverage_ledger_path",+ "findings_dir",+ ),+ ),+ ):+ assignments = ", ".join(+ f"{column} = archive_path({column})" for column in columns+ )+ connection.execute(+ f"UPDATE {table} SET {assignments} WHERE scan_id = ?",+ (previous_scan["id"],),+ )+ finally:+ connection.create_function("archive_path", 1, None)# The caller commits registration before leaving this context. Older SDKs# supplied an already-moved directory; only restore moves we own.yield archived_scan_dirdiff --git a/plugins/codex-security/tests/test_workbench_deep_scan.py b/plugins/codex-security/tests/test_workbench_deep_scan.pyindex 20bb05510..28ea88db9 100644--- a/plugins/codex-security/tests/test_workbench_deep_scan.py+++ b/plugins/codex-security/tests/test_workbench_deep_scan.py@@ -41,6 +41,7 @@ from workbench_test_support import (update_progress,upsert_deep_worker,worker_paths,+ write_checkpoint,write_completed_contract,)@@ -381,6 +382,76 @@ def test_iteration_commits_all_sources_once_in_launch_order(tmp_path: Path) -> Nassert "other completed scans" in save(sources, check=False)["stderr"][email protected]("legacy_archive", [False, True])+def test_archived_deep_scan_keeps_its_discovery_and_checkpoint_paths(+ tmp_path: Path, legacy_archive: bool+) -> None:+ deep = start_empty_target_scan(tmp_path)+ worker, *_ = deep.dispatch_discovery_worker(name="discovery-0001")+ deep.record_iteration(name="dedup-0001", input_worker_ids=[worker], new_findings_count=1)+ manifest = deep.directory / "coordinator.json"+ manifest.write_text("{}")+ before = deep.command(+ "fail-deep-scan", "--message", "Stopped", "--manifest-path", str(manifest)+ )["deepScan"]++ target = tmp_path / "target"+ registration = run_workbench(+ deep.state_dir,+ "register-cli-scan",+ "--repository",+ str(target),+ "--scan-dir",+ str(deep.directory),+ "--archive-existing",+ "--recipe-json",+ json.dumps(+ {+ "config": {},+ "mode": "deep",+ "repository": str(target),+ "target": {"kind": "repository", "paths": []},+ }+ ),+ environment=deep_environment(deep.codex_home),+ )+ archived = Path(registration["archivedScanDir"])+ if legacy_archive:+ with sqlite3.connect(deep.state_dir / "workbench.sqlite3") as connection:+ connection.execute(+ "UPDATE deep_scan_runs SET manifest_path = ? WHERE scan_id = ?",+ (str(manifest), deep.id),+ )+ connection.executemany(+ "UPDATE deep_scan_workers SET prompt_path = ?, artifact_dir = ?, "+ "result_manifest_path = ? WHERE id = ?",+ [+ (row["promptPath"], row["artifactDir"], row["resultManifestPath"], row["id"])+ for row in before["workers"]+ ],+ )+ after = deep.read("thread-deep-scan")+ assert Path(after["manifestPath"]) == archived / manifest.name+ for old, current in zip(before["workers"], after["workers"], strict=True):+ assert old["id"] == current["id"]+ for field in ("promptPath", "artifactDir", "resultManifestPath"):+ path = Path(current[field])+ assert path == archived / Path(old[field]).relative_to(deep.directory)+ assert path.exists()+ replay = deep.command(+ "fail-deep-scan", "--message", "Stopped", "--manifest-path", after["manifestPath"]+ )+ assert replay["deepScan"]["manifestPath"] == after["manifestPath"]+ worker_output = Path(+ next(row["artifactDir"] for row in after["workers"] if row["id"] == worker)+ )+ checkpoint = write_checkpoint(worker_output / "checkpoints", saved_draft(deep.id))+ assert deep.command("get-scan")["scan"]["resultsRecoveryNeeded"]+ deep.command("recover-scan-results")+ saved = json.loads((archived / "scan-manifest.json").read_text())+ assert checkpoint.relative_to(archived).as_posix() in saved["scan"]["preservedSources"]++def test_existing_generation_safely_claims_and_reclaims_without_schema_migration(tmp_path: Path,) -> None:@@ -973,6 +1044,9 @@ def test_scan_progress_projects_active_and_completed_independent_reviews(def independent_reviews() -> dict[str, int | bool]:context = get_scan(deep.state_dir, deep.id)+ assert get_scan(deep.state_dir, deep.id, "--progress-only") == {+ "scan": {"progress": context["scan"]["progress"]}+ }return context["scan"]["progress"]["independentReviews"]assert independent_reviews() == {diff --git a/plugins/codex-security/tests/test_workbench_saved_source_order.py b/plugins/codex-security/tests/test_workbench_saved_source_order.pyindex 70f12c740..f8867b4f1 100644--- a/plugins/codex-security/tests/test_workbench_saved_source_order.py+++ b/plugins/codex-security/tests/test_workbench_saved_source_order.py@@ -48,6 +48,39 @@ def test_latest_iteration_uses_its_number_when_completion_times_tie() -> None:assert saved_sources._latest_iteration([latest, previous]) == latest+def test_stopped_scan_prefers_latest_iteration_over_older_reducer_checkpoint(+ tmp_path: Path,+) -> None:+ state, home, target, scan_dir, scan_id = deep_scan_fixture(tmp_path)+ finding = standard_finding(tmp_path, scan_id, target)+ # An upgraded scan can contain both a legacy reducer checkpoint and a host iteration.+ with sqlite3.connect(state / "workbench.sqlite3") as connection:+ for label, worker_id in (("dedup-0009", "z"), ("dedup-0010", "a")):+ output = scan_dir / "artifacts" / "deep_discovery" / "dedup" / label / "output"+ output.mkdir(parents=True)+ result = output / "result.json"+ draft = {+ "scanId": scan_id,+ "findings": [{**finding, "summary": label}],+ "threatModel": {"summary": label},+ }+ result.write_text(json.dumps(draft))+ if label == "dedup-0009":+ write_checkpoint(output / "checkpoints", draft)+ connection.execute(+ """INSERT INTO deep_scan_workers (+ id, scan_id, kind, status, prompt_path, artifact_dir, result_manifest_path,+ created_at, completed_at, updated_at+ ) VALUES (?, ?, 'dedup', 'succeeded', ?, ?, ?, '2026-10-27', '2026-10-27', '2026-10-27')""",+ (worker_id, scan_id, str(result), str(output), str(result)),+ )+ fail_deep_scan(state, home, scan_id, message="Stopped before parent publication.")+ findings = json.loads((scan_dir / "findings.json").read_text())["findings"]+ assert [row["summary"] for row in findings] == ["dedup-0010"]+ manifest = json.loads((scan_dir / "scan-manifest.json").read_text())+ assert manifest["scan"]["threatModel"]["summary"] == "dedup-0010"++def call_workbench(monkeypatch, state, codex_home, *args):with open(os.devnull) as stdin, monkeypatch.context() as patch:patch.setenv("CODEX_HOME", str(codex_home))diff --git a/plugins/codex-security/tests/test_workbench_scan_history.py b/plugins/codex-security/tests/test_workbench_scan_history.pyindex 4afe3f4d3..d05b02615 100644--- a/plugins/codex-security/tests/test_workbench_scan_history.py+++ b/plugins/codex-security/tests/test_workbench_scan_history.py@@ -55,6 +55,9 @@ def test_rename_persists_without_changing_scan_results(assert renamed == {"scanId": scan["scanId"], "name": "Release audit"}after = run_workbench(state_dir, "get-scan", "--scan-id", scan["scanId"])["scan"]+ assert get_scan(state_dir, scan["scanId"][:8], "--progress-only") == {+ "scan": {"progress": after["progress"]}+ }assert after == {**before, "name": "Release audit"}listed = run_workbench(state_dir, "list-scans", "--query", "release audit")["scans"]assert [(item["scanId"], item["name"]) for item in listed] == [diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.tsindex 12e0a2b73..9f7efa97d 100644--- a/sdk/typescript/src/api.ts+++ b/sdk/typescript/src/api.ts@@ -2957,7 +2957,11 @@ export class CodexSecurity {...workbenchOptions,signal: AbortSignal.any([signal, progressSignal]),},- workbenchArgs("get-scan", { scanId }),+ workbenchArgs("get-scan", {+ scanId,+ // Custom plugins may predate the compact progress projection.+ progressOnly: this.config.pluginPath === undefined,+ }),),onProgress:mode === "deep"diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex 354ded7b7..1c16f4ea8 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -3449,6 +3449,7 @@ if __name__ == "__main__":input?: string,): Promise<JsonObject> => {if (args[0] === "get-scan") {+ expect(args).toContain("--progress-only");return {scan: {progress: {diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.tsindex f0b8a5894..a7a2a01fc 100644--- a/sdk/typescript/tests-ts/runtime.test.ts+++ b/sdk/typescript/tests-ts/runtime.test.ts@@ -5758,93 +5758,6 @@ describe("runtime directories and plugin Python boundary", () => {);});- test("preserves recorded artifact paths when archiving a completed scan", async () => {- const root = await temporaryDirectory();- const scanDir = join(root, "scan");- const archivedScanDir = `${scanDir}.previous-20260729T000000Z`;- await mkdir(scanDir, { mode: 0o700 });- await mkdir(archivedScanDir, { mode: 0o700 });-- const python = Bun.which("python3") ?? Bun.which("python");- expect(python).not.toBeNull();- const result = runNodePython(python!, [- "-c",- [- "import argparse, json, sqlite3, sys",- "from pathlib import Path",- "sys.path.insert(0, sys.argv[1])",- "from workbench_scan_start import archive_scan",- "scan_dir = Path(sys.argv[2])",- "archived_scan_dir = Path(sys.argv[3])",- "connection = sqlite3.connect(':memory:')",- "connection.row_factory = sqlite3.Row",- "connection.execute('CREATE TABLE scans (id TEXT PRIMARY KEY, status TEXT NOT NULL, scan_dir TEXT NOT NULL, updated_at TEXT NOT NULL)')",- "connection.execute('CREATE TABLE scan_artifacts (scan_id TEXT NOT NULL, kind TEXT NOT NULL, path TEXT NOT NULL, PRIMARY KEY (scan_id, kind))')",- "connection.execute('CREATE TABLE finding_workflows (scan_id TEXT, scan_dir TEXT NOT NULL, results_json TEXT NOT NULL)')",- "connection.execute('INSERT INTO scans VALUES (?, ?, ?, ?)', ('previous-scan', 'complete', str(scan_dir), 'before'))",- "artifacts = {'coverage': 'coverage.json', 'findings': 'findings.json', 'manifest': 'scan-manifest.json', 'markdownReport': 'report.md'}",- "connection.executemany('INSERT INTO scan_artifacts VALUES (?, ?, ?)', [('previous-scan', kind, str(scan_dir / path)) for kind, path in artifacts.items()])",- "args = argparse.Namespace(archive_existing=True, archived_scan_dir=str(archived_scan_dir))",- "with archive_scan(connection, args, scan_dir, 'after', lambda path: path.resolve(strict=True)):",- " pass",- "scan = connection.execute('SELECT scan_dir FROM scans WHERE id = ?', ('previous-scan',)).fetchone()",- "rows = connection.execute('SELECT kind, path FROM scan_artifacts WHERE scan_id = ? ORDER BY kind', ('previous-scan',))",- "print(json.dumps({'scanDir': scan['scan_dir'], 'artifacts': [dict(row) for row in rows]}))",- ].join("\n"),- join(PLUGIN_ROOT, "scripts"),- scanDir,- archivedScanDir,- ]);-- expect(result.status).toBe(0);- expect(result.stderr).toBe("");- expect(JSON.parse(result.stdout)).toEqual({- scanDir: archivedScanDir,- artifacts: [- { kind: "coverage", path: join(archivedScanDir, "coverage.json") },- { kind: "findings", path: join(archivedScanDir, "findings.json") },- { kind: "manifest", path: join(archivedScanDir, "scan-manifest.json") },- { kind: "markdownReport", path: join(archivedScanDir, "report.md") },- ],- });- });-- test("does not strand completed scan artifacts without an archive path", async () => {- const root = await temporaryDirectory();- const scanDir = join(root, "scan");- await mkdir(scanDir, { mode: 0o700 });-- const python = Bun.which("python3") ?? Bun.which("python");- expect(python).not.toBeNull();- const result = runNodePython(python!, [- "-c",- [- "import argparse, sqlite3, sys",- "from pathlib import Path",- "sys.path.insert(0, sys.argv[1])",- "from workbench_scan_start import archive_scan",- "scan_dir = Path(sys.argv[2])",- "connection = sqlite3.connect(':memory:')",- "connection.row_factory = sqlite3.Row",- "connection.execute('CREATE TABLE scans (id TEXT PRIMARY KEY, status TEXT NOT NULL, scan_dir TEXT NOT NULL, updated_at TEXT NOT NULL)')",- "connection.execute('CREATE TABLE scan_artifacts (scan_id TEXT NOT NULL, kind TEXT NOT NULL, path TEXT NOT NULL, PRIMARY KEY (scan_id, kind))')",- "connection.execute('INSERT INTO scans VALUES (?, ?, ?, ?)', ('previous-scan', 'complete', str(scan_dir), 'before'))",- "connection.execute('INSERT INTO scan_artifacts VALUES (?, ?, ?)', ('previous-scan', 'coverage', str(scan_dir / 'coverage.json')))",- "args = argparse.Namespace(archive_existing=True, archived_scan_dir=None)",- "with archive_scan(connection, args, scan_dir, 'after', lambda path: path.resolve(strict=True)):",- " pass",- ].join("\n"),- join(PLUGIN_ROOT, "scripts"),- scanDir,- ]);-- expect(result.status).toBe(1);- expect(result.stderr).toContain(- "The archived scan directory is required to preserve existing scan artifacts.",- );- expect(await readdir(root)).toEqual(["scan"]);- });-for (const readonly of [false, true]) {test.skipIf(diff --git a/sdk/typescript/tests-ts/scan-recovery.test.ts b/sdk/typescript/tests-ts/scan-recovery.test.tsindex 54be7699d..7d33fc088 100644--- a/sdk/typescript/tests-ts/scan-recovery.test.ts+++ b/sdk/typescript/tests-ts/scan-recovery.test.ts@@ -1,8 +1,12 @@import { spawnSync } from "node:child_process";-import { mkdir, readFile, writeFile } from "node:fs/promises";+import { mkdir, readdir, readFile, rename, writeFile } from "node:fs/promises";import { join } from "node:path";+import { Database } from "bun:sqlite";import { afterEach, describe, expect, test } from "bun:test";-import { workbenchCommand } from "./support/workbench-command.js";+import {+ scanRegistrationArguments,+ workbenchCommand,+} from "./support/workbench-command.js";import { runNodePython } from "./support/python-probe.js";import { copyCompletedScanFixture, PLUGIN_ROOT } from "./plugin-root.js";import { createApiTestFixtures } from "./support/temporary-directories.js";@@ -185,6 +189,53 @@ async function completeScan(fixture: ScanFixture): Promise<ScanSummary> {}describe("scan publication and artifact recovery", () => {+ test("preserves recorded artifact paths when archiving a completed scan", async () => {+ const fixture = await startDraftScan();+ await completeScan(fixture);+ const { scanDir, scanId } = fixture;+ using database = new Database(join(fixture.stateDir, "workbench.sqlite3"));+ // Older scans also registered the coverage document as an artifact.+ database+ .query(+ "INSERT OR IGNORE INTO scan_artifacts (scan_id, kind, path, created_at) VALUES (?, 'coverage', ?, CURRENT_TIMESTAMP)",+ )+ .run(scanId, join(scanDir, "coverage.json"));+ const archived = scanDir + ".previous-fixture";+ await rename(scanDir, archived);+ await mkdir(scanDir, { mode: 0o700 });+ const registration = [+ ...scanRegistrationArguments(fixture.repository, scanDir),+ "--archive-existing",+ ];++ await expect(workbench(fixture, registration)).rejects.toThrow(+ "The archived scan directory is required to preserve existing scan artifacts.",+ );+ expect(await readdir(scanDir)).toEqual([]);+ await workbench(fixture, [+ ...registration,+ "--archived-scan-dir",+ archived,+ ]);+ expect(+ database.query("SELECT scan_dir FROM scans WHERE id = ?").get(scanId),+ ).toEqual({+ scan_dir: archived,+ });+ expect(+ database+ .query(+ "SELECT kind, path FROM scan_artifacts WHERE scan_id = ? ORDER BY kind",+ )+ .all(scanId),+ ).toEqual([+ { kind: "coverage", path: join(archived, "coverage.json") },+ { kind: "findings", path: join(archived, "findings.json") },+ { kind: "manifest", path: join(archived, "scan-manifest.json") },+ { kind: "markdownReport", path: join(archived, "report.md") },+ ]);+ });+test.each(["scan", "rerun", "resume"] as const)("%s full-output includes sealed findings after execution throws",async (command) => {