From 2fa5f5050bd907e0cf726824b0acdd66cfcb9b90 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 01:16:59 +0000 Subject: [PATCH 1/3] feat(lint)!: judge a lookupFilters { $record } path against the record being edited and its one hop object-field-ref-unknown gains the lookupFilters[].value.$record member of its owner-addressed field-level sweep: on a picker field, the path's head is a field of the object that owns the field, a second segment a field of the object that relationship references, and a second hop is refused at the segment past the bound. A hop to an object outside the stack stays unjudged. Claude-Session: https://claude.ai/code/session_01ADHkmS3jo9CFJZXCvjc2n4 Co-authored-by: Claude --- ...34200-lookup-filter-record-path-checked.md | 16 ++ packages/lint/src/rule-explanations.ts | 7 + .../src/validate-object-field-refs.test.ts | 139 +++++++++++++++++- .../lint/src/validate-object-field-refs.ts | 108 +++++++++++++- ...okup-filter-record-path-unknown-refused.ts | 39 +++++ 5 files changed, 301 insertions(+), 8 deletions(-) create mode 100644 .changeset/34200-lookup-filter-record-path-checked.md create mode 100644 packages/spec/src/migrations/entries/semantic/18.lookup-filter-record-path-unknown-refused.ts diff --git a/.changeset/34200-lookup-filter-record-path-checked.md b/.changeset/34200-lookup-filter-record-path-checked.md new file mode 100644 index 00000000000..8ceda17903c --- /dev/null +++ b/.changeset/34200-lookup-filter-record-path-checked.md @@ -0,0 +1,16 @@ +--- +'@objectstack/lint': minor +'@objectstack/spec': minor +--- + +feat(lint)!: a `lookupFilters` `{ $record: "path" }` path must name a field of the record being edited, or one hop from it + +Clause-②: no (narrowing) — a `lookupFilters[].value` `{ $record }` path on a lookup, master_detail or user field that names no field of the object owning that field, hops through a field that is not a relationship, names a leaf the referenced object lacks, or takes a second hop, parsed clean and published; it is now refused at error as `object-field-ref-unknown` by `os lint`, `os validate`, `os build` and the runtime publish door. +Metadata-protocol: narrowed +Skills-docs: follow-up #34201 — no doc or skill teaches `{ $record }` yet (the picker that resolves it has not landed; both describes carry `[PLANNED — not enforced]`), so there is no teaching to correct; the existing follow-up for `{ $record }` docs moves with the picker change. + + + +**BREAKING** only for a `{ $record }` path that already names nothing the record being edited carries. The `{ $record }` shape landed with its spelling judged (snake_case names, at most one dot) but not what it names, so `{ $record: "acount.cb_market" }` parsed and was stored. `object-field-ref-unknown` now resolves it against the object that owns the picker field: the first segment is a field of that object; with a second segment the first is a relationship field and the second a field of the object it references. A hop to an object outside the stack is not judged. Measured first-party exposure: zero — no example app, platform object, skill or docs sample writes a `$record` path. + +**Fix:** correct the misspelt segment. `{ $record }` reads the record being edited; a column of the candidate row is written `{ $field: "column" }`. The semantic entry `lookup-filter-record-path-unknown-refused` carries the same notice into the upgrade guide and `os migrate meta`. `os explain object-field-ref-unknown` lists the position. diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index baf57a7ab04..1b0bd7f94f8 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -4482,6 +4482,13 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = { '(the picker scopes its candidates by that key). The referenced object is judged only on ' + '`lookup`, `master_detail` and `user` fields, the types that render the picker, and a bare ' + '`dependsOn` name that misses on the owning object is reported once, there.', + 'On those picker fields a `lookupFilters[].value.$record` path is judged too, against the record ' + + 'being edited: a field of the object that owns the picker field, or at most one hop from it (a ' + + 'relationship field of that object, then a field of the object it references, as in ' + + '`account.cb_market`). The picker swaps that value into its query, so a path the record does ' + + 'not have leaves the filter with nothing to compare. A miss names the segment: an unknown head, ' + + 'a hop through a field that is not a relationship, a leaf the referenced object lacks, or a ' + + 'second hop. A `$record` nested inside a literal value is not a reference and is not judged.', 'A summary field\'s `summaryOperations.filter` is judged against the CHILD object ' + '`summaryOperations.object` names: the engine ANDs it with the parent-FK match and runs it as the ' + 'query on that child, so every key (inside `$and` / `$or` / `$not` groups) is a field of the child. ' + diff --git a/packages/lint/src/validate-object-field-refs.test.ts b/packages/lint/src/validate-object-field-refs.test.ts index 59c9b8cde1d..3b924e3c766 100644 --- a/packages/lint/src/validate-object-field-refs.test.ts +++ b/packages/lint/src/validate-object-field-refs.test.ts @@ -10,6 +10,7 @@ import { import { explainRule } from './rule-explanations.js'; import { runRuntimeAuthoringRules, runtimeAuthoringRulesFor } from './runtime-gate.js'; import { SEMANTIC_ROLE_FIELD_UNKNOWN, validateSemanticRoles } from './validate-semantic-roles.js'; +import { FieldSchema } from '@objectstack/spec/data'; const obj = (over: Record = {}) => ({ name: 'proj_task', @@ -705,6 +706,139 @@ describe('validateObjectFieldRefs — lookupFilters[].field (addresses the REFER }); }); +describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD BEING EDITED, one hop, #34200)', () => { + // A quote's Price Book picker (the `LookupFilterRecordReference` example): + // `$record` reads the quote — the object that OWNS the picker field — or one + // lookup hop from it, never the price book the filter runs on. + const quote = (filters: unknown[], over: Record = {}) => ({ + objects: [ + { + name: 'sales_quote', + fields: { + quote_date: { type: 'date' }, + notes: { type: 'text' }, + account: { type: 'lookup', reference: 'crm_account' }, + partner: { type: 'lookup', reference: 'elsewhere_partner' }, + price_book: { type: 'lookup', reference: 'sales_price_book', lookupFilters: filters }, + ...over, + }, + }, + { + name: 'crm_account', + fields: { + name: { type: 'text' }, + cb_market: { type: 'select' }, + parent: { type: 'lookup', reference: 'crm_account' }, + }, + }, + { + name: 'sales_price_book', + fields: { valid_from: { type: 'date' }, valid_to: { type: 'date' }, cb_market: { type: 'select' } }, + }, + ], + }); + const at = (i: number) => `objects[0].fields.price_book.lookupFilters[${i}].value.$record`; + const entry = (path: string, field = 'cb_market') => ({ field, operator: 'eq', value: { $record: path } }); + + it('REFUSES an unknown head, naming the segment and the edited object', () => { + const findings = validateObjectFieldRefs(quote([entry('acount.cb_market')])); + expect(findings).toHaveLength(1); + expect(findings[0]).toMatchObject({ severity: 'error', rule: OBJECT_FIELD_REF_UNKNOWN, path: at(0) }); + expect(findings[0]!.message).toBe( + 'fields.price_book.lookupFilters[0].value.$record "acount.cb_market" traverses "acount", which is not a ' + + 'field on object "sales_quote". Did you mean "account"?', + ); + expect(findings[0]!.hint).toContain('`$record` reads the record being edited'); + }); + + it('REFUSES an unknown leaf, judged against the object the hop references', () => { + const findings = validateObjectFieldRefs(quote([entry('account.cb_markt')])); + expect(findings.map((f) => f.path)).toEqual([at(0)]); + expect(findings[0]!.message).toContain('"account.cb_markt" is not a field on object "crm_account"'); + expect(findings[0]!.message).toContain('Did you mean "cb_market"?'); + }); + + it('REFUSES a hop through a field that is not a relationship', () => { + const findings = validateObjectFieldRefs(quote([entry('notes.cb_market')])); + expect(findings.map((f) => f.path)).toEqual([at(0)]); + expect(findings[0]!.message).toContain('traverses "notes", which is a `text` field on object "sales_quote"'); + }); + + it('REFUSES two hops at the second one, even when every segment exists (the raw `os lint` path)', () => { + const findings = validateObjectFieldRefs(quote([entry('account.parent.cb_market')])); + expect(findings.map((f) => f.path)).toEqual([at(0)]); + expect(findings[0]!.message).toBe( + 'fields.price_book.lookupFilters[0].value.$record "account.parent.cb_market" takes a second hop at ' + + '"parent"; it reads at most one lookup hop from the record being edited.', + ); + }); + + it('REFUSES a single name the edited record does not carry — a field of the FILTERED object is not one', () => { + // `valid_from` is a column of the price book the filter runs on; `$record` + // reads the quote. Writing the candidate's own column is `{ $field }`. + const findings = validateObjectFieldRefs(quote([entry('valid_from', 'valid_to')])); + expect(findings.map((f) => f.path)).toEqual([at(0)]); + expect(findings[0]!.message).toContain('"valid_from" is not a field on object "sales_quote"'); + }); + + it('passes a single field of the edited record, and an injected column of it', () => { + expect(validateObjectFieldRefs(quote([ + { field: 'valid_from', operator: 'lte', value: { $record: 'quote_date' }, orEmpty: true }, + { field: 'valid_to', operator: 'gte', value: { $record: 'created_at' } }, + ]))).toEqual([]); + }); + + it('passes a single hop to a field of the referenced object', () => { + expect(validateObjectFieldRefs(quote([entry('account.cb_market')]))).toEqual([]); + }); + + it('stays silent on a hop whose referenced object is not in this stack, as `dependsOn` does', () => { + expect(validateObjectFieldRefs(quote([entry('partner.anything')]))).toEqual([]); + }); + + it('reports the `$record` miss and the `.field` miss of one entry as two findings: two objects, two fixes', () => { + const findings = validateObjectFieldRefs(quote([ + { field: 'cb_markt', operator: 'eq', value: { $record: 'cb_markt' } }, + ])); + expect(findings.map((f) => f.path)).toEqual([ + 'objects[0].fields.price_book.lookupFilters[0].field', + at(0), + ]); + }); + + it('reads the whole value only: a list member is the parse\'s refusal, not this rule\'s', () => { + // `refuseMalformedLookupFilterEntry` refuses `{ $record }` as a list member + // ("never a member of a list"), so nothing judged here could add to it. + expect(validateObjectFieldRefs(quote([ + { field: 'cb_market', operator: 'in', value: [{ $record: 'acount.cb_market' }, 'domestic'] }, + ]))).toEqual([]); + expect(FieldSchema.safeParse({ + type: 'lookup', + reference: 'sales_price_book', + lookupFilters: [{ field: 'cb_market', operator: 'in', value: [{ $record: 'account.cb_market' }, 'domestic'] }], + }).success).toBe(false); + }); + + it('leaves a `$record` nested deeper inside a literal unnamed — an opaque literal to the parse too', () => { + expect(validateObjectFieldRefs(quote([ + { field: 'cb_market', operator: 'eq', value: { market: { $record: 'acount.cb_market' } } }, + ]))).toEqual([]); + }); + + it('stays silent on a type with no picker: nothing reads the key there', () => { + expect(validateObjectFieldRefs(quote([], { + memo: { type: 'text', lookupFilters: [entry('acount.cb_market')] }, + }))).toEqual([]); + }); + + it('judges a `user` field\'s picker too, against the record being edited', () => { + const findings = validateObjectFieldRefs(quote([], { + approver: { type: 'user', lookupFilters: [{ field: 'name', operator: 'eq', value: { $record: 'acount.name' } }] }, + })); + expect(findings.map((f) => f.path)).toEqual(['objects[0].fields.approver.lookupFilters[0].value.$record']); + }); +}); + describe('validateObjectFieldRefs — summaryOperations.filter (addresses the CHILD object, #31224)', () => { // `crm_account` is the parent; `crm_invoice` (with an FK to it) the child. const rollup = (filter: unknown, over: Record = {}) => ({ @@ -1030,6 +1164,8 @@ describe('[#22161] one-line verdicts — object-field-ref-unknown', () => { '`compactLayout`', '`relatedListColumns` against the object that owns the field', '`lookupColumns` and `lookupFilters[].field` against the REFERENCED object', + '`lookupFilters[].value.$record`', + 'at most one hop', '`lookup`, `master_detail` and `user`', 'reported once, there', 'read verbatim', @@ -1056,6 +1192,7 @@ describe('[#22161] one-line verdicts — object-field-ref-unknown', () => { '.relatedListColumns[', '.lookupColumns[', '.lookupFilters[', + '.value.$record', '.dependsOn[', '.summaryOperations.filter.', '.nameField', @@ -1079,7 +1216,7 @@ describe('[#22161] one-line fix — object-field-ref-unknown', () => { const converted = fired.filter((f) => f.rule === OBJECT_FIELD_REF_UNKNOWN); // Coverage control: every position fired (the verdict block above names // them), so the bound reads each prescription. - for (const position of ['.highlightFields[', '.publicSharing.redactFields[', '.indexes[', '.relatedListColumns[', '.lookupColumns[', '.lookupFilters[', '.dependsOn[', '.summaryOperations.filter.', '.nameField', '.displayNameField', '.activityMilestones[']) { + for (const position of ['.highlightFields[', '.publicSharing.redactFields[', '.indexes[', '.relatedListColumns[', '.lookupColumns[', '.lookupFilters[', '.value.$record', '.dependsOn[', '.summaryOperations.filter.', '.nameField', '.displayNameField', '.activityMilestones[']) { expect(converted.some((f) => f.path.includes(position)), position).toBe(true); } for (const f of converted) { diff --git a/packages/lint/src/validate-object-field-refs.ts b/packages/lint/src/validate-object-field-refs.ts index b2a4f203d59..d0591651212 100644 --- a/packages/lint/src/validate-object-field-refs.ts +++ b/packages/lint/src/validate-object-field-refs.ts @@ -103,6 +103,21 @@ * - **`lookupColumns[]`** (both arms: a name, or `{ field }`) — the columns * of this field's record picker. * - **`lookupFilters[].field`** — the picker's base filter. + * - **`lookupFilters[].value.$record`** (#34200) — a comparand read from the + * RECORD BEING EDITED (`LookupFilterRecordReferenceSchema`, #34009): a + * field of the object that owns the picker field, or one lookup hop from + * it (`account.cb_market`). The parse judges its SHAPE (snake_case names, + * at most one dot, the whole value, a scalar operator); only the object + * graph can say whether `account` is a relationship of the edited object + * and `cb_market` a field of what it references. Judged on the picker + * types alone, the picker being its only reader. A path of two hops is + * refused at the second hop on the raw `os lint` path the parse has not + * seen; a hop's leaf on an object outside this stack stays unjudged, as + * every cross-package name in this family does. A `{ $record }` nested + * deeper inside a literal (`value: { any: { $record: 'x' } }`) is an + * opaque literal to the parse, and this rule does not name it either: no + * reader resolves that shape, nothing first-party writes it, and the + * unresolved-`$record` refusal belongs to the server door that meets it. * - **`dependsOn[]`** (both arms: a name, or `{ field, param }`) — the fields * whose values gate this field and, on a picker, scope its candidates. * - **`summaryOperations.filter`** — every field key of a roll-up's child-row @@ -168,6 +183,10 @@ * → the query on `referenceTo` * (`validate-preset-comparands.ts` binds * the same key the same way, #19791) + * lookupFilters[i].value OWNER field.zod.ts `LookupFilterRecordReference` + * .$record — the picker swaps in the edited + * record's value (its reader is #34197, + * not yet landed: judged as declared) * dependsOn[i] / .field OWNER LookupField.tsx — the gate reads the * host's record by this key * dependsOn[i] / .param REFERENCE LookupField.tsx `dependentFilter` — the @@ -184,8 +203,9 @@ * `lookupColumns`, `dependsOn` and `indexes[].fields` are read VERBATIM by * their readers — a picker column key, a record key, a physical column — so * a dotted name there addresses nothing and is judged as one name, never - * walked as a relationship path. `relatedListColumns` and - * `lookupFilters[].field` keep the family's path resolution. + * walked as a relationship path. `relatedListColumns`, + * `lookupFilters[].field` and `lookupFilters[].value.$record` keep the + * family's path resolution — the last bounded to one hop. * * On `dependsOn`, a bare name that misses on the owner is reported once, * there; the same name is not reported a second time against the referenced @@ -435,6 +455,29 @@ interface FieldNameSlot { read: (entry: unknown) => SlotRead | undefined; /** The hint: this position's remedy, one line (the verdict carries the "Did you mean"). */ prescription: string; + /** + * [#34200] `true` when the slot's only reader is the record picker, so it is + * judged only on {@link PICKER_FIELD_TYPES} even though its names address + * the OWNER. (A REFERENCE slot needs the picker's target anyway, so it is + * judged on those types alone without saying so.) + */ + pickerOnly?: boolean; + /** + * [#34200] The most relationship hops a path may take before its leaf, at a + * path-resolved (`verbatim: false`) position whose reader walks a bounded + * number. A path longer than that is refused at the first segment past the + * bound, before anything is resolved. Unset = the family's path resolution, + * unbounded. + */ + maxHops?: number; + /** + * [#34200] `true` when a miss here is its own finding, never folded into + * another slot's at the same entry: the `dependsOn` pair reports a shared + * name once because one fix answers both, which is not true of a `$record` + * path beside the same entry's `.field` — the two name fields of two + * different objects. + */ + ownFinding?: boolean; } function nameOf(v: unknown): string | undefined { @@ -453,6 +496,21 @@ function readMember(entry: unknown, member: string): SlotRead | undefined { return name ? { name, suffix: `.${member}` } : undefined; } +/** + * [#34200] The path of a `{ $record: 'path' }` comparand that is the WHOLE + * `value` of a `lookupFilters` entry — the one place `refuseMalformedLookupFilterEntry` + * (`field.zod.ts`) admits it. A `$record` object as a member of a list value + * is refused by that parse with its own sentence, so it is not read here; one + * nested deeper inside a literal is an opaque literal to the parse and to this + * rule alike (see the module note). + */ +function readRecordReference(entry: unknown): SlotRead | undefined { + if (!isRec(entry) || !isRec(entry.value)) return undefined; + if (!Object.prototype.hasOwnProperty.call(entry.value, '$record')) return undefined; + const name = nameOf(entry.value.$record); + return name ? { name, suffix: '.value.$record' } : undefined; +} + const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [ { key: 'relatedListColumns', @@ -482,6 +540,22 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [ 'Fix `field` — a picker filter runs on the referenced object, so it names a field of that ' + 'object, not of the object that owns this field.', }, + { + // [#34200] `{ $record: 'path' }` reads the RECORD BEING EDITED — the record + // of the object that owns this field — and at most one lookup hop from it + // (`account.cb_market`). Its reader is the picker, which swaps the value in + // before the query leaves the browser. + key: 'lookupFilters', + address: 'owner', + verbatim: false, + pickerOnly: true, + maxHops: 1, + ownFinding: true, + read: readRecordReference, + prescription: + 'Fix the path — `$record` reads the record being edited: a field of this object, or one lookup ' + + 'field of it and then a field of the object that lookup references (`account.cb_market`).', + }, { key: 'dependsOn', address: 'owner', @@ -863,6 +937,7 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[] for (const slot of FIELD_NAME_SLOTS) { const list = field[slot.key]; if (!Array.isArray(list)) continue; + if (slot.pickerOnly && !(meta?.type && PICKER_FIELD_TYPES.has(meta.type))) continue; const against = slot.address === 'owner' ? objName : target; if (!against) continue; @@ -870,17 +945,36 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[] const read = slot.read(entry); if (!read) return; const at = `${slot.key}[${i}]`; - if (reported.has(`${at}=${read.name}`)) return; + if (!slot.ownFinding && reported.has(`${at}=${read.name}`)) return; + const subject = `fields.${fieldName}.${at}${read.suffix}`; + const where = `${label} › fields.${fieldName}.${slot.key}`; + const path = `${objPath}.fields.${fieldName}.${at}${read.suffix}`; + + // A path past the slot's hop bound is refused at the first segment + // beyond it, whatever the earlier segments resolve to: no reader + // walks it, so the rest is not worth resolving. + const segments = read.name.split('.'); + if (slot.maxHops !== undefined && segments.length - 1 > slot.maxHops) { + const past = segments[slot.maxHops]; + refuseKey( + { where, path }, + `${subject} "${read.name}" takes a second hop at "${past}"; it reads at most one lookup hop ` + + `from the record being edited.`, + slot.prescription, + ); + return; + } + const hit = judge({ against, name: read.name, verbatim: slot.verbatim, - subject: `fields.${fieldName}.${at}${read.suffix}`, - where: `${label} › fields.${fieldName}.${slot.key}`, - path: `${objPath}.fields.${fieldName}.${at}${read.suffix}`, + subject, + where, + path, prescription: slot.prescription, }); - if (hit) reported.add(`${at}=${read.name}`); + if (hit && !slot.ownFinding) reported.add(`${at}=${read.name}`); }); } diff --git a/packages/spec/src/migrations/entries/semantic/18.lookup-filter-record-path-unknown-refused.ts b/packages/spec/src/migrations/entries/semantic/18.lookup-filter-record-path-unknown-refused.ts new file mode 100644 index 00000000000..ab823e280d7 --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.lookup-filter-record-path-unknown-refused.ts @@ -0,0 +1,39 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// #34200 — a `lookupFilters[].value` `{ $record: 'path' }` path must resolve +// against the record being edited: `object-field-ref-unknown`, under the family +// ruling that a misspelling is refused loudly at authoring (#19332). The parse +// judges the path's shape only (#34009); which fields it names is the object +// graph's. Measured first-party exposure at this change: zero — no example app, +// platform object, skill or docs sample writes a `$record` path. Not converted: +// which field a misspelt path meant is the author's judgement. +export const entry: SemanticMigration = { + id: 'lookup-filter-record-path-unknown-refused', + surface: + 'objects[].fields..lookupFilters[].value.$record of a lookup, master_detail or user field, on an object saved ' + + 'or published through the metadata doors (PUT /api/v1/meta/object/NAME, POST /api/v1/packages/PKG/publish-drafts, ' + + 'the per-item publish and the restore doors) or loaded by os validate / os build / os lint: a path whose first ' + + 'segment is not a field of the object that owns the picker field, whose hop is not a relationship field, whose ' + + 'second segment is not a field of the object that relationship references, or that takes a second hop', + replacement: + 'A { $record } path names the record being edited: a field of the object that owns the picker field ' + + '("quote_date"), or one relationship field of it followed by a field of the object that field references ' + + '("account.cb_market"). Fix the misspelt segment; a column of the candidate row is a { $field } comparand, not ' + + '{ $record }. Refused at error as `object-field-ref-unknown` (422 INVALID_METADATA at the doors).', + reason: + 'The { $record } shape was declared with only its spelling judged (snake_case names, at most one dot), so a path ' + + 'naming no field of the edited record, or a hop through a text field, parsed clean and was stored. The declared ' + + 'picker swaps in the value at that path before it queries, and an empty value leaves the entry out; a path the ' + + 'record does not have is always empty, so the picker would offer candidates the author meant to exclude, with ' + + 'nothing on screen saying why. The same rule already refuses a dangling lookupFilters[].field or dependsOn name. ' + + 'No first-party stack (example apps, platform objects, skills, docs samples) writes a $record path today. ' + + 'A hop to an object outside the stack (another package) is not judged. There is no mechanical rewrite: which ' + + 'field a misspelt path meant is a judgement about the object.', + acceptanceCriteria: + 'Load every object (`os validate` or `os build`): no `object-field-ref-unknown` finding at ' + + 'fields.NAME.lookupFilters[N].value.$record. PUT /api/v1/meta/object/NAME?mode=draft&package=PKG with each such ' + + 'path naming a field of the object, or one hop to a field of the object a relationship field references, answers ' + + '200, and POST /api/v1/packages/PKG/publish-drafts publishes it.', +}; From d180955e532ba29062b92d2ac11a024151b802ab Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 01:26:28 +0000 Subject: [PATCH 2/3] docs(lint): word the $record explanation as the picker's declared behaviour Claude-Session: https://claude.ai/code/session_01ADHkmS3jo9CFJZXCvjc2n4 Co-authored-by: Claude --- packages/lint/src/rule-explanations.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 1b0bd7f94f8..c258aca4c2b 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -4485,8 +4485,9 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = { 'On those picker fields a `lookupFilters[].value.$record` path is judged too, against the record ' + 'being edited: a field of the object that owns the picker field, or at most one hop from it (a ' + 'relationship field of that object, then a field of the object it references, as in ' + - '`account.cb_market`). The picker swaps that value into its query, so a path the record does ' + - 'not have leaves the filter with nothing to compare. A miss names the segment: an unknown head, ' + + '`account.cb_market`). The picker is declared to swap that value into its query and to leave ' + + 'an entry out while the value is empty, so a path the record does not have would drop the filter ' + + 'without a word. A miss names the segment: an unknown head, ' + 'a hop through a field that is not a relationship, a leaf the referenced object lacks, or a ' + 'second hop. A `$record` nested inside a literal value is not a reference and is not judged.', 'A summary field\'s `summaryOperations.filter` is judged against the CHILD object ' + From c83d11952d4f7e2eaec92308b91cbaf17aaaf61e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 02:53:05 +0000 Subject: [PATCH 3/3] test(lint): pin the $record hops through user, tree and injected columns as accepted; say relationship hop Claude-Session: https://claude.ai/code/session_01ADHkmS3jo9CFJZXCvjc2n4 Co-authored-by: Claude --- ...34200-lookup-filter-record-path-checked.md | 4 ++-- packages/lint/src/rule-explanations.ts | 3 ++- .../src/validate-object-field-refs.test.ts | 24 ++++++++++++++++--- .../lint/src/validate-object-field-refs.ts | 10 ++++---- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.changeset/34200-lookup-filter-record-path-checked.md b/.changeset/34200-lookup-filter-record-path-checked.md index 8ceda17903c..0da74dfa6a1 100644 --- a/.changeset/34200-lookup-filter-record-path-checked.md +++ b/.changeset/34200-lookup-filter-record-path-checked.md @@ -5,12 +5,12 @@ feat(lint)!: a `lookupFilters` `{ $record: "path" }` path must name a field of the record being edited, or one hop from it -Clause-②: no (narrowing) — a `lookupFilters[].value` `{ $record }` path on a lookup, master_detail or user field that names no field of the object owning that field, hops through a field that is not a relationship, names a leaf the referenced object lacks, or takes a second hop, parsed clean and published; it is now refused at error as `object-field-ref-unknown` by `os lint`, `os validate`, `os build` and the runtime publish door. +Clause-②: no (narrowing) — a `lookupFilters[].value` `{ $record }` path on a lookup, master_detail or user field that names no field of the object owning that field, hops through a field that is not a relationship, names a leaf the referenced object lacks, or takes a second hop, parsed clean and published; it is now refused at error as `object-field-ref-unknown` by `os lint`, `os validate`, `os build` and the runtime publish door, and reported (never refused) on the package publish receipt's object probe. Metadata-protocol: narrowed Skills-docs: follow-up #34201 — no doc or skill teaches `{ $record }` yet (the picker that resolves it has not landed; both describes carry `[PLANNED — not enforced]`), so there is no teaching to correct; the existing follow-up for `{ $record }` docs moves with the picker change. -**BREAKING** only for a `{ $record }` path that already names nothing the record being edited carries. The `{ $record }` shape landed with its spelling judged (snake_case names, at most one dot) but not what it names, so `{ $record: "acount.cb_market" }` parsed and was stored. `object-field-ref-unknown` now resolves it against the object that owns the picker field: the first segment is a field of that object; with a second segment the first is a relationship field and the second a field of the object it references. A hop to an object outside the stack is not judged. Measured first-party exposure: zero — no example app, platform object, skill or docs sample writes a `$record` path. +**BREAKING** only for a `{ $record }` path that already names nothing the record being edited carries. The `{ $record }` shape landed with its spelling judged (snake_case names, at most one dot) but not what it names, so `{ $record: "acount.cb_market" }` parsed and was stored. `object-field-ref-unknown` now resolves it against the object that owns the picker field: the first segment is a field of that object; with a second segment the first is a relationship field (`lookup`, `master_detail`, `user` or `tree`) and the second a field of the object it references. A hop to an object outside the stack is not judged. Measured first-party exposure: zero — no example app, platform object, skill or docs sample writes a `$record` path. **Fix:** correct the misspelt segment. `{ $record }` reads the record being edited; a column of the candidate row is written `{ $field: "column" }`. The semantic entry `lookup-filter-record-path-unknown-refused` carries the same notice into the upgrade guide and `os migrate meta`. `os explain object-field-ref-unknown` lists the position. diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index c258aca4c2b..4f9ea6da094 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -4483,7 +4483,8 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = { '`lookup`, `master_detail` and `user` fields, the types that render the picker, and a bare ' + '`dependsOn` name that misses on the owning object is reported once, there.', 'On those picker fields a `lookupFilters[].value.$record` path is judged too, against the record ' + - 'being edited: a field of the object that owns the picker field, or at most one hop from it (a ' + + 'being edited: a field of the object that owns the picker field, or at most one relationship hop ' + + 'from it (a ' + 'relationship field of that object, then a field of the object it references, as in ' + '`account.cb_market`). The picker is declared to swap that value into its query and to leave ' + 'an entry out while the value is empty, so a path the record does not have would drop the filter ' + diff --git a/packages/lint/src/validate-object-field-refs.test.ts b/packages/lint/src/validate-object-field-refs.test.ts index 3b924e3c766..be22cb298a2 100644 --- a/packages/lint/src/validate-object-field-refs.test.ts +++ b/packages/lint/src/validate-object-field-refs.test.ts @@ -709,7 +709,7 @@ describe('validateObjectFieldRefs — lookupFilters[].field (addresses the REFER describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD BEING EDITED, one hop, #34200)', () => { // A quote's Price Book picker (the `LookupFilterRecordReference` example): // `$record` reads the quote — the object that OWNS the picker field — or one - // lookup hop from it, never the price book the filter runs on. + // relationship hop from it, never the price book the filter runs on. const quote = (filters: unknown[], over: Record = {}) => ({ objects: [ { @@ -719,6 +719,8 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD notes: { type: 'text' }, account: { type: 'lookup', reference: 'crm_account' }, partner: { type: 'lookup', reference: 'elsewhere_partner' }, + parent_quote: { type: 'tree', reference: 'sales_quote' }, + approver_user: { type: 'user' }, price_book: { type: 'lookup', reference: 'sales_price_book', lookupFilters: filters }, ...over, }, @@ -769,7 +771,7 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD expect(findings.map((f) => f.path)).toEqual([at(0)]); expect(findings[0]!.message).toBe( 'fields.price_book.lookupFilters[0].value.$record "account.parent.cb_market" takes a second hop at ' - + '"parent"; it reads at most one lookup hop from the record being edited.', + + '"parent"; it reads at most one relationship hop from the record being edited.', ); }); @@ -792,6 +794,22 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD expect(validateObjectFieldRefs(quote([entry('account.cb_market')]))).toEqual([]); }); + // [review S1] The hop set is the family's `RELATIONSHIP_FIELD_TYPES`, not + // lookup / master_detail alone: a `user` field is a lookup to `sys_user` + // and a `tree` a self-lookup, each one stored foreign key the picker + // resolves the same way. An injected relationship column is unjudged. + it('passes a hop through a `tree` field (a self-lookup)', () => { + expect(validateObjectFieldRefs(quote([entry('parent_quote.quote_date', 'valid_from')]))).toEqual([]); + }); + + it('passes a hop through a `user` field (a lookup to `sys_user`, unjudged past the hop here)', () => { + expect(validateObjectFieldRefs(quote([entry('approver_user.department')]))).toEqual([]); + }); + + it('passes a hop through an injected column (`owner_id.NAME`): the graph cannot judge it', () => { + expect(validateObjectFieldRefs(quote([entry('owner_id.anything')]))).toEqual([]); + }); + it('stays silent on a hop whose referenced object is not in this stack, as `dependsOn` does', () => { expect(validateObjectFieldRefs(quote([entry('partner.anything')]))).toEqual([]); }); @@ -1165,7 +1183,7 @@ describe('[#22161] one-line verdicts — object-field-ref-unknown', () => { '`relatedListColumns` against the object that owns the field', '`lookupColumns` and `lookupFilters[].field` against the REFERENCED object', '`lookupFilters[].value.$record`', - 'at most one hop', + 'at most one relationship hop', '`lookup`, `master_detail` and `user`', 'reported once, there', 'read verbatim', diff --git a/packages/lint/src/validate-object-field-refs.ts b/packages/lint/src/validate-object-field-refs.ts index d0591651212..9ebcf010481 100644 --- a/packages/lint/src/validate-object-field-refs.ts +++ b/packages/lint/src/validate-object-field-refs.ts @@ -105,7 +105,7 @@ * - **`lookupFilters[].field`** — the picker's base filter. * - **`lookupFilters[].value.$record`** (#34200) — a comparand read from the * RECORD BEING EDITED (`LookupFilterRecordReferenceSchema`, #34009): a - * field of the object that owns the picker field, or one lookup hop from + * field of the object that owns the picker field, or one relationship hop from * it (`account.cb_market`). The parse judges its SHAPE (snake_case names, * at most one dot, the whole value, a scalar operator); only the object * graph can say whether `account` is a relationship of the edited object @@ -542,7 +542,7 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [ }, { // [#34200] `{ $record: 'path' }` reads the RECORD BEING EDITED — the record - // of the object that owns this field — and at most one lookup hop from it + // of the object that owns this field — and at most one relationship hop from it // (`account.cb_market`). Its reader is the picker, which swaps the value in // before the query leaves the browser. key: 'lookupFilters', @@ -553,8 +553,8 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [ ownFinding: true, read: readRecordReference, prescription: - 'Fix the path — `$record` reads the record being edited: a field of this object, or one lookup ' - + 'field of it and then a field of the object that lookup references (`account.cb_market`).', + 'Fix the path — `$record` reads the record being edited: a field of this object, or one ' + + 'relationship field of it and then a field of the object it references (`account.cb_market`).', }, { key: 'dependsOn', @@ -958,7 +958,7 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[] const past = segments[slot.maxHops]; refuseKey( { where, path }, - `${subject} "${read.name}" takes a second hop at "${past}"; it reads at most one lookup hop ` + `${subject} "${read.name}" takes a second hop at "${past}"; it reads at most one relationship hop ` + `from the record being edited.`, slot.prescription, );