Skip to content

specmem impact

Analyze the impact of code changes on specifications.

Usage

specmem impact [OPTIONS]

Description

Identifies which specifications and tests are affected by code changes using the impact graph.

Options

Option Description Default
--files, -f FILES Files to analyze required*
--git-diff Use git diff for changed files false
--git-staged Use git staged files false
--tests Include test recommendations false
--depth INT Traversal depth 2
--format FORMAT Output format (text, json, list) text
--verbose, -v Show detailed output false

*One of --files, --git-diff, or --git-staged is required.

Examples

Analyze Specific Files

specmem impact --files src/auth/service.py

Output:

๐Ÿ“Š Impact Analysis

Changed files:
  โ€ข src/auth/service.py

๐ŸŽฏ Directly Impacted Specs (2):
  โ€ข auth/requirements.md
  โ€ข auth/design.md

๐Ÿ”— Transitively Impacted (2):
  โ€ข api-security/design.md
  โ€ข session-management/tasks.md

Total: 4 specs impacted

Multiple Files

specmem impact --files src/auth/service.py src/auth/models.py src/auth/routes.py

With Test Recommendations

specmem impact --files src/auth/service.py --tests

Output:

๐Ÿ“Š Impact Analysis

Changed files:
  โ€ข src/auth/service.py

๐ŸŽฏ Directly Impacted Specs (2):
  โ€ข auth/requirements.md
  โ€ข auth/design.md

๐Ÿงช Recommended Tests (4):
  โ€ข tests/test_auth.py::test_login
  โ€ข tests/test_auth.py::test_logout
  โ€ข tests/test_auth.py::test_token_refresh
  โ€ข tests/integration/test_auth_flow.py::test_full_flow

โฑ๏ธ  Estimated time: 45s (vs 8m for full suite)

From Git Diff

specmem impact --git-diff

From Staged Changes

specmem impact --git-staged

Deeper Analysis

specmem impact --files src/auth/service.py --depth 3

JSON Output

specmem impact --files src/auth/service.py --format json

Output:

{
  "changed_files": ["src/auth/service.py"],
  "direct_specs": [
    {
      "path": "auth/requirements.md",
      "relationship": "implemented_by"
    }
  ],
  "transitive_specs": [
    {
      "path": "api-security/design.md",
      "relationship": "depends_on",
      "via": "auth/requirements.md"
    }
  ],
  "recommended_tests": [
    "tests/test_auth.py::test_login",
    "tests/test_auth.py::test_logout"
  ]
}

List Output (for piping)

# Get just test paths
specmem impact --files src/auth/service.py --tests --format list

Output:

tests/test_auth.py::test_login
tests/test_auth.py::test_logout
tests/test_auth.py::test_token_refresh

Pipe to pytest

pytest $(specmem impact --files src/auth/service.py --tests --format list)

CI Integration

# GitHub Actions
- name: Get impacted tests
  run: |
    TESTS=$(specmem impact --git-diff --tests --format list)
    if [ -n "$TESTS" ]; then
      pytest $TESTS
    fi

See Also