Repository navigation
fix(#870): resolve worktree package manager from lockfile when manifest is absent - #874
Merged
admarble merged 6 commits intoJul 30, 2026
Conversation
…st is absent `installWorktreeDeps` and `reinstallIfLockfileChanged` both resolved the package manager as `(packageManager as keyof typeof PM_CONFIG) || "npm"`. That value comes from the worktree manifest — a snapshot taken at `sequant init` — so it is absent on manifest-less or pre-init worktrees, and the bare literal then assumed npm. `new-feature.sh` has detected live from the lockfile since #847, so on a pnpm/yarn/bun project without a manifest the two provisioning paths ran different frozen installs for the same repo. Same dual-producer drift class as #833. Both sites now call a new `resolvePackageManager(declared, root)` in `stacks.ts` — the module new-feature.sh already names as its source of truth — which keeps a declared manager and otherwise falls back to `detectPackageManagerSync`, the helper #487 added for exactly this. This is the continuation of #487's conversion pass, whose inventory covered `version-check.ts` and `bin/cli.ts` but never `worktree-manager.ts`. The `in PM_CONFIG` membership test also retires the unchecked cast: a declared value outside `PackageManager` used to index `PM_CONFIG` to `undefined` and throw on the next property access, and now routes to detection. Python managers stay declared-wins, since the sync detector is JS-only. Manifest-less npm projects and lockfile-less worktrees are unaffected. AC-1: both sites converted (worktree-manager.ts:541, :1223). AC-2: pnpm case asserts `pnpm install --frozen-lockfile`, byte-identical to new-feature.sh's `pm_frozen_install` pnpm branch. AC-3: gate tests added; mutation result recorded in the PR body. Tests: 229 files, 4707 passed, 1 expected fail, 2 skipped. Build + lint clean.
… test
Adversarial QA pass on the previous commit: `in` walks the prototype
chain, so `"toString"`, `"constructor"`, `"valueOf"`, `"hasOwnProperty"`,
and `"__proto__"` all passed the membership test and were returned as if
they named a package manager. `PM_CONFIG["toString"]` then yields the
inherited function (and `PM_CONFIG["__proto__"]` yields Object.prototype),
whose `ciInstall` is undefined, so the caller crashed on `.split(" ")`:
TypeError: Cannot read properties of undefined (reading 'split')
That is the exact failure the guard was added to prevent, reintroduced one
layer down — and the doc comment, commit message, and CHANGELOG all claimed
it was closed. `Object.prototype.hasOwnProperty.call` closes it for real.
Adds a table-driven gate test over the five inherited keys, and corrects
the CHANGELOG wording to name the `hasOwnProperty`-vs-`in` choice.
`docs/features/package-manager-detection.md` told users that a missing `packageManager` field means "Sequant defaults to npm". That is now stale for the path this issue changed: worktree provisioning detects from the worktree's lockfile, so a manifest-less pnpm/yarn/bun project gets that manager's frozen install, and npm applies only when no lockfile is present. The sentence is scoped rather than deleted, because it is still accurate for `sequant update`, whose three sibling sites keep the bare npm fallback pending the follow-up noted in the PR body.
3 tasks
Closes the scope gap flagged in QA. `update.ts:113`, `:128`, and `:296` carried the byte-identical `(manifest.packageManager as keyof typeof PM_CONFIG) || "npm"` spelling. The manifest field is absent precisely on pre-1.3.0 installs — the population the PM_RUN backfill exists to serve — so `update` wrote an npm PM_RUN token into pnpm/yarn/bun projects and ran `npm install` there when package.json changed. All three now consume one `const pm` resolved right after the manifest loads, from `resolvePackageManager(manifest.packageManager, process.cwd())`. Resolving once rather than converting each site in place is the point: the defect was one rule copied to three places, and three copies of the new call would have preserved that shape. The cwd is the correct root because `update` operates on the project in place, the same directory `getManifest` and `syncSequantMcpPin` read. Repo-wide grep confirms no live `|| "npm"` fallback remains; only the comments explaining the old spelling mention it. Tests: 4 behavioral cases driving `updateCommand` with a redirected cwd and a real temp-dir lockfile — pnpm backfill, yarn first-run config, the unchanged no-lockfile npm default, and manifest-wins-over-lockfile. Mutation result recorded in the PR body. Docs and CHANGELOG updated: the previous pass scoped the docs sentence to "`sequant update` still assumes npm", which this commit makes false.
…manager-s-bare-npm-fallback-disagrees
… runtime The #870 update tests used `vi.spyOn(process, "cwd").mockReturnValue(dir)` so the resolver would read a temp-dir lockfile. `process.cwd` is a process global and `pool: "forks"` reuses a worker across test files, so the patch escaped the file that set it. Measured on this machine, holding directory and node_modules constant and varying only the source: main's code in the worktree 205s 0 failures branch, update.test.ts removed 211s 0 failures branch, only the cwd spy disabled 230s 2 failures (its own) branch as committed 695s 4 failures (semgrep, mcp-serve, App.tsx, lock-manager — all unrelated) One line accounted for ~465s and every unrelated failure: the poisoned cwd made other files in the reused fork slow enough to blow their timeouts. The file itself ran in 11s, which is why per-file runs never showed it. Faking a process global to control one function argument was the wrong lever. The resolver's lockfile semantics are already covered directly, with a real temp dir, in stacks.resolve-package-manager.test.ts (12 cases, mutation-verified). What update.test.ts needs to pin is the *wiring* — that update consults the resolver, passes the manifest value and project root, and lets the answer drive PM_RUN — which needs no filesystem at all. So `resolvePackageManager` is mocked (everything else in stacks.js stays real) and the assertions moved to call arguments and the resulting PM_RUN. The rewrite also gates harder: 4 of 5 tests now fail when update.ts is reverted to the bare `|| "npm"`, against 2 of 4 before. Second defect fixed here: `updateCommand` calls `syncSequantMcpPin` before the template short-circuit, so the non-dry-run cases were rewriting the repo's real `.mcp.json` on every test run (observed twice as an unexplained dirty file). The pre-existing tests never hit it because they all pass `--dry-run`. `mcp-config.js` is now mocked. Full suite after the fix: 229 files, 4717 passed, 0 failures, 190s — below main's own 205s on the same machine.
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.
Summary
worktree-manager.ts(installWorktreeDeps,reinstallIfLockfileChanged) now resolve through a newresolvePackageManager(declared, root)instacks.ts, which falls back todetectPackageManagerSync(worktreePath)instead of the bare literal"npm"when the manifest records no manager.templates/scripts/new-feature.sh(PM-aware since new-feature.sh hardcodes npm ci while the TS path is package-manager aware — pnpm/yarn/bun provisioning fails misleadingly #847) on manifest-less pnpm/yarn/bun projects, closing the dual-producer drift described in the issue.sequant update's three sibling sites are converted through the same resolver, so no live|| "npm"fallback remains anywhere insrc/.as keyof typeof PM_CONFIGcast, which turned an unrecognized manifest value into aTypeErroron the next property access. The test ishasOwnProperty, notin— see the QA finding below.AC Verification
detectPackageManagerSync(worktreePath)when the manifest value is absentworktree-manager.ts:544and:1228— both nowPM_CONFIG[resolvePackageManager(packageManager, worktreePath)]. Neither function needed a signature change; both already heldworktreePath.new-feature.shworktree-manager.frozen-install.test.ts— "installWorktreeDeps runs pnpm's frozen install on a manifest-less pnpm worktree" asserts the spawned command ispnpm install --frozen-lockfile, byte-identical to thepnpm)branch ofpm_frozen_installinnew-feature.sh:211. Both readPM_CONFIG.pnpm.ciInstall.|| "npm"failsDefect found by the review pass, fixed in this PR
The first commit used
declared in PM_CONFIG.inwalks the prototype chain, so"toString","constructor","valueOf","hasOwnProperty", and"__proto__"all passed the membership test and were returned as if they named a package manager. IndexingPM_CONFIGwith one yields an inherited function (orObject.prototype) whoseciInstallisundefined. Confirmed by running it:An uncaught
TypeErrorduring worktree provisioning — the exact crash class this guard exists to close, reintroduced one layer down, while the comment, commit message, and CHANGELOG all claimed it was closed. Fixed in8165b530withObject.prototype.hasOwnProperty.call, a table-driven gate test over all five inherited keys, and corrected wording in all three places.A second, smaller gap:
docs/features/package-manager-detection.md:157still told users "Sequant defaults to npm" when the manifest field is missing, which this change makes false for the provisioning path. Scoped rather than deleted inb510669a, since it remains true forsequant update.Mutation verification (CLAUDE.md gate-test rule)
Two independent mutations. Committed first each time, then reverted
resolvePackageManager's body to the bare fallback (return (declared as PackageManager) || "npm";) and re-ran both test files:Mutation 2 — revert
hasOwnPropertyback toin:In both cases exactly the intended tests fail and every pre-existing test still passes, so the coverage is real and scoped.
git checkout src/lib/stacks.tsrestored each time; 22/22 green.Behavior change surface
Deliberately narrow:
npm, same as the old literal).detectPackageManagerSyncstill defaults tonpm, and a failingnpm ciis surfaced by the ensureWorktree swallows the provisioning install exit status — npm ci failure yields a silent dependency-less worktree #846 warn-and-continue path. Pinned by "a manifest-less worktree with no lockfile still falls back to npm".pip/poetry/uv), which arePM_CONFIGkeys but absent fromLOCKFILE_PRIORITYand so would be silently rewritten tonpmby an always-detect implementation. Pinned by two tests.Test plan
npm run build— cleannpm run lint— clean (--max-warnings 0)npm test— green in CI (build (22.x)runsnpm test,ci.yml:36); all 5 checks passOne local full-suite run failed
mcp-e2e … SIGTERM(4107 ms). Measured rather than assumed: it passes in isolation on this branch, the branch's first full run was clean, and a full run onmainunder identical conditions failed 4 different tests while that one passed. Pre-existing load-dependent integration flakes on this machine, not a regression.Files changed
src/lib/stacks.tsresolvePackageManagerexport besidedetectPackageManagerSyncsrc/lib/workflow/worktree-manager.tssrc/lib/stacks.resolve-package-manager.test.tssrc/lib/workflow/worktree-manager.frozen-install.test.ts#870describe block — 4 call-site testsCHANGELOG.md[Unreleased] → Fixedentrydocs/features/package-manager-detection.mdsequant update's three sites (originally deferred, now included)Open Question 1 in the plan proposed leaving
src/commands/update.ts:113/:128/:296— the byte-identical pattern — to a follow-up. They are now converted in this PR instead.They mattered more than the deferral assumed: the manifest field is absent precisely on pre-1.3.0 installs, which is exactly the population the
PM_RUNbackfill at:113exists to serve. So the site most likely to run with an absent manifest value was the one hardcoding npm — writing an npmPM_RUNtoken into pnpm/yarn/bun projects and runningnpm installat:296whenpackage.jsonchanged.All three now consume a single
const pmresolved right after the manifest loads. Resolving once rather than converting each site in place is deliberate: the defect was one rule copied to three places, and three copies of the new call would have preserved that shape. The root isprocess.cwd(), matching whatgetManifestandsyncSequantMcpPinalready read.Coverage: 4 behavioral tests drive
updateCommandwith a redirectedprocess.cwd()and a real temp-dir lockfile — pnpm backfill, yarn first-run config, the unchanged no-lockfile npm default, and manifest-wins-over-lockfile.Mutation 3 — revert that resolution to
(manifest.packageManager as keyof typeof PM_CONFIG) || "npm":Exactly the two lockfile-detection tests fail. The other two new tests correctly keep passing under the mutation — the no-lockfile and manifest-present cases have the same expected result under both implementations, so they are boundary guards rather than gates, and claiming otherwise would overstate the coverage.
Branch state
origin/mainis merged in (33405d16), so the branch is 0 commits behind. The merge brought only the dependabothonobump (package-lock.json). The post-merge install rewrote that lockfile by strippinglibcfields a newer npm had committed — the exact normalizationinstallWorktreeDeps' comment documents — so the rewrite was discarded rather than committed.Fixes #870