gitoriaLog in with ident

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmain4f47843egate: ticket links use the tickets short URL (/<slug>/<n>, tickets#25)mremain/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

  • mainmain branch

Latest commits

  • 4f47843egate: ticket links use the tickets short URL (/<slug>/<n>, tickets#25)mre
  • 86605446mission 002 (code order) 4/4: README file map + import order + 'Same output' test + gate run with a tickets HEAD copy, STATUS (entry, lessons), LOG, report; tests/realdata-baseline.mjs + realdata-compare.py (a cleanup answers the same on live data: pages, modules, API, git over HTTPS and SSH, faces), tests/letcount.pymre
  • cc7bf7bamission 002 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (289 lets → plain declarations; 213 left: 125 reassigned, 88 loop-bound; no member/import/param clash). gates 200/0, 46/0, 44/0; real-data reads + writes identical (browser modules: var → const only)mre
  • 090a20c6mission 002 (code order) 2/4: one lib/ file per topic — git.hl split into git (calls, branches, init, temp folder) / homepage / code / pulls / releases (+ git-helpers: paths, ids, |||PR/|||RL markers); repos-helpers, tickets-helpers, transport-helpers; util.hl = localtime + env, storage dir, addresses, lists, text checks, one newest-first sort (was 3 copies); the function routes out of project.hl into lib/api.hl (thin; plumbing in api-helpers.hl), sshgate.hl folded into api.hl + sshkeys.hl keyLine + repos.hl mayPush; 'Make main' and the merge answer out of the faces (code.hl makeMain, pulls.hl pullsView), one login helper (users.hl userOfLoginCode); project.hl is the map. Session-writing routes get &req + &server.sessions. gates 200/0, 46/0, 44/0; real-data identical except /login/failed now shows the parked reason for a browser that already had a session (the old copy-of-req lost it)mre
  • 110c2799mission 002 (code order) 1/4: .hl files out of the root — lib/ (api, git, localtime, markdown, repos, sshgate, sshkeys, tickets, tokens, transport, users), components/styles.hl; jsoncheck.hl removed (imported nowhere); import paths only. gates 200/0, 46/0, 44/0; real-data reads + writes identicalmre
  • fdfb4b1bgitoria: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 200/0, 46/0, 44/0mre
  • 5b46ac84antcolony#40: LOG.md — missions 069/072 are antcolony missions (report paths on Byrodin)mre
  • 5602ff41gitoria: Hybriel master 190aa11d (fc838894 GC correctness, #127 mountKids by reference, #126, #48) — tracker README flat; gates 200/0, 46/0, 44/0mre
  • e85eaf01gitoria: 069 round 2 — hybriel 1a096ad3 not adopted (Markdown SSR still grows); browser gate waits for the server-side logout before restartmre
  • 09ce4f3fgitoria: mission 069 re-vendor hybriel 8efba065 stopped (big SSR pages grow + slow down); lambda audit clean; old vendor keptmre
  • 3dc43108antcolony#40: mission references point to the moved missionsmre
  • 8d9450fdantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 205d5fe4gitoria: Hybriel master ff51cf46; ssh keys/tokens no double rows (session sync); gates follow #20mre
  • 9b27cb26gitoria#21: installable app (manifest, service worker, offline start page), own iconmre
  • 68dcb603deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • e2deed6dgitoria#20: "Add code" only on the Code page of an empty repository, no collapsiblemre
  • 8bb97ffddeploy.sh: never send .git or .gitignore to Byrodinmre
  • fd981932State of 2026-09-27; bin/ no longer tracked (Hybriel commit is in README)mre
  • 4a2d7125initial commitmre