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 c23e556
Browse filesBrowse the repository at this point in the historyBrowse files
fix(metadata-protocol): a 422 INVALID_METADATA issue entry carries its zod issue's params (#37962)
repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoCSEGDBy5L8NnTLNqGDmXLf)_Fixes#36594
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:保存元数据被拒时,返回的每条问题除了原有的路径、说明和通用代码外,还会带上规则自己的具体原因码(例如主从对象的主字段不可写),调用方不必再靠英文句子猜是哪条规则。
- 为什么做:属于“搭建应用”专题,替通过接口保存元数据的客户端和智能体解决“只看到 custom、看不到具体原因码”的问题。
- 出错会怎样:只是在拒绝回复里多加一个字段,原有字段一个不动;若有问题,最坏是多出的字段内容不对,可直接撤回本次改动。
- 要你做什么:无。
## What changes
Revised after the contract review FAIL (record 7219293041, L1 REWORK
7219317393). Round 2 closes M1, S1, S2 and N1-N3.
- `packages/metadata-protocol/src/protocol-metadata-issues.ts`:
`MetadataIssueEntry` gains an optional `params?: Record<string, string |
number | boolean>`. `zodIssuesToMetadataIssues` takes a new option, `{
refusalParams?: boolean }`, threaded through `collectMetadataIssues`.
Only when it is set does an entry carry `params`. Three limits apply:
- **Registered codes only:** an issue gets the member only when its
`params.code` is a string `ErrorCode` accepts. Internal markers
(`readAsWritten`, `refusalHead`, `retiredComponentType`) never reach the
wire.
- **JSON scalars only:** only string, finite-number and boolean members
are copied. A BigInt, a cycle, a function or NaN is left out, so
answering cannot throw, and the copy shares nothing with the issue (S1,
S2, N3).
- **Entry shape unchanged otherwise:** `code` is still
`String(issue.code)`, `'custom'` for a refinement, and the
de-duplication key is unchanged.
- `packages/metadata-protocol/src/protocol-save.ts`: the save door's 422
(`saveMetaItem`, the spec-validation refusal) is the one caller that
passes `{ refusalParams: true }`. Every other caller is unchanged, so
`_diagnostics.errors[]` (`parseDiagnostics`, whose cached verdict
`copyDiagnostics` copies one level deep), `seedApplied.issues[]`
(`seedRequestValidationError`) and the unmanaged-install 400 keep
exactly `path` / `message` / `code`. That is the shape
`MetadataValidationResultSchema` and the publish response declare (M1).
- `packages/spec/src/api/error-code-ledger.zod.ts` (the
`CONTROLLED_BY_PARENT_MASTER_INVALID` comment) and
`packages/spec/src/data/controlled-by-parent-master.ts` (the constant's
docblock): both said the save door's 422 never carries `params`. Both
now say the 422's `issues[]` entry carries the code on `params.code`,
and that the read path's `_diagnostics.errors[]` does not. The ledger
comment now spells out `door: 'none'` as "no door answers with this code
as its `error.code`" (N1). Comment and TSDoc only.
- `.changeset/36594-metadata-issue-params.md`: `patch` on both packages.
AGENTS.md Post-Task Checklist step 3 sets the level by the
`Metadata-protocol` kind, and "a non-protocol change, widening or
breaking, ships `patch`". This change widens the 422 wire entry
(`Clause-②: yes (widening)`) but changes nothing a metadata author can
write (`Metadata-protocol: none`). `PLUGIN_UI_REQUIRED_KEY_MISSING` is
named as a `PluginSchema` example, not a save-door one (N2).
The REST error answer spreads `error.issues` unchanged
(`packages/rest/src/error-response.ts`, the `issues` member), so the
HTTP 422 body carries `params` with no REST change.
## Tests
The new top-level `describe` in
`packages/metadata-protocol/src/protocol.save-union-issues.test.ts` (the
save door's issue-mapping harness: the real repository write path over a
stub engine) has 7 cases:
- `CONTROLLED_BY_PARENT_MASTER_INVALID` over `saveMetaItem`: an object
save with a `readonly` master answers 422 `INVALID_METADATA` with
exactly `[{ path: 'fields', code: 'custom', message, params: { code:
'CONTROLLED_BY_PARENT_MASTER_INVALID', shape: 'master-not-writable' }
}]`, and nothing is stored.
- Control over `saveMetaItem`: an issue zod raised without params
(`label: 42`) gets no `params` own property.
- Over `saveMetaItem`: a refusal whose params also hold a BigInt, a
cycle, a function and NaN still answers 422 `INVALID_METADATA`. The
entry keeps only `code`, `shape` and the scalar members, and
`JSON.stringify` of the issues does not throw. The door is reached
through a `registerMetadataTypeSchema('object', …)` override, restored
in `finally` and checked restored.
- `PLUGIN_UI_REQUIRED_KEY_MISSING`: the real `PluginSchema` refusal
through the mapper with the door's option gives `{ path: 'staticPath',
code: 'custom', params: { code: 'PLUGIN_UI_REQUIRED_KEY_MISSING', key:
'staticPath' } }`. It is not tested over `saveMetaItem` because no
metadata type the save door accepts parses with `PluginSchema` on this
tree. Measured: registering `PluginSchema` for a new type name and
saving under it answers `INVALID_REQUEST` before any schema runs.
- Params whose `code` is not a registered error code (`readAsWritten`,
`retiredComponentType`, an unregistered string, a number, an array,
null) give no `params`.
- READ PATH: `decorateMetadataItem('object', …)` on the same refused
object gives `_diagnostics.errors` of exactly `[{ path, message, code
}]`.
- SEED: `seedRequestValidationError` over an issue carrying CBP params
gives `issues` with no `params`.
## Acceptance notes
- No `ui/` consumer reads `params` from the 422 yet. Studio parses
locally and already reads the code off the zod issue. The two `ui/`
read-path mirrors the review named (`draftVerdict.ts`,
`metadata-client.ts`) describe `_diagnostics`, which stays three keys,
so they still match.
- `packages/spec/CHANGELOG.md` still holds the released sentence "never
`params`". It is release-owned and left alone.
## Verification
Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec
vitest run --maxWorkers=2 src/protocol.save-union-issues.test.ts -t
36594`. Expect 7 passed.
Read first, by risk:
1. `packages/metadata-protocol/src/protocol-metadata-issues.ts`:
`refusalParamsOf`, the option, and where `collectMetadataIssues` reads
it.
2. `packages/metadata-protocol/src/protocol-save.ts`: the one call that
passes `{ refusalParams: true }`.
3. The new `describe` at the foot of
`protocol.save-union-issues.test.ts`.
Local readings at head `ddbd5578`:
<details><summary>Package tests and typecheck</summary>
`pnpm --filter @objectstack/metadata-protocol typecheck && pnpm --filter
@objectstack/metadata-protocol test` under the verify lock: `VERDICT
command-exit 0`, Test Files 372 passed, 9 skipped (381); Tests 23605
passed, 45 skipped.
</details>
<details><summary>Ablation, four legs</summary>
Each leg used `node scripts/ablation-replace.mjs` on
`protocol-metadata-issues.ts` or `protocol-save.ts`, ran the new
describe, and restored with blob == HEAD and an empty `git diff HEAD`.
- A: the save door drops `{ refusalParams: true }`. The CBP and BigInt
cases go red.
- B: the option defaults on. The READ PATH and SEED cases go red.
- C: the scalar filter is removed. The BigInt case goes red.
- D: the registered-code gate is removed (anchor 1 -> 0, blob 49c9d69
-> 300da885). The markers case goes red: 1 failed, 6 passed.
</details>
<details><summary>Derived gate families</summary>
`node scripts/pm/dispatch-gates.mjs --ran` on a record carrying each
exit code: `98 derived famil(ies) accounted for — 97 run, 1
NOT-MEASURED`. The NOT-MEASURED one is `node
scripts/check-plugin-teardown-shape.mjs --self-test` (checker health
only, exit 3: its positive control is pinned to a commit this shallow
clone cannot reach; CI's "Lint · scoped · tooling self-tests" is green).
</details>
CI on `ddbd5578`: every check green except `Test UI (13/16)`, one case
in `StudioRoute.metadataArea-28561.test.tsx` that passes locally at this
head and on this head merged with `origin/main` (3 runs, 33/33 each).
See the PR comment.
Changed lines: 255 (+238 / -17) across 6 files, under the 3000
threshold. Dogfood battery: not owed (no `!` in the title, no narrowing
arm).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibzQhDYnejPUPpyJvyc)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(metadata-protocol): a `422 INVALID_METADATA` issue entry carries the registered refusal on `params`, so a client of the save door can read the code
7
+
8
+
Clause-②: yes (widening)
9
+
Metadata-protocol: none
10
+
11
+
A spec rule that owns a registered error code stamps it on its zod issue as `params.code`, next to the fields that say which fix applies: `CONTROLLED_BY_PARENT_MASTER_INVALID` with `shape` (an object save), and `PLUGIN_UI_REQUIRED_KEY_MISSING` with `key` (`PluginSchema`, which no save-door type parses today). zod reports every such rule with its own issue code `'custom'`. The metadata save door's `422 INVALID_METADATA` built each `issues[]` entry from `path`, `message` and that `'custom'` only, so a client of the door (anything that does not parse locally the way Studio does) could not tell which rule refused the body except by its English message.
12
+
13
+
-**`@objectstack/metadata-protocol`.** The save door's 422 entry gains an optional `params` member: the registered refusal the issue carries, present only when the issue's `params.code` is a registered error code, and holding only its string, finite-number and boolean members. An object save refused for a `controlled_by_parent` master now answers `{ path: 'fields', code: 'custom', message, params: { code: 'CONTROLLED_BY_PARENT_MASTER_INVALID', shape: 'master-not-writable' } }`. Read the registered code from `params.code`. `zodIssuesToMetadataIssues` takes a new option, `refusalParams`, which only the save door sets. The read path's `_diagnostics.errors[]` and the seed refusal's `seedApplied.issues[]` keep exactly `path`, `message` and `code`, the shape their spec schemas publish.
14
+
-**`@objectstack/spec`.** The `CONTROLLED_BY_PARENT_MASTER_INVALID` docblock and its ledger note now say the save door's 422 carries the code on `params.code`.
15
+
16
+
Nothing to migrate. The entry's `code` is unchanged (still zod's issue code, `'custom'` for these rules), and an entry that carries no registered refusal gets no `params` member, so a client that matches `code` or compares whole entries for other issues reads exactly what it read before.
0 commit comments