@semiont/core 0.5.10 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/state-unit-axioms.ts"],"names":[],"mappings":";;;;AAwCO,SAAS,YAAA,GAA6B;AAC3C,EAAA,IAAI,CAAA,GAAI,CAAA;AACR,EAAA,OAAO;AAAA,IACL,OAAA,GAAU;AAAE,MAAA,CAAA,IAAK,CAAA;AAAA,IAAG,CAAA;AAAA,IACpB,IAAI,YAAA,GAAe;AAAE,MAAA,OAAO,CAAA;AAAA,IAAG;AAAA,GACjC;AACF;AA8BA,SAAS,UAA+B,CAAA,EAAkC;AACxE,EAAA,IAAI,CAAA,IAAK,OAAO,CAAA,KAAM,QAAA,IAAY,UAAU,CAAA,EAAG;AAC7C,IAAA,OAAO,EAAE,IAAA,EAAM,CAAA,CAAE,IAAA,EAAM,QAAA,EAAU,CAAA,CAAE,QAAA,IAAY,EAAC,EAAG,QAAA,EAAU,CAAA,CAAE,QAAA,KAAa,MAAM;AAAA,IAAC,CAAA,CAAA,EAAG;AAAA,EACxF;AACA,EAAA,OAAO,EAAE,IAAA,EAAM,CAAA,EAAQ,UAAU,EAAC,EAAG,UAAU,MAAM;AAAA,EAAC,CAAA,EAAE;AAC1D;AAEA,SAAS,aAAa,KAAA,EAAsB;AAC1C,EAAA,IAAI,SAAS,OAAO,KAAA,KAAU,YAAY,OAAQ,KAAA,CAA6B,SAAS,UAAA,EAAY;AAClG,IAAC,KAAA,CAA2B,IAAA,CAAK,MAAA,EAAW,MAAM;AAAA,IAAC,CAAC,CAAA;AAAA,EACtD;AACF;AAOO,SAAS,sBAA2C,IAAA,EAAmC;AAC5F,EAAA,MAAM,OAAA,GAAU,KAAK,OAAA,IAAW,EAAA;AAChC,EAAA,MAAM,KAAA,GAAQ,MAAqB,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAKzD,EAAA,MAAM,GAAA,GA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I,KAAA,CAAM,CAAA,+BAAA,EAAkC,CAAC,CAAA,kCAAA,CAAoC,CAAA;AAAA,IACpG,CAAC,CAAA;AACD,IAAA,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAA,KAAM,CAAA,CAAE,aAAa,CAAA;AACnC,IAAA,QAAA,EAAS;AAAA,EACX;AAGA,EAAA,IAAI,KAAK,QAAA,EAAU;AACjB,IAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAS,GAAI,KAAA,EAAM;AACjC,IAAA,IAAA,CAAK,OAAA,EAAQ;AACb,IAAA,IAAA,CAAK,SAAS,IAAI,CAAA,CAAE,OAAA,CAAQ,CAAC,GAAG,CAAA,KAAM;AACpC,MAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,MAAA,IAAI,IAAA,GAAO,KAAA;AACX,MAAA,CAAA,CAAE,SAAA,CAAU,EAAE,IAAA,EAAM,MAAM;AAAE,QAAA,KAAA,IAAS,CAAA;AAAA,MAAG,CAAA,EAAG,UAAU,MAAM;AAAE,QAAA,IAAA,GAAO,IAAA;AAAA,MAAM,CAAA,EAAG,CAAA,CAAE,WAAA,EAAY;AAC3F,MAAA,IAAI,QAAQ,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,CAAA,0BAAA,EAA6B,CAAC,CAAA,8BAAA,CAAgC,CAAA;AAC7F,MAAA,IAAI,CAAC,IAAA,EAAM,MAAM,IAAI,KAAA,CAAM,CAAA,0BAAA,EAA6B,CAAC,CAAA,+BAAA,CAAiC,CAAA;AAAA,IAC5F,CAAC,CAAA;AACD,IAAA,QAAA,EAAS;AAAA,EACX;AACF","file":"testing.js","sourcesContent":["/**\n * Executable enforcement of the StateUnit pattern — the runtime twin of\n * `packages/sdk/docs/STATE-UNITS.md` and the ledger in\n * `.plans/STATE-UNIT-AXIOMS.md`. The `StateUnit` interface's own comment notes\n * the pattern is convention; this file makes it executable.\n *\n * `assertStateUnitAxioms(spec)` runs every applicable axiom against a factory in\n * one shot, throwing a labeled Error on the first violation (the axiom id is in\n * the message). It is framework-agnostic on purpose — only `rxjs` + `fast-check`,\n * no `vitest` — so it ships through `@semiont/core/testing` and any package's test\n * runner can invoke it from a single `it(...)` per state unit. It lives in core\n * (not sdk) so even packages below sdk (e.g. `http-transport`) can use it without\n * a dependency cycle.\n *\n * Axioms (random-input dimension; fast-check):\n * A5 dispose() is idempotent and total (n ∈ [1,20] calls never throw)\n * A5b post-dispose inertness — every public method is a no-op after dispose\n * A6 every pre-dispose subscriber (k ∈ [1,10]) sees `complete` on dispose\n * X3-runtime instance isolation — driving one instance never moves another's surfaces\n * Structural assertions (single-shot):\n * A1 plain-object identity (no class instance)\n * X1 no raw Subject on the public surface\n * A7-passed disposing the unit must NOT dispose an injected dependency\n * A7-owned disposing the unit MUST dispose its internally-constructed children\n */\n\nimport * as fc from 'fast-check';\nimport { Subject, type Observable } from 'rxjs';\nimport type { StateUnit } from './state-unit';\n\n/**\n * A disposable stand-in for an injected dependency. Pass one as a unit's\n * constructor arg, then list it in `setup().passedIn` so A7-passed can assert\n * the unit never disposed it. Counts calls so A7-passed also holds under the\n * repeated-dispose stress of A5.\n */\nexport interface DisposeProbe extends StateUnit {\n readonly disposeCount: number;\n}\n\nexport function disposeProbe(): DisposeProbe {\n let n = 0;\n return {\n dispose() { n += 1; },\n get disposeCount() { return n; },\n };\n}\n\ntype SetupResult<T extends StateUnit> =\n | T\n | { unit: T; passedIn?: readonly DisposeProbe[]; teardown?: () => void };\n\nexport interface StateUnitAxiomSpec<T extends StateUnit> {\n /**\n * Build a FRESH unit. Called many times (fast-check re-runs), so it must\n * return an independent instance each call. Return the bare unit, or an object\n * carrying the injected `passedIn` probes (A7-passed) and a `teardown` to\n * release per-instance resources (e.g. a mock bus).\n */\n setup: () => SetupResult<T>;\n /** Owned public Observables — Subjects the unit completes on dispose (A6, X3, post-dispose inertness). */\n surfaces?: (unit: T) => readonly Observable<unknown>[];\n /** Public input methods as zero-arg callers (A5b post-dispose, X3 drive). */\n invocations?: (unit: T) => readonly (() => unknown)[];\n /** Surfaces of internally-constructed children — must complete when the outer disposes (A7-owned). */\n ownedChildSurfaces?: (unit: T) => readonly Observable<unknown>[];\n /** fast-check run budget per property (default 30). */\n numRuns?: number;\n}\n\ninterface Normalized<T extends StateUnit> {\n unit: T;\n passedIn: readonly DisposeProbe[];\n teardown: () => void;\n}\n\nfunction normalize<T extends StateUnit>(r: SetupResult<T>): Normalized<T> {\n if (r && typeof r === 'object' && 'unit' in r) {\n return { unit: r.unit, passedIn: r.passedIn ?? [], teardown: r.teardown ?? (() => {}) };\n }\n return { unit: r as T, passedIn: [], teardown: () => {} };\n}\n\nfunction swallowAsync(value: unknown): void {\n if (value && typeof value === 'object' && typeof (value as { then?: unknown }).then === 'function') {\n (value as Promise<unknown>).then(undefined, () => {});\n }\n}\n\n/**\n * Run every applicable axiom against `spec`. Throws a labeled Error on the first\n * violation. Axioms whose accessors are omitted are skipped (e.g. A7-passed\n * runs only when `setup` returns `passedIn`; A6 only when `surfaces` is given).\n */\nexport function assertStateUnitAxioms<T extends StateUnit>(spec: StateUnitAxiomSpec<T>): void {\n const numRuns = spec.numRuns ?? 30;\n const fresh = (): Normalized<T> => normalize(spec.setup());\n\n // fast-check's default falsification message is just \"Property failed after N\n // tests {seed}\" — it drops the thrown axiom id. Prepend the axiom so a real\n // failure names itself; the seed/shrink detail is preserved.\n const run = (axiom: string, prop: Parameters<typeof fc.assert>[0]): void => {\n try {\n fc.assert(prop, { numRuns });\n } catch (e) {\n throw new Error(`${axiom}: ${e instanceof Error ? e.message : String(e)}`);\n }\n };\n\n // A1 — plain-object identity (no class instance).\n {\n const { unit, teardown } = fresh();\n const proto = Object.getPrototypeOf(unit);\n if (proto !== Object.prototype && proto !== null) {\n throw new Error('A1: state unit is not a plain object (has a class prototype)');\n }\n unit.dispose();\n teardown();\n }\n\n // X1 — no raw *origin* Subject on the public surface (expose `.asObservable()`).\n // Flag only origin Subjects — `new Subject` / `new BehaviorSubject`, the unit's own\n // state, where `.source` is undefined. Derived `AnonymousSubject`s from `Subject.lift`\n // (`shareReplay().pipe(...)`) carry a `.source` and are inert sinks (`.next()` does\n // nothing useful) — idiomatic, not the forgotten-internal-Subject smell — so exclude them.\n {\n const { unit, teardown } = fresh();\n for (const [key, value] of Object.entries(unit)) {\n if (value instanceof Subject && (value as { source?: unknown }).source === undefined) {\n throw new Error(`X1: public field \"${key}\" is a raw Subject — expose it via .asObservable()`);\n }\n }\n unit.dispose();\n teardown();\n }\n\n // A7-passed — disposing the unit must NOT dispose an injected dependency.\n {\n const { unit, passedIn, teardown } = fresh();\n unit.dispose();\n passedIn.forEach((probe, i) => {\n if (probe.disposeCount > 0) {\n throw new Error(`A7-passed: the unit disposed injected dependency #${i} (it doesn't own it)`);\n }\n });\n teardown();\n }\n\n // A5 — dispose() idempotent & total: n calls never throw; injected deps stay untouched.\n run('A5', fc.property(fc.integer({ min: 1, max: 20 }), (n) => {\n const { unit, passedIn, teardown } = fresh();\n for (let i = 0; i < n; i++) unit.dispose();\n passedIn.forEach((probe, i) => {\n if (probe.disposeCount > 0) {\n throw new Error(`injected dependency #${i} disposed under ${n} dispose() calls`);\n }\n });\n teardown();\n }));\n\n // A6 — k pre-dispose subscribers on each owned surface all see `complete` on dispose.\n if (spec.surfaces) {\n const surfaces = spec.surfaces;\n run('A6', fc.property(fc.integer({ min: 1, max: 10 }), (k) => {\n const { unit, teardown } = fresh();\n const completed: boolean[] = [];\n const subs = surfaces(unit).flatMap((o) =>\n Array.from({ length: k }, () => {\n const idx = completed.push(false) - 1;\n return o.subscribe({ complete: () => { completed[idx] = true; } });\n }),\n );\n unit.dispose();\n completed.forEach((seen, idx) => {\n if (!seen) throw new Error(`a subscriber did not see complete on dispose (k=${k}, sub #${idx})`);\n });\n subs.forEach((s) => s.unsubscribe());\n teardown();\n }));\n }\n\n // A5b — post-dispose inertness: every public method is a no-op (no throw) after dispose.\n if (spec.invocations) {\n const invocations = spec.invocations;\n run('A5b', fc.property(fc.array(fc.nat(), { maxLength: 12 }), (seq) => {\n const { unit, teardown } = fresh();\n const callers = invocations(unit);\n unit.dispose();\n for (const raw of seq) {\n if (callers.length === 0) break;\n swallowAsync(callers[raw % callers.length]());\n }\n teardown();\n }));\n }\n\n // X3-runtime — instance isolation: driving instance A never moves instance B's surfaces.\n if (spec.surfaces && spec.invocations) {\n const surfaces = spec.surfaces;\n const invocations = spec.invocations;\n run('X3-runtime', fc.property(fc.array(fc.nat(), { minLength: 1, maxLength: 8 }), (seq) => {\n const a = fresh();\n const b = fresh();\n const bSurfaces = surfaces(b.unit);\n const bCounts = bSurfaces.map(() => 0);\n const bSubs = bSurfaces.map((o, i) => o.subscribe(() => { bCounts[i] += 1; }));\n const baseline = bCounts.slice(); // initial replay captured synchronously above\n const aCallers = invocations(a.unit);\n for (const raw of seq) {\n if (aCallers.length === 0) break;\n swallowAsync(aCallers[raw % aCallers.length]());\n }\n bCounts.forEach((count, i) => {\n if (count !== baseline[i]) {\n throw new Error(`driving instance A perturbed instance B's surface #${i}`);\n }\n });\n bSubs.forEach((s) => s.unsubscribe());\n a.unit.dispose();\n b.unit.dispose();\n a.teardown();\n b.teardown();\n }));\n }\n\n // A7-owned — internally-constructed children are disposed (their surfaces complete) on outer dispose.\n if (spec.ownedChildSurfaces) {\n const { unit, teardown } = fresh();\n const childSurfaces = spec.ownedChildSurfaces(unit);\n const completed = childSurfaces.map(() => false);\n const subs = childSurfaces.map((o, i) => o.subscribe({ complete: () => { completed[i] = true; } }));\n unit.dispose();\n completed.forEach((seen, i) => {\n if (!seen) throw new Error(`A7-owned: owned child surface #${i} did not complete on outer dispose`);\n });\n subs.forEach((s) => s.unsubscribe());\n teardown();\n }\n\n // Post-dispose surface inertness: a NEW subscription after dispose completes with no `next`.\n if (spec.surfaces) {\n const { unit, teardown } = fresh();\n unit.dispose();\n spec.surfaces(unit).forEach((o, i) => {\n let nexts = 0;\n let done = false;\n o.subscribe({ next: () => { nexts += 1; }, complete: () => { done = true; } }).unsubscribe();\n if (nexts > 0) throw new Error(`A5b/inert: owned surface #${i} emitted a value after dispose`);\n if (!done) throw new Error(`A5b/inert: owned surface #${i} did not complete after dispose`);\n });\n teardown();\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/state-unit-axioms.ts","../src/branded-types.ts","../src/bus-operations.ts","../src/bridged-channels.ts","../src/bus-log.ts","../src/event-bus.ts","../src/faulty-transport.ts","../src/liveness-axioms.ts"],"names":["fc","Subject"],"mappings":";;;;AAwCO,SAAS,YAAA,GAA6B;AAC3C,EAAA,IAAI,CAAA,GAAI,CAAA;AACR,EAAA,OAAO;AAAA,IACL,OAAA,GAAU;AAAE,MAAA,CAAA,IAAK,CAAA;AAAA,IAAG,CAAA;AAAA,IACpB,IAAI,YAAA,GAAe;AAAE,MAAA,OAAO,CAAA;AAAA,IAAG;AAAA,GACjC;AACF;AA8BA,SAAS,UAA+B,CAAA,EAAkC;AACxE,EAAA,IAAI,CAAA,IAAK,OAAO,CAAA,KAAM,QAAA,IAAY,UAAU,CAAA,EAAG;AAC7C,IAAA,OAAO,EAAE,IAAA,EAAM,CAAA,CAAE,IAAA,EAAM,QAAA,EAAU,CAAA,CAAE,QAAA,IAAY,EAAC,EAAG,QAAA,EAAU,CAAA,CAAE,QAAA,KAAa,MAAM;AAAA,IAAC,CAAA,CAAA,EAAG;AAAA,EACxF;AACA,EAAA,OAAO,EAAE,IAAA,EAAM,CAAA,EAAQ,UAAU,EAAC,EAAG,UAAU,MAAM;AAAA,EAAC,CAAA,EAAE;AAC1D;AAEA,SAAS,aAAa,KAAA,EAAsB;AAC1C,EAAA,IAAI,SAAS,OAAO,KAAA,KAAU,YAAY,OAAQ,KAAA,CAA6B,SAAS,UAAA,EAAY;AAClG,IAAC,KAAA,CAA2B,IAAA,CAAK,MAAA,EAAW,MAAM;AAAA,IAAC,CAAC,CAAA;AAAA,EACtD;AACF;AAOO,SAAS,sBAA2C,IAAA,EAAmC;AAC5F,EAAA,MAAM,OAAA,GAAU,KAAK,OAAA,IAAW,EAAA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AK,KAAA,CAAM,CAAC,CAAA,CAAA;AAEpC,UAAA,SAAA,CAAU,MAAM,MAAM;AACpB,YAAA,KAAA,MAAW,MAAM,OAAA,EAAS;AACxB,cAAA,MAAM,IAAI,SAAA,CAAU,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,KAAM,EAAE,CAAA,CAAE,MAAA;AAC5C,cAAA,IAAI,MAAM,CAAA,EAAG;AACX,gBAAA,MAAM,IAAI,KAAA;AAAA,kBACR,mBAAc,EAAE,CAAA,qCAAA,EAA8B,GAAA,CAAI,IAAA,CAAK,GAAG,CAAC,CAAA,wEAAA;AAAA,iBAE7D;AAAA,cACF;AACA,cAAA,IAAI,IAAI,CAAA,EAAG;AACT,gBAAA,MAAM,IAAI,KAAA;AAAA,kBACR,CAAA,gBAAA,EAAc,EAAE,CAAA,iBAAA,EAAe,CAAC,sBAAiB,GAAA,CAAI,IAAA,CAAK,GAAG,CAAC,CAAA,gCAAA;AAAA,iBAChE;AAAA,cACF;AAAA,YACF;AAAA,UACF,CAAC,CAAA;AAAA,QACH,CAAA,SAAE;AACA,UAAA,GAAA,CAAI,WAAA,EAAY;AAChB,UAAA,OAAA,CAAQ,QAAA,IAAW;AAAA,QACrB;AAAA,MACF,CAAC,CAAA;AAAA,MACD,EAAE,OAAA,EAAS,IAAA,CAAK,OAAA,IAAW,EAAA;AAAG;AAChC,GACF;AACF","file":"testing.js","sourcesContent":["/**\n * Executable enforcement of the StateUnit pattern — the runtime twin of\n * `packages/sdk/docs/STATE-UNITS.md` and the ledger in\n * `.plans/STATE-UNIT-AXIOMS.md`. The `StateUnit` interface's own comment notes\n * the pattern is convention; this file makes it executable.\n *\n * `assertStateUnitAxioms(spec)` runs every applicable axiom against a factory in\n * one shot, throwing a labeled Error on the first violation (the axiom id is in\n * the message). It is framework-agnostic on purpose — only `rxjs` + `fast-check`,\n * no `vitest` — so it ships through `@semiont/core/testing` and any package's test\n * runner can invoke it from a single `it(...)` per state unit. It lives in core\n * (not sdk) so even packages below sdk (e.g. `http-transport`) can use it without\n * a dependency cycle.\n *\n * Axioms (random-input dimension; fast-check):\n * A5 dispose() is idempotent and total (n ∈ [1,20] calls never throw)\n * A5b post-dispose inertness — every public method is a no-op after dispose\n * A6 every pre-dispose subscriber (k ∈ [1,10]) sees `complete` on dispose\n * X3-runtime instance isolation — driving one instance never moves another's surfaces\n * Structural assertions (single-shot):\n * A1 plain-object identity (no class instance)\n * X1 no raw Subject on the public surface\n * A7-passed disposing the unit must NOT dispose an injected dependency\n * A7-owned disposing the unit MUST dispose its internally-constructed children\n */\n\nimport * as fc from 'fast-check';\nimport { Subject, type Observable } from 'rxjs';\nimport type { StateUnit } from './state-unit';\n\n/**\n * A disposable stand-in for an injected dependency. Pass one as a unit's\n * constructor arg, then list it in `setup().passedIn` so A7-passed can assert\n * the unit never disposed it. Counts calls so A7-passed also holds under the\n * repeated-dispose stress of A5.\n */\nexport interface DisposeProbe extends StateUnit {\n readonly disposeCount: number;\n}\n\nexport function disposeProbe(): DisposeProbe {\n let n = 0;\n return {\n dispose() { n += 1; },\n get disposeCount() { return n; },\n };\n}\n\ntype SetupResult<T extends StateUnit> =\n | T\n | { unit: T; passedIn?: readonly DisposeProbe[]; teardown?: () => void };\n\nexport interface StateUnitAxiomSpec<T extends StateUnit> {\n /**\n * Build a FRESH unit. Called many times (fast-check re-runs), so it must\n * return an independent instance each call. Return the bare unit, or an object\n * carrying the injected `passedIn` probes (A7-passed) and a `teardown` to\n * release per-instance resources (e.g. a mock bus).\n */\n setup: () => SetupResult<T>;\n /** Owned public Observables — Subjects the unit completes on dispose (A6, X3, post-dispose inertness). */\n surfaces?: (unit: T) => readonly Observable<unknown>[];\n /** Public input methods as zero-arg callers (A5b post-dispose, X3 drive). */\n invocations?: (unit: T) => readonly (() => unknown)[];\n /** Surfaces of internally-constructed children — must complete when the outer disposes (A7-owned). */\n ownedChildSurfaces?: (unit: T) => readonly Observable<unknown>[];\n /** fast-check run budget per property (default 30). */\n numRuns?: number;\n}\n\ninterface Normalized<T extends StateUnit> {\n unit: T;\n passedIn: readonly DisposeProbe[];\n teardown: () => void;\n}\n\nfunction normalize<T extends StateUnit>(r: SetupResult<T>): Normalized<T> {\n if (r && typeof r === 'object' && 'unit' in r) {\n return { unit: r.unit, passedIn: r.passedIn ?? [], teardown: r.teardown ?? (() => {}) };\n }\n return { unit: r as T, passedIn: [], teardown: () => {} };\n}\n\nfunction swallowAsync(value: unknown): void {\n if (value && typeof value === 'object' && typeof (value as { then?: unknown }).then === 'function') {\n (value as Promise<unknown>).then(undefined, () => {});\n }\n}\n\n/**\n * Run every applicable axiom against `spec`. Throws a labeled Error on the first\n * violation. Axioms whose accessors are omitted are skipped (e.g. A7-passed\n * runs only when `setup` returns `passedIn`; A6 only when `surfaces` is given).\n */\nexport function assertStateUnitAxioms<T extends StateUnit>(spec: StateUnitAxiomSpec<T>): void {\n const numRuns = spec.numRuns ?? 30;\n const fresh = (): Normalized<T> => normalize(spec.setup());\n\n // fast-check's default falsification message is just \"Property failed after N\n // tests {seed}\" — it drops the thrown axiom id. Prepend the axiom so a real\n // failure names itself; the seed/shrink detail is preserved.\n const run = (axiom: string, prop: Parameters<typeof fc.assert>[0]): void => {\n try {\n fc.assert(prop, { numRuns });\n } catch (e) {\n throw new Error(`${axiom}: ${e instanceof Error ? e.message : String(e)}`);\n }\n };\n\n // A1 — plain-object identity (no class instance).\n {\n const { unit, teardown } = fresh();\n const proto = Object.getPrototypeOf(unit);\n if (proto !== Object.prototype && proto !== null) {\n throw new Error('A1: state unit is not a plain object (has a class prototype)');\n }\n unit.dispose();\n teardown();\n }\n\n // X1 — no raw *origin* Subject on the public surface (expose `.asObservable()`).\n // Flag only origin Subjects — `new Subject` / `new BehaviorSubject`, the unit's own\n // state, where `.source` is undefined. Derived `AnonymousSubject`s from `Subject.lift`\n // (`shareReplay().pipe(...)`) carry a `.source` and are inert sinks (`.next()` does\n // nothing useful) — idiomatic, not the forgotten-internal-Subject smell — so exclude them.\n {\n const { unit, teardown } = fresh();\n for (const [key, value] of Object.entries(unit)) {\n if (value instanceof Subject && (value as { source?: unknown }).source === undefined) {\n throw new Error(`X1: public field \"${key}\" is a raw Subject — expose it via .asObservable()`);\n }\n }\n unit.dispose();\n teardown();\n }\n\n // A7-passed — disposing the unit must NOT dispose an injected dependency.\n {\n const { unit, passedIn, teardown } = fresh();\n unit.dispose();\n passedIn.forEach((probe, i) => {\n if (probe.disposeCount > 0) {\n throw new Error(`A7-passed: the unit disposed injected dependency #${i} (it doesn't own it)`);\n }\n });\n teardown();\n }\n\n // A5 — dispose() idempotent & total: n calls never throw; injected deps stay untouched.\n run('A5', fc.property(fc.integer({ min: 1, max: 20 }), (n) => {\n const { unit, passedIn, teardown } = fresh();\n for (let i = 0; i < n; i++) unit.dispose();\n passedIn.forEach((probe, i) => {\n if (probe.disposeCount > 0) {\n throw new Error(`injected dependency #${i} disposed under ${n} dispose() calls`);\n }\n });\n teardown();\n }));\n\n // A6 — k pre-dispose subscribers on each owned surface all see `complete` on dispose.\n if (spec.surfaces) {\n const surfaces = spec.surfaces;\n run('A6', fc.property(fc.integer({ min: 1, max: 10 }), (k) => {\n const { unit, teardown } = fresh();\n const completed: boolean[] = [];\n const subs = surfaces(unit).flatMap((o) =>\n Array.from({ length: k }, () => {\n const idx = completed.push(false) - 1;\n return o.subscribe({ complete: () => { completed[idx] = true; } });\n }),\n );\n unit.dispose();\n completed.forEach((seen, idx) => {\n if (!seen) throw new Error(`a subscriber did not see complete on dispose (k=${k}, sub #${idx})`);\n });\n subs.forEach((s) => s.unsubscribe());\n teardown();\n }));\n }\n\n // A5b — post-dispose inertness: every public method is a no-op (no throw) after dispose.\n if (spec.invocations) {\n const invocations = spec.invocations;\n run('A5b', fc.property(fc.array(fc.nat(), { maxLength: 12 }), (seq) => {\n const { unit, teardown } = fresh();\n const callers = invocations(unit);\n unit.dispose();\n for (const raw of seq) {\n if (callers.length === 0) break;\n swallowAsync(callers[raw % callers.length]());\n }\n teardown();\n }));\n }\n\n // X3-runtime — instance isolation: driving instance A never moves instance B's surfaces.\n if (spec.surfaces && spec.invocations) {\n const surfaces = spec.surfaces;\n const invocations = spec.invocations;\n run('X3-runtime', fc.property(fc.array(fc.nat(), { minLength: 1, maxLength: 8 }), (seq) => {\n const a = fresh();\n const b = fresh();\n const bSurfaces = surfaces(b.unit);\n const bCounts = bSurfaces.map(() => 0);\n const bSubs = bSurfaces.map((o, i) => o.subscribe(() => { bCounts[i] += 1; }));\n const baseline = bCounts.slice(); // initial replay captured synchronously above\n const aCallers = invocations(a.unit);\n for (const raw of seq) {\n if (aCallers.length === 0) break;\n swallowAsync(aCallers[raw % aCallers.length]());\n }\n bCounts.forEach((count, i) => {\n if (count !== baseline[i]) {\n throw new Error(`driving instance A perturbed instance B's surface #${i}`);\n }\n });\n bSubs.forEach((s) => s.unsubscribe());\n a.unit.dispose();\n b.unit.dispose();\n a.teardown();\n b.teardown();\n }));\n }\n\n // A7-owned — internally-constructed children are disposed (their surfaces complete) on outer dispose.\n if (spec.ownedChildSurfaces) {\n const { unit, teardown } = fresh();\n const childSurfaces = spec.ownedChildSurfaces(unit);\n const completed = childSurfaces.map(() => false);\n const subs = childSurfaces.map((o, i) => o.subscribe({ complete: () => { completed[i] = true; } }));\n unit.dispose();\n completed.forEach((seen, i) => {\n if (!seen) throw new Error(`A7-owned: owned child surface #${i} did not complete on outer dispose`);\n });\n subs.forEach((s) => s.unsubscribe());\n teardown();\n }\n\n // Post-dispose surface inertness: a NEW subscription after dispose completes with no `next`.\n if (spec.surfaces) {\n const { unit, teardown } = fresh();\n unit.dispose();\n spec.surfaces(unit).forEach((o, i) => {\n let nexts = 0;\n let done = false;\n o.subscribe({ next: () => { nexts += 1; }, complete: () => { done = true; } }).unsubscribe();\n if (nexts > 0) throw new Error(`A5b/inert: owned surface #${i} emitted a value after dispose`);\n if (!done) throw new Error(`A5b/inert: owned surface #${i} did not complete after dispose`);\n });\n teardown();\n }\n}\n","/**\n * Branded string types for compile-time type safety\n *\n * These types are zero-cost at runtime but prevent mixing\n * different string types at compile time.\n */\n\nimport type { components } from './types';\n\n// ============================================================================\n// OPENAPI-GENERATED TYPES (use directly from spec)\n// ============================================================================\n\nexport type Motivation = components['schemas']['Motivation'];\nexport type ContentFormat = components['schemas']['ContentFormat'];\n\n// ============================================================================\n// AUTHENTICATION & TOKENS\n// ============================================================================\n\nexport type Email = string & { readonly __brand: 'Email' };\nexport type AuthCode = string & { readonly __brand: 'AuthCode' };\nexport type GoogleCredential = string & { readonly __brand: 'GoogleCredential' };\nexport type AccessToken = string & { readonly __brand: 'AccessToken' };\nexport type RefreshToken = string & { readonly __brand: 'RefreshToken' };\nexport type MCPToken = string & { readonly __brand: 'MCPToken' };\nexport type CloneToken = string & { readonly __brand: 'CloneToken' };\n\n// ============================================================================\n// SYSTEM IDENTIFIERS\n// ============================================================================\n\nexport type JobId = string & { readonly __brand: 'JobId' };\nexport type UserDID = string & { readonly __brand: 'UserDID' };\nexport type EntityType = string & { readonly __brand: 'EntityType' };\nexport type SearchQuery = string & { readonly __brand: 'SearchQuery' };\nexport type BaseUrl = string & { readonly __brand: 'BaseUrl' };\n\n// ============================================================================\n// HELPER FUNCTIONS (minimal validation, just branding)\n// ============================================================================\n\nexport function email(value: string): Email { return value as Email; }\nexport function authCode(value: string): AuthCode { return value as AuthCode; }\nexport function googleCredential(value: string): GoogleCredential { return value as GoogleCredential; }\nexport function accessToken(value: string): AccessToken { return value as AccessToken; }\nexport function refreshToken(value: string): RefreshToken { return value as RefreshToken; }\nexport function mcpToken(value: string): MCPToken { return value as MCPToken; }\nexport function cloneToken(value: string): CloneToken { return value as CloneToken; }\nexport function jobId(value: string): JobId { return value as JobId; }\nexport function userDID(value: string): UserDID { return value as UserDID; }\nexport function entityType(value: string): EntityType { return value as EntityType; }\nexport function searchQuery(value: string): SearchQuery { return value as SearchQuery; }\nexport function baseUrl(value: string): BaseUrl { return value as BaseUrl; }\n\n// Motivation is an OpenAPI enum — use its values directly, no helper needed.\n// ContentFormat is a free-form MIME string whose base type must be a\n// SupportedMediaType; validation lives in media-types.ts, not in a brand.\n\n// ============================================================================\n// HTTP URI TYPES\n// ============================================================================\n\n// Branded type definitions for HTTP URIs returned by the API\nexport type ResourceUri = string & { readonly __brand: 'ResourceUri' };\n\n// W3C flat format for content negotiation: http://localhost:4000/annotations/{id}\nexport type AnnotationUri = string & { readonly __brand: 'AnnotationUri' };\n\n// Nested format for CRUD operations: http://localhost:4000/resources/{resourceId}/annotations/{annotationId}\nexport type ResourceAnnotationUri = string & { readonly __brand: 'ResourceAnnotationUri' };\n\n// Factory functions with runtime validation\nexport function resourceUri(uri: string): ResourceUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected ResourceUri, got: ${uri}`);\n }\n return uri as ResourceUri;\n}\n\nexport function annotationUri(uri: string): AnnotationUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected AnnotationUri, got: ${uri}`);\n }\n return uri as AnnotationUri;\n}\n\nexport function resourceAnnotationUri(uri: string): ResourceAnnotationUri {\n if (!uri.startsWith('http://') && !uri.startsWith('https://')) {\n throw new TypeError(`Expected ResourceAnnotationUri, got: ${uri}`);\n }\n // Additional validation: must contain /resources/ and /annotations/\n if (!uri.includes('/resources/') || !uri.includes('/annotations/')) {\n throw new TypeError(`Expected nested ResourceAnnotationUri format, got: ${uri}`);\n }\n return uri as ResourceAnnotationUri;\n}\n","import type { EventName, EmittableChannel } from './bus-protocol';\n\n/**\n * BUS_OPERATIONS — the request/reply operations registry (Tier 1).\n *\n * Each entry declares ONE operation as the triple that was previously three\n * loose, independently-maintained facts spread across call sites:\n * - the request channel (the key — an `EmittableChannel`),\n * - the `result` channel (success reply),\n * - the `failure` channel,\n * - and, for a streaming op, an optional `progress` channel.\n *\n * `BridgedChannel` / `BRIDGED_CHANNELS` are DERIVED from this map\n * (bridged-channels.ts): every reply lands in the bridged fan-in set by\n * construction, so \"a reply channel forgotten from BRIDGED_CHANNELS\" — the\n * recurring bug class (gather:resource-complete, frame:*-add-failed) — is no\n * longer representable. See .plans/BUS-OPERATIONS-REGISTRY.md.\n *\n * `Partial<Record<EmittableChannel, …>>` enforces that every key is a real\n * emittable request. `result`/`failure`/`progress` stay `EventName` rather than\n * `BridgedChannel` to avoid a circular reference (BridgedChannel derives from\n * this map); the derivation closes the loop instead.\n */\nexport interface BusOperationSpec {\n result: EventName;\n failure: EventName;\n /** Streaming ops only: an intermediate channel that also bridges. */\n progress?: EventName;\n}\n\nexport const BUS_OPERATIONS = {\n // ── BIND ────────────────────────────────────────────────────────\n 'bind:update-body': { result: 'bind:body-updated', failure: 'bind:body-update-failed' },\n\n // ── BROWSE (reads) ──────────────────────────────────────────────\n 'browse:resource-requested': { result: 'browse:resource-result', failure: 'browse:resource-failed' },\n 'browse:resources-requested': { result: 'browse:resources-result', failure: 'browse:resources-failed' },\n 'browse:annotation-requested': { result: 'browse:annotation-result', failure: 'browse:annotation-failed' },\n 'browse:annotations-requested': { result: 'browse:annotations-result', failure: 'browse:annotations-failed' },\n 'browse:annotation-history-requested': { result: 'browse:annotation-history-result', failure: 'browse:annotation-history-failed' },\n 'browse:events-requested': { result: 'browse:events-result', failure: 'browse:events-failed' },\n 'browse:referenced-by-requested': { result: 'browse:referenced-by-result', failure: 'browse:referenced-by-failed' },\n 'browse:entity-types-requested': { result: 'browse:entity-types-result', failure: 'browse:entity-types-failed' },\n 'browse:tag-schemas-requested': { result: 'browse:tag-schemas-result', failure: 'browse:tag-schemas-failed' },\n 'browse:agents-requested': { result: 'browse:agents-result', failure: 'browse:agents-failed' },\n 'browse:directory-requested': { result: 'browse:directory-result', failure: 'browse:directory-failed' },\n // dormant — backend handler complete, no client caller yet (annotation-detail capability)\n 'browse:annotation-context-requested': { result: 'browse:annotation-context-result', failure: 'browse:annotation-context-failed' },\n\n // ── FRAME (KB schema writes) ────────────────────────────────────\n 'frame:add-entity-type': { result: 'frame:entity-type-add-ok', failure: 'frame:entity-type-add-failed' },\n 'frame:add-tag-schema': { result: 'frame:tag-schema-add-ok', failure: 'frame:tag-schema-add-failed' },\n\n // ── GATHER ──────────────────────────────────────────────────────\n // streaming: take-1 result + failure plus an intermediate progress channel\n 'gather:requested': { result: 'gather:complete', failure: 'gather:failed', progress: 'gather:annotation-progress' },\n 'gather:resource-requested': { result: 'gather:resource-complete', failure: 'gather:resource-failed' },\n // dormant — backend handler complete, no client caller yet (annotation summary)\n 'gather:summary-requested': { result: 'gather:summary-result', failure: 'gather:summary-failed' },\n\n // ── JOB ─────────────────────────────────────────────────────────\n 'job:create': { result: 'job:created', failure: 'job:create-failed' },\n 'job:status-requested': { result: 'job:status-result', failure: 'job:status-failed' },\n 'job:cancel-requested': { result: 'job:cancel-ok', failure: 'job:cancel-failed' },\n // worker-side: the worker claims a queued job (not an SDK call)\n 'job:claim': { result: 'job:claimed', failure: 'job:claim-failed' },\n\n // ── MARK ────────────────────────────────────────────────────────\n 'mark:create-request': { result: 'mark:create-ok', failure: 'mark:create-failed' },\n 'mark:delete': { result: 'mark:delete-ok', failure: 'mark:delete-failed' },\n 'mark:archive': { result: 'mark:archive-ok', failure: 'mark:archive-failed' },\n 'mark:unarchive': { result: 'mark:unarchive-ok', failure: 'mark:unarchive-failed' },\n 'mark:update-entity-types': { result: 'mark:update-entity-types-ok', failure: 'mark:update-entity-types-failed' },\n\n // ── MATCH ───────────────────────────────────────────────────────\n // take-1 dressed as an Observable in the SDK; no progress channel\n 'match:search-requested': { result: 'match:search-results', failure: 'match:search-failed' },\n\n // ── YIELD ───────────────────────────────────────────────────────\n // live in-process (resource-operations.ts emits + awaits via race()); the\n // client also .on()-subscribes -ok for cache invalidation\n 'yield:create': { result: 'yield:create-ok', failure: 'yield:create-failed' },\n // dormant — handler in stower exists, no request emitter; client pre-subscribes -ok\n 'yield:update': { result: 'yield:update-ok', failure: 'yield:update-failed' },\n 'yield:clone-create': { result: 'yield:clone-created', failure: 'yield:clone-create-failed' },\n 'yield:clone-resource-requested': { result: 'yield:clone-resource-result', failure: 'yield:clone-resource-failed' },\n 'yield:clone-token-requested': { result: 'yield:clone-token-generated', failure: 'yield:clone-token-failed' },\n} as const satisfies Partial<Record<EmittableChannel, BusOperationSpec>>;\n\n/** The request-channel key of a registered operation — what `busRequest` takes. */\nexport type BusOperationKey = keyof typeof BUS_OPERATIONS;\n","import type { EventName } from './bus-protocol';\nimport { BUS_OPERATIONS } from './bus-operations';\n\n/**\n * BRIDGED_CHANNELS\n *\n * The set of bus channels that any concrete transport bridges into the\n * caller-supplied bus via `bridgeInto`. Transport-neutral: every concrete\n * `ITransport` shares the same set; HTTP delivers them via SSE, in-process\n * transports forward them directly from the local actor bus.\n *\n * This is the *fan-in* set — channels for events the transport receives and\n * pushes onto the client's bus. It is not the same as the channels the client\n * emits (which is open-ended).\n *\n * It is DERIVED, not hand-listed: the request/reply replies come from\n * `BUS_OPERATIONS` (bus-operations.ts), so no operation's reply can be\n * forgotten here — that was the recurring unbridged-reply bug class. The only\n * hand-maintained part is `BRIDGED_BROADCASTS`: the genuine non-request/reply\n * minority (lifecycle events and UI/infra signals that no single requester\n * owns). See .plans/BUS-OPERATIONS-REGISTRY.md.\n *\n * Resource-scoped channels (joined/left via `subscribeToResource`) are tracked\n * separately by transports that care about scope (HTTP).\n */\n\n/**\n * Bridged channels with no owning operation: job-lifecycle events (multi-viewer,\n * no single requester owns the reply), KB-global frame domain events, UI signals,\n * and SSE infrastructure. A reply channel must NOT go here — declare its\n * operation in `BUS_OPERATIONS` instead.\n */\nexport const BRIDGED_BROADCASTS = [\n 'job:report-progress', 'job:complete', 'job:fail',\n 'frame:entity-type-added', 'frame:tag-schema-added',\n 'beckon:focus', 'beckon:sparkle',\n 'bus:resume-gap',\n] as const satisfies readonly EventName[];\n\n// ── Derivation ──────────────────────────────────────────────────────────────\n// Every operation's result + failure (+ progress) channel bridges, by\n// construction. Type and runtime are derived from the same `BUS_OPERATIONS`.\n\ntype OpSpecs = (typeof BUS_OPERATIONS)[keyof typeof BUS_OPERATIONS];\n\n// Generic wrapper so the conditional distributes over each union member (a bare\n// `OpSpecs extends …` would test the whole union at once and collapse to never\n// because only the streaming ops carry `progress`).\ntype ProgressChannel<O> = O extends { progress: infer P extends EventName } ? P : never;\n\n/** The union of every reply channel declared in the registry. */\ntype RegistryReply = OpSpecs['result'] | OpSpecs['failure'] | ProgressChannel<OpSpecs>;\n\n// Iterate by typed key so each op's literal reply types survive — the element\n// type stays `RegistryReply` (no widening to `EventName`), so the composed\n// array is `BridgedChannel[]` with no narrowing assertion. The runtime proof\n// that this derived set is exactly the intended one is the equality test in\n// __tests__/bus-invariants.test.ts.\nconst REGISTRY_REPLIES = (Object.keys(BUS_OPERATIONS) as (keyof typeof BUS_OPERATIONS)[]).flatMap(\n (key) => {\n const op = BUS_OPERATIONS[key];\n return 'progress' in op ? [op.result, op.failure, op.progress] : [op.result, op.failure];\n },\n);\n\nexport const BRIDGED_CHANNELS: readonly BridgedChannel[] = [\n ...REGISTRY_REPLIES,\n ...BRIDGED_BROADCASTS,\n];\n\n/**\n * The SUBSCRIBE-side subset of `EventName` — the channels a client can receive\n * over a concrete transport. See the family note on `EventName` in\n * bus-protocol.ts (emit on an `EmittableChannel`, subscribe on a `BridgedChannel`).\n */\nexport type BridgedChannel = RegistryReply | (typeof BRIDGED_BROADCASTS)[number];\n","/**\n * Bus logging — runtime-toggleable cross-wire visibility.\n *\n * One line per event that crosses a process boundary, in a grep-able\n * format that's symmetric across frontend and backend:\n *\n * [bus EMIT] <channel> [scope=X] [cid=<first8>] <payload>\n * [bus RECV] <channel> [scope=X] [cid=<first8>] <payload>\n * [bus SSE] <channel> [scope=X] [cid=<first8>] <payload>\n *\n * Tier 1 of `.plans/OBSERVABILITY.md`. Forward-compatible with Tier 2:\n * the `cid` printed here is exactly the prefix of the W3C trace-id we\n * adopt later.\n *\n * Cost when disabled: one property read per call, zero allocations.\n *\n * Enable:\n * - Browser: `window.__SEMIONT_BUS_LOG__ = true` (DevTools or e2e init)\n * - Node: `SEMIONT_BUS_LOG=1` in the process env (read at module load)\n */\n\nimport { BRIDGED_CHANNELS } from './bridged-channels';\n\nconst NODE_BUS_LOG =\n typeof process !== 'undefined' && !!process.env?.SEMIONT_BUS_LOG;\n\nconst IS_NODE =\n typeof process !== 'undefined' && !!process.versions?.node;\n\nexport type BusOp = 'EMIT' | 'RECV' | 'SSE' | 'PUT' | 'GET';\n\nexport function busLogEnabled(): boolean {\n const g = globalThis as { __SEMIONT_BUS_LOG__?: boolean };\n if (g.__SEMIONT_BUS_LOG__) return true;\n return NODE_BUS_LOG;\n}\n\n/**\n * Optional active-span trace-id provider. When a Tier 2 OTel SDK is\n * initialized, `@semiont/observability` registers a provider here that\n * returns the active span's W3C `trace_id`. busLog appends it to each\n * emitted line so the grep-timeline correlates with the span tree in\n * an APM UI.\n *\n * Decoupling: `@semiont/core` does not depend on `@opentelemetry/api`.\n * If no provider is registered (Tier 1-only deployments, or before\n * `initObservabilityNode` runs), the field is omitted from the line —\n * same shape as before this hook existed.\n */\nlet traceIdProvider: (() => string | undefined) | undefined;\n\nexport function setBusLogTraceIdProvider(fn: (() => string | undefined) | undefined): void {\n traceIdProvider = fn;\n}\n\nexport function busLog(\n op: BusOp,\n channel: string,\n payload: unknown,\n scope?: string,\n): void {\n if (!busLogEnabled()) return;\n const cidRaw = (payload as { correlationId?: unknown } | null | undefined)?.correlationId;\n const cid = typeof cidRaw === 'string' ? cidRaw.slice(0, 8) : undefined;\n let traceId: string | undefined;\n if (traceIdProvider) {\n try { traceId = traceIdProvider(); } catch { /* noop */ }\n }\n const tag =\n `[bus ${op}] ${channel}` +\n (scope ? ` scope=${scope}` : '') +\n (cid ? ` cid=${cid}` : '') +\n (traceId ? ` trace=${traceId.slice(0, 8)}` : '');\n // eslint-disable-next-line no-console\n console.debug(tag, payload);\n}\n\n/**\n * Whether to run the unobserved-reply check on every local emit.\n *\n * On in Node (backend + worker + smelter), where a dropped reply is a real\n * delivery bug; off in the browser, where a 0-observer bridged reply just\n * means the awaiting `busRequest` already resolved/timed out (benign).\n *\n * Always-on (no env flag) by design: the failure it catches is rare and\n * high-signal, and the whole point is that it fires with zero setup — the\n * incident that motivated it (.plans/bugs/gather-resource-complete-not-bridged.md)\n * ran with bus-logging off, so a flag-gated check would have stayed silent.\n */\nexport function warnUnobservedRepliesEnabled(): boolean {\n return IS_NODE;\n}\n\n/** One line per channel per process — a missing fan-in wiring is a config\n * bug, so the first dropped reply is enough; we don't spam on retries. */\nconst unobservedReplyWarned = new Set<string>();\n\n/**\n * The silent-dropped-reply detector.\n *\n * A correlation-bearing payload is a request/reply *reply* (`*-result`,\n * `*-complete`, `*-failed`, …). If one is emitted on the backend bus with\n * **zero local observers**, nothing forwards it — no SSE subscription, no\n * in-process consumer — so the awaiting client never receives it and times\n * out 30 s later with no error logged anywhere. That is exactly how\n * `gather:resource-complete` failed when it was missing from\n * `BRIDGED_CHANNELS` (.plans/bugs/gather-resource-complete-not-bridged.md).\n *\n * Emits one WARN per channel naming the likely fix. Ignored (no warning):\n * non-reply emits (no `correlationId`), emits with observers, and — crucially —\n * channels already in `BRIDGED_CHANNELS`: a 0-observer emit there is a redundant\n * copy, not a gap (see .plans/bugs/BRIDGE-GAPS.md). So the detector fires only\n * for a genuine missing forwarder, and its remediation text is always correct.\n */\nexport function warnIfUnobservedReply(\n channel: string,\n payload: unknown,\n observerCount: number,\n): void {\n if (observerCount > 0) return;\n const cidRaw = (payload as { correlationId?: unknown } | null | undefined)?.correlationId;\n if (typeof cidRaw !== 'string' || cidRaw.length === 0) return;\n // A 0-observer emit on a *bridged* channel is a redundant copy (a global +\n // resource-scoped dual-emit, or an SSE reconnect replay), not a missing\n // forwarder — the first copy already reached the awaiting `take(1)`\n // subscriber. Only a NOT-bridged channel is a genuine drop. (`busRequest` now\n // types its reply channels `BridgedChannel`, so an unbridged reply is a\n // compile error; this runtime check covers non-`busRequest` correlation\n // emits.) See .plans/bugs/BRIDGE-GAPS.md.\n if ((BRIDGED_CHANNELS as readonly string[]).includes(channel)) return;\n if (unobservedReplyWarned.has(channel)) return;\n unobservedReplyWarned.add(channel);\n // eslint-disable-next-line no-console\n console.warn(\n `[bus DROP] ${channel} cid=${cidRaw.slice(0, 8)} emitted with 0 subscribers and not in ` +\n `BRIDGED_CHANNELS — a correlation reply with no forwarder is dropped, so the awaiting ` +\n `client times out (no error). Bridge it by declaring its operation in BUS_OPERATIONS ` +\n `(packages/core/src/bus-operations.ts) — or, if it is a non-reply broadcast, add it to ` +\n `BRIDGED_BROADCASTS (packages/core/src/bridged-channels.ts) — so transports subscribe to it.`,\n );\n}\n","/**\n * RxJS-based Event Bus\n *\n * Framework-agnostic event bus providing direct access to typed RxJS Subjects.\n *\n * Can be used in Node.js, browser, workers, CLI - anywhere RxJS runs.\n */\n\nimport { Subject } from 'rxjs';\nimport { busLog, busLogEnabled, warnIfUnobservedReply, warnUnobservedRepliesEnabled } from './bus-log';\nimport type { EventMap } from './bus-protocol';\nimport type { StoredEvent } from './event-base';\nimport type { PersistedEventType } from './persisted-events';\n\n/**\n * RxJS-based event bus\n *\n * Provides direct access to RxJS Subjects for each event type.\n * Use standard RxJS patterns for emitting and subscribing.\n *\n * @example\n * ```typescript\n * const eventBus = new EventBus();\n *\n * // Emit events\n * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });\n *\n * // Subscribe to events\n * const subscription = eventBus.get('beckon:hover').subscribe(({ annotationId }) => {\n * console.log('Hover:', annotationId);\n * });\n *\n * // Use RxJS operators\n * import { debounceTime } from 'rxjs/operators';\n * eventBus.get('beckon:hover')\n * .pipe(debounceTime(100))\n * .subscribe(handleHover);\n *\n * // Cleanup\n * subscription.unsubscribe();\n * eventBus.destroy();\n * ```\n */\nexport class EventBus {\n private subjects: Map<keyof EventMap, Subject<any>>;\n private isDestroyed: boolean;\n\n constructor() {\n this.subjects = new Map();\n this.isDestroyed = false;\n }\n\n /**\n * Get the RxJS Subject for an event\n *\n * Returns a typed Subject that can be used with all RxJS operators.\n * Subjects are created lazily on first access.\n *\n * @param eventName - The event name\n * @returns The RxJS Subject for this event\n *\n * @example\n * ```typescript\n * // Emit\n * eventBus.get('beckon:hover').next({ annotationId: 'ann-1' });\n *\n * // Subscribe\n * const sub = eventBus.get('beckon:hover').subscribe(handleHover);\n *\n * // With operators\n * eventBus.get('beckon:hover')\n * .pipe(debounceTime(100), distinctUntilChanged())\n * .subscribe(handleHover);\n * ```\n */\n get<K extends keyof EventMap>(eventName: K): Subject<EventMap[K]> {\n if (this.isDestroyed) {\n throw new Error(`Cannot access event '${String(eventName)}' on destroyed bus`);\n }\n\n if (!this.subjects.has(eventName)) {\n const subject = new Subject<EventMap[K]>();\n // When bus-log is enabled (`SEMIONT_BUS_LOG=1` or\n // `window.__SEMIONT_BUS_LOG__ = true`), wrap `.next()` so every\n // local emit on this channel produces a `[bus EMIT] <channel> ...`\n // line on `console.debug` — same shape as cross-wire emits from\n // HttpTransport. This is what makes local-only fan-out signals\n // (`beckon.hover`, `beckon.sparkle`, `mark.request`, etc.)\n // visible to the e2e bus capture and to a developer's DevTools.\n // The `busLogEnabled()` check is at first-`get` time per channel;\n // setting the flag after channels are constructed won't\n // retroactively wrap them. The bus capture fixture uses\n // `addInitScript` so the flag is set before any namespace\n // construction, which is when `get()` is first called.\n //\n // Independently, on Node we wrap `.next()` to catch *dropped replies*:\n // a correlation-bearing payload emitted with zero observers (see\n // `warnIfUnobservedReply`). This needs no flag — it's how the\n // `gather:resource-complete` bridge gap stayed invisible until a 30 s\n // timeout. The two wraps share one closure when both are active.\n const wantBusLog = busLogEnabled();\n const wantDropCheck = warnUnobservedRepliesEnabled();\n if (wantBusLog || wantDropCheck) {\n const wrapped = subject;\n const originalNext = subject.next.bind(subject);\n subject.next = (value: EventMap[K]): void => {\n if (wantBusLog) busLog('EMIT', String(eventName), value as object);\n if (wantDropCheck) warnIfUnobservedReply(String(eventName), value, wrapped.observers.length);\n originalNext(value);\n };\n }\n this.subjects.set(eventName, subject);\n }\n return this.subjects.get(eventName)!;\n }\n\n /**\n * Get the RxJS Subject for a domain event type (PersistedEventType).\n *\n * Domain event channels carry `StoredEvent`. This method avoids the need\n * for `as keyof EventMap` casts when subscribing to domain event channels\n * using runtime `PersistedEventType` strings.\n */\n getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent> {\n return this.get(eventType as keyof EventMap) as unknown as Subject<StoredEvent>;\n }\n\n /**\n * Destroy the event bus and complete all subjects\n *\n * After calling destroy(), no new events can be emitted or subscribed to.\n * All active subscriptions will be completed.\n */\n destroy(): void {\n if (this.isDestroyed) {\n return;\n }\n\n for (const subject of this.subjects.values()) {\n subject.complete();\n }\n\n this.subjects.clear();\n this.isDestroyed = true;\n }\n\n /**\n * Check if the event bus has been destroyed\n */\n get destroyed(): boolean {\n return this.isDestroyed;\n }\n\n /**\n * Create a resource-scoped event bus\n *\n * Events emitted or subscribed through the scoped bus are isolated to that resource.\n * Internally, events are namespaced but the API remains identical to the parent bus.\n *\n * @param resourceId - Resource identifier to scope events to\n * @returns A scoped event bus for this resource\n *\n * @example\n * ```typescript\n * const eventBus = new EventBus();\n * const resource1 = eventBus.scope('resource-1');\n * const resource2 = eventBus.scope('resource-2');\n *\n * // These are isolated - only resource1 subscribers will fire\n * resource1.get('detection:progress').next({ status: 'started' });\n * ```\n */\n scope(resourceId: string): ScopedEventBus {\n return new ScopedEventBus(this, resourceId);\n }\n}\n\n/**\n * Resource-scoped event bus\n *\n * Provides isolated event streams per resource while maintaining the same API\n * as the parent EventBus. Events are internally namespaced by resourceId.\n */\nexport class ScopedEventBus {\n constructor(\n private parent: EventBus,\n private scopePrefix: string\n ) {}\n\n /**\n * Get the RxJS Subject for a scoped event\n *\n * Returns the same type as the parent bus, but events are isolated to this scope.\n * Internally uses namespaced keys but preserves type safety.\n *\n * @param event - The event name\n * @returns The RxJS Subject for this scoped event\n */\n get<E extends keyof EventMap>(event: E): Subject<EventMap[E]> {\n // Internally namespace the event key, but preserve return type\n const scopedKey = `${this.scopePrefix}:${event as string}`;\n\n // Access parent's subjects map directly (needs cast for private access)\n const parentSubjects = (this.parent as any).subjects as Map<string, Subject<any>>;\n\n if (!parentSubjects.has(scopedKey)) {\n parentSubjects.set(scopedKey, new Subject<EventMap[E]>());\n }\n return parentSubjects.get(scopedKey)!;\n }\n\n /** Get the RxJS Subject for a domain event type on this scoped bus. */\n getDomainEvent(eventType: PersistedEventType): Subject<StoredEvent> {\n return this.get(eventType as keyof EventMap) as unknown as Subject<StoredEvent>;\n }\n\n /**\n * Create a nested scope\n *\n * Allows hierarchical scoping like `resource-1:subsystem-a`\n *\n * @param subScope - Additional scope level\n * @returns A nested scoped event bus\n */\n scope(subScope: string): ScopedEventBus {\n return new ScopedEventBus(this.parent, `${this.scopePrefix}:${subScope}`);\n }\n}\n","/**\n * FaultyTransport — a seeded, scriptable `ITransport` simulator for the\n * liveness axioms (`.plans/LIVENESS-AXIOMS.md`). fast-check draws a fault\n * schedule; the transport applies one `FaultAction` per request-channel emit\n * and synthesizes replies from the `BUS_OPERATIONS` registry, so real\n * compositions (`busRequest`, SWR caches, live queries) run unmodified against\n * generated wire behavior no hand-written test names.\n *\n * Home is core (not sdk/test-utils) for the same reason as\n * `assertStateUnitAxioms`: it needs only core types, and every layer —\n * including `http-transport`, below sdk — can consume it via\n * `@semiont/core/testing` without a dependency cycle.\n *\n * Deterministic-by-construction: no `Date.now`, no randomness of its own —\n * all variation comes in through the schedule (fast-check owns the seed).\n * Time is real `setTimeout` at millisecond scale; properties pass a small\n * explicit `timeoutMs` to `busRequest`, so nothing waits 30 s.\n */\n\nimport { BehaviorSubject, Subject, type Observable } from 'rxjs';\nimport type { SemiontError } from './errors';\nimport type { BaseUrl } from './branded-types';\nimport { baseUrl as makeBaseUrl } from './branded-types';\nimport type { ResourceId } from './identifiers';\nimport type { EventMap } from './bus-protocol';\nimport type { ConnectionState, ITransport } from './transport';\nimport { EventBus } from './event-bus';\nimport { BRIDGED_CHANNELS } from './bridged-channels';\nimport { BUS_OPERATIONS, type BusOperationKey } from './bus-operations';\n\n/** One wire behavior, applied to a single request-channel emit. */\nexport type FaultAction =\n | { kind: 'deliver' }\n | { kind: 'drop-reply' }\n | { kind: 'delay'; ms: number }\n | { kind: 'duplicate-reply' }\n | { kind: 'reject-emit' };\n\n/**\n * Scope-contention behavior of `subscribeToResource`:\n * `single-slot-throw` mirrors today's HttpTransport (one distinct scope at a\n * time; a second distinct scope throws); `multi` mirrors the\n * post-MULTI-RESOURCE-SCOPE world. The same properties run under both so the\n * migration can't silently change liveness behavior.\n */\nexport type ScopeModel = 'single-slot-throw' | 'multi';\n\n/** requestLog entry — one per request-channel emit, in arrival order. */\nexport interface RequestLogEntry {\n channel: BusOperationKey;\n /** The action the schedule assigned to this emit. */\n action: FaultAction;\n correlationId: string | undefined;\n /**\n * Request identity for retry accounting: channel + payload minus the\n * per-issue fields (`correlationId`, `_trace`, `_userId`). Two emits with\n * the same key are the same logical request re-issued.\n */\n retryKey: string;\n}\n\nexport interface FaultyTransportConfig {\n /**\n * The i-th request-channel emit applies `schedule[i % schedule.length]`.\n * Empty/omitted → every request delivers.\n */\n schedule?: readonly FaultAction[];\n /** Default `'single-slot-throw'` (today's HttpTransport). */\n scopeModel?: ScopeModel;\n /**\n * Synthesize the `response` value for a delivered reply. Return `undefined`\n * for a void ack (`{ correlationId }` only). Default: `{}` for every op.\n */\n makeResponse?: (operation: BusOperationKey, payload: Record<string, unknown>) => unknown;\n}\n\nfunction isOperation(channel: string): channel is BusOperationKey {\n return channel in BUS_OPERATIONS;\n}\n\n/** Stable request identity: channel + sorted payload minus per-issue fields. */\nexport function retryKeyOf(channel: string, payload: Record<string, unknown>): string {\n const entries = Object.entries(payload)\n .filter(([k]) => k !== 'correlationId' && k !== '_trace' && k !== '_userId')\n .sort(([a], [b]) => (a < b ? -1 : 1));\n return `${channel} ${JSON.stringify(entries)}`;\n}\n\nexport class FaultyTransport implements ITransport {\n readonly baseUrl: BaseUrl = makeBaseUrl('faulty://simulator');\n readonly state$ = new BehaviorSubject<ConnectionState>('open');\n private readonly errorsSubject = new Subject<SemiontError>();\n readonly errors$: Observable<SemiontError> = this.errorsSubject.asObservable();\n\n /** Every request-channel emit, in order — the L2 accounting surface. */\n readonly requestLog: RequestLogEntry[] = [];\n\n private readonly bus = new EventBus();\n private readonly schedule: readonly FaultAction[];\n private readonly scopeModel: ScopeModel;\n private readonly makeResponse: (op: BusOperationKey, payload: Record<string, unknown>) => unknown;\n private requestCount = 0;\n private activeScope: string | null = null;\n private scopeRefs = 0;\n private readonly timers = new Set<ReturnType<typeof setTimeout>>();\n private disposed = false;\n\n constructor(cfg: FaultyTransportConfig = {}) {\n this.schedule = cfg.schedule ?? [];\n this.scopeModel = cfg.scopeModel ?? 'single-slot-throw';\n this.makeResponse = cfg.makeResponse ?? (() => ({}));\n }\n\n // ── Bus primitives ──────────────────────────────────────────────────────\n\n async emit<K extends keyof EventMap>(\n channel: K,\n payload: EventMap[K],\n resourceScope?: ResourceId,\n ): Promise<void> {\n if (this.disposed) return;\n const name = channel as string;\n if (!isOperation(name)) {\n // Non-request channel: forward as-is (scoped or global).\n const target = resourceScope === undefined\n ? this.bus.get(channel)\n : this.bus.scope(resourceScope as string).get(channel);\n target.next(payload);\n return;\n }\n\n const record = payload as Record<string, unknown>;\n const action: FaultAction = this.schedule.length === 0\n ? { kind: 'deliver' }\n : this.schedule[this.requestCount % this.schedule.length]!;\n this.requestCount += 1;\n this.requestLog.push({\n channel: name,\n action,\n correlationId: typeof record.correlationId === 'string' ? record.correlationId : undefined,\n retryKey: retryKeyOf(name, record),\n });\n\n if (action.kind === 'reject-emit') {\n // Models a /bus/emit 4xx: the request never reaches the bus.\n throw new Error(`FaultyTransport: emit rejected by schedule (reject-emit) on ${name}`);\n }\n\n // The request itself is observable (handlers-eye view), then the\n // simulator plays backend: synthesize the registry reply per the action.\n this.bus.get(channel).next(payload);\n\n const reply = (): void => {\n if (this.disposed) return;\n const response = this.makeResponse(name, record);\n const replyPayload = response === undefined\n ? { correlationId: record.correlationId }\n : { correlationId: record.correlationId, response };\n const resultChannel = BUS_OPERATIONS[name].result as keyof EventMap;\n this.bus.get(resultChannel).next(replyPayload as EventMap[keyof EventMap]);\n };\n\n switch (action.kind) {\n case 'deliver':\n queueMicrotask(reply);\n break;\n case 'duplicate-reply':\n queueMicrotask(reply);\n queueMicrotask(reply);\n break;\n case 'delay': {\n const t = setTimeout(() => { this.timers.delete(t); reply(); }, action.ms);\n this.timers.add(t);\n break;\n }\n case 'drop-reply':\n break;\n }\n }\n\n on<K extends keyof EventMap>(channel: K, handler: (payload: EventMap[K]) => void): () => void {\n const sub = this.bus.get(channel).subscribe(handler);\n return () => sub.unsubscribe();\n }\n\n stream<K extends keyof EventMap>(channel: K): Observable<EventMap[K]> {\n return this.bus.get(channel);\n }\n\n subscribeToResource(rid: ResourceId): () => void {\n const scope = rid as string;\n if (this.scopeModel === 'single-slot-throw' && this.activeScope !== null && this.activeScope !== scope) {\n // Mirrors HttpTransport's one-distinct-scope-at-a-time contention throw.\n throw new Error(\n `FaultyTransport: scope slot busy (${this.activeScope}); ` +\n `unsubscribe before subscribing to ${scope} (scopeModel=single-slot-throw)`,\n );\n }\n this.activeScope = this.activeScope ?? scope;\n this.scopeRefs += 1;\n let released = false;\n return () => {\n if (released) return;\n released = true;\n this.scopeRefs -= 1;\n if (this.scopeRefs === 0) this.activeScope = null;\n };\n }\n\n bridgeInto(bus: EventBus): void {\n for (const channel of BRIDGED_CHANNELS) {\n this.bus.get(channel as keyof EventMap).subscribe((payload) => {\n bus.get(channel as keyof EventMap).next(payload as EventMap[keyof EventMap]);\n });\n }\n }\n\n // ── Lifecycle ───────────────────────────────────────────────────────────\n\n dispose(): void {\n if (this.disposed) return;\n this.disposed = true;\n for (const t of this.timers) clearTimeout(t);\n this.timers.clear();\n this.state$.next('closed');\n this.state$.complete();\n this.errorsSubject.complete();\n // Completes every subject: in-flight busRequests resolve `bus.closed`.\n this.bus.destroy();\n }\n}\n","/**\n * Executable enforcement of the liveness axioms — the runtime twin of\n * `.plans/LIVENESS-AXIOMS.md`, and the composition-level sibling of\n * `assertStateUnitAxioms` (state-unit-axioms.ts). Where the StateUnit axioms\n * make *per-unit* wrongness mechanically detectable, these make *silence*\n * detectable: every existing enforcement tier is safety (nothing wrong is\n * delivered); these assert liveness (something is eventually delivered).\n *\n * Axioms (fault-schedule dimension; fast-check):\n * L1 Subscriber liveness — every output emits next|error within the bound,\n * under any fault schedule. Error is a permitted outcome; the forbidden\n * fourth state is pending-forever.\n * L2 Request settlement — every awaited path settles within the bound;\n * re-issues per logical request stay within the retry budget (B14: one);\n * a faulted request must be re-issued or surfaced, never swallowed.\n * L3 Delivery across lifecycle transitions — every event written to a live\n * connection reaches the output exactly once, wherever a client-initiated\n * transition (handover / reconnect / scope change) lands. Retirement is\n * by drain, never by abort (TRANSPORT-HTTP.md, Abort discipline).\n *\n * Framework-agnostic on purpose — only `rxjs` + `fast-check`, no `vitest` — so\n * it ships through `@semiont/core/testing` and any package's test runner can\n * invoke it. Deterministic virtual time: properties pass a small explicit\n * `timeoutMs` to `busRequest`; no `Date.now`, no 30 s real waits.\n */\n\nimport * as fc from 'fast-check';\nimport type { Observable, Subscription } from 'rxjs';\nimport { FaultyTransport, type FaultAction, type ScopeModel } from './faulty-transport';\n\n// ── L1/L2: liveness over a composition on FaultyTransport ────────────────\n\n/** What one fresh run of the composition exposes to the axioms. */\nexport interface LivenessScenario {\n /**\n * Live-query-shaped outputs. The harness subscribes each one; every\n * subscription must see `next` or `error` within the bound (L1).\n */\n outputs: readonly Observable<unknown>[];\n /**\n * Awaited paths. Each promise must settle — resolve or reject — within the\n * bound (L2). Rejections are fine; pending-forever is the violation.\n */\n settlements?: readonly Promise<unknown>[];\n teardown?: () => void;\n}\n\nexport interface LivenessAxiomSpec {\n /** Build a FRESH composition wired to the given transport. Called per run. */\n setup: (transport: FaultyTransport) => LivenessScenario | Promise<LivenessScenario>;\n /**\n * The timeoutMs the scenario passes to `busRequest` — the bound is derived\n * from it: (timeoutMs × (1 + retryBudget) + Σdelays) × slackFactor.\n */\n timeoutMs: number;\n /** Max sanctioned re-issues per logical request (B14 budget). Default 1. */\n retryBudget?: number;\n /** Override the generated fault schedules (teeth tests pin one). */\n scheduleArb?: fc.Arbitrary<readonly FaultAction[]>;\n /** Scope model(s) to run under. Default `'single-slot-throw'`. */\n scopeModel?: ScopeModel | 'both';\n /** Passed through to FaultyTransport (reply synthesis). */\n makeResponse?: (operation: string, payload: Record<string, unknown>) => unknown;\n /** fast-check run budget (default 25 — CI-fast; crank locally). */\n numRuns?: number;\n /** Real-scheduler jitter headroom on the bound (default 4×). */\n slackFactor?: number;\n}\n\n/** The five wire behaviors, uniformly weighted; delays stay small (≤5 ms). */\nexport function arbFaultAction(): fc.Arbitrary<FaultAction> {\n return fc.oneof(\n fc.constant<FaultAction>({ kind: 'deliver' }),\n fc.constant<FaultAction>({ kind: 'drop-reply' }),\n fc.integer({ min: 0, max: 5 }).map((ms): FaultAction => ({ kind: 'delay', ms })),\n fc.constant<FaultAction>({ kind: 'duplicate-reply' }),\n fc.constant<FaultAction>({ kind: 'reject-emit' }),\n );\n}\n\nexport function arbFaultSchedule(maxLength = 8): fc.Arbitrary<readonly FaultAction[]> {\n return fc.array(arbFaultAction(), { minLength: 1, maxLength });\n}\n\nfunction describeSchedule(schedule: readonly FaultAction[]): string {\n return schedule.map((a) => (a.kind === 'delay' ? `delay(${a.ms})` : a.kind)).join(',');\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Sibling of state-unit-axioms' `run`, adapted for properties that check more\n * than one axiom: fast-check's falsification message carries the seed and\n * counterexample but not the thrown axiom id (fc v4 moves the inner error to\n * `cause`), so the property captures its own labeled violation into `slot`\n * and the wrapper re-throws with the axiom id leading and fc's detail after.\n */\nasync function runLabeled(\n fallback: string,\n slot: { violation: Error | null },\n assertion: () => Promise<void>,\n): Promise<void> {\n try {\n await assertion();\n } catch (e) {\n const detail = e instanceof Error ? e.message : String(e);\n if (slot.violation) throw new Error(`${slot.violation.message}\\n${detail}`);\n throw new Error(`${fallback}: ${detail}`);\n }\n}\n\n/** Wrap a check block so its labeled throw lands in `slot` before falsifying. */\nfunction capturing(slot: { violation: Error | null }, block: () => void): void {\n try {\n block();\n } catch (e) {\n slot.violation = e instanceof Error ? e : new Error(String(e));\n throw e;\n }\n}\n\n/**\n * Run L1 + L2 against `spec` across generated fault schedules. Throws a\n * labeled Error (`L1: …` / `L2: …`) on the first violation.\n */\nexport async function assertLivenessAxioms(spec: LivenessAxiomSpec): Promise<void> {\n const retryBudget = spec.retryBudget ?? 1;\n const slack = spec.slackFactor ?? 4;\n const scheduleArb = spec.scheduleArb ?? arbFaultSchedule();\n const scopeArb: fc.Arbitrary<ScopeModel> =\n spec.scopeModel === 'both'\n ? fc.constantFrom<ScopeModel>('single-slot-throw', 'multi')\n : fc.constant(spec.scopeModel ?? 'single-slot-throw');\n\n const slot = { violation: null as Error | null };\n await runLabeled('liveness', slot, () =>\n fc.assert(\n fc.asyncProperty(scheduleArb, scopeArb, async (schedule, scopeModel) => {\n const delayTotal = schedule.reduce((n, a) => n + (a.kind === 'delay' ? a.ms : 0), 0);\n const bound = (spec.timeoutMs * (1 + retryBudget) + delayTotal) * slack;\n const transport = new FaultyTransport({\n schedule,\n scopeModel,\n ...(spec.makeResponse ? { makeResponse: spec.makeResponse } : {}),\n });\n const scenario = await spec.setup(transport);\n const outputs = scenario.outputs;\n const settlements = scenario.settlements ?? [];\n\n // Subscribe every output (that's what makes a live query live) and\n // track notifications; track settlement of every awaited path.\n const notified: boolean[] = outputs.map(() => false);\n const settled: boolean[] = settlements.map(() => false);\n let doneResolve: () => void = () => {};\n const allDone = new Promise<void>((resolve) => { doneResolve = resolve; });\n const check = (): void => {\n if (notified.every(Boolean) && settled.every(Boolean)) doneResolve();\n };\n const subs: Subscription[] = outputs.map((o, i) =>\n o.subscribe({\n next: () => { notified[i] = true; check(); },\n error: () => { notified[i] = true; check(); },\n }),\n );\n settlements.forEach((p, i) => {\n p.then(() => { settled[i] = true; check(); },\n () => { settled[i] = true; check(); });\n });\n check();\n\n // Wait for full liveness or the bound, whichever first.\n await Promise.race([allDone, sleep(bound)]);\n\n try {\n // L2 first: when it applies it names the mechanism (swallow, budget,\n // unsettled await); L1 below is the broader every-output net. All-\n // outputs-silent is a subset of any-output-silent, so checking L1\n // first would shadow the sharper L2 diagnoses entirely.\n capturing(slot, () => {\n // L2 — settlement: every awaited path settled.\n settled.forEach((seen, i) => {\n if (!seen) {\n throw new Error(\n `L2: settlement #${i} did not settle within ${bound}ms ` +\n `under schedule ⟨${describeSchedule(schedule)}⟩ — the forbidden fourth state`,\n );\n }\n });\n\n // L2 — retry accounting over the transport's request log.\n const issues = new Map<string, { count: number; lastFaulted: boolean }>();\n for (const entry of transport.requestLog) {\n const prior = issues.get(entry.retryKey) ?? { count: 0, lastFaulted: false };\n issues.set(entry.retryKey, {\n count: prior.count + 1,\n lastFaulted: entry.action.kind === 'drop-reply' || entry.action.kind === 'reject-emit',\n });\n }\n for (const [key, { count, lastFaulted }] of issues) {\n if (count > 1 + retryBudget) {\n throw new Error(\n `L2: request ⟨${key}⟩ issued ${count} times — exceeds the retry budget ` +\n `(1 + ${retryBudget}) under schedule ⟨${describeSchedule(schedule)}⟩`,\n );\n }\n // Swallow detection: the final issue of a logical request was\n // faulted, the composition had retry budget left but didn't use\n // it, and no output surfaced anything — the rejection went into\n // a void (the pre-B14 `catch(() => {})`).\n if (lastFaulted && count <= retryBudget && outputs.length > 0 && !notified.some(Boolean)) {\n throw new Error(\n `L2: faulted request ⟨${key}⟩ was neither re-issued nor surfaced ` +\n `under schedule ⟨${describeSchedule(schedule)}⟩ — rejection swallowed`,\n );\n }\n }\n\n // L1 — every subscription saw next|error; pending-forever is the bug.\n notified.forEach((seen, i) => {\n if (!seen) {\n throw new Error(\n `L1: output #${i} received no next/error within ${bound}ms ` +\n `under schedule ⟨${describeSchedule(schedule)}⟩ (scope=${scopeModel}) — silently pending`,\n );\n }\n });\n });\n } finally {\n subs.forEach((s) => s.unsubscribe());\n scenario.teardown?.();\n transport.dispose();\n }\n }),\n { numRuns: spec.numRuns ?? 25 },\n ),\n );\n}\n\n// ── L3: exactly-once delivery across client-initiated transitions ────────\n\n/**\n * A connection-stream-shaped subject: something that accepts writes to the\n * live connection, can be told to transition (handover / reconnect / scope\n * change), and exposes the subscriber-facing output. P3 adapts the real\n * actor's mock-connection harness to this shape; the teeth tests drive\n * reconstructed pre-fix doubles.\n */\nexport interface DeliverySubject {\n /** Write the event with this id to the currently-live connection. */\n write: (eventId: string) => void;\n /** Client-initiated lifecycle transition. */\n transition: () => void | Promise<void>;\n /** Subscriber-facing output; each emission is a delivered event id. */\n output$: Observable<string>;\n /**\n * Drain pending asynchronous delivery at end of sequence (a live connection\n * eventually flushes). Default: one macrotask tick.\n */\n settle?: () => Promise<void>;\n teardown?: () => void;\n}\n\nexport type DeliveryOp = 'write' | 'transition';\n\nexport interface DeliveryAxiomSpec {\n /** Build a FRESH subject. Called per run. */\n setup: () => DeliverySubject;\n /** Override the generated op sequences (teeth tests pin one). */\n opsArb?: fc.Arbitrary<readonly DeliveryOp[]>;\n /** Max generated sequence length (default 12). */\n maxOps?: number;\n /** fast-check run budget (default 50 — these runs are cheap). */\n numRuns?: number;\n}\n\nexport function arbDeliveryOps(maxOps = 12): fc.Arbitrary<readonly DeliveryOp[]> {\n return fc\n .array(fc.constantFrom<DeliveryOp>('write', 'transition'), { minLength: 1, maxLength: maxOps })\n // A sequence with no write asserts nothing — always exercise delivery.\n .map((ops) => (ops.includes('write') ? ops : ([...ops, 'write'] as const)));\n}\n\n/**\n * Run L3 against `spec` across generated write/transition interleavings.\n * Throws a labeled Error (`L3: …`) on the first violation: an event written\n * to a live connection delivered zero times (lost — retired by abort instead\n * of drain) or more than once (duplicate).\n */\nexport async function assertExactlyOnceDelivery(spec: DeliveryAxiomSpec): Promise<void> {\n const opsArb = spec.opsArb ?? arbDeliveryOps(spec.maxOps ?? 12);\n\n const slot = { violation: null as Error | null };\n await runLabeled('L3', slot, () =>\n fc.assert(\n fc.asyncProperty(opsArb, async (ops) => {\n const subject = spec.setup();\n const delivered: string[] = [];\n const sub = subject.output$.subscribe((id) => delivered.push(id));\n const written: string[] = [];\n try {\n for (let i = 0; i < ops.length; i++) {\n if (ops[i] === 'write') {\n const id = `e${i}`;\n written.push(id);\n subject.write(id);\n } else {\n await subject.transition();\n }\n // Deliberately no settling between ops: the interesting races are\n // transitions landing before a write's asynchronous delivery.\n }\n await (subject.settle?.() ?? sleep(0));\n\n capturing(slot, () => {\n for (const id of written) {\n const n = delivered.filter((d) => d === id).length;\n if (n === 0) {\n throw new Error(\n `L3: event ⟨${id}⟩ delivered 0 times under ⟨${ops.join(',')}⟩ — ` +\n `lost across a transition (retire by drain, never by abort)`,\n );\n }\n if (n > 1) {\n throw new Error(\n `L3: event ⟨${id}⟩ delivered ${n} times under ⟨${ops.join(',')}⟩ — duplicate delivery`,\n );\n }\n }\n });\n } finally {\n sub.unsubscribe();\n subject.teardown?.();\n }\n }),\n { numRuns: spec.numRuns ?? 50 },\n ),\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semiont/core",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
4
4
  "description": "Core types and domain logic for Semiont - Resource, Annotation, and Graph models",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -71,7 +71,7 @@
71
71
  "rollup": "^4.61.0",
72
72
  "rollup-plugin-dts": "^6.4.1",
73
73
  "tsup": "^8.5.1",
74
- "tsx": "^4.22.4",
74
+ "tsx": "^4.22.5",
75
75
  "typescript": "^6.0.2",
76
76
  "vitest": "^4.1.8"
77
77
  },