




















@@ -126,6 +126,33 @@ function makeParams(): HandleCommandsParams {
126126} as unknown as HandleCommandsParams;
127127}
128128129+function writeFileArg(callIndex: number, argIndex: number): unknown {
130+const call = hoisted.writeFileMock.mock.calls.at(callIndex);
131+if (!call) {
132+throw new Error(`Expected writeFile call ${callIndex}`);
133+}
134+if (!(argIndex in call)) {
135+throw new Error(`Expected writeFile call ${callIndex} argument ${argIndex}`);
136+}
137+return call[argIndex];
138+}
139+140+function writeFilePath(callIndex: number): string {
141+const value = writeFileArg(callIndex, 0);
142+if (typeof value !== "string") {
143+throw new Error(`Expected writeFile call ${callIndex} path`);
144+}
145+return value;
146+}
147+148+function writtenHtml(): string {
149+const value = writeFileArg(0, 1);
150+if (typeof value !== "string") {
151+throw new Error("Expected exported HTML");
152+}
153+return value;
154+}
155+129156describe("buildExportSessionReply", () => {
130157afterEach(() => {
131158vi.useRealTimers();
@@ -213,8 +240,7 @@ describe("buildExportSessionReply", () => {
213240it("injects scripts and session data through the real export template", async () => {
214241await buildExportSessionReply(makeParams());
215242216-const html = hoisted.writeFileMock.mock.calls[0]?.[1];
217-expect(typeof html).toBe("string");
243+const html = writtenHtml();
218244expect(html).not.toContain("{{CSS}}");
219245expect(html).not.toContain("{{JS}}");
220246expect(html).not.toContain("{{SESSION_DATA}}");
@@ -251,12 +277,12 @@ describe("buildExportSessionReply", () => {
251277"/tmp/workspace",
252278"openclaw-session-session--2026-05-05T10-11-12-2.html",
253279);
254-expect(hoisted.writeFileMock.mock.calls[0]?.[0]).toBe(expectedBase);
255-expect(hoisted.writeFileMock.mock.calls[0]?.[2]).toEqual({
280+expect(writeFilePath(0)).toBe(expectedBase);
281+expect(writeFileArg(0, 2)).toEqual({
256282encoding: "utf-8",
257283flag: "wx",
258284});
259-expect(hoisted.writeFileMock.mock.calls[1]?.[0]).toBe(expectedSuffix);
285+expect(writeFilePath(1)).toBe(expectedSuffix);
260286expect(reply.text).toContain("📄 File: openclaw-session-session--2026-05-05T10-11-12-2.html");
261287});
262288@@ -281,7 +307,7 @@ describe("buildExportSessionReply", () => {
281307282308await buildExportSessionReply(makeParams());
283309284-const html = hoisted.writeFileMock.mock.calls[0]?.[1];
310+const html = writtenHtml();
285311expect(html).toContain("$&$1");
286312expect(html).toContain("const marker = '$&$1';");
287313expect(html).toContain("const markedMarker = '$&$1';");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。