OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
test(release): share label and proposal fixtures (#1473)
mldangelo-oai3fcdcc647a3f
diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex 029fc1a3e..b44502db7 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -364,6 +364,24 @@ function workflowStepShell(workflow: string, stepName: string): string {return step.run;}+function runReleaseLabels(+ title: string,+ routes: readonly string[],+ setup: readonly string[] = [],+ shiftEndpoint = true,+) {+ const mock = [...setup, releaseLabelGhMock(routes, shiftEndpoint)].join("\n");+ const script = workflowStepShell(+ releaseLabelsWorkflow,+ "Categorize pull request without checking out its code",+ );+ return runShell(`${mock}\n${script}`, {+ GITHUB_REPOSITORY: "test/codex-security",+ MOCK_PR_TITLE: title,+ PR_NUMBER: "17",+ });+}+async function evaluateWorkflowCondition(condition: string,values: Record<string, string>,@@ -3905,18 +3923,9 @@ describe("GitHub release workflow safeguards", () => {])("preserves a manually excluded release and reconciles its category after retitling to $title",async ({ title, expectedLabel }) => {- const script = workflowStepShell(- releaseLabelsWorkflow,- "Categorize pull request without checking out its code",- );- const mock = [- "base64() {",- ' if [[ "${1:-}" == "--decode" ]]; then',- " return 64",- " fi",- ' command base64 "$@"',- "}",- releaseLabelGhMock([+ const result = await runReleaseLabels(+ title,+ [' "GET repos/test/codex-security/issues/17/labels")'," printf '%s\\n' enhancement skip-release-notes"," ;;",@@ -3930,13 +3939,16 @@ describe("GitHub release workflow safeguards", () => {" printf '%s\\n' 'removed a manually excluded release label'"," return 70"," ;;",- ]),- ].join("\n");- const result = await runShell(`${mock}\n${script}`, {- GITHUB_REPOSITORY: "test/codex-security",- MOCK_PR_TITLE: title,- PR_NUMBER: "17",- });+ ],+ [+ "base64() {",+ ' if [[ "${1:-}" == "--decode" ]]; then',+ " return 64",+ " fi",+ ' command base64 "$@"',+ "}",+ ],+ );expect(result.status).toBe(0);expect(result.stdout).toContain(@@ -3960,11 +3972,7 @@ describe("GitHub release workflow safeguards", () => {);test("preserves the latest unattributed skip label after earlier automation", async () => {- const script = workflowStepShell(- releaseLabelsWorkflow,- "Categorize pull request without checking out its code",- );- const mock = releaseLabelGhMock([+ const result = await runReleaseLabels("feat: customer-visible change", [' "GET repos/test/codex-security/issues/17")'," printf '%s' 'feat: customer-visible change' | base64"," ;;",@@ -3983,10 +3991,6 @@ describe("GitHub release workflow safeguards", () => {" return 70"," ;;",]);- const result = await runShell(`${mock}\n${script}`, {- GITHUB_REPOSITORY: "test/codex-security",- PR_NUMBER: "17",- });expect(result.status).toBe(0);expect(result.stdout).toContain(@@ -4007,11 +4011,7 @@ describe("GitHub release workflow safeguards", () => {])("reconciles an automatic skip label after retitling to $title",async ({ title, label }) => {- const script = workflowStepShell(- releaseLabelsWorkflow,- "Categorize pull request without checking out its code",- );- const mock = releaseLabelGhMock([+ const result = await runReleaseLabels(title, [' "GET repos/test/codex-security/issues/17/labels")'," printf '%s\\n' skip-release-notes"," ;;",@@ -4022,11 +4022,6 @@ describe("GitHub release workflow safeguards", () => {" printf '%s\\n' 'removed automatically applied skip-release-notes'"," ;;",]);- const result = await runShell(`${mock}\n${script}`, {- GITHUB_REPOSITORY: "test/codex-security",- MOCK_PR_TITLE: title,- PR_NUMBER: "17",- });expect(result.status).toBe(0);expect(result.stdout).toContain(@@ -4061,11 +4056,7 @@ describe("GitHub release workflow safeguards", () => {label: "breaking-change",},])("categorizes breaking-change title $title", async ({ title, label }) => {- const script = workflowStepShell(- releaseLabelsWorkflow,- "Categorize pull request without checking out its code",- );- const mock = releaseLabelGhMock([+ const result = await runReleaseLabels(title, [' "GET repos/test/codex-security/issues/17/labels")'," return 0"," ;;",@@ -4073,11 +4064,6 @@ describe("GitHub release workflow safeguards", () => {" return 0"," ;;",]);- const result = await runShell(`${mock}\n${script}`, {- GITHUB_REPOSITORY: "test/codex-security",- MOCK_PR_TITLE: title,- PR_NUMBER: "17",- });expect(result.status).toBe(0);expect(result.stdout).toContain(`labels[]=${label}`);@@ -4090,41 +4076,31 @@ describe("GitHub release workflow safeguards", () => {])("excludes %s and recovers from concurrent skip-label creation",async (title) => {- const script = workflowStepShell(- releaseLabelsWorkflow,- "Categorize pull request without checking out its code",+ const result = await runReleaseLabels(+ title,+ [+ ' "GET repos/test/codex-security/issues/17")',+ " printf '%s' \"$MOCK_PR_TITLE\" | base64",+ " ;;",+ ' "GET repos/test/codex-security/issues/17/labels")',+ " return 0",+ " ;;",+ ' "GET repos/test/codex-security/labels/skip-release-notes")',+ ' [[ "$skip_label_exists" == 1 ]]',+ " ;;",+ ' "POST repos/test/codex-security/labels")',+ " skip_label_exists=1",+ " return 1",+ " ;;",+ ' "POST repos/test/codex-security/issues/17/labels")',+ ' if [[ "$skip_label_exists" != 1 ]]; then return 65; fi',+ " printf '%s\\n' 'applied skip-release-notes'",+ " ;;",+ " *) return 66 ;;",+ ],+ ["skip_label_exists=0"],+ false,);- const mock = [- "skip_label_exists=0",- releaseLabelGhMock(- [- ' "GET repos/test/codex-security/issues/17")',- " printf '%s' \"$MOCK_PR_TITLE\" | base64",- " ;;",- ' "GET repos/test/codex-security/issues/17/labels")',- " return 0",- " ;;",- ' "GET repos/test/codex-security/labels/skip-release-notes")',- ' [[ "$skip_label_exists" == 1 ]]',- " ;;",- ' "POST repos/test/codex-security/labels")',- " skip_label_exists=1",- " return 1",- " ;;",- ' "POST repos/test/codex-security/issues/17/labels")',- ' if [[ "$skip_label_exists" != 1 ]]; then return 65; fi',- " printf '%s\\n' 'applied skip-release-notes'",- " ;;",- " *) return 66 ;;",- ],- false,- ),- ].join("\n");- const result = await runShell(`${mock}\n${script}`, {- GITHUB_REPOSITORY: "test/codex-security",- MOCK_PR_TITLE: title,- PR_NUMBER: "17",- });expect(result.status).toBe(0);expect(result.stdout).toContain("applied skip-release-notes");diff --git a/sdk/typescript/tests-ts/release-pr.test.ts b/sdk/typescript/tests-ts/release-pr.test.tsindex 62ba5c10c..515dfb1ce 100644--- a/sdk/typescript/tests-ts/release-pr.test.ts+++ b/sdk/typescript/tests-ts/release-pr.test.ts@@ -172,6 +172,16 @@ function apiError(status: number) {}class Fixture {+ static async withInitialPull() {+ const fixture = new Fixture();+ fixture.merge("feat: initial feature");+ const first = await fixture.run();+ const pull = fixture.github.pulls.find(+ (candidate) => candidate.number === first.pull,+ )!;+ return { fixture, first, pull };+ }+readonly directory = directories.create("release pr test ");readonly repo = createGitRepository(this.directory);readonly github = new FakeGitHub(this);@@ -1072,9 +1082,7 @@ describe("rolling release reconciliation", () => {});test("incorporates main-only changes without another proposal review or repeated commits", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();+ const { fixture, first } = await Fixture.withInitialPull();fixture.merge("test: add coverage", {"sdk/typescript/tests-ts/example.test.ts": "// Additional coverage.\n",});@@ -1106,9 +1114,7 @@ describe("rolling release reconciliation", () => {});test("posts new suggestions for human-owned notes without repeating an unchanged proposal review", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();+ const { fixture, first } = await Fixture.withInitialPull();fixture.commit(first.plan.branch,{@@ -1155,9 +1161,7 @@ describe("rolling release reconciliation", () => {});test("recovers review on a manual rerun after GitHub exposes the updated head", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();+ const { fixture, first } = await Fixture.withInitialPull();fixture.merge("fix: later fix");const request = fixture.github.request.bind(fixture.github);let headLagged = true;@@ -1196,9 +1200,7 @@ describe("rolling release reconciliation", () => {});test("retries a concurrent human commit without dropping its notes or history", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();+ const { fixture, first } = await Fixture.withInitialPull();fixture.merge("fix: later fix");let humanSha = "";fixture.github.beforeRefWrite = () => {@@ -1243,12 +1245,7 @@ describe("rolling release reconciliation", () => {test.each(["closed", "retargeted"])("does not request review after a PR is %s during its final checks",async (change) => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();- const pull = fixture.github.pulls.find(- (candidate) => candidate.number === first.pull,- )!;+ const { fixture, pull } = await Fixture.withInitialPull();const commentCount = fixture.github.comments.get(pull.number)!.length;fixture.merge("fix: another fix");const request = fixture.github.request.bind(fixture.github);@@ -1275,12 +1272,7 @@ describe("rolling release reconciliation", () => {);test("waits for a new change after a release is squash-merged before opening the next ready PR", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();- const pull = fixture.github.pulls.find(- (candidate) => candidate.number === first.pull,- )!;+ const { fixture, first, pull } = await Fixture.withInitialPull();fixture.merge("fix: another change before release");const updated = await fixture.run();expect(updated.headSha).not.toBe(first.headSha);@@ -1354,9 +1346,7 @@ describe("rolling release reconciliation", () => {});test("preserves a deleted notes file on the remote branch", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();+ const { fixture, first } = await Fixture.withInitialPull();fixture.commit(first.plan.branch,{ [notesPath]: null },@@ -1372,9 +1362,7 @@ describe("rolling release reconciliation", () => {{ "sdk/typescript/src/example.ts": "Human implementation changes.\n" },{ [packagePath]: packageText("0.1.24", { example: "1.0.0" }) },])("pauses instead of losing unrelated human edits (%#)", async (files) => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();+ const { fixture, first } = await Fixture.withInitialPull();const humanSha = fixture.commit(first.plan.branch,files,@@ -1438,9 +1426,7 @@ describe("rolling release reconciliation", () => {});test("uses the merge commit as the boundary for a release merged without squashing", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();+ const { fixture, first } = await Fixture.withInitialPull();const releaseTree = fixture.git("rev-parse", `${first.headSha}^{tree}`).trim();@@ -1476,12 +1462,7 @@ describe("release proposal pauses", () => {test.each(["open", "closed"] as const)("keeps a retargeted %s proposal paused across workflow runs",async (state) => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();- const pull = fixture.github.pulls.find(- (candidate) => candidate.number === first.pull,- )!;+ const { fixture, first, pull } = await Fixture.withInitialPull();pull.base.ref = "maintenance";pull.state = state;fixture.merge("fix: later fix");@@ -1548,12 +1529,7 @@ describe("release proposal pauses", () => {test.each([false, true])("updates an existing proposal with draft=%p",async (draft) => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();- const pull = fixture.github.pulls.find(- (candidate) => candidate.number === first.pull,- )!;+ const { fixture, first, pull } = await Fixture.withInitialPull();pull.draft = draft;pull.body += "\nMaintainer review notes.\n";const reviewedBody = pull.body;@@ -1571,12 +1547,7 @@ describe("release proposal pauses", () => {);test("does not advance a proposal closed during preparation", async () => {- const fixture = new Fixture();- fixture.merge("feat: initial feature");- const first = await fixture.run();- const pull = fixture.github.pulls.find(- (candidate) => candidate.number === first.pull,- )!;+ const { fixture, first, pull } = await Fixture.withInitialPull();fixture.merge("fix: later fix");fixture.github.afterCommit = () => {pull.state = "closed";