gitoria
All repositories: gitoria
10.2 KB
# W40 report — gitoria#40: a pull request gets a stable number and a fetchable head refBranch `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.## Built- **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.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.- `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.- `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.- 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).- `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).- **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).- **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`).- **/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).- **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`.## Tests (LC_ALL=C, ports 8720–8729 only)- 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.- "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)`.- 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.- 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.## Contract pointsCovered: §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`.Not covered (other tickets): events/signing/delivery (#43), routes/tokens (#42/#44), `review_*` events, statuses.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.## DOCS / GAP- 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.- **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.- **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`).- Local `x = null` then `x = ...` needs `let` even when assigned in an if (my `sender`); expected, just noted.## Open risks- 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.- Concurrent pushes: mpackdb unique indexes (`key`, `shaKey`) protect against double numbers; a collision would just skip that PR until the next sync.- ssh door change untested; docker image must be rebuilt for it.- Pre-existing records of a repo that is later moved keep working (keyed by repo id); not exercised with tools/move-repo.hl.- Steps/requests: about 45.## ProcessesEvery 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).## Addendum (review fixes, 2 more commits on the same branch)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.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.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
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 26117255|||PR apps API: review comments on files with spaces in their namemre
- b8796cecMerge branch 'f1-broken-json' into mainGitoria
- 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
- f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
- 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
- 16a3530fMerge branch 'heap-revert' into mainGitoria
- 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
- 13f0c342Merge branch 'hl25-records' into mainGitoria
- a002ecb7|||PR records: HL25 report, heap helper, logmre
- 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre
- 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
- c4f6d9e3reports: G25c growth huntmre
- b88e39f1log: privacy cleanup donemre
- bfd7826ddocs: neutral example organisation namemre