gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf8-sharedd69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmref8-shared/tests/realdata-compare.py

5.6 KB

  1. #!/usr/bin/env python3
  2. # tests/realdata-compare.py (ident mission 009, from gitoria's mission 002): compare two tests/realdata-baseline.mjs
  3. # outputs. Masks only what is not the app's output:
  4. # every file "at":<ms> (the seed's request time), "since":<ms> (a session's sign-in time), "who":<hex> (the connection), "site":"<file:l:c>" and Child@<line>:<col> (source positions of
  5. # View nodes / mount keys: they move when lines move), ?v=<hash> and hl-shell-<hash> (hl:web's content hashes of the modules, the worker's cache name)
  6. # 'w-' files (the writes) what is random or a clock per run: new mpackdb ids, rids / codes / pick ids / hashes (hex),
  7. # API keys and secrets, invite tokens, new short ids, millisecond times, "YYYY-MM-DD HH:MM" stamps, six-digit codes;
  8. # the stored state (w-store) is compared line by line, sorted after masking
  9. # '-module-' files (the browser half) count as the same when their own code is the same with every source position
  10. # masked and every imported name it uses is the same kind with the same body (moving a static to another
  11. # file changes the module's tables, not the behaviour); `var x=` ↔ `const x=` is masked (the `let` step).
  12. # python3 tests/realdata-compare.py <dirA> <dirB> [-v] → counts + the differing files; exit 1 on a real difference
  13. import os, re, sys, difflib
  14. a, b = sys.argv[1], sys.argv[2]; verbose = '-v' in sys.argv
  15. masks = [(re.compile(r'\\"at\\":\d+'), r'\"at\":T'), (re.compile(r'"at":\d+'), '"at":T'),
  16. (re.compile(r'\\"site\\":\\"[^"\\]*\\"'), r'\"site\":S'), (re.compile(r'"site":"[^"]*"'), '"site":S'),
  17. (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'),
  18. (re.compile(r'(\\?"since\\?":)\d+'), r'\1T'), (re.compile(r'(\\?"who\\?":\\?")[0-9a-f]+'), r'\1W')]
  19. wmasks = [(re.compile(r'pk_[0-9a-f]{32}'), 'pk_KEY'), (re.compile(r'sk_[0-9a-f]{48}'), 'sk_SECRET'), (re.compile(r'\b0m[0-9a-z]{10}\b'), 'ID'), (re.compile(r'\b[0-9a-f]{64}\b'), 'H64'), (re.compile(r'\b[0-9a-f]{48}\b'), 'H48'),
  20. (re.compile(r'\b[0-9a-f]{32}\b'), 'H32'),
  21. (re.compile(r'\b1[789]\d{11}\b'), 'MS'), (re.compile(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}'), 'TIME'),
  22. (re.compile(r'(?<![\d.])\d{6}(?![\d.])'), 'CODE'), (re.compile(r'(shortId\\?":\\?"|class="shortid">)[0-9a-z]{5}'), r'\1SHORT')]
  23. POS = re.compile(r'[\w-]+\.hl:\d+:\d+|[A-Z]\w*@\d+:\d+|\b(?:var|const) (?=\w+=)')
  24. def moduleParts(t):
  25. t = re.sub(r'\?v=[0-9a-f]+', '?v=H', t)
  26. kinds, own = {}, []
  27. lines = t.split('\n'); i = 0
  28. while i < len(lines):
  29. l = lines[i]
  30. m = re.match(r'\$_\d+\.(\w+)=(.*)$', l)
  31. if m:
  32. if re.match(r'\(\)=>_\d+\(', m.group(2)): kinds.setdefault(m.group(1), ('stub', ''))
  33. else:
  34. body = [m.group(2)]
  35. while not lines[i].endswith('}));') and not (lines[i].endswith(';') and lines[i] is l and '=>{' not in l):
  36. i += 1; body.append(lines[i])
  37. kinds[m.group(1)] = ('fn', POS.sub('P', re.sub(r'\$_\d+', '$_N', '\n'.join(body))))
  38. i += 1; continue
  39. if l.startswith('import{') and '/__hl/hl-runtime.js' in l: i += 1; continue
  40. if re.match(r'const \$_\d+=\{\};$', l) or re.match(r'const \w+=\$_\d+\.\w+;$', l) or re.match(r'const \w+=\(\)=>_\d+\(2,', l):
  41. m2 = re.match(r'const (\w+)=\(\)=>_\d+\(2,', l)
  42. if m2: kinds[m2.group(1)] = ('plugin', '')
  43. i += 1; continue
  44. own.append(POS.sub('P', re.sub(r'\$_\d+', '$_N', l))); i += 1
  45. return kinds, '\n'.join(own)
  46. def sameModule(x, y):
  47. kx, ox = moduleParts(x); ky, oy = moduleParts(y)
  48. if ox != oy: return False
  49. words = set(re.findall(r'\b\w+\b', ox))
  50. return all(kx.get(n) == ky.get(n) for n in words & (set(kx) | set(ky)))
  51. # mission 010: Hybriel 0f396652's hl:web registers its own routes FIRST and one more (/__hl/up); the seed lists them, so the
  52. # route entries are compared as a set without /__hl/up (the answers themselves are compared byte for byte, line for line)
  53. ROUTE = re.compile(r'\{\\?"kind\\?":\\?"function\\?",\\?"pattern\\?":\\?"([^"\\]*)\\?"\}')
  54. def routes(t):
  55. found = ROUTE.findall(t)
  56. return re.sub(r',\]', ']', re.sub(r'\[,', '[', re.sub(r',{2,}', ',', ROUTE.sub('', t)))) + ' ROUTES ' + ' '.join(sorted(r for r in found if r != '/__hl/up'))
  57. def norm(t, w, store=False):
  58. t = routes(t)
  59. for r, s in masks: t = r.sub(s, t)
  60. if w:
  61. for r, s in wmasks: t = r.sub(s, t)
  62. if store: t = '\n'.join(sorted(t.split('\n')))
  63. return t
  64. skip = {'0000-server-log'}
  65. fa, fb = sorted(f for f in os.listdir(a) if f not in skip), sorted(f for f in os.listdir(b) if f not in skip)
  66. if fa != fb: print('FILE LISTS DIFFER', sorted(set(fa) ^ set(fb))[:20]); sys.exit(1)
  67. same = masked = modules = 0; bad = []
  68. for f in fa:
  69. x, y = open(os.path.join(a, f), errors='replace').read(), open(os.path.join(b, f), errors='replace').read()
  70. if x == y: same += 1; continue
  71. w = '-w-' in f; st = f.endswith('-w-store')
  72. if norm(x, w, st) == norm(y, w, st): masked += 1; continue
  73. if '-module-' in f and sameModule(x, y): modules += 1; continue
  74. bad.append(f)
  75. if verbose:
  76. print('==== DIFF', f)
  77. for l in list(difflib.unified_diff(norm(x, w, st).split('\n'), norm(y, w, st).split('\n'), lineterm='', n=0))[:12]: print(' ', l[:300])
  78. reads = sum(1 for f in fa if '-w-' not in f)
  79. 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')
  80. for f in bad[:40]: print(' DIFF', f)
  81. sys.exit(1 if bad else 0)

Branches

Latest commits

  • d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmre
  • 3a64dc48ident#34: chipLook: radius as the same var() string (a bare token name in a static does not compile); selector gate selectormre
  • eb039073ident#34: tests: signin and migration find the choice without the classmre
  • 4b94a594ident#34: tests: fix selector of the identity choicemre
  • bebc88e4ident#34: main.hl drops the unstyled classes inboxlink and whomre
  • b4e7ad04ident#34: the identity choice link/button has no class (rule on #chooselist a)mre
  • 3c33d6eaident#34: the connection link in inbox has no class (rule on #conns a)mre
  • dc97ec0dident#34: the Notif. chip and the Used in link share chipLook (Style.pChip) instead of the classes chip/used/notifmre
  • 378bd432ident#34: the identity picture look is a static in styles.hl (Style.pAvatar); sizes stay with each listmre
  • 1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre
  • ddc7d135Merge branch 'f7-hooks' into mainIdent
  • eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
  • ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre