dsh-test-impact
Static test impact analysis for Python/pytest projects. Available as a DeepSeek Harness plugin and a command-line tool.
For each changed file, the analyser follows reverse import dependencies to find related tests. Results include dependency paths, unresolved imports and recommendations to widen the test run. It does not execute the project's code or tests. Selected tests are a starting point, not a guarantee that other tests can be skipped.
Requirements
- Node.js 24.9 or later
- Python 3.11 or later
- Git for working-tree and revision comparisons; explicit file lists work without Git
The analyser uses the Python standard library. Interpreter selection: plugin pythonPath, DSH_TEST_IMPACT_PYTHON, python3, Windows py -3, then python. Set the interpreter explicitly if automatic detection fails. Python runs in isolated mode without site startup customisations.
Installation
In DSH, open Plugins → Add plugin and enter:
https://github.com/DengyiGu/dsh-test-impact
Or install a tagged version:
dsh plugin --profile web add github:DengyiGu/dsh-test-impact#v0.1.0
For the standalone CLI:
npm install -g github:DengyiGu/dsh-test-impact#v0.1.0
dsh-test-impact --help
Releases also provide a .tgz. No compilation or installation scripts are required. Bare package-name installation requires a separate npm publication.
DSH tools
test_impact({ repo: 'C:/work/project', changed: ['src/app/core.py'], depth: 6 })
dep_graph({ repo: 'C:/work/project', module: 'app.core', direction: 'dependents', depth: 3 })
test_impact accepts repo, optional base or changed, depth, maxFiles and maxSeconds. Omit base and changed to compare the current working tree with HEAD. An explicit empty changed array means no changes and does not invoke Git.
dep_graph accepts a dotted module name or relative Python path. direction is dependencies or dependents. Each edge includes the importing file and source line.
Plugin settings: pythonPath, timeoutMs (default 120000), maxFiles and maxSeconds (0 uses project defaults for the latter two).
CLI
dsh-test-impact analyze --repo /path/to/repo --json
dsh-test-impact analyze --repo /path/to/repo --base main --json
dsh-test-impact analyze --repo /path/to/repo --changed app/core.py
dsh-test-impact graph app.core --repo /path/to/repo --reverse
dsh-test-impact doctor --repo /path/to/repo --json
From a checkout, use node bin/dsh-test-impact.mjs or python python/launch.py in place of dsh-test-impact.
Default comparison includes staged, unstaged and untracked changes relative to HEAD. --base compares the named commit to the current tree, including untracked files. Use the Git repository root. Deleted and renamed files are flagged for broader verification; the entire historical dependency graph is not reconstructed.
Exit codes: 0 analysis complete, 1 usage/processing error, 2 incomplete analysis, 3 Git repository or revision error. Code 0 does not certify a change as safe.
Results
recommended: test paths, evidence type and dependency chains.widening: scopes that should receive broader verification, with reasons.unassociated: changed files without a known static test dependency. This does not mean they have no tests.unresolved: imports and runtime behavior the analyser could not resolve.analysis.complete: whether scanning and resolution completed within supported limits.
Recommendations include direct/transitive imports, changed tests, pytest directory scope and configuration changes. Naming hints are listed separately. Dynamic imports, unresolved dependencies and pytest hooks trigger full configured-scope guidance when changes exist, including cross-package cases. Package initialisation, non-Python inputs, deletions, renames and invalid configuration also widen the run.
Configuration
Reads pytest discovery settings from pytest.ini, pyproject.toml, tox.ini or setup.cfg. Supported settings include testpaths, python_files and norecursedirs. Collection options outside supported static behavior are reported.
Project-specific settings use pyproject.toml:
[tool.test-impact]
source_roots = ["src", "."]
test_roots = ["tests"]
extra_paths = ["vendor"]
always_run = ["tests/test_smoke.py"]
max_files = 20000
max_seconds = 60
Common virtual environments, caches and build directories are excluded. Directory/file links are skipped and reported as an incomplete scan. Explicit changed paths outside the repository are rejected.
Disk caching is off by default. Enable it explicitly with --cache-dir /path/to/cache; use --no-cache to disable it for a call. Only parsed facts are cached, using content hashes and configuration keys. The cache can be cleared with dsh-test-impact cache --repo /path/to/repo --cache-dir /path/to/cache. Enabling caching may make small repositories slower.
Development
npm run verify
npm run integration
npm run perf
npm pack
Tests use project-owned sample repositories. Integration checks compare recommendations with actual pytest failures after known mutations. Synthetic performance trees measure cold/warm scans and cache equivalence. These checks do not prove selection accuracy for arbitrary repositories.
Release review: 83 Python tests and 11 Node tests passed. Three integration scenarios had zero failures outside recommendations or widening guidance; one dynamic-import failure required widening. On a generated 501-file tree, an uncached scan took about 203 ms (median of three); warm caching took about 210 ms on the review machine. Timings are machine-specific.
The packaged adapter was also registered and invoked directly with actual Cordis/ToolsService libraries, with host output-schema validation. The system-prompt dependency used a minimal callback sink. Full DSH application startup and conversation-driven invocation remain unverified.
Limitations
Arbitrary dynamic loading, native code, environment changes and external data dependencies cannot be fully inferred from Python imports. Some pytest collection behavior and namespace layouts are unsupported. Large graphs or ambiguous dependencies may result in broad recommendations. The plugin does not run tests, edit source files or write a disk cache unless explicitly requested.
License
MIT.
No comments yet. Be the first to write one.