Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test([med-canon-server-services-canonusage-js-zero-test]): tighten kind-routing test scope + fix changelog field count
[._.]/ Adam Eivyf1f502cd1cd3
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 36385c78a9..f72e57e39c 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,7 @@## Changed-- **[med-canon-server-services-canonusage-js-zero-test] `getUniverseCanonUsage` heavy-endpoint contract now pinned.** `server/services/canonUsage.test.js` previously only covered `seriesNameMap`/`seriesCount` and the thin `listLinkedSeriesNames` variant. The per-entry usage rows the comic-panel / canon-card UI consumes — produced by the multi-stage corpus scan + per-(kind, entryId, seriesId) tally + sort at `canonUsage.js:99-132` — had no tests, so the JSDoc-pinned "Appears-in sort: issueCount desc + alpha tiebreaker on seriesName" invariant could regress silently. New `getUniverseCanonUsage entry rows` describe block adds six tests: 404 on missing universe (separate from `listLinkedSeriesNames`' 404 because that variant only translates `ERR_NOT_FOUND` while `getUniverseCanonUsage` re-throws any `getUniverse` error as 404), sort by `issueCount` desc with alpha tiebreaker (`Zeta Tales (1)` < `Alpha Tales (1)` < `Beta Tales (2)` → output order `Beta, Alpha, Zeta`), kind-routing through `matchCharactersInText` / `matchPlacesInText` / `matchObjectsInText`, the corpus-skip path for empty/whitespace issues + the `issueCount` "total scanned" contract, the multi-stage corpus aggregation (idea / comicScript / teleplay), and the `Array.isArray(universe[kind])` guard for undefined kinds. 11/11 tests in the file pass; 6169/6169 server tests pass. `[cover-prose-input-idea-input-in-canonusage-corpus]` captured as a follow-up — the multi-stage corpus test seeds 3 of the 6 fields `corpusForIssue` aggregates (`idea.output`, `comicScript.output`, `teleplay.output` + the implicit `prose.output` from sibling tests); a regression that drops `prose.input` or `idea.input` from the corpus list would still slip past the suite.+- **[med-canon-server-services-canonusage-js-zero-test] `getUniverseCanonUsage` heavy-endpoint contract now pinned.** `server/services/canonUsage.test.js` previously only covered `seriesNameMap`/`seriesCount` and the thin `listLinkedSeriesNames` variant. The per-entry usage rows the comic-panel / canon-card UI consumes — produced by the multi-stage corpus scan + per-(kind, entryId, seriesId) tally + sort at `canonUsage.js:99-132` — had no tests, so the JSDoc-pinned "Appears-in sort: issueCount desc + alpha tiebreaker on seriesName" invariant could regress silently. New `getUniverseCanonUsage entry rows` describe block adds six tests: 404 on missing universe (separate from `listLinkedSeriesNames`' 404 because that variant only translates `ERR_NOT_FOUND` while `getUniverseCanonUsage` re-throws any `getUniverse` error as 404), sort by `issueCount` desc with alpha tiebreaker (`Zeta Tales (1)` < `Alpha Tales (1)` < `Beta Tales (2)` → output order `Beta, Alpha, Zeta`), kind-routing through `matchCharactersInText` / `matchPlacesInText` / `matchObjectsInText`, the corpus-skip path for empty/whitespace issues + the `issueCount` "total scanned" contract, the multi-stage corpus aggregation (idea / comicScript / teleplay), and the `Array.isArray(universe[kind])` guard for undefined kinds. 11/11 tests in the file pass; 6169/6169 server tests pass. `[cover-prose-input-idea-input-in-canonusage-corpus]` captured as a follow-up — across the new block + sibling tests, 4 of the 6 fields `corpusForIssue` aggregates are covered (`prose.output` via sibling tests; `idea.output` / `comicScript.output` / `teleplay.output` via the multi-stage corpus test). `prose.input` and `idea.input` aren't seeded by any test, so a regression that drops either from the corpus list would still slip past the suite.- **[add-emitrunstarted-hook-shape-test-to-runner] Pin `emitRunStarted` payload-flattening contract in `server/services/runner.test.js`.** The `provider?.name || provider?.id` and `model ?? provider?.defaultModel` fallbacks in `runner.js:198-204` previously had zero direct coverage — `tuiPromptRunner.js`'s PTY tests mock `emitRunStarted` itself, so a regression that dropped the `name` preference or flipped the model fallback from `??` to `||` (silently rewriting an intentionally-empty model to `defaultModel`) would have slipped past every test. New `describe('emitRunStarted — payload-flattening contract')` block in `runner.test.js` exports `emitRunStarted` from the module under test, registers a `runnerConfig.hooks.onRunStarted` mock via `setAIToolkit(fakeToolkit(), { hooks })`, and asserts the hook payload across 8 cases: `name`-preferred-over-`id`, `id` fallback when `name` is absent, explicit `model` overriding `defaultModel`, `defaultModel` fallback when `model` is `undefined`, `defaultModel` fallback when `model` is `null` (`??` semantics), empty-string `model` preserved (guards against a `||` regression), `provider: undefined` → both fields `undefined`, and the no-op path when no hook is registered. 43/43 runner tests pass (35 prior + 8 new).diff --git a/server/services/canonUsage.test.js b/server/services/canonUsage.test.jsindex 404ed6fef4..f8d78d1925 100644--- a/server/services/canonUsage.test.js+++ b/server/services/canonUsage.test.js@@ -147,7 +147,7 @@ describe('canonUsage — getUniverseCanonUsage entry rows', () => {expect(usage.issueCount).toBe(4);});- it('routes each kind through its dedicated matcher (characters/places/objects)', async () => {+ it('buckets matched entries under each kind\'s output key (characters/places/objects)', async () => {mockUniverses.set('uni-1', {id: 'uni-1',characters: [{ id: 'char-1', name: 'Lyra' }],@@ -156,9 +156,15 @@ describe('canonUsage — getUniverseCanonUsage entry rows', () => {});mockSeriesList.push({ id: 'ser-1', name: 'Series One', universeId: 'uni-1' });mockIssuesBySeries.set('ser-1', [- // One issue mentioning all three so we can prove each matcher wires to- // the right universe field (a swap between places/objects would put the- // entry under the wrong key).+ // One issue mentioning all three pins (a) that the iteration over+ // `Object.keys(MATCHERS)` covers all 3 kinds and (b) that each kind's+ // matches land in the correctly-named `usage[kind]` output bucket. A+ // refactor that dropped one of the three from the loop, or that wrote+ // `usage.locations` instead of `usage.places`, would fail here. (This+ // test does NOT verify the per-matcher *behavior* — alias-aware vs+ // name-only — because all three seeded names are unique to their kind;+ // matcher-function swaps would still pass. Behavior coverage belongs+ // in `scenePrompt.test.js` against the matchers directly.){ id: 'iss-1', stages: { prose: { output: 'Lyra walked through Thornwood holding a Lantern.' } } },]);