Skip to content
Merged
15 changes: 15 additions & 0 deletions .changeset/33940-cbp-omitted-required-lint-default-door.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/spec': patch
'@objectstack/lint': patch
---

fix(spec,lint): `os lint` reports an omitted `required` on a `controlled_by_parent` object's `master_detail` on the default strict `defineStack` door

Clause-②: yes
Metadata-protocol: none

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.

**`@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.

**`@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.
14 changes: 10 additions & 4 deletions docs/qa/platform-checklist/areas/cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@
"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",
"since": "v18",
"status": "active",
"revision": 5,
"revision": 6,
"priority": "P1",
"surface": "cli",
"personas": [
Expand All @@ -2440,7 +2440,7 @@
"steps": [
"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\"}",
"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",
"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"
"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"
],
"acceptance": [
{
Expand All @@ -2462,9 +2462,9 @@
"evidence": "four lines"
},
{
"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",
"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",
"oracle": "build",
"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",
"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",
"evidence": "the os lint, os validate and os build exits + the lint finding line"
}
],
Expand Down Expand Up @@ -2509,6 +2509,12 @@
"date": "2026-11-15",
"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",
"ref": "#34068"
},
{
"revision": 6,
"date": "2026-11-15",
"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",
"ref": "#33940"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
*/

import { describe, expect, it } from 'vitest';
import { Field, ObjectSchema } from '@objectstack/spec/data';
import { defineStack } from '@objectstack/spec';
import { Field, ObjectSchema, masterDetailRequiredOmitted } from '@objectstack/spec/data';
import {
lintDataModel as lintDataModelUnrecorded,
RELATIONSHIP_DELETE_BEHAVIOR,
Expand Down Expand Up @@ -229,6 +230,67 @@ describe('R2 over objects built by ObjectSchema.create()', () => {
});
});

// [#33940 · ruling A, record 6687830530] What reaches the rule from the
// DEFAULT door: a config module that calls `defineStack` itself, strict. The
// parse writes `false` into an omitted `required` (the optional master, as
// ruled) and records the omission on the field it returns; the rule reads that
// record, so the omitted spelling is reported here exactly as on the raw
// literal and on `{ strict: false }`. The stack still loads in every case.
describe('R2 over a stack a strict defineStack built — the omitted spelling is still reported (#33940)', () => {
const built = (shape: Record<string, unknown>, options?: { strict: boolean }) =>
(
defineStack(
{
manifest: { id: 'com.example.r2-door', namespace: 'wo', version: '0.0.1', type: 'app', name: 'R2' },
objects: [
{ name: 'wo_order', label: 'Order', fields: { name: { type: 'text', label: 'Name' } } },
{
name: 'wo_item',
label: 'Item',
sharingModel: 'controlled_by_parent',
fields: { order: { type: 'master_detail', label: 'Order', reference: 'wo_order', deleteBehavior: 'cascade', ...shape } },
},
],
} as never,
options,
) as unknown as { objects: any[] }
).objects;

it('the sole master_detail without `required`: one error at `.required`, naming both spellings', () => {
const objects = built({});
// The parsed value is the ruled one: `false`, the optional master — recorded as omitted.
expect(objects[1].fields.order.required).toBe(false);
expect(masterDetailRequiredOmitted(objects[1].fields.order)).toBe(true);
const issues = r2(objects);
expect(issues).toHaveLength(1);
expect(issues[0]).toMatchObject({
severity: 'error',
rule: R2,
path: 'objects[1].fields.order.required',
fix: 'required: true',
});
expect(issues[0]!.message).toContain('declares no required: write true (every detail names its master) or false (an optional master)');
});

it('CONTROL: an explicit `required: false` (the optional master) and `required: true` lint clean', () => {
expect(r2(built({ required: false }))).toEqual([]);
expect(r2(built({ required: true }))).toEqual([]);
});

it('CONTROL: `{ strict: false }` reports the same finding, on the same path, as before', () => {
const issues = r2(built({}, { strict: false }));
expect(issues.map((issue) => [issue.severity, issue.path, issue.fix])).toEqual([
['error', 'objects[1].fields.order.required', 'required: true'],
]);
});

it('a copy of the built field drops the record and reads as the explicit `false` — the pre-record reading', () => {
const objects = built({});
const copied = [objects[0], { ...objects[1], fields: { order: { ...objects[1].fields.order } } }];
expect(r2(copied)).toEqual([]);
});
});

