Skip to content

Commit d24e4ab

Browse files
feat(spec,app-shell): controlled_by_parent refusal carries a code; Studio settings tab words it in en and zh (#36579)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi973kVV4iHmicnT3W3avzhv3)_ Fixes #36526 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:Studio 里给对象选「跟随所属的主记录」却没有合适的主从字段时,设置页现在用中文或英文的业务话说明哪里不对、该改哪个字段,不再显示带 ADR 编号的英文开发者原文。 - 为什么做:属于 Studio 文案业务化专题,接着上一张设置页去掉 ADR 编号的改动,把这条拒绝提示也改成作者能看懂的话。 - 出错会怎样:最坏是提示文字措辞不准或退回英文原文,保存是否被拒的判断不变;可以直接撤回本 PR。 - 要你做什么:无。 ## What changes **Spec (`@objectstack/spec`).** The `controlled_by_parent` master refusal now carries a machine-readable code. Both raise sites, `ObjectSchema`'s refinement (`refuseControlledByParentWithoutOneMaster`) and `defineStack`'s extension-merge gate (`applyControlledByParentExtensionGate`), stamp `params: { code: CONTROLLED_BY_PARENT_MASTER_INVALID, shape }` on the issue. `shape` is the existing published `ControlledByParentMasterShape`. The new constant and a `ControlledByParentMasterIssueParams` type are exported from `@objectstack/spec/data`, and the code is registered in `ERROR_CODE_LEDGER` under `@objectstack/spec` (the `PLUGIN_UI_REQUIRED_KEY_MISSING` precedent: a code on a zod issue's `params.code`, door `none`). Which objects are refused, and at which path, is unchanged. Where the code is visible: on the zod issue itself (any `ObjectSchema` / `ObjectStackDefinitionSchema` `safeParse`, which is the Studio tab's path) and on `defineStack`'s `STACK_SCHEMA_INVALID` refusal, whose `issues` are the raw zod issues (measured on this head: `objects.0.sharingModel` carries `{ code, shape: 'no-master' }`). Where it is not: the metadata save door's `422 INVALID_METADATA`. Its `issues[]` entries come from `zodIssuesToMetadataIssues` (`@objectstack/metadata-protocol`) and keep `path`, `message` and zod's issue code (`custom`) only. The const's JSDoc, the ledger row's comment and the changeset say exactly this. Carrying `params` through that envelope would be a wire change and is not made here. The three English message arms drop the developer citation: `ADR-0055 §1: since @objectstack/spec 18, …` becomes `Since @objectstack/spec 18, …`. The prescription in each arm is unchanged. Card re-check: `grep -n "ADR-0055 §1" packages/spec/src/data/controlled-by-parent-master.ts` now hits docblock lines only, no message line. **Studio (`@object-ui/app-shell`, `@object-ui/i18n`).** `cbpMasterRefusal` (owd-sharing.ts) still parses the save door's `ObjectSchema` on a probe, and now returns `{ message, shape, fields }`: it reads the shape off the issue only when `params.code` is the spec's code, and lists the fields the author has to act on. `ObjectSettingsPanel` renders the `studio` namespace row the shape selects (`engine.studio.settings.cbpRefusal*`, six shapes, en and zh), naming the fields by label (key when unlabeled). With no code on the issue, or a shape with no row, it shows the spec's message as before. The shape-to-key map is typed on the spec's shape union, so a new shape fails type-check until it has a row. The probe now also carries the master's writability flags: on a `master_detail` field it copies `readonly` and `system` when they are booleans, exactly as written (the spec's module-private `UNWRITABLE_MASTER_FLAGS`, hard-coded in owd-sharing.ts with a comment naming it; no new spec export). Before, the probe dropped both flags, so a master marked `readonly: true` or `system: true` was refused by the save door (shape `master-not-writable`) while the tab showed nothing. Now the tab shows that shape's row. The field that row names is the master as the parse reads it: the one `master_detail` declared `required: true`, else the object's only `master_detail` (on the parsed map an omitted `required` is `false`, the optional master). Reading it off the raw probe named no field for a flagged master that writes no `required`, and the row printed an empty name. `cbpMasterRefusal` takes the issue whose `params.code` is the spec's code, and falls back to the custom issue at `sharingModel` / `fields` only when none carries it. The en `required-lookup-only` wording has a one-field row and a several-field row (`cbpRefusalRequiredLookupsOnly`); zh carries both keys for parity. The stale docblock claim "The spec does not export the check" is corrected: `controlledByParentMasterRefusal` is exported; the probe keeps parsing `ObjectSchema` so the code it reads is the one the save door stamps. Naming: the code name `CONTROLLED_BY_PARENT_MASTER_INVALID` is accepted by seat ruling 7088548226 on this PR (precedent: the spec's `<SUBJECT>_INVALID` refusal codes such as `STACK_SCHEMA_INVALID` and `DATASET_INVALID`). Route chosen: one new ledger code plus the existing `shape` vocabulary as the sub-discriminator. The shape alone does not identify the refusal family on an arbitrary issue, and ADR-0112 registers a code that ships in `dist`. Generated artifacts regenerated: `packages/spec/api-surface/data.json`, `packages/spec/export-origins/data.json`, `content/docs/references/api/{error-code-ledger,contract,automation-api}.mdx`. ## Tests Changed tests (forced by the change): - `packages/spec/src/data/object.test.ts`: the two `toMatch` pins that ended in `ADR-0055 §1:` and the two `toContain('since @objectstack/spec 18, …')` pins now read `Since @objectstack/spec 18, …`; `issuesOf` also returns `params`. - `ui/packages/app-shell/src/views/studio-design/owd-sharing.test.ts`: the three `cbpMasterRefusal(...)` equality pins compare `.message`. - `ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.cbpRequiredMaster-12326.test.tsx`: the two cases that expected the spec text verbatim in `owd-cbp-refusal` now expect the business wording. New assertions: - `object.test.ts`: every reachable shape (`no-master`, `required-lookup-only`, `several-masters`, `several-required-masters`, `master-not-writable`) carries `params` equal to `{ code: CONTROLLED_BY_PARENT_MASTER_INVALID, shape }`, and no message matches `ADR-`. - `stack-cbp-extension-master.test.ts`: the extension-merge issue carries the same `params`. - `owd-sharing.test.ts`: shape and named fields per shape, including `master-not-writable` for a master marked `readonly` or `system` (and no refusal when both are `false`), and the same shape naming the master when it writes no `required`; the shape equals the one on the save door's issue; the key map covers all six shapes; the spec-parity cases add a readonly required master and a system optional master. - `ObjectSettingsPanel.cbpRequiredMaster-12326.test.tsx`: a new describe renders five shapes in eight cases (a readonly and a system required master, and a readonly master that writes no `required`, all show the `master-not-writable` row naming the field; one required lookup and two required lookups take the one-field and several-field rows) in en-US and zh-CN and checks the exact row text, that zh differs from en, and that neither contains `ADR-`, `@objectstack/spec`, `sharingModel`, `master_detail` or `required: `. <details><summary>Ablation (one reading, then restored)</summary> Mutation via `scripts/ablation-replace.mjs` on `packages/spec/src/data/object.zod.ts`: the refinement's `code: CONTROLLED_BY_PARENT_MASTER_INVALID` replaced with `code: 'ABLATION_36526'`. Anchor 1 to 0, blob 723be4e to 3889e32b7048. Spec rebuilt; `ablation-dist-preflight.mjs @objectstack/spec ABLATION_36526` found the marker in 2 dist files. - spec `object.test.ts` + `stack-cbp-extension-master.test.ts`: 1 failed / 227 passed (`no-master: expected { code: 'ABLATION_36526', …(1) } to deeply equal { …(2) }`). - ui `owd-sharing.test.ts` + `ObjectSettingsPanel.cbpRequiredMaster-12326.test.tsx`: 11 failed / 30 passed (the shape reads `undefined`, the panel falls back to the spec text). Restore: blob back to HEAD 723be4e, `git diff HEAD` empty; spec rebuilt; `--absent` preflight: marker absent from all 614 built files, working tree clean. Second reading, for the flag carry (patch round 1, head ca3ebc2): `scripts/ablation-replace.mjs` replaced the probe's flag copy in `owd-sharing.ts` with a no-op (anchor 1 to 0, blob fb3c386 to bd773cd5b26b; the tests read this source directly, no build in between). `owd-sharing.test.ts` + `ObjectSettingsPanel.cbpRequiredMaster-12326.test.tsx`: 5 failed / 41 passed, the five readonly/system cases. Restore: blob back to HEAD fb3c386, `git diff HEAD` empty, `git status --porcelain` empty. Third reading, for the master resolution (patch round 2, head c8366b9): `scripts/ablation-replace.mjs` made the only-`master_detail` arm of `refusalFields` return no field (anchor 1 to 0, blob be67de1 to 25dda5fdf07b; source read directly, no build). `owd-sharing.test.ts` + `ObjectSettingsPanel.cbpRequiredMaster-12326.test.tsx`: 2 failed / 46 passed, the two omitted-`required` cases. Restore: blob back to HEAD be67de1, `git diff HEAD` empty, `git status --porcelain` empty. </details> <details><summary>Local runs</summary> - `pnpm --filter @objectstack/spec test`: Test Files 875 passed, Tests 27973 passed, 1 todo. - `ui` vitest `packages/app-shell/src/views/studio-design/` + `packages/i18n/src/__tests__/studio-namespace.test.ts`: Test Files 356 passed, Tests 2791 passed. - Downstream refusal suites (metadata-protocol 2 files 50 tests, objectql 2 files 38 tests, plugin-security 4 files 187 tests, lint 5 files 826 tests): all passed. - `pnpm --filter @objectstack/spec typecheck`, `pnpm --filter @object-ui/i18n type-check`, `pnpm --filter @object-ui/app-shell type-check`: exit 0. - `pnpm --filter @objectstack/spec check:generated`: all 14 artifacts up to date. - Gate list from `node scripts/pm/dispatch-gates.mjs --commands` at 2d20f93: 126 derived, 125 run with exit 0, 1 NOT MEASURED (`pnpm check:dual-build-cjs-loads`: PREREQUISITE NOT MET, it reads every package's dist and this box has no full build; CI carries it). `--ran` reconciliation: 126 accounted, 0 unrun. - Patch round 1 (head ca3ebc2): `owd-sharing.test.ts`, `ObjectSettingsPanel.cbpRequiredMaster-12326.test.tsx`, `ObjectSettingsPanel.businessWording-36512.test.tsx`, `PackageOwdOverviewPanel.cbpRequiredMaster-12326.test.tsx` and `studio-namespace.test.ts`: 5 files / 85 tests passed; `pnpm --filter @object-ui/app-shell type-check` exit 0. `dispatch-gates --commands` at ca3ebc2 derives the same 126 families as at 2d20f93 (no family newly touched), so none was re-run; `--ran` reconciliation still 126 accounted, 1 NOT MEASURED. - Patch round 2 (head c8366b9): spec build, `pnpm --filter @objectstack/spec typecheck` and `object.test.ts` + `stack-cbp-extension-master.test.ts` + `error-code-ledger.test.ts` + `controlled-by-parent-master.test.ts`: 4 files / 301 tests passed; `check:generated` all 14 up to date. ui targeted suites (the same five files): 87 tests passed; `@object-ui/i18n` and `@object-ui/app-shell` type-check exit 0. `dispatch-gates --commands` at c8366b9 derives the same 126 families (none newly touched); the twelve that read the changed text (error-code casing, dispatcher vocabulary, status conformance, the three changeset gates, doc-authoring, nul-bytes, issue-citations, error-code-provenance, api-surface, ui `scripts/`) were re-run, all exit 0; `--ran` reconciliation 126 accounted, 1 NOT MEASURED. - All other readings above were taken at head 2d20f93 (after merging origin/main ad50d61), except the full spec suite, the full studio-design suite and the ablation, which ran before the merge (at bc5a55626 and a6b5ec9, whose source is identical; a6b5ec9 adds only the changeset); the targeted refusal suites were re-run after the merge: spec `src/data/` + stack + ledger 191 files / 6806 tests passed, ui 5 files / 80 tests passed. </details> ## Acceptance notes - Card claim: the governing `Claim:` on #36526 is comment 7088513159, naming this card thread's branch `claude/project-thread-h6ofg9`. - `master-not-required` cannot reach the tab through a raw parse (an omitted `required` defaults to `false` first); its row exists for completeness. ## Verification Read first: `ui/packages/app-shell/src/views/studio-design/owd-sharing.ts` (`refusalShape`, `refusalFields`), `packages/spec/src/data/object.zod.ts` (the refinement's `params`), `ui/packages/i18n/src/namespaces/studio/zh.ts` (the six rows). Two-minute check: in Studio, open an object with no master-detail field, set sharing to "Follows its parent record" with the console in Chinese. Expected: the red line under the picker reads 「该对象设为「跟随所属的主记录」,但它没有可跟随的主从关系字段,因此无法保存。…」 with no ADR number. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmSBA2pE8xHD9x1XEXj <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmSBA2pE8xHD9x1XEXj --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f66340a commit d24e4ab

18 files changed

Lines changed: 530 additions & 50 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@object-ui/app-shell': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
feat: the controlled-by-parent master refusal carries a machine-readable code, and the Studio settings tab words it for the author in en and zh
8+
9+
Clause-②: yes
10+
Metadata-protocol: none
11+
12+
`@objectstack/spec` — the refusal of a `sharingModel: 'controlled_by_parent'` object that does not derive exactly one writable master now stamps its parse issue with `params: { code: 'CONTROLLED_BY_PARENT_MASTER_INVALID', shape }`, at both raise sites: `ObjectSchema`'s refinement and `defineStack`'s extension-merge gate. `shape` is the refusal's existing `ControlledByParentMasterShape` (`several-required-masters`, `several-masters`, `master-not-required`, `required-lookup-only`, `no-master`, `master-not-writable`). The code is exported as `CONTROLLED_BY_PARENT_MASTER_INVALID` from `@objectstack/spec/data`, with the `ControlledByParentMasterIssueParams` type, and is registered in `ERROR_CODE_LEDGER` under `@objectstack/spec`. Which objects are refused, and where, is unchanged.
13+
14+
The refusal's English message no longer cites an ADR section: each of its three arms read `ADR-0055 §1: since @objectstack/spec 18, …` and now reads `Since @objectstack/spec 18, …`. The rest of each message, including the fix it prescribes, is unchanged. A script that matched `ADR-0055 §1:` in this message should match `params.code` on the zod issue instead, where it can see the issue: an `ObjectSchema` / `ObjectStackDefinitionSchema` `safeParse`, or the `issues` of `defineStack`'s `STACK_SCHEMA_INVALID` refusal. The metadata save door's `422 INVALID_METADATA` does not carry the code: its `issues[]` entries keep `path`, `message` and zod's issue code (`custom`) only, so a reader there still has only the message.
15+
16+
`@object-ui/app-shell` / `@object-ui/i18n` — the Studio object settings tab no longer shows the spec's English message verbatim when "Follows its parent record" cannot be saved. It reads the code and shape off the save door's own parse and shows one sentence per shape from the `studio` namespace (`engine.studio.settings.cbpRefusal*`, en and zh), naming the fields to change by their labels. A refusal without the code, or with a shape that has no sentence, still shows the spec's message.

‎content/docs/references/api/automation-api.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ const result = AutomationApiErrorCode.parse(data);
425425

426426
| Property | Type | Required | Description |
427427
| :--- | :--- | :--- | :--- |
428-
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +378 more>` | ✅ | The inner refusal's code in its WIRE spelling - the ADR-0112 member a record save of the same write answers in `error.code` (e.g. `UNIQUE_VIOLATION`); the closed set `ApiErrorSchema.code` parses against |
428+
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +379 more>` | ✅ | The inner refusal's code in its WIRE spelling - the ADR-0112 member a record save of the same write answers in `error.code` (e.g. `UNIQUE_VIOLATION`); the closed set `ApiErrorSchema.code` parses against |
429429
| **message** | `string` | ✅ | The inner refusal's own diagnostic text, verbatim, without the node and operation prefixes the run's failure text adds |
430430

431431
### Allowed Values: `FlowInnerRefusal.code`
@@ -529,6 +529,7 @@ const result = AutomationApiErrorCode.parse(data);
529529
* `CONNECTOR_CREDENTIAL_REJECTED`
530530
* `CONNECTOR_UPSTREAM_CHANGED`
531531
* `CONNECTOR_UPSTREAM_UNAVAILABLE`
532+
* `CONTROLLED_BY_PARENT_MASTER_INVALID`
532533
* `CREATE_FAILED`
533534
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
534535
* `CUBE_NOT_FOUND`

‎content/docs/references/api/contract.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const result = ApiErrorSchema.parse(data);
2828

2929
| Property | Type | Required | Description |
3030
| :--- | :--- | :--- | :--- |
31-
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +378 more>` | ✅ | Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages) |
31+
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +379 more>` | ✅ | Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages) |
3232
| **declaredCode** | `string` | optional | The producer-declared code, verbatim, when it is not a member of the closed `code` vocabulary — the open, author-authored channel (app-specific spellings; ADR-0112) |
3333
| **message** | `string` | ✅ | Readable error message |
3434
| **userMessage** | `string` | optional | Producer-marked user-facing refusal text, verbatim, in the request's locale: platform-composed text falls back to the workspace default locale, then `en`; an app-authored refusal falls back to its declared wording. Present exactly when the producer opted in at throw time; consumers render it to end users as received and keep their generic substitution for anything unmarked. Status-agnostic; never replaces `message`. |
@@ -139,6 +139,7 @@ const result = ApiErrorSchema.parse(data);
139139
* `CONNECTOR_CREDENTIAL_REJECTED`
140140
* `CONNECTOR_UPSTREAM_CHANGED`
141141
* `CONNECTOR_UPSTREAM_UNAVAILABLE`
142+
* `CONTROLLED_BY_PARENT_MASTER_INVALID`
142143
* `CREATE_FAILED`
143144
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
144145
* `CUBE_NOT_FOUND`

