Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion workers/skill-harness/src/skillgen-opt-ins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export async function readSkillgenOptIns(input: {
fetch: typeof fetch
}): Promise<{ _tag: 'Ok', repositories: Set<string> } | { _tag: 'Unavailable', status: number }> {
const optedIn = new Set<string>()
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),
Expand Down
19 changes: 19 additions & 0 deletions workers/skill-harness/test/skillgen-opt-ins.test.ts
Original file line number Diff line number Diff line change
@@ -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']) })
})