run-affected-tests
Use when tests take too long and the user wants to run only the tests that matter, see which tests cover a change, check test impact, or skip the full suite. Selects and runs the smallest set of affected tests, states why each test belongs, and widens for blind spots the import g
Install
npx skills add https://github.com/Heyvhuang/copybook-skills/tree/main/plugins/skills/skills/run-affected-tests
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install heyvhuang-copybook-skills@llmmart
git clone https://github.com/Heyvhuang/copybook-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole heyvhuang/copybook-skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Run affected tests
Running the whole test suite after every edit slows down feedback, while guessing tests by file name misses indirect callers and runtime loads. Trace static dependencies from the diff to test files, widen for blind spots the import graph cannot see, and run only that set with a clear reason why it covers the change.
1. List changed files from the diff
Find the base commit for the change, such as the merge base with the default branch or the commit range the user names. Collect every added, modified, renamed, and deleted file from that diff, along with staged, unstaged, and relevant untracked edits.
Sort the changed paths into four groups: source files, test files, fixtures or snapshots, and config or environment files. Add every modified test file to the run set right away and record its reason as a direct test edit.
2. Walk the reverse import graph
Start from each changed source file and find every file that statically imports or requires it. Follow incoming edges through intermediate modules, re-exports, wildcard exports, and index barrel files until each path reaches a test file or ends with no more callers.
Resolve path aliases, workspace package names, and implicit index files from the project's module config so chains do not stop early at folder or package boundaries. Add each reached test file to the run set and save the import chain from the changed file as its reason. Keep out tests that have no static path or blind-spot link to the change.
3. Add tests the graph cannot see
Search test files and shared test helpers for links that static import tracing misses:
- Dynamic imports or
requirecalls with computed paths, variables, or string templates that could load a changed file or its barrel. - Snapshots, fixtures, golden files, or other disk assets that tests read when the asset changed in the diff or captures output from a changed module.
- Changes to build rules, test runner config, shared test setup, lockfiles, or environment definitions.
Include every test file that executes a matching dynamic import or loads a matching fixture or snapshot, and mark it as a blind-spot addition. When you cannot narrow a dynamic loader to specific test files, or when config, shared setup, or environment files change, widen the run set to that package's test suite (or the full suite for repository-wide config) and record what triggered the widening.
4. Run the set and report coverage
Run only the selected test files and any widened suites through the project's test runner using explicit file or suite paths. If a failure exposes another affected module, update the set and rerun before finishing.
Show the user four details in the final report:
- The exact test command you ran and the pass or fail counts, including how many test files ran out of the full suite.
- Each selected test file with its concrete reason: direct edit, reverse import chain through any barrels, snapshot or fixture link, or blind-spot widening.
- Every blind spot you found and how you widened the set for it, or an explicit statement that none applied.
- A brief summary stating why the selected set is enough to cover the change.
Based on Copybook original (CC BY 4.0), rewritten by Copybook.
Files (copybook-skills)
-
CHANGES.md 337 B
Loading… -
example.md 1.1 KB
Loading… -
LICENSE 18.2 KB · in bundle
-
SKILL.md 3.6 KB
--- name: run-affected-tests description: "Use when tests take too long and the user wants to run only the tests that matter, see which tests cover a change, check test impact, or skip the full suite. Selects and runs the smallest set of affected tests, states why each test belongs, and widens for blind spots the import graph misses. Not for proving a claim before saying done (verify-work-done)." license: CC-BY-4.0 (see LICENSE) --- # Run affected tests Running the whole test suite after every edit slows down feedback, while guessing tests by file name misses indirect callers and runtime loads. Trace static dependencies from the diff to test files, widen for blind spots the import graph cannot see, and run only that set with a clear reason why it covers the change. ## 1. List changed files from the diff Find the base commit for the change, such as the merge base with the default branch or the commit range the user names. Collect every added, modified, renamed, and deleted file from that diff, along with staged, unstaged, and relevant untracked edits. Sort the changed paths into four groups: source files, test files, fixtures or snapshots, and config or environment files. Add every modified test file to the run set right away and record its reason as a direct test edit. ## 2. Walk the reverse import graph Start from each changed source file and find every file that statically imports or requires it. Follow incoming edges through intermediate modules, re-exports, wildcard exports, and index barrel files until each path reaches a test file or ends with no more callers. Resolve path aliases, workspace package names, and implicit index files from the project's module config so chains do not stop early at folder or package boundaries. Add each reached test file to the run set and save the import chain from the changed file as its reason. Keep out tests that have no static path or blind-spot link to the change. ## 3. Add tests the graph cannot see Search test files and shared test helpers for links that static import tracing misses: - Dynamic imports or `require` calls with computed paths, variables, or string templates that could load a changed file or its barrel. - Snapshots, fixtures, golden files, or other disk assets that tests read when the asset changed in the diff or captures output from a changed module. - Changes to build rules, test runner config, shared test setup, lockfiles, or environment definitions. Include every test file that executes a matching dynamic import or loads a matching fixture or snapshot, and mark it as a blind-spot addition. When you cannot narrow a dynamic loader to specific test files, or when config, shared setup, or environment files change, widen the run set to that package's test suite (or the full suite for repository-wide config) and record what triggered the widening. ## 4. Run the set and report coverage Run only the selected test files and any widened suites through the project's test runner using explicit file or suite paths. If a failure exposes another affected module, update the set and rerun before finishing. Show the user four details in the final report: - The exact test command you ran and the pass or fail counts, including how many test files ran out of the full suite. - Each selected test file with its concrete reason: direct edit, reverse import chain through any barrels, snapshot or fixture link, or blind-spot widening. - Every blind spot you found and how you widened the set for it, or an explicit statement that none applied. - A brief summary stating why the selected set is enough to cover the change. Based on Copybook original (CC BY 4.0), rewritten by Copybook.
Reviews (0)
No reviews yet.
Comments
Sign in to join the conversation.
No comments yet. Start the conversation.