Skip to content

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

test([med-canon-server-services-canonusage-js-zero-test]): tighten test names + changelog wording per codex iter-1

[._.]/ Adam Eivyd22d8e15c812
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index f72e57e39c..91a6d7bc3b 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 — 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.
+- **[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`), bucket wiring for the three kinds (matches for `characters` / `places` / `objects` each land under their canonically-named `usage[kind]` key — does not pin matcher *behavior*, which lives in `scenePrompt.test.js`), the empty/whitespace-corpus contract (issues still count toward `issueCount` but produce no entry rows), the multi-stage corpus aggregation (idea / comicScript / teleplay), and the empty-bucket return for kinds the universe defines no entries for (also exercises the `Array.isArray(universe[kind])` guard). 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.js
index f8d78d1925..66e662ffde 100644
--- a/server/services/canonUsage.test.js
+++ b/server/services/canonUsage.test.js
@@ -180,7 +180,7 @@ describe('canonUsage — getUniverseCanonUsage entry rows', () => {
]);
});
- it('skips issues with empty / whitespace-only corpus', async () => {
+ it('counts empty/whitespace-corpus issues toward issueCount but excludes them from entry rows', async () => {
mockUniverses.set('uni-1', {
id: 'uni-1',
characters: [{ id: 'char-1', name: 'Lyra' }],
@@ -204,10 +204,13 @@ describe('canonUsage — getUniverseCanonUsage entry rows', () => {
]);
});
- it('aggregates corpus across prose / idea / comicScript / teleplay stages', async () => {
- // A character that only appears in dialogue (comicScript / teleplay) or in
- // the idea blurb must still surface — that's the whole point of the
- // multi-stage corpus assembly in corpusForIssue().
+ it('aggregates corpus across idea / comicScript / teleplay stages', async () => {
+ // A character that only appears in dialogue (comicScript / teleplay) or
+ // in the idea blurb must still surface — that's the whole point of the
+ // multi-stage corpus assembly in corpusForIssue(). `prose.output` is
+ // covered by the other tests in this describe block; the two remaining
+ // corpus fields (`prose.input`, `idea.input`) aren't yet seeded — see
+ // PLAN.md `[cover-prose-input-idea-input-in-canonusage-corpus]`.
mockUniverses.set('uni-1', {
id: 'uni-1',
characters: [
@@ -229,7 +232,7 @@ describe('canonUsage — getUniverseCanonUsage entry rows', () => {
expect(Object.keys(usage.characters).sort()).toEqual(['char-idea', 'char-script', 'char-tele']);
});
- it('omits a kind entirely when the universe has no entries of that kind', async () => {
+ it('returns empty buckets for kinds the universe defines no entries for', async () => {
mockUniverses.set('uni-1', {
id: 'uni-1',
characters: [{ id: 'char-1', name: 'Lyra' }],