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(release): share note generation and test setup (#1373)

mldangelo-oai3e96bcaae827
diff --git a/sdk/typescript/scripts/release-automation.mjs b/sdk/typescript/scripts/release-automation.mjs
index bf8cbd517..8920a0f99 100644
--- a/sdk/typescript/scripts/release-automation.mjs
+++ b/sdk/typescript/scripts/release-automation.mjs
@@ -4,6 +4,14 @@ import { basename } from "node:path";
import { isMain } from "./is-main.mjs";
import { assertExpectedGitHead } from "./package-provenance.mjs";
+/**
+ * @typedef {Record<string, unknown>} ReleaseMetadata
+ * @typedef {{ version: string, gitHead: string }} PublishedRelease
+ * @typedef {PublishedRelease & { repository: string }} RepositoryRelease
+ * @typedef {RepositoryRelease & { runId: string }} WorkflowRelease
+ * @typedef {WorkflowRelease & { sha512: string }} ReleaseProvenance
+ */
+
const packageName = "@openai/codex-security";
const stableVersion = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/u;
const provenancePredicate = "https://slsa.dev/provenance/v1";
@@ -13,6 +21,7 @@ const fulcioExtensionPrefix = Buffer.from("2b0601040183bf3001", "hex");
const releaseSummaryStart = "<!-- codex-security-release-summary:start -->";
const releaseSummaryEnd = "<!-- codex-security-release-summary:end -->";
+/** @param {unknown} tag */
function stableReleaseTagVersion(tag) {
if (typeof tag !== "string" || !tag.startsWith("npm-v")) {
throw new Error("Release tags must identify a stable npm-vX.Y.Z version.");
@@ -25,6 +34,7 @@ function stableReleaseTagVersion(tag) {
return version;
}
+/** @param {unknown} version */
export function assertStableVersion(version) {
if (typeof version !== "string" || !stableVersion.test(version)) {
throw new Error("Release package must have a stable X.Y.Z version.");
@@ -32,6 +42,7 @@ export function assertStableVersion(version) {
return version;
}
+/** @param {ReleaseMetadata} packageJson */
export function releaseVersion(packageJson) {
if (packageJson?.name !== packageName) {
throw new Error("Release package must be @openai/codex-security.");
@@ -65,6 +76,7 @@ export function parseReviewedReleaseNotes(version, notes) {
return summary;
}
+/** @param {string} notes */
export function extractHistoricalReleaseSummary(notes) {
if (typeof notes !== "string") {
throw new Error("Existing release notes must be a string.");
@@ -99,6 +111,11 @@ export function extractHistoricalReleaseSummary(notes) {
return summary;
}
+/**
+ * @param {string} version
+ * @param {string | undefined} taggedNotes
+ * @param {string | undefined} existingNotes
+ */
export function resolveReleaseSummary(version, taggedNotes, existingNotes) {
if (taggedNotes !== undefined) {
return parseReviewedReleaseNotes(version, taggedNotes);
@@ -144,6 +161,12 @@ function releaseNoteFileArguments(args) {
return files;
}
+/**
+ * @param {string} refType
+ * @param {string} ref
+ * @param {string} refName
+ * @param {ReleaseMetadata} packageJson
+ */
export function releaseTagVersion(refType, ref, refName, packageJson) {
if (refType !== "tag" || ref !== `refs/tags/${refName}`) {
throw new Error("npm releases must be dispatched from a real Git tag.");
@@ -158,6 +181,10 @@ export function releaseTagVersion(refType, ref, refName, packageJson) {
return packageVersion;
}
+/**
+ * @param {string} left
+ * @param {string} right
+ */
export function compareReleaseVersions(left, right) {
if (!stableVersion.test(left) || !stableVersion.test(right)) {
throw new Error("Release versions must use stable X.Y.Z versions.");
@@ -172,6 +199,10 @@ export function compareReleaseVersions(left, right) {
return 0;
}
+/**
+ * @param {string} version
+ * @param {string} previousVersion
+ */
export function requireReleaseIncrease(version, previousVersion) {
if (compareReleaseVersions(version, previousVersion) <= 0) {
throw new Error(
@@ -181,6 +212,11 @@ export function requireReleaseIncrease(version, previousVersion) {
return version;
}
+/**
+ * @param {string} version
+ * @param {unknown} registryError
+ * @returns {string[]}
+ */
export function initialPublishedVersions(version, registryError) {
releaseVersion({ name: packageName, version });
if (version !== "0.1.0" || registryError?.error?.code !== "E404") {
@@ -189,6 +225,11 @@ export function initialPublishedVersions(version, registryError) {
return [];
}
+/**
+ * @param {string} version
+ * @param {unknown} publishedVersions
+ * @returns {"publish" | "recover"}
+ */
export function publishedReleaseMode(version, publishedVersions) {
releaseVersion({ name: packageName, version });
if (!Array.isArray(publishedVersions)) {
@@ -214,6 +255,10 @@ export function publishedReleaseMode(version, publishedVersions) {
return mode;
}
+/**
+ * @param {string} version
+ * @param {unknown} publishedVersions
+ */
export function requirePublishedReleaseIncrease(version, publishedVersions) {
if (publishedReleaseMode(version, publishedVersions) !== "publish") {
throw new Error(
@@ -439,6 +484,10 @@ function verifySigningCertificate(bundle, expected) {
}
}
+/**
+ * @param {string} tag
+ * @param {{ registryVersions: string[], githubReleaseTags: string[], reachableTags: string[] }} history
+ */
export function releaseHistory(tag, history) {
const version = stableReleaseTagVersion(tag);
if (
@@ -486,6 +535,11 @@ export function releaseHistory(tag, history) {
};
}
+/**
+ * @param {ReleaseMetadata} metadata
+ * @param {Uint8Array} archive
+ * @param {PublishedRelease} expected
+ */
export function verifyPublishedRelease(metadata, archive, expected) {
const version = releaseVersion(metadata);
if (version !== expected.version) {
@@ -516,6 +570,12 @@ export function verifyPublishedRelease(metadata, archive, expected) {
};
}
+/**
+ * @param {ReleaseMetadata} metadata
+ * @param {Uint8Array} archive
+ * @param {WorkflowRelease} expected
+ * @param {ReleaseProvenance} provenance
+ */
export function verifyGitHubPublishedRelease(
metadata,
archive,
@@ -568,6 +628,11 @@ function readProvenance(verified) {
return { provenance, statement };
}
+/**
+ * @param {ReleaseMetadata} report
+ * @param {Uint8Array} archive
+ * @param {WorkflowRelease} expected
+ */
export function verifySignatureAudit(report, archive, expected) {
if (
!Array.isArray(report?.invalid) ||
@@ -712,6 +777,11 @@ export function verifySignatureAudit(report, archive, expected) {
};
}
+/**
+ * @param {ReleaseMetadata} report
+ * @param {Uint8Array} archive
+ * @param {RepositoryRelease} expected
+ */
export function verifyRecoveredSignatureAudit(report, archive, expected) {
const version = releaseVersion({
name: packageName,
@@ -761,6 +831,13 @@ export function verifyRecoveredSignatureAudit(report, archive, expected) {
});
}
+/**
+ * @param {ReleaseMetadata} release
+ * @param {Uint8Array} archive
+ * @param {string} expectedTag
+ * @param {string} assetName
+ * @param {Uint8Array} [downloadedArchive]
+ */
export function verifyGitHubRelease(
release,
archive,
diff --git a/sdk/typescript/scripts/release-pr.mjs b/sdk/typescript/scripts/release-pr.mjs
index 67ea14a31..2ace87cc6 100644
--- a/sdk/typescript/scripts/release-pr.mjs
+++ b/sdk/typescript/scripts/release-pr.mjs
@@ -124,28 +124,18 @@ export function updateReleaseNotes(
) {
const header = `<!-- release-version: ${version} -->`;
const sections = {};
- if (previousSections === undefined) {
- const blocks = sectionIds.map((id) => {
- const block = sectionBlock(id, generated[id]);
- sections[id] = {
- generatedHash: hash("sha256", block),
- humanOwned: false,
- };
- return block;
- });
- return { notes: `${header}\n\n${blocks.join("\n\n")}\n`, sections };
- }
-
- let notes = previousNotes;
+ const initial = previousSections === undefined;
+ let notes = initial ? null : previousNotes;
if (notes !== null) {
notes = /^<!-- release-version: [^\r\n]* -->/u.test(notes)
? notes.replace(/^<!-- release-version: [^\r\n]* -->/u, header)
: `${header}\n\n${notes}`;
}
for (const id of sectionIds) {
- const previous = previousSections[id];
- const block = notes === null ? null : findSection(notes, id);
+ const previous = initial ? null : previousSections[id];
+ const block = initial || notes === null ? null : findSection(notes, id);
const humanOwned =
+ !initial &&
previous?.reset !== true &&
(previous?.humanOwned !== false ||
block === null ||
diff --git a/sdk/typescript/tests-ts/api-provider-isolation.test.ts b/sdk/typescript/tests-ts/api-provider-isolation.test.ts
index 3382380b3..d01072630 100644
--- a/sdk/typescript/tests-ts/api-provider-isolation.test.ts
+++ b/sdk/typescript/tests-ts/api-provider-isolation.test.ts
@@ -196,6 +196,7 @@ test.each(["root", "profile override", "profile only"] as const)(
await effectiveProvider({ CODEX_HOME: sharedHome }, repository, []);
const workerRuntimeSettings = await loadWorkerSettings(root);
+ let nativeProbe = Promise.resolve();
const ready = [
Promise.withResolvers<void>(),
@@ -362,12 +363,20 @@ test.each(["root", "profile override", "profile only"] as const)(
featureOverrides,
);
expect(settings.config["web_search"]).toBe(webSearch);
- const actual = await effectiveProvider(
- environment,
- repository,
- profileConfigOverrides(settings.config),
- settings.nativeProfile,
+ // Native SQLite probes share a home; keep the scans concurrent.
+ const probe = nativeProbe.then(() =>
+ effectiveProvider(
+ environment,
+ repository,
+ profileConfigOverrides(settings.config),
+ settings.nativeProfile,
+ ),
);
+ nativeProbe = probe.then(
+ () => undefined,
+ () => undefined,
+ );
+ const actual = await probe;
expect(actual).toMatchObject(provider);
expect(actual.http_headers ?? {}).toEqual(
provider.http_headers ?? {},
diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts
index d21a61552..dd5eb6d75 100644
--- a/sdk/typescript/tests-ts/cli.test.ts
+++ b/sdk/typescript/tests-ts/cli.test.ts
@@ -122,14 +122,15 @@ async function multiscanInventory(root: string): Promise<void> {
"initial",
],
]) {
- const result = await runCommand("git", args, { timeout: 10_000 });
+ const result = await runCommand("git", args);
expect(result.status, result.stderr).toBe(0);
}
- const { status, stdout, stderr } = await runCommand(
- "git",
- ["-C", repository, "rev-parse", "HEAD"],
- { timeout: 10_000 },
- );
+ const { status, stdout, stderr } = await runCommand("git", [
+ "-C",
+ repository,
+ "rev-parse",
+ "HEAD",
+ ]);
expect(status, stderr).toBe(0);
await writeFile(
join(root, "repositories.csv"),
@@ -508,7 +509,7 @@ describe("CLI", () => {
["init", "-q", root],
["-C", root, "config", "core.hooksPath", ".custom hooks"],
]) {
- const result = await runCommand("git", args, { timeout: 10_000 });
+ const result = await runCommand("git", args);
expect(result.status, result.stderr).toBe(0);
}
let started = false;
@@ -599,11 +600,13 @@ describe("CLI", () => {
'#!/bin/sh\nprintf "codex-security\\n" > "$CODEX_SECURITY_HOOK_MARKER"\nexit 0\n',
{ mode: 0o755 },
);
- const staged = await runCommand(
- "git",
- ["-C", root, "add", "-f", "node_modules/.bin/codex-security"],
- { timeout: 10_000 },
- );
+ const staged = await runCommand("git", [
+ "-C",
+ root,
+ "add",
+ "-f",
+ "node_modules/.bin/codex-security",
+ ]);
expect(staged.status, staged.stderr).toBe(0);
const commit = await runCommand(
"git",
@@ -630,7 +633,6 @@ describe("CLI", () => {
OPENAI_API_KEY: "",
PATH: [binaries, process.env["PATH"] ?? ""].join(delimiter),
},
- timeout: 10_000,
},
);
expect(commit.status, commit.stderr).toBeGreaterThan(0);
diff --git a/sdk/typescript/tests-ts/mock-scan.test.ts b/sdk/typescript/tests-ts/mock-scan.test.ts
index be812918a..80624f5b0 100644
--- a/sdk/typescript/tests-ts/mock-scan.test.ts
+++ b/sdk/typescript/tests-ts/mock-scan.test.ts
@@ -212,23 +212,19 @@ test("mock scan CLI forwards the flag and never offers authentication or patchin
test("mock scans bind clean Git, committed diff, and working-tree snapshots", async () => {
const { root, repository, client } = await fixture();
const git = async (...args: string[]) => {
- const result = await runCommand(
- "git",
- [
- "-C",
- repository,
- "-c",
- `core.hooksPath=${join(root, "hooks")}`,
- "-c",
- "commit.gpgsign=false",
- "-c",
- "user.name=Example",
- "-c",
- ...args,
- ],
- { timeout: 10000 },
- );
+ const result = await runCommand("git", [
+ "-C",
+ repository,
+ "-c",
+ `core.hooksPath=${join(root, "hooks")}`,
+ "-c",
+ "commit.gpgsign=false",
+ "-c",
+ "user.name=Example",
+ "-c",
+ ...args,
+ ]);
expect(result.status).toBe(0);
};
try {
diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.ts
index b524208c4..f8a542355 100644
--- a/sdk/typescript/tests-ts/release-automation.test.ts
+++ b/sdk/typescript/tests-ts/release-automation.test.ts
@@ -13,126 +13,8 @@ import { fileURLToPath } from "node:url";
import { describe, expect, test } from "bun:test";
import { bashCommand, runCommand } from "./support/shell.js";
-type ReleaseMetadata = Record<string, unknown>;
-
-type ReleaseAutomation = {
- parseReviewedReleaseNotes: (version: string, notes: string) => string;
- extractHistoricalReleaseSummary: (notes: string) => string | null;
- resolveReleaseSummary: (
- version: string,
- taggedNotes: string | undefined,
- existingNotes: string | undefined,
- ) => string | null;
- composeReleaseNotes: (
- generatedNotes: string,
- releaseSummary: string | null,
- ) => string;
- releaseVersion: (packageJson: ReleaseMetadata) => string;
- releaseTagVersion: (
- refType: string,
- ref: string,
- refName: string,
- packageJson: ReleaseMetadata,
- ) => string;
- compareReleaseVersions: (left: string, right: string) => -1 | 0 | 1;
- requireReleaseIncrease: (version: string, previousVersion: string) => string;
- initialPublishedVersions: (
- version: string,
- registryError: unknown,
- ) => string[];
- publishedReleaseMode: (
- version: string,
- publishedVersions: unknown,
- ) => "publish" | "recover";
- requirePublishedReleaseIncrease: (
- version: string,
- publishedVersions: unknown,
- ) => string;
- releaseHistory: (
- tag: string,
- history: {
- registryVersions: string[];
- githubReleaseTags: string[];
- reachableTags: string[];
- },
- ) => { previousTag: string | null; makeLatest: boolean };
- verifyPublishedRelease: (
- metadata: ReleaseMetadata,
- archive: Uint8Array,
- expected: { version: string; gitHead: string },
- ) => {
- version: string;
- gitHead: string;
- integrity: string;
- sha256: string;
- };
- verifyGitHubPublishedRelease: (
- metadata: ReleaseMetadata,
- archive: Uint8Array,
- expected: {
- version: string;
- gitHead: string;
- repository: string;
- runId: string;
- },
- provenance: {
- version: string;
- gitHead: string;
- repository: string;
- runId: string;
- sha512: string;
- },
- ) => {
- version: string;
- gitHead: string;
- integrity: string;
- sha256: string;
- };
- verifySignatureAudit: (
- report: ReleaseMetadata,
- archive: Uint8Array,
- expected: {
- version: string;
- gitHead: string;
- repository: string;
- runId: string;
- },
- ) => {
- version: string;
- gitHead: string;
- repository: string;
- runId: string;
- sha512: string;
- };
- verifyRecoveredSignatureAudit: (
- report: ReleaseMetadata,
- archive: Uint8Array,
- expected: {
- version: string;
- gitHead: string;
- repository: string;
- },
- ) => {
- version: string;
- gitHead: string;
- repository: string;
- runId: string;
- sha512: string;
- };
- verifyGitHubRelease: (
- release: ReleaseMetadata,
- archive: Uint8Array,
- expectedTag: string,
- assetName: string,
- downloadedArchive?: Uint8Array,
- ) => { tag: string; asset: string; digest: string };
-};
-
-const automationScript = new URL(
- "../scripts/release-automation.mjs",
- import.meta.url,
-);
-const {
+import {
+ type ReleaseMetadata,
parseReviewedReleaseNotes,
extractHistoricalReleaseSummary,
resolveReleaseSummary,
@@ -150,7 +32,12 @@ const {
verifySignatureAudit,
verifyRecoveredSignatureAudit,
verifyGitHubRelease,
-} = (await import(automationScript.href)) as ReleaseAutomation;
+} from "../scripts/release-automation.mjs";
+
+const automationScript = new URL(
+ "../scripts/release-automation.mjs",
+ import.meta.url,
+);
const releaseCommit = "1e03c89ad22d2df5ae65b146be1483b3608572a9";
const releaseRun = "30481596229";
@@ -159,11 +46,14 @@ const releaseWorkflowTimeout = process.platform === "win32" ? 20_000 : 10_000;
const bash = bashCommand();
-function runShell(script: string, env: NodeJS.ProcessEnv, cwd?: string) {
+function runShell(
+ script: string,
+ env: NodeJS.ProcessEnv,
+ options: { cwd?: string; timeout?: number } = {},
+) {
return runCommand(bash, ["-c", script], {
- cwd,
+ ...options,
env: { ...process.env, ...env },
- timeout: 10_000,
});
}
@@ -420,6 +310,14 @@ function signatureExpected() {
};
}
+function verifySignatureFixture(options: SignatureAuditFixture = {}) {
+ return verifySignatureAudit(
+ signatureAudit(options),
+ archive,
+ signatureExpected(),
+ );
+}
+
function workflowStepShell(workflow: string, stepName: string): string {
const stepMarker = ` - name: ${stepName}\n`;
const stepStart = workflow.indexOf(stepMarker);
@@ -1119,9 +1017,7 @@ describe("GitHub release publication verification", () => {
describe("cryptographically verified npm provenance", () => {
test("binds the verified bundle to the exact archive, source, and run", () => {
- expect(
- verifySignatureAudit(signatureAudit(), archive, signatureExpected()),
- ).toEqual({
+ expect(verifySignatureFixture()).toEqual({
version: "0.1.2",
gitHead: releaseCommit,
repository: releaseRepository,
@@ -1149,13 +1045,7 @@ describe("cryptographically verified npm provenance", () => {
test.each(["", "0", "01", "not-a-number", "1/extra", "1?attempt=2"])(
"rejects the malformed protected workflow run attempt %j",
(attempt) => {
- expect(() =>
- verifySignatureAudit(
- signatureAudit({ attempt }),
- archive,
- signatureExpected(),
- ),
- ).toThrow(
+ expect(() => verifySignatureFixture({ attempt })).toThrow(
"Verified SLSA provenance must identify the successful release run.",
);
expect(() =>
@@ -1209,13 +1099,7 @@ describe("cryptographically verified npm provenance", () => {
});
test("accepts the real Fulcio certificate in the legacy chain format", () => {
- expect(
- verifySignatureAudit(
- signatureAudit({ certificateLocation: "chain" }),
- archive,
- signatureExpected(),
- ),
- ).toEqual({
+ expect(verifySignatureFixture({ certificateLocation: "chain" })).toEqual({
version: "0.1.2",
gitHead: releaseCommit,
repository: releaseRepository,
@@ -1226,13 +1110,9 @@ describe("cryptographically verified npm provenance", () => {
test("rejects missing and malformed Fulcio signing certificates", () => {
for (const signingCertificate of [null, "not-base64"]) {
- expect(() =>
- verifySignatureAudit(
- signatureAudit({ signingCertificate }),
- archive,
- signatureExpected(),
- ),
- ).toThrow("The verified Fulcio signing certificate is invalid.");
+ expect(() => verifySignatureFixture({ signingCertificate })).toThrow(
+ "The verified Fulcio signing certificate is invalid.",
+ );
}
});
@@ -1247,13 +1127,9 @@ describe("cryptographically verified npm provenance", () => {
for (const certificate of invalidCertificates) {
expect(() =>
- verifySignatureAudit(
- signatureAudit({
- signingCertificate: certificate.toString("base64"),
- }),
- archive,
- signatureExpected(),
- ),
+ verifySignatureFixture({
+ signingCertificate: certificate.toString("base64"),
+ }),
).toThrow("The verified Fulcio signing certificate is invalid.");
}
});
@@ -1401,13 +1277,7 @@ describe("cryptographically verified npm provenance", () => {
"Verified SLSA provenance must use a GitHub-hosted release runner.",
},
])("$name", ({ options, message }) => {
- expect(() =>
- verifySignatureAudit(
- signatureAudit(options()),
- archive,
- signatureExpected(),
- ),
- ).toThrow(message);
+ expect(() => verifySignatureFixture(options())).toThrow(message);
});
test("rejects malformed attestation bundle collections safely", () => {
@@ -1430,15 +1300,21 @@ describe("cryptographically verified npm provenance", () => {
});
describe("idempotent GitHub release verification", () => {
+ function verifyGitHubReleaseFixture(
+ release: ReleaseMetadata,
+ downloadedArchive?: Uint8Array,
+ ) {
+ return verifyGitHubRelease(
+ release,
+ archive,
+ "npm-v0.1.2",
+ "openai-codex-security-0.1.2.tgz",
+ downloadedArchive,
+ );
+ }
+
test("accepts the already-published exact verified release asset", () => {
- expect(
- verifyGitHubRelease(
- githubRelease(),
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- ),
- ).toEqual({
+ expect(verifyGitHubReleaseFixture(githubRelease())).toEqual({
tag: "npm-v0.1.2",
asset: "openai-codex-security-0.1.2.tgz",
digest,
@@ -1449,15 +1325,12 @@ describe("idempotent GitHub release verification", () => {
const release = githubRelease();
expect(
- verifyGitHubRelease(
+ verifyGitHubReleaseFixture(
{
...release,
assets: [{ name: "openai-codex-security-0.1.2.tgz" }],
},
archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- archive,
),
).toEqual({
tag: "npm-v0.1.2",
@@ -1468,15 +1341,10 @@ describe("idempotent GitHub release verification", () => {
test("rejects a digestless release asset without its downloaded bytes", () => {
expect(() =>
- verifyGitHubRelease(
- {
- ...githubRelease(),
- assets: [{ name: "openai-codex-security-0.1.2.tgz" }],
- },
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- ),
+ verifyGitHubReleaseFixture({
+ ...githubRelease(),
+ assets: [{ name: "openai-codex-security-0.1.2.tgz" }],
+ }),
).toThrow(
"Existing GitHub Release asset must match the verified npm artifact.",
);
@@ -1484,14 +1352,11 @@ describe("idempotent GitHub release verification", () => {
test("rejects downloaded release bytes that differ from the npm archive", () => {
expect(() =>
- verifyGitHubRelease(
+ verifyGitHubReleaseFixture(
{
...githubRelease(),
assets: [{ name: "openai-codex-security-0.1.2.tgz" }],
},
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
Buffer.from("different downloaded GitHub release"),
),
).toThrow(
@@ -1501,42 +1366,30 @@ describe("idempotent GitHub release verification", () => {
test("rejects a GitHub release for another tag", () => {
expect(() =>
- verifyGitHubRelease(
- { ...githubRelease(), tag_name: "npm-v0.1.1" },
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- ),
+ verifyGitHubReleaseFixture({
+ ...githubRelease(),
+ tag_name: "npm-v0.1.1",
+ }),
).toThrow("Existing GitHub Release must match the release tag.");
});
test("rejects a draft or prerelease", () => {
expect(() =>
- verifyGitHubRelease(
- { ...githubRelease(), draft: true },
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- ),
+ verifyGitHubReleaseFixture({ ...githubRelease(), draft: true }),
).toThrow("Existing GitHub Release must be published and stable.");
});
test("rejects a missing or different GitHub release artifact", () => {
expect(() =>
- verifyGitHubRelease(
- {
- ...githubRelease(),
- assets: [
- {
- name: "openai-codex-security-0.1.2.tgz",
- digest: "sha256:incorrect",
- },
- ],
- },
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- ),
+ verifyGitHubReleaseFixture({
+ ...githubRelease(),
+ assets: [
+ {
+ name: "openai-codex-security-0.1.2.tgz",
+ digest: "sha256:incorrect",
+ },
+ ],
+ }),
).toThrow(
"Existing GitHub Release asset must match the verified npm artifact.",
);
@@ -1545,12 +1398,7 @@ describe("idempotent GitHub release verification", () => {
test("rejects malformed GitHub release assets safely", () => {
for (const assets of [null, {}, [null]]) {
expect(() =>
- verifyGitHubRelease(
- { ...githubRelease(), assets },
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- ),
+ verifyGitHubReleaseFixture({ ...githubRelease(), assets }),
).toThrow(
"Existing GitHub Release asset must match the verified npm artifact.",
);
@@ -1561,15 +1409,10 @@ describe("idempotent GitHub release verification", () => {
const release = githubRelease();
expect(
- verifyGitHubRelease(
- {
- ...release,
- assets: [null, ...(release["assets"] as ReleaseMetadata[])],
- },
- archive,
- "npm-v0.1.2",
- "openai-codex-security-0.1.2.tgz",
- ),
+ verifyGitHubReleaseFixture({
+ ...release,
+ assets: [null, ...(release["assets"] as ReleaseMetadata[])],
+ }),
).toEqual({
tag: "npm-v0.1.2",
asset: "openai-codex-security-0.1.2.tgz",
@@ -1697,7 +1540,7 @@ describe("GitHub release workflow safeguards", () => {
MOCK_RELEASE_SUMMARY: summary,
RELEASE_VERSION: "0.1.6",
},
- fileURLToPath(new URL("../../../", import.meta.url)),
+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },
);
expect(result.status).toBe(status);
@@ -1808,7 +1651,7 @@ describe("GitHub release workflow safeguards", () => {
GITHUB_REF: "refs/heads/main",
GITHUB_SHA: releaseCommit,
},
- fileURLToPath(new URL("../../../", import.meta.url)),
+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },
);
expect(result.status).toBe(1);
@@ -1955,7 +1798,7 @@ describe("GitHub release workflow safeguards", () => {
MOCK_TAGGED_ANCESTOR: String(taggedAncestor),
RELEASE_SHA: releaseCommit,
},
- fileURLToPath(new URL("../../../", import.meta.url)),
+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },
);
expect(result.stderr).toBe("");
@@ -2024,7 +1867,7 @@ describe("GitHub release workflow safeguards", () => {
MOCK_RELEASE_SUMMARY: summary,
RELEASE_SHA: releaseCommit,
},
- fileURLToPath(new URL("../../../", import.meta.url)),
+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },
);
expect(result.status).toBe(1);
@@ -2115,7 +1958,7 @@ describe("GitHub release workflow safeguards", () => {
}),
MOCK_RELEASE_VERSION: version,
},
- fileURLToPath(new URL("../../../", import.meta.url)),
+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },
);
expect(result.status).toBe(status);
@@ -2150,16 +1993,16 @@ describe("GitHub release workflow safeguards", () => {
" printf 'created tag at %s\\n' \"$RELEASE_SHA\"",
"}",
].join("\n");
- const result = await runCommand(bash, ["-c", `${mock}\n${script}`], {
- env: {
- ...process.env,
+ const result = await runShell(
+ `${mock}\n${script}`,
+ {
GITHUB_REPOSITORY: "test/codex-security",
GITHUB_SHA: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
RELEASE_SHA: releaseCommit,
RELEASE_TAG: "npm-v0.1.2",
},
- timeout: releaseWorkflowTimeout,
- });
+ { timeout: releaseWorkflowTimeout },
+ );
expect(result.status).toBe(0);
expect(result.stdout).toContain(`created tag at ${releaseCommit}`);
@@ -2218,17 +2061,17 @@ describe("GitHub release workflow safeguards", () => {
" printf 'created exact release tag\\n'",
"}",
].join("\n");
- const result = await runCommand(bash, ["-c", `${mock}\n${script}`], {
- env: {
- ...process.env,
+ const result = await runShell(
+ `${mock}\n${script}`,
+ {
GITHUB_REPOSITORY: "test/codex-security",
GITHUB_SHA: releaseCommit,
MOCK_LOOKUP_HTTP_STATUS: lookupHttpStatus,
MOCK_LOOKUP_RESPONSE: lookupResponse,
RELEASE_TAG: "npm-v0.1.2",
},
- timeout: releaseWorkflowTimeout,
- });
+ { timeout: releaseWorkflowTimeout },
+ );
expect(result.status).toBe(status);
if (status === 0) {
@@ -2294,9 +2137,9 @@ describe("GitHub release workflow safeguards", () => {
" esac",
"}",
].join("\n");
- const result = await runCommand(bash, ["-c", `${mock}\n${script}`], {
- env: {
- ...process.env,
+ const result = await runShell(
+ `${mock}\n${script}`,
+ {
GITHUB_REPOSITORY: "test/codex-security",
GITHUB_SHA: releaseCommit,
MOCK_PEELED_COMMIT: peeledCommit,
@@ -2304,8 +2147,8 @@ describe("GitHub release workflow safeguards", () => {
MOCK_TAG_TYPE: tagType,
RELEASE_TAG: "npm-v0.1.2",
},
- timeout: releaseWorkflowTimeout,
- });
+ { timeout: releaseWorkflowTimeout },
+ );
expect(result.status).toBe(status);
if (status === 0) {
@@ -2425,7 +2268,7 @@ describe("GitHub release workflow safeguards", () => {
GITHUB_REF_TYPE: "tag",
GITHUB_SHA: releaseCommit,
},
- fileURLToPath(new URL("../../../", import.meta.url)),
+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },
);
expect(result.status).toBe(1);
@@ -2452,7 +2295,7 @@ describe("GitHub release workflow safeguards", () => {
GITHUB_REF_TYPE: "tag",
GITHUB_SHA: releaseCommit,
},
- fileURLToPath(new URL("../../../", import.meta.url)),
+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },
);
expect(result.status).toBe(0);
@@ -2562,16 +2405,16 @@ describe("GitHub release workflow safeguards", () => {
' printf "wait\\n" >> "$MOCK_CALL_LOG"',
"}",
].join("\n");
- const result = await runCommand(bash, ["-c", `${mocks}\n${script}`], {
- env: {
- ...process.env,
+ const result = await runShell(
+ `${mocks}\n${script}`,
+ {
MOCK_CALL_LOG: callLog,
MOCK_MISSING_ATTEMPTS: String(missingAttempts),
MOCK_ERROR_CODE: errorCode,
RELEASE_VERSION: "0.1.2",
},
- timeout: releaseWorkflowTimeout,
- });
+ { timeout: releaseWorkflowTimeout },
+ );
const events = readFileSync(callLog, "utf8").split("\n");
expect(result.status).toBe(status);
expect(events.filter((event) => event === "query")).toHaveLength(calls);
@@ -3179,7 +3022,7 @@ describe("GitHub release workflow safeguards", () => {
RELEASE_TAG: "npm-v0.1.2",
RELEASE_VERSION: "0.1.2",
},
- workspace,
+ { cwd: workspace },
);
expect(result.status).toBe(status);
diff --git a/sdk/typescript/tests-ts/support/shell.ts b/sdk/typescript/tests-ts/support/shell.ts
index 2fec8ac9e..b33591da8 100644
--- a/sdk/typescript/tests-ts/support/shell.ts
+++ b/sdk/typescript/tests-ts/support/shell.ts
@@ -25,14 +25,15 @@ export function runCommand(
args: string[],
{
input,
+ timeout = 10_000,
...options
}: {
cwd?: string;
env?: NodeJS.ProcessEnv;
input?: string;
- timeout: number;
+ timeout?: number;
windowsHide?: boolean;
- },
+ } = {},
): Promise<{
status: number | null;
stdout: string;
@@ -45,7 +46,7 @@ export function runCommand(
const child = execFile(
command,
args,
- { ...options, encoding: "utf8" },
+ { ...options, timeout, encoding: "utf8" },
(error, stdout, stderr) => {
resolve({
status: child.exitCode,