mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
chore: Fix types in tests 43/N.
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
resolveBootstrapTotalMaxChars,
|
||||
} from "./pi-embedded-helpers.js";
|
||||
import { DEFAULT_AGENTS_FILENAME } from "./workspace.js";
|
||||
import type { WorkspaceBootstrapFile } from "./workspace.js";
|
||||
|
||||
const makeFile = (overrides: Partial<WorkspaceBootstrapFile>): WorkspaceBootstrapFile => ({
|
||||
name: DEFAULT_AGENTS_FILENAME,
|
||||
|
||||
@@ -35,7 +35,7 @@ vi.mock("@mariozechner/pi-ai", async () => {
|
||||
|
||||
const buildAssistantErrorMessage = (model: { api: string; provider: string; id: string }) => ({
|
||||
role: "assistant" as const,
|
||||
content: [] as const,
|
||||
content: [],
|
||||
stopReason: "error" as const,
|
||||
errorMessage: "boom",
|
||||
api: model.api,
|
||||
|
||||
@@ -21,7 +21,7 @@ describe("sanitizeSessionHistory openai tool id preservation", () => {
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "toolCall", id: "call_123|fc_123", name: "noop", arguments: {} }],
|
||||
},
|
||||
} as unknown as AgentMessage,
|
||||
{
|
||||
role: "toolResult",
|
||||
toolCallId: "call_123|fc_123",
|
||||
|
||||
@@ -9,8 +9,7 @@ import {
|
||||
sanitizeWithOpenAIResponses,
|
||||
} from "./pi-embedded-runner.sanitize-session-history.test-harness.js";
|
||||
|
||||
type SanitizeSessionHistory =
|
||||
typeof import("./pi-embedded-runner/google.js").sanitizeSessionHistory;
|
||||
type SanitizeSessionHistory = Awaited<ReturnType<typeof loadSanitizeSessionHistoryWithCleanMocks>>;
|
||||
let sanitizeSessionHistory: SanitizeSessionHistory;
|
||||
|
||||
vi.mock("./pi-embedded-helpers.js", async () => {
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("runEmbeddedPiAgent usage reporting", () => {
|
||||
});
|
||||
|
||||
// Check usage in meta
|
||||
const usage = result.meta.agentMeta.usage;
|
||||
const usage = result.meta.agentMeta?.usage;
|
||||
expect(usage).toBeDefined();
|
||||
|
||||
// Check if total matches the last turn's total (200)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createStubSessionHarness,
|
||||
|
||||
@@ -14,7 +14,14 @@ function makeAssistantMessage(
|
||||
api: "responses",
|
||||
provider: "openai",
|
||||
model: "gpt-5",
|
||||
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: 0 },
|
||||
usage: {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 0,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
},
|
||||
stopReason: "stop",
|
||||
...message,
|
||||
};
|
||||
|
||||
@@ -119,7 +119,7 @@ describe("computeAdaptiveChunkRatio", () => {
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "y".repeat(1000) }],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
} as unknown as AgentMessage,
|
||||
];
|
||||
|
||||
const ratio = computeAdaptiveChunkRatio(messages, CONTEXT_WINDOW);
|
||||
@@ -134,7 +134,7 @@ describe("computeAdaptiveChunkRatio", () => {
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "y".repeat(50_000 * 4) }],
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
} as unknown as AgentMessage,
|
||||
];
|
||||
|
||||
const ratio = computeAdaptiveChunkRatio(messages, CONTEXT_WINDOW);
|
||||
|
||||
@@ -68,7 +68,14 @@ function makeAssistant(text: string): AgentMessage {
|
||||
api: "openai-responses",
|
||||
provider: "openai",
|
||||
model: "fake",
|
||||
usage: { input: 1, output: 1, cacheRead: 0, cacheWrite: 0, total: 2 },
|
||||
usage: {
|
||||
input: 1,
|
||||
output: 1,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 2,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
},
|
||||
stopReason: "stop",
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ function createReadTool() {
|
||||
}
|
||||
|
||||
type ToolExecute = ReturnType<typeof toToolDefinitions>[number]["execute"];
|
||||
const extensionContext = {} as Parameters<ToolExecute>[3];
|
||||
const extensionContext = {} as Parameters<ToolExecute>[4];
|
||||
|
||||
function enableAfterToolCallHook() {
|
||||
hookMocks.runner.hasHooks.mockImplementation((name: string) => name === "after_tool_call");
|
||||
@@ -45,14 +45,12 @@ function enableAfterToolCallHook() {
|
||||
|
||||
async function executeReadTool(callId: string) {
|
||||
const defs = toToolDefinitions([createReadTool()]);
|
||||
const args: Parameters<(typeof defs)[number]["execute"]> = [
|
||||
callId,
|
||||
{ path: "/tmp/file" },
|
||||
undefined,
|
||||
extensionContext,
|
||||
undefined,
|
||||
];
|
||||
return await defs[0].execute(...args);
|
||||
const def = defs[0];
|
||||
if (!def) {
|
||||
throw new Error("missing tool definition");
|
||||
}
|
||||
const execute = (...args: Parameters<(typeof defs)[0]["execute"]>) => def.execute(...args);
|
||||
return await execute(callId, { path: "/tmp/file" }, undefined, undefined, extensionContext);
|
||||
}
|
||||
|
||||
function expectReadAfterToolCallPayload(result: Awaited<ReturnType<typeof executeReadTool>>) {
|
||||
@@ -119,14 +117,12 @@ describe("pi tool definition adapter after_tool_call", () => {
|
||||
} satisfies AgentTool;
|
||||
|
||||
const defs = toToolDefinitions([tool]);
|
||||
const args: Parameters<(typeof defs)[number]["execute"]> = [
|
||||
"call-err",
|
||||
{ cmd: "ls" },
|
||||
undefined,
|
||||
extensionContext,
|
||||
undefined,
|
||||
];
|
||||
const result = await defs[0].execute(...args);
|
||||
const def = defs[0];
|
||||
if (!def) {
|
||||
throw new Error("missing tool definition");
|
||||
}
|
||||
const execute = (...args: Parameters<(typeof defs)[0]["execute"]>) => def.execute(...args);
|
||||
const result = await execute("call-err", { cmd: "ls" }, undefined, undefined, extensionContext);
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
status: "error",
|
||||
|
||||
@@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";
|
||||
import { toToolDefinitions } from "./pi-tool-definition-adapter.js";
|
||||
|
||||
type ToolExecute = ReturnType<typeof toToolDefinitions>[number]["execute"];
|
||||
const extensionContext = {} as Parameters<ToolExecute>[3];
|
||||
const extensionContext = {} as Parameters<ToolExecute>[4];
|
||||
|
||||
describe("pi tool definition adapter", () => {
|
||||
it("wraps tool errors into a tool result", async () => {
|
||||
@@ -19,14 +19,12 @@ describe("pi tool definition adapter", () => {
|
||||
} satisfies AgentTool;
|
||||
|
||||
const defs = toToolDefinitions([tool]);
|
||||
const args: Parameters<(typeof defs)[number]["execute"]> = [
|
||||
"call1",
|
||||
{},
|
||||
undefined,
|
||||
extensionContext,
|
||||
undefined,
|
||||
];
|
||||
const result = await defs[0].execute(...args);
|
||||
const def = defs[0];
|
||||
if (!def) {
|
||||
throw new Error("missing tool definition");
|
||||
}
|
||||
const execute = (...args: Parameters<(typeof defs)[0]["execute"]>) => def.execute(...args);
|
||||
const result = await execute("call1", {}, undefined, undefined, extensionContext);
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
status: "error",
|
||||
@@ -48,14 +46,12 @@ describe("pi tool definition adapter", () => {
|
||||
} satisfies AgentTool;
|
||||
|
||||
const defs = toToolDefinitions([tool]);
|
||||
const args: Parameters<(typeof defs)[number]["execute"]> = [
|
||||
"call2",
|
||||
{},
|
||||
undefined,
|
||||
extensionContext,
|
||||
undefined,
|
||||
];
|
||||
const result = await defs[0].execute(...args);
|
||||
const def = defs[0];
|
||||
if (!def) {
|
||||
throw new Error("missing tool definition");
|
||||
}
|
||||
const execute = (...args: Parameters<(typeof defs)[0]["execute"]>) => def.execute(...args);
|
||||
const result = await execute("call2", {}, undefined, undefined, extensionContext);
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
status: "error",
|
||||
|
||||
@@ -618,7 +618,8 @@ describe("Agent-specific tool filtering", () => {
|
||||
yieldMs: 10,
|
||||
});
|
||||
|
||||
expect(result?.details.status).toBe("completed");
|
||||
const resultDetails = result?.details as { status?: string } | undefined;
|
||||
expect(resultDetails?.status).toBe("completed");
|
||||
});
|
||||
|
||||
it("should apply agent-specific exec host defaults over global defaults", async () => {
|
||||
@@ -673,6 +674,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
host: "sandbox",
|
||||
yieldMs: 1000,
|
||||
});
|
||||
expect(helperResult?.details.status).toBe("completed");
|
||||
const helperDetails = helperResult?.details as { status?: string } | undefined;
|
||||
expect(helperDetails?.status).toBe("completed");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -151,16 +151,14 @@ describe("before_tool_call hook deduplication (#15502)", () => {
|
||||
sessionKey: "main",
|
||||
});
|
||||
const [def] = toToolDefinitions([wrapped]);
|
||||
const extensionContext = {} as Parameters<typeof def.execute>[3];
|
||||
|
||||
const args: Parameters<typeof def.execute> = [
|
||||
const extensionContext = {} as Parameters<typeof def.execute>[4];
|
||||
await def.execute(
|
||||
"call-dedup",
|
||||
{ url: "https://example.com" },
|
||||
undefined,
|
||||
extensionContext,
|
||||
undefined,
|
||||
];
|
||||
await def.execute(...args);
|
||||
extensionContext,
|
||||
);
|
||||
|
||||
expect(hookRunner.runBeforeToolCall).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
@@ -200,16 +198,8 @@ describe("before_tool_call hook integration for client tools", () => {
|
||||
onClientToolCall,
|
||||
{ agentId: "main", sessionKey: "main" },
|
||||
);
|
||||
const extensionContext = {} as Parameters<typeof tool.execute>[3];
|
||||
|
||||
const args: Parameters<typeof tool.execute> = [
|
||||
"client-call-1",
|
||||
{ value: "ok" },
|
||||
undefined,
|
||||
extensionContext,
|
||||
undefined,
|
||||
];
|
||||
await tool.execute(...args);
|
||||
const extensionContext = {} as Parameters<typeof tool.execute>[4];
|
||||
await tool.execute("client-call-1", { value: "ok" }, undefined, undefined, extensionContext);
|
||||
|
||||
expect(onClientToolCall).toHaveBeenCalledWith("client_tool", {
|
||||
value: "ok",
|
||||
|
||||
@@ -79,7 +79,7 @@ describe("createOpenClawCodingTools", () => {
|
||||
sessionKey: "sandbox:test",
|
||||
workspaceDir: sandboxDir,
|
||||
agentWorkspaceDir: path.join(os.tmpdir(), "moltbot-workspace"),
|
||||
workspaceAccess: "none",
|
||||
workspaceAccess: "none" as const,
|
||||
containerName: "openclaw-sbx-test",
|
||||
containerWorkdir: "/workspace",
|
||||
fsBridge: createHostSandboxFsBridge(sandboxDir),
|
||||
@@ -112,7 +112,7 @@ describe("createOpenClawCodingTools", () => {
|
||||
sessionKey: "sandbox:test",
|
||||
workspaceDir: sandboxDir,
|
||||
agentWorkspaceDir: path.join(os.tmpdir(), "moltbot-workspace"),
|
||||
workspaceAccess: "ro",
|
||||
workspaceAccess: "ro" as const,
|
||||
containerName: "openclaw-sbx-test",
|
||||
containerWorkdir: "/workspace",
|
||||
fsBridge: createHostSandboxFsBridge(sandboxDir),
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import "./test-helpers/fast-coding-tools.js";
|
||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
||||
@@ -62,15 +63,12 @@ describe("createOpenClawCodingTools", () => {
|
||||
it("adds Claude-style aliases to schemas without dropping metadata", () => {
|
||||
const base: AgentTool = {
|
||||
name: "write",
|
||||
label: "write",
|
||||
description: "test",
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["path", "content"],
|
||||
properties: {
|
||||
path: { type: "string", description: "Path" },
|
||||
content: { type: "string", description: "Body" },
|
||||
},
|
||||
},
|
||||
parameters: Type.Object({
|
||||
path: Type.String({ description: "Path" }),
|
||||
content: Type.String({ description: "Body" }),
|
||||
}),
|
||||
execute: vi.fn(),
|
||||
};
|
||||
|
||||
@@ -90,15 +88,12 @@ describe("createOpenClawCodingTools", () => {
|
||||
const execute = vi.fn(async (_id, args) => args);
|
||||
const tool: AgentTool = {
|
||||
name: "write",
|
||||
label: "write",
|
||||
description: "test",
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["path", "content"],
|
||||
properties: {
|
||||
path: { type: "string" },
|
||||
content: { type: "string" },
|
||||
},
|
||||
},
|
||||
parameters: Type.Object({
|
||||
path: Type.String(),
|
||||
content: Type.String(),
|
||||
}),
|
||||
execute,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
@@ -7,12 +8,12 @@ import {
|
||||
resolveSubagentToolPolicy,
|
||||
} from "./pi-tools.policy.js";
|
||||
|
||||
function createStubTool(name: string): AgentTool<unknown, unknown> {
|
||||
function createStubTool(name: string): AgentTool {
|
||||
return {
|
||||
name,
|
||||
label: name,
|
||||
description: "",
|
||||
parameters: {},
|
||||
parameters: Type.Object({}),
|
||||
execute: async () => ({}) as AgentToolResult<unknown>,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -110,7 +110,8 @@ describe("createOpenClawCodingTools safeBins", () => {
|
||||
})();
|
||||
const text = result.content.find((content) => content.type === "text")?.text ?? "";
|
||||
|
||||
expect(result.details.status).toBe("completed");
|
||||
const resultDetails = result.details as { status?: string };
|
||||
expect(resultDetails.status).toBe("completed");
|
||||
expect(text).toContain(marker);
|
||||
});
|
||||
|
||||
@@ -152,7 +153,8 @@ describe("createOpenClawCodingTools safeBins", () => {
|
||||
});
|
||||
const text = result.content.find((content) => content.type === "text")?.text ?? "";
|
||||
|
||||
expect(result.details.status).toBe("completed");
|
||||
const blockedResultDetails = result.details as { status?: string };
|
||||
expect(blockedResultDetails.status).toBe("completed");
|
||||
expect(text).not.toContain(secret);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@ describe("sandboxed workspace paths", () => {
|
||||
sessionKey: "sandbox:test",
|
||||
workspaceDir: sandboxDir,
|
||||
agentWorkspaceDir: workspaceDir,
|
||||
workspaceAccess: "rw",
|
||||
workspaceAccess: "rw" as const,
|
||||
containerName: "openclaw-sbx-test",
|
||||
containerWorkdir: "/workspace",
|
||||
fsBridge: createHostSandboxFsBridge(sandboxDir),
|
||||
|
||||
Reference in New Issue
Block a user