diff --git a/workers/skill-harness/src/skillgen-opt-ins.ts b/workers/skill-harness/src/skillgen-opt-ins.ts index a0f15677..925c30f6 100644 --- a/workers/skill-harness/src/skillgen-opt-ins.ts +++ b/workers/skill-harness/src/skillgen-opt-ins.ts @@ -17,8 +17,9 @@ export async function readSkillgenOptIns(input: { fetch: typeof fetch }): Promise<{ _tag: 'Ok', repositories: Set } | { _tag: 'Unavailable', status: number }> { const optedIn = new Set() + const fetcher = input.fetch for (let start = 0; start < input.repositories.length; start += BATCH) { - const response = await input.fetch(new URL('/api/internal/skillgen/opt-ins', input.siteUrl), { + const response = await fetcher(new URL('/api/internal/skillgen/opt-ins', input.siteUrl), { method: 'POST', redirect: 'manual', signal: AbortSignal.timeout(10_000), diff --git a/workers/skill-harness/test/skillgen-opt-ins.test.ts b/workers/skill-harness/test/skillgen-opt-ins.test.ts new file mode 100644 index 00000000..62930125 --- /dev/null +++ b/workers/skill-harness/test/skillgen-opt-ins.test.ts @@ -0,0 +1,19 @@ +import { expect, it } from 'vitest' +import { readSkillgenOptIns } from '../src/skillgen-opt-ins' + +it('reads opt-ins with a fetch function that rejects an object receiver', async () => { + const fetcher: typeof fetch = async function (this: unknown) { + if (this !== undefined && this !== globalThis) + throw new TypeError('Illegal invocation') + return Response.json({ repositories: ['Maintainer/opted'] }) + } + + const result = await readSkillgenOptIns({ + siteUrl: 'https://skilld.dev', + token: 'site-token', + repositories: ['Maintainer/opted'], + fetch: fetcher, + }) + + expect(result).toEqual({ _tag: 'Ok', repositories: new Set(['maintainer/opted']) }) +})