chore: Fix types in tests 20/N.

This commit is contained in:
cpojer 2026-02-17 12:21:55 +09:00
parent e09643e82c
commit 18cc48dfd9
No known key found for this signature in database
GPG Key ID: C29F94A3201118AF
9 changed files with 68 additions and 58 deletions

View File

@ -4,6 +4,7 @@ import {
ANTHROPIC_CFG, ANTHROPIC_CFG,
ANTHROPIC_STORE, ANTHROPIC_STORE,
} from "./auth-profiles.resolve-auth-profile-order.fixtures.js"; } from "./auth-profiles.resolve-auth-profile-order.fixtures.js";
import type { AuthProfileStore } from "./auth-profiles/types.js";
describe("resolveAuthProfileOrder", () => { describe("resolveAuthProfileOrder", () => {
const store = ANTHROPIC_STORE; const store = ANTHROPIC_STORE;
@ -37,7 +38,7 @@ describe("resolveAuthProfileOrder", () => {
cfg: { cfg: {
auth: { auth: {
order: { anthropic: ["anthropic:work", "anthropic:default"] }, order: { anthropic: ["anthropic:work", "anthropic:default"] },
profiles: cfg.auth.profiles, profiles: cfg.auth?.profiles,
}, },
}, },
store, store,
@ -50,7 +51,7 @@ describe("resolveAuthProfileOrder", () => {
cfg: { cfg: {
auth: { auth: {
order: { anthropic: ["anthropic:default", "anthropic:work"] }, order: { anthropic: ["anthropic:default", "anthropic:work"] },
profiles: cfg.auth.profiles, profiles: cfg.auth?.profiles,
}, },
}, },
store: { store: {
@ -82,7 +83,7 @@ describe("resolveAuthProfileOrder", () => {
cfg: { cfg: {
auth: { auth: {
order: { anthropic: ["anthropic:default", "anthropic:work"] }, order: { anthropic: ["anthropic:default", "anthropic:work"] },
profiles: cfg.auth.profiles, profiles: cfg.auth?.profiles,
}, },
}, },
store: { store: {
@ -120,7 +121,7 @@ describe("resolveAuthProfileOrder", () => {
cfg: { cfg: {
auth: { auth: {
order: { anthropic: ["anthropic:default", "anthropic:work"] }, order: { anthropic: ["anthropic:default", "anthropic:work"] },
profiles: cfg.auth.profiles, profiles: cfg.auth?.profiles,
}, },
}, },
store: { store: {

View File

@ -1,3 +1,4 @@
import type { OpenClawConfig } from "../config/config.js";
import type { AuthProfileStore } from "./auth-profiles.js"; import type { AuthProfileStore } from "./auth-profiles.js";
export const ANTHROPIC_STORE: AuthProfileStore = { export const ANTHROPIC_STORE: AuthProfileStore = {
@ -16,7 +17,7 @@ export const ANTHROPIC_STORE: AuthProfileStore = {
}, },
}; };
export const ANTHROPIC_CFG = { export const ANTHROPIC_CFG: OpenClawConfig = {
auth: { auth: {
profiles: { profiles: {
"anthropic:default": { provider: "anthropic", mode: "api_key" }, "anthropic:default": { provider: "anthropic", mode: "api_key" },

View File

@ -7,6 +7,7 @@ import {
} from "../hooks/internal-hooks.js"; } from "../hooks/internal-hooks.js";
import { makeTempWorkspace } from "../test-helpers/workspace.js"; import { makeTempWorkspace } from "../test-helpers/workspace.js";
import { resolveBootstrapContextForRun, resolveBootstrapFilesForRun } from "./bootstrap-files.js"; import { resolveBootstrapContextForRun, resolveBootstrapFilesForRun } from "./bootstrap-files.js";
import type { WorkspaceBootstrapFile } from "./workspace.js";
describe("resolveBootstrapFilesForRun", () => { describe("resolveBootstrapFilesForRun", () => {
beforeEach(() => clearInternalHooks()); beforeEach(() => clearInternalHooks());
@ -22,14 +23,14 @@ describe("resolveBootstrapFilesForRun", () => {
path: path.join(context.workspaceDir, "EXTRA.md"), path: path.join(context.workspaceDir, "EXTRA.md"),
content: "extra", content: "extra",
missing: false, missing: false,
}, } as unknown as WorkspaceBootstrapFile,
]; ];
}); });
const workspaceDir = await makeTempWorkspace("openclaw-bootstrap-"); const workspaceDir = await makeTempWorkspace("openclaw-bootstrap-");
const files = await resolveBootstrapFilesForRun({ workspaceDir }); const files = await resolveBootstrapFilesForRun({ workspaceDir });
expect(files.some((file) => file.name === "EXTRA.md")).toBe(true); expect(files.some((file) => file.path === path.join(workspaceDir, "EXTRA.md"))).toBe(true);
}); });
}); });
@ -47,7 +48,7 @@ describe("resolveBootstrapContextForRun", () => {
path: path.join(context.workspaceDir, "EXTRA.md"), path: path.join(context.workspaceDir, "EXTRA.md"),
content: "extra", content: "extra",
missing: false, missing: false,
}, } as unknown as WorkspaceBootstrapFile,
]; ];
}); });

View File

@ -7,7 +7,9 @@ import {
import { applyBootstrapHookOverrides } from "./bootstrap-hooks.js"; import { applyBootstrapHookOverrides } from "./bootstrap-hooks.js";
import { DEFAULT_SOUL_FILENAME, type WorkspaceBootstrapFile } from "./workspace.js"; import { DEFAULT_SOUL_FILENAME, type WorkspaceBootstrapFile } from "./workspace.js";
function makeFile(name = DEFAULT_SOUL_FILENAME): WorkspaceBootstrapFile { function makeFile(
name: WorkspaceBootstrapFile["name"] = DEFAULT_SOUL_FILENAME,
): WorkspaceBootstrapFile {
return { return {
name, name,
path: `/tmp/${name}`, path: `/tmp/${name}`,
@ -25,7 +27,12 @@ describe("applyBootstrapHookOverrides", () => {
const context = event.context as AgentBootstrapHookContext; const context = event.context as AgentBootstrapHookContext;
context.bootstrapFiles = [ context.bootstrapFiles = [
...context.bootstrapFiles, ...context.bootstrapFiles,
{ name: "EXTRA.md", path: "/tmp/EXTRA.md", content: "extra", missing: false }, {
name: "EXTRA.md",
path: "/tmp/EXTRA.md",
content: "extra",
missing: false,
} as unknown as WorkspaceBootstrapFile,
]; ];
}); });
@ -35,6 +42,6 @@ describe("applyBootstrapHookOverrides", () => {
}); });
expect(updated).toHaveLength(2); expect(updated).toHaveLength(2);
expect(updated[1]?.name).toBe("EXTRA.md"); expect(updated[1]?.path).toBe("/tmp/EXTRA.md");
}); });
}); });

