forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-memory-store.test.ts
More file actions
95 lines (81 loc) · 2.84 KB
/
Copy pathfile-memory-store.test.ts
File metadata and controls
95 lines (81 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { existsSync } from "node:fs";
import { rm } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { JsonFileMemoryStore } from "../src/index.js";
describe("JsonFileMemoryStore", () => {
let tempFilePath: string;
beforeEach(() => {
tempFilePath = join(
tmpdir(),
`agentlily-memory-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
"task-history.json"
);
});
afterEach(async () => {
const parentDir = join(tempFilePath, "..");
if (existsSync(parentDir)) {
await rm(parentDir, { recursive: true, force: true });
}
});
it("appends and persists entries to disk", async () => {
const store = new JsonFileMemoryStore(tempFilePath);
expect(store.getFilePath()).toBe(tempFilePath);
await store.append({
agentId: "agent-1",
taskId: "task-1",
input: "Input 1",
output: { result: "Success 1" },
recordedAt: new Date().toISOString()
});
await store.append({
agentId: "agent-1",
taskId: "task-2",
input: "Input 2",
output: { result: "Success 2" },
recordedAt: new Date().toISOString()
});
await store.append({
agentId: "agent-2",
taskId: "task-3",
input: "Input 3",
output: { result: "Success 3" },
recordedAt: new Date().toISOString()
});
expect(existsSync(tempFilePath)).toBe(true);
const agent1Entries = await store.listByAgent("agent-1");
expect(agent1Entries).toHaveLength(2);
expect(agent1Entries[0]?.taskId).toBe("task-1");
expect(agent1Entries[1]?.taskId).toBe("task-2");
const agent2Entries = await store.listByAgent("agent-2");
expect(agent2Entries).toHaveLength(1);
expect(agent2Entries[0]?.taskId).toBe("task-3");
});
it("retains entries across separate store instances sharing the same file path", async () => {
const initialStore = new JsonFileMemoryStore(tempFilePath);
await initialStore.append({
agentId: "agent-persist",
taskId: "task-p1",
input: "Durable Input",
output: { status: "persisted" },
recordedAt: "2026-08-30T12:00:00.000Z"
});
const secondStoreInstance = new JsonFileMemoryStore(tempFilePath);
const loadedEntries =
await secondStoreInstance.listByAgent("agent-persist");
expect(loadedEntries).toHaveLength(1);
expect(loadedEntries[0]).toEqual({
agentId: "agent-persist",
taskId: "task-p1",
input: "Durable Input",
output: { status: "persisted" },
recordedAt: "2026-08-30T12:00:00.000Z"
});
});
it("returns empty list when file does not exist yet", async () => {
const store = new JsonFileMemoryStore(tempFilePath);
const entries = await store.listByAgent("nonexistent-agent");
expect(entries).toEqual([]);
});
});