Squashed 'third_party/pi/' content from commit d981de122
git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
This commit is contained in:
36
packages/agent/test/harness/memory-storage.test.ts
Normal file
36
packages/agent/test/harness/memory-storage.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { BACKGROUND_CONTEXT } from "../../src/harness/context.ts";
|
||||
import * as sessionWrites from "../../src/harness/session/commit.ts";
|
||||
import { MemoryStorage } from "../../src/harness/session/memory.ts";
|
||||
import * as storedValues from "../../src/harness/session/values.ts";
|
||||
|
||||
const NOW = 1_700_000_000_000;
|
||||
|
||||
describe("MemoryStorage", () => {
|
||||
it("uses the injected clock once per transaction", async () => {
|
||||
let timestamp = NOW;
|
||||
const storage = new MemoryStorage({ now: () => timestamp++ });
|
||||
|
||||
const first = await storage.commit(
|
||||
[
|
||||
sessionWrites.insertEntry({
|
||||
id: "first",
|
||||
parentId: null,
|
||||
type: "custom",
|
||||
customType: "note",
|
||||
}),
|
||||
storedValues.setValue(storedValues.sessionName, "first"),
|
||||
],
|
||||
BACKGROUND_CONTEXT,
|
||||
);
|
||||
const second = await storage.commit(
|
||||
[storedValues.setValue(storedValues.sessionName, "second")],
|
||||
BACKGROUND_CONTEXT,
|
||||
);
|
||||
|
||||
expect(first.timestamp).toBe(NOW);
|
||||
expect(second.timestamp).toBe(NOW + 1);
|
||||
expect((await storage.getEntries(["first"], BACKGROUND_CONTEXT)).get("first")?.timestamp).toBe(first.timestamp);
|
||||
await storage.close(BACKGROUND_CONTEXT);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user