Repository navigation
test(infra): pin every in-memory mongod to the harness version + cache dir (TASK-149) - #1923
Merged
Merged
Conversation
samxu01
force-pushed
the
kai/task149-mongod-version-agreement
branch
from
September 26, 2026 14:27
0bd7403 to
4765293
Compare
…che dir (TASK-149) Measured at f5fd55b: eight call sites pass `binary` options to `MongoMemoryServer.create(`. Four pinned mongod 7.0.11 and two pinned 7.0.14 without `downloadDir`, against the harness's MONGO_BINARY_VERSION = '7.0.14' — three versions in one run, none of the mismatches pointing at the shared cache. Why the mismatch is the one that can download in the wrong window: globalSetup warms the harness binary once, before any worker exists, and assigns process.env.MONGOMS_DOWNLOAD_DIR so per-file create() inherits it. An explicit `version` option beats the env MONGOMS_VERSION, and the candidate filename is version-scoped (mongod-<arch>-<dist>-<version>), so a mismatched pin misses the warm-up, falls past every candidate on a cold runner, and reaches MongoBinary.download() inside the parallel worker phase — the download-lock window globalSetup exists to serialise. generateOptions folds the env DOWNLOAD_DIR into downloadDir, so all four 7.0.11 suites contend on one lock path: <pinned dir>/7.0.11.lock. No workflow caches a binary: MONGOMS/ mongodb-binaries has zero references under .github/workflows, and the only `cache:` key in the test job is setup-node's ~/.npm. (The comment this PR corrects claimed the pinned dir "survives across test runs in CI cache".) Half (a) of TASK-149 only — the version/cache-dir split. Half (b), moving the 27 suites that own a create() onto testUtils.setupMongoDb, is not in this PR. - 6 suites: version + downloadDir now come from mongoBinaryConfig's constants - new guard mongodBinaryPinAgreement.test.js, three arms: no version string literal at a call site; every options object passed to a call site names downloadDir; and the options must be written INLINE — a hoisted variable is refused rather than parsed, because arms 1 and 2 read the literal text after the call and a hoisted call site leaves the population silently (Vera's hold on this PR demonstrated the escape: 7.0.11 + no downloadDir behind a variable stayed green). The call-site floor is the measured population (8), not a number three below it: at 5 the same escape kept it green. If half (b) removes call sites, the floor moves with the change. - the two precedences are opposite, and the docblock says so: an explicit `version` option BEATS the env (`getEnsuredOptions`), so the version agreement is what closes the worker-phase lock; the env `DOWNLOAD_DIR` BEATS the option, so the explicit downloadDir is inert on a normal unit run and decides the path only where the env is absent — `globalSetup` returns early under INTEGRATION_TEST=true before exporting either variable. Arm 1 guards the unit path, arm 2 the integration path. Nobody should read arm 2 as the fix. - one comment corrected in mongoBinaryConfig.js Node 22: 7 suites / 57 tests pass. Guard reddens under: literal reinstated (M1), downloadDir dropped (M2), scan root emptied (M3), and the hoisted escape (M4 — 2 failed: the floor and arm 3); with arm 3 removed the floor still catches it, and with the pre-fix guard (floor 5, two arms) the escape is green, exactly as the hold reported. A synthetic file holding a bare create(), a clean literal create({...}) and one hoisted site flags exactly one offender, so the arm discriminates. The pre-existing eslint parsing error in agentEnsembleService.test.js (line 274 on f5fd55b, 276 after this diff) is untouched.
samxu01
force-pushed
the
kai/task149-mongod-version-agreement
branch
3 times, most recently
from
September 26, 2026 14:33
ca8598c to
c14cc61
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes half (a) of TASK-149. Row:
TASK-149, pod6a8f6dc7a1dccf2e02f31015. Gate: @vera (single).The defect, measured at
f5fd55bcgit grep -A2 'MongoMemoryServer.create({' backend/__tests__— eight call sites passbinaryoptions, and six of them disagree with the harness:services/agentEnsembleService.test.js:407.0.11services/dmService.agentDm.test.ts:367.0.11services/dmService.test.ts:307.0.11unit/cap/session-token.test.js:677.0.11unit/models/AgentInstallation.wakePolicy.test.js:157.0.14, nodownloadDirunit/models/agentRegistry.manifestRuntime.test.js:727.0.14, nodownloadDiragainst
mongoBinaryConfig.MONGO_BINARY_VERSION = '7.0.14'. Two of the three versions are visibly resident on this box (~/.cache/mongodb-binariesholds7.0.14,7.0.11,6.0.14) — the split is not hypothetical.Why it matters, and why this half goes first
globalSetupwarms the harness binary once, before any worker exists, and assignsprocess.env.MONGOMS_DOWNLOAD_DIRso per-filecreate()inherits it. An explicitversionoption beats the envMONGOMS_VERSION, so a mismatched pin misses that warm-up and reachesMongoBinary.download()inside the parallel worker phase — the download-lock windowglobalSetupexists to serialise. Those four are the only population in the tree that downloads after workers start.CI has no binary cache to hide behind:
MONGOMS/mongodb-binarieshas zero references under.github/workflows, and the onlycache:key in the test job is setup-node's~/.npm(tests.yml:61,:216). The comment this PR corrects claimed the pinned dir "survives across test runs in CI cache"; it does not.Read out of the library (
[email protected]), because the candidate order decides which suites download:generateOptions(DryMongoBinary.js:76) puts envMONGOMS_DOWNLOAD_DIRintodownloadDir— the env beats the passed option; worker processes inherit it fromglobalSetup:39.getEnsuredOptions(:66) isopts.version || defaultVersion— the option beats the env — whilegenerateOptionsisresolveConfig(DOWNLOAD_DIR) || ensuredOpts.downloadDir— the env beats the option. So the version agreement is what closes the worker-phase lock; the explicitdownloadDirthis PR adds is inert on a normal unit run. It is not decoration:globalSetupreturns early underINTEGRATION_TEST=truebefore exporting either variable, so on that path a suite resolves purely from its own options and its owndownloadDiris what fixes the lock path. Arm 1 guards the unit path, arm 2 the integration path.generateDownloadPathprobesresolveConfig→homeCache→modulesCache→relative, each ascombineBinaryName(dir, binaryName)(:184,:150), and the binary name carries the version (mongod-<arch>-<dist>-<version>,:139). So inheriting the warm directory does not rescue a mismatched version: the filename is a different one.modulesCacheisfind-cache-dir({name:'mongodb-memory-server'})=node_modules/.cache/mongodb-memory-server— a different directory from the pinnednode_modules/.cache/mongodb-binaries. The pinned dir is reachable only asresolveConfig, i.e. through the env var. Verified on this box:find-cache-dir→.../node_modules/.cache/mongodb-memory-server;mongoBinaryConfig→.../node_modules/.cache/mongodb-binaries.paths.resolveConfig(:253) and the lock islockfilePath(downloadDir, version)=<pinned dir>/7.0.11.lock(utils.js:308). All four 7.0.11 suites therefore contend on one identical lock path — which is the.lockin the error string, and this run would print7.0.11.lock.Simulated cold runner (temp
HOME, pinned dir holding only the 7.0.14 file, env exported,generatePathsprobed directly — constructed, not CI): for7.0.14candidate 1 exists → resolves, no download; for7.0.11all four candidates miss →download()in that worker. The two7.0.14-without-downloadDirsuites are safe for a reason unrelated tomodulesCache: candidate 1 already matches. After this PR all eight call sites inherit one version — which, because the option beats the env, is the half that decides whether a worker reachesdownload()at all — so every suite resolves from candidate 1 and no CI worker downloads on the unit path. The explicit dir rides along for theINTEGRATION_TESTpath, where no env var is exported; read arm 2 as guarding that path, not as what closed the lock.Honest label: the cold-runner consequence is a code read (above) plus the measured absence of any cache step, backed by a constructed simulation of a cold runner — I have no runner access, so it is a prediction about cold CI, not an observation of CI.
What changed
versionanddownloadDirfrommongoBinaryConfig's constants (the shapeservice/agent-profile-memory-write.test.js:26already used);mongodBinaryPinAgreement.test.js— a static guard with three arms: (1) noversionstring literal at any call site; (2) every options object passed to a call site namesdownloadDir; (3) the options must be written inline — a hoisted variable is refused rather than parsed. It asserts a call-site count first, so an empty scan cannot pass vacuously;mongoBinaryConfig.js.Evidence
PATH=/opt/homebrew/opt/node@22/bin:$PATH: 7 suites / 56 tests pass (guard + the six changed suites).downloadDirdropped, M3 scan root emptied, M4 the hoisted rewrite (see the table above); green on the clean tree. Now 7 suites / 57 tests.agentEnsembleService.test.js(line 274 atf5fd55bc, 276 after this diff) is untouched and unrelated.Scope
Half (a) only. Half (b) — moving the 27 suites that own a
create()ontotestUtils.setupMongoDb— is deliberately not here: it is a 27-file change and it does not depend on this one.A residual, measured and left for half (b) (Vera 74512; facts re-verified here rather than taken on report). On the
INTEGRATION_TEST=truepath neitherMONGOMS_VERSIONnorMONGOMS_DOWNLOAD_DIRis ever exported, so a call site there resolves purely from its own options — and a bare call site resolves the library'sDEFAULT_VERSIONwith no shared dir, invisible to both arms, which only read call sites that pass options.Reachable in principle, harmless in practice today, on two measured facts:
tests.yml:205(INTEGRATION_TEST: "true"), on the Tier-1 service job. But that job runsnpx jest --testPathPattern="__tests__/service" --forceExit --runInBand(tests.yml:231), and under--runInBandthere are no parallel workers, so a download lock cannot be contended there by construction. Worst case on that path is a wasted ~160 MB fetch, not a flake.backend/__tests__/service/three suites mentionMongoMemoryServer—agent-profile-memory-write.test.js:25calls it with options (covered by the arms here),uploads.signedurl.integration.test.js:8is a docblock,clawdbot-e2e.test.js:42is a comment. Zero bare call sites on the integration path, so a fourth arm would police nothing.So no fourth arm, and no row: half (b) carries the note. If a suite under
__tests__/service/ever starts a barecreate(), it resolves the library default with no shared dir and neither arm can see it.The guard's own escape, found by the hold on the first head
The two-arm guard at
0bd74037was blind to a hoisted call site. Demonstrated, not argued: rewriting a suite's call as— the exact defect this row was opened for — left it 3/3 green, exit 0. The scan requires
create(immediately followed by{, so hoisting removes the site from the population without touching either arm. Same blind-to-a-variant-shape class ascreate()vscreate(, which is what produced the miscount that started this row.Two nets close it:
utils/testUtils.js), not a number three below it. The floor's only job is to notice the scan going blind, and at 5 it cannot: under the hoisted rewrite above the count fell 8 → 7 and stayed green.Escapes are now caught twice, which the mutation ledger shows rather than asserts:
The call-site floor stays a literal — 8, not derived (Vera 74509). A derived floor counts the call sites the same scan can see, so it moves with a blindness loss and stops being able to detect one: the vacuity it exists to prevent, reintroduced through the back door. It is a ratchet, the same shape as
routeRateLimitGuard.baseline.json(edited by the PR that changes the population); half (b) lowers the literal in the same commit that retires the call sites, so the diff makes the count visible to its reviewer. Withdrawn: my suggestion to derive it.Arm 2's implemented predicate is deliberately stricter than its old name: it refuses any options object whose region lacks
downloadDir, including one carrying onlyinstance. That is the safe direction (arm 1 cannot see a version that is not written inline) and it is kept; the docblock and the test name now say what the code does.optionRegionstill takes the first}after the call's{, which is thebinaryoption block in both the inline and multi-line forms (8/8 call sites). If a future call site puts another option first, the region would be wrong — say so and I'll make it structural.