




















@@ -5,7 +5,9 @@ import type { OpenClawConfig } from "../../src/config/config.js";
55import { buildPluginApi } from "../../src/plugins/api-builder.js";
66import type { PluginRuntime } from "../../src/plugins/runtime/types.js";
77import { registerSingleProviderPlugin } from "../../test/helpers/plugins/plugin-registration.js";
8+import { resetBedrockDiscoveryCacheForTest } from "./discovery.js";
89import amazonBedrockPlugin from "./index.js";
10+import { resetBedrockAppProfileCacheEligibilityForTest } from "./register.sync.runtime.js";
9111012type BedrockClientResult =
1113| {
@@ -15,14 +17,44 @@ type BedrockClientResult =
1517}
1618| Error;
171918-const inferenceProfileResults: BedrockClientResult[] = [];
20+const foundationModelResults: BedrockClientResult[] = [];
21+const inferenceProfileListResults: BedrockClientResult[] = [];
22+const inferenceProfileGetResults: BedrockClientResult[] = [];
1923const bedrockClientConfigs: Array<Record<string, unknown>> = [];
20-const sendGetInferenceProfile = vi.fn(async () => {
21-const next = inferenceProfileResults.shift();
24+const sendBedrockCommand = vi.fn(async (command: unknown) => {
25+const commandName = command?.constructor?.name;
26+const queue =
27+commandName === "ListFoundationModelsCommand"
28+ ? foundationModelResults
29+ : commandName === "ListInferenceProfilesCommand"
30+ ? inferenceProfileListResults
31+ : inferenceProfileGetResults;
32+const next = queue.shift();
2233if (next instanceof Error) {
2334throw next;
2435}
25-return next ?? { models: [] };
36+if (next) {
37+return next;
38+}
39+if (commandName === "ListFoundationModelsCommand") {
40+return {
41+modelSummaries: [
42+{
43+modelId: NON_ANTHROPIC_MODEL,
44+modelName: "Nova Micro",
45+providerName: "Amazon",
46+inputModalities: ["TEXT"],
47+outputModalities: ["TEXT"],
48+responseStreamingSupported: true,
49+modelLifecycle: { status: "ACTIVE" },
50+},
51+],
52+};
53+}
54+if (commandName === "ListInferenceProfilesCommand") {
55+return { inferenceProfileSummaries: [] };
56+}
57+return { models: [] };
2658});
27592860vi.mock("@aws-sdk/client-bedrock", () => {
@@ -43,7 +75,7 @@ vi.mock("@aws-sdk/client-bedrock", () => {
4375bedrockClientConfigs.push(config);
4476}
457746-send = sendGetInferenceProfile;
78+send = sendBedrockCommand;
4779}
48804981return {
@@ -156,17 +188,6 @@ function callWrappedStream(
156188return result;
157189}
158190159-async function runCatalog(
160-provider: RegisteredProviderPlugin,
161-config: OpenClawConfig,
162-env: NodeJS.ProcessEnv = {} as NodeJS.ProcessEnv,
163-) {
164-return provider.catalog?.run({
165- config,
166- env,
167-} as never);
168-}
169-170191function runtimePluginConfig(config?: Record<string, unknown>): OpenClawConfig {
171192return {
172193plugins: {
@@ -183,9 +204,13 @@ function runtimePluginConfig(config?: Record<string, unknown>): OpenClawConfig {
183204184205describe("amazon-bedrock provider plugin", () => {
185206beforeEach(() => {
186-inferenceProfileResults.length = 0;
207+foundationModelResults.length = 0;
208+inferenceProfileListResults.length = 0;
209+inferenceProfileGetResults.length = 0;
187210bedrockClientConfigs.length = 0;
188-sendGetInferenceProfile.mockClear();
211+sendBedrockCommand.mockClear();
212+resetBedrockDiscoveryCacheForTest();
213+resetBedrockAppProfileCacheEligibilityForTest();
189214});
190215191216it("marks Claude 4.6 Bedrock models as adaptive by default", async () => {
@@ -439,51 +464,6 @@ describe("amazon-bedrock provider plugin", () => {
439464});
440465});
441466442-describe("discovery config", () => {
443-it("uses live plugin config to re-enable discovery after startup disable", async () => {
444-inferenceProfileResults.push(
445-{
446-modelSummaries: [
447-{
448-modelId: NON_ANTHROPIC_MODEL,
449-modelName: "Nova Micro",
450-providerName: "Amazon",
451-inputModalities: ["TEXT"],
452-outputModalities: ["TEXT"],
453-responseStreamingSupported: true,
454-modelLifecycle: { status: "ACTIVE" },
455-},
456-],
457-},
458-{
459-inferenceProfileSummaries: [],
460-},
461-);
462-const provider = await registerWithConfig({
463-discovery: {
464-enabled: false,
465-},
466-});
467-468-const catalog = await runCatalog(
469-provider,
470-runtimePluginConfig({
471-discovery: {
472-enabled: true,
473-region: "us-east-1",
474-},
475-}),
476-);
477-478-expect(catalog).toMatchObject({
479-provider: {
480-baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com",
481-api: "bedrock-converse-stream",
482-},
483-});
484-});
485-});
486-487467describe("application inference profile cache point injection", () => {
488468/**
489469 * Invoke wrapStreamFn with a payload containing system/messages, then
@@ -721,7 +701,7 @@ describe("amazon-bedrock provider plugin", () => {
721701it("injects cache points for opaque application inference profile ARNs after profile lookup", async () => {
722702const modelId =
723703"arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/z27qyso459da";
724-inferenceProfileResults.push({
704+inferenceProfileGetResults.push({
725705models: [
726706{
727707modelArn:
@@ -745,14 +725,14 @@ describe("amazon-bedrock provider plugin", () => {
745725746726const system = payload.system as Array<Record<string, unknown>>;
747727expect(system[1]).toEqual({ cachePoint: { type: "default" } });
748-expect(sendGetInferenceProfile).toHaveBeenCalledTimes(1);
728+expect(sendBedrockCommand).toHaveBeenCalledTimes(1);
749729expect(bedrockClientConfigs).toEqual([{ region: "us-east-1" }]);
750730});
751731752732it("does not inject cache points when any resolved profile target is not cacheable", async () => {
753733const modelId =
754734"arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/z27qyso459db";
755-inferenceProfileResults.push({
735+inferenceProfileGetResults.push({
756736models: [
757737{
758738modelArn:
@@ -785,7 +765,7 @@ describe("amazon-bedrock provider plugin", () => {
785765it("retries opaque profile lookup after a transient failure instead of caching the fallback", async () => {
786766const modelId =
787767"arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/z27qyso459dc";
788-inferenceProfileResults.push(new Error("throttled"), {
768+inferenceProfileGetResults.push(new Error("throttled"), {
789769models: [
790770{
791771modelArn:
@@ -823,7 +803,7 @@ describe("amazon-bedrock provider plugin", () => {
823803{ text: "You are helpful." },
824804{ cachePoint: { type: "default" } },
825805]);
826-expect(sendGetInferenceProfile).toHaveBeenCalledTimes(2);
806+expect(sendBedrockCommand).toHaveBeenCalledTimes(2);
827807});
828808});
829809});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。