re: diff_optrace.py — engine-vs-VM offset-path divergence oracle

Pure first_divergence + pick_scene_codebase (longest-common-prefix codebase
identification), unit-tested (test_diff_optrace.py, 4/4). CLI loads the engine
jsonl + VM json, isolates the scene's codebase, and reports the first divergence
with the mis-modeled instruction and +/-3 ops of context on each side (opcode
+ rendered line via sys4load).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-09 11:25:20 -04:00
parent 06231b9459
commit 0ba965d7e6
2 changed files with 209 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
# tools/test_diff_optrace.py (plain runner)
import sys
from diff_optrace import first_divergence, pick_scene_codebase
FAILS=[]
def check(c,m): (FAILS.append(m) or print("FAIL:",m)) if not c else print("ok:",m)
def test_equal_no_divergence():
r = first_divergence([0,1,2,3],[0,1,2,3])
check(r["index"] is None and r["agreed"]==4, "equal traces -> no divergence")
def test_first_divergence_point():
r = first_divergence([0,1,2,9],[0,1,2,3])
check(r["index"]==3 and r["a"]==9 and r["b"]==3, "divergence at first differing offset")
def test_prefix_shorter_vm():
r = first_divergence([0,1,2,3],[0,1]) # vm ends early
check(r["index"]==2 and r["b"] is None and r["agreed"]==2, "shorter VM trace flagged at end")
def test_pick_codebase_by_longest_common_prefix():
entries=[{"codebase":100,"offset":0},{"codebase":100,"offset":5}, # cb100: [0,5,...]
{"codebase":200,"offset":0},{"codebase":200,"offset":1},{"codebase":200,"offset":2}]
check(pick_scene_codebase(entries,[0,1,2])==200, "codebase matching VM prefix chosen")
def main():
test_equal_no_divergence(); test_first_divergence_point(); test_prefix_shorter_vm()
test_pick_codebase_by_longest_common_prefix()
print("FAILURES:",len(FAILS)); return 1 if FAILS else 0
if __name__=="__main__": sys.exit(main())