gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf16-setf953bf03a|||PR ident setF mirror dropped (hybriel#370)mref16-setf/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

  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre
  • 675493b1ident#42: editing an identity upserts the one edited row (face editIdentity answers { identity, row }); a create or delete keeps the whole list because the rows' position-dependent parts (default, Delete, Identity n) changemre
  • 45e55303ident#42: an app write patches one row: upsert on create, edit and new secret, one-argument remove on delete; the faces answer the changed app (or the deleted id), not the whole listmre
  • 991641d4Merge branch 'f10-access' into mainIdent
  • e56d8273|||PR ident#34 part 4: access and inbox fixed classesmre
  • df7696dbident#34: tests: access ticks selector quoting fixmre
  • 7215903eident#34: access: the unstyled classes all, app, tick, apptick, plus are dropped; the gate finds the app ticks by input[name=app]mre
  • 69b0a0ceident#34: access: the pick buttons use Style.pickCard instead of class pickmre
  • dc702419Merge branch 'f9-choose' into mainIdent
  • 8caec771|||PR ident#34 restore .choose hookmre