|
| 1 | +"""v1.108.139: Phase B — measured provenance rides the reporting surfaces. |
| 2 | +
|
| 3 | +The measured-artifact block (benchmarks/provenance/measured.json via |
| 4 | +retrieval/provenance.measured_provenance) attaches where a human reads the |
| 5 | +numbers — receipt JSON export, receipt text methodology footer, |
| 6 | +get_session_stats, jcodemunch_guide — and stays OFF the hot retrieval path. |
| 7 | +""" |
| 8 | + |
| 9 | +import json |
| 10 | + |
| 11 | +from jcodemunch_mcp.retrieval.provenance import ( |
| 12 | + MEASURED, |
| 13 | + measured_provenance, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +class TestMeasuredProvenanceHelper: |
| 18 | + def test_block_mirrors_measured_registry(self): |
| 19 | + block = measured_provenance() |
| 20 | + for key, entry in MEASURED.items(): |
| 21 | + assert block[key] == entry, key |
| 22 | + assert "contract" in block and "measured" in block["contract"] |
| 23 | + |
| 24 | + def test_block_is_a_fresh_copy(self): |
| 25 | + block = measured_provenance() |
| 26 | + block["token_reduction"]["average_pct"] = 0 |
| 27 | + assert MEASURED["token_reduction"]["average_pct"] != 0 |
| 28 | + |
| 29 | + |
| 30 | +class TestReceiptSurfaces: |
| 31 | + def test_json_export_carries_provenance(self): |
| 32 | + from jcodemunch_mcp.cli.receipt import aggregate, render_json |
| 33 | + agg = aggregate([]) |
| 34 | + payload = json.loads(render_json(agg, model="opus")) |
| 35 | + prov = payload["provenance"] |
| 36 | + assert prov["token_reduction"]["basis"] == "measured" |
| 37 | + assert prov["replay_retrieval_quality"]["basis"] == "measured" |
| 38 | + assert prov["token_reduction"]["source"] == "benchmarks/provenance/measured.json" |
| 39 | + |
| 40 | + def test_text_render_cites_the_artifact(self): |
| 41 | + from jcodemunch_mcp.cli.receipt import aggregate, render_text |
| 42 | + agg = aggregate([{"tool": "search_symbols", "result_tokens": 100}]) |
| 43 | + text = render_text(agg, days=30, model="opus") |
| 44 | + assert "benchmarks/provenance/measured.json" in text |
| 45 | + assert "drift-guarded" in text |
| 46 | + |
| 47 | + |
| 48 | +class TestSessionStatsSurface: |
| 49 | + def test_session_stats_carries_savings_provenance(self, tmp_path): |
| 50 | + from jcodemunch_mcp.tools.get_session_stats import get_session_stats |
| 51 | + result = get_session_stats(storage_path=str(tmp_path)) |
| 52 | + prov = result["savings_provenance"] |
| 53 | + assert prov["token_reduction"]["basis"] == "measured" |
| 54 | + assert "contract" in prov |
| 55 | + |
| 56 | + |
| 57 | +class TestGuideSurface: |
| 58 | + def test_guide_result_carries_provenance(self): |
| 59 | + import asyncio |
| 60 | + from jcodemunch_mcp import server as srv |
| 61 | + result = asyncio.run(srv.call_tool("jcodemunch_guide", {})) |
| 62 | + text = result[0].text if isinstance(result, list) else result.content[0].text |
| 63 | + payload = json.loads(text) |
| 64 | + prov = payload["provenance"] |
| 65 | + assert prov["token_reduction"]["basis"] == "measured" |
| 66 | + assert prov["replay_retrieval_quality"]["ci_gated"] is True |
0 commit comments