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

refactor(plugin): stream normalized candidate rows (#422)

mldangelo-oai14b36f9384d4
diff --git a/sdk/typescript/_bundled_plugin/scripts/normalize_candidates.py b/sdk/typescript/_bundled_plugin/scripts/normalize_candidates.py
index bcc5474a8..a445acd70 100644
--- a/sdk/typescript/_bundled_plugin/scripts/normalize_candidates.py
+++ b/sdk/typescript/_bundled_plugin/scripts/normalize_candidates.py
@@ -308,10 +308,6 @@ def main() -> None:
raise ValueError(f"{source} row {number}: {error}") from error
combined = combine(rows)
output.parent.mkdir(parents=True, exist_ok=True)
- payload = "".join(
- json.dumps(row, ensure_ascii=False, separators=(",", ":"), sort_keys=True) + "\n"
- for row in combined
- )
temporary: Path | None = None
try:
with tempfile.NamedTemporaryFile(
@@ -323,7 +319,11 @@ def main() -> None:
delete=False,
) as handle:
temporary = Path(handle.name)
- handle.write(payload)
+ for row in combined:
+ handle.write(
+ json.dumps(row, ensure_ascii=False, separators=(",", ":"), sort_keys=True)
+ + "\n"
+ )
temporary.replace(output)
finally:
if temporary is not None:
diff --git a/sdk/typescript/tests-ts/compact-diff-scan.test.ts b/sdk/typescript/tests-ts/compact-diff-scan.test.ts
index afcf871a8..2543c7c5f 100644
--- a/sdk/typescript/tests-ts/compact-diff-scan.test.ts
+++ b/sdk/typescript/tests-ts/compact-diff-scan.test.ts
@@ -302,11 +302,20 @@ describe("compact diff scan", () => {
test("keeps deleted inventory paths without accepting unsafe candidates", () => {
const { root, repository } = createRepository();
writeSource(repository, "src/handler.py", "value = 1\n");
+ writeSource(repository, "src/second.py", "value = 2\n");
const inventory = join(root, "in-scope.txt");
const input = join(root, "candidates.jsonl");
const output = join(root, "normalized.jsonl");
- writeFileSync(inventory, "src/deleted.py\nsrc/handler.py\n");
- writeFileSync(input, `${JSON.stringify(candidate("src/handler.py"))}\n`);
+ writeFileSync(inventory, "src/deleted.py\nsrc/handler.py\nsrc/second.py\n");
+ writeFileSync(
+ input,
+ [
+ candidate("src/handler.py"),
+ { ...candidate("src/second.py"), summary: "Résumé: missing guard" },
+ ]
+ .map((entry) => JSON.stringify(entry))
+ .join("\n") + "\n",
+ );
const args = [
"--input",
input,
@@ -325,10 +334,16 @@ describe("compact diff scan", () => {
"--allow-missing-in-scope",
);
expect(accepted.status, accepted.stderr).toBe(0);
- const normalized = JSON.parse(readFileSync(output, "utf8")) as {
- locations: { path: string }[];
- };
- expect(normalized.locations[0]?.path).toBe("src/handler.py");
+ const contents = readFileSync(output, "utf8");
+ expect(contents).toContain("Résumé: missing guard");
+ const normalized = contents
+ .trimEnd()
+ .split("\n")
+ .map((line) => JSON.parse(line) as { locations: { path: string }[] });
+ expect(normalized.map((entry) => entry.locations[0]?.path).sort()).toEqual([
+ "src/handler.py",
+ "src/second.py",
+ ]);
writeFileSync(inventory, "../escaped.py\nsrc/handler.py\n");
const escaped = python(