mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:41:23 +00:00
test(agents): dedupe workspace memory-entry assertions
This commit is contained in:
@@ -103,18 +103,27 @@ describe("ensureAgentWorkspace", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("loadWorkspaceBootstrapFiles", () => {
|
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 () => {
|
it("includes MEMORY.md when present", async () => {
|
||||||
const tempDir = await makeTempWorkspace("openclaw-workspace-");
|
const tempDir = await makeTempWorkspace("openclaw-workspace-");
|
||||||
await writeWorkspaceFile({ dir: tempDir, name: "MEMORY.md", content: "memory" });
|
await writeWorkspaceFile({ dir: tempDir, name: "MEMORY.md", content: "memory" });
|
||||||
|
|
||||||
const files = await loadWorkspaceBootstrapFiles(tempDir);
|
const files = await loadWorkspaceBootstrapFiles(tempDir);
|
||||||
const memoryEntries = files.filter((file) =>
|
expectSingleMemoryEntry(files, "memory");
|
||||||
[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");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("includes memory.md when MEMORY.md is absent", async () => {
|
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" });
|
await writeWorkspaceFile({ dir: tempDir, name: "memory.md", content: "alt" });
|
||||||
|
|
||||||
const files = await loadWorkspaceBootstrapFiles(tempDir);
|
const files = await loadWorkspaceBootstrapFiles(tempDir);
|
||||||
const memoryEntries = files.filter((file) =>
|
expectSingleMemoryEntry(files, "alt");
|
||||||
[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");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("omits memory entries when no memory files exist", async () => {
|
it("omits memory entries when no memory files exist", async () => {
|
||||||
const tempDir = await makeTempWorkspace("openclaw-workspace-");
|
const tempDir = await makeTempWorkspace("openclaw-workspace-");
|
||||||
|
|
||||||
const files = await loadWorkspaceBootstrapFiles(tempDir);
|
const files = await loadWorkspaceBootstrapFiles(tempDir);
|
||||||
const memoryEntries = files.filter((file) =>
|
expect(getMemoryEntries(files)).toHaveLength(0);
|
||||||
[DEFAULT_MEMORY_FILENAME, DEFAULT_MEMORY_ALT_FILENAME].includes(file.name),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(memoryEntries).toHaveLength(0);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user