Repository navigation
fix(bench): load benchmark modules under test through jiti - #23482
Conversation
`pnpm run bench:terminal-partial-escape-tail` and `pnpm run bench:worktree-refresh-churn` both died at startup with ERR_MODULE_NOT_FOUND. Each entrypoint static-imported a `src/` module with an explicit `.ts` extension, but bare `node` type-stripping cannot resolve the extensionless relative specifiers *inside* that module's graph (`terminal-partial-escape-tail.ts` -> `./terminal-escape-introducer`, `worktree-catalog-reconciliation.ts` -> `../../../../shared/structural-value-equality`). Routes both through jiti, matching the four benchmarks that already load `src/` TypeScript that way (`pty-source-ack-boundary`, `locale-collator-sort`, `worktree-base-pending-marker`, `wsl-git-shell`). Adding the extension at each import site was the alternative, but `config/tsconfig.node.json` does not set `allowImportingTsExtensions`, so a `.ts` specifier in `src/shared` fails typecheck with TS5097 -- and no file under `src/` uses that shape today. Developer tooling only; no production code changed. Co-authored-by: Claude <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
terminal-partial-escape-tail-benchmark.mjs— replaced the static.tsimport withcreateJiti(import.meta.url)+await jiti.import('../../src/shared/terminal-partial-escape-tail.ts'), destructuring the three named exports.worktree-refresh-churn-benchmark.mjs— same treatment forplanWorktreeSortOrderUpdatesandreuseEqualCatalogRows.
Both changes match the pattern already used by pty-source-ack-boundary-benchmark.mjs, locale-collator-sort-benchmark.mjs, worktree-base-pending-marker-benchmark.mjs, and wsl-hook-relay-reattach-benchmark.mjs. The diagnosis is correct: plain node type-stripping resolves the explicit .ts entrypoint but not the extensionless relative imports inside the loaded graph, and jiti is resolvable through the repo's shamefullyHoist: true install. No production code is touched, and the loaded graphs contain no @-alias imports that would need additional jiti config.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughBoth benchmark scripts replace direct TypeScript imports with asynchronous imports through jiti. One script loads three exports from the terminal-tail module. The other loads two exports from TypeScript modules and adds a comment about extensionless relative imports. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The benchmark-loading change is mergeable after normal checks; no unresolved issue is established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |

ELI5
Two of our performance measuring scripts were broken and crashed the moment you ran them. They tried to load some of the app's own code, and the way they asked for it didn't work. This teaches them to ask a different way. Nothing about the app itself changes — only the scripts a developer runs by hand.
What Changed
Before:
pnpm run bench:terminal-partial-escape-tailandpnpm run bench:worktree-refresh-churnboth exited immediately withERR_MODULE_NOT_FOUNDand printed no measurements at all.After: both run and print their result tables.
The mechanism: each script is a plain
.mjsfile thatnoderuns directly, and each static-imported a TypeScript module out ofsrc/using an explicit.tsextension. That part was fine. The failure was one level deeper — plainnode's TypeScript type-stripping does no extension guessing, so the extensionless relative imports inside the loaded module's own graph could not resolve:src/shared/terminal-partial-escape-tail.ts→'./terminal-escape-introducer'src/renderer/src/store/slices/worktree-catalog-reconciliation.ts→'../../../../shared/structural-value-equality'Both scripts now load those modules through
jiti, which resolves extensionless TypeScript specifiers across the whole graph. Only the two script files changed.Why
Two ways to fix this were considered.
Add the missing extensions at each import site — rejected.
config/tsconfig.node.jsonincludessrc/shared/**/*and does not setallowImportingTsExtensions, so a.tsspecifier there fails typecheck:Enabling that flag is a repo-wide compiler change, and no file under
src/uses an explicit.tsrelative import today — so this fix would have edited production shared code to a shape the repo does not otherwise use, in order to repair a dev script.Load through
jiti— chosen. This is the pattern four benchmarks already use for exactly this job:pty-source-ack-boundary-benchmark.mjs,locale-collator-sort-benchmark.mjs,worktree-base-pending-marker-benchmark.mjs, andwsl-hook-relay-reattach-benchmark.mjs.jitiis already resolvable in the tree (2.7.0) and no dependency was added. It keeps the fix entirely insideconfig/scripts/and leaves production code untouched.I also swept every
bench:*entrypoint for this same failure shape. Exactly these two were affected; the rest either import nosrc/TypeScript or already go throughjiti/esbuild. One unwired script,config/scripts/terminal-reattach-payload-scan-benchmark.mjs, has the same shape but is not referenced by anypackage.jsonscript, so I left it alone rather than widen the diff — noting it here as a follow-up.Linked Issue
No pre-existing issue; internal developer-tooling fix found while running the benchmark.
Visual Proof
N/A— there is no UI, rendering, or user-visible behavior in this change. It only affects two developer benchmark scripts invoked from the command line; the app's runtime code is byte-for-byte unchanged.Testing
Platform tested: macOS (arm64). The change is pure module resolution in Node with no platform-dependent code, so no Linux/Windows/SSH-specific paths are involved.
Reproduced the failure first on
origin/main(0547b322), then verified the fix:Both ran to completion. The escape-tail benchmark self-checks 256 equivalence cases before timing, so its run also confirms the module loaded through
jitibehaves identically.Gates run locally, all passing:
pnpm teston the four covering suites —src/shared/terminal-partial-escape-tail.test.ts,terminal-partial-escape-tail-ground-scan.test.ts,terminal-partial-escape-tail.fuzz.test.ts,terminal-escape-introducer.test.ts— 4 files, 29 tests passedpnpm run check:code-quality:changed— 0 new findings across 2 changed filesoxlint— clean (exit 0)oxfmt --check— all matched files correctly formattedpnpm tc:node— clean (exit 0)I manually tested these changes locally
Automated tests added/updated, or explained why not below
No new automated test: the fix is that two hand-run benchmark scripts start at all, and the repo does not execute
bench:*scripts in CI. The existing suites listed above cover the modules being loaded and confirm nothing about them changed.Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
jitiresolution is platform-neutral and the four existingjitibenchmarks already run on all three.jitiadds a small transform cost to benchmark startup only; both benchmarks warm up and discard their first sample, so reported numbers are unaffected.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Co-authored-by: Claude [email protected]