Analyses Snapshot Testing Instructions
Overview
The analyses-snapshot-testing directory validates that protocol analysis output remains consistent across code changes by comparing JSON results against committed snapshots.
- Regression testing: Detect unintended changes in protocol analysis behavior
- Protocol validation: Ensure protocols analyze correctly for OT-2
- CI/CD: Automated testing in GitHub Actions with matrix-based parallel execution
- Snapshot management: Track expected output and flag deviations
Architecture
Core Components
- Protocol Files (
files/protocols/) — testing protocols organized by source (standard, Protocol Designer exports, Protocol Library imports, generators)
- Analysis Engine (
automation/analyze.py) — runs protocol analysis in subprocess, 120-second timeout, JSON output
- Snapshot Storage (
tests/__snapshots__/) — committed JSON snapshots managed by syrupy with custom JSON extension
- Test Suite (
tests/) — analyses_snapshot_test.py (main), audit_snapshot_test.py (audit), custom_json_snapshot_extension.py (serialization)
- Audit (
automation/audit_snapshots.py) — validates snapshots: OT2_S protocols must have zero errors; OT2_X protocols are expected to have errors
- Protocol Registry (
automation/data/) — protocols.py (auto-generated), protocols_with_overrides.py (manual), protocol_registry.py (combined)
- CI/CD (
citools/, .github/workflows/) — matrix-based parallel execution via Docker
Protocol Naming Convention
{Robot}_{Status}_{Version}_{Source}_{Pipettes}_{Modules}_{Overrides}\_{Description}
- Robot:
OT2
- Status:
S (Success) or X (Failure expected)
- Version: API version (e.g.,
v2_19) or PD (Protocol Designer)
- Source (optional):
PL_ (Protocol Library) or MPL_ (Manual Protocol Library)
- Pipettes: e.g.,
P1000M_P50M
- Modules:
GRIP, HS, MM, MB, TC, TM
- Overrides:
Overrides if protocol has parameter overrides
- Description: Max 25 characters
Example: OT2_S_v2_19_P300M_P20S_HS_TC_TM_SmokeTestV3.py
Development Workflow
Adding New Protocols
- Create protocol file in
files/protocols/ following naming convention
- Run
make prep (auto-updates automation/data/protocols.py, displays snapshot command)
- Generate snapshots:
make snapshot-test-update PROTOCOL_NAMES=YourProtocolName OVERRIDE_PROTOCOL_NAMES=none
- Commit protocol file + snapshot + updated
protocols.py
Adding Override Protocols
- Create generator in
files/protocols/generators/
- Add entry to
automation/data/protocols_with_overrides.py
- Generate snapshots:
make snapshot-test-update PROTOCOL_NAMES=none OVERRIDE_PROTOCOL_NAMES=YourOverrideProtocol
- Commit generator + snapshot + updated registry
Updating Snapshots
make snapshot-test-update # All
make snapshot-test-update PROTOCOL_NAMES="P1,P2" OVERRIDE_PROTOCOL_NAMES=none # Specific
Running Tests Locally
make snapshot-test # All (reduced verbosity)
make snapshot-test PROTOCOL_NAMES=OT2_S_v2_7_P20S_None_Walkthrough OVERRIDE_PROTOCOL_NAMES=none # Specific
uv run python -m pytest -k analyses_snapshot_test -vv --tb=short # Verbose debugging
Code Modification Guidelines
When Modifying Analysis Logic (api/, shared-data/)
- Run snapshot tests to detect changes
- Review diffs carefully
- Update snapshots only if changes are intentional
- Document breaking changes in commit messages
Protocol Registry (automation/data/protocols.py)
- DO NOT manually edit — auto-generated by
make prep
- Regenerate after adding/removing protocols
Snapshot Extension (tests/custom_json_snapshot_extension.py)
- Normalizes timestamps, IDs, file paths for stable comparisons
- Add new normalization rules to
replacement_patterns
- Add new ID-like fields to
id_keys_to_replace
Environment Setup
Prerequisites: Python 3.12, uv, Node.js/pnpm (for prettier)
cd analyses-snapshot-testing
make setup # Creates uv venv and installs dependencies
The setup script (bootstrap_uv_env.py) installs api and shared-data as editable packages so analysis uses local code.
Common Commands
# Setup
make setup # Initial environment setup
make teardown # Remove virtual environment
# Testing
make snapshot-test # Run all snapshot tests
make snapshot-test-update # Update all snapshots
make snapshot-audit-test # Validate snapshot audit metadata
# Protocol Management
make prep # Regenerate protocol registry
make generate-protocols # Generate override protocols
# Formatting
make format # Format Python + Markdown
make ruff # Format and lint Python
# CI Simulation
make gen-chunks # Generate protocol chunks
make analyze-chunk CHUNK=chunk_0.json # Analyze specific chunk
CI/CD Integration
Workflow (analyses-snapshot-test.yaml) triggers on:
- PRs affecting
api/, shared-data/, or this directory
- Scheduled daily at 7:26 AM UTC
- Manual dispatch
PR label gen-analyses-snapshot-pr auto-opens a PR with updated snapshots on failure.
Troubleshooting
- Snapshot mismatch: Review diff, update if intentional (
make snapshot-test-update PROTOCOL_NAMES=...), fix code if not
- Protocol not found: Check registry, run
make prep, verify file exists and follows naming convention
- Analysis timeout (120s): Simplify protocol or increase timeout in
automation/analyze.py
- Environment issues: Run
make setup, ensure uv is installed
1---2name: analyses-snapshot-testing3description: Conventions for the analyses snapshot testing framework in analyses-snapshot-testing/. Use when working with protocol analysis snapshots, adding protocols, updating snapshots, or running snapshot tests.4---56# Analyses Snapshot Testing Instructions78## Overview910The `analyses-snapshot-testing` directory validates that protocol analysis output remains consistent across code changes by comparing JSON results against committed snapshots.1112- **Regression testing**: Detect unintended changes in protocol analysis behavior13- **Protocol validation**: Ensure protocols analyze correctly for OT-214- **CI/CD**: Automated testing in GitHub Actions with matrix-based parallel execution15- **Snapshot management**: Track expected output and flag deviations1617## Architecture1819### Core Components20211. **Protocol Files** (`files/protocols/`) — testing protocols organized by source (standard, Protocol Designer exports, Protocol Library imports, generators)222. **Analysis Engine** (`automation/analyze.py`) — runs protocol analysis in subprocess, 120-second timeout, JSON output233. **Snapshot Storage** (`tests/__snapshots__/`) — committed JSON snapshots managed by `syrupy` with custom JSON extension244. **Test Suite** (`tests/`) — `analyses_snapshot_test.py` (main), `audit_snapshot_test.py` (audit), `custom_json_snapshot_extension.py` (serialization)255. **Audit** (`automation/audit_snapshots.py`) — validates snapshots: `OT2_S` protocols must have zero errors; `OT2_X` protocols are expected to have errors266. **Protocol Registry** (`automation/data/`) — `protocols.py` (auto-generated), `protocols_with_overrides.py` (manual), `protocol_registry.py` (combined)277. **CI/CD** (`citools/`, `.github/workflows/`) — matrix-based parallel execution via Docker2829## Protocol Naming Convention3031```markdown32{Robot}_{Status}_{Version}_{Source}_{Pipettes}_{Modules}_{Overrides}\_{Description}33```3435- **Robot**: `OT2`36- **Status**: `S` (Success) or `X` (Failure expected)37- **Version**: API version (e.g., `v2_19`) or `PD` (Protocol Designer)38- **Source** (optional): `PL_` (Protocol Library) or `MPL_` (Manual Protocol Library)39- **Pipettes**: e.g., `P1000M_P50M`40- **Modules**: `GRIP`, `HS`, `MM`, `MB`, `TC`, `TM`41- **Overrides**: `Overrides` if protocol has parameter overrides42- **Description**: Max 25 characters4344Example: `OT2_S_v2_19_P300M_P20S_HS_TC_TM_SmokeTestV3.py`4546## Development Workflow4748### Adding New Protocols49501. Create protocol file in `files/protocols/` following naming convention512. Run `make prep` (auto-updates `automation/data/protocols.py`, displays snapshot command)523. Generate snapshots: `make snapshot-test-update PROTOCOL_NAMES=YourProtocolName OVERRIDE_PROTOCOL_NAMES=none`534. Commit protocol file + snapshot + updated `protocols.py`5455### Adding Override Protocols56571. Create generator in `files/protocols/generators/`582. Add entry to `automation/data/protocols_with_overrides.py`593. Generate snapshots: `make snapshot-test-update PROTOCOL_NAMES=none OVERRIDE_PROTOCOL_NAMES=YourOverrideProtocol`604. Commit generator + snapshot + updated registry6162### Updating Snapshots6364```bash65make snapshot-test-update # All66make snapshot-test-update PROTOCOL_NAMES="P1,P2" OVERRIDE_PROTOCOL_NAMES=none # Specific67```6869### Running Tests Locally7071```bash72make snapshot-test # All (reduced verbosity)73make snapshot-test PROTOCOL_NAMES=OT2_S_v2_7_P20S_None_Walkthrough OVERRIDE_PROTOCOL_NAMES=none # Specific74uv run python -m pytest -k analyses_snapshot_test -vv --tb=short # Verbose debugging75```7677## Code Modification Guidelines7879### When Modifying Analysis Logic (`api/`, `shared-data/`)80811. Run snapshot tests to detect changes822. Review diffs carefully833. Update snapshots only if changes are intentional844. Document breaking changes in commit messages8586### Protocol Registry (`automation/data/protocols.py`)8788- **DO NOT** manually edit — auto-generated by `make prep`89- Regenerate after adding/removing protocols9091### Snapshot Extension (`tests/custom_json_snapshot_extension.py`)9293- Normalizes timestamps, IDs, file paths for stable comparisons94- Add new normalization rules to `replacement_patterns`95- Add new ID-like fields to `id_keys_to_replace`9697## Environment Setup9899**Prerequisites**: Python 3.12, **uv**, Node.js/pnpm (for prettier)100101```bash102cd analyses-snapshot-testing103make setup # Creates uv venv and installs dependencies104```105106The setup script (`bootstrap_uv_env.py`) installs `api` and `shared-data` as editable packages so analysis uses local code.107108## Common Commands109110```bash111# Setup112make setup # Initial environment setup113make teardown # Remove virtual environment114115# Testing116make snapshot-test # Run all snapshot tests117make snapshot-test-update # Update all snapshots118make snapshot-audit-test # Validate snapshot audit metadata119120# Protocol Management121make prep # Regenerate protocol registry122make generate-protocols # Generate override protocols123124# Formatting125make format # Format Python + Markdown126make ruff # Format and lint Python127128# CI Simulation129make gen-chunks # Generate protocol chunks130make analyze-chunk CHUNK=chunk_0.json # Analyze specific chunk131```132133## CI/CD Integration134135Workflow (`analyses-snapshot-test.yaml`) triggers on:136137- PRs affecting `api/`, `shared-data/`, or this directory138- Scheduled daily at 7:26 AM UTC139- Manual dispatch140141PR label `gen-analyses-snapshot-pr` auto-opens a PR with updated snapshots on failure.142143## Troubleshooting144145- **Snapshot mismatch**: Review diff, update if intentional (`make snapshot-test-update PROTOCOL_NAMES=...`), fix code if not146- **Protocol not found**: Check registry, run `make prep`, verify file exists and follows naming convention147- **Analysis timeout** (120s): Simplify protocol or increase timeout in `automation/analyze.py`148- **Environment issues**: Run `make setup`, ensure `uv` is installed