_content_hash ported with FULL python json.dumps byte semantics: nested sort_keys recursion, ensure_ascii escaping, and the int-vs-float literal distinction preserved via json.Number decoding (the oracle distinguishes 1 from 1.0; the hash of an int-carrying payload differs from the float-carrying one). 6-case battery — the oracle corrected two assumptions before the design was pinned.
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""gen_event_bus_truth.py — factory batch 9 truth battery (live oracle)."""
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(REPO / "src"))
|
|
sys.path.insert(0, str(REPO / "src" / "rune"))
|
|
|
|
import event_bus as eb # noqa: E402
|
|
|
|
|
|
def main():
|
|
payloads = [
|
|
{},
|
|
{"k": "v"},
|
|
{"task_id": "t1", "status": "failed", "count": 3},
|
|
{"nested": {"a": [1, 2, "x"]}, "flag": True, "nothing": None},
|
|
{"text": "quote\" inside\\ back\nnewline\ttab"},
|
|
{"float_int": 1.0, "float_frac": 2.5},
|
|
]
|
|
cases = [
|
|
{"fn": "hash", "name": f"payload_{i}", "input": {"payload": p},
|
|
"expected": {"hash": eb._content_hash(p)}}
|
|
for i, p in enumerate(payloads)
|
|
]
|
|
out = {"oracle": "event_bus._content_hash", "generated": "2026-10-07", "cases": cases}
|
|
(REPO / "src/go/event-bus" / "truth_bus.json").write_text(json.dumps(out, indent=1) + "\n")
|
|
print(f"wrote {len(cases)} cases")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|