Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

perf: speed up plugin setup and defer CLI prompts (#2146)

Michael D'Angelod2714476c39c
diff --git a/plugins/codex-security/mcp-app/src/server/workbench-process.ts b/plugins/codex-security/mcp-app/src/server/workbench-process.ts
index 455a3ffd8..cabe2ddea 100644
--- a/plugins/codex-security/mcp-app/src/server/workbench-process.ts
+++ b/plugins/codex-security/mcp-app/src/server/workbench-process.ts
@@ -1,8 +1,13 @@
export const WORKBENCH_PYTHON = `
import json, sys
from pathlib import Path
-sys.path.insert(0, str(Path(sys.argv.pop(1)).resolve().parent))
-import workbench_db
-sys.argv = [workbench_db.__file__, *json.loads(sys.stdin.buffer.readline())]
-workbench_db.main()
+script = Path(sys.argv.pop(1)).resolve()
+sys.path.insert(0, str(script.parent))
+args = json.loads(sys.stdin.buffer.readline())
+sys.argv = [str(script), *args]
+if args and args[0] in {"inspect-target", "inspect-setup"}:
+ from workbench_setup import main
+else:
+ from workbench_db import main
+main()
`;
diff --git a/plugins/codex-security/mcp-app/tests/test_workbench_state.ts b/plugins/codex-security/mcp-app/tests/test_workbench_state.ts
index 32dfd5560..206483b88 100644
--- a/plugins/codex-security/mcp-app/tests/test_workbench_state.ts
+++ b/plugins/codex-security/mcp-app/tests/test_workbench_state.ts
@@ -117,7 +117,32 @@ try {
);
assert.equal(await readFile(defaultState, "utf8"), "occupied state path\n");
+ const inspectSetup = [
+ "inspect-setup",
+ "--target-path",
+ targetPath,
+ "--mode",
+ "standard",
+ "--scope=.",
+ ];
+ const inspection = runWorkbench(
+ inspectSetup,
+ { ...explicitEnvironment, PYTHONPROFILEIMPORTTIME: "1" },
+ true,
+ );
+ assert.equal(inspection.status, 0, inspection.stderr);
+ assert.equal(JSON.parse(inspection.stdout).target.targetPath, targetPath);
+ assert.doesNotMatch(
+ inspection.stderr,
+ /\b(?:workbench_db|finalize_scan_contract)\s*$/mu,
+ );
+
for (const args of [
+ inspectSetup,
+ ["inspect-target", "--help"],
+ ["inspect-setup", "--help"],
+ [...inspectSetup, "--unknown"],
+ ["inspect-target", "--target-path", targetPath, "--unknown"],
["--help"],
["create-workspace", "--help"],
["resolve-scan-root"],
diff --git a/plugins/codex-security/plugin-files.json b/plugins/codex-security/plugin-files.json
index 07301c0eb..9dcfc9ccd 100644
--- a/plugins/codex-security/plugin-files.json
+++ b/plugins/codex-security/plugin-files.json
@@ -105,6 +105,7 @@
"scripts/workbench_scan_start.py",
"scripts/workbench_scan_usage.py",
"scripts/workbench_schema.py",
+ "scripts/workbench_setup.py",
"scripts/workbench_source_excerpt.py",
"scripts/workbench_source_scopes.py",
"scripts/workbench_target.py",
diff --git a/plugins/codex-security/scripts/workbench_cli.py b/plugins/codex-security/scripts/workbench_cli.py
index 37df392c0..8660419f9 100644
--- a/plugins/codex-security/scripts/workbench_cli.py
+++ b/plugins/codex-security/scripts/workbench_cli.py
@@ -8,7 +8,6 @@ from pathlib import Path
# Some plugin hosts launch Python with safe-path isolation enabled.
sys.path.insert(0, str(Path(__file__).resolve().parent))
-import deep_scan_workbench as deep_scan
from workbench_constants import (
DIFF_TARGET_KINDS,
EXPORT_FORMATS,
@@ -30,7 +29,7 @@ def add_user_context(parser: argparse.ArgumentParser, *, required: bool = False)
context.add_argument("--user-context-stdin", action="store_true")
-def parse_args(description: str) -> argparse.Namespace:
+def parse_args(description: str, *, inspection_only: bool = False) -> argparse.Namespace:
parser = argparse.ArgumentParser(description=description)
subparsers = parser.add_subparsers(dest="command", required=True)
@@ -82,6 +81,14 @@ def parse_args(description: str) -> argparse.Namespace:
diff_parser.add_argument("--diff-head-revision")
diff_parser.add_argument("--diff-content-digest")
+ if inspection_only:
+ # Unknown arguments use the full parser below for its normal usage diagnostic.
+ args, unknown = parser.parse_known_args()
+ if not unknown:
+ return args
+
+ import deep_scan_workbench as deep_scan
+
start_headless_standard_scan = add_command(
"start-headless-standard-scan", "--thread-id", "--target-path", "--scope"
)
diff --git a/plugins/codex-security/scripts/workbench_constants.py b/plugins/codex-security/scripts/workbench_constants.py
index 98b610335..a5441e42c 100644
--- a/plugins/codex-security/scripts/workbench_constants.py
+++ b/plugins/codex-security/scripts/workbench_constants.py
@@ -62,6 +62,15 @@ EMPTY_GIT_TREES = {
}
+def optional_text(value: str | None, *, maximum: int | None = None) -> str | None:
+ if value is None:
+ return None
+ normalized = value.strip()
+ if maximum is not None and len(normalized) > maximum:
+ raise SystemExit(f"Text value must be no longer than {maximum} characters.")
+ return normalized or None
+
+
def positive_int(value: str) -> int:
parsed = int(value)
if parsed < 1:
diff --git a/plugins/codex-security/scripts/workbench_db.py b/plugins/codex-security/scripts/workbench_db.py
index be917615c..10ba234bd 100644
--- a/plugins/codex-security/scripts/workbench_db.py
+++ b/plugins/codex-security/scripts/workbench_db.py
@@ -43,7 +43,6 @@ import workbench_remediation as remediation_state
import workbench_saved_results as saved_results
import workbench_scan_history as scan_history
import workbench_scan_usage as scan_usage
-from deep_scan_config import resolve_deep_scan_setup
from finalize_scan_contract import (
PRODUCER_NAME,
ContractError,
@@ -62,9 +61,6 @@ from workbench_constants import (
ARTIFACTS,
CLAIM_LEASE_SECONDS,
DELIVERED_ACTION_LEASE_SECONDS,
- DIFF_TARGET_KINDS,
- EMPTY_GIT_TREE,
- EMPTY_GIT_TREES,
FINDING_ABSOLUTE_PATH_BYTES,
FINDING_LEVEL_BYTES,
FINDING_LOCATION_PATH_BYTES,
@@ -96,6 +92,17 @@ from workbench_schema import (
from workbench_schema import (
apply_migrations as apply_schema_migrations,
)
+from workbench_setup import (
+ inspect_command,
+ inspect_selected_setup,
+ inspect_setup_values,
+ require_diff_target,
+ require_review_changes_target,
+ require_scannable_target,
+ require_scope,
+ require_target,
+ resolve_git_commit,
+)
from workbench_source_excerpt import finding_source_excerpt
from workbench_source_scopes import (
capture_source_scopes,
@@ -111,7 +118,6 @@ from workbench_target import (
diff_snapshot_digest,
directory_content_digest,
directory_snapshot_regular_file_count,
- git_bytes,
git_command,
git_output,
git_revision,
@@ -119,7 +125,6 @@ from workbench_target import (
git_target_metadata,
git_worktree_context,
remediation_checkout_snapshot,
- require_git_worktree_head,
require_remediation_target,
require_scan_target_identity,
require_scan_target_unchanged,
@@ -267,168 +272,6 @@ def apply_migrations(connection: sqlite3.Connection, *, immediate: bool = False)
)
-def require_target(value: str) -> Path:
- expanded = Path(value).expanduser()
- if not expanded.is_absolute():
- raise SystemExit("Scan target must be an absolute local directory path.")
- target = expanded.resolve()
- if not target.is_dir():
- raise SystemExit(f"Scan target is not a readable local directory: {target}")
- return target
-
-
-def inspect_target(target_path: str) -> dict[str, Any]:
- target = require_target(target_path)
- return {
- "displayName": target.name,
- "targetMetadata": git_target_metadata(target),
- "targetPath": str(target),
- }
-
-
-def resolve_git_commit(target: Path, revision: str, label: str) -> str:
- value = optional_text(revision, maximum=512)
- if not value:
- raise SystemExit(f"{label} is required.")
- resolved = git_output(
- target,
- "rev-parse",
- "--verify",
- "--end-of-options",
- f"{value}^{{commit}}",
- )
- if resolved is None:
- raise SystemExit(f"{label} does not resolve to a local Git commit: {value}")
- return resolved
-
-
-def require_diff_target(
- target: Path,
- kind: str | None,
- base_revision: str | None,
- head_revision: str | None,
- content_digest: str | None,
-) -> dict[str, str]:
- current_head = require_review_changes_target(target)
- if kind not in DIFF_TARGET_KINDS:
- raise SystemExit("Choose which Git changes to review before starting a diff scan.")
- if kind == "working_tree":
- base = resolve_git_commit(target, base_revision or "HEAD", "Working-tree base")
- head = resolve_git_commit(target, head_revision or current_head, "Working-tree HEAD")
- current_digest = worktree_content_digest(target)
- if base != current_head or head != current_head:
- raise SystemExit(
- "Repository HEAD changed after these working-tree changes were selected. "
- "Select Uncommitted changes again."
- )
- if content_digest and content_digest != current_digest:
- raise SystemExit(
- "Working-tree contents changed after they were selected. "
- "Select Uncommitted changes again."
- )
- return {
- "kind": kind,
- "baseRevision": current_head,
- "headRevision": current_head,
- "contentDigest": current_digest,
- }
- if kind == "commit":
- head = resolve_git_commit(target, head_revision or "", "Commit")
- commit = git_bytes(target, "cat-file", "-p", head)
- if commit is None:
- raise SystemExit(f"Commit is not available in the local checkout: {head}")
- parent_line = next(
- (
- line
- for line in commit.split(b"\n\n", 1)[0].splitlines()
- if line.startswith(b"parent ")
- ),
- None,
- )
- if parent_line is None:
- parent = EMPTY_GIT_TREES[git_output(target, "rev-parse", "--show-object-format")]
- else:
- parent = resolve_git_commit(
- target,
- parent_line.removeprefix(b"parent ").decode("ascii").strip(),
- "Commit parent",
- )
- if base_revision and base_revision != parent:
- supplied_base = (
- base_revision
- if base_revision == EMPTY_GIT_TREE
- else resolve_git_commit(target, base_revision, "Commit base")
- )
- if supplied_base != parent:
- raise SystemExit("Commit base revision must match the selected commit's parent.")
- return {"kind": kind, "baseRevision": parent, "headRevision": head}
- base = resolve_git_commit(target, base_revision or "", "Base revision")
- head = resolve_git_commit(target, head_revision or "", "Head revision")
- if base == head:
- raise SystemExit("Base and head revisions must identify different commits.")
- return {"kind": kind, "baseRevision": base, "headRevision": head}
-
-
-def inspect_setup_values(
- target_path: str,
- scope: str,
- mode: str,
- diff_target_kind: str | None,
- diff_base_revision: str | None,
- diff_head_revision: str | None,
- diff_content_digest: str | None,
-) -> dict[str, Any]:
- target = require_target(target_path)
- require_scannable_target(target)
- normalized_scope = require_scope(scope, mode, target)
- if mode == "diff" and normalized_scope != ".":
- raise SystemExit("Review changes requires the whole target; use scope '.'.")
- if mode != "diff" and any(
- value is not None
- for value in (
- diff_target_kind,
- diff_base_revision,
- diff_head_revision,
- diff_content_digest,
- )
- ):
- raise SystemExit("A Git diff target requires Review changes mode.")
- diff_target = (
- require_diff_target(
- target,
- diff_target_kind,
- diff_base_revision,
- diff_head_revision,
- diff_content_digest,
- )
- if mode == "diff"
- else None
- )
- return {
- "diffTarget": diff_target,
- "scope": normalized_scope,
- "target": inspect_target(str(target)),
- }
-
-
-def require_review_changes_target(target: Path) -> str:
- revision = require_git_worktree_head(target)
- repository_root = git_output(target, "rev-parse", "--show-toplevel")
- if repository_root is None or not Path(repository_root).samefile(target):
- raise SystemExit(
- "Review changes requires the checked-out Git repository root as the target."
- )
- return revision
-
-
-def require_scannable_target(target: Path) -> None:
- metadata = git_target_metadata(target)
- if metadata["isGit"] and not metadata["isWorktree"]:
- raise SystemExit(
- "Codex Security requires a checked-out worktree, not a bare Git repository."
- )
-
-
def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
# Older scans did not record path kinds. Retain their lexical scope semantics
# rather than infer the original target from a possibly changed checkout.
@@ -609,30 +452,6 @@ def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None
raise SystemExit("scan-manifest.json scope must stay inside the workbench scan scope.")
-def require_scope(scope: str, mode: str, target: Path) -> str:
- value = scope if scope.strip() else "."
- requested_scope = Path(value)
- if "\\" in value and (os.name != "nt" or not requested_scope.is_absolute()):
- raise SystemExit("Scan scope must use repository-relative POSIX paths.")
- if ".." in requested_scope.parts:
- raise SystemExit("Scan scope must stay inside the scanned target.")
- try:
- resolved_scope = (
- requested_scope if requested_scope.is_absolute() else target / requested_scope
- ).resolve()
- relative_scope = resolved_scope.relative_to(target)
- except (RuntimeError, ValueError) as exc:
- raise SystemExit("Scan scope must stay inside the scanned target.") from exc
- normalized = relative_scope.as_posix() or "."
- if not normalized.strip():
- normalized = "./" + normalized
- if mode == "deep" and normalized != ".":
- raise SystemExit("Deep Scan is repository-wide and cannot use a scoped path.")
- if not resolved_scope.is_dir():
- raise SystemExit("Scan scope must reference an existing directory inside the target.")
- return normalized
-
-
def require_workspace(connection: sqlite3.Connection, workspace_id: str) -> sqlite3.Row:
workspace_id = require_uuid(workspace_id, "workspace-id")
row = connection.execute("SELECT * FROM workspaces WHERE id = ?", (workspace_id,)).fetchone()
@@ -740,25 +559,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
return workspace_state(connection, workspace_id)
-def inspect_selected_setup(args: argparse.Namespace) -> dict[str, Any]:
- inspected = inspect_setup_values(
- args.target_path,
- args.scope,
- args.mode,
- args.diff_target_kind,
- args.diff_base_revision,
- args.diff_head_revision,
- args.diff_content_digest,
- )
- if args.mode == "deep":
- inspected["deepScanConfig"] = resolve_deep_scan_setup(
- os.cpu_count() or 1, args.deep_scan_project_json
- )
- elif args.deep_scan_project_json is not None:
- raise SystemExit("Project Deep Scan settings require Deep Scan mode.")
- return inspected
-
-
def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
workspace = require_workspace(connection, args.workspace_id)
if workspace["active_scan_id"]:
@@ -3304,12 +3104,8 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
if args.command == "resolve-scan-root":
print(json.dumps({"scanRoot": str(resolve_scan_root(args.scan_root))}))
return
- if args.command == "inspect-target":
- result = inspect_target(args.target_path)
- print(json.dumps(result, allow_nan=False, sort_keys=True))
- return
- if args.command == "inspect-setup":
- print(json.dumps(inspect_selected_setup(args), allow_nan=False, sort_keys=True))
+ if args.command in {"inspect-target", "inspect-setup"}:
+ print(json.dumps(inspect_command(args), allow_nan=False, sort_keys=True))
return
if args.command in {"save-artifact", "read-artifact"}:
print(json.dumps(saved_results.read_or_save_artifact(args)))
diff --git a/plugins/codex-security/scripts/workbench_setup.py b/plugins/codex-security/scripts/workbench_setup.py
new file mode 100644
index 000000000..6fa406952
--- /dev/null
+++ b/plugins/codex-security/scripts/workbench_setup.py
@@ -0,0 +1,239 @@
+"""Read-only target and setup inspection shared by the MCP server and workbench."""
+
+from __future__ import annotations
+
+import argparse
+import json
+import os
+import sys
+from pathlib import Path
+from typing import Any
+
+from deep_scan_config import resolve_deep_scan_setup
+from workbench_cli import parse_args
+from workbench_constants import DIFF_TARGET_KINDS, EMPTY_GIT_TREE, EMPTY_GIT_TREES, optional_text
+from workbench_target import (
+ git_bytes,
+ git_output,
+ git_target_metadata,
+ require_git_worktree_head,
+ worktree_content_digest,
+)
+
+
+def require_target(value: str) -> Path:
+ expanded = Path(value).expanduser()
+ if not expanded.is_absolute():
+ raise SystemExit("Scan target must be an absolute local directory path.")
+ target = expanded.resolve()
+ if not target.is_dir():
+ raise SystemExit(f"Scan target is not a readable local directory: {target}")
+ return target
+
+
+def inspect_target(target: Path) -> dict[str, Any]:
+ return {
+ "displayName": target.name,
+ "targetMetadata": git_target_metadata(target),
+ "targetPath": str(target),
+ }
+
+
+def resolve_git_commit(target: Path, revision: str, label: str) -> str:
+ value = optional_text(revision, maximum=512)
+ if not value:
+ raise SystemExit(f"{label} is required.")
+ resolved = git_output(
+ target,
+ "rev-parse",
+ "--verify",
+ "--end-of-options",
+ f"{value}^{{commit}}",
+ )
+ if resolved is None:
+ raise SystemExit(f"{label} does not resolve to a local Git commit: {value}")
+ return resolved
+
+
+def require_diff_target(
+ target: Path,
+ kind: str | None,
+ base_revision: str | None,
+ head_revision: str | None,
+ content_digest: str | None,
+) -> dict[str, str]:
+ current_head = require_review_changes_target(target)
+ if kind not in DIFF_TARGET_KINDS:
+ raise SystemExit("Choose which Git changes to review before starting a diff scan.")
+ if kind == "working_tree":
+ base = resolve_git_commit(target, base_revision or "HEAD", "Working-tree base")
+ head = resolve_git_commit(target, head_revision or current_head, "Working-tree HEAD")
+ current_digest = worktree_content_digest(target)
+ if base != current_head or head != current_head:
+ raise SystemExit(
+ "Repository HEAD changed after these working-tree changes were selected. "
+ "Select Uncommitted changes again."
+ )
+ if content_digest and content_digest != current_digest:
+ raise SystemExit(
+ "Working-tree contents changed after they were selected. "
+ "Select Uncommitted changes again."
+ )
+ return {
+ "kind": kind,
+ "baseRevision": current_head,
+ "headRevision": current_head,
+ "contentDigest": current_digest,
+ }
+ if kind == "commit":
+ head = resolve_git_commit(target, head_revision or "", "Commit")
+ commit = git_bytes(target, "cat-file", "-p", head)
+ if commit is None:
+ raise SystemExit(f"Commit is not available in the local checkout: {head}")
+ parent_line = next(
+ (
+ line
+ for line in commit.split(b"\n\n", 1)[0].splitlines()
+ if line.startswith(b"parent ")
+ ),
+ None,
+ )
+ if parent_line is None:
+ parent = EMPTY_GIT_TREES[git_output(target, "rev-parse", "--show-object-format")]
+ else:
+ parent = resolve_git_commit(
+ target,
+ parent_line.removeprefix(b"parent ").decode("ascii").strip(),
+ "Commit parent",
+ )
+ if base_revision and base_revision != parent:
+ supplied_base = (
+ base_revision
+ if base_revision == EMPTY_GIT_TREE
+ else resolve_git_commit(target, base_revision, "Commit base")
+ )
+ if supplied_base != parent:
+ raise SystemExit("Commit base revision must match the selected commit's parent.")
+ return {"kind": kind, "baseRevision": parent, "headRevision": head}
+ base = resolve_git_commit(target, base_revision or "", "Base revision")
+ head = resolve_git_commit(target, head_revision or "", "Head revision")
+ if base == head:
+ raise SystemExit("Base and head revisions must identify different commits.")
+ return {"kind": kind, "baseRevision": base, "headRevision": head}
+
+
+def inspect_setup_values(
+ target_path: str,
+ scope: str,
+ mode: str,
+ diff_target_kind: str | None,
+ diff_base_revision: str | None,
+ diff_head_revision: str | None,
+ diff_content_digest: str | None,
+) -> dict[str, Any]:
+ target = require_target(target_path)
+ inspected = require_scannable_target(target)
+ normalized_scope = require_scope(scope, mode, target)
+ if mode == "diff" and normalized_scope != ".":
+ raise SystemExit("Review changes requires the whole target; use scope '.'.")
+ if mode != "diff" and any(
+ value is not None
+ for value in (
+ diff_target_kind,
+ diff_base_revision,
+ diff_head_revision,
+ diff_content_digest,
+ )
+ ):
+ raise SystemExit("A Git diff target requires Review changes mode.")
+ diff_target = (
+ require_diff_target(
+ target,
+ diff_target_kind,
+ diff_base_revision,
+ diff_head_revision,
+ diff_content_digest,
+ )
+ if mode == "diff"
+ else None
+ )
+ return {
+ "diffTarget": diff_target,
+ "scope": normalized_scope,
+ "target": inspected,
+ }
+
+
+def require_review_changes_target(target: Path) -> str:
+ revision = require_git_worktree_head(target)
+ repository_root = git_output(target, "rev-parse", "--show-toplevel")
+ if repository_root is None or not Path(repository_root).samefile(target):
+ raise SystemExit(
+ "Review changes requires the checked-out Git repository root as the target."
+ )
+ return revision
+
+
+def require_scannable_target(target: Path) -> dict[str, Any]:
+ inspected = inspect_target(target)
+ metadata = inspected["targetMetadata"]
+ if metadata["isGit"] and not metadata["isWorktree"]:
+ raise SystemExit(
+ "Codex Security requires a checked-out worktree, not a bare Git repository."
+ )
+ return inspected
+
+
+def require_scope(scope: str, mode: str, target: Path) -> str:
+ value = scope if scope.strip() else "."
+ requested_scope = Path(value)
+ if "\\" in value and (os.name != "nt" or not requested_scope.is_absolute()):
+ raise SystemExit("Scan scope must use repository-relative POSIX paths.")
+ if ".." in requested_scope.parts:
+ raise SystemExit("Scan scope must stay inside the scanned target.")
+ try:
+ resolved_scope = (
+ requested_scope if requested_scope.is_absolute() else target / requested_scope
+ ).resolve()
+ relative_scope = resolved_scope.relative_to(target)
+ except (RuntimeError, ValueError) as exc:
+ raise SystemExit("Scan scope must stay inside the scanned target.") from exc
+ normalized = relative_scope.as_posix() or "."
+ if not normalized.strip():
+ normalized = "./" + normalized
+ if mode == "deep" and normalized != ".":
+ raise SystemExit("Deep Scan is repository-wide and cannot use a scoped path.")
+ if not resolved_scope.is_dir():
+ raise SystemExit("Scan scope must reference an existing directory inside the target.")
+ return normalized
+
+
+def inspect_selected_setup(args: argparse.Namespace) -> dict[str, Any]:
+ inspected = inspect_setup_values(
+ args.target_path,
+ args.scope,
+ args.mode,
+ args.diff_target_kind,
+ args.diff_base_revision,
+ args.diff_head_revision,
+ args.diff_content_digest,
+ )
+ if args.mode == "deep":
+ inspected["deepScanConfig"] = resolve_deep_scan_setup(
+ os.cpu_count() or 1, args.deep_scan_project_json
+ )
+ elif args.deep_scan_project_json is not None:
+ raise SystemExit("Project Deep Scan settings require Deep Scan mode.")
+ return inspected
+
+
+def inspect_command(args: argparse.Namespace) -> dict[str, Any]:
+ if args.command == "inspect-target":
+ return inspect_target(require_target(args.target_path))
+ return inspect_selected_setup(args)
+
+
+def main() -> None:
+ sys.stdin.reconfigure(encoding="utf-8")
+ args = parse_args("Codex Security workbench persistence.", inspection_only=True)
+ print(json.dumps(inspect_command(args), allow_nan=False, sort_keys=True))
diff --git a/plugins/codex-security/scripts/workbench_validation.py b/plugins/codex-security/scripts/workbench_validation.py
index 8cdb31533..124269d34 100644
--- a/plugins/codex-security/scripts/workbench_validation.py
+++ b/plugins/codex-security/scripts/workbench_validation.py
@@ -16,6 +16,7 @@ from typing import Any
# Some plugin hosts launch Python with safe-path isolation enabled.
sys.path.insert(0, str(Path(__file__).resolve().parent))
import finalize_scan_contract as finalizer
+from workbench_constants import optional_text as optional_text
from workbench_scan_usage import TOKEN_FIELDS, valid_account_rate_limit
from workbench_scan_usage import (
_reject_nonstandard_json_number as reject_nonstandard_json_number,
@@ -45,15 +46,6 @@ def require_uuid(value: str, label: str) -> str:
raise SystemExit(f"{label} must be a UUID.") from exc
-def optional_text(value: str | None, *, maximum: int | None = None) -> str | None:
- if value is None:
- return None
- normalized = value.strip()
- if maximum is not None and len(normalized) > maximum:
- raise SystemExit(f"Text value must be no longer than {maximum} characters.")
- return normalized or None
-
-
def sqlite_busy(error: sqlite3.OperationalError) -> bool:
return "locked" in str(error).lower() or "busy" in str(error).lower()
diff --git a/plugins/codex-security/tests/test_git_inventory_regressions.py b/plugins/codex-security/tests/test_git_inventory_regressions.py
index 9e0965bd3..9a33642cb 100644
--- a/plugins/codex-security/tests/test_git_inventory_regressions.py
+++ b/plugins/codex-security/tests/test_git_inventory_regressions.py
@@ -25,7 +25,8 @@ def test_root_commit_message_does_not_supply_diff_parent(tmp_path: Path, workben
git(target, "commit", "--amend", "-qm", f"Synthetic root\n\nparent {previous}")
head = git(target, "rev-parse", "HEAD").decode()
diff = workbench_api["require_diff_target"](target, "commit", None, head, None)
- assert diff["baseRevision"] == workbench_api["EMPTY_GIT_TREE"]
+ empty_tree = git(target, "hash-object", "-t", "tree", "--stdin", input=b"").decode()
+ assert diff["baseRevision"] == empty_tree
def test_sha256_root_commit_uses_the_sha256_empty_tree(tmp_path: Path, workbench_api) -> None:
diff --git a/sdk/typescript/scripts/check-package.mjs b/sdk/typescript/scripts/check-package.mjs
index 2aba2953a..44c8da8fa 100644
--- a/sdk/typescript/scripts/check-package.mjs
+++ b/sdk/typescript/scripts/check-package.mjs
@@ -6,6 +6,7 @@ import {
readFileSync,
readdirSync,
rmSync,
+ writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
@@ -236,6 +237,8 @@ function extractedArchiveFiles() {
);
try {
chmodSync(extractionRoot, 0o700);
+ const fileList = join(extractionRoot, "members.list");
+ writeFileSync(fileList, [...logicalSizes.keys(), ""].join("\0"));
try {
tar([
"-m",
@@ -248,11 +251,14 @@ function extractedArchiveFiles() {
"-",
"-C",
extractionRoot,
- ...logicalSizes.keys(),
+ "--null",
+ "-T",
+ fileList,
]);
} finally {
privateExtractionDirectories(extractionRoot);
}
+ rmSync(fileList);
const archiveFiles = new Map();
let expandedBytes = 0;
diff --git a/sdk/typescript/src/bulk-scan-discovery.ts b/sdk/typescript/src/bulk-scan-discovery.ts
index 5901418d1..34259ce72 100644
--- a/sdk/typescript/src/bulk-scan-discovery.ts
+++ b/sdk/typescript/src/bulk-scan-discovery.ts
@@ -3,7 +3,6 @@ import { lstat, mkdir, writeFile } from "node:fs/promises";
import { join, resolve } from "node:path";
import { stdin } from "node:process";
import { Writable } from "node:stream";
-import { checkbox, confirm, input, search, Separator } from "@inquirer/prompts";
import { Octokit } from "@octokit/core";
import Papa from "papaparse";
import { createAuthenticatedGitHub } from "./github.js";
@@ -346,12 +345,17 @@ export function createTerminalPrompt(output: PromptOutput): BulkScanPrompt {
write: (value) => {
output.write(value);
},
- confirm: (message, defaultValue = false, signal) =>
- confirm({ message, default: defaultValue }, context(signal)),
- input: (message, defaultValue, signal) =>
- input({ message, default: defaultValue }, context(signal)),
- checkbox: (message, options, presentation, signal) =>
- checkbox(
+ async confirm(message, defaultValue = false, signal) {
+ const { confirm } = await import("@inquirer/prompts");
+ return confirm({ message, default: defaultValue }, context(signal));
+ },
+ async input(message, defaultValue, signal) {
+ const { input } = await import("@inquirer/prompts");
+ return input({ message, default: defaultValue }, context(signal));
+ },
+ async checkbox(message, options, presentation, signal) {
+ const { checkbox, Separator } = await import("@inquirer/prompts");
+ return checkbox(
{
message,
choices: [
@@ -367,9 +371,11 @@ export function createTerminalPrompt(output: PromptOutput): BulkScanPrompt {
required: presentation?.required,
},
context(signal),
- ),
- select: (message, options, presentation, signal) =>
- search(
+ );
+ },
+ async select(message, options, presentation, signal) {
+ const { search } = await import("@inquirer/prompts");
+ return search(
{
message,
...(presentation?.header === undefined
@@ -394,6 +400,7 @@ export function createTerminalPrompt(output: PromptOutput): BulkScanPrompt {
})),
},
context(signal),
- ),
+ );
+ },
};
}
diff --git a/sdk/typescript/tests-ts/package-tar-listing.test.ts b/sdk/typescript/tests-ts/package-tar-listing.test.ts
index 3bd2f4fb9..f415b43a0 100644
--- a/sdk/typescript/tests-ts/package-tar-listing.test.ts
+++ b/sdk/typescript/tests-ts/package-tar-listing.test.ts
@@ -1331,14 +1331,30 @@ describe("npm package tar listings", () => {
const contractPath = join(root, "plugin contract.json");
const logPath = join(root, "tar calls.jsonl");
const adjacentTarMarker = join(root, "archive tar ran");
+ // A valid plugin inventory can exceed the Windows process command-line limit.
+ const extraFiles = Array.from(
+ { length: 256 },
+ (_, index) => `fixtures/generated-plugin-document-${index}.md`,
+ );
const tarBytes = packageTar({
compatibleLayout: true,
rootDirectoryMode: 0o555,
readmeMode: 0,
+ additionalRecords: extraFiles.map((file) =>
+ tarRecord(Buffer.alloc(0), {
+ name: `package/_bundled_plugin/${file}`,
+ }),
+ ),
});
const archiveContents = gzipSync(tarBytes, { level: 0 });
writeFileSync(archivePath, archiveContents);
- writeFileSync(contractPath, JSON.stringify(pluginContract));
+ writeFileSync(
+ contractPath,
+ JSON.stringify({
+ ...pluginContract,
+ shippedExact: [...pluginContract.shippedExact, ...extraFiles],
+ }),
+ );
const environment: NodeJS.ProcessEnv = { ...process.env };
delete environment["CODEX_SECURITY_EXPECTED_GIT_HEAD"];
diff --git a/sdk/typescript/tests-ts/workbench-windows-compatibility.test.ts b/sdk/typescript/tests-ts/workbench-windows-compatibility.test.ts
index 82d7e9c95..6d5dd2ea9 100644
--- a/sdk/typescript/tests-ts/workbench-windows-compatibility.test.ts
+++ b/sdk/typescript/tests-ts/workbench-windows-compatibility.test.ts
@@ -28,7 +28,7 @@ test("normalizes absolute Windows scopes without accepting escapes", () => {
"from pathlib import PureWindowsPath",
"from types import SimpleNamespace",
"sys.path.insert(0, sys.argv[1])",
- "import workbench_db as workbench",
+ "import workbench_setup as workbench",
"class WindowsPath(PureWindowsPath):",
" def resolve(self): return self",
" def is_dir(self): return True",