|
| 1 | +import type { JsonSchema } from "../../core/types.ts"; |
| 2 | + |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | 4 | import { provider } from "./definition.ts"; |
3 | 5 | import { issueActionHandlers } from "./runtime-issue.ts"; |
4 | 6 |
|
5 | | -function pageFetcher(items: unknown[]): typeof fetch { |
6 | | - return async () => |
7 | | - new Response(JSON.stringify(items), { |
| 7 | +function pageFetcher(items: unknown[], onRequest?: (url: string) => void): typeof fetch { |
| 8 | + return async (url) => { |
| 9 | + onRequest?.(String(url)); |
| 10 | + return new Response(JSON.stringify(items), { |
8 | 11 | status: 200, |
9 | 12 | headers: { "content-type": "application/json" }, |
10 | 13 | }); |
| 14 | + }; |
11 | 15 | } |
12 | 16 |
|
13 | 17 | describe("list_repository_issues pagination signal", () => { |
@@ -48,16 +52,31 @@ describe("list_repository_issues pagination signal", () => { |
48 | 52 | expect(result.pageInfo.fetched).toBe(2); |
49 | 53 | }); |
50 | 54 |
|
51 | | - it("declares pageInfo.fetched in the action's output schema", () => { |
52 | | - interface ObjectSchema { |
53 | | - properties?: Record<string, ObjectSchema>; |
54 | | - required?: string[]; |
55 | | - type?: string; |
56 | | - } |
| 55 | + it("requests the documented default page size when perPage is omitted", async () => { |
| 56 | + let requestedUrl = ""; |
| 57 | + await issueActionHandlers.list_repository_issues( |
| 58 | + { owner: "acme", repo: "widgets" }, |
| 59 | + { |
| 60 | + accessToken: "token", |
| 61 | + fetcher: pageFetcher([], (url) => { |
| 62 | + requestedUrl = url; |
| 63 | + }), |
| 64 | + }, |
| 65 | + ); |
| 66 | + |
| 67 | + expect(new URL(requestedUrl).searchParams.get("per_page")).toBe("30"); |
| 68 | + }); |
| 69 | + |
| 70 | + it("declares the pagination contract in the action schemas", () => { |
57 | 71 | const action = provider.actions.find((entry) => entry.name === "list_repository_issues"); |
58 | | - const pageInfo = (action?.outputSchema as ObjectSchema | undefined)?.properties?.pageInfo; |
| 72 | + const inputProperties = action?.inputSchema.properties as Record<string, JsonSchema> | undefined; |
| 73 | + const outputProperties = action?.outputSchema.properties as Record<string, JsonSchema> | undefined; |
| 74 | + const perPage = inputProperties?.perPage; |
| 75 | + const pageInfo = outputProperties?.pageInfo; |
| 76 | + const pageInfoProperties = pageInfo?.properties as Record<string, JsonSchema> | undefined; |
59 | 77 |
|
60 | | - expect(pageInfo?.properties?.fetched?.type).toBe("integer"); |
61 | | - expect(pageInfo?.required).toContain("fetched"); |
| 78 | + expect(perPage).toMatchObject({ type: "integer", minimum: 1, maximum: 100, default: 30 }); |
| 79 | + expect(pageInfoProperties?.fetched?.type).toBe("integer"); |
| 80 | + expect(pageInfo?.required as string[] | undefined).toContain("fetched"); |
62 | 81 | }); |
63 | 82 | }); |
0 commit comments