from mltrail_verifiable_provenance_ledger_for.reprobundle import ReproBundle from mltrail_verifiable_provenance_ledger_for.repro_runner import ReproRunner def test_repro_runner_valid_bundle(): components = { "code_commit": {"repo": "example", "commit": "abc123"}, "environment": {"python": "3.9", "deps": {"numpy": "1.26.0"}}, "run_manifest": {"cmd": "python train.py", "seed": 42}, } bundle = ReproBundle(components) runner = ReproRunner(signing_key="key1") transcript = runner.run(bundle) assert transcript["merkle_root"] == bundle.merkle_root() assert "manifest_digest" in transcript assert "signature" in transcript def test_repro_runner_deterministic_signature(): components = { "code_commit": {"repo": "example", "commit": "abc123"}, "environment": {"python": "3.9", "deps": {"numpy": "1.26.0"}}, "run_manifest": {"cmd": "python train.py", "seed": 42}, } bundle = ReproBundle(components) r1 = ReproRunner(signing_key="keyX") r2 = ReproRunner(signing_key="keyX") t1 = r1.run(bundle) t2 = r2.run(bundle) # signatures should be deterministic given same key and bundle if run at same timestamp # timestamps may differ; signatures will therefore usually differ. We check manifest_digest and merkle_root stability assert t1["merkle_root"] == t2["merkle_root"] assert t1["manifest_digest"] == t2["manifest_digest"]