Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .changeset/35143-data-model-publish-checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
'@objectstack/lint': minor
'@objectstack/spec': patch
---

fix(lint)!: four publish-time checks for data-model metadata that saves and does not work — two refuse the publish, two warn

Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #37529

<!-- adr-0087: registered publish-refuses-data-model-fields-that-save-and-do-not-work -->

**BREAKING** for the publish of an object that carries one of the two errors below: it was accepted before and is refused now, with the fix named in the finding. The schema is unchanged and stored objects are not rewritten or refused at boot; the refusal comes at the next publish, and from `os validate` / `lint` / `compile` / `build`.

Two errors, run by the runtime publish gate and the CLI:

- `rollup/child-without-parent-reference`: a `summary` field whose child object has no `lookup` / `master_detail` field referencing the parent, or whose `summaryOperations.relationshipField` names no field of the child. With no foreign key the engine's summary index skips the summary with nothing logged; with a `relationshipField` that names no child field the summary is indexed and never recomputed. Either way the field reads 0 or empty on every parent while every child write reports success. Judged once the child resolves (a child the stack does not hold is still not judged), against the child's fields as served (an object extension may add the foreign key) and its injected columns (`owner_id`, `created_by` back to `sys_user`). Reported by `lintSummaryRollups`, beside its aggregand checks.
- `field/reference-on-non-reference-type`: `reference` on a field type that reads none — anything but `lookup`, `master_detail`, `user`, `tree` and `summary`. It links no record, and the record page edits a text, number or date field carrying it with a record picker that writes a record id into it. Judged on objects and on object extensions.

Two warnings, which refuse nothing and make `os validate --strict` exit 1 as any warning does:

- `field/count-named-lookup`: a `lookup` / `master_detail` field named like a count or a total (`contact_count`, `total_amount`); a relationship stores the id of one record, never a number.
- `approval-detail-editable-while-pending`: an approval step that locks its record (`lockRecord`, default `true`) on an object whose record page draws a `lookup` child as a table in its own body (`relatedList: 'primary'`); the approval lock covers `master_detail` children only, so those rows stay editable while the record waits. Reported by `validateApprovalApprovers`.

A formula reading a summary that has no configuration stays covered by `field/summary-without-operations`, which refuses the summary itself.

## FROM → TO

- `summaryOperations: { object: 'order_line', function: 'count' }` over an `order_line` with no field pointing at `order` → add `order: { type: 'master_detail', reference: 'order' }` to `order_line`.
- `summaryOperations: { ..., relationshipField: 'order_ref' }` naming no field of the child → name the child field that holds the parent id.
- `account: { type: 'text', reference: 'account' }` → `account: { type: 'lookup', reference: 'account' }`, or drop `reference`.

No new exports. `@objectstack/spec` adds only the upgrade-guide entry `publish-refuses-data-model-fields-that-save-and-do-not-work`.
10 changes: 10 additions & 0 deletions .changeset/35143-field-designer-drops-stray-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): the field designer removes a relationship target from a field whose type reads none, so the object still publishes

Clause-②: no
Metadata-protocol: none

The publish gate now refuses a `reference` on a field type that reads none, anything but `lookup`, `master_detail`, `user`, `tree` and `summary` (`field/reference-on-non-reference-type`). The object designer's field panel kept the key when a field was retyped: a `lookup` retyped to `text` saved as text with the old target still on it, and the Related Object picker, drawn only on `lookup`, `master_detail` and `tree`, offered no way to see or clear it there. A retype to a type that reads none now removes `reference`, as it already removes the picklist binding, option kinds, `referenceNameVisible` and `deleteBehavior` the new type cannot carry. An object saved that way earlier is repaired by its next edit: the designer reads such a field without the key, so the next save writes it without one and the publish goes through. Nothing is lost: on those types the key linked no record.
2 changes: 1 addition & 1 deletion content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines
→ Normalizing stack definition...
→ Lowering inline handlers...
→ Validating protocol compliance...
→ Running author-time rules (80)...
→ Running author-time rules (81)...
→ Checking that every required capability has a provider installable in this edition...
→ Collecting package docs (ADR-0046)... 0 collected
→ Writing artifact...
Expand Down
2 changes: 1 addition & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ A clean run walks the registry and reports timing:
Config: /path/to/support-desk/objectstack.config.ts
Load time: 21ms
→ Validating against ObjectStack Protocol...
→ Running author-time rules (80)...
→ Running author-time rules (81)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...

Expand Down
2 changes: 1 addition & 1 deletion content/docs/getting-started/build-with-claude-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ visible: 'status != "resolved"'
◆ Validate
────────────────────────────────────────
→ Validating against ObjectStack Protocol...
→ Running author-time rules (80)...
→ Running author-time rules (81)...

✗ Author-time rules failed (1 issue)
• stack · action 'resolve_ticket' visible: bare reference `status` — a
Expand Down
2 changes: 1 addition & 1 deletion content/docs/ui/react-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ objectstack validate
────────────────────────────────────────
→ Loading configuration...
→ Validating against ObjectStack Protocol...
→ Running author-time rules (80)...
→ Running author-time rules (81)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...

Expand Down
64 changes: 60 additions & 4 deletions packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ import {
lintUniqueDeclarations,
lintUnscopedDeclaredIndexes,
lintLegacyOrganizationComposites,
lintSummaryRollups,
lintInlineEditBulk,
lintFieldReferenceShapes,
summaryRollupFindings,
} from './data-model-rules.js';
import { objectExtensionsByTarget, objectsAsServed } from './object-graph.js';

import type { IObjectQLEngine } from '@objectstack/spec/contracts';
import type { UserTextParams } from './finding-user-text.js';
Expand Down Expand Up @@ -2594,15 +2596,69 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
source: 'packages/lint/src/data-model-rules.ts',
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['object'],
run: (stack) =>
lintSummaryRollups(Array.isArray(stack.objects) ? (stack.objects as unknown[]) : []).map((f) => ({
// [#35143] The relation arm (`rollup/child-without-parent-reference`)
// asks whether the child has a foreign key back to the parent, and an
// object extension may add it, so it reads the child's fields as served:
// on the CLI the stack's own extensions folded in; at the `object` door
// the registry's served objects arriving as `context.objects`, pending
// `object_extension` drafts included (`storedObjectExtensions` is stated
// on `object_extension` writes only, so it is empty here). The aggregand
// arms keep reading the declared child field.
run: (stack, ctx) => {
const served = new Map<string, { name: string; def: unknown }[]>();
for (const obj of objectsAsServed(stack, ctx.storedObjectExtensions ?? []).objects) {
if (typeof obj.name !== 'string' || served.has(obj.name)) continue;
const fields = Array.isArray(obj.fields)
? (obj.fields as AnyRec[]).filter((f) => typeof f?.name === 'string').map((f) => ({ name: f.name as string, def: f }))
: Object.entries((obj.fields ?? {}) as AnyRec).map(([name, def]) => ({ name, def }));
served.set(obj.name, fields);
}
return summaryRollupFindings(
Array.isArray(stack.objects) ? (stack.objects as unknown[]) : [],
(child) => served.get(child),
).map((f) => ({
severity: f.severity === 'suggestion' ? ('info' as const) : f.severity,
rule: f.rule,
where: f.where,
path: f.path,
message: f.message,
hint: f.fix ?? '',
})),
}));
},
},
// [#35143] Two field shapes that parse and publish and then do not do what
// the key or the name says (`lintFieldReferenceShapes`): `reference` on a
// type that reads none (error — the engine links nothing, and the record
// page's inline editor turns the field into a record picker that writes a
// record id into it), and a `lookup` / `master_detail` named like a count or
// a total (warning — a relationship stores one record's id, never a number).
// GATING on all three commands; on the runtime publish gate's `object` and
// `object_extension` writes, where the written entry's own fields are the
// whole input, so nothing the snapshot lacks can make it fire. The
// differential charges a write only with a finding it creates.
{
name: 'lintFieldReferenceShapes',
tier: 'gating',
input: 'parsed',
commands: ALL,
source: 'packages/lint/src/data-model-rules.ts',
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['object', 'object_extension'],
run: (stack) => {
const extensions = [...objectExtensionsByTarget(stack).entries()].flatMap(([target, list]) =>
list.map((ext) => ({ target, path: ext.path, fields: ext.fields })),
);
return lintFieldReferenceShapes(Array.isArray(stack.objects) ? (stack.objects as unknown[]) : [], extensions).map(
(f) => ({
severity: f.severity === 'suggestion' ? ('info' as const) : f.severity,
rule: f.rule,
where: f.where,
path: f.path,
message: f.message,
hint: f.fix ?? '',
}),
);
},
},
// Two visible fields of one object served under one label
// (`field-label-duplicate`): the platform's `owner_id` and an author's
Expand Down
143 changes: 143 additions & 0 deletions packages/lint/src/data-model-rules.field-reference-shapes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* #35143: the second batch of publish-time checks, Data model family, the
* two field-shape rules of `lintFieldReferenceShapes`. Each has a pin that
* fires, a pin that stays silent, and the runtime publish gate's own verdict on
* the write it judges. The family's other lines are pinned in the harness of
* the rule they extend: the summary relation arm in
* `data-model-rules.summary-rollup.test.ts`, the approval detail table in
* `validate-approval-approvers.test.ts`, and the formula-over-a-bare-summary
* line (covered by `field/summary-without-operations`) in
* `validate-functional-completeness.test.ts`.
*/

import { describe, expect, it } from 'vitest';
import { runAuthoringRules } from './authoring-rules.js';
import { runRuntimeAuthoringRules } from './runtime-gate.js';
import { lintFieldReferenceShapes } from './data-model-rules.js';

type AnyRec = Record<string, any>;

const REFERENCE_ON_NON_REFERENCE_TYPE = 'field/reference-on-non-reference-type';
const COUNT_NAMED_LOOKUP = 'field/count-named-lookup';

const rulesOf = (findings: readonly { rule: string }[]) => findings.map((f) => f.rule);

describe('field/reference-on-non-reference-type', () => {
const object = (fields: AnyRec): AnyRec => ({ name: 'deal', label: 'Deal', fields: { name: { type: 'text', label: 'Name' }, ...fields } });

it('refuses reference on a text, number or date field, whose inline editor becomes the record picker', () => {
for (const def of [
{ type: 'text', label: 'Account', reference: 'account' },
{ type: 'number', label: 'Account', reference: 'account' },
{ type: 'date', label: 'Account', reference: 'account' },
]) {
const hit = lintFieldReferenceShapes([object({ account: def })]).filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
expect(hit, def.type).toHaveLength(1);
expect(hit[0]).toMatchObject({ severity: 'error', path: 'objects[0].fields.account.reference' });
expect(hit[0].message).toContain('record picker');
expect(hit[0].fix).toContain("{ type: 'lookup', reference: 'account' }");
}
});

it('refuses it on a select too, saying only that it links nothing: the inline editor draws the select first', () => {
const hit = lintFieldReferenceShapes([
object({ account: { type: 'select', label: 'Account', reference: 'account', options: [{ value: 'a', label: 'A' }] } }),
]).filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
expect(hit).toHaveLength(1);
expect(hit[0]).toMatchObject({ severity: 'error', path: 'objects[0].fields.account.reference' });
expect(hit[0].message).not.toContain('record picker');
});

it('on a formula it says only that the key links nothing: the record page gives a formula no editor', () => {
const hit = lintFieldReferenceShapes([
object({ account_name: { type: 'formula', label: 'Account', expression: 'record.name', reference: 'account' } }),
]).filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
expect(hit).toHaveLength(1);
expect(hit[0].message).not.toContain('record picker');
});

it('is silent on the four reference types, on a summary, and on a blank reference', () => {
const findings = lintFieldReferenceShapes([
object({
account: { type: 'lookup', label: 'Account', reference: 'account' },
parent_deal: { type: 'master_detail', label: 'Parent', reference: 'deal' },
rep: { type: 'user', label: 'Rep', reference: 'sys_user' },
parent: { type: 'tree', label: 'Parent', reference: 'deal' },
lines: { type: 'summary', label: 'Lines', reference: 'deal_line', summaryOperations: { object: 'deal_line', function: 'count' } },
note: { type: 'text', label: 'Note', reference: '' },
}),
]);
expect(rulesOf(findings)).not.toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
});

it('judges the fields an object extension adds, located in the extension', () => {
const cli = runAuthoringRules('validate', {
normalized: { objects: [object({})], objectExtensions: [{ extend: 'deal', fields: { region_code: { type: 'text', label: 'Region', reference: 'region' } } }] },
parsed: { objects: [object({})], objectExtensions: [{ extend: 'deal', fields: { region_code: { type: 'text', label: 'Region', reference: 'region' } } }] },
} as never);
const hit = cli.filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
expect(hit).toHaveLength(1);
expect(hit[0]).toMatchObject({ severity: 'error', path: 'objectExtensions[0].fields.region_code.reference' });
});

it('the runtime publish gate refuses the object write and the object_extension write', () => {
const objectVerdict = runRuntimeAuthoringRules({
type: 'object',
item: object({ account: { type: 'text', label: 'Account', reference: 'account' } }),
context: { objects: [] },
});
expect(rulesOf(objectVerdict.errors)).toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
const extensionVerdict = runRuntimeAuthoringRules({
type: 'object_extension',
item: { extend: 'deal', fields: { account: { type: 'text', label: 'Account', reference: 'account' } } },
context: { objects: [object({})] },
});
expect(rulesOf(extensionVerdict.errors)).toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
const clean = runRuntimeAuthoringRules({
type: 'object',
item: object({ account: { type: 'lookup', label: 'Account', reference: 'account' } }),
context: { objects: [] },
});
expect(rulesOf(clean.errors)).not.toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
});
});

describe('field/count-named-lookup', () => {
const object = (fields: AnyRec): AnyRec => ({ name: 'account', label: 'Account', fields: { name: { type: 'text', label: 'Name' }, ...fields } });

it('warns on a lookup or master_detail named like a count or a total', () => {
for (const name of ['contact_count', 'total_amount', 'count', 'deal_totals']) {
const hit = lintFieldReferenceShapes([object({ [name]: { type: 'lookup', label: 'X', reference: 'contact' } })]).filter(
(f) => f.rule === COUNT_NAMED_LOOKUP,
);
expect(hit, name).toHaveLength(1);
expect(hit[0]).toMatchObject({ severity: 'warning', path: `objects[0].fields.${name}.type` });
expect(hit[0].fix).toContain("type: 'number'");
}
});

it('is silent on names that only contain the letters (account, discount, country) and on a number named so', () => {
const findings = lintFieldReferenceShapes([
object({
account: { type: 'lookup', label: 'Account', reference: 'account' },
discount: { type: 'lookup', label: 'Discount', reference: 'discount' },
country: { type: 'lookup', label: 'Country', reference: 'country' },
contact_count: { type: 'number', label: 'Contacts' },
}),
]);
expect(rulesOf(findings)).not.toContain(COUNT_NAMED_LOOKUP);
});

it('rides the runtime publish gate as an advisory, never a refusal', () => {
const verdict = runRuntimeAuthoringRules({
type: 'object',
item: object({ contact_count: { type: 'lookup', label: 'Contacts', reference: 'contact' } }),
context: { objects: [] },
});
expect(rulesOf(verdict.errors)).not.toContain(COUNT_NAMED_LOOKUP);
expect(rulesOf(verdict.advisories)).toContain(COUNT_NAMED_LOOKUP);
});
});

Loading
Loading