diff --git a/src/agents/workspace.e2e.test.ts b/src/agents/workspace.e2e.test.ts index 085afbcb39b..2fef954c1f7 100644 --- a/src/agents/workspace.e2e.test.ts +++ b/src/agents/workspace.e2e.test.ts @@ -103,18 +103,27 @@ describe("ensureAgentWorkspace", () => { }); describe("loadWorkspaceBootstrapFiles", () => { + const getMemoryEntries = (files: Awaited>) => + files.filter((file) => + [DEFAULT_MEMORY_FILENAME, DEFAULT_MEMORY_ALT_FILENAME].includes(file.name), + ); + + const expectSingleMemoryEntry = ( + files: Awaited>, + content: string, + ) => { + const memoryEntries = getMemoryEntries(files); + expect(memoryEntries).toHaveLength(1); + expect(memoryEntries[0]?.missing).toBe(false); + expect(memoryEntries[0]?.content).toBe(content); + }; + it("includes MEMORY.md when present", async () => { const tempDir = await makeTempWorkspace("openclaw-workspace-"); await writeWorkspaceFile({ dir: tempDir, name: "MEMORY.md", content: "memory" }); const files = await loadWorkspaceBootstrapFiles(tempDir); - const memoryEntries = files.filter((file) => - [DEFAULT_MEMORY_FILENAME, DEFAULT_MEMORY_ALT_FILENAME].includes(file.name), - ); - - expect(memoryEntries).toHaveLength(1); - expect(memoryEntries[0]?.missing).toBe(false); - expect(memoryEntries[0]?.content).toBe("memory"); + expectSingleMemoryEntry(files, "memory"); }); it("includes memory.md when MEMORY.md is absent", async () => { @@ -122,23 +131,13 @@ describe("loadWorkspaceBootstrapFiles", () => { await writeWorkspaceFile({ dir: tempDir, name: "memory.md", content: "alt" }); const files = await loadWorkspaceBootstrapFiles(tempDir); - const memoryEntries = files.filter((file) => - [DEFAULT_MEMORY_FILENAME, DEFAULT_MEMORY_ALT_FILENAME].includes(file.name), - ); - - expect(memoryEntries).toHaveLength(1); - expect(memoryEntries[0]?.missing).toBe(false); - expect(memoryEntries[0]?.content).toBe("alt"); + expectSingleMemoryEntry(files, "alt"); }); it("omits memory entries when no memory files exist", async () => { const tempDir = await makeTempWorkspace("openclaw-workspace-"); const files = await loadWorkspaceBootstrapFiles(tempDir); - const memoryEntries = files.filter((file) => - [DEFAULT_MEMORY_FILENAME, DEFAULT_MEMORY_ALT_FILENAME].includes(file.name), - ); - - expect(memoryEntries).toHaveLength(0); + expect(getMemoryEntries(files)).toHaveLength(0); }); });