Tools for spec-driven development - validate specifications, test coverage, file structure, and documentation links
Project description
spec-check
Tools for spec-driven development - a toolkit for managing and validating project specifications and files.
Features
Lint Tool
The lint tool validates that all files in your repository match patterns in an allowlist. Think of it as the inverse of .gitignore - instead of specifying what to ignore, you specify what files are allowed.
Key features:
- Uses gitignore-style glob patterns for flexible file matching
- Respects
.gitignorepatterns by default - Supports complex patterns including character classes (e.g.,
[0-9]) - Validates that all tracked files match at least one allowlist pattern
- Reports unmatched files for easy identification
Markdown Link Validator
The check-links tool validates hyperlinks in markdown files to ensure documentation stays up-to-date and accessible.
Key features:
- Validates internal links (relative paths) resolve correctly
- Checks anchor links point to existing headings
- Validates external URLs are accessible
- Supports private URL patterns that are skipped during validation
- Concurrent external URL checking for performance
- Respects
.gitignorepatterns by default
Spec Coverage Validator
The check-coverage tool ensures 100% traceability between specification requirements and tests.
Key features:
- Extracts requirement IDs from spec files (e.g., REQ-001, NFR-001)
- Validates every requirement has at least one corresponding test
- Reports coverage percentage and uncovered requirements
- Uses pytest markers for machine-readable test-to-requirement linking
- Identifies tests without requirement markers
Structure Validator
The check-structure tool enforces consistent spec-to-test structure alignment.
Key features:
- Verifies each spec file has a corresponding test file or directory
- Supports flexible naming conventions (kebab-case to snake_case)
- Allows unit tests without corresponding specs
- Reports specs without tests
- Ensures consistent project organization
Installation
Using uv (recommended)
uv pip install spec-check
Using pip
pip install spec-check
Development installation
# Clone the repository
git clone https://github.com/TradeMe/spec-check.git
cd spec-check
# Install with uv
uv venv
uv pip install -e ".[dev]"
Configuration
spec-check can be configured via pyproject.toml for seamless integration with Python projects. This allows you to set default options without needing to pass command-line arguments every time.
pyproject.toml Configuration
Add a [tool.spec-check] section to your pyproject.toml:
[tool.spec-check.lint]
allowlist = ".specallowlist"
use_gitignore = true
[tool.spec-check.check-links]
config = ".speclinkconfig"
timeout = 15
max_concurrent = 5
check_external = true
use_gitignore = true
[tool.spec-check.check-schema]
config = ".specschemaconfig"
use_gitignore = true
Configuration Options
Lint Command ([tool.spec-check.lint])
allowlist(string): Path to allowlist file (default:.specallowlist)use_gitignore(boolean): Respect .gitignore patterns (default:true)
Check Links Command ([tool.spec-check.check-links])
config(string): Path to config file for private URLs (default:.speclinkconfig)timeout(integer): Timeout for external URL requests in seconds (default:10)max_concurrent(integer): Maximum concurrent external URL requests (default:10)check_external(boolean): Validate external URLs (default:true)use_gitignore(boolean): Respect .gitignore patterns (default:true)
Check Schema Command ([tool.spec-check.check-schema])
config(string): Path to schema config file (default:.specschemaconfig)use_gitignore(boolean): Respect .gitignore patterns (default:true)
Configuration Precedence
Configuration values are resolved in the following order (highest to lowest precedence):
- Command-line arguments (e.g.,
--timeout 30) - pyproject.toml configuration (e.g.,
timeout = 15in[tool.spec-check.check-links]) - Built-in defaults
This means you can set project defaults in pyproject.toml and override them on the command line when needed.
Usage
Lint Command
Create a .specallowlist file in your project root with gitignore-style patterns:
# Documentation
*.md
docs/**/*.rst
# Source code
spec_check/**/*.py
tests/**/*.py
# Configuration files
*.toml
*.yaml
*.yml
# Specs with specific naming convention
specs/research-[0-9][0-9][0-9]-*.md
specs/design-*.md
Then run the linter:
# Lint the current directory
spec-check lint
# Lint a specific directory
spec-check lint /path/to/project
# Use a custom allowlist file
spec-check lint --allowlist .myallowlist
# Don't respect .gitignore patterns
spec-check lint --no-gitignore
# Verbose output
spec-check lint --verbose
Exit Codes
0: All files match the allowlist patterns1: Some files don't match or an error occurred
This makes it easy to integrate into CI/CD pipelines:
# .github/workflows/ci.yml
- name: Validate file allowlist
run: spec-check lint
Check Links Command
Validate all hyperlinks in your markdown documentation:
# Check links in current directory
spec-check check-links
# Check links in a specific directory
spec-check check-links /path/to/docs
# Skip external URL validation (faster)
spec-check check-links --no-external
# Use a custom config file for private URLs
spec-check check-links --config .myconfigfile
# Set timeout for external URLs (default: 10 seconds)
spec-check check-links --timeout 30
# Limit concurrent requests (default: 10)
spec-check check-links --max-concurrent 5
# Verbose output
spec-check check-links --verbose
Private URL Configuration
Create a .speclinkconfig file to specify private URL patterns that should not be validated:
# Private domains (will skip any URL containing these domains)
internal.company.com
localhost
# Private URL prefixes (exact prefix match)
https://private.example.com/
http://localhost:
http://127.0.0.1:
What Gets Validated
- Internal links:
[text](./file.md)- checked relative to the markdown file - Anchor links:
[text](#heading)- validated against headings in the file - Cross-file anchors:
[text](./other.md#section)- validates both file and heading - External URLs:
[text](https://example.com)- HTTP request to verify accessibility - Private URLs: URLs matching configured patterns are skipped
CI/CD Integration
# .github/workflows/ci.yml
- name: Validate documentation links
run: spec-check check-links --no-external # Skip external URLs in CI
Check Coverage Command
Ensure all spec requirements have corresponding tests:
# Check coverage in current directory
spec-check check-coverage
# Check coverage in a specific directory
spec-check check-coverage /path/to/project
# Use custom specs and tests directories
spec-check check-coverage --specs-dir my-specs --tests-dir my-tests
Marking Tests with Requirements
Use pytest markers to link tests to requirements:
import pytest
@pytest.mark.req("REQ-001")
def test_inline_link_parsing():
"""Test that inline links are parsed correctly."""
# Test implementation
assert True
# For tests covering multiple requirements:
@pytest.mark.req("REQ-002", "REQ-003")
def test_reference_style_links():
"""Test reference-style link parsing."""
# Test implementation
assert True
CI/CD Integration
# .github/workflows/ci.yml
- name: Validate spec coverage
run: spec-check check-coverage
Check Structure Command
Validate spec-to-test structure alignment:
# Check structure in current directory
spec-check check-structure
# Check structure in a specific directory
spec-check check-structure /path/to/project
# Use custom specs and tests directories
spec-check check-structure --specs-dir my-specs --tests-dir my-tests
Structure Conventions
For a spec file specs/feature-name.md, the tool expects either:
tests/test_feature_name.py(single test file)tests/feature_name/(test directory)
This allows unit tests without corresponding specs while ensuring all specs have requirement tests.
CI/CD Integration
# .github/workflows/ci.yml
- name: Validate spec structure
run: spec-check check-structure
Pattern Syntax
The allowlist uses gitignore-style glob patterns:
*- matches any number of characters (except/)**- matches any number of directories?- matches a single character[abc]- matches one character in the set[0-9]- matches one character in the range!pattern- negates a pattern (matches files that don't match the pattern)
Examples
# Match all Python files
*.py
# Match Python files in src directory and subdirectories
src/**/*.py
# Match numbered specification files
specs/spec-[0-9][0-9][0-9].md
# Match files with specific naming pattern
docs/architecture-*.md
docs/design-*.md
# Match multiple file types
*.{yml,yaml}
Use Cases
- Enforce file organization: Ensure all files follow your project's structure
- Validate spec compliance: Make sure all files match expected patterns
- CI/CD validation: Automatically check that no unexpected files are committed
- Documentation enforcement: Ensure all code files have matching documentation
- Naming convention enforcement: Validate files follow naming standards
- Test-to-requirement traceability: Guarantee 100% requirement coverage with automated validation
- Spec-driven development: Enforce consistent spec-to-test structure for better maintainability
- Documentation quality: Ensure all links in documentation are valid and up-to-date
Example: Research Paper Repository
# .specallowlist
# Papers must follow naming: research-NNN-title.md
papers/research-[0-9][0-9][0-9]-*.md
# Supporting data files
papers/data-[0-9][0-9][0-9]-*.csv
papers/figures-[0-9][0-9][0-9]-*.{png,jpg,svg}
# Project files
*.md
LICENSE
.gitignore
.specallowlist
Development
Running Tests
# Activate virtual environment
source .venv/bin/activate
# Run tests
pytest tests/ -v
# Run tests with coverage
pytest tests/ -v --cov=spec_check --cov-report=term-missing
Linting
# Check code with ruff
ruff check spec_check/ tests/
# Format code with ruff
ruff format spec_check/ tests/
Building
# Build with flit
uv pip install flit
flit build
Roadmap
Future tools planned for spec-check:
- spec-graph: Visualize dependencies between spec files
- spec-init: Initialize new spec-driven projects
- spec-sync: Keep specs in sync with implementation
- spec-extract: Extract requirements from code comments into spec files
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spec_check-0.1.4.tar.gz.
File metadata
- Download URL: spec_check-0.1.4.tar.gz
- Upload date:
- Size: 220.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d8e4cee99a678518a6b93d446a69d0acd261e35daf4a70adf7150f1164d1f14
|
|
| MD5 |
372029c64094aa348a8940b20b298a65
|
|
| BLAKE2b-256 |
b4f49a17aa1d15fca79f3c702897e01eee41e367666bf563f9b85a38c2ffe460
|
Provenance
The following attestation bundles were made for spec_check-0.1.4.tar.gz:
Publisher:
create-release.yml on TradeMe/spec-check
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spec_check-0.1.4.tar.gz -
Subject digest:
8d8e4cee99a678518a6b93d446a69d0acd261e35daf4a70adf7150f1164d1f14 - Sigstore transparency entry: 653537383
- Sigstore integration time:
-
Permalink:
TradeMe/spec-check@c259334e65a2dcbaee01c37b53943c1c1fdd4cb9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TradeMe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
create-release.yml@c259334e65a2dcbaee01c37b53943c1c1fdd4cb9 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file spec_check-0.1.4-py3-none-any.whl.
File metadata
- Download URL: spec_check-0.1.4-py3-none-any.whl
- Upload date:
- Size: 63.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b266efcbdc3a201e1a339cde9387a6aeb61a0025e107e43f3ee1b5805d896fe
|
|
| MD5 |
0181db703e1f5db80eb8baf8c8247432
|
|
| BLAKE2b-256 |
a92ffe894f691d63d777de68d18fa16849a7a5a403774545db9fe41929a3ed4d
|
Provenance
The following attestation bundles were made for spec_check-0.1.4-py3-none-any.whl:
Publisher:
create-release.yml on TradeMe/spec-check
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spec_check-0.1.4-py3-none-any.whl -
Subject digest:
7b266efcbdc3a201e1a339cde9387a6aeb61a0025e107e43f3ee1b5805d896fe - Sigstore transparency entry: 653537386
- Sigstore integration time:
-
Permalink:
TradeMe/spec-check@c259334e65a2dcbaee01c37b53943c1c1fdd4cb9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TradeMe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
create-release.yml@c259334e65a2dcbaee01c37b53943c1c1fdd4cb9 -
Trigger Event:
pull_request
-
Statement type: