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(publish): preserve completed publication after late cancellation (#1725)

Michael D'Angeloe59dc16a0183
diff --git a/sdk/typescript/src/publish.ts b/sdk/typescript/src/publish.ts
index b2cac0e2a..908efe0fa 100644
--- a/sdk/typescript/src/publish.ts
+++ b/sdk/typescript/src/publish.ts
@@ -523,7 +523,7 @@ export async function publishScanInternal(
try {
await saveReceipt(result, environment);
} catch (error) {
- if (result.created.length === 0 || options.signal?.aborted) throw error;
+ if (result.created.length === 0) throw error;
result.warnings = [
...(result.warnings ?? []),
`Could not save the publication receipt: ${errorMessage(error)}. Linear issues were already created; do not retry publication.`,
diff --git a/sdk/typescript/tests-ts/publish.test.ts b/sdk/typescript/tests-ts/publish.test.ts
index 3815b6def..ae25bedcb 100644
--- a/sdk/typescript/tests-ts/publish.test.ts
+++ b/sdk/typescript/tests-ts/publish.test.ts
@@ -3427,8 +3427,14 @@ describe("connected Linear publication", () => {
});
test("returns persisted successes and partial failures when an optional receipt cannot be saved", async () => {
- for (const partialFailure of [false, true]) {
+ for (const [partialFailure, lateAbort] of [
+ [false, false],
+ [true, false],
+ [false, true],
+ [true, true],
+ ] as const) {
const publication = preparedPublication(2);
+ const controller = new AbortController();
const progress: PublishScanProgress[] = [];
let invocations = 0;
let persisted: string[] = [];
@@ -3438,6 +3444,7 @@ describe("connected Linear publication", () => {
publication.scanDirectory,
{
...OPTIONS,
+ ...(lateAbort ? { signal: controller.signal } : {}),
onProgress: (event) => progress.push(event),
},
dependencies(publication, {
@@ -3466,15 +3473,19 @@ describe("connected Linear publication", () => {
persisted = issues.map((issue) => issue.issueIdentifier);
return [...issues];
},
- writeReceipt: rejecting(
- "OPENAI_API_KEY=sk-proj-SYNTHETIC_RECEIPT_SECRET_123",
- ),
+ writeReceipt: async () => {
+ if (lateAbort) controller.abort("SIGINT");
+ throw new Error(
+ "OPENAI_API_KEY=sk-proj-SYNTHETIC_RECEIPT_SECRET_123",
+ );
+ },
}),
);
const expectedCreated = partialFailure
? ["SEC-PERSISTED"]
: ["SEC-PERSISTED", "SEC-ALSO-PERSISTED"];
+ expect(controller.signal.aborted).toBe(lateAbort);
expect(invocations).toBe(1);
expect(persisted).toEqual(expectedCreated);
expect(result.created.map((issue) => issue.issueIdentifier)).toEqual(