test(agents): dedupe workspace memory-entry assertions
This commit is contained in:
@@ -103,18 +103,27 @@ describe("ensureAgentWorkspace", () => {
|
||||
});
|
||||
|
||||
describe("loadWorkspaceBootstrapFiles", () => {
|
||||
const getMemoryEntries = (files: Awaited<ReturnType<typeof loadWorkspaceBootstrapFiles>>) =>
|
||||
files.filter((file) =>
|
||||
[DEFAULT_MEMORY_FILENAME, DEFAULT_MEMORY_ALT_FILENAME].includes(file.name),
|
||||
);
|
||||
|
||||
const expectSingleMemoryEntry = (
|
||||
files: Awaited<ReturnType<typeof loadWorkspaceBootstrapFiles>>,
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user