‎content/docs/references/api/error-code-ledger.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ const result = ErrorCode.parse(data);
306306
* `CONNECTOR_CREDENTIAL_REJECTED`
307307
* `CONNECTOR_UPSTREAM_CHANGED`
308308
* `CONNECTOR_UPSTREAM_UNAVAILABLE`
309+
* `CONTROLLED_BY_PARENT_MASTER_INVALID`
309310
* `CREATE_FAILED`
310311
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
311312
* `CUBE_NOT_FOUND`

‎packages/spec/api-surface/data.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"CONTEXT_TOKEN_DESCRIPTIONS (const)",
111111
"CONTEXT_TOKEN_SUGGESTIONS (const)",
112112
"CONTEXT_TOKEN_WRAPPED_RE (const)",
113+
"CONTROLLED_BY_PARENT_MASTER_INVALID (const)",
113114
"CREDENTIAL_KEY_SPELLINGS (const)",
114115
"CREDENTIAL_URL_QUERY_PARAMS (const)",
115116
"CREDENTIAL_URL_QUERY_PARAM_NAMES (const)",
@@ -143,6 +144,7 @@
143144
"ContextTokenPlaceholderSchema (const)",
144145
"ContextTokenSchema (const)",
145146
"ControlledByParentMaster (interface)",
147+
"ControlledByParentMasterIssueParams (interface)",
146148
"ControlledByParentMasterRefusal (interface)",
147149
"ControlledByParentMasterShape (type)",
148150
"CrossFieldColumnVerdict (type)",

‎packages/spec/export-origins/data.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"CONTEXT_TOKEN_DESCRIPTIONS": "src/data/context-tokens.zod.ts#CONTEXT_TOKEN_DESCRIPTIONS (const)",
108108
"CONTEXT_TOKEN_SUGGESTIONS": "src/data/context-tokens.zod.ts#CONTEXT_TOKEN_SUGGESTIONS (const)",
109109
"CONTEXT_TOKEN_WRAPPED_RE": "src/data/context-tokens.zod.ts#CONTEXT_TOKEN_WRAPPED_RE (const)",
110+
"CONTROLLED_BY_PARENT_MASTER_INVALID": "src/data/controlled-by-parent-master.ts#CONTROLLED_BY_PARENT_MASTER_INVALID (const)",
110111
"CREDENTIAL_KEY_SPELLINGS": "src/data/driver/common.zod.ts#CREDENTIAL_KEY_SPELLINGS (const)",
111112
"CREDENTIAL_URL_QUERY_PARAMS": "src/data/driver/common.zod.ts#CREDENTIAL_URL_QUERY_PARAMS (const)",
112113
"CREDENTIAL_URL_QUERY_PARAM_NAMES": "src/data/driver/common.zod.ts#CREDENTIAL_URL_QUERY_PARAM_NAMES (const)",
@@ -140,6 +141,7 @@
140141
"ContextTokenPlaceholderSchema": "src/data/context-tokens.zod.ts#ContextTokenPlaceholderSchema (const)",
141142
"ContextTokenSchema": "src/data/context-tokens.zod.ts#ContextTokenSchema (const)",
142143
"ControlledByParentMaster": "src/data/controlled-by-parent-master.ts#ControlledByParentMaster (interface)",
144+
"ControlledByParentMasterIssueParams": "src/data/controlled-by-parent-master.ts#ControlledByParentMasterIssueParams (interface)",
143145
"ControlledByParentMasterRefusal": "src/data/controlled-by-parent-master.ts#ControlledByParentMasterRefusal (interface)",
144146
"ControlledByParentMasterShape": "src/data/controlled-by-parent-master.ts#ControlledByParentMasterShape (type)",
145147
"CrossFieldColumnVerdict": "src/data/filter-cross-field-comparison-class.ts#CrossFieldColumnVerdict (type)",

‎packages/spec/src/api/error-code-ledger.zod.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,17 @@ export const ERROR_CODE_LEDGER = {
19071907
// tree answers with it, the thrown value is the boundary.
19081908
'CONNECTOR_UPSTREAM_CHANGED',
19091909
'CONNECTOR_UPSTREAM_UNAVAILABLE',
1910+
// `door: 'none'` on the `PLUGIN_UI_REQUIRED_KEY_MISSING` reading below: the
1911+
// `controlled_by_parent` master refusal's code (`data/controlled-by-parent-master.ts`),
1912+
// stamped on the zod ISSUE as `params.code` beside `params.shape` by
1913+
// `ObjectSchema`'s refinement and `defineStack`'s extension-merge gate, never
1914+
// on a thrown error, and not in the `message`; no `status` of its own.
1915+
// Visible on the zod issue itself (any `safeParse`, the Studio settings
1916+
// tab's path, which keys its localized wording on it) and on `defineStack`'s
1917+
// `STACK_SCHEMA_INVALID` refusal, whose `issues` are the raw zod issues. NOT
1918+
// on the metadata save door's `422 INVALID_METADATA`: `zodIssuesToMetadataIssues`
1919+
// keeps `path`, `message` and zod's `code` ('custom'), never `params`.
1920+
'CONTROLLED_BY_PARENT_MASTER_INVALID',
19101921
'EXTERNAL_SCHEMA_MISMATCH',
19111922
'EXTERNAL_SCHEMA_MODE_VIOLATION',
19121923
'EXTERNAL_WRITE_FORBIDDEN',

‎packages/spec/src/data/controlled-by-parent-master.ts‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ export type ControlledByParentMasterShape =
9898
| 'no-master'
9999
| 'master-not-writable';
100100

101+
/**
102+
* The machine-readable code of a `controlled_by_parent` master refusal, so a
103+
* reader can tell the refusal apart without reading its English `message`.
104+
*
105+
* Stamped on the parse issue by both raise sites — `ObjectSchema`'s refinement
106+
* (`refuseControlledByParentWithoutOneMaster`, `object.zod.ts`) and the
107+
* extension-merge gate (`applyControlledByParentExtensionGate`,
108+
* `stack.zod.ts`) — as zod's slot for custom-issue metadata:
109+
* `params: { code: CONTROLLED_BY_PARENT_MASTER_INVALID, shape }`, where
110+
* `shape` is the refusal's {@link ControlledByParentMasterShape}. One code for
111+
* every shape; the shape says which fix applies. A surface that shows the
112+
* refusal in the author's own language (the Studio object settings tab) keys
113+
* its wording on the shape and keeps the `message` as the fallback.
114+
*
115+
* Registered in `ERROR_CODE_LEDGER` under `@objectstack/spec` (ADR-0112: a code
116+
* that ships in `dist` is the published face, door or no door). It has no
117+
* `status` of its own, and it is NOT in the `message`. Where a reader can see
118+
* it: on the zod issue itself (any `ObjectSchema` / `ObjectStackDefinitionSchema`
119+
* `safeParse`, which is the Studio tab's path), and on `defineStack`'s
120+
* `STACK_SCHEMA_INVALID` refusal, whose `issues` are the raw zod issues. Where
121+
* it is not: the metadata save door's `422 INVALID_METADATA` — its `issues[]`
122+
* entries (`zodIssuesToMetadataIssues`, `@objectstack/metadata-protocol`) carry
123+
* `path`, `message` and zod's own issue `code` (`'custom'`), never `params`.
124+
*/
125+
export const CONTROLLED_BY_PARENT_MASTER_INVALID = 'CONTROLLED_BY_PARENT_MASTER_INVALID' as const;
126+
127+
/**
128+
* The `params` a `controlled_by_parent` master refusal carries on its parse
129+
* issue — see {@link CONTROLLED_BY_PARENT_MASTER_INVALID}.
130+
*/
131+
export interface ControlledByParentMasterIssueParams {
132+
readonly code: typeof CONTROLLED_BY_PARENT_MASTER_INVALID;
133+
readonly shape: ControlledByParentMasterShape;
134+
}
135+
101136
/** Why an object fails the one-required-master rule — see {@link controlledByParentMasterRefusal}. */
102137
export interface ControlledByParentMasterRefusal {
103138
/**
@@ -228,7 +263,7 @@ export function controlledByParentMasterRefusal(
228263
requiredLookups,
229264
message:
230265
`Object '${name}' declares sharingModel 'controlled_by_parent' with its ${which}, `
231-
+ `\`${master.field}\`, marked ${flags.map((f) => `\`${f}: true\``).join(' and ')}. ADR-0055 §1: since `
266+
+ `\`${master.field}\`, marked ${flags.map((f) => `\`${f}: true\``).join(' and ')}. Since `
232267
+ '@objectstack/spec 18, a controlled-by-parent object derives its master from exactly one '
233268
+ '`master_detail` field that every write of a detail supplies, and a field marked `readonly` or '
234269
+ '`system` is not one an author\'s write supplies, so this reference cannot be that master. '
@@ -245,7 +280,7 @@ export function controlledByParentMasterRefusal(
245280
requiredLookups,
246281
message:
247282
`Object '${name}' declares sharingModel 'controlled_by_parent' with ${masters.length} required `
248-
+ `\`master_detail\` fields (${masters.map((m) => `\`${m}\``).join(', ')}). ADR-0055 §1: since `
283+
+ `\`master_detail\` fields (${masters.map((m) => `\`${m}\``).join(', ')}). Since `
249284
+ '@objectstack/spec 18, a controlled-by-parent object derives its master from exactly one required `master_detail` field, so '
250285
+ 'with two the declaration does not say which master governs its rows, and the platform derives none '
251286
+ '(every read is denied, every write refused). Keep `master_detail` on the one master, and declare '
@@ -285,7 +320,7 @@ export function controlledByParentMasterRefusal(
285320
message:
286321
`Object '${name}' declares sharingModel 'controlled_by_parent' but no required \`master_detail\` field, `
287322
+ 'nor a single `master_detail` declared `required: false`. '
288-
+ 'ADR-0055 §1: since @objectstack/spec 18, a controlled-by-parent object derives its master from exactly '
323+
+ 'Since @objectstack/spec 18, a controlled-by-parent object derives its master from exactly '
289324
+ 'one `master_detail` field declared `required: true`, or, with none, from its only `master_detail` '
290325
+ 'declared `required: false` (an optional master: a row that names none is readable only by its owner '
291326
+ 'and by View All on the object), and from nothing else, so as declared the platform derives no master '

‎packages/spec/src/data/object.test.ts‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { collectDroppedRefinements } from '../../scripts/lib/dropped-refinements
1414
import { Field } from './field.zod';
1515
import { defineStack } from '../stack.zod';
1616
import { isMaskedOnReadFieldType } from './masked-field-types';
17+
import { CONTROLLED_BY_PARENT_MASTER_INVALID, type ControlledByParentMasterShape } from './controlled-by-parent-master';
1718
import type { StateMachineValidation } from './validation.zod';
1819

1920
describe('ObjectCapabilities', () => {
@@ -1635,7 +1636,13 @@ describe('ObjectSchema refuses a controlled_by_parent object without exactly one
16351636
({ name: 'cbp_line', sharingModel: 'controlled_by_parent' as const, fields });
16361637
const issuesOf = (input: unknown) => {
16371638
const r = ObjectSchema.safeParse(input);
1638-
return r.success ? [] : r.error.issues.map((i) => ({ path: i.path.join('.'), message: i.message }));
1639+
return r.success
1640+
? []
1641+
: r.error.issues.map((i) => ({
1642+
path: i.path.join('.'),
1643+
message: i.message,
1644+
params: (i as { params?: Record<string, unknown> }).params,
1645+
}));
16391646
};
16401647

16411648
it('ACCEPTS one required master_detail — through the raw parse and through the builder', () => {
@@ -1653,7 +1660,7 @@ describe('ObjectSchema refuses a controlled_by_parent object without exactly one
16531660
const issues = issuesOf(cbp({ parent: { type: 'lookup', reference: 'cbp_header', required: true } }));
16541661
expect(issues).toHaveLength(1);
16551662
expect(issues[0].path).toBe('sharingModel');
1656-
expect(issues[0].message).toMatch(/^Object 'cbp_line' declares sharingModel 'controlled_by_parent' but no required `master_detail` field, nor a single `master_detail` declared `required: false`\. ADR-0055 §1:/);
1663+
expect(issues[0].message).toMatch(/^Object 'cbp_line' declares sharingModel 'controlled_by_parent' but no required `master_detail` field, nor a single `master_detail` declared `required: false`\. Since @objectstack\/spec 18, /);
16571664
expect(issues[0].message).toContain("`parent` is a required `lookup`");
16581665
// The builder path refuses it too — the HotCRM shape.
16591666
expect(() => ObjectSchema.create(cbp({ parent: Field.lookup('cbp_header', { label: 'Header', required: true }) }))).toThrow(
@@ -1692,10 +1699,33 @@ describe('ObjectSchema refuses a controlled_by_parent object without exactly one
16921699
b: { type: 'master_detail', reference: 'master_b', required: true },
16931700
}));
16941701
expect(two.map((i) => i.path)).toEqual(['fields']);
1695-
expect(two[0].message).toMatch(/^Object 'cbp_line' declares sharingModel 'controlled_by_parent' with 2 required `master_detail` fields \(`a`, `b`\)\. ADR-0055 §1:/);
1702+
expect(two[0].message).toMatch(/^Object 'cbp_line' declares sharingModel 'controlled_by_parent' with 2 required `master_detail` fields \(`a`, `b`\)\. Since @objectstack\/spec 18, /);
16961703
// Both refusals date themselves: 17.7.0 accepts either shape, so each names the release that refuses it.
1697-
expect(two[0].message).toContain('since @objectstack/spec 18, a controlled-by-parent object derives');
1698-
expect(none[0].message).toContain('since @objectstack/spec 18, a controlled-by-parent object derives');
1704+
expect(two[0].message).toContain('Since @objectstack/spec 18, a controlled-by-parent object derives');
1705+
expect(none[0].message).toContain('Since @objectstack/spec 18, a controlled-by-parent object derives');
1706+
});
1707+
1708+
it('stamps every refusal with the machine-readable code and its shape, and cites no ADR in the message', () => {
1709+
const SHAPES: Array<[ControlledByParentMasterShape, Record<string, unknown>]> = [
1710+
['no-master', { title: { type: 'text' } }],
1711+
['required-lookup-only', { parent: { type: 'lookup', reference: 'cbp_header', required: true } }],
1712+
['several-masters', {
1713+
a: { type: 'master_detail', reference: 'master_a', required: false },
1714+
b: { type: 'master_detail', reference: 'master_b', required: false },
1715+
}],
1716+
['several-required-masters', {
1717+
a: { type: 'master_detail', reference: 'master_a', required: true },
1718+
b: { type: 'master_detail', reference: 'master_b', required: true },
1719+
}],
1720+
['master-not-writable', { parent: { type: 'master_detail', reference: 'cbp_header', required: true, system: true } }],
1721+
];
1722+
for (const [shape, fields] of SHAPES) {
1723+
const issues = issuesOf(cbp(fields));
1724+
expect(issues, shape).toHaveLength(1);
1725+
expect(issues[0].params, shape).toEqual({ code: CONTROLLED_BY_PARENT_MASTER_INVALID, shape });
1726+
expect(issues[0].message, shape).not.toMatch(/ADR-/);
1727+
}
1728+
expect(CONTROLLED_BY_PARENT_MASTER_INVALID).toBe('CONTROLLED_BY_PARENT_MASTER_INVALID');
16991729
});
17001730

17011731
it('judges controlled_by_parent only — every other sharing model keeps its relations as authored', () => {

0 commit comments

Comments
 (0)