rtk-ai/rtk

rtk vitest handler silently passes through Jest output — no compression when pnpm test runs Jest

Open

#1,345 创建于 2026年4月16日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)Rust (2,914 fork)batch import
area:clibugeffort-mediumfilter-qualityhelp wantedpriority:high

仓库指标

Star
 (48,085 star)
PR 合并指标
 (平均合并 11天 1小时) (30 天内合并 45 个 PR)

描述

Summary

The registry rule in src/discover/rules.rs matches vitest|jest|test and routes to rtk vitest, but the handler at src/cmds/js/vitest_cmd.rs parses only Vitest's JSON schema (numTotalTests, testResults[...]). Jest's JSON is shaped differently (numTestSuites, numPassTests). Tier-1 parse fails silently, Tier-2 regex partially catches text, Tier-3 falls through to raw output. Net effect on Jest repos: ~0 compression, no error surfaced.

Separately: the same rule's rewrite_prefixes does not include "pnpm test", so rtk rewrite "pnpm test" returns exit 1 even though the pattern matches — the command is classified as supported but fails to produce a rewritten form.

Reproduction

Environment: rtk v0.36.0 (Homebrew, macOS), zsh.

  1. Repo where pnpm test runs Jest (e.g., an Expo / React Native workspace)
  2. rtk rewrite \"jest\" → exit 3, rewrites to rtk vitest <args>
  3. rtk vitest on Jest's JSON output — parser fails, output passes through uncompressed
  4. rtk rewrite \"pnpm test\" → exit 1 (no rewrite), despite the regex matching

Impact

In a Next.js + Expo monorepo (web = Vitest, mobile = Jest), rtk discover reports pnpm test at 618 invocations / ~170K tokens saveable over 30 days. With the current handler, Jest-side invocations contribute near zero savings because the parser silently fails.

Proposed options (not prescribing)

(a) Separate rtk jest handler that parses Jest JSON; route jestrtk jest, keep vitestrtk vitest.

(b) Generic rtk pnpm-test wrapper that detects runner at runtime and dispatches — covers mixed monorepos where pnpm test runs different runners per workspace.

(c) Extend rtk vitest with a second JSON tier for Jest before regex fallback. Smallest change, conflates two tools.

Plus a tiny fix regardless of shape: add \"pnpm test\" to rewrite_prefixes so the existing rule actually emits a rewrite.

Happy to open a PR once you pick the shape.

Related

Config-level workaround tracked separately in #1344 (would let users auto-allow jest/vitest without redesigning the handler).

贡献者指南