Skip to content

Commit d9bc148

Browse files
fix(lint)!: four publish-time checks for data-model metadata that saves and does not work (#37513)
Part of #35143 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up #37529 ## 维护者速读 - 搭应用的人在发布对象和本地校验时,会被拦下两类“保存成功却不工作”的字段(汇总字段的子对象没有指回父对象、给不能关联记录的字段填了关联目标),另有两类只提醒不拦截。 - 属于“发布期作者规则第二批”中的数据模型一族,替搭应用的人在保存时就发现汇总永远是 0、记录选择器把编号写进文本字段这类问题。 - 已经存好的对象不会被改写也不会在启动时被拒,只是下次发布被拦并给出改法;误拦时撤回这次合并即可恢复。 - 无 ## What changes The Data model family of the card's second batch of publish-time checks, five lines, each verified on `origin/main` first. | Line | Verdict on main | This PR | |---|---|---| | D1 lookup named like a count or total | holds, no rule | new warning `field/count-named-lookup` | | D2 formula reading an unconfigured summary | **already covered** — `field/summary-without-operations` refuses the summary itself | no rule; a coverage pin at the runtime gate | | D3 summary whose child has no reference back | holds, no rule | new error `rollup/child-without-parent-reference`, added to the existing `lintSummaryRollups` | | D4 `reference` on a type that reads none | holds, no rule | new error `field/reference-on-non-reference-type` | | D5 approval detail editable while pending | holds, no rule | new warning `approval-detail-editable-while-pending`, added to the existing `validateApprovalApprovers` | - **D3** follows the engine's summary index (`buildSummaryIndex`). It reads `summaryOperations.relationshipField` when that is set. Otherwise it looks for the first `master_detail` / `lookup` on the child that references the parent. When the index finds no foreign key, the summary is skipped with nothing logged, so the field reads 0 or empty while every child write reports success. - The check counts the child's fields as served, including fields added by an object extension. It also counts the injected columns (`owner_id`, `created_by` and `updated_by` back to `sys_user`, plus the tenancy lookups). - A child the stack does not hold is not judged. - The finding is reported beside the existing aggregand arms, not instead of them. - **D4** fires when a non-blank `reference` sits on any type outside `REFERENCE_VALUE_TYPES` plus `summary`. `summary` is exempt because the hosted blueprint reads `summary` + `reference`. - It runs on objects and on object extensions. - The record page's inline editor sends any field with a `reference` to the record picker, except the textual fallback types. For text, number and date fields the message therefore names the record-id write; a select and the other types the inline editor routes first are told only that the key links nothing. - **D1** and **D4** sit in one new gating entry, `lintFieldReferenceShapes`, which runs on both the `object` and the `object_extension` door. D1 is a warning, so it comes back as a 2xx advisory. - **D5**: an approval node with `lockRecord` not set to `false` makes the rule look at the flow's start object. If that object has a non-multiple `lookup` child drawn as a body table (`relatedList: 'primary'`, read through `isBodyTableRelationship`), the rule warns once per flow. The approval lock covers `master_detail` children only. - **Export surface:** no new exports and no new catalogs. The new rule ids are module-local, which matches the Flows precedent's r2 PASS. The authoring-rule count in four docs pages moves from 80 to 81. - **Upgrade guide:** new ADR-0087 semantic entry `publish-refuses-data-model-fields-that-save-and-do-not-work` in `@objectstack/spec`. It is a notice only, because each fix is a choice only the author can make. ## Tests - `data-model-rules.field-reference-shapes.test.ts` (new) covers D4 and D1: - both fire, and stay silent on legal shapes; - the object-extension location is reported; - the runtime gate refuses D4 on `object` and on `object_extension`, and returns D1 as an advisory. - `data-model-rules.summary-rollup.test.ts` covers D3: - fires on a child with no foreign key, and on a `relationshipField` that names no field of the child; - silent with `master_detail`, with `lookup`, with a `relationshipField` that names a real child field, when the child is absent, for `sys_user` via the injected column, and for a foreign key added by an extension on the CLI; - the runtime gate refuses, and passes once fixed. - `validate-functional-completeness.test.ts` covers D2: a bare summary that a formula reads is refused at the gate as `field/summary-without-operations`. - `validate-approval-approvers.test.ts` covers D5: - warns on a primary lookup child; - silent for a `master_detail` child, a non-body lookup and `lockRecord: false`; - rides the flow door as an advisory. - Door roster pins: `lintFieldReferenceShapes` is added to the exact `rulesRun` lists in three runtime-gate test files. ## Acceptance notes - **The Clause-② line differs from the dispatch order's literal spelling.** The order asks for `Clause-②: no` together with `Metadata-protocol: narrowed`. The changeset gate refuses `narrowed` without the `(narrowing)` arm. Two of the checks refuse a publish that used to be accepted, so the change narrows. This PR therefore carries `Clause-②: no (narrowing)` and a `!` title, the same as the Flows precedent. - **D2 has no new rule.** On main, a summary with no `summaryOperations` is already refused as itself, so the formula that reads it cannot publish either. That is recorded and pinned. - **D4 exempts `summary`,** because the hosted blueprint reads `summary` + `reference`. `formula` and `autonumber` still fire, but their message drops the record-picker clause because they have no editor. - **D1 and D5 are warnings.** They refuse nothing and make `os validate --strict` exit 1, as any warning does. D1 rides the object door as a gating-rule warning, so it comes back as an advisory, not a refusal. - **Reading outside this card (R8 in `lintDataModel`).** R8 counts `refOf(def)`, and the keys `optionsFrom` / `dataSource`, as select option sources. Neither key exists in the spec. This is a carrier note and is not filed. - **Collision with #37422.** That PR also bumps the authoring-rule count in the same four docs pages, so they conflict textually. Whichever lands second takes the higher count. `authoring-rules.ts` merges cleanly. - **Skills-docs** follow-up is owed, as declared above. ## Verification Two-minute check: `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2 src/data-model-rules.field-reference-shapes.test.ts src/data-model-rules.summary-rollup.test.ts`. Expect every case to pass. Read first, by risk: 1. `packages/lint/src/data-model-rules.ts`, the D3 relation arm in `summaryRollupFindings`. It must agree with the engine's foreign-key choice, or it refuses roll-ups that compute. 2. `packages/lint/src/authoring-rules.ts`: the new entry's doors (`object`, `object_extension`) and the served-fields map passed to the roll-up check. 3. `packages/lint/src/validate-approval-approvers.ts`: the body-table reading for D5. Readings at final head ad43f0b: lint 237/237 files, 9682 tests (at 2740a17); app-shell narrowed set 221/221 files, 2429 tests (at 48d632c) plus the retype pin file at ad43f0b; dogfood battery 487 passed, 3 skipped files, 4129 passed, 68 skipped tests; CI 63 success, 11 skipped, 0 failed (after the body edit re-ran four jobs). Follow-ups from the contract review nits: #37577. Also in this PR: 77ac3ce gives the objectql duplicatePackage roll-up fixture's child a foreign key back to its parent (the new rollup/child-without-parent-reference refusal turned that stale fixture red); 48d632c and ad43f0b make the console field designer drop reference on a retype to a type that reads none and strip a stored one at its read door (contract review M1, under the seat's scope line 7190889569), with its own @object-ui/app-shell patch changeset. <details><summary>Earlier local readings (head b26f2c1, tree identical to the readings' tree 4e2ea58)</summary> - `@objectstack/lint` full suite, under the lock: Test Files 237 passed (237), Tests 9680 passed (9680), VERDICT command-exit 0. - metadata-protocol battery, under the lock: Test Files 370 passed, 9 skipped (379); Tests 23440 passed, 45 skipped; VERDICT command-exit 0. - New and changed lint test files: Test Files 7 passed (7), Tests 185 passed (185), VERDICT command-exit 0. - `os validate` on app-crm, app-multi-package, app-showcase, app-starter and app-todo: each "Validation passed", with zero findings from the four new checks. - The derived gate families (`dispatch-gates.mjs --commands`), the full dogfood battery and the CI check-runs are read in the os-dev-report comment on the card. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Q4EjjQkY5yXZrN9BEA3rEK)_ <!-- signed: repo:objectstack#6 · hotlong · session_01Q4EjjQkY5yXZrN9BEA3rEK --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e2837e7 commit d9bc148

22 files changed

Lines changed: 1002 additions & 17 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/spec': patch
4+
---
5+
6+
fix(lint)!: four publish-time checks for data-model metadata that saves and does not work — two refuse the publish, two warn
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: narrowed
10+
Skills-docs: follow-up #37529
11+
12+
<!-- adr-0087: registered publish-refuses-data-model-fields-that-save-and-do-not-work -->
13+
14+
**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`.
15+
16+
Two errors, run by the runtime publish gate and the CLI:
17+
18+
- `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.
19+
- `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.
20+
21+
Two warnings, which refuse nothing and make `os validate --strict` exit 1 as any warning does:
22+
23+
- `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.
24+
- `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`.
25+
26+
A formula reading a summary that has no configuration stays covered by `field/summary-without-operations`, which refuses the summary itself.
27+
28+
## FROM → TO
29+
30+
- `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`.
31+
- `summaryOperations: { ..., relationshipField: 'order_ref' }` naming no field of the child → name the child field that holds the parent id.
32+
- `account: { type: 'text', reference: 'account' }` → `account: { type: 'lookup', reference: 'account' }`, or drop `reference`.
33+
34+
No new exports. `@objectstack/spec` adds only the upgrade-guide entry `publish-refuses-data-model-fields-that-save-and-do-not-work`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): the field designer removes a relationship target from a field whose type reads none, so the object still publishes
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
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.

‎content/docs/deployment/cli.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines
937937
→ Normalizing stack definition...
938938
→ Lowering inline handlers...
939939
→ Validating protocol compliance...
940-
→ Running author-time rules (80)...
940+
→ Running author-time rules (81)...
941941
→ Checking that every required capability has a provider installable in this edition...
942942
→ Collecting package docs (ADR-0046)... 0 collected
943943
→ Writing artifact...

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ A clean run walks the registry and reports timing:
867867
Config: /path/to/support-desk/objectstack.config.ts
868868
Load time: 21ms
869869
→ Validating against ObjectStack Protocol...
870-
→ Running author-time rules (80)...
870+
→ Running author-time rules (81)...
871871
→ Checking that every required capability has a provider installable in this edition...
872872
→ Checking package docs (ADR-0046)...
873873

‎content/docs/getting-started/build-with-claude-code.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ visible: 'status != "resolved"'
312312
◆ Validate
313313
────────────────────────────────────────
314314
→ Validating against ObjectStack Protocol...
315-
→ Running author-time rules (80)...
315+
→ Running author-time rules (81)...
316316
317317
✗ Author-time rules failed (1 issue)
318318
• stack · action 'resolve_ticket' visible: bare reference `status` — a

‎content/docs/ui/react-pages.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ objectstack validate
404404
────────────────────────────────────────
405405
→ Loading configuration...
406406
→ Validating against ObjectStack Protocol...
407-
→ Running author-time rules (80)...
407+
→ Running author-time rules (81)...
408408
→ Checking that every required capability has a provider installable in this edition...
409409
→ Checking package docs (ADR-0046)...
410410

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ import {
179179
lintUniqueDeclarations,
180180
lintUnscopedDeclaredIndexes,
181181
lintLegacyOrganizationComposites,
182-
lintSummaryRollups,
183182
lintInlineEditBulk,
183+
lintFieldReferenceShapes,
184+
summaryRollupFindings,
184185
} from './data-model-rules.js';
186+
import { objectExtensionsByTarget, objectsAsServed } from './object-graph.js';
185187

186188
import type { IObjectQLEngine } from '@objectstack/spec/contracts';
187189
import type { UserTextParams } from './finding-user-text.js';
@@ -2594,15 +2596,69 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
25942596
source: 'packages/lint/src/data-model-rules.ts',
25952597
surfaces: CLI_AND_RUNTIME,
25962598
runtimeTypes: ['object'],
2597-
run: (stack) =>
2598-
lintSummaryRollups(Array.isArray(stack.objects) ? (stack.objects as unknown[]) : []).map((f) => ({
2599+
// [#35143] The relation arm (`rollup/child-without-parent-reference`)
2600+
// asks whether the child has a foreign key back to the parent, and an
2601+
// object extension may add it, so it reads the child's fields as served:
2602+
// on the CLI the stack's own extensions folded in; at the `object` door
2603+
// the registry's served objects arriving as `context.objects`, pending
2604+
// `object_extension` drafts included (`storedObjectExtensions` is stated
2605+
// on `object_extension` writes only, so it is empty here). The aggregand
2606+
// arms keep reading the declared child field.
2607+
run: (stack, ctx) => {
2608+
const served = new Map<string, { name: string; def: unknown }[]>();
2609+
for (const obj of objectsAsServed(stack, ctx.storedObjectExtensions ?? []).objects) {
2610+
if (typeof obj.name !== 'string' || served.has(obj.name)) continue;
2611+
const fields = Array.isArray(obj.fields)
2612+
? (obj.fields as AnyRec[]).filter((f) => typeof f?.name === 'string').map((f) => ({ name: f.name as string, def: f }))
2613+
: Object.entries((obj.fields ?? {}) as AnyRec).map(([name, def]) => ({ name, def }));
2614+
served.set(obj.name, fields);
2615+
}
2616+
return summaryRollupFindings(
2617+
Array.isArray(stack.objects) ? (stack.objects as unknown[]) : [],
2618+
(child) => served.get(child),
2619+
).map((f) => ({
25992620
severity: f.severity === 'suggestion' ? ('info' as const) : f.severity,
26002621
rule: f.rule,
26012622
where: f.where,
26022623
path: f.path,
26032624
message: f.message,
26042625
hint: f.fix ?? '',
2605-
})),
2626+
}));
2627+
},
2628+
},
2629+
// [#35143] Two field shapes that parse and publish and then do not do what
2630+
// the key or the name says (`lintFieldReferenceShapes`): `reference` on a
2631+
// type that reads none (error — the engine links nothing, and the record
2632+
// page's inline editor turns the field into a record picker that writes a
2633+
// record id into it), and a `lookup` / `master_detail` named like a count or
2634+
// a total (warning — a relationship stores one record's id, never a number).
2635+
// GATING on all three commands; on the runtime publish gate's `object` and
2636+
// `object_extension` writes, where the written entry's own fields are the
2637+
// whole input, so nothing the snapshot lacks can make it fire. The
2638+
// differential charges a write only with a finding it creates.
2639+
{
2640+
name: 'lintFieldReferenceShapes',
2641+
tier: 'gating',
2642+
input: 'parsed',
2643+
commands: ALL,
2644+
source: 'packages/lint/src/data-model-rules.ts',
2645+
surfaces: CLI_AND_RUNTIME,
2646+
runtimeTypes: ['object', 'object_extension'],
2647+
run: (stack) => {
2648+
const extensions = [...objectExtensionsByTarget(stack).entries()].flatMap(([target, list]) =>
2649+
list.map((ext) => ({ target, path: ext.path, fields: ext.fields })),
2650+
);
2651+
return lintFieldReferenceShapes(Array.isArray(stack.objects) ? (stack.objects as unknown[]) : [], extensions).map(
2652+
(f) => ({
2653+
severity: f.severity === 'suggestion' ? ('info' as const) : f.severity,
2654+
rule: f.rule,
2655+
where: f.where,
2656+
path: f.path,
2657+
message: f.message,
2658+
hint: f.fix ?? '',
2659+
}),
2660+
);
2661+
},
26062662
},
26072663
// Two visible fields of one object served under one label
26082664
// (`field-label-duplicate`): the platform's `owner_id` and an author's
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #35143: the second batch of publish-time checks, Data model family, the
5+
* two field-shape rules of `lintFieldReferenceShapes`. Each has a pin that
6+
* fires, a pin that stays silent, and the runtime publish gate's own verdict on
7+
* the write it judges. The family's other lines are pinned in the harness of
8+
* the rule they extend: the summary relation arm in
9+
* `data-model-rules.summary-rollup.test.ts`, the approval detail table in
10+
* `validate-approval-approvers.test.ts`, and the formula-over-a-bare-summary
11+
* line (covered by `field/summary-without-operations`) in
12+
* `validate-functional-completeness.test.ts`.
13+
*/
14+
15+
import { describe, expect, it } from 'vitest';
16+
import { runAuthoringRules } from './authoring-rules.js';
17+
import { runRuntimeAuthoringRules } from './runtime-gate.js';
18+
import { lintFieldReferenceShapes } from './data-model-rules.js';
19+
20+
type AnyRec = Record<string, any>;
21+
22+
const REFERENCE_ON_NON_REFERENCE_TYPE = 'field/reference-on-non-reference-type';
23+
const COUNT_NAMED_LOOKUP = 'field/count-named-lookup';
24+
25+
const rulesOf = (findings: readonly { rule: string }[]) => findings.map((f) => f.rule);
26+
27+
describe('field/reference-on-non-reference-type', () => {
28+
const object = (fields: AnyRec): AnyRec => ({ name: 'deal', label: 'Deal', fields: { name: { type: 'text', label: 'Name' }, ...fields } });
29+
30+
it('refuses reference on a text, number or date field, whose inline editor becomes the record picker', () => {
31+
for (const def of [
32+
{ type: 'text', label: 'Account', reference: 'account' },
33+
{ type: 'number', label: 'Account', reference: 'account' },
34+
{ type: 'date', label: 'Account', reference: 'account' },
35+
]) {
36+
const hit = lintFieldReferenceShapes([object({ account: def })]).filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
37+
expect(hit, def.type).toHaveLength(1);
38+
expect(hit[0]).toMatchObject({ severity: 'error', path: 'objects[0].fields.account.reference' });
39+
expect(hit[0].message).toContain('record picker');
40+
expect(hit[0].fix).toContain("{ type: 'lookup', reference: 'account' }");
41+
}
42+
});
43+
44+
it('refuses it on a select too, saying only that it links nothing: the inline editor draws the select first', () => {
45+
const hit = lintFieldReferenceShapes([
46+
object({ account: { type: 'select', label: 'Account', reference: 'account', options: [{ value: 'a', label: 'A' }] } }),
47+
]).filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
48+
expect(hit).toHaveLength(1);
49+
expect(hit[0]).toMatchObject({ severity: 'error', path: 'objects[0].fields.account.reference' });
50+
expect(hit[0].message).not.toContain('record picker');
51+
});
52+
53+
it('on a formula it says only that the key links nothing: the record page gives a formula no editor', () => {
54+
const hit = lintFieldReferenceShapes([
55+
object({ account_name: { type: 'formula', label: 'Account', expression: 'record.name', reference: 'account' } }),
56+
]).filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
57+
expect(hit).toHaveLength(1);
58+
expect(hit[0].message).not.toContain('record picker');
59+
});
60+
61+
it('is silent on the four reference types, on a summary, and on a blank reference', () => {
62+
const findings = lintFieldReferenceShapes([
63+
object({
64+
account: { type: 'lookup', label: 'Account', reference: 'account' },
65+
parent_deal: { type: 'master_detail', label: 'Parent', reference: 'deal' },
66+
rep: { type: 'user', label: 'Rep', reference: 'sys_user' },
67+
parent: { type: 'tree', label: 'Parent', reference: 'deal' },
68+
lines: { type: 'summary', label: 'Lines', reference: 'deal_line', summaryOperations: { object: 'deal_line', function: 'count' } },
69+
note: { type: 'text', label: 'Note', reference: '' },
70+
}),
71+
]);
72+
expect(rulesOf(findings)).not.toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
73+
});
74+
75+
it('judges the fields an object extension adds, located in the extension', () => {
76+
const cli = runAuthoringRules('validate', {
77+
normalized: { objects: [object({})], objectExtensions: [{ extend: 'deal', fields: { region_code: { type: 'text', label: 'Region', reference: 'region' } } }] },
78+
parsed: { objects: [object({})], objectExtensions: [{ extend: 'deal', fields: { region_code: { type: 'text', label: 'Region', reference: 'region' } } }] },
79+
} as never);
80+
const hit = cli.filter((f) => f.rule === REFERENCE_ON_NON_REFERENCE_TYPE);
81+
expect(hit).toHaveLength(1);
82+
expect(hit[0]).toMatchObject({ severity: 'error', path: 'objectExtensions[0].fields.region_code.reference' });
83+
});
84+
85+
it('the runtime publish gate refuses the object write and the object_extension write', () => {
86+
const objectVerdict = runRuntimeAuthoringRules({
87+
type: 'object',
88+
item: object({ account: { type: 'text', label: 'Account', reference: 'account' } }),
89+
context: { objects: [] },
90+
});
91+
expect(rulesOf(objectVerdict.errors)).toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
92+
const extensionVerdict = runRuntimeAuthoringRules({
93+
type: 'object_extension',
94+
item: { extend: 'deal', fields: { account: { type: 'text', label: 'Account', reference: 'account' } } },
95+
context: { objects: [object({})] },
96+
});
97+
expect(rulesOf(extensionVerdict.errors)).toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
98+
const clean = runRuntimeAuthoringRules({
99+
type: 'object',
100+
item: object({ account: { type: 'lookup', label: 'Account', reference: 'account' } }),
101+
context: { objects: [] },
102+
});
103+
expect(rulesOf(clean.errors)).not.toContain(REFERENCE_ON_NON_REFERENCE_TYPE);
104+
});
105+
});
106+
107+
describe('field/count-named-lookup', () => {
108+
const object = (fields: AnyRec): AnyRec => ({ name: 'account', label: 'Account', fields: { name: { type: 'text', label: 'Name' }, ...fields } });
109+
110+
it('warns on a lookup or master_detail named like a count or a total', () => {
111+
for (const name of ['contact_count', 'total_amount', 'count', 'deal_totals']) {
112+
const hit = lintFieldReferenceShapes([object({ [name]: { type: 'lookup', label: 'X', reference: 'contact' } })]).filter(
113+
(f) => f.rule === COUNT_NAMED_LOOKUP,
114+
);
115+
expect(hit, name).toHaveLength(1);
116+
expect(hit[0]).toMatchObject({ severity: 'warning', path: `objects[0].fields.${name}.type` });
117+
expect(hit[0].fix).toContain("type: 'number'");
118+
}
119+
});
120+
121+
it('is silent on names that only contain the letters (account, discount, country) and on a number named so', () => {
122+
const findings = lintFieldReferenceShapes([
123+
object({
124+
account: { type: 'lookup', label: 'Account', reference: 'account' },
125+
discount: { type: 'lookup', label: 'Discount', reference: 'discount' },
126+
country: { type: 'lookup', label: 'Country', reference: 'country' },
127+
contact_count: { type: 'number', label: 'Contacts' },
128+
}),
129+
]);
130+
expect(rulesOf(findings)).not.toContain(COUNT_NAMED_LOOKUP);
131+
});
132+
133+
it('rides the runtime publish gate as an advisory, never a refusal', () => {
134+
const verdict = runRuntimeAuthoringRules({
135+
type: 'object',
136+
item: object({ contact_count: { type: 'lookup', label: 'Contacts', reference: 'contact' } }),
137+
context: { objects: [] },
138+
});
139+
expect(rulesOf(verdict.errors)).not.toContain(COUNT_NAMED_LOOKUP);
140+
expect(rulesOf(verdict.advisories)).toContain(COUNT_NAMED_LOOKUP);
141+
});
142+
});
143+

0 commit comments

Comments
 (0)