gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb37cc1dab37cc1da|||PR Vendor Hybriel day59Atlasb37cc1da/tests/realdata-compare.py

5.3 KB

  1. #!/usr/bin/env python3
  2. # tests/realdata-compare.py (calendar mission 001, copied from notes mission 002 / 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 / offline block's request time, also double-escaped), the port in the echoed Host header, "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), hl-shell-<hash> (the service worker's
  7. # cache name: a hash of all modules, so it changes with any code change)
  8. # 'w-' files (the writes) the new mpackdb ids, the version stamps (`edited`, ms), the random login tags
  9. # '-module-' files (the browser half: component modules, runtime, client) — a module is the component's own code + tables
  10. # of the statics it imports (a real client-callable function, or a refusing server-only stub naming its
  11. # file). Moving a static to another file changes those tables and the source positions, not the behaviour, so
  12. # a module counts as the same when (1) its own code is the same with every source position masked and (2) every
  13. # imported name its own code uses is the same kind (function / stub), a function with the same body. A
  14. # declaration's keyword is masked too (`var x=` ↔ `const x=`): Hybriel compiles `let x` to `var` and a plain
  15. # declaration to `const` — exactly what the `let` cleanup changes.
  16. # python3 tests/realdata-compare.py <dirA> <dirB> [-v] → counts + the differing files; exit 1 on a real difference
  17. import os, re, sys, difflib
  18. a, b = sys.argv[1], sys.argv[2]; verbose = '-v' in sys.argv
  19. masks = [(re.compile(r'(\\+)"at(\\+)":\d+'), r'\1"at\2":T'), (re.compile(r'calendar\.test:\d+'), 'calendar.test:PORT'), (re.compile(r'"at":\d+'), '"at":T'),
  20. (re.compile(r'\\"site\\":\\"[^"\\]*\\"'), r'\"site\":S'), (re.compile(r'"site":"[^"]*"'), '"site":S'),
  21. (re.compile(r'\?v=[0-9a-f]+'), '?v=H'), (re.compile(r'hl-shell-[0-9a-f]+'), 'hl-shell-H'), (re.compile(r'([A-Z]\w*)@\d+:\d+'), r'\1@L:C'),
  22. (re.compile(r'state%3D[0-9a-f]+|state=[0-9a-f]+'), 'state=NONCE')]
  23. wmasks = [(re.compile(r'\b0m[0-9a-z]{10}\b'), 'ID'), (re.compile(r'\b1[6-9]\d{11}\b'), 'MS'), (re.compile(r'\b[0-9a-f]{32}\b'), 'TAG')]
  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. # the names the component's own code takes from the module scope: not `this.x` / `o.x`, not its own methods
  51. # (`async build(…){` — calendar's month view has a method `build`, events-helpers.hl a static `build`)
  52. words = set(re.findall(r'(?<![.\w$])[A-Za-z_]\w*\b', ox)) - set(re.findall(r'\basync (\w+)\(', ox))
  53. return all(kx.get(n) == ky.get(n) for n in words & (set(kx) | set(ky)))
  54. def norm(t, w):
  55. for r, s in masks: t = r.sub(s, t)
  56. if w:
  57. for r, s in wmasks: t = r.sub(s, t)
  58. return t
  59. 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')
  60. if fa != fb: print('FILE LISTS DIFFER', sorted(set(fa) ^ set(fb))[:20]); sys.exit(1)
  61. same = masked = modules = 0; bad = []
  62. for f in fa:
  63. x, y = open(os.path.join(a, f), errors='replace').read(), open(os.path.join(b, f), errors='replace').read()
  64. if x == y: same += 1; continue
  65. w = '-w-' in f
  66. if norm(x, w) == norm(y, w): masked += 1; continue
  67. if '-module-' in f and sameModule(x, y): modules += 1; continue
  68. bad.append(f)
  69. if verbose:
  70. print('==== DIFF', f)
  71. for l in list(difflib.unified_diff(norm(x, w).split('\n'), norm(y, w).split('\n'), lineterm='', n=0))[:12]: print(' ', l[:300])
  72. reads = sum(1 for f in fa if '-w-' not in f)
  73. 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')
  74. for f in bad[:40]: print(' DIFF', f)
  75. sys.exit(1 if bad else 0)

Branches

Latest commits

  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas
  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
  • 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
  • cc759328Merge sb3-standby: calendar deploys through its standbymre
  • f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre