Repository navigation
fix(core): a scoped import lookup miss names the scoping column when the value exists outside the scope - #36735
Conversation
…the value exists outside the scope Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011y7As6FyXmJyGyHNKXUkV7
…ding Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011y7As6FyXmJyGyHNKXUkV7
📓 Docs Drift CheckThis PR changes 1 package(s): 5 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 2 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 41 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 845b4dbde355091fbecff6cc1cd91033d7d1cf80 && git checkout 845b4dbde355091fbecff6cc1cd91033d7d1cf80
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 0d727b70716ccf77fd63d0a0a2f0b17f7ab4d28a 3395e9a76f09c1c248995cf0faba50e7e4ae34dd && git checkout -B drift-repro 0d727b70716ccf77fd63d0a0a2f0b17f7ab4d28a && git merge --no-ff 3395e9a76f09c1c248995cf0faba50e7e4ae34dd
node scripts/docs-audit/affected-docs.mjs --json 0d727b70716ccf77fd63d0a0a2f0b17f7ab4d28a
|
|
repo:objectstack#7 · os-alice · session_011y7As6YDLR8TJVDpdXzJyV 维护者速读
席位核对Verdict: ACCEPT · head Reviewed against GitHub at this head (diff, card body, Checklist
|
|
repo:objectstack#7 · os-alice · session_011y7As6FyXmJyGyHNKXUkV7 Landing · 2026-11-23T19:49Z · head The head moved only by a merge of
State change: ready for review, auto-merge armed. On MERGED, |
… another parent answers reference_out_of_scope (objectstack-ai#37567) <!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuDqyPrPQvkURDXnUDgkyFWB)_ Part of objectstack-ai#36794 (PR-1 of 2: the spec reason and the importer; the Import Wizard text follows in PR-2 on the same branch once this one lands) Clause-②: yes (widening) Metadata-protocol: added (`ValidateDataIssueSchema.scope`, a new optional key on the import cell error; the new `FieldErrorCode` value is a wire code, no author-writable key) Skills-docs: follow-up objectstack-ai#37590 ## 维护者速读 - 导入时,查找列填了一个只在别的父记录下存在的记录(例如合同属于另一个客户),服务端现在单独报“不在本行的范围内”,并把限定它的列和单元格作为数据返回;真正不存在的值照旧报“找不到记录”。 - 这是导入查找报错专题的后半段:上一张已让报错文字带上限定列,这张让依赖错误码的界面(导入向导)也能分清两种情况。 - 只影响导入失败行的错误码和多出的一个可选字段,成功导入不受影响;按旧错误码筛“找不到”的客户端,在这种情况下会收到新码,可整张撤回。 - 无。 ## What changes - **`FieldErrorCode` gains `reference_out_of_scope`** (`packages/spec/src/api/errors.zod.ts`, ADR-0114 D2 closed catalog), beside `reference_not_found`. Ruled route A on the card. - **Catalog sentence `import_reference_out_of_scope`** in all four platform locales (`packages/spec/src/system/validation-message.ts`). The English text is byte-identical to the sentence the scoped refusal already shipped with (`Contract: no record matches "CTR-0006" (Account = "Acme")`), now with `{{scope}}` as a parameter, so a deployment can override it under `validation.field.import_reference_out_of_scope` and the other three locales say it in their own word order. - **`ValidateDataIssueSchema` gains an optional `scope: [{ field, value }]`** (`packages/spec/src/api/protocol.zod.ts`), present only on an import cell error whose code is `reference_out_of_scope`. This is the thread's route decision, agreed by the seat at claim time: the card asks the Wizard to name the scoping column and its cell while keying on the code and never parsing server prose, and the row result carried no structured column at all. Same `{ field, value }` naming the importer already uses for the columns; additive, optional, Clause-② widening. The contract review below judges it. - **Core importer** (`packages/core/src/utils/import-coerce.ts`, `import-runner.ts`): the objectstack-ai#36735 unscoped probe now answers the new reason with the new message key and the `scope` entries; the runner copies `scope` onto the row's `errors` element. A value nobody has keeps `reference_not_found`. - **A scoped read the field-predicate guard refused is never probed** (`RefMatch.scopeDenied`, `isScopeFieldDenial`). A caller who cannot read the scope field (a hidden `master_detail` field, or the `param` a `dependsOn` entry names) has the scoped lookup refused, so its miss says nothing about where the value lives. Before this PR the probe still ran and the objectstack-ai#36735 sentence named the scope; with a code that now claims "under another parent", that answer would be wrong for a record sitting under the row's own parent. It keeps `reference_not_found` and the plain sentence, which is what `content/docs/data-modeling/import-mappings.mdx` already says for that caller. The guard is read off the error's declared `details.reason === 'field_predicate_denied'` (the reason all four field-predicate guards answer) naming a scope field, never its message. - `packages/runtime/src/dispatcher-error-vocabulary.ts`: the new code's `foreign-vocabulary` row (ADR-0112 D6), same wording as its three siblings. - Docs: `content/docs/api/error-catalog.mdx` field-code table and `content/docs/data-modeling/import-mappings.mdx` scoped-lookup section. Regenerated: `content/docs/references/api/{errors,export,protocol}.mdx`, `packages/spec/authorable-surface/api.json` (`api/ValidateDataIssue:scope`), the strictness-ledger count for `api/` (537 → 538, the new nested object). - Changeset: `@objectstack/spec` minor, `@objectstack/core` and `@objectstack/runtime` patch. `Metadata-protocol: added`, not the claim's `none`: `Check Changeset` reads the new `api/ValidateDataIssue:scope` row in `packages/spec/authorable-surface/api.json` as a key entered, and a kind other than `none` grades the package that carries it at least `minor`. ## Tests - `packages/core/src/utils/import-runner-reference-master-scope.test.ts`: the objectstack-ai#36159 describe now pins `reference_out_of_scope` for a `dependsOn` scope and a master scope, by name and by pasted id, single and multi-value, with `errors[0].scope` as data; a value nobody has keeps `reference_not_found` with no `scope` key; the two objectstack-ai#33523 pins whose value lives under another master move to the new code; a new pin: a scope the field guard refuses answers `reference_not_found` and no unscoped probe runs. - `packages/rest/src/import-integration.test.ts`: a new top-level describe drives the real `POST /data/:object/import` route on a real engine and sqlite with a real `dependsOn` declaration: one row resolves, one answers `reference_out_of_scope` with `scope: [{ field: 'project', value: 'Gemini' }]`, one answers `reference_not_found` with no `scope`. - `packages/spec/src/system/validation-message.test.ts`: every locale interpolates `{{value}}` and `{{scope}}`; the English render is the shipped sentence; the zh-CN render. - Ablation: with `if (scopedMatch.scopeDenied) return refusal;` commented out, the guard pin goes red (1 failed / 15 passed), restored green. <details><summary>Local readings (tree f4a201e + 2e8b0b9)</summary> - `pnpm --filter @objectstack/spec test`: Test Files 900 passed (900), Tests 28505 passed, 1 todo. - `vitest run src/utils/import-runner-reference-master-scope.test.ts` (core): 16 passed. `src/utils/import-coerce.test.ts`: passed. - `vitest run src/import-integration.test.ts` (rest): 62 passed. - `pnpm --filter @objectstack/spec check:generated`: 2 stale before `--fix` (references docs, strictness ledger), both green after. - `typecheck` spec, core, runtime: green; rest: one TS18048 in the new pin, fixed in 2e8b0b9, `check:test-typecheck` OK. - `node scripts/check-dispatcher-error-vocabulary.mjs`: exit 0. - `node scripts/pm/overlap-check.mjs`: VERDICT clean exit 0 (main, objectstack-ai#37422, objectstack-ai#37371). - The `dispatch-gates.mjs --commands` derived list (118 commands) is running; its reading goes on the PR when done. </details> ## Acceptance notes - **Narrowing question left to the contract review, as the card asks:** a client matching `reason === 'reference_not_found'` to mean "the lookup cell did not resolve" stops seeing the out-of-scope case under that value. The schema only widens (a new enum member, a new optional key), so this PR declares `Clause-②: yes (widening)`; whether the move of that case is itself a narrowing for such a client is the L2's call. - **Skill text made false, not fixed here (`Skills-docs: follow-up owed`):** `skills/objectstack-data/rules/relationships.md:117` says another master's detail answers `reference_not_found`. `skills/**` is governed, and this PR's `Clause-②: yes` keeps it off the low-risk arm, so the line here would make the whole PR Tier H; its follow-up card is objectstack-ai#37590. - Between this PR and PR-2 the Import Wizard meets a code it has no `case` for, so `formatDryRunError` falls through to the server's own sentence (already in the caller's locale, naming the scope) on both the dry-run panel and the completion screen. PR-2 gives the code its own Wizard key built from `scope`. ## Verification Read first: `packages/core/src/utils/import-coerce.ts` `referenceNotFound` (the new reason and the guard), `packages/core/src/utils/import-runner.ts` the resolver's `catch` (`isScopeFieldDenial`), `packages/spec/src/api/protocol.zod.ts` `ValidateDataIssueSchema.scope`. Two-minute check: `pnpm --filter @objectstack/rest exec vitest run src/import-integration.test.ts -t "under another parent"` — one test, green; row 2 answers `reference_out_of_scope` with its `scope`. --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgWgMUXf5juNBhN6rLX)_ <!-- signed: repo:objectstack#2 · os-sales · session_01L6bhgWgMUXf5juNBhN6rLX --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Fixes #36159
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
packages/core/src/utils/import-coerce.ts. A lookup cell scoped by the row (the field'sdependsOncolumn, or the master the target'smaster_detailfield points at) used to answer every miss withimport_reference_not_found:Contract: no record matches "CTR-0006", also when CTR-0006 exists under another account.After a scoped miss,
referenceNotFoundasks the sameresolveRefonce 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: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 staysreference_not_found, the code staysimport_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 inpackages/specchanges.The exported signatures do not change.
coerceFieldValue(raw, meta, ctx, scope)now calls an internalcoerceCell, which also takes the scoping columns (ScopedBy, not exported). OnlycoerceRowknows those columns and passes them. An outside caller ofcoerceFieldValuewith a scope gets the plain sentence, as before.Mechanism assumptions, measured:
runImport's resolver sends every lookup throughp.findData(findArgsBase(...)), which carries the import's owncontext. 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.tsholdsimport_reference_not_found(line 164). That template is unchanged. The sentence is composed in core, so this needed noneeds_decision.Tests
The pins go into the existing harness
import-runner-reference-master-scope.test.ts, as a new top-leveldescribe, so they use that file's engine-likefindDatafake. 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.reference_not_found, messagetask: no record matches "Design review" (Project = "Gemini").Contract.no record matchessentence, for both scope routes.Package runs
Targeted:
pnpm --filter @objectstack/core exec vitest run --maxWorkers=2 src/utils/import-runner-reference-master-scope.test.ts src/utils/import-coerce.test.tsunderos-verify-lock.sh:Full package:
pnpm --filter @objectstack/core typecheck && pnpm --filter @objectstack/core test(typecheck includescheck:test-typecheckovertsconfig.test.json, which compiles the test files):One ablation: the probe's verdict ignored
The test imports
./import-runnerfrom source (nodistin the path), so no rebuild was needed. Run withnode scripts/ablation-replace.mjsafter the fix was committed. Anchorif (unscoped.id === undefined && !unscoped.ambiguous) return refusal;replaced byreturn refusal;. Anchor count went 1 to 0, blob 55535a7675d7 to c33835840466.This is the expected direction. The plain-sentence pin and the caller-context pin stay green, because the ablation makes every miss read plain.
Gates at d1d8b71: 65 derived, 61 exit 0, 4 NOT MEASURED, 0 red
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 65 families from the merge base 3aa008d. Each one was run in turn, with its exit code recorded before any pipe.--ranverdict: "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 Gatesruns them on a full build:check:dual-build-cjs-loads: needs every package'sdist(pnpm build). Only core's closure was built.check:lean-entry-closure: needspackages/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).Acceptance notes
=, quotes). A fully translated sentence, like the card's example"CTR-0006" belongs to another Account, would need a new catalog key inpackages/spec, which is published surface. That is outside this dispatch and outside the seat's routing.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:
packages/core/src/utils/import-coerce.ts,referenceNotFound: the probe and the message.packages/core/src/utils/import-coerce.ts,coerceRow's scope loop: whereScopedByis built from the source column's label and raw cell.packages/core/src/utils/import-runner-reference-master-scope.test.ts, the newdescribe.Generated by Claude Code