Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/dimtensor-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Coverage dashboard

# v5.2.0 task #274: Public coverage reports.
# Runs the test suite with coverage, uploads to Codecov, and publishes
# an HTML coverage report as a GitHub Pages artifact.

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
coverage:
name: Generate coverage report
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: |
pip install --upgrade pip
pip install -e ".[dev]"
pip install hypothesis coverage[toml] pytest-cov

- name: Run tests with coverage
run: |
pytest \
--cov=dimtensor \
--cov-report=xml:coverage.xml \
--cov-report=html:htmlcov \
--cov-report=term-missing \
--cov-report=json:coverage.json \
--ignore=tests/test_numba.py \
-m "not slow" \
-q

- name: Generate coverage badge
run: |
python -c "
import json
with open('coverage.json') as f:
data = json.load(f)
pct = data['totals']['percent_covered']
color = 'red' if pct < 50 else 'orange' if pct < 70 else 'yellow' if pct < 85 else 'success'
badge = {
'schemaVersion': 1,
'label': 'coverage',
'message': f'{pct:.1f}%',
'color': color,
}
with open('coverage-badge.json', 'w') as f:
json.dump(badge, f)
print(f'Coverage: {pct:.1f}%')
"

- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.xml
coverage.json
coverage-badge.json
htmlcov/
retention-days: 30

- name: Upload to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: dimtensor-coverage
fail_ci_if_error: false

- name: Comment coverage on PR
if: github.event_name == 'pull_request'
uses: orgoro/coverage@v3.2
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
145 changes: 145 additions & 0 deletions .github/workflows/dimtensor-security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Security audit

# v5.2.0 task #275: SAST/DAST scanning + dependency vulnerability checks.
#
# Runs on every push to main, on pull requests, and weekly to catch new
# advisories on existing dependencies.

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
# Run every Monday at 08:00 UTC
- cron: '0 8 * * 1'
workflow_dispatch:

permissions:
contents: read
security-events: write

jobs:
bandit:
name: Static analysis (Bandit)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install bandit
run: pip install "bandit[toml]>=1.7"

- name: Run bandit
# Use SARIF output for the GitHub security tab. Don't fail the build
# on findings - they're surfaced via the security tab/PR annotations.
run: |
bandit -r src/dimtensor -c pyproject.toml -f sarif -o bandit-results.sarif || true
bandit -r src/dimtensor -c pyproject.toml -ll

- name: Upload SARIF to GitHub
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: bandit-results.sarif
category: bandit
continue-on-error: true

pip-audit:
name: Dependency vulnerabilities (pip-audit)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install pip-audit
run: pip install "pip-audit>=2.6"

- name: Audit installed dependencies
run: |
pip install -e ".[dev]"
pip-audit --strict --desc || true

safety:
name: Dependency vulnerabilities (Safety)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install safety
run: pip install "safety>=3.0"

- name: Run safety check
run: |
pip install -e ".[dev]"
# safety scan: don't fail the build on advisories alone; the team
# should review them in the workflow logs.
safety scan --output text || true

trivy:
name: Filesystem scan (Trivy)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
exit-code: '0'

- name: Upload Trivy SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: trivy
continue-on-error: true

codeql:
name: CodeQL analysis (Python)
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
queries: security-and-quality

- name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v3
with:
category: '/language:python'
24 changes: 24 additions & 0 deletions .mutmut.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# mutmut configuration for dimtensor (v5.2.0 task #271).
#
# Mutation testing modifies the source code in small ways and re-runs the
# test suite to check whether tests catch the modification. A high mutation
# score means the tests are sensitive to bugs.
#
# Usage:
# pip install mutmut
# mutmut run --paths-to-mutate=src/dimtensor/core
# mutmut results
# mutmut show <id>
#
# We focus mutmut on the *core* modules (dimensions, units, dimarray) since
# those have the strongest invariants and the most concentrated risk.

[mutmut]
paths_to_mutate = "src/dimtensor/core/"
backup = false
runner = "python -m pytest tests/test_dimensions.py tests/test_dimarray.py tests/test_property_based.py -x -q --tb=no -p no:cacheprovider"
tests_dir = "tests/"
# Skip mutating these patterns - they are pure data definitions or generated.
exclude = [
"src/dimtensor/core/__init__.py",
]
64 changes: 64 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,70 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.2.0] - 2026-04-16

### Added
- **Testing & Quality** - Production-grade reliability infrastructure:

**Property-based tests** (`tests/test_property_based.py`):
- 27 Hypothesis-driven tests covering algebraic invariants
- Verifies Dimension forms an Abelian group under multiplication
- Tests power laws (`a**p * a**q == a**(p+q)`, `(a**p)**q == a**(p*q)`)
- Round-trip checks for unit conversion factors
- DimArray arithmetic invariants (addition, multiplication, negation)
- Physics-formula invariants (F=ma, v=d/t, E=Fd produce correct dimensions)

**Fuzz tests** (`tests/test_fuzz.py`):
- 16 fuzz tests for malformed/random inputs
- JSON round-trip fuzzing (DimArray ↔ dict ↔ JSON)
- Adversarial JSON input fuzzing (garbage strings, missing keys)
- Operation sequence fuzzing (random pipelines preserve dimensions)
- DimArray with NaN/inf data (no crashes)
- Asserts only documented exception types are raised

**Chaos tests** (`tests/test_chaos.py`):
- 20 chaos tests for graceful degradation
- Filesystem failure modes (missing files, corrupt JSON, truncated input)
- Optional-dependency missing scenarios
- Pathological inputs (empty arrays, 0-d arrays, division by zero)
- Concurrent read safety
- Recovery from ill-formed serialized data

**Load tests** (`tests/test_load.py`):
- 9 load tests with generous time budgets
- Catches catastrophic O(n²) regressions on 1M+ element arrays
- Repeated-operation stress (1000 additions/conversions/dimension constructs)
- Hash distribution stress (2000 unique Dimensions in a dict)
- Optional `slow` marker for huge (10M element) arrays

**Mutation testing** (`.mutmut.toml`):
- mutmut configuration scoped to core/ modules
- Custom runner using property-based + unit tests
- Documented in `docs/guide/testing.md`

**Coverage dashboard** (`.github/workflows/dimtensor-coverage.yml`):
- Codecov upload on every push to main
- HTML coverage report as build artifact
- Coverage badge JSON for shields.io endpoint
- PR comments with coverage delta

**Security audit** (`.github/workflows/dimtensor-security.yml`):
- Bandit static analysis (SAST) with SARIF upload
- pip-audit for dependency CVEs (PyPA advisory DB)
- Safety scan for known vulnerabilities
- Trivy filesystem scan
- CodeQL deep semantic analysis (security & quality queries)
- Weekly schedule + on-PR runs

**New documentation**:
- `docs/guide/testing.md` - Comprehensive testing & QA guide

### Changed
- New `[test]` optional dependency group: `hypothesis`, `mutmut`, `bandit`, `safety`, `pip-audit`
- Added pytest markers: `slow`, `network`, `load`
- Added `[tool.coverage.*]` and `[tool.bandit]` sections to `pyproject.toml`
- Bumped `__version__` to 5.2.0 (was mismatched in 5.1.0 release)

## [5.1.0] - 2026-01-13

### Added
Expand Down
Loading
Loading