| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
feat(scripts): add :agent variants for running tests (and other slow commands) (#832) ## At a glance ```bash $ pnpm test:packages:agent log: wip/test-packages.20260615-190441.32317.log $ grep -nE " FAIL |Test Files" wip/test-packages.20260615-190441.32317.log … ``` The `:agent` variant runs the canonical command, redirects its full output to a timestamped file under `wip/`, prints that path as its first line of output, and exits with the same status as the underlying command. The agent uses the exact path the script just announced. ## The decision Every slow verification command — `test:packages`, `test:integration`, `test:e2e`, `build`, `typecheck`, `lint`, `lint:deps`, `fixtures:check` — gets an `:agent` variant. Agents use the `:agent` form; canonical commands are unchanged for humans and CI. Each variant writes `wip/<name>.<YYYYMMDD-HHMMSS>.<pid>.log` and a sibling `.exit`, then prints the log path. Every run gets a unique filename so history is preserved automatically. `wip/.gitkeep` is committed; everything else under `wip/` is gitignored. A new always-apply rulecard, `.agents/rules/running-tests.mdc`, documents the workflow: 1. Run a test suite (use the `:agent` variant). 2. Run one package's tests (`pnpm --filter <pkg> test`). 3. Rerun a specific failing test (by file, or by test name with vitest `-t`). 4. Find specific failures in the captured output (grep the log path the `:agent` printed). ## Why this matters Sampled from one Drive session, ~90 min in a single subagent: - 4× `pnpm test:packages` (~150s each) chasing the same failure list - 4× `pnpm test:integration` for the same reason - 11× `pnpm fixtures:check` re-runs grepping different slices of the same output - 3× `pnpm turbo typecheck --force` in the same minute ~25 min of pure re-run waste in one subagent. The cause: piping `pnpm test:packages` to `tail`/`grep`/`head` discards the rest of the output and hides the exit code (those tools return 0). The next question about the failure forces a full re-run. A rulecard alone would tell agents "redirect to a file, then grep it" — standing guidance they have to remember and apply. The `:agent` scripts bake the pattern into the command. Affordance, not memory. ## What's in this PR - **8 new package.json scripts**, one per slow command. Each follows the same shell template: ``` ts=$(date +%Y%m%d-%H%M%S).$$; log=wip/<name>.$ts.log; echo "log: $log"; \ pnpm <name> > "$log" 2>&1; status=$?; \ echo $status > wip/<name>.$ts.exit; exit $status ``` - **`.agents/rules/running-tests.mdc`** (always-apply), symlinked into `.cursor/rules/` and `.claude/rules/` by the existing `pnpm rules:sync`. - **`wip/.gitkeep`** committed; `.gitignore` now reads `/wip/*` + `!/wip/.gitkeep`. - Rules-footprint thresholds bumped to fit the new always-apply rule. ## Alternatives considered - **A helper script (`scripts/agent-run.sh`).** Each `:agent` is one self-contained shell statement; no shared library to maintain. - **A skill** (`skills-contrib/running-tests/`). Skills are procedural workflows you *invoke*; "always run tests this way" is standing guidance, which is what `.agents/rules/*.mdc` is for. - **Stable symlinks** `wip/<name>.log` → latest run. Tried, removed. The script prints the exact log path, so the read path is unambiguous — no need for a "latest" abstraction. - **`mkdir -p wip` prefix in every script.** Replaced by committing `wip/.gitkeep` — the directory always exists, the scripts stay short. - **Overwriting a single log per command.** First iteration. Broke the "run full → fix → run full again, compare" workflow. Replaced by timestamped + PID-suffixed filenames; history is preserved automatically. - **A structured (`--reporter=json`) reporter on the first run.** Plausible but unnecessary — everything an agent does is programmatic; the agent reads the same human-readable log a human would, and `grep`/`tail` work fine against it. ## Verification - `pnpm lint:deps:agent` end-to-end: prints `log: wip/lint-deps.<ts>.<pid>.log`, writes the log + `.exit`, exits with the right status. - `pnpm lint:rules:footprint` — passes after threshold bumps. - `pnpm lint:rules:symlinks` — symlink trees consistent. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> --------- Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> | 2 个月前 |