You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 97f3420
Browse filesBrowse the repository at this point in the historyBrowse files
fix(metadata-protocol)!: drop an explained union head from a refused save's issues only when it is zod's bare "Invalid input" (#35520)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgRuogP8Tp8XyFXLc92Bxvo6)_
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me
Fixes#35400
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no skill or doc teaches the order of a refused
metadata save's `issues`, or its union entry (searched `skills/` and
`content/docs/` for `invalid_union`, "Invalid input", `issues[0]` and
"strictly additive"; the hits describe the data API's `fields[]` and the
UI CLI's validate report, both unchanged here)
## 维护者速读
1. 设计器、接口或 AI
助手保存元数据被拒时,清单里那句什么都没说的「输入无效」不再排在真正原因前面,第一条直接指出是哪个键错了;自带修法说明的条目照旧保留。
2. 这是巡检发现的「视图或表单保存被拒时,清单第一行是一句空话」的问题,按您两次裁定的范围执行:每一层都去掉,但只去真正空的那句。
3. 出错时,设计器约 25
个字段在保存被拒后少一行「输入无效」红字(多数在作者下次改动后恢复,表单另开一张单改),按第几条读清单的外部调用方会读到另一条;不丢数据也不影响权限,回退代码即可恢复,但发版后回退等于接口再变一次。
4. 无。
## What changes
- **The rule** (`collectMetadataIssues`,
`packages/metadata-protocol/src/protocol-metadata-issues.ts`): a union's
own entry (the head) is dropped only when BOTH hold: the branch
expansion appended at least one entry, and the head's message is exactly
zod's default for a failed union. Every other head stays, ahead of what
it explains: a head carrying the schema's own sentence (the template
slot's sentence telling the author to write a template string, an
action's `confirmText` sentence, a view's retirement prescription), a
head nothing below explains (every branch a bare kind mismatch, zod's
empty `errors`, the depth bound), and every container head
(`invalid_key`, `invalid_element`). This narrows the round-1 WIP
(`b277779bd0`), which dropped every explained head whatever its message.
- **One named constant** for the compared text,
`ZOD_UNION_DEFAULT_MESSAGE` (module-level export, not re-exported by
`protocol.ts`), pinned against a real zod parse (plain `z.union` and the
real view schema), so a zod rewording fails a test instead of silently
turning the drop off.
- **Texts that became false move here:** the producer's entry-rule
docblock (and the WIP's "carries no prescription" line, measured false),
the `zodIssuesToMetadataIssues` docblock, and the read-path comment in
`metadata-diagnostics.ts` that said the union entry stays first.
- **All four callers move together** (save `422 INVALID_METADATA`, read
`_diagnostics.errors`, seed-request refusal, unmanaged-import `400`):
they share the one producer.
- **Changeset** `.changeset/metadata-issues-bare-union-head.md`:
`patch`, both declaration lines, BREAKING banner, a was/now table, "read
entries by `path` and `code`, not by index", one ADR-0087 marker
(`not-required (no-migration-prescription)`; the gate accepted it), what
stays, the deliberate asymmetry, and the known regression below.
- **The asymmetry, recorded** in
`union-branch-policy.cross-package-parity.test.ts`: this envelope drops
an explained bare head; the terminal renderer keeps it as its parent
row; the data API's `fields[]` keeps it as `invalid_shape` (#35433
tracks it). §2 still compares branch selection across all three walks,
with exactly those heads projected out of the two spec walks; §4 asserts
the asymmetry itself and that an unexplained bare head is kept by all
three.
- **Not here:** no `ui/` change (Studio's form rows are #35499) and no
change to `packages/spec/src/api/zod-issues-to-fields.ts` (#35433).
**Known regression, until #35499 lands.** Studio's metadata form draws a
refusal's entry on a field row only when the entry's path equals the
row's key. On about 25 top-level keys the dropped head was the only
entry at that exact path, so after a refused save that row shows one red
line fewer (the "Invalid input" line). On a type with a live validator
the author's next edit redraws the row; on the rest (the seat's analysis
counted 9 keys) it stays off until #35499. The place is still named by
the entries themselves and in the Save button's tooltip.
## Tests
Readings are on this branch after its one merge of `origin/main`
`5756ae0d75`; the code head was `62387026db`; the final head
`692d874e93` adds a merge of `origin/main` `94fb8db2d1` and a
changeset-only commit (the Clause-② line reads `no (narrowing)`). The
code head's last commit only adds a module-top preload import to four
pin files (Verification), so the five pin files and the package
typecheck were re-run on it: 122 passed, `VERDICT command-exit 0`.
- **Moved pins: 22 tests in the five files** went red on the producer
change alone and were rewritten (save-union-issues 7, cross-package
parity 8, 422 face inventory 3, container descent 2, diagnostics 2).
That is the same 22 the WIP rule moved: every moved pin's head was zod's
bare text, so the bare-only condition moved none back.
- **New pins** (one `describe` in `protocol.save-union-issues.test.ts`,
the file's shared harness): the zod text pin; synthetic
bare-vs-authored; a refused view save with a non-locale `label` map
answers only the two `label.not_a_locale` entries, container head first;
an object `titleFormat` and an action `confirmText` written as formulas
keep their authored heads ahead of the `.dialect` cause; CONTROL `label:
42` keeps its unexplained bare head. Plus §4's asymmetry pin in the
parity file.
<details><summary>Five pin files: red on the producer alone, green after
the rewrite</summary>
```text
producer commit only (715b42d), 5 files under the verify lock:
Test Files 5 failed (5)
Tests 22 failed | 93 passed (115)
os-verify-lock: VERDICT command-exit 1
after the rewrite:
Test Files 5 passed (5)
Tests 122 passed (122)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Whole package: test and typecheck</summary>
```text
pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2
Test Files 360 passed | 9 skipped (369)
Tests 23256 passed | 45 skipped (23301)
os-verify-lock: VERDICT command-exit 0
pnpm --filter @objectstack/metadata-protocol build && … typecheck
check-dts-emitted: @objectstack/metadata-protocol - 2/2 declared declaration file(s) present.
os-verify-lock: VERDICT command-exit 0
(tsc --listFiles: 368 test files in the program, all five edited files among them)
```
</details>
<details><summary>Ablations (committed first;
scripts/ablation-replace.mjs, anchor 1 to 0, restored to the HEAD
blob)</summary>
The tests import the producer by relative path (`./protocol.js`), so
`src` is what runs and no rebuild is involved.
```text
A1 · keep every head (main's behaviour): `out.push(entry);`
Tests 23 failed | 99 passed (122) VERDICT command-exit 1
red: 20 of the 22 rewritten pins (the other two, in the 422 face inventory, hold under
either rule) plus the three new drop pins (bare-vs-authored, the label map, §4's asymmetry);
green: the authored-head, unexplained-head and container controls
ok restored: blob == HEAD (dccd42f) and `git diff HEAD` is empty
A2 · drop every explained head (the WIP rule): `if (below.length === 0) out.push(entry);`
Tests 3 failed | 119 passed (122) VERDICT command-exit 1
red: exactly the three authored-head pins (synthetic, titleFormat, confirmText)
ok restored: blob == HEAD (dccd42f) and `git diff HEAD` is empty
```
</details>
## Acceptance notes
- Studio was measured from source in round 1 and in the seat's scope
analysis, not driven in a browser; the form change is #35499.
- The data API's `fields[]` keeps its `invalid_shape` head (#35433); the
CLI and terminal renderer keep the parent line. Both are pinned as
deliberate.
- A union head whose message is the schema's own sentence is kept even
when its sentence is repeated on an entry below (for example a view's
retirement prescription, which also rides on the retired key's own
entry). Bare-only was ruled over "drop when repeated below".
## Verification
Local subset on the code head `62387026db` (the final head `692d874e93`
adds only a merge of main and a changeset line; CI on it: 39 success, 18
skipped, 0 failed): the derived list (`node
scripts/pm/dispatch-gates.mjs --commands`, 66 families) all exit 0.
`--ran` reconciliation over the recorded exits: "66 derived, 66 run, 0
NOT-MEASURED, 0 UNRUN" (a derived zero: all 66 recorded an exit code and
none is 3).
- One family was red on the head before last and is answered in the
diff: `check:test-source-alias` judged the four edited pin files that
reach the protocol's lazy lint import inside a clocked case. They now
import the package's existing lint preload testkit at module top, as
`protocol.save-union-issues.test.ts` already does; the gate then read
"the source reach judged 5 test file(s) changed", OK.
- `check:dual-build-cjs-loads` and `check:lean-entry-closure` exited 3
(prerequisite, no `dist/`) on the first run; on the final head, after
the dogfood closure build, both exit 0.
- `node scripts/pm/overlap-check.mjs
--branch=claude/issue-35400-drop-explained-union-wrapper` before every
push: "VERDICT clean exit 0", 0 PR heads overlapping.
- Families CI owns (`Lint & Repo Gates`, `TypeScript Type Check`, `Test
Core`, `Build Core`, the UI lanes) are read from this PR's check-runs,
not re-run locally.
<details><summary>Dogfood battery (narrowing arm)</summary>
The full battery (`pnpm --filter @objectstack/dogfood test` under the
verify lock, no shard, no path) ran on the final head `692d874e93`:
VERDICT command-exit 0; 482 test files passed, 3 skipped; 4092 tests
passed, 68 skipped; no failures (os-dev-report 7013769621 on #35400; the
same counts as the earlier run on `62387026db`, report 7011455182).
</details>
## 席位核对
- Read first:
`packages/metadata-protocol/src/protocol-metadata-issues.ts` (the
one-line rule in `collectMetadataIssues`, and the constant), then
`union-branch-policy.cross-package-parity.test.ts`
(`withoutExplainedBareHeads` and §4), then the changeset.
- Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec
vitest run src/protocol.save-union-issues.test.ts` (after building its
dependencies) shows 37 passed, including the `#35400` describe.
- Line budget: 8 files, +360 / -88 (the changeset +32; production code
+72 / -30 in two files; the rest is tests).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CZiaBg6rk7dpy1s9Me -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(metadata-protocol)!: a refused metadata save no longer lists zod's bare "Invalid input" union entry ahead of the entries that explain it
6
+
7
+
Clause-②: no (narrowing) — narrowed: the `issues[]` of a refused metadata save (`422 INVALID_METADATA`), a stored item's `_diagnostics.errors`, the seed-request refusal's `issues` and the unmanaged-import `400` no longer carry a union's own `invalid_union` entry when its message is zod's bare `Invalid input` and an entry below it explains the failure. `issues[0]` of a refused view save is now the first located cause.
8
+
Metadata-protocol: none
9
+
10
+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed or renamed, and nothing stored is rewritten: what moves is which entries a refusal's issues list carries, computed afresh on every refused save and every read. The accept set is unchanged. The one reading instruction is in the body: read entries by path and code, never by index. -->
11
+
12
+
**BREAKING** for a client that reads a refused metadata save's `issues[]`, or a stored item's `_diagnostics.errors`, by position, or that looks for a root `invalid_union` entry. That entry said only `Invalid input` and named no key; the entries that name the key were always further down the same list, and they are now first. Read entries by `path` and `code`, not by index.
13
+
14
+
| Refused save | Was | Now |
15
+
|:--|:--|:--|
16
+
| A list view with a typo in a column's `summary` key |`issues[0]` is `{ path: '', code: 'invalid_union', message: 'Invalid input' }`, then the `unrecognized_keys` entry |`issues[0]` is the `unrecognized_keys` entry naming `type` and `columns`|
17
+
| A view whose `label` is a map keyed by something other than a locale |`invalid_union` / `Invalid input` at `''` and again at `label`, then two `label.not_a_locale` entries | only the two `label.not_a_locale` entries: `invalid_key`, then the locale-tag prescription |
18
+
| The `meta-envelope` face's headline for the first row |`2 issues — (root) [invalid_union]; (root) [unrecognized_keys]`|`1 issue — (root) [unrecognized_keys]`|
19
+
20
+
The headline's root locator is the angle-bracketed word `root`; it is spelled `(root)` above only so this changelog renders it.
21
+
22
+
**What stays.** A union entry is kept, ahead of what it explains, in every other case:
23
+
24
+
- its message is the schema's own sentence rather than zod's default. An object whose `titleFormat` is written as a formula still gets, first, the template slot's sentence telling the author to write `'{{record.name}}'`; the entry below it says only `expected "template"`, so dropping the first would drop the fix. An action's `confirmText` written as a formula is the same.
25
+
- nothing below explains it: every branch only says the value is the wrong kind (a view's `label: 42`), or the nesting bound was reached. Then it is the whole answer for that slot.
26
+
- it is a container's entry (`invalid_key`, `invalid_element`): its code is the one place that says the key was refused rather than the value under it.
27
+
28
+
The comparison is against zod's exact default text, held in one constant in the producer and pinned against a real zod parse, so a zod upgrade that rewords the default fails a test instead of quietly bringing every such entry back.
29
+
30
+
**Unchanged, on purpose.** The terminal renderer (`formatZodError`, the CLI) still prints the union line as the parent of its indented tree, and the data API's `fields[]` (`zodIssuesToFields`, `400 VALIDATION_ERROR`) still carries it as an `invalid_shape` entry; whether that one follows is #35433. The cross-package parity test records the asymmetry.
31
+
32
+
**Known regression, until #35499 lands.** Studio's metadata form draws a refusal's entry on a field row only when the entry's path equals that row's key. On about 25 top-level keys (for example a view's `label`, `description`, `columns` and `exportOptions`) the dropped entry was the only one at that exact path, so after a refused save that row shows one red line fewer: the `Invalid input` line. The place is still named by the entries themselves and in the Save button's tooltip, and on a type with a live validator the next edit redraws the row. #35499 makes the form show the located cause on the row it sits under.
0 commit comments