Skip to content

feat(BACK-001): counterfactual provider and evidence export - #13

Merged
mrnicholasbcarter-code merged 1 commit into
masterfrom
feat/back-001-provider-receipts
Aug 20, 2026
Merged

feat(BACK-001): counterfactual provider and evidence export#13
mrnicholasbcarter-code merged 1 commit into
masterfrom
feat/back-001-provider-receipts

Conversation

@mrnicholasbcarter-code

Copy link
Copy Markdown
Owner

Summary

Implements [BACK-001] "Backtest counterfactual provider and evidence export" (issue #11). Exposes Monte Carlo, fee, walk-forward, and tear-sheet results as verification / counterfactual evidence compatible with Verdict Core's VerificationResult and EvidenceChainLink contracts (ADR-021 / ADR-024).

Changes

  • src/backtest_harness/evidence.py (new): deterministic, seeded run_counterfactual, explicit build_failure_evidence for failure/timeout/denied/cancelled/unknown states, and Core adapters to_verification_result / to_evidence_chain_link.
  • src/backtest_harness/provider_receipts.py: added canonical_hash (byte-for-byte identical to verdict-core.canonical_hash) and PROVIDER_VERSION.
  • src/backtest_harness/analytics.py: precise tearsheet overloads so mypy narrows the as_dict=True return to dict.
  • docs/ARCHITECTURE.md: documented the BACK-001 counterfactual evidence flow.
  • Tests: test_evidence.py, test_provider_receipts.py (conformance mirror of core), test_core_conformance.py (boundary conformance against real verdict.contracts.VerificationResult / EvidenceChainLink / verdict.provider_receipts.ProviderReceipt).

Acceptance-criteria evidence

  • Recorded provenance (inputs, seeds, fee model, code version, dataset refs); reproducible; no live/network side effects: run_counterfactual records dataset_ref, seed, fee_config["model"], code_version, and trade_returns_hash in the receipt; results are bound by evidence_refs=(results_hash,). Pure in-process NumPy only; RNG state is saved/restored so callers are unaffected (test_does_not_leak_global_rng_state). Identical args → identical bundle (test_same_seed_reproduces_identical_evidence); different seed → different results.
  • Core VerificationResult and EvidenceChain adapters pass: test_core_conformance.py round-trips the receipt through verdict.provider_receipts.ProviderReceipt.from_dict, exports through verdict.contracts.VerificationResult.from_dict (status passed/failed) and verdict.contracts.EvidenceChainLink.from_dict.
  • Failure/timeout/stale/unknown/denial states explicit: build_failure_evidence allowlists non-success outcomes; success cannot be fabricated; to_verification_result maps only successpassed, failure/denied/error → failed, timeout/unknown → unknown, cancelled/skipped → skipped.
  • No learning/retrieval/provider data can weaken hard policy: to_verification_result derives status solely from the recorded outcome; tampered advisory detail fields (status: "passed") are ignored (test_advisory_details_cannot_upgrade_status). to_evidence_chain_link rejects empty decision/policy/envelope and cannot mint authority (test_provider_cannot_mint_decision_authority).
  • Sensitive fields rejected: _reject_sensitive rejects api_key/authorization/password/secret/token at the receipt boundary (test_sensitive_provenance_is_rejected, test_receipt_rejects_sensitive_metadata).
  • Negative-path tests: empty/NaN/non-numeric returns, empty run_id/dataset_ref, non-positive equity/sim counts, bad walk-forward splits, unknown fee model, fee_trades without config, malformed payloads, tampered digests.

Verification

  • uv run python -m pytest -q66 passed (incl. core conformance).
  • uv run ruff check . → All checks passed.
  • uv run ruff format --check . → formatted.
  • uv run mypy src/ → no issues.
  • git diff --check → clean.

Closes #11.

- Add backtest_harness.evidence module with run_counterfactual,
  build_failure_evidence, to_verification_result, to_evidence_chain_link
- Extend provider_receipts with canonical_hash (ADR-021 byte-for-byte
  compatibility) and PROVIDER_VERSION
- Add tearsheet overloads for precise mypy typing
- Add conformance tests against verdict-core contracts (VerificationResult,
  EvidenceChainLink, ProviderReceipt)
- Update ARCHITECTURE.md with BACK-001 evidence flow documentation

Refs #11
@mrnicholasbcarter-code
mrnicholasbcarter-code merged commit f333365 into master Aug 20, 2026
8 checks passed
@mrnicholasbcarter-code
mrnicholasbcarter-code deleted the feat/back-001-provider-receipts branch August 20, 2026 01:55
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.

[BACK-001] Backtest counterfactual provider and evidence export

1 participant