gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit77829b7377829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre77829b73/tests/letcount.py

3.4 KB

  1. #!/usr/bin/env python3
  2. # tests/letcount.py (copied from tickets.worldapi.org mission 010; gitoria mission 002): the code-order counts of an app tree (antcolony docs/code-order.md) — root .hl files, project.hl lines, and every `let`:
  3. # reassigned the name is assigned again later in its block → `let` is right
  4. # loop-bound declared inside a for/while body (re-bound each pass —
  5. # Hybriel refuses a plain declaration there on pass 2) → `let` is right
  6. # never neither → should be a plain declaration
  7. # python3 tests/letcount.py . [-v] (-v lists every `let` that should be a plain declaration) (scans *.hl, components/, lib/, tools/, tests/; not plugins/)
  8. import os, re, sys
  9. root = sys.argv[1]; verbose = '-v' in sys.argv
  10. files = []
  11. for d in ['', 'components', 'lib', 'tools', 'tests']:
  12. p = os.path.join(root, d)
  13. if os.path.isdir(p): files += [os.path.join(p, f) for f in sorted(os.listdir(p)) if f.endswith('.hl')]
  14. def strip(src):
  15. # blank out strings and comments (same length) so braces/names inside them do not count
  16. out = list(src); i = 0; n = len(src)
  17. while i < n:
  18. c = src[i]
  19. if src.startswith('//', i):
  20. j = src.find('\n', i); j = n if j < 0 else j
  21. for k in range(i, j): out[k] = ' '
  22. i = j; continue
  23. if c in '\'"`':
  24. j = i + 1
  25. while j < n and src[j] != c:
  26. if c == "'" and src[j] == '\\' and j + 1 < n and src[j + 1] == "'": j += 2; continue
  27. j += 1
  28. for k in range(i + 1, min(j, n)):
  29. if out[k] != '\n': out[k] = ' '
  30. i = j + 1; continue
  31. i += 1
  32. return ''.join(out)
  33. tot = {'reassigned': 0, 'loop-bound': 0, 'never': 0}
  34. per = {}
  35. for f in files:
  36. s = strip(open(f).read())
  37. opens = []; match = {}; stack = []
  38. for i, c in enumerate(s):
  39. if c == '{': stack.append(i)
  40. elif c == '}' and stack: match[stack.pop()] = i
  41. for m in re.finditer(r'\blet\s+(\w+)\s*=', s):
  42. name, p = m.group(1), m.start()
  43. encl = [o for o, e in match.items() if o < p < e]
  44. encl.sort(reverse=True) # innermost first
  45. inner_end = match[encl[0]] if encl else len(s)
  46. kind = 'never'
  47. if re.search(r'(?<![\w.#])' + re.escape(name) + r'\s*(=(?!=)|\+\+|--|\+=|-=)', s[m.end():inner_end]): kind = 'reassigned'
  48. else:
  49. for o in encl:
  50. head = s[max(0, o - 300):o]
  51. line = head[head.rfind('\n') + 1:] if '\n' in head else head
  52. if re.search(r'=>\s*$', head) or re.match(r'\s*(on\s|static\s|\w+\s*\([^)]*\)\s*$)', line) and not re.match(r'\s*(if|for|while|else)\b', line): break
  53. if re.search(r'\b(for|while)\s*\([^{}]*\)\s*$', head): kind = 'loop-bound'; break
  54. tot[kind] += 1
  55. per.setdefault(os.path.relpath(f, root), {'reassigned': 0, 'loop-bound': 0, 'never': 0})[kind] += 1
  56. if verbose and kind == 'never': print(f' never: {os.path.relpath(f, root)}:{s.count(chr(10), 0, p) + 1} {name}')
  57. rootHl = [f for f in os.listdir(root) if f.endswith('.hl')]
  58. pl = sum(1 for _ in open(os.path.join(root, 'project.hl')))
  59. print(f'root .hl files: {len(rootHl)} ({" ".join(sorted(rootHl))})')
  60. print(f'project.hl lines: {pl}')
  61. print(f'let total {sum(tot.values())}: reassigned {tot["reassigned"]}, loop-bound {tot["loop-bound"]}, never reassigned {tot["never"]}')
  62. for f, k in sorted(per.items()): print(f' {f}: {k}')

Branches

Latest commits

  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
  • 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre
  • fdb9ed28gitoria#41: repo owners can connect an app (merge w41-apps-connect)mre
  • 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
  • 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
  • b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
  • 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
  • 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
  • c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
  • c50d17efKeep function-route not-found style in shared stylesheetmre
  • e42d78d3Preserve ticket state CSS and document function-route style gapmre
  • c6b7154eWIP gitoria#26: move styles into nested component blocksmre
  • 77a2c31cgitoria#31: plain declarations instead of needless let in lib/ and tools/ (103 let removed, 137 kept because reassigned); no other changemre
  • 4b98ab62gitoria: an ident access key (idt_) works as the git password; read key clones only, bad key 401, ident down 503 (ident#27); gate tests/ident-access-gitoria.mjs in deploy.shmre
  • 1185f686gitoria#36: a failed return from tickets shows a note on the settings page and leaves one log line per outcome; no code is exchangedmre
  • 5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre
  • 241ef3f9deploy.sh: rebuild the sshd image before up -d (GO34c)mre
  • 821cdbb1gitoria#34b: styles, create-repo tool, docs, push/ssh gates sign in through the selector, shots scriptmre
  • a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre