test: speed up provider payload coverage

This commit is contained in:
Mario Zechner
2026-05-20 12:37:36 +02:00
parent ac58c6f449
commit f1f7cd50c3
5 changed files with 106 additions and 72 deletions

View File

@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { getModel } from "../src/models.js";
import { type BedrockOptions, streamBedrock } from "../src/providers/amazon-bedrock.js";
import type { Context, Model } from "../src/types.js";
import { getModel } from "../src/models.ts";
import { type BedrockOptions, streamBedrock } from "../src/providers/amazon-bedrock.ts";
import type { Context, Model } from "../src/types.ts";
interface BedrockThinkingPayload {
additionalModelRequestFields?: {
@@ -11,6 +11,13 @@ interface BedrockThinkingPayload {
};
}
class PayloadCaptured extends Error {
constructor() {
super("payload captured");
this.name = "PayloadCaptured";
}
}
function makeContext(): Context {
return {
messages: [{ role: "user", content: "Hello", timestamp: Date.now() }],
@@ -25,10 +32,9 @@ async function capturePayload(
const s = streamBedrock(model, makeContext(), {
...options,
reasoning: options?.reasoning ?? "high",
signal: AbortSignal.abort(),
onPayload: (payload) => {
capturedPayload = payload as BedrockThinkingPayload;
return payload;
throw new PayloadCaptured();
},
});
@@ -137,10 +143,9 @@ describe("Application inference profile support", () => {
messages: [{ role: "user", content: "Hello", timestamp: Date.now() }],
},
{
signal: AbortSignal.abort(),
onPayload: (payload) => {
capturedPayload = payload;
return payload;
throw new PayloadCaptured();
},
},
);