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

test(workbench): make Git scope and sealed CSV fixtures portable (#2517)

Michael D'Angelo6df392cf0261
diff --git a/plugins/codex-security/tests/test_workbench_db_exports.py b/plugins/codex-security/tests/test_workbench_db_exports.py
index b5c7e7737..5098a445d 100644
--- a/plugins/codex-security/tests/test_workbench_db_exports.py
+++ b/plugins/codex-security/tests/test_workbench_db_exports.py
@@ -815,6 +815,7 @@ def test_deep_csv_export_adds_only_candidate_id_column(
assert closed_rows == {closed_occurrence: "wont_fix"}
def test_csv_export_escapes_newline_and_full_width_formula_prefixes(tmp_path: Path) -> None:
state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)
write_completed_contract(scan_dir, scan_id, target)
@@ -828,7 +829,7 @@ def test_csv_export_escapes_newline_and_full_width_formula_prefixes(tmp_path: Pa
scan_command(state_dir, "complete-scan", scan_id)
exported = scan_command(state_dir, "export-findings", scan_id, "--format", "csv")["export"]
- with Path(exported["path"]).open(newline="") as source:
+ with Path(exported["path"]).open(encoding="utf-8", newline="") as source:
row = next(csv.DictReader(source))
assert row["title"] == "'\n=1+1"
@@ -1082,6 +1083,7 @@ def test_primary_location_prefers_root_control_in_bounded_and_csv_results(
assert row["path"] == "root.py"
def test_csv_export_preserves_a_sealed_export(tmp_path: Path, workbench_api) -> None:
state_dir, target, scan_id, scan_dir = empty_target_scan(tmp_path)
write_completed_contract(scan_dir, scan_id, target)
@@ -1101,7 +1103,9 @@ def test_csv_export_preserves_a_sealed_export(tmp_path: Path, workbench_api) ->
}
)
manifest_path = scan_dir / "scan-manifest.json"
- manifest_path.write_text(json.dumps(manifest, allow_nan=False, indent=2, sort_keys=True) + "\n")
+ manifest_path.write_bytes(
+ (json.dumps(manifest, allow_nan=False, indent=2, sort_keys=True) + "\n").encode("utf-8")
+ )
run_workbench(state_dir, "complete-scan", "--scan-id", scan_id)
sealed_manifest = manifest_path.read_bytes()
diff --git a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
index 1bad134a3..d951e03b8 100644
--- a/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
+++ b/plugins/codex-security/tests/test_workbench_setup_and_migrations.py
@@ -771,14 +771,31 @@ def test_scan_start_rejects_submodule_at_unrecorded_revision(tmp_path: Path) ->
assert "revision recorded by the parent repository" in str(failed["stderr"])
-def test_nested_target_name_is_a_literal_git_pathspec(tmp_path: Path) -> None:
+ ("target_name", "outside_name"),
+ [
+ pytest.param(":(top,glob)**", "outside.py", id="top-glob", marks=pytest.mark.native_macos),
+ pytest.param(
+ "selected[ab]", "selecteda", id="bracket-glob", marks=pytest.mark.cross_platform
+ ),
+ ],
+)
+def test_nested_target_name_is_a_literal_git_pathspec(
+ tmp_path: Path, target_name: str, outside_name: str
+) -> None:
state_dir = tmp_path / "state"
repository = tmp_path / "repository"
initialize_git_repository(repository)
- target = repository / ":(top,glob)**"
- target.mkdir()
+ target = repository / target_name
+ try:
+ target.mkdir()
+ except OSError as error:
+ if target_name == ":(top,glob)**" and error.errno == errno.EINVAL:
+ pytest.skip("The filesystem cannot create a directory with Git top/glob magic.")
+ raise
+ outside = repository / outside_name
(target / "source.py").write_text("selected = True\n")
- (repository / "outside.py").write_text("outside = 1\n")
+ outside.write_text("outside = 1\n")
subprocess.run(["git", "add", "."], cwd=repository, check=True)
subprocess.run(["git", "commit", "-qm", "Add selected target"], cwd=repository, check=True)
revision = subprocess.check_output(
@@ -786,7 +803,8 @@ def test_nested_target_name_is_a_literal_git_pathspec(tmp_path: Path) -> None:
).strip()
workspace_id = str(create_saved_git_workspace(state_dir, target)["id"])
scan_id, scan_dir = start_workspace_scan(state_dir, workspace_id, tmp_path / "scans")
- (repository / "outside.py").write_text("outside = 2\n")
+ outside.write_text("outside = 2\n")
+ assert get_scan(state_dir, scan_id, "--check-target")["scan"]["scanId"] == scan_id
write_completed_contract(
scan_dir,
scan_id,