
























@@ -37,6 +37,14 @@ function logLine(params: { module: string; message: string }) {
3737});
3838}
393940+function readJsonPayload() {
41+return JSON.parse(String(runtime.log.mock.calls[0]?.[0])) as {
42+file: string;
43+channel: string;
44+lines: Array<{ message: string }>;
45+};
46+}
47+4048describe("channelsLogsCommand", () => {
4149let tempDir: string;
4250let logPath: string;
@@ -75,11 +83,78 @@ describe("channelsLogsCommand", () => {
7583includeDisabled: true,
7684}),
7785);
78-const payload = JSON.parse(String(runtime.log.mock.calls[0]?.[0])) as {
79-channel: string;
80-lines: Array<{ message: string }>;
81-};
86+const payload = readJsonPayload();
8287expect(payload.channel).toBe("external-chat");
8388expect(payload.lines.map((line) => line.message)).toEqual(["external sent"]);
8489});
90+91+it("falls back to the latest rolling log when the configured rolling file is missing", async () => {
92+const configuredFile = path.join(tempDir, "openclaw-2026-04-26.log");
93+const fallbackFile = path.join(tempDir, "openclaw-2026-04-25.log");
94+const staleFile = path.join(tempDir, "openclaw-2026-04-24.log");
95+setLoggerOverride({ file: configuredFile });
96+await fs.writeFile(
97+fallbackFile,
98+[
99+logLine({ module: "gateway/channels/slack/send", message: "slack fallback" }),
100+logLine({ module: "gateway/channels/external-chat/send", message: "fallback sent" }),
101+].join("\n"),
102+);
103+await fs.writeFile(
104+staleFile,
105+logLine({ module: "gateway/channels/external-chat/send", message: "stale sent" }),
106+);
107+await fs.utimes(
108+staleFile,
109+new Date("2026-04-24T12:00:00.000Z"),
110+new Date("2026-04-24T12:00:00.000Z"),
111+);
112+await fs.utimes(
113+fallbackFile,
114+new Date("2026-04-25T12:00:00.000Z"),
115+new Date("2026-04-25T12:00:00.000Z"),
116+);
117+118+await channelsLogsCommand({ channel: "external-chat", json: true }, runtime);
119+120+const payload = readJsonPayload();
121+expect(payload.file).toBe(fallbackFile);
122+expect(payload.lines.map((line) => line.message)).toEqual(["fallback sent"]);
123+});
124+125+it("prefers the configured rolling log when it exists", async () => {
126+const configuredFile = path.join(tempDir, "openclaw-2026-04-26.log");
127+const fallbackFile = path.join(tempDir, "openclaw-2026-04-25.log");
128+setLoggerOverride({ file: configuredFile });
129+await fs.writeFile(
130+fallbackFile,
131+logLine({ module: "gateway/channels/external-chat/send", message: "fallback sent" }),
132+);
133+await fs.writeFile(
134+configuredFile,
135+logLine({ module: "gateway/channels/external-chat/send", message: "current sent" }),
136+);
137+138+await channelsLogsCommand({ channel: "external-chat", json: true }, runtime);
139+140+const payload = readJsonPayload();
141+expect(payload.file).toBe(configuredFile);
142+expect(payload.lines.map((line) => line.message)).toEqual(["current sent"]);
143+});
144+145+it("does not fall back to rolling logs for a missing custom log file", async () => {
146+const configuredFile = path.join(tempDir, "custom-channel.log");
147+const fallbackFile = path.join(tempDir, "openclaw-2026-04-25.log");
148+setLoggerOverride({ file: configuredFile });
149+await fs.writeFile(
150+fallbackFile,
151+logLine({ module: "gateway/channels/external-chat/send", message: "fallback sent" }),
152+);
153+154+await channelsLogsCommand({ channel: "external-chat", json: true }, runtime);
155+156+const payload = readJsonPayload();
157+expect(payload.file).toBe(configuredFile);
158+expect(payload.lines).toEqual([]);
159+});
85160});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。