fix(cli): analyze the baseline under the current checkout's config instead of re-loading it in the worktree - #400
Conversation
…stead of re-loading it in the worktree
--baseline checks out the ref into a git worktree under os.tmpdir(), which
has no node_modules in its ancestry. analyzeProject re-loaded
svelte-vitals.config.* from that worktree cwd, so any config that imports a
runtime dependency (e.g. the install wizard's own .ts scaffold, which does
`import { defineConfig } from 'svelte-vitals'`) threw ERR_MODULE_NOT_FOUND,
silently degrading the baseline comparison to "report everything".
Add AnalyzeOptions.loadedConfig (LoadedConfigFile | null) so a caller can
hand analyzeProject an already-loaded config instead of loading one from its
cwd; null means "no config file, don't look for one" and is distinct from
undefined ("load normally"). run() now threads its own loadConfigFile()
result (surfaced via the new AnalyzeResult.loadedConfig) into the baseline
analyzeProject call, so both sides of the comparison run under the current
checkout's config. This also fixes a quieter bug: a config edit between the
baseline ref and HEAD no longer makes unrelated findings look "introduced".
|
Warning Review limit reached
Next review available in: 19 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
--baseline <ref>checks out<ref>into a worktree underos.tmpdir()and runsanalyzeProjectthere — which re-loadedsvelte-vitals.config.*from the worktree, a directory with nonode_modulesanywhere in its ancestry (git worktrees only contain tracked content). Theinstallwizard's own.tsscaffold emitsimport { defineConfig } from 'svelte-vitals'(a runtime bare-specifier import), so for every project that took the wizard's default, the baseline-side config load threwERR_MODULE_NOT_FOUND, the catch logged one stderr line, and all findings were reported as new — the PR gate exited 1 on unrelated changes. The tool's own scaffolder produced the config that disabled the tool's own baseline gate.Second, quieter wrong: even when the worktree config did load, it was the ref's config, so the two sides of the comparison ran under different rule sets whenever the config changed between ref and HEAD — a config-only edit produced "introduced" findings.
Semantics
The current checkout's config now governs both sides of the comparison: a baseline run answers "which findings does my change introduce, under today's policy?" — policy is an input to the comparison, not part of the compared code.
Changes
AnalyzeOptions.loadedConfig?: LoadedConfigFile | null(additive, public API): reuse a priorloadConfigFile()result instead of loading fromcwd;nullmeans "no config file — don't look".AnalyzeResult.loadedConfigreturns the load result sorun()can thread it into the baseline call viaanalyzeOpts.checkoutBaseline(real git repo + realgit worktree add, config importing an untrackednode_modules/fake-pkg): (1) theERR_MODULE_NOT_FOUNDshape — new finding reported, pre-existing finding filtered, no degradation message on stderr; (2) config-governs-both-sides — a config-only rule re-enable does not report the pre-existing finding as introduced. Both were shown to fail without the fix (viagit stashof the src change).Note for the action repo
svelte-vitals-actionbundlesapplyScopedirectly; its baseline path keeps the old re-load-from-worktree behavior until it passesanalyzeOpts.loadedConfigthe same wayrun()now does. Small follow-up candidate there.Verification
pnpm -r typecheck/pnpm test(core 1292, cli 824, vite 207) /pnpm lintall green;io-budget.test.tsuntouched and passing (no new collector I/O).🤖 Generated with Claude Code