Skip to content

loopguard: pnpm --filter web test, npm -w web test, npm t and pnpm vitest run are not counted as test runs #335

Backlog

Description

The loop guard's test-run pattern (VERIFY_RE in tokeneconomizer/loopguard/turn.py) reads npm test, pnpm test and yarn test only right after the package manager. It misses:

  • a workspace or folder named first, as monorepos do: pnpm --filter web test, pnpm -r test, npm -w web test, npm --prefix web test, yarn --cwd web test, yarn workspace web test
  • npm's and pnpm's aliases of test: npm t, npm tst, pnpm t
  • pnpm and yarn running an installed runner by name: pnpm vitest run, pnpm jest, yarn jest, yarn vitest run

So when one of these fails after the last edit, the turn still counts as ended green and feeds the envelope.

I'd like to fix this: read each manager's own options (with the value of those that take one: npm's -w/--workspace and -C/--prefix, pnpm's -F/--filter and -C/--dir, yarn's --cwd), the aliases, and the runners, with tests for what should and should not count. I'll open a PR shortly.

Activity

  1. github-actions commented on Nov 26, 2026

    @github-actions

    Scout plan

    Issue: #335 — loopguard: pnpm --filter web test, npm -w web test, npm t and pnpm vitest run are not counted as test runs

    Understanding

    VERIFY_RE in tokeneconomizer/loopguard/turn.py (line ~66) matches (?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test only, so manager options before the script, the t/tst aliases, and pnpm|yarn <runner> are read as non-test commands. A failing run of those after the last edit then counts as a green turn end. The end state is that these forms count as test runs, while non-runs (installs, --help, wrong script names) still do not. The issue author says they will open the PR.

    Approach

    1. In tokeneconomizer/loopguard/turn.py, add a named sub-pattern (like _GRADLE_TASKS or _MAKE_VALUE) for each manager's options before the script, and use it in VERIFY_RE in place of the bare (?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test:

      • npm: -w/--workspace and -C/--prefix take a value (= or space); other -x/--long flags do not. -ws, --workspaces take none.
      • pnpm: -F/--filter and -C/--dir take a value; -r/--recursive takes none.
      • yarn: --cwd takes a value; yarn workspace <name> test is its own form.
      • Aliases: npm t|tst|test, pnpm t|test (npm accepts run test/run-script; keep the existing run). Do not add yarn t.
      • Runners: pnpm|yarn (?:exec\s+)?(?:jest|vitest|mocha|ava|playwright test).

      Keep the option value tokens bounded (no nested unbounded (\S+\s*)*), as the make pattern's comment warns about backtracking. Keep the final (?![\w.\-/]) guard so npm test:unit-style and pnpm tsx stay judged as before.

    2. Check the interaction with _PREFIX_RE (pnpm exec/yarn dlx prefixes) and _NOT_A_RUN_RE: pnpm --filter web test --help must still not count. -w/--prefix values that look like test (npm --prefix test install) must not match.

    3. Tests: add a parametrized case in tests/test_loopguard_productive_turns.py (or a new tests/test_loopguard_node_runners.py) calling VERIFY_RE.match(_PREFIX_RE.sub("", cmd)) or going through TurnGuard.fold, with positives (every form listed in the issue) and negatives (npm install, pnpm --filter web build, npm --prefix test install, npm run testbed, pnpm --filter web test --help, yarn workspace web add x). Also add a TurnGuard case showing a failed pnpm --filter web test after an edit is not a green turn end.

    4. No on-disk state, setting or event-kind names change, and no plugin user-visible text changes.

    Verification

    • python -m pytest tests/test_loopguard_productive_turns.py tests/test_loopguard_jvm_builds.py tests/test_live_core.py -q
    • python -m pytest tests experiments/tests -q
    • Replay a few recorded Node/pnpm sessions through TurnGuard before and after, and confirm only the turns that ran the newly matched forms change their verdict. Also time the regex on a long option line to rule out backtracking.

    Open questions

    None.


    Reply confirm to have scout implement this plan on a scout/issue-335 branch and link a one-click pull request (write access required). Reply /scout to plan again after editing the issue; text after the command is guidance for the new plan.

    Generated by Scout for #335 · claude · sonnet55 · ~17 AIC · ⌖ ~16 AIC · ⊞ 2.6K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions