mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 20:21:23 +00:00
cron: infer payload kind for model-only update patches (openclaw#15664) thanks @rodrigouroz
Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm check (fails on current origin/main in src/memory/embedding-manager.test-harness.ts; unchanged by this PR) Co-authored-by: rodrigouroz <384037+rodrigouroz@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
71
src/agents/pi-embedded-subscribe.handlers.tools.test.ts
Normal file
71
src/agents/pi-embedded-subscribe.handlers.tools.test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { handleToolExecutionStart } from "./pi-embedded-subscribe.handlers.tools.js";
|
||||
|
||||
function createTestContext() {
|
||||
const onBlockReplyFlush = vi.fn();
|
||||
const warn = vi.fn();
|
||||
const ctx = {
|
||||
params: {
|
||||
runId: "run-test",
|
||||
onBlockReplyFlush,
|
||||
onAgentEvent: undefined,
|
||||
onToolResult: undefined,
|
||||
},
|
||||
flushBlockReplyBuffer: vi.fn(),
|
||||
hookRunner: undefined,
|
||||
log: {
|
||||
debug: vi.fn(),
|
||||
warn,
|
||||
},
|
||||
state: {
|
||||
toolMetaById: new Map<string, string | undefined>(),
|
||||
toolSummaryById: new Set<string>(),
|
||||
pendingMessagingTargets: new Map<string, unknown>(),
|
||||
pendingMessagingTexts: new Map<string, string>(),
|
||||
messagingToolSentTexts: [],
|
||||
messagingToolSentTextsNormalized: [],
|
||||
messagingToolSentTargets: [],
|
||||
},
|
||||
shouldEmitToolResult: () => false,
|
||||
emitToolSummary: vi.fn(),
|
||||
trimMessagingToolSent: vi.fn(),
|
||||
} as const;
|
||||
|
||||
return { ctx, warn, onBlockReplyFlush };
|
||||
}
|
||||
|
||||
describe("handleToolExecutionStart read path checks", () => {
|
||||
it("does not warn when read tool uses file_path alias", async () => {
|
||||
const { ctx, warn, onBlockReplyFlush } = createTestContext();
|
||||
|
||||
await handleToolExecutionStart(
|
||||
ctx as never,
|
||||
{
|
||||
type: "tool_execution_start",
|
||||
toolName: "read",
|
||||
toolCallId: "tool-1",
|
||||
args: { file_path: "/tmp/example.txt" },
|
||||
} as never,
|
||||
);
|
||||
|
||||
expect(onBlockReplyFlush).toHaveBeenCalledTimes(1);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("warns when read tool has neither path nor file_path", async () => {
|
||||
const { ctx, warn } = createTestContext();
|
||||
|
||||
await handleToolExecutionStart(
|
||||
ctx as never,
|
||||
{
|
||||
type: "tool_execution_start",
|
||||
toolName: "read",
|
||||
toolCallId: "tool-2",
|
||||
args: {},
|
||||
} as never,
|
||||
);
|
||||
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
expect(String(warn.mock.calls[0]?.[0] ?? "")).toContain("read tool called without path");
|
||||
});
|
||||
});
|
||||
@@ -75,12 +75,13 @@ export async function handleToolExecutionStart(
|
||||
|
||||
if (toolName === "read") {
|
||||
const record = args && typeof args === "object" ? (args as Record<string, unknown>) : {};
|
||||
const filePath =
|
||||
const filePathValue =
|
||||
typeof record.path === "string"
|
||||
? record.path.trim()
|
||||
? record.path
|
||||
: typeof record.file_path === "string"
|
||||
? record.file_path.trim()
|
||||
? record.file_path
|
||||
: "";
|
||||
const filePath = filePathValue.trim();
|
||||
if (!filePath) {
|
||||
const argsPreview = typeof args === "string" ? args.slice(0, 200) : undefined;
|
||||
ctx.log.warn(
|
||||
|
||||
Reference in New Issue
Block a user