Skip to content

Commit 2cf35d4

Browse files
claude[bot]claudeos-zhuang
authored
test(driver-mongodb): correct the last reference_to fixture and pin the divergence it was hiding (#13224)
`mongodb-driver.test.ts` declared its lookup as `reference_to: 'company'`, a key `FieldSchema` refuses (`unrecognized_keys`), so it described an object no author could publish. It was also the only thing in the tree reaching `mongodb-schema.ts`'s lookup arm, which gates on `field.reference_to` and reads no other relationship key. Correcting the spelling therefore does not leave the outcome alone: measured differentially against the real `syncCollectionSchema`, `idx_company_id_lookup` is the one index that disappears, while a `type: 'user'` field still gets its own — so the gate is live, not dead code. The assertion is inverted in place with a comment recording what was measured, what falsified the old fact, and that #13222 owns the disposition. It records what the driver DOES, not what it should do. The published README taught the same refused spelling and promised the same index; it now shows `reference`, lists only the indexes an authored object actually gets, and names #13222. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: os-zhuang <jack@objectstack.ai>
1 parent 8b236c8 commit 2cf35d4

3 files changed

Lines changed: 67 additions & 8 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
"@objectstack/driver-mongodb": patch
3+
---
4+
5+
docs(driver-mongodb): stop teaching the spec-refused `reference_to` in the published README, and stop promising a lookup index the driver does not build (#12252 / #13223)
6+
7+
The schema-sync example in this package's README — which ships to npm — declared
8+
its lookup as `company_id: { type: 'lookup', reference_to: 'company' }` and
9+
closed with `// Creates: … idx_company_id_lookup`. Both halves were wrong, in
10+
opposite directions:
11+
12+
- `reference` is the only relationship spelling `@objectstack/spec` declares.
13+
`reference_to` is a **rejected alias**, answered by `FieldSchema` with
14+
`unrecognized_keys` and *"Did you mean `reference_to``reference`?"* — so
15+
the sample instructed authors to write a key the platform refuses, in the one
16+
place a reader is most likely to copy verbatim.
17+
- The `// Creates:` line promised an index that a *correctly* spelled lookup
18+
does not get. `syncCollectionSchema`'s lookup arm gates on
19+
`field.reference_to`, so it cannot fire for a spec-conformant lookup. Fixing
20+
only the spelling would have left the sample promising an outcome the driver
21+
had just stopped producing.
22+
23+
The sample now uses `reference`, lists only the three indexes an authored object
24+
actually gets, and the surrounding prose no longer claims lookup fields index
25+
themselves — it names the defect and points at #13222, which owns the fix.
26+
27+
**No runtime behaviour changes here.** Whether the lookup arm learns to read
28+
`reference` — which would index 57 relationship fields across the 44 exported
29+
platform objects that get no join index today — is #13222's decision, not this
30+
change's.

packages/drivers/driver-mongodb/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,26 @@ try {
158158

159159
Schema sync creates collections and indexes:
160160

161-
Field-level `unique` and lookup fields index themselves; everything else is
162-
declared in the object's `indexes[]` — the one surface an index is declared on
163-
(a field-level `indexed` flag is not a `FieldSchema` key and never built an
164-
index, #2377 / #6810).
161+
Field-level `unique` fields index themselves; everything else is declared in the
162+
object's `indexes[]` — the one surface an index is declared on (a field-level
163+
`indexed` flag is not a `FieldSchema` key and never built an index,
164+
#2377 / #6810).
165+
166+
⚠️ Lookup fields are **not** indexed today. The lookup arm gates on
167+
`reference_to`, a spelling `FieldSchema` refuses, so a canonically-spelled
168+
`reference` lookup gets no join index — see #13222, which owns that fix.
165169

166170
```typescript
167171
await driver.syncSchema('account', {
168172
name: 'account',
169173
fields: {
170174
name: { type: 'string', unique: true },
171175
email: { type: 'email' },
172-
company_id: { type: 'lookup', reference_to: 'company' },
176+
company_id: { type: 'lookup', reference: 'company' },
173177
},
174178
indexes: [{ fields: ['email'] }],
175179
});
176-
// Creates: idx_id_unique, idx_name_unique, idx_email, idx_company_id_lookup
180+
// Creates: idx_id_unique, idx_name_unique, idx_email
177181
```
178182

179183
### Aggregation

packages/drivers/driver-mongodb/src/mongodb-driver.test.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe.skipIf(!sharedMongod)('MongoDBDriver', () => {
344344
fields: {
345345
name: { type: 'string', unique: true },
346346
email: { type: 'email' },
347-
company_id: { type: 'lookup', reference_to: 'company' },
347+
company_id: { type: 'lookup', reference: 'company' },
348348
},
349349
// [#6810] `email` used to carry a field-level `indexed: true` here. That
350350
// was never a `FieldSchema` key (#2377 / ADR-0049); the index is
@@ -361,7 +361,32 @@ describe.skipIf(!sharedMongod)('MongoDBDriver', () => {
361361
expect(indexNames).toContain('idx_id_unique');
362362
expect(indexNames).toContain('idx_name_unique');
363363
expect(indexNames).toContain('idx_email');
364-
expect(indexNames).toContain('idx_company_id_lookup');
364+
/**
365+
* ⚠️ [#12252] DIVERGENCE PINNED, DISPOSITION OPEN (#13222) — a
366+
* canonically-spelled lookup gets NO join index here.
367+
*
368+
* This fixture used to spell the field `reference_to: 'company'` and
369+
* assert `idx_company_id_lookup` was CREATED. `reference_to` is a key
370+
* `FieldSchema` REFUSES (`unrecognized_keys`), so the object it described
371+
* was one no author could publish — and the assertion passed only because
372+
* this fixture was the sole thing in the tree reaching the lookup arm of
373+
* `mongodb-schema.ts`, which gates on `field.reference_to` and reads no
374+
* other relationship key.
375+
*
376+
* So correcting the spelling does not leave the outcome alone. Measured
377+
* differentially against the real `syncCollectionSchema`,
378+
* `idx_company_id_lookup` is the ONE index that disappears; a
379+
* `type: 'user'` field still gets its index, so the gate is live rather
380+
* than dead code. The consequence in production is that EVERY authored
381+
* lookup on MongoDB is unindexed — 57/57 relationship fields across the
382+
* 44 exported platform objects (#13222).
383+
*
384+
* ⛔ This records what the driver DOES, not what it SHOULD do. Whether
385+
* the lookup arm learns to read `reference` is #13222's to settle, ⛔ not
386+
* this pin's — when it lands, this line flips back to `toContain`
387+
* deliberately rather than the divergence reopening in silence.
388+
*/
389+
expect(indexNames).not.toContain('idx_company_id_lookup');
365390
});
366391

367392
it('should be idempotent (safe to call multiple times)', async () => {

0 commit comments

Comments
 (0)