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

test(ci): simplify container workflow fixtures and gate checks (#1992)

Michael D'Angelod2db069dc2c4
diff --git a/.github/scripts/test-ci-selection.mjs b/.github/scripts/test-ci-selection.mjs
index ca6a08035..ac4d33e65 100644
--- a/.github/scripts/test-ci-selection.mjs
+++ b/.github/scripts/test-ci-selection.mjs
@@ -244,6 +244,7 @@ test("release helper changes select their release-progress regression checks", (
test("ordinary TypeScript source and tests retain the reduced version matrices", () => {
for (const path of [
"sdk/typescript/src/cost.ts",
+ "sdk/typescript/src/index.ts",
"sdk/typescript/tests-ts/support/test-subprocess.ts",
"plugins/codex-security/mcp-app/src/stdio-transport.ts",
"plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts",
@@ -323,6 +324,13 @@ test("unknown paths and dependency configuration receive full qualification", ()
test("tooling and non-TypeScript product inputs receive full qualification", () => {
for (const path of [
+ "Dockerfile",
+ ".github/workflows/container-ci.yml",
+ ".github/workflows/container-validate.yml",
+ ".github/workflows/container-release.yml",
+ ".github/workflows/native-windows.yml",
+ "sdk/typescript/scripts/run-ci-tests.mts",
+ "plugins/codex-security/skills/example/SKILL.md",
"package.json",
"sdk/typescript/pnpm-lock.yaml",
"sdk/typescript/bunfig.toml",
@@ -401,9 +409,29 @@ test("the final gate distinguishes a failed check from a skipped dependent job",
encoding: "utf8",
});
const needs = successfulFullRun();
- const passed = run(needs);
- assert.equal(passed.status, 0, passed.stderr);
- assert.equal(passed.stdout.trim(), "All selected required CI checks passed.");
+ for (const selected of [true, false]) {
+ const outputs = select([selected ? "Dockerfile" : "README.md"]);
+ for (const result of ["success", "failure", "cancelled", "skipped"]) {
+ const verdict = run({
+ ...needs,
+ "classify-changes": { result: "success", outputs },
+ "container-validate": { result },
+ });
+ const failed = selected && result !== "success";
+ assert.equal(verdict.status, failed ? 1 : 0, verdict.stderr);
+ if (failed) {
+ assert.ok(
+ verdict.stderr.includes(`container-validate (${result})`),
+ verdict.stderr,
+ );
+ } else {
+ assert.equal(
+ verdict.stdout.trim(),
+ "All selected required CI checks passed.",
+ );
+ }
+ }
+ }
needs["static-checks"].result = "failure";
needs["container-validate"].result = "skipped";
diff --git a/sdk/typescript/tests-ts/container-ci-workflow.test.ts b/sdk/typescript/tests-ts/container-ci-workflow.test.ts
index cc8633a08..7da272612 100644
--- a/sdk/typescript/tests-ts/container-ci-workflow.test.ts
+++ b/sdk/typescript/tests-ts/container-ci-workflow.test.ts
@@ -1,14 +1,11 @@
-import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
-import { fileURLToPath } from "node:url";
import { expect, test } from "bun:test";
-type Step = { name?: string; uses?: string; run?: string; if?: string };
type Job = {
uses?: string;
needs?: string | string[];
if?: string;
- steps?: Step[];
+ steps?: Array<{ name?: string }>;
strategy?: { matrix: { include: Array<{ architecture: string }> } };
};
@@ -22,14 +19,6 @@ function workflow(name: string) {
}
const ci = workflow("node-ci");
-const { selectChecks } = (await import(
- new URL("../../../.github/scripts/select-ci-checks.mjs", import.meta.url).href
-)) as {
- selectChecks(
- paths: string[],
- options: { event: string; baseChanged: boolean },
- ): Record<string, string>;
-};
test("shares one native build and container matrix in automatic CI", () => {
const container = workflow("container-ci");
@@ -47,6 +36,7 @@ test("shares one native build and container matrix in automatic CI", () => {
).toEqual([ci.jobs["container-validate"]!]);
expect(ci.jobs["container-validate"]).toMatchObject({
needs: ["classify-changes", "native", "static-checks"],
+ if: "needs.classify-changes.outputs.container-validate == 'true'",
uses: "./.github/workflows/container-validate.yml",
});
expect(container.jobs["container"]).toMatchObject({
@@ -86,76 +76,3 @@ test("keeps container validation available to forks and publication upstream-onl
);
expect(release.jobs["publish-platform"]?.needs).toBe("authorize");
});
-
-test.each([
- ["push", false, "README.md", true],
- ["pull_request", true, "README.md", true],
- ["pull_request", false, "README.md", false],
- ["pull_request", false, "Dockerfile", true],
- ["pull_request", false, ".github/workflows/container-ci.yml", true],
- ["pull_request", false, ".github/workflows/container-validate.yml", true],
- ["pull_request", false, ".github/workflows/container-release.yml", true],
- ["pull_request", false, ".github/workflows/native-windows.yml", true],
- ["pull_request", false, ".github/workflows/node-ci.yml", true],
- ["pull_request", false, ".github/actions/setup-tools/action.yml", true],
- ["pull_request", false, "sdk/typescript/src/index.ts", true],
- ["pull_request", false, "sdk/typescript/scripts/run-ci-tests.mts", true],
- [
- "pull_request",
- false,
- "plugins/codex-security/skills/example/SKILL.md",
- true,
- ],
-] as const)(
- "selects container validation for %s / retarget=%p / %s",
- (eventName, baseChanged, path, selected) => {
- const outputs = selectChecks([path], { event: eventName, baseChanged });
- expect(outputs["container-validate"]).toBe(String(selected));
- },
-);
-
-test("the final CI gate executes selected container failures and permits unselected checks", () => {
- const gate = ci.jobs["ci"]!;
- expect(gate.needs).toContain("container-validate");
- expect(gate.if).toContain("always()");
- const step = gate.steps!.find(
- (step) => step.name === "Require selected checks",
- )!;
- const [command, script] = step.run!.split(" ");
- expect(command).toBe("node");
- for (const selected of [true, false]) {
- const outputs = selectChecks([selected ? "Dockerfile" : "README.md"], {
- event: "pull_request",
- baseChanged: false,
- });
- const needs = Object.fromEntries(
- (gate.needs as string[]).map((name) => [name, { result: "success" }]),
- );
- const classified = {
- ...needs,
- "classify-changes": { result: "success", outputs },
- "action-ci": { result: "success", outputs: { passed: "true" } },
- };
- for (const result of ["success", "failure", "cancelled", "skipped"]) {
- const execution = spawnSync(
- command!,
- [fileURLToPath(new URL(`../../../${script}`, import.meta.url))],
- {
- encoding: "utf8",
- env: {
- ...process.env,
- CI_RESULTS: JSON.stringify({
- ...classified,
- "container-validate": { result },
- }),
- },
- },
- );
- expect(execution.status, execution.stderr).toBe(
- selected && result !== "success" ? 1 : 0,
- );
- if (selected && result !== "success")
- expect(execution.stderr).toContain("container-validate");
- }
- }
-});
diff --git a/sdk/typescript/tests-ts/container-release-workflow.test.ts b/sdk/typescript/tests-ts/container-release-workflow.test.ts
index f3e6f520f..23b3f3d73 100644
--- a/sdk/typescript/tests-ts/container-release-workflow.test.ts
+++ b/sdk/typescript/tests-ts/container-release-workflow.test.ts
@@ -1,15 +1,8 @@
import { afterEach, expect, test } from "bun:test";
import { execFileSync } from "node:child_process";
-import {
- copyFileSync,
- mkdirSync,
- mkdtempSync,
- readFileSync,
- rmSync,
- writeFileSync,
-} from "node:fs";
-import { tmpdir } from "node:os";
+import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { delimiter, join } from "node:path";
+import { createTemporaryDirectoriesSync } from "./support/temporary-directories.js";
import { runWorkflowScript } from "./support/workflow-script.js";
type Step = {
@@ -42,15 +35,11 @@ function workflow(name: string) {
};
}
const release = workflow("container-release");
-const directories: string[] = [];
-afterEach(() => {
- for (const directory of directories.splice(0))
- rmSync(directory, { recursive: true, force: true });
-});
+const directories = createTemporaryDirectoriesSync();
+afterEach(directories.cleanup);
function fixture() {
- const directory = mkdtempSync(join(tmpdir(), "container release "));
- directories.push(directory);
+ const directory = directories.create("container release ");
const repository = join(directory, "source");
mkdirSync(join(repository, "sdk/typescript"), { recursive: true });
const output = join(directory, "output");
@@ -102,7 +91,7 @@ function fixture() {
);
return { ...result, output: readFileSync(output, "utf8") };
}
- return { directory, repository, source, automation, git, commit, run };
+ return { source, automation, git, commit, run };
}
test("backfills the tagged release after main has advanced", () => {
@@ -258,18 +247,20 @@ test("builds and downloads native payloads from the same source as the image", (
const digest = `sha256:${"a".repeat(64)}`;
function existingFixture() {
- const source = fixture();
- const bin = join(source.directory, "bin");
- const events = join(source.directory, "events");
- const output = join(source.directory, "reuse-output");
+ const directory = directories.create("container release ");
+ const source = "1".repeat(40);
+ const repository = join(directory, "source");
+ const bin = join(directory, "bin");
+ const events = join(directory, "events");
+ const output = join(directory, "reuse-output");
mkdirSync(bin);
- mkdirSync(join(source.repository, "docker"));
+ mkdirSync(join(repository, "docker"), { recursive: true });
copyFileSync(
new URL(
"../../../docker/verify-container-release-version.sh",
import.meta.url,
),
- join(source.repository, "docker/verify-container-release-version.sh"),
+ join(repository, "docker/verify-container-release-version.sh"),
);
writeFileSync(
join(bin, "gh"),
@@ -297,7 +288,7 @@ esac
const manifest = {
annotations: {
"org.opencontainers.image.version": "99.1.2",
- "org.opencontainers.image.revision": source.source,
+ "org.opencontainers.image.revision": source,
},
manifests: ["amd64", "arm64"].map((architecture) => ({
platform: { os: "linux", architecture },
@@ -309,7 +300,7 @@ esac
function run(env: Record<string, string> = {}) {
writeFileSync(events, "");
writeFileSync(output, "");
- const result = runWorkflowScript(source.repository, script, {
+ const result = runWorkflowScript(repository, script, {
PATH: `${bin}${delimiter}${process.env["PATH"]}`,
EVENTS: events.replaceAll("\\", "/"),
GITHUB_OUTPUT: output.replaceAll("\\", "/"),
@@ -317,12 +308,12 @@ esac
GITHUB_REPOSITORY_OWNER: "Example",
IMAGE: "ghcr.io/example/codex-security",
VERSION: "99.1.2",
- RELEASE_SHA: source.source,
+ RELEASE_SHA: source,
MOCK_VERSIONS: JSON.stringify([
{
name: digest,
metadata: {
- container: { tags: ["99.1.2", "latest", `sha-${source.source}`] },
+ container: { tags: ["99.1.2", "latest", `sha-${source}`] },
},
},
]),
@@ -338,7 +329,7 @@ esac
events: readFileSync(events, "utf8"),
};
}
- return { run, manifest, source: source.source };
+ return { run, manifest, source };
}
test("verifies and reuses the published source without a registry write", () => {