gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainfe209ffeMerge branch 'w56-owner-members' into mainGitoriamain/reports/W40-REPORT.md

10.2 KB

  1. # W40 report — gitoria#40: a pull request gets a stable number and a fetchable head ref
  2. Branch `w40-pr-number` (worktree `W40/wt`, base 06d622d), 2 commits: b9137ff (the feature + gate), 2ef23df (browser gate reads the title without "#N"). Nothing pushed, deployed or written to tickets. Live/byrodin never touched.
  3. ## Built
  4. - **lib/pullsync.hl** (new, topic file) + **lib/pullsync-helpers.hl**. Tables (storage `pullrecs.db`, `pullinit.db`) are keyed by the repo's `@id` (field `rid`), never the slug.
  5. Record: number N (max+1 per repo, records are never deleted → never reused), sha of the `|||PR` commit, source, target (+ `implicit` = follows the main branch), state open|closed|merged, head, **heads** (every head the PR has had), authorId/authorName, createdMs/updatedMs.
  6. - `ensurePulls(slug)`: numbers existing PRs once, quietly (no changes), oldest commit time first. Called before a push lands (transport.hl) and when /pulls is built.
  7. - `syncPulls(slug, userId)`: returns and logs CHANGES `{number, action, before, after, forced, mergeCommit, sender}`. Rules per contract §4: closed = branch gone or `|||PR` commit no longer on it; reopened = comes back; synchronize = tip moved, `forced` = old tip not an ancestor; merged = the `|||PR` commit is in the target (final), `mergeCommit` = first commit on the target's first-parent line that has the PR commit as ancestor (the merge commit; for a fast-forward that commit itself). `refs/pull/N/head` is set with `update-ref <ref> <new> <old>` BEFORE the change is returned; if that fails the PR state is not saved and the next sync retries.
  8. - Called after a successful git-receive-pack (transport.hl, next to notifyPush) and after the Merge button (components/pulls.hl). Log: JSON line per change in `<storage>/pull-changes.log` + console line `pull-change {...}` (gitoria#43 replaces it).
  9. - `pullObject(slug, N)`: contract §4 pull JSON (number, title, body, draft=false, state, author{id,name}, source, target, head, ref, baseRef, base, mergeBase, tickets, url, created, updated). No route (#42/#44).
  10. - **wasHeadOf(slug, N, sha)** → bool (new, from your added scope): true for every head the PR ever had (also after a force-push), false for a never-head sha and for a head of another PR. #44 uses it for 409 `stale_head`. Heads are recorded at opened/synchronize/reopened/merged. Note: after a force-push the old head commit is unreferenced and git gc may delete it (a fetch of it then fails); not solved here (would need `refs/pull/N/heads/<sha>` refs).
  11. - **refs/pull/* not pushable**: `-c receive.hideRefs=refs/pull` on every git call of transport.hl (existing repos too), `receive.hideRefs` also set in a new repo's config (git.hl initRepo), and the sshd door (`docker/sshd/gitoria-shell`) sets it via GIT_CONFIG_* env (NOT tested: needs the docker sshd). Fetch of `refs/pull/N/head` still works. Not in any branch list: branches are read from `refs/heads` only (checked in the code/branch/pulls HTML and `for-each-ref refs/heads`).
  12. - **/pulls shows "#N"** before each title (components/pulls.hl, `withNumbers`). Existing gate tests/browser.mjs read `.subject` textContent → adjusted to strip the leading `#N`, plus one new check (numbers #1..#4 once each, real Chrome).
  13. - **Merge button**: `mergePullNow` still finds the PR by the sha of its `|||PR` commit (the row's value). Reason: that sha is exactly what the record is keyed on, the server re-finds it itself (client only names it), and it keeps the existing forged-input checks. Number-based lookup can be added when a route needs it. After a successful merge the face calls `syncPulls`.
  14. ## Tests (LC_ALL=C, ports 8720–8729 only)
  15. - New gate `tests/pull-numbers.mjs` (+ `tests/pulls-seed.hl`, `tests/pulls-probe.hl`), added to deploy.sh GATES: own server+storage, real `git` over HTTP with a token. **44 passed, 0 failed.** Covers: backfill order by commit time (older commit = #1 although its branch was made later) and no change logged; opened #1/#2/#3 (never reused, next after a closed one); synchronize forced false/true with before/after; ref follows head; push of refs/pull update/create/+force/delete all refused, ref unchanged, no change logged; fetch of refs/pull/1/head over HTTPS; closed (branch deleted; `|||PR` commit gone), reopened with same number; merged with mergeCommit by a push (merge commit), second push no change; sender = pusher; pull object fields, author id, url, ticket names (explicit `other-proj#7` listed, bare `#12` not, as repo not connected); wasHeadOf true/false; "#N" on /pulls; no refs/pull in pages.
  16. - "Fails on old code": the old code has no numbers/log (gate cannot even seed). For the key safety point, a plain git repo without the setting accepts `git push main:refs/pull/1/head` (exit 0, ref created); with `receive.hideRefs=refs/pull`: `! [remote rejected] main -> refs/pull/2/head (deny updating a hidden ref)`.
  17. - All other gates, run once after the change: signin-return 3/0, check-theme exit 0, browser 266/0 (first run 134/3 failed because of the "#N" in `.subject`, fixed in the gate), security 82/0, private 158/0, ident-access-gitoria 30/0. No flake.
  18. - Timing: a push that opens a PR took 205–224 ms including git itself (local, tiny repo). Per push: 1 `for-each-ref`, 1 `log -500`, ~2–3 git calls per not-yet-merged PR.
  19. ## Contract points
  20. Covered: §0 PR number; §3 refs/pull/N/head kept at the head before the change is returned, `base`/`baseRef`, `mergeBase` (merge-base of target tip and head at the time, computed when the object is built); §4 pull object, change rules and fields (`before/after/forced/mergeCommit`), `author` (id null + commit author when gitoria can't tell: backfilled PRs), `tickets` rule, `draft:false`.
  21. Not covered (other tickets): events/signing/delivery (#43), routes/tokens (#42/#44), `review_*` events, statuses.
  22. Decisions to confirm: (1) a PR first seen already merged (e.g. pushed together with its merge) emits only `merged` (before null), no `opened`. (2) A closed PR is not listed on /pulls (the page is still read from git; closed ones have no commit on a branch). (3) `url` is `<repo>/pulls/N` as in the contract, but **no such page exists yet** (404 shell page) — a route/page is for #44 or later. (4) Branch rename moves a PR's `source` silently (same commit still on another branch); target follows the repo's main branch for plain `|||PR` commits.
  23. ## DOCS / GAP
  24. - DOCS used: HL-PRIMER, CODE-ORDER, COMPONENTS "hl:web — a function route and its request", §9 Data, mpackdb/time READMEs, fs `appendFile` in plugins/fs/server.hl. Not answered by docs: how an app guards a callee that can fault.
  25. - **GAP: no way to contain a runtime fault.** "Never fail a push" cannot be guaranteed by the language (no try/catch; `on Error` only ends the delivery, the request gets a 500). Seen for real: my first bug in syncPulls made every push answer HTTP 500. Repro `W40/repro/fault.hl`: `on boom(x){ y=null console.log(y.id) }` + `f=()=>{ emit boom(1) console.log('after') ...}` → 'after' never prints, the calling statement is abandoned (emit is synchronous). Mitigation here: every git call is null/exit-checked, no workaround. Open risk: an unforeseen fault in syncPulls = failed push.
  26. - **GAP (surprise, worth a doc line):** in a hybrid literal `{ repo = repo.id key = repo.id + 'x' }` the entry name `repo` rebinds the local `repo` for the following entries ("reading 'id': the value is String"). I renamed the field (`rid`).
  27. - Local `x = null` then `x = ...` needs `let` even when assigned in an if (my `sender`); expected, just noted.
  28. ## Open risks
  29. - Only the newest 500 commits (`--branches`) are scanned for NEW `|||PR` commits (max 50 new per sync, same limits as /pulls); known PRs are checked directly, so they never get lost by scan depth.
  30. - Concurrent pushes: mpackdb unique indexes (`key`, `shaKey`) protect against double numbers; a collision would just skip that PR until the next sync.
  31. - ssh door change untested; docker image must be rebuilt for it.
  32. - Pre-existing records of a repo that is later moved keep working (keyed by repo id); not exercised with tools/move-repo.hl.
  33. - Steps/requests: about 45.
  34. ## Processes
  35. Every gate server/Chrome started by the gates ended by itself; at the end no listener on 8720–8729 and no chrome with a W40 cwd. (pgrep of "W40" shows only this chat's own HyperConductor job.) bin in the worktree is a symlink to the main checkout's bin, excluded from commits (never added).
  36. ## Addendum (review fixes, 2 more commits on the same branch)
  37. 1. **ssh pushes.** New route `GET /__git/pushed?user&slug&phase=before|after` (lib/api.hl `gitPushed`, project.hl next to `/__git/access`; same `sshGuard` secret check, plus `mayPush(user, repo)`, so a wrong secret or foreign user is 403). `before` → `ensurePulls`; `after` → `notifyPush` (the existing gap) + `syncPulls(slug, user)`. `docker/sshd/gitoria-shell` no longer `exec`s: for write=1 it calls the route before, runs receive-pack, calls it again only when git exited 0, and exits with git's own status; a curl failure is ignored (`|| true`). Gate `tests/pull-ssh.mjs` (in deploy.sh GATES) uses the REAL sshd image built from docker/sshd (host network, ports 8725 app / 8726 ssh), real ssh+git: a `|||PR` push over ssh gets #1 and `refs/pull/1/head`, the log has `opened` with `sender.id` = the pusher's user id, a second push gives `synchronize`, wrong/missing secret and a foreign user → 403, ssh pushes to `refs/pull/1/head`, `refs/pull/7/head`, a delete of it and `refs/pull/1/heads/<sha>` are refused, nothing changes. **20/0.** On the OLD shell the same gate has 6 FAILs. Not tested: a failing curl while the push goes on (the access call would fail first inside the container); it is `|| true` in the script. notifyPush is called but has no tickets connection in the gate, so only that it does not break the push is shown.
  38. 2. **Old heads survive gc.** `setPullRef` also writes `refs/pull/N/heads/<sha>` for every head (hidden by the same `receive.hideRefs=refs/pull`). Gates: tests/pull-numbers.mjs (now 48/0) force-pushes a PR, runs `git gc --prune=now`, and both replaced heads still resolve; a push to `refs/pull/N/heads/*` is refused over HTTPS; tests/pull-ssh.mjs does the same over ssh.
  39. Gates rerun after the changes (LC_ALL=C, ports 8720–8729): signin-return 3/0, check-theme 0, browser 266/0, security 82/0, private 158/0, ident-access 30/0, pull-numbers 48/0, pull-ssh 20/0. Docker container `gitoria-sshd-w40gate` removed by the gate; nothing listens on 8720–8729.

Branches

Latest commits

  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre