



























1+import { beforeEach, describe, expect, it, vi } from "vitest";
2+import type { SubagentRunRecord } from "../../agents/subagent-registry.types.js";
3+import type { OpenClawConfig } from "../../config/config.js";
4+import type { ReplyPayload } from "../types.js";
5+import { handleSubagentsLogAction } from "./commands-subagents/action-log.js";
6+7+const callGatewayMock = vi.hoisted(() => vi.fn());
8+9+vi.mock("../../gateway/call.js", () => ({
10+callGateway: (params: unknown) => callGatewayMock(params),
11+}));
12+13+function makeRun(overrides: Partial<SubagentRunRecord> = {}): SubagentRunRecord {
14+return {
15+runId: "run-subagent-log",
16+childSessionKey: "agent:main:subagent:log",
17+requesterSessionKey: "agent:main:main",
18+requesterDisplayKey: "main",
19+task: "inspect logs",
20+cleanup: "keep",
21+createdAt: Date.now() - 10_000,
22+startedAt: Date.now() - 10_000,
23+ ...overrides,
24+};
25+}
26+27+function buildLogContext(restTokens: string[], runs: SubagentRunRecord[]) {
28+return {
29+params: {
30+cfg: {} as OpenClawConfig,
31+sessionKey: "agent:main:main",
32+},
33+handledPrefix: "/subagents",
34+requesterKey: "agent:main:main",
35+ runs,
36+ restTokens,
37+} as Parameters<typeof handleSubagentsLogAction>[0];
38+}
39+40+function requireReplyText(reply: ReplyPayload | undefined): string {
41+if (reply?.text === undefined) {
42+throw new Error("expected reply text");
43+}
44+return reply.text;
45+}
46+47+beforeEach(() => {
48+callGatewayMock.mockReset();
49+callGatewayMock.mockResolvedValue({
50+messages: [{ role: "assistant", content: "log line" }],
51+});
52+});
53+54+describe("subagents log", () => {
55+it("does not treat a numeric target as the history limit", async () => {
56+const result = await handleSubagentsLogAction(buildLogContext(["1"], [makeRun()]));
57+58+expect(result.shouldContinue).toBe(false);
59+expect(requireReplyText(result.reply)).toContain("log line");
60+expect(callGatewayMock).toHaveBeenCalledWith({
61+method: "chat.history",
62+params: { sessionKey: "agent:main:subagent:log", limit: 20 },
63+});
64+});
65+66+it("uses the numeric token after the target as the history limit", async () => {
67+await handleSubagentsLogAction(buildLogContext(["1", "5"], [makeRun()]));
68+69+expect(callGatewayMock).toHaveBeenCalledWith({
70+method: "chat.history",
71+params: { sessionKey: "agent:main:subagent:log", limit: 5 },
72+});
73+});
74+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。