describe('[#22161] one-line verdicts — relationship/master-detail-required, relationship/delete-behavior', () => {
it('the published constants spell the ids the findings carry', () => {
expect(RELATIONSHIP_MASTER_DETAIL_REQUIRED).toBe(R2);
Expand Down
13 changes: 12 additions & 1 deletion packages/lint/src/data-model-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
BOOLEAN_VALUE_TYPES,
NUMERIC_VALUE_TYPES,
isAggregateCompatibleWithFieldType,
masterDetailRequiredOmitted,
referenceCarrierOf,
type AggregationFunction,
} from '@objectstack/spec/data';
Expand Down Expand Up @@ -348,6 +349,12 @@ const CBP_ORPHAN_CONSEQUENCE =
* `false`, so it admits the optional master) while `ObjectSchema.create()`
* forces it to `true`: one source, two meanings, until the author writes one.
* The fix stays `required: true`, the reading the builder already gives it.
* This rule sees the omission on every stack `os lint` loads: an unparsed one
* still lacks the key, and on one a strict `defineStack` parsed (the default
* door, where the field arrives as `false`) the producer RECORDED it on the
* field — `masterDetailRequiredOmitted` (`@objectstack/spec/data`) is that
* record's reader (#33940). A field that lost the record (a copy) reads as the
* explicit `false`, the optional master: the pre-record reading.
*
* Why these three. A `controlled_by_parent` detail derives ALL of its record
* access from the master its `master_detail` reference names (ADR-0055: such an
Expand Down Expand Up @@ -413,8 +420,12 @@ function cbpMasterReferenceFinding(
// `master_detail`, declared `required: false`, is its optional master — the
// spelling passes. Beside another `master_detail` an explicit `false` is
// judged as before; an omitted `required` is reported on every field.
// [#33940] On a stack `defineStack` parsed, an omitted `required` arrives as
// the parsed `false`; the producer's record of the omission
// (`masterDetailRequiredOmitted`) is what tells the two apart, so the
// omitted spelling is reported on the default strict door too.
const soleMasterDetail = masterDetailCount === 1;
const optionalMaster = soleMasterDetail && def.required === false;
const optionalMaster = soleMasterDetail && def.required === false && !masterDetailRequiredOmitted(def);
const missingRequired = def.required !== true && !optionalMaster;
// On the sole `master_detail`, an omitted (or non-boolean) `required` has
// two honest spellings; elsewhere only `required: true` is one.
Expand Down
1 change: 1 addition & 0 deletions packages/spec/api-surface/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@
"lintAuthoredRecordKeys (function)",
"lowerFilterCondition (function)",
"markFilterSubtreeProvenance (function)",
"masterDetailRequiredOmitted (function)",
"matchesLikePattern (function)",
"materializeTreeSelfReferences (function)",
"missingFieldValues (function)",
Expand Down
1 change: 1 addition & 0 deletions packages/spec/export-origins/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@
"lintAuthoredRecordKeys": "src/data/authoring-key-lint.ts#lintAuthoredRecordKeys (function)",
"lowerFilterCondition": "src/data/filter-lowering.ts#lowerFilterCondition (function)",
"markFilterSubtreeProvenance": "src/data/filter-subtree-provenance.ts#markFilterSubtreeProvenance (function)",
"masterDetailRequiredOmitted": "src/data/master-detail-required-omission.ts#masterDetailRequiredOmitted (function)",
"matchesLikePattern": "src/data/filter.zod.ts#matchesLikePattern (function)",
"materializeTreeSelfReferences": "src/data/object.zod.ts#materializeTreeSelfReferences (function)",
"missingFieldValues": "src/data/autonumber-format.ts#missingFieldValues (function)",
Expand Down
5 changes: 4 additions & 1 deletion packages/spec/src/data/controlled-by-parent-master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@
* `error` — and an object registered without the parse keeps failing closed
* on it. A raw parse cannot see the omission (the field default has already
* written `false` when the object refinement runs), so there an omitted
* `required` reads as the optional master.
* `required` reads as the optional master. `defineStack` keeps that reading
* and records the omission beside it, on the parsed field
* (`master-detail-required-omission.ts`), so the linter can still report the
* omitted spelling; nothing here reads that record.
* `readonly` (`z.boolean().default(false)`) and `system` (optional) are read
* the same way: only `=== true` marks the one master unwritable.
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/spec/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ export * from './injected-system-column-provenance';
// that writes `controlled_by_parent` asks the spec instead of restating it.
export * from './controlled-by-parent-master';

// [ADR-0055 §1 as amended · ruling A] `defineStack`'s record that an author
// omitted `required` on a `controlled_by_parent` object's `master_detail` —
// the parse has already written `false` there. Only the reader is published;
// `@objectstack/lint` reads it to report the omitted spelling.
export { masterDetailRequiredOmitted } from './master-detail-required-omission';

// record-currency path refusals (ADR-0144 D2/D6, amended) — the one wording of
// "segment 2 of a `PARENT_FIELD.CODE_FIELD` path names no code field" and of a
// `record` roll-up over a child amount that follows no parent. Read by
Expand Down
Loading
Loading