Skip to content

Commit f6540b0

Browse files
steipetePeter Steinberger
andauthored
test(agents): reuse prepared plugin metadata (#118613)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent 0fbddda commit f6540b0

2 files changed

Lines changed: 38 additions & 33 deletions

File tree

‎src/agents/model-fallback.test.ts‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import crypto from "node:crypto";
33
import path from "node:path";
44
import { expectDefined } from "@openclaw/normalization-core";
5-
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
5+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
66
import { TranscriptNotContinuableError } from "../../packages/agent-core/src/errors.js";
77
import type { OpenClawConfig } from "../config/config.js";
88
import { createAgentRunStaleLifecycleError } from "../infra/agent-lifecycle-error.js";
@@ -13,9 +13,6 @@ import {
1313
} from "../infra/diagnostic-events.js";
1414
import { resetLogger, setLoggerOverride } from "../logging/logger.js";
1515
import { createWarnLogCapture } from "../logging/test-helpers/warn-log-capture.js";
16-
import { setCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js";
17-
import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-state.js";
18-
import { loadPluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.js";
1916
import { GatewayDrainingError } from "../process/gateway-work-admission.js";
2017
import { AgentRunTerminalOutcomeError } from "./agent-run-terminal-error.js";
2118
import { AUTH_STORE_VERSION } from "./auth-profiles/constants.js";
@@ -50,13 +47,19 @@ import { resolveSessionSuspensionReason } from "./session-suspension.js";
5047
import { SessionWriteLockTimeoutError } from "./session-write-lock-error.js";
5148
import { makeModelFallbackCfg } from "./test-helpers/model-fallback-config-fixture.js";
5249

50+
const emptyManifestPlugins = [] as const;
51+
52+
function resolveFallbackCandidateRoutes(params: Parameters<typeof resolveModelCandidateChain>[0]) {
53+
return resolveModelCandidateChain({ manifestPlugins: emptyManifestPlugins, ...params });
54+
}
55+
5356
function resolveFallbackCandidateRefs(params: Parameters<typeof resolveModelCandidateChain>[0]) {
54-
return resolveModelCandidateChain(params).map(({ provider, model }) => ({ provider, model }));
57+
return resolveFallbackCandidateRoutes(params).map(({ provider, model }) => ({ provider, model }));
5558
}
5659

5760
const testing = {
5861
resolveFallbackCandidates: resolveFallbackCandidateRefs,
59-
resolveFallbackCandidateRoutes: resolveModelCandidateChain,
62+
resolveFallbackCandidateRoutes,
6063
resolveSessionSuspensionReason,
6164
shouldDiscardDeferredSessionSuspension,
6265
};
@@ -215,7 +218,6 @@ vi.mock("./auth-profiles.runtime.js", () => authRuntimeMock.runtime);
215218
const makeCfg = makeModelFallbackCfg;
216219
let authTempRoot = "";
217220
let authTempCounter = 0;
218-
const emptyManifestPlugins = [] as const;
219221

220222
function registerFallbackHarness(id: string): void {
221223
registerAgentHarness(
@@ -242,14 +244,6 @@ function createHarnessScopedPreflightError(harnessId: string): AgentHarnessPrefl
242244
const runWithModelFallback: typeof runWithModelFallbackBase = (params) =>
243245
runWithModelFallbackBase({ manifestPlugins: emptyManifestPlugins, ...params });
244246

245-
beforeAll(() => {
246-
setDefaultPluginMetadataSnapshot();
247-
});
248-
249-
afterAll(() => {
250-
clearCurrentPluginMetadataSnapshot();
251-
});
252-
253247
function resetModelFallbackTestState(): void {
254248
// Fallback state has process-level caches for skip markers, harnesses, auth,
255249
// and plugin normalization. Reset every surface between tests.
@@ -265,13 +259,6 @@ function resetModelFallbackTestState(): void {
265259
resetDiagnosticEventsForTest();
266260
}
267261

268-
function setDefaultPluginMetadataSnapshot(): void {
269-
setCurrentPluginMetadataSnapshot(loadPluginMetadataSnapshot({ config: {}, env: process.env }), {
270-
config: {},
271-
env: process.env,
272-
});
273-
}
274-
275262
afterEach(() => {
276263
resetModelFallbackTestState();
277264
cliBackendsTesting.resetDepsForTest();

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,36 @@ import {
99
import {
1010
areRuntimeModelRefsEquivalent,
1111
isCliRuntimeProvider,
12-
resolveCliRuntimeExecutionProvider,
12+
resolveCliRuntimeExecutionProvider as resolveCliRuntimeExecutionProviderBase,
1313
} from "./model-runtime-aliases.js";
1414

15+
const anthropicAuthAliasMetadata = {
16+
plugins: [
17+
{
18+
id: "anthropic",
19+
origin: "bundled",
20+
providerAuthChoices: [
21+
{
22+
provider: "anthropic",
23+
method: "cli",
24+
choiceId: "anthropic-cli",
25+
deprecatedChoiceIds: ["claude-cli"],
26+
choiceLabel: "Anthropic Claude CLI",
27+
},
28+
],
29+
},
30+
],
31+
} as never;
32+
33+
function resolveCliRuntimeExecutionProvider(
34+
params: Omit<Parameters<typeof resolveCliRuntimeExecutionProviderBase>[0], "metadataSnapshot">,
35+
) {
36+
return resolveCliRuntimeExecutionProviderBase({
37+
...params,
38+
metadataSnapshot: anthropicAuthAliasMetadata,
39+
});
40+
}
41+
1542
function createAnthropicAuthConfig(params: {
1643
order?: string[];
1744
models?: NonNullable<NonNullable<OpenClawConfig["agents"]>["defaults"]>["models"];
@@ -103,22 +130,13 @@ describe("resolveCliRuntimeExecutionProvider", () => {
103130
).toBe("claude-cli");
104131
});
105132

106-
it("uses caller-provided plugin auth aliases without metadata discovery", () => {
133+
it("uses prepared Anthropic auth choice aliases without metadata discovery", () => {
107134
expect(
108135
resolveCliRuntimeExecutionProvider({
109136
authProfileId: "anthropic:claude-cli",
110137
cfg: createAnthropicAuthConfig({ order: ["anthropic:api"] }),
111138
provider: "anthropic",
112139
modelId: "opus-4.7",
113-
metadataSnapshot: {
114-
plugins: [
115-
{
116-
id: "anthropic",
117-
origin: "bundled",
118-
providerAuthAliases: { "claude-cli": "anthropic" },
119-
},
120-
],
121-
} as never,
122140
}),
123141
).toBe("claude-cli");
124142
});

0 commit comments

Comments
 (0)