Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 2c7452b

Browse files
committed
test(types): pin round 4's retirements and mirrors on every face (objectui#6152, round 4)
Claude-Session: https://claude.ai/code/session_01TdiauJaVCHuj45EzZGUxHh Co-authored-by: Claude <noreply@anthropic.com>
1 parent 66ad6c9 commit 2c7452b

1 file changed

Lines changed: 183 additions & 0 deletions

File tree

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
* objectui#6152 round 4 — what this round did to the declared-but-unmirrored keys
9+
* it closed by RETIREMENT and by MIRRORING. (The eighteen keys it filed as runtime
10+
* slots by name moved between two test ledgers only; `zod-mirror-parity.test.ts`
11+
* reconciles them, and no published face changed for them.)
12+
*
13+
* ## Retired on both faces
14+
*
15+
* Four keys the TypeScript face declared and the zod mirror had never heard of:
16+
*
17+
* - `label.content` — a THIRD spelling of the label text, after `text` and
18+
* `label`; the renderer's third read is dropped in the same change;
19+
* - `report.chartConfig`, `report.reportType`, `detail-view.autoDiscoverRelated`
20+
* — each re-measured ZERO-READ by a type-checker census, with no authored
21+
* document (`reportType`'s one in-code producer stops writing it).
22+
*
23+
* Each is `?: never` on the interface and a `retirementTombstone()` on the mirror,
24+
* so an authored value is refused BY NAME at the key on every face instead of
25+
* being kept unexamined by `.passthrough()`.
26+
*
27+
* ## Mirrored
28+
*
29+
* - `chatbot.requestBody` — read by all three chatbot registrations, and until
30+
* now refused by the strict face on a `chatbot` node although `tsc` accepted it;
31+
* - `chatbot-floating.floatingConfig` — read by that registration alone, now
32+
* judged member by member (its `triggerIcon` tombstone is pinned in
33+
* `floating-chatbot-trigger-icon-retired.test.ts`).
34+
*/
35+
import { describe, it, expect } from 'vitest';
36+
import { readFileSync } from 'node:fs';
37+
import { fileURLToPath } from 'node:url';
38+
import { dirname, join } from 'node:path';
39+
40+
import type { LabelSchema as TsLabelSchema } from '../form';
41+
import type { ReportComponentSchema as TsReportComponentSchema } from '../reports';
42+
import type { DetailViewSchema as TsDetailViewSchema } from '../views';
43+
import { LabelSchema as LabelMirror } from '../zod/form.zod.js';
44+
import { ReportComponentSchema as ReportMirror } from '../zod/reports.zod.js';
45+
import { DetailViewSchema as DetailViewMirror } from '../zod/views.zod.js';
46+
import { ChatbotSchema as ChatbotMirror, ChatbotFloatingSchema as ChatbotFloatingMirror } from '../zod/complex.zod.js';
47+
import { AnyComponentSchema, StrictAnyComponentSchema } from '../zod/index.zod.js';
48+
49+
const HERE = dirname(fileURLToPath(import.meta.url));
50+
const REPO_ROOT = join(HERE, '..', '..', '..', '..');
51+
52+
type Issue = { code: string; path: PropertyKey[]; message: string };
53+
type Parse = (v: unknown) => { success: boolean; error?: { issues: Issue[] } };
54+
type Mirror = { shape: Record<string, unknown>; safeParse: Parse };
55+
56+
type Retired = { name: string; key: string; value: unknown; base: Record<string, unknown>; mirror: Mirror };
57+
58+
const RETIRED: Retired[] = [
59+
{ name: 'label', key: 'content', value: 'Email', base: { type: 'label', text: 'Email' }, mirror: LabelMirror as unknown as Mirror },
60+
{
61+
name: 'report',
62+
key: 'chartConfig',
63+
value: { chartType: 'bar', xAxisField: 'stage', yAxisFields: ['amount'] },
64+
base: { type: 'report', title: 'Pipeline' },
65+
mirror: ReportMirror as unknown as Mirror,
66+
},
67+
{ name: 'report', key: 'reportType', value: 'summary', base: { type: 'report', title: 'Pipeline' }, mirror: ReportMirror as unknown as Mirror },
68+
{
69+
name: 'detail-view',
70+
key: 'autoDiscoverRelated',
71+
value: true,
72+
base: { type: 'detail-view', objectName: 'account' },
73+
mirror: DetailViewMirror as unknown as Mirror,
74+
},
75+
];
76+
77+
const FACES: ReadonlyArray<readonly [string, (row: Retired) => Parse]> = [
78+
['the mirror', (row) => (v) => row.mirror.safeParse(v)],
79+
['the tolerant face', () => (v) => AnyComponentSchema.safeParse(v) as ReturnType<Parse>],
80+
['the strict face', () => (v) => StrictAnyComponentSchema.safeParse(v) as ReturnType<Parse>],
81+
];
82+
83+
const RETIRED_ON_FACES = RETIRED.flatMap((row) => FACES.map(([face, parse]) => ({ ...row, face, parse: parse(row) })));
84+
85+
describe('objectui#6152 round 4 — keys RETIRED on both faces', () => {
86+
it.each(RETIRED)('CONTROL: the minimal `$name` document parses on both faces', ({ base }) => {
87+
expect(AnyComponentSchema.safeParse(base).success).toBe(true);
88+
const strict = StrictAnyComponentSchema.safeParse(base);
89+
expect(strict.success, JSON.stringify(strict.error?.issues)).toBe(true);
90+
});
91+
92+
it.each(RETIRED)('`$name`.`$key` stays a MEMBER of the mirror, so an authored value is refused by name rather than kept', ({ key, mirror }) => {
93+
expect(key in mirror.shape).toBe(true);
94+
});
95+
96+
it.each(RETIRED_ON_FACES)('an authored `$name`.`$key` is refused at the key on $face', ({ key, value, base, parse }) => {
97+
const parsed = parse({ ...base, [key]: value });
98+
expect(parsed.success).toBe(false);
99+
const atKey = (parsed.error?.issues ?? []).filter((issue) => issue.path[0] === key);
100+
expect(atKey.length, JSON.stringify(parsed.error?.issues)).toBeGreaterThan(0);
101+
});
102+
103+
it.each(RETIRED)('the `$name`.`$key` refusal is the tombstone kind (`invalid_type`), not an unrecognised key', ({ key, value, base, mirror }) => {
104+
const parsed = mirror.safeParse({ ...base, [key]: value });
105+
const atKey = (parsed.error?.issues ?? []).filter((issue) => issue.path[0] === key);
106+
expect(atKey.map((issue) => issue.code)).toEqual(['invalid_type']);
107+
});
108+
109+
it('the `label.content` refusal names the live spelling `text`', () => {
110+
const parsed = LabelMirror.safeParse({ type: 'label', content: 'Email' });
111+
const atKey = (parsed.error?.issues ?? []).filter((issue) => issue.path[0] === 'content');
112+
expect(atKey.some((issue) => issue.message.includes('`text`')), JSON.stringify(atKey)).toBe(true);
113+
});
114+
115+
it('each is a `tsc` error on its interface, while a live neighbour type-checks', () => {
116+
// The directives are real enforcement: this package type-checks its tests
117+
// (`tsconfig.test.json`), so re-declaring a key fails on the unused directive.
118+
// @ts-expect-error `content` is RETIRED (objectui#6152) — write `text`
119+
const label: TsLabelSchema = { type: 'label', content: 'Email' };
120+
// @ts-expect-error `chartConfig` is RETIRED (objectui#6152) — nothing read it
121+
const chart: TsReportComponentSchema = { type: 'report', chartConfig: { chartType: 'bar' } };
122+
// @ts-expect-error `reportType` is RETIRED (objectui#6152) — nothing read it
123+
const kind: TsReportComponentSchema = { type: 'report', reportType: 'summary' };
124+
// @ts-expect-error `autoDiscoverRelated` is RETIRED (objectui#6152) — nothing read it
125+
const detail: TsDetailViewSchema = { type: 'detail-view', autoDiscoverRelated: true };
126+
const live: TsLabelSchema = { type: 'label', text: 'Email', label: 'Email' };
127+
expect([label.type, chart.type, kind.type, detail.type, live.text]).toEqual(['label', 'report', 'report', 'detail-view', 'Email']);
128+
});
129+
});
130+
131+
describe('objectui#6152 round 4 — `chatbot.requestBody` and `chatbot-floating.floatingConfig` are MIRRORED', () => {
132+
const messages = [{ id: 'm1', role: 'user', content: 'hi' }];
133+
const ROWS = [
134+
{
135+
name: 'chatbot',
136+
key: 'requestBody',
137+
mirror: ChatbotMirror as unknown as Mirror,
138+
base: { type: 'chatbot', messages },
139+
valid: { tenant: 'acme', temperature: 0.2 },
140+
wrong: 'tenant=acme',
141+
wrongPath: 'requestBody',
142+
},
143+
{
144+
name: 'chatbot-floating',
145+
key: 'floatingConfig',
146+
mirror: ChatbotFloatingMirror as unknown as Mirror,
147+
base: { type: 'chatbot-floating', messages },
148+
valid: { position: 'bottom-left', defaultOpen: true, panelWidth: 420, panelHeight: 560, title: 'Support', triggerSize: 48 },
149+
wrong: { position: 'top-left' },
150+
wrongPath: 'floatingConfig.position',
151+
},
152+
] as const;
153+
154+
it.each(ROWS)('`$name`.`$key` is a member of the mirror', ({ key, mirror }) => {
155+
expect(key in mirror.shape).toBe(true);
156+
});
157+
158+
it.each(ROWS)('an authored `$name`.`$key` parses on the strict face and the tolerant face', ({ key, base, valid }) => {
159+
const doc = { ...base, [key]: valid };
160+
const strict = StrictAnyComponentSchema.safeParse(doc);
161+
expect(strict.success, JSON.stringify(strict.error?.issues)).toBe(true);
162+
const tolerant = AnyComponentSchema.safeParse(doc);
163+
expect(tolerant.success, JSON.stringify(tolerant.error?.issues)).toBe(true);
164+
});
165+
166+
it.each(ROWS)('a wrong-typed `$name`.`$key` is refused at its path on the tolerant face', ({ key, base, wrong, wrongPath }) => {
167+
const parsed = AnyComponentSchema.safeParse({ ...base, [key]: wrong });
168+
expect(parsed.success).toBe(false);
169+
const paths = (parsed.error?.issues ?? []).map((issue) => issue.path.join('.'));
170+
expect(paths, JSON.stringify(parsed.error?.issues)).toContain(wrongPath);
171+
});
172+
});
173+
174+
describe('objectui#6152 round 4 — the pagination catalog document authors only what `pagination` declares', () => {
175+
it('`with-item-count` parses on the strict face, and no longer carries `pageSize` / `totalItems`', () => {
176+
const doc = JSON.parse(readFileSync(join(REPO_ROOT, 'examples/schema-catalog/src/schemas/components-basic-pagination/with-item-count.json'), 'utf8'));
177+
// Non-vacuity: this is the document the finding named, and it is a pagination node.
178+
expect(doc).toMatchObject({ type: 'pagination', currentPage: 3, totalPages: 20 });
179+
expect('pageSize' in doc || 'totalItems' in doc).toBe(false);
180+
const strict = StrictAnyComponentSchema.safeParse(doc);
181+
expect(strict.success, JSON.stringify(strict.error?.issues)).toBe(true);
182+
});
183+
});

0 commit comments

Comments
 (0)