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(plugin): deduplicate tracked ignored files in scoped inventories (#1077)

124874724c0d81
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_inventory.mjs b/plugins/codex-security/mcp-app/tests/test_artifact_inventory.mjs
index 755ecee48..efd4d3ed3 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_inventory.mjs
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_inventory.mjs
@@ -33,6 +33,7 @@ const inventory = await import(
try {
await testSchemasAreBoundAndExact();
await testPrepareUsesTheExistingStandardGenerator();
+ await testPrepareListsIgnoredTrackedFilesOnce();
await testPrepareExcludesGitMetadata();
await testPrepareUsesOnlyAuthoritativeDiffChanges();
await testPrepareIncludesStagedAndUnstagedChanges();
@@ -148,6 +149,39 @@ async function testPrepareUsesTheExistingStandardGenerator() {
);
}
+async function testPrepareListsIgnoredTrackedFilesOnce() {
+ const fixture = await createFixture("ignored tracked files");
+ await initializeRepository(fixture.repoRoot);
+ await writeRepositoryFile(fixture.repoRoot, ".gitignore", "generated/\n");
+ for (const name of ["a.ts", "b.ts"]) {
+ await writeRepositoryFile(
+ fixture.repoRoot,
+ `generated/${name}`,
+ "export const value = 1;\n",
+ );
+ }
+ await runGit(fixture.repoRoot, "add", "--force", "--", "generated");
+ const context = { ...fixture.scan, scope: "generated" };
+
+ assert.deepEqual(await inventory.prepareCodexSecurityReviewItems(context), {
+ reviewItemsTotal: 2,
+ });
+ const first = await inventory.listCodexSecurityReviewItems(context, {
+ limit: 1,
+ });
+ assert.deepEqual(first, {
+ items: [{ path: "generated/a.ts" }],
+ nextCursor: "1",
+ });
+ assert.deepEqual(
+ await inventory.listCodexSecurityReviewItems(context, {
+ cursor: first.nextCursor,
+ limit: 1,
+ }),
+ { items: [{ path: "generated/b.ts" }] },
+ );
+}
+
async function testPrepareExcludesGitMetadata() {
const fixture = await createFixture("nested repositories");
for (const [name, source] of [
diff --git a/plugins/codex-security/scripts/generate_in_scope_files.py b/plugins/codex-security/scripts/generate_in_scope_files.py
index ad3d843ae..8e61e5009 100644
--- a/plugins/codex-security/scripts/generate_in_scope_files.py
+++ b/plugins/codex-security/scripts/generate_in_scope_files.py
@@ -153,9 +153,8 @@ def generate_in_scope_files(repository: Path, scope: str, output: Path) -> int:
"Repository contains a path that cannot fit in the file inventory"
)
rows.append(path + b"\n")
- rows.sort()
- return write_inventory(output, rows)
+ return write_inventory(output, sorted(set(rows)))
def committed_changed_paths(repository: Path, base: str, head: str) -> list[tuple[Path, str]]:
diff --git a/plugins/codex-security/tests/test_generate_in_scope_files.py b/plugins/codex-security/tests/test_generate_in_scope_files.py
index b06210af3..8a00ab9a7 100644
--- a/plugins/codex-security/tests/test_generate_in_scope_files.py
+++ b/plugins/codex-security/tests/test_generate_in_scope_files.py
@@ -159,6 +159,36 @@ def test_inventory_keeps_ignored_tracked_files_without_ignored_untracked_files(
assert "./app/ignored.skip" not in paths
+ ("scope", "absolute"),
+ [
+ (".", False),
+ ("ignored", False),
+ ("./ignored", False),
+ ("ignored/tracked.py", False),
+ ("./ignored/tracked.py", False),
+ ("ignored", True),
+ ("ignored/tracked.py", True),
+ ],
+)
+def test_inventory_lists_ignored_tracked_files_once(
+ tmp_path: Path, scope: str, absolute: bool
+) -> None:
+ repository = make_repository(tmp_path)
+ write_file(repository, "ignored/tracked.py")
+ git(repository, "add", "--force", "--", "ignored/tracked.py")
+ output = tmp_path / "in_scope_files.txt"
+
+ result = run_inventory(repository, str(repository / scope) if absolute else scope, output)
+
+ assert result.returncode == 0, result.stderr
+ rows = output.read_bytes().splitlines()
+ prefix = b"./" if scope == "." or scope.startswith("./") else b""
+ assert rows.count(prefix + b"ignored/tracked.py") == 1
+ assert rows == sorted(set(rows))
+ assert result.stdout == f"Recorded {len(rows)} in-scope files.\n"
+
+
@pytest.mark.parametrize(
("scope", "expected"),
[(".", "./vendor/lib/handler.py"), ("vendor", "vendor/lib/handler.py")],