/** * The reserved-namespace predicate, in isolation. * * It is one `startsWith`, but it is the seam that keeps the polyfill's emulated * branches out of the consumer's data (see `machinery.ts`), so its edges are worth * pinning: get it wrong in one direction and machinery leaks into domain properties; * wrong in the other and real data silently disappears from reads. */ import { test, expect } from "bun:test"; import { MACHINERY_NS, isMachinerySubject } from "../src/machinery"; test("the emulated branch subjects are all machinery", () => { // The four compartments store-registry emulates, verbatim. for (const s of [ "urn:ng-eventually:shim:index", "urn:ng-eventually:shim:storeBranch", "urn:ng-eventually:shim:userBranch", "urn:ng-eventually:shim:headerBranch", ]) { expect(isMachinerySubject(s)).toBe(true); } }); test("inbox deposits are machinery too — a second prefix under the same namespace", () => { expect(isMachinerySubject("urn:ng-eventually:inbox:deposit:1700:abc")).toBe(true); }); test("consumer subjects are not machinery — including a NURI, which is what entities use", () => { expect(isMachinerySubject("did:ng:o:doc1")).toBe(false); expect(isMachinerySubject("urn:e2e:secret")).toBe(false); expect(isMachinerySubject("http://example.org/thing")).toBe(false); }); test("a look-alike prefix is NOT machinery — the boundary is exact, not fuzzy", () => { // Anything that merely resembles the namespace must fall on the data side, or a // consumer's own vocabulary could vanish from its reads. expect(isMachinerySubject("urn:ng-eventuallyX:thing")).toBe(false); expect(isMachinerySubject("urn:ng-event:thing")).toBe(false); expect(isMachinerySubject("x-urn:ng-eventually:shim:index")).toBe(false); }); test("an absent subject is not machinery — read paths hand bindings straight in", () => { expect(isMachinerySubject(undefined)).toBe(false); expect(isMachinerySubject("")).toBe(false); }); test("the namespace is the prefix both writers actually use", () => { // Guards against the constant drifting away from store-registry/inbox. expect("urn:ng-eventually:shim".startsWith(MACHINERY_NS)).toBe(true); expect("urn:ng-eventually:inbox".startsWith(MACHINERY_NS)).toBe(true); });