|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * Pin for the root `content/docs/references/meta.json` category filter — WHICH |
| 5 | + * categories reach the sidebar (#11482). |
| 6 | + * |
| 7 | + * THE DEFECT THIS PINS. `build-docs.ts` §3 built the root `meta.json`'s |
| 8 | + * category list from `categoryZodFiles` — the `.zod.ts` files found on disk — |
| 9 | + * a THIRD enumeration of "the pages of this category", independent of both the |
| 10 | + * category's own `meta.json` (§2) and its card grid (§2.5, fixed by #11260 to |
| 11 | + * read the same declared list §2 wrote). A category whose published pages all |
| 12 | + * come from plain `.ts` files (the `misc` catch-all class — `security/misc` |
| 13 | + * proves the shape) has zero `.zod.ts` files while still publishing a page, so |
| 14 | + * the old filter dropped it from the sidebar even though it was fully |
| 15 | + * generated and routed everywhere else. |
| 16 | + * |
| 17 | + * WHY A UNIT TEST, rather than the regenerated root `meta.json` alone. Same |
| 18 | + * two reasons #11260's `category-index.test.ts` gives for the card grid: |
| 19 | + * |
| 20 | + * - the defect's output is an ABSENT sidebar entry. `check:docs` compares |
| 21 | + * generated output to committed output, so a category that was never |
| 22 | + * emitted into `pages` is green forever; |
| 23 | + * - the edge this exists to catch — a category with pages but NO `.zod.ts` |
| 24 | + * file at all — HAS NO INSTANCE in the repo today (measured on |
| 25 | + * `origin/main`: all 14 categories have `zodFiles.size > 0`), so no |
| 26 | + * generated artifact can pin it in either direction. Asserting on a |
| 27 | + * category that does not exist requires the rule out of the side-effecting |
| 28 | + * script. |
| 29 | + */ |
| 30 | + |
| 31 | +import { describe, expect, it } from 'vitest'; |
| 32 | + |
| 33 | +import { rootCategoryDirs } from './lib/root-meta'; |
| 34 | + |
| 35 | +describe('rootCategoryDirs — which categories reach the root sidebar (#11482)', () => { |
| 36 | + it('includes an all-misc category — no `.zod.ts` files, but it published a page', () => { |
| 37 | + // The exact latent shape #11482 named: a category whose every published |
| 38 | + // schema falls to the catch-all bucket, so `categoryZodFiles` would record |
| 39 | + // zero files for it while `categoryMetaPages` (built from the pages §2 |
| 40 | + // actually emitted) still holds `['misc']`. |
| 41 | + const metaPages = new Map([['ghost', ['misc']]]); |
| 42 | + |
| 43 | + expect(rootCategoryDirs(['ghost'], metaPages)).toEqual(['ghost']); |
| 44 | + }); |
| 45 | + |
| 46 | + it('excludes a category that published no page', () => { |
| 47 | + // §2 writes no `meta.json` for a category with zero pages, so |
| 48 | + // `categoryMetaPages` has no entry for it — the same "no meta.json ⇒ |
| 49 | + // absent" discipline the map already documents at its declaration site. |
| 50 | + const metaPages = new Map<string, string[]>(); |
| 51 | + |
| 52 | + expect(rootCategoryDirs(['contracts'], metaPages)).toEqual([]); |
| 53 | + }); |
| 54 | + |
| 55 | + it('sorts the result alphabetically, independent of input or map order', () => { |
| 56 | + const metaPages = new Map([ |
| 57 | + ['zebra', ['a']], |
| 58 | + ['alpha', ['b']], |
| 59 | + ]); |
| 60 | + |
| 61 | + expect(rootCategoryDirs(['zebra', 'alpha'], metaPages)).toEqual(['alpha', 'zebra']); |
| 62 | + }); |
| 63 | + |
| 64 | + it('reproduces the real 14-category shape unchanged (#11482 "Measured")', () => { |
| 65 | + // Every category on `origin/main` today has both `.zod.ts` files AND |
| 66 | + // declared pages, so the old (`.zod.ts`-keyed) and new (`meta.json`-keyed) |
| 67 | + // filters agree on all 14 — the byte-identical root `meta.json` the issue |
| 68 | + // itself measured, and the acceptance bar this fix must not move. |
| 69 | + const categories = [ |
| 70 | + 'ai', 'api', 'automation', 'cloud', 'data', 'identity', 'integration', |
| 71 | + 'kernel', 'qa', 'security', 'shared', 'studio', 'system', 'ui', |
| 72 | + ]; |
| 73 | + const metaPages = new Map(categories.map(c => [c, ['some-page']])); |
| 74 | + |
| 75 | + expect(rootCategoryDirs(categories, metaPages)).toEqual([...categories].sort()); |
| 76 | + }); |
| 77 | +}); |
0 commit comments