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

fix(targets): skip index paths under directories replaced by files (#2182)

1297b0a138ff17
diff --git a/plugins/codex-security/scripts/workbench_target.py b/plugins/codex-security/scripts/workbench_target.py
index f20e0442b..d262b439c 100644
--- a/plugins/codex-security/scripts/workbench_target.py
+++ b/plugins/codex-security/scripts/workbench_target.py
@@ -1018,7 +1018,7 @@ def copy_git_worktree_files(
source_path = _directory_link_boundary(repository, source_path, linked_prefixes)
relative = source_path.relative_to(repository)
metadata = source_path.lstat()
- except FileNotFoundError:
+ except (FileNotFoundError, NotADirectoryError):
continue
if relative in copied:
continue
diff --git a/plugins/codex-security/tests/test_workbench_target.py b/plugins/codex-security/tests/test_workbench_target.py
index 33b07d5e2..0d5cc129f 100644
--- a/plugins/codex-security/tests/test_workbench_target.py
+++ b/plugins/codex-security/tests/test_workbench_target.py
@@ -1353,6 +1353,20 @@ def test_git_context_preserves_trailing_root_whitespace(
assert (destination / "synthetic.txt").read_text() == "selected target content\n"
+def test_copy_skips_index_paths_under_a_directory_replaced_by_a_file(tmp_path: Path) -> None:
+ target = tmp_path / "target"
+ initialize_git_repository(target)
+ (target / "config").mkdir()
+ (target / "config" / "settings.py").write_text("tracked = True\n")
+ subprocess.run(["git", "add", "config"], cwd=target, check=True)
+ subprocess.run(["git", "commit", "-qm", "Add config"], cwd=target, check=True)
+ shutil.rmtree(target / "config")
+ (target / "config").write_text("replacement file\n")
+ destination = tmp_path / "copied"
+ WORKBENCH_TARGET["copy_git_worktree_files"](target, destination, ())
+ assert (destination / "config").read_text() == "replacement file\n"
+
+
def test_git_context_rejects_an_unrelated_configured_worktree(tmp_path: Path) -> None:
target = tmp_path / "target"
unrelated = tmp_path / "unrelated"