Skip to content

Commit 94f4314

Browse files
steipetePeter Steinberger
andauthored
test(agents): avoid provider fixture fallback delays (#118770)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent b8f5aa8 commit 94f4314

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎src/agents/model-runtime-aliases.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function createAnthropicAuthConfig(params: {
6464
describe("resolveCliRuntimeExecutionProvider", () => {
6565
beforeEach(() => {
6666
cliBackendsTesting.setDepsForTest({
67+
resolvePluginSetupCliBackend: () => undefined,
6768
resolvePluginSetupRegistry: () => ({
6869
providers: [],
6970
cliBackends: [],

‎src/agents/provider-http-errors.test.ts‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,19 +421,29 @@ describe("provider error utils", () => {
421421
});
422422

423423
it("rejects stalled non-2xx error body read after chunk idle timeout", async () => {
424-
const stream = new ReadableStream<Uint8Array>({
425-
start(controller) {
426-
controller.enqueue(new TextEncoder().encode('{"error": {"message": "par'));
427-
},
428-
});
429-
const response = new Response(stream, {
430-
status: 502,
431-
headers: { "content-type": "application/json" },
432-
});
424+
vi.useFakeTimers();
425+
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
426+
try {
427+
const stream = new ReadableStream<Uint8Array>({
428+
start(controller) {
429+
controller.enqueue(new TextEncoder().encode('{"error": {"message": "par'));
430+
},
431+
});
432+
const response = new Response(stream, {
433+
status: 502,
434+
headers: { "content-type": "application/json" },
435+
});
433436

434-
await expect(assertOkOrThrowProviderError(response, "stalled-error")).rejects.toThrow(
435-
"stalled-error (502)",
436-
);
437+
const assertion = expect(
438+
assertOkOrThrowProviderError(response, "stalled-error"),
439+
).rejects.toThrow("stalled-error (502)");
440+
await vi.advanceTimersByTimeAsync(0);
441+
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 10_000);
442+
await vi.advanceTimersByTimeAsync(10_000);
443+
await assertion;
444+
} finally {
445+
vi.useRealTimers();
446+
}
437447
});
438448

439449
it("proves idle timeout with a real TCP server that stalls mid-JSON-body", async () => {

0 commit comments

Comments
 (0)