Skip to content

Commit 25e1270

Browse files
committed
fix(evals): accept abort-based repairs in user-fetch grader
The fetch stub now accepts an optional RequestInit and respects AbortSignal, so an idiomatic AbortController cleanup correctly prevents stale responses. The URL assertion checks only the first argument instead of requiring exactly one argument, so passing { signal } no longer fails the load test.
1 parent 35f1a71 commit 25e1270

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • packages/octane-evals/datasets/train/user-apps-v1/tasks/octane.strong-user-fetch

‎packages/octane-evals/datasets/train/user-apps-v1/tasks/octane.strong-user-fetch/grader.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ beforeEach(() => {
1111
vi.stubGlobal(
1212
'fetch',
1313
vi.fn(
14-
(url: string) =>
15-
new Promise((resolve) => {
14+
(url: string, init?: RequestInit) =>
15+
new Promise<Response>((resolve, reject) => {
1616
const id = url.split('/').pop()!;
17-
responses.set(id, () =>
18-
resolve({ json: () => Promise.resolve({ name: USERS[id] }) } as Response),
17+
const signal = init?.signal;
18+
const settle = () =>
19+
resolve({ json: () => Promise.resolve({ name: USERS[id] }) } as Response);
20+
responses.set(id, settle);
21+
if (signal?.aborted) {
22+
reject(new DOMException('The operation was aborted.', 'AbortError'));
23+
return;
24+
}
25+
signal?.addEventListener('abort', () =>
26+
reject(new DOMException('The operation was aborted.', 'AbortError')),
1927
);
2028
}),
2129
),
@@ -42,7 +50,7 @@ describe(TASK, () => {
4250
const { App } = await import('@octane-eval-submission/octane.strong-user-fetch/src/App.tsrx');
4351
const view = render(App, { props: { userId: '1' } });
4452
expect(view.container.textContent).toBe('Loading…');
45-
expect(fetch).toHaveBeenCalledWith('/api/users/1');
53+
expect(vi.mocked(fetch).mock.calls[0]![0]).toBe('/api/users/1');
4654
await respond('1');
4755
expect(view.container.textContent).toBe('Ada Lovelace');
4856
});

0 commit comments

Comments
 (0)