Skip to content

Add comprehensive testing & quality assurance infrastructure (v5.2.0) - #10

Merged
marcoloco23 merged 1 commit into
mainfrom
claude/continue-work-h9Glp
Apr 29, 2026
Merged

marcoloco23 merged 1 commit into
mainfrom
claude/continue-work-h9Glp

Conversation

@marcoloco23

Copy link
Copy Markdown
Owner

Summary

This PR introduces production-grade testing and quality assurance infrastructure for dimtensor, adding 72 new tests across four complementary testing layers plus security scanning and coverage reporting workflows.

Key Changes

Testing Infrastructure

  • Property-based tests (tests/test_property_based.py, 27 tests):

    • Hypothesis-driven verification of algebraic invariants (Dimension as Abelian group)
    • Power law properties (a**p * a**q == a**(p+q), (a**p)**q == a**(p*q))
    • Unit conversion symmetry and round-trip consistency
    • DimArray arithmetic invariants and physics formula validation (F=ma, v=d/t, E=Fd)
  • Fuzz tests (tests/test_fuzz.py, 16 tests):

    • JSON round-trip fuzzing for serialization robustness
    • Adversarial input handling (garbage strings, truncated files, missing keys)
    • Operation sequence fuzzing to verify dimension preservation
    • NaN/inf propagation without crashes
    • Strict exception type validation (only documented exceptions allowed)
  • Chaos tests (tests/test_chaos.py, 20 tests):

    • Filesystem failure modes (missing files, corrupt JSON, truncated input)
    • Optional dependency missing scenarios (torch, JAX, pandas, xarray)
    • Pathological inputs (empty arrays, 0-d arrays, division by zero)
    • Concurrent read safety smoke tests
    • Graceful degradation verification
  • Load tests (tests/test_load.py, 9 tests):

    • 1M-element array operations with generous time budgets
    • Repeated operation stress (1000x additions)
    • Hash distribution validation (2000 unique Dimensions)
    • Catches catastrophic O(n²) regressions

Quality Assurance Workflows

  • Coverage dashboard (.github/workflows/dimtensor-coverage.yml):

    • Codecov integration with HTML report artifacts
    • Coverage badge generation (JSON format)
    • PR comment with coverage summary
    • Excludes slow tests and optional integrations
  • Security audit (.github/workflows/dimtensor-security.yml):

    • Bandit (SAST) with SARIF output
    • pip-audit for dependency vulnerabilities
    • Safety for advisory scanning
    • Trivy for filesystem scanning
    • CodeQL analysis for Python code quality
    • Weekly scheduled runs plus on-demand triggers

Configuration & Documentation

  • Mutation testing (.mutmut.toml):

    • Scoped to src/dimtensor/core/ for focused mutation analysis
    • Configured to detect gaps in test coverage
  • Test markers (pyproject.toml):

    • slow: for expensive tests (deselectable)
    • network: for tests requiring network access
    • load: for stress tests
  • Coverage configuration (pyproject.toml):

    • Branch coverage enabled
    • Exclusions for test files, stubs, and optional integrations
    • HTML and XML report generation
  • Testing guide (docs/guide/testing.md):

    • Overview of all test layers with run instructions
    • Property-based testing explanation with examples
    • Fuzz and chaos testing rationale
    • Mutation testing workflow
    • Load testing interpretation

Dependencies

  • Added [test] extras group: hypothesis, mutmut, pytest-cov, coverage, bandit, safety, pip-audit

Version Update

  • Updated __version__ to "5.2.0" in src/dimtensor/__init__.py
  • Updated CHANGELOG.md with v5.2.0 release notes
  • Updated mkdocs.yml navigation to include testing guide

Implementation Details

Test Strategy: The four-layer approach provides complementary coverage:

  • Property-based tests verify mathematical invariants hold universally
  • Fuzz tests stress the system with adversarial/malformed inputs
  • Chaos tests confirm graceful degradation under environmental failures
  • Load tests catch performance regressions on large datasets

**Exception Safety

https://claude.ai/code/session_01C5HKiidr4gE4dqDqrZtHMZ

Adds production-grade reliability infrastructure:

* Property-based tests (test_property_based.py): 27 Hypothesis tests
  verifying Dimension forms an Abelian group, power laws hold, unit
  conversion is symmetric, and physics formulas (F=ma, v=d/t, E=Fd)
  produce correct dimensions.

* Fuzz tests (test_fuzz.py): 16 tests with adversarial JSON, NaN/inf
  data, and random operation sequences.  Asserts only documented
  exception types are raised.

