forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-state-store.test.ts
More file actions
51 lines (45 loc) · 1.87 KB
/
Copy pathruntime-state-store.test.ts
File metadata and controls
51 lines (45 loc) · 1.87 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
import { describe, it, expect } from "vitest";
import { InMemoryRuntimeStateStore } from "../../src/state/runtime-state.js";
describe("InMemoryRuntimeStateStore put/get round trips", () => {
it("stores and retrieves a string value", async () => {
const store = new InMemoryRuntimeStateStore();
await store.put("key1", "value1");
const result = await store.get<string>("key1");
expect(result).toBe("value1");
});
it("stores and retrieves an object value", async () => {
const store = new InMemoryRuntimeStateStore();
const obj = { taskId: "t1", status: "running" };
await store.put("taskState", obj);
const result = await store.get<typeof obj>("taskState");
expect(result).toEqual(obj);
});
it("returns undefined for non-existent keys", async () => {
const store = new InMemoryRuntimeStateStore();
const result = await store.get("missing");
expect(result).toBeUndefined();
});
it("overwrites existing values on subsequent puts", async () => {
const store = new InMemoryRuntimeStateStore();
await store.put("counter", 1);
await store.put("counter", 2);
const result = await store.get<number>("counter");
expect(result).toBe(2);
});
it("handles null and zero as valid stored values", async () => {
const store = new InMemoryRuntimeStateStore();
await store.put("nullVal", null);
await store.put("zeroVal", 0);
expect(await store.get("nullVal")).toBeNull();
expect(await store.get("zeroVal")).toBe(0);
});
it("isolates keys across multiple put operations", async () => {
const store = new InMemoryRuntimeStateStore();
await store.put("a", "alpha");
await store.put("b", "beta");
await store.put("c", "gamma");
expect(await store.get<string>("a")).toBe("alpha");
expect(await store.get<string>("b")).toBe("beta");
expect(await store.get<string>("c")).toBe("gamma");
});
});