Repository navigation
Commit dfe60e3
fix(core): the import resolves a lookup cell by the target object's stored title field (#25033)
Part of #24981
Clause-②: no
The import door now honours the title rule ADR-0079 already declares; no
schema, export or published accept set moves, and nothing narrows.
## What this delivers (the decision-independent half)
The import's lookup resolution (`resolveRef`,
`packages/core/src/utils/import-runner.ts`) now asks the target object's
title field after the id and the lookup's own `displayField`, and before
the fallback keys. The title is resolved by ADR-0079's one rule,
`resolveDisplayField` from `@objectstack/spec/data`. Only a STORED title
is asked.
- `Wren` (target title `displayNameField: 'nickname'`, a stored text
field) now resolves. On `main` it answered `reference_not_found`,
because `nickname` was never asked.
- A formula title (`John Smith` against `nameField: 'full_name'`, `Acme
(EMEA)` against `nameField: 'display_title'`) is not asked by `where`.
The swallowed `INVALID_FIELD` query is gone, and the cell still answers
`reference_not_found`.
- Two records sharing a stored title answer the existing
`reference_ambiguous`. Neither is linked.
- The fallback key list (`name`, `title`, `label`, `full_name`, `email`,
`username`) and its order are unchanged. The exposure check from #22739
still runs first and still withholds a target whose declared exposure
does not serve `list`.
## What is left (with the maintainer)
Q1 on the card asks how a FORMULA title should be matched (options A,
B-cap, C and D in the first dev report and in the seat's analysis).
Nothing is built for it here: no scan, no search door, no new refusal
code. The card's second Wanted bullet ("A formula title is matched by
the engine's own record-title resolution") is not delivered by this PR,
so #24981 remains open after it merges.
## Mechanism (measured in this run)
- **H1 holds.** `servesReferenceTarget` already read the target's
`getMetaItem` item for its `enable` block. It now also returns the title
field (`resolveDisplayField(item)`) and the field map from that same
read. No extra metadata read is made. Pinned: two rows asking one target
cost one `getMetaItem` call.
- **The export reads the same seam.** `withReferenceTitleFields`
(`packages/rest/src/export-format.ts`) resolves a lookup cell's title
with `resolveDisplayField` over the `getMetaItem` item
(`readObjectSchema` in `packages/rest/src/data-action-routes.ts`). So
the import asks the field the export wrote the cell from.
- **H2 holds.** "Stored" is decided by `isVirtualSearchField`
(`@objectstack/spec/data`, over `SEARCH_VIRTUAL_TYPES`, which holds
`formula`). It is the same predicate the engine's filter seam
`assertFilterIsMaterializable`
(`packages/objectql/src/filter-comparand-shape.ts`) uses to refuse a
`where`, so there is no second list. `packages/core` cannot import
objectql, because objectql depends on core. The spec-level predicate the
engine itself reads is the one reused.
- **The skip covers every candidate the target declares as a formula,
not only the title rung.** The formula pin needs this: the card's
formula title `full_name` is also on the fallback list, so skipping only
the rung would still send `where full_name`. The skip changes no
verdict. The engine refuses every `where` over a formula at that seam,
which its own comment calls "the one place EVERY caller-supplied `where`
passes through". The resolver's `catch` read that refusal as "field
absent" and moved on.
## Pins
(`packages/core/src/utils/import-runner-reference-title.test.ts`)
The fake `findData` answers like the engine: equality over the stored
row, and a recorded `INVALID_FIELD` / 400 refusal for a `where` over a
formula field.
1. `Wren` resolves through a stored `displayNameField: 'nickname'`, and
through `nameField: 'nickname'` (the alias as the registry normalizes
it). The asked keys are `id`, then the lookup's `displayField`
(`first_name`), then `nickname`.
2. A real (non-dry) run stores the matched id. `getMetaItem` is called
once for two rows.
3. `John Smith` (formula `full_name`) and `Acme (EMEA)` (formula
`display_title`) answer `reference_not_found`. The find calls never name
the formula field. The asked keys are exactly `id` plus the fallback
list minus the formula member, and no refusal was produced.
4. Two records sharing a stored title answer `code:
'reference_ambiguous'`.
5. For #22739: a target with `enable: { apiEnabled: false }` and a
stored title answers `reference_not_found` for a match and for a miss.
`findData` is never called, and `getMetaItem` is called once.
## Ablations
The fix was committed first. Both mutations went through
`scripts/ablation-replace.mjs`: the anchor hit 1 and fell to 0, and the
blob moved. Each restore is proven by blob hash equal to HEAD and an
empty `git diff HEAD`. The subject is imported by relative path from
`src/`, so no `dist/` leg applies.
- **Rung removed** (the line `...(target.titleField ?
[target.titleField] : []),` deleted): 4 failed, 3 passed. Both Wren pins
went red with `reference_not_found` for `person`. The stored-id pin went
red. The ambiguity pin went red with `reference_not_found` in place of
`reference_ambiguous`. Restored: blob `d9b249d961d4` equals HEAD.
- **Virtual filter removed** (the `isVirtualSearchField` filter on the
candidate list dropped): 2 failed, 5 passed. Both formula pins went red:
"expected [ 'id', 'full_name', ... ] to not include 'full_name'", and
the same for `display_title`. Restored: blob `d9b249d961d4` equals HEAD.
## Tests and gates (final head `9a67cf4ce`)
- `pnpm --filter @objectstack/core typecheck`: exit 0. The test layer
compiles under `tsconfig.test.json` (the new file is in that program),
with 4 of 4 pinned signatures held.
- `pnpm --filter @objectstack/core exec vitest run --project local
--maxWorkers=2`: 109 files, 2630 tests passed.
- The `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derivation gave 68 commands. All 68 were run
at `9a67cf4ce`, and every one exited 0. `--ran` reconciliation: "68
derived famil(ies) accounted for — 68 run, 0 NOT-MEASURED (a DERIVED
zero — all 68 recorded an exit code and none of them is 3)".
- An earlier battery at `745620fac` went red on
`check:error-code-casing`. The new test spelled a field-addressed code
with a shorthand `field` key, which the gate does not read as
field-addressed. `9a67cf4ce` spells `field: column`.
- `eslint --no-inline-config` over the two touched source files: exit 0.
The repo-wide `pnpm lint` is CI's.
## Acceptance notes
- **Takeover.** This PR continues an interrupted dev run. The inherited
uncommitted change to `import-runner.ts` (+63/-16) was read hunk by hunk
and kept unchanged as the first commit. Every claim above was measured
again in this run.
- **The refusal wording.** For a formula-titled target, the
`reference_not_found` text does not say why the cell cannot match. The
first dev measured `Contact: no record matches "John Smith"`. No wording
changes here. Whether the refusal should name the formula title belongs
with Q1's answer; the seat's analysis lists it as a confidence gap.
- **Carried from the first dev report, not filed.** When the declared
title misses, the fallback key list can still link a cell by an
unrelated column (`VP of Engineering` links a contact by its job
`title`). This PR leaves that unchanged, by ruling.
- **Carried, not filed.** `resolveRef`'s `catch` reads every `findData`
throw as "field absent". Only the `INVALID_FIELD` path is measured.
- **Declared to CI, not run locally.** Some consumer suites drive
`runImport` through `@objectstack/core`:
`packages/rest/src/import-integration.test.ts`,
`packages/plugins/plugin-auth/src/admin-import-users.test.ts` and the
dogfood import-reference pins. No export, type or wire shape of
`@objectstack/core` changed, so CI's Test Core carries them.
- **Base.** `origin/main` was merged at `73432299c` before this PR
opened. Two later commits on `main` touch neither `packages/core` nor
`packages/spec`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QK6pdbxKZiHdFApL8RYVh9)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d68aab6 commit dfe60e3
3 files changed
Lines changed: 237 additions & 16 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 | + | |
| 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 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
210 | 213 | | |
211 | 214 | | |
212 | 215 | | |
213 | | - | |
| 216 | + | |
| 217 | + | |
214 | 218 | | |
215 | 219 | | |
216 | 220 | | |
| |||
593 | 597 | | |
594 | 598 | | |
595 | 599 | | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
596 | 604 | | |
597 | | - | |
598 | | - | |
599 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
600 | 608 | | |
601 | | - | |
602 | | - | |
| 609 | + | |
| 610 | + | |
603 | 611 | | |
604 | | - | |
| 612 | + | |
605 | 613 | | |
606 | | - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
607 | 644 | | |
608 | 645 | | |
609 | 646 | | |
| |||
678 | 715 | | |
679 | 716 | | |
680 | 717 | | |
681 | | - | |
| 718 | + | |
682 | 719 | | |
683 | 720 | | |
684 | 721 | | |
685 | | - | |
| 722 | + | |
| 723 | + | |
686 | 724 | | |
687 | 725 | | |
688 | 726 | | |
689 | 727 | | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
694 | 740 | | |
695 | 741 | | |
696 | 742 | | |
| 743 | + | |
697 | 744 | | |
698 | | - | |
| 745 | + | |
699 | 746 | | |
700 | 747 | | |
701 | 748 | | |
| |||
0 commit comments