Compress ported verbatim: drop empty/comment/decorative/citation/short lines, join, 797+... truncate past 800. 9-case battery (4 hash + 5 compress) from the live oracle. First-run green.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""gen_cache_hash_truth.py — factory batch 6 truth battery (live cache._hash)."""
|
|
|
|
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 cache as ch # noqa: E402
|
|
|
|
|
|
def main():
|
|
cases = [
|
|
{"fn": "hash", "name": "ascii", "input": {"text": s},
|
|
"expected": {"hash": ch._hash(s)}}
|
|
for s in ["", "hello world", "unicode ümlaut ✅", "a" * 500]
|
|
]
|
|
comp_inputs = [
|
|
"",
|
|
"# comment\n\nreal line here\n====\n// slash comment\n(_source_: x)\n[source: y]\ntiny\nkeep this line too\n\n" + "z" * 900,
|
|
"line one\nline two\nline three",
|
|
"====",
|
|
"ab\ncdefgh",
|
|
]
|
|
for i, s in enumerate(comp_inputs):
|
|
cases.append({"fn": "compress", "name": f"compress_{i}",
|
|
"input": {"text": s},
|
|
"expected": {"compressed": ch._compress(s)}})
|
|
out = {"oracle": "cache._hash", "generated": "2026-10-07", "cases": cases}
|
|
(REPO / "src/go/cache" / "truth_hash.json").write_text(json.dumps(out, indent=1) + "\n")
|
|
print(f"wrote {len(cases)} cases")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|