From 0ac6c4bd2e84d50785aa6500afae4fd1b71aff10 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 19 Aug 2026 00:14:09 +0800 Subject: [PATCH] test(agents): isolate live session model fixture (#125659) --- .../sessions/agent-session.live.test.ts | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/agents/sessions/agent-session.live.test.ts b/src/agents/sessions/agent-session.live.test.ts index 99a7129cb386..af137e1c6dac 100644 --- a/src/agents/sessions/agent-session.live.test.ts +++ b/src/agents/sessions/agent-session.live.test.ts @@ -1,19 +1,17 @@ // Live end-to-end checks for AgentSession turns, compaction, and follow-up delivery. -import { mkdir, mkdtemp, rm } from "node:fs/promises"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import type { Model } from "openclaw/plugin-sdk/llm"; import { Type } from "typebox"; import { afterEach, describe, expect, it } from "vitest"; -import { discoverModels } from "../agent-model-discovery.js"; -import { isLiveTestEnabled, readLiveTestConfig } from "../live-test-helpers.js"; -import { ensureOpenClawModelsJson } from "../models-config.js"; +import { isLiveTestEnabled } from "../live-test-helpers.js"; import type { AgentMessage } from "../runtime/index.js"; import { AgentSession } from "./agent-session.js"; import { AuthStorage } from "./auth-storage.js"; import { createExtensionRuntime } from "./extensions/loader.js"; import type { LoadExtensionsResult, ToolDefinition } from "./extensions/types.js"; -import type { ModelRegistry } from "./model-registry.js"; +import { ModelRegistry } from "./model-registry.js"; import type { ResourceLoader } from "./resource-loader.js"; import { createAgentSession } from "./sdk.js"; import { SessionManager } from "./session-manager.js"; @@ -69,20 +67,41 @@ function createResourceLoader(handlers: ExtensionHandlers = new Map()): Resource } async function resolveLiveModel( - agentDir: string, + modelsPath: string, authStorage: AuthStorage, ): Promise<{ model: Model; modelRegistry: ModelRegistry }> { - await ensureOpenClawModelsJson(await readLiveTestConfig(), agentDir, { - providerDiscoveryProviderIds: ["anthropic"], - }); - const modelRegistry = discoverModels(authStorage, agentDir, { providerFilter: "anthropic" }); const requestedModelId = process.env.OPENCLAW_LIVE_AGENT_SESSION_MODEL?.trim() || DEFAULT_MODEL_ID; - const model = - modelRegistry.find("anthropic", requestedModelId) ?? - modelRegistry - .getAll() - .find((candidate) => candidate.provider === "anthropic" && /haiku/i.test(candidate.id)); + // This suite owns AgentSession behavior, so keep its provider fixture independent from the + // operator's config and refreshable catalog state. Catalog discovery has dedicated live lanes. + await writeFile( + modelsPath, + `${JSON.stringify( + { + providers: { + anthropic: { + baseUrl: "https://api.anthropic.com", + api: "anthropic-messages", + models: [ + { + id: requestedModelId, + name: requestedModelId, + reasoning: true, + input: ["text", "image"], + cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, + contextWindow: 200_000, + maxTokens: 64_000, + }, + ], + }, + }, + }, + null, + 2, + )}\n`, + ); + const modelRegistry = ModelRegistry.create(authStorage, modelsPath); + const model = modelRegistry.find("anthropic", requestedModelId); if (!model) { throw new Error(`No Anthropic Haiku model found for ${requestedModelId}`); } @@ -102,10 +121,11 @@ async function createLiveSession( tempRoots.push(root); const cwd = join(root, "workspace"); const agentDir = join(root, "agent"); + const modelsPath = join(root, "models.json"); await mkdir(cwd, { recursive: true }); const authStorage = AuthStorage.inMemory(); authStorage.setRuntimeApiKey("anthropic", API_KEY); - const { model, modelRegistry } = await resolveLiveModel(agentDir, authStorage); + const { model, modelRegistry } = await resolveLiveModel(modelsPath, authStorage); const sessionManager = SessionManager.inMemory(); const settingsManager = SettingsManager.inMemory({ defaultThinkingLevel: "off",