|
| 1 | +/** |
| 2 | + * ObjectUI |
| 3 | + * Copyright (c) 2024-present ObjectStack Inc. |
| 4 | + * |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * `@object-ui/layout` has no page-node renderer — the tombstone for |
| 11 | + * objectui#3223. |
| 12 | + * |
| 13 | + * The `page` key belongs to `@object-ui/components`'s `PageRenderer`: it is the |
| 14 | + * one that understands page types (record/home/app/utility), named regions and |
| 15 | + * `PageVariablesProvider`. This package carried a second renderer for the same |
| 16 | + * node (`Page`, renamed `PageNodeRenderer` in objectui#3161 / objectstack#4115 |
| 17 | + * batch 7) that was registered nowhere and imported by nothing — reachable only |
| 18 | + * as a public export. Deleted under ADR-0049 (enforce-or-remove). |
| 19 | + * |
| 20 | + * Why a test and not just the deletion: what made the dead renderer expensive |
| 21 | + * was never its behaviour — it had none, nothing called it — but the claim its |
| 22 | + * mere presence made. A reader (or an AI author) who greps `PageNodeRenderer` |
| 23 | + * and finds it exported from `@object-ui/layout` reasonably concludes that this |
| 24 | + * package is where page rendering lives, and wires a second implementation of a |
| 25 | + * key that already has an owner. Re-adding the export is a one-line change and |
| 26 | + * looks like filling a gap; this file is what turns it into a red test naming |
| 27 | + * the decision to reverse first. |
| 28 | + * |
| 29 | + * Scope, stated honestly: this is a SOURCE-level ban inside this package, not a |
| 30 | + * proof about the composed registry. It cannot tell you which renderer wins at |
| 31 | + * runtime — `packages/components`' own registration tests own that question. |
| 32 | + * What it pins is that `@object-ui/layout` does not re-enter the race. |
| 33 | + */ |
| 34 | + |
| 35 | +import { describe, it, expect } from 'vitest'; |
| 36 | +import { existsSync, readFileSync, readdirSync } from 'node:fs'; |
| 37 | +import { join, resolve } from 'node:path'; |
| 38 | + |
| 39 | +/** `packages/layout/src` — one level up from `src/__tests__`. */ |
| 40 | +const SRC = resolve(__dirname, '..'); |
| 41 | + |
| 42 | +/** Source files that legitimately discuss the removal (this file, and the |
| 43 | + * barrel's note explaining why `page` is not registered here). */ |
| 44 | +const MAY_MENTION = new Set([ |
| 45 | + '__tests__/page-node-renderer-stays-deleted.test.ts', |
| 46 | + '__tests__/spec-symbol-batch7.test.ts', |
| 47 | + 'index.ts', |
| 48 | +]); |
| 49 | + |
| 50 | +/** Every `.ts`/`.tsx` under `src/`, relative to `src/`. */ |
| 51 | +function sourceFiles(dir = SRC, prefix = ''): string[] { |
| 52 | + return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { |
| 53 | + const rel = prefix ? `${prefix}/${entry.name}` : entry.name; |
| 54 | + if (entry.isDirectory()) return sourceFiles(join(dir, entry.name), rel); |
| 55 | + return /\.tsx?$/.test(entry.name) ? [rel] : []; |
| 56 | + }); |
| 57 | +} |
| 58 | + |
| 59 | +describe('the layout page-node renderer stays deleted (objectui#3223)', () => { |
| 60 | + it('has no `./Page` module', () => { |
| 61 | + expect(existsSync(join(SRC, 'Page.tsx'))).toBe(false); |
| 62 | + expect(existsSync(join(SRC, 'Page.ts'))).toBe(false); |
| 63 | + }); |
| 64 | + |
| 65 | + it('does not re-export it from the package barrel', () => { |
| 66 | + const barrel = readFileSync(join(SRC, 'index.ts'), 'utf8'); |
| 67 | + expect(barrel).not.toMatch(/export\s+\*\s+from\s+['"]\.\/Page['"]/); |
| 68 | + // …nor under a named re-export. The barrel's prose may still explain the |
| 69 | + // removal (it does); only an `export { … }` naming it is banned. |
| 70 | + expect(barrel).not.toMatch(/export\s*(type\s*)?\{[^}]*\bPageNodeRenderer\b/); |
| 71 | + }); |
| 72 | + |
| 73 | + it('does not register the `page` key — that owner is @object-ui/components', () => { |
| 74 | + const barrel = readFileSync(join(SRC, 'index.ts'), 'utf8'); |
| 75 | + // `page:card` / `page-header` are this package's own keys and stay. |
| 76 | + expect(barrel).not.toMatch(/ComponentRegistry\.register\(\s*['"]page['"]/); |
| 77 | + }); |
| 78 | + |
| 79 | + it('leaves no source file naming the removed component', () => { |
| 80 | + const offenders = sourceFiles() |
| 81 | + .filter((file) => !MAY_MENTION.has(file)) |
| 82 | + .filter((file) => /\bPageNodeRenderer\b/.test(readFileSync(join(SRC, file), 'utf8'))); |
| 83 | + |
| 84 | + expect(offenders).toEqual([]); |
| 85 | + }); |
| 86 | +}); |
0 commit comments