Skip to content

Add database summary and comparison utilities for symmetry testing#115

Merged
stevewds merged 5 commits intomainfrom
claude/add-symmetry-tests-0cjnw
Mar 16, 2026
Merged

Add database summary and comparison utilities for symmetry testing#115
stevewds merged 5 commits intomainfrom
claude/add-symmetry-tests-0cjnw

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

Summary

This PR introduces utilities for generating and comparing DID database summaries, along with a comprehensive cross-language symmetry testing framework. These tools enable validation of database state consistency across MATLAB and other DID implementations (e.g., Python).

Key Changes

New Utility Functions

  • did.util.databaseSummary(db): Generates a deterministic struct summarizing a DID database's complete state, including:

    • Database ID and all branch names
    • Branch hierarchy (parent-child relationships)
    • Per-branch document counts and full document properties
    • Suitable for JSON serialization and cross-language comparison
  • did.util.compareDatabaseSummary(summaryA, summaryB, options): Compares two database summaries and returns a detailed report of differences:

    • Accepts summaries as structs, JSON file paths, or live did.database objects
    • Detects branch differences, document count mismatches, class name changes, property value differences, and dependency mismatches
    • Supports excluding specific fields via excludeFields option
    • Returns empty cell array if summaries are identical

Symmetry Testing Framework

  • tests/+did/+symmetry/+makeArtifacts/+database/buildDatabase.m: Test class that generates standard DID database artifacts:

    • Creates a multi-branch database with hierarchical structure
    • Exports database summary and per-branch JSON files to tempdir()
    • Uses fixed random seed for reproducibility
    • Includes self-validation via compareDatabaseSummary()
  • tests/+did/+symmetry/+readArtifacts/+database/buildDatabase.m: Test class that validates artifacts from both MATLAB and external implementations:

    • Parameterized to test both matlabArtifacts and pythonArtifacts
    • Loads saved summaries and re-summarizes live databases
    • Compares saved vs. live summaries for consistency
    • Verifies per-branch JSON files and document properties
  • GitHub Actions Workflow (.github/workflows/test-symmetry.yml): Automated CI pipeline that:

    • Runs makeArtifacts tests to generate reference artifacts
    • Runs readArtifacts tests to validate consistency
    • Supports cross-language validation when Python artifacts are available

Documentation

  • INSTRUCTIONS.md files in both makeArtifacts and readArtifacts packages explaining:
    • Artifact directory structure and naming conventions
    • Testing goals and expected behavior
    • Example implementations for extending the framework

Implementation Details

  • Database summaries are deterministic: documents within each branch are sorted by ID for consistent output
  • Helper functions handle flexible input formats (structs, JSON files, live database objects)
  • Comparison logic normalizes dependencies and handles various struct representations from JSON deserialization
  • Tests use matlab.unittest framework with proper fixtures and parameterization for maintainability

https://claude.ai/code/session_01TT3ycsjcvsKLnAp1WffRPe

claude added 4 commits March 15, 2026 23:51
Introduce symmetry test infrastructure following the NDI-matlab pattern,
enabling cross-language validation between MATLAB and Python DID implementations.

- makeArtifacts: generates a small DID database with random demoA/demoB/demoC
  documents across 3 branches (branch_main, branch_dev, branch_feature), exports
  the SQLite database file and per-branch JSON audit files as persistent artifacts
- readArtifacts: parameterized test that reads artifacts from either matlabArtifacts
  or pythonArtifacts, validates document counts, class names, field values, and
  dependencies against the JSON audit files
- INSTRUCTIONS.md files document the directory conventions and artifact format

https://claude.ai/code/session_01TT3ycsjcvsKLnAp1WffRPe
Introduce reusable utilities for summarizing and comparing DID databases,
then refactor symmetry tests to use them:

- did.util.databaseSummary(db): produces a struct capturing the full database
  state (branches, hierarchy, documents sorted by ID with class names and
  properties), suitable for JSON serialization
- did.util.compareDatabaseSummary(a, b): compares two summaries (structs,
  JSON files, or database objects) and returns a report with isEqual flag
  and detailed per-branch/per-document mismatch messages
- makeArtifacts now exports summary.json via databaseSummary and includes
  a self-check round-trip comparison
- readArtifacts now loads summary.json, re-summarizes the live database,
  and uses compareDatabaseSummary for the primary validation

https://claude.ai/code/session_01TT3ycsjcvsKLnAp1WffRPe
Update compareDatabaseSummary to return a cell array of message strings
(empty = equal) instead of a struct with .isEqual, matching the pattern
used by ndi.util.compareSessionSummary on the NDI-matlab side. Also add
arguments block with excludeFields option and use sprintf for messages.

Update symmetry tests to use verifyEmpty(report) accordingly.

https://claude.ai/code/session_01TT3ycsjcvsKLnAp1WffRPe
Runs makeArtifacts tests first (generating the database and JSON audit
artifacts in tempdir), then readArtifacts tests (validating the artifacts
against the live database). Triggered on pushes to main, PRs to main,
or manually via workflow_dispatch.

https://claude.ai/code/session_01TT3ycsjcvsKLnAp1WffRPe
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 16, 2026

Test Results

104 tests   102 ✅  1m 14s ⏱️
 16 suites    2 💤
  1 files      0 ❌

Results for commit 294982b.

♻️ This comment has been updated with latest results.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 68.13187% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.63%. Comparing base (4a0fda5) to head (294982b).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/did/+did/+util/compareDatabaseSummary.m 62.50% 51 Missing ⚠️
src/did/+did/+util/databaseSummary.m 84.78% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #115      +/-   ##
==========================================
+ Coverage   44.15%   45.63%   +1.47%     
==========================================
  Files          53       55       +2     
  Lines        2976     3158     +182     
==========================================
+ Hits         1314     1441     +127     
- Misses       1662     1717      +55     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The sqlitedb implementation requires the mksqlite package. Add steps
to install MatBox first, then use matbox.installRequirements to install
mksqlite and other dependencies from requirements.txt.

https://claude.ai/code/session_01TT3ycsjcvsKLnAp1WffRPe
@stevevanhooser stevevanhooser requested a review from stevewds March 16, 2026 00:23
@stevewds stevewds merged commit de5e8f0 into main Mar 16, 2026
6 checks passed
@stevewds stevewds deleted the claude/add-symmetry-tests-0cjnw branch March 16, 2026 00:25
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