|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | +// |
| 3 | +// A name-keyed `pages:` map reaches the four source-page lints (#15728). |
| 4 | +// |
| 5 | +// ## What was vacuous, and why it read as green |
| 6 | +// |
| 7 | +// `pages` is an authoring surface with TWO carriers. `MAP_SUPPORTED_FIELDS` |
| 8 | +// (`packages/spec/src/shared/metadata-collection.zod.ts`) lists it, and |
| 9 | +// `normalizeStackInput` folds the map into an array — injecting the map key as |
| 10 | +// `name` — BEFORE `ObjectStackDefinitionSchema` sees it, which is why |
| 11 | +// `stack.zod.ts` declares the post-normalization form `z.array(PageSchema)` |
| 12 | +// and a raw map fails a bare `safeParse`. Reading that declaration alone says |
| 13 | +// "map is not authorable", and that reading is wrong. |
| 14 | +// |
| 15 | +// These four rules are pure `(stack) => Finding[]` (ADR-0019) and run on the |
| 16 | +// RAW `os lint` path as well as the parsed one, so on the raw path they see |
| 17 | +// exactly what the author's file deserialised to — the map. Each of them used |
| 18 | +// to coerce it with a private |
| 19 | +// `(v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : [])`, which |
| 20 | +// answers a map with `[]`. So every page lint below passed on a map-shaped |
| 21 | +// stack by never running: no finding, no error, nothing to notice. That is the |
| 22 | +// failure mode this file exists to keep closed — a lint whose green means it |
| 23 | +// looked, not a lint whose green means it never did. |
| 24 | +// |
| 25 | +// Each case therefore asserts a SPECIFIC rule id and the finding's path. The |
| 26 | +// path is the second half of the fix: `collectionEntries` reports the map key |
| 27 | +// (`pages.home.source`), not a synthetic array index nobody can look up, so |
| 28 | +// the finding stays usable as an edit target on either carrier. |
| 29 | +import { describe, expect, it } from 'vitest'; |
| 30 | +import { validateJsxPages } from './validate-jsx-pages.js'; |
| 31 | +import { validatePageSourceStyling, PAGE_SOURCE_CLASSNAME } from './validate-page-source-styling.js'; |
| 32 | +import { validateReactPageProps, REACT_PAGE_SOURCE_UNPARSEABLE } from './validate-react-page-props.js'; |
| 33 | +import { validateReactPages } from './validate-react-pages.js'; |
| 34 | + |
| 35 | +/** The same page, authored both ways. `home` is the map key and the `name`. */ |
| 36 | +const asMap = (page: Record<string, unknown>) => ({ pages: { home: page } }); |
| 37 | +const asList = (page: Record<string, unknown>) => ({ pages: [{ name: 'home', ...page }] }); |
| 38 | + |
| 39 | +describe('a name-keyed `pages:` map reaches every source-page lint (#15728)', () => { |
| 40 | + it('validateReactPages reports the empty source it used to walk past', () => { |
| 41 | + const f = validateReactPages(asMap({ kind: 'react' })); |
| 42 | + expect(f.map((x) => x.rule)).toContain('react-page-empty-source'); |
| 43 | + expect(f.find((x) => x.rule === 'react-page-empty-source')?.path).toBe('pages.home.source'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('validateJsxPages reports the empty source it used to walk past', () => { |
| 47 | + const f = validateJsxPages(asMap({ kind: 'html' })); |
| 48 | + expect(f.map((x) => x.rule)).toContain('jsx-page-empty-source'); |
| 49 | + expect(f.find((x) => x.rule === 'jsx-page-empty-source')?.path).toBe('pages.home.source'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('validatePageSourceStyling reports the Tailwind className it used to walk past', () => { |
| 53 | + const f = validatePageSourceStyling(asMap({ kind: 'react', source: 'function Page(){ return <div className="p-4" />; }' })); |
| 54 | + expect(f.map((x) => x.rule)).toContain(PAGE_SOURCE_CLASSNAME); |
| 55 | + expect(f.find((x) => x.rule === PAGE_SOURCE_CLASSNAME)?.path).toBe('pages.home.source'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('validateReactPageProps reports the unparseable source it used to walk past', () => { |
| 59 | + const wrecked = 'function Page(){\n /* TODO\n return <ObjectForm mode="edit" />;\n}\n'; |
| 60 | + const f = validateReactPageProps(asMap({ kind: 'react', source: wrecked })); |
| 61 | + expect(f.map((x) => x.rule)).toContain(REACT_PAGE_SOURCE_UNPARSEABLE); |
| 62 | + expect(f.find((x) => x.rule === REACT_PAGE_SOURCE_UNPARSEABLE)?.path).toBe('pages.home.source'); |
| 63 | + }); |
| 64 | + |
| 65 | + // The array carrier is the control: the same page authored as a list still |
| 66 | + // reports the same rule at the positional path, so the map cases above are a |
| 67 | + // carrier the rules GAINED and not a path spelling they swapped to. |
| 68 | + it('POSITIVE CONTROL — the list carrier still reports at its positional path', () => { |
| 69 | + const f = validateReactPages(asList({ kind: 'react' })); |
| 70 | + expect(f.map((x) => x.rule)).toContain('react-page-empty-source'); |
| 71 | + expect(f.find((x) => x.rule === 'react-page-empty-source')?.path).toBe('pages[0].source'); |
| 72 | + }); |
| 73 | +}); |
0 commit comments