From 263249029b0b3bd5baabf42e16673f0e78ad0173 Mon Sep 17 00:00:00 2001 From: goodboy Date: Tue, 14 Apr 2026 17:33:46 -0400 Subject: [PATCH] Add `lastfailed` cache inspection to `/run-tests` skill MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New "Inspect last failures" section reads the pytest `lastfailed` cache JSON directly — instant, no collection overhead, and filters to `tests/`-prefixed entries to avoid stale junk paths. Also, - add `jq` tool permission for `.pytest_cache/` files (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- .claude/skills/run-tests/SKILL.md | 44 ++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/.claude/skills/run-tests/SKILL.md b/.claude/skills/run-tests/SKILL.md index 1d2b284a..f185c927 100644 --- a/.claude/skills/run-tests/SKILL.md +++ b/.claude/skills/run-tests/SKILL.md @@ -12,6 +12,7 @@ allowed-tools: - Bash(UV_PROJECT_ENVIRONMENT=py* uv sync *) - Bash(ls *) - Bash(cat *) + - Bash(jq * .pytest_cache/*) - Read - Grep - Glob @@ -217,7 +218,48 @@ python -c 'import tractor' && python -m pytest tests/ -x -q --co 2>&1 | tail -3 python -m pytest tests/test_local.py tests/test_rpc.py tests/test_spawning.py tests/discovery/test_registrar.py -x --tb=short --no-header ``` -### Re-run last failures only: +### Inspect last failures (without re-running): + +When the user asks "what failed?", "show failures", +or wants to check the last-failed set before +re-running — read the pytest cache directly. This +is instant and avoids test collection overhead. + +```sh +python -c " +import json, pathlib, sys +p = pathlib.Path('.pytest_cache/v/cache/lastfailed') +if not p.exists(): + print('No lastfailed cache found.'); sys.exit() +data = json.loads(p.read_text()) +# filter to real test node IDs (ignore junk +# entries that can accumulate from system paths) +tests = sorted(k for k in data if k.startswith('tests/')) +if not tests: + print('No failures recorded.') +else: + print(f'{len(tests)} last-failed test(s):') + for t in tests: + print(f' {t}') +" +``` + +**Why not `--cache-show` or `--co --lf`?** + +- `pytest --cache-show 'cache/lastfailed'` works + but dumps raw dict repr including junk entries + (stale system paths that leak into the cache). +- `pytest --co --lf` actually *collects* tests which + triggers import resolution and is slow (~0.5s+). + Worse, when cached node IDs don't exactly match + current parametrize IDs (e.g. param names changed + between runs), pytest falls back to collecting + the *entire file*, giving false positives. +- Reading the JSON directly is instant, filterable + to `tests/`-prefixed entries, and shows exactly + what pytest recorded — no interpretation. + +**After inspecting**, re-run the failures: ```sh python -m pytest --lf -x --tb=short --no-header ```