gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6bfbd3f26bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre6bfbd3f2/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

  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
  • 80965c08ident#28: README says the deploy goes through the standbymre
  • 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
  • a544b261ident#28: README names the new vendored Hybrielmre
  • 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
  • 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre
  • f5a55f8aident#11: apps can ask for nickname, firstname and lastname (fields list on /api/exchange, new POST /api/profile); empty fields come back null; gate checks, READMEmre
  • d8be66ebident: report and log line for the widget cache and frame height changemre
  • 2068f61aident#31: browsers revalidate the widget scripts on every load; the sign-in frame is exactly as tall as the current step (the frame page reports its height, selector.js accepts it from ident only)mre
  • a22d2daaident#31: the sign-in frame is no taller than the tallest step needs (plain CSS height per width), gate check for itmre
  • a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemre
  • 5c481bfdident#31: sign in to ident inside the selector's panel (email, code, identity in an iframe; a new address goes to ident in the same tab and comes back)mre
  • 061abfe2ident: the apps gate waits until the test app's login button stops moving before it clicks (the page grows after load and the click missed about every second run)mre
  • 45f7e4daident: the user menu's Sign out waits for the server before it reloads (the apps gate failed because the session could still be signed in)mre
  • f07658c7ident: home page shows the account once (account bar removed, the user menu carries email, Sign out, Sign out everywhere); wildcard origins https://*.domain for apps on many subdomains; gates follow (WIP: gates not re-run after the last edits)mre
  • f2c43bbbtheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 6d4f996esessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 029eb5e5deploy: security gate (tests/security.mjs)mre
  • d3c065a8security audit (SI): uploadMax 0, Secure __Host- cookie behind https, headers on function routes/files, page CSP+referrer meta, app/identity caps, tests/security.mjs, reportmre
  • 5561a0cbreport I4-mobilemre