Skip to content

Commit c83d119

Browse files
committed
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 <noreply@anthropic.com>
1 parent d180955 commit c83d119

4 files changed

Lines changed: 30 additions & 11 deletions

File tree

‎.changeset/34200-lookup-filter-record-path-checked.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
feat(lint)!: a `lookupFilters` `{ $record: "path" }` path must name a field of the record being edited, or one hop from it
77

8-
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.
8+
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.
99
Metadata-protocol: narrowed
1010
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.
1111

1212
<!-- adr-0087: registered lookup-filter-record-path-unknown-refused -->
1313

14-
**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.
14+
**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.
1515

1616
**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.

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4483,7 +4483,8 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = {
44834483
'`lookup`, `master_detail` and `user` fields, the types that render the picker, and a bare ' +
44844484
'`dependsOn` name that misses on the owning object is reported once, there.',
44854485
'On those picker fields a `lookupFilters[].value.$record` path is judged too, against the record ' +
4486-
'being edited: a field of the object that owns the picker field, or at most one hop from it (a ' +
4486+
'being edited: a field of the object that owns the picker field, or at most one relationship hop ' +
4487+
'from it (a ' +
44874488
'relationship field of that object, then a field of the object it references, as in ' +
44884489
'`account.cb_market`). The picker is declared to swap that value into its query and to leave ' +
44894490
'an entry out while the value is empty, so a path the record does not have would drop the filter ' +

‎packages/lint/src/validate-object-field-refs.test.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ describe('validateObjectFieldRefs — lookupFilters[].field (addresses the REFER
709709
describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD BEING EDITED, one hop, #34200)', () => {
710710
// A quote's Price Book picker (the `LookupFilterRecordReference` example):
711711
// `$record` reads the quote — the object that OWNS the picker field — or one
712-
// lookup hop from it, never the price book the filter runs on.
712+
// relationship hop from it, never the price book the filter runs on.
713713
const quote = (filters: unknown[], over: Record<string, unknown> = {}) => ({
714714
objects: [
715715
{
@@ -719,6 +719,8 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD
719719
notes: { type: 'text' },
720720
account: { type: 'lookup', reference: 'crm_account' },
721721
partner: { type: 'lookup', reference: 'elsewhere_partner' },
722+
parent_quote: { type: 'tree', reference: 'sales_quote' },
723+
approver_user: { type: 'user' },
722724
price_book: { type: 'lookup', reference: 'sales_price_book', lookupFilters: filters },
723725
...over,
724726
},
@@ -769,7 +771,7 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD
769771
expect(findings.map((f) => f.path)).toEqual([at(0)]);
770772
expect(findings[0]!.message).toBe(
771773
'fields.price_book.lookupFilters[0].value.$record "account.parent.cb_market" takes a second hop at '
772-
+ '"parent"; it reads at most one lookup hop from the record being edited.',
774+
+ '"parent"; it reads at most one relationship hop from the record being edited.',
773775
);
774776
});
775777

@@ -792,6 +794,22 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD
792794
expect(validateObjectFieldRefs(quote([entry('account.cb_market')]))).toEqual([]);
793795
});
794796

797+
// [review S1] The hop set is the family's `RELATIONSHIP_FIELD_TYPES`, not
798+
// lookup / master_detail alone: a `user` field is a lookup to `sys_user`
799+
// and a `tree` a self-lookup, each one stored foreign key the picker
800+
// resolves the same way. An injected relationship column is unjudged.
801+
it('passes a hop through a `tree` field (a self-lookup)', () => {
802+
expect(validateObjectFieldRefs(quote([entry('parent_quote.quote_date', 'valid_from')]))).toEqual([]);
803+
});
804+
805+
it('passes a hop through a `user` field (a lookup to `sys_user`, unjudged past the hop here)', () => {
806+
expect(validateObjectFieldRefs(quote([entry('approver_user.department')]))).toEqual([]);
807+
});
808+
809+
it('passes a hop through an injected column (`owner_id.NAME`): the graph cannot judge it', () => {
810+
expect(validateObjectFieldRefs(quote([entry('owner_id.anything')]))).toEqual([]);
811+
});
812+
795813
it('stays silent on a hop whose referenced object is not in this stack, as `dependsOn` does', () => {
796814
expect(validateObjectFieldRefs(quote([entry('partner.anything')]))).toEqual([]);
797815
});
@@ -1165,7 +1183,7 @@ describe('[#22161] one-line verdicts — object-field-ref-unknown', () => {
11651183
'`relatedListColumns` against the object that owns the field',
11661184
'`lookupColumns` and `lookupFilters[].field` against the REFERENCED object',
11671185
'`lookupFilters[].value.$record`',
1168-
'at most one hop',
1186+
'at most one relationship hop',
11691187
'`lookup`, `master_detail` and `user`',
11701188
'reported once, there',
11711189
'read verbatim',

‎packages/lint/src/validate-object-field-refs.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
* - **`lookupFilters[].field`** — the picker's base filter.
106106
* - **`lookupFilters[].value.$record`** (#34200) — a comparand read from the
107107
* RECORD BEING EDITED (`LookupFilterRecordReferenceSchema`, #34009): a
108-
* field of the object that owns the picker field, or one lookup hop from
108+
* field of the object that owns the picker field, or one relationship hop from
109109
* it (`account.cb_market`). The parse judges its SHAPE (snake_case names,
110110
* at most one dot, the whole value, a scalar operator); only the object
111111
* graph can say whether `account` is a relationship of the edited object
@@ -542,7 +542,7 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [
542542
},
543543
{
544544
// [#34200] `{ $record: 'path' }` reads the RECORD BEING EDITED — the record
545-
// of the object that owns this field — and at most one lookup hop from it
545+
// of the object that owns this field — and at most one relationship hop from it
546546
// (`account.cb_market`). Its reader is the picker, which swaps the value in
547547
// before the query leaves the browser.
548548
key: 'lookupFilters',
@@ -553,8 +553,8 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [
553553
ownFinding: true,
554554
read: readRecordReference,
555555
prescription:
556-
'Fix the path — `$record` reads the record being edited: a field of this object, or one lookup '
557-
+ 'field of it and then a field of the object that lookup references (`account.cb_market`).',
556+
'Fix the path — `$record` reads the record being edited: a field of this object, or one '
557+
+ 'relationship field of it and then a field of the object it references (`account.cb_market`).',
558558
},
559559
{
560560
key: 'dependsOn',
@@ -958,7 +958,7 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[]
958958
const past = segments[slot.maxHops];
959959
refuseKey(
960960
{ where, path },
961-
`${subject} "${read.name}" takes a second hop at "${past}"; it reads at most one lookup hop `
961+
`${subject} "${read.name}" takes a second hop at "${past}"; it reads at most one relationship hop `
962962
+ `from the record being edited.`,
963963
slot.prescription,
964964
);

0 commit comments

Comments
 (0)