"""Independent point-coverage oracle; no RocksDB code is copied here.""" import argparse import hashlib import json import subprocess from datetime import datetime, timezone import platform from pathlib import Path SHAPES = ("nested", "disjoint", "coincident") MODES = ("read", "none", "middle", "all") SIZES = tuple(range(1, 65)) + (256,) def ranges(shape, n): if not isinstance(n, int) or not 1 <= n <= 256: raise ValueError("n must be an integer in 1..256") if shape == "nested": return [(i, 2 * n - i, i + 1) for i in range(n)] if shape == "disjoint": return [(2 * i, 2 * i + 1, i + 1) for i in range(n)] if shape == "coincident": return [(0, 1, i + 1) for i in range(n)] raise ValueError("unknown shape") def oracle(shape, n, mode): if mode not in MODES: raise ValueError("unknown mode") source = ranges(shape, n) endpoints = sorted({x for a, b, _ in source for x in (a, b)}) snapshots = [] if mode == "none" else ([n // 2] if mode == "middle" else list(range(1, n + 1))) rows = [] for a, b in zip(endpoints, endpoints[1:]): covering = [seq for start, end, seq in source if start <= a < end] if not covering: continue if mode == "read": retained = covering else: # Independently ask what each snapshot and the latest view can see. retained = {max(covering)} for snapshot in snapshots: visible = [seq for seq in covering if seq <= snapshot] if visible: retained.add(max(visible)) rows.append([a, b, sorted(retained, reverse=True)]) return rows def summary(shape, n, mode, rows): encoded = json.dumps(rows, separators=(",", ":")).encode() return {"shape": shape, "inputRanges": n, "mode": mode, "spans": len(rows), "sequenceEntries": sum(len(row[2]) for row in rows), "stackSha256": hashlib.sha256(encoded).hexdigest()} def check_results(result): expected = [summary(shape, n, mode, oracle(shape, n, mode)) for shape in SHAPES for n in SIZES for mode in MODES] if result["cases"] != expected or result["caseCount"] != len(expected): raise ValueError("native observation differs from independent oracle") if result["kind"] != "native-component-observation" or result["mismatches"] != 0: raise ValueError("invalid observation classification") rows = [row for row in expected if row["shape"] == "nested" and row["inputRanges"] in (4, 16, 64, 256)] if result["tableRows"] != rows: raise ValueError("publication summary differs from full observations") def observe(binary): cases = [] for shape in SHAPES: for n in SIZES: for mode in MODES: actual = json.loads(subprocess.check_output([str(binary), shape, str(n), mode], timeout=20)) if actual != oracle(shape, n, mode): raise ValueError(f"native mismatch: {shape}, {n}, {mode}") cases.append(summary(shape, n, mode, actual)) result = {"kind": "native-component-observation", "rocksdbVersion": "9.7.3", "observedAt": datetime.now(timezone.utc).isoformat(), "runtime": {"python": platform.python_version(), "platform": platform.system() + " " + platform.machine(), "compiler": subprocess.check_output(["g++", "--version"], text=True).splitlines()[0], "binarySha256": hashlib.sha256(binary.read_bytes()).hexdigest()}, "sourceCommit": "0e2801ac30b3f283c3b14e523ba3667eca024f09", "caseCount": len(cases), "mismatches": 0, "keyEncoding": "Eight lowercase zero-padded ASCII hexadecimal digits; bytewise comparator", "sequencePolicy": "Distinct sequence i+1 for every input range; duplicate-sequence inputs excluded", "userDefinedTimestamps": False, "cases": cases, "tableRows": [row for row in cases if row["shape"] == "nested" and row["inputRanges"] in (4, 16, 64, 256)], "limits": ["In-memory native fragment-list component, not a DB workload or performance benchmark.", "No allocation bytes, construction CPU, lookup latency, SST reclamation or recovery measured.", "No claim of novelty or replication of GLORAN; no user-defined timestamps or duplicate sequences."]} check_results(result) return result if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--observe", type=Path) parser.add_argument("--output", type=Path) parser.add_argument("--check", type=Path) args = parser.parse_args() if args.observe and args.output and not args.check: result = observe(args.observe.resolve()) args.output.write_text(json.dumps(result, indent=2) + "\n") print(json.dumps({"caseCount": result["caseCount"], "mismatches": result["mismatches"]})) elif args.check and not args.observe and not args.output: check_results(json.loads(args.check.read_text())) print("780 stored native cases agree with the independent oracle") else: parser.error("use --observe BINARY --output JSON, or --check JSON")