Repository navigation
Commit 81eae2b
fix(core): a scoped import lookup miss names the scoping column when the value exists outside the scope (#36735)
Fixes #36159
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:导入数据时,如果某个查找列的值只存在于另一个上级记录下(例如合同属于另一个客户),被拒的那一行提示现在会写明是按哪一列、哪个值限定的,例如「合同:未找到匹配“CTR-0006”的记录(客户
= "Acme")」;真的不存在的值,提示不变。
- 为什么做:替用 CSV 批量导入订单、合同的用户解决;以前这种行只提示“找不到记录”,导入的人去搜却能搜到,误以为系统出错。
- 出错会怎样:只改提示文字,拒绝与否和错误代码都不变;最坏是提示多一段或少一段说明,可以直接撤回本次合并。
- 无。
## What changes
`packages/core/src/utils/import-coerce.ts`. A lookup cell scoped by the
row (the field's `dependsOn` column, or the master the target's
`master_detail` field points at) used to answer every miss with
`import_reference_not_found`: `Contract: no record matches "CTR-0006"`,
also when CTR-0006 exists under another account.
After a scoped miss, `referenceNotFound` asks the same `resolveRef` once
more without the scope. When that finds a record (one or several), the
scope is why nothing matched, and the message adds the scoping columns
and the cells the row gave them:
```
Contract: no record matches "CTR-0006" (Account = "UI Probe X Co")
```
A value that matches nothing at all keeps the plain sentence.
Single-value and multi-value cells use the same path.
Per the seat's routing in the claim (`Ruling-ref:`): the reason stays
`reference_not_found`, the code stays `import_reference_not_found`, no
new enum value, no new catalog key. The extra part is built in core from
the column label, the cell and punctuation only. It reads the same under
every locale the catalog sentence is rendered in, and nothing in
`packages/spec` changes.
The exported signatures do not change. `coerceFieldValue(raw, meta, ctx,
scope)` now calls an internal `coerceCell`, which also takes the scoping
columns (`ScopedBy`, not exported). Only `coerceRow` knows those columns
and passes them. An outside caller of `coerceFieldValue` with a scope
gets the plain sentence, as before.
Mechanism assumptions, measured:
- The probe runs as the importer. `runImport`'s resolver sends every
lookup through `p.findData(findArgsBase(...))`, which carries the
import's own `context`. The probe is the same resolver with no scope, so
it finds only records the importer can already read by the same value,
and the message says nothing about the record it found. A runner test
pins this: rows hidden from the caller produce the plain sentence, and
every read runs with the caller's context.
- `packages/spec/src/system/validation-message.ts` holds
`import_reference_not_found` (line 164). That template is unchanged. The
sentence is composed in core, so this needed no `needs_decision`.
## Tests
The pins go into the existing harness
`import-runner-reference-master-scope.test.ts`, as a new top-level
`describe`, so they use that file's engine-like `findData` fake. This
follows AGENTS.md (ruling record 6583487846: a new pin for a component
that already has a shared harness file goes into that file). The
dispatch had preferred a new file named for the card.
- dependsOn-scoped cell naming another parent's record:
`reference_not_found`, message `task: no record matches "Design review"
(Project = "Gemini")`.
- master-scoped cell naming another master's detail, by name and by
pasted id: same shape, naming `Contract`.
- a value that matches no record anywhere: the plain `no record matches`
sentence, for both scope routes.
- multi-value cell: the out-of-scope token gets the qualified sentence,
and a truly missing token gets the plain one.
- the probe runs as the caller: a record the caller's reads cannot see
stays unnamed, the unscoped probe read did happen, and every read ran
with the caller's context.
<details><summary>Package runs</summary>
Targeted: `pnpm --filter @objectstack/core exec vitest run
--maxWorkers=2 src/utils/import-runner-reference-master-scope.test.ts
src/utils/import-coerce.test.ts` under `os-verify-lock.sh`:
```
Test Files 2 passed (2)
Tests 191 passed (191)
os-verify-lock: VERDICT command-exit 0
```
Full package: `pnpm --filter @objectstack/core typecheck && pnpm
--filter @objectstack/core test` (typecheck includes
`check:test-typecheck` over `tsconfig.test.json`, which compiles the
test files):
```
check:test-typecheck: OK
Test Files 156 passed (156)
Tests 3712 passed (3712)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>One ablation: the probe's verdict ignored</summary>
The test imports `./import-runner` from source (no `dist` in the path),
so no rebuild was needed. Run with `node scripts/ablation-replace.mjs`
after the fix was committed. Anchor `if (unscoped.id === undefined &&
!unscoped.ambiguous) return refusal;` replaced by `return refusal;`.
Anchor count went 1 to 0, blob 55535a7 to c33835840466.
```
× a dependsOn-scoped cell naming another parent's record ...
× a master-scoped cell naming another master's detail, by name or by id ...
× a multi-value cell: the token outside the scope is refused with the same sentence
Test Files 1 failed (1)
Tests 3 failed | 12 passed (15)
ablation-replace: ok restored: blob == HEAD (55535a7) and `git diff HEAD` is empty
```
This is the expected direction. The plain-sentence pin and the
caller-context pin stay green, because the ablation makes every miss
read plain.
</details>
<details><summary>Gates at d1d8b71: 65 derived, 61 exit 0, 4 NOT
MEASURED, 0 red</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 65 families from the merge base
3aa008d. Each one was run in turn, with its exit code recorded before
any pipe. `--ran` verdict: "65 derived famil(ies) accounted for — 61
run, 4 NOT-MEASURED (4 DERIVED from a recorded exit 3)".
NOT MEASURED here, all four exit 3 PREREQUISITE NOT MET; CI's `Lint &
Repo Gates` runs them on a full build:
- `check:dual-build-cjs-loads`: needs every package's `dist` (`pnpm
build`). Only core's closure was built.
- `check:lean-entry-closure`: needs `packages/objectql/dist`, and
objectql's own closure was not built.
- `node scripts/check-plugin-teardown-shape.mjs --self-test`: needs an
unshallowed clone for its pinned fixture commit.
- `check:type-check-debt`: its closure build queued on the shared verify
lock behind a sibling's dogfood run (exit 99, queue-timeout).
`node scripts/pm/overlap-check.mjs --branch=HEAD`: VERDICT clean exit 0
(origin/main merges cleanly, 0 open PR heads share a file).
</details>
## Acceptance notes
- The added part is locale-neutral by design (label, cell, `=`, quotes).
A fully translated sentence, like the card's example `"CTR-0006" belongs
to another Account`, would need a new catalog key in `packages/spec`,
which is published surface. That is outside this dispatch and outside
the seat's routing.
- The probe adds one lookup per scoped miss. A scoped hit costs nothing
extra. An unscoped verdict that is a hit is cached by the resolver, as
before.
- A caller who cannot read the scoping field on the target (the
narrowing that came with the scope) also gets the qualified sentence
when the unscoped lookup finds the record. That is true: the row's scope
is why the cell did not resolve.
## Verification
Two minutes: in the worktree, run `pnpm --filter @objectstack/core exec
vitest run --maxWorkers=2
src/utils/import-runner-reference-master-scope.test.ts`. Expect 15
passed, including the five `[#36159]` cases.
Read first, by risk:
1. `packages/core/src/utils/import-coerce.ts`, `referenceNotFound`: the
probe and the message.
2. `packages/core/src/utils/import-coerce.ts`, `coerceRow`'s scope loop:
where `ScopedBy` is built from the source column's label and raw cell.
3.
`packages/core/src/utils/import-runner-reference-master-scope.test.ts`,
the new `describe`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_011y7As6FyXmJyGyHNKXUkV7)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent cb2d6aa commit 81eae2b
3 files changed
Lines changed: 168 additions & 10 deletions
File tree
- .changeset
- packages/core/src/utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
147 | 189 | | |
148 | 190 | | |
149 | 191 | | |
| |||
760 | 802 | | |
761 | 803 | | |
762 | 804 | | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
763 | 819 | | |
764 | 820 | | |
765 | 821 | | |
| |||
850 | 906 | | |
851 | 907 | | |
852 | 908 | | |
853 | | - | |
854 | | - | |
855 | | - | |
| 909 | + | |
856 | 910 | | |
857 | 911 | | |
858 | 912 | | |
| |||
866 | 920 | | |
867 | 921 | | |
868 | 922 | | |
869 | | - | |
870 | | - | |
871 | | - | |
| 923 | + | |
872 | 924 | | |
873 | 925 | | |
874 | 926 | | |
| |||
1026 | 1078 | | |
1027 | 1079 | | |
1028 | 1080 | | |
| 1081 | + | |
1029 | 1082 | | |
1030 | 1083 | | |
1031 | 1084 | | |
1032 | | - | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
1033 | 1092 | | |
1034 | 1093 | | |
1035 | | - | |
| 1094 | + | |
1036 | 1095 | | |
1037 | 1096 | | |
1038 | 1097 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | | - | |
| 70 | + | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| |||
225 | 230 | | |
226 | 231 | | |
227 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
0 commit comments