|
| 1 | +/** |
| 2 | + * The manifest carries the html tier's intrinsic elements marked |
| 3 | + * `tier: 'html'` — the objectui#10735 mechanism, ported into this copy in |
| 4 | + * lockstep (objectstack#20112). |
| 5 | + * |
| 6 | + * objectui's `getPublicConfigs()` stamps the html tier's registered intrinsic |
| 7 | + * set `tier: 'html'` in its projection, and the tracked repo-root |
| 8 | + * `sdui.manifest.json` is serialised through THIS copy's `manifestFromConfigs` |
| 9 | + * (`scripts/gen-sdui-manifest-node.mjs`). Before the port this copy's |
| 10 | + * `RegistryConfigLike.tier` admitted only `'public' | 'internal'` and the |
| 11 | + * serializer dropped the key, so the manifest declared the html tier's tags |
| 12 | + * with no marker at all. `check:sdui-lockstep` compares diagnostic codes, the grammar |
| 13 | + * region and the containment predicate — never a type union — so nothing |
| 14 | + * surfaced the drift. |
| 15 | + * |
| 16 | + * The cases below are the ones objectui pins in its own |
| 17 | + * `html-tier-manifest-10735.test.ts`, one per reader of the ONE flat |
| 18 | + * `components` map: |
| 19 | + * |
| 20 | + * - `manifestFromConfigs` copies exactly `'html'` and nothing else, so every |
| 21 | + * curated entry serialises byte-identically to before the key existed; |
| 22 | + * - `compile` whitelists the html tags by key — the gate that reads the |
| 23 | + * manifest needs no change — and still refuses `<div>` because the roster |
| 24 | + * leaves it out; |
| 25 | + * - `generateBlockList` sections the html tier under its own count instead |
| 26 | + * of reading it as curated blocks; |
| 27 | + * - `generateDts` emits the tags into `JSX.IntrinsicElements`, which is the |
| 28 | + * authoring surface a `kind:'html'` page type-checks against. |
| 29 | + */ |
| 30 | + |
| 31 | +import { describe, expect, it } from 'vitest'; |
| 32 | +import { compile, generateBlockList, generateDts, manifestFromConfigs, type RegistryConfigLike } from '../index.js'; |
| 33 | + |
| 34 | +const configs: RegistryConfigLike[] = [ |
| 35 | + { type: 'flex', namespace: 'ui', isContainer: true, inputs: [{ name: 'gap', type: 'number' }, { name: 'children', type: 'slot' }] }, |
| 36 | + { type: 'my-widget', namespace: 'x', tier: 'public', inputs: [{ name: 'label', type: 'string' }] }, |
| 37 | + { type: 'studio-admin', namespace: 'app-shell', tier: 'internal', inputs: [] }, |
| 38 | + { type: 'p', namespace: 'ui', tier: 'html', inputs: [{ name: 'className', type: 'string' }, { name: 'children', type: 'slot' }] }, |
| 39 | + { type: 'a', namespace: 'ui', tier: 'html', inputs: [{ name: 'className', type: 'string' }, { name: 'href', type: 'string' }, { name: 'children', type: 'slot' }] }, |
| 40 | + { type: 'img', namespace: 'ui', tier: 'html', inputs: [{ name: 'src', type: 'string' }, { name: 'alt', type: 'string' }] }, |
| 41 | + { type: 'main', namespace: 'ui', tier: 'html', isContainer: true, inputs: [{ name: 'className', type: 'string' }, { name: 'children', type: 'slot' }] }, |
| 42 | +]; |
| 43 | + |
| 44 | +const manifest = manifestFromConfigs(configs); |
| 45 | +/** What a consumer reads back off disk — `JSON.stringify` drops every `undefined`. */ |
| 46 | +const published = JSON.parse(JSON.stringify(manifest)) as typeof manifest; |
| 47 | + |
| 48 | +describe('manifestFromConfigs carries the html-tier stamp, and only that stamp', () => { |
| 49 | + it('writes `tier: html` on a stamped config', () => { |
| 50 | + for (const tag of ['p', 'a', 'img', 'main']) { |
| 51 | + expect(published.components[tag].tier, `${tag} lost its stamp`).toBe('html'); |
| 52 | + } |
| 53 | + }); |
| 54 | + |
| 55 | + it('publishes NO `tier` key for a curated, an opted-in or an internal config — byte-identical to before', () => { |
| 56 | + for (const tag of ['flex', 'my-widget', 'studio-admin']) { |
| 57 | + expect(Object.prototype.hasOwnProperty.call(published.components[tag], 'tier'), `${tag} grew a tier key`).toBe(false); |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + it('keeps every other field exactly as the registration declared it', () => { |
| 62 | + expect(published.components.a.inputs.map((i) => i.name)).toEqual(['className', 'href', 'children']); |
| 63 | + expect(published.components.main.isContainer).toBe(true); |
| 64 | + expect(published.components.img.inputs.map((i) => i.name)).toEqual(['src', 'alt']); |
| 65 | + }); |
| 66 | + |
| 67 | + it('`publicOnly` keeps the curated tier alone — the html tier is not `public`', () => { |
| 68 | + expect(Object.keys(manifestFromConfigs(configs, { publicOnly: true }).components)).toEqual(['my-widget']); |
| 69 | + }); |
| 70 | +}); |
| 71 | + |
| 72 | +describe('compile reads the manifest as a whitelist — the stamp changes nothing for that reader', () => { |
| 73 | + it('accepts an html-tier tag with its declared inputs and child slot', () => { |
| 74 | + const r = compile('<main className="x"><p className="lead">Hello <a href="/docs">docs</a></p><img src="/x.png" alt="x" /></main>', published); |
| 75 | + expect(r.diagnostics.filter((d) => d.severity === 'error')).toEqual([]); |
| 76 | + expect(r.ok).toBe(true); |
| 77 | + expect(r.tree?.type).toBe('main'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('refuses `<div>` — the roster leaves it out, so it is `forbidden-tag` like any unknown tag', () => { |
| 81 | + const r = compile('<main><div>hi</div></main>', published); |
| 82 | + expect(r.ok).toBe(false); |
| 83 | + expect(r.diagnostics).toEqual( |
| 84 | + expect.arrayContaining([expect.objectContaining({ severity: 'error', code: 'forbidden-tag', tag: 'div' })]), |
| 85 | + ); |
| 86 | + // The lit control: the same source with `p` in place of `div` is clean. |
| 87 | + expect(compile('<main><p>hi</p></main>', published).ok).toBe(true); |
| 88 | + }); |
| 89 | + |
| 90 | + it('warns `not-a-container` on a void tag authored with children — the slot is declared per tag, honestly', () => { |
| 91 | + const r = compile('<main><img src="/x.png" alt="x">stray</img></main>', published); |
| 92 | + expect(r.diagnostics).toEqual( |
| 93 | + expect.arrayContaining([expect.objectContaining({ severity: 'warning', code: 'not-a-container', tag: 'img' })]), |
| 94 | + ); |
| 95 | + }); |
| 96 | +}); |
| 97 | + |
| 98 | +describe('generateBlockList sections the html tier under its own count', () => { |
| 99 | + it('counts curated blocks in the title and lists the html tier separately', () => { |
| 100 | + const list = generateBlockList(published); |
| 101 | + // Curated title counts `flex`, `my-widget`, `studio-admin` — not the four html-tier rows. |
| 102 | + expect(list).toContain('# SDUI public blocks (3)'); |
| 103 | + expect(list).toContain('## html tier intrinsic elements (4)'); |
| 104 | + // Rows land in the right section: the html rows come AFTER the section heading. |
| 105 | + const heading = list.indexOf('## html tier intrinsic elements'); |
| 106 | + for (const tag of ['p', 'a', 'img', 'main']) { |
| 107 | + expect(list.indexOf(`| \`${tag}\` |`), `${tag} row is missing or above the html section`).toBeGreaterThan(heading); |
| 108 | + } |
| 109 | + for (const tag of ['flex', 'my-widget']) { |
| 110 | + expect(list.indexOf(`| \`${tag}\` |`), `${tag} row landed in the html section`).toBeLessThan(heading); |
| 111 | + } |
| 112 | + }); |
| 113 | + |
| 114 | + it('emits no html section for a manifest without html-tier entries — the curated list is unchanged', () => { |
| 115 | + const curatedOnly = manifestFromConfigs(configs.filter((c) => c.tier !== 'html')); |
| 116 | + const list = generateBlockList(curatedOnly); |
| 117 | + expect(list).toContain('# SDUI public blocks (3)'); |
| 118 | + expect(list).not.toContain('html tier intrinsic elements'); |
| 119 | + }); |
| 120 | +}); |
| 121 | + |
| 122 | +describe('generateDts publishes the html tier into JSX.IntrinsicElements', () => { |
| 123 | + it('emits an interface and an intrinsic entry per html-tier tag, beside the curated ones', () => { |
| 124 | + const dts = generateDts(published); |
| 125 | + expect(dts).toContain('"p": PProps;'); |
| 126 | + expect(dts).toContain('"a": AProps;'); |
| 127 | + expect(dts).toContain('export interface AProps extends SduiBaseProps {\n className?: string;\n href?: string;\n}'); |
| 128 | + expect(dts).toContain('"flex": FlexProps;'); |
| 129 | + }); |
| 130 | +}); |
0 commit comments