Skip to content

Commit f23c71e

Browse files
feat(lint)!: refuse a lookupFilters { $record } path through or to a multi-valued field (#34489)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9HYSvbtx2THhVaC74JSSiEP)_ Fixes #34378 Clause-②: no (narrowing) — a `lookupFilters[].value` `{ $record }` path on a lookup, master_detail or user field whose first segment is a multi-valued field of the object owning that field (a plain path to it, or a hop through it), or whose leaf behind a single-valued hop is a multi-valued field, linted 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, so there is no teaching to correct here; the multi-valued clause rides the describes this change edits. ## 维护者速读 - 改了什么:查找字段 `lookupFilters` 里的 `{ $record: "路径" }`(读取正在编辑的记录)如果指向或穿过多值字段(`multiple: true` 的查找/选择/人员字段,或多选、复选框、标签字段),lint 现在直接报错并点名那个字段。 - 为什么改:`$record` 代表"一个值",只配 eq/ne/gt/lt/gte/lte 这类单值比较;多值字段是一个列表,之前 lint 照样放行,结果选择器要么悄悄丢掉这条过滤,要么拿列表去比单值,过滤看着对、实际不生效。 - 风险与回滚:只收紧同一条 lint 规则(`object-field-ref-unknown` 的 `$record` 成员);examples / 平台对象 / 插件 / skills / 文档样例实测 0 处写 `$record` 路径,无存量受影响。客户端半边(选择器丢弃该条并给开发提示)在 #34389,不在本 PR。回滚即 revert。 - 先看:`packages/lint/src/validate-object-field-refs.ts`(`multiValuedSegment` 与 `$record` 槽位后的判读)、`packages/lint/src/validate-object-field-refs.test.ts`(多值一组 8 条)、`packages/spec/src/migrations/entries/semantic/18.lookup-filter-record-path-multi-valued-refused.ts`。 - 两分钟验证:`pnpm --filter @objectstack/lint exec vitest run src/validate-object-field-refs.test.ts`,预期 127 条全绿,其中多值一组 8 条。 - 需要你做的:无,席位落地。 ## What changes - `object-field-ref-unknown`, `lookupFilters[N].value.$record` member: a path that already resolves is judged for cardinality too (a new slot property `singleValued`, set only on that member). The predicate is spec's own `isMultiValueField` (`@objectstack/spec/data`), the one `FieldSchema` reads: an inherently multi type (`multiselect`, `checkboxes`, `tags`), or `multiple: true` on a multi-capable type. No second copy of the type list. - A multi-valued FIRST segment of the owning object is refused at the head, whether the path ends there (`tags`) or hops through it (`accounts.cb_market`): message `... names "tags", a multi-valued field ...` / `... goes through "accounts", a multi-valued field ...`. - Behind a single-valued hop, a multi-valued LEAF is refused at the leaf, naming the leaf's object (`account.markets` ends at `markets` on `crm_account`). - Judged only on a path the family's resolution did not already refuse (a misspelt leaf behind a multi hop is reported once, as the miss). A registry-injected column and a leaf on an object outside the stack stay unjudged, as today. A multi-valued head pointing outside the stack is still refused: the head is the owning object's own field. - Hint: `Point $record at a single-valued field ...`. - `rule-explanations.ts`: the `$record` paragraph of `os explain object-field-ref-unknown` names the multi-valued refusal. - `packages/spec/src/data/field.zod.ts`: the `LookupFilterRecordReferenceSchema` describe and the `lookupFilters[].value` describe each gain one clause: such a path has no single value, is not resolved, and lint refuses it. No client behaviour is claimed; the picker's handling is #34389 (named in the jsdoc only — the describes carry no tracker ids). The value describe keeps main's sentence on the server refusal of an unresolved `{ $record }`. - ADR-0087 semantic entry `lookup-filter-record-path-multi-valued-refused` (template: `lookup-filter-record-path-unknown-refused`); the id does not collide on main at `0e2e4f56`. - Regenerated `content/docs/references/data/field.mdx`. ### First-party exposure (measured at `7f731083`) `git grep -lE` for a `$record:` key with a string value, outside `*.test.ts(x)` and `content/docs/references/**`: zero files in `examples/`, `packages/platform-objects`, `packages/plugins`, `packages/services`, `packages/qa`, `skills/`, `content/docs/` and `ui/examples`. Repo-wide the only hits are changesets, the spec/lint/core sources and semantic entries, and the ui picker reader. Positive control: the same expression counts 8 lines in `packages/lint/src/validate-object-field-refs.test.ts`. Verdict: nothing first-party to judge; no shipped app's picker changes. ## Tests `packages/lint/src/validate-object-field-refs.test.ts`, new block `a path through or to a multi-valued field` (8 cases); every refusal asserts `severity: 'error'`, `rule: OBJECT_FIELD_REF_UNKNOWN`, the path and the hint: | case | verdict | |:--|:--| | plain path to `tags` | refused, `names "tags"` (full message pinned) | | plain path to a `multiple: true` select | refused | | hop through a `multiple: true` lookup `accounts.cb_market` | refused at the hop (full message pinned) | | hop through a `multiple: true` user field | refused at the hop | | hop through a multi lookup to an object outside the stack | refused at the head | | multi-valued leaf `account.markets` behind a single hop | refused at the leaf, on `crm_account` (full message pinned) | | misspelt leaf behind a multi hop | one finding, the miss | | CONTROLS: plain single field, single lookup, single hop, `multiple: false` select, hop to an injected column | clean | Forced edits to existing tests, named: the shared `quote` fixture's `crm_account` gains a `markets: multiselect` field (no existing case reads it), and the one-line-verdict fact list gains `a path through or to a multi-valued field`. <details><summary>Ablation (scripts/ablation-replace.mjs; restored blob == HEAD)</summary> Cardinality read disabled (`if (!hit && slot.singleValued) {` → guarded by an unset global marker): `Tests 6 failed | 121 passed (127)` — exactly the six refusal cases; the miss case and every control stayed green. Restored: blob `fd916767` == HEAD, `git diff HEAD` empty. The test imports `./validate-object-field-refs.js` relatively (source, not `dist`), so no rebuild leg applies. </details> ## Acceptance notes - The resumed commits (`ff1bf727`, `5b520173`, `3781dec5`) came from a stopped thread with no report; every reading here was re-taken on this branch. Merging them onto main conflicted in the `lookupFilters[].value` describe with main's server-refusal sentence (#34330); both sentences are kept. - The client still sends the list for a plain multi-valued path today; that half is #34389 (domain:ui). This PR touches no `ui/` file. ## Verification Readings at head `7f731083` (merge of `origin/main` `e8cba8fe`; the incoming commits touch only `ui/`), after a full `pnpm build --concurrency=2` (119 tasks, VERDICT command-exit 0). - `@objectstack/lint` `typecheck` exit 0; `test`: `Test Files 214 passed (214)`, `Tests 9091 passed (9091)`. - `@objectstack/spec` `typecheck` exit 0; `vitest run src/data src/migrations`: `Test Files 178 passed (178)`, `Tests 6556 passed | 1 todo (6557)`. - `@objectstack/cli` unit `test/explain-rule-id.test.ts` (iterates every `os explain` entry): `Tests 14 passed (14)`. - `pnpm --filter @objectstack/spec check:generated`: `content/docs/references/**` stale until `gen:schema && gen:docs` regenerated `field.mdx` (committed); `check:test-typecheck` exit 0 when re-run with a 4 GB heap (the first run died in `tsc` without diagnostics, a heap reading, not a finding). - Full dogfood battery (title carries `!`, Clause-② carries `(narrowing)`): running at this head when the PR opened; the reading follows on the card report. <details><summary>Derived gate round at 7f73108: dispatch-gates --commands gives 117 families; --ran gives 117 run, 0 NOT-MEASURED, 0 UNRUN</summary> All 117 exited 0 on their first run at this head (`check-plugin-teardown-shape --self-test` after fetching its pinned fixture commit). </details> --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmR92m7ZN6cUVQTj1VE --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ea1edf9 commit f23c71e

7 files changed

Lines changed: 218 additions & 8 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/spec': minor
4+
---
5+
6+
feat(lint)!: a `lookupFilters` `{ $record: "path" }` path through or to a multi-valued field is refused
7+
8+
Clause-②: no (narrowing) — a `lookupFilters[].value` `{ $record }` path on a lookup, master_detail or user field whose first segment is a multi-valued field of the object owning that field (a plain path to it, or a hop through it), or whose leaf behind a single-valued hop is a multi-valued field, linted 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.
9+
Metadata-protocol: narrowed
10+
Skills-docs: follow-up #34201 — no doc or skill teaches `{ $record }` yet, so there is no teaching to correct here; the multi-valued clause rides the describes this change edits.
11+
12+
<!-- adr-0087: registered lookup-filter-record-path-multi-valued-refused -->
13+
14+
**BREAKING** only for a `{ $record }` path that reads a list. A `{ $record }` comparand stands for ONE value of the record being edited and pairs only with `eq`, `ne`, `gt`, `lt`, `gte` or `lte`, but the path check judged only that each segment names a field, so `{ $record: "accounts.cb_market" }` through a `multiple: true` lookup, or `{ $record: "tags" }`, linted clean. A hop through a multi-valued lookup reaches no single row, so the entry was left out without a word; a plain path to a multi-valued field put a list where one value goes. `object-field-ref-unknown` now refuses the path at the multi-valued field and names it. Multi-valued means `isMultiValueField`: a field flagged `multiple: true`, or a `multiselect`, `checkboxes` or `tags` field. A registry-injected column and a leaf on an object outside the stack are not judged. Measured first-party exposure: zero — no example app, platform object, skill or docs sample writes a `$record` path.
15+
16+
**FROM → TO.** FROM `{ $record: "accounts.cb_market" }` (a hop through a `multiple: true` lookup), `{ $record: "tags" }` or `{ $record: "account.markets" }` (a multi-valued leaf) TO a path that ends at, and hops through, single-valued fields only.
17+
18+
**Fix:** copy the value you mean onto a single-valued field of the record being edited (or of the record one single-valued hop away) and reference that. The semantic entry `lookup-filter-record-path-multi-valued-refused` carries the same notice into the upgrade guide and `os migrate meta`. `os explain object-field-ref-unknown` lists the position.

‎content/docs/references/data/field.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ const result = CurrencyConfigSchema.parse(data);
242242
| :--- | :--- | :--- | :--- |
243243
| **field** | `string` | ✅ | |
244244
| **operator** | `Enum<'eq' \| 'ne' \| 'gt' \| 'lt' \| 'gte' \| 'lte' \| 'contains' \| 'in' \| 'notIn'>` | ✅ | |
245-
| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. In a record form, whatever its layout, the picker sends the referenced value in place of the reference; every other picker host leaves the entry out. A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null. |
245+
| **value** | `any` | ✅ | The comparand: a literal (an array for `in` / `notIn`), a date placeholder such as `{today}` or a `{ $now: true, addDays }` comparand for a date relative to today, or a `{ $record: "path" }` reference to the record being edited — a field of it, or one lookup hop ("account.cb_market"); a `{ $record }` value pairs only with eq, ne, gt, lt, gte or lte. In a record form, whatever its layout, the picker sends the referenced value in place of the reference; every other picker host leaves the entry out. A `{ $record }` path through or to a multi-valued field (one flagged `multiple: true`, or a multiselect, checkboxes or tags field) has no single value: it is not resolved, and lint refuses it (`object-field-ref-unknown`). A `{ $record }` that reaches a server unresolved is refused (INVALID_FILTER), never read as null. |
246246
| **orEmpty** | `boolean` | optional | TRUE: the entry also matches a candidate whose column is null — "valid from the quote date, or with no start date". Only with eq, ne, gt, lt, gte or lte. The picker sends the comparison or a null match on the same column. |
247247

248248
### Nested Shape: `Field.lookupAutofill[number]`
@@ -437,7 +437,7 @@ Allowed Values: `phone`, `id_card`, `bank_account`, `email`, `name`
437437

438438
## LookupFilterRecordReference
439439

440-
A lookupFilters comparand read from the record being edited: `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop). The picker replaces it with that value before querying; unlike `{ $field }`, which names a column of the candidate row.
440+
A lookupFilters comparand read from the record being edited: `{ $record: "field" }` or `{ $record: "lookup_field.field" }` (at most one lookup hop). The picker replaces it with that value before querying; unlike `{ $field }`, which names a column of the candidate row. A path through or to a multi-valued field (one flagged `multiple: true`, or a multiselect, checkboxes or tags field) has no single value: it is not resolved, and lint refuses it (`object-field-ref-unknown`).
441441

442442
### Properties
443443

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4499,7 +4499,10 @@ const OBJECT_FIELD_REF_UNKNOWN_EXPLANATION: RuleExplanation = {
44994499
'an entry out while the value is empty, so a path the record does not have would drop the filter ' +
45004500
'without a word. A miss names the segment: an unknown head, ' +
45014501
'a hop through a field that is not a relationship, a leaf the referenced object lacks, or a ' +
4502-
'second hop. A `$record` nested inside a literal value is not a reference and is not judged.',
4502+
'second hop. A path that names real fields is refused too when it reads a list: a path through or ' +
4503+
'to a multi-valued field (one flagged `multiple: true`, or a `multiselect`, `checkboxes` or `tags` ' +
4504+
'field), or a multi-valued leaf behind one hop, because the comparand is one ' +
4505+
'value under a scalar operator. A `$record` nested inside a literal value is not a reference and is not judged.',
45034506
'A summary field\'s `summaryOperations.filter` is judged against the CHILD object ' +
45044507
'`summaryOperations.object` names: the engine ANDs it with the parent-FK match and runs it as the ' +
45054508
'query on that child, so every key (inside `$and` / `$or` / `$not` groups) is a field of the child. ' +

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD
731731
name: { type: 'text' },
732732
cb_market: { type: 'select' },
733733
parent: { type: 'lookup', reference: 'crm_account' },
734+
markets: { type: 'multiselect' },
734735
},
735736
},
736737
{
@@ -855,6 +856,79 @@ describe('validateObjectFieldRefs — lookupFilters[].value.$record (the RECORD
855856
}));
856857
expect(findings.map((f) => f.path)).toEqual(['objects[0].fields.approver.lookupFilters[0].value.$record']);
857858
});
859+
860+
// [#34378] A path that names real fields can still read a LIST. The
861+
// comparand is one value under a scalar operator, so a multi-valued head
862+
// (a plain path to it, or a hop through it) or a multi-valued leaf behind a
863+
// single-valued hop is refused — by `isMultiValueField`, `FieldSchema`'s own
864+
// predicate: an inherently multi type, or `multiple: true` on a
865+
// multi-capable one.
866+
describe('a path through or to a multi-valued field (#34378)', () => {
867+
const multi = {
868+
tags: { type: 'tags' },
869+
regions: { type: 'select', multiple: true },
870+
stage: { type: 'select', multiple: false },
871+
accounts: { type: 'lookup', reference: 'crm_account', multiple: true },
872+
partners: { type: 'lookup', reference: 'elsewhere_partner', multiple: true },
873+
watchers: { type: 'user', multiple: true },
874+
};
875+
const refused = (path: string) => {
876+
const findings = validateObjectFieldRefs(quote([entry(path)], multi));
877+
expect(findings.map((f) => f.path)).toEqual([at(0)]);
878+
expect(findings[0]).toMatchObject({ severity: 'error', rule: OBJECT_FIELD_REF_UNKNOWN });
879+
expect(findings[0]!.hint).toContain('Point `$record` at a single-valued field');
880+
return findings[0]!.message;
881+
};
882+
883+
it('REFUSES a plain path to an inherently multi-valued field (`tags`)', () => {
884+
expect(refused('tags')).toBe(
885+
'fields.price_book.lookupFilters[0].value.$record "tags" names "tags", a multi-valued field on object '
886+
+ '"sales_quote"; a $record comparand is one value under a scalar operator.',
887+
);
888+
});
889+
890+
it('REFUSES a plain path to a `multiple: true` select', () => {
891+
expect(refused('regions')).toContain('names "regions", a multi-valued field on object "sales_quote"');
892+
});
893+
894+
it('REFUSES a hop through a `multiple: true` lookup, at the hop', () => {
895+
expect(refused('accounts.cb_market')).toBe(
896+
'fields.price_book.lookupFilters[0].value.$record "accounts.cb_market" goes through "accounts", a '
897+
+ 'multi-valued field on object "sales_quote"; a $record comparand is one value under a scalar operator.',
898+
);
899+
});
900+
901+
it('REFUSES a hop through a `multiple: true` user field, its target unjudged past the hop', () => {
902+
expect(refused('watchers.department')).toContain('goes through "watchers", a multi-valued field');
903+
});
904+
905+
it('REFUSES a hop through a multi-valued lookup to an object outside the stack: the head is this object\'s', () => {
906+
expect(refused('partners.anything')).toContain('goes through "partners", a multi-valued field');
907+
});
908+
909+
it('REFUSES a multi-valued leaf behind a single-valued hop, naming the leaf and its object', () => {
910+
expect(refused('account.markets')).toBe(
911+
'fields.price_book.lookupFilters[0].value.$record "account.markets" ends at "markets", a multi-valued '
912+
+ 'field on object "crm_account"; a $record comparand is one value under a scalar operator.',
913+
);
914+
});
915+
916+
it('reports a misspelt leaf behind a multi-valued hop once, as the miss', () => {
917+
const findings = validateObjectFieldRefs(quote([entry('accounts.cb_markt')], multi));
918+
expect(findings.map((f) => f.path)).toEqual([at(0)]);
919+
expect(findings[0]!.message).toContain('"accounts.cb_markt" is not a field on object "crm_account"');
920+
});
921+
922+
it('passes single-valued paths: a plain field, a single lookup, a hop, a `multiple: false` select', () => {
923+
expect(validateObjectFieldRefs(quote([
924+
{ field: 'valid_from', operator: 'lte', value: { $record: 'quote_date' } },
925+
entry('account', 'cb_market'),
926+
entry('account.cb_market'),
927+
entry('stage'),
928+
entry('account.created_at', 'valid_to'),
929+
], multi))).toEqual([]);
930+
});
931+
});
858932
});
859933

860934
describe('validateObjectFieldRefs — summaryOperations.filter (addresses the CHILD object, #31224)', () => {
@@ -1184,6 +1258,7 @@ describe('[#22161] one-line verdicts — object-field-ref-unknown', () => {
11841258
'`lookupColumns` and `lookupFilters[].field` against the REFERENCED object',
11851259
'`lookupFilters[].value.$record`',
11861260
'at most one relationship hop',
1261+
'a path through or to a multi-valued field',
11871262
'`lookup`, `master_detail` and `user`',
11881263
'reported once, there',
11891264
'read verbatim',

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

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@
113113
* types alone, the picker being its only reader. A path of two hops is
114114
* refused at the second hop on the raw `os lint` path the parse has not
115115
* seen; a hop's leaf on an object outside this stack stays unjudged, as
116-
* every cross-package name in this family does. A `{ $record }` nested
116+
* every cross-package name in this family does. A path through or to a
117+
* MULTI-VALUED field (#34378) — a hop through a `multiple: true` lookup
118+
* (`accounts.cb_market`), a plain path to one (`tags`), or a leaf that is
119+
* one behind a single-valued hop — is refused too: the comparand is ONE
120+
* value under a scalar operator, and a list has no such value. The
121+
* predicate is `isMultiValueField` (`@objectstack/spec/data`), the one
122+
* `FieldSchema` reads. A registry-injected column, and a leaf on an object
123+
* outside this stack, stay unjudged. A `{ $record }` nested
117124
* deeper inside a literal (`value: { any: { $record: 'x' } }`) is an
118125
* opaque literal to the parse, and this rule does not name it either: no
119126
* reader resolves that shape, nothing first-party writes it, and the
@@ -286,9 +293,10 @@ import {
286293
recordsOf,
287294
resolveFieldPath,
288295
type FieldPathVerdict,
296+
type GraphField,
289297
type ObjectGraph,
290298
} from './object-graph.js';
291-
import { classifyDottedFilterHead, isVirtualSearchField } from '@objectstack/spec/data';
299+
import { classifyDottedFilterHead, isMultiValueField, isVirtualSearchField } from '@objectstack/spec/data';
292300

293301
/**
294302
* A field-name list entry — object-level, or on one of the object's fields —
@@ -478,6 +486,18 @@ interface FieldNameSlot {
478486
* different objects.
479487
*/
480488
ownFinding?: boolean;
489+
/**
490+
* [#34378] `true` when the path must read ONE value: its first segment and,
491+
* behind a hop, its leaf may not be multi-valued (`isMultiValueField`). A
492+
* path whose head is multi-valued is refused whether it ends there or hops
493+
* through it, at the head; a multi-valued leaf behind a single-valued hop is
494+
* refused at the leaf. Judged only on a path the family's resolution did
495+
* not already refuse, and only on AUTHORED fields: a registry-injected
496+
* column, or a leaf on an object outside the stack, stays unjudged.
497+
*/
498+
singleValued?: boolean;
499+
/** [#34378] The hint when {@link singleValued} refuses a path. */
500+
singleValuedPrescription?: string;
481501
}
482502

483503
function nameOf(v: unknown): string | undefined {
@@ -551,10 +571,14 @@ const FIELD_NAME_SLOTS: readonly FieldNameSlot[] = [
551571
pickerOnly: true,
552572
maxHops: 1,
553573
ownFinding: true,
574+
singleValued: true,
554575
read: readRecordReference,
555576
prescription:
556577
'Fix the path — `$record` reads the record being edited: a field of this object, or one '
557578
+ 'relationship field of it and then a field of the object it references (`account.cb_market`).',
579+
singleValuedPrescription:
580+
'Point `$record` at a single-valued field: a multi-valued field holds a list, and no scalar comparison '
581+
+ 'takes one. Copy the value you mean onto a single-valued field and reference that.',
558582
},
559583
{
560584
key: 'dependsOn',
@@ -675,6 +699,29 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[]
675699
findings.push({ severity: 'error', rule: OBJECT_FIELD_REF_UNKNOWN, where: at.where, path: at.path, message, hint });
676700
};
677701

702+
/**
703+
* [#34378] Where a path that resolved stops reading ONE value: its AUTHORED
704+
* first segment on `objectName` when that is multi-valued (a plain path to
705+
* it, or a hop through it), else — behind a single-valued hop — its
706+
* authored leaf when that is. `undefined` = single-valued, or not
707+
* judgeable here (a registry-injected column, an object outside the stack).
708+
*/
709+
const multiValuedSegment = (
710+
objectName: string,
711+
segments: readonly string[],
712+
): { how: string; field: string; object: string } | undefined => {
713+
const isMulti = (m: GraphField | undefined): boolean =>
714+
typeof m?.type === 'string' && isMultiValueField({ type: m.type, multiple: m.multiple === true });
715+
const head = graph.get(objectName)?.fields.get(segments[0]!);
716+
if (isMulti(head)) {
717+
return { how: segments.length > 1 ? 'goes through' : 'names', field: segments[0]!, object: objectName };
718+
}
719+
if (segments.length < 2) return undefined;
720+
const verdict = resolveFieldPath(graph, objectName, segments.join('.'));
721+
if (verdict?.kind !== 'ok' || verdict.injected || !isMulti(verdict.meta)) return undefined;
722+
return { how: 'ends at', field: verdict.field, object: verdict.object };
723+
};
724+
678725
/** The declared slice of `name` on `objectName` — authored, else registry-injected. */
679726
const fieldOf = (objectName: string, name: string) => {
680727
const o = graph.get(objectName);
@@ -975,6 +1022,21 @@ export function validateObjectFieldRefs(stack: AnyRec): ObjectFieldRefFinding[]
9751022
prescription: slot.prescription,
9761023
});
9771024
if (hit && !slot.ownFinding) reported.add(`${at}=${read.name}`);
1025+
1026+
// [#34378] A path that names real fields can still read a LIST: a
1027+
// multi-valued head, or a multi-valued leaf behind one hop. The
1028+
// comparand is one value under a scalar operator, so it is refused.
1029+
if (!hit && slot.singleValued) {
1030+
const multi = multiValuedSegment(against, segments);
1031+
if (multi) {
1032+
refuseKey(
1033+
{ where, path },
1034+
`${subject} "${read.name}" ${multi.how} "${multi.field}", a multi-valued field on object `
1035+
+ `"${multi.object}"; a $record comparand is one value under a scalar operator.`,
1036+
slot.singleValuedPrescription ?? slot.prescription,
1037+
);
1038+
}
1039+
}
9781040
});
9791041
}
9801042

0 commit comments

Comments
 (0)