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(build): keep usable bundles after failures and preserve release labels (#1263)

mldangelo-oai7eba9000353a
diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.yml
index 7f8a05e90..7eead71e6 100644
--- a/.github/workflows/container-release.yml
+++ b/.github/workflows/container-release.yml
@@ -400,7 +400,7 @@ jobs:
owner="${GITHUB_REPOSITORY_OWNER,,}"
endpoint="orgs/$owner/packages/container/codex-security"
- sh docker/verify-container-release-version.sh "$endpoint" "$VERSION"
+ sh docker/verify-container-release-version.sh "$endpoint" "$VERSION" "$MANIFEST_DIGEST"
docker buildx imagetools create \
--tag "$IMAGE:$VERSION" \
diff --git a/.github/workflows/node-github-release.yml b/.github/workflows/node-github-release.yml
index 9cd3cb8b7..840d35db6 100644
--- a/.github/workflows/node-github-release.yml
+++ b/.github/workflows/node-github-release.yml
@@ -289,7 +289,7 @@ jobs:
"$RELEASE_VERSION" \
"$RELEASE_SHA" \
"$GITHUB_REPOSITORY" \
- "$RELEASE_RUN_ID" 2>/dev/null
+ "$RELEASE_RUN_ID"
)"; then
verified_run_id="$RELEASE_RUN_ID"
printf '%s\n' "$verified_provenance"
diff --git a/.github/workflows/node-release-labels.yml b/.github/workflows/node-release-labels.yml
index 468dae3a0..ae3d7cb31 100644
--- a/.github/workflows/node-release-labels.yml
+++ b/.github/workflows/node-release-labels.yml
@@ -91,48 +91,56 @@ jobs:
--jq '.[].name'
)"
- preserve_skip_label=false
- while IFS= read -r current_label; do
- if [[ "$current_label" == "skip-release-notes" ]]; then
- skip_label_actors="$(
- gh api \
- "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/timeline?per_page=100" \
- --paginate \
- --jq '.[] | select(.event == "labeled" and .label.name == "skip-release-notes") | if (.actor.login // "") == "" then "__unattributed__" else .actor.login end'
- )"
- skip_label_actor=""
- while IFS= read -r event_actor; do
- skip_label_actor="$event_actor"
- done <<< "$skip_label_actors"
-
- if [[ "$skip_label_actor" != "github-actions[bot]" ]]; then
- echo "Preserving existing skip-release-notes label."
- preserve_skip_label=true
- fi
- break
- fi
- done <<< "$current_labels"
+ label_events=""
+ if [[ -n "$current_labels" ]]; then
+ label_events="$(
+ gh api \
+ "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/timeline?per_page=100" \
+ --paginate \
+ --jq '.[] | select(.event == "labeled") | [.label.name, (.actor.login // "__unattributed__")] | @tsv'
+ )"
+ fi
label_already_present=false
+ manual_category_present=false
+ bot_labels=""
while IFS= read -r current_label; do
case "$current_label" in
breaking-change | enhancement | bug | documentation | skip-release-notes)
- if [[ "$current_label" == "skip-release-notes" &&
- "$preserve_skip_label" == true ]]; then
- if [[ "$current_label" == "$label" ]]; then
+ label_actor=""
+ while IFS=$'\t' read -r event_label event_actor; do
+ if [[ "$event_label" == "$current_label" ]]; then
+ label_actor="$event_actor"
+ fi
+ done <<< "$label_events"
+ if [[ "$label_actor" != "github-actions[bot]" ]]; then
+ echo "Preserving existing $current_label label."
+ if [[ "$current_label" != "skip-release-notes" || "$current_label" == "$label" ]]; then
label_already_present=true
fi
- elif [[ "$current_label" != "$label" ]]; then
- gh api --method DELETE \
- "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels/$current_label" \
- --silent
+ if [[ "$current_label" != "skip-release-notes" ]]; then
+ manual_category_present=true
+ fi
else
- label_already_present=true
+ bot_labels+="$current_label"$'\n'
fi
;;
esac
done <<< "$current_labels"
+ while IFS= read -r current_label; do
+ if [[ -z "$current_label" ]]; then
+ continue
+ fi
+ if [[ "$manual_category_present" == true || "$current_label" != "$label" ]]; then
+ gh api --method DELETE \
+ "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels/$current_label" \
+ --silent
+ else
+ label_already_present=true
+ fi
+ done <<< "$bot_labels"
+
if [[ -z "$label" ]]; then
echo "No automatic release-note category applies."
exit 0
diff --git a/.ona/automations.yml b/.ona/automations.yml
index 1599817a8..bc134aa5c 100644
--- a/.ona/automations.yml
+++ b/.ona/automations.yml
@@ -15,6 +15,8 @@ tasks:
- manual
- prebuild
+ # First download the source-matched universal native artifact described in
+ # sdk/typescript/TESTING.md. Dependency installation does not provide it.
test:
name: Run tests
command: |
diff --git a/docker/README.md b/docker/README.md
index 45d8810d6..cbe053932 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -89,7 +89,8 @@ version or run `container-release` manually on `main`. Releases require a commit
on protected `main`; pull requests only build and test.
If a release fails, fix the cause and rerun only failed jobs; do not overwrite
-an existing stable version. `bootstrap` and
+an existing stable version. Promotion retries accept an existing version only
+when it already points to the same verified image digest. `bootstrap` and
`release-candidate-<commit>` tags are not consumer releases.
See the [findings service guide](../sdk/typescript/README.md#findings-service-preview)
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index fbaca7c41..b51798d82 100644
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -36,10 +36,10 @@ for argument do
bulk_scan_command=yes
fi
;;
- --output-dir|--workers|--mode|--model|--effort|--provider|\
+ --config|-c|--output-dir|--workers|--mode|--model|--effort|--provider|\
--knowledge-base|--max-attempts|--max-cost|--plugin-path|--python|\
--codex|--filter-output|--format|\
- --scan-prompt-file|--post-scan-prompt-file|\
+ --scan-prompt-file|--post-scan-prompt-file|--validation-prompt-file|\
--token-limit|--token-offset)
expects_option_value=yes
;;
diff --git a/docker/verify-container-release-version.sh b/docker/verify-container-release-version.sh
index ec0b71855..86d0faf25 100644
--- a/docker/verify-container-release-version.sh
+++ b/docker/verify-container-release-version.sh
@@ -2,13 +2,14 @@
set -eu
-if [ "$#" -ne 2 ]; then
- printf '%s\n' 'Usage: verify-container-release-version.sh PACKAGE_ENDPOINT VERSION' >&2
+if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
+ printf '%s\n' 'Usage: verify-container-release-version.sh PACKAGE_ENDPOINT VERSION [VERIFIED_DIGEST]' >&2
exit 2
fi
endpoint=$1
version=$2
+verified_digest=${3:-}
if ! versions="$(gh api --paginate "$endpoint/versions?per_page=100")"; then
printf '%s\n' "::error::Unable to verify whether container version $version already exists; refusing to publish." >&2
@@ -17,11 +18,18 @@ fi
if ! already_published="$(
printf '%s\n' "$versions" |
- jq --slurp --arg version "$version" '
+ jq --slurp --arg version "$version" --arg digest "$verified_digest" '
if length == 0 or any(.[]; type != "array") then
error("Container package versions must contain at least one JSON array.")
else
- any(.[]; any(.[]; any(.metadata.container.tags[]?; . == $version)))
+ [.[][] | select(any(.metadata.container.tags[]?; . == $version))] as $existing |
+ if ($existing | length) == 0 then false
+ elif ($digest | test("^sha256:[a-fA-F0-9]{64}$")) then
+ [.[][] | select(any(.metadata.container.tags[]?; . == "latest"))] as $latest |
+ any($existing[]; .name != $digest) or
+ ($latest | length) == 0 or any($latest[]; .name != $digest)
+ else true
+ end
end
'
)"; then
@@ -34,7 +42,7 @@ case "$already_published" in
exit 0
;;
true)
- printf '%s\n' "::error::Container version $version already exists; stable version tags cannot be overwritten." >&2
+ printf '%s\n' "::error::Container version $version already exists; retries require both that version and latest to match the verified digest." >&2
exit 1
;;
*)
diff --git a/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs b/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs
index c0ad12f22..c981431d4 100644
--- a/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs
+++ b/plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs
@@ -1,7 +1,7 @@
#!/usr/bin/env node
+import { realpathSync } from "node:fs";
import { copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
-import { pathToFileURL } from "node:url";
import { brotliCompressSync, constants as zlibConstants } from "node:zlib";
import { execFileSync } from "node:child_process";
import { build } from "esbuild";
@@ -60,7 +60,21 @@ export async function buildMcpApp({ output, native = "universal" }) {
}
const destination = join(mcpDir, "native", path);
await mkdir(dirname(destination), { recursive: true });
- await copyFile(join(nativeRoot, path), destination);
+ try {
+ await copyFile(join(nativeRoot, path), destination);
+ } catch (error) {
+ if (error.code !== "ENOENT") throw error;
+ const preparation =
+ native === "host"
+ ? "Run node plugins/codex-security/mcp-app/scripts/build_native.mjs first."
+ : "Download a source-matched native-universal artifact as described in plugins/codex-security/native/README.md before running SDK tests or universal builds.";
+ throw new Error(
+ `Missing native payload ${path}. ${preparation} ${error.message}`,
+ {
+ cause: error,
+ },
+ );
+ }
}
await writeRuntime("helpers", "helpers-main.ts");
await build({
@@ -85,6 +99,19 @@ export async function buildMcpApp({ output, native = "universal" }) {
logOverride: { "empty-import-meta": "silent" },
outfile: bundle,
platform: "node",
+ plugins: [
+ {
+ name: "native-typescript-source",
+ setup(builder) {
+ builder.onResolve({ filter: /\.mjs$/ }, (args) => {
+ const source = resolve(args.resolveDir, args.path);
+ if (dirname(source) === resolve(root, "../native")) {
+ return { path: source.slice(0, -4) + ".mts" };
+ }
+ });
+ },
+ },
+ ],
target: "node20",
write: false,
});
@@ -106,11 +133,27 @@ export async function buildMcpApp({ output, native = "universal" }) {
}
}
-const invokedPath = process.argv[1];
-if (
- invokedPath !== undefined &&
- pathToFileURL(resolve(invokedPath)).href === import.meta.url
-) {
+function isMain() {
+ if (
+ process.execArgv.some(
+ (argument) =>
+ /^(?:--(?:eval|print)(?:=|$)|-(?:e|p|pe)$)/u.test(argument) ||
+ (process.versions["bun"] !== undefined && /^-[ep]/u.test(argument)),
+ )
+ )
+ return false;
+ try {
+ return (
+ process.argv[1] !== undefined &&
+ process.argv[1] !== "-" &&
+ realpathSync(process.argv[1]) === realpathSync(new URL(import.meta.url))
+ );
+ } catch {
+ return false;
+ }
+}
+
+if (isMain()) {
const args = process.argv.slice(2);
if (
args[0] !== "--output" ||
diff --git a/plugins/codex-security/native/check.mts b/plugins/codex-security/native/check.mts
index d63c6b3e1..e2a6719da 100644
--- a/plugins/codex-security/native/check.mts
+++ b/plugins/codex-security/native/check.mts
@@ -1,8 +1,6 @@
import { execFileSync } from "node:child_process";
import { createHash } from "node:crypto";
-import { readFileSync } from "node:fs";
-import { resolve } from "node:path";
-import { pathToFileURL } from "node:url";
+import { readFileSync, realpathSync } from "node:fs";
import { binaryPath } from "./binding.mjs";
import { libc } from "./platform.mjs";
@@ -39,10 +37,27 @@ function versionAfter(value: string, floor: string): boolean {
return false;
}
-if (
- process.argv[1] !== undefined &&
- pathToFileURL(resolve(process.argv[1])).href === import.meta.url
-) {
+function isMain() {
+ if (
+ process.execArgv.some(
+ (argument) =>
+ /^(?:--(?:eval|print)(?:=|$)|-(?:e|p|pe)$)/u.test(argument) ||
+ (process.versions["bun"] !== undefined && /^-[ep]/u.test(argument)),
+ )
+ )
+ return false;
+ try {
+ return (
+ process.argv[1] !== undefined &&
+ process.argv[1] !== "-" &&
+ realpathSync(process.argv[1]) === realpathSync(new URL(import.meta.url))
+ );
+ } catch {
+ return false;
+ }
+}
+
+if (isMain()) {
const bytes = readFileSync(binaryPath);
checkPrivatePaths(bytes);
let floor: string;
diff --git a/plugins/codex-security/tests/test_threat_model_projection.py b/plugins/codex-security/tests/test_threat_model_projection.py
index d30428018..31fdfa4c8 100644
--- a/plugins/codex-security/tests/test_threat_model_projection.py
+++ b/plugins/codex-security/tests/test_threat_model_projection.py
@@ -439,7 +439,7 @@ class ThreatModelProjectionTest(unittest.TestCase):
source = Path(directory).resolve()
path = source / filename
path.parent.mkdir(parents=True, exist_ok=True)
- path.write_text(body)
+ path.write_bytes(body.encode())
self.assertEqual(FINALIZER.build_threat_model_export(source), body.encode())
self.assertEqual(path.read_text(), body)
description = FINALIZER.describe_threat_model(source)
@@ -489,6 +489,15 @@ class ThreatModelProjectionTest(unittest.TestCase):
)
self.assertEqual(outside_lookups, [])
+ def test_exports_legacy_document_with_crlf_bytes_unchanged(self) -> None:
+ body = b"# Existing Model\r\n\r\n Preserve indentation.\r\n"
+ with tempfile.TemporaryDirectory() as directory:
+ source = Path(directory).resolve()
+ path = source / "threatmodel.md"
+ path.write_bytes(body)
+ self.assertEqual(FINALIZER.build_threat_model_export(source), body)
+ self.assertEqual(path.read_bytes(), body)
+
def test_malformed_canonical_model_does_not_export_a_stale_legacy_document(self) -> None:
body = "# Earlier model\n\nEarlier service boundaries.\n"
for filename in ("scan-manifest.json", "policy-draft.json"):
@@ -508,7 +517,7 @@ class ThreatModelProjectionTest(unittest.TestCase):
original = json.dumps(manifest)
path.write_text(original)
legacy = source / "threatmodel.md"
- legacy.write_text(body)
+ legacy.write_bytes(body.encode())
for read_model in (
FINALIZER.describe_threat_model,
FINALIZER.build_threat_model_export,
@@ -597,7 +606,7 @@ class ThreatModelProjectionTest(unittest.TestCase):
FINALIZER.finalize_scan(self.scan_dir)
legacy_path = self.scan_dir / "artifacts" / "01_context" / "threat_model.md"
legacy_path.parent.mkdir(parents=True)
- legacy_path.write_text(body)
+ legacy_path.write_bytes(body.encode())
manifest = self.read_json("scan-manifest.json")
manifest["scan"]["artifacts"].append(
FINALIZER._artifact_record(
@@ -636,7 +645,7 @@ class ThreatModelProjectionTest(unittest.TestCase):
}
)
)
- (source / "THREAT_MODEL.md").write_text(body)
+ (source / "THREAT_MODEL.md").write_bytes(body.encode())
description = FINALIZER.describe_threat_model(source)
self.assertEqual(description["provenance"]["source"], "policy")
self.assertEqual(description["provenance"]["revision"], "abc123")
diff --git a/sdk/typescript/TESTING.md b/sdk/typescript/TESTING.md
index 72a1abc91..ea985d934 100644
--- a/sdk/typescript/TESTING.md
+++ b/sdk/typescript/TESTING.md
@@ -46,6 +46,23 @@ JavaScript and TypeScript, not the Python helpers or child processes. It is
diagnostic for now. Use several successful CI runs to establish a baseline
before proposing a coverage floor.
+## Native artifacts in fresh development environments
+
+SDK tests, including Ona's **Run tests** automation, require the eight verified
+native payloads. Installing Node and Python dependencies alone does not supply
+them. Select a successful native-artifacts or node-ci run built from this
+checkout's native sources and toolchain, then use the exact artifact name from
+that run (pull request artifacts use the tested merge commit):
+
+```sh
+gh run download <run-id> --name native-universal-<commit> --dir plugins/codex-security/native/prebuilt
+```
+
+Run this command from the repository root before starting the automation.
+Refresh the artifact after changing native source or toolchain. The standalone
+plugin supports a host-only build; that does not satisfy the SDK's universal
+packaging tests. See the [native build guide](../../plugins/codex-security/native/README.md).
+
## Writing tests
- Test observable results, failures, cancellation, and cleanup. Prefer a
diff --git a/sdk/typescript/scripts/build-dashboard.mjs b/sdk/typescript/scripts/build-dashboard.mjs
index bf79b8b4a..d8357515b 100644
--- a/sdk/typescript/scripts/build-dashboard.mjs
+++ b/sdk/typescript/scripts/build-dashboard.mjs
@@ -3,6 +3,7 @@ import {
mkdir,
readFile,
readdir,
+ realpath,
writeFile,
} from "node:fs/promises";
import { fileURLToPath } from "node:url";
@@ -70,8 +71,12 @@ for (const output of Object.values(built.metafile.outputs)) {
}
}
const notices = [];
-for (const directory of [...packages].sort()) {
- const path = join(root, directory);
+const packagePaths = new Set(
+ await Promise.all(
+ [...packages].map((directory) => realpath(join(root, directory))),
+ ),
+);
+for (const path of [...packagePaths].sort()) {
const manifest = JSON.parse(
await readFile(join(path, "package.json"), "utf8"),
);
diff --git a/sdk/typescript/scripts/release-pr.mjs b/sdk/typescript/scripts/release-pr.mjs
index 2ace87cc6..3d99da98f 100644
--- a/sdk/typescript/scripts/release-pr.mjs
+++ b/sdk/typescript/scripts/release-pr.mjs
@@ -90,7 +90,7 @@ export function generateNoteSections(changes) {
"",
...breaking.map(changeLine),
].join("\n")
- : "Review compatibility and document any required migration steps before releasing.",
+ : "No additional migration steps are documented for this release.",
].join("\n"),
};
}
diff --git a/sdk/typescript/tests-ts/build-plugin.test.ts b/sdk/typescript/tests-ts/build-plugin.test.ts
index 859de266c..5747763fd 100644
--- a/sdk/typescript/tests-ts/build-plugin.test.ts
+++ b/sdk/typescript/tests-ts/build-plugin.test.ts
@@ -482,3 +482,42 @@ describe("generated plugin ownership", () => {
);
});
});
+
+test("failed compiler preserves the previous bundle and its diagnostics", async () => {
+ const root = await temporaryDirectory();
+ const source = join(root, "source");
+ const destination = join(root, "bundle");
+ const contractPath = join(source, "plugin-files.json");
+ await writeFixture(
+ source,
+ "plugin-files.json",
+ JSON.stringify({
+ externalOwnedExact: [".codex-plugin/plugin.json"],
+ shippedExact: ["mcp/server.mjs"],
+ }),
+ );
+ await writeFixture(source, ".codex-plugin/plugin.json", "{}");
+ await writeFixture(
+ source,
+ "mcp-app/scripts/build_mcp_app.mjs",
+ 'console.log("synthetic compiler diagnostic"); process.exit(1);',
+ );
+ await writeFixture(destination, "previous.txt", "previous valid bundle");
+ const driver = join(root, "driver.mjs");
+ await writeFile(
+ driver,
+ `import { buildBundledPlugin } from ${JSON.stringify(new URL("../scripts/build-plugin.mjs", import.meta.url).href)};
+try { await buildBundledPlugin(${JSON.stringify({ contractPath, destination, source })}); }
+catch (error) { console.error(error.message); process.exitCode = 1; }`,
+ );
+ const result = await execFileAsync(process.execPath, [driver]).then(
+ () => {
+ throw new Error("synthetic compiler unexpectedly succeeded");
+ },
+ (error: { stdout: string; stderr: string }) => error,
+ );
+ expect(result.stdout).toContain("synthetic compiler diagnostic");
+ expect(await readFile(join(destination, "previous.txt"), "utf8")).toBe(
+ "previous valid bundle",
+ );
+});
diff --git a/sdk/typescript/tests-ts/container-entrypoint.test.ts b/sdk/typescript/tests-ts/container-entrypoint.test.ts
index 5243a1d48..6534afb78 100644
--- a/sdk/typescript/tests-ts/container-entrypoint.test.ts
+++ b/sdk/typescript/tests-ts/container-entrypoint.test.ts
@@ -48,6 +48,7 @@ async function runEntrypoint(
async function runVersionVerifier(
response: string,
failure = false,
+ digest?: string,
): Promise<SpawnSyncReturns<string>> {
const root = await realpath(
await mkdtemp(join(tmpdir(), "codex-security-container-version-")),
@@ -74,17 +75,26 @@ async function runVersionVerifier(
);
const endpoint = "orgs/openai/packages/container/codex-security";
- return spawnSync("sh", [versionVerifier, endpoint, "0.1.4"], {
- encoding: "utf8",
- env: {
- ...process.env,
- EXPECTED_ENDPOINT: endpoint,
- GH_FIXTURE_FAILURE: failure ? "1" : "0",
- GH_FIXTURE_RESPONSE: response,
- PATH: `${root}${delimiter}${process.env["PATH"] ?? ""}`,
+ return spawnSync(
+ "sh",
+ [
+ versionVerifier,
+ endpoint,
+ "0.1.4",
+ ...(digest === undefined ? [] : [digest]),
+ ],
+ {
+ encoding: "utf8",
+ env: {
+ ...process.env,
+ EXPECTED_ENDPOINT: endpoint,
+ GH_FIXTURE_FAILURE: failure ? "1" : "0",
+ GH_FIXTURE_RESPONSE: response,
+ PATH: `${root}${delimiter}${process.env["PATH"] ?? ""}`,
+ },
+ timeout: 10_000,
},
- timeout: 10_000,
- });
+ );
} finally {
await rm(root, { recursive: true, force: true });
}
@@ -122,6 +132,14 @@ describe("customer container entrypoint", () => {
testPosix("accepts CSVs after global and bulk-scan options", async () => {
for (const arguments_ of [
["bulk-scan", "--workers", "2", "/input/repositories.csv"],
+ ["bulk-scan", "--config", "settings.json", "/input/repositories.csv"],
+ ["bulk-scan", "-c", "settings.json", "/input/repositories.csv"],
+ [
+ "bulk-scan",
+ "--validation-prompt-file",
+ "prompt.md",
+ "/input/repositories.csv",
+ ],
["bulk-scan", "--max-cost", "12.50", "/input/repositories.csv"],
["bulk-scan", "bulk-scan", "--output-dir", "/output"],
[
@@ -172,6 +190,9 @@ describe("customer container entrypoint", () => {
for (const arguments_ of [
["bulk-scan"],
["bulk-scan", "--workers", "8"],
+ ["bulk-scan", "--config", "settings.json"],
+ ["bulk-scan", "-c", "settings.json"],
+ ["bulk-scan", "--validation-prompt-file", "prompt.md"],
["bulk-scan", "--max-cost", "12.50"],
["bulk-scan", "--scan-prompt-file", "prompt.md"],
["bulk-scan", "--post-scan-prompt-file", "post-prompt.md"],
@@ -250,3 +271,41 @@ describe("immutable customer container releases", () => {
expect(result.stderr).toContain("refusing to publish");
});
});
+
+testPosix(
+ "retries promotion only for the same verified manifest digest",
+ async () => {
+ const digest = `sha256:${"a".repeat(64)}`;
+ const response = JSON.stringify([
+ { name: digest, metadata: { container: { tags: ["0.1.4", "latest"] } } },
+ ]);
+ expect((await runVersionVerifier(response, false, digest)).status).toBe(0);
+ expect(
+ (await runVersionVerifier(response, false, `sha256:${"b".repeat(64)}`))
+ .status,
+ ).toBe(1);
+ expect((await runVersionVerifier(response, false, "invalid")).status).toBe(
+ 1,
+ );
+ expect((await runVersionVerifier(response, true, digest)).status).toBe(1);
+ const older = JSON.stringify([
+ { name: digest, metadata: { container: { tags: ["0.1.4"] } } },
+ {
+ name: `sha256:${"b".repeat(64)}`,
+ metadata: { container: { tags: ["0.1.5", "latest"] } },
+ },
+ ]);
+ expect((await runVersionVerifier(older, false, digest)).status).toBe(1);
+ expect(
+ (
+ await runVersionVerifier(
+ JSON.stringify([
+ { name: digest, metadata: { container: { tags: ["0.1.4"] } } },
+ ]),
+ false,
+ digest,
+ )
+ ).status,
+ ).toBe(1);
+ },
+);
diff --git a/sdk/typescript/tests-ts/findings-serve.test.ts b/sdk/typescript/tests-ts/findings-serve.test.ts
new file mode 100644
index 000000000..4d42a42ee
--- /dev/null
+++ b/sdk/typescript/tests-ts/findings-serve.test.ts
@@ -0,0 +1,27 @@
+import { spawnSync } from "node:child_process";
+import { resolve } from "node:path";
+import { expect, test } from "bun:test";
+
+test("findings service uses a nonempty API key with CODEX_API_KEY fallback", () => {
+ const source = `
+ import { mock } from 'bun:test';
+ const keys = [];
+ mock.module(${JSON.stringify(resolve(import.meta.dir, "../src/server/embeddings.ts"))}, () => ({OpenAiFindingEmbedder: class {constructor(key) { keys.push(key ?? null); }}}));
+ mock.module(${JSON.stringify(resolve(import.meta.dir, "../src/server/sqlite-store.ts"))}, () => ({SqliteFindingsStore: class {}}));
+ mock.module(${JSON.stringify(resolve(import.meta.dir, "../src/server/server.ts"))}, () => ({startFindingsServer: async () => ({address: () => null})}));
+ const { serveFindings } = await import(${JSON.stringify(resolve(import.meta.dir, "../src/server/serve.ts"))});
+ await serveFindings({OPENAI_API_KEY:'', CODEX_API_KEY:'synthetic-codex-key'});
+ await serveFindings({OPENAI_API_KEY:'synthetic-openai-key', CODEX_API_KEY:'synthetic-codex-key'});
+ await serveFindings({});
+ console.log(JSON.stringify(keys));
+ `;
+ const result = spawnSync(process.execPath, ["--eval", source], {
+ encoding: "utf8",
+ });
+ expect(result.status).toBe(0);
+ expect(JSON.parse(result.stdout)).toEqual([
+ "synthetic-codex-key",
+ "synthetic-openai-key",
+ null,
+ ]);
+});
diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.ts
index f8a542355..dc2a8aed9 100644
--- a/sdk/typescript/tests-ts/release-automation.test.ts
+++ b/sdk/typescript/tests-ts/release-automation.test.ts
@@ -8,8 +8,8 @@ import {
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
-import { join } from "node:path";
-import { fileURLToPath } from "node:url";
+import { join, resolve } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
import { describe, expect, test } from "bun:test";
import { bashCommand, runCommand } from "./support/shell.js";
@@ -346,30 +346,50 @@ function workflowStepShell(workflow: string, stepName: string): string {
.join("\n");
}
-function evaluateWorkflowCondition(
+async function evaluateWorkflowCondition(
condition: string,
values: Record<string, string>,
-): boolean {
- let expression = condition
- .replace(/^\$\{\{\s*/u, "")
- .replace(/\s*\}\}$/u, "");
- for (const [identifier, value] of Object.entries(values).sort(
- ([left], [right]) => right.length - left.length,
- )) {
- if (!/^[a-z0-9_/-]+$/u.test(value)) {
- throw new Error(`Unsafe workflow test value: ${value}`);
- }
- expression = expression.replaceAll(identifier, `'${value}'`);
- }
- if (!/^[\s()'/a-z0-9_!=&|-]+$/u.test(expression)) {
- throw new Error(`Unsupported workflow condition: ${condition}`);
- }
+): Promise<boolean> {
+ return (await evaluateWorkflowConditions([{ condition, values }]))[0]!;
+}
- const result = spawnSync(bash, ["-c", `[[ ${expression} ]]`]);
- if (result.status !== 0 && result.status !== 1) {
- throw new Error(`Could not evaluate workflow condition: ${condition}`);
+async function evaluateWorkflowConditions(
+ conditions: Array<{ condition: string; values: Record<string, string> }>,
+): Promise<boolean[]> {
+ const expressions = conditions.map(({ condition, values }) => {
+ let expression = condition
+ .replace(/^\$\{\{\s*/u, "")
+ .replace(/\s*\}\}$/u, "");
+ for (const [identifier, value] of Object.entries(values).sort(
+ ([left], [right]) => right.length - left.length,
+ )) {
+ if (!/^[a-z0-9_/-]+$/u.test(value)) {
+ throw new Error(`Unsafe workflow test value: ${value}`);
+ }
+ expression = expression.replaceAll(identifier, `'${value}'`);
+ }
+ if (!/^[\s()'/a-z0-9_!=&|-]+$/u.test(expression)) {
+ throw new Error(`Unsupported workflow condition: ${condition}`);
+ }
+ return `[[ ${expression} ]]
+result=$?
+if [[ $result != 0 && $result != 1 ]]; then exit "$result"; fi
+printf '%s\n' "$result"`;
+ });
+ const result = await runCommand(bash, [], {
+ input: expressions.join("\n"),
+ timeout: 30_000,
+ });
+ if (result.status !== 0) {
+ throw new Error(
+ `Could not evaluate workflow conditions (status ${result.status}, signal ${result.signal}):\n${result.stderr}`,
+ { cause: result.error },
+ );
}
- return result.status === 0;
+ return result.stdout
+ .trimEnd()
+ .split("\n")
+ .map((status) => status === "0");
}
describe("reviewed release note helpers", () => {
@@ -1613,12 +1633,12 @@ describe("GitHub release workflow safeguards", () => {
headBranch: "none",
expected: true,
},
- ])("gates release cutting for $name", (scenario) => {
+ ])("gates release cutting for $name", async (scenario) => {
const workflow = Bun.YAML.parse(releaseCutWorkflow) as {
jobs: { cut: { if: string } };
};
expect(
- evaluateWorkflowCondition(workflow.jobs.cut.if, {
+ await evaluateWorkflowCondition(workflow.jobs.cut.if, {
"github.event.workflow_run.conclusion": scenario.conclusion,
"github.event.workflow_run.head_branch": scenario.headBranch,
"github.event.workflow_run.event": scenario.sourceEvent,
@@ -3613,7 +3633,7 @@ describe("GitHub release workflow safeguards", () => {
expect(nodeCiWorkflow).toContain("needs: validate-title");
});
- test("keeps required contexts stable for every change", () => {
+ test("keeps required contexts stable for every change", async () => {
const workflow = Bun.YAML.parse(nodeCiWorkflow) as {
concurrency: {
group: string;
@@ -3671,6 +3691,12 @@ describe("GitHub release workflow safeguards", () => {
name ===
`Require every ${job === "windows" ? "Windows" : "Unix"} coverage job`,
);
+ const conditionCases: Array<{
+ condition: string;
+ values: Record<string, string>;
+ expected: boolean;
+ message: string;
+ }> = [];
for (const [validation, upstream, gateFailure] of [
["success", "success", false],
["success", "skipped", true],
@@ -3689,10 +3715,12 @@ describe("GitHub release workflow safeguards", () => {
"needs.windows-verify.result": upstream,
};
for (const job of ["required-test", "windows"]) {
- expect(
- evaluateWorkflowCondition(coverageGate(job)?.if ?? "", values),
- `${job}: ${validation}/${upstream}`,
- ).toBe(gateFailure);
+ conditionCases.push({
+ condition: coverageGate(job)?.if ?? "",
+ values,
+ expected: gateFailure,
+ message: `${job}: ${validation}/${upstream}`,
+ });
}
}
@@ -3716,8 +3744,9 @@ describe("GitHub release workflow safeguards", () => {
})) {
for (const dependency of dependencies) {
for (const result of ["failure", "cancelled", "skipped"]) {
- expect(
- evaluateWorkflowCondition(coverageGate(gate)?.if ?? "", {
+ conditionCases.push({
+ condition: coverageGate(gate)?.if ?? "",
+ values: {
"needs.validate-title.result": "success",
...Object.fromEntries(
dependencies.map((job) => [
@@ -3725,14 +3754,20 @@ describe("GitHub release workflow safeguards", () => {
job === dependency ? result : "success",
]),
),
- }),
- `${gate}: ${dependency}/${result}`,
- ).toBe(true);
+ },
+ expected: true,
+ message: `${gate}: ${dependency}/${result}`,
+ });
}
}
expect(coverageGate(gate)?.run).toBe("exit 1");
}
+ const conditions = await evaluateWorkflowConditions(conditionCases);
+ for (const [index, item] of conditionCases.entries()) {
+ expect(conditions[index], item.message).toBe(item.expected);
+ }
+
const renderName = (template: string, values: Record<string, string>) => {
let name = template;
for (const [key, value] of Object.entries(values)) {
@@ -3900,7 +3935,7 @@ describe("GitHub release workflow safeguards", () => {
" printf '%s\\n' enhancement skip-release-notes",
" ;;",
' "GET repos/test/codex-security/issues/17/timeline?per_page=100")',
- " printf '%s\\n' 'github-actions[bot]' 'trusted-reviewer'",
+ " printf '%b\\n' 'enhancement\\tgithub-actions[bot]' 'skip-release-notes\\tgithub-actions[bot]' 'skip-release-notes\\ttrusted-reviewer'",
" ;;",
' "DELETE repos/test/codex-security/issues/17/labels/enhancement")',
" printf '%s\\n' 'removed a stale managed category'",
@@ -3968,9 +4003,9 @@ describe("GitHub release workflow safeguards", () => {
" ;;",
' "GET repos/test/codex-security/issues/17/timeline?per_page=100")',
' if [[ "$*" == *"__unattributed__"* ]]; then',
- " printf '%s\\n' 'github-actions[bot]' '__unattributed__'",
+ " printf '%b\\n' 'skip-release-notes\\tgithub-actions[bot]' 'skip-release-notes\\t__unattributed__'",
" else",
- " printf '%s\\n' 'github-actions[bot]' ''",
+ " printf '%b\\n' 'skip-release-notes\\tgithub-actions[bot]' 'skip-release-notes\\t'",
" fi",
" ;;",
' "DELETE repos/test/codex-security/issues/17/labels/skip-release-notes")',
@@ -4031,7 +4066,7 @@ describe("GitHub release workflow safeguards", () => {
" printf '%s\\n' skip-release-notes",
" ;;",
' "GET repos/test/codex-security/issues/17/timeline?per_page=100")',
- " printf '%s\\n' 'github-actions[bot]'",
+ " printf '%b\\n' 'skip-release-notes\\tgithub-actions[bot]'",
" ;;",
' "DELETE repos/test/codex-security/issues/17/labels/skip-release-notes")',
" printf '%s\\n' 'removed automatically applied skip-release-notes'",
@@ -4192,3 +4227,122 @@ describe("GitHub release workflow safeguards", () => {
expect(result.stderr).toContain("GitHub release JSON from stdin");
});
});
+
+test.skipIf(process.platform === "win32")(
+ "preserves manual release categories while replacing stale automated labels",
+ async () => {
+ const script = workflowStepShell(
+ releaseLabelsWorkflow,
+ "Categorize pull request without checking out its code",
+ );
+ const fixture = `gh() {
+ case "$*" in
+ "api repos/test/codex-security/issues/17 --jq "*) printf '%s' 'feat: synthetic feature' | base64 ;;
+ "api repos/test/codex-security/issues/17/labels --jq "*) printf '%s\\n' breaking-change bug ;;
+ "api repos/test/codex-security/issues/17/timeline?per_page=100 "*) printf '%b\\n' 'breaking-change\\tsynthetic-reviewer' 'bug\\tgithub-actions[bot]' ;;
+ "api --method DELETE repos/test/codex-security/issues/17/labels/bug --silent") echo removed-stale-bug ;;
+ "api --method DELETE "*) echo removed-manual-label; return 70 ;;
+ "api --method POST repos/test/codex-security/issues/17/labels "*) printf '%s\\n' "$*" ;;
+ "api repos/test/codex-security/labels/enhancement --silent") return 0 ;;
+ *) echo "Unexpected request: $*" >&2; return 65 ;;
+ esac
+ }`;
+ const result = await runCommand(bash, ["-c", `${fixture}\n${script}`], {
+ env: {
+ ...process.env,
+ GITHUB_REPOSITORY: "test/codex-security",
+ PR_NUMBER: "17",
+ },
+ timeout: 10_000,
+ });
+ expect(result.status).toBe(0);
+ expect(result.stdout).toContain(
+ "Preserving existing breaking-change label.",
+ );
+ expect(result.stdout).toContain("removed-stale-bug");
+ expect(result.stdout).not.toContain("labels[]=enhancement");
+ expect(result.stdout).not.toContain("removed-manual-label");
+ },
+);
+
+test("imports maintainer utilities from Node stdin and eval modules", async () => {
+ const workspace = mkdtempSync(join(tmpdir(), "maintainer-stdin-"));
+ const packageRoot = resolve(import.meta.dir, "..");
+ try {
+ const build = await runCommand(
+ "node",
+ [
+ join(packageRoot, "node_modules", "typescript", "bin", "tsc"),
+ "--project",
+ join(packageRoot, "tsconfig.ci.json"),
+ "--outDir",
+ workspace,
+ ],
+ { timeout: 30_000 },
+ );
+ expect(build.status, build.stdout + build.stderr).toBe(0);
+ const checker = pathToFileURL(
+ join(workspace, "plugins/codex-security/native/check.mjs"),
+ ).href;
+ const source = `import { releaseVersion } from "./scripts/release-automation.mjs"; import { buildBundledPlugin } from "./scripts/build-plugin.mjs"; import { buildMcpApp } from "../../plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs"; import { checkPrivatePaths } from ${JSON.stringify(checker)}; console.log(typeof releaseVersion, typeof buildBundledPlugin, typeof buildMcpApp, typeof checkPrivatePaths);`;
+ for (const args of [
+ ["--input-type=module", "-"],
+ ["--input-type=module", "--eval", source, "synthetic-virtual-entrypoint"],
+ ]) {
+ const result = spawnSync("node", args, {
+ cwd: packageRoot,
+ input: source,
+ encoding: "utf8",
+ });
+ expect(result.status, result.stderr).toBe(0);
+ expect(result.stdout.trim()).toBe("function function function function");
+ }
+ } finally {
+ rmSync(workspace, { recursive: true, force: true });
+ }
+});
+
+test.skipIf(process.platform === "win32").each([
+ {
+ title: "fix: synthetic correction",
+ manual: "documentation",
+ stale: "enhancement",
+ },
+ { title: "feat: synthetic feature", manual: "bug", stale: "documentation" },
+ { title: "feat: synthetic feature", manual: "bug", stale: "enhancement" },
+])(
+ "uses the manual $manual release category over stale $stale after retitling to $title",
+ async ({ title, manual, stale }) => {
+ const script = workflowStepShell(
+ releaseLabelsWorkflow,
+ "Categorize pull request without checking out its code",
+ );
+ const fixture = `gh() {
+ case "$*" in
+ "api repos/test/codex-security/issues/17 --jq "*) printf '%s' "$MOCK_PR_TITLE" | base64 ;;
+ "api repos/test/codex-security/issues/17/labels --jq "*) printf '%s\\n' "$MANUAL_LABEL" "$STALE_LABEL" ;;
+ "api repos/test/codex-security/issues/17/timeline?per_page=100 "*) printf '%s\\t%s\\n' "$MANUAL_LABEL" synthetic-reviewer "$STALE_LABEL" 'github-actions[bot]' ;;
+ "api --method DELETE repos/test/codex-security/issues/17/labels/$STALE_LABEL --silent") echo removed-stale-label ;;
+ "api --method DELETE "*) echo removed-manual-label; return 70 ;;
+ "api --method POST "*) echo added-automatic-category ;;
+ *) return 65 ;;
+ esac
+ }`;
+ const result = await runCommand(bash, ["-c", `${fixture}\n${script}`], {
+ env: {
+ ...process.env,
+ GITHUB_REPOSITORY: "test/codex-security",
+ PR_NUMBER: "17",
+ MOCK_PR_TITLE: title,
+ MANUAL_LABEL: manual,
+ STALE_LABEL: stale,
+ },
+ timeout: 10_000,
+ });
+ expect(result.status, result.stderr).toBe(0);
+ expect(result.stdout).toContain(`Preserving existing ${manual} label.`);
+ expect(result.stdout).toContain("removed-stale-label");
+ expect(result.stdout).not.toContain("removed-manual-label");
+ expect(result.stdout).not.toContain("added-automatic-category");
+ },
+);
diff --git a/sdk/typescript/tests-ts/script-entrypoints.test.ts b/sdk/typescript/tests-ts/script-entrypoints.test.ts
index d48e9b8fd..7f68ba94c 100644
--- a/sdk/typescript/tests-ts/script-entrypoints.test.ts
+++ b/sdk/typescript/tests-ts/script-entrypoints.test.ts
@@ -27,6 +27,7 @@ beforeAll(async () => {
preload,
`
import childProcess from "node:child_process";
+ import syncFs from "node:fs";
import fs from "node:fs/promises";
import http from "node:http";
import { syncBuiltinESMExports } from "node:module";
@@ -39,6 +40,9 @@ beforeAll(async () => {
const readFile = fs.readFile;
fs.readFile = (path, ...args) => String(path).endsWith("plugin-files.json")
? entered() : readFile(path, ...args);
+ const readFileSync = syncFs.readFileSync;
+ syncFs.readFileSync = (path, ...args) => String(path).endsWith(".node")
+ ? entered() : readFileSync(path, ...args);
syncBuiltinESMExports();
`,
);
@@ -51,6 +55,16 @@ beforeAll(async () => {
},
);
expect(build.status, build.stderr).toBe(0);
+ const native = await runCommand(
+ "node",
+ ["--run", "build:ci", "--", "--outDir", compiled],
+ {
+ cwd: join(repository, "sdk", "typescript"),
+ timeout: 30_000,
+ },
+ );
+ expect(native.status, native.stdout + native.stderr).toBe(0);
+ await symlink(compiled, join(root, "linked compiled"), "junction");
await symlink(
join(compiled, "app.mjs"),
join(root, "linked app.mjs"),
@@ -68,19 +82,31 @@ test.each([
"sdk/typescript/scripts/check-plugin-source.mjs",
"sdk/typescript/scripts/build-plugin.mjs",
"sdk/typescript/scripts/smoke-published-package.mjs",
+ "plugins/codex-security/mcp-app/scripts/build_mcp_app.mjs",
+ "plugins/codex-security/native/check.mjs",
".github/scripts/invoice-desk-source.mjs",
".github/scripts/invoice-desk-target.mjs",
"app.mjs",
])("runs %s through symlinks and stays inert when imported", async (script) => {
+ const native = script === "plugins/codex-security/native/check.mjs";
+ const pluginScript = native || script.endsWith("build_mcp_app.mjs");
const direct =
- script === "app.mjs" ? join(compiled, script) : join(repository, script);
+ script === "app.mjs" || native
+ ? join(compiled, script)
+ : join(repository, script);
const linked =
script === "app.mjs"
? join(root, "linked app.mjs")
- : join(linkedRepository, script);
+ : native
+ ? join(root, "linked compiled", script)
+ : join(linkedRepository, script);
const version = script.endsWith("release-automation.mjs");
const target = script.endsWith("invoice-desk-target.mjs");
- const args = version ? ["version", join(root, "package.json")] : [];
+ const args = version
+ ? ["version", join(root, "package.json")]
+ : script.endsWith("build_mcp_app.mjs")
+ ? ["--output", join(root, "mcp")]
+ : [];
const environment = {
...process.env,
GITHUB_EVENT_NAME: "workflow_dispatch",
@@ -95,6 +121,12 @@ test.each([
[direct],
[linked],
["--preserve-symlinks-main", linked],
+ ...(pluginScript
+ ? [
+ ["-predictable", direct],
+ ["-expose-gc", direct],
+ ]
+ : []),
]) {
const result = await runCommand(
"node",
@@ -112,7 +144,11 @@ test.each([
);
else expect(result.stderr).toContain("SCRIPT_MAIN_REACHED");
}
- for (const argument of [[], ["unrelated argument"]]) {
+ for (const argument of [
+ [],
+ ["unrelated argument"],
+ ...(pluginScript ? [[direct], [linked]] : []),
+ ]) {
const result = await runCommand(
"node",
[
@@ -128,4 +164,26 @@ test.each([
expect(result.status, result.stderr).toBe(0);
expect(result.stdout + result.stderr).toBe("");
}
+ if (pluginScript) {
+ const expression = `void import(${JSON.stringify(pathToFileURL(linked).href)})`;
+ for (const [command, mode, stdout] of [
+ ["node", ["-pe", expression], "undefined\n"],
+ [process.execPath, [`-e${expression}`], ""],
+ [process.execPath, [`-p${expression}`], "undefined\n"],
+ ] as const) {
+ const result = await runCommand(
+ command,
+ [
+ "--import",
+ command === "node" ? pathToFileURL(preload).href : preload,
+ ...mode,
+ direct,
+ ],
+ { env: environment, timeout: 30_000 },
+ );
+ expect(result.status, result.stderr).toBe(0);
+ expect(result.stdout).toBe(stdout);
+ expect(result.stderr).toBe("");
+ }
+ }
});
diff --git a/sdk/typescript/tests-ts/skeleton.test.ts b/sdk/typescript/tests-ts/skeleton.test.ts
index 195d1e388..21b4ee2d4 100644
--- a/sdk/typescript/tests-ts/skeleton.test.ts
+++ b/sdk/typescript/tests-ts/skeleton.test.ts
@@ -345,8 +345,9 @@ describe("TypeScript package skeleton", () => {
["Check formatting", "static-checks"],
["Check MCP formatting", "static-checks"],
] as const) {
- expect(steps.filter((step) => step.name === name)).toHaveLength(1);
- expect(jobs[job]!.steps!.some((step) => step.name === name)).toBe(true);
+ expect(
+ jobs[job]!.steps!.filter((step) => step.name === name),
+ ).toHaveLength(1);
}
for (const name of [
"Upload test reports",