View File

@ -161,10 +161,10 @@ describe("pruneHistoryForContextShare", () => {
role: "assistant", role: "assistant",
content: [ content: [
{ type: "text", text: "x".repeat(4000) }, { type: "text", text: "x".repeat(4000) },
{ type: "toolUse", id: "call_123", name: "test_tool", input: {} }, { type: "toolCall", id: "call_123", name: "test_tool", arguments: {} },
], ],
timestamp: 1, timestamp: 1,
}, } as unknown as AgentMessage,
// Chunk 2 (will be kept) - contains orphaned tool_result // Chunk 2 (will be kept) - contains orphaned tool_result
{ {
role: "toolResult", role: "toolResult",
@ -172,7 +172,7 @@ describe("pruneHistoryForContextShare", () => {
toolName: "test_tool", toolName: "test_tool",
content: [{ type: "text", text: "result".repeat(500) }], content: [{ type: "text", text: "result".repeat(500) }],
timestamp: 2, timestamp: 2,
} as AgentMessage, } as unknown as AgentMessage,
{ {
role: "user", role: "user",
content: "x".repeat(500), content: "x".repeat(500),
@ -212,17 +212,17 @@ describe("pruneHistoryForContextShare", () => {
role: "assistant", role: "assistant",
content: [ content: [
{ type: "text", text: "y".repeat(500) }, { type: "text", text: "y".repeat(500) },
{ type: "toolUse", id: "call_456", name: "kept_tool", input: {} }, { type: "toolCall", id: "call_456", name: "kept_tool", arguments: {} },
], ],
timestamp: 2, timestamp: 2,
}, } as unknown as AgentMessage,
{ {
role: "toolResult", role: "toolResult",
toolCallId: "call_456", toolCallId: "call_456",
toolName: "kept_tool", toolName: "kept_tool",
content: [{ type: "text", text: "result" }], content: [{ type: "text", text: "result" }],
timestamp: 3, timestamp: 3,
} as AgentMessage, } as unknown as AgentMessage,
]; ];
const pruned = pruneHistoryForContextShare({ const pruned = pruneHistoryForContextShare({
@ -247,11 +247,11 @@ describe("pruneHistoryForContextShare", () => {
role: "assistant", role: "assistant",
content: [ content: [
{ type: "text", text: "x".repeat(4000) }, { type: "text", text: "x".repeat(4000) },
{ type: "toolUse", id: "call_a", name: "tool_a", input: {} }, { type: "toolCall", id: "call_a", name: "tool_a", arguments: {} },
{ type: "toolUse", id: "call_b", name: "tool_b", input: {} }, { type: "toolCall", id: "call_b", name: "tool_b", arguments: {} },
], ],
timestamp: 1, timestamp: 1,
}, } as unknown as AgentMessage,
// Chunk 2 (will be kept) - contains orphaned tool_results // Chunk 2 (will be kept) - contains orphaned tool_results
{ {
role: "toolResult", role: "toolResult",
@ -259,14 +259,14 @@ describe("pruneHistoryForContextShare", () => {
toolName: "tool_a", toolName: "tool_a",
content: [{ type: "text", text: "result_a" }], content: [{ type: "text", text: "result_a" }],
timestamp: 2, timestamp: 2,
} as AgentMessage, } as unknown as AgentMessage,
{ {
role: "toolResult", role: "toolResult",
toolCallId: "call_b", toolCallId: "call_b",
toolName: "tool_b", toolName: "tool_b",
content: [{ type: "text", text: "result_b" }], content: [{ type: "text", text: "result_b" }],
timestamp: 3, timestamp: 3,
} as AgentMessage, } as unknown as AgentMessage,
{ {
role: "user", role: "user",
content: "x".repeat(500), content: "x".repeat(500),

View File

@ -1,9 +1,12 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { resolveMemorySearchConfig } from "./memory-search.js"; import { resolveMemorySearchConfig } from "./memory-search.js";
const asConfig = (cfg: OpenClawConfig): OpenClawConfig => cfg;
describe("memory search config", () => { describe("memory search config", () => {
it("returns null when disabled", () => { it("returns null when disabled", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { enabled: true }, memorySearch: { enabled: true },
@ -16,13 +19,13 @@ describe("memory search config", () => {
}, },
], ],
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved).toBeNull(); expect(resolved).toBeNull();
}); });
it("defaults provider to auto when unspecified", () => { it("defaults provider to auto when unspecified", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -30,14 +33,14 @@ describe("memory search config", () => {
}, },
}, },
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.provider).toBe("auto"); expect(resolved?.provider).toBe("auto");
expect(resolved?.fallback).toBe("none"); expect(resolved?.fallback).toBe("none");
}); });
it("merges defaults and overrides", () => { it("merges defaults and overrides", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -69,7 +72,7 @@ describe("memory search config", () => {
}, },
], ],
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.provider).toBe("openai"); expect(resolved?.provider).toBe("openai");
expect(resolved?.model).toBe("text-embedding-3-small"); expect(resolved?.model).toBe("text-embedding-3-small");
@ -82,7 +85,7 @@ describe("memory search config", () => {
}); });
it("merges extra memory paths from defaults and overrides", () => { it("merges extra memory paths from defaults and overrides", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -99,13 +102,13 @@ describe("memory search config", () => {
}, },
], ],
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.extraPaths).toEqual(["/shared/notes", "docs", "../team-notes"]); expect(resolved?.extraPaths).toEqual(["/shared/notes", "docs", "../team-notes"]);
}); });
it("includes batch defaults for openai without remote overrides", () => { it("includes batch defaults for openai without remote overrides", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -113,7 +116,7 @@ describe("memory search config", () => {
}, },
}, },
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.remote?.batch).toEqual({ expect(resolved?.remote?.batch).toEqual({
enabled: false, enabled: false,
@ -125,7 +128,7 @@ describe("memory search config", () => {
}); });
it("keeps remote unset for local provider without overrides", () => { it("keeps remote unset for local provider without overrides", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -133,13 +136,13 @@ describe("memory search config", () => {
}, },
}, },
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.remote).toBeUndefined(); expect(resolved?.remote).toBeUndefined();
}); });
it("includes remote defaults for gemini without overrides", () => { it("includes remote defaults for gemini without overrides", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -147,7 +150,7 @@ describe("memory search config", () => {
}, },
}, },
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.remote?.batch).toEqual({ expect(resolved?.remote?.batch).toEqual({
enabled: false, enabled: false,
@ -159,7 +162,7 @@ describe("memory search config", () => {
}); });
it("defaults session delta thresholds", () => { it("defaults session delta thresholds", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -167,7 +170,7 @@ describe("memory search config", () => {
}, },
}, },
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.sync.sessions).toEqual({ expect(resolved?.sync.sessions).toEqual({
deltaBytes: 100000, deltaBytes: 100000,
@ -176,7 +179,7 @@ describe("memory search config", () => {
}); });
it("merges remote defaults with agent overrides", () => { it("merges remote defaults with agent overrides", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -200,7 +203,7 @@ describe("memory search config", () => {
}, },
], ],
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.remote).toEqual({ expect(resolved?.remote).toEqual({
baseUrl: "https://agent.example/v1", baseUrl: "https://agent.example/v1",
@ -217,7 +220,7 @@ describe("memory search config", () => {
}); });
it("gates session sources behind experimental flag", () => { it("gates session sources behind experimental flag", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -235,13 +238,13 @@ describe("memory search config", () => {
}, },
], ],
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.sources).toEqual(["memory"]); expect(resolved?.sources).toEqual(["memory"]);
}); });
it("allows session sources when experimental flag is enabled", () => { it("allows session sources when experimental flag is enabled", () => {
const cfg = { const cfg = asConfig({
agents: { agents: {
defaults: { defaults: {
memorySearch: { memorySearch: {
@ -251,7 +254,7 @@ describe("memory search config", () => {
}, },
}, },
}, },
}; });
const resolved = resolveMemorySearchConfig(cfg, "main"); const resolved = resolveMemorySearchConfig(cfg, "main");
expect(resolved?.sources).toContain("sessions"); expect(resolved?.sources).toContain("sessions");
}); });

View File

@ -4,7 +4,6 @@ describe("minimaxUnderstandImage apiKey normalization", () => {
const priorFetch = global.fetch; const priorFetch = global.fetch;
afterEach(() => { afterEach(() => {
// @ts-expect-error restore
global.fetch = priorFetch; global.fetch = priorFetch;
vi.restoreAllMocks(); vi.restoreAllMocks();
}); });
@ -22,7 +21,6 @@ describe("minimaxUnderstandImage apiKey normalization", () => {
{ status: 200, headers: { "Content-Type": "application/json" } }, { status: 200, headers: { "Content-Type": "application/json" } },
); );
}); });
// @ts-expect-error mock fetch
global.fetch = fetchSpy; global.fetch = fetchSpy;
const { minimaxUnderstandImage } = await import("./minimax-vlm.js"); const { minimaxUnderstandImage } = await import("./minimax-vlm.js");

View File

@ -6,7 +6,7 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js"; import type { OpenClawConfig } from "../config/config.js";
import type { EmbeddedRunAttemptResult } from "./pi-embedded-runner/run/types.js"; import type { EmbeddedRunAttemptResult } from "./pi-embedded-runner/run/types.js";
const runEmbeddedAttemptMock = vi.fn<Promise<EmbeddedRunAttemptResult>, [unknown]>(); const runEmbeddedAttemptMock = vi.fn<(params: unknown) => Promise<EmbeddedRunAttemptResult>>();
vi.mock("./pi-embedded-runner/run/attempt.js", () => ({ vi.mock("./pi-embedded-runner/run/attempt.js", () => ({
runEmbeddedAttempt: (params: unknown) => runEmbeddedAttemptMock(params), runEmbeddedAttempt: (params: unknown) => runEmbeddedAttemptMock(params),

View File

@ -10,13 +10,12 @@ import {
makeReasoningAssistantMessages, makeReasoningAssistantMessages,
makeSimpleUserMessages, makeSimpleUserMessages,
makeSnapshotChangedOpenAIReasoningScenario, makeSnapshotChangedOpenAIReasoningScenario,
type SanitizeSessionHistoryFn,
sanitizeWithOpenAIResponses, sanitizeWithOpenAIResponses,
TEST_SESSION_ID, TEST_SESSION_ID,
} from "./pi-embedded-runner.sanitize-session-history.test-harness.js"; } from "./pi-embedded-runner.sanitize-session-history.test-harness.js";
type SanitizeSessionHistory = let sanitizeSessionHistory: SanitizeSessionHistoryFn;
typeof import("./pi-embedded-runner/google.js").sanitizeSessionHistory;
let sanitizeSessionHistory: SanitizeSessionHistory;
// Mock dependencies // Mock dependencies
vi.mock("./pi-embedded-helpers.js", async () => { vi.mock("./pi-embedded-helpers.js", async () => {
@ -137,7 +136,7 @@ describe("sanitizeSessionHistory", () => {
it("keeps reasoning-only assistant messages for openai-responses", async () => { it("keeps reasoning-only assistant messages for openai-responses", async () => {
vi.mocked(helpers.isGoogleModelApi).mockReturnValue(false); vi.mocked(helpers.isGoogleModelApi).mockReturnValue(false);
const messages: AgentMessage[] = [ const messages = [
{ role: "user", content: "hello" }, { role: "user", content: "hello" },
{ {
role: "assistant", role: "assistant",
@ -150,7 +149,7 @@ describe("sanitizeSessionHistory", () => {
}, },
], ],
}, },
]; ] as unknown as AgentMessage[];
const result = await sanitizeSessionHistory({ const result = await sanitizeSessionHistory({
messages, messages,
@ -165,12 +164,12 @@ describe("sanitizeSessionHistory", () => {
}); });
it("does not synthesize tool results for openai-responses", async () => { it("does not synthesize tool results for openai-responses", async () => {
const messages: AgentMessage[] = [ const messages = [
{ {
role: "assistant", role: "assistant",
content: [{ type: "toolCall", id: "call_1", name: "read", arguments: {} }], content: [{ type: "toolCall", id: "call_1", name: "read", arguments: {} }],
}, },
]; ] as unknown as AgentMessage[];
const result = await sanitizeSessionHistory({ const result = await sanitizeSessionHistory({
messages, messages,
@ -185,13 +184,13 @@ describe("sanitizeSessionHistory", () => {
}); });
it("drops malformed tool calls missing input or arguments", async () => { it("drops malformed tool calls missing input or arguments", async () => {
const messages: AgentMessage[] = [ const messages = [
{ {
role: "assistant", role: "assistant",
content: [{ type: "toolCall", id: "call_1", name: "read" }], content: [{ type: "toolCall", id: "call_1", name: "read" }],
}, },
{ role: "user", content: "hello" }, { role: "user", content: "hello" },
]; ] as unknown as AgentMessage[];
const result = await sanitizeSessionHistory({ const result = await sanitizeSessionHistory({
messages, messages,
@ -247,7 +246,7 @@ describe("sanitizeSessionHistory", () => {
}), }),
]; ];
const sessionManager = makeInMemorySessionManager(sessionEntries); const sessionManager = makeInMemorySessionManager(sessionEntries);
const messages: AgentMessage[] = [ const messages = [
{ {
role: "assistant", role: "assistant",
content: [{ type: "toolCall", id: "tool_abc123", name: "read", arguments: {} }], content: [{ type: "toolCall", id: "tool_abc123", name: "read", arguments: {} }],
@ -265,7 +264,7 @@ describe("sanitizeSessionHistory", () => {
toolName: "read", toolName: "read",
content: [{ type: "text", text: "stale result" }], content: [{ type: "text", text: "stale result" }],
} as unknown as AgentMessage, } as unknown as AgentMessage,
]; ] as unknown as AgentMessage[];
const result = await sanitizeSessionHistory({ const result = await sanitizeSessionHistory({
messages, messages,