From 50d4ae81dcdb5db942085fa73439c86b6f7c9444 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 17:05:04 +0000 Subject: [PATCH 1/3] fix(lint): state-machine-no-initial-states judges only machines that run on insert An update-only state machine (events without insert) never runs on create, so the engine never reads its initialStates; the rule no longer refuses it. The three showcase machines that carried a declaration-only initialStates list to pass the rule drop it. Claude-Session: https://claude.ai/code/session_01L6bhgUZrkMKgGrXXe8zPGq Co-authored-by: Claude --- .changeset/35251-state-machine-update-only.md | 13 ++++++++++ content/docs/references/data/validation.mdx | 8 +++--- .../src/data/objects/account.object.ts | 4 --- .../src/data/objects/project.object.ts | 3 --- .../src/data/objects/task.object.ts | 4 --- packages/lint/src/rule-explanations.ts | 3 ++- ...validate-inert-object-declarations.test.ts | 26 +++++++++++++++++++ .../src/validate-inert-object-declarations.ts | 17 +++++++++++- packages/spec/src/data/validation.zod.ts | 2 +- ...sh-refuses-metadata-the-runtime-ignores.ts | 4 +-- 10 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 .changeset/35251-state-machine-update-only.md diff --git a/.changeset/35251-state-machine-update-only.md b/.changeset/35251-state-machine-update-only.md new file mode 100644 index 00000000000..ad7d8b7e199 --- /dev/null +++ b/.changeset/35251-state-machine-update-only.md @@ -0,0 +1,13 @@ +--- +'@objectstack/lint': minor +'@objectstack/spec': minor +--- + +fix(lint): `state-machine-no-initial-states` judges only state machines that run on insert + +Clause-②: yes (widening) +Metadata-protocol: added + +The publish-time rule `state-machine-no-initial-states` now refuses an active `state_machine` validation with no (or an empty) `initialStates` only when the machine runs on insert: its `events` include `insert`, or are left to the default `['insert', 'update']`. The engine runs a rule only on the write contexts its `events` name, so a machine declared `events: ['update']` (or `events: []`) never runs on create and never reads `initialStates`. Such a machine is accepted at publish and by `os validate` again, with no `initialStates`; adding one to satisfy the rule produced metadata the runtime ignores. A machine that runs on insert without `initialStates` is still refused, with the same fix. + +`@objectstack/spec` changes only the description of a state machine validation's `initialStates`, which now says the rule judges a machine that runs on insert. diff --git a/content/docs/references/data/validation.mdx b/content/docs/references/data/validation.mdx index 4fcf686bbd7..811ea5c6ad2 100644 --- a/content/docs/references/data/validation.mdx +++ b/content/docs/references/data/validation.mdx @@ -192,7 +192,7 @@ const result = ConditionalValidationSchema.parse(data); | **type** | `'state_machine'` | ✅ | | | **field** | `string` | ✅ | State field (e.g. status) | | **transitions** | `Record` | ✅ | Map of `{ OldState: [AllowedNewStates] }` | -| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate`. | +| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate` when its `events` include `insert` (the default). An update-only machine never runs on create, so it needs no `initialStates`. | ### Nested Shape: `ConditionalValidation.then[type='format']` @@ -313,7 +313,7 @@ const result = ConditionalValidationSchema.parse(data); | **type** | `'state_machine'` | ✅ | | | **field** | `string` | ✅ | State field (e.g. status) | | **transitions** | `Record` | ✅ | Map of `{ OldState: [AllowedNewStates] }` | -| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate`. | +| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate` when its `events` include `insert` (the default). An update-only machine never runs on create, so it needs no `initialStates`. | ### Nested Shape: `ConditionalValidation.otherwise[type='format']` @@ -532,7 +532,7 @@ const result = ConditionalValidationSchema.parse(data); | **type** | `'state_machine'` | ✅ | | | **field** | `string` | ✅ | State field (e.g. status) | | **transitions** | `Record` | ✅ | Map of `{ OldState: [AllowedNewStates] }` | -| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate`. | +| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate` when its `events` include `insert` (the default). An update-only machine never runs on create, so it needs no `initialStates`. | --- @@ -599,7 +599,7 @@ This schema accepts one of the following structures: | **type** | `'state_machine'` | ✅ | | | **field** | `string` | ✅ | State field (e.g. status) | | **transitions** | `Record` | ✅ | Map of `{ OldState: [AllowedNewStates] }` | -| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate`. | +| **initialStates** | `string[]` | optional | States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate` when its `events` include `insert` (the default). An update-only machine never runs on create, so it needs no `initialStates`. | --- diff --git a/examples/app-showcase/src/data/objects/account.object.ts b/examples/app-showcase/src/data/objects/account.object.ts index f6fde33e0b9..db6c9249cbd 100644 --- a/examples/app-showcase/src/data/objects/account.object.ts +++ b/examples/app-showcase/src/data/objects/account.object.ts @@ -141,10 +141,6 @@ export const Account = ObjectSchema.create({ field: 'status', // Transitions are validated on update; insert sets the initial state. events: ['update'] as const, - // The entry state: `prospect`, the field's default and the machine's - // root. This machine runs on updates only, so the server does not check - // it on create; it states the entry the lifecycle assumes. - initialStates: ['prospect'], message: 'Invalid account lifecycle transition.', transitions: { prospect: ['active', 'churned'], diff --git a/examples/app-showcase/src/data/objects/project.object.ts b/examples/app-showcase/src/data/objects/project.object.ts index a6bf34eb424..9964f9805f6 100644 --- a/examples/app-showcase/src/data/objects/project.object.ts +++ b/examples/app-showcase/src/data/objects/project.object.ts @@ -191,9 +191,6 @@ export const Project = ObjectSchema.create({ description: 'Health should change one step at a time; skips are warned, not blocked.', field: 'health', events: ['update'] as const, - // A project starts `green` (the field's default). Updates only, so this - // states the entry rather than checking it on create. - initialStates: ['green'], severity: 'warning' as const, message: 'Health changed by more than one step — confirm this is intentional.', transitions: { diff --git a/examples/app-showcase/src/data/objects/task.object.ts b/examples/app-showcase/src/data/objects/task.object.ts index e45404bcbef..760dfedcbe5 100644 --- a/examples/app-showcase/src/data/objects/task.object.ts +++ b/examples/app-showcase/src/data/objects/task.object.ts @@ -115,10 +115,6 @@ export const Task = ObjectSchema.create({ // — an authored message is emitted verbatim unless the bundle carries // that key, and the bundle wins once it does (#14518). message: 'Invalid task status transition.', - // A task is created on the board's first two columns: `backlog` (the - // default) or `todo`. Updates only, so this states the entry rather - // than checking it on create. - initialStates: ['backlog', 'todo'], transitions: { backlog: ['todo'], todo: ['in_progress', 'backlog'], diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 07926b3e9b4..061d22bcd12 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -6338,7 +6338,8 @@ const STATE_MACHINE_NO_INITIAL_STATES_EXPLANATION: RuleExplanation = { 'empty `initialStates` list is the same as none: the engine reads it as no entry contract.', '`initialStates` lists the states a record may be created in, and the server refuses an insert in any ' + 'other. Seed rows are exempt from the machine on purpose, so curated sample data can start mid-process. ' + - 'A machine with `active: false` is not run, so it is not reported.', + 'A machine with `active: false` is not run, so it is not reported; nor is one whose `events` leave out ' + + '`insert`, because the engine never runs it on create and would never read its `initialStates`.', ], }; diff --git a/packages/lint/src/validate-inert-object-declarations.test.ts b/packages/lint/src/validate-inert-object-declarations.test.ts index 0bbf17b6661..3d45a5814f3 100644 --- a/packages/lint/src/validate-inert-object-declarations.test.ts +++ b/packages/lint/src/validate-inert-object-declarations.test.ts @@ -45,6 +45,26 @@ describe('state-machine-no-initial-states', () => { expect(validateInertObjectDeclarations({ objects: [task({ status: STATUS }, [machine({ active: false })])] })).toEqual([]); }); + it('is silent on an update-only machine with no `initialStates`: the engine never runs it on create', () => { + expect(validateInertObjectDeclarations({ objects: [task({ status: STATUS }, [machine({ events: ['update'] })])] })).toEqual([]); + expect(validateInertObjectDeclarations({ objects: [task({ status: STATUS }, [machine({ events: [] })])] })).toEqual([]); + }); + + it('still refuses a machine whose `events` name `insert`, or leave it to the default', () => { + const objects = [ + task({ status: STATUS }, [ + machine({ name: 'explicit_insert', events: ['insert'] }), + machine({ name: 'both', events: ['update', 'insert'] }), + machine({ name: 'defaulted' }), + ]), + ]; + expect(validateInertObjectDeclarations({ objects }).map((f) => [f.rule, f.path])).toEqual([ + [STATE_MACHINE_NO_INITIAL_STATES, 'objects[0].validations[0]'], + [STATE_MACHINE_NO_INITIAL_STATES, 'objects[0].validations[1]'], + [STATE_MACHINE_NO_INITIAL_STATES, 'objects[0].validations[2]'], + ]); + }); + it('is silent when the machine declares its entry states, and on other validation types', () => { expect(validateInertObjectDeclarations({ objects: [task({ status: STATUS }, [machine({ initialStates: ['draft'] }), { name: 'r', type: 'script', message: 'm', condition: 'false' }])], @@ -59,6 +79,12 @@ describe('the runtime publish gate refuses an object write carrying the declarat expect(verdict.errors.map((f) => f.rule)).toContain(STATE_MACHINE_NO_INITIAL_STATES); }); + it('passes an `object` write whose only machine is update-only', () => { + const item = task({ status: STATUS }, [machine({ events: ['update'] })]); + const verdict = runRuntimeAuthoringRules({ type: 'object', item }); + expect(verdict.errors.map((f) => f.rule)).not.toContain(STATE_MACHINE_NO_INITIAL_STATES); + }); + it('a required boolean is not refused: the form treats false as present', () => { const item = task({ is_done: { type: 'boolean', label: 'Done', required: true, defaultValue: true } }); const verdict = runRuntimeAuthoringRules({ type: 'object', item }); diff --git a/packages/lint/src/validate-inert-object-declarations.ts b/packages/lint/src/validate-inert-object-declarations.ts index 3c722679f88..030c04c461d 100644 --- a/packages/lint/src/validate-inert-object-declarations.ts +++ b/packages/lint/src/validate-inert-object-declarations.ts @@ -10,7 +10,11 @@ * "no entry contract" (`checkStateMachine`), so a record can be CREATED * already in any state (born `approved`), walking straight past the process * the machine declares. A rule with `active: false` is skipped, as the engine - * skips it. + * skips it, and so is a machine whose `events` leave out `insert`: the + * engine runs a rule only on the write contexts its `events` list + * (`r.events ?? ['insert', 'update']`, `rule-validator.ts`), so on an + * update-only machine `initialStates` is never read and adding it would be + * metadata the runtime ignores. * * It reads the object's own body alone, so the runtime publish gate judges an * `object` write exactly as the CLI judges the stack. @@ -30,6 +34,16 @@ export interface InertObjectDeclarationFinding { hint: string; } +/** + * Whether the engine runs a rule on insert. An absent `events` takes the + * schema default `['insert', 'update']`; an explicit list runs on exactly the + * contexts it names, so `[]` and `['update']` never run on create. + */ +function runsOnInsert(events: unknown): boolean { + if (events === undefined || events === null) return true; + return Array.isArray(events) && events.includes('insert'); +} + /** Flag an entry-unguarded state machine on every object. */ export function validateInertObjectDeclarations(stack: Record): InertObjectDeclarationFinding[] { const findings: InertObjectDeclarationFinding[] = []; @@ -41,6 +55,7 @@ export function validateInertObjectDeclarations(stack: Record): const validationList: readonly unknown[] = Array.isArray(obj.validations) ? obj.validations : []; for (const rule of validations) { if (rule.type !== 'state_machine' || rule.active === false) continue; + if (!runsOnInsert(rule.events)) continue; // Absent and empty are the same to the engine: no entry contract. if (Array.isArray(rule.initialStates) && rule.initialStates.length > 0) continue; const ruleName = typeof rule.name === 'string' ? rule.name : 'state_machine'; diff --git a/packages/spec/src/data/validation.zod.ts b/packages/spec/src/data/validation.zod.ts index a85c8f03f83..7e7301269ec 100644 --- a/packages/spec/src/data/validation.zod.ts +++ b/packages/spec/src/data/validation.zod.ts @@ -194,7 +194,7 @@ export const StateMachineValidationSchema = lazySchema(() => strictObject({ type: z.literal('state_machine'), field: z.string().describe('State field (e.g. status)'), transitions: z.record(z.string(), z.array(z.string())).describe('Map of { OldState: [AllowedNewStates] }'), - initialStates: z.array(z.string()).optional().describe('States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate`.'), + initialStates: z.array(z.string()).optional().describe('States a record may be CREATED in. When set, an INSERT whose state field carries a value outside this list is rejected (server-enforced) — the FSM entry point. `transitions` only governs UPDATE, and a `select` field permits ANY declared option as an initial value, so without this a record could be born mid-flow (e.g. created already `approved`). Omitted or empty, insert is not checked; the author-time rule `state-machine-no-initial-states` refuses an active machine declared that way at publish and in `os validate` when its `events` include `insert` (the default). An update-only machine never runs on create, so it needs no `initialStates`.'), })); /** diff --git a/packages/spec/src/migrations/entries/semantic/18.publish-refuses-metadata-the-runtime-ignores.ts b/packages/spec/src/migrations/entries/semantic/18.publish-refuses-metadata-the-runtime-ignores.ts index 8a16ecf683c..57dad60c510 100644 --- a/packages/spec/src/migrations/entries/semantic/18.publish-refuses-metadata-the-runtime-ignores.ts +++ b/packages/spec/src/migrations/entries/semantic/18.publish-refuses-metadata-the-runtime-ignores.ts @@ -14,8 +14,8 @@ export const entry: SemanticMigration = { + 'a flow node whose `type` no executor in the deployment runs (`flow-node-type-no-executor`, judged at publish ' + 'against the automation engine\'s sealed node-type vocabulary); an `approval` node whose decision out-edges are ' + 'not labelled `approve` and `reject` (`flow-approval-decision-unrouted`); an `http` node with no `timeoutMs` ' - + '(`flow-http-timeout-missing`, a warning); an active `state_machine` validation with no or an empty ' - + '`initialStates` (`state-machine-no-initial-states`); a standalone action that declares `locations` but no `objectName` ' + + '(`flow-http-timeout-missing`, a warning); an active `state_machine` validation that runs on insert (its `events` ' + + 'include `insert`, the default) with no or an empty `initialStates` (`state-machine-no-initial-states`); a standalone action that declares `locations` but no `objectName` ' + '(`action-no-object-binding`)', replacement: 'Give the node a type the deployment runs (or install the plugin that contributes it); label the approval node\'s ' From f76bbfba526d0765b11a7ca75f824bebd706ef04 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 17:33:35 +0000 Subject: [PATCH 2/3] fix(lint): field-group-shadowed judges the six highlights the record page hoists The record page draws the first six highlightFields in its header strip and leaves them out of the Details body; the lint judged four, so a group emptied by the fifth or sixth highlight passed. The count is now one constant, RECORD_HIGHLIGHTS_MAX in @objectstack/spec/ui, read by the lint and by the record page synthesizer in @object-ui/plugin-detail. Claude-Session: https://claude.ai/code/session_01L6bhgUZrkMKgGrXXe8zPGq Co-authored-by: Claude --- ...252-field-group-shadowed-six-highlights.md | 18 +++++ .../lint/src/validate-semantic-roles.test.ts | 67 ++++++++++++++----- packages/lint/src/validate-semantic-roles.ts | 13 ++-- packages/spec/api-surface/ui.json | 1 + packages/spec/export-origins/ui.json | 1 + packages/spec/liveness/object.json | 2 +- .../18.field-group-shadowed-six-highlights.ts | 28 ++++++++ packages/spec/src/ui/component.zod.ts | 17 +++++ .../src/synth/buildDefaultPageSchema.ts | 7 +- 9 files changed, 133 insertions(+), 21 deletions(-) create mode 100644 .changeset/35252-field-group-shadowed-six-highlights.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.field-group-shadowed-six-highlights.ts diff --git a/.changeset/35252-field-group-shadowed-six-highlights.md b/.changeset/35252-field-group-shadowed-six-highlights.md new file mode 100644 index 00000000000..4c626c0099e --- /dev/null +++ b/.changeset/35252-field-group-shadowed-six-highlights.md @@ -0,0 +1,18 @@ +--- +'@objectstack/lint': minor +'@objectstack/spec': minor +'@object-ui/plugin-detail': minor +--- + +fix(lint): `field-group-shadowed` judges the six highlights the record page draws, from one shared constant + +Clause-②: yes (widening) +Metadata-protocol: narrowed + +The default record page draws the first six of an object's `highlightFields` (after the title field leaves the list) in its header strip and leaves those fields out of the Details body. The `field-group-shadowed` warning judged only the first four, so a field group whose only member sat fifth or sixth in `highlightFields` was empty on the record page and passed `os lint --strict`. It now judges the same six, and its hint says "first 6 highlightFields". + +What was accepted before and is warned now: an object whose field group is emptied by its fifth or sixth highlight. Fix it as the hint says: keep a member of that group out of the first six highlights, or drop the group. A list the old count warned is still warned: six hoisted fields include the first four, so no list that passed only under six is refused. + +New export: `@objectstack/spec/ui` adds `RECORD_HIGHLIGHTS_MAX` (6), the count both the lint and `@object-ui/plugin-detail`'s record page synthesizer read. `@object-ui/plugin-detail` now takes its own `RECORD_HIGHLIGHTS_MAX` from there; the value and the page are unchanged. + + diff --git a/packages/lint/src/validate-semantic-roles.test.ts b/packages/lint/src/validate-semantic-roles.test.ts index 77e198a3eed..3684fd102d4 100644 --- a/packages/lint/src/validate-semantic-roles.test.ts +++ b/packages/lint/src/validate-semantic-roles.test.ts @@ -130,7 +130,7 @@ describe('validateSemanticRoles (ADR-0085)', () => { expect(findings[0].message).toContain('amount'); }); - it('rule d counts the title field as hidden-from-body and respects the 4-entry strip cap', () => { + it('rule d counts the title field as hidden-from-body and respects the 6-entry strip cap', () => { // A group holding only the record title never renders in the body even // though the title is filtered OUT of the strip. const titleOnly = validateSemanticRoles(stack([{ @@ -141,15 +141,15 @@ describe('validateSemanticRoles (ADR-0085)', () => { }])); expect(titleOnly.map((f) => f.rule)).toEqual([FIELD_GROUP_SHADOWED]); - // Entry #5 is beyond the strip (first 4 after the title filter), so a + // Entry #7 is beyond the strip (first 6 after the title filter), so a // group containing it still renders → clean. const beyondCap = validateSemanticRoles(stack([{ name: 'wide', - highlightFields: ['name', 'a', 'b', 'c', 'd', 'e'], + highlightFields: ['name', 'a', 'b', 'c', 'd', 'e', 'f', 'g'], fieldGroups: [{ key: 'tail', label: 'Tail' }], fields: { - name: {}, a: {}, b: {}, c: {}, d: {}, - e: { type: 'text', group: 'tail' }, + name: {}, a: {}, b: {}, c: {}, d: {}, e: {}, f: {}, + g: { type: 'text', group: 'tail' }, }, }])); expect(beyondCap).toEqual([]); @@ -169,6 +169,43 @@ describe('validateSemanticRoles (ADR-0085)', () => { expect(hiddenMember.map((f) => f.rule)).toEqual([FIELD_GROUP_SHADOWED]); }); + // The record page hoists RECORD_HIGHLIGHTS_MAX (6) highlights and its body + // leaves them out. The rule used to cut at 4, so a group whose only member + // sat 5th or 6th was emptied on the page and passed the lint. + it('rule d judges the six highlights the record page hoists, not four', () => { + for (const position of [5, 6]) { + const strip = ['a', 'b', 'c', 'd', 'e', 'f']; + const owner = strip[position - 1]; + const findings = validateSemanticRoles(stack([{ + name: 'lead', + highlightFields: strip, + fieldGroups: [{ key: 'basics', label: 'Basics' }, { key: 'assignment', label: 'Assignment' }], + fields: { + name: { type: 'text', group: 'basics' }, notes: { type: 'textarea', group: 'basics' }, + ...Object.fromEntries(strip.map((n) => [n, { type: 'text', ...(n === owner ? { group: 'assignment' } : {}) }])), + }, + }])); + expect(findings, `position ${position}`).toHaveLength(1); + expect(findings[0]).toMatchObject({ severity: 'warning', rule: FIELD_GROUP_SHADOWED, path: 'objects[0].fieldGroups' }); + expect(findings[0]?.message).toContain('"assignment"'); + expect(findings[0]?.hint).toContain('first 6 highlightFields'); + } + + // Control: four highlights out of a six-slot strip, every group keeping + // a member the body draws → clean. + const fourOfSix = validateSemanticRoles(stack([{ + name: 'lead', + highlightFields: ['a', 'b', 'c', 'd'], + fieldGroups: [{ key: 'basics', label: 'Basics' }, { key: 'assignment', label: 'Assignment' }], + fields: { + name: { type: 'text', group: 'basics' }, notes: { type: 'textarea', group: 'basics' }, + a: { type: 'text', group: 'basics' }, b: { type: 'text' }, c: { type: 'text' }, + d: { type: 'text', group: 'assignment' }, owner_id: { type: 'text', group: 'assignment' }, + }, + }])); + expect(fourOfSix).toEqual([]); + }); + // #6326 — rule (d)'s title resolution used to read // `[nameField, primaryField, displayNameField]`. `primaryField` is declared // NOWHERE in `packages/spec`: measured on 17.0.0-rc.5, @@ -183,26 +220,26 @@ describe('validateSemanticRoles (ADR-0085)', () => { // make the fixture schema-valid: that deletes the coverage. // // The pair below is the discriminating one. Title resolution matters here - // because the title is filtered OUT of the 4-entry strip, so whether - // `ref_no` counts as the title decides whether entry #5 (`d`) lands inside - // the strip. Read as the title → strip is [a,b,c,d], group "tail" (only - // member `d`) is fully hidden → SHADOWED. Not read → strip is - // [ref_no,a,b,c], `d` still renders → clean. No field here is one of the + // because the title is filtered OUT of the 6-entry strip, so whether + // `ref_no` counts as the title decides whether entry #7 (`f`) lands inside + // the strip. Read as the title → strip is [a,b,c,d,e,f], group "tail" + // (only member `f`) is fully hidden → SHADOWED. Not read → strip is + // [ref_no,a,b,c,d,e], `f` still renders → clean. No field here is one of the // conventional fallbacks (name/full_name/title/subject/display_name), and // none is an injected system column, so nothing else can supply a title. it('ignores primaryField in title resolution; nameField still resolves (#6326)', () => { const withPhantomKey = validateSemanticRoles(stack([{ name: 'ledger_entry', primaryField: 'ref_no', - highlightFields: ['ref_no', 'a', 'b', 'c', 'd'], + highlightFields: ['ref_no', 'a', 'b', 'c', 'd', 'e', 'f'], fieldGroups: [{ key: 'tail', label: 'Tail' }], fields: { ref_no: { type: 'text' }, a: { type: 'text' }, b: { type: 'text' }, - c: { type: 'text' }, d: { type: 'text', group: 'tail' }, + c: { type: 'text' }, d: { type: 'text' }, e: { type: 'text' }, f: { type: 'text', group: 'tail' }, }, }])); // Goes red the moment the `primaryField` entry returns to the chain: - // `ref_no` would become the title, `d` would fall inside the strip, and + // `ref_no` would become the title, `f` would fall inside the strip, and // one FIELD_GROUP_SHADOWED finding would appear. expect(withPhantomKey).toEqual([]); @@ -212,11 +249,11 @@ describe('validateSemanticRoles (ADR-0085)', () => { const withNameField = validateSemanticRoles(stack([{ name: 'ledger_entry', nameField: 'ref_no', - highlightFields: ['ref_no', 'a', 'b', 'c', 'd'], + highlightFields: ['ref_no', 'a', 'b', 'c', 'd', 'e', 'f'], fieldGroups: [{ key: 'tail', label: 'Tail' }], fields: { ref_no: { type: 'text' }, a: { type: 'text' }, b: { type: 'text' }, - c: { type: 'text' }, d: { type: 'text', group: 'tail' }, + c: { type: 'text' }, d: { type: 'text' }, e: { type: 'text' }, f: { type: 'text', group: 'tail' }, }, }])); // Indexed rather than `.map((f) => f.rule)` on purpose: this file's diff --git a/packages/lint/src/validate-semantic-roles.ts b/packages/lint/src/validate-semantic-roles.ts index 32aa173ad96..2b06ef801d7 100644 --- a/packages/lint/src/validate-semantic-roles.ts +++ b/packages/lint/src/validate-semantic-roles.ts @@ -28,6 +28,7 @@ * are different questions, and only one of them moved. */ +import { RECORD_HIGHLIGHTS_MAX } from '@objectstack/spec/ui'; import { injectedColumnsFor, unprovisionedInjectedColumnsFor } from './system-fields.js'; import { recordsOf } from './object-graph.js'; @@ -215,8 +216,12 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { } // ── (d) declared group fully shadowed by the detail highlight strip ── - // Detail pages render the first 4 highlightFields as the top strip and - // HIDE those fields from the details body; the record's title field is + // Detail pages render the first RECORD_HIGHLIGHTS_MAX highlightFields + // (after the title leaves the list) as the top strip and HIDE those + // fields from the details body. The count is the spec constant the record + // page synthesizer cuts with, so the verdict and the screen cannot drift + // apart; a literal here once judged 4 while the page drew 6, so a group + // emptied by the 5th or 6th highlight passed. The record's title field is // the page H1 and never renders in the body either. A group whose every // visible member is covered by strip ∪ title therefore renders on FORMS // but silently never on detail pages — legal, but almost never what the @@ -239,7 +244,7 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { const titleField = declaredTitle ?? ['name', 'full_name', 'title', 'subject', 'display_name'].find((c) => fieldNames.has(c)); const stripSet = new Set( - declaredStrings.filter((h) => h !== titleField).slice(0, 4), + declaredStrings.filter((h) => h !== titleField).slice(0, RECORD_HIGHLIGHTS_MAX), ); const hiddenFromBody = new Set(stripSet); if (titleField) hiddenFromBody.add(titleField); @@ -263,7 +268,7 @@ export function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] { hint: `Keep at least one non-highlighted field in "${key}", or remove the ` + `group if the strip already covers it. (Detail pages show the first ` + - `4 highlightFields as the top strip and hide them from the body.)`, + `${RECORD_HIGHLIGHTS_MAX} highlightFields as the top strip and hide them from the body.)`, }); } } diff --git a/packages/spec/api-surface/ui.json b/packages/spec/api-surface/ui.json index fb48dd45051..bbe4f7cde88 100644 --- a/packages/spec/api-surface/ui.json +++ b/packages/spec/api-surface/ui.json @@ -389,6 +389,7 @@ "REACT_RETIRED_OVERLAY_PROPS (const)", "RECORD_CONTEXT_BLOCK_TAGS (const)", "RECORD_CONTEXT_TYPE_PREFIX (const)", + "RECORD_HIGHLIGHTS_MAX (const)", "RESERVED_COMPONENT_TYPE_NAMESPACES (const)", "RETIRED_PAGE_COMPONENT_TYPES (const)", "ReactBlockDef (interface)", diff --git a/packages/spec/export-origins/ui.json b/packages/spec/export-origins/ui.json index 2c17987d2ac..2de045b1e01 100644 --- a/packages/spec/export-origins/ui.json +++ b/packages/spec/export-origins/ui.json @@ -381,6 +381,7 @@ "REACT_RETIRED_OVERLAY_PROPS": "src/ui/react-blocks.ts#REACT_RETIRED_OVERLAY_PROPS (const)", "RECORD_CONTEXT_BLOCK_TAGS": "src/ui/react-blocks.ts#RECORD_CONTEXT_BLOCK_TAGS (const)", "RECORD_CONTEXT_TYPE_PREFIX": "src/ui/react-blocks.ts#RECORD_CONTEXT_TYPE_PREFIX (const)", + "RECORD_HIGHLIGHTS_MAX": "src/ui/component.zod.ts#RECORD_HIGHLIGHTS_MAX (const)", "RESERVED_COMPONENT_TYPE_NAMESPACES": "src/ui/component-type-vocabulary.ts#RESERVED_COMPONENT_TYPE_NAMESPACES (const)", "RETIRED_PAGE_COMPONENT_TYPES": "src/ui/page.zod.ts#RETIRED_PAGE_COMPONENT_TYPES (const)", "ReactBlockDef": "src/ui/react-blocks.ts#ReactBlockDef (interface)", diff --git a/packages/spec/liveness/object.json b/packages/spec/liveness/object.json index 758ac2330bd..7eba8244dc1 100644 --- a/packages/spec/liveness/object.json +++ b/packages/spec/liveness/object.json @@ -45,7 +45,7 @@ "highlightFields": { "status": "live", "proof": "packages/qa/dogfood/test/semantic-roles.dogfood.test.ts#semantic-roles-served", - "note": "ADR-0085 semantic role (renamed from compactLayout): objectui default list/grid columns (ObjectGrid/ObjectView/InterfaceListPage), child-record previews (first entry), record:details auto layout, detail highlight strip (first 4)." + "note": "ADR-0085 semantic role (renamed from compactLayout): objectui default list/grid columns (ObjectGrid/ObjectView/InterfaceListPage), child-record previews (first entry), record:details auto layout, detail highlight strip (first RECORD_HIGHLIGHTS_MAX = 6, after the title)." }, "relatedLists": { "status": "live", diff --git a/packages/spec/src/migrations/entries/semantic/18.field-group-shadowed-six-highlights.ts b/packages/spec/src/migrations/entries/semantic/18.field-group-shadowed-six-highlights.ts new file mode 100644 index 00000000000..668ec2f5969 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.field-group-shadowed-six-highlights.ts @@ -0,0 +1,28 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// The upgrade-guide entry of the `field-group-shadowed` warning moving from the +// first four highlightFields to the six the default record page draws +// (RECORD_HIGHLIGHTS_MAX, `@objectstack/spec/ui`). Notice only: no key is +// removed and no D2 conversion exists, because which field leaves the strip, or +// whether the group goes, is a choice only the author can make. +export const entry: SemanticMigration = { + id: 'field-group-shadowed-six-highlights', + surface: + 'The `field-group-shadowed` warning of `os validate` / `lint` / `compile` / `build`: a field group of an object ' + + 'whose every visible member is the record title or one of the first six `highlightFields` (after the title ' + + 'leaves the list). It judged the first four before', + replacement: + 'Keep at least one member of the group out of the first six `highlightFields`, or remove the group if the record ' + + 'header strip already shows its fields', + reason: + 'The default record page draws the first six highlights in its header strip and leaves those fields out of the ' + + 'Details body, so a group whose only members sit there is empty on the record page while it still shows on ' + + 'forms. The warning judged four of the six, so a group emptied by the fifth or sixth highlight passed. A group ' + + 'it warned before is still warned. Stored items are not rewritten or refused at publish; like any warning, it ' + + 'makes `os validate --strict` exit 1.', + acceptanceCriteria: + 'os validate reports no `field-group-shadowed` warning, and each declared field group shows at least one field ' + + 'in the Details body of the default record page.', +}; diff --git a/packages/spec/src/ui/component.zod.ts b/packages/spec/src/ui/component.zod.ts index 1c1a95576cc..9494b62f9f8 100644 --- a/packages/spec/src/ui/component.zod.ts +++ b/packages/spec/src/ui/component.zod.ts @@ -1862,6 +1862,23 @@ export const RecordRelatedListProps = strictObject({ aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'), }); +/** + * How many of an object's declared `highlightFields` (ADR-0085), after the + * record's title field leaves the list, the DEFAULT record page draws in its + * header strip. The Details body leaves those fields out, so an entry past + * this count is drawn in the body instead. + * + * The one source both readers ask: the record page synthesizer in + * `@object-ui/plugin-detail` cuts the strip with it, and the + * `field-group-shadowed` lint in `@objectstack/lint` judges with it which + * field groups the strip empties on the record page. A second literal on + * either side is how the lint came to judge four while the page drew six. + * + * Not the bound of an authored `record:highlights` block's `fields` + * ({@link RecordHighlightsProps}): an authored page writes its own strip. + */ +export const RECORD_HIGHLIGHTS_MAX = 6; + /** * ⚠️ The object arm is CLOSED, and closing a union arm is a different act from * closing a plain shape — worth reading before the next arm is touched. diff --git a/ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts b/ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts index f2c71fec6e7..f2b1f4f40c0 100644 --- a/ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts +++ b/ui/packages/plugin-detail/src/synth/buildDefaultPageSchema.ts @@ -24,6 +24,7 @@ */ import { deriveFieldGroupLayout } from '@objectstack/spec/data'; +import { RECORD_HIGHLIGHTS_MAX } from '@objectstack/spec/ui'; import type { SelectOptionKind, ServiceObject } from '@objectstack/spec/data'; import { detectStatusField } from '@object-ui/types'; import { resolveNameField } from '@object-ui/core'; @@ -446,8 +447,12 @@ export function resolveTitleField(def: ObjectDefLike | undefined): string | null * How many highlights the record header shows (objectstack#27055, the v3 * header: 「要点 6 项等宽」 — the same six Studio's highlight editor offers). * A declared `highlightFields` list longer than this is cut here. + * + * Declared once in `@objectstack/spec/ui` and re-exported here: the + * `field-group-shadowed` lint judges which field groups this strip empties + * with the same constant, so its verdict matches the page. */ -export const RECORD_HIGHLIGHTS_MAX = 6; +export { RECORD_HIGHLIGHTS_MAX }; /** * The record's highlight strip: the object's DECLARED `highlightFields` From 18224af0429a5564c670f6049ce328b7e884f318 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 18:49:04 +0000 Subject: [PATCH 3/3] fix(changeset): the field-group-shadowed note declares the narrowing arm beside narrowed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Metadata-protocol narrowed is a breaking narrowing by definition, so the Clause-② line carries (narrowing), not (widening). Claude-Session: https://claude.ai/code/session_01L6bhgUZrkMKgGrXXe8zPGq Co-authored-by: Claude --- .changeset/35252-field-group-shadowed-six-highlights.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/35252-field-group-shadowed-six-highlights.md b/.changeset/35252-field-group-shadowed-six-highlights.md index 4c626c0099e..4d9a7ef2197 100644 --- a/.changeset/35252-field-group-shadowed-six-highlights.md +++ b/.changeset/35252-field-group-shadowed-six-highlights.md @@ -6,7 +6,7 @@ fix(lint): `field-group-shadowed` judges the six highlights the record page draws, from one shared constant -Clause-②: yes (widening) +Clause-②: yes (narrowing) Metadata-protocol: narrowed The default record page draws the first six of an object's `highlightFields` (after the title field leaves the list) in its header strip and leaves those fields out of the Details body. The `field-group-shadowed` warning judged only the first four, so a field group whose only member sat fifth or sixth in `highlightFields` was empty on the record page and passed `os lint --strict`. It now judges the same six, and its hint says "first 6 highlightFields".