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(publish): cover observer failures in direct Linear publication (#1067)

Dipesh Babu12a01d7b2271
diff --git a/sdk/typescript/tests-ts/publish.test.ts b/sdk/typescript/tests-ts/publish.test.ts
index 3603a6aab..ad0f2aebd 100644
--- a/sdk/typescript/tests-ts/publish.test.ts
+++ b/sdk/typescript/tests-ts/publish.test.ts
@@ -918,6 +918,44 @@ describe("direct Linear API publication", () => {
},
);
+ test.each([
+ ["throws", throwing("The optional progress display failed.")],
+ ["rejects", rejecting("The optional progress display failed.")],
+ ["never settles", () => new Promise<void>(() => {})],
+ ] as const)(
+ "preserves direct publication when handoff progress %s",
+ async (_name, observer) => {
+ const publication = preparedPublication();
+ const handoffProgress = mock(observer);
+ const persisted = mock(copyPublishedIssues);
+ const receipts: PublishScanResult[] = [];
+ const result = await publishScanInternal(
+ publication.scanDirectory,
+ {
+ ...OPTIONS,
+ linearApiKey: "synthetic-key",
+ onProgress: (event) => {
+ if (event.type === "handoff_recorded") return handoffProgress();
+ },
+ },
+ dependencies(publication, {
+ linearClient: linearApiClient(publication),
+ recordPublishedIssues: persisted,
+ writeReceipt: recordReceipts(receipts),
+ }),
+ );
+
+ expect(handoffProgress).toHaveBeenCalledTimes(1);
+ expect(result.counts).toEqual({ findings: 1, created: 1, failed: 0 });
+ expect(persisted).toHaveBeenCalledWith(
+ publication,
+ result.created,
+ expect.anything(),
+ );
+ expect(receipts.at(-1)).toEqual(result);
+ },
+ );
+
test.each([
{ label: "zero bytes", failedWrites: 1, partial: "" },
{ label: "a partial row", failedWrites: 1, partial: '{"scanId":' },
@@ -1034,6 +1072,7 @@ describe("direct Linear API publication", () => {
const updates: PublishScanProgress[] = [];
let started = 0;
let completed = 0;
+ let completedAtFirstHandoffProgress: number | undefined;
let completedAtFirstIssueProgress: number | undefined;
const firstBatchStarted = Promise.withResolvers<void>();
const result = await publishScanInternal(
@@ -1044,7 +1083,7 @@ describe("direct Linear API publication", () => {
onProgress: (event) => {
updates.push(event);
if (event.type === "handoff_recorded" && event.recorded === 1)
- expect(completed).toBe(20);
+ completedAtFirstHandoffProgress = completed;
if (
event.type === "issue_completed" &&
completedAtFirstIssueProgress === undefined
@@ -1075,6 +1114,7 @@ describe("direct Linear API publication", () => {
expect(result.failed).toEqual([
{ findingId: "finding-22", error: "Linear rejected this finding." },
]);
+ expect(completedAtFirstHandoffProgress).toBe(20);
expect(completedAtFirstIssueProgress).toBe(23);
expect(
updates.filter((event) => event.type === "handoff_recorded"),