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 explicit usage database paths (#2556)
Michael D'Angelo1c4431b36e6f
diff --git a/plugins/codex-security/scripts/workbench_scan_usage.py b/plugins/codex-security/scripts/workbench_scan_usage.pyindex 5af54fef4..f06df3788 100644--- a/plugins/codex-security/scripts/workbench_scan_usage.py+++ b/plugins/codex-security/scripts/workbench_scan_usage.py@@ -607,9 +607,9 @@ def _scan_worker_directories(def _codex_state_database() -> Path | None:- configured_database = os.environ.get("CODEX_STATE_DB", "").strip()- if configured_database:- path = Path(configured_database).expanduser()+ configured_database = os.environ.get("CODEX_STATE_DB", "")+ if configured_database.strip():+ path = Path(os.path.expanduser(configured_database))return path.resolve() if path.is_file() and os.access(path, os.R_OK) else Noneconfigured_home = os.environ.get("CODEX_HOME", "")diff --git a/plugins/codex-security/tests/test_workbench_scan_usage.py b/plugins/codex-security/tests/test_workbench_scan_usage.pyindex 3e51d5f2a..bf85a47d8 100644--- a/plugins/codex-security/tests/test_workbench_scan_usage.py+++ b/plugins/codex-security/tests/test_workbench_scan_usage.py@@ -9,6 +9,7 @@ import subprocessimport sysimport tempfileimport uuid+from contextlib import closingfrom dataclasses import dataclass, replacefrom datetime import datetime, timedeltafrom pathlib import Path@@ -328,7 +329,7 @@ def _state_graph() -> None:sqlite_home = Path(environment["CODEX_SQLITE_HOME"])sqlite_home.mkdir(parents=True, exist_ok=True)- with sqlite3.connect(sqlite_home / "state_5.sqlite") as connection:+ with closing(sqlite3.connect(sqlite_home / "state_5.sqlite")) as connection, connection:connection.execute("CREATE TABLE threads ""(id TEXT PRIMARY KEY, rollout_path TEXT NOT NULL, cwd TEXT, created_at INTEGER)"@@ -1307,6 +1308,46 @@ def test_usage_finds_state_database_in_configured_home(assert scan_usage._codex_state_database() == database.resolve()[email protected]_platform+ "spelling",+ ["leading-relative", "trailing-absolute"]+ + ([] if sys.platform == "win32" else ["literal-tilde"]),+)+def test_completion_reads_the_literal_usage_database(+ tmp_path: Path, spelling: str, monkeypatch: pytest.MonkeyPatch+) -> None:+ fixture = _start_scan(tmp_path)+ counted = fixture.started_at + timedelta(microseconds=1)+ fixture.write_parent_rollout([_token_event(counted, 18, 2)])+ original = Path(fixture.environment["CODEX_SQLITE_HOME"]) / "state_5.sqlite"+ selected = (+ tmp_path+ / {+ "leading-relative": " usage.sqlite",+ "trailing-absolute": "usage.sqlite\N{NO-BREAK SPACE}"+ if sys.platform == "win32"+ else "usage.sqlite ",+ "literal-tilde": "~synthetic-usage.sqlite",+ }[spelling]+ )+ original.rename(selected)++ neighbor = tmp_path / "neighbor"+ neighbor.mkdir()+ other_rollout = _rollout(neighbor, "scan-parent", [_token_event(counted, 96, 2)])+ _state_graph(fixture.environment, {"scan-parent": other_rollout}, [])+ original.rename(tmp_path / "usage.sqlite")+ monkeypatch.chdir(tmp_path)+ fixture.environment["CODEX_STATE_DB"] = (+ str(selected) if spelling == "trailing-absolute" else selected.name+ )++ usage = _complete_scan(fixture)["scan"]["usage"]+ assert usage["coverage"] == "complete"+ assert usage["totalTokens"] == 20++def test_completion_reports_unavailable_without_fabricating_zero(tmp_path: Path) -> None:fixture = _start_scan(tmp_path)usage = _complete_scan(fixture)["scan"]["usage"]