

























@@ -1,13 +1,14 @@
1+// Exercises model fallback through the embedded runner integration surface.
12import fs from "node:fs/promises";
23import os from "node:os";
34import path from "node:path";
45import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
56import type { OpenClawConfig } from "../config/config.js";
67import type { AuthProfileFailureReason } from "./auth-profiles.js";
8+import { ensureAuthProfileStore, saveAuthProfileStore } from "./auth-profiles/store.js";
79import { classifyEmbeddedAgentRunResultForModelFallback } from "./embedded-agent-runner/result-fallback-classifier.js";
810import type { EmbeddedRunAttemptResult } from "./embedded-agent-runner/run/types.js";
911import { runWithModelFallback } from "./model-fallback.js";
10-import { ensureAuthProfileStore, saveAuthProfileStore } from "./auth-profiles/store.js";
1112import {
1213buildEmbeddedRunnerAssistant,
1314createResolvedEmbeddedRunnerModel,
@@ -39,6 +40,8 @@ vi.mock("./models-config.js", async () => {
3940});
40414142const installRunEmbeddedMocks = () => {
43+// Install the runner mocks before importing runEmbeddedAgent so the e2e path
44+// exercises fallback orchestration without live model/provider calls.
4245installEmbeddedRunnerBaseE2eMocks();
4346installEmbeddedRunnerFastRunE2eMocks({
4447runEmbeddedAttempt: (params) => runEmbeddedAttemptMock(params),
@@ -131,6 +134,8 @@ function makeConfig(): OpenClawConfig {
131134async function withAgentWorkspace<T>(
132135fn: (ctx: { agentDir: string; workspaceDir: string }) => Promise<T>,
133136): Promise<T> {
137+// Each e2e case gets isolated agent/workspace dirs because usage stats and
138+// transcripts are part of the fallback behavior under test.
134139const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-model-fallback-"));
135140const agentDir = path.join(root, "agent");
136141const workspaceDir = path.join(root, "workspace");
@@ -217,6 +222,8 @@ async function runEmbeddedFallback(params: {
217222abortSignal?: AbortSignal;
218223config?: OpenClawConfig;
219224}) {
225+// Runs the same embedded-agent entrypoint that production fallback uses while
226+// keeping provider/model attempts deterministic through mocks.
220227const cfg = params.config ?? makeConfig();
221228return await runWithModelFallback({
222229 cfg,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。