pi-mono/packages/chord/test/next/store/allocator.test.ts
Mario Zechner 14b4c56e57 feat(chord,durable): Chord v2 slice 6b, Durable and jobs on the store
StoreStorage (Durable's storage on Chord v2's store, @earendil-works/pi-durable/storage/store) passes
Durable's storage conformance suite and runs Durable's harness tests (npm run test:store). The store
gets owner names and claims, one id allocator, Durable's Storage semantics for refused steps, history
none/latest/rewindable with reads at a point, archive revisions and applyBatch. self.follow follows
Durable's synchronous observers as Chord sources. Persisted jobs: records and state in the owner's
store, restarts as Durable's tasks, abort stored, deferred state. Chord's ./next export returns for
the adapter surface.
2026-10-28 19:18:30 +00:00

24 lines
1,010 B
TypeScript

// Tests of the id allocator (slice 6b D3, §1.2): from 2, raised by explicit ids, saturating at the safe range.
import { describe, expect, it } from "vitest";
import { FIRST_ID, IdAllocator } from "../../../src/next/store/allocator.ts";
describe("the allocator", () => {
it("mints from its value, and an explicit id raises it above itself, never lowering it", () => {
const ids = new IdAllocator(FIRST_ID);
expect([ids.mint(), ids.mint()]).toEqual([2, 3]);
ids.raise(100);
expect(ids.mint()).toBe(101);
ids.raise(50);
expect(ids.value).toBe(102);
});
it("saturates at Number.MAX_SAFE_INTEGER: that id may be written, every later mint is refused", () => {
const ids = new IdAllocator(Number.MAX_SAFE_INTEGER - 1);
expect(ids.mint()).toBe(Number.MAX_SAFE_INTEGER - 1);
expect(() => ids.mint()).toThrow("ID space is exhausted");
ids.raise(Number.MAX_SAFE_INTEGER);
expect(ids.value).toBe(Number.MAX_SAFE_INTEGER);
expect(() => ids.mint()).toThrow("ID space is exhausted");
});
});