* Chaos tests (test_chaos.py): 20 tests for graceful degradation
  (missing files, corrupt JSON, optional dependencies, concurrent
  reads, ill-formed serialized data).

* Load tests (test_load.py): 9 stress tests with generous time budgets
  to catch O(n^2) regressions on million-element arrays.

* Mutation testing (.mutmut.toml): mutmut config scoped to core
  modules so mutation runs are tractable.

* Coverage dashboard (.github/workflows/dimtensor-coverage.yml):
  Codecov upload, HTML report artifact, badge JSON, PR comments.

* Security audit (.github/workflows/dimtensor-security.yml):
  Bandit (SAST), pip-audit, Safety, Trivy, CodeQL.  Weekly schedule
  plus on-PR runs.

* New [test] optional dependency group covering hypothesis, mutmut,
  bandit, safety, pip-audit.

* New docs/guide/testing.md describing every layer.

* Fixes version mismatch: __init__.py was 5.1.0, pyproject.toml was
  5.2.0; both are now 5.2.0.

184 core+new tests pass, 0 regressions.

https://claude.ai/code/session_01C5HKiidr4gE4dqDqrZtHMZ
@marcoloco23
marcoloco23 merged commit 8ac778f into main Apr 29, 2026
10 of 17 checks passed
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@github-actions

Copy link
Copy Markdown

Benchmark Results

Operation Array Size NumPy (μs) DimArray (μs) Overhead
creation 1,000 26.05 26.56 1.02x
addition 1,000 0.89 3.74 4.22x
multiplication 1,000 0.81 12.80 15.77x
division 1,000 1.19 12.62 10.63x
power 1,000 0.81 12.29 15.23x
sum 1,000 1.39 2.35 1.69x
matmul 10,000 31.72 46.52 1.47x
indexing 1,000 0.34 1.65 4.91x
chained_ops 1,000 4.65 19.85 4.27x
creation 10,000 256.09 258.65 1.01x
addition 10,000 5.61 7.99 1.42x
multiplication 10,000 5.61 17.14 3.05x
division 10,000 6.32 17.71 2.80x
power 10,000 3.23 14.25 4.41x
sum 10,000 3.40 4.43 1.30x
matmul 10,000 32.47 46.57 1.43x
indexing 10,000 0.34 1.50 4.47x
chained_ops 10,000 14.75 33.19 2.25x

Average overhead: 4.52x


📊 Full benchmark results are available in the workflow artifacts.

@github-actions

Copy link
Copy Markdown

Dimensional Linting Results

⚠️ Warnings (5)

  • tests/test_priors.py:120:19: Potential dimension mismatch: Θ + L²MT⁻³I⁻¹
  • tests/test_property_based.py:150:40: Potential dimension mismatch: LMT⁻¹ + TI
  • tests/test_serverless.py:137:19: Potential dimension mismatch: M + L
  • tests/test_dimarray.py:67:12: Potential dimension mismatch: LT⁻¹ + LT⁻²
  • tests/test_dimarray.py:81:12: Potential dimension mismatch: M - L

Please fix these dimensional inconsistencies before merging.

@github-actions

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
14994 7639 51% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/dimtensor/_init_.py 100% 🟢
TOTAL 100% 🟢

updated for commit: 512fab0 by action🐍

Comment thread tests/test_chaos.py

from __future__ import annotations

import io
Comment thread tests/test_chaos.py

import io
import json
import sys
Comment thread tests/test_chaos.py
import io
import json
import sys
import tempfile
Comment thread tests/test_chaos.py
import sys
import tempfile
from pathlib import Path
from unittest.mock import patch
Comment thread tests/test_chaos.py
import numpy as np
import pytest

from dimtensor import DimArray, Dimension, Unit, units
Comment thread tests/test_fuzz.py
"""Garbage JSON strings must raise an allowed exception type."""
try:
from_json(text)
except ALLOWED_EXCEPTIONS + (json.JSONDecodeError,):
Comment thread tests/test_fuzz.py
"""Random dicts: from_dict must raise an allowed exception."""
try:
from_dict(payload)
except ALLOWED_EXCEPTIONS:
Comment thread tests/test_fuzz.py
try:
recovered = from_dict(d)
assert recovered.unit.symbol == garbage_symbol
except ALLOWED_EXCEPTIONS:
Comment thread tests/test_fuzz.py
"""unit * scalar should always work or raise an allowed exception."""
try:
_ = unit * scalar
except ALLOWED_EXCEPTIONS:
Comment thread tests/test_load.py
import numpy as np
import pytest

from dimtensor import DimArray, Dimension, Unit, units
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants