fix(init): only detect pnpm approve-builds failures from pnpm-specific output#2404
Conversation
commit: |
Performance benchmarksCompared 1 improved · 0 regressed · 5 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
|
/bigbonk review for issues |
There was a problem hiding this comment.
Review: fix(init): tighten approve-builds detection
The change to isApproveBuildsError() is correct and a real improvement. Splitting the matcher so that the generic ignored build scripts / blocked build scripts phrases only trigger when pnpm is also present in the output is the right call — those phrases are not pnpm-exclusive, so the previous broad regex could misclassify unrelated install output. The approve-builds and ERR_PNPM_*BUILD branches stay unconditional, which is appropriate since both are unambiguously pnpm-specific.
I ran vitest run tests/init.test.ts — all 101 tests pass.
Main concern: the change is effectively untested
The PR description's Validation section cites the test "does not classify non-pnpm install failures as approve-builds errors" (tests/init.test.ts:962). That test already exists on main (last touched in #2389) — it is not added by this PR, and it does not exercise this change.
The reason: that test goes through the catch error path, which is gated on the package manager before isApproveBuildsError is consulted:
// init.ts:521
if (pmName !== "pnpm" || !isApproveBuildsError(error)) throw error;The test's fixture (setupProject(tmpDir, { router: "pages" })) writes no pnpm-lock.yaml, so pmName !== "pnpm" short-circuits to true and the error is rethrown regardless of what isApproveBuildsError returns. That test therefore passes identically against both the old and new regex — it does not protect against regressions in this function.
The behavior this PR actually changes lives in the success path (init.ts:505 and init.ts:519), which calls isApproveBuildsError(installOutput) for any package manager and is not guarded by pmName. There is currently no test covering: a successful install whose output contains ignored build scripts without pnpm → should NOT set dependencyInstallNeedsApproval. Adding such a test would lock in the fix and prevent the broad regex from creeping back.
This is non-blocking (the fix is correct), but I'd recommend adding a targeted test for the success path so the change is genuinely covered.
| details, | ||
| return ( | ||
| /approve-builds|ERR_PNPM_.*BUILD/i.test(details) || | ||
| (/pnpm/i.test(details) && /(ignored build scripts|blocked build scripts)/i.test(details)) |
There was a problem hiding this comment.
The logic here is right. Note the call site that this actually affects in practice is the success path (init.ts:505 / init.ts:519), which invokes isApproveBuildsError(installOutput) for any package manager. The catch error path (init.ts:507 / init.ts:521) is gated on pmName === "pnpm" first, so for non-pnpm projects the error is rethrown before this function is even consulted. That's why the cited validation test ("does not classify non-pnpm install failures as approve-builds errors") passes against both old and new code — it doesn't exercise this change. A test on the success path (successful install whose output contains ignored build scripts but no pnpm → dependencyInstallNeedsApproval stays false) would actually cover this fix.
|
Review posted successfully. Summary of my findings: Review summary for PR #2404Verdict: the fix is correct, but effectively untested. What's goodThe change to Key issue raisedThe PR description's "Validation" section cites the test "does not classify non-pnpm install failures as approve-builds errors" (
The behavior the PR actually changes is the success path ( This is non-blocking since the code change is correct, but the validation claim is misleading and the fix lacks real regression coverage. |
What changed
Tightened
vinext init's approve-builds error detection so it only treats install failures as pnpm build-approval issues when the output is actually pnpm-specific.In practice, this narrows
isApproveBuildsError()to match:approve-buildsoutputERR_PNPM_*BUILDignored build scripts/blocked build scriptstext only whenpnpmis also presentWhy
vinext initwas previously too eager here and could misclassify a generic install failure as a pnpmapprove-buildscase.That led to the CLI swallowing the real install error and printing pnpm recovery instructions even when the failure was not actually a pnpm build-approval problem.
Impact
approve-buildsrecovery flow working when the output is genuinely pnpm-specificvinext initfailure reporting and recovery guidanceRoot cause
The approve-builds matcher was keyed off broad phrases like
ignored build scriptswithout requiring enough pnpm-specific context.Validation
Ran:
pnpm test tests/init.test.ts -t "does not classify non-pnpm install failures as approve-builds errors"pnpm test tests/init.test.ts -t "approve-builds"pnpm test tests/init.test.ts