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

Commit 7d074ba

Browse files
fix(types): objectui validate judges every node inside a page container's properties.children and items[].children, at the positions the platform walks (objectui#11223) (#11267)
Fixes #11223 Clause-②: no (narrowing) `safeValidateSchema` (what `objectui validate` runs) and `StrictAnyComponentSchema` now judge each component nested in a page container's props bag. They judge it at the positions the page walk that `@objectstack/spec` exports descends, and report each issue at the nested node's real path. The `Clause-②: no (narrowing)` line is copied from the PM claim `5917605842`. Before, a document whose nested bag child was malformed parsed on both faces; now it is refused. Nothing that was refused before is accepted, and no export moves. Changeset: `.changeset/11223-nested-page-children-judged.md`, `'@object-ui/types': minor`. ## The positions are read from the spec, not written here I measured the installed `@objectstack/spec` 17.5.0 before writing anything: - `COMPONENT_CHILD_KEYS` and `mapComponentTree` (the conversions walk) are module-private. They sit in the bundled dist, and no entry's export list names them. - `walkAddressedPageComponents` IS exported, from `@objectstack/spec/system`. Its contract calls it "THE one traversal" behind `translatePage` and the platform CLI's i18n extractor. It descends `properties.children` and `properties.items[].children`, matched by shape. - `@objectstack/lint` is not a dependency of `packages/types`, and this PR does not add one. So `packages/types/src/zod/nested-component-walk.ts` hands each node to that walk and reads back what it visited. The walk gives its visitor no path. Its contract does say that the visitor's return value replaces the node, at the node's own position, in the tree it rebuilds. So the visitor returns a marker, and a scan of the rebuilt tree reads each marker's position back. The scan does not depend on key names, and the module names no bag key. ## What changed - `packages/types/src/zod/nested-component-walk.ts` is new. It is internal, and the barrel does not re-export it. It holds three things: - `nestedComponentsOf(node)`: the node's direct nested components, each with its path. - `nestedComponentJudgment(judge)`: a check. It parses each nested component with the judge and re-issues that parse's issues under the component's path. It runs even when the node refused something of its own (zod `when`). - `rebindNestedComponentJudgment`: the same check, bound to a derived face's judge. A guard across calls stops a JavaScript value that nests a component inside itself from recursing without end. - `packages/types/src/zod/index.zod.ts`: the `AnyComponentSchema` initializer carries that check, with the union itself as the judge. So it applies at every depth, including under a node-level child slot. - `packages/types/src/strict-authoring-face.ts`: the walker swaps that check for one bound to its own twin of the union (`rebindNestedJudgments`). On the strict face, a nested component is now judged strictly. Without the swap, the strict face would consult the tolerant union one bag down, which is the closure limit its docblock names. The docblock now says which closure is re-pointed and why. - Pins: `packages/types/src/__tests__/nested-page-children-11223.test.ts` and `packages/cli/src/__tests__/validate-nested-bag-children-11223.test.ts`. - Docs: `content/docs/utilities/cli.mdx` (a new "What is judged" section) and `packages/types/src/zod/README.md` ("Nested Validation"). Not touched: `public-blocks.zod.ts`, `objectql.zod.ts`, `base.zod.ts`, `imported-defaults-8317.test.ts` and `packages/cli/src/utils/unbindable-text-expressions.ts`. ## Before and after Before, measured at `ae0b9d390` with a one-off probe through the real faces, every one of these rows parsed on BOTH faces: - the four `properties.children` containers and the two `properties.items[].children` containers; - each of those with a malformed child (`content: 7` plus an undeclared `bogus`), and each with an unknown nested `type`; - `page:card` with a malformed child in `properties.footer`. The node-level control, the same child in `grid.children`, was refused. After, every bag row is refused on both faces. Examples: - `invalid_union` at `properties.children.0.properties.content`; - `unrecognized_keys` (`bogus`) at `properties.children.0.properties`; - `invalid_union` at `properties.items.0.children.0.type`, with "No matching discriminator". `objectui validate` prints it as "No arm accepts type ..." at the nested node, with the nearest accepted types. `page:card` with a malformed footer child still parses. The Acceptance notes explain why. ## Pins (`nested-page-children-11223.test.ts`, 45 rows) - (a) Six containers on both faces, 12 rows, each with a malformed child and with an unknown nested `type`. The child sits second in its list, so the index in the reported path is measured. Every issue must land under the child's path. - (b) Controls: a valid nested page (card, tabs and accordion inside a section) parses on both faces. The nesting is also judged two bag levels down, and under a node-level child slot. - (c) The strict face refuses an undeclared node key one bag down, by name, at `properties.children.0`. The tolerant face passes it, as it does at the root. - (d) Parity. A probe whose props bag answers ANY key with marked components reads off the installed walk every position it descends, without naming any key. Then: `nestedComponentsOf` reaches a component at each of those positions; each position is one a row of (a) judges; and `nestedComponentsOf` equals the walk's direct visits, in order and by identity. If the spec's walk gains a position, objectui walks it the same day, and the coverage row goes red until a row of (a) judges it. - (e) The footer gap (see the Acceptance notes). This row goes red the day the exported walk descends `properties.footer`. - (f) A self-nesting JavaScript value gets a verdict instead of overflowing the stack. The CLI pin covers `objectui validate` at the public door: the nested path line, the "No arm accepts type" note with the nearest types, and "Schema is valid!" for a valid nested page. ## Ablation Both legs ran on committed code. Each mutation went through objectstack's `scripts/ablation-replace.mjs`: the anchor hit once, and the blob changed. Each restore was proven: the blob equals HEAD, and `git diff HEAD` is empty. 1. Remove the check from `AnyComponentSchema`: 33 failed, 15 passed across the two pin files (48 rows). Every nested-refusal row went red: all of (a), the depth and child-slot rows of (b), the strict refusal in (c), both rows of (f), and two CLI rows. Nothing else went red; the controls, the parity walk rows and the footer-gap rows stayed green. 2. Remove the strict walker's rebinding: 1 failed, 44 passed. Exactly the strict face's nested unknown-key refusal, (c), went red. ## Verification, on head `eebfc2765` (the merge below) - `pnpm --filter @object-ui/types type-check` (src, examples and tests projects): exit 0. - `pnpm --workspace-concurrency=2 --filter '@object-ui/cli^...' build`, then `pnpm --filter @object-ui/cli type-check`: exit 0. - `pnpm exec vitest run packages/types/src/` in five chunks: 7419 passed, 0 failed. `packages/cli/src/`: 338 passed. The whole root `scripts/__tests__/` in three chunks: 5371 passed, 2 skipped, 0 failed. Each chunk ran under `timeout 300` with the verbose reporter. - `pnpm exec eslint` on the five changed TypeScript files: exit 0. - These exited 0: `check-changeset-presence`, `check-control-bytes`, `check-new-cross-file-line-citations` (0 new), `markdown-test-inputs --audit`, `check:pending-changeset-literals`, `changeset:check`, `check:doc-fences`, `check:doc-types`, `check:doc-example-ids` and `check:doc-example-readers`. - Measured at `c7f883f9c`, before the merge; the merge changed none of this diff's files except the zod README's neighbouring section. `check:doc-snippets` and `check:doc-examples` stopped with exit 2, PREREQUISITE NOT MET: they need their 34-package build. Their CI runs are the verdict. As a stand-in, the README snippet compiles under `tsc --strict` against the built `@object-ui/types` dist. - Also at `c7f883f9c`: `check:spec-floors` exited 1, and every finding was `no-artifact` for a package this run did not build. It read `./system` at the declared floor 17.5.0 and reported nothing for `@object-ui/types`. The full verdict is CI's. ## Serial constraint Seat 1's serial note `5917593110` put this card after objectui#10872 batch 8. That PR landed as `54a78308a` (#11260) during this run. This branch merges main at that commit (`eebfc2765`), and I re-read the arms there. Batch 8 adds `responsiveStyles` through `PUBLIC_BLOCK_ENVELOPE` and leaves every `propsBag` and child-list member as it was, so the walk is unaffected. This PR edits neither `public-blocks.zod.ts` nor `objectql.zod.ts`. ## Acceptance notes - **Premise correction.** The card and triage `5913780517` say objectstack's `packages/lint/src/page-walk.ts` walks exactly `properties.children` and `properties.items[i].children`. It also walks `properties.body` and `properties.footer`, both at the 17.5.0 tag (`0f6dcac5e9`) and at objectstack main (`33b6e8bec`). The spec's exported walk does not; its contract says "`body` / `footer` are deliberately still not descended". - **The gap that leaves.** `page:card`'s row declares `footer` as a component slot ("Card footer components (slot)"), `PageCardRenderer` draws it, and the lint walk descends it. The exported walk does not. So a malformed component in a card footer is still accepted on both faces. Pin (e) holds this. It goes red the day the walk descends the footer, and nothing else in this repository needs to change then. I report it for routing in the dev report; I did not write the position here by hand. - Entries the walk does not visit (strings, numbers, `null`, nested arrays) are not judged, as the walk's own contract says. objectui's node-level child slots accept the same primitives. - The judgment lives on the union. A container's own arm schema parsed alone (`PageSectionBlockSchema.safeParse`) does not judge its bag children. `safeValidateSchema`, `StrictAnyComponentSchema` and every node-level child slot do. - A nested component's issues come from a separate parse of that component. So a per-call error map passed to the outer `safeParse` does not reach their messages. Nothing in this repository passes one to these faces. - For objectui#11170: the position walk lives in `packages/types/src/zod/nested-component-walk.ts`, as `nestedComponentsOf(node)`. It is internal today. `packages/cli` can use it after a one-line re-export from `index.zod.ts`, which is that card's decision. - **New runtime read.** `@object-ui/types/zod` now imports a value from `@objectstack/spec/system`; before, the package re-exported only a type from it. `check:spec-floors` read `./system` at floor 17.5.0 and reported nothing for this package. The console already routes `@objectstack/spec/system` into `vendor-objectstack`. `check:eager-closure` and `check:node-esm-load` need a whole-workspace build, so their verdicts are CI's. As a stand-in, at `c7f883f9c`, a Node ESM import of the built `@object-ui/types/zod` from `packages/cli` loaded, and it refused a nested unknown type at `properties.children.0.type`. - The CLI guide's "Reading a failure" section still describes the root-level union report from before objectui#8498. This PR does not change it. Carrier: none. --- _Generated by [Claude Code](https://claude.ai/code/session_011p7ikEivgXefNDaE5S5Uec)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fc65038 commit 7d074ba

8 files changed

Lines changed: 756 additions & 2 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/types': minor
3+
---
4+
5+
`safeValidateSchema` — and so `objectui validate` — and `StrictAnyComponentSchema` judge a component nested in a page container's props bag (objectui#11223).
6+
7+
**Clause-②: no (narrowing)** — a document whose bag child is malformed, or names a `type` no arm declares, parsed on both faces and is refused now. Nothing that was refused before is accepted, and no export is added or removed.
8+
9+
**What it was.** The page containers take their child lists in the bag: `properties.children` on `page:card`, `page:section`, `page:footer` and `page:sidebar`, and `properties.items[].children` on `page:tabs` and `page:accordion`. Their arms read the spec's `ComponentPropsMap` rows by reference, and the rows type every one of those slots as a list of anything, so neither face looked inside it. The same child in a node-level child slot was judged by its own component schema.
10+
11+
**What changed, in observable terms.**
12+
13+
- `AnyComponentSchema` judges every component nested in a node's bag with the same union, at each position `@objectstack/spec`'s own page walk (`walkAddressedPageComponents`, `@objectstack/spec/system`) descends — read from the installed spec at parse time, not listed here. Each issue is reported at the nested node's real path, for example `properties.children.0.properties.content`, and an unknown nested `type` gets the discriminator's own verdict at `….type`, which `objectui validate` prints as "No arm accepts type …" with the nearest accepted types. The judgment runs even when the node refuses something of its own, and it applies at every depth, including under a node-level child slot.
14+
- `StrictAnyComponentSchema` judges those components against its own strict twin of the union, so an undeclared key on a nested component is refused by name there, as it is one child slot down.
15+
- Entries of a bag child list that the spec's walk does not visit — a string, a number, `null` — are not components to it and are not judged.
16+
- One slot the renderer draws is not walked yet: `page:card`'s `properties.footer`. The spec's exported walk does not descend it, so a component written there is still accepted unexamined; it is judged the day the walk descends it.
17+
- A container's own arm schema parsed alone (`PageSectionBlockSchema.safeParse(…)`) is unchanged: the judgment lives on the union.

‎content/docs/utilities/cli.mdx‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,27 @@ objectui validate app.json
158158
objectui validate ./schemas/dashboard.yaml
159159
```
160160

161+
#### What is judged
162+
163+
Every node is judged by its own component schema, at every depth: a child in a
164+
node-level slot such as `children`, and a component nested in a container's
165+
props bag — at the positions `@objectstack/spec`'s own page walk
166+
(`walkAddressedPageComponents`) descends, which for the page containers are
167+
`properties.children` and `properties.items[].children`. A nested failure is
168+
reported at the nested node's real path:
169+
170+
```text
171+
1. Invalid input
172+
Path: properties → items → 0 → children → 0 → type
173+
Code: invalid_union
174+
No arm accepts type "element:txt" at properties → items → 0 → children → 0.
175+
Nearest of the … accepted types: element:text, element:button, …
176+
```
177+
178+
A slot that walk does not descend is not judged here. One is live today:
179+
`page:card`'s `properties.footer`, which the card draws — a component written
180+
there is accepted unexamined until the spec's walk reaches it.
181+
161182
#### Reading a failure
162183

163184
A document is checked against a union of every component type, so a failure is
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
* `objectui validate` judges a component nested in a `page:` container's props
11+
* bag (objectui#11223) — the public door the card measured.
12+
*
13+
* A page built the way the spec and the validator's own remedy text teach —
14+
* blocks nested in `properties.children` — got `Schema is valid!` for a
15+
* malformed nested block and for a nested `type` no arm declares. The command
16+
* runs `safeValidateSchema`, which now judges each nested component by the node
17+
* union at its real path; this file pins what an author reads: the numbered
18+
* issue with that path, and the "No arm accepts type" note the printer builds
19+
* from the nested discriminator's own verdict. The schema-level pins live in
20+
* `packages/types/src/__tests__/nested-page-children-11223.test.ts`.
21+
*
22+
* Harness (fixtures under `os.tmpdir()`, `process.exit` recorded rather than
23+
* taken) follows `validate-root-path-line.test.ts`.
24+
*/
25+
26+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
27+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
28+
import { join } from 'node:path';
29+
import { tmpdir } from 'node:os';
30+
import { validate } from '../commands/validate.js';
31+
32+
/** The CSI sequences chalk may add; the escape byte is built, never spelled. */
33+
const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, 'g');
34+
35+
const text = (content: unknown) => ({ type: 'element:text', properties: { content } });
36+
37+
let dir: string;
38+
let out: string[];
39+
let exitCodes: number[];
40+
let restore: () => void;
41+
42+
const printed = (): string => out.join('\n').replace(ANSI, '');
43+
44+
function writeSchema(name: string, schema: unknown): string {
45+
const file = join(dir, name);
46+
writeFileSync(file, JSON.stringify(schema, null, 2), 'utf-8');
47+
return file;
48+
}
49+
50+
beforeEach(() => {
51+
dir = mkdtempSync(join(tmpdir(), 'objectui-validate-11223-'));
52+
out = [];
53+
exitCodes = [];
54+
const originalLog = console.log;
55+
const originalError = console.error;
56+
const capture = (...args: unknown[]) => {
57+
out.push(args.map(String).join(' '));
58+
};
59+
console.log = capture;
60+
console.error = capture;
61+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code?: number) => {
62+
exitCodes.push(code ?? 0);
63+
return undefined as never;
64+
}) as never);
65+
restore = () => {
66+
console.log = originalLog;
67+
console.error = originalError;
68+
exitSpy.mockRestore();
69+
};
70+
});
71+
72+
afterEach(() => {
73+
restore();
74+
rmSync(dir, { recursive: true, force: true });
75+
});
76+
77+
describe('objectui validate — a component nested in a props bag is judged (objectui#11223)', () => {
78+
it('refuses a malformed nested block, at the member\'s own path', async () => {
79+
await validate(writeSchema('section.json', {
80+
type: 'page:section',
81+
properties: { children: [text('intro'), text(7)] },
82+
}));
83+
84+
expect(exitCodes).toEqual([1]);
85+
const lines = printed();
86+
expect(lines).not.toContain('Schema is valid!');
87+
expect(lines).toContain('Path: properties → children → 1 → properties → content');
88+
});
89+
90+
it('names the unknown nested `type` where it sits, with the nearest accepted types', async () => {
91+
await validate(writeSchema('tabs.json', {
92+
type: 'page:tabs',
93+
properties: { items: [{ label: 'One', children: [{ type: 'element:txt' }] }] },
94+
}));
95+
96+
expect(exitCodes).toEqual([1]);
97+
const lines = printed();
98+
expect(lines).toContain('Path: properties → items → 0 → children → 0 → type');
99+
expect(lines).toContain('No arm accepts type "element:txt" at properties → items → 0 → children → 0.');
100+
expect(lines).toMatch(/Nearest of the \d+ accepted types: .*element:text/);
101+
});
102+
103+
it('still says `Schema is valid!` for a valid nested page (the control)', async () => {
104+
await validate(writeSchema('page.json', {
105+
type: 'page:section',
106+
properties: {
107+
children: [
108+
text('intro'),
109+
{ type: 'page:card', properties: { title: 'Card', children: [text('in the card')] } },
110+
{ type: 'page:accordion', properties: { items: [{ label: 'Panel', children: [text('in the panel')] }] } },
111+
],
112+
},
113+
}));
114+
115+
expect(exitCodes).toEqual([0]);
116+
expect(printed()).toContain('Schema is valid!');
117+
});
118+
});

0 commit comments

Comments
 (0)