chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
32
third_party/pi/packages/durable/test/memory-storage.test.ts
vendored
Normal file
32
third_party/pi/packages/durable/test/memory-storage.test.ts
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
||||
import { registerStorageConformance } from "@earendil-works/pi-durable/testing";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { idFromNumber, seqFromNumber } from "../src/ids.ts";
|
||||
import { MemoryStorage } from "../src/storage/memory.ts";
|
||||
import { type EntryId, ROOT_CONVERSATION_ID } from "../src/types.ts";
|
||||
|
||||
registerStorageConformance({ describe, expect, it }, "MemoryStorage", (use) => use(new MemoryStorage()));
|
||||
|
||||
it("does not expose retained state through a prepared commit", async () => {
|
||||
const storage = new MemoryStorage();
|
||||
await storage.commit([{ type: "conversation", value: { id: ROOT_CONVERSATION_ID } }], BACKGROUND_CONTEXT);
|
||||
const entryId = idFromNumber<EntryId>(2);
|
||||
const prepared = storage.prepareCommit([
|
||||
{
|
||||
type: "entry",
|
||||
value: {
|
||||
id: entryId,
|
||||
conversationId: ROOT_CONVERSATION_ID,
|
||||
kind: "test",
|
||||
data: { nested: [1] },
|
||||
},
|
||||
},
|
||||
]);
|
||||
const exposed = prepared.writes[0];
|
||||
if (exposed.type !== "entry") throw new Error("Expected an entry write");
|
||||
expect(() => (exposed.value.data as { nested: number[] }).nested.push(2)).toThrow();
|
||||
|
||||
expect(prepared.apply()).toBe(seqFromNumber(2));
|
||||
expect(prepared.apply()).toBe(seqFromNumber(2));
|
||||
expect((await storage.entry(entryId, BACKGROUND_CONTEXT))?.entry.data).toEqual({ nested: [1] });
|
||||
});
|
||||
Reference in New Issue
Block a user