Repository navigation
Commit 709a087
fix(lint,core)!: refuse a lookup dependsOn filter key naming a formula of its target; an import lookup no scoped read answered is never out of scope (#37910)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu1PSnWkmbF453BynqtyjJc5)_
Fixes #37717
Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — no `skills/` page teaches a `dependsOn` filter key
on a formula field; `content/docs/data-modeling/import-mappings.mdx`
names the refusal in this change
## 维护者速读
- 应用作者在查找字段的 `dependsOn` 里,把筛选键指向目标对象上的公式字段时,`os validate`、构建以及
Studio、REST、MCP
保存都会直接报错,并点出是哪个字段、为什么不行、该改成哪个存储字段。以前这种写法能发布,之后记录选择器查不出候选,导入这一列的每一行都失败。
- 这是座位复审 PR #37706
时留下的两条小尾巴(导入“值属于另一个父记录”这条提示的后续):一条是作者时提前报错,一条是导入时如果限定范围的查询一次都没得到回答,就不再说“这个值在别的父记录下”,只说找不到记录。
- 出错会怎样:只有用到这种写法的对象下次保存时会被拒;仓库里的示例应用和打包对象、hotcrm 都没有这种写法;存量数据不改写,开机不拒。整张
PR 可以直接撤回。
- 要你做的:这是收严(narrowing),走 Tier H,等你审批。
## What changes
- **`@objectstack/lint`, N2: the `dependsOn` filter key must be
filterable.** `validateObjectFieldRefs`
(`validate-object-field-refs.ts`) gains a `filtered` flag on its
field-name slots, set on the REFERENCE half of `dependsOn` (`param`,
else the bare name or `field`), the key the record picker's candidate
query and the importer's scoped lookup filter the referenced object by.
When that name resolves to an authored field of the referenced object
that is computed on read (`isVirtualSearchField` from
`@objectstack/spec/data`, the predicate the engine's filter seam and the
import resolver already use), it reports at `error`, under the existing
rule id `object-field-ref-unknown`, at the entry's path. It runs
wherever that rule runs: `os validate` / `lint` / `compile` / `build`
and the runtime publish gate for `object` writes. Example finding:
```text
fields.contact.dependsOn[0].param "account_label" is a formula field of
"showcase_contact", computed on read: no record-picker query or import
lookup can filter on it.
```
The hint names the fix: point the entry at a stored field of the
referenced object that holds the same value, in the `{ field, param }`
form, or drop it. A formula on the OWNING side (`dependsOn[i].field`,
the form's gate, read from the record being edited) stays legal. `os
explain object-field-ref-unknown` (`rule-explanations.ts`) gains one
sentence for it; the module note says what is judged and why.
- **`@objectstack/core`, N4: no unscoped probe when no scoped read
answered.** The import resolver (`import-runner.ts`) now marks every
scoped lookup none of whose candidate reads answered, and the field
guard did not refuse, as `RefMatch.scopeUnanswered` when the refusals
did not name an unfilterable scope field (that case keeps
`scopeUnqueryable`). `referenceNotFound` (`import-coerce.ts`) returns
the plain `reference_not_found` refusal for it before the unscoped
probe. Before, an all-refused scoped lookup (for example every read
refused `INVALID_FILTER` because the row's master cell is a value the
scoping field's type cannot take) was asked again without the scope and
could answer `reference_out_of_scope`, a claim about where the value
lives that the import never checked. `RefMatch` gains the optional
member `scopeUnanswered`.
- **Wording (N4).** The `validation-message.ts` jsdoc on
`import_reference_scope_unqueryable` and the `import-mappings.mdx`
paragraph now say that any other all-refused scoped lookup keeps
`reference_not_found` and the plain sentence and is not tried again
without the scope. The docs paragraph also says the formula case is
refused at authoring now.
- **Upgrade guide.** New ADR-0087 semantic entry
`lookup-depends-on-param-computed-field-refused`
(`packages/spec/src/migrations/entries/semantic/`), notice only: no D2
conversion, since only the author knows which stored field carries the
value the formula computes.
- **Changeset**
`.changeset/37717-lookup-depends-on-param-computed-field.md`:
`@objectstack/lint` minor (the narrowing), `@objectstack/core` and
`@objectstack/spec` patch, BREAKING banner, FROM → TO, `registered`
disposition. The pending note
`.changeset/36794-wizard-reference-out-of-scope.md` is left as it is:
its sentence "A scoped lookup whose reads are all refused for any other
reason (no read access to the target, say) keeps the plain `no record
matches` sentence." was loose on `main` (review N4) and is exactly true
after this change, so it is not rewritten.
### Small choices made here (dev's call, per the claim)
- One rule id, `object-field-ref-unknown`, not a new one. The roll-up
filter position in the same rule already refuses a key computed on read
under that id, and the rule already runs at error on every door this
needs, so no new registration, explanation entry or door wiring was
added.
- Population: fields computed on read only (`SEARCH_VIRTUAL_TYPES`,
today `formula`), which is what the card names. A `secret` / `password`
field, or one flagged `internal: true`, is also refused as a filter key
for a non-system caller, but by a guard that judges the caller, not the
field's storage; left out (see Acceptance notes).
- N4 covers every all-refused scoped lookup, not only `INVALID_FILTER`:
whatever refused every scoped read, the scope was never asked, so a hit
without it says nothing about the scope.
## Tests
- `packages/lint/src/validate-object-field-refs.test.ts`, in the
`dependsOn` describe: a `param` naming a formula of the referenced
object is refused at `.param` with the field and the reason; a bare name
that is a formula on the referenced side is refused at the entry; a
stored `param`, and a formula on the owning side only, pass; the runtime
publish gate refuses it too
(`objects.crm_invoice.fields.contact.dependsOn[0].param`). The file's
own 200-character cap on every fired verdict still holds.
-
`packages/core/src/utils/import-runner-reference-master-scope.test.ts`:
every scoped read refused `INVALID_FILTER` while the unscoped read would
answer with a record under another project; the cell answers
`reference_not_found`, the plain sentence, no `scope`, and every read of
the target carried the scope (no unscoped probe).
- Ablations (tree `40007bc2`, through `scripts/ablation-replace.mjs`,
each restored to the `HEAD` blob with `git diff HEAD` empty):
- runner: `{ scopeUnanswered: true }` → `{}`: the N4 pin goes red
(`reference_out_of_scope` received), 1 failed / 19 passed; restored 20
passed.
- coerce: the `scopeUnanswered` early return deleted: the same pin red,
1 failed / 19 passed.
- lint: the `filtered` branch disabled: 3 failed / 128 passed (the two
refusals and the runtime-gate pin); restored 131 passed.
## Acceptance notes
- First-party exposure, measured: `objectstack validate` passes on all
five example apps (`app-crm`, `app-showcase`, `app-starter`, `app-todo`,
`app-multi-package`) with the new rule built in. Positive control on the
same CLI: adding a formula `account_label` to `showcase_contact` and
pointing `showcase_invoice.contact`'s `dependsOn` `param` at it exits 1
with the finding quoted above (both mutations restored). By reading,
every other shipped `dependsOn` is clean: the five in `plugin-sharing`
sit on `text` / non-picker fields, where the filter half has no reader
and is not judged; every one in hotcrm (`crm_account`, `crm_project`)
names a `lookup` / `master_detail` field of its target.
- Not judged here, for a later card if anyone wants it: a `dependsOn`
filter key naming a `secret` / `password` field or an `internal: true`
field. Those are refused as filters for non-system callers by the
credential and internal-field guards, a judgment about the caller, not
about the field's storage.
- A stored object that already carries such an entry is not refused at
boot. Its import keeps the could-not-look-up sentence from #37706, and
its next publish is refused.
## Verification
Read first: the `filtered` branch in `validateObjectFieldRefs`
(`validate-object-field-refs.ts`), the all-refused branch at the end of
the resolver's `lookup` (`import-runner.ts`), and the `scopeUnanswered`
return in `referenceNotFound` (`import-coerce.ts`).
Two-minute check: `pnpm --filter @objectstack/lint exec vitest run
src/validate-object-field-refs.test.ts -t "formula"` runs 3 tests, all
green.
<details><summary>Local readings (tree 40007bc, on main
1e721fd)</summary>
- `@objectstack/lint` whole package: 242 files / 9801 passed.
`@objectstack/core` whole package: 166 files / 3902 passed.
- `typecheck` lint, core and spec: green. `eslint --no-inline-config` on
the eight changed source files: 0 problems.
- `objectstack validate`: all five example apps pass; the positive
control exits 1 with the new finding.
- The derived local gate sweep (`dispatch-gates.mjs --commands`, 119
commands, tree 40007bc): 116 exit 0. Three exit 3, prerequisite not
met, NOT measured: `check-plugin-teardown-shape --self-test` (shallow
clone), `spec check:skill-examples` (client-react not built),
`check:dual-build-cjs-loads`; CI covers these families on this head.
`check:type-check-debt` first queued behind the dogfood hold, then
re-run under the lock: exit 0, 0 ledger entries above their number.
- Dogfood battery on 40007bc under `os-verify-lock`: VERDICT
command-exit 0, Test Files 490 passed / 3 skipped (493), Tests 4144
passed / 68 skipped (4212), no failures.
- CI on 40007bc: 60 check-runs success, 10 skipped, none failed.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgXj9vLmZ3KE2rWhtBH
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgXj9vLmZ3KE2rWhtBH)_
<!-- signed: repo:objectstack#2 · os-sales ·
session_01L6bhgXj9vLmZ3KE2rWhtBH -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 39fafc0 commit 709a087
10 files changed
Lines changed: 232 additions & 10 deletions
File tree
- .changeset
- content/docs/data-modeling
- packages
- core/src/utils
- lint/src
- spec/src
- migrations/entries/semantic
- system
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
378 | | - | |
379 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
| |||
191 | 201 | | |
192 | 202 | | |
193 | 203 | | |
194 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
195 | 210 | | |
196 | 211 | | |
197 | 212 | | |
| |||
213 | 228 | | |
214 | 229 | | |
215 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
216 | 234 | | |
217 | 235 | | |
218 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
400 | 425 | | |
401 | 426 | | |
402 | 427 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
1050 | 1054 | | |
1051 | 1055 | | |
1052 | 1056 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4768 | 4768 | | |
4769 | 4769 | | |
4770 | 4770 | | |
4771 | | - | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
| 4775 | + | |
4772 | 4776 | | |
4773 | 4777 | | |
4774 | 4778 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1128 | 1128 | | |
1129 | 1129 | | |
1130 | 1130 | | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
1131 | 1194 | | |
1132 | 1195 | | |
1133 | 1196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
130 | 136 | | |
131 | 137 | | |
132 | 138 | | |
| |||
498 | 504 | | |
499 | 505 | | |
500 | 506 | | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
501 | 516 | | |
502 | 517 | | |
503 | 518 | | |
| |||
601 | 616 | | |
602 | 617 | | |
603 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
604 | 628 | | |
605 | 629 | | |
606 | 630 | | |
| |||
1023 | 1047 | | |
1024 | 1048 | | |
1025 | 1049 | | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
1026 | 1065 | | |
1027 | 1066 | | |
1028 | 1067 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments