Skip to content
Documentation

Testing

This page is published from the ml repository. Edit on GitHub View source

The suite under tests/ is plain pytest. It has three jobs: pin the Python side of every seam with the agent (features, canonical command line, inference, attribution), pin the bytes of everything a gate hashes, and exercise each entry point end to end on synthetic data. CI runs it on Linux, Windows and macOS (development.md).

pytest tests                       # everything
pytest tests/test_features_golden.py -q
SYNTHAEA_REQUIRE_SIBLINGS=1 pytest tests   # as CI runs it

What the suite covers

AreaTests
Feature paritytest_features_golden, test_capture_parity, test_t1_parity, test_lineage_golden, test_rarity_golden, test_behavior_golden, test_mutation_parity, test_canonical, test_attribution_golden
Feature unitstest_correlation_features, test_behavior_features, test_combined_features, test_rarity
Datatest_jsonl, test_jsonl_readers, test_wire, test_baselines, test_hashing, test_manifest, test_manifest_cli
Trainingtest_trainers, test_train_behavior, test_train_correlation, test_train_site_model, test_training_pipeline, test_training_config, test_training_floor, test_trainer_artifacts
Site rarity floorstest_rarity_floor, test_rarity_global_floor, test_site_rarity_messages, test_site_rarity_record
Calibrationtest_calibrate_conformal
Evaluationtest_scenario_replay, test_robustness, test_robustness_snapshot, test_robustness_cli, test_mutations_cmdline, test_mutations_lineage, test_mutations_prng, test_t1_lineage_gain, test_odd_parent_scenarios, test_case_labels
Registrytest_training_record, test_training_record_golden, test_record_codec, test_verify_onnx, test_verify_provenance
Structuretest_import_direction, test_cli_entry_points, test_cli_logging

The training and evaluation tests use synthetic captures, baselines and corpora built by tests/helpers.py and the fixtures in tests/conftest.py. They prove the pipeline runs and what it writes, not how well a model detects anything.

Two structural tests guard the package shape: test_cli_entry_points.py requires every module with a __main__ block to be a console script and every main to take argv and return the exit status; test_import_direction.py keeps the training scripts out of verify_onnx and the lineage-gain tool (architecture.md).

Golden fixtures

A golden is a file of inputs and the exact outputs the reference implementation produces. The pytest suite here and the agent's crates/ml tests assert against the same file, so a drift on either side fails a test. The fixtures README maps each golden to its generator and the tests that read it.

SeamGoldenLives in
Command-line featuresfeatures_golden.jsonlthis repository
Correlation features from a real capturecapture_events.jsonl, capture_correlation_golden.jsonlthis repository
T1 vector, per incarnationt1_events.jsonl, t1_golden.jsonlthis repository
Lineage featureslineage_golden.jsonlthis repository
Rarity featuresrarity_golden.jsonlthis repository
Common-set snapshot formatcommon_set_snapshot_golden.jsonthis repository
Behavior vectorbehavior_golden.jsonlthis repository
Mutated feature vectorsmutation_parity_golden.jsonlthis repository
Attributionisoforest_small.onnx, attribution_golden.jsonthe agent's crates/ml/tests/fixtures/
T0 inferencecmdline_scorer.onnx, scorer_golden.jsonthe agent
T2 inferencecorrelation_scorer.onnx, correlation_scorer_golden.jsonlthe agent
T1 inferencet1_scorer.onnx, t1_scorer_golden.jsonlthe agent

The behavior and mutation-parity goldens are read only by the Python suite today; the other goldens of this repository are asserted on both sides. The inference goldens pin the agent's ort scores to onnxruntime's in Python for the same model and the same extractor. The attribution golden pins the agent's tree-path attribution to the independent Python reference in tests/attribution_reference.py, which parses the ONNX file with the onnx package. The fixture models are trained on synthetic vectors: they pin agreement between the two sides, not detection quality.

Regenerating a golden

Each generator in tests/fixtures/generators/ resolves its paths from its own location and runs from any directory:

python tests/fixtures/generators/gen_features_golden.py

Generators that write into the agent find it through SYNTHAEA_ROOT. gen_t1_scorer_golden.py reads t1_golden.jsonl, so run gen_t1_golden.py first when that changed. lineage_golden.jsonl has no generator in this repository.

Regenerate only on a deliberate change to a feature definition, a model recipe or a wire format, and open the matching pull request on the agent at the same time. Never regenerate to make a failing parity test pass: the failure is the drift the golden exists to catch.

Sibling checkouts

Some tests read files owned by other public repositories: the agent's crates/ml/tests/fixtures/ (attribution), and the scenarios repository's scenarios/ sidecars and ml-capture/odd-parents/ scripts (robustness, site floors, lineage gain, odd-parent declarations). synthaea_ml/siblings.py locates them under SYNTHAEA_ROOT, which defaults to the parent of this repository:

<root>/
    ml/          this repository
    agent/
    scenarios/

A test whose sibling is missing is skipped through tests/siblings.py, unless SYNTHAEA_REQUIRE_SIBLINGS=1, in which case collection fails. CI checks out both siblings (sparse: the agent's ML fixtures, the scenarios' scenarios/ and ml-capture/) and sets the variable, so a parity test can never go quietly missing there.

Writing a test

  • Prefer synthetic inputs built in tmp_path. Do not commit real captures as test data.
  • A builder used by several modules goes in helpers.py; one that needs pytest state goes in conftest.py as a fixture.
  • A test that needs a sibling uses needs(repo, *parts) from tests/siblings.py, never a bare skipif, so CI's strict mode applies to it.
  • Tests may use assert, /tmp paths and seeded non-cryptographic randomness; the lint exceptions for tests/** in pyproject.toml allow exactly that.