Skip to content

Commit 5fed01d

Browse files
committed
fix(lint): the overlay save door refuses a list view bound to an object that exists nowhere
A runtime write that names no package is judged against the whole collection the host serves, so a list-view binding missing from it exists nowhere. validateListViewFieldRefs now refuses it once, at the binding key (list-view-object-unknown, error) when the reference-integrity suite states the whole collection (a runtime write with no closure in force). The CLI keeps skip 1. Claude-Session: https://claude.ai/code/session_019oFY6Hi35J7atvgVFnmoaK Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4b114ed commit 5fed01d

5 files changed

Lines changed: 352 additions & 15 deletions

File tree

‎packages/lint/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,15 @@ export type {
493493
// [#24563] Its THIRD: a list view judged under a package closure whose bound
494494
// object is outside that closure — refused (`error`) where skip 1 judged
495495
// nothing; `ListViewFieldRefOptions` is how the runtime gate states the closure.
496+
// [#24668] Its FOURTH: a list view judged against the whole collection (a
497+
// runtime write that names no package) whose bound object exists nowhere —
498+
// refused the same way; `wholeCollection` is the statement.
496499
export {
497500
validateListViewFieldRefs,
498501
LIST_VIEW_FIELD_UNKNOWN,
499502
LIST_VIEW_FIELD_DOTTED,
500503
LIST_VIEW_OBJECT_OUTSIDE_CLOSURE,
504+
LIST_VIEW_OBJECT_UNKNOWN,
501505
} from './validate-list-view-field-refs.js';
502506
export type {
503507
ListViewFieldRefFinding,

‎packages/lint/src/reference-integrity-suite.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,29 @@ export const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [
318318
// missing-collection argument above is unchanged: the binding is judged
319319
// against `stack.objects`, the collection every per-write snapshot carries,
320320
// and the gate states the scope only when it narrowed that collection.
321+
//
322+
// [#24668] And the other half of that sentence: a runtime write with NO
323+
// closure in force is judged against the whole collection the host serves
324+
// (`RuntimeStackContext.objects`: registry plus stored rows, unnarrowed), so
325+
// a binding missing from it exists nowhere, and the member refuses it
326+
// (`list-view-object-unknown`, `error`) — stated as `wholeCollection`.
327+
// `runtimeWriteType` is the signal because the gate sets it on every gated
328+
// write and the CLI commands never do, and `packageScope` is absent exactly
329+
// when the gate narrowed nothing (one predicate, `packageScopeInForce`). The
330+
// CLI keeps skip 1: its stack is one app, and an unresolved binding there
331+
// may be a dependency package's object.
321332
{
322333
name: 'validateListViewFieldRefs',
323334
runtimeTypes: ['flow', 'view', 'object'],
324335
run: (stack, ctx) =>
325-
validateListViewFieldRefs(stack, ctx?.packageScope ? { packageScope: ctx.packageScope } : undefined),
336+
validateListViewFieldRefs(
337+
stack,
338+
ctx?.packageScope
339+
? { packageScope: ctx.packageScope }
340+
: ctx?.runtimeWriteType !== undefined
341+
? { wholeCollection: true }
342+
: undefined,
343+
),
326344
},
327345
// [#15254] The same question, one surface IN: the field-name lists the
328346
// OBJECT itself carries (`highlightFields`, `publicSharing.redactFields`),
@@ -679,7 +697,8 @@ export interface ReferenceIntegrityRunOptions {
679697
* `stack.objects` to — spells the same key as
680698
* `AuthoringRuleContext.packageScope`. Present only when a closure was in
681699
* force; ABSENT on the CLI commands and on a write that names no package.
682-
* Read by `validateListViewFieldRefs` only.
700+
* Read by `validateListViewFieldRefs` only — which reads its absence beside
701+
* a set `runtimeWriteType` as the whole collection (#24668).
683702
*/
684703
packageScope?: { readonly packageId: string; readonly dependencies: readonly string[] };
685704
}

‎packages/lint/src/runtime-gate.package-closure.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,17 @@ describe('the view door under a package closure (#24563)', () => {
385385
expect(scoped(listViewOn('tenant_overlay')).advisories).toEqual([]);
386386
});
387387

388-
it('a write that names no package is unchanged — the whole collection, field verdict and silence alike', () => {
388+
it('a write that names no package is judged against the whole collection — field verdict unchanged, no closure verdict', () => {
389389
// ⛔ The overlay door: the stranger's object is in the whole collection, so
390-
// its unknown column is refused exactly as before, and an object that
391-
// exists nowhere stays skip 1's silence (no scope, so no closure verdict).
390+
// its unknown column is refused exactly as before. An object that exists
391+
// nowhere gets no closure verdict (no scope); [#24668] it is refused as
392+
// existing nowhere instead (`runtime-gate.whole-collection.test.ts`).
392393
expect(rules(whole(listViewOn('other_0_0')).errors)).toEqual([FIELD_UNKNOWN]);
393394
expect(whole(listViewOn('other_0_0')).advisories).toEqual([]);
394-
expect(whole(listViewOn('nosuch_obj'))).toMatchObject({ errors: [], advisories: [] });
395+
expect(rules(whole(listViewOn('nosuch_obj')).errors)).toEqual(['list-view-object-unknown']);
395396
// An empty package id narrows nothing, so it states no closure either.
396397
const empty = { packageId: '', dependencies: [] } as RuntimePackageScope;
397-
expect(scoped(listViewOn('nosuch_obj'), empty)).toMatchObject({ errors: [], advisories: [] });
398+
expect(rules(scoped(listViewOn('nosuch_obj'), empty).errors)).toEqual(['list-view-object-unknown']);
398399
});
399400

400401
it('the flow verdict is unchanged, and a stored object\'s out-of-closure list view is not charged to it', () => {
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #24668 — the VIEW door against the WHOLE collection: a runtime write that
5+
* names no package (an overlay write) of a list view bound to an object that
6+
* exists nowhere is REFUSED `list-view-object-unknown`, once, at the binding.
7+
*
8+
* The overlay twin of #24563 (`runtime-gate.package-closure.test.ts`, the
9+
* closure verdict). With no closure in force the gate hands the rules every
10+
* object the host serves, so a binding missing from it exists nowhere — there
11+
* is no other package for it to come from. What these pins hold:
12+
*
13+
* - the refusal itself, on every rung the rule walks, at the binding key;
14+
* - a binding that resolves keeps its field verdict exactly;
15+
* - the CLI (`os validate` / `os build` / `os lint`) keeps skip 1 — its stack
16+
* is one app, and an unresolved binding may be a dependency's object;
17+
* - an EMPTY collection is no universe, so nothing is judged;
18+
* - a closure wins over the whole-collection statement;
19+
* - the differential charges a write only with its own finding: a stored
20+
* sibling's dangling binding cancels, including when the write creates the
21+
* object nearest to it (the suggestion rides the hint, not the message).
22+
*
23+
* Drafts are not a lint-layer concept: the draft door is pinned where it
24+
* lives, in `packages/metadata-protocol` (`protocol.runtime-authoring-gate.test.ts`).
25+
*/
26+
import { describe, expect, it } from 'vitest';
27+
import { runAuthoringRules, splitBySeverity } from './authoring-rules.js';
28+
import { validateReferenceIntegrity } from './reference-integrity-suite.js';
29+
import { runRuntimeAuthoringRules, type RuntimePackageScope } from './runtime-gate.js';
30+
import {
31+
LIST_VIEW_FIELD_UNKNOWN,
32+
LIST_VIEW_OBJECT_OUTSIDE_CLOSURE,
33+
LIST_VIEW_OBJECT_UNKNOWN,
34+
validateListViewFieldRefs,
35+
} from './validate-list-view-field-refs.js';
36+
37+
type AnyRec = Record<string, any>;
38+
39+
const OWN = 'com.acme.crm';
40+
const STRANGER = 'com.other.analytics';
41+
const PLATFORM = 'com.objectstack.platform';
42+
43+
/** A minimal, spec-shaped object declaration (every one declares `name`). */
44+
function obj(name: string, packageId?: string, extra: AnyRec = {}): AnyRec {
45+
return {
46+
name,
47+
label: name,
48+
sharingModel: 'private',
49+
fields: { name: { type: 'text', label: 'Name' } },
50+
...(packageId === undefined ? {} : { _packageId: packageId }),
51+
...extra,
52+
};
53+
}
54+
55+
/** The whole collection a host serves: two packages, a platform object, a provenance-less overlay row. */
56+
const OBJECTS: readonly AnyRec[] = [
57+
obj('crm_account', OWN),
58+
obj('showcase_task', STRANGER),
59+
obj('sys_audit_log', PLATFORM),
60+
obj('tenant_overlay'),
61+
];
62+
63+
/**
64+
* The card's body: a flattened list overlay — the shape `PUT /api/v1/meta/view`
65+
* carries — bound to `object`, one known and by default one unknown column.
66+
*/
67+
function listViewOn(object: string, columns: readonly string[] = ['name', 'zzz_nope']): AnyRec {
68+
return {
69+
name: `${object}.probe_list`,
70+
object,
71+
viewKind: 'list',
72+
label: 'Probe',
73+
type: 'grid',
74+
data: { provider: 'object', object },
75+
columns: columns.map((field) => ({ field })),
76+
};
77+
}
78+
79+
const overlay = (item: AnyRec, objects: readonly AnyRec[] = OBJECTS) =>
80+
runRuntimeAuthoringRules({ type: 'view', item, context: { objects } });
81+
const rules = (fs: readonly AnyRec[]) => fs.map((f) => f.rule);
82+
83+
describe('the view door against the whole collection (#24668)', () => {
84+
it('REFUSES a binding to an object that exists nowhere — once, at the binding, positions unjudged', () => {
85+
const result = overlay(listViewOn('nosuch_obj'));
86+
87+
expect(result.advisories).toEqual([]);
88+
expect(result.errors).toHaveLength(1);
89+
expect(result.errors[0]).toMatchObject({ severity: 'error', rule: LIST_VIEW_OBJECT_UNKNOWN });
90+
expect(result.errors[0].path).toMatch(/^views(\[0\]|\.nosuch_obj\.probe_list)\.data\.object$/);
91+
expect(result.errors[0].message).toContain('"nosuch_obj"');
92+
// ⛔ One finding per list view: the unknown column is not judged against
93+
// an object there is no field map for.
94+
expect(rules(result.errors)).not.toContain(LIST_VIEW_FIELD_UNKNOWN);
95+
});
96+
97+
it('names the nearest object in the HINT, and leaves the message free of it', () => {
98+
const result = overlay(listViewOn('crm_acount'));
99+
100+
expect(rules(result.errors)).toEqual([LIST_VIEW_OBJECT_UNKNOWN]);
101+
expect(result.errors[0].hint).toContain('Did you mean "crm_account"?');
102+
expect(result.errors[0].message).not.toContain('crm_account"');
103+
});
104+
105+
it('refuses on every rung the rule walks, each at the key the binding was read from', () => {
106+
const rungs: Array<[string, AnyRec, RegExp]> = [
107+
['container `list`', { name: 'board', object: 'nosuch_obj', list: { type: 'grid', columns: [{ field: 'name' }] } }, /\.objectName$|\.object$/],
108+
['container `list.data.object`', { name: 'board', object: 'crm_account', list: { type: 'grid', data: { provider: 'object', object: 'nosuch_obj' }, columns: [{ field: 'name' }] } }, /\.list\.data\.object$/],
109+
['container `listViews.*`', { name: 'board', object: 'crm_account', listViews: { all: { type: 'grid', data: { provider: 'object', object: 'nosuch_obj' }, columns: [{ field: 'name' }] } } }, /\.listViews\.all\.data\.object$/],
110+
['ViewItem record', { name: 'board', object: 'nosuch_obj', viewKind: 'list', config: { type: 'grid', columns: [{ field: 'name' }] } }, /\.object$/],
111+
];
112+
for (const [label, item, path] of rungs) {
113+
const result = overlay(item);
114+
expect(rules(result.errors), label).toEqual([LIST_VIEW_OBJECT_UNKNOWN]);
115+
expect(result.errors[0].path, label).toMatch(path);
116+
expect(result.advisories, label).toEqual([]);
117+
}
118+
});
119+
120+
it('refuses an OBJECT write whose built-in list view retargets an object that exists nowhere', () => {
121+
const item = obj('crm_board', undefined, {
122+
listViews: { foreign: { label: 'Foreign', data: { provider: 'object', object: 'nosuch_obj' }, columns: ['name'] } },
123+
});
124+
const result = runRuntimeAuthoringRules({ type: 'object', item, context: { objects: OBJECTS } });
125+
126+
expect(rules(result.errors)).toEqual([LIST_VIEW_OBJECT_UNKNOWN]);
127+
expect(result.errors[0].path).toMatch(/listViews\.foreign\.data\.object$/);
128+
});
129+
130+
it('a binding that RESOLVES keeps its field verdict — package, stranger, platform and overlay objects alike', () => {
131+
for (const bound of ['crm_account', 'showcase_task', 'sys_audit_log', 'tenant_overlay']) {
132+
expect(overlay(listViewOn(bound, ['name'])), bound).toMatchObject({ errors: [], advisories: [] });
133+
const refused = overlay(listViewOn(bound));
134+
expect(rules(refused.errors), bound).toEqual([LIST_VIEW_FIELD_UNKNOWN]);
135+
expect(refused.errors[0].path, bound).toMatch(/columns\[1\]\.field$/);
136+
expect(refused.advisories, bound).toEqual([]);
137+
}
138+
});
139+
140+
it('an EMPTY collection is no universe: nothing is judged, exactly as before', () => {
141+
expect(overlay(listViewOn('nosuch_obj'), [])).toMatchObject({ errors: [], advisories: [] });
142+
expect(runRuntimeAuthoringRules({ type: 'view', item: listViewOn('nosuch_obj') }))
143+
.toMatchObject({ errors: [], advisories: [] });
144+
});
145+
146+
it('a closure wins: the same body written into a package is the #24563 verdict, not this one', () => {
147+
const scope: RuntimePackageScope = { packageId: OWN, dependencies: [] };
148+
const result = runRuntimeAuthoringRules({ type: 'view', item: listViewOn('nosuch_obj'), context: { objects: OBJECTS }, packageScope: scope });
149+
150+
expect(rules(result.errors)).toEqual([LIST_VIEW_OBJECT_OUTSIDE_CLOSURE]);
151+
// And at the rule itself, when a caller states both.
152+
expect(
153+
validateListViewFieldRefs(
154+
{ objects: OBJECTS, views: [listViewOn('nosuch_obj')] },
155+
{ packageScope: scope, wholeCollection: true },
156+
).map((f) => f.rule),
157+
).toEqual([LIST_VIEW_OBJECT_OUTSIDE_CLOSURE]);
158+
});
159+
160+
it('a stored sibling\'s dangling binding is not charged to a flow write', () => {
161+
const dangling = obj('crm_board', OWN, {
162+
listViews: { foreign: { label: 'Foreign', data: { provider: 'object', object: 'nosuch_obj' }, columns: ['name'] } },
163+
});
164+
const flow = {
165+
name: 'crm_account_touched',
166+
label: 'Touched',
167+
status: 'active',
168+
type: 'autolaunched',
169+
nodes: [
170+
{ id: 'start', type: 'start', label: 'On update', config: { objectName: 'crm_account', triggerType: 'record-after-update' } },
171+
{ id: 'end', type: 'end', label: 'End' },
172+
],
173+
edges: [{ id: 'e1', source: 'start', target: 'end', type: 'default', isDefault: false }],
174+
};
175+
const result = runRuntimeAuthoringRules({ type: 'flow', item: flow, context: { objects: [...OBJECTS, dangling] } });
176+
177+
expect(rules([...result.errors, ...result.advisories])).not.toContain(LIST_VIEW_OBJECT_UNKNOWN);
178+
// Non-vacuous: written itself, the sibling IS refused.
179+
expect(rules(runRuntimeAuthoringRules({ type: 'object', item: dangling, context: { objects: OBJECTS } }).errors))
180+
.toEqual([LIST_VIEW_OBJECT_UNKNOWN]);
181+
});
182+
183+
it('…nor to an object write that creates the object NEAREST to it — the suggestion moves, the fingerprint does not', () => {
184+
const dangling = obj('crm_board', undefined, {
185+
listViews: { typo: { label: 'Typo', data: { provider: 'object', object: 'crm_invoce' }, columns: ['name'] } },
186+
});
187+
const created = obj('crm_invoice');
188+
const result = runRuntimeAuthoringRules({ type: 'object', item: created, context: { objects: [...OBJECTS, dangling] } });
189+
190+
expect(result.errors).toEqual([]);
191+
expect(rules(result.advisories)).not.toContain(LIST_VIEW_OBJECT_UNKNOWN);
192+
// Non-vacuous: the suggestion really does differ between the two
193+
// universes the differential compares.
194+
const before = validateListViewFieldRefs({ objects: [...OBJECTS, dangling] }, { wholeCollection: true });
195+
const after = validateListViewFieldRefs({ objects: [...OBJECTS, dangling, created] }, { wholeCollection: true });
196+
expect(rules(before)).toEqual([LIST_VIEW_OBJECT_UNKNOWN]);
197+
expect(rules(after)).toEqual([LIST_VIEW_OBJECT_UNKNOWN]);
198+
expect(after[0]!.hint).not.toEqual(before[0]!.hint);
199+
expect(after[0]!.message).toEqual(before[0]!.message);
200+
});
201+
});
202+
203+
describe('the CLI reading is unchanged (#24668)', () => {
204+
const stack = { name: 'p', objects: [...OBJECTS], views: [listViewOn('nosuch_obj')] };
205+
206+
it('the rule with no statement keeps skip 1', () => {
207+
expect(validateListViewFieldRefs(stack)).toEqual([]);
208+
});
209+
210+
it('the suite with no runtime write type keeps skip 1', () => {
211+
expect(rules(validateReferenceIntegrity(stack))).not.toContain(LIST_VIEW_OBJECT_UNKNOWN);
212+
// …and the same stack judged as a runtime `view` snapshot is the verdict above.
213+
expect(rules(validateReferenceIntegrity(stack, { runtimeWriteType: 'view' }))).toContain(LIST_VIEW_OBJECT_UNKNOWN);
214+
});
215+
216+
for (const command of ['validate', 'build', 'lint'] as const) {
217+
it(`\`${command}\` reports nothing for the binding`, () => {
218+
const { errors, advisories } = splitBySeverity(runAuthoringRules(command, { normalized: stack }));
219+
expect(rules([...errors, ...advisories])).not.toContain(LIST_VIEW_OBJECT_UNKNOWN);
220+
});
221+
}
222+
});

0 commit comments

Comments
 (0)