Skip to content

Commit 75ab117

Browse files
fix(spec,lint): os lint reports an omitted cbp master required on the default defineStack door (#34020)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9CZHtkC74Ydb9at95QTnivt)_ Fixes #33940 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 改了什么:默认(strict)`defineStack` 解析时,如果作者在 `controlled_by_parent` 对象的 `master_detail` 上没写 `required`,spec 会在解析后的字段上悄悄记一笔“作者省略了”;`os lint` 的 `relationship/master-detail-required` 读这笔记录,在默认写法下也报 error。 - 为什么改:裁决 A(#30905,记录 6687830530)放行可选主字段,同时承诺 `os lint` 对省略写法报错;但默认 strict 解析先把省略填成 false,lint 永远看不到,迁移说明那句话在最常见的写法下是假的。 - 风险与回滚:解析结果不变(仍是 `required: false`,可选主字段),栈照常加载,`os validate` / `os build` 不变;只是 `os lint` 在这一种写法上多报一条 error。回滚即 revert 本 PR。 - 先看:`packages/spec/src/data/master-detail-required-omission.ts`(记录与读取),`packages/spec/src/stack.zod.ts` 中 `recordMasterDetailRequiredOmissions` 的调用,`packages/lint/src/data-model-rules.ts` 中 `optionalMaster` 那一行。 - 两分钟验证:在示例应用副本的默认 `defineStack({ … })` 里加一个 cbp 对象,唯一的 master_detail 不写 required,跑 `os lint --json`:应 exit 1,报 relationship/master-detail-required 在 `.required`;改成 `required: false` 后应 exit 0。 - 需要你做的:无,席位落地。 ## What changes - **`@objectstack/spec`** — new module `src/data/master-detail-required-omission.ts`. After a strict `defineStack` parse succeeds, `recordMasterDetailRequiredOmissions(normalized.objects, data.objects)` stamps a non-enumerable, non-writable `Symbol.for('objectstack.field.masterDetailRequiredOmitted')` on each parsed `master_detail` field of a `controlled_by_parent` object whose authored definition writes no `required`. The one published reader is `masterDetailRequiredOmitted(field)` (`@objectstack/spec/data`); the stamp is internal (not re-exported), mirroring `stack-provenance.ts`. The parsed value is untouched (`required: false`), so the ruled reading (option A: the omission is admitted as the optional master) holds at every runtime reader, and nothing refuses the stack. - **`@objectstack/lint`** — `cbpMasterReferenceFinding` (R2) treats a sole `master_detail` as the optional master only when `required === false` AND the field does not carry the record. On the default door the omitted spelling now gets the same finding, path and fix it already got on `{ strict: false }` and on a raw config. - **Why on the field, not the stack:** `loadConfig` (`packages/cli/src/utils/config.ts`) spreads the default export into a new object, which drops a stack-level symbol (that is why it reads `stackConversionsOf` before the spread). The `objects` array and each field reach `lintDataModel` by reference, so a field-level record needs no `packages/cli` change and no second load of the user's module. Measured: `composeStacks` (error / override / merge) keeps the record on the composed field too. - Regenerated: `packages/spec/api-surface/data.json`, `packages/spec/export-origins/data.json` (one added export each). - **Fix of text this change made false:** `docs/qa/platform-checklist/areas/cli.json`, item `cli.validate-v18-authoring-verdicts`. Revision 4 (PR #33929, merged into main while this card was in flight) moved the item's `os lint` arm to `{ strict: false }` and said the default strict door gives `os lint` exit 0 with no finding. That is no longer true, so revision 6 (stacked on main's revision 5, PR #34068, which only adds `--reporter=tree` to acceptance[0].verify) moves steps[2] and acceptance[3] back to the default door, states that the default door reports only `relationship/master-detail-required` (not `security-controlled-by-parent-no-relation`, because the parsed field is the optional master the runtime derives access from) and keeps `{ strict: false }` as the second door. No other clause changed. - Docblocks touched: `data-model-rules.ts` (R2 header), `controlled-by-parent-master.ts` (module header). The semantic entry `cbp-optional-master-admitted` is unchanged: its sentence "`os lint` reports the omission at `error`" is now true on the default door, which was the seat's call (fix the reach, not the prose). ## Why The maintainer ruling on #30905 (record 6687830530), option 「A 放行为可选主字段(推荐)」, keeps the omitted `required` readable as the optional master at the parse and pairs it with the lint: "`os lint` errors on the omitted spelling". The published entry repeats that promise. On the ordinary authoring door it did not hold (measured on #33842 / PR #33929). ## Tests New, no existing assertion edited (no forced test edits): - `packages/spec/src/data/master-detail-required-omission.test.ts` (7 cases): strict `defineStack` records an omitted `required` on the sole master and on a second `master_detail` beside a required one; nothing for explicit `false` / `true`, for another sharing model, for a lookup, for `{ strict: false }`, or for a bare `ObjectSchema.safeParse`; the record is invisible to `Object.keys`, `JSON.stringify` and `FieldSchema`, and a copy drops it. - `packages/lint/src/data-model-rules.master-detail-required.test.ts`, new top-level `describe` (4 cases) over stacks a real `defineStack` built: omitted → one error at `.required` with both spellings; CONTROLS explicit `false` and `true` → clean; `{ strict: false }` → the same finding as before; a copied field → clean (the pre-record reading). Ablations (each committed first, mutated through `scripts/ablation-replace.mjs`, rebuilt, `ablation-dist-preflight` hit, then restored with blob == HEAD and rebuilt with the marker absent from dist): - A1, lint stops reading the record: lint unit `the sole master_detail without required` turns red (1 failed / 33 passed); the CLI on the default door reads `os lint` exit 0, passed true, 0 R2 findings (the defect). - A2, `defineStack` stops stamping: spec unit 3 failed / 4 passed (src), lint unit 1 failed / 33 passed (spec dist), CLI default door `os lint` exit 0 with 0 R2 findings. ## Acceptance notes - `Clause-②: yes` differs from the claim's expected `no`: the diff adds one public export, `masterDetailRequiredOmitted` on `@objectstack/spec/data`, and the spec lane charter counts any widening of the public surface as Clause ②. No parse accept set moves, so `Metadata-protocol: none` and patch changesets. - On the default door only R2 fires; `security-controlled-by-parent-no-relation` does not, because the stack the runtime loads really does derive the optional master from the parsed `false`. On `{ strict: false }` both fire, as before. - Not reached by design: the save door and a bare `ObjectSchema.safeParse` record nothing (neither runs `os lint`); `ObjectSchema.create()` still forces an omitted `required` to `true`. - The record lives in `packages/spec` as a declared producer record beside the provenance mark, not as business logic: it states what the author wrote and nothing reads it at runtime. - `pnpm --filter @objectstack/spec check:generated` exits 1 at Node's default heap in this container: its `check:test-typecheck` leg's `tsc` dies without diagnostics. At `NODE_OPTIONS=--max-old-space-size=6144` (the heap `lint.yml` sets for the ledger re-measure) it exits 0 with all 14 artifacts current, and `check:test-typecheck` alone reads OK (52 files / 240 errors / 131 pinned signatures held). ## Verification Verification head: `7e6f3db1` (main `ea6de745` merged in via `scripts/pm/os-regen-merge.sh`). That merge had one conflict, `docs/qa/platform-checklist/areas/cli.json` item `cli.validate-v18-authoring-verdicts`: PR #34068 had meanwhile taken revision 5 on the same item. Resolution: main's revision 5 row and its acceptance[0] edit are kept as written; this PR's row is renumbered to revision 6 and the item's `revision` set to 6. Apart from those two numbers the PR's diff is byte-identical to the one verified at `6e1439cc` (per-file hunks of `git diff e71ecc1 d468bb8` and `git diff ea6de74 7e6f3db` match in 10 of 11 files; cli.json differs only in `"revision": 5` → `6` on the item and the row). Re-read at `7e6f3db1` after `pnpm install --frozen-lockfile`, `rm -rf packages/runtime/.objectstack` and a full `./packages/**` rebuild under the verify lock: `check:generated` exit 0 at heap 6144 (all 14 artifacts current), spec test 844 files / 26973 tests passed, lint test 212 files / 9030 tests passed, `check:platform-checklist` exit 0 (16 areas, 433 items). The readings below were verified at `6e1439cc` (main `b4ce310b` merged in via `scripts/pm/os-regen-merge.sh`; no conflict, the regen chain found nothing to rewrite). Re-read at `6e1439cc` after `pnpm install --frozen-lockfile`, `rm -rf packages/runtime/.objectstack` and a full `./packages/**` rebuild under the verify lock: `check:generated` exit 0 (all 14 artifacts current), spec test 843 files / 26968 tests passed, lint test 212 files / 9030 tests passed, the four end-to-end readings below unchanged, and the 96 derived gates all exit 0 at heap 6144 (`--ran`: 96 run, 0 NOT-MEASURED). CI on `6e1439cc`: every check-run completed, all required contexts success. The readings below were first taken at `eb7616fe` (main `0ac112fc` merged in), with the same results. <details> <summary>End to end: the #33929 reproduction and its controls (scratch copy of examples/app-todo, CLI from the tree)</summary> ``` === sole master_detail, required omitted, default strict defineStack os lint --json exit 1 passed false error relationship/master-detail-required at objects[2].fields.hdr.required os validate --json exit 0 os build exit 0 === required: false, default door os lint --json exit 0 passed true os validate --json exit 0 os build exit 0 === required: true, default door os lint --json exit 0 passed true os validate --json exit 0 os build exit 0 === required omitted, defineStack(..., { strict: false }) os lint --json exit 1 passed false error relationship/master-detail-required at objects[2].fields.hdr.required error security-controlled-by-parent-no-relation at objects[2].sharingModel os validate --json exit 0 os build exit 0 ``` Base reading (#33929, at 895783a): the first case gave `os lint --json` exit 0 with no finding. The shipped examples app-crm and app-todo lint with no R2 finding (their cbp masters are built by `ObjectSchema.create()`, which writes `required: true`); app-showcase's config could not load here (its connector-slack dist is not in the CLI closure), and its two cbp masters are `ObjectSchema.create()` with `required: true` in source. </details> <details> <summary>Package tests and typecheck (under the verify lock)</summary> ``` pnpm --filter @objectstack/spec test Test Files 843 passed (843) Tests 26968 passed | 1 todo pnpm --filter @objectstack/lint test Test Files 212 passed (212) Tests 9030 passed pnpm --filter @objectstack/spec typecheck VERDICT command-exit 0 pnpm --filter @objectstack/lint typecheck VERDICT command-exit 0 pnpm --filter @objectstack/cli exec vitest run --project unit Test Files 422 passed (422) Tests 6002 passed ``` The cli integration layer is declared to CI (no spawn entry or integration file touched). </details> <details> <summary>Derived gates (dispatch-gates --commands at eb7616f, re-run at 6e1439c)</summary> 96 derived families, 96 run, reconciled with `--ran`: "96 run, 0 NOT-MEASURED (a DERIVED zero)". 95 exited 0 at the default heap; `check:generated` exited 1 there (the out-of-memory `tsc` above) and 0 at the CI heap of 6144, which is the line reconciled. `check:platform-checklist` exit 0 (16 areas, 429 items). `check:dev-prereqs` (local-only family): NOT MEASURED, 34 `ui/` packages unbuilt in this container. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic (the record is a producer stamp beside the provenance mark; nothing reads it at runtime). - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is CI's. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. <!-- signed: domain:spec#2 · os-steve · session_01ADHkmSUpRcnYp68V8zPYaB --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 121017b commit 75ab117

11 files changed

Lines changed: 356 additions & 7 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/lint': patch
4+
---
5+
6+
fix(spec,lint): `os lint` reports an omitted `required` on a `controlled_by_parent` object's `master_detail` on the default strict `defineStack` door
7+
8+
Clause-②: yes
9+
Metadata-protocol: none
10+
11+
The semantic migration entry `cbp-optional-master-admitted` (maintainer ruling A on the optional master, ADR-0055 §1 as amended) says that a raw parse reads an omitted `required` as the optional master and that `os lint` reports the omission at `error`, so the author writes `true` or `false`. On a project whose `objectstack.config.ts` calls `defineStack({ … })` with its default strict parse, `os lint` did not: the parse had already written `false` into the omitted key before any command loaded the stack, so `relationship/master-detail-required` read the explicit optional master and passed. Only `defineStack(…, { strict: false })` and a raw object config reached the finding.
12+
13+
**`@objectstack/spec`.** A strict `defineStack` now records, on each parsed `master_detail` field of a `controlled_by_parent` object whose authored definition writes no `required`, that the key was omitted. The new reader `masterDetailRequiredOmitted(field)` (`@objectstack/spec/data`) answers it. The record is a non-enumerable symbol on the field: it is not a key, so the field schema, `JSON.stringify` and the compiled `dist/objectstack.json` never see it, and any copy of the field drops it. Nothing parsed changes: `required` is still `false`, the stack still loads, and the runtime still reads the field as the optional master, as ruled.
14+
15+
**`@objectstack/lint`.** `relationship/master-detail-required` reads that record, so on the default door it now reports the omitted `required` on the object's only `master_detail` at `error`, with the same message, path and fix it already gave on `{ strict: false }`: write `required: true` (every detail names its master) or `required: false` (an optional master). An explicit `required: false` or `required: true` still lints clean. `os validate` and `os build` are unchanged.

‎docs/qa/platform-checklist/areas/cli.json‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@
24242424
"title": "`os validate` / `os build` verdicts new on v18: an unknown seed record key (with did-you-mean), a misspelt record[…] / previous[…] field, a duplicate stack entry name, a controlled_by_parent object with no master_detail or with two required ones (also through objectExtensions), a component-props finding (now an error), and a credential in stack email/sms config each fail the build",
24252425
"since": "v18",
24262426
"status": "active",
2427-
"revision": 5,
2427+
"revision": 6,
24282428
"priority": "P1",
24292429
"surface": "cli",
24302430
"personas": [
@@ -2440,7 +2440,7 @@
24402440
"steps": [
24412441
"for each arm run `os validate --json` and `os build`, recording exit code + rule id + path: seed key created_atx; record[\"typo\"] in a validation; two datasources named alike; a cbp object with no master_detail; a cbp object with two master_details both declared required: true, once inline and once with the second arriving through objectExtensions; an object-grid with defaultFilters; email:{apiKey:\"x\"}",
24422442
"controls: seed key created_at, record.name == \"record.typo\", email.provider, and a cbp object whose ONLY master_detail declares required: false (the optional master, ruling A of #30905) — all pass",
2443-
"the os lint arm: in the scratch app switch the stack call to `defineStack({ … }, { strict: false })` — the one door where the omission survives to `os lint` — and author a cbp object as a plain object literal (not through ObjectSchema.create(), which forces an omitted required to true) whose ONLY master_detail omits `required`; run `os lint --json`, then `os validate --json` and `os build`, recording each exit code and rule id. Not the default strict `defineStack({ … })`: its parse defaults the omitted `required` to false before any CLI verb loads the stack, so `os lint` reads the optional master and reports nothing. Not a raw-object default export either: `os lint` reports the rule there, but `os validate` and `os build` refuse any export `defineStack` did not build"
2443+
"the os lint arm: in the scratch app keep the default strict `defineStack({ … })` and author a cbp object as a plain object literal (not through ObjectSchema.create(), which forces an omitted required to true) whose ONLY master_detail omits `required`; run `os lint --json`, then `os validate --json` and `os build`, recording each exit code and rule id. The strict parse defaults the omitted `required` to false (ruling A of #30905, the optional master) and records the omission on the field it returns, which the lint rule reads. `defineStack({ … }, { strict: false })` reaches the same finding (the key is still absent there). Not a raw-object default export: `os lint` reports the rule there, but `os validate` and `os build` refuse any export `defineStack` did not build"
24442444
],
24452445
"acceptance": [
24462446
{
@@ -2462,9 +2462,9 @@
24622462
"evidence": "four lines"
24632463
},
24642464
{
2465-
"clause": "the lint-only shape is `os lint`'s verdict, not the build's: on a stack built by `defineStack(…, { strict: false })` (steps[2]'s door), a cbp object whose ONLY master_detail omits `required` fails `os lint` with relationship/master-detail-required at error, while `os validate` and `os build` accept it",
2465+
"clause": "the lint-only shape is `os lint`'s verdict, not the build's: on a stack built by the default strict `defineStack({ … })` (steps[2]'s door), a cbp object whose ONLY master_detail omits `required` fails `os lint` with relationship/master-detail-required at error, while `os validate` and `os build` accept it",
24662466
"oracle": "build",
2467-
"verify": "on the `strict: false` door, `os lint` exits ≠ 0 naming relationship/master-detail-required at the master_detail's path (it is a lintDataModel rule, packages/lint/src/data-model-rules.ts#RELATIONSHIP_MASTER_DETAIL_REQUIRED, which `os lint` runs and `os validate` / `os build` do not; the same run also reports security-controlled-by-parent-no-relation at error on the object's sharingModel); the door matters because the rule reads the stack as loaded and, as its docblock says, the strict parse cannot see the omission: on the default strict `defineStack` the same object reaches every verb as `required: false`, `os lint` exits 0 with no relationship/master-detail-required, and that run is not this clause's arm; `os validate --json` and `os build` exit 0, because the parse reads the parsed `required: false` and admits the optional master (packages/spec/src/data/controlled-by-parent-master.ts#controlledByParentMasterRefusal, ruling A of #30905). An explicit `required: false` on the ONLY master_detail is the optional master and passes all three (a control, steps[1]); the rule's cases are pinned at unit by packages/lint/src/data-model-rules.master-detail-required.test.ts, acceptance[0]'s pin",
2467+
"verify": "on the default strict door, `os lint` exits ≠ 0 naming relationship/master-detail-required at the master_detail's `.required` path (it is a lintDataModel rule, packages/lint/src/data-model-rules.ts#RELATIONSHIP_MASTER_DETAIL_REQUIRED, which `os lint` runs and `os validate` / `os build` do not); the rule sees the omission there because `defineStack` records it on the parsed field (packages/spec/src/data/master-detail-required-omission.ts#masterDetailRequiredOmitted) after the parse has written `required: false`. The same run does NOT report security-controlled-by-parent-no-relation: the parsed field is the optional master the runtime derives access from. On `defineStack(…, { strict: false })` the key stays absent, so `os lint` reports relationship/master-detail-required at the same path and also security-controlled-by-parent-no-relation at the object's sharingModel. `os validate --json` and `os build` exit 0 on both doors, because the parse reads the parsed `required: false` and admits the optional master (packages/spec/src/data/controlled-by-parent-master.ts#controlledByParentMasterRefusal, ruling A of #30905). An explicit `required: false` on the ONLY master_detail is the optional master and passes all three (a control, steps[1]); the rule's cases are pinned at unit by packages/lint/src/data-model-rules.master-detail-required.test.ts, acceptance[0]'s pin",
24682468
"evidence": "the os lint, os validate and os build exits + the lint finding line"
24692469
}
24702470
],
@@ -2509,6 +2509,12 @@
25092509
"date": "2026-11-15",
25102510
"change": "acceptance[0].verify names `--reporter=tree`, the reporter that prints the one line per pin file this is scored on: in a runner's non-TTY shell vitest's default reporter prints the run's totals only (RUNNER.md's environment facts; QA run #33784's note 10, comment 6893243542). No clause or threshold changed. Card #33969",
25112511
"ref": "#34068"
2512+
},
2513+
{
2514+
"revision": 6,
2515+
"date": "2026-11-15",
2516+
"change": "steps[2] and acceptance[3] move the os lint arm back to the default strict `defineStack({ … })` (card #33940, the reach half of ruling A of #30905: `os lint` errors on the omitted spelling). `defineStack` now records an omitted `required` on a cbp master_detail on the parsed field (packages/spec/src/data/master-detail-required-omission.ts#masterDetailRequiredOmitted) and relationship/master-detail-required reads it. Driven live in a scratch copy of examples/app-todo with the CLI from the tree: default strict door `os lint --json` exit 1 with relationship/master-detail-required at objects[2].fields.hdr.required (no security-controlled-by-parent-no-relation), `os validate --json` / `os build` exit 0; `required: false` and `required: true` lint clean; `{ strict: false }` unchanged from rev 4. The other clauses are unchanged",
2517+
"ref": "#33940"
25122518
}
25132519
]
25142520
},

‎packages/lint/src/data-model-rules.master-detail-required.test.ts‎

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
*/
2727

2828
import { describe, expect, it } from 'vitest';
29-
import { Field, ObjectSchema } from '@objectstack/spec/data';
29+
import { defineStack } from '@objectstack/spec';
30+
import { Field, ObjectSchema, masterDetailRequiredOmitted } from '@objectstack/spec/data';
3031
import {
3132
lintDataModel as lintDataModelUnrecorded,
3233
RELATIONSHIP_DELETE_BEHAVIOR,
@@ -229,6 +230,67 @@ describe('R2 over objects built by ObjectSchema.create()', () => {
229230
});
230231
});
231232

233+
// [#33940 · ruling A, record 6687830530] What reaches the rule from the
234+
// DEFAULT door: a config module that calls `defineStack` itself, strict. The
235+
// parse writes `false` into an omitted `required` (the optional master, as
236+
// ruled) and records the omission on the field it returns; the rule reads that
237+
// record, so the omitted spelling is reported here exactly as on the raw
238+
// literal and on `{ strict: false }`. The stack still loads in every case.
239+
describe('R2 over a stack a strict defineStack built — the omitted spelling is still reported (#33940)', () => {
240+
const built = (shape: Record<string, unknown>, options?: { strict: boolean }) =>
241+
(
242+
defineStack(
243+
{
244+
manifest: { id: 'com.example.r2-door', namespace: 'wo', version: '0.0.1', type: 'app', name: 'R2' },
245+
objects: [
246+
{ name: 'wo_order', label: 'Order', fields: { name: { type: 'text', label: 'Name' } } },
247+
{
248+
name: 'wo_item',
249+
label: 'Item',
250+
sharingModel: 'controlled_by_parent',
251+
fields: { order: { type: 'master_detail', label: 'Order', reference: 'wo_order', deleteBehavior: 'cascade', ...shape } },
252+
},
253+
],
254+
} as never,
255+
options,
256+
) as unknown as { objects: any[] }
257+
).objects;
258+
259+
it('the sole master_detail without `required`: one error at `.required`, naming both spellings', () => {
260+
const objects = built({});
261+
// The parsed value is the ruled one: `false`, the optional master — recorded as omitted.
262+
expect(objects[1].fields.order.required).toBe(false);
263+
expect(masterDetailRequiredOmitted(objects[1].fields.order)).toBe(true);
264+
const issues = r2(objects);
265+
expect(issues).toHaveLength(1);
266+
expect(issues[0]).toMatchObject({
267+
severity: 'error',
268+
rule: R2,
269+
path: 'objects[1].fields.order.required',
270+
fix: 'required: true',
271+
});
272+
expect(issues[0]!.message).toContain('declares no required: write true (every detail names its master) or false (an optional master)');
273+
});
274+
275+
it('CONTROL: an explicit `required: false` (the optional master) and `required: true` lint clean', () => {
276+
expect(r2(built({ required: false }))).toEqual([]);
277+
expect(r2(built({ required: true }))).toEqual([]);
278+
});
279+
280+
it('CONTROL: `{ strict: false }` reports the same finding, on the same path, as before', () => {
281+
const issues = r2(built({}, { strict: false }));
282+
expect(issues.map((issue) => [issue.severity, issue.path, issue.fix])).toEqual([
283+
['error', 'objects[1].fields.order.required', 'required: true'],
284+
]);
285+
});
286+
287+
it('a copy of the built field drops the record and reads as the explicit `false` — the pre-record reading', () => {
288+
const objects = built({});
289+
const copied = [objects[0], { ...objects[1], fields: { order: { ...objects[1].fields.order } } }];
290+
expect(r2(copied)).toEqual([]);
291+
});
292+
});
293+
232294
describe('[#22161] one-line verdicts — relationship/master-detail-required, relationship/delete-behavior', () => {
233295
it('the published constants spell the ids the findings carry', () => {
234296
expect(RELATIONSHIP_MASTER_DETAIL_REQUIRED).toBe(R2);

‎packages/lint/src/data-model-rules.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
BOOLEAN_VALUE_TYPES,
2222
NUMERIC_VALUE_TYPES,
2323
isAggregateCompatibleWithFieldType,
24+
masterDetailRequiredOmitted,
2425
referenceCarrierOf,
2526
type AggregationFunction,
2627
} from '@objectstack/spec/data';
@@ -348,6 +349,12 @@ const CBP_ORPHAN_CONSEQUENCE =
348349
* `false`, so it admits the optional master) while `ObjectSchema.create()`
349350
* forces it to `true`: one source, two meanings, until the author writes one.
350351
* The fix stays `required: true`, the reading the builder already gives it.
352+
* This rule sees the omission on every stack `os lint` loads: an unparsed one
353+
* still lacks the key, and on one a strict `defineStack` parsed (the default
354+
* door, where the field arrives as `false`) the producer RECORDED it on the
355+
* field — `masterDetailRequiredOmitted` (`@objectstack/spec/data`) is that
356+
* record's reader (#33940). A field that lost the record (a copy) reads as the
357+
* explicit `false`, the optional master: the pre-record reading.
351358
*
352359
* Why these three. A `controlled_by_parent` detail derives ALL of its record
353360
* access from the master its `master_detail` reference names (ADR-0055: such an
@@ -413,8 +420,12 @@ function cbpMasterReferenceFinding(
413420
// `master_detail`, declared `required: false`, is its optional master — the
414421
// spelling passes. Beside another `master_detail` an explicit `false` is
415422
// judged as before; an omitted `required` is reported on every field.
423+
// [#33940] On a stack `defineStack` parsed, an omitted `required` arrives as
424+
// the parsed `false`; the producer's record of the omission
425+
// (`masterDetailRequiredOmitted`) is what tells the two apart, so the
426+
// omitted spelling is reported on the default strict door too.
416427
const soleMasterDetail = masterDetailCount === 1;
417-
const optionalMaster = soleMasterDetail && def.required === false;
428+
const optionalMaster = soleMasterDetail && def.required === false && !masterDetailRequiredOmitted(def);
418429
const missingRequired = def.required !== true && !optionalMaster;
419430
// On the sole `master_detail`, an omitted (or non-boolean) `required` has
420431
// two honest spellings; elsewhere only `required: true` is one.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@
10391039
"lintAuthoredRecordKeys (function)",
10401040
"lowerFilterCondition (function)",
10411041
"markFilterSubtreeProvenance (function)",
1042+
"masterDetailRequiredOmitted (function)",
10421043
"matchesLikePattern (function)",
10431044
"materializeTreeSelfReferences (function)",
10441045
"missingFieldValues (function)",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@
10251025
"lintAuthoredRecordKeys": "src/data/authoring-key-lint.ts#lintAuthoredRecordKeys (function)",
10261026
"lowerFilterCondition": "src/data/filter-lowering.ts#lowerFilterCondition (function)",
10271027
"markFilterSubtreeProvenance": "src/data/filter-subtree-provenance.ts#markFilterSubtreeProvenance (function)",
1028+
"masterDetailRequiredOmitted": "src/data/master-detail-required-omission.ts#masterDetailRequiredOmitted (function)",
10281029
"matchesLikePattern": "src/data/filter.zod.ts#matchesLikePattern (function)",
10291030
"materializeTreeSelfReferences": "src/data/object.zod.ts#materializeTreeSelfReferences (function)",
10301031
"missingFieldValues": "src/data/autonumber-format.ts#missingFieldValues (function)",

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
* `error` — and an object registered without the parse keeps failing closed
5757
* on it. A raw parse cannot see the omission (the field default has already
5858
* written `false` when the object refinement runs), so there an omitted
59-
* `required` reads as the optional master.
59+
* `required` reads as the optional master. `defineStack` keeps that reading
60+
* and records the omission beside it, on the parsed field
61+
* (`master-detail-required-omission.ts`), so the linter can still report the
62+
* omitted spelling; nothing here reads that record.
6063
* `readonly` (`z.boolean().default(false)`) and `system` (optional) are read
6164
* the same way: only `=== true` marks the one master unwritable.
6265
*/

‎packages/spec/src/data/index.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ export * from './injected-system-column-provenance';
423423
// that writes `controlled_by_parent` asks the spec instead of restating it.
424424
export * from './controlled-by-parent-master';
425425

426+
// [ADR-0055 §1 as amended · ruling A] `defineStack`'s record that an author
427+
// omitted `required` on a `controlled_by_parent` object's `master_detail` —
428+
// the parse has already written `false` there. Only the reader is published;
429+
// `@objectstack/lint` reads it to report the omitted spelling.
430+
export { masterDetailRequiredOmitted } from './master-detail-required-omission';
431+
426432
// record-currency path refusals (ADR-0144 D2/D6, amended) — the one wording of
427433
// "segment 2 of a `PARENT_FIELD.CODE_FIELD` path names no code field" and of a
428434
// `record` roll-up over a child amount that follows no parent. Read by

0 commit comments

Comments
 (0)