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(linear): cover project issue pagination with SDK connections (#517)

Sylvester Kaczmarek6428090b2bad
diff --git a/sdk/typescript/tests-ts/linear-pagination.test.ts b/sdk/typescript/tests-ts/linear-pagination.test.ts
new file mode 100644
index 000000000..c44a3af1f
--- /dev/null
+++ b/sdk/typescript/tests-ts/linear-pagination.test.ts
@@ -0,0 +1,38 @@
+import { expect, test } from "bun:test";
+import { importLinearIssues, type LinearClientFactory } from "../src/linear.js";
+import { paginated } from "./support/linear-pagination.js";
+
+test.each([
+ [1, []],
+ [51, ["50"]],
+ [101, ["50", "100"]],
+] as const)(
+ "imports %i project issues exactly once",
+ async (count, expectedCursors) => {
+ const issues = Array.from({ length: count }, (_, index) => ({
+ identifier: `DEMO-${index + 1}`,
+ title: `Synthetic issue ${index + 1}`,
+ description: "Synthetic evidence.",
+ url: `https://linear.app/example/issue/DEMO-${index + 1}`,
+ comments: async () => paginated([]).connection,
+ }));
+ const { connection, cursors } = paginated(issues);
+
+ const imported = await importLinearIssues({
+ issues: [],
+ project: "Example project",
+ environment: { CODEX_SECURITY_LINEAR_API_KEY: "synthetic-key" },
+ linearClient: () =>
+ ({
+ projects: async () => ({
+ nodes: [{ issues: async () => connection }],
+ }),
+ }) as unknown as ReturnType<LinearClientFactory>,
+ });
+
+ expect(imported.map(({ id }) => id)).toEqual(
+ issues.map(({ identifier }) => identifier),
+ );
+ expect(cursors).toEqual([...expectedCursors]);
+ },
+);
diff --git a/sdk/typescript/tests-ts/support/linear-pagination.ts b/sdk/typescript/tests-ts/support/linear-pagination.ts
new file mode 100644
index 000000000..0fb0d671d
--- /dev/null
+++ b/sdk/typescript/tests-ts/support/linear-pagination.ts
@@ -0,0 +1,25 @@
+import { Connection, PageInfo, type LinearRequest } from "@linear/sdk";
+
+/** Replace page transport while retaining the SDK's pagination behavior. */
+export function paginated<Value>(values: Value[]) {
+ const cursors: string[] = [];
+ const request: LinearRequest = async () => {
+ throw new Error("Unexpected request outside the synthetic page transport.");
+ };
+ const page = (offset: number): Connection<Value> =>
+ new Connection(
+ request,
+ async (variables) => {
+ cursors.push(variables!.after!);
+ return page(Number(variables!.after));
+ },
+ values.slice(offset, offset + 50),
+ new PageInfo(request, {
+ __typename: "PageInfo",
+ hasNextPage: offset + 50 < values.length,
+ hasPreviousPage: offset > 0,
+ endCursor: String(Math.min(offset + 50, values.length)),
+ }),
+ );
+ return { connection: page(0), cursors };
+}