From 954190efa8ba8ca2af732725f1203570ba919d8e Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Tue, 6 Oct 2026 20:58:06 +1100 Subject: [PATCH] fix(skillgen): call fetch without an object receiver --- workers/skill-harness/src/skillgen-opt-ins.ts | 3 ++- .../test/skillgen-opt-ins.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 workers/skill-harness/test/skillgen-opt-ins.test.ts 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']) }) +})