gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf2-api-bugs26117255|||PR apps API: review comments on files with spaces in their namemref2-api-bugs/tests/realdata-compare.py

4.8 KB

  1. #!/usr/bin/env python3
  2. # tests/realdata-compare.py (gitoria mission 002): compare two tests/realdata-baseline.mjs outputs. Masks only what is
  3. # not the app's output:
  4. # every file "at":<ms> (the seed's request time), "site":"<file:l:c>" and Child@<line>:<col> (source positions of
  5. # View nodes / mount keys: they move when lines move), ?v=<hash> (hl:web's content hashes of the modules),
  6. # state=<nonce> in the tickets connect redirect (random per click)
  7. # 'w-' files (the writes) the new mpackdb ids, the stored times ("YYYY-MM-DD HH:MM", createdMs), the token secret
  8. # '-module-' files (the browser half: component modules, runtime, client) — a module is the component's own code + tables
  9. # of the statics it imports (a real client-callable function, or a refusing server-only stub naming its
  10. # file). Moving a static to another file changes those tables and the source positions, not the behaviour, so
  11. # a module counts as the same when (1) its own code is the same with every source position masked and (2) every
  12. # imported name its own code uses is the same kind (function / stub), a function with the same body. A
  13. # declaration's keyword is masked too (`var x=` ↔ `const x=`): Hybriel compiles `let x` to `var` and a plain
  14. # declaration to `const` — exactly what the `let` cleanup changes.
  15. # python3 tests/realdata-compare.py <dirA> <dirB> [-v] → counts + the differing files; exit 1 on a real difference
  16. import os, re, sys, difflib
  17. a, b = sys.argv[1], sys.argv[2]; verbose = '-v' in sys.argv
  18. masks = [(re.compile(r'\\"at\\":\d+'), r'\"at\":T'), (re.compile(r'"at":\d+'), '"at":T'),
  19. (re.compile(r'\\"site\\":\\"[^"\\]*\\"'), r'\"site\":S'), (re.compile(r'"site":"[^"]*"'), '"site":S'),
  20. (re.compile(r'\?v=[0-9a-f]+'), '?v=H'), (re.compile(r'([A-Z]\w*)@\d+:\d+'), r'\1@L:C'),
  21. (re.compile(r'state%3D[0-9a-f]+|state=[0-9a-f]+'), 'state=NONCE')]
  22. wmasks = [(re.compile(r'\b0m[0-9a-z]{10}\b'), 'ID'), (re.compile(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}'), 'TIME'),
  23. (re.compile(r'createdMs\\?":\d+'), 'createdMs":MS'), (re.compile(r'gtr_[0-9a-f]{40}'), 'gtr_TOKEN')]
  24. POS = re.compile(r'[\w-]+\.hl:\d+:\d+|[A-Z]\w*@\d+:\d+|\b(?:var|const) (?=\w+=)')
  25. def moduleParts(t):
  26. t = re.sub(r'\?v=[0-9a-f]+', '?v=H', t)
  27. kinds, own = {}, []
  28. lines = t.split('\n'); i = 0
  29. while i < len(lines):
  30. l = lines[i]
  31. m = re.match(r'\$_\d+\.(\w+)=(.*)$', l)
  32. if m:
  33. if m.group(2).startswith('()=>_55('): kinds.setdefault(m.group(1), ('stub', ''))
  34. else:
  35. body = [m.group(2)]
  36. while not lines[i].endswith('}));') and not (lines[i].endswith(';') and lines[i] is l and '=>{' not in l):
  37. i += 1; body.append(lines[i])
  38. kinds[m.group(1)] = ('fn', POS.sub('P', re.sub(r'\$_\d+', '$_N', '\n'.join(body))))
  39. i += 1; continue
  40. if l.startswith('import{') and '/__hl/hl-runtime.js' in l: i += 1; continue # the runtime helpers the tables use too
  41. if re.match(r'const \$_\d+=\{\};$', l) or re.match(r'const \w+=\$_\d+\.\w+;$', l) or re.match(r'const \w+=\(\)=>_55\(2,', l):
  42. m2 = re.match(r'const (\w+)=\(\)=>_55\(2,', l)
  43. if m2: kinds[m2.group(1)] = ('plugin', '')
  44. i += 1; continue
  45. own.append(POS.sub('P', re.sub(r'\$_\d+', '$_N', l))); i += 1
  46. return kinds, '\n'.join(own)
  47. def sameModule(x, y):
  48. kx, ox = moduleParts(x); ky, oy = moduleParts(y)
  49. if ox != oy: return False
  50. words = set(re.findall(r'\b\w+\b', ox))
  51. return all(kx.get(n) == ky.get(n) for n in words & (set(kx) | set(ky)))
  52. def norm(t, w):
  53. for r, s in masks: t = r.sub(s, t)
  54. if w:
  55. for r, s in wmasks: t = r.sub(s, t)
  56. return t
  57. fa, fb = sorted(f for f in os.listdir(a) if f != '0000-server-log'), sorted(f for f in os.listdir(b) if f != '0000-server-log')
  58. if fa != fb: print('FILE LISTS DIFFER', sorted(set(fa) ^ set(fb))[:20]); sys.exit(1)
  59. same = masked = modules = 0; bad = []
  60. for f in fa:
  61. x, y = open(os.path.join(a, f), errors='replace').read(), open(os.path.join(b, f), errors='replace').read()
  62. if x == y: same += 1; continue
  63. w = '-w-' in f
  64. if norm(x, w) == norm(y, w): masked += 1; continue
  65. if '-module-' in f and sameModule(x, y): modules += 1; continue
  66. bad.append(f)
  67. if verbose:
  68. print('==== DIFF', f)
  69. for l in list(difflib.unified_diff(norm(x, w).split('\n'), norm(y, w).split('\n'), lineterm='', n=0))[:12]: print(' ', l[:300])
  70. reads = sum(1 for f in fa if '-w-' not in f)
  71. print(f'{len(fa)} files ({reads} reads, {len(fa) - reads} writes): {same} byte-identical, {masked} identical after masking, {modules} browser modules the same (code, imported functions), {len(bad)} DIFFERENT')
  72. for f in bad[:40]: print(' DIFF', f)
  73. sys.exit(1 if bad else 0)

Branches

Latest commits

  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
  • f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
  • 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
  • 16a3530fMerge branch 'heap-revert' into mainGitoria
  • 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
  • 13f0c342Merge branch 'hl25-records' into mainGitoria
  • a002ecb7|||PR records: HL25 report, heap helper, logmre
  • 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
  • fefaedd2log: tracker PR-only, HL25 startedmre
  • 21aa57calog: parkmre
  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre
  • b88e39f1log: privacy cleanup donemre
  • bfd7826ddocs: neutral example organisation namemre