Files
openclaw/extensions/amazon-bedrock/stream.runtime.test.ts
Peter Steinberger 85f3e9e988 refactor: extract shared llm runtime
Move provider model registries, stream wrappers, OAuth helpers, and LLM utilities into src/llm with plugin-sdk barrels instead of depending on the old embedded runtime layout.
2026-05-27 10:40:15 +01:00

82 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { testing } from "./stream.runtime.js";
function bedrockModel(overrides: Record<string, unknown>) {
return {
api: "bedrock-converse-stream",
provider: "amazon-bedrock",
id: "amazon.nova-micro-v1:0",
name: "Nova Micro",
baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
reasoning: true,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 128000,
maxTokens: 4096,
...overrides,
} as never;
}
function signedThinkingContext(modelId: string) {
return {
messages: [
{
role: "assistant",
api: "bedrock-converse-stream",
provider: "amazon-bedrock",
model: modelId,
content: [{ type: "thinking", thinking: "private reasoning", thinkingSignature: "sig-1" }],
},
],
} as never;
}
describe("Bedrock reasoning replay", () => {
it("preserves signed reasoning for Claude profile descriptors", () => {
const modelId =
"arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/profile-abc";
const messages = testing.convertMessages(
signedThinkingContext(modelId),
bedrockModel({
id: modelId,
name: "Claude Sonnet application profile",
}),
"none",
);
expect(messages[0]?.content).toEqual([
{
reasoningContent: {
reasoningText: { text: "private reasoning", signature: "sig-1" },
},
},
]);
});
it("replays signed reasoning as plain text for non-Claude models", () => {
const modelId = "amazon.nova-micro-v1:0";
const messages = testing.convertMessages(
signedThinkingContext(modelId),
bedrockModel({ id: modelId, name: "Nova Micro" }),
"none",
);
expect(messages[0]?.content).toEqual([{ text: "private reasoning" }]);
});
});
describe("Bedrock profile endpoint resolution", () => {
it("treats request profiles as configured profiles for standard endpoints", () => {
const endpoint = "https://bedrock-runtime.us-west-2.amazonaws.com";
expect(testing.hasConfiguredBedrockProfile({ profile: "prod-bedrock" })).toBe(true);
expect(
testing.shouldUseExplicitBedrockEndpoint(
endpoint,
undefined,
testing.hasConfiguredBedrockProfile({ profile: "prod-bedrock" }),
),
).toBe(false);
});
});