diff --git a/web/src/routes/[handle]/[repo]/pulls/+page.ts b/web/src/routes/[handle]/[repo]/pulls/+page.ts index 7ed96e1e8..928b76fa4 100644 --- a/web/src/routes/[handle]/[repo]/pulls/+page.ts +++ b/web/src/routes/[handle]/[repo]/pulls/+page.ts @@ -44,7 +44,7 @@ export const load: PageLoad = async (event) => { const pulls: PullSummary[] = page.output.items.map((item): PullSummary => { const authorDid = didFromUri(item.uri); - const authorHandle = handleOf(page.data, authorDid, "sh.tangled.repo.issue:.repo"); + const authorHandle = handleOf(page.data, authorDid, "sh.tangled.repo.pull:.repo"); return { uri: item.uri, rkey: rkeyFromUri(item.uri), diff --git a/web/src/routes/[handle]/[repo]/pulls/pulls.test.ts b/web/src/routes/[handle]/[repo]/pulls/pulls.test.ts new file mode 100644 index 000000000..f5b6da1ee --- /dev/null +++ b/web/src/routes/[handle]/[repo]/pulls/pulls.test.ts @@ -0,0 +1,76 @@ +import { describe, expect, it, vi } from "vitest"; +import { load } from "./+page"; +import { TYPE_MINIDOC } from "$lib/api/enrich"; + +const REPO_DID = "did:plc:j5hmlfdrwkvtxm7cjmu7j2is"; +const AUTHOR_DID = "did:plc:2zcfjzyocp6kapg6jc4eacok"; + +const jsonResponse = (body: unknown): Response => + new Response(JSON.stringify(body), { + status: 200, + headers: { "content-type": "application/json" } + }); + +const pullsResponse = () => + jsonResponse({ + output: { + items: [ + { + uri: `at://${AUTHOR_DID}/sh.tangled.repo.pull/3mgftgdw6ad22`, + cid: "bafyreidakrovoxr2yfueukylm44kthte5g3usyex27e5cqv3nkze7tfxb4", + state: "open", + commentCount: 2, + value: { title: "fix: cli failures", createdAt: "2026-08-04T09:00:00.000Z" } + } + ] + }, + // docs come back under the source that was asked for, reading another one + // silently gives handle.invalid + data: { + [AUTHOR_DID]: { + "sh.tangled.repo.pull:.repo": { + [TYPE_MINIDOC]: { did: AUTHOR_DID, handle: "andrew.heiss.phd" } + } + } + } + }); + +const makeEvent = () => { + const fetchMock = vi + .fn() + .mockImplementation(async (input) => + String(input).includes("countPulls") ? jsonResponse({ count: 3 }) : pullsResponse() + ); + return { + fetchMock, + event: { + url: new URL("http://web.test/alice.test/core/pulls"), + fetch: fetchMock, + parent: async () => ({ + publicConfig: { bobbinUrl: "https://bobbin.test" }, + repo: { repoDid: REPO_DID, ownerHandle: "alice.test", name: "core" }, + counts: { pulls: 1 } + }) + } as never + }; +}; + +describe("pulls load", () => { + it("resolves pull authors from the pull sidecar", async () => { + const { event, fetchMock } = makeEvent(); + const data = (await load(event))!; + + expect(data.pulls[0]).toMatchObject({ + authorDid: AUTHOR_DID, + authorHandle: "andrew.heiss.phd", + state: "open" + }); + + const [, request] = fetchMock.mock.calls.find(([url]) => + String(url).includes("enrichResponse") + )!; + expect(JSON.parse(String(request?.body)).enrich).toEqual([ + { source: "sh.tangled.repo.pull:.repo", type: TYPE_MINIDOC, targets: ["items[].uri"] } + ]); + }); +});