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): share the protected release lookup fixture (#2026)

Michael D'Angeloc55240536ef3
diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.ts
index 414d8c386..716390ae0 100644
--- a/sdk/typescript/tests-ts/release-automation.test.ts
+++ b/sdk/typescript/tests-ts/release-automation.test.ts
@@ -531,6 +531,67 @@ function workflowStepShell(workflow: string, stepName: string): string {
return step.run;
}
+function resolveProtectedRelease(env: Record<string, string>) {
+ const script = workflowStepShell(
+ githubReleaseWorkflow,
+ "Resolve the successful protected release",
+ );
+ return runShell(
+ String.raw`
+sleep() {
+ [[ $# == 1 && -n "$MOCK_SLEEP_LOG" ]] || return 99
+ printf '%s\n' "$1" >> "$MOCK_SLEEP_LOG"
+ MOCK_RUN_STATUS=$MOCK_NEXT_STATUS
+}
+git() {
+ [[ $# == 3 && "$1" == rev-parse && "$2" == --verify && "$3" == "$MOCK_TAG_OBJECT^{commit}" ]] || return 66
+ [[ "$MOCK_TAG_TYPE" == commit ]] || return 67
+ printf '%s\n' "$MOCK_TAG_OBJECT"
+}
+gh() {
+ printf '%s\n' "$*" >> "$MOCK_GH_LOG"
+ [[ $# == 4 && "$1" == api && "$3" == --jq ]] || return 64
+ case "$2" in
+ "repos/test/codex-security/git/ref/tags/npm-v0.1.2")
+ [[ -n "$MOCK_TAG_TYPE" ]] || return 1
+ [[ "$4" == '[.object.type, .object.sha] | @tsv' ]] || return 65
+ printf '%s\t%s\n' "$MOCK_TAG_TYPE" "$MOCK_TAG_OBJECT"
+ ;;
+ "repos/test/codex-security/git/tags/$MOCK_TAG_OBJECT")
+ [[ "$MOCK_TAG_TYPE" == tag && "$4" == 'if .object.type == "commit" then .object.sha else empty end' ]] || return 65
+ printf '%s\n' '${releaseCommit}'
+ ;;
+ "repos/test/codex-security/commits/npm-v0.1.2")
+ printf '%s\n' "$MOCK_BRANCH_SHA"
+ ;;
+ "repos/test/codex-security/actions/runs/$INPUT_RUN_ID")
+ [[ "$4" == '[.name, .status, (.conclusion // "pending"), .head_sha, .head_branch] | @tsv' ]] || return 65
+ local conclusion=pending
+ if [[ "$MOCK_RUN_STATUS" == completed ]]; then conclusion=success; fi
+ printf '%s\t%s\t%s\t%s\t%s\n' node-release "$MOCK_RUN_STATUS" "$conclusion" "$MOCK_RUN_SHA" npm-v0.1.2
+ ;;
+ *) return 65 ;;
+ esac
+}
+${script}`,
+ {
+ GITHUB_OUTPUT: "/dev/null",
+ GITHUB_REPOSITORY: "test/codex-security",
+ INPUT_RUN_ID: releaseRun,
+ INPUT_TAG: "npm-v0.1.2",
+ MOCK_TAG_TYPE: "commit",
+ MOCK_TAG_OBJECT: releaseCommit,
+ MOCK_RUN_STATUS: "completed",
+ MOCK_NEXT_STATUS: "completed",
+ MOCK_SLEEP_LOG: "",
+ MOCK_RUN_SHA: releaseCommit,
+ MOCK_BRANCH_SHA: releaseCommit,
+ MOCK_GH_LOG: "/dev/null",
+ ...env,
+ },
+ );
+}
+
function runReleaseLabels(
title: string,
routes: readonly string[],
@@ -2890,80 +2951,24 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}
test.each(["queued", "in_progress"])(
"waits for a %s protected npm release to finish before publishing notes",
async (pendingStatus) => {
- const script = workflowStepShell(
- githubReleaseWorkflow,
- "Resolve the successful protected release",
- );
const root = directories.create(
"codex-security-release-wait-$(echo literal)-'-",
);
- const state = join(root, "release-state");
const sleeps = join(root, "release-sleeps");
- const mocks = [
- "gh() {",
- ' if [[ "$1" != "api" ]]; then return 64; fi',
- " shift",
- ' case "$1" in',
- ' "repos/openai/codex-security/git/ref/tags/npm-v0.1.2")',
- ` printf '%s\\t%s\\n' 'commit' '${releaseCommit}'`,
- " ;;",
- ` "repos/openai/codex-security/actions/runs/${releaseRun}")`,
- ' if [[ -f "$MOCK_RUN_STATE" ]]; then',
- ` printf '%s\\t%s\\t%s\\t%s\\t%s\\n' 'node-release' 'completed' 'success' '${releaseCommit}' 'npm-v0.1.2'`,
- " else",
- ' touch "$MOCK_RUN_STATE"',
- ` printf '%s\\t%s\\t%s\\t%s\\t%s\\n' 'node-release' '${pendingStatus}' 'pending' '${releaseCommit}' 'npm-v0.1.2'`,
- " fi",
- " ;;",
- " *) return 65 ;;",
- " esac",
- "}",
- 'sleep() { printf "%s\\n" "$1" >> "$MOCK_SLEEP_LOG"; }',
- ].join("\n");
-
- const result = await runShell(`${mocks}\n${script}`, {
- GITHUB_OUTPUT: "/dev/null",
- GITHUB_REPOSITORY: releaseRepository,
- INPUT_RUN_ID: releaseRun,
- INPUT_TAG: "npm-v0.1.2",
- MOCK_RUN_STATE: state,
+ const result = await resolveProtectedRelease({
+ MOCK_RUN_STATUS: pendingStatus,
MOCK_SLEEP_LOG: sleeps,
});
-
expect(result.status).toBe(0);
expect(readFileSync(sleeps, "utf8")).toBe("2\n");
},
);
test("rejects a pending npm release for a different tagged commit", async () => {
- const script = workflowStepShell(
- githubReleaseWorkflow,
- "Resolve the successful protected release",
- );
- const differentCommit = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
- const mocks = [
- "gh() {",
- ' if [[ "$1" != "api" ]]; then return 64; fi',
- " shift",
- ' case "$1" in',
- ' "repos/openai/codex-security/git/ref/tags/npm-v0.1.2")',
- ` printf '%s\\t%s\\n' 'commit' '${releaseCommit}'`,
- " ;;",
- ` "repos/openai/codex-security/actions/runs/${releaseRun}")`,
- ` printf '%s\\t%s\\t%s\\t%s\\t%s\\n' 'node-release' 'in_progress' 'pending' '${differentCommit}' 'npm-v0.1.2'`,
- " ;;",
- " *) return 65 ;;",
- " esac",
- "}",
- "sleep() { return 99; }",
- ].join("\n");
- const result = await runShell(`${mocks}\n${script}`, {
- GITHUB_OUTPUT: "/dev/null",
- GITHUB_REPOSITORY: releaseRepository,
- INPUT_RUN_ID: releaseRun,
- INPUT_TAG: "npm-v0.1.2",
+ const result = await resolveProtectedRelease({
+ MOCK_RUN_STATUS: "in_progress",
+ MOCK_RUN_SHA: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
});
-
expect(result.status).toBe(1);
expect(result.stderr).toContain(
"The release run must successfully publish the exact tagged commit.",
@@ -2971,33 +2976,13 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}
});
test("times out safely if a protected npm release never completes", async () => {
- const script = workflowStepShell(
- githubReleaseWorkflow,
- "Resolve the successful protected release",
- );
- const mocks = [
- "gh() {",
- ' if [[ "$1" != "api" ]]; then return 64; fi',
- " shift",
- ' case "$1" in',
- ' "repos/openai/codex-security/git/ref/tags/npm-v0.1.2")',
- ` printf '%s\\t%s\\n' 'commit' '${releaseCommit}'`,
- " ;;",
- ` "repos/openai/codex-security/actions/runs/${releaseRun}")`,
- ` printf '%s\\t%s\\t%s\\t%s\\t%s\\n' 'node-release' 'in_progress' 'pending' '${releaseCommit}' 'npm-v0.1.2'`,
- " ;;",
- " *) return 65 ;;",
- " esac",
- "}",
- "sleep() { :; }",
- ].join("\n");
- const result = await runShell(`${mocks}\n${script}`, {
- GITHUB_OUTPUT: "/dev/null",
- GITHUB_REPOSITORY: releaseRepository,
- INPUT_RUN_ID: releaseRun,
- INPUT_TAG: "npm-v0.1.2",
+ const sleeps = join(directories.create("release-timeout-"), "sleeps");
+ const result = await resolveProtectedRelease({
+ MOCK_RUN_STATUS: "in_progress",
+ MOCK_NEXT_STATUS: "in_progress",
+ MOCK_SLEEP_LOG: sleeps,
});
-
+ expect(readFileSync(sleeps, "utf8")).toBe("2\n".repeat(29));
expect(result.status).toBe(1);
expect(result.stderr).toContain(
`Timed out waiting for protected npm release ${releaseRun} to complete.`,
@@ -3005,35 +2990,12 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}
});
test("rejects a release-shaped branch before resolving its commit", async () => {
- const script = workflowStepShell(
- githubReleaseWorkflow,
- "Resolve the successful protected release",
- );
- const mock = [
- "gh() {",
- ' if [[ "$1" != "api" ]]; then return 64; fi',
- " shift",
- ' case "$1" in',
- ' "repos/openai/codex-security/git/ref/tags/npm-v0.1.2")',
- " return 1",
- " ;;",
- ' "repos/openai/codex-security/commits/npm-v0.1.2")',
- ` printf '%s\\n' '${releaseCommit}'`,
- " ;;",
- ` "repos/openai/codex-security/actions/runs/${releaseRun}")`,
- ` printf '%s\\t%s\\t%s\\t%s\\t%s\\n' 'node-release' 'completed' 'success' '${releaseCommit}' 'npm-v0.1.2'`,
- " ;;",
- " *) return 65 ;;",
- " esac",
- "}",
- ].join("\n");
- const result = await runShell(`${mock}\n${script}`, {
- GITHUB_OUTPUT: "/dev/null",
- GITHUB_REPOSITORY: "openai/codex-security",
- INPUT_RUN_ID: releaseRun,
- INPUT_TAG: "npm-v0.1.2",
+ const calls = join(directories.create("missing-tag-"), "gh-calls");
+ const result = await resolveProtectedRelease({
+ MOCK_TAG_TYPE: "",
+ MOCK_GH_LOG: calls,
});
-
+ expect(readFileSync(calls, "utf8")).not.toContain("/commits/");
expect(result.status).toBe(1);
expect(result.stderr).toContain(
"GitHub releases require an existing stable npm-vX.Y.Z tag.",
@@ -3050,49 +3012,11 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}
])(
"resolves the exact $kind tag when a same-named branch exists",
async ({ tagType, objectSha }) => {
- const script = workflowStepShell(
- githubReleaseWorkflow,
- "Resolve the successful protected release",
- );
- const branchCommit = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
- const mocks = [
- "git() {",
- ` if [[ "$1" != "rev-parse" || "$2" != "--verify" || "$3" != "${objectSha}^{commit}" ]]; then return 66; fi`,
- ' if [[ "$MOCK_TAG_TYPE" == "tag" ]]; then return 67; fi',
- ` printf '%s\\n' '${releaseCommit}'`,
- "}",
- "gh() {",
- ' if [[ "$1" != "api" ]]; then return 64; fi',
- " shift",
- ' case "$1" in',
- ' "repos/openai/codex-security/git/ref/tags/npm-v0.1.2")',
- ' if [[ "$3" == ".object.sha" ]]; then',
- ` printf '%s\\n' '${objectSha}'`,
- " else",
- ` printf '%s\\t%s\\n' '${tagType}' '${objectSha}'`,
- " fi",
- " ;;",
- ` "repos/openai/codex-security/git/tags/${objectSha}")`,
- ` printf '%s\\n' '${releaseCommit}'`,
- " ;;",
- ' "repos/openai/codex-security/commits/npm-v0.1.2")',
- ` printf '%s\\n' '${branchCommit}'`,
- " ;;",
- ` "repos/openai/codex-security/actions/runs/${releaseRun}")`,
- ` printf '%s\\t%s\\t%s\\t%s\\t%s\\n' 'node-release' 'completed' 'success' '${releaseCommit}' 'npm-v0.1.2'`,
- " ;;",
- " *) return 65 ;;",
- " esac",
- "}",
- ].join("\n");
- const result = await runShell(`${mocks}\n${script}`, {
- GITHUB_OUTPUT: "/dev/null",
- GITHUB_REPOSITORY: "openai/codex-security",
- INPUT_RUN_ID: releaseRun,
- INPUT_TAG: "npm-v0.1.2",
+ const result = await resolveProtectedRelease({
MOCK_TAG_TYPE: tagType,
+ MOCK_TAG_OBJECT: objectSha,
+ MOCK_BRANCH_SHA: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
});
-
expect(result.status).toBe(0);
expect(result.stderr).not.toContain(
"The release run must successfully publish the exact tagged commit.",
@@ -3103,32 +3027,7 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}
test.each(["0", "01", "000123"])(
"rejects the noncanonical protected GitHub release run ID %j",
async (runId) => {
- const script = workflowStepShell(
- githubReleaseWorkflow,
- "Resolve the successful protected release",
- );
- const mocks = [
- "gh() {",
- ' if [[ "$1" != "api" ]]; then return 64; fi',
- " shift",
- ' case "$1" in',
- ' "repos/openai/codex-security/git/ref/tags/npm-v0.1.2")',
- ` printf '%s\\t%s\\n' 'commit' '${releaseCommit}'`,
- " ;;",
- ' "repos/openai/codex-security/actions/runs/"*)',
- ` printf '%s\\t%s\\t%s\\t%s\\t%s\\n' 'node-release' 'completed' 'success' '${releaseCommit}' 'npm-v0.1.2'`,
- " ;;",
- " *) return 65 ;;",
- " esac",
- "}",
- ].join("\n");
- const result = await runShell(`${mocks}\n${script}`, {
- GITHUB_OUTPUT: "/dev/null",
- GITHUB_REPOSITORY: "openai/codex-security",
- INPUT_RUN_ID: runId,
- INPUT_TAG: "npm-v0.1.2",
- });
-
+ const result = await resolveProtectedRelease({ INPUT_RUN_ID: runId });
expect(result.status).toBe(1);
expect(result.stderr).toContain(
"No successful protected npm release exists for npm-v0.1.2.",