mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
test(agents): isolate live session model fixture (#125659)
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user