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: reuse native equality for contract lists (#1457)

mldangelo-oai5f4b5ca4e0d6
diff --git a/plugins/codex-security/mcp-app/src/helpers/rank-pool.ts b/plugins/codex-security/mcp-app/src/helpers/rank-pool.ts
index d54d954a5..f7f4cb558 100644
--- a/plugins/codex-security/mcp-app/src/helpers/rank-pool.ts
+++ b/plugins/codex-security/mcp-app/src/helpers/rank-pool.ts
@@ -1,3 +1,4 @@
+import { isDeepStrictEqual as same } from "node:util";
import { createHash } from "node:crypto";
import { basename, dirname } from "node:path";
import { mkdir, readFile, writeFile } from "./helper-files";
@@ -28,9 +29,6 @@ interface Worker {
output_shards: string[];
slot: number;
}
-const same = (left: string[], right: string[]) =>
- left.length === right.length &&
- left.every((name, index) => name === right[index]);
function requirePlanDirectory(plan: string, directory: string): void {
const expected = childPath(dirname(plan), "rank_shards");
diff --git a/sdk/typescript/scripts/build-plugin.mjs b/sdk/typescript/scripts/build-plugin.mjs
index 4bc2cc1a0..10b9331d4 100644
--- a/sdk/typescript/scripts/build-plugin.mjs
+++ b/sdk/typescript/scripts/build-plugin.mjs
@@ -1,4 +1,5 @@
import { execFileSync } from "node:child_process";
+import { isDeepStrictEqual } from "node:util";
import {
chmod,
copyFile,
@@ -113,12 +114,7 @@ export async function buildBundledPlugin({
await chmod(output, mode);
}
- const generated = await destinationFiles(staged);
- const expected = [...files].sort();
- if (
- generated.length !== expected.length ||
- generated.some((path, index) => path !== expected[index])
- ) {
+ if (!isDeepStrictEqual(await destinationFiles(staged), [...files].sort())) {
throw new Error("Bundled plugin generated files outside its contract.");
}
try {
diff --git a/sdk/typescript/src/contract.ts b/sdk/typescript/src/contract.ts
index 2086f34cb..35d11b429 100644
--- a/sdk/typescript/src/contract.ts
+++ b/sdk/typescript/src/contract.ts
@@ -1,3 +1,4 @@
+import { isDeepStrictEqual as sameArray } from "node:util";
import { createHash, hash } from "node:crypto";
import { isNonEmptyString } from "./value.js";
import { constants, type BigIntStats, type Stats } from "node:fs";
@@ -1160,13 +1161,6 @@ function schemaError(
);
}
-function sameArray(left: readonly string[], right: readonly string[]): boolean {
- return (
- left.length === right.length &&
- left.every((value, index) => value === right[index])
- );
-}
-
function nodeErrorCode(error: unknown): string | undefined {
return typeof error === "object" && error !== null && "code" in error
? String(error.code)