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
9 changed files with 68 additions and 58 deletions

View File

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

View File

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

View File

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

View File

@@ -7,7 +7,9 @@ import {
import { applyBootstrapHookOverrides } from "./bootstrap-hooks.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 {
name,
path: `/tmp/${name}`,
@@ -25,7 +27,12 @@ describe("applyBootstrapHookOverrides", () => {
const context = event.context as AgentBootstrapHookContext;
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[1]?.name).toBe("EXTRA.md");
expect(updated[1]?.path).toBe("/tmp/EXTRA.md");
});
});

View File

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

View File

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

View File

@@ -4,7 +4,6 @@ describe("minimaxUnderstandImage apiKey normalization", () => {
const priorFetch = global.fetch;
afterEach(() => {
// @ts-expect-error restore
global.fetch = priorFetch;
vi.restoreAllMocks();
});
@@ -22,7 +21,6 @@ describe("minimaxUnderstandImage apiKey normalization", () => {
{ status: 200, headers: { "Content-Type": "application/json" } },
);
});
// @ts-expect-error mock fetch
global.fetch = fetchSpy;
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 { 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", () => ({
runEmbeddedAttempt: (params: unknown) => runEmbeddedAttemptMock(params),

View File

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