|
80 | 80 | // is this gate's whole value (see the baseline's `$comment`: shrink-only, hand |
81 | 81 | // reviewed). |
82 | 82 | // |
| 83 | +// A fourth shape sits one layer BELOW the driver (#29859): MongoDB's native |
| 84 | +// `Collection`, faked by driver-mongodb tests to record what the driver sends. |
| 85 | +// `findOne(filter, options)` takes no object name, and `find`/`insertMany` |
| 86 | +// read as engine siblings, so it is vetoed by NATIVE_COLLECTION_ONLY_MEMBERS |
| 87 | +// under the same object-name guard -- out of scan scope, for the same reason. |
| 88 | +// |
83 | 89 | // Deliberately NOT covered, and why (each wants its own slice, not a vaguer |
84 | 90 | // version of these -- a gate whose scope is fuzzy is indistinguishable from |
85 | 91 | // no gate to everyone downstream of it): |
@@ -506,6 +512,39 @@ const ENGINE_ONLY_MEMBERS = new Set(['insert', 'insertMany', 'aggregate', 'getSc |
506 | 512 | */ |
507 | 513 | const REPOSITORY_ONLY_MEMBERS = new Set(['updateById', 'deleteById']); |
508 | 514 |
|
| 515 | +/** |
| 516 | + * The fourth shape (#29859): MongoDB's native `Collection`, which a driver- |
| 517 | + * mongodb test fakes to record what the DRIVER sends (`(driver as any).db = |
| 518 | + * { collection: () => collection }`). Its read and batch-write names collide |
| 519 | + * with the engine's -- `find`, `findOne`, `insertMany`, `aggregate` -- so a |
| 520 | + * fake declaring `insertOne`/`insertMany`/`updateOne`/`findOne`/`find` holds |
| 521 | + * two engine siblings and reads as an engine `findOne` double whose |
| 522 | + * `findOne(filter, options)` takes no object name at all. It is not a looser |
| 523 | + * copy of `ObjectQL.findOne`; it is the driver's DEPENDENCY, one layer below |
| 524 | + * the driver, and has no dispatch contract to be looser than. |
| 525 | + * |
| 526 | + * `insertMany` stays engine evidence: `ObjectQL.insertMany(object, rows)` is a |
| 527 | + * real member of the engine class, and an engine double spelling it must keep |
| 528 | + * reading as one. The fix is positive evidence of the OTHER shape, not less |
| 529 | + * evidence of this one. |
| 530 | + * |
| 531 | + * Verified member by member on the tree this landed against: none of these |
| 532 | + * names is declared in `packages/objectql/src/engine.ts`, nor on `IDataEngine`, |
| 533 | + * `IDataDriver` or `IScopedObjectRepository` (`packages/spec/src/contracts/`). |
| 534 | + * Kept to the names only the native Collection speaks -- its single-document |
| 535 | + * writes, its atomic find-and-modify forms, its counts and `bulkWrite`. Its |
| 536 | + * `updateMany`/`deleteMany` are absent because DRIVER_ONLY_MEMBERS already |
| 537 | + * vetoes them at any arity; `distinct`/`createIndex`/`watch` are absent because |
| 538 | + * those names are too generic to answer "Mongo" in a repo with caches and |
| 539 | + * routers. Consulted under the same object-name guard as the repository veto, |
| 540 | + * so `findOne(objectName, query)` beside an `insertOne` helper stays in scope. |
| 541 | + */ |
| 542 | +const NATIVE_COLLECTION_ONLY_MEMBERS = new Set([ |
| 543 | + 'insertOne', 'updateOne', 'deleteOne', 'replaceOne', 'bulkWrite', |
| 544 | + 'countDocuments', 'estimatedDocumentCount', |
| 545 | + 'findOneAndUpdate', 'findOneAndDelete', 'findOneAndReplace', |
| 546 | +]); |
| 547 | + |
509 | 548 | /** |
510 | 549 | * Parameter names that mean "this position holds an OBJECT NAME" — the |
511 | 550 | * complement of ID_PARAM, and the first position rather than the second. |
@@ -1016,6 +1055,16 @@ function isEngineVerbShape(fn, memberNames = new Set(), opts = {}) { |
1016 | 1055 | if (!opts.skipRepositoryVeto && !takesObjectNameFirst(fn)) { |
1017 | 1056 | for (const n of memberNames) if (REPOSITORY_ONLY_MEMBERS.has(n)) return false; |
1018 | 1057 | } |
| 1058 | + // The NATIVE COLLECTION veto (#29859): the same two halves for the same |
| 1059 | + // reasons. The member is the evidence (a name only Mongo's `Collection` |
| 1060 | + // speaks); the object-name test keeps an engine double that hangs an |
| 1061 | + // `insertOne` helper off its side in scope. It must decide here, before the |
| 1062 | + // arity paths below: `findOne(filter, options)` has a second parameter that is |
| 1063 | + // neither an id nor a string, so the two-parameter path would admit it on its |
| 1064 | + // own, and the short-arity path reads `insertMany` as engine evidence. |
| 1065 | + if (!opts.skipCollectionVeto && !takesObjectNameFirst(fn)) { |
| 1066 | + for (const n of memberNames) if (NATIVE_COLLECTION_ONLY_MEMBERS.has(n)) return false; |
| 1067 | + } |
1019 | 1068 | if (params.length < 2) { |
1020 | 1069 | let engineEvidence = false; |
1021 | 1070 | for (const n of memberNames) { |
@@ -1651,23 +1700,30 @@ function censusRecognizer() { |
1651 | 1700 | // off and diff. The prose used to assert "the pair moves exactly 2, and 0 of |
1652 | 1701 | // the PINNED doubles" as a constant; this recomputes it on today's corpus, |
1653 | 1702 | // which is the only form of that claim worth having. |
1654 | | - const vetoed = []; |
1655 | | - for (const slice of SLICES) { |
1656 | | - for (const abs of files) { |
1657 | | - const rel = relative(ROOT, abs).split(sep).join('/'); |
1658 | | - const text = readFileSync(abs, 'utf8'); |
1659 | | - if (!mentionsVerb(text, slice.verb)) continue; |
1660 | | - const withVeto = scanSource(abs, text, slice); |
1661 | | - const without = scanSource(abs, text, slice, { skipRepositoryVeto: true }); |
1662 | | - if (without.length === withVeto.length) continue; |
1663 | | - const kept = new Set(withVeto.map((d) => d.line)); |
1664 | | - for (const d of without) { |
1665 | | - if (!kept.has(d.line)) vetoed.push({ verb: slice.verb, file: rel, line: d.line, pinned: d.pinned }); |
| 1703 | + // The NATIVE_COLLECTION_ONLY_MEMBERS veto (#29859) is ablated the same way, |
| 1704 | + // separately, so each veto's reach is its own reading. |
| 1705 | + const ablate = (skip) => { |
| 1706 | + const moved = []; |
| 1707 | + for (const slice of SLICES) { |
| 1708 | + for (const abs of files) { |
| 1709 | + const rel = relative(ROOT, abs).split(sep).join('/'); |
| 1710 | + const text = readFileSync(abs, 'utf8'); |
| 1711 | + if (!mentionsVerb(text, slice.verb)) continue; |
| 1712 | + const withVeto = scanSource(abs, text, slice); |
| 1713 | + const without = scanSource(abs, text, slice, { [skip]: true }); |
| 1714 | + if (without.length === withVeto.length) continue; |
| 1715 | + const kept = new Set(withVeto.map((d) => d.line)); |
| 1716 | + for (const d of without) { |
| 1717 | + if (!kept.has(d.line)) moved.push({ verb: slice.verb, file: rel, line: d.line, pinned: d.pinned }); |
| 1718 | + } |
1666 | 1719 | } |
1667 | 1720 | } |
1668 | | - } |
| 1721 | + return moved; |
| 1722 | + }; |
| 1723 | + const vetoed = ablate('skipRepositoryVeto'); |
| 1724 | + const collectionVetoed = ablate('skipCollectionVeto'); |
1669 | 1725 |
|
1670 | | - return { files: files.length, members, byKind, byCallee, notWidened, assignSites, vetoed }; |
| 1726 | + return { files: files.length, members, byKind, byCallee, notWidened, assignSites, vetoed, collectionVetoed }; |
1671 | 1727 | } |
1672 | 1728 |
|
1673 | 1729 | function censusReport() { |
@@ -1716,6 +1772,11 @@ function censusReport() { |
1716 | 1772 | + `${c.vetoed.filter((v) => v.pinned).length} of them pinned:`, |
1717 | 1773 | ); |
1718 | 1774 | for (const v of c.vetoed) console.log(` [${v.verb}] ${v.file}:${v.line}${v.pinned ? ' (pinned)' : ''}`); |
| 1775 | + console.log( |
| 1776 | + `\n NATIVE_COLLECTION_ONLY_MEMBERS veto moves ${c.collectionVetoed.length} construct(s); ` |
| 1777 | + + `${c.collectionVetoed.filter((v) => v.pinned).length} of them pinned:`, |
| 1778 | + ); |
| 1779 | + for (const v of c.collectionVetoed) console.log(` [${v.verb}] ${v.file}:${v.line}${v.pinned ? ' (pinned)' : ''}`); |
1719 | 1780 | console.log(''); |
1720 | 1781 | } |
1721 | 1782 |
|
@@ -3696,6 +3757,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ |
3696 | 3757 | 'Arity: a fake omits the parameters it ignores (#5629).': 9, |
3697 | 3758 | 'The `update` slice (#5480).': 15, |
3698 | 3759 | 'The SCOPED REPOSITORY, the third shape (#6327, from #5945).': 11, |
| 3760 | + 'The NATIVE COLLECTION, the fourth shape (#29859).': 7, |
3699 | 3761 | 'The CONSUMER SEAMS (#8194)': 20, |
3700 | 3762 | 'The ratchet-remedy authority convention (#8435)': 2, |
3701 | 3763 | 'The INHERITANCE clause (#8553)': 5, |
@@ -3726,7 +3788,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ |
3726 | 3788 |
|
3727 | 3789 | // DELETING an entry silences that battery's floor exactly as effectively as |
3728 | 3790 | // zeroing it, so the roster's own size is pinned too. |
3729 | | -const SELF_TEST_BATTERY_FLOOR = 34; |
| 3791 | +const SELF_TEST_BATTERY_FLOOR = 35; |
3730 | 3792 |
|
3731 | 3793 | // The key an assertion is filed under when no battery is open. It is not a |
3732 | 3794 | // declared battery, so it reds by the same set difference rather than silently |
@@ -4306,6 +4368,75 @@ const engine = { |
4306 | 4368 | .some((f) => f.file === 'packages/plugins/plugin-sharing/src/sharing-rule.test.ts'), |
4307 | 4369 | ); |
4308 | 4370 |
|
| 4371 | + // ── The NATIVE COLLECTION, the fourth shape (#29859) ────────────────────── |
| 4372 | + // |
| 4373 | + // A/B pairs again, for the same reason as the repository battery: every |
| 4374 | + // "out of scope" below is the SAME literal with one thing changed beside a |
| 4375 | + // control that IS discovered, so a veto that silenced everything fails here. |
| 4376 | + battery('The NATIVE COLLECTION, the fourth shape (#29859).'); |
| 4377 | + const F = SLICES.find((s) => s.verb === 'findOne'); |
| 4378 | + const collectionBody = ` |
| 4379 | + insertMany: async (many: Doc[]) => ({}), |
| 4380 | + findOne: async (filter: Doc, options: { projection?: Record<string, number> }) => null, |
| 4381 | + find: (filter: Doc, options?: any) => ({ toArray: async () => [] }),`; |
| 4382 | + const nativeCollection = `const collection = { |
| 4383 | + insertOne: async (doc: Doc) => ({}),${collectionBody} |
| 4384 | + updateOne: async (filter: Doc, update: { $set?: Doc }) => ({ matchedCount: 0 }), |
| 4385 | +}; |
| 4386 | +`; |
| 4387 | + const sameCollectionWithoutMarker = `const collection = {${collectionBody} |
| 4388 | +}; |
| 4389 | +`; |
| 4390 | + expect('a five-member native Mongo Collection fake is out of scope for the findOne slice', |
| 4391 | + scanSource('nc.test.ts', nativeCollection, F).length === 0); |
| 4392 | + expect('…and the SAME literal without insertOne/updateOne is still discovered', |
| 4393 | + scanSource('nc.test.ts', sameCollectionWithoutMarker, F).length === 1); |
| 4394 | + |
| 4395 | + // Both arity paths the veto has to outrank: a one-parameter `findOne(filter)` |
| 4396 | + // reaches the short-arity path, where `insertMany` alone is engine evidence. |
| 4397 | + const oneArityCollection = `const collection = { |
| 4398 | + insertOne: async (doc: any) => ({}), |
| 4399 | + insertMany: async (many: any[]) => ({}), |
| 4400 | + findOne: async (filter: any) => null, |
| 4401 | + find: (filter: any) => ({ toArray: async () => [] }), |
| 4402 | +}; |
| 4403 | +`; |
| 4404 | + expect('a one-parameter native findOne beside insertMany is out of scope', |
| 4405 | + scanSource('nc1.test.ts', oneArityCollection, F).length === 0); |
| 4406 | + expect('…and the same without insertOne is discovered', |
| 4407 | + scanSource('nc1.test.ts', oneArityCollection.replace(' insertOne: async (doc: any) => ({}),\n', ''), F) |
| 4408 | + .length === 1); |
| 4409 | + |
| 4410 | + // The control the card names: a real engine double holding `find` and |
| 4411 | + // `insertMany` plus engine members is still attributed, still unpinned. |
| 4412 | + const engineWithInsertMany = ` |
| 4413 | +const engine = { |
| 4414 | + async find(objectName: string, q?: any) { return []; }, |
| 4415 | + async insertMany(objectName: string, rows: any[]) { return rows; }, |
| 4416 | + async insert(objectName: string, data: any) { return data; }, |
| 4417 | + async findOne(objectName: string, q?: any) { return null; }, |
| 4418 | +}; |
| 4419 | +`; |
| 4420 | + d = scanSource('em.test.ts', engineWithInsertMany, F); |
| 4421 | + expect('an engine double with find/insertMany is still a findOne double', |
| 4422 | + d.length === 1 && d[0].pinned === false); |
| 4423 | + |
| 4424 | + // The member is not a licence by itself: an engine double that takes the |
| 4425 | + // object name first stays in scope however many Mongo-named helpers it adds. |
| 4426 | + const engineWithInsertOneHelper = engineWithInsertMany.replace( |
| 4427 | + ' async insert(', |
| 4428 | + ' async insertOne(doc: any) { return doc; },\n async insert(', |
| 4429 | + ); |
| 4430 | + d = scanSource('eo.test.ts', engineWithInsertOneHelper, F); |
| 4431 | + expect('an engine double that ALSO declares insertOne stays in scope', |
| 4432 | + engineWithInsertOneHelper.includes('insertOne') && d.length === 1 && d[0].pinned === false); |
| 4433 | + |
| 4434 | + // Exact-set form: both shapes in one file, only the engine reported. |
| 4435 | + const mixedCollection = `${nativeCollection}${engineWithInsertMany}`; |
| 4436 | + const mixedCollectionFound = scanSource('mc.test.ts', mixedCollection, F); |
| 4437 | + expect('a mixed fixture reports EXACTLY the engine double, not the native Collection', |
| 4438 | + mixedCollectionFound.length === 1 && mixedCollectionFound[0].line === 9); |
| 4439 | + |
4309 | 4440 | // ── The CONSUMER SEAMS (#8194) ──────────────────────────────────────────── |
4310 | 4441 | // |
4311 | 4442 | // Driven on both sides of all four decisions the seam scan makes — the three |
|
0 commit comments