gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita81abdc9a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmrea81abdc9/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

  • a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
  • 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
  • 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
  • 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
  • a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
  • 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
  • c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre
  • e307d69agitoria: say what is per process during the hand-overmre
  • f0cbe6a6gitoria: standby service on port 45014 and a deploy that hands over through it without a gapmre
  • 727cd083gitoria#25: README: vendor notes for Hybriel c1b1010f and the page cachemre
  • 61b72dedgitoria#25: re-vendor Hybriel master c1b1010f (W149 page cache), key the repo Readme page by slug and main commit, extend the readme-cache gatemre
  • 5b0b4b9ereadme-cache gate: use the security gate's ports when no own ports are givenmre
  • bc8f20d9gitoria#25: re-vendor Hybriel c09538bb with the W141 render cache, cache the homepage per commit, add the readme-cache gatemre
  • 9feebbd3Re-vendor Hybriel to ded47c13 (W145: Firefox start script fix)mre
  • 28ed41e5gitoria#24: one sign-in comes from hl:web batch 20, the /session/share workaround is gonemre
  • 3b2669e4gs: drop the unbuildable legacy check, fix pwa fetchmre
  • 2a2fdd77gs: C2 check before cookie experimentsmre
  • 76e0587aWIP gs 2mre
  • a80da7bdWIP gs: security gate for lazy sessions, g24 browser checksmre
  • 23fb05d8re-vendor Hybriel aaa39e69 (hl:web batch 20: login emit and Sessions.mint, tab follows a login, signed-in session cookie wins among duplicates and is re-issued with the Domain, W85 faster render, lazy sessions)mre