interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

Comparing a64d48239e0204bf7585620b2bc9b7078550d1ab ... 3df50b9554ac999c45c6eaea50884e11e257bc45

173 files changed, +24312 -1298

README.md+10-1
SANDBOX-NEEDS.md+4-2
browse/a_core.om+2-2
browse/c1_page.om+7-8
browse/c2_hist.om+9-9
browse/c3_blame.om+2-2
browse/e1_json.om+4-4
browse/e2_json.om+7-7
browse/tests/stubutil.om+3-0
chain/README.md+40-14
chain/chain.om+280-3
chain/proof.css+14-0
chain/tests/run.sh+78-0
collab/co0form.om+205-0
collab/co2cob.om+5-0
collab/co3view.om+2-2
collab/co9comp.om+0-205
collab/co9form.om+3-3
collab/co9page.om+8-130
collab/native/helpers.om+256-0
collab/native/issue.om+878-0
collab/native/json.om+447-0
collab/native/route.om+84-0
collab/native/write.om+841-0
collab/tests/compose.sh+20-17
collab/tests/native-issues-store.sh+224-0
community/30page.om+1-1
dl/dl.om+11-44
dl/dlclone.om+31-0
dl/tests/check.sh+7-3
dl/tests/fstub.om+3-0
docs/AGENT-DOOR.md+164-0
docs/ANNOYANCES.md+1-0
docs/API.md+289-41
docs/BRING.md+83-6
docs/CONTRACT.md+68-14
docs/FEATURES.md+12-8
docs/social.md+8-2
door/READY+1-0
door/ev1decl.om+497-0
door/ev2log.om+416-0
door/ev3col.om+1029-0
door/ev4json.om+565-0
door/ev5feed.om+298-0
galaxy/page.om+93-5
galaxy/tests/run.sh+4-1
growth/g1prep.om+14-14
growth/g2page.om+4-5
growth/tests/check.sh+2-2
infra/DEPLOY.md+6-0
infra/apache/omega-source.conf+13-0
infra/bazinga/omega-read+43-0
infra/bazinga/post-update+5-0
infra/bazinga/sync.sh+53-0
infra/nginx/conf.d/bazinga-rad-map.conf+109-0
infra/nginx/conf.d/forge.conf+23-6
infra/nginx/sites-enabled/interplane.io+30-0
infra/nginx/snippets/aienos-rad-moved.conf+11-0
infra/nginx/snippets/bazinga-git.conf+54-0
infra/nginx/snippets/forge-archive.conf+1-0
infra/nginx/snippets/forge-proxy.conf+5-2
infra/smoke.sh+16-4
infra/spark/forged-public.sh+38-7
infra/spark/forged-sandbox.sh+84-6
infra/spark/forged-service.sh+3-0
infra/spark/interplane-chain.service+2-2
infra/spark/nginx/sites-interplane.io+28-0
infra/test/count-snapshot.py+23-18
infra/test/edge-bundle-limit.sh+253-0
infra/test/edge-patch-limit.sh+130-0
infra/test/sandbox-integrated.py+2-2
infra/test/sandbox-netns.sh+4-1
infra/test/sandbox-patch.sh+162-0
infra/test/sandbox.sh+135-7
nodes/srch.om+1-1
nodes/stat.om+5-5
open/route.om+156-45
open/tests/run.sh+8-8
open/tests/up.sh+7-7
patch/READY+0-0
patch/p1decl.om+482-0
patch/p2base.om+522-0
patch/p2utf8.om+79-0
patch/p3gate.om+401-0
patch/p4take.om+1179-0
patch/p5imp.om+1281-0
patch/p5page.om+614-0
patch/p6json.om+637-0
patch/p7route.om+133-0
patch/tests/e2e-import.sh+511-0
patch/tests/e2e.sh+122-0
patch/tests/lib.sh+305-0
patch/tests/resilience.sh+56-0
patch/tests/run.sh+1642-0
research/build.om+14-7
research/intake-route.om+3-6
research/tests/authors.sh+5-5
research/tests/intake.sh+2-1
run.sh+255-18
salvage/15bundle.om+1-1
salvage/20web.om+1-1
server/agents.om+195-0
server/agents.tsv+61-0
server/count-snapshot.om+17-17
server/counts.om+36-153
server/json.om+4-14
server/jsonp.om+11-7
server/main.om+85-7
server/nodoor.om+22-0
server/noissuewrite.om+17-0
server/nopatch.om+12-0
server/nostat.om+14-0
server/pages.om+37-53
server/radsrc.om+300-0
server/repos.om+8-151
server/route.om+25-3
server/state.om+1-1
server/tests/agentdoor.py+492-0
server/tests/agentdoor.sh+320-0
server/tests/bigrepo.sh+11-0
server/tests/check.sh+36-5
server/tests/counts.sh+29-35
server/tests/cutdata.sh+21-0
server/tests/jsonpages.sh+19-3
server/tests/overflow.sh+12-3
server/tests/readmefirst.sh+37-16
server/tests/sitechrome.sh+22-5
server/tests/title.sh+13-2
server/tests/translate.sh+5-6
server/tests/trial-real.sh+3-3
server/util.om+226-20
social/05decl.om+8-5
social/30store.om+3-1
social/40auth.om+54-4
social/55pages.om+18-7
social/60json.om+1-1
social/signin.sh+43-0
social/tests/lib.sh+26-8
social/tests/onebox.sh+23-0
social/tests/units-check.sh+158-0
social/tests/units.sh+34-0
store/clone.om+40-0
store/evcol.om+863-0
store/head.om+25-0
store/moving.om+42-0
store/mvcommunity.om+13-0
store/mvgrowth.om+15-0
store/mvopen.om+27-0
store/mvsalvage.om+14-0
store/repos.om+1112-0
store/tests/agentdoor-store.sh+340-0
store/tests/capacity.sh+106-0
store/tests/compare-controls.sh+155-0
store/tests/compare.py+488-0
store/tests/compare.sh+588-0
store/tests/crawl-store.sh+59-0
store/tests/expect_served.py+58-0
store/tests/fixstore.sh+46-0
store/tests/mutant-scan.om+55-0
store/tests/radcrawl.py+106-0
store/tests/svlib.sh+20-0
tools/bring/PLATFORMS.md+13-2
tools/bring/build.sh+1-1
tools/bring/src/10base.om+1-1
tools/bring/src/40net.om+13-2
tools/bring/src/50patch.om+760-0
tools/bring/src/90main.om+5-1
tools/bring/tests/run.sh+39-0
tools/bring/tests/standin.om+47-3
visits/README.md+17-11
visits/tests/owner.sh+2-2
visits/tests/run.sh+48-9
visits/visits.om+46-21

README.md

@@ -31,12 +31,14 @@ How the pieces fit together: `docs/CONTRACT.md`. What replaces the GitHub annoya
3131 | `social/` | ForgeSocial | sign-in, sessions, stars, favorites, watch, follows |
3232 | `infra/` | ForgeInfra | service supervisor, tunnel, nginx, smoke tests |
3333 | `quiet/` | simplify (L1008 D) | one digest per subscriber, patch evidence receipt |
34+| `door/` | AgentDoor | the public event stream (`events.json`) and the feed page; `agents.json` is `server/agents.om` |
3435 | `docs/` | shared | CONTRACT.md, FEATURES.md, ANNOYANCES.md |
3536
3637 ## Build and run (on spark)
3738
3839 ```
3940 ./run.sh units # list the units in compose order
41+./run.sh seams # tests only: the same list with every slice as its seam server/no<slice>.om
4042 ./run.sh build # compose and compile with the pinned omc -> server/forged (clean tree only)
4143 ./run.sh deploy # build HEAD in a fresh git worktree, install server/forged, log it in infra/DEPLOY.md
4244 ./run.sh start | stop | status | reload
@@ -57,13 +59,18 @@ How the pieces fit together: `docs/CONTRACT.md`. What replaces the GitHub annoya
5759 `127.0.0.1:18480` only. The supervisor restarts forged if it exits; systemd restarts the supervisor.
5860 - `./run.sh reload` (or SIGHUP to the supervisor) touches `~/forge-data/reload`; forged then re-reads
5961 the allow-list and the social log without a restart.
62+- Store-reading build (interplane-native DESIGN.md step 2, not deployed):
63+ `FORGE_STORE=<store root> FORGED_OUT=<path> ./run.sh build` (optionally
64+ `FORGE_CLONE_BASE=https://<host>/<path>/`) reads the project list from the store's `catalog.tsv`
65+ and Git from `projects/NAME/repo.git` (`store/`, docs/CONTRACT.md section 1); `deploy` and
66+ `restart` refuse it. Acceptance: `bash store/tests/compare.sh STORE KEY IPL_DIR`.
6067
6168 ## Data
6269
6370 - Repositories: Radicle storage `~/.radicle/storage/<RID>`, read with `git` (argv exec, no shell).
6471 Only the 28 rows of the public table in `~/handoffs/radicle/RIDS.md` exist; everything else is 404.
6572 `server/repos.om` `fdeny` refuses the withdrawn private projects and their RIDs
66- even if a table row lists them.
73+ even if a table row lists them (in the store-reading build, by name and by the old id in record 1).
6774 - Forge data dir `~/forge-data/`: the social append-only log and key, `archives/` (archive cache,
6875 512 MiB cap per file), `logs/forged.log` (access log and supervisor log), `counts.log` (append-only
6976 journal of the counted clone and download events and the log positions, `server/counts.om`),
@@ -75,6 +82,8 @@ How the pieces fit together: `docs/CONTRACT.md`. What replaces the GitHub annoya
7582 same data as the HTML pages as JSON: schemas `forge/explore/1` and `forge/repo/1` in `docs/API.md`.
7683 `<base>trending` and `<base>explore?order=trending|new` order the public list.
7784 `<base><owner>/<repo>/insights` is the per-repo numbers page. Schemas and sources: `docs/GROWTH.md`.
85+`<base>agents.json` lists every machine-readable address (from `server/agents.tsv`); `<base>events.json`
86+is the public activity stream and `<base>feed` its page: `docs/AGENT-DOOR.md`.
7887
7988 ## Host dependencies (production path)
8089

SANDBOX-NEEDS.md

@@ -349,8 +349,10 @@ existing renderer uses it. Archives plus assets must not overflow. The file
349349 contains only public project identifiers, aggregate figures and collection times.
350350 It contains no client address, user agent, raw request line or key material.
351351
352-Limits: 16384 file bytes, 65 LF-terminated lines including the header, 256 bytes
353-per line excluding LF, 11 row fields, 64 bytes per field, 64 project rows.
352+Limits: 65536 file bytes, 257 LF-terminated lines including the header, 256 bytes
353+per line excluding LF, 11 row fields, 64 bytes per field, 256 project rows (FAMAX,
354+server/util.om; 16384 bytes, 65 lines and 64 rows before 2026-11-14, when the
355+allow-list table grew for the native store).
354356 Duplicate project identifiers, incomplete lines, wrong field counts, invalid
355357 numbers, future collection time or source times after collection are rejected.
356358 Files older than 3600 seconds are rejected. A missing, rejected or stale snapshot

browse/a_core.om

@@ -382,7 +382,7 @@ end
382382 note brrevp: rev-parse gbfr^{commit} into gbsha; false when it does not name a commit
383383 fn brrevp to bool
384384 put gbshl 0 0
385-fkgit
385+fksource
386386 fka tbrevp
387387 fka tbverif
388388 fka tbq
@@ -419,7 +419,7 @@ put gbfrl 0 0
419419 if eq get gbrl 0 0
420420 ret false
421421 end
422-fkgit
422+fksource
423423 fka tbfer
424424 fka tbfmtr
425425 fka tbrh

browse/c1_page.om

@@ -319,7 +319,7 @@ fput tbae
319319 end
320320 note brlast: the newest commit touching gbp at gbsha, in a box
321321 fn brlast to void
322-fkgit
322+fksource
323323 fka tblog
324324 fka tbn1
325325 fka tbone
@@ -358,7 +358,7 @@ fn brotype to ulong
358358 if eq get gbpl 0 0
359359 ret 1
360360 end
361-fkgit
361+fksource
362362 fka tbcatf
363363 fka tbt
364364 brkshp
@@ -377,7 +377,7 @@ ret 0
377377 end
378378 note ---- tree listing
379379 fn brlsx to bool
380-fkgit
380+fksource
381381 fka tblstr
382382 fka tbz
383383 fka tbll
@@ -565,7 +565,7 @@ n = get gbrml 0
565565 if eq n 0
566566 ret
567567 end
568-fkgit
568+fksource
569569 fka tbcatf
570570 fka tbblob
571571 fkopen
@@ -686,7 +686,6 @@ end
686686 end
687687 fpjdev1
688688 brrefbar
689-dlclone
690689 brlast
691690 if rd
692691 if not brlist
@@ -842,7 +841,7 @@ end
842841 ret false
843842 end
844843 fn brcatb to bool
845-fkgit
844+fksource
846845 fka tbcatf
847846 fka tbblob
848847 brkshp
@@ -1120,7 +1119,7 @@ end
11201119 note brbsz: gbbsz = the size of the blob <gbsha>:<gbp> (git cat-file -s)
11211120 fn brbsz to bool
11221121 put gbbsz 0 0
1123-fkgit
1122+fksource
11241123 fka tbcatf
11251124 fka tbsz
11261125 brkshp
@@ -1146,7 +1145,7 @@ ret true
11461145 end
11471146 note brboid: gbboid = the blob id of <gbsha>:<gbp> (rev-parse, 40 lowercase hex checked)
11481147 fn brboid to bool
1149-fkgit
1148+fksource
11501149 fka tbrevp
11511150 fka tbverif
11521151 fka tbq

browse/c2_hist.om

@@ -240,7 +240,7 @@ ret brerr 404
240240 end
241241 p = brpgnum
242242 put gbpg 0 p
243-fkgit
243+fksource
244244 fka tblog
245245 fka tbfmtc
246246 fka tbn1
@@ -370,7 +370,7 @@ end
370370 note brcmtargs: argv in fpk of git format-patch (mode 1) or git show -p (mode 2) of commit gbsha.
371371 note brcmtraw runs it; output larger than the capture runs again, streamed by the server (kind 4)
372372 fn brcmtargs mode ulong to void
373-fkgit
373+fksource
374374 if eq mode 1
375375 fka tbfmtp
376376 fka tbstdo
@@ -388,7 +388,7 @@ brksha
388388 end
389389 note brcmthd: the commit header box; false when git show fails
390390 fn brcmthd to bool
391-fkgit
391+fksource
392392 fka tbshow
393393 fka tbsfmt
394394 fka tbfmtk
@@ -510,7 +510,7 @@ fputc get gbsha i
510510 end
511511 end
512512 fn brcmtstat to void
513-fkgit
513+fksource
514514 fka tbshow
515515 fka tbfmt0
516516 fka tbnums
@@ -524,7 +524,7 @@ brstat
524524 end
525525 end
526526 fn brcmtdiff to void
527-fkgit
527+fksource
528528 fka tbshow
529529 fka tbfmt0
530530 fka tbpp
@@ -863,7 +863,7 @@ end
863863 fput tbpe
864864 end
865865 fn brkref tg bool to void
866-fkgit
866+fksource
867867 fka tbfer
868868 if tg
869869 fka tbsortt
@@ -1167,7 +1167,7 @@ end
11671167 ret eq get gbpl 0 0
11681168 end
11691169 fn brcmplog to void
1170-fkgit
1170+fksource
11711171 fka tblog
11721172 fka tbfmtc
11731173 fka tbn1
@@ -1186,7 +1186,7 @@ fput tbcpcut
11861186 end
11871187 end
11881188 fn brcmpdiff to void
1189-fkgit
1189+fksource
11901190 fka tbdiff
11911191 fka tbnums
11921192 fka tbmm
@@ -1199,7 +1199,7 @@ if eq get fxol 0 0
11991199 ret
12001200 end
12011201 brstat
1202-fkgit
1202+fksource
12031203 fka tbdiff
12041204 brkdiff
12051205 brkcs tbdots

browse/c3_blame.om

@@ -66,7 +66,7 @@ if eq k 1
6666 brloc tbtree
6767 ret 302
6868 end
69-fkgit
69+fksource
7070 fka tbblame
7171 fka tbporc
7272 fkopen
@@ -291,7 +291,7 @@ brrefesc
291291 fput tbsf5
292292 end
293293 fn brsrun to void
294-fkgit
294+fksource
295295 fka tbgrep
296296 fka tbgz
297297 fka tbgn

browse/e1_json.om

@@ -239,7 +239,7 @@ fputc 34
239239 end
240240 note brylast: the brlast box (newest commit touching gbp at gbsha) as a commit summary, or null
241241 fn brylast to void
242-fkgit
242+fksource
243243 fka tblog
244244 fka tbn1
245245 fka tbone
@@ -452,7 +452,7 @@ fputc 34
452452 end
453453 note bryrdok: git cat-file -e <sha>:<gbp>/<readme> (brrdshow shows nothing when the blob is unreadable)
454454 fn bryrdok to bool
455-fkgit
455+fksource
456456 fka tbcatf
457457 fka tbge
458458 fkopen
@@ -646,7 +646,7 @@ if eq k 1
646646 brloc tbtree
647647 ret 302
648648 end
649-fkgit
649+fksource
650650 fka tbblame
651651 fka tbporc
652652 fkopen
@@ -809,7 +809,7 @@ ret 200
809809 end
810810 note brysrun: brsrun's git grep; the hits array; true when the BRHITS cap cut the list
811811 fn brysrun to bool
812-fkgit
812+fksource
813813 fka tbgrep
814814 fka tbgz
815815 fka tbgn

browse/e2_json.om

@@ -417,7 +417,7 @@ ret brerr 404
417417 end
418418 p = brpgnum
419419 put gbpg 0 p
420-fkgit
420+fksource
421421 fka tblog
422422 fka tbfmtc
423423 fka tbn1
@@ -491,7 +491,7 @@ end
491491 if gt mode 0
492492 ret brcmtraw mode
493493 end
494-fkgit
494+fksource
495495 fka tbshow
496496 fka tbsfmt
497497 fka tbfmtk
@@ -509,7 +509,7 @@ end
509509 fyrhead tbzsc
510510 brzcmthd
511511 brzlinks
512-fkgit
512+fksource
513513 fka tbshow
514514 fka tbfmt0
515515 fka tbnums
@@ -519,7 +519,7 @@ fkopen
519519 brksha
520520 st = fexec BRTMO
521521 brzfiles st
522-fkgit
522+fksource
523523 fka tbshow
524524 fka tbfmt0
525525 fka tbpp
@@ -686,7 +686,7 @@ fputc 34
686686 fputc 125
687687 end
688688 fn brzclog to void
689-fkgit
689+fksource
690690 fka tblog
691691 fka tbfmtc
692692 fka tbn1
@@ -705,7 +705,7 @@ fyk tbzkctr
705705 fybool gt c 250
706706 end
707707 fn brzcdiff to void
708-fkgit
708+fksource
709709 fka tbdiff
710710 fka tbnums
711711 fka tbmm
@@ -720,7 +720,7 @@ if eq get fxol 0 0
720720 brzdnull
721721 ret
722722 end
723-fkgit
723+fksource
724724 fka tbdiff
725725 brkdiff
726726 brkcs tbdots

browse/tests/stubutil.om

@@ -297,6 +297,9 @@ for i ulong len t
297297 fkc get t i
298298 end
299299 end
300+fn fksource to void
301+fkgit
302+end
300303 fn fkgit to void
301304 fkb
302305 fka tfgit

chain/README.md

@@ -34,24 +34,36 @@ OMV=$HOME/work/flux/omega-mv # sha2.om sha256 5cf0f981…fdb3
3434 ./chain-bin add LEDGER KIND ACTOR SUBJECT < payload # prints: OK <seq> <head>
3535 ./chain-bin verify LEDGER # prints: OK <count> <head>, or BAD line N code
3636 ./chain-bin check LEDGER SEQ < payload # exit 0 only if this is the payload record SEQ committed to
37-./chain-bin feed LEDGER FILE KIND ACTOR # one record per new complete line of FILE
37+./chain-bin feed LEDGER FILE KIND ACTOR [PAGE] # one record per new complete line of FILE; then PAGE
38+./chain-bin page LEDGER OUT # the head as a page with the check by hand
3839 ```
3940
4041 `add` takes an exclusive lock, verifies the whole ledger and refuses to append to one that does not
4142 verify. `verify` enforces every rule in the table above, not only the chain. Commands are matched as
42-whole words (`add`, `verify`, `check`, `feed`). Exit 0 done; 1 usage or a bad argument; 2 the ledger
43+whole words (`add`, `verify`, `check`, `feed`, `page`). Exit 0 done; 1 usage or a bad argument; 2 the ledger
4344 does not verify; 3 read or write failed; 4 `check`: no such record, or the payload is not the one
4445 committed; 5 `feed`: the file has fewer complete lines than were already recorded from it. BAD
4546 codes: 1 not seven fields, or a byte that is not a tab or printable ASCII; 2 seq; 3 utc; 4 payload
4647 digest; 5 prev; 6 line longer than 1,023 bytes; 7 last line has no line feed; 8 kind, actor or
4748 subject breaks its rule.
4849
50+`page` verifies the ledger and writes one HTML file: the record count, the time of the last
51+record, the head, and the commands from "Checking it without this program" with the public
52+address of the ledger. It writes nothing for a ledger that does not verify. The file has no script
53+and no inline style; it links `/assets/tokens.css` and `/assets/proof.css` (`chain/proof.css`).
54+It is written as `OUT.tmp` and renamed. `feed` with a fifth argument writes the same page after
55+its last record, so one service keeps ledger and page together. A page name, or its `.tmp`, that is
56+the ledger or (in `feed`) the fed file is refused with exit 1 before anything is written. A stale
57+`OUT.tmp` is removed first (the name, never what a link points to), the new one is created
58+exclusively, and it is removed again when writing or renaming fails.
59+
4960 `feed` is how a running log becomes a chain. It records line N of FILE with the subject
5061 `<file name> line N` and the SHA-256 of the line's bytes, without its line feed, as the payload.
5162 It resumes after the highest N already recorded for that KIND and file name, so running it again
5263 adds only new lines; a last line with no line feed yet is left for the next run. Only the digest
5364 enters the ledger, so a private log can be chained in public: whoever holds a line can prove it was
54-recorded (`printf %s "LINE" | chain check LEDGER SEQ`), and nobody can read it from the ledger.
65+recorded (`printf %s "$(sed -n 'Np' FILE)" | chain check LEDGER SEQ`, with the line number for N,
66+so the line needs no quoting), and nobody can read it from the ledger.
5567 The file name is at most 100 bytes of printable ASCII. Two files with one base name share a resume
5668 point under one KIND, so give each its own KIND. A record another writer adds with the same kind and
5769 a subject of the same form moves the resume point; one ledger per trusted set of writers. FILE may
@@ -65,7 +77,7 @@ first run over a long file costs one sync, not one per line; the gate counts the
6577 ```sh
6678 # every record's prev is the digest of the line above it
6779 awk 'NR>1' ledger.tsv | cut -f7 > claimed
68-head -n -1 ledger.tsv | while IFS= read -r line; do printf %s "$line" | sha256sum | cut -d' ' -f1; done > computed
80+sed '$d' ledger.tsv | while IFS= read -r line; do printf %s "$line" | sha256sum | cut -d' ' -f1; done > computed
6981 cmp claimed computed && echo chain intact
7082 # a payload is the one a record committed to
7183 sha256sum < payload # equals field 6 of that record
@@ -79,21 +91,23 @@ sha256sum < payload # equals field 6 of that record
7991 - Assumed, not proved: that nobody can find such a SHA-256 collision.
8092 - Not proved by the chain alone: when a record was written, and who wrote the payload. A ledger
8193 kept only on one machine can be rebuilt from scratch by whoever holds it. Time and authorship
82- come from outside: publish each new head where the publisher cannot take it back (a signed commit
83- on Radicle, replicated by seeds other people run), and the record existed no later than that.
94+ come from outside: publish each new head where the publisher cannot take it back (for example a
95+ signed commit copied to machines other people run), and the record existed no later than that.
8496 A model vendor does not sign what its model says, so "this model wrote this text" needs a
8597 witness of the vendor connection; that is a later unit, not claimed here.
8698
8799 ## Service (after merge)
88100
89101 `infra/spark/interplane-chain.service` chains the hive's message board, `~/handoffs/BOARD.md`,
90-one record per line, into `~/forge-data/proof/board.tsv`. It runs when the folder changes (inotify
91-through `aien-onchange`, at most once a minute), not on a clock. Only digests enter the ledger.
102+one record per line, into `~/forge-data/proof/board.tsv`, and rewrites the page
103+`~/forge-data/proof/index.html` after each run. It runs when the folder changes (inotify through
104+`aien-onchange`, at most once a minute), not on a clock. Only digests enter the ledger.
92105
93106 ```sh
94107 mkdir -p ~/.local/share/interplane-chain ~/forge-data/proof
95108 { printf 'om2\n'; cat $OMV/om/tls/sha2.om chain/chain.om; } | $OMV/seed/out/omc > ~/.local/share/interplane-chain/chain
96109 chmod 755 ~/.local/share/interplane-chain/chain
110+cp chain/proof.css ~/forge-data/proof/
97111 cp infra/spark/interplane-chain.service ~/.config/systemd/user/
98112 systemctl --user daemon-reload && systemctl --user enable --now interplane-chain.service
99113 ```
@@ -105,7 +119,7 @@ append-only by intent. On a copy of the board of 2026-11-09 (3,294 lines) the fi
105119 ## Gate
106120
107121 ```sh
108-sh chain/tests/run.sh # RESULT pass=122 fail=0 at this commit
122+sh chain/tests/run.sh # prints RESULT pass=<count> fail=0 when every case holds
109123 ```
110124
111125 The oracle is `sha256sum`, never the program under test: every `prev`, every payload digest
@@ -123,14 +137,26 @@ writes nothing. A command that only starts like `add` or `verify`, or has a byte
123137 line (an empty line, a line with a tab, a 200,000-byte line of arbitrary bytes), for leaving an
124138 unfinished line, for adding nothing when run again, for resuming only on its own kind and exact file
125139 name, for exit 5 with nothing written when the file lost lines, for refusing the ledger itself as
126-the file (by its name and through a link), and for its argument rules.
140+the file (by its name and through a link), and for its argument rules. `page` is checked on a
141+ledger of 1,234 records: its head and count against `sha256sum` and `wc`, and then the commands
142+are taken out of the page itself, entity-decoded and run: the head command gives the page's head,
143+the link check prints `chain intact`, and on a copy with one edited record it does not; the
144+"prove one message" command, run on a board line holding a quote, an apostrophe, parentheses and a
145+dollar sign, gives that line's SHA-256; the page ends with `</html>` and its line feed. (A page
146+that would pass the 16,383-byte page buffer is refused with exit 3, never cut short; today's page
147+is under 3,000 bytes, so the gate does not reach that case.) A damaged
148+ledger gets exit 2 and no page; an empty one says so. A page named as the ledger, as the ledger's
149+name plus `.tmp`, or (in `feed`) as the fed file is refused and leaves both unchanged; a stale
150+`OUT.tmp` link is not written through; a failed rename leaves no `OUT.tmp`.
127151 Negative controls: a mutant that skips the prev check accepts the edited ledger; a mutant that
128-forgets what was recorded records lines twice; a mutant without the lost-lines rule exits 0. The
152+forgets what was recorded records lines twice; a mutant without the lost-lines rule exits 0; a
153+mutant without the verify rule writes a page for a damaged ledger; a mutant without the name guard
154+replaces its own ledger with the page. The
129155 gate refuses any compiler or `sha2.om` other than the pins (exit 2).
130156
131157 ## Not done
132158
133-- The ledger is not served from interplane.io yet: `feed` and its service exist, the forged route
134- does not.
135-- No outside time anchor yet beyond what publishing on Radicle will give.
159+- The ledger and its page are not served from interplane.io yet: the files exist under
160+ `~/forge-data/proof/`, the forged routes (`/proof`, `/proof/board.tsv`, `/assets/proof.css`) do not.
161+- No outside time anchor yet: publishing each head where it cannot be taken back is a later unit.
136162 - A ledger line is at most 1,023 bytes.

chain/chain.om

@@ -2,7 +2,9 @@ note chain.om: the INTERPLANE ledger, a hash chain anyone can check. Composed af
22 note chain add LEDGER KIND ACTOR SUBJECT < payload append one record; prints "OK seq head"
33 note chain verify LEDGER prints "OK count head" or "BAD line N code"
44 note chain check LEDGER SEQ < payload the payload is the one record SEQ committed to
5-note chain feed LEDGER FILE KIND ACTOR one record per new complete line of FILE
5+note chain feed LEDGER FILE KIND ACTOR [PAGE] one record per new complete line of FILE; then
6+note the page, when PAGE is given
7+note chain page LEDGER OUT write OUT: the head as a page with the check by hand
68 note feed records line N of FILE with the subject "<file name> line N" and the SHA-256 of the line's
79 note bytes (without its line feed) as payload. It resumes after the highest N already recorded for
810 note that KIND and file name, so running it again adds only new lines. A last line without a line
@@ -24,7 +26,10 @@ note BAD codes: 1 not seven fields, or a byte that is not a tab or printable ASC
2426 note zero); 3 utc (a real date and time, never earlier than the record before); 4 payload digest;
2527 note 5 prev; 6 line longer than 1,023 bytes; 7 last line has no line feed; 8 kind, actor or subject
2628 note breaks its rule (kind 1..24 bytes of A-Z 0-9 _, actor 1..64 bytes, subject 1..128 bytes).
27-note Commands are matched as whole words: add, verify, check, feed.
29+note page verifies the ledger first and writes nothing when it does not verify (exit 2). OUT is
30+note written as OUT.tmp (created exclusively) and renamed, so a reader never sees half a page. A
31+note page name, or its .tmp, that is the ledger or the fed file is refused (exit 1).
32+note Commands are matched as whole words: add, verify, check, feed, page.
2833 global gl uchar 1024
2934 global gll ulong 1
3035 global gh uchar 64
@@ -47,6 +52,20 @@ text tver "verify"
4752 text tchk "check"
4853 text tfeed "feed"
4954 text tline " line "
55+text tpage "page"
56+text ttmp ".tmp"
57+text tnone "no records yet"
58+text q01 "<!doctype html><html lang='en' data-theme='dark'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>Check the record yourself - INTERPLANE</title><link rel='stylesheet' href='/assets/tokens.css'><link rel='stylesheet' href='/assets/proof.css'></head><body><main>\n"
59+text q02 "<p class='eyebrow'>Proof</p><h1>Check the record yourself</h1>\n<p class='sub'>The agents that build INTERPLANE talk on one message board. Each line of that board is recorded here by its SHA-256 digest, and each record names the digest of the record before it. You do not need to trust this page, this site or its author. Download the ledger and check it with tools already on your machine.</p>\n<dl class='stats'><div><dt>Records</dt><dd>"
60+text q03 "</dd></div><div><dt>Last record (UTC)</dt><dd>"
61+text q04 "</dd></div></dl>\n<h2>The head</h2>\n<p class='sub'>The head is the SHA-256 of the ledger's last line. Change, remove, add or move any earlier record and the head changes.</p>\n<pre class='cmd'>"
62+text q05 "</pre>\n<h2>Check it by hand</h2>\n<p class='sub'>Get the ledger and compute its head. It must be the line above. Where there is no sha256sum (macOS), shasum -a 256 does the same.</p>\n<pre class='cmd'>curl -s https://interplane.io/proof/board.tsv -o board.tsv\nprintf %s &quot;$(tail -n 1 board.tsv)&quot; | sha256sum</pre>\n"
63+text q06 "<p class='sub'>Then check every link. Field 7 of each record must be the SHA-256 of the line above it.</p>\n<pre class='cmd'>awk 'NR&gt;1' board.tsv | cut -f7 &gt; claimed\nsed '$d' board.tsv | while IFS= read -r line; do printf %s &quot;$line&quot; | sha256sum | cut -d' ' -f1; done &gt; computed\ncmp claimed computed &amp;&amp; echo chain intact</pre>\n"
64+text q07 "<h2>Prove one message</h2>\n<p class='sub'>Only digests are public; the board itself is not. Whoever holds line N of the board, as it was when the line was recorded, can prove it is the line that was recorded: its SHA-256 is field 6 of the record whose subject is BOARD.md line N. Write the line number in place of N; the command reads the line from the file, so nothing in it needs quoting.</p>\n<pre class='cmd'>printf %s &quot;$(sed -n 'Np' BOARD.md)&quot; | sha256sum</pre>\n"
65+text q08 "<h2>What this proves, and what it does not</h2>\n<p class='sub'>Proved in Lean 4 with no axioms: two valid ledgers with the same head are the same ledger, unless SHA-256 gives one digest for two different lines. Nobody is known to be able to do that; it is assumed, not proved.</p>\n<p class='sub'>Not proved by the chain alone: when a record was written, and who or what wrote a message. A ledger kept on one machine can be rebuilt by whoever holds it. Time comes from outside, from publishing each head where it cannot be taken back.</p>\n</main></body></html>\n"
66+global gp uchar 16384
67+global gpl ulong 1
68+global go uchar 2100
5069 note gs: 0 records accepted, 1 first BAD code, 2 its line number, 3 wanted seq, 4 wanted seq found,
5170 note 5 feed mode, 6 highest source line already recorded for the fed kind and file name
5271 note gx: the fed kind at 0 (length gxl 0), actor at 64 (gxl 1), file name at 192 (gxl 2)
@@ -945,6 +964,12 @@ end
945964 if not sarg 3 192 2 100 false
946965 ret 1
947966 end
967+if eq argcnt 7
968+pl = argread 6 ga 0 4095
969+if or lt pl 1 gt pl 1000
970+ret 1
971+end
972+end
948973 m = argread 3 ga 0 4095
949974 sf = int fopen ga 0 ulong m 0 0
950975 if lt sf 0
@@ -961,6 +986,12 @@ r = fsame sf fd
961986 if ne r 0
962987 ret r
963988 end
989+if eq argcnt 7
990+r = pprep 6
991+if ne r 0
992+ret r
993+end
994+end
964995 put gs 5 1
965996 put gs 6 0
966997 if not vfy fd
@@ -977,9 +1008,249 @@ end
9771008 if ne r 0
9781009 ret r
9791010 end
1011+if eq argcnt 7
1012+pbuild
1013+w = pfile
1014+if ne w 0
1015+ret w
1016+end
1017+end
9801018 y = fclose fd
9811019 ret say
9821020 end
1021+note ---- page
1022+note pb: one byte into the page; a page that would pass 16,383 bytes is marked as over (gpl 16384)
1023+note and pput refuses to write it, so it is never cut short in silence
1024+fn pb c uchar to void
1025+o = get gpl 0
1026+if lt o 16383
1027+put gp o c
1028+put gpl 0 add o 1
1029+else
1030+put gpl 0 16384
1031+end
1032+end
1033+note pt: a text of at most 4,096 bytes into the page
1034+fn pt t view uchar * to void
1035+n = len t
1036+i = ulong 0
1037+while lt i n bound 4096
1038+pb get t i
1039+i = add i 1
1040+end
1041+end
1042+note pn: a count with its digits grouped in threes
1043+fn pn v ulong to void
1044+d = new uchar 20 0
1045+n = ulong 0
1046+x = v
1047+if eq x 0
1048+pb 48
1049+end
1050+while gt x 0 bound 20
1051+put d n uchar add 48 rem x 10
1052+x = div x 10
1053+n = add n 1
1054+end
1055+while gt n 0 bound 20
1056+n = sub n 1
1057+pb get d n
1058+if gt n 0
1059+if eq rem n 3 0
1060+pb 44
1061+end
1062+end
1063+end
1064+end
1065+note pbuild: the page for the ledger just verified (gs 0 records, head in gh, last time in gu)
1066+fn pbuild to void
1067+put gpl 0 0
1068+pt q01
1069+pt q02
1070+pn get gs 0
1071+pt q03
1072+if eq get gs 0 0
1073+pt tnone
1074+else
1075+for i ulong 10
1076+pb get gu i
1077+end
1078+pb 32
1079+for j ulong 8
1080+pb get gu add 11 j
1081+end
1082+end
1083+pt q04
1084+if eq get gs 0 0
1085+pt tnone
1086+else
1087+for k ulong 64
1088+pb get gh k
1089+end
1090+end
1091+pt q05
1092+pt q06
1093+pt q07
1094+pt q08
1095+end
1096+note pput: the page into the new file named go[0, n), mode 0644, created exclusively (O_WRONLY,
1097+note O_CREAT, O_EXCL: never through a link, never into a file that is already there); true when all
1098+note of it is written and synced
1099+fn pput n ulong to bool
1100+if gt get gpl 0 16383
1101+ret false
1102+end
1103+fd = int fopen go 0 n 193 420
1104+if lt fd 0
1105+ret false
1106+end
1107+m = get gpl 0
1108+o = ulong 0
1109+good = true
1110+while lt o m bound 16384
1111+k = write fd gp o sub m o
1112+if le k 0
1113+good = false
1114+o = m
1115+else
1116+o = add o ulong k
1117+end
1118+end
1119+if ne fsync fd 0
1120+good = false
1121+end
1122+r = fclose fd
1123+ret good
1124+end
1125+note peq: the first 16 bytes of two stat records (st_dev, st_ino) are equal
1126+fn peq a view uchar 128 b view uchar 128 to bool
1127+for i ulong 16
1128+if ne get a i get b i
1129+ret false
1130+end
1131+end
1132+ret true
1133+end
1134+note pid: s holds the lstat of a name; 1 when it is the entry or the file argument idx names (by
1135+note lstat or by stat), 0 when not, 3 when argument idx cannot be read or does not exist
1136+fn pid s view uchar 128 idx ulong to int
1137+m = argread idx ga 0 4095
1138+if lt m 1
1139+ret 3
1140+end
1141+t = new uchar 128 0
1142+if lt stat ga 0 ulong m t 0 128 0
1143+ret 3
1144+end
1145+if peq s t
1146+ret 1
1147+end
1148+if lt lstat ga 0 ulong m t 0 128 0
1149+ret 3
1150+end
1151+if peq s t
1152+ret 1
1153+end
1154+ret 0
1155+end
1156+note pguard: 0 when the name go[0, n) does not exist or is neither the ledger (argument 2) nor, in
1157+note feed, the fed file (argument 3); otherwise the exit code. Renaming the page over the ledger, or
1158+note removing a stale <name>.tmp that is the ledger, would destroy it.
1159+fn pguard n ulong to int
1160+s = new uchar 128 0
1161+if lt lstat go 0 n s 0 128 0
1162+ret 0
1163+end
1164+r = pid s 2
1165+if ne r 0
1166+ret r
1167+end
1168+if eq argcnt 7
1169+ret pid s 3
1170+end
1171+ret 0
1172+end
1173+note pprep: argument idx (1..1,000 bytes) into go as <name>.tmp, its length in gs 7, and both names
1174+note through pguard. Runs before anything is written. 0, or the exit code.
1175+fn pprep idx ulong to int
1176+n = argread idx ga 0 4095
1177+if or lt n 1 gt n 1000
1178+ret 1
1179+end
1180+l = ulong n
1181+for i ulong l bound 1000
1182+put go i get ga i
1183+end
1184+for j ulong 4
1185+put go add l j get ttmp j
1186+end
1187+put gs 7 l
1188+r = pguard l
1189+if ne r 0
1190+ret r
1191+end
1192+ret pguard add l 4
1193+end
1194+note pfile: the page built by pbuild into the name pprep prepared, written as <name>.tmp and
1195+note renamed. A stale <name>.tmp is removed first (the name only, never what it points to); on any
1196+note failure the .tmp is removed again. w holds the two names as the list renames takes: count 2,
1197+note then each name as a 2-byte length and its bytes. 0, or the exit code.
1198+fn pfile to int
1199+l = get gs 7
1200+t = add l 4
1201+u = unlink go 0 t
1202+if not pput t
1203+u = unlink go 0 t
1204+ret 3
1205+end
1206+w = new uchar 2100 0
1207+put w 0 2
1208+put w 1 0
1209+put w 2 uchar rem t 256
1210+put w 3 uchar div t 256
1211+for a ulong t bound 1004
1212+put w add 4 a get go a
1213+end
1214+b = add 4 t
1215+put w b uchar rem l 256
1216+put w add b 1 uchar div l 256
1217+for c ulong l bound 1000
1218+put w add add b 2 c get go c
1219+end
1220+if ne renames w 0 add add b 2 l 0 0
1221+u = unlink go 0 t
1222+ret 3
1223+end
1224+ret 0
1225+end
1226+fn cpage to int
1227+fd = ropen 0
1228+if lt fd 0
1229+ret 3
1230+end
1231+note the same exclusive lock add and feed take: one page writer per ledger, and never mid-append
1232+if ne flock fd 2 0
1233+ret 3
1234+end
1235+p = pprep 3
1236+if ne p 0
1237+ret p
1238+end
1239+good = vfy fd
1240+r = fclose fd
1241+if not good
1242+ret 3
1243+end
1244+if ne get gs 1 0
1245+ret say
1246+end
1247+pbuild
1248+w = pfile
1249+if ne w 0
1250+ret w
1251+end
1252+ret say
1253+end
9831254 fn main to int
9841255 if lt argcnt 3
9851256 ret 1
@@ -1003,10 +1274,16 @@ end
10031274 ret 1
10041275 end
10051276 if argis tfeed
1006-if eq argcnt 6
1277+if or eq argcnt 6 eq argcnt 7
10071278 ret cfeed
10081279 end
10091280 ret 1
10101281 end
1282+if argis tpage
1283+if eq argcnt 4
1284+ret cpage
1285+end
1286+ret 1
1287+end
10111288 ret 1
10121289 end

chain/proof.css

new file mode 100644
@@ -0,0 +1,14 @@
1+/* proof.css: the page `chain page` writes. Colours only through tokens.css. */
2+*{box-sizing:border-box}
3+html,body{margin:0;background:var(--bg-primary);color:var(--text-primary);font:14px/20px var(--font-sans,Inter,system-ui,sans-serif)}
4+main{max-width:880px;margin:0 auto;padding:32px 24px 56px}
5+.eyebrow{margin:0 0 8px;font-size:12px;font-weight:600;letter-spacing:.2em;text-transform:uppercase;color:var(--accent)}
6+h1{margin:0 0 12px;font-size:36px;line-height:40px;font-weight:700}
7+h2{margin:32px 0 8px;font-size:18px;line-height:28px;font-weight:600}
8+.sub{margin:0 0 16px;max-width:720px;color:var(--text-secondary)}
9+.stats{display:grid;grid-template-columns:repeat(2,1fr);gap:16px;margin:0 0 16px}
10+.stats div{padding:24px;border:1px solid var(--border);border-radius:16px;background:var(--bg-card)}
11+.stats dt{font-size:12px;line-height:16px;color:var(--text-secondary)}
12+.stats dd{margin:4px 0 0;font:600 24px/32px var(--font-mono,ui-monospace,monospace)}
13+.cmd{margin:0 0 16px;padding:16px;border:1px solid var(--border);border-radius:16px;background:var(--bg-card);font:12px/20px var(--font-mono,ui-monospace,monospace);white-space:pre-wrap;overflow-wrap:anywhere}
14+@media (max-width:720px){.stats{grid-template-columns:1fr}main{padding:24px 12px}h1{font-size:30px;line-height:36px}}

chain/tests/run.sh

@@ -245,6 +245,84 @@ if command -v strace >/dev/null 2>&1; then
245245 else
246246 no "strace is needed to count syncs"
247247 fi
248+
249+# page: the head as a page anyone can check by hand; the check it prints must itself work
250+awk 'BEGIN { for (i = 1; i <= 1234; i++) print "message " i }' >"$T/src/LONG.md"
251+P=$T/page.tsv
252+o=$("$T/chain" feed "$P" "$T/src/LONG.md" MSG hive-board "$T/page.html"); eq "feed with a page exit" "$?" 0
253+HEADP=$(printf %s "$(tail -n 1 "$P")" | sha)
254+eq "feed with a page prints the count and the head" "$o" "$(printf 'OK\t1234\t%s' "$HEADP")"
255+eq "page shows the head sha256sum gives" "$(grep -c "<pre class='cmd'>$HEADP</pre>" "$T/page.html")" 1
256+eq "page shows the count, digits grouped" "$(grep -c '<dt>Records</dt><dd>1,234</dd>' "$T/page.html")" 1
257+eq "page shows the last record's time" "$(grep -c "<dd>$(tail -n 1 "$P" | cut -f2 | tr 'T' ' ' | tr -d 'Z')</dd>" "$T/page.html")" 1
258+eq "page has no script and no inline style" "$(grep -ci '<script\|style=' "$T/page.html")" 0
259+eq "page left no temporary file" "$(ls "$T" | grep -c '^page\.html\.tmp$')" 0
260+"$T/chain" page "$P" "$T/page2.html" >/dev/null; eq "page exit" "$?" 0
261+if cmp -s "$T/page.html" "$T/page2.html"; then ok "page and feed write the same page"; else no "page and feed write the same page"; fi
262+# the commands on the page, taken from the page: entity-decoded, the download replaced by a local copy
263+cmds() { awk -v n="$1" 'BEGIN { RS = "<pre class=.cmd.>"; FS = "</pre>" } NR == n + 1 { printf "%s\n", $1 }' "$T/page.html" | sed -e 's/&quot;/"/g' -e 's/&gt;/>/g' -e 's/&lt;/</g' -e 's/&amp;/\&/g'; }
264+eq "the page's first command fetches the public ledger" "$(cmds 2 | head -n 1)" "curl -s https://interplane.io/proof/board.tsv -o board.tsv"
265+mkdir "$T/hand"
266+cp "$P" "$T/hand/board.tsv"
267+cmds 2 | tail -n +2 >"$T/hand/head.sh"
268+cmds 3 >"$T/hand/links.sh"
269+eq "the page's head command gives the page's head" "$(cd "$T/hand" && sh head.sh | cut -d' ' -f1)" "$HEADP"
270+eq "the page's link check passes on the ledger" "$(cd "$T/hand" && sh links.sh 2>/dev/null)" "chain intact"
271+sed -i '600s/hive-board/hive-b0ard/' "$T/hand/board.tsv"
272+eq "the page's link check fails on a ledger with one edited record" "$(cd "$T/hand" && sh links.sh 2>/dev/null | grep -c 'chain intact')" 0
273+# the page's "prove one message" command, from the page, on a board line that typing it by hand
274+# inside quotes would break: a quote, an apostrophe, parentheses, a dollar sign and a backquote
275+BL='it'"'"'s "quoted" (a) $HOME `x` line'
276+printf 'first line\n%s\nlast line\n' "$BL" >"$T/hand/BOARD.md"
277+cmds 4 | sed 's/Np/2p/' >"$T/hand/one.sh"
278+eq "the page's prove-one-message command gives the line's SHA-256" "$(cd "$T/hand" && sh one.sh 2>/dev/null | cut -d' ' -f1)" "$(printf %s "$BL" | sha256sum | cut -d' ' -f1)"
279+eq "the page ends with </html> and a line feed" "$(tail -c 8 "$T/page.html" | tr '\n' '|')" "</html>|"
280+"$T/chain" page "$T/d1" "$T/bad.html" >/dev/null; eq "page of a damaged ledger exits 2" "$?" 2
281+eq "and writes no page" "$(ls "$T" | grep -c '^bad\.html')" 0
282+: >"$T/empty.tsv"
283+"$T/chain" page "$T/empty.tsv" "$T/empty.html" >/dev/null; eq "page of an empty ledger exit" "$?" 0
284+eq "it says there are no records yet, twice" "$(grep -o 'no records yet' "$T/empty.html" | wc -l | tr -d ' ')" 2
285+longp=$T/$(awk 'BEGIN { for (i = 0; i < 1001; i++) printf "p" }')
286+cp "$P" "$T/page.before"; printf 'one more\n' >>"$T/src/LONG.md"
287+"$T/chain" feed "$P" "$T/src/LONG.md" MSG hive-board "$longp" >/dev/null 2>&1; eq "feed with a page name over 1,000 bytes refused" "$?" 1
288+if cmp -s "$P" "$T/page.before"; then ok "and it records nothing"; else no "and it records nothing"; fi
289+"$T/chain" page "$P" >/dev/null 2>&1; eq "page without a name refused" "$?" 1
290+"$T/chain" pagex "$P" "$T/x.html" >/dev/null 2>&1; eq "pagex refused" "$?" 1
291+# the page never replaces the ledger or the fed file, never writes through a stale OUT.tmp, never leaves one
292+cp "$P" "$T/same.tsv"
293+"$T/chain" page "$T/same.tsv" "$T/same.tsv" >/dev/null 2>&1; eq "page named as its own ledger refused" "$?" 1
294+if cmp -s "$P" "$T/same.tsv"; then ok "and the ledger is unchanged"; else no "and the ledger is unchanged"; fi
295+cp "$P" "$T/sl.tmp"
296+"$T/chain" page "$T/sl.tmp" "$T/sl" >/dev/null 2>&1; eq "page whose OUT.tmp is the ledger refused" "$?" 1
297+if cmp -s "$P" "$T/sl.tmp"; then ok "and that ledger is unchanged"; else no "and that ledger is unchanged"; fi
298+cp "$T/src/LONG.md" "$T/long.before"
299+"$T/chain" feed "$P" "$T/src/LONG.md" MSG hive-board "$T/src/LONG.md" >/dev/null 2>&1; eq "feed with the fed file as the page refused" "$?" 1
300+if cmp -s "$P" "$T/page.before" && cmp -s "$T/src/LONG.md" "$T/long.before"; then ok "and ledger and file are unchanged"; else no "and ledger and file are unchanged"; fi
301+printf 'victim\n' >"$T/victim"; ln -s "$T/victim" "$T/lk.html.tmp"
302+"$T/chain" page "$P" "$T/lk.html" >/dev/null 2>&1; eq "page over a stale OUT.tmp link exit" "$?" 0
303+eq "it writes the page, not through the link" "$(cat "$T/victim")/$(cmp -s "$T/lk.html" "$T/page.html" && echo same)" "victim/same"
304+mkdir "$T/dir.html"
305+"$T/chain" page "$P" "$T/dir.html" >/dev/null 2>&1; eq "page onto a directory fails" "$?" 3
306+eq "and leaves no OUT.tmp" "$(ls "$T" | grep -c '^dir\.html\.tmp$')" 0
307+# negative control: without the name guard the page replaces its own ledger
308+awk '{ if ($0 == "if lt lstat go 0 n s 0 128 0") print "if true"; else print }' "$C/chain.om" >"$T/gm.om"
309+if cmp -s "$C/chain.om" "$T/gm.om"; then
310+ no "guard mutant differs from source"
311+else
312+ build "$T/gm.om" "$T/gm"
313+ cp "$P" "$T/gm.tsv"
314+ "$T/gm" page "$T/gm.tsv" "$T/gm.tsv" >/dev/null 2>&1
315+ eq "mutant without the name guard replaces the ledger with the page" "$(grep -c '<!doctype html>' "$T/gm.tsv")" 1
316+fi
317+# negative control: the page is written although the ledger does not verify
318+awk '/^if ne get gs 1 0$/ { c++ } { l[NR] = $0 } END { for (i = 1; i <= NR; i++) { if (l[i] == "if ne get gs 1 0") { k++; if (k == c) { print "if false"; continue } } print l[i] } }' "$C/chain.om" >"$T/pm.om"
319+if cmp -s "$C/chain.om" "$T/pm.om"; then
320+ no "page mutant differs from source"
321+else
322+ build "$T/pm.om" "$T/pm"
323+ "$T/pm" page "$T/d1" "$T/pm.html" >/dev/null 2>&1
324+ eq "mutant without the verify rule writes a page for a damaged ledger" "$(ls "$T" | grep -c '^pm\.html$')" 1
325+fi
248326 LEAN=${LEAN:-$HOME/.elan/bin/lean}
249327 if [ -x "$LEAN" ]; then
250328 eq "Lean checks tamper_evident, no axioms" "$("$LEAN" "$C/Ledger.lean" 2>&1 | grep -c 'does not depend on any axioms')" 1

collab/co0form.om

new file mode 100644
@@ -0,0 +1,205 @@
1+global gcfv uchar 65536
2+global gcfvl ulong 1
3+note Shared issue and preview form decoding and text validation.
4+note cobfld t: decode field t into gcfv; its length, -1 when absent, -2 when over 65536 bytes
5+fn cobfld t view uchar * to long
6+n = get fbodyl 0
7+i = ulong 0
8+while lt i n bound 70000
9+if cobfmat t i n
10+ret cobfdec add add i len t 1 n
11+end
12+i = cobfnxt i n
13+end
14+ret -1
15+end
16+fn cobfmat t view uchar * i ulong n ulong to bool
17+if gt add add i len t 1 n
18+ret false
19+end
20+for k ulong len t bound 64
21+if ne get fbody add i k get t k
22+ret false
23+end
24+end
25+ret eq get fbody add i len t 61
26+end
27+fn cobfnxt i ulong n ulong to ulong
28+j = i
29+while lt j n bound 70000
30+if eq get fbody j 38
31+ret add j 1
32+end
33+j = add j 1
34+end
35+ret n
36+end
37+fn cobfdec i ulong n ulong to long
38+j = i
39+o = ulong 0
40+while lt j n bound 70000
41+c = get fbody j
42+if eq c 38
43+break
44+end
45+if ge o 65536
46+ret -2
47+end
48+j = add j 1
49+if eq c 43
50+c = uchar 32
51+end
52+if eq c 37
53+c = cobpct j n
54+if lt add j 1 n
55+j = add j 2
56+end
57+end
58+put gcfv o c
59+o = add o 1
60+end
61+put gcfvl 0 o
62+ret long o
63+end
64+fn cobpct j ulong n ulong to uchar
65+if ge add j 1 n
66+ret uchar 37
67+end
68+a = fhexv get fbody j
69+b = fhexv get fbody add j 1
70+if or lt a 0 lt b 0
71+ret uchar 37
72+end
73+ret uchar add mul a 16 b
74+end
75+note ---- text checks on gcfv[0,n)
76+note cotxtok n ml: CRLF and lone CR become LF; then the text must be UTF-8 without NUL or control
77+note bytes (ml: tab and LF allowed; else none); trailing blanks and leading newlines are trimmed
78+note (single line: leading blanks too). The cleaned length, or -1 when the text is refused.
79+fn cotxtok n ulong ml bool to long
80+m = cocrlf n
81+if eq cowutf8 m ml false
82+ret -1
83+end
84+e = m
85+while gt e 0 bound 70000
86+c = get gcfv sub e 1
87+if and ne c 32 and ne c 9 ne c 10
88+break
89+end
90+e = sub e 1
91+end
92+s = ulong 0
93+while lt s e bound 70000
94+c = get gcfv s
95+if and ne c 10 or ml and ne c 32 ne c 9
96+break
97+end
98+s = add s 1
99+end
100+if gt s 0
101+for k ulong sub e s bound 70000
102+put gcfv k get gcfv add s k
103+end
104+end
105+ret long sub e s
106+end
107+fn cocrlf n ulong to ulong
108+o = ulong 0
109+for i ulong n bound 70000
110+c = get gcfv i
111+if eq c 13
112+c = uchar 10
113+if lt add i 1 n
114+if eq get gcfv add i 1 10
115+c = uchar 0
116+end
117+end
118+end
119+if ne c 0
120+put gcfv o c
121+o = add o 1
122+else
123+if ne get gcfv i 13
124+put gcfv o c
125+o = add o 1
126+end
127+end
128+end
129+ret o
130+end
131+note cowutf8 n ml: well-formed UTF-8 (no overlong forms, surrogates or code points over U+10FFFF), no
132+note NUL, C0 control or DEL byte except tab and LF when ml
133+fn cowutf8 n ulong ml bool to bool
134+i = ulong 0
135+while lt i n bound 70000
136+c = get gcfv i
137+if lt c 128
138+if eq coctlok c ml false
139+ret false
140+end
141+i = add i 1
142+else
143+k = coulen i n
144+if eq k 0
145+ret false
146+end
147+i = add i k
148+end
149+end
150+ret true
151+end
152+fn coctlok c uchar ml bool to bool
153+if eq c 127
154+ret false
155+end
156+if ge c 32
157+ret true
158+end
159+if and ml or eq c 9 eq c 10
160+ret true
161+end
162+ret false
163+end
164+note coulen i n: byte length of the multi-byte sequence at gcfv[i], 0 when it is malformed
165+fn coulen i ulong n ulong to ulong
166+c = get gcfv i
167+k = ulong 0
168+lo = uchar 128
169+hi = uchar 191
170+if and ge c 194 le c 223
171+k = ulong 2
172+end
173+if and ge c 224 le c 239
174+k = ulong 3
175+if eq c 224
176+lo = uchar 160
177+end
178+if eq c 237
179+hi = uchar 159
180+end
181+end
182+if and ge c 240 le c 244
183+k = ulong 4
184+if eq c 240
185+lo = uchar 144
186+end
187+if eq c 244
188+hi = uchar 143
189+end
190+end
191+if or eq k 0 gt add i k n
192+ret ulong 0
193+end
194+d = get gcfv add i 1
195+if or lt d lo gt d hi
196+ret ulong 0
197+end
198+for j ulong sub k 2 bound 2
199+d = get gcfv add add i 2 j
200+if or lt d 128 gt d 191
201+ret ulong 0
202+end
203+end
204+ret k
205+end

collab/co2cob.om

@@ -96,6 +96,8 @@ global gccn ulong 1
9696 note model slots gcm: 0,1 title (pool off,len) 2 lifecycle (0 open 1 draft 2 archived/closed)
9797 note 3,4 labels 5,6 assignees 7,8 close reason 9 kind (1 patch 2 issue) 10 actions not understood
9898 global gcm ulong 16
99+note gclfc: the change whose lifecycle action was applied last (the event stream, door/, names it)
100+global gclfc ulong 1
99101 note revisions: id, base, head oid, creating change, description (off,len), redacted, verdict line
100102 global gcrv uchar 2560
101103 global gcrb uchar 2560
@@ -623,6 +625,7 @@ end
623625 note ---- load and replay
624626 fn coreset to void
625627 put gcov 0 0
628+put gclfc 0 0
626629 put gccn 0 0
627630 put gcpl 0 0
628631 put gcrn 0 0
@@ -851,6 +854,7 @@ coatitle a e
851854 ret
852855 end
853856 if coseq t e tclife
857+put gclfc 0 ci
854858 coalife a e
855859 ret
856860 end
@@ -897,6 +901,7 @@ coatitle a e
897901 ret
898902 end
899903 if coseq t e tclife
904+put gclfc 0 ci
900905 coalife a e
901906 ret
902907 end

collab/co3view.om

@@ -334,8 +334,8 @@ text tclul "<ul class=\"repos\">\n"
334334 text tcluln "</ul>\n"
335335 text tclnone "<p class=\"muted\">Nothing here in this state.</p>\n"
336336 text tclcap "<p class=\"muted\">Only the 200 most recently updated are listed.</p>\n"
337-text tcpnote "<p class=\"muted\">Patches are Radicle collaborative objects (xyz.radicle.patch), read from this repository's storage. Open one by pushing a branch with <code>git push rad HEAD:refs/patches</code> from a clone.</p>\n"
338-text tcinote "<p class=\"muted\">Issues are Radicle collaborative objects (xyz.radicle.issue), read from this repository's storage. Open one with <code>rad issue open</code> from a clone.</p>\n"
337+text tcpnote "<p class=\"muted\">Patches are stored in this repository and read from it. Opening a new patch from a clone is closed for now: Interplane does not accept pushes yet.</p>\n"
338+text tcinote "<p class=\"muted\">Issues are stored in this repository and read from it. Opening a new issue is closed for now: Interplane does not accept issues yet.</p>\n"
339339 note cotab f s nm v: one filter link (kind in gcm 9); v is the query value
340340 fn cotab f ulong s ulong nm view uchar * v view uchar * to void
341341 kd = get gcm 9

collab/co9comp.om

@@ -5,8 +5,6 @@ note session's CSRF token, the repo and a 128-bit random id (/dev/urandom); GET
55 note preview and the exact rad or git command the author runs in a clone, signing with their own key.
66 note Kinds: 1 issue comment, 2 patch comment, 3 patch review, 4 new issue, 5 new patch; 0 free slot.
77 text tcurnd "/dev/urandom"
8-global gcfv uchar 65536
9-global gcfvl ulong 1
108 global gczk ulong 32
119 global gczt ulong 32
1210 global gczix ulong 32
@@ -25,209 +23,6 @@ global gcsti uchar 256
2523 global gcstil ulong 1
2624 global gcsf ulong 1
2725 global gcsrv ulong 1
28-note ---- form body fields (application/x-www-form-urlencoded, fbody up to 64 KiB) into gcfv
29-note cobfld t: decode field t into gcfv; its length, -1 when absent, -2 when over 65536 bytes
30-fn cobfld t view uchar * to long
31-n = get fbodyl 0
32-i = ulong 0
33-while lt i n bound 70000
34-if cobfmat t i n
35-ret cobfdec add add i len t 1 n
36-end
37-i = cobfnxt i n
38-end
39-ret -1
40-end
41-fn cobfmat t view uchar * i ulong n ulong to bool
42-if gt add add i len t 1 n
43-ret false
44-end
45-for k ulong len t bound 64
46-if ne get fbody add i k get t k
47-ret false
48-end
49-end
50-ret eq get fbody add i len t 61
51-end
52-fn cobfnxt i ulong n ulong to ulong
53-j = i
54-while lt j n bound 70000
55-if eq get fbody j 38
56-ret add j 1
57-end
58-j = add j 1
59-end
60-ret n
61-end
62-fn cobfdec i ulong n ulong to long
63-j = i
64-o = ulong 0
65-while lt j n bound 70000
66-c = get fbody j
67-if eq c 38
68-break
69-end
70-if ge o 65536
71-ret -2
72-end
73-j = add j 1
74-if eq c 43
75-c = uchar 32
76-end
77-if eq c 37
78-c = cobpct j n
79-if lt add j 1 n
80-j = add j 2
81-end
82-end
83-put gcfv o c
84-o = add o 1
85-end
86-put gcfvl 0 o
87-ret long o
88-end
89-fn cobpct j ulong n ulong to uchar
90-if ge add j 1 n
91-ret uchar 37
92-end
93-a = fhexv get fbody j
94-b = fhexv get fbody add j 1
95-if or lt a 0 lt b 0
96-ret uchar 37
97-end
98-ret uchar add mul a 16 b
99-end
100-note ---- text checks on gcfv[0,n)
101-note cotxtok n ml: CRLF and lone CR become LF; then the text must be UTF-8 without NUL or control
102-note bytes (ml: tab and LF allowed; else none); trailing blanks and leading newlines are trimmed
103-note (single line: leading blanks too). The cleaned length, or -1 when the text is refused.
104-fn cotxtok n ulong ml bool to long
105-m = cocrlf n
106-if eq cowutf8 m ml false
107-ret -1
108-end
109-e = m
110-while gt e 0 bound 70000
111-c = get gcfv sub e 1
112-if and ne c 32 and ne c 9 ne c 10
113-break
114-end
115-e = sub e 1
116-end
117-s = ulong 0
118-while lt s e bound 70000
119-c = get gcfv s
120-if and ne c 10 or ml and ne c 32 ne c 9
121-break
122-end
123-s = add s 1
124-end
125-if gt s 0
126-for k ulong sub e s bound 70000
127-put gcfv k get gcfv add s k
128-end
129-end
130-ret long sub e s
131-end
132-fn cocrlf n ulong to ulong
133-o = ulong 0
134-for i ulong n bound 70000
135-c = get gcfv i
136-if eq c 13
137-c = uchar 10
138-if lt add i 1 n
139-if eq get gcfv add i 1 10
140-c = uchar 0
141-end
142-end
143-end
144-if ne c 0
145-put gcfv o c
146-o = add o 1
147-else
148-if ne get gcfv i 13
149-put gcfv o c
150-o = add o 1
151-end
152-end
153-end
154-ret o
155-end
156-note cowutf8 n ml: well-formed UTF-8 (no overlong forms, surrogates or code points over U+10FFFF), no
157-note NUL, C0 control or DEL byte except tab and LF when ml
158-fn cowutf8 n ulong ml bool to bool
159-i = ulong 0
160-while lt i n bound 70000
161-c = get gcfv i
162-if lt c 128
163-if eq coctlok c ml false
164-ret false
165-end
166-i = add i 1
167-else
168-k = coulen i n
169-if eq k 0
170-ret false
171-end
172-i = add i k
173-end
174-end
175-ret true
176-end
177-fn coctlok c uchar ml bool to bool
178-if eq c 127
179-ret false
180-end
181-if ge c 32
182-ret true
183-end
184-if and ml or eq c 9 eq c 10
185-ret true
186-end
187-ret false
188-end
189-note coulen i n: byte length of the multi-byte sequence at gcfv[i], 0 when it is malformed
190-fn coulen i ulong n ulong to ulong
191-c = get gcfv i
192-k = ulong 0
193-lo = uchar 128
194-hi = uchar 191
195-if and ge c 194 le c 223
196-k = ulong 2
197-end
198-if and ge c 224 le c 239
199-k = ulong 3
200-if eq c 224
201-lo = uchar 160
202-end
203-if eq c 237
204-hi = uchar 159
205-end
206-end
207-if and ge c 240 le c 244
208-k = ulong 4
209-if eq c 240
210-lo = uchar 144
211-end
212-if eq c 244
213-hi = uchar 143
214-end
215-end
216-if or eq k 0 gt add i k n
217-ret ulong 0
218-end
219-d = get gcfv add i 1
220-if or lt d lo gt d hi
221-ret ulong 0
222-end
223-for j ulong sub k 2 bound 2
224-d = get gcfv add add i 2 j
225-if or lt d 128 gt d 191
226-ret ulong 0
227-end
228-end
229-ret k
230-end
23126 note ---- slots
23227 fn conow to ulong
23328 ret div ulong realns 1000000000

collab/co9form.om

@@ -33,7 +33,7 @@ text tcfsnp "New patch"
3333 text tcfs2 "</h2>\n"
3434 text tcfse "</section>\n"
3535 text tcsgn1 "<p class=\"muted\">Sign in to prepare one. <a href=\""
36-text tcsgn2 "\">Sign in with your Radicle key</a></p>\n"
36+text tcsgn2 "\">Sign in with your key</a></p>\n"
3737 text tcfo1 "<form method=\"post\" action=\""
3838 text tcfo2 "\">\n<input type=\"hidden\" name=\"csrf\" value=\""
3939 text tcfo3 "\">\n"
@@ -49,8 +49,8 @@ text tcfv1 "<p><label><input type=\"radio\" name=\"verdict\" value=\"comment\" c
4949 text tcfv2 "</label><br>\n<label><input type=\"radio\" name=\"verdict\" value=\"review\"> Review without a verdict</label><br>\n<label><input type=\"radio\" name=\"verdict\" value=\"accept\"> Review: accept</label><br>\n<label><input type=\"radio\" name=\"verdict\" value=\"reject\"> Review: reject</label></p>\n"
5050 text tcfdr "<p><label><input type=\"checkbox\" name=\"draft\" value=\"1\"> Open it as a draft</label></p>\n"
5151 text tcfsub "<p><button type=\"submit\">Prepare</button></p>\n</form>\n"
52-text tcfexp "<p class=\"meta\">The forge checks the text and gives you the command that publishes it, signed by your own Radicle key. It never writes to Radicle itself.</p>\n"
53-text tcfexpp "<p class=\"meta\">The forge never takes your commits. It checks the title and description and gives you the git push that opens the patch from your clone, signed by your own Radicle key.</p>\n"
52+text tcfexp "<p class=\"meta\">The forge checks the text and keeps a preview for this session. Publishing it is closed for now: Interplane does not accept comments, reviews or issues yet.</p>\n"
53+text tcfexpp "<p class=\"meta\">The forge never takes your commits. It checks the title and description and keeps a preview for this session. Opening a patch is closed for now: Interplane does not accept pushes yet.</p>\n"
5454 text tcfnorev "<p class=\"muted\">Every revision of this patch is redacted; there is nothing to comment on.</p>\n"
5555 text tcnwl1 "<p><a href=\""
5656 text tcnwli "/issues/new\">Prepare a new issue</a></p>\n"

collab/co9page.om

@@ -1,5 +1,5 @@
11 note collab/co9page.om (ForgePatches): GET <o>/<r>/compose/<cid>, the checked text with its preview and
2-note the exact command, and GET compose/<cid>/<file>, the file that command reads.
2+note the note that publishing is closed for now, and GET compose/<cid>/<file>, the checked text as a file.
33 text tcfnc "comment.md"
44 text tcfnr "review.md"
55 text tcfni "issue.md"
@@ -16,39 +16,17 @@ text tcpkr ", revision "
1616 text tcpkacc " (accept)"
1717 text tcpkrej " (reject)"
1818 text tcpkdr " (draft)"
19-text tcpg2 "</h2>\n<p class=\"meta\">The forge checked this text and keeps it for 15 minutes, for this session only. It wrote nothing: a Radicle change is signed by its author, so your own node signs and publishes it.</p>\n<h3>Preview</h3>\n"
19+text tcpg2 "</h2>\n<p class=\"meta\">The forge checked this text and keeps it for 15 minutes, for this session only. It wrote nothing to this repository.</p>\n<h3>Preview</h3>\n"
2020 text tcpgt1 "<p><b>"
2121 text tcpgt2 "</b></p>\n"
2222 text tcpgnone "<p class=\"muted\">No text.</p>\n"
2323 text tcpg3 "<h3>Publish it</h3>\n<ol class=\"so-steps\">\n"
2424 text tcpgdl1 "<li>Save <a href=\""
2525 text tcpgdl2 "\" download>"
26-text tcpgdl3 "</a> in a clone of this repository (<code>rad clone rad:"
27-text tcpgdl4 "</code>).</li>\n"
28-text tcpgr1 "<li>From that clone, in sh, bash or zsh, run:<pre class=\"so-cmd\">"
29-text tcpgr1p "<li>From that clone, on the branch you propose, in sh, bash or zsh, run:<pre class=\"so-cmd\">"
30-text tcpgr2 "</pre></li>\n"
31-text tcpge1 "<li>Then set the full description, with the patch id that git push printed in place of PATCH_ID:<pre class=\"so-cmd\">"
32-text tcpgb1 "<li>It shows here once this forge's node has fetched it from yours: <a href=\""
33-text tcpgb2 "\">back</a>.</li>\n</ol></section>\n"
34-text tccmrid " --repo rad:"
35-text tccm1 "rad issue comment "
36-text tccm2 "rad patch comment "
37-text tccm3 "rad patch review "
38-text tccm3r " --revision "
39-text tccmacc " --accept"
40-text tccmrej " --reject"
41-text tccmmsg " --message=\"$(cat "
42-text tccmend ")\""
43-text tccmnom " --no-message"
44-text tccm4 "rad issue open"
45-text tccm4t " --title=\"$(head -n 1 issue.md)\" --description=\"$(tail -n +3 issue.md)\""
46-text tccm5 "git push -o patch.message=\"$(head -n 1 patch.md)\""
47-text tccm5b " -o patch.message=\"$(tail -n +3 patch.md)\""
48-text tccm5d " -o patch.draft"
49-text tccm5r " rad HEAD:refs/patches"
50-text tccm6 "rad patch edit PATCH_ID"
51-text tccm6m " --message=\"$(head -n 1 patch.md)\" --message=\"$(tail -n +3 patch.md)\""
26+text tcpgdl3 "</a> to keep a copy.</li>\n"
27+text tcpgcl "<li>Publishing it is closed for now: Interplane does not accept comments, reviews, issues or patches yet.</li>\n"
28+text tcpgb1 "<li><a href=\""
29+text tcpgb2 "\">Back</a>.</li>\n</ol></section>\n"
5230 note cofneq kd a b: frest[a,b) is the file name of kind kd
5331 fn cofneq kd ulong a ulong b ulong to bool
5432 if or eq kd 1 eq kd 2
@@ -77,17 +55,7 @@ ret
7755 end
7856 fput tcfnp
7957 end
80-note cozbnl s: the body of slot s has a line break
81-fn cozbnl s ulong to bool
82-o = mul s 60000
83-for k ulong get gczbl s bound 60000
84-if eq get gczb add o k 10
85-ret true
86-end
87-end
88-ret false
89-end
90-note cocdlf s: the file the command reads: the body (comments, reviews), or the title, a blank line
58+note cocdlf s: the downloaded file: the body (comments, reviews), or the title, a blank line
9159 note and the description (new issues and patches)
9260 fn cocdlf s ulong to long
9361 kd = get gczk s
@@ -162,7 +130,7 @@ end
162130 comdz s
163131 fput tcpg3
164132 cocpdl s
165-cocprun s
133+fput tcpgcl
166134 fput tcpgb1
167135 cocpback s
168136 fput tcpgb2
@@ -239,96 +207,6 @@ cofname get gczk s
239207 fput tcpgdl2
240208 cofname get gczk s
241209 fput tcpgdl3
242-fputrid get fridx 0
243-fput tcpgdl4
244-end
245-fn cotg40 s ulong to void
246-for k ulong 40
247-fputc get gcztg add mul s 40 k
248-end
249-end
250-fn corv40 s ulong to void
251-for k ulong 40
252-fputc get gczrv add mul s 40 k
253-end
254-end
255-fn corepo to void
256-fesc tccmrid
257-fputrid get fridx 0
258-end
259-note cocprun s: the command step(s)
260-fn cocprun s ulong to void
261-kd = get gczk s
262-if eq kd 5
263-fput tcpgr1p
264-else
265-fput tcpgr1
266-end
267-if eq kd 1
268-fesc tccm1
269-cotg40 s
270-corepo
271-cocmsg s
272-end
273-if eq kd 2
274-fesc tccm2
275-corv40 s
276-corepo
277-cocmsg s
278-end
279-if eq kd 3
280-cocrev s
281-end
282-if eq kd 4
283-fesc tccm4
284-corepo
285-fesc tccm4t
286-end
287-if eq kd 5
288-cocpush s
289-end
290-fput tcpgr2
291-if and eq kd 5 cozbnl s
292-fput tcpge1
293-fesc tccm6
294-corepo
295-fesc tccm6m
296-fput tcpgr2
297-end
298-end
299-fn cocmsg s ulong to void
300-fesc tccmmsg
301-cofname get gczk s
302-fesc tccmend
303-end
304-fn cocrev s ulong to void
305-f = get gczf s
306-fesc tccm3
307-cotg40 s
308-corepo
309-fesc tccm3r
310-corv40 s
311-if eq f 1
312-fesc tccmacc
313-end
314-if eq f 2
315-fesc tccmrej
316-end
317-if eq get gczbl s 0
318-fesc tccmnom
319-else
320-cocmsg s
321-end
322-end
323-fn cocpush s ulong to void
324-fesc tccm5
325-if and gt get gczbl s 0 eq cozbnl s false
326-fesc tccm5b
327-end
328-if eq and get gczf s 8 8
329-fesc tccm5d
330-end
331-fesc tccm5r
332210 end
333211 note cocpback s: link back to the issue, the patch or the list
334212 fn cocpback s ulong to void

collab/native/helpers.om

new file mode 100644
@@ -0,0 +1,256 @@
1+note HTML and JSON helpers shared by the imported issue views.
2+global gcrq uchar 16
3+global gcrql ulong 1
4+text tcid "id"
5+text tcdraft "draft"
6+text tcarch "archived"
7+text tcclosed "closed"
8+global gcm ulong 16
9+text tcah "<a href=\""
10+text tcqg "\">"
11+text tcae "</a>"
12+text tcissp "/issues/"
13+text tcpats "/patches"
14+text tcisss "/issues"
15+text tcnot "(no title)"
16+text tcmidd " &#183; "
17+text tcstq "?state="
18+text tcstn "state"
19+text tcopen "open"
20+text tcmerged "merged"
21+text tcall "all"
22+text tcsopen "Open"
23+text tcsdraft "Draft"
24+text tcsclos "Closed"
25+text tcsmerg "Merged"
26+text tcsarch "Archived"
27+text tcsall "All"
28+text tciss "Issues"
29+text tcbon "<b>"
30+text tcboff "</b>"
31+text tcopar " ("
32+text tccpar ")"
33+global gcsn ulong 1
34+global gccnt ulong 8
35+text tcbok "<b class=\"ok\">"
36+text tcbbad "<b class=\"bad\">"
37+text tcbmut "<b class=\"muted\">"
38+text tclh1 "<h2>"
39+text tclh2 "</h2>\n<p class=\"bar\">"
40+text tclh3 "</p>\n"
41+text tclul "<ul class=\"repos\">\n"
42+text tcluln "</ul>\n"
43+text tclnone "<p class=\"muted\">Nothing here in this state.</p>\n"
44+text tcli1 "<li><a class=\"rname\" href=\""
45+text tcli2 "</a> "
46+text tcli7 "</p>"
47+text tcli10 "</li>\n"
48+text tcnwr "new"
49+text tcjsis "forge/issues/1"
50+text tcjsi "forge/issue/1"
51+text tcjsts "states"
52+text tcjcnt "count"
53+text tcjpath "path"
54+text tcjtr "truncated"
55+text tcjisss "issues"
56+text tcjtitl "title"
57+text tcjauth "author"
58+text tcjupd "updated"
59+text tcjcoms "comments"
60+text tcjverd "verdict"
61+text tcjopen "opened"
62+text tcjlabs "labels"
63+text tcjasg "assignees"
64+text tcjnum "number"
65+text tcjred "redacted"
66+text tcjtime "time"
67+text tcjbody "body"
68+text tcjreas "reason"
69+text tcjtrvw "review"
70+text tcjtcom "comment"
71+fn cosp to void
72+fputc 32
73+end
74+fn coqeq n long t view uchar * to bool
75+if ne ulong n len t
76+ret false
77+end
78+for i ulong len t
79+if ne get fval i get t i
80+ret false
81+end
82+end
83+ret true
84+end
85+fn coqstate kd ulong to ulong
86+n = fqget tcstn
87+if lt n 0
88+ret ulong 0
89+end
90+if coqeq n tcdraft
91+ret ulong 1
92+end
93+if or coqeq n tcclosed coqeq n tcarch
94+ret ulong 2
95+end
96+if coqeq n tcmerged
97+ret ulong 3
98+end
99+if coqeq n tcall
100+ret ulong 9
101+end
102+ret ulong 0
103+end
104+fn costname kd ulong s ulong to void
105+if eq s 9
106+fput tcsall
107+ret
108+end
109+if eq s 0
110+fput tcsopen
111+ret
112+end
113+if eq s 1
114+fput tcsdraft
115+ret
116+end
117+if eq s 3
118+fput tcsmerg
119+ret
120+end
121+if eq kd 1
122+fput tcsarch
123+ret
124+end
125+fput tcsclos
126+end
127+fn costbadge kd ulong s ulong to void
128+if or eq s 0 eq s 3
129+fput tcbok
130+else
131+if eq s 1
132+fput tcbmut
133+else
134+fput tcbbad
135+end
136+end
137+costname kd s
138+fput tcboff
139+end
140+fn cotab f ulong s ulong nm view uchar * v view uchar * to void
141+kd = get gcm 9
142+fput tcah
143+fputrl
144+if eq kd 1
145+fput tcpats
146+else
147+fput tcisss
148+end
149+fput tcstq
150+fput v
151+fput tcqg
152+if eq f s
153+fput tcbon
154+end
155+fput nm
156+fput tcopar
157+cotabn kd s
158+fput tccpar
159+if eq f s
160+fput tcboff
161+end
162+fput tcae
163+cosp
164+end
165+fn cotabn kd ulong s ulong to void
166+if eq s 9
167+fnum get gcsn 0
168+ret
169+end
170+fnum get gccnt s
171+end
172+fn cotabs kd ulong f ulong to void
173+cotab f 0 tcsopen tcopen
174+if eq kd 1
175+cotab f 1 tcsdraft tcdraft
176+cotab f 3 tcsmerg tcmerged
177+cotab f 2 tcsarch tcarch
178+else
179+cotab f 2 tcsclos tcclosed
180+end
181+cotab f 9 tcsall tcall
182+end
183+fn codrefb to void
184+i = get fridx 0
185+o = get fabo i
186+n = get fabl i
187+for k ulong n bound 64
188+put gbref k get fabr add o k
189+end
190+put gbrefl 0 n
191+end
192+fn cojq to void
193+fputc 34
194+end
195+fn cojsn kd ulong s ulong to void
196+cojq
197+cojsv kd s
198+cojq
199+end
200+fn cojsv kd ulong s ulong to void
201+if eq s 9
202+fput tcall
203+end
204+if eq s 0
205+fput tcopen
206+end
207+if eq s 1
208+fput tcdraft
209+end
210+if eq s 3
211+fput tcmerged
212+end
213+if eq s 2
214+if eq kd 1
215+fput tcarch
216+else
217+fput tcclosed
218+end
219+end
220+ret
221+end
222+fn cojtabs kd ulong to void
223+fputc 91
224+cojtab kd 0 false
225+if eq kd 1
226+cojtab kd 1 true
227+cojtab kd 3 true
228+cojtab kd 2 true
229+else
230+cojtab kd 2 true
231+end
232+cojtab kd 9 true
233+fputc 93
234+end
235+fn cojtab kd ulong s ulong c bool to void
236+if c
237+fputc 44
238+end
239+fputc 123
240+fyk0 tcstn
241+cojsn kd s
242+fyk tcjcnt
243+cotabn kd s
244+fyk tcjpath
245+cojq
246+fputrl
247+if eq kd 1
248+fput tcpats
249+else
250+fput tcisss
251+end
252+fput tcstq
253+cojsv kd s
254+cojq
255+fputc 125
256+end

collab/native/issue.om

new file mode 100644
@@ -0,0 +1,878 @@
1+note collab/co5iss.om: issues from the native issue store (GitHub import contract r1 G3; docs/API.md
2+note forge/issues/1, forge/issue/1). The store is <data>issues/<owner>/<repo>/: an index file of lines
3+note "<id>\n" (16 lowercase hex) and one folder per issue with title, description, status ("open\n" or
4+note "closed\n"), labels (one per line), gh (number, login, opened, closed, reason lines), thread and
5+note source.json for imports, or native metadata for web writes. Nothing here reads Radicle storage.
6+note A native-comment record holds the author DID and form token before the length.
7+note A thread is a run of records "<kind> <time> <login> [<state> | <line> <pathlen>] <len>\n" then
8+note [<path>\n] <body>\n with kind comment, review or review-comment.
9+note An imported issue names its GitHub author as plain text, "Imported from GitHub <owner>/<repo>#<n>,
10+note by <login>": never a link, an account of this forge or a DID (G1).
11+note Prefixes: functions ni*, globals gn*, texts tn*.
12+text tniwnat "native"
13+text tniwdid "did "
14+text tniwncom "native-comment"
15+text tniss "issues/"
16+text tnindex "index"
17+text tnfttl "title"
18+text tnfdsc "description"
19+text tnfsts "status"
20+text tnfgh "gh"
21+text tnfthr "thread"
22+text tnflab "labels"
23+text tnfsrc "source.json"
24+text tnghn "number "
25+text tnghl "login "
26+text tnghop "opened "
27+text tnghcl "closed "
28+text tnghre "reason "
29+text tnjow "\"owner\":\""
30+text tnjrp "\"repo\":\""
31+text tnrcom "comment"
32+text tnrrev "review"
33+text tnrrc "review-comment"
34+text tnimp1 "Imported from GitHub "
35+text tnimp2 ", by "
36+text tnmeta "<p class=\"meta\">"
37+text tnmetae "</p>\n"
38+text tnli3 "<p class=\"meta\"><code>#"
39+text tnli4 "</code> &#183; opened "
40+text tnli5 " comment"
41+text tnph1 "<section class=\"rhead\"><h1>"
42+text tnph2 "</h1>\n"
43+text tnclo " &#183; closed "
44+text tnreas " (reason "
45+text tnlab "Labels: "
46+text tnbox "<section class=\"box\"><p class=\"meta\">"
47+text tnwrote " wrote on "
48+text tnrevd " reviewed ("
49+text tnrevd2 ") on "
50+text tnrcon " commented on <code>"
51+text tnline "</code> line "
52+text tnon " on "
53+text tnsece "</section>\n"
54+text tnnocm "<p class=\"muted\">No comments.</p>\n"
55+text tnutc " UTC"
56+text tntiss " - issue - "
57+text tnmd1 "<article class=\"md\">\n"
58+text tnmd2 "</article>\n"
59+text tnpkey "page"
60+text tnpp "per_page"
61+text tnnext "next"
62+text tnprev "prev"
63+text tnpage "&amp;page="
64+text tnpjson "&page="
65+text tnnava "<nav aria-label=\"Issue pages\">"
66+text tnnavz "</nav>\n"
67+text tnpnext "Next"
68+text tnpprev "Previous"
69+const NIPAGE ulong 30
70+const NIROWS ulong 262144
71+const NILEG ulong 200
72+global gnpage ulong 1
73+global gnmatch ulong 1
74+global gnpaged ulong 1
75+note the index of the repository's store (17 bytes per id line) and its count
76+global gnix uchar 4456448
77+global gnn ulong 1
78+note one issue's thread file, a small file (title, gh, status, source.json) and its length
79+global gnth uchar 16777216
80+global gnthl ulong 1
81+global gnf uchar 65536
82+global gnfl ulong 1
83+global gngh uchar 65536
84+global gnghl ulong 1
85+global gnative ulong 1
86+note a parsed thread record: kind (1 comment 2 review 3 review comment), time, login, state, line,
87+note path and body as offsets and lengths into gnth
88+global gnr ulong 16
89+
90+note ---- paths and reads
91+fn nipath to void
92+fpb
93+fpt tfdata
94+fpt tniss
95+fpt tfowner
96+fpc 47
97+r = get fridx 0
98+for i ulong get fanl r bound 128
99+fpc frnbyte r i
100+end
101+fpc 47
102+end
103+fn nipf k ulong t view uchar * to void
104+nipath
105+for i ulong 16
106+fpc get gnix add mul k 17 i
107+end
108+fpc 47
109+fpt t
110+end
111+note niidx: the ids of the index into gnix (lines that are not 16 lowercase hex and a line feed are
112+note left out); a missing index is an empty store. false when the index does not fit the table.
113+fn niidx to bool
114+put gnn 0 0
115+nipath
116+fpt tnindex
117+r = frdall
118+if lt r 0
119+ret true
120+end
121+if ne get fxotr 0 0
122+fincut
123+ret false
124+end
125+n = div ulong r 17
126+if gt n 262144
127+fincut
128+ret false
129+end
130+m = ulong 0
131+for j ulong n bound 262144
132+if niidok mul j 17
133+nicp mul j 17 mul m 17
134+m = add m 1
135+end
136+end
137+put gnn 0 m
138+ret true
139+end
140+fn nicp a ulong b ulong to void
141+for i ulong 17
142+put gnix add b i get fxo add a i
143+end
144+end
145+fn niidok o ulong to bool
146+for i ulong 16
147+c = get fxo add o i
148+if not or and ge c 48 le c 57 and ge c 97 le c 102
149+ret false
150+end
151+end
152+ret eq get fxo add o 16 10
153+end
154+note nismall k t: the file t of issue k into gnf (at most 65536 bytes are kept); its length
155+fn nismall k ulong t view uchar * to ulong
156+put gnfl 0 0
157+nipf k t
158+r = frdall
159+if lt r 0
160+ret 0
161+end
162+n = ulong r
163+if gt n 65536
164+n = ulong 65536
165+end
166+for i ulong n bound 65536
167+put gnf i get fxo i
168+end
169+put gnfl 0 n
170+ret n
171+end
172+note nistate k: 0 open, 2 closed (the states of costbadge 2)
173+fn nistate k ulong to ulong
174+n = nismall k tnfsts
175+if and eq n 5 eq get gnf 0 111
176+ret 0
177+end
178+ret 2
179+end
180+note nigh k: the gh file of issue k into gngh
181+fn nigh k ulong to void
182+n = nismall k tniwnat
183+put gnative 0 0
184+if eq n 0
185+n = nismall k tnfgh
186+else
187+put gnative 0 1
188+end
189+for i ulong n bound 65536
190+put gngh i get gnf i
191+end
192+put gnghl 0 n
193+end
194+note nighv t: the value of the gh line "<t><value>\n": its offset in gngh; its length in gnr 15
195+fn nighv t view uchar * to ulong
196+n = get gnghl 0
197+s = ulong 0
198+for i ulong n bound 65536
199+if eq get gngh i 10
200+if nighat s i t
201+put gnr 15 sub sub i s len t
202+ret add s len t
203+end
204+s = add i 1
205+end
206+end
207+put gnr 15 0
208+ret 0
209+end
210+fn nighat s ulong e ulong t view uchar * to bool
211+if lt sub e s len t
212+ret false
213+end
214+for i ulong len t bound 16
215+if ne get gngh add s i get t i
216+ret false
217+end
218+end
219+ret true
220+end
221+note nighp t: the gh value t, HTML-escaped
222+fn nighp t view uchar * to void
223+o = nighv t
224+for i ulong get gnr 15 bound 65536
225+fescc get gngh add o i
226+end
227+end
228+note nijv t: in gnf (a source.json), the string value after t (plain names), HTML-escaped
229+fn nijv t view uchar * to void
230+n = get gnfl 0
231+for s ulong n bound 65536
232+if nijat s t
233+p = add s len t
234+while lt p n bound 65536
235+c = get gnf p
236+if eq c 34
237+ret
238+end
239+fescc c
240+p = add p 1
241+end
242+ret
243+end
244+end
245+end
246+fn nijat s ulong t view uchar * to bool
247+if gt add s len t get gnfl 0
248+ret false
249+end
250+for i ulong len t bound 16
251+if ne get gnf add s i get t i
252+ret false
253+end
254+end
255+ret true
256+end
257+note nithr k: the thread of issue k into gnth; false when it does not fit
258+fn nithr k ulong to bool
259+put gnthl 0 0
260+nipf k tnfthr
261+r = frdall
262+if lt r 0
263+ret true
264+end
265+if ne get fxotr 0 0
266+ret false
267+end
268+for i ulong ulong r bound 16777216
269+put gnth i get fxo i
270+end
271+put gnthl 0 ulong r
272+ret true
273+end
274+
275+note ---- thread records
276+global gnbad ulong 1
277+global gncur ulong 1
278+fn niword a ulong to void
279+put gnr add a 1 0
280+if ne get gnbad 0 0
281+ret
282+end
283+p = get gncur 0
284+n = get gnthl 0
285+q = p
286+while lt q n bound 257
287+if le get gnth q 32
288+break
289+end
290+if ge sub q p 256
291+put gnbad 0 1
292+ret
293+end
294+q = add q 1
295+end
296+if or ge q n eq q p
297+put gnbad 0 1
298+ret
299+end
300+if ne get gnth q 32
301+put gnbad 0 1
302+ret
303+end
304+put gnr a p
305+put gnr add a 1 sub q p
306+put gncur 0 add q 1
307+end
308+note nidec t: the decimal at gncur (1..18 digits) ended by the byte t; gncur moves past t. gnbad is
309+note set when it is not one. At most 19 passes: the pass that sees an 19th digit returns.
310+fn nidec t uchar to ulong
311+if ne get gnbad 0 0
312+ret 0
313+end
314+p = get gncur 0
315+n = get gnthl 0
316+v = ulong 0
317+k = ulong 0
318+while lt p n bound 19
319+c = get gnth p
320+if not fisdig c
321+break
322+end
323+if ge k 18
324+put gnbad 0 1
325+ret 0
326+end
327+v = add mul v 10 ulong sub c 48
328+k = add k 1
329+p = add p 1
330+end
331+if or eq k 0 ge p n
332+put gnbad 0 1
333+ret 0
334+end
335+if ne get gnth p t
336+put gnbad 0 1
337+ret 0
338+end
339+put gncur 0 add p 1
340+ret v
341+end
342+note niwordis a t: the word of gnr a, a+1 is t
343+fn niwordis a ulong t view uchar * to bool
344+if ne get gnr add a 1 len t
345+ret false
346+end
347+o = get gnr a
348+for i ulong len t bound 16
349+if ne get gnth add o i get t i
350+ret false
351+end
352+end
353+ret true
354+end
355+note nikind: the record kind of the word in gnr 12, 13: 1 comment, 2 review, 3 review-comment, else 0
356+fn nikind to ulong
357+if niwordis 12 tnrcom
358+ret 1
359+end
360+if niwordis 12 tniwncom
361+ret 4
362+end
363+if niwordis 12 tnrrev
364+ret 2
365+end
366+if niwordis 12 tnrrc
367+ret 3
368+end
369+ret 0
370+end
371+note nitok: the time word (gnr 1, 2) is 20 bytes or "-"
372+fn nitok to bool
373+k = get gnr 2
374+if eq k 20
375+ret true
376+end
377+if ne k 1
378+ret false
379+end
380+ret eq get gnth get gnr 1 45
381+end
382+note nirec p: parse the record at p into gnr (0 kind, 1-2 time, 3-4 login, 5-6 state, 7 line, 8-9
383+note path, 10-11 body); the index after it. A malformed record leaves kind 0 and returns the thread's
384+note length, which stops the caller: every length is checked against the thread before the bytes it
385+note names are read (a path is at most 4096 bytes).
386+fn nirec p ulong to ulong
387+n = get gnthl 0
388+put gnr 0 0
389+put gnr 6 0
390+put gnr 7 0
391+put gnr 9 0
392+put gnbad 0 0
393+put gncur 0 p
394+niword 12
395+k = nikind
396+if eq k 0
397+ret n
398+end
399+niword 1
400+niword 3
401+if or eq k 2 eq k 4
402+niword 5
403+end
404+if eq k 3
405+put gnr 7 nidec 32
406+put gnr 9 nidec 32
407+end
408+b = nidec 10
409+if ne get gnbad 0 0
410+ret n
411+end
412+if not nitok
413+ret n
414+end
415+q = get gncur 0
416+if eq k 3
417+m = get gnr 9
418+if or gt m 4096 ge add q m n
419+ret n
420+end
421+if ne get gnth add q m 10
422+ret n
423+end
424+put gnr 8 q
425+q = add add q m 1
426+end
427+if ge add q b n
428+ret n
429+end
430+if ne get gnth add q b 10
431+ret n
432+end
433+put gnr 10 q
434+put gnr 11 b
435+put gnr 0 k
436+ret add add q b 1
437+end
438+note nicount: the records of the loaded thread
439+fn nicount to ulong
440+p = ulong 0
441+c = ulong 0
442+n = get gnthl 0
443+while lt p n bound 16777216
444+p = nirec p
445+if ne get gnr 0 0
446+c = add c 1
447+end
448+end
449+ret c
450+end
451+note nitime o: the ISO time gnth[o, o+20) as YYYY-MM-DD HH:MM UTC
452+fn nitime o ulong to void
453+for i ulong 10
454+fescc get gnth add o i
455+end
456+fputc 32
457+for i ulong 5
458+fescc get gnth add add o 11 i
459+end
460+fput tnutc
461+end
462+note nighte t: the gh time value t as YYYY-MM-DD HH:MM UTC ("-" stays "-")
463+fn nighte t view uchar * to void
464+o = nighv t
465+if ne get gnr 15 20
466+fputc 45
467+ret
468+end
469+for i ulong 10
470+fescc get gngh add o i
471+end
472+fputc 32
473+for i ulong 5
474+fescc get gngh add add o 11 i
475+end
476+fput tnutc
477+end
478+
479+note ---- the provenance line: Imported from GitHub <owner>/<repo>#<n>, by <login> (plain text)
480+fn niprov k ulong to void
481+x = nismall k tnfsrc
482+fput tnimp1
483+nijv tnjow
484+fputc 47
485+nijv tnjrp
486+fputc 35
487+nighp tnghn
488+fput tnimp2
489+nighp tnghl
490+end
491+fn niwho to void
492+if eq get gnative 0 1
493+nighp tniwdid
494+else
495+nighp tnghl
496+end
497+end
498+fn niorigin k ulong to void
499+if eq get gnative 0 1
500+niwho
501+else
502+niprov k
503+end
504+end
505+note niref: the request's id prefix (gcrq, 4..16 hex) names exactly one issue: its index, else gnn
506+fn niref to ulong
507+n = get gnn 0
508+q = get gcrql 0
509+if gt q 16
510+ret n
511+end
512+w = n
513+c = ulong 0
514+for k ulong n bound 262144
515+if nipre k q
516+w = k
517+c = add c 1
518+end
519+end
520+if ne c 1
521+ret n
522+end
523+ret w
524+end
525+fn nipre k ulong q ulong to bool
526+for i ulong q bound 16
527+if ne get gnix add mul k 17 i get gcrq i
528+ret false
529+end
530+end
531+ret true
532+end
533+fn nilink k ulong to void
534+fputrl
535+fput tcissp
536+for i ulong 16
537+fputc get gnix add mul k 17 i
538+end
539+end
540+
541+note ---- the list page
542+note nifilt: the ?state= filter (0 open, 2 closed, 9 all; anything else open) and the tab counts in
543+note gccnt and gcsn (cotabs reads them)
544+fn nifilt to ulong
545+f = coqstate 2
546+if and ne f 2 ne f 9
547+f = ulong 0
548+end
549+for s ulong 8
550+put gccnt s 0
551+end
552+for k ulong get gnn 0 bound 262144
553+s = nistate k
554+put gccnt s add get gccnt s 1
555+end
556+put gcsn 0 get gnn 0
557+put gcm 9 2
558+ret f
559+end
560+note Keep list thread reads to one page. The status scan also supplies the filter counts.
561+fn nipagen f ulong to void
562+n = fqget tnpkey
563+put gnpaged 0 0
564+if ge n 0
565+put gnpaged 0 1
566+end
567+v = ulong 0
568+if and gt n 0 le n 6
569+for i ulong ulong n bound 6
570+c = get fval i
571+if not fisdig c
572+v = ulong 0
573+break
574+end
575+v = add mul v 10 ulong sub c 48
576+end
577+end
578+if eq v 0
579+v = ulong 1
580+end
581+put gnpage 0 v
582+put gnmatch 0 cotabnval f
583+end
584+fn cotabnval s ulong to ulong
585+if eq s 9
586+ret get gcsn 0
587+end
588+ret get gccnt s
589+end
590+fn nipageurl f ulong p ulong html bool to void
591+fputrl
592+fput tcisss
593+fput tcstq
594+cojsv 2 f
595+if html
596+fput tnpage
597+else
598+fput tnpjson
599+end
600+fnum p
601+end
602+fn nilnav f ulong to void
603+p = get gnpage 0
604+if and eq p 1 le get gnmatch 0 NIPAGE
605+ret
606+end
607+fput tnnava
608+if gt p 1
609+fput tcah
610+nipageurl f sub p 1 true
611+fput tcqg
612+fput tnpprev
613+fput tcae
614+cosp
615+end
616+if gt get gnmatch 0 mul p NIPAGE
617+fput tcah
618+nipageurl f add p 1 true
619+fput tcqg
620+fput tnpnext
621+fput tcae
622+end
623+fput tnnavz
624+end
625+fn nilist to long
626+if not niidx
627+ret 500
628+end
629+f = nifilt
630+nipagen f
631+fsetti tciss
632+frepohd 6
633+ftic 32
634+ftirepo
635+fput tclh1
636+costname 2 f
637+fput tclh2
638+cotabs 2 f
639+fput tclh3
640+niwlink
641+m = ulong 0
642+fput tclul
643+skip = mul sub get gnpage 0 1 NIPAGE
644+for j ulong get gnn 0 bound 262144
645+k = sub sub get gnn 0 1 j
646+s = nistate k
647+if or eq f 9 eq f s
648+if ge m skip
649+if not nirow k s
650+ret 500
651+end
652+end
653+m = add m 1
654+if eq m add skip NIPAGE
655+break
656+end
657+end
658+end
659+fput tcluln
660+if le m skip
661+fput tclnone
662+end
663+nilnav f
664+ret 200
665+end
666+fn nirow k ulong s ulong to bool
667+fput tcli1
668+nilink k
669+fput tcqg
670+n = nismall k tnfttl
671+if eq n 0
672+fput tcnot
673+end
674+for i ulong n bound 65536
675+fescc get gnf i
676+end
677+fput tcli2
678+costbadge 2 s
679+nigh k
680+if eq get gnative 0 0
681+fput tnli3
682+nighp tnghn
683+fput tnli4
684+nighte tnghop
685+else
686+fput tnmeta
687+fput tcopen
688+cosp
689+nighte tnghop
690+end
691+fput tcmidd
692+if not nithr k
693+ret false
694+end
695+c = nicount
696+fnum c
697+fput tnli5
698+if ne c 1
699+fputc 115
700+end
701+fput tcli7
702+fput tnmeta
703+niorigin k
704+fput tnmetae
705+fput tcli10
706+ret true
707+end
708+
709+note ---- one issue page
710+fn nipage to long
711+if not niidx
712+ret 500
713+end
714+k = niref
715+if ge k get gnn 0
716+ret 404
717+end
718+s = nistate k
719+n = nismall k tnfttl
720+put ftil 0 0
721+for i ulong hmin n 256 bound 256
722+ftic get gnf i
723+end
724+for i ulong len tntiss
725+ftic get tntiss i
726+end
727+ftirepo
728+frepohd 6
729+fput tnph1
730+if eq n 0
731+fput tcnot
732+end
733+for i ulong n bound 65536
734+fescc get gnf i
735+end
736+fput tnph2
737+nigh k
738+fput tnmeta
739+costbadge 2 s
740+fput tcmidd
741+if eq get gnative 0 0
742+fputc 35
743+nighp tnghn
744+fput tcmidd
745+end
746+fput tcopen
747+cosp
748+nighte tnghop
749+if eq s 2
750+fput tnclo
751+nighte tnghcl
752+x = nighv tnghre
753+if gt get gnr 15 1
754+fput tnreas
755+nighp tnghre
756+fputc 41
757+end
758+end
759+fput tnmetae
760+fput tnmeta
761+niorigin k
762+fput tnmetae
763+nilabs k
764+fput tnsece
765+if not nibody k
766+ret 500
767+end
768+if not nithr k
769+ret 500
770+end
771+nicoms
772+niwform k false
773+ret 200
774+end
775+fn nilabs k ulong to void
776+n = nismall k tnflab
777+if eq n 0
778+ret
779+end
780+fput tnmeta
781+fput tnlab
782+for i ulong n bound 65536
783+c = get gnf i
784+if eq c 10
785+if lt add i 1 n
786+fputc 44
787+fputc 32
788+end
789+else
790+fescc c
791+end
792+end
793+fput tnmetae
794+end
795+note nibody k: the description as Markdown (the default branch for relative links)
796+fn nibody k ulong to bool
797+nipf k tnfdsc
798+r = frdall
799+if le r 0
800+ret true
801+end
802+if ne get fxotr 0 0
803+ret false
804+end
805+codrefb
806+fput tnbox
807+niwho
808+fput tnwrote
809+nighte tnghop
810+fput tnmetae
811+put gbmdl 0 0
812+fput tnmd1
813+brmd 0 ulong r
814+fput tnmd2
815+fput tnsece
816+ret true
817+end
818+fn nicoms to void
819+p = ulong 0
820+c = ulong 0
821+n = get gnthl 0
822+while lt p n bound 16777216
823+p = nirec p
824+if ne get gnr 0 0
825+nicom
826+c = add c 1
827+end
828+end
829+if eq c 0
830+fput tnnocm
831+end
832+end
833+note nicom: the parsed record (gnr) as a comment box; the login is text, the body Markdown
834+fn nicom to void
835+k = get gnr 0
836+fput tnbox
837+niraw 3
838+if or eq k 1 eq k 4
839+fput tnwrote
840+end
841+if eq k 2
842+fput tnrevd
843+niraw 5
844+fput tnrevd2
845+end
846+if eq k 3
847+fput tnrcon
848+niraw 8
849+fput tnline
850+fnum get gnr 7
851+fput tnon
852+end
853+if eq get gnr 2 20
854+nitime get gnr 1
855+else
856+fputc 45
857+end
858+fput tnmetae
859+o = get gnr 10
860+b = get gnr 11
861+if gt b 0
862+for i ulong b bound 16777216
863+put fxo i get gnth add o i
864+end
865+put gbmdl 0 0
866+fput tnmd1
867+brmd 0 b
868+fput tnmd2
869+end
870+fput tnsece
871+end
872+note niraw a: the bytes gnth[gnr a, + gnr a+1), HTML-escaped
873+fn niraw a ulong to void
874+o = get gnr a
875+for i ulong get gnr add a 1 bound 16777216
876+fescc get gnth add o i
877+end
878+end

collab/native/json.om

new file mode 100644
@@ -0,0 +1,447 @@
1+note ---- issues of the native store (collab/co5iss.om): forge/issues/1 and forge/issue/1. An imported
2+note issue has "author": null and an "imported" object naming its GitHub source and login (plain data,
3+note never an account or a DID of this forge); the first comment is the issue body, as on the page.
4+text tnjimp "imported"
5+text tnjdid "did"
6+text tnjnm "name"
7+text tnjfrom "from"
8+text tnjgh "github"
9+text tnjown "owner"
10+text tnjrepo "repo"
11+text tnjurl "url"
12+text tnjlog "login"
13+text tnjkind "kind"
14+text tnjclos "closed"
15+text tnjline "line"
16+text tnjurlk "\"url\":\""
17+fn nijlist to long
18+if not niidx
19+ret 500
20+end
21+f = nifilt
22+nipagen f
23+fyrhead tcjsis
24+fyk tcstn
25+cojsn 2 f
26+fyk tcjsts
27+cojtabs 2
28+fyk tcjtr
29+paged = ne get gnpaged 0 0
30+fybool and not paged gt get gnmatch 0 NILEG
31+if paged
32+fyk tnpkey
33+fnum get gnpage 0
34+fyk tnpp
35+fnum NIPAGE
36+nijnav f
37+end
38+fyk tcjisss
39+fputc 91
40+if not nijrows f paged
41+ret 500
42+end
43+fputc 93
44+fyk tcnwr
45+niwnewjson
46+fputc 10
47+fyend
48+ret 200
49+end
50+fn nijrows f ulong paged bool to bool
51+m = ulong 0
52+skip = ulong 0
53+count = NILEG
54+if paged
55+skip = mul sub get gnpage 0 1 NIPAGE
56+count = NIPAGE
57+end
58+n = get gnn 0
59+for j ulong n bound NIROWS
60+k = j
61+if paged
62+k = sub sub n 1 j
63+end
64+s = nistate k
65+if or eq f 9 eq f s
66+if ge m skip
67+if gt m skip
68+fputc 44
69+end
70+fputc 10
71+if not nijrow k s
72+ret false
73+end
74+end
75+m = add m 1
76+if eq m add skip count
77+break
78+end
79+end
80+end
81+ret true
82+end
83+fn nijnav f ulong to void
84+p = get gnpage 0
85+fyk tnprev
86+if gt p 1
87+cojq
88+nipageurl f sub p 1 false
89+cojq
90+else
91+fynull
92+end
93+fyk tnnext
94+if gt get gnmatch 0 mul p NIPAGE
95+cojq
96+nipageurl f add p 1 false
97+cojq
98+else
99+fynull
100+end
101+end
102+fn nijid k ulong to void
103+cojq
104+for i ulong 16
105+fputc get gnix add mul k 17 i
106+end
107+cojq
108+end
109+fn nijtitle k ulong to void
110+n = nismall k tnfttl
111+fjtb
112+for i ulong n bound 65536
113+fjtc get gnf i
114+end
115+fjstr
116+end
117+fn nijrow k ulong s ulong to bool
118+fputc 123
119+fyk0 tcid
120+nijid k
121+fyk tcjtitl
122+nijtitle k
123+fyk tcstn
124+cojsn 2 s
125+nigh k
126+fyk tcjauth
127+nijauthor
128+nijimp k
129+if not nithr k
130+ret false
131+end
132+fyk tcjupd
133+nijupd
134+fyk tcjcoms
135+fnum nicount
136+fyk tcjverd
137+fynull
138+fyk tcjpath
139+cojq
140+nilink k
141+cojq
142+fputc 125
143+ret true
144+end
145+fn nijauthor to void
146+if eq get gnative 0 0
147+fynull
148+ret
149+end
150+fputc 123
151+fyk0 tnjdid
152+nijgh tniwdid
153+fyk tnjnm
154+fynull
155+fputc 125
156+end
157+note nijgh t: the gh value t as a JSON string (null when "-" or absent)
158+fn nijgh t view uchar * to void
159+o = nighv t
160+n = get gnr 15
161+if or eq n 0 and eq n 1 eq get gngh o 45
162+fynull
163+ret
164+end
165+fjtb
166+for i ulong n bound 65536
167+fjtc get gngh add o i
168+end
169+fjstr
170+end
171+note nijsv t: in gnf (a source.json), the string value after t as a JSON string
172+fn nijsv t view uchar * to void
173+fjtb
174+n = get gnfl 0
175+for s ulong n bound 65536
176+if nijat s t
177+p = add s len t
178+while lt p n bound 65536
179+c = get gnf p
180+if eq c 34
181+break
182+end
183+fjtc c
184+p = add p 1
185+end
186+break
187+end
188+end
189+fjstr
190+end
191+note nighnum: imported issue number as a bounded decimal; invalid or missing is zero
192+fn nighnum to ulong
193+o = nighv tnghn
194+n = get gnr 15
195+if gt n 18
196+ret 0
197+end
198+v = ulong 0
199+for i ulong n bound 18
200+c = get gngh add o i
201+if not fisdig c
202+ret 0
203+end
204+v = add mul v 10 ulong sub c 48
205+end
206+ret v
207+end
208+note nijimp k: ,"imported":{"from":"github","owner","repo","number","url","login"} (gh must be loaded)
209+fn nijimp k ulong to void
210+x = nismall k tnfsrc
211+fyk tnjimp
212+if eq get gnative 0 1
213+fynull
214+ret
215+end
216+fputc 123
217+fyk0 tnjfrom
218+fysv tnjgh
219+fyk tnjown
220+nijsv tnjow
221+fyk tnjrepo
222+nijsv tnjrp
223+fyk tcjnum
224+fnum nighnum
225+fyk tnjurl
226+nijsv tnjurlk
227+fyk tnjlog
228+nijgh tnghl
229+fputc 125
230+end
231+note nijupd: the newest of the opened and closed times and the loaded thread's record times
232+fn nijupd to void
233+o = nighv tnghop
234+if ne get gnr 15 20
235+fynull
236+ret
237+end
238+for i ulong 20
239+put gnf i get gngh add o i
240+end
241+c = nighv tnghcl
242+if eq get gnr 15 20
243+if nighlt 0 c
244+for i ulong 20
245+put gnf i get gngh add c i
246+end
247+end
248+end
249+p = ulong 0
250+n = get gnthl 0
251+while lt p n bound 16777216
252+p = nirec p
253+if and ne get gnr 0 0 eq get gnr 2 20
254+if nithlt get gnr 1
255+for i ulong 20
256+put gnf i get gnth add get gnr 1 i
257+end
258+end
259+end
260+end
261+fjtb
262+for i ulong 20
263+fjtc get gnf i
264+end
265+fjstr
266+end
267+note nighlt a c: gnf[a, a+20) sorts before gngh[c, c+20)
268+fn nighlt a ulong c ulong to bool
269+for i ulong 20
270+x = get gnf add a i
271+y = get gngh add c i
272+if ne x y
273+ret lt x y
274+end
275+end
276+ret false
277+end
278+fn nithlt c ulong to bool
279+for i ulong 20
280+x = get gnf i
281+y = get gnth add c i
282+if ne x y
283+ret lt x y
284+end
285+end
286+ret false
287+end
288+note nijraw a: gnth[gnr a, + gnr a+1) as a JSON string
289+fn nijraw a ulong to void
290+fjtb
291+o = get gnr a
292+for i ulong get gnr add a 1 bound 16777216
293+fjtc get gnth add o i
294+end
295+fjstr
296+end
297+fn nijone to long
298+if not niidx
299+ret 500
300+end
301+k = niref
302+if ge k get gnn 0
303+ret 404
304+end
305+s = nistate k
306+fyrhead tcjsi
307+fyk tcid
308+nijid k
309+fyk tcjtitl
310+nijtitle k
311+fyk tcstn
312+cojsn 2 s
313+nigh k
314+fyk tcjauth
315+nijauthor
316+nijimp k
317+fyk tcjopen
318+nijgh tnghop
319+fyk tnjclos
320+nijgh tnghcl
321+fyk tcjpath
322+cojq
323+nilink k
324+cojq
325+fyk tcjreas
326+nijgh tnghre
327+nijlabs k
328+fyk tcjasg
329+fputc 91
330+fputc 93
331+if not nithr k
332+ret 500
333+end
334+if not nijcoms k
335+ret 500
336+end
337+fyend
338+ret 200
339+end
340+fn nijlabs k ulong to void
341+fyk tcjlabs
342+fputc 91
343+n = nismall k tnflab
344+s = ulong 0
345+c = ulong 0
346+for i ulong n bound 65536
347+if eq get gnf i 10
348+if gt c 0
349+fputc 44
350+end
351+fjtb
352+for j ulong sub i s bound 65536
353+fjtc get gnf add s j
354+end
355+fjstr
356+c = add c 1
357+s = add i 1
358+end
359+end
360+fputc 93
361+end
362+note nijcoms k: "comments": the body first (author null, the GitHub login, opened), then the thread
363+fn nijcoms k ulong to bool
364+fyk tcjcoms
365+fputc 91
366+fputc 10
367+fputc 123
368+fyk0 tcjauth
369+nijauthor
370+fyk tnjlog
371+nijgh tnghl
372+fyk tnjkind
373+fysv tcjtcom
374+fyk tcjtime
375+nijgh tnghop
376+fyk tcjbody
377+nipf k tnfdsc
378+r = frdall
379+if lt r 0
380+r = 0
381+end
382+if ne get fxotr 0 0
383+ret false
384+end
385+fjfx 0 ulong r
386+fyk tcjred
387+fybool false
388+fputc 125
389+p = ulong 0
390+n = get gnthl 0
391+while lt p n bound 16777216
392+p = nirec p
393+if ne get gnr 0 0
394+fputc 44
395+fputc 10
396+nijcom
397+end
398+end
399+fputc 93
400+ret true
401+end
402+fn nijcom to void
403+k = get gnr 0
404+fputc 123
405+fyk0 tcjauth
406+if eq k 4
407+fputc 123
408+fyk0 tnjdid
409+nijraw 3
410+fyk tnjnm
411+fynull
412+fputc 125
413+fyk tnjlog
414+fynull
415+else
416+fynull
417+fyk tnjlog
418+nijraw 3
419+end
420+fyk tnjkind
421+if or eq k 1 eq k 4
422+fysv tcjtcom
423+end
424+if eq k 2
425+fysv tcjtrvw
426+fyk tcstn
427+nijraw 5
428+end
429+if eq k 3
430+fysv tnrrc
431+fyk tcjpath
432+nijraw 8
433+fyk tnjline
434+fnum get gnr 7
435+end
436+fyk tcjtime
437+if eq get gnr 2 20
438+nijraw 1
439+else
440+fynull
441+end
442+fyk tcjbody
443+nijraw 10
444+fyk tcjred
445+fybool false
446+fputc 125
447+end

collab/native/route.om

new file mode 100644
@@ -0,0 +1,84 @@
1+note Native issue list, detail, creation and comments. Prefixes are accepted only on reads.
2+text tnnew "new"
3+text tncoms "/comments"
4+fn niresat a ulong n ulong t view uchar * to bool
5+if ne sub n a len t
6+ret false
7+end
8+for i ulong len t bound 16
9+if ne get frest add a i get t i
10+ret false
11+end
12+end
13+ret true
14+end
15+fn niresid a ulong size ulong to bool
16+if or lt size 4 gt size 16
17+ret false
18+end
19+for i ulong size bound 16
20+c = get frest add a i
21+if not or and ge c 48 le c 57 and ge c 97 le c 102
22+ret false
23+end
24+put gcrq i c
25+end
26+put gcrql 0 size
27+ret true
28+end
29+fn coroute to long
30+if or ge get fridx 0 get fan 0 not frstpre tcisss
31+ret 0
32+end
33+prefix = len tcisss
34+n = get frestl 0
35+if and gt n prefix ne get frest prefix 47
36+ret 0
37+end
38+fsetepno
39+m = get fmeth 0
40+start = add prefix 1
41+if le n start
42+if ne m 1
43+ret 405
44+end
45+if fjwant
46+ret nijlist
47+end
48+fyalt
49+ret nilist
50+end
51+if niresat start n tnnew
52+if eq m 3
53+ret niwpost true
54+end
55+if eq m 1
56+ret niwnew
57+end
58+ret 405
59+end
60+stop = add start 16
61+if and gt n stop niresat stop n tncoms
62+if not niresid start 16
63+ret 404
64+end
65+if eq m 3
66+ret niwpost false
67+end
68+if eq m 1
69+ret niwcform
70+end
71+ret 405
72+end
73+if not niresid start sub n start
74+ret 404
75+end
76+if ne m 1
77+ret 405
78+end
79+if fjwant
80+ret nijone
81+end
82+fyalt
83+ret nipage
84+end

collab/native/write.om

new file mode 100644
@@ -0,0 +1,841 @@
1+note Native issue writes. The author comes from the session established by SSH key proof. The
2+note repository lock serializes replacements of its index and threads, even across server processes.
3+note fopen flags below use Linux AArch64 values (O_CLOEXEC 524288, O_NOFOLLOW 32768).
4+text tniwnp "/issues/new"
5+text tniwlog "login"
6+text tniwlink "<p><a href=\""
7+text tniwnewa "\">New issue</a></p>\n"
8+text tniwttl "New issue"
9+text tniwform "<section class=\"box\" id=\"comment-form\">"
10+text tniwsign "<p><a href=\""
11+text tniwsgc "\">Sign in to comment</a></p>"
12+text tniwsgn "\">Sign in to open an issue</a></p>"
13+text tniwfa "<form method=\"post\" action=\""
14+text tniwcs "\"><input type=\"hidden\" name=\"csrf\" value=\""
15+text tniwrh "\"><input type=\"hidden\" name=\"request\" value=\""
16+text tniwqt "\">"
17+text tniwtf "<p><label>Title<br><input name=\"title\" required maxlength=\"256\"></label></p>"
18+text tniwdf "<p><label>Description (Markdown)<br><textarea name=\"body\" rows=\"8\" maxlength=\"16000\"></textarea></label></p>"
19+text tniwcf "<p><label>Comment (Markdown)<br><textarea name=\"body\" rows=\"6\" required maxlength=\"16000\"></textarea></label></p>"
20+text tniwbn "<p><button type=\"submit\">Open issue</button></p>"
21+text tniwbc "<p><button type=\"submit\">Post comment</button></p>"
22+text tniwfe "</form></section>\n"
23+text tniwrq "request"
24+text tniwrql "request "
25+text tniwmrq "Reload the form before sending it again."
26+text tniwfs "issue store: directory sync failed after publication\n"
27+text tniwfsch "forge/issue-form/1"
28+text tniwwsch "forge/issue-write/1"
29+text tniwact "action"
30+text tniwcsrf "csrf"
31+text tniwappl "applied"
32+text tniwft "title"
33+text tniwfb "body"
34+text tniwbadt "Enter a single-line title of 1 to 256 UTF-8 bytes."
35+text tniwbadb "Enter valid Markdown text of at most 16000 UTF-8 bytes. A comment cannot be empty."
36+text tniwopa "open\n"
37+text tniwlock ".write.lock"
38+text tniwist ".index.tmp"
39+text tniwtht ".thread.tmp"
40+text tniwstg ".new-"
41+text tniwdir "issues"
42+text tniwemp ""
43+global gniwid uchar 16
44+global gniwtt uchar 256
45+global gniwtl ulong 1
46+global gniwrq uchar 32
47+
48+fn niwlink to void
49+fput tniwlink
50+fputrl
51+fput tniwnp
52+fput tniwnewa
53+end
54+fn niwnewjson to void
55+fputc 34
56+fputrl
57+fput tniwnp
58+fputc 34
59+end
60+fn niwform k ulong opening bool to void
61+fput tniwform
62+if eq get gscur 0 0
63+fput tniwsign
64+fputb
65+fput tniwlog
66+if opening
67+fput tniwsgn
68+else
69+fput tniwsgc
70+end
71+fput tnsece
72+ret
73+end
74+hex = new uchar 32 0
75+if not niwtoken hex
76+fput tniwmrq
77+fput tnsece
78+ret
79+end
80+fput tniwfa
81+if opening
82+fputrl
83+fput tniwnp
84+else
85+nilink k
86+fput tncoms
87+end
88+fput tniwcs
89+for j ulong get fcsrfl 0 bound 64
90+fputc get fcsrf j
91+end
92+fput tniwrh
93+for j ulong 32
94+fputc get hex j
95+end
96+fput tniwqt
97+if opening
98+fput tniwtf
99+fput tniwdf
100+fput tniwbn
101+else
102+fput tniwcf
103+fput tniwbc
104+end
105+fput tniwfe
106+end
107+fn niwtoken hex edit uchar 32 to bool
108+raw = new uchar 16 0
109+if not sorand raw
110+ret false
111+end
112+sohex raw hex
113+ret true
114+end
115+fn niwlogin to long
116+put fkind 0 2
117+flocb
118+floct tniwlog
119+ret 303
120+end
121+fn niwjsform k ulong opening bool to long
122+if eq get gscur 0 0
123+ret niwlogin
124+end
125+hex = new uchar 32 0
126+if not niwtoken hex
127+ret 500
128+end
129+fyrhead tniwfsch
130+fyk tniwact
131+cojq
132+if opening
133+fputrl
134+fput tniwnp
135+else
136+nilink k
137+fput tncoms
138+end
139+cojq
140+fyk tniwcsrf
141+fjtb
142+for i ulong get fcsrfl 0 bound 64
143+fjtc get fcsrf i
144+end
145+fjstr
146+fyk tniwrq
147+fysv hex
148+fyend
149+ret 200
150+end
151+fn niwcform to long
152+if not fjwant
153+ret 405
154+end
155+if eq get gscur 0 0
156+ret niwlogin
157+end
158+if not niidx
159+ret 500
160+end
161+k = niref
162+if ge k get gnn 0
163+ret 404
164+end
165+ret niwjsform k false
166+end
167+fn niwresult applied bool to long
168+if fjwant
169+fyrhead tniwwsch
170+fyk tcjpath
171+cojq
172+fputrl
173+fput tcissp
174+for i ulong 16
175+fputc get gniwid i
176+end
177+cojq
178+fyk tniwappl
179+fybool applied
180+fyend
181+if applied
182+ret 201
183+end
184+ret 200
185+end
186+put fkind 0 2
187+flocrepo
188+floct tcissp
189+for i ulong 16
190+flocc get gniwid i
191+end
192+ret 303
193+end
194+fn niwnew to long
195+if fjwant
196+ret niwjsform 0 true
197+end
198+fsetti tniwttl
199+frepohd 6
200+niwform 0 true
201+ret 200
202+end
203+fn niwerr t view uchar * to long
204+if fjwant
205+fyerr 400
206+note The common error envelope is used by all machine clients.
207+else
208+frepohd 6
209+fput tnbox
210+fput t
211+fput tnmetae
212+fput tnsece
213+end
214+ret 400
215+end
216+fn niwfields opening bool to long
217+if ne cobfld tniwrq 32
218+ret niwerr tniwmrq
219+end
220+for i ulong 32
221+c = get gcfv i
222+if lt sohexv c 0
223+ret niwerr tniwmrq
224+end
225+put gniwrq i c
226+end
227+if opening
228+n = cobfld tniwft
229+if or lt n 1 gt n 256
230+ret niwerr tniwbadt
231+end
232+n = cotxtok ulong n false
233+if lt n 1
234+ret niwerr tniwbadt
235+end
236+put gniwtl 0 ulong n
237+for i ulong ulong n bound 256
238+put gniwtt i get gcfv i
239+end
240+end
241+b = cobfld tniwfb
242+if eq b -1
243+b = 0
244+end
245+if lt b 0
246+ret niwerr tniwbadb
247+end
248+b = cotxtok ulong b true
249+if or or lt b 0 gt b 16000 and not opening eq b 0
250+ret niwerr tniwbadb
251+end
252+put gcfvl 0 ulong b
253+ret 0
254+end
255+fn niwpost opening bool to long
256+r = sowpre
257+if ne r 0
258+if and fjwant ne r 303
259+put fobl 0 0
260+put fkind 0 0
261+end
262+ret r
263+end
264+soratev get gscur 0 get gsnow 0
265+r = niwfields opening
266+if ne r 0
267+ret r
268+end
269+fd = niwacq opening
270+if lt fd 0
271+if eq fd -2
272+ret 404
273+end
274+if eq fd -11
275+put fretry 0 1
276+ret 503
277+end
278+ret 500
279+end
280+if opening
281+r = niwcreate
282+else
283+r = niwcomment
284+end
285+x = fclose int fd
286+if gt r 0
287+ret r
288+end
289+ret niwresult eq r 0
290+end
291+
292+note ---- Storage
293+fn niwdirs to bool
294+fpb
295+fpt tfdata
296+fpt tniwdir
297+if not niwmkdir
298+ret false
299+end
300+fpc 47
301+fpt tfowner
302+if not niwmkdir
303+ret false
304+end
305+fpc 47
306+i = get fridx 0
307+for k ulong get fanl i bound 128
308+fpc frnbyte i k
309+end
310+ret niwmkdir
311+end
312+fn niwmkdir to bool
313+r = makedir fpth 0 get fpthl 0 448
314+ret or eq r 0 eq r -17
315+end
316+fn niwacq opening bool to long
317+if opening
318+if not niwdirs
319+ret -5
320+end
321+end
322+nipath
323+fpt tniwlock
324+fd = fopen fpth 0 get fpthl 0 557121 384
325+if lt fd 0
326+ret fd
327+end
328+r = flock int fd 6
329+if ne r 0
330+x = fclose int fd
331+ret r
332+end
333+ret fd
334+end
335+fn niwpath stage bool file view uchar * to void
336+nipath
337+if stage
338+fpt tniwstg
339+end
340+for i ulong 16
341+fpc get gniwid i
342+end
343+if ne len file 0
344+fpc 47
345+fpt file
346+end
347+end
348+fn niwarg to void
349+soavopen
350+for i ulong get fpthl 0 bound 4096
351+soavc get fpth i
352+end
353+end
354+note Source selectors: response buffer (0), file read buffer (1), title (2), form body (3), open status (4).
355+fn niwwrite fd int src ulong p ulong n ulong to long
356+if eq src 0
357+ret write fd fob p n
358+end
359+if eq src 1
360+ret write fd fxo p n
361+end
362+if eq src 2
363+ret write fd gniwtt p n
364+end
365+if eq src 3
366+ret write fd gcfv p n
367+end
368+ret write fd tniwopa p n
369+end
370+fn niwout fd int src ulong size ulong to bool
371+p = ulong 0
372+for i ulong 100000
373+if eq p size
374+ret true
375+end
376+n = niwwrite fd src p sub size p
377+if gt n 0
378+p = add p ulong n
379+else
380+if ne n -4
381+ret false
382+end
383+end
384+end
385+ret false
386+end
387+fn niwput src ulong size ulong tail ulong to bool
388+fd = fopen fpth 0 get fpthl 0 557249 384
389+if lt fd 0
390+ret false
391+end
392+ok = niwout int fd src size
393+if and ok gt tail 0
394+ok = niwout int fd 0 tail
395+end
396+if ok
397+ok = eq fsync int fd 0
398+end
399+r = fclose int fd
400+if or not ok ne r 0
401+x = unlink fpth 0 get fpthl 0
402+ret false
403+end
404+ret true
405+end
406+note Read a whole file into fxo under the write lock. Distinguish missing from other I/O errors.
407+fn niwread cap ulong to long
408+fd = fopen fpth 0 get fpthl 0 559104 0
409+if lt fd 0
410+ret fd
411+end
412+n = niwreadfd int fd cap
413+r = fclose int fd
414+ret n
415+end
416+fn niwreadfd fd int cap ulong to long
417+p = ulong 0
418+for i ulong 100000
419+if gt p cap
420+ret -27
421+end
422+n = read fd fxo p sub add cap 1 p
423+if eq n 0
424+ret long p
425+end
426+if gt n 0
427+p = add p ulong n
428+else
429+if ne n -4
430+ret n
431+end
432+end
433+end
434+ret -5
435+end
436+fn niwremove file view uchar * stage bool to void
437+niwpath stage file
438+x = unlink fpth 0 get fpthl 0
439+end
440+fn niwdiscard stage bool to void
441+niwremove tnfttl stage
442+niwremove tnfdsc stage
443+niwremove tnfsts stage
444+niwremove tniwnat stage
445+niwpath stage tniwemp
446+x = rmdir fpth 0 get fpthl 0
447+end
448+note Use the authenticated DID and the form token as a stable issue ID across retries.
449+fn niwnewid to void
450+seed = new uchar 160 0
451+hash = new uchar 32 0
452+hex = new uchar 16 0
453+for i ulong 32
454+put seed i get gniwrq i
455+end
456+d = get gscur 0
457+o = get gsso d
458+n = get gssl d
459+for i ulong n bound 128
460+put seed add i 32 get gsstr add o i
461+end
462+x = sha2_digest 256 part seed 0 add 32 n hash
463+sohex part hash 0 8 hex
464+for i ulong 16
465+put gniwid i get hex i
466+end
467+end
468+fn niwreq to void
469+for i ulong 32
470+fputc get gniwrq i
471+end
472+end
473+fn niwmeta to void
474+put fobl 0 0
475+fput tniwdid
476+niwactor
477+fputc 10
478+fput tnghop
479+fjisob get gsnow 0
480+fputc 10
481+fput tniwrql
482+niwreq
483+fputc 10
484+end
485+fn niwactor to void
486+d = get gscur 0
487+o = get gsso d
488+for i ulong get gssl d bound 128
489+fputc get gsstr add o i
490+end
491+end
492+fn niwnewfiles to bool
493+niwpath true tnfttl
494+if not niwput 2 get gniwtl 0 0
495+ret false
496+end
497+niwpath true tnfdsc
498+if not niwput 3 get gcfvl 0 0
499+ret false
500+end
501+niwpath true tnfsts
502+if not niwput 4 len tniwopa 0
503+ret false
504+end
505+niwmeta
506+niwpath true tniwnat
507+ok = niwput 0 get fobl 0 0
508+put fobl 0 0
509+if not ok
510+ret false
511+end
512+ret niwsync true
513+end
514+fn niwsync stage bool to bool
515+niwpath stage tniwemp
516+ret niwsyncat
517+end
518+fn niwsyncat to bool
519+fd = fopen fpth 0 get fpthl 0 573440 0
520+if lt fd 0
521+ret false
522+end
523+r = fsync int fd
524+x = fclose int fd
525+ret eq r 0
526+end
527+note Publish the complete issue before replacing its index. After a crash between the renames the
528+note unindexed directory is unreachable. Retrying the same request repairs its index entry.
529+fn niwcreate to long
530+niwnewid
531+nipath
532+fpt tnindex
533+n = niwread len gnix
534+if eq n -2
535+n = 0
536+end
537+if eq n -27
538+ret 409
539+end
540+if or lt n 0 ne rem ulong n 17 0
541+ret 500
542+end
543+for j ulong div ulong n 17 bound NIROWS
544+p = mul j 17
545+if not niidok p
546+ret 500
547+end
548+if niwrow p
549+if niwexisting
550+ret -1
551+end
552+ret 409
553+end
554+end
555+if eq n long len gnix
556+ret 409
557+end
558+for i ulong 16
559+put fob i get gniwid i
560+end
561+put fob 16 10
562+nipath
563+fpt tniwist
564+x = unlink fpth 0 get fpthl 0
565+if not niwput 1 ulong n 17
566+ret 500
567+end
568+r = niwinst
569+if gt r 0
570+nipath
571+fpt tniwist
572+x = unlink fpth 0 get fpthl 0
573+end
574+ret r
575+end
576+fn niwrow p ulong to bool
577+for i ulong 16
578+if ne get fxo add p i get gniwid i
579+ret false
580+end
581+end
582+ret true
583+end
584+fn niwexisting to bool
585+niwpath false tniwnat
586+r = niwread 256
587+if le r 0
588+ret false
589+end
590+for i ulong ulong r bound 256
591+put gngh i get fxo i
592+end
593+put gnghl 0 ulong r
594+if not niwmetasame
595+ret false
596+end
597+ret niwsame
598+end
599+fn niwmetasame to bool
600+d = get gscur 0
601+o = get gsso d
602+a = nighv tniwdid
603+if ne get gnr 15 get gssl d
604+ret false
605+end
606+for i ulong get gssl d bound 128
607+if ne get gngh add a i get gsstr add o i
608+ret false
609+end
610+end
611+b = nighv tniwrql
612+if ne get gnr 15 32
613+ret false
614+end
615+for i ulong 32
616+if ne get gngh add b i get gniwrq i
617+ret false
618+end
619+end
620+ret true
621+end
622+fn niwsame to bool
623+niwpath false tnfttl
624+if ne niwread 256 long get gniwtl 0
625+ret false
626+end
627+for i ulong get gniwtl 0 bound 256
628+if ne get fxo i get gniwtt i
629+ret false
630+end
631+end
632+niwpath false tnfdsc
633+if ne niwread 16000 long get gcfvl 0
634+ret false
635+end
636+for i ulong get gcfvl 0 bound 16000
637+if ne get fxo i get gcfv i
638+ret false
639+end
640+end
641+ret true
642+end
643+fn niwinst to long
644+niwpath false tniwemp
645+r = stat fpth 0 get fpthl 0 fstb 0 128
646+if eq r -2
647+if not niwstage
648+ret 500
649+end
650+else
651+if lt r 0
652+ret 500
653+end
654+if not niwexisting
655+ret 409
656+end
657+end
658+nipath
659+if not niwsyncat
660+ret 500
661+end
662+soavb
663+nipath
664+fpt tniwist
665+niwarg
666+nipath
667+fpt tnindex
668+niwarg
669+if ne renames gspk 0 get gspkl 0 0 0
670+ret 500
671+end
672+nipath
673+if not niwsyncat
674+flog tniwfs
675+end
676+ret 0
677+end
678+fn niwstage to bool
679+note Discard remnants of an interrupted attempt of this same unindexed action.
680+niwdiscard true
681+niwpath true tniwemp
682+if ne makedir fpth 0 get fpthl 0 448 0
683+ret false
684+end
685+if not niwnewfiles
686+niwdiscard true
687+ret false
688+end
689+soavb
690+niwpath true tniwemp
691+niwarg
692+niwpath false tniwemp
693+niwarg
694+if ne renames gspk 0 get gspkl 0 1 0
695+niwdiscard true
696+ret false
697+end
698+ret true
699+end
700+fn niwrecord to void
701+put fobl 0 0
702+fput tniwncom
703+cosp
704+fjisob get gsnow 0
705+cosp
706+niwactor
707+cosp
708+niwreq
709+cosp
710+n = get gcfvl 0
711+fnum n
712+fputc 10
713+for i ulong n bound 16000
714+fputc get gcfv i
715+end
716+fputc 10
717+end
718+fn niwcomment to long
719+for i ulong 16
720+put gniwid i get gcrq i
721+end
722+r = niwindexed
723+if ne r 0
724+ret r
725+end
726+niwpath false tnfthr
727+n = niwread 1048576
728+if eq n -2
729+n = 0
730+end
731+if eq n -27
732+ret 409
733+end
734+if lt n 0
735+ret 500
736+end
737+r = niwthread ulong n
738+if ne r 0
739+ret r
740+end
741+niwrecord
742+if gt add ulong n get fobl 0 1048576
743+put fobl 0 0
744+ret 409
745+end
746+niwpath false tniwtht
747+x = unlink fpth 0 get fpthl 0
748+ok = niwput 1 ulong n get fobl 0
749+put fobl 0 0
750+if not ok
751+ret 500
752+end
753+soavb
754+niwarg
755+niwpath false tnfthr
756+niwarg
757+if ne renames gspk 0 get gspkl 0 0 0
758+niwremove tniwtht false
759+ret 500
760+end
761+if not niwsync false
762+flog tniwfs
763+end
764+ret 0
765+end
766+fn niwindexed to long
767+nipath
768+fpt tnindex
769+n = niwread len gnix
770+if eq n -2
771+ret 404
772+end
773+if or lt n 0 ne rem ulong n 17 0
774+ret 500
775+end
776+for j ulong div ulong n 17 bound NIROWS
777+p = mul j 17
778+if and niidok p niwrow p
779+ret 0
780+end
781+end
782+ret 404
783+end
784+note Check the whole prefix before replacing it. An already-published form returns its prior result.
785+fn niwthread n ulong to long
786+for i ulong n bound 1048576
787+put gnth i get fxo i
788+end
789+put gnthl 0 n
790+p = ulong 0
791+while lt p n bound 1048576
792+p = nirec p
793+k = get gnr 0
794+if eq k 0
795+ret 409
796+end
797+if eq k 4
798+if niwcomreq
799+if niwcombody
800+ret -1
801+end
802+ret 409
803+end
804+end
805+end
806+ret 0
807+end
808+fn niwcomreq to bool
809+d = get gscur 0
810+n = get gssl d
811+if or ne get gnr 4 n ne get gnr 6 32
812+ret false
813+end
814+a = get gnr 3
815+o = get gsso d
816+for i ulong n bound 128
817+if ne get gnth add a i get gsstr add o i
818+ret false
819+end
820+end
821+b = get gnr 5
822+for i ulong 32
823+if ne get gnth add b i get gniwrq i
824+ret false
825+end
826+end
827+ret true
828+end
829+fn niwcombody to bool
830+n = get gcfvl 0
831+if ne n get gnr 11
832+ret false
833+end
834+a = get gnr 10
835+for i ulong n bound 16000
836+if ne get gnth add a i get gcfv i
837+ret false
838+end
839+end
840+ret true
841+end

collab/tests/compose.sh

@@ -1,6 +1,7 @@
11 #!/bin/bash
22 # collab/tests/compose.sh: end-to-end HOST test of Phase A (docs/collab-write.md): the web composes and
3-# checks, the author runs the shown command, and the result shows on the forge. Everything is private
3+# checks and says publishing is closed (no command shown); the author runs commands this test writes,
4+# and the result shows on the forge. Everything is private
45 # to a temp dir: a throwaway Radicle profile (RAD_HOME) with a private repo, a test forged on PORT
56 # (default 18493) whose store and allow-list point at that profile, throwaway ssh keys for sign-in.
67 # Nothing touches ~/.radicle, the live forged or the network. Every gate has a negative control.
@@ -55,6 +56,9 @@ for m in re.findall(r'<pre class="so-cmd">(.*?)</pre>', open(sys.argv[1]).read()
5556 EOF
5657 }
5758 run_() { [ -n "$1" ] && (cd "$W" && sh -c "$1"); }
59+# The compose page shows no command: publishing is closed for now. The author's own commands below
60+# are written by this test (not read from the page) so the fixture repo still gets its COBs.
61+closed() { has 'Publishing it is closed for now: Interplane does not accept comments, reviews, issues or patches yet.' && [ -z "$(cmds)" ] && ok "$1: publishing closed, no command shown" || bad "$1: closed note missing or a command shown"; }
5862 dl() { curl -s -o "$2" -D "$T/hdr" -H "X-Forge-Base: $BASE" -H "$CK" "$U$1" -w '%{http_code}'; }
5963 cidof() { hdr location | sed -n 's|.*/compose/\([0-9a-f]\{32\}\)$|\1|p'; }
6064
@@ -88,7 +92,7 @@ CK="Cookie: $SES"
8892
8993 # ---- forms
9094 c=$(code GET "$R/issues/new"); check "$c" 200 "GET issues/new signed out"
91-has 'Sign in with your Radicle key' && ! has 'name="title"' && ok "NEG signed out: sign-in link, no form" || bad "signed-out new-issue page"
95+has 'Sign in with your key' && ! has 'name="title"' && ok "NEG signed out: sign-in link, no form" || bad "signed-out new-issue page"
9296 c=$(code GET "$R/issues/new" -H "$CK"); check "$c" 200 "GET issues/new signed in"
9397 has "action=\"$R/issues/new\"" && has 'name="title"' && has "value=\"$TOK\"" && ok "new-issue form with this session's CSRF token" || bad "new-issue form"
9498 c=$(code GET "$R/patches/new" -H "$CK"); has 'name="draft"' && ok "new-patch form has the draft box" || bad "new-patch form ($c)"
@@ -128,7 +132,7 @@ c=$(code GET "$R/compose/$CID" -H "$CK"); check "$c" 200 "compose page"
128132 has '<strong>bold</strong>' && ok "preview renders Markdown" || bad "preview markdown"
129133 ! has '<script>alert' && ! has 'href="javascript:' && ! has '<img src=x' && ok "NEG preview renders the XSS inert" || bad "preview XSS"
130134 has 'Crash on &quot;quotes&quot; &amp; $(id)' && ok "title escaped in preview" || bad "title escape"
131-CMD=$(cmds); check "$CMD" "rad issue open --repo rad:$RID --title=\"\$(head -n 1 issue.md)\" --description=\"\$(tail -n +3 issue.md)\"" "issue open command"
135+closed "new issue"; CMD="rad issue open --repo rad:$RID --title=\"\$(head -n 1 issue.md)\" --description=\"\$(tail -n +3 issue.md)\""
132136 c=$(dl "$R/compose/$CID/issue.md" "$W/issue.md"); check "$c" 200 "download issue.md"
133137 check "$(hdr content-type)" "text/markdown; charset=utf-8" "issue.md content type"
134138 check "$(hdr content-disposition)" 'attachment; filename="issue.md"' "issue.md is an attachment"
@@ -149,15 +153,15 @@ has "$ET" && ok "title reached rad unchanged (leading -, quotes, \$(...), backti
149153 c=$(code GET "$R/issues/$ISS"); check "$c" 200 "issue page"
150154 has '<strong>bold</strong>' && ok "issue body rendered as Markdown" || bad "issue body markdown"
151155 ! has '<script>alert' && ! has 'href="javascript:' && ! has '<img src=x' && ok "NEG published issue renders the XSS inert" || bad "published issue XSS"
152-has 'id="compose"' && has 'Sign in with your Radicle key' && ok "issue page: sign-in prompt when signed out" || bad "issue page prompt"
156+has 'id="compose"' && has 'Sign in with your key' && ok "issue page: sign-in prompt when signed out" || bad "issue page prompt"
153157
154158 # ---- comment on the issue
155159 c=$(code GET "$R/issues/$ISS" -H "$CK"); ISSF=$(grep -o "issues/[0-9a-f]\{40\}/compose" "$T/body" | head -1 | cut -d/ -f2)
156160 [ ${#ISSF} = 40 ] && has "value=\"$TOK\"" && ok "issue page has the comment form" || bad "issue comment form"
157161 c=$(code POST "$R/issues/$ISSF/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body= "); check "$c" 400 "NEG blank comment"
158162 c=$(code POST "$R/issues/${ISSF:0:8}/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body=First *comment* from the forge"); check "$c" 303 "POST issue comment (short id)"
159-CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; CMD=$(cmds)
160-check "$CMD" "rad issue comment $ISSF --repo rad:$RID --message=\"\$(cat comment.md)\"" "issue comment command"
163+CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "issue comment"
164+CMD="rad issue comment $ISSF --repo rad:$RID --message=\"\$(cat comment.md)\""
161165 dl "$R/compose/$CID/comment.md" "$W/comment.md" > /dev/null
162166 check "$(cat "$W/comment.md")" "First *comment* from the forge" "comment.md content"
163167 run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad issue comment" || bad "rad issue comment: $(cat "$T/out")"
@@ -168,9 +172,8 @@ IP=10.9.0.3
168172 git -C "$W" checkout -qb feat && echo more > "$W/b.txt" && git -C "$W" add b.txt && git -C "$W" commit -qm "add b"
169173 printf 'Line one of the description.\n\nLine three, `code`.\n' > "$T/pb"
170174 c=$(code POST "$R/patches/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=Add b.txt" --data-urlencode "body@$T/pb"); check "$c" 303 "POST patches/new"
171-CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; cmds > "$T/cmds"
172-check "$(sed -n 1p "$T/cmds")" 'git push -o patch.message="$(head -n 1 patch.md)" rad HEAD:refs/patches' "patch push command (multi-line: title only)"
173-check "$(sed -n 2p "$T/cmds")" "rad patch edit PATCH_ID --repo rad:$RID --message=\"\$(head -n 1 patch.md)\" --message=\"\$(tail -n +3 patch.md)\"" "patch edit command"
175+CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "new patch"
176+printf '%s\n' 'git push -o patch.message="$(head -n 1 patch.md)" rad HEAD:refs/patches' "rad patch edit PATCH_ID --repo rad:$RID --message=\"\$(head -n 1 patch.md)\" --message=\"\$(tail -n +3 patch.md)\"" > "$T/cmds"
174177 dl "$R/compose/$CID/patch.md" "$W/patch.md" > /dev/null
175178 run_ "$(sed -n 1p "$T/cmds")" > "$T/out" 2>&1 && ok "author ran: git push" || bad "git push: $(cat "$T/out")"
176179 PAT=$(grep -o '[0-9a-f]\{40\}' "$T/out" | head -1)
@@ -181,21 +184,21 @@ has 'Add b.txt' && has 'Line three, <code>code</code>.' && ok "patch title and M
181184 # single-line description and draft go into the push options
182185 c=$(code POST "$R/patches/new" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "title=T2" --data-urlencode "body=one line" --data-urlencode "draft=1")
183186 CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null
184-check "$(cmds)" 'git push -o patch.message="$(head -n 1 patch.md)" -o patch.message="$(tail -n +3 patch.md)" -o patch.draft rad HEAD:refs/patches' "draft single-line push command"
187+closed "draft patch"
185188 has 'New patch (draft)' && ok "draft named on the compose page" || bad "draft heading"
186189
187190 # ---- patch comment and reviews
188191 c=$(code GET "$R/patches/$PAT" -H "$CK"); REV=$(field rev)
189192 [ ${#REV} = 40 ] && has 'name="verdict" value="accept"' && ok "patch page has the review form (revision $REV)" || bad "patch form"
190193 c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "body=Looks *fine*"); check "$c" 303 "POST patch comment"
191-CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; CMD=$(cmds)
192-check "$CMD" "rad patch comment $REV --repo rad:$RID --message=\"\$(cat comment.md)\"" "patch comment command (on the revision)"
194+CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "patch comment"
195+CMD="rad patch comment $REV --repo rad:$RID --message=\"\$(cat comment.md)\""
193196 dl "$R/compose/$CID/comment.md" "$W/comment.md" > /dev/null
194197 run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad patch comment" || bad "rad patch comment: $(cat "$T/out")"
195198 c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "rev=$REV" --data-urlencode "verdict=accept" --data-urlencode "body=Ship **it**")
196199 check "$c" 303 "POST review accept"
197-CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; CMD=$(cmds)
198-check "$CMD" "rad patch review $PAT --repo rad:$RID --revision $REV --accept --message=\"\$(cat review.md)\"" "review command"
200+CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "review accept"
201+CMD="rad patch review $PAT --repo rad:$RID --revision $REV --accept --message=\"\$(cat review.md)\""
199202 dl "$R/compose/$CID/review.md" "$W/review.md" > /dev/null
200203 run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad patch review --accept" || bad "rad patch review: $(cat "$T/out")"
201204 c=$(code GET "$R/patches/$PAT"); has 'Looks <em>fine</em>' && ok "patch comment shows on the forge" || bad "patch comment missing"
@@ -203,11 +206,11 @@ has 'Ship <strong>it</strong>' && ok "review body shows on the forge" || bad "re
203206 c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "verdict=reject")
204207 check "$c" 303 "POST review reject without text"
205208 CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null
206-check "$(cmds)" "rad patch review $PAT --repo rad:$RID --revision $REV --reject --no-message" "reject command, no file"
209+closed "review reject without text"
207210 ! has 'download>' && ok "no download step without text" || bad "download step shown"
208211 c=$(code POST "$R/patches/$PAT/compose" -H "$CK" --data-urlencode "csrf=$TOK" --data-urlencode "verdict=review" --data-urlencode "body=Needs a test")
209-CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; CMD=$(cmds)
210-check "$CMD" "rad patch review $PAT --repo rad:$RID --revision $REV --message=\"\$(cat review.md)\"" "review without verdict command"
212+CID=$(cidof); code GET "$R/compose/$CID" -H "$CK" > /dev/null; closed "review without verdict"
213+CMD="rad patch review $PAT --repo rad:$RID --revision $REV --message=\"\$(cat review.md)\""
211214 dl "$R/compose/$CID/review.md" "$W/review.md" > /dev/null
212215 run_ "$CMD" > "$T/out" 2>&1 && ok "author ran: rad patch review (no verdict)" || bad "rad patch review (no verdict): $(cat "$T/out")"
213216 c=$(code GET "$R/patches/$PAT"); has 'Needs a test' && ok "review without verdict shown on the forge" || bad "no-verdict review missing ($c)"

collab/tests/native-issues-store.sh

new file mode 100755
@@ -0,0 +1,224 @@
1+#!/usr/bin/env bash
2+# Loopback check for the imported issue views in the signed-store build.
3+. patch/tests/lib.sh
4+set -e
5+trap 'printf "FAIL issue test at line %s, fixture %s\n" "$LINENO" "$T" >&2' ERR
6+trap 'set +e; stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
7+store="$T/data/issues/$OWNER/fixrepo"
8+for row in "0123456789abcdef open 3" "01234fedcba98765 closed 4"; do
9+ read -r id state number <<< "$row"
10+ mkdir -p "$store/$id"
11+ printf '%s\n' "$id" >> "$store/index"
12+ printf 'Fixture issue %s' "$number" > "$store/$id/title"
13+ printf 'Body with **Markdown** and a [relative link](README.md)\n' > "$store/$id/description"
14+ printf '%s\n' "$state" > "$store/$id/status"
15+ printf 'number %s\nlogin octo\nopened 2026-01-01T00:00:00Z\nclosed -\nreason -\n' "$number" > "$store/$id/gh"
16+ printf 'bug\n' > "$store/$id/labels"
17+ : > "$store/$id/thread"
18+ printf '{"kind":"github-import","owner":"fixo","repo":"fixrepo","number":%s,"url":"https://github.com/fixo/fixrepo/issues/%s"}\n' "$number" "$number" > "$store/$id/source.json"
19+done
20+start
21+test "$(code GET "$R/issues")" = 200
22+grep -q 'Fixture issue 3' "$T/body"
23+! grep -q 'Fixture issue 4' "$T/body"
24+echo 'PASS default issue list shows only open items'
25+test "$(code GET "$R/issues?state=all" -H 'Accept: application/json')" = 200
26+jq -e '.schema == "forge/issues/1" and (.issues | length == 2)' "$T/body" >/dev/null
27+echo 'PASS JSON issue list returns both states'
28+test "$(code GET "$R/issues/012345" -H 'Accept: application/json')" = 200
29+jq -e '.schema == "forge/issue/1" and .title == "Fixture issue 3" and .author == null and .imported.login == "octo" and .labels == ["bug"]' "$T/body" >/dev/null
30+echo 'PASS JSON detail resolves a unique prefix and preserves source attribution and labels'
31+test "$(code GET "$R/issues/01234fedcba98765")" = 200
32+grep -q 'Imported from GitHub' "$T/body"
33+grep -q '<strong>Markdown</strong>' "$T/body"
34+echo 'PASS HTML issue detail renders provenance and Markdown'
35+test "$(code GET "$R/issues/01234")" = 404
36+test "$(code GET "$R/issues/ffffffff")" = 404
37+test "$(code POST "$R/issues/0123456789abcdef/compose")" = 404
38+test "$(code GET "/$OWNER/unknown/issues")" = 404
39+echo 'PASS ambiguous or missing issues, the retired preview endpoint, and unknown repositories are refused'
40+test "$(code GET "$R/patches" -H 'Accept: application/json')" = 200
41+jq -e '.schema == "forge/patch-list/1"' "$T/body" >/dev/null
42+echo 'PASS patch and issue routes coexist in the same build'
43+
44+fixture="$store/0123456789abcdef"
45+printf 'comment 2026-01-01T00:00:00Z octo 4\nNote\ncomment 2026-01-01T00:00:00Z octo 9999999999999999999\n' > "$fixture/thread"
46+sed -i 's/^number .*/number invalid/' "$fixture/gh"
47+test "$(code GET "$R/issues/0123456789abcdef" -H 'Accept: application/json')" = 200
48+jq -e '.imported.number == 0 and (.comments | length == 2) and .comments[1].body == "Note"' "$T/body" >/dev/null
49+echo 'PASS invalid import numbers and overlong thread lengths preserve valid records and valid JSON'
50+printf 'opened 2026-01-01T<test>00Z\n' > "$fixture/gh"
51+test "$(code GET "$R/issues/0123456789abcdef")" = 200
52+! grep -Fq '<test>' "$T/body"
53+grep -Fq "&lt;test" "$T/body"
54+echo 'PASS imported time text is escaped in the issue page'
55+
56+test "$(code GET "$R/issues/new")" = 200
57+grep -q 'Sign in to open an issue' "$T/body"
58+test "$(code POST "$R/issues/new" --data 'title=Unsigned')" = 303
59+test "$(hdr location)" = /login
60+test "$(code POST "$R/issues/0123456789abcdef/comments" --data 'body=Unsigned')" = 303
61+test "$(wc -l < "$store/index")" = 2
62+echo 'PASS sign-in controls protect both write routes'
63+
64+newkey writer
65+signin writer 10.4.20.1
66+writer=$DID
67+issue_cookie="Cookie: __Host-forge_session=$SES"
68+test "$(code GET "$R/issues/new" -H "$issue_cookie")" = 200
69+test "$(field csrf)" = "$TOK"
70+request=$(field request)
71+test "${#request}" = 32
72+test "$(code POST "$R/issues/new" -H "$issue_cookie" --data-urlencode "request=$request" --data-urlencode 'title=Missing CSRF')" = 403
73+test "$(code POST "$R/issues/new" -H "$issue_cookie" -H 'Origin: https://elsewhere.example' --data-urlencode "csrf=$TOK" --data-urlencode "request=$request" --data-urlencode 'title=Foreign origin')" = 403
74+test "$(code POST "$R/issues/new" -H "$issue_cookie" --data-urlencode "csrf=$TOK" --data-urlencode "request=$request" --data-urlencode $'title=first\nsecond')" = 400
75+test "$(code POST "$R/issues/new" -H "$issue_cookie" --data-urlencode "csrf=$TOK" --data-urlencode "request=$request" --data-urlencode 'title=Oversized' --data-urlencode "body=$(head -c 16001 /dev/zero | tr '\0' a)")" = 400
76+test "$(wc -l < "$store/index")" = 2
77+echo 'PASS missing CSRF, foreign origin, multiline title and oversized body refuse writes'
78+
79+openissue() {
80+ code POST "$R/issues/new" -H "$issue_cookie" --data-urlencode "csrf=$TOK" \
81+ --data-urlencode "request=$request" --data-urlencode "title=$1" --data-urlencode $'body=This is **native**.\n\n<script>alert(1)</script>\n\n[Unsafe](javascript:alert(1))'
82+}
83+test "$(openissue 'Native issue <proof>')" = 303
84+issue=$(hdr location)
85+id=${issue##*/}
86+test "${#id}" = 16
87+test "$(openissue 'Native issue <proof>')" = 303
88+test "$(hdr location)" = "$issue"
89+test "$(openissue 'Changed title')" = 409
90+test "$(wc -l < "$store/index")" = 3
91+test "$(code GET "$issue" -H "$issue_cookie")" = 200
92+grep -q 'Native issue &lt;proof&gt;' "$T/body"
93+grep -q '<strong>native</strong>' "$T/body"
94+if grep -qE '<script>|href="javascript:' "$T/body"; then false; fi
95+grep -q 'Post comment' "$T/body"
96+test "$(hdr x-accel-expires)" = 0
97+test "$(code GET "$R/issues" -H 'Accept: application/json')" = 200
98+jq -e --arg did "$writer" --arg id "$id" --arg new "$R/issues/new" '
99+ .new == $new and any(.issues[]; .id == $id and .author.did == $did and .imported == null)
100+' "$T/body" >/dev/null
101+echo 'PASS issue creation, stable retries, conflicting retry, HTML and native list attribution'
102+
103+# Simulate the crash window after the issue directory is published but before its index is replaced.
104+sed -i "/^$id$/d" "$store/index"
105+test "$(code GET "$issue")" = 404
106+test "$(openissue 'Native issue <proof>')" = 303
107+test "$(hdr location)" = "$issue"
108+test "$(grep -c "^$id$" "$store/index")" = 1
109+flock -x "$store/.write.lock" -c 'echo held; read -r _' < <(sleep 2) > "$T/lock" &
110+holder=$!
111+for _ in $(seq 100); do [ -s "$T/lock" ] && break; sleep .01; done
112+test "$(cat "$T/lock")" = held
113+test "$(openissue 'Native issue <proof>')" = 503
114+test "$(hdr retry-after)" = 1
115+wait "$holder" || :
116+test "$(openissue 'Native issue <proof>')" = 303
117+echo 'PASS an interrupted creation is recovered and a competing writer can retry when the lock clears'
118+
119+newkey commenter
120+signin commenter 10.4.20.2
121+commenter=$DID
122+issue_cookie="Cookie: __Host-forge_session=$SES"
123+test "$(code GET "$issue" -H "$issue_cookie")" = 200
124+request=$(field request)
125+test "${#request}" = 32
126+comment() {
127+ code POST "$1/comments" -H "$issue_cookie" --data-urlencode "csrf=$TOK" \
128+ --data-urlencode "request=$request" --data-urlencode "body=$2" --data-urlencode 'author=forged'
129+}
130+test "$(comment "$issue" ' ')" = 400
131+test "$(comment "$R/issues/${id:0:8}" 'Prefix')" = 404
132+test "$(comment "$R/issues/ffffffffffffffff" 'Missing')" = 404
133+test "$(comment "$issue" 'Posted **directly** via Interplane.')" = 303
134+test "$(hdr location)" = "$issue"
135+test "$(comment "$issue" 'Posted **directly** via Interplane.')" = 303
136+test "$(comment "$issue" 'Conflicting retry')" = 409
137+test "$(code GET "$issue" -H 'Accept: application/json')" = 200
138+jq -e --arg writer "$writer" --arg commenter "$commenter" '
139+ .author.did == $writer and .imported == null and (.comments | length == 2)
140+ and .comments[0].author.did == $writer and .comments[1].author.did == $commenter
141+ and .comments[1].body == "Posted **directly** via Interplane."
142+' "$T/body" >/dev/null
143+echo 'PASS comment writes preserve both authors and deduplicate retries'
144+
145+old="$R/issues/0123456789abcdef"
146+printf 'number 3\nlogin octo\nopened 2026-01-01T00:00:00Z\nclosed -\nreason -\n' > "$fixture/gh"
147+test "$(comment "$old" 'This must not disappear after a corrupt record.')" = 409
148+printf 'comment 2026-01-01T00:00:00Z octo 4\nNote\n' > "$fixture/thread"
149+test "$(comment "$old" 'Native reply to an imported issue.')" = 303
150+test "$(code GET "$old" -H 'Accept: application/json')" = 200
151+jq -e --arg did "$commenter" '
152+ .imported.login == "octo" and .author == null and .comments[1].author == null
153+ and .comments[1].login == "octo" and .comments[2].author.did == $did
154+' "$T/body" >/dev/null
155+echo 'PASS imported authorship survives native comments and corrupt threads refuse edits'
156+
157+mkdir "$store/$id/.thread.tmp"
158+request=0123456789abcdef0123456789abcdef
159+test "$(comment "$issue" 'Should not publish.')" = 500
160+rmdir "$store/$id/.thread.tmp"
161+test "$(code GET "$issue" -H 'Accept: application/json')" = 200
162+jq -e '(.comments | length) == 2' "$T/body" >/dev/null
163+test "$(comment "$issue" 'Successful retry after I/O error.')" = 303
164+stop || :
165+start
166+test "$(code GET "$issue" -H 'Accept: application/json')" = 200
167+jq -e '.comments[2].body == "Successful retry after I/O error."' "$T/body" >/dev/null
168+echo 'PASS failed replacement leaves the thread intact and a successful retry survives restart'
169+
170+# A full first page must keep the newest item visible and preserve a path to older imports.
171+for u in $(seq 1 30); do
172+ other=$(printf '12345678%08x' "$u")
173+ mkdir "$store/$other"
174+ printf 'open\n' > "$store/$other/status"
175+ printf '%s\n' "$other" >> "$store/index"
176+done
177+test "$(code GET "$R/issues?state=all&page=1" -H 'Accept: application/json')" = 200
178+jq -e '.page == 1 and (.issues | length == 30) and .next != null and .prev == null' "$T/body" >/dev/null
179+test "$(code GET "$R/issues?state=all&page=2" -H 'Accept: application/json')" = 200
180+jq -e --arg id "$id" '.page == 2 and .prev != null and .next == null and any(.issues[]; .id == $id)' "$T/body" >/dev/null
181+echo 'PASS issue list pagination bounds thread reads and older records stay reachable'
182+
183+test "$(code GET "$R/issues?state=all" -H 'Accept: application/json')" = 200
184+jq -e '.page == null and (.issues | length == 33) and .issues[0].id == "0123456789abcdef"' "$T/body" >/dev/null
185+test "$(curl -sI -o /dev/null -w '%{http_code}' "$B$issue")" = 200
186+echo 'PASS unpaged JSON retains prior index order and HEAD still serves the issue'
187+
188+json=(-H 'Accept: application/json')
189+test "$(code GET "$R/issues/new" "${json[@]}")" = 303
190+test "$(code GET "$issue/comments" "${json[@]}")" = 303
191+newkey agent
192+signin agent 10.4.20.3
193+issue_cookie="Cookie: __Host-forge_session=$SES"
194+test "$(code GET "$R/issues/new" "${json[@]}" -H "$issue_cookie")" = 200
195+jq -e --arg route "$R/issues/new" '.schema == "forge/issue-form/1" and .action == $route' "$T/body" >/dev/null
196+test "$(hdr x-accel-expires)" = 0
197+request=$(jq -r .request "$T/body")
198+test "$(jq -r .csrf "$T/body")" = "$TOK"
199+agentopen() {
200+ code POST "$R/issues/new" "${json[@]}" -H "$issue_cookie" -H "X-Real-IP: $IP" --data-urlencode "csrf=$TOK" \
201+ --data-urlencode "request=$request" --data-urlencode 'title=Issue from the JSON form'
202+}
203+test "$(agentopen)" = 201
204+issue=$(jq -er 'select(.schema == "forge/issue-write/1" and .applied == true).path' "$T/body")
205+test "$(agentopen)" = 200
206+jq -e --arg path "$issue" '.path == $path and .applied == false' "$T/body" >/dev/null
207+test "$(code GET "$issue/comments" "${json[@]}" -H "$issue_cookie")" = 200
208+jq -e --arg route "$issue/comments" '.schema == "forge/issue-form/1" and .action == $route' "$T/body" >/dev/null
209+request=$(jq -r .request "$T/body")
210+agentcomment() {
211+ code POST "$issue/comments" "${json[@]}" -H "$issue_cookie" -H "X-Real-IP: $IP" --data-urlencode "csrf=$1" \
212+ --data-urlencode "request=$request" --data-urlencode 'body=Comment from the JSON form'
213+}
214+test "$(agentcomment wrong)" = 403
215+jq -e '.schema == "forge/error/1" and .status == 403' "$T/body" >/dev/null
216+test "$(agentcomment "$TOK")" = 201
217+jq -e --arg path "$issue" '.path == $path and .applied == true' "$T/body" >/dev/null
218+test "$(agentcomment "$TOK")" = 200
219+jq -e '.applied == false' "$T/body" >/dev/null
220+test "$(code GET "$issue" "${json[@]}")" = 200
221+jq -e '(.comments | length) == 2 and .comments[1].body == "Comment from the JSON form"' "$T/body" >/dev/null
222+test "$(code GET /agents.json)" = 200
223+jq -e '[.routes[] | select((.schema == "forge/issue-form/1" and .method == "GET" or .schema == "forge/issue-write/1" and .method == "POST") and .auth == "session")] | length == 4' "$T/body" >/dev/null
224+echo 'PASS agents can fetch both forms, post, get a JSON result, and replay without parsing HTML'

community/30page.om

@@ -45,7 +45,7 @@ text cmrule "Each runner is a key. One computer can hold several runners, and In
4545 text cmpartsh "Published parts and their reruns"
4646 text cmnopart "No part is published in the salvage yard yet."
4747 text cmdevh "For developers"
48-text cmdev "The protocol, the runner's source and its gates are in spark-connector, <code>rad:z2LKDxnAK3EFfqgr7HTZh6djts65P</code>. Every accepted message and every refusal is kept:"
48+text cmdev "The protocol, the runner's source and its gates are in the spark-connector repository. Every accepted message and every refusal is kept:"
4949 text cmled "community/ledger\">ledger</a> &#183; <a href=\""
5050 text cmrefl "community/refused\">refusals</a> &#183; <a href=\""
5151 text cmsums "community/dl/SHA256SUMS\">SHA256SUMS</a></p>"

dl/dl.om

@@ -11,7 +11,8 @@ note (5368709120 bytes), one file at most 512 MiB (536870912); eviction is least
1111 note ctime (a cache hit chmods the file, which sets its ctime). Release assets (files in the tag's
1212 note release-assets/ dir) are cached as <blob>.blob the same way. Every cached file gets a sidecar
1313 note <file>.sha256 (64 hex) computed in Omega by om/tls/sha2.om.
14-note dlclone appends the clone panel (rad clone, git over HTTPS, archive links) for the repo header.
14+note dlclone (dl/dlclone.om) appends the clone panel (no public Git URL yet, archive links) for the
15+note repo header; the store-reading build composes store/clone.om in its place (run.sh units).
1516 global gdp uchar 4096
1617 global gdpl ulong 1
1718 global gdf uchar 4096
@@ -173,14 +174,6 @@ text tdpgn "<a href=\"?page="
173174 text tdpgnew "\">Newer</a> "
174175 text tdpgold "\">Older</a>"
175176 text tdnavx "</nav>\n"
176-text tdcl1 "<div class=\"clone\"><h3>Get this repository</h3><dl><dt>Radicle</dt><dd><code>rad clone rad:"
177-text tdcl2 "</code></dd><dt>Git over HTTPS</dt><dd><code>git clone https://www.aienos.com/rad/"
178-text tdcl3 ".git</code></dd><dt>Source archive of "
179-text tdcl4 "</dt><dd><a href=\""
180-text tdcl5 ".zip\">zip</a> &middot; <a href=\""
181-text tdcl6 ".tar.gz\">tar.gz</a></dd></dl></div>\n"
182-text tdcl7 "<p class=\"meta\">One command for agents: <code>forge-contribute "
183-text tdcl8 " DIR BRANCH TITLE CMD SUB AGENT REPO FILE BODY DATA HOME</code> clones, branches, commits, opens a Radicle patch with an evidence receipt (exact commit, command, exit status, output sha256) and requests review. Arguments and exit codes: docs/ANNOYANCES.md in interplane-forge.</p>\n"
184177 note ---- byte classes and hex
185178 fn dlhx v uchar to uchar
186179 if lt v 10
@@ -526,7 +519,7 @@ ret 0
526519 end
527520 note dlkarch: argv git archive --format=zip|tar.gz --prefix=<gdpre>/ <gdsha>
528521 fn dlkarch to void
529-fkgit
522+fksource
530523 fka tdarcw
531524 if eq get gdfmt 0 1
532525 fka tdfzip
@@ -543,7 +536,7 @@ dlksha
543536 end
544537 note dlkblob: argv git cat-file blob <gdsha>
545538 fn dlkblob to void
546-fkgit
539+fksource
547540 fka tdcatf
548541 fka tdeblob
549542 dlksha
@@ -823,7 +816,7 @@ end
823816 note dlrevp: rev-parse one candidate for gdref: 0 as given, 1 refs/heads/, 2 delegate heads,
824817 note 3 refs/tags/, 4 delegate tags; the commit sha into gdsha
825818 fn dlrevp mode ulong to bool
826-fkgit
819+fksource
827820 fka tdrevp
828821 fka tdverif
829822 fka tdquiet
@@ -858,7 +851,7 @@ note dlrch0 / dlrch1: reachability from a canonical head or tag (root or delegat
858851 note dlrch0 starts the for-each-ref --contains argv, the caller adds one commit id, dlrch1 adds the
859852 note ref patterns and runs it; shared with browse (brreach)
860853 fn dlrch0 to void
861-fkgit
854+fksource
862855 fka tdfer
863856 fka tdcnt1
864857 fka tdfmtx
@@ -1095,7 +1088,7 @@ end
10951088 note dlpts: the first canonical head (else tag) that points at gdsha, peeled, into gdkind / gdref
10961089 note (refname order puts refs/heads and refs/namespaces/<nid>/refs/heads before any tag)
10971090 fn dlpts to bool
1098-fkgit
1091+fksource
10991092 fka tdfer
11001093 fka tdcnt1
11011094 fka tdfmtr
@@ -1187,7 +1180,7 @@ note ---- tags (releases)
11871180 note dltags: the whole tag list (no --count: an older tag is a release like the newest) into gdtl,
11881181 note records split, short names, dedup and validity into gdkeep
11891182 fn dltags to bool
1190-fkgit
1183+fksource
11911184 fka tdfer
11921185 fka tdsortd
11931186 fka tdtfmt
@@ -1534,7 +1527,7 @@ fn dlmsg r ulong to bool
15341527 put gdmsn 0 0
15351528 put gdmbn 0 0
15361529 dlfld r 0
1537-fkgit
1530+fksource
15381531 fka tdfer
15391532 fka tdcnt1
15401533 fka tdmfmt
@@ -1632,7 +1625,7 @@ note call), and the count of entries not offered in gdaskip
16321625 fn dllsa to void
16331626 put gdan 0 0
16341627 put gdaskip 0 0
1635-fkgit
1628+fksource
16361629 fka tdlstr
16371630 fka tdlopt
16381631 fka tdzopt
@@ -2084,7 +2077,7 @@ note storage root, then the delegate namespace), so /releases lists a release. O
20842077 note --count=1: the project page's "Get it" button (server/pages.om fpjget) reads only this, never the
20852078 note whole tag list (a list too long for gdtl is the whole 500 of dltags; the button must not be).
20862079 fn dlanytag to bool
2087-fkgit
2080+fksource
20882081 fka tdfer
20892082 fka tdcnt1
20902083 fka tdfmtx
@@ -2113,32 +2106,6 @@ put gdref i get tdmain i
21132106 end
21142107 put gdrefl 0 len tdmain
21152108 end
2116-fn dlputrid to void
2117-for i ulong get fridl 0
2118-fescc get frid i
2119-end
2120-end
2121-fn dlclone to void
2122-dldefbr
2123-fput tdcl1
2124-dlputrid
2125-fput tdcl2
2126-dlputrid
2127-fput tdcl3
2128-dlescref
2129-fput tdcl4
2130-dlrepol
2131-fput tdarhh
2132-dlescref
2133-fput tdcl5
2134-dlrepol
2135-fput tdarhh
2136-dlescref
2137-fput tdcl6
2138-fput tdcl7
2139-dlputrid
2140-fput tdcl8
2141-end
21422109 note ---- dispatch
21432110 fn dlroute to long
21442111 if ge get fridx 0 get fan 0

dl/dlclone.om

new file mode 100644
@@ -0,0 +1,31 @@
1+note dl/dlclone.om: the clone panel of the default build (texts tdcl*, fns dlputrid, dlclone): no public Git URL
2+note yet, the archive links; moved out of dl/dl.om so that the store-reading build can compose store/clone.om in its
3+note place (run.sh units). It reads dl.om's helpers and texts, so it is composed after dl/dl.om.
4+text tdcl1 "<div class=\"clone\"><h3>Get this repository</h3><p class=\"meta\">No public Git URL yet: Interplane does not serve Git clones yet.</p><dl><dt>Source archive of "
5+text tdcl4 "</dt><dd><a href=\""
6+text tdcl5 ".zip\">zip</a> &middot; <a href=\""
7+text tdcl6 ".tar.gz\">tar.gz</a></dd></dl></div>\n"
8+text tdcl7 "<p class=\"meta\">For agents: <code>forge-contribute "
9+text tdcl8 " DIR BRANCH TITLE CMD SUB AGENT REPO FILE BODY DATA HOME</code> clones, branches, commits and opens a patch with an evidence receipt (exact commit, command, exit status, output sha256). It is closed for now: Interplane does not serve Git clones or accept pushes yet. Arguments and exit codes: docs/ANNOYANCES.md in interplane-forge.</p>\n"
10+fn dlputrid to void
11+for i ulong get fridl 0
12+fescc get frid i
13+end
14+end
15+fn dlclone to void
16+dldefbr
17+fput tdcl1
18+dlescref
19+fput tdcl4
20+dlrepol
21+fput tdarhh
22+dlescref
23+fput tdcl5
24+dlrepol
25+fput tdarhh
26+dlescref
27+fput tdcl6
28+fput tdcl7
29+dlputrid
30+fput tdcl8
31+end

dl/tests/check.sh

@@ -11,7 +11,9 @@ W=$(cd "$(dirname "$0")/../.." && pwd)
1111 O=${OMEGA_MV:-$HOME/work/flux/omega-mv}
1212 T=/tmp/forge-dltest
1313 EV=$W/dl/evidence
14-STORE=$HOME/.radicle/storage/
14+# the storage of the cuda-crack checks: FORGE_TEST_RSTORE (default the read-only frozen copy kept after
15+# the Radicle removal of 2026-11-14; ~/.radicle no longer exists)
16+STORE=${FORGE_TEST_RSTORE:-$HOME/radicle-storage-frozen/storage}/
1517 CC=z631r2JJiVT8it4tST7RK24hpowi
1618 NID=z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK
1719 FXR=zDLfixture1
@@ -290,8 +292,10 @@ chk "$(fld $R FILE)" "" "NEG: dlblobf refuses a non-hex id (no file)"
290292 req fx-blobf-short "$F" BLOBF "/drakestapleton/dlfix/abc" / - -
291293 chk "$(fld $R FILE)" "" "NEG: dlblobf refuses a short id"
292294 req cc-clone "$STORE" CLONE /drakestapleton/cuda-crack /forge/ - -
293-has "$R" "rad clone rad:$CC" "clone panel: rad clone"
294-has "$R" "https://www.aienos.com/rad/$CC.git" "clone panel: git over HTTPS"
295+has "$R" "No public Git URL yet: Interplane does not serve Git clones yet." "clone panel: no public Git URL yet"
296+hasnt "$R" "rad" "NEG: clone panel has no rad command or rad: id"
297+hasnt "$R" "Radicle" "NEG: clone panel has no Radicle wording"
298+hasnt "$R" "git clone" "NEG: clone panel offers no git clone URL"
295299 has "$R" 'href="/forge/drakestapleton/cuda-crack/archive/refs/heads/main.zip"' "clone panel: zip link"
296300
297301 # ---------- LRU eviction (cap 5 GiB = 5368709120 bytes) ----------

dl/tests/fstub.om

@@ -281,6 +281,9 @@ for i ulong len t
281281 fkc get t i
282282 end
283283 end
284+fn fksource to void
285+fkgit
286+end
284287 fn fkgit to void
285288 fkb
286289 fka tfgit

docs/AGENT-DOOR.md

new file mode 100644
@@ -0,0 +1,164 @@
1+# The agent door: agents.json, the event stream, the feed
2+
3+Owner: AgentDoor (2026-11-14). Code: `server/agents.om` and `server/agents.tsv` (the address list),
4+`door/` (the stream and the feed; names `ev*`, globals `gev*`, texts `tev*`), `server/nodoor.om` (the
5+seam). Schemas: `interplane/agents/1` and `interplane/events/1` in `docs/API.md`. Gate:
6+`server/tests/agentdoor.sh` (with `server/tests/agentdoor.py`). Status: HOST_TESTED, not deployed.
7+
8+Read-only. Nothing here writes to Radicle, git or the social log, and nothing changes sign-in.
9+
10+## The three addresses
11+
12+| Address | What it is |
13+|---|---|
14+| `<base>agents.json` | The document an agent reads first: every machine-readable address the forge answers, as a path template, with how to ask for JSON (`.json` name, `Accept` header, or always), the schema it answers, whether it needs a browser session, and one line of purpose. Also the plain-text form (`format=text`), the error schema `forge/error/1`, the event stream, and a `not_available` list (writes over HTTP without a browser session, an MCP server, git over this HTTP server, webhooks, an HTML `/agents` page) so agents stop guessing. |
15+| `<base>events.json?after=<seq>&limit=<n>` | The public activity of the forge as one append-only stream, oldest first. Also `<base>events` and `<base>feed` with `Accept: application/json`; `<base>events` without it redirects to the feed. `after` is exclusive; `limit` is 50 by default and 200 at most (a larger one is answered with 200 and `limited: true`); `next` is the address to read next. An `ETag` lets a poller send `If-None-Match` and get `304` while nothing changed. |
16+| `<base>feed` | The same stream for people: newest first, 50 a page, older pages with `?before=<seq>`, one plain sentence each ("fixdev proposed a change to hop: <title>", "hop: 3 new commits on main", "someone starred omega-mv"), each naming who did it with a link to their page and linking the thing. `?format=text` is its plain-text form; its `<link rel="alternate" type="application/json">` is `<base>events.json`; "Feed" is in the forge row of every page. |
17+
18+`/agents` is not claimed: interplane.io serves the static `/agents/` page of the site first (nginx
19+`try_files $uri $uri/ @forged`), so only `agents.json` is the forge's.
20+
21+## The list cannot drift
22+
23+`server/agents.tsv` is the one table (method, path template, how to ask for JSON, schema, auth, doc,
24+purpose; rows whose first field is `none` are the `not_available` list). `./run.sh units` (every build)
25+compiles it into `.build/agents.om` as one text, refusing a byte that is not printable ASCII or tab, a
26+quote or a backslash. `server/tests/agentdoor.sh` fetches every row under both bases with the template
27+filled from its fixture and checks the schema the address answers, checks that every `## ` schema
28+heading of `docs/API.md` is a row and that every row's schema is written in the file its `doc` column
29+names; a row with a wrong schema makes it fail (negative control `broken-row`).
30+
31+## Kinds
32+
33+Only from records that exist, each with the object it was read from as `source`:
34+
35+| Kind | Read from | `source` | `time` |
36+|---|---|---|---|
37+| `patch_opened`, `issue_opened` | the COB (collab `coload`) | the COB id | the root change's author time |
38+| `patch_revised` | a revision after the first | the change commit | its author time |
39+| `patch_merged` | a merge action | the change commit | its author time |
40+| `patch_archived`, `issue_closed` | the lifecycle action in force (`gclfc`) | the change commit | its author time |
41+| `review` (`verdict` accept or reject) | a review action | the change commit | its author time |
42+| `comment` | a patch or issue comment (not the issue's opening text, not a redacted one) | the change commit | its author time |
43+| `release` | a tag, at the storage root or in the delegate's namespace | the tag object (or the commit of a light tag) | the tag date |
44+| `branch_moved` (`from`, `commits`) | the default branch moving from one head to another | the new head | its committer date |
45+| `star` | a `star` line of the social log, of a public repository | `social.log:<seq>` | the line's `ts` |
46+| `follow` (`target`) | a `follow` line of the social log | `social.log:<seq>` | the line's `ts` |
47+| `open_brought`, `open_withdrawn` | a `held`/`stored` or `withdrawn` row of `<data>open/list.tsv` | `open/list.tsv:<rid>@<day>` | the row's day, 00:00 UTC (the list keeps the day only) |
48+
49+One event per kind and change: two comments in one change are one event. Several states between two
50+reads of a COB are seen as the last one (an archive undone before the next read is not an event).
51+
52+Never an event: favorites (private), unstar, watch, unwatch, unfollow, account, name, session and logout
53+lines; anything about a repository that is not on the public allow-list (a private one, a name or RID
54+refused by `server/repos.om` fdeny); the refused RIDs on the open shelf. An event whose repository
55+leaves the allow-list later is no longer shown (its `seq` stays used).
56+
57+## Storage
58+
59+`<data>events/log`, one line an event, tab-separated: seq, time, kind, actor, rid, source, path, json,
60+x, subject, prev, where prev is the hex sha256 of the previous line (64 zeros for line 1), the same
61+chain as `social.log`. It is read and checked once after a start; a line that does not check switches
62+the stream off (`503`, `EVENTS-LOG TAMPER` on stderr) and nothing is appended to it. `seq` is the line
63+number, so it is stable across restarts and never reused. `<data>events/r/<rid>` is the last ref list
64+read of each repository (written to `.tmp`, then renamed). An event is appended once: its key (kind,
65+rid, source, x) is checked against every line already in the log. Account names are not stored: the
66+stream shows the name an account has when it is read.
67+
68+## The trigger: change-triggered, never a clock, never a full rescan per request
69+
70+forged serves one request at a time, so collection runs inside the request that needs it: before
71+`events.json`, `events` or `feed` is answered, `evcollect` compares cheap fingerprints with the ones of
72+the last pass and reads only what moved:
73+
74+- the social log: its size (stat). New bytes are read from where the last pass stopped, with the social
75+ slice's own line parser.
76+- the open shelf: the change time and size of `<data>open/list.tsv`.
77+- each public repository: the change times of `refs/heads`, `refs/tags`, `packed-refs`,
78+ `refs/namespaces`, `refs/rad` and every `refs/namespaces/<node>/refs/rad` folder (Radicle renames a
79+ new `sigrefs` into the node's `refs/rad` at every ref update of that node, COB changes included; git
80+ renames into `refs/heads` and `refs/tags`). When they moved: one `git for-each-ref` of the default
81+ branch, the tags and the patch and issue COB refs, compared line by line with the last list; only the
82+ COBs whose tip moved are loaded.
83+
84+Why this trigger: the sources are files that change only when someone acts; a stat of each is cheap
85+and needs no other process. A timer would run when nobody reads; a rescan per request would load every
86+COB of every repository each time; a hook in the node or the social writer would put this slice inside
87+code it does not own (the social log is written by forged itself, but the Radicle storage is written by
88+the node and `git push`). Nothing runs when nobody reads the stream; the first read after a change pays
89+for that change only. A start reads every repository's ref list once (fingerprints live in memory) and
90+appends nothing new.
91+
92+## Store-reading build
93+
94+The store-reading build (`FORGE_STORE`, interplane-native DESIGN.md step 2) serves every public line
95+of the store's `catalog.tsv` less the deny list (there is no separate served list since 2026-11-14)
96+and composes `door/` with `store/evcol.om` in place of `door/ev3col.om` (which reads Radicle refs and
97+COBs); it needs `social/` only. Its collector reads the store: per served project, its own catalog
98+line (id, branch, head), and the change times and sizes of `repo.git/refs/heads`,
99+`repo.git/refs/tags`, `repo.git/packed-refs` and `chain.tsv`; a moved project gets one
100+`git for-each-ref` of its default branch and its tags, compared with its snapshot. The catalog file's
101+own stat is not in any fingerprint: `ipl` rewrites `catalog.tsv` on every landing, and with it in
102+every fingerprint each landing made the next request read every served project. A landing changes
103+its project's line (head) and refs, so it costs that one project's read; a project added, removed or
104+replaced, or rows moved by a reload, give the row another key or id, so it is read; a catalog
105+rewritten with the same lines reads nothing. Kinds: `branch_moved` (old and new head, commit count;
106+source `chain.tsv:<N>`, the LAND or IMPORT record of that branch whose payload says `new <head>`, and
107+its time, or `repo.git:<sha>` and the commit time when no record names the move), `release` (a tag
108+created or moved, source `repo.git:<sha>`), `star` and `follow` (`social.log:<seq>`). The patch, issue
109+and open-shelf kinds never occur: their slices are seams in this build, and `agents.json` lists their
110+addresses under `not_available` (generated from the build's units, `run.sh agentsgen`). The feed's
111+first lines name only these kinds. Gate: `store/tests/agentdoor-store.sh` (two served projects: a
112+landing reads one source; the same catalog rewritten reads none; an added project is read once).
113+
114+The parts this build composes out while they move to the new Interplane store (the Salvage Yard,
115+Community Machines, Open builds, trending) answer `503` with no `Retry-After` and the text "This part
116+is moving to the new Interplane store and is not available yet." (`forge/error/1` with
117+`"reason":"moving"` to a JSON request; docs/API.md "Parts moving to the new Interplane store" lists
118+the addresses). `agents.json` names them under `not_available`: their rows (`open.json`,
119+`open/{project}.json`, `open/alarms.json`, `trending.json`) say "moving to the new Interplane store"
120+and that the address answers 503, and two rows `salvage/` and `community/` name those parts, which
121+have no machine-readable row of their own. The growth rows that are not moving addresses
122+(`explore?order=`, `insights`) say they answer 404 or without their schema.
123+
124+A build that composes neither (no `social/`, or the Radicle build without `collab/`) gets the seam
125+`server/nodoor.om`: `events.json`, `events` and `feed` answer `501` (`forge/error/1` for `events.json`),
126+the forge row has no Feed entry, and `agents.json` moves those three addresses to `not_available`.
127+Chosen over an empty stream because an empty stream would say "nothing happened" when the truth is
128+"not built here".
129+
130+## Measured costs
131+
132+MEASURED on the Spark, 2026-11-14 15:03Z, build of `a37cb7bc` (pinned omc `3ad9f10f...3194`), cores
133+16-18 at nice 10 while the machine carried other lanes (load about 17), by `server/tests/agentdoor.sh`
134+(log sha256 `7466ed88ad31621021b830b7c2a42846bf0d07f4e80121ab86598ddc45327ffe`, in
135+`~/work/hive/agent-door/ev-a37cb7b/logs/agentdoor.log`). Client: `curl` `time_total`, one request at a
136+time. Pass times are forged's own stderr line (`events: pass <us> us, sources read <n>, events added <n>`).
137+The ranges below are the smallest and largest sample; no other statistic was computed.
138+
139+| What | Data | Measured |
140+|---|---|---|
141+| `events.json?limit=200`, nothing changed (fingerprints only, no pass) | fixture, 19 events | 20 requests: 0.362 ms to 3.053 ms |
142+| `events.json?limit=200`, nothing changed | live-sized: the 50 public repositories of the real storage and allow-list (read-only), copies of the real social log and open list; 1,318 events | 20 requests: 2.654 ms to 5.316 ms |
143+| `feed`, nothing changed | live-sized | 5 requests: 1.943 ms to 17.737 ms |
144+| first pass (backfill: every source read, every changed COB loaded) | fixture: 3 sources, 17 events | 67.5 ms |
145+| one repository changed (main moved by 2 commits) | fixture | 23.2 ms, 1 source read, 1 event |
146+| one COB changed (an issue comment after a restart) | fixture | 34.4 ms, 1 source read, 1 event |
147+| first pass after a restart, nothing new (fingerprints are in memory, so every ref list is read once and compared) | fixture / live-sized | 15.2 ms / 517.5 ms (52 sources: the social log, the open list, 50 repositories; 0 events) |
148+| first pass ever (backfill) | live-sized | 11.06 s (52 sources, 1,318 events); an earlier run the same day on the same data took 6.87 s |
149+| the log and the snapshots | live-sized | 1,318 lines, 550,559 bytes; `events/r/` 125,794 bytes |
150+
151+The cost that matters is the backfill: forged is sequential, so the first stream request after the first
152+deploy holds every other request for about 7 to 11 seconds on today's data, once. After that, a pass
153+reads only what changed; a restart costs about half a second once. Live-sized backfill kinds: 598
154+patch_opened, 516 patch_merged, 47 patch_revised, 2 patch_archived, 8 issue_opened, 10 comment, 66
155+release, 1 star, 69 open_brought, 1 open_withdrawn; no COB failed to load.
156+
157+## Not done
158+
159+- Signed agent writes (work units Ask, Claim, Attempt, Landing): design only, back to Drake first.
160+- A per-reader feed (only the accounts you follow): the feed is the whole public stream.
161+- RSS or Atom of the stream.
162+- The feed is not part of the edge smoke test (`infra/smoke.sh`); it is not deployed.
163+- The backfill is not spread over several requests: the first read after the first deploy pays it whole
164+ (above). Running one stream request by hand right after the deploy keeps visitors from paying it.

docs/ANNOYANCES.md

@@ -27,6 +27,7 @@ The forge never writes git or Radicle from the web. An agent writes with its own
2727 | Secrets in a CI log on a shared runner | The forge stores the sha256 of the command output, not the output. The patch page shows the hash, the command path, and the exit status. | `out` is 64 hex characters |
2828 | Status checks from an app you cannot audit | There is no app install and no OAuth. The check is the receipt binding, done by the forge you are reading. | `qn2bind.om` |
2929 | Projects, boards, and a mobile app that need JavaScript | Not offered. Pages are server-rendered. No script, no hotkeys. | CSP `script-src 'none'` |
30+| Polling dozens of list pages (or an events API that keeps 300 events and asks you to wait between polls) to learn what changed | One append-only stream of public activity. Ask for the events after the last `seq` you read; `next` is the address to read next; an unchanged stream answers `304` to your `If-None-Match`. Every event names the object it was read from. The forge reads its sources only when they change, not on a clock. | `/events.json`, `/agents.json`, `/feed` |
3031 | "Conversation must be resolved" and checkbox theater | Not offered. | |
3132 | Forced squash and a commit-message template | The tool commits the file you gave it, with the title you gave it, and does not rewrite history. | `git commit` |
3233 | SSH key upload, 2FA apps, recovery codes | The Radicle key is the only factor. There is nothing to upload. | `/login` |

docs/API.md

@@ -73,11 +73,13 @@ browser or tool; the English page is the reference. Two things make that safe (s
7373
7474 - Keys are stable. A new version of a document gets a new schema name (`forge/repo/2`); keys are
7575 only added within a version, never renamed or removed.
76-- Ids: a repository is its RID as `"rad:<RID>"`; a commit is its full 40-hex sha.
76+- Ids: a repository is its id as a bare `"<RID>"` (`z` then base58); in the store-reading build
77+ (`FORGE_STORE`, docs/CONTRACT.md section 1) it is `"git:<id>"`, the 64 lowercase hex digits of the
78+ project's id in the Interplane store (the SHA-256 of its record 1). A commit is its full 40-hex sha.
7779 - Times: ISO-8601 UTC strings, `"2026-11-07T11:01:21Z"`.
7880 - `null` means not known or not measured. A count of zero is `0`, never `null`.
7981 - Paths (`path`, `json`, archive and readme links) start with `<base>`, so they are correct for the
80- domain the request came in on. `clone.git_https` is absolute.
82+ domain the request came in on.
8183 - Strings are valid UTF-8 JSON. Bytes that are not well-formed UTF-8 in the source (a commit subject,
8284 a file name) become U+FFFD. `<`, `>`, `&` and control bytes are written as `\u00XX`.
8385
@@ -88,19 +90,19 @@ browser or tool; the English page is the reference. Two things make that safe (s
8890 | `schema` | string | `"forge/explore/1"` |
8991 | `base` | string | the base of the request, `"/"` or `"/forge/"` |
9092 | `count` | integer | number of public repositories (the length of `repos`) |
91-| `repos` | array of repo summaries | in the order of the HTML list (the RIDS.md public table) |
93+| `repos` | array of repo summaries | in the order of the HTML list (the RIDS.md public table; in the store-reading build every public line of the store's `catalog.tsv` less the deny list, in catalog order) |
9294
9395 A repo summary (also the first keys of `forge/repo/1`):
9496
9597 | Key | Type | Meaning |
9698 |---|---|---|
9799 | `owner` | string | `"drakestapleton"` (the node delegate; the only owner) |
98-| `name` | string | repository name as in RIDS.md |
99-| `rid` | string | `"rad:<RID>"` |
100+| `name` | string | repository name as in RIDS.md (the catalog in the store-reading build) |
101+| `rid` | string | `"<RID>"` (bare); `"git:<id>"` in the store-reading build (Conventions) |
100102 | `path` | string | HTML page, `<base><owner>/<name>` |
101103 | `json` | string | its `forge/repo/1` document, `<base><owner>/<name>.json` |
102-| `description` | string or null | from the Radicle identity document |
103-| `default_branch` | string | from RIDS.md |
104+| `description` | string or null | from the project's identity document (kept in `repo.git` when the project was imported) |
105+| `default_branch` | string | from RIDS.md (the catalog in the store-reading build) |
104106 | `stars` | integer | star count from the forge's social log |
105107 | `last_commit` | object or null | last commit of the default branch: `sha` (40 hex), `time` (committer time, UTC), `subject` (first line, at most about 980 bytes; the HTML list shows the first 200 bytes of date, short sha and subject) |
106108
@@ -108,7 +110,7 @@ Example (shortened; sha, time and subject are the real last commit of cuda-crack
108110
109111 ```json
110112 {"schema":"forge/explore/1","base":"/forge/","count":29,"repos":[
111-{"owner":"drakestapleton","name":"cuda-crack","rid":"rad:z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","json":"/forge/drakestapleton/cuda-crack.json","description":"...","default_branch":"main","stars":0,"last_commit":{"sha":"7e3c9a731d8607ceb60b5a257c8c3652becd544f","time":"2026-11-07T11:01:21Z","subject":"replicate.sh --agent --yes: ..."}}
113+{"owner":"drakestapleton","name":"cuda-crack","rid":"z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","json":"/forge/drakestapleton/cuda-crack.json","description":"...","default_branch":"main","stars":0,"last_commit":{"sha":"7e3c9a731d8607ceb60b5a257c8c3652becd544f","time":"2026-11-07T11:01:21Z","subject":"replicate.sh --agent --yes: ..."}}
112114 ]}
113115 ```
114116
@@ -120,7 +122,7 @@ All keys of the repo summary above, then:
120122 |---|---|---|
121123 | `schema` | string | `"forge/repo/1"` (first key) |
122124 | `favorites` | integer | favorite count from the social log |
123-| `clone` | object | `rad` (`"rad:<RID>"`), `rad_clone` (`"rad clone rad:<RID>"`), `git_https` (`"https://www.aienos.com/rad/<RID>.git"`) |
125+| `clone` | object | `rad` (`"<RID>"`, bare), `rad_clone` (`null`), `git_https` (`null`: no public Git URL yet). Store-reading build: `rad` and `rad_clone` null, `git_https` `"<clone base>projects/<name>/repo.git"` when built with `FORGE_CLONE_BASE`, else null |
124126 | `archives` | object | `zip`, `tar_gz`: source archive links of the default branch |
125127 | `files` | array or null | top-level entries of the default branch (`git ls-tree -l`), each `name` (string), `type` (`"blob"`, `"tree"` or `"commit"`), `sha` (40 hex object id), `size` (integer bytes, null for trees and submodules); null when the branch cannot be read |
126128 | `files_truncated` | boolean | true when the tree has more than 1000 entries (only the first 1000 are listed), or its listing is longer than the 16 MiB forged reads (the entries in it are listed, the rest are not) |
@@ -136,10 +138,12 @@ never been readable.
136138
137139 | Key | Source | What one count is | Left out |
138140 |---|---|---|---|
139-| `git_fetches` | front-door nginx download log | a git smart-HTTP `GET .../info/refs?service=git-upload-pack` answered 200, for `/rad/<RID>.git[/<delegate>]` or `/code/git/<name>.git`: one per `git clone` or `git fetch` | our own addresses (loopback, LAN, tailnet 100.64/10, IPv6 local, the address `www.aienos.com` resolves to, which is the home connection) and user agents naming bot, crawl or spider |
140-| `upload_pack_requests` | front-door nginx access log | a `POST /rad/<RID>.git[/<delegate>]/git-upload-pack` answered 200 (a clone is usually two: list refs, then fetch) | nothing; that log has no client address, so our own agents are included |
141+| `git_fetches` | front-door nginx download log | a git smart-HTTP `GET .../info/refs?service=git-upload-pack` answered 200, for `/code/git/<name>.git` or the retired clone path: one per `git clone` or `git fetch` | our own addresses (loopback, LAN, tailnet 100.64/10, IPv6 local, the address `www.aienos.com` resolves to, which is the home connection) and user agents naming bot, crawl or spider |
142+| `upload_pack_requests` | retired | not measured: `count` and `since` are always `null` | `null` |
141143 | `downloads` | forged's access log | a `GET` or `HEAD` of `/<owner>/<repo>/archive/...` (`archives`) or `/releases/download/...` (`release_assets`) answered 200; `count` = `archives` + `release_assets` | our own addresses as above (requests that did not come through the public edge are logged as loopback) |
142-| `radicle_seeds` | this node's Radicle routing table (`rad node routing --rid <RID> --json`) | a node that announced it seeds the repository, this node included; `as_of` (instead of `since`) is when it was read | `null` with `as_of` null when rad did not answer |
144+| `seeds` | retired | not measured: `count` and `as_of` are always `null` | (no `excludes` key) |
145+
146+`seeds` replaced the earlier `radicle_seeds` key on 2026-11-14, when its source was retired.
143147
144148 Each object also has `source`, `counts` and `excludes` strings with the same words, so a reader
145149 never needs this page to know what a number means.
@@ -164,9 +168,9 @@ all 29 public repositories; the long strings are shortened here):
164168 ```json
165169 "counts":{
166170 "git_fetches":{"count":2,"since":"2026-11-08T11:48:05Z","source":"front-door nginx download log","counts":"...","excludes":"..."},
167-"upload_pack_requests":{"count":5,"since":"2026-11-08T11:48:05Z","source":"front-door nginx access log","counts":"...","excludes":"..."},
171+"upload_pack_requests":{"count":null,"since":null,"source":"retired","counts":"not measured: the source of this count is retired","excludes":null},
168172 "downloads":{"count":0,"archives":0,"release_assets":0,"since":"2026-11-07T11:02:18Z","source":"forged access log","counts":"...","excludes":"..."},
169-"radicle_seeds":{"count":7,"as_of":"2026-11-09T00:12:38Z","source":"this node's Radicle routing table (rad node routing --rid <RID> --json)","counts":"..."}
173+"seeds":{"count":null,"as_of":null,"source":"retired","counts":"not measured: the source of this count is retired"}
170174 }
171175 ```
172176
@@ -187,6 +191,9 @@ of the same URL answers the same code.
187191 | `error` | string | the error page's title (`"Not found"`) |
188192 | `message` | string | the error page's explanation |
189193
194+Only the 503 "moving" answer of the store-reading build (section below) has one more key, `reason`
195+(a string, `"moving"`); it is not in the table because every other error document lacks it.
196+
190197 Example (`GET /forge/drakestapleton/<name>/tree/main`, a refused repository):
191198
192199 ```json
@@ -196,9 +203,31 @@ Example (`GET /forge/drakestapleton/<name>/tree/main`, a refused repository):
196203 A response that would not fit the server's body (8 MiB, for the JSON or the HTML form of a page) is
197204 never sent cut: the answer is `500` with this document and a message that says the page is too
198205 large. A document that is JSON by its name (`.json`, `.receipt`) gets it without an `Accept` header.
199-The data is whole in the repository and can be read with git or rad. Gates:
206+The data is whole in the repository and can be read with git. Gates:
200207 `server/tests/overflow.sh`, `collab/tests/bigstore.sh`.
201208
209+### Parts moving to the new Interplane store (store-reading build)
210+
211+The store-reading build (`FORGE_STORE`) does not compose the Salvage Yard, Community Machines, Open
212+builds and the trending list (`run.sh` composes `store/mvsalvage.om`, `store/mvcommunity.om`,
213+`store/mvopen.om` and `store/mvgrowth.om` in place of their slices; `store/moving.om` answers). Their
214+addresses do not answer 404: `<base>salvage`, `<base>salvage/` and everything under `<base>salvage/`;
215+`<base>community`, `<base>community/` and everything under it; `<base>open`, `<base>open/` and
216+everything under it; `<base>open.json`; `<base>bring.sh`, `<base>get.sh`, `<base>withdraw.sh`;
217+`<base>trending` and `<base>trending.json` answer `503` for any method, with no `Retry-After` header
218+(no time is promised). The HTML page's title is `Moving` and its text is exactly "This part is moving
219+to the new Interplane store and is not available yet." A JSON request (a `.json` name, or
220+`Accept: application/json`) gets this document with `"reason":"moving"`:
221+
222+```json
223+{"schema":"forge/error/1","status":503,"error":"Moving","message":"This part is moving to the new Interplane store and is not available yet.","reason":"moving"}
224+```
225+
226+Every other 503 (the event stream's fail-closed answer, a busy download with `Retry-After`) keeps its
227+own words and has no `reason` key. `agents.json` lists these parts under `not_available` with the
228+same reason. Gate: `store/tests/agentdoor-store.sh`. The default build keeps its 404s
229+(`server/no<slice>.om`) when a slice is not composed.
230+
202231 ## `forge/search/1`
203232
204233 `GET <base>search?q=<words>` with `Accept: application/json`: the forge-wide search page. The
@@ -242,7 +271,7 @@ all, in repository order), exactly as the HTML page lists them. `q` is cut at 20
242271 | Key | Type | Meaning |
243272 |---|---|---|
244273 | `repo` | string | repository name |
245-| `rid` | string | `"rad:<RID>"` |
274+| `rid` | string | `"<RID>"` (bare) |
246275 | `path` | string | file path in the repository |
247276 | `line` | integer | line number (1-based) |
248277 | `text` | string | the matching line, its first 300 bytes (the HTML page shows the same 300) |
@@ -252,8 +281,8 @@ Example (`GET /forge/search?q=gb10`, shortened to one repository and one match o
252281
253282 ```json
254283 {"schema":"forge/search/1","base":"/forge/","query":"gb10",
255-"repos":[{"owner":"drakestapleton","name":"aien-sovereign-core-mv","rid":"rad:z44GqrPVAPjZkhoD2MWVjqy18ighN","path":"/forge/drakestapleton/aien-sovereign-core-mv","json":"/forge/drakestapleton/aien-sovereign-core-mv.json","description":"AienOS host runtime: ...","default_branch":"main","stars":0,"last_commit":{"sha":"314c0cc2360c75fd44edfc55ae22db036e792e96","time":"2026-11-09T00:48:00Z","subject":"Merge fix/crumb-924-lock (7bdf1521): ..."}}],
256-"code":[{"repo":"aien-sovereign-core-mv","rid":"rad:z44GqrPVAPjZkhoD2MWVjqy18ighN","path":".github/workflows/release.yml","line":57,"text":" # The native engine is linked only on the candidate target (linux aarch64, the GB10 host class).","html":"/forge/drakestapleton/aien-sovereign-core-mv/blob/main/.github/workflows/release.yml#L57"}],
284+"repos":[{"owner":"drakestapleton","name":"aien-sovereign-core-mv","rid":"z44GqrPVAPjZkhoD2MWVjqy18ighN","path":"/forge/drakestapleton/aien-sovereign-core-mv","json":"/forge/drakestapleton/aien-sovereign-core-mv.json","description":"AienOS host runtime: ...","default_branch":"main","stars":0,"last_commit":{"sha":"314c0cc2360c75fd44edfc55ae22db036e792e96","time":"2026-11-09T00:48:00Z","subject":"Merge fix/crumb-924-lock (7bdf1521): ..."}}],
285+"code":[{"repo":"aien-sovereign-core-mv","rid":"z44GqrPVAPjZkhoD2MWVjqy18ighN","path":".github/workflows/release.yml","line":57,"text":" # The native engine is linked only on the candidate target (linux aarch64, the GB10 host class).","html":"/forge/drakestapleton/aien-sovereign-core-mv/blob/main/.github/workflows/release.yml#L57"}],
257286 "code_truncated":true}
258287 ```
259288
@@ -318,7 +347,7 @@ Example (real, shortened with ... only inside long strings):
318347 "repo": {
319348 "owner": "drakestapleton",
320349 "name": "cuda-crack",
321- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
350+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
322351 "path": "/forge/drakestapleton/cuda-crack",
323352 "json": "/forge/drakestapleton/cuda-crack.json"
324353 },
@@ -410,7 +439,7 @@ Example (real, shortened with ... only inside long strings):
410439 "repo": {
411440 "owner": "drakestapleton",
412441 "name": "cuda-crack",
413- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
442+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
414443 "path": "/drakestapleton/cuda-crack",
415444 "json": "/drakestapleton/cuda-crack.json"
416445 },
@@ -483,7 +512,7 @@ Example (real, shortened with ... only inside long strings):
483512 "repo": {
484513 "owner": "drakestapleton",
485514 "name": "cuda-crack",
486- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
515+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
487516 "path": "/drakestapleton/cuda-crack",
488517 "json": "/drakestapleton/cuda-crack.json"
489518 },
@@ -570,7 +599,7 @@ Example (real, shortened with ... only inside long strings):
570599 "repo": {
571600 "owner": "drakestapleton",
572601 "name": "cuda-crack",
573- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
602+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
574603 "path": "/drakestapleton/cuda-crack",
575604 "json": "/drakestapleton/cuda-crack.json"
576605 },
@@ -685,7 +714,7 @@ Example (real, shortened with ... only inside long strings):
685714 "repo": {
686715 "owner": "drakestapleton",
687716 "name": "cuda-crack",
688- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
717+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
689718 "path": "/drakestapleton/cuda-crack",
690719 "json": "/drakestapleton/cuda-crack.json"
691720 },
@@ -773,7 +802,7 @@ Example (real, shortened with ... only inside long strings):
773802 "repo": {
774803 "owner": "drakestapleton",
775804 "name": "cuda-crack",
776- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
805+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
777806 "path": "/forge/drakestapleton/cuda-crack",
778807 "json": "/forge/drakestapleton/cuda-crack.json"
779808 },
@@ -890,7 +919,7 @@ Example (real, shortened with ... only inside long strings):
890919 "repo": {
891920 "owner": "drakestapleton",
892921 "name": "cuda-crack",
893- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
922+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
894923 "path": "/drakestapleton/cuda-crack",
895924 "json": "/drakestapleton/cuda-crack.json"
896925 },
@@ -987,7 +1016,7 @@ Example (real, shortened with ... only inside long strings):
9871016 "repo": {
9881017 "owner": "drakestapleton",
9891018 "name": "cuda-crack",
990- "rid": "rad:z631r2JJiVT8it4tST7RK24hpowi",
1019+ "rid": "z631r2JJiVT8it4tST7RK24hpowi",
9911020 "path": "/drakestapleton/cuda-crack",
9921021 "json": "/drakestapleton/cuda-crack.json"
9931022 },
@@ -1060,7 +1089,7 @@ Example (real, shortened with ... only inside long strings):
10601089 "repo": {
10611090 "owner": "drakestapleton",
10621091 "name": "omega-bridge",
1063- "rid": "rad:z3Hr9ZaiKHwwuNzPK5M8c7uw6pj7y",
1092+ "rid": "z3Hr9ZaiKHwwuNzPK5M8c7uw6pj7y",
10641093 "path": "/forge/drakestapleton/omega-bridge",
10651094 "json": "/forge/drakestapleton/omega-bridge.json"
10661095 },
@@ -1180,7 +1209,7 @@ Example (real, from a trial forged over a fixture repository; the live allow-lis
11801209 "repo": {
11811210 "owner": "drakestapleton",
11821211 "name": "dlfix",
1183- "rid": "rad:z3FixtureRepoForReasesTagsXY",
1212+ "rid": "z3FixtureRepoForReasesTagsXY",
11841213 "path": "/forge/drakestapleton/dlfix",
11851214 "json": "/forge/drakestapleton/dlfix.json"
11861215 },
@@ -1279,7 +1308,7 @@ Example (real, from a trial forged over a fixture repository; the live allow-lis
12791308 Live (`cuda-crack`, no tags), under base `/`:
12801309
12811310 ```json
1282-{"schema":"forge/releases/1","base":"/","repo":{"owner":"drakestapleton","name":"cuda-crack","rid":"rad:z631r2JJiVT8it4tST7RK24hpowi","path":"/drakestapleton/cuda-crack","json":"/drakestapleton/cuda-crack.json"},"page":1,"releases":[],"prev":null,"next":null}
1311+{"schema":"forge/releases/1","base":"/","repo":{"owner":"drakestapleton","name":"cuda-crack","rid":"z631r2JJiVT8it4tST7RK24hpowi","path":"/drakestapleton/cuda-crack","json":"/drakestapleton/cuda-crack.json"},"page":1,"releases":[],"prev":null,"next":null}
12831312 ```
12841313
12851314 ## `forge/release/1`
@@ -1359,7 +1388,7 @@ Example (real, fixture repository, after one download of each asset and of the z
13591388 "repo": {
13601389 "owner": "drakestapleton",
13611390 "name": "dlfix",
1362- "rid": "rad:z3FixtureRepoForReasesTagsXY",
1391+ "rid": "z3FixtureRepoForReasesTagsXY",
13631392 "path": "/drakestapleton/dlfix",
13641393 "json": "/drakestapleton/dlfix.json"
13651394 },
@@ -1465,7 +1494,7 @@ Example (real, shortened with ... only inside long strings):
14651494 "repo": {
14661495 "owner": "drakestapleton",
14671496 "name": "omega-harness",
1468- "rid": "rad:z39gvwWsnkRZsAConQLjaKiNVLHfW",
1497+ "rid": "z39gvwWsnkRZsAConQLjaKiNVLHfW",
14691498 "path": "/drakestapleton/omega-harness",
14701499 "json": "/drakestapleton/omega-harness.json"
14711500 },
@@ -1637,7 +1666,7 @@ Example (real, shortened with ... only inside long strings):
16371666 "repo": {
16381667 "owner": "drakestapleton",
16391668 "name": "omega-bridge",
1640- "rid": "rad:z3Hr9ZaiKHwwuNzPK5M8c7uw6pj7y",
1669+ "rid": "z3Hr9ZaiKHwwuNzPK5M8c7uw6pj7y",
16411670 "path": "/drakestapleton/omega-bridge",
16421671 "json": "/drakestapleton/omega-bridge.json"
16431672 },
@@ -1715,10 +1744,69 @@ Example (real, shortened with ... only inside long strings):
17151744 }
17161745 ```
17171746
1747+## Native issue forms
1748+
1749+Signed-in accounts can open issues and comment on public repositories in the native store. Sign in
1750+at `<base>login` with an Ed25519 key. Browser forms submit the session cookie, hidden csrf and request
1751+fields, title (one line, 1 to 256 UTF-8 bytes, for creation), and body (Markdown). The body may be
1752+empty for creation. The body limit is 16,000 UTF-8 bytes after normalizing line endings. The browser
1753+receives 303 with the canonical issue URL in Location.
1754+
1755+Agents use the same session and URL-encoded fields. Request the form and submit it with
1756+`Accept: application/json`. The two form URLs are `<base><owner>/<repo>/issues/new` and
1757+`<base><owner>/<repo>/issues/<id>/comments`. The latter requires the full 16-hex issue ID. Imported
1758+issues accept native comments. GET returns the fields below. POST returns a write result.
1759+
1760+A repeat with the same account, form request token and normalized fields returns the previously
1761+published outcome. A recognized token with different text returns 409. Invalid fields return 400,
1762+incorrect or missing CSRF returns 403, and a missing issue returns 404. A full index or thread
1763+returns 409, rate limiting returns 429, and contention returns 503 with Retry-After. An I/O failure
1764+returns 500. An unsigned form request for JSON or an unsigned POST redirects to sign-in.
1765+
1766+The historical importer is run against isolated staging data. Publishing its output into a
1767+repository with live issues requires coordination with the forge writer lock and a merge of existing
1768+issue IDs and comments. Replacing an active issues directory with the staging export loses the
1769+repository's live records.
1770+
1771+## `forge/issue-form/1`
1772+
1773+`GET <base><owner>/<repo>/issues/new` or `GET <base><owner>/<repo>/issues/<id>/comments`
1774+
1775+Send `Accept: application/json` and the signed-in session cookie. The response is private to the
1776+session and cannot be cached by the public edge.
1777+
1778+| Key | Type | Meaning |
1779+|---|---|---|
1780+| `schema` | string | `forge/issue-form/1` |
1781+| `base` | string | `/` or `/forge/` |
1782+| `repo` | object | the repository (see `forge/repo/1`) |
1783+| `action` | string | URL for the form POST |
1784+| `csrf` | string | session-bound CSRF field |
1785+| `request` | string | token for deduplication of this form submission |
1786+
1787+## `forge/issue-write/1`
1788+
1789+`POST <base><owner>/<repo>/issues/new` or `POST <base><owner>/<repo>/issues/<id>/comments`
1790+
1791+Send `Accept: application/json`, the session cookie, and the form's URL-encoded fields. A new write
1792+returns 201. A replay of an accepted submission returns 200.
1793+
1794+| Key | Type | Meaning |
1795+|---|---|---|
1796+| `schema` | string | `forge/issue-write/1` |
1797+| `base` | string | `/` or `/forge/` |
1798+| `repo` | object | the repository (see `forge/repo/1`) |
1799+| `path` | string | canonical issue URL |
1800+| `applied` | boolean | true for a new write and false for a replay |
1801+
17181802 ## `forge/issues/1`
17191803
17201804 `GET <base><owner>/<repo>/issues[?state=open|closed|all]`
17211805
1806+In the native store, the unpaged JSON list preserves index order and lists up to 200 issues.
1807+Add `?page=1` for a 30-item page, newest indexed issue first, with `page`, `per_page`, `prev`, and
1808+`next` fields. State counts cover the entire index. The HTML list opens on the newest page.
1809+
17221810 The issue list page: same shape as `forge/patches/1` without revisions. `draft` and `merged` are `open`
17231811 here, and `archived` is `closed`, as on the page.
17241812
@@ -1774,7 +1862,7 @@ Example (real, shortened with ... only inside long strings):
17741862 "repo": {
17751863 "owner": "drakestapleton",
17761864 "name": "heartwood",
1777- "rid": "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5",
1865+ "rid": "z3gqcJUoA1n9HaHKufZs5FCSGazv5",
17781866 "path": "/drakestapleton/heartwood",
17791867 "json": "/drakestapleton/heartwood.json"
17801868 },
@@ -1838,6 +1926,10 @@ Example (real, shortened with ... only inside long strings):
18381926 One issue. `<id>` is 4 to 40 lowercase hex naming exactly one issue, else 404. The first comment is the
18391927 issue body, as on the page.
18401928
1929+The native store accepts unique prefixes of 4 to 16 hex characters. Directly posted authors and
1930+commenters carry their session key in `author.did` with `name: null`. An issue opened natively has
1931+`imported: null`. Imported authors retain source attribution with `author: null`.
1932+
18411933 | Key | Type | Meaning |
18421934 |---|---|---|
18431935 | `schema` | string | `forge/issue/1` |
@@ -1888,7 +1980,7 @@ Example (real, shortened with ... only inside long strings):
18881980 "repo": {
18891981 "owner": "drakestapleton",
18901982 "name": "heartwood",
1891- "rid": "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5",
1983+ "rid": "z3gqcJUoA1n9HaHKufZs5FCSGazv5",
18921984 "path": "/drakestapleton/heartwood",
18931985 "json": "/drakestapleton/heartwood.json"
18941986 },
@@ -1955,7 +2047,7 @@ Example (real, shortened with ... only inside long strings):
19552047 Example (real, trial server with throwaway accounts, 2026-11-09 UTC):
19562048
19572049 ```json
1958-{"schema":"forge/stargazers/1","base":"/forge/","repo":{"owner":"drakestapleton","name":"cuda-crack","rid":"rad:z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","json":"/forge/drakestapleton/cuda-crack.json"},"count":2,"users":[{"name":"tester-one","path":"/forge/tester-one"},{"name":"z6MkkjqXvx7SrFRXDXTmpvXEib7jCwnQVQcAaQtXFC6Yczam","path":"/forge/z6MkkjqXvx7SrFRXDXTmpvXEib7jCwnQVQcAaQtXFC6Yczam"}]}
2050+{"schema":"forge/stargazers/1","base":"/forge/","repo":{"owner":"drakestapleton","name":"cuda-crack","rid":"z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","json":"/forge/drakestapleton/cuda-crack.json"},"count":2,"users":[{"name":"tester-one","path":"/forge/tester-one"},{"name":"z6MkkjqXvx7SrFRXDXTmpvXEib7jCwnQVQcAaQtXFC6Yczam","path":"/forge/z6MkkjqXvx7SrFRXDXTmpvXEib7jCwnQVQcAaQtXFC6Yczam"}]}
19592051 ```
19602052
19612053 ## `forge/watchers/1`
@@ -1980,7 +2072,7 @@ Example (real, trial server with throwaway accounts, 2026-11-09 UTC):
19802072 Example (real, trial server):
19812073
19822074 ```json
1983-{"schema":"forge/watchers/1","base":"/forge/","repo":{"owner":"drakestapleton","name":"cuda-crack","rid":"rad:z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","json":"/forge/drakestapleton/cuda-crack.json"},"count":1,"users":[{"name":"tester-one","path":"/forge/tester-one"}]}
2075+{"schema":"forge/watchers/1","base":"/forge/","repo":{"owner":"drakestapleton","name":"cuda-crack","rid":"z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","json":"/forge/drakestapleton/cuda-crack.json"},"count":1,"users":[{"name":"tester-one","path":"/forge/tester-one"}]}
19842076 ```
19852077
19862078 ## `forge/user/1`
@@ -2023,7 +2115,7 @@ Repo summaries exactly as the items of `forge/explore/1` (`owner`, `name`, `rid`
20232115 | Key | Type | Meaning |
20242116 |---|---|---|
20252117 | `name` | string | repository name |
2026-| `rid` | string | `"rad:<RID>"` |
2118+| `rid` | string | `"<RID>"` (bare) |
20272119 | `path` | string | the repository page, `<base><owner>/<name>` |
20282120 | `stars` | integer | the repository's star count (shown next to it in the list) |
20292121
@@ -2037,7 +2129,7 @@ Repo summaries exactly as the items of `forge/explore/1` (`owner`, `name`, `rid`
20372129 Example (real, trial server, `?tab=stars` of an account):
20382130
20392131 ```json
2040-{"schema":"forge/user/1","base":"/forge/","user":"tester-one","did":"did:key:z6Mkry4YVoekcSfSHEZZkyJRYg2tURTFhnh9PNuP87uZ3AzQ","followers":1,"following":2,"tab":"stars","repos":null,"stars_received":null,"favorites_received":null,"starred":[{"name":"omega-mv","rid":"rad:z6do9WDBhuSnvopDkgFdFr1yWA62","path":"/forge/drakestapleton/omega-mv","stars":1},{"name":"cuda-crack","rid":"rad:z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","stars":2}],"users":null}
2132+{"schema":"forge/user/1","base":"/forge/","user":"tester-one","did":"did:key:z6Mkry4YVoekcSfSHEZZkyJRYg2tURTFhnh9PNuP87uZ3AzQ","followers":1,"following":2,"tab":"stars","repos":null,"stars_received":null,"favorites_received":null,"starred":[{"name":"omega-mv","rid":"z6do9WDBhuSnvopDkgFdFr1yWA62","path":"/forge/drakestapleton/omega-mv","stars":1},{"name":"cuda-crack","rid":"z631r2JJiVT8it4tST7RK24hpowi","path":"/forge/drakestapleton/cuda-crack","stars":2}],"users":null}
20412133 ```
20422134
20432135 Example (real, trial server, `<base>tester-one/following`):
@@ -2063,14 +2155,14 @@ Example (real, trial server, `<base>tester-one/following`):
20632155 | Key | Type | Meaning |
20642156 |---|---|---|
20652157 | `name` | string | repository name |
2066-| `rid` | string | `"rad:<RID>"` |
2158+| `rid` | string | `"<RID>"` (bare) |
20672159 | `path` | string | the repository page, `<base><owner>/<name>` |
20682160 | `stars` | integer | the repository's star count (shown next to it in the list) |
20692161
20702162 Example (real, trial server, `?tab=favorites`):
20712163
20722164 ```json
2073-{"schema":"forge/stars/1","base":"/forge/","user":"tester-one","tab":"favorites","repos":[{"name":"omega-mv","rid":"rad:z6do9WDBhuSnvopDkgFdFr1yWA62","path":"/forge/drakestapleton/omega-mv","stars":1}]}
2165+{"schema":"forge/stars/1","base":"/forge/","user":"tester-one","tab":"favorites","repos":[{"name":"omega-mv","rid":"z6do9WDBhuSnvopDkgFdFr1yWA62","path":"/forge/drakestapleton/omega-mv","stars":1}]}
20742166 ```
20752167
20762168 Social pages without a JSON form: `<base>login`, `<base>logout`, `<base>settings` (forms, or private
@@ -2079,6 +2171,162 @@ account data) and every `POST` (`star`, `unstar`, `fav`, `unfav`, `watch`, `unwa
20792171 and carry no alternate link. A non-existent user is `404` with a `forge/error/1` body, like its HTML
20802172 page. `<base>stars` without a session stays `303` to `<base>login`.
20812173
2174+## `interplane/agents/1`
2175+
2176+`GET <base>agents.json`: the one document an agent reads first (`server/agents.om`). It lists every
2177+machine-readable address this forge answers today, how to ask each for JSON, the schema it answers
2178+(from this file, `docs/GROWTH.md` or `docs/OPEN-BUILDS.md`), whether it needs a browser session, and
2179+what is not available, so an agent does not have to guess. The routes are not prose kept by hand:
2180+`server/agents.tsv` is the one table, compiled into the build by `run.sh` (`.build/agents.om`), and
2181+`server/tests/agentdoor.sh` fetches every row with its template filled from a fixture and checks the
2182+schema it answers, and that every schema heading of this file is a row. Only `agents.json` is claimed:
2183+`/agents/` on interplane.io is a page of the static site (nginx serves existing files first), so the
2184+forge does not answer `/agents`. JSON whatever the headers; errors are `forge/error/1`.
2185+
2186+| Key | Type | Meaning |
2187+|---|---|---|
2188+| `schema` | string | `"interplane/agents/1"` |
2189+| `base` | string | the base of the request (`"/"` or `"/forge/"`); every address below starts with it |
2190+| `read_first` | string | the address of this document |
2191+| `how_to_ask` | object | what the `json` word of a route means |
2192+| `text_form` | string | how to get the plain-text form of an HTML page (`format=text`) |
2193+| `error_schema` | string | `"forge/error/1"`: the document of every error a JSON request gets |
2194+| `events` | object or null | the activity stream (below); null in a build without the event store |
2195+| `routes` | array | one item per address, in the order of `server/agents.tsv` |
2196+| `not_available` | array | what agents ask for that this forge does not offer, and why |
2197+
2198+### `how_to_ask` object
2199+
2200+| Key | Type | Meaning |
2201+|---|---|---|
2202+| `suffix` | string | `json` is `"suffix"`: the path itself is the JSON name (`.json`) |
2203+| `accept` | string | `json` is `"accept"`: send `Accept: application/json` (and not `text/html`) to the page's own address |
2204+| `always` | string | `json` is `"always"`: JSON whatever the headers say |
2205+
2206+### `events` object
2207+
2208+| Key | Type | Meaning |
2209+|---|---|---|
2210+| `path` | string | `<base>events.json` |
2211+| `schema` | string | `"interplane/events/1"` |
2212+| `after` | string | how `after=` and `next` work |
2213+| `limit_default` | integer | 50 |
2214+| `limit_max` | integer | 200 |
2215+| `etag` | string | how to poll cheaply with `If-None-Match` |
2216+| `feed` | string | `<base>feed`, the same stream as a page for people |
2217+
2218+### `routes` items
2219+
2220+| Key | Type | Meaning |
2221+|---|---|---|
2222+| `method` | string | `"GET"` |
2223+| `path` | string | the base and a path template: `{owner}`, `{repo}`, `{ref}`, `{path}`, `{sha}`, `{id}`, `{tag}`, `{user}`, `{q}`, `{a}`, `{b}`, `{rid}`, `{slug}`, `{order}`, `{seq}`, `{n}` are filled by the reader |
2224+| `json` | string | `"suffix"`, `"accept"` or `"always"` (`how_to_ask`) |
2225+| `schema` | string or null | the `schema` of the answer; null for `status.json`, which has no schema key |
2226+| `auth` | string | `"none"`, or `"session"`: answers only with a signed-in browser session (signed out it is a 303 to `<base>login`) |
2227+| `doc` | string | the file of this repository that documents the schema |
2228+| `purpose` | string | one line |
2229+
2230+### `not_available` items
2231+
2232+| Key | Type | Meaning |
2233+|---|---|---|
2234+| `what` | string | what is not offered (or the address that is not built in this build) |
2235+| `why` | string | why, and what to use instead |
2236+
2237+Example (`GET /agents.json`, shortened):
2238+
2239+```json
2240+{"schema":"interplane/agents/1","base":"/","read_first":"/agents.json","how_to_ask":{"suffix":"the path itself is the JSON name","accept":"...","always":"..."},"text_form":"...","error_schema":"forge/error/1","events":{"path":"/events.json","schema":"interplane/events/1","after":"...","limit_default":50,"limit_max":200,"etag":"...","feed":"/feed"},"routes":[{"method":"GET","path":"/{owner}/{repo}/patches/{id}","json":"accept","schema":"forge/patch/1","auth":"none","doc":"docs/API.md","purpose":"one patch: revisions, reviews, comments, merges, verdicts"}],"not_available":[{"what":"MCP server","why":"..."}]}
2241+```
2242+
2243+## `interplane/events/1`
2244+
2245+`GET <base>events.json?after=<seq>&limit=<n>` (JSON whatever the headers; also `<base>events` and
2246+`<base>feed` with `Accept: application/json`; `<base>events` without it redirects to the feed page):
2247+the public activity of this forge as one append-only, ordered stream, so an agent reads from where it
2248+stopped instead of polling every list page. Source and rules: `door/`, `docs/AGENT-DOOR.md`.
2249+
2250+- `after` (default 0) is exclusive: the answer holds the events with a higher `seq`, oldest first.
2251+ `limit` defaults to 50; the maximum is 200, and a larger request is answered with 200 events and
2252+ `limited: true` (not an error). Anything but 1 to 18 digits, or `limit=0`, is `400`.
2253+- `next` is the address to read next: `after` is the last `seq` this answer looked at, so a reader that
2254+ follows `next` sees every event once, with no gap and no repeat. An answer with no events keeps
2255+ `after` where it was: read the same `next` again later.
2256+- `seq` is strictly increasing and never reused; it stays the same across restarts (the stream is the
2257+ file `<data>events/log`). A `seq` can be missing from every answer: an event of a repository that is
2258+ no longer public is not shown, and its number is not given to another event.
2259+- The answer carries an `ETag`; a request with `If-None-Match` set to it is answered `304` with no body
2260+ while the stream (and the account names and the public list it shows) did not change.
2261+- The edge cache in front of interplane.io keeps a 200 answer up to 30 seconds.
2262+
2263+| Key | Type | Meaning |
2264+|---|---|---|
2265+| `schema` | string | `"interplane/events/1"` |
2266+| `base` | string | the base of the request |
2267+| `head_seq` | integer | the highest `seq` in the stream (0 when it is empty) |
2268+| `after` | integer | the `after` of the request |
2269+| `limit` | integer | the limit applied (at most `limit_max`) |
2270+| `limit_requested` | integer | the limit asked for (50 when none) |
2271+| `limit_max` | integer | 200 |
2272+| `limited` | boolean | true when the limit asked for was larger than `limit_max` |
2273+| `events` | array | the events, oldest first |
2274+| `count` | integer | the length of `events` |
2275+| `next` | string | `<base>events.json?after=<seq>&limit=<limit>`: read this next |
2276+
2277+### `events` items
2278+
2279+| Key | Type | Meaning |
2280+|---|---|---|
2281+| `seq` | integer | the event's number in the stream, from 1 |
2282+| `time` | string | ISO-8601 UTC time from the source record: the change's author time (patches, issues, reviews, comments), the tag or commit date (release, branch moved), the social log line, the day of the open shelf row (00:00); store-reading build, a branch move recorded by the chain: the record's time |
2283+| `kind` | string | `patch_opened`, `patch_revised`, `patch_merged`, `patch_archived`, `review`, `comment`, `issue_opened`, `issue_closed`, `release`, `branch_moved`, `star`, `follow`, `open_brought`, `open_withdrawn`; the store-reading build has only `release`, `branch_moved`, `star` and `follow` |
2284+| `actor` | object or null | who did it |
2285+| `repo` | object or null | the public repository it is about (`forge/repo/1` summary keys: `rid` is that form's identifier, the bare `"<RID>"` in the Radicle build (no `rad:` prefix since 9a4420a, as in Conventions) or, in the store-reading build, `"git:<id>"`); null for a follow and the open shelf |
2286+| `subject` | string | one line: the patch or issue title, the tag name, `"<n> new commits on <branch>"`, the starred repository, the followed key, the shelf name |
2287+| `path` | string or null | the HTML page of the thing |
2288+| `json` | string or null | its JSON address (the same page with `Accept: application/json`, or the `.json` name) |
2289+| `source` | string | the object it was read from, so it can be checked: the COB id (opening), the change commit (revision, merge, review, comment, archive, close), the tag object or the commit (release, branch moved), `social.log:<seq>`, `open/list.tsv:<rid>@<day>`; store-reading build: `chain.tsv:<N>` (the chain record of a branch move), `repo.git:<sha>` (a tag object, or a move no record names) |
2290+| `verdict` | string or null | a review's verdict word (`accept`, `reject`), else null |
2291+| `from` | string or null | branch moved: the old head (40 hex), else null |
2292+| `commits` | integer or null | branch moved: the commits the new head has that the old one has not, else null |
2293+| `target` | object or null | follow: the followed account (same keys as `actor`), else null |
2294+
2295+### `events.actor` object
2296+
2297+| Key | Type | Meaning |
2298+|---|---|---|
2299+| `name` | string or null | the account's display name (the owner: `drakestapleton`); null when it has none or the key has no account here |
2300+| `did` | string | the `did:key:` of the key that signed the change or the social line |
2301+| `path` | string or null | the account's page; null when the key has no account here |
2302+
2303+### `events.target` object
2304+
2305+| Key | Type | Meaning |
2306+|---|---|---|
2307+| `name` | string or null | as `actor` |
2308+| `did` | string | as `actor` |
2309+| `path` | string or null | as `actor` |
2310+
2311+### `events.repo` object
2312+
2313+| Key | Type | Meaning |
2314+|---|---|---|
2315+| `owner` | string | `"drakestapleton"` |
2316+| `name` | string | repository name as in RIDS.md |
2317+| `rid` | string | `"<RID>"` (bare) |
2318+| `path` | string | HTML page, `<base><owner>/<name>` |
2319+| `json` | string | its `forge/repo/1` document, `<base><owner>/<name>.json` |
2320+
2321+Example (`GET /events.json?after=40&limit=2`, shortened):
2322+
2323+```json
2324+{"schema":"interplane/events/1","base":"/","head_seq":57,"after":40,"limit":2,"limit_requested":2,"limit_max":200,"limited":false,"events":[
2325+{"seq":41,"time":"2026-11-14T15:02:10Z","kind":"patch_opened","actor":{"name":"fixdev","did":"did:key:z6Mk...","path":"/fixdev"},"repo":{"owner":"drakestapleton","name":"hop","rid":"z3uek...","path":"/drakestapleton/hop","json":"/drakestapleton/hop.json"},"subject":"fixture change one","path":"/drakestapleton/hop/patches/<id>","json":"/drakestapleton/hop/patches/<id>","source":"<COB id>","verdict":null,"from":null,"commits":null,"target":null},
2326+{"seq":42,"time":"2026-11-14T15:20:00Z","kind":"branch_moved","actor":{"name":"drakestapleton","did":"did:key:z6MkfZ...","path":"/drakestapleton"},"repo":{...},"subject":"2 new commits on main","path":"/drakestapleton/hop/compare/<old>...<new>","json":"/drakestapleton/hop/compare/<old>...<new>","source":"<new head>","verdict":null,"from":"<old head>","commits":2,"target":null}
2327+],"count":2,"next":"/events.json?after=42&limit=2"}
2328+```
2329+
20822330 ## Pages without a JSON form
20832331
20842332 These answer the same bytes whatever the `Accept` header says, and their HTML names no JSON alternate.
@@ -2091,4 +2339,4 @@ These answer the same bytes whatever the `Accept` header says, and their HTML na
20912339 `/archive/...`, `/releases/download/...`.
20922340 - Redirects stay redirects: `/pulls/<id>` and `/pull/<id>` (302 to `/patches/<id>`), `/releases/latest`
20932341 (302), `<base>stars` signed out (303 to `<base>login`), tree on a file and blob on a folder (302).
2094-- POST handlers are unchanged.
2342+- Native issue POSTs support the machine form and result documented above.

docs/BRING.md

@@ -1,4 +1,4 @@
1-# interplane: bring a project, get a project, withdraw a project
1+# interplane: bring a project, get a project, withdraw a project, send a patch
22
33 `interplane` is the person's program in the one-command contract
44 (`~/handoffs/yourtrained-cortex/briefs/one-command-contract.md`, slice TOOL). It is seeded Omega:
@@ -9,6 +9,8 @@ What each target can do and why is in `tools/bring/PLATFORMS.md`.
99 interplane bring [folder] publish a folder (default: the current folder)
1010 interplane get <page address|rid> download a project into ./<name>/
1111 interplane withdraw <page address|rid> take your project off the shelf (only from the computer that brought it)
12+interplane patch [--base REF] [--title T] [--message-file F] [--yes] OWNER/REPO
13+ send the commits of this git work tree as a patch to OWNER/REPO
1214 interplane pack <folder> <file> the walk, scan and archive only (no network, no key): for checks
1315 interplane unpack <file> <folder> the strict unpack only
1416 interplane --version
@@ -95,14 +97,85 @@ The line people paste is `curl -fsSL https://interplane.io/withdraw.sh | sh -s h
9597 The hub's own gates (only the bringer's key can withdraw; withdrawal unseeds and removes the
9698 download) are tested in `open/tests/up.sh`.
9799
100+## patch
101+
102+`interplane patch [--base REF] [--title T] [--message-file F] [--yes] OWNER/REPO` (source
103+`tools/bring/src/50patch.om`, contract `~/work/lanes/CONTRACT-interplane-connector-r1.md` F7). Run it
104+inside a git work tree whose commits on top of the project's `main` are the patch. The forge side,
105+the checks and the answers are in `docs/API.md` "Git patches".
106+
107+1. **Arguments.** OWNER/REPO is two names of letters, digits, `.`, `-` and `_` around one slash, given
108+ once. `--title` takes 1 to 256 bytes; a `--base` value that starts with `-` is refused as naming no
109+ commit; a flag given twice keeps its last value. A missing value, an unknown word or a second
110+ OWNER/REPO prints the usage line and exits 1.
111+2. **git, read only.** Every git run is `/usr/bin/git` started with an argument list (no shell, no
112+ PATH search), an empty environment, standard input `/dev/null`, its output into the tool's private
113+ temp folder, in the current folder. In order:
114+ - `git rev-parse --is-inside-work-tree` must print `true`, and `git rev-parse --verify --quiet
115+ HEAD^{commit}` must name a commit (else: not inside a git work tree / no commit at HEAD).
116+ - The base: `--base REF` is `git rev-parse --verify --quiet --end-of-options REF^{commit}`;
117+ without it, `git merge-base HEAD refs/remotes/origin/main` (no such ref: the message says to
118+ name the base with `--base`).
119+ - `git rev-list --count BASE..HEAD`: 1 to 100 commits (0: nothing to send; more than 100: refused
120+ here, a patch holds at most 100).
121+ - `git format-patch --stdout --no-color --no-ext-diff --no-textconv --no-attach --no-thread
122+ --no-cover-letter --src-prefix=a/ --dst-prefix=b/ --no-signature BASE..HEAD`: the mbox, at most
123+ 2097152 bytes (larger: nothing sent). The flags pin what a repository's configuration could
124+ otherwise change in the output; with no `HOME`, no user configuration is read.
125+ - `git diff --name-only -z BASE HEAD`: the number of files changed.
126+ - The title: `--title`, else `git log -1 --format=%s HEAD` (the HEAD commit's subject); 1 to 256
127+ bytes on one line, no control byte.
128+ - The description: the bytes of `--message-file` (none: empty), carriage returns dropped, blanks
129+ and line feeds at the end trimmed, at most 60000 bytes.
130+3. **What would be sent.** Seven lines, then the question:
131+ ```
132+ Repository: drakestapleton/fixrepo
133+ Base: 937467a8c4a62d02a8dedb574a8603b17c5aa87e
134+ Commits: 2
135+ Files changed: 2
136+ Bytes: 854
137+ Title: src: e2e line, the patch title
138+ Send to: http://127.0.0.1:18488
139+ ```
140+ (a real run: `patch/tests/e2e.sh` on 2026-11-17 against a scratch forge, with `--yes`).
141+4. **Consent.** Without `--yes` it asks `Type yes to send this patch, anything else to stop:` and reads
142+ one line from `/dev/tty` (never stdin). Anything but exactly `yes`, or no terminal, prints
143+ `Nothing sent.` and exits 1: no key is made, ssh-keygen and curl are not started, and nothing
144+ reaches the forge. `--yes` is the consent given on the command line (a harness's own permission
145+ prompt for the command is then the human gate).
146+5. **Key and statement.** `~/.interplane/key` is made once as bring makes it. The statement
147+ `interplane-patch 1\nOWNER/REPO\nBASE\n<sha256 of the mbox>\n<sha256 of title, line feed,
148+ description>\n` is signed with `ssh-keygen -Y sign -n interplane-patch`. The key never leaves the
149+ computer.
150+6. **Sign-in and send.** The sign-in of bring, then one `POST <BASE>/OWNER/REPO/patches/new` with
151+ the form csrf, repo, base, title, description, mbox (base64url, no padding) and sig. A 429 (the
152+ write gate) waits a second and sends the same form again, for as long as it lasts.
153+7. **Final lines.** `201`: `Patch page: <BASE>/OWNER/REPO/patches/<id>`, exit 0. `200` (the forge
154+ already has this statement): `Interplane already has this patch.` and the same line, exit 0. Any
155+ other answer: `interplane: Interplane refused the patch: <the server's reason>` (or the HTTP code
156+ when the answer has no reason line), exit 2.
157+
158+Exit status: 0 sent (or already there), 1 nothing sent (usage, no work tree, no base, nothing or too
159+much to send, git failed, a local check failed, no consent), 2 the server refused it. A failure of the
160+sign-in itself stops with a message and exit 1, after the sign-in request but before the patch is
161+sent. The tool never fetches, pushes, or writes the work tree, the index or any ref.
162+
163+Tests: `patch/tests/run.sh` (the tool against a test forged: consent, the summary, replay, options,
164+refusals, arguments; part of `./run.sh check-patch`) and `patch/tests/e2e.sh` (the loopback run: the
165+raw route is byte-equal to `git format-patch` with the flags above, and `git am` of it onto the base
166+gives the tool's tree).
167+
98168 ## Programs and network
99169
100170 The tool starts only `/usr/bin/curl` (the one network path; `--proto =https`, no redirects, a
101-cleared environment, no shell) and `/usr/bin/ssh-keygen`. bring starts both only after the yes;
102-withdraw reads the shelf JSON with curl before asking, and signs only after the yes. `BASE` is
103-`https://interplane.io`; `INTERPLANE_BASE` may name another `https://` base, or `http://127.0.0.1:`
104-or `http://localhost:` for tests. On Linux the start word is `execprog` (empty environment, every
105-descriptor above 2 closed); on macOS `posix_spawn` with `POSIX_SPAWN_CLOEXEC_DEFAULT`.
171+cleared environment, no shell), `/usr/bin/ssh-keygen` and, for `patch` only, `/usr/bin/git`. bring
172+starts curl and ssh-keygen only after the yes; withdraw reads the shelf JSON with curl before asking,
173+and signs only after the yes; patch runs git (read only: `rev-parse`, `merge-base`, `rev-list`,
174+`format-patch`, `diff`, `log`; never fetch, push or any write) before asking, and curl and ssh-keygen
175+only after the yes. `BASE` is `https://interplane.io`; `INTERPLANE_BASE` may name another `https://`
176+base, or `http://127.0.0.1:` or `http://localhost:` for tests. On Linux the start word is `execprog`
177+(empty environment, every descriptor above 2 closed); on macOS `posix_spawn` with
178+`POSIX_SPAWN_CLOEXEC_DEFAULT`.
106179
107180 ## Installer
108181
@@ -159,6 +232,10 @@ repository name and the receipt anchors are Drake's to confirm.
159232 | 429 retry | no limit | the contract: never give up while the server says 429 | kept |
160233 | busy retry (503, 502, 504, 429 on get's GETs, the status GET and withdraw's GETs and POST; 503 on a chunk or the finish; the scripts' download) | no limit | the owner's rule: a stranger's first run must not fail on a cold cache | one line per try, 10 seconds apart; Ctrl-C stops it. The Omega loops carry `bound 9223372036854775807`, the language's required loop bound, not a give-up count |
161234 | write-gate 429 on the finish and the withdraw POST | no limit | 30 writes a key a clock minute; every chunk counts | a quiet second and the same request again, as for chunks |
235+| patch: commits | 100 | the contract (F1) and the forge's check | refused before anything is sent |
236+| patch: mbox | 2097152 bytes | the contract (F1) and the forge's check | refused before anything is sent |
237+| patch: title, description | 256 bytes, 60000 bytes | the forge's field rules (`docs/collab-write.md` section 2) | refused before anything is sent |
238+| patch: write-gate 429 | no limit | 30 writes a key a clock minute | a quiet second and the same form again |
162239
163240 ## Tests
164241

docs/CONTRACT.md

@@ -18,20 +18,33 @@ omega-mv seed/net/http.om (names h*, H*)
1818 omega-mv seed/net/notls.om
1919 omega-mv om/tls/sha2.om (sha256 for anyone: see its own header)
2020 server/util.om (this contract: globals f*, helpers f*, texts tf*)
21-server/repos.om (allow-list loader, repo metadata)
21+server/repos.om (allow-list helpers, repo metadata: both repository sources use them)
22+server/radsrc.om (Radicle source: RIDS.md allow-list, routing table; or .build/store.om + store/repos.om)
23+nodes/head.om (default branch from HEAD; or store/head.om)
2224 browse/*.om or server/nobrowse.om ForgeBrowse prefix br* (fns), gb* / tb* (globals / texts)
23-dl/*.om or server/nodl.om ForgeDownloads prefix dl*, gd* / td*
25+dl/*.om or server/nodl.om ForgeDownloads prefix dl*, gd* / td* (dl/dlclone.om: the clone panel)
2426 collab/*.om or server/nocollab.om ForgePatches prefix co*, gc* / tc*
2527 social/*.om or server/nosocial.om ForgeSocial prefix so*, gs* / ts*
2628 server/json.om server/counts.om (ForgeServer: JSON form fj* / tfj*, counts fz* / tfz*; docs/API.md)
29+store/moving.om (store-reading build only: the 503 "moving" answer mv*, fmvng; docs/API.md)
2730 growth/*.om or server/nogrowth.om ForgeGrowth prefix gr* / gg* / tg*; docs/GROWTH.md; after counts so it can read them
31+ (store-reading build: store/mvgrowth.om, /trending and /trending.json answer 503)
2832 salvage/[0-9][0-9]*.om or server/nosalvage.om salvage (submissions) prefix sl* / gl* / tl*; docs/SALVAGE.md;
2933 needs collab/ and social/ composed; salvage/collector.om is its own program
34+ (store-reading build: store/mvsalvage.om, salvage/... answers 503)
35+community/[0-9][0-9]*.om or server/nocommunity.om Community Machines prefix cm_*; docs/COMMUNITY.md
36+ (store-reading build: store/mvcommunity.om, community/... answers 503)
3037 open/route.om or server/noopen.om open builds (Open Humanity shelf) prefix oh* / go* / to*; docs/OPEN-BUILDS.md;
3138 needs salvage/ composed; open/intake.om is its own program
39+ (store-reading build: store/mvopen.om, open/..., open.json, bring.sh, get.sh,
40+ withdraw.sh answer 503)
3241 research/route.om or server/noresearch.om research pages and questions prefix rx* / gx* / tx*; research/README.md
3342 salvage, open and research each define <prefix>nav (slnav, ohnav, rxnav): one
3443 entry in the forge row of server/pages.om fhead; the seam defines it empty
44+door/*.om or server/nodoor.om the agent door: event stream, feed prefix ev* / gev* / tev*; docs/AGENT-DOOR.md;
45+ needs collab/ and social/ composed; evnav is its forge row entry
46+.build/agents.om server/agents.om (ForgeServer: agents.json, fqa* / tfqa*; .build/agents.om is server/agents.tsv
47+ compiled by run.sh at every build)
3548 server/pages.om server/jsonp.om (jsonp: the JSON of every other page, fy* / tfy*; after pages.om for its globals)
3649 server/route.om server/main.om
3750 ```
@@ -48,6 +61,33 @@ server/route.om server/main.om
4861 - The seam `server/no<slice>.om` defines your required functions with "not available" behaviour
4962 (route returns 0; nodl also defines an empty `dlclone`).
5063
64+### Store-reading build (interplane-native DESIGN.md step 2)
65+
66+`FORGE_STORE=<absolute store root> FORGED_OUT=<path> ./run.sh build` (optional
67+`FORGE_CLONE_BASE=https://<host>/<path>/`) builds the same source with a second repository source.
68+`run.sh storegen` writes `.build/store.om` (texts `tfsroot`, `tfcbase`, const `FSCB`), composed after
69+`server/repos.om`, and these units are composed in place of the default ones:
70+
71+| Default unit | Store-reading unit | What it gives |
72+|---|---|---|
73+| `server/radsrc.om` | `store/repos.om` | the allow-list, reload check, identifiers, identity words, JSON clone object, footer line, routing table |
74+| `nodes/head.om` | `store/head.om` | the default branch (the catalog's field instead of the HEAD file) |
75+| `dl/dlclone.om` | `store/clone.om` | the clone panel (no `rad clone` line; HTTPS only with a clone base) |
76+| `collab/`, `quiet/`, `growth/`, `salvage/`, `community/`, `open/` | their `server/no<slice>.om` seams | collab and quiet read Radicle patches and issues; growth, salvage, community and open need collab or salvage |
77+| `research/intake-route.om` | `research/noadd.om` | the intake runs `rad` through the open shelf |
78+
79+Both sources define the same words, used by the units around them: `fload` (fills the allow-list, returns
80+the count or -1), `fsrcchg` (true when the source changed: RIDS.md mtime, or the catalog's inode, size and
81+mtime), `fputid i` (the identifier in machine forms: `rad:<RID>` or `git:<64-hex id>`), `fhasal i` (repo i
82+has an old Radicle id), `fradsrc` (Radicle node data may be read: server/counts.om `fzseeds` and its line),
83+`fradwalk` / `fradseeds i` (the routing table), `fpjterms` (the identity words of the "For developers"
84+section), `fjclone i` (the JSON clone object) and the text `tfsf4` (the footer line). `fkgit` / `fkgiti`
85+stay in server/util.om: `store/repos.om` sets `fsrcst` to 1 and `fsrt` to the store root when it loads,
86+and they then name `<root>projects/<name>/repo.git`. `deploy` and `restart` refuse `FORGE_STORE`; a
87+store-reading build never writes `server/forged`. The store layout and its rules are interplane-native's
88+CONTRACT.md v0; `store/repos.om` says which of them forged checks. `store/tests/compare.sh` is the
89+acceptance test.
90+
5191 ## 2. Request (set by the server before dispatch; read only)
5292
5393 Scalars are `global X ulong 1`, read with `get X 0`.
@@ -62,9 +102,9 @@ Scalars are `global X ulong 1`, read with `get X 0`.
62102 | `fip`, `fipl` | uchar 64 | client IP: `X-Real-IP` from nginx when present, else `127.0.0.1` |
63103 | `fbase`, `fbasel` | uchar 64 | `/` or `/forge/` (from `X-Forge-Base`; any other value = `/`). Always ends in `/` |
64104 | `fridx` | ulong 1 | allow-list index of the repo for `/<owner>/<repo>/...`, else 9999 |
65-| `frid`, `fridl` | uchar 64 | that repo's RID **without** `rad:` |
105+| `frid`, `fridl` | uchar 64 | that repo's key: its RID **without** `rad:` (store-reading build: the old RID from record 1, or the 64-hex id of a project without one) |
66106 | `fown`, `fownl` | uchar 64 | owner segment (`drakestapleton`) |
67-| `frepo`, `frepol` | uchar 128 | repo name exactly as in RIDS.md |
107+| `frepo`, `frepol` | uchar 128 | repo name exactly as in the allow-list |
68108 | `frest`, `frestl` | uchar 4096 | the path after `/<owner>/<repo>`; empty for the repo home, else starts with `/` (e.g. `/tree/main/src`) |
69109 | `fuser`, `fuserl` | uchar 64 | signed-in user name; `fuserl` 0 = signed out (set by `sosess`) |
70110 | `fcsrf`, `fcsrfl` | uchar 64 | the session's CSRF token (set by `sosess`), for hidden form fields |
@@ -72,15 +112,29 @@ Scalars are `global X ulong 1`, read with `get X 0`.
72112 | `forig`, `forigl` | uchar 256 | `Origin` header value (empty when absent) |
73113 | `facc`, `faccl` | uchar 512 | `Accept` header value (cut at 512); `fjwant` is true when it names `application/json` and not `text/html` |
74114
75-Allow-list (loaded at start and on SIGHUP from spark `~/handoffs/radicle/RIDS.md`, first table only):
76-`fan` (count), and per index `i < fan`: `fputrn i` appends the name, `fputrid i` the RID (no `rad:`),
77-`frnlen i`/`fridlen i` lengths, `frnbyte i k`/`fridbyte i k` one byte. `frepoix` returns the index of the
78-repo whose name equals `frepo[0,frepol)` or 9999. A repo not in the table does not exist for any
79-handler: the server returns 404 before dispatch, and handlers MUST NOT read other storage dirs.
115+Allow-list (loaded at start, on the reload flag, and when the source changes): default build from spark
116+`~/handoffs/radicle/RIDS.md`, first table only; store-reading build from `<store>/catalog.tsv`: every
117+public line (there is no served list since 2026-11-14; RIDS.md is not read), every project checked as
118+`store/repos.om` says (folders not links, record 1 hashes to the id and names the same project, deny
119+list by name or old id, no old id already served, head equal to `refs/heads/<branch>`; a malformed
120+catalog serves nothing; a private line is skipped; a project that fails a check is left out with one
121+stderr line). `fan` (count), and per index `i < fan`:
122+`fputrn i` appends the name, `fputrid i` the key (no
123+`rad:`), `fputid i` the identifier (the bare `<RID>` since 9a4420a / `git:<id>`), `frnlen i`/`fridlen i` lengths,
124+`frnbyte i k`/`fridbyte i k` one byte. `frepoix` returns the index of the repo whose name equals
125+`frepo[0,frepol)` or 9999. A repo not in the table does not exist for any handler: the server returns 404
126+before dispatch, and handlers MUST NOT read other storage dirs. The table holds `FAMAX` (256)
127+repositories (`fano` and the per-repo arrays, every loop over them `bound FAMAX`); a project past it is
128+left out alone ("the allow-list table is full"), and `store/tests/capacity.sh` alarms when the store's
129+public lines (or, in the default build, the RIDS.md first table) pass 192. In the store-reading build
130+the sandbox (`infra/spark/forged-sandbox.sh` with `FORGED_STORE`) holds only the projects
131+`forged-public.sh store_names` selects (public, valid name, not denied); a project created after the
132+start is bound at the next start.
80133
81-Constants: `FSTORE` text `tfstore` = `/home/drakestapleton/.radicle/storage/` and `tfgit` = `/usr/bin/git`,
82-`tfdata` = `/home/drakestapleton/forge-data/`. Owner name text `tfowner` = `drakestapleton`,
83-owner NID text `tfnid` = `z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK`.
134+Constants: `tfgit` = `/usr/bin/git`, `tfdata` = `/home/drakestapleton/forge-data/`. Default build:
135+`tfstore` = `/home/drakestapleton/.radicle/storage/` (server/util.om, used by fkgit / fkgiti while `fsrcst` is 0); store-reading build: `tfsroot`
136+(.build/store.om). Owner name text `tfowner` = `drakestapleton`, owner NID text `tfnid` =
137+`z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK` (the namespace of copied Radicle refs).
84138
85139 ## 3. Response (written by the handler)
86140
@@ -163,7 +217,7 @@ The edge CSP forbids inline `style=` and `<style>`: use class names from the ser
163217 `:root` line and, between the site-chrome marks, its header and footer rules, made at every build by
164218 `server/chromegen.om` from interplane.io `public/style.css`; checked by `server/tests/sitechrome.sh`) and the
165219 texts `tfcssv` and `tfcss2..9` in `server/pages.om` (ask ForgeServer to add a class). `frepohd tab` and `dlclone` (the clone panel: rad, git over HTTPS, zip/tar.gz) are in
166-pages.om / dl.om.
220+pages.om / dl/dlclone.om (store-reading build: store/clone.om, git over HTTPS only with a clone base, zip/tar.gz).
167221
168222 ## 4. Helpers in server/util.om
169223
@@ -185,7 +239,7 @@ pages.om / dl.om.
185239 | `fbget n view uchar * to long` | same for the urlencoded POST body `fbody` |
186240 | `flocb`, `flocc c uchar`, `floct t view uchar *` | build `floc`: base, then bytes |
187241 | `fsetct t view uchar *`, `fsetcd t view uchar *`, `fsetti t view uchar *`, `ftic c`, `fcdc c`| set content type, Content-Disposition, title (and byte variants) |
188-| `fkgit` / `fkgiti i ulong` | start an argv in `fpk` (uchar 8192): `/usr/bin/git --git-dir=<storage>/<rid>` for the current repo / repo i |
242+| `fkgit` / `fkgiti i ulong` | start an argv in `fpk` (uchar 8192): `/usr/bin/git --git-dir=<storage>/<rid>` (store-reading build, `fsrcst` 1: `<store>/projects/<name>/repo.git`) for the current repo / repo i |
189243 | `fkb`, `fka t view uchar *`, `fkopen`, `fkc c uchar` | argv builder (`fkb` empty; `fka` add an arg; `fkopen` start an arg and `fkc` append bytes to it) |
190244 | `fexec tmo long to long` | fork + execprog argv `fpk` (no shell, empty env, stdin/stderr `/dev/null`, stdout into `fxo` uchar 16777216, length `fxol`; `fxotr` 1 when cut). Returns exit status, -1 timeout (killed), -2 cannot start |
191245 | `fxput a ulong n ulong` / `fxesc a ulong n ulong` | append `fxo[a,a+n)` raw / escaped to `fob` |

docs/FEATURES.md

@@ -8,11 +8,13 @@ running binary is PLANNED here until ForgeServer integrates and tests it.
88
99 Owners: Server = ForgeServer (`server/`), Browse = ForgeBrowse (`browse/`), DL = ForgeDownloads
1010 (`dl/`), Collab = ForgePatches (`collab/`), Social = ForgeSocial (`social/`), Infra = ForgeInfra
11-(`infra/`).
11+(`infra/`), Door = the agent door (`door/`, `server/agents.om`).
1212
1313 Fixed design limits (decisions, not gaps): no JavaScript anywhere (server-rendered HTML, plain form
14-POST + redirect); Radicle is the source of truth, so the forge never writes git or Radicle data from
15-the web; only the 28 repositories of the public table in `~/handoffs/radicle/RIDS.md` exist.
14+POST + redirect); Radicle is the source of truth of the live binary, so the forge never writes git or
15+Radicle data from the web; only the 28 repositories of the public table in `~/handoffs/radicle/RIDS.md`
16+exist. The store-reading build (row "Native store" below) serves the public lines of an Interplane
17+store's `catalog.tsv` instead; it is built and tested, not deployed.
1618
1719 Last full update: 2026-11-07 11:15Z, head of `main` in spark `~/work/forge/web` (live binary: server + browse + dl + collab + social).
1820 Unclaimed feature paths answer a styled 501 "Coming soon" page, never a crash or a blank page.
@@ -25,7 +27,8 @@ Unclaimed feature paths answer a styled 501 "Coming soon" page, never a crash or
2527 | Repository home | Name, description, file list, README, clone box | README first (ForgeReadmeFirst, 2026-11-11): a short header (name, the description, "Brought by", the state, one "Get it" button: the releases page when the repo has a tag, else the zip of the default branch, and the star / watch forms), tabs (About, Files, History, Releases, Proposed changes, Issues, For developers), the README large; no README: a plain note and the file list. Then the section "For developers: proof and records" (`<repo>#For-developers`): RID, delegate, seed, refs and HEAD, patch and receipt each explained in one line, the three count lines, branch bar, clone panel, newest commit, file list and a link to every record page. Every earlier address answers as before (`server/tests/readmefirst.sh` part A) | DONE | Server, Browse, DL |
2628 | Project state | (mine) whether anyone rebuilt it | `server/state.om`: "Checked: ran again on <date>" only when the Interplane receipts list (`content/receipts/ledger.tsv` at HEAD of rad:z399yKvnXcBQNkKoq86iBDgTvQ5QV, on the allow-list) verifies as `verify.sh` walks it, holds a BUILD record and, among the neighbouring records of the same time, a SOURCE record of the same writer naming `rad:<RID>`, and the BUILD evidence file hashes to its name; the header says whether that was the version shown or an earlier one. Anything else is "Unfinished: not checked yet". Checked against an independent shell reading of the list on the real list and six made-up ones, with a mutant (`server/tests/readmefirst.sh` part B) | DONE | Server |
2729 | Canonical URLs | `/<owner>/<repo>` | `/<owner>/<repo>` with owner `drakestapleton`; `/<owner>/<repo>/` redirects (301) to it, query kept; `/rad:<RID>[/...]` redirects (302) to it; non-public RIDs are 404 | DONE | Server |
28-| Private / hidden repositories | Visible only to members | Anything outside the RIDS.md public table is 404 even by direct URL (fail closed, reloaded on SIGHUP / flag) | DONE | Server |
30+| Private / hidden repositories | Visible only to members | Anything outside the RIDS.md public table is 404 even by direct URL (fail closed, reloaded on SIGHUP / flag); in the store-reading build, any catalog line whose visibility is not `public`, and any project folder the catalog does not list | DONE | Server |
31+| Native store (store-reading build) | (mine) the projects of Interplane's own store, no Radicle underneath (interplane-native DESIGN.md step 2) | `FORGE_STORE=<root> FORGED_OUT=<path> ./run.sh build` (optionally `FORGE_CLONE_BASE=https://.../`): the project list is every public line of the store's `catalog.tsv` less the deny list (no separate served list, RIDS.md is not read; a malformed, duplicate or unreadable catalog serves nothing and says why on stderr; reloaded on the flag and when the catalog changes); Git is read from `projects/NAME/repo.git`; a project folder or repo.git that is a link, a record 1 that does not hash to the catalog id or names another project, a deny-listed name or old id, or a head the branch does not have is left out. `/rad:<RID>` links and stars already in the social log resolve through the old id in record 1; new identifiers are `git:<id>` (a project without an old id is served under it); no `rad clone` line. Patches, issues, routing counts, insights and the research intake answer as their seams; the Salvage Yard, Community Machines, Open builds (with bring.sh, get.sh, withdraw.sh) and trending answer 503 "This part is moving to the new Interplane store and is not available yet." with no Retry-After (`forge/error/1` with `"reason":"moving"` as JSON; docs/API.md). The sandbox binds only the served projects. Pages and their JSON forms are byte-identical to the Radicle binary apart from listed lines that name Radicle (`store/tests/compare.sh`). Not deployed; the allow-list table holds FAMAX (256) projects, a public line past it is left out with a stderr line, and `store/tests/capacity.sh` alarms at 192 public lines | PARTIAL | Server |
2932 | Tree view | Browse directories at a ref | `/<o>/<r>/tree/<ref>/<path>` via `git ls-tree`: directories first, sizes, breadcrumbs, latest commit; a file path redirects (302) to blob; unknown ref or path 404 | DONE | Browse |
3033 | File view | Show a file with line numbers and anchors | `/<o>/<r>/blob/<ref>/<path>` with `id="L<n>"` line anchors; `.md` rendered, `?plain=1` for source; a directory path redirects (302) to tree | DONE | Browse |
3134 | Raw file | Serve file bytes unrendered | `/<o>/<r>/raw/<ref>/<path>`: text as `text/plain; charset=utf-8`, images / PDF with their type, anything else `application/octet-stream` as an attachment; raw responses carry a sandbox CSP (`sandbox; default-src 'none'`). Up to 8 MiB from memory; 8 MiB to 512 MiB written once to the archive cache and streamed (shares the 2 cold builds / 60 s cap, 503 + Retry-After); above 512 MiB 404 and the blob page says the file is too large to show, with no raw link | DONE | Browse, DL |
@@ -40,7 +43,7 @@ Unclaimed feature paths answer a styled 501 "Coming soon" page, never a crash or
4043 | Tags | List tags | `/<o>/<r>/tags`; tags are also listed as releases on `/releases` | DONE | Browse |
4144 | History of a file | Commits that touched a path | `/<o>/<r>/commits/<ref>/<path>` | DONE | Browse |
4245 | Permalinks | Links pinned to a commit sha | tree / blob / raw accept a full commit sha as the ref | DONE | Browse |
43-| Clone URLs | HTTPS / SSH clone | Clone panel on the repo home: `rad clone rad:<RID>`, `git clone https://www.aienos.com/rad/<RID>.git` (git-over-HTTPS by the rad-http service; `info/refs` answers 200), zip / tar.gz, and the one-command `forge-contribute` (arguments in docs/ANNOYANCES.md). No SSH clone | PARTIAL | DL, Infra, simplify |
46+| Clone URLs | HTTPS / SSH clone | Clone panel on the repo home: `rad clone rad:<RID>`, `git clone https://www.aienos.com/rad/<RID>.git` (git-over-HTTPS by the rad-http service; `info/refs` answers 200), zip / tar.gz, and the one-command `forge-contribute` (arguments in docs/ANNOYANCES.md). No SSH clone. Store-reading build: no `rad clone` and no `forge-contribute` line; `git clone <base>projects/<name>/repo.git` only when built with `FORGE_CLONE_BASE` (no server answers that address yet) | PARTIAL | DL, Infra, simplify |
4447 | Code search (global) | Search code across repositories | `/search?q=`: case-insensitive fixed-string `git grep` over every public repo's default branch in allow-list order, at most 5 hits per file and 100 in total, links to `blob/<branch>/<path>#L<n>`. Each grep is stopped once the page has the lines it can still show, so a common word no longer scans whole trees; the page bytes are the same as reading every grep to the end (`nodes/tests/ab.sh check`); time in `docs/PERF.md` | DONE | Server |
4548 | Code search (one repo) | Search inside one repository | `/<o>/<r>/search?q=`: fixed-string `git grep` on the default branch, hits link to `blob/...#L<n>` | DONE | Browse |
4649 | Repository search | Search repositories by name / description | `/search?q=`: case-insensitive substring on name and description | DONE | Server |
@@ -95,7 +98,7 @@ Unclaimed feature paths answer a styled 501 "Coming soon" page, never a crash or
9598 | Fork | Copy a repo under your account | Not on the web: forking is `rad fork` in the Radicle CLI | PLANNED | Server |
9699 | Notifications | Inbox of activity | `/notifications` and `/notifications.json`: one digest per signed-in name, filtered by agent and repo, written when a filter is saved or a patch event arrives, never on a clock. A read does not create the file. Not in the live binary until this branch is reviewed and deployed | PLANNED | simplify |
97100 | Profiles | User page with repos, stars, followers | `/drakestapleton`: did:key, follower / following counts, stars and favorites received, repo list, follow form; signed-in users have their own profile | DONE | Server, Social |
98-| Activity feed | Recent events of followed accounts | Not yet | PLANNED | Social |
101+| Activity feed | Recent events of followed accounts | `<base>feed`: every public event of the forge, newest first, 50 a page (`?before=<seq>`), one plain sentence each with who did it (their page) and a link to the thing; `?format=text`; JSON alternate `<base>events.json`; "Feed" in the forge row. All public activity, not only followed accounts (no per-reader filter yet). Built from `door/` and tested on a host test copy (`server/tests/agentdoor.sh`); not in the live binary until this branch is reviewed and deployed. `docs/AGENT-DOOR.md` | HOST_TESTED | Door |
99102 | Sponsors | Fund maintainers | Not offered | PLANNED | Server |
100103
101104 ## Accounts and security
@@ -126,9 +129,10 @@ Unclaimed feature paths answer a styled 501 "Coming soon" page, never a crash or
126129 | Packages | Package registry | Not offered | PLANNED | Server |
127130 | Pages | Static site hosting | interplane.io and aienos.com are served by the hub; not per repo | PLANNED | Infra |
128131 | Codespaces | Cloud dev environments | Not offered | PLANNED | Server |
129-| REST API | JSON API with GitHub-like shapes | `/api` reserved; GitHub-compatible shapes (`/repos/<o>/<r>`, `/users/<u>`) PLANNED. The pages' own machine form is the next row | PLANNED | Server |
132+| REST API | JSON API with GitHub-like shapes | `/api` reserved; GitHub-compatible shapes (`/repos/<o>/<r>`, `/users/<u>`) PLANNED. The pages' own machine form, the agent front door and the event stream are the next rows | PLANNED | Server |
130133 | Machine form of pages (JSON) | (ours) every page readable by agents at its own URL | `<base>explore.json` (`forge/explore/1`) and `<base><o>/<r>.json` (`forge/repo/1`), or the same URLs with `Accept: application/json` (without `text/html`); RIDs and full shas as ids, ISO-8601 UTC times, stable keys; `<link rel="alternate" type="application/json">` on both HTML pages; denied repos 404; schemas in `docs/API.md`. Other pages have no JSON form yet. Built and tested on a trial build (`server/tests/counts.sh`, smoke on the trial); live test pending the deploy | PLANNED | Server |
131134 | Machine form of every other page | (ours) the rest of the pages readable by agents at their own URL | Tree, blob, blame, repo search, commits, commit, compare, branches, tags, releases, release, patches, patch, issues, issue, stargazers, watchers, profiles and their followers / following tabs, signed-in stars, global search: the page's own URL with `Accept: application/json` (`forge/tree/1` ... `forge/search/1`); same facts as the HTML page, full shas and RIDs as ids, `<link rel="alternate" type="application/json">` naming the page's own URL; errors as `forge/error/1` with the HTML status (refused repos 404 on every page); raw bytes, forms and redirects unchanged; schemas in `docs/API.md`. Tested on a trial build by `server/tests/jsonpages.sh` (every page type of every public repo under both bases, HTML byte-equal to the build before); live test pending the deploy | PLANNED | Server, Browse, DL, Patches, Social |
135+| Agent front door and event stream | (ours) one list of every machine-readable address; activity read from where the agent stopped | `<base>agents.json` (`interplane/agents/1`): every JSON address with its template, how to ask for JSON, schema, auth and purpose, compiled from `server/agents.tsv`, plus what is not available. `<base>events.json?after=<seq>&limit=<n>` (`interplane/events/1`): append-only stream (14 kinds, stable `seq`, source ids, `ETag`/304), change-triggered collection into `<data>events/log`. Tested on a host test copy with fixtures, restart, paging and three negative controls (`server/tests/agentdoor.sh`); not deployed. `docs/AGENT-DOOR.md` | HOST_TESTED | Door, Server |
132136 | GraphQL API | Query API | Not planned | PLANNED | Server |
133137 | Webhooks | POST events to URLs | Not offered (no outbound calls) | PLANNED | Server |
134138 | Apps / OAuth | Third-party app auth | Not offered | PLANNED | Social |
@@ -159,7 +163,7 @@ Unclaimed feature paths answer a styled 501 "Coming soon" page, never a crash or
159163 | Keyboard shortcuts | Hotkeys | Not offered (needs JS) | PLANNED | Server |
160164 | Access log | (platform) | One line per request to stderr: epoch, IP, method, path, status, bytes, ms | DONE | Server |
161165 | Node health | (mine) | `/status` and `/status.json`: this node's connected peers and, for each public repository, seeding scope, how many other nodes hold our signed copy, how many of those are behind, seconds our latest version took to reach them and seconds it has been waiting on the ones behind. Written by `nodes/snap.om` when the node reports events (no timer); the page shows when it was checked and flags a snapshot older than a day. Withdrawn RIDs and lines with markup are never shown. `docs/NODES.md` | DONE | Server |
162-| Reload without restart | (platform) | Allow-list and social log re-read when RIDS.md changes or `~/forge-data/reload` appears (SIGHUP via the supervisor) | DONE | Server, Infra |
166+| Reload without restart | (platform) | Allow-list and social log re-read when RIDS.md changes (store-reading build: when `catalog.tsv` gets another inode, size or mtime) or `~/forge-data/reload` appears (SIGHUP via the supervisor). A list that cannot be read now serves nothing and logs `public repos 0`; before 2026-11-13 it stopped forged (trap 5 in `freload`) | DONE | Server, Infra |
163167
164168 ## Gate receipts: exact reader behaviour
165169

docs/social.md

@@ -105,8 +105,14 @@ the data dir can rewrite the whole chain and head. The data dir is the trust bou
105105 ## Evidence
106106
107107 `social/tests/run.sh` builds a test copy (data dir under a temp dir, port 18489), creates throwaway ed25519 keys,
108-and drives the server with curl (build and helpers: `social/tests/lib.sh`). Last run: `social/tests/last-run.txt`
109-(88 passed, 0 failed). It covers the full sign-in, the `__Host-` cookies (Path=/, no Domain) under both bases
108+and drives the server with curl (build and helpers: `social/tests/lib.sh`). The test copy's units come from the
109+build itself: `./run.sh seams` lists them in the build's order with every slice as its seam, and
110+`social/tests/units.sh` puts `social/*.om` in place of `server/nosocial.om`; `social/tests/units-check.sh` runs
111+first and fails the build when lib.sh types a unit list or when an order change in run.sh would not reach the
112+test copy. `STORE_VARIANT=1` exports `FORGE_STORE` (default `~/interplane-store-owner`, read only), so the same
113+two commands list the store-reading source in place of the Radicle one; every other unit is the same.
114+Last run, with its counts: `social/tests/last-run.txt`. It covers the full sign-in, the `__Host-`
115+cookies (Path=/, no Domain) under both bases
110116 with a session working under `/forge/`, star 1 / unstar 0 / double star 1, favorites, watchers, follows,
111117 restart and in-process reload, an independent Python check of the chain, and the negatives: forged
112118 signature, a challenge spent by one failed attempt, malformed signature, tampered form MAC, missing pre

door/READY

new file mode 100644
@@ -0,0 +1 @@
1+composed: the agent door (event stream, feed). Set by AgentDoor (mac-omp) with server/tests/agentdoor.sh passing; the parent removes it if it lands without the live test.

door/ev1decl.om

new file mode 100644
@@ -0,0 +1,497 @@
1+note door/ (the agent door, docs/AGENT-DOOR.md): the public activity stream <base>events.json
2+note (schema interplane/events/1, also <base>events and <base>feed with Accept: application/json),
3+note the feed page <base>feed, and their store: the append-only, hash-chained file <data>events/log.
4+note Names: functions ev*, globals gev*, texts tev*. Needs collab/ (corefs, coload: the COB model) and
5+note social/ (the social log parser and the account names) composed; otherwise run.sh composes the
6+note seam server/nodoor.om, which answers 501 for these pages.
7+note Collection is change-triggered, never on a clock: before a page of the stream is answered, evcollect
8+note compares cheap fingerprints (the size of the social log, the change time of the open shelf list,
9+note and per public repository the change times of the ref folders that every Radicle ref update
10+note renames into) with the last ones and reads only what changed (docs/AGENT-DOOR.md).
11+note Log line, tab-separated, sanitized (no tab, newline or control byte inside a field):
12+note seq time kind actor rid source path json x subject prev
13+note seq from 1, time epoch seconds from the source record, kind 1..14, actor a did:key or empty, rid
14+note without rad: or empty, source the object id the event was read from, path and json relative to
15+note the base, x the verdict word (review) or "<old sha> <count>" (branch moved) or the followed did
16+note (follow) or the shelf name (open), prev the hex sha256 of the previous line (64 zeros for line 1).
17+const EVMAX ulong 262144
18+const EVLMAX ulong 8192
19+const EVBMAX ulong 32768
20+text tevdir "events"
21+text tevrdir "events/r"
22+text tevlog "events/log"
23+text tevrp "events/r/"
24+text tevtmp ".tmp"
25+text tevlist "open/list.tsv"
26+text tevfer "for-each-ref"
27+text tevfmt "--format=%(objectname) %(creatordate:unix) %(refname)"
28+text tevrh "refs/heads/"
29+text tevrt "refs/tags"
30+text tevrtp "refs/tags/"
31+text tevns "refs/namespaces/"
32+text tevnst "/refs/tags"
33+text tevnstp "/refs/tags/"
34+text tevcpg "refs/namespaces/*/refs/cobs/xyz.radicle.patch/*"
35+text tevcig "refs/namespaces/*/refs/cobs/xyz.radicle.issue/*"
36+text tevcpm "/refs/cobs/xyz.radicle.patch/"
37+text tevcim "/refs/cobs/xyz.radicle.issue/"
38+text tevrl "rev-list"
39+text tevcnt "--count"
40+text tevdots ".."
41+text tevsrh "/refs/heads"
42+text tevsrt "/refs/tags"
43+text tevsns "/refs/namespaces"
44+text tevspk "/packed-refs"
45+text tevsrad "/refs/rad"
46+text tevdidk "did:key:"
47+text tevsocs "social.log:"
48+text tevopns "open/list.tsv:"
49+text tevopnp "open/"
50+text tevopnj "open.json"
51+text tevjsx ".json"
52+text tevpatp "/patches/"
53+text tevissp "/issues/"
54+text tevrelp "/releases/tag/"
55+text tevcmpp "/compare/"
56+text tevtdot "..."
57+text tevheld "held"
58+text tevstor "stored"
59+text tevwdr "withdrawn"
60+text tevvacc "accept"
61+text tevvrej "reject"
62+text tevmovd " moved"
63+text tevncom " new commit"
64+text tevncs "s"
65+text tevon " on "
66+text tevlbad "EVENTS-LOG TAMPER: events off at line "
67+text tevlwr "EVENTS-LOG write failed: events off"
68+text tevlpas "events: pass "
69+text tevlpus " us, sources read "
70+text tevlpev ", events added "
71+text tevlcob "events: COB not loaded, no events from it: "
72+text tevlcut "events: ref list longer than the buffer, repository skipped: "
73+text tevlbfl "events: batch full, flushed early"
74+note the log index: gevoff[k] is the byte offset of line k (seq k+1); gevoff[gevn] is the end
75+global gevoff ulong 262145
76+global gevn ulong 1
77+note gevok: 0 not loaded, 1 loaded and appendable, 2 refused (the chain did not verify, a write failed)
78+global gevok ulong 1
79+global gevprv uchar 32
80+note gevset: open-addressing set of event keys (FNV-1a 64 of kind, rid, source and x; never 0)
81+global gevset ulong 524288
82+note per allow-list index: the fingerprint of the repository's ref folders when it was last read
83+global gevfp ulong 256
84+note the social log bytes already read, and the open list fingerprint
85+global gevsoff ulong 1
86+global gevofp ulong 1
87+note read buffer (log lines, social lines), the old ref snapshot of one repository, the new one
88+global gevrb uchar 2097152
89+global gevold uchar 4194304
90+global gevoldl ulong 1
91+global gevnew uchar 4194304
92+global gevnewl ulong 1
93+global gevst uchar 128
94+global gevde uchar 16384
95+note the line being written
96+global gevln uchar 8192
97+global gevlnl ulong 1
98+note the event being built: kind, time, and its byte fields (each a buffer and its length)
99+global gevk ulong 1
100+global gevt ulong 1
101+global gevact uchar 128
102+global gevactl ulong 1
103+global gevrid uchar 64
104+global gevridl ulong 1
105+global gevsub uchar 512
106+global gevsubl ulong 1
107+global gevpth uchar 1024
108+global gevpthl ulong 1
109+global gevjs uchar 1024
110+global gevjsl ulong 1
111+global gevsrc uchar 128
112+global gevsrcl ulong 1
113+global gevx uchar 192
114+global gevxl ulong 1
115+note the batch of one collection pass: partial lines (time .. subject) sorted by time before append
116+global gevbat uchar 16777216
117+global gevbatl ulong 1
118+global gevbo ulong 32768
119+global gevbl ulong 32768
120+global gevbt ulong 32768
121+global gevbi ulong 32768
122+global gevbj ulong 32768
123+global gevbn ulong 1
124+note counters of one collection pass (its stderr line names them with its cost in microseconds)
125+global gevpr ulong 1
126+global gevpe ulong 1
127+note changed COB ids of the repository being read: id (40 bytes) and kind (1 patch, 2 issue)
128+global gevcid uchar 163840
129+global gevckd ulong 4096
130+global gevcn ulong 1
131+note one stderr line (evgb, evgt, evgn, evgc, then evgout)
132+global gevlg uchar 512
133+global gevlgl ulong 1
134+fn evgb to void
135+put gevlgl 0 0
136+end
137+fn evgc c uchar to void
138+n = get gevlgl 0
139+if lt n 510
140+put gevlg n c
141+put gevlgl 0 add n 1
142+end
143+end
144+fn evgt t view uchar * to void
145+for i ulong len t bound 256
146+evgc get t i
147+end
148+end
149+fn evgn v ulong to void
150+d = new uchar 24 0
151+k = evdec v d
152+for j ulong k bound 24
153+evgc get d j
154+end
155+end
156+fn evgout to void
157+evgc 10
158+w = write 2 gevlg 0 get gevlgl 0
159+end
160+note ---- byte helpers for the line being written
161+fn evlc c uchar to void
162+n = get gevlnl 0
163+if lt n sub EVLMAX 1
164+put gevln n c
165+put gevlnl 0 add n 1
166+end
167+end
168+note evdec v d: the decimal digits of v into d at 0; returns their count
169+fn evdec v ulong d edit uchar 24 to ulong
170+t = new uchar 24 0
171+k = ulong 0
172+x = v
173+for it ulong 21
174+put t k uchar add rem x 10 48
175+k = add k 1
176+x = div x 10
177+if eq x 0
178+break
179+end
180+end
181+for j ulong k bound 24
182+put d j get t sub sub k j 1
183+end
184+ret k
185+end
186+fn evlnum v ulong to void
187+d = new uchar 24 0
188+k = evdec v d
189+for j ulong k bound 24
190+evlc get d j
191+end
192+end
193+note evsafe: a field byte as stored: tab, newline and the other control bytes become a space
194+fn evsafe c uchar to uchar
195+if or lt c 32 eq c 127
196+ret uchar 32
197+end
198+ret c
199+end
200+note ---- path helpers: fpth = <data><t>
201+fn evpath t view uchar * to void
202+fpb
203+fpt tfdata
204+fpt t
205+end
206+note evmkdirs: <data>events and <data>events/r (an existing folder is fine)
207+fn evmkdirs to void
208+evpath tevdir
209+x = makedir fpth 0 get fpthl 0 448
210+evpath tevrdir
211+y = makedir fpth 0 get fpthl 0 448
212+end
213+note evstat: stat fpth into gevst; a fingerprint of its change time and size, 0 when it is missing
214+fn evstat to ulong
215+r = stat fpth 0 get fpthl 0 gevst 0 128
216+if lt r 0
217+ret 0
218+end
219+h = ulong 14695981039346656037
220+for k ulong 8
221+h = evfnv h get gevst add 48 k
222+h = evfnv h get gevst add 104 k
223+h = evfnv h get gevst add 112 k
224+end
225+ret h
226+end
227+fn evst64 o ulong to ulong
228+v = ulong 0
229+for i ulong 8
230+b = ulong get gevst add o i
231+v = or v shl b mul i 8
232+end
233+ret v
234+end
235+note ---- event field setters (a collector fills one event, then evemit)
236+fn evclr to void
237+put gevk 0 0
238+put gevt 0 0
239+put gevactl 0 0
240+put gevridl 0 0
241+put gevsubl 0 0
242+put gevpthl 0 0
243+put gevjsl 0 0
244+put gevsrcl 0 0
245+put gevxl 0 0
246+end
247+fn evactc c uchar to void
248+n = get gevactl 0
249+if lt n len gevact
250+put gevact n evsafe c
251+put gevactl 0 add n 1
252+end
253+end
254+fn evactt t view uchar * to void
255+for i ulong len t bound 128
256+evactc get t i
257+end
258+end
259+fn evridc c uchar to void
260+n = get gevridl 0
261+if lt n len gevrid
262+put gevrid n evsafe c
263+put gevridl 0 add n 1
264+end
265+end
266+note evsubc: the subject is one line of at most 400 bytes (evsubend cuts it at a character start)
267+fn evsubc c uchar to void
268+n = get gevsubl 0
269+if lt n 400
270+put gevsub n evsafe c
271+put gevsubl 0 add n 1
272+end
273+end
274+fn evsubt t view uchar * to void
275+for i ulong len t bound 400
276+evsubc get t i
277+end
278+end
279+fn evsubend to void
280+n = get gevsubl 0
281+if lt n 400
282+ret
283+end
284+for it ulong 4
285+k = get gevsubl 0
286+if eq k 0
287+ret
288+end
289+c = get gevsub sub k 1
290+if ne and c 192 128
291+put gevsubl 0 sub k 1
292+ret
293+end
294+put gevsubl 0 sub k 1
295+end
296+end
297+note evpthc: one byte of a URL path, percent-encoded unless unreserved or /; evpthr: raw
298+fn evpthc c uchar to void
299+if evunres c
300+evpthr c
301+ret
302+end
303+evpthr 37
304+evpthr evhexu shr ulong c 4
305+evpthr evhexu and ulong c 15
306+end
307+fn evpthr c uchar to void
308+n = get gevpthl 0
309+if lt n len gevpth
310+put gevpth n c
311+put gevpthl 0 add n 1
312+end
313+end
314+fn evptht t view uchar * to void
315+for i ulong len t bound 64
316+evpthr get t i
317+end
318+end
319+fn evunres c uchar to bool
320+if and ge c 97 le c 122
321+ret true
322+end
323+if and ge c 65 le c 90
324+ret true
325+end
326+if and ge c 48 le c 57
327+ret true
328+end
329+ret or or eq c 45 eq c 46 or or eq c 95 eq c 126 eq c 47
330+end
331+fn evhexu v ulong to uchar
332+if lt v 10
333+ret uchar add v 48
334+end
335+ret uchar add v 55
336+end
337+note evpthrepo i: path = <owner>/<repo name of i>
338+fn evpthrepo i ulong to void
339+put gevpthl 0 0
340+evptht tfowner
341+evpthr 47
342+for k ulong frnlen i bound 128
343+evpthc frnbyte i k
344+end
345+end
346+note evjsame: json = path (the page answers JSON at its own address with Accept: application/json)
347+fn evjsame to void
348+n = get gevpthl 0
349+for k ulong n bound 1024
350+put gevjs k get gevpth k
351+end
352+put gevjsl 0 n
353+end
354+fn evjsc c uchar to void
355+n = get gevjsl 0
356+if lt n len gevjs
357+put gevjs n c
358+put gevjsl 0 add n 1
359+end
360+end
361+fn evjst t view uchar * to void
362+for i ulong len t bound 64
363+evjsc get t i
364+end
365+end
366+fn evsrcc c uchar to void
367+n = get gevsrcl 0
368+if lt n len gevsrc
369+put gevsrc n evsafe c
370+put gevsrcl 0 add n 1
371+end
372+end
373+fn evsrct t view uchar * to void
374+for i ulong len t bound 64
375+evsrcc get t i
376+end
377+end
378+fn evsrcnum v ulong to void
379+d = new uchar 24 0
380+k = evdec v d
381+for j ulong k bound 24
382+evsrcc get d j
383+end
384+end
385+fn evxc c uchar to void
386+n = get gevxl 0
387+if lt n len gevx
388+put gevx n evsafe c
389+put gevxl 0 add n 1
390+end
391+end
392+fn evxt t view uchar * to void
393+for i ulong len t bound 64
394+evxc get t i
395+end
396+end
397+note evridi i: the event is about allow-list repository i
398+fn evridi i ulong to void
399+put gevridl 0 0
400+for k ulong fridlen i bound 64
401+evridc fridbyte i k
402+end
403+end
404+note evowndid: the actor is the node delegate (did:key:<tfnid>)
405+fn evowndid to void
406+put gevactl 0 0
407+evactt tevdidk
408+evactt tfnid
409+end
410+note ---- FNV-1a 64
411+fn evfnv h ulong c uchar to ulong
412+x = xor h ulong c
413+ret mul x 1099511628211
414+end
415+note evkey: the key of the event being built (kind, rid, source, x)
416+fn evkey to ulong
417+h = evfnv ulong 14695981039346656037 uchar get gevk 0
418+h = evfnv h 0
419+for i ulong get gevridl 0 bound 64
420+h = evfnv h get gevrid i
421+end
422+h = evfnv h 0
423+for i ulong get gevsrcl 0 bound 128
424+h = evfnv h get gevsrc i
425+end
426+h = evfnv h 0
427+for i ulong get gevxl 0 bound 192
428+h = evfnv h get gevx i
429+end
430+if eq h 0
431+ret ulong 1
432+end
433+ret h
434+end
435+note ---- the key set
436+fn evhas k ulong to bool
437+m = sub len gevset 1
438+s = and k m
439+for it ulong len gevset
440+v = get gevset s
441+if eq v 0
442+ret false
443+end
444+if eq v k
445+ret true
446+end
447+s = and add s 1 m
448+end
449+ret false
450+end
451+fn evput k ulong to void
452+m = sub len gevset 1
453+s = and k m
454+for it ulong len gevset
455+v = get gevset s
456+if or eq v 0 eq v k
457+put gevset s k
458+ret
459+end
460+s = and add s 1 m
461+end
462+end
463+note ---- digits
464+fn evdig c uchar to bool
465+ret and ge c 48 le c 57
466+end
467+fn evhexd c uchar to bool
468+if evdig c
469+ret true
470+end
471+ret and ge c 97 le c 102
472+end
473+fn evhexc v ulong to uchar
474+if lt v 10
475+ret uchar add v 48
476+end
477+ret uchar add v 87
478+end
479+note evridpub: the allow-list index of the event's RID (gevrid, no rad:), 9999 when it is not public
480+fn evridpub to ulong
481+n = get gevridl 0
482+for i ulong get fan 0 bound FAMAX
483+if eq fridlen i n
484+same = true
485+for k ulong n bound 64
486+if ne fridbyte i k get gevrid k
487+same = false
488+break
489+end
490+end
491+if same
492+ret i
493+end
494+end
495+end
496+ret ulong 9999
497+end

door/ev2log.om

new file mode 100644
@@ -0,0 +1,416 @@
1+note door/ev2log.om: the event log. evload reads <data>events/log once (at the first page of the stream
2+note after a start or a reload), checks every line (seq, field count, the sha256 chain) and indexes
3+note it; a line that does not check switches the stream off (503, fail closed) and nothing is appended
4+note to a log that did not check. evemit puts one event in the batch of the current pass unless its
5+note key (kind, rid, source, x) is already in the log; evflush sorts the batch by time and appends it.
6+global gevtb ulong 16
7+global gevh2 uchar 32
8+fn evload to void
9+put gevok 0 2
10+evmkdirs
11+put gevn 0 0
12+put gevoff 0 0
13+for i ulong 32
14+put gevprv i 0
15+end
16+for i ulong len gevset
17+put gevset i 0
18+end
19+evpath tevlog
20+fd = fopen fpth 0 get fpthl 0 524288 0
21+if lt fd 0
22+if eq fd -2
23+put gevok 0 1
24+end
25+ret
26+end
27+pos = ulong 0
28+ok = true
29+for it ulong 1000000
30+r = pread int fd gevrb 0 len gevrb long pos
31+if lt r 0
32+ok = false
33+break
34+end
35+if eq r 0
36+break
37+end
38+u = evscan ulong r pos
39+if lt u 0
40+ok = false
41+break
42+end
43+if eq u 0
44+evtamper
45+ok = false
46+break
47+end
48+pos = add pos ulong u
49+end
50+x = fclose int fd
51+if ok
52+put gevok 0 1
53+end
54+end
55+fn evtamper to void
56+evgb
57+evgt tevlbad
58+evgn add get gevn 0 1
59+evgout
60+end
61+note evscan n pos: the complete lines of gevrb[0, n) (read at file offset pos); returns the bytes they
62+note take, -1 when a line does not check
63+fn evscan n ulong pos ulong to long
64+p = ulong 0
65+for it ulong 2097152
66+if ge p n
67+break
68+end
69+e = p
70+for k ulong 2097152
71+if ge e n
72+break
73+end
74+if eq get gevrb e 10
75+break
76+end
77+e = add e 1
78+end
79+if ge e n
80+break
81+end
82+if not evline p e
83+evtamper
84+ret -1
85+end
86+k = get gevn 0
87+put gevoff k add pos p
88+put gevn 0 add k 1
89+put gevoff add k 1 add pos add e 1
90+p = add e 1
91+end
92+ret long p
93+end
94+note evline a e: check the line gevrb[a, e) as line gevn+1, then chain it and add its key
95+fn evline a ulong e ulong to bool
96+n = sub e a
97+if or ge n EVLMAX ge get gevn 0 EVMAX
98+ret false
99+end
100+ln = new uchar 8192 0
101+for i ulong n bound 8192
102+put ln i get gevrb add a i
103+end
104+ret evlchk part ln 0 n
105+end
106+fn evlchk ln view uchar * to bool
107+if not evtabs ln
108+ret false
109+end
110+seq = evfnum ln 0
111+if ne seq add get gevn 0 1
112+ret false
113+end
114+pv = add get gevtb 9 1
115+if ne sub len ln pv 64
116+ret false
117+end
118+for i ulong 32
119+b = ulong get gevprv i
120+if ne get ln add pv mul i 2 evhexc shr b 4
121+ret false
122+end
123+if ne get ln add add pv mul i 2 1 evhexc and b 15
124+ret false
125+end
126+end
127+evclr
128+put gevk 0 evfnum ln 2
129+evfcopy ln 4 1
130+evfcopy ln 5 2
131+evfcopy ln 8 3
132+evput evkey
133+evsha ln
134+for i ulong 32
135+put gevprv i get gevh2 i
136+end
137+ret true
138+end
139+note evtabs ln: the positions of the 10 tabs of a line into gevtb[0..9]; false for another count
140+fn evtabs ln view uchar * to bool
141+k = ulong 0
142+for i ulong len ln bound 8192
143+if eq get ln i 9
144+if ge k 10
145+ret false
146+end
147+put gevtb k i
148+k = add k 1
149+end
150+end
151+ret eq k 10
152+end
153+note evfa f / evfe f: start and end of field f (0..10) of the line whose tabs are in gevtb
154+fn evfa f ulong to ulong
155+if eq f 0
156+ret 0
157+end
158+ret add get gevtb sub f 1 1
159+end
160+fn evfe f ulong ln ulong to ulong
161+if ge f 10
162+ret ln
163+end
164+ret get gevtb f
165+end
166+note evfnum ln f: the decimal number in field f (at most 19 digits), 0 for anything else
167+fn evfnum ln view uchar * f ulong to ulong
168+a = evfa f
169+e = evfe f len ln
170+if or eq a e gt sub e a 19
171+ret 0
172+end
173+v = ulong 0
174+for i ulong sub e a bound 19
175+c = get ln add a i
176+if not evdig c
177+ret 0
178+end
179+v = add mul v 10 ulong sub c 48
180+end
181+ret v
182+end
183+note evfcopy ln f w: field f into the event field w (1 rid, 2 source, 3 x)
184+fn evfcopy ln view uchar * f ulong w ulong to void
185+a = evfa f
186+e = evfe f len ln
187+for i ulong sub e a bound 8192
188+c = get ln add a i
189+if eq w 1
190+evridc c
191+end
192+if eq w 2
193+evsrcc c
194+end
195+if eq w 3
196+evxc c
197+end
198+end
199+end
200+note ---- the batch
201+fn evbc c uchar to void
202+n = get gevbatl 0
203+if lt n len gevbat
204+put gevbat n c
205+put gevbatl 0 add n 1
206+end
207+end
208+fn evbnum v ulong to void
209+d = new uchar 24 0
210+k = evdec v d
211+for j ulong k bound 24
212+evbc get d j
213+end
214+end
215+note evemit: the event built in the gev* fields joins the batch, unless its key is known
216+fn evemit to void
217+if or eq get gevk 0 0 eq get gevt 0 0
218+ret
219+end
220+k = evkey
221+if evhas k
222+ret
223+end
224+if or ge get gevbn 0 EVBMAX gt add get gevbatl 0 4096 len gevbat
225+flog tevlbfl
226+evflush
227+if ne get gevok 0 1
228+ret
229+end
230+end
231+evput k
232+evsubend
233+b = get gevbn 0
234+put gevbo b get gevbatl 0
235+put gevbt b get gevt 0
236+evbnum get gevt 0
237+evbc 9
238+evbnum get gevk 0
239+evbc 9
240+for i ulong get gevactl 0 bound 128
241+evbc get gevact i
242+end
243+evbc 9
244+for i ulong get gevridl 0 bound 64
245+evbc get gevrid i
246+end
247+evbc 9
248+for i ulong get gevsrcl 0 bound 128
249+evbc get gevsrc i
250+end
251+evbc 9
252+for i ulong get gevpthl 0 bound 1024
253+evbc get gevpth i
254+end
255+evbc 9
256+for i ulong get gevjsl 0 bound 1024
257+evbc get gevjs i
258+end
259+evbc 9
260+for i ulong get gevxl 0 bound 192
261+evbc get gevx i
262+end
263+evbc 9
264+for i ulong get gevsubl 0 bound 512
265+evbc get gevsub i
266+end
267+put gevbl b sub get gevbatl 0 get gevbo b
268+put gevbn 0 add b 1
269+put gevpe 0 add get gevpe 0 1
270+end
271+note evsort: gevbi = the batch indices ordered by time, equal times in batch order (bottom-up merge)
272+fn evsort to void
273+n = get gevbn 0
274+for i ulong n bound 32768
275+put gevbi i i
276+end
277+w = ulong 1
278+for pass ulong 20
279+if ge w n
280+break
281+end
282+lo = ulong 0
283+for it ulong 32768
284+if ge lo n
285+break
286+end
287+mid = add lo w
288+if gt mid n
289+mid = n
290+end
291+hi = add lo mul w 2
292+if gt hi n
293+hi = n
294+end
295+evmerge lo mid hi
296+lo = hi
297+end
298+for i ulong n bound 32768
299+put gevbi i get gevbj i
300+end
301+w = mul w 2
302+end
303+end
304+fn evmerge lo ulong mid ulong hi ulong to void
305+i = lo
306+j = mid
307+for k ulong sub hi lo bound 32768
308+if evtakel i mid j hi
309+put gevbj add lo k get gevbi i
310+i = add i 1
311+else
312+put gevbj add lo k get gevbi j
313+j = add j 1
314+end
315+end
316+end
317+note evtakel: the next merged entry comes from the left run (equal times keep batch order)
318+fn evtakel i ulong mid ulong j ulong hi ulong to bool
319+if ge i mid
320+ret false
321+end
322+if ge j hi
323+ret true
324+end
325+ret le get gevbt get gevbi i get gevbt get gevbi j
326+end
327+note evflush: append the batch in time order, each line with its seq and the chain, then fsync once
328+fn evflush to void
329+n = get gevbn 0
330+if eq n 0
331+ret
332+end
333+evsort
334+evpath tevlog
335+fd = fopen fpth 0 get fpthl 0 525377 384
336+if lt fd 0
337+evwfail
338+ret
339+end
340+ok = true
341+for q ulong n bound 32768
342+if ge get gevn 0 EVMAX
343+break
344+end
345+b = get gevbi q
346+if not evwline int fd b
347+ok = false
348+break
349+end
350+end
351+x = fsync int fd
352+y = fclose int fd
353+if not ok
354+evwfail
355+end
356+put gevbn 0 0
357+put gevbatl 0 0
358+end
359+fn evwfail to void
360+put gevok 0 2
361+flog tevlwr
362+end
363+note evwline fd b: write batch entry b as line gevn+1 (built in gevln, hashed, written, then indexed)
364+fn evwline fd int b ulong to bool
365+l = evwbuild b
366+if ge l sub EVLMAX 1
367+ret false
368+end
369+ret evwout fd l
370+end
371+fn evwbuild b ulong to ulong
372+put gevlnl 0 0
373+evlnum add get gevn 0 1
374+evlc 9
375+o = get gevbo b
376+for i ulong get gevbl b bound 8192
377+evlc get gevbat add o i
378+end
379+evlc 9
380+for i ulong 32
381+v = ulong get gevprv i
382+evlc evhexc shr v 4
383+evlc evhexc and v 15
384+end
385+ret get gevlnl 0
386+end
387+note evsha ln: sha256 of ln into gevh2
388+fn evsha ln view uchar * to void
389+c = new ulong 40 0
390+h = new uchar 32 0
391+sha256_init c
392+sha256_update c ln
393+sha256_final c h
394+for i ulong 32
395+put gevh2 i get h i
396+end
397+end
398+fn evwout fd int l ulong to bool
399+ln = new uchar 8192 0
400+for i ulong l bound 8192
401+put ln i get gevln i
402+end
403+evsha part ln 0 l
404+put gevln l 10
405+w = write fd gevln 0 add l 1
406+if ne w long add l 1
407+ret false
408+end
409+for i ulong 32
410+put gevprv i get gevh2 i
411+end
412+k = get gevn 0
413+put gevn 0 add k 1
414+put gevoff add k 1 add get gevoff k add l 1
415+ret true
416+end

door/ev3col.om

new file mode 100644
@@ -0,0 +1,1029 @@
1+note door/ev3col.om: one collection pass. Change-triggered: each source is read only when its
2+note fingerprint moved since the last pass of this process (a start reads every repository once and
3+note finds nothing new: the snapshots in <data>events/r/ and the keys of the log say what was seen).
4+note social log its size; the new bytes are read with social's own line parser (stars, follows)
5+note open shelf <data>open/list.tsv, its change time and size (brought, withdrawn)
6+note repository i the change times of refs/heads, refs/tags, packed-refs, refs/namespaces, refs/rad
7+note and every refs/namespaces/<nid>/refs/rad (Radicle renames sigrefs into it at
8+note every ref update of that node, COB changes included); then one for-each-ref of
9+note the default branch, the tags and the patch and issue COB refs, compared line by
10+note line with the snapshot; only COBs whose tip moved are loaded (collab coload)
11+text tevfh1 "<section class=\"box\"><h1>Feed</h1>\n<p class=\"muted\">What happened on this forge, newest first: changes proposed, reviewed and merged, issues, releases, new commits on default branches, stars, follows and the open builds shelf. Only public repositories. Agents read the same list as <a href=\""
12+const EVNO ulong 99999999
13+fn evcollect to void
14+if eq get gevok 0 0
15+evload
16+end
17+if ne get gevok 0 1
18+ret
19+end
20+t0 = monons
21+put gevpr 0 0
22+put gevpe 0 0
23+put gevbn 0 0
24+put gevbatl 0 0
25+evsocial
26+evopen
27+for i ulong get fan 0 bound FAMAX
28+evrepochk i
29+end
30+if gt get gevbn 0 0
31+evflush
32+end
33+note a COB read past a buffer marks the response cut (fincut); collection is not the response
34+put ficut 0 0
35+put fobtr 0 0
36+put fobl 0 0
37+if gt get gevpr 0 0
38+dt = div ulong sub monons t0 1000
39+evgb
40+evgt tevlpas
41+evgn dt
42+evgt tevlpus
43+evgn get gevpr 0
44+evgt tevlpev
45+evgn get gevpe 0
46+evgout
47+end
48+end
49+note ---- the social log (social/30store.om writes it; soload has verified it)
50+fn evsocial to void
51+if eq get gsok 0 0
52+ret
53+end
54+sopdd
55+sopt tslog
56+fpb
57+for i ulong get gspthl 0 bound 1024
58+fpc get gspth i
59+end
60+if eq evstat 0
61+ret
62+end
63+sz = evst64 48
64+off = get gevsoff 0
65+if eq sz off
66+ret
67+end
68+if lt sz off
69+off = ulong 0
70+end
71+fd = fopen fpth 0 get fpthl 0 524288 0
72+if lt fd 0
73+ret
74+end
75+put gevpr 0 add get gevpr 0 1
76+for it ulong 100000
77+r = pread int fd gevrb 0 len gevrb long off
78+if le r 0
79+break
80+end
81+u = evsocscan ulong r
82+if eq u 0
83+break
84+end
85+off = add off u
86+end
87+x = fclose int fd
88+put gevsoff 0 off
89+end
90+fn evsocscan n ulong to ulong
91+ln = new uchar 1024 0
92+p = ulong 0
93+for it ulong 2097152
94+e = evrbeol p n
95+if ge e n
96+break
97+end
98+l = sub e p
99+if lt l 1024
100+for i ulong l bound 1024
101+put ln i get gevrb add p i
102+end
103+evsocln part ln 0 l
104+end
105+p = add e 1
106+end
107+ret p
108+end
109+fn evrbeol p ulong n ulong to ulong
110+e = p
111+for k ulong 2097152
112+if ge e n
113+ret n
114+end
115+if eq get gevrb e 10
116+ret e
117+end
118+e = add e 1
119+end
120+ret n
121+end
122+note evsocln: one social line; only star (1) and follow (7) are events. fav, unfav, watch, unwatch,
123+note unstar, unfollow, account, name, session and logout are never read past their action word.
124+fn evsocln ln view uchar * to void
125+put gspc 0 0
126+put gsbad 0 0
127+solit ln tsl1
128+seq = sonum ln
129+solit ln tsl2
130+ts = sonum ln
131+solit ln tsl3
132+sokclr
133+sokt tsdidp
134+dl = sostr ln
135+evclr
136+for i ulong get gskbl 0 bound 128
137+evactc get gskb i
138+end
139+solit ln tsl4
140+a = soact ln
141+solit ln tsl5
142+sokclr
143+tl = sostr ln
144+if ne get gsbad 0 0
145+ret
146+end
147+put gevt 0 ts
148+evsrct tevsocs
149+evsrcnum seq
150+if eq a 1
151+evsstar
152+end
153+if eq a 7
154+evsfoll
155+end
156+end
157+note evsstar: gskb holds rad:<rid>; an event only for a repository that is public now
158+fn evsstar to void
159+if not sokpre tsradp
160+ret
161+end
162+for i ulong sub get gskbl 0 len tsradp bound 64
163+evridc get gskb add len tsradp i
164+end
165+r = evridpub
166+if eq r 9999
167+ret
168+end
169+put gevk 0 11
170+evpthrepo r
171+evjsame
172+evjst tevjsx
173+for k ulong frnlen r bound 128
174+evsubc frnbyte r k
175+end
176+evemit
177+end
178+note evsfoll: gskb holds the followed account's did:key; its page is found when the stream is read
179+fn evsfoll to void
180+if not sokpre tsdidp
181+ret
182+end
183+put gevk 0 12
184+for i ulong get gskbl 0 bound 128
185+evxc get gskb i
186+evsubc get gskb i
187+end
188+evemit
189+end
190+note ---- the open shelf: <data>open/list.tsv (rid, state, did, date, size, name, ...), as the intake wrote it
191+fn evopen to void
192+evpath tevlist
193+fp = evstat
194+if eq fp get gevofp 0
195+ret
196+end
197+put gevofp 0 fp
198+if eq fp 0
199+ret
200+end
201+r = frdall
202+if or lt r 0 ne get fxotr 0 0
203+ret
204+end
205+put gevpr 0 add get gevpr 0 1
206+n = get fxol 0
207+p = ulong 0
208+for it ulong 16777216
209+if ge p n
210+break
211+end
212+e = p
213+for k ulong 16777216
214+if ge e n
215+break
216+end
217+if eq get fxo e 10
218+break
219+end
220+e = add e 1
221+end
222+evopnln p e
223+p = add e 1
224+end
225+end
226+fn evfxeq a ulong e ulong t view uchar * to bool
227+if ne sub e a len t
228+ret false
229+end
230+for i ulong len t bound 64
231+if ne get fxo add a i get t i
232+ret false
233+end
234+end
235+ret true
236+end
237+note evopnln a e: one shelf row; held or stored is "brought", withdrawn is "withdrawn". Time: the row's
238+note date at 00:00 UTC (the list keeps the day only). A denied RID (server/repos.om fdeny) is never named.
239+fn evopnln a ulong e ulong to void
240+tb = new ulong 8 0
241+k = ulong 0
242+for i ulong sub e a bound 16777216
243+if eq get fxo add a i 9
244+if lt k 8
245+put tb k add a i
246+k = add k 1
247+end
248+end
249+end
250+if lt k 6
251+ret
252+end
253+evopn2 tb a
254+end
255+fn evopnkd tb view ulong * to ulong
256+s = add get tb 0 1
257+e = get tb 1
258+if or evfxeq s e tevheld evfxeq s e tevstor
259+ret 13
260+end
261+if evfxeq s e tevwdr
262+ret 14
263+end
264+ret 0
265+end
266+fn evopn2 tb view ulong * a ulong to void
267+kd = evopnkd tb
268+if eq kd 0
269+ret
270+end
271+if or eq get tb 0 a gt sub get tb 0 a 64
272+ret
273+end
274+if evfxeq a get tb 0 tfdnr1
275+ret
276+end
277+d = add get tb 2 1
278+if ne sub get tb 3 d 10
279+ret
280+end
281+t = evdate d
282+if eq t 0
283+ret
284+end
285+evclr
286+put gevk 0 kd
287+put gevt 0 t
288+evopnf a get tb 0 add get tb 1 1 get tb 2 d
289+evopnnm add get tb 4 1 get tb 5
290+evemit
291+end
292+fn evopnnm a ulong e ulong to void
293+for i ulong sub e a bound 4096
294+c = get fxo add a i
295+evxc c
296+evsubc c
297+end
298+end
299+note evopnf: rid fxo[a, ra), actor fxo[da, de) when it is a did:key, source, path and json
300+fn evopnf a ulong ra ulong da ulong de ulong d ulong to void
301+for i ulong sub ra a bound 64
302+evridc get fxo add a i
303+end
304+if evfxpre da de tevdidk
305+for i ulong sub de da bound 128
306+evactc get fxo add da i
307+end
308+end
309+evsrct tevopns
310+for i ulong sub ra a bound 64
311+evsrcc get fxo add a i
312+end
313+evsrcc 64
314+for i ulong 10
315+evsrcc get fxo add d i
316+end
317+evptht tevopnp
318+if eq get gevk 0 13
319+for i ulong sub ra a bound 64
320+evpthc get fxo add a i
321+end
322+evjsame
323+evjst tevjsx
324+else
325+evjst tevopnj
326+end
327+end
328+fn evfxpre a ulong e ulong t view uchar * to bool
329+if lt sub e a len t
330+ret false
331+end
332+for i ulong len t bound 64
333+if ne get fxo add a i get t i
334+ret false
335+end
336+end
337+ret true
338+end
339+note evdate p: fxo[p, p+10) = YYYY-MM-DD as epoch seconds at 00:00 UTC; 0 when it is not a date
340+fn evdate p ulong to ulong
341+for i ulong 10
342+c = get fxo add p i
343+if or eq i 4 eq i 7
344+if ne c 45
345+ret 0
346+end
347+else
348+if not evdig c
349+ret 0
350+end
351+end
352+end
353+y = evdn add p 0 4
354+m = evdn add p 5 2
355+d = evdn add p 8 2
356+if or or lt y 1970 lt m 1 or gt m 12 or lt d 1 gt d 31
357+ret 0
358+end
359+ret mul evdays y m d 86400
360+end
361+note evdays y m d: days since 1970-01-01 of a civil date (proleptic Gregorian, y >= 1970)
362+fn evdays y0 ulong m ulong d ulong to ulong
363+y = y0
364+if le m 2
365+y = sub y 1
366+end
367+era = div y 400
368+yoe = sub y mul era 400
369+mp = add m 9
370+if gt m 2
371+mp = sub m 3
372+end
373+doy = add div add mul 153 mp 2 5 sub d 1
374+a = add mul yoe 365 div yoe 4
375+doe = add sub a div yoe 100 doy
376+ret sub add mul era 146097 doe 719468
377+end
378+fn evdn p ulong n ulong to ulong
379+v = ulong 0
380+for i ulong n bound 4
381+v = add mul v 10 ulong sub get fxo add p i 48
382+end
383+ret v
384+end
385+note ---- repositories
386+note evstp: fpth = <storage><rid of repo i><t>
387+fn evstp i ulong t view uchar * to void
388+fpb
389+fpt tfstore
390+for k ulong fridlen i bound 64
391+fpc fridbyte i k
392+end
393+fpt t
394+end
395+fn evrepochk i ulong to void
396+h = ulong 14695981039346656037
397+for k ulong fridlen i bound 64
398+h = evfnv h fridbyte i k
399+end
400+evstp i tevsrh
401+h = add h evstat
402+evstp i tevsrt
403+h = add h mul evstat 3
404+evstp i tevspk
405+h = add h mul evstat 5
406+evstp i tevsns
407+h = add h mul evstat 7
408+evstp i tevsrad
409+h = add h mul evstat 11
410+h = add h evnsfp i
411+if eq h get gevfp i
412+ret
413+end
414+if evrepo i
415+put gevfp i h
416+end
417+end
418+note evnsfp i: the sum of the fingerprints of refs/namespaces/<nid>/refs/rad, one per node
419+fn evnsfp i ulong to ulong
420+evstp i tevsns
421+fd = fopen fpth 0 get fpthl 0 540672 0
422+if lt fd 0
423+ret 0
424+end
425+s = ulong 0
426+for it ulong 4096
427+n = getdnts int fd gevde 0 len gevde
428+if le n 0
429+break
430+end
431+s = add s evnsdir i ulong n
432+end
433+x = fclose int fd
434+ret s
435+end
436+fn evnsdir i ulong n ulong to ulong
437+s = ulong 0
438+p = ulong 0
439+for it ulong 16384
440+if ge add p 19 n
441+break
442+end
443+rl = or ulong get gevde add p 16 shl ulong get gevde add p 17 8
444+if eq rl 0
445+break
446+end
447+s = add s evnsent i p
448+p = add p rl
449+end
450+ret s
451+end
452+note evnsent i p: a node folder (d_type 4, not dot-named) at gevde[p]: its refs/rad fingerprint, else 0
453+fn evnsent i ulong p ulong to ulong
454+if ne get gevde add p 18 4
455+ret 0
456+end
457+if eq get gevde add p 19 46
458+ret 0
459+end
460+evstp i tevsns
461+fpc 47
462+for k ulong 255
463+c = get gevde add add p 19 k
464+if eq c 0
465+break
466+end
467+fpc c
468+end
469+fpt tevsrad
470+ret mul evstat 13
471+end
472+note evsetrepo i: the request globals collab reads (fridx, frid, frepo) name repository i
473+fn evsetrepo i ulong to void
474+put fridx 0 i
475+for k ulong fridlen i bound 64
476+put frid k fridbyte i k
477+end
478+put fridl 0 fridlen i
479+for k ulong frnlen i bound 128
480+put frepo k frnbyte i k
481+end
482+put frepol 0 frnlen i
483+end
484+fn evunset to void
485+put fridx 0 9999
486+put fridl 0 0
487+put frepol 0 0
488+end
489+note evsnapp i: fpth = <data>events/r/<rid of i>
490+fn evsnapp i ulong to void
491+evpath tevrp
492+for k ulong fridlen i bound 64
493+fpc fridbyte i k
494+end
495+end
496+note evrepo i: read repository i; false when git did not answer (the next pass tries again)
497+fn evrepo i ulong to bool
498+evsetrepo i
499+fkgiti i
500+fka tevfer
501+fka tevfmt
502+fkopen
503+fkt tevrh
504+for k ulong get fabl i bound 64
505+fkc get fabr add get fabo i k
506+end
507+fka tevrt
508+fkopen
509+fkt tevns
510+fkt tfnid
511+fkt tevnst
512+fka tevcpg
513+fka tevcig
514+x = fexec 10000000000
515+if ne x 0
516+evunset
517+ret false
518+end
519+put gevpr 0 add get gevpr 0 1
520+if or ne get fxotr 0 0 gt get fxol 0 len gevnew
521+evgb
522+evgt tevlcut
523+for k ulong fridlen i bound 64
524+evgc fridbyte i k
525+end
526+evgout
527+evunset
528+ret true
529+end
530+n = get fxol 0
531+for k ulong n bound 4194304
532+put gevnew k get fxo k
533+end
534+put gevnewl 0 n
535+first = evoldld i
536+put gevcn 0 0
537+p = ulong 0
538+for it ulong 4194304
539+if ge p n
540+break
541+end
542+e = p
543+for k ulong 4194304
544+if ge e n
545+break
546+end
547+if eq get gevnew e 10
548+break
549+end
550+e = add e 1
551+end
552+evrefln i p e first
553+p = add e 1
554+end
555+evcobs i 1
556+evcobs i 2
557+evsnapw i
558+evunset
559+ret true
560+end
561+note evoldld i: the snapshot of the last read into gevold; true when there is none (first sight)
562+fn evoldld i ulong to bool
563+put gevoldl 0 0
564+evsnapp i
565+r = frdall
566+if lt r 0
567+ret true
568+end
569+if or ne get fxotr 0 0 gt get fxol 0 len gevold
570+ret true
571+end
572+n = get fxol 0
573+for k ulong n bound 4194304
574+put gevold k get fxo k
575+end
576+put gevoldl 0 n
577+ret false
578+end
579+note evsnapw i: gevnew becomes the snapshot (written to .tmp, then renamed over it)
580+fn evsnapw i ulong to void
581+evsnapp i
582+fpt tevtmp
583+fd = fopen fpth 0 get fpthl 0 524865 384
584+if lt fd 0
585+ret
586+end
587+n = get gevnewl 0
588+off = ulong 0
589+for it ulong 4096
590+if ge off n
591+break
592+end
593+w = write int fd gevnew off sub n off
594+if le w 0
595+break
596+end
597+off = add off ulong w
598+end
599+x = fsync int fd
600+y = fclose int fd
601+if ne off n
602+ret
603+end
604+pk = new uchar 8200 0
605+put pk 0 2
606+o = evpkadd pk 2
607+evsnapp i
608+o = evpkadd pk o
609+r = renames pk 0 o 0
610+end
611+fn evpkadd pk edit uchar * o ulong to ulong
612+n = get fpthl 0
613+put pk o uchar and n 255
614+put pk add o 1 uchar shr n 8
615+for k ulong n bound 4096
616+put pk add add o 2 k get fpth k
617+end
618+ret add add o 2 n
619+end
620+note ---- one ref line of gevnew: "<sha> <time> <refname>"
621+fn evrefln i ulong a ulong e ulong first bool to void
622+if lt sub e a 44
623+ret
624+end
625+if ne get gevnew add a 40 32
626+ret
627+end
628+r = add a 41
629+t = ulong 0
630+for k ulong 20
631+if ge r e
632+ret
633+end
634+c = get gevnew r
635+r = add r 1
636+if eq c 32
637+break
638+end
639+if not evdig c
640+ret
641+end
642+t = add mul t 10 ulong sub c 48
643+end
644+o = ulong EVNO
645+if not first
646+o = evoldsha r e
647+end
648+if ne o EVNO
649+if evsame o a
650+ret
651+end
652+end
653+evrefcls i a e r t o
654+end
655+fn evsame o ulong a ulong to bool
656+for k ulong 40
657+if ne get gevold add o k get gevnew add a k
658+ret false
659+end
660+end
661+ret true
662+end
663+note evrefcls: classify the moved ref (the default branch, a tag, a patch or issue COB)
664+fn evrefcls i ulong a ulong e ulong r ulong t ulong o ulong to void
665+if evnat r e tevrh
666+if evnbr i add r len tevrh e
667+if ne o EVNO
668+evbranch i o a t
669+end
670+ret
671+end
672+end
673+if evnat r e tevrtp
674+evtag i a t add r len tevrtp e
675+ret
676+end
677+if evnat r e tevns
678+q = add r len tevns
679+if evnat q e tfnid
680+q2 = add q len tfnid
681+if evnat q2 e tevnstp
682+evtag i a t add q2 len tevnstp e
683+ret
684+end
685+end
686+end
687+if lt sub e r add len tevcpm 40
688+ret
689+end
690+m = sub sub e 40 len tevcpm
691+if evnat m e tevcpm
692+evaddcob sub e 40 1
693+ret
694+end
695+m2 = sub sub e 40 len tevcim
696+if evnat m2 e tevcim
697+evaddcob sub e 40 2
698+end
699+end
700+note evnat p e t: gevnew[p, e) starts with t
701+fn evnat p ulong e ulong t view uchar * to bool
702+if lt sub e p len t
703+ret false
704+end
705+for k ulong len t bound 128
706+if ne get gevnew add p k get t k
707+ret false
708+end
709+end
710+ret true
711+end
712+note evnbr i p e: gevnew[p, e) is exactly the default branch of repository i
713+fn evnbr i ulong p ulong e ulong to bool
714+if ne sub e p get fabl i
715+ret false
716+end
717+o = get fabo i
718+for k ulong get fabl i bound 64
719+if ne get gevnew add p k get fabr add o k
720+ret false
721+end
722+end
723+ret true
724+end
725+note evoldsha r e: the offset of the sha of the gevold line whose refname equals gevnew[r, e), else EVNO
726+fn evoldsha r ulong e ulong to ulong
727+n = get gevoldl 0
728+l = sub e r
729+p = ulong 0
730+for it ulong 4194304
731+if ge p n
732+break
733+end
734+q = p
735+for k ulong 4194304
736+if ge q n
737+break
738+end
739+if eq get gevold q 10
740+break
741+end
742+q = add q 1
743+end
744+s = evoldref p q
745+if ne s EVNO
746+if eq sub q s l
747+if evrefeq s r l
748+ret p
749+end
750+end
751+end
752+p = add q 1
753+end
754+ret EVNO
755+end
756+note evoldref p q: start of the refname of the gevold line [p, q) (after the second space), else EVNO
757+fn evoldref p ulong q ulong to ulong
758+if lt sub q p 44
759+ret EVNO
760+end
761+s = add p 41
762+for k ulong 21
763+if ge s q
764+ret EVNO
765+end
766+if eq get gevold s 32
767+ret add s 1
768+end
769+s = add s 1
770+end
771+ret EVNO
772+end
773+fn evrefeq s ulong r ulong l ulong to bool
774+for k ulong l bound 4096
775+if ne get gevold add s k get gevnew add r k
776+ret false
777+end
778+end
779+ret true
780+end
781+note evaddcob p kd: the COB id gevnew[p, p+40) of kind kd moved (each id once)
782+fn evaddcob p ulong kd ulong to void
783+for k ulong 40
784+if not evhexd get gevnew add p k
785+ret
786+end
787+end
788+n = get gevcn 0
789+for j ulong n bound 4096
790+if evcideq j p
791+ret
792+end
793+end
794+if ge n 4096
795+ret
796+end
797+for k ulong 40
798+put gevcid add mul n 40 k get gevnew add p k
799+end
800+put gevckd n kd
801+put gevcn 0 add n 1
802+end
803+fn evcideq j ulong p ulong to bool
804+o = mul j 40
805+for k ulong 40
806+if ne get gevcid add o k get gevnew add p k
807+ret false
808+end
809+end
810+ret true
811+end
812+note ---- events of one repository
813+fn evtag i ulong a ulong t ulong s ulong e ulong to void
814+evclr
815+put gevk 0 9
816+put gevt 0 t
817+evowndid
818+evridi i
819+for k ulong 40
820+evsrcc get gevnew add a k
821+end
822+evpthrepo i
823+evptht tevrelp
824+for k ulong sub e s bound 1024
825+c = get gevnew add s k
826+evpthc c
827+evsubc c
828+end
829+evjsame
830+evemit
831+end
832+fn evbranch i ulong o ulong a ulong t ulong to void
833+fkgiti i
834+fka tevrl
835+fka tevcnt
836+fkopen
837+for k ulong 40
838+fkc get gevold add o k
839+end
840+fkt tevdots
841+for k ulong 40
842+fkc get gevnew add a k
843+end
844+x = fexec 10000000000
845+known = false
846+cnt = ulong 0
847+if eq x 0
848+for k ulong get fxol 0 bound 21
849+c = get fxo k
850+if not evdig c
851+break
852+end
853+cnt = add mul cnt 10 ulong sub c 48
854+known = true
855+end
856+end
857+evclr
858+put gevk 0 10
859+put gevt 0 t
860+evowndid
861+evridi i
862+for k ulong 40
863+evsrcc get gevnew add a k
864+evxc get gevold add o k
865+end
866+evxc 32
867+evpthrepo i
868+evptht tevcmpp
869+for k ulong 40
870+evpthr get gevold add o k
871+end
872+evptht tevtdot
873+for k ulong 40
874+evpthr get gevnew add a k
875+end
876+evjsame
877+evbrsub i known cnt
878+evemit
879+end
880+note evbrsub: "<n> new commit(s) on <branch>", or "<branch> moved" when the count is not known
881+fn evbrsub i ulong known bool cnt ulong to void
882+o = get fabo i
883+if not known
884+evxc 45
885+for k ulong get fabl i bound 64
886+evsubc get fabr add o k
887+end
888+evsubt tevmovd
889+ret
890+end
891+d = new uchar 24 0
892+n = evdec cnt d
893+for k ulong n bound 24
894+evxc get d k
895+evsubc get d k
896+end
897+evsubt tevncom
898+if ne cnt 1
899+evsubt tevncs
900+end
901+evsubt tevon
902+for k ulong get fabl i bound 64
903+evsubc get fabr add o k
904+end
905+end
906+note ---- COBs: the moved ids of kind kd are loaded with collab's corefs / coload
907+fn evcobs i ulong kd ulong to void
908+any = false
909+for j ulong get gevcn 0 bound 4096
910+if eq get gevckd j kd
911+any = true
912+end
913+end
914+if not any
915+ret
916+end
917+if not corefs kd
918+ret
919+end
920+for j ulong get gevcn 0 bound 4096
921+if eq get gevckd j kd
922+for k ulong 40
923+put gcid k get gevcid add mul j 40 k
924+end
925+ok = false
926+if coload kd
927+if eq get gcov 0 0
928+ok = true
929+end
930+end
931+if ok
932+evcob i kd
933+else
934+evgb
935+evgt tevlcob
936+for k ulong 40
937+evgc get gcid k
938+end
939+evgout
940+end
941+end
942+end
943+end
944+note evcob i kd: the events of the loaded COB (collab's model: changes, revisions, merges, reviews,
945+note comments, lifecycle). One event per kind and change; the opening is keyed by the COB id.
946+fn evcob i ulong kd ulong to void
947+if eq kd 1
948+evchg i kd 1 0 true 0
949+for r ulong get gcrn 0 bound 64
950+if gt r 0
951+evchg i kd 2 get gcrt r false 0
952+end
953+end
954+for m ulong get gcmn 0 bound 16
955+evchg i kd 3 get gcmt m false 0
956+end
957+for w ulong get gcwn 0 bound 64
958+evchg i kd 5 get gcwt w false get gcwv w
959+end
960+if eq get gcm 2 2
961+evchg i kd 4 get gclfc 0 false 0
962+end
963+else
964+evchg i kd 7 0 true 0
965+if eq get gcm 2 2
966+evchg i kd 8 get gclfc 0 false 0
967+end
968+end
969+for q ulong get gcqn 0 bound 8192
970+if and eq get gcqx q 0 ne get gcqt q 0
971+evchg i kd 6 get gcqt q false 0
972+end
973+end
974+end
975+fn evchg i ulong kd ulong kind ulong ci ulong root bool vd ulong to void
976+if ge ci get gccn 0
977+ret
978+end
979+evchgh kind ci
980+evridi i
981+evchgs ci root
982+if eq vd 1
983+evxt tevvacc
984+end
985+if eq vd 2
986+evxt tevvrej
987+end
988+evchgp i kd
989+evemit
990+end
991+note evchgh kind ci: kind, the change's author time and its author (did:key of the NID that signed it)
992+fn evchgh kind ulong ci ulong to void
993+evclr
994+put gevk 0 kind
995+put gevt 0 get gccts ci
996+evactt tevdidk
997+o = mul ci 64
998+for k ulong get gccal ci bound 64
999+evactc get gccau add o k
1000+end
1001+end
1002+note evchgs ci root: the source: the COB id for its opening, else the change commit
1003+fn evchgs ci ulong root bool to void
1004+o = mul ci 40
1005+for k ulong 40
1006+if root
1007+evsrcc get gcid k
1008+else
1009+evsrcc get gcch add o k
1010+end
1011+end
1012+end
1013+note evchgp i kd: path and json <owner>/<repo>/patches|issues/<id>, and the title as the subject
1014+fn evchgp i ulong kd ulong to void
1015+evpthrepo i
1016+if eq kd 1
1017+evptht tevpatp
1018+else
1019+evptht tevissp
1020+end
1021+for k ulong 40
1022+evpthr get gcid k
1023+end
1024+evjsame
1025+o = get gcm 0
1026+for k ulong get gcm 1 bound 400
1027+evsubc get gcpool add o k
1028+end
1029+end

door/ev4json.om

new file mode 100644
@@ -0,0 +1,565 @@
1+note door/ev4json.om: the routes and the machine form of the stream (schema interplane/events/1,
2+note docs/API.md). <base>events.json is JSON whatever the headers; <base>events and <base>feed answer
3+note it with Accept: application/json; <base>events without it redirects to the feed page.
4+note An event is shown only while it is public: a repository event whose repository is not on the
5+note allow-list now (or is refused) is skipped, its seq stays used. Names of accounts are read from
6+note the social log when the stream is read, so a renamed account shows its current name.
7+text tevpj "/events.json"
8+text tevpe "/events"
9+text tevpf "/feed"
10+text tevpfr "feed"
11+text tevqa "after"
12+text tevql "limit"
13+text tevqb "before"
14+text tevk1 "patch_opened"
15+text tevk2 "patch_revised"
16+text tevk3 "patch_merged"
17+text tevk4 "patch_archived"
18+text tevk5 "review"
19+text tevk6 "comment"
20+text tevk7 "issue_opened"
21+text tevk8 "issue_closed"
22+text tevk9 "release"
23+text tevk10 "branch_moved"
24+text tevk11 "star"
25+text tevk12 "follow"
26+text tevk13 "open_brought"
27+text tevk14 "open_withdrawn"
28+text tevj1 "{\"schema\":\"interplane/events/1\",\"base\":\""
29+text tevj2 "\",\"head_seq\":"
30+text tevj3 ",\"after\":"
31+text tevj4 ",\"limit\":"
32+text tevj5 ",\"limit_requested\":"
33+text tevj6 ",\"limit_max\":200,\"limited\":"
34+text tevj7 ",\"events\":["
35+text tevj8 "\n],\"count\":"
36+text tevj9 ",\"next\":\""
37+text tevj10 "events.json?after="
38+text tevj11 "&limit="
39+text tevj12 "\"}\n"
40+text teve1 "\n{\"seq\":"
41+text teve2 ",\"time\":\""
42+text teve3 "\",\"kind\":\""
43+text teve4 "\",\"actor\":"
44+text teve5 ",\"repo\":"
45+text teve6 ",\"subject\":"
46+text teve7 ",\"path\":"
47+text teve8 ",\"json\":"
48+text teve9 ",\"source\":"
49+text teve10 ",\"verdict\":"
50+text teve11 ",\"from\":"
51+text teve12 ",\"commits\":"
52+text teve13 ",\"target\":"
53+text tevan "{\"name\":"
54+text tevad ",\"did\":"
55+text tevap ",\"path\":"
56+text tevro "{\"owner\":\""
57+text tevrn "\",\"name\":"
58+note the repository's "rid" is its identifier as forge/repo/1 gives it (fputid: the bare old id in the
59+note Radicle build, git:<id> in the store-reading build)
60+text tevrr ",\"rid\":\""
61+text tevrp2 "\",\"path\":\""
62+text tevrj "\",\"json\":\""
63+text tevrje ".json\"}"
64+global gevqbad ulong 1
65+fn evon to bool
66+ret true
67+end
68+note evroute: 0 = not one of these paths
69+fn evroute to long
70+pj = fpeq tevpj
71+pe = fpeq tevpe
72+pf = fpeq tevpf
73+if not or or pj pe pf
74+ret 0
75+end
76+if pj
77+fqajsn
78+end
79+if not fget
80+ret 405
81+end
82+if or pj fjwant
83+ret evstream
84+end
85+if pe
86+put fkind 0 2
87+flocb
88+floct tevpfr
89+ret 302
90+end
91+ret evfeed
92+end
93+note evqnum n: fval[0, n) as a decimal number of 1..18 digits; gevqbad 1 for anything else
94+fn evqnum n long to ulong
95+put gevqbad 0 0
96+if or le n 0 gt n 18
97+put gevqbad 0 1
98+ret 0
99+end
100+v = ulong 0
101+for i ulong ulong n bound 18
102+c = get fval i
103+if not evdig c
104+put gevqbad 0 1
105+ret 0
106+end
107+v = add mul v 10 ulong sub c 48
108+end
109+ret v
110+end
111+fn evstream to long
112+a = ulong 0
113+r = fqget tevqa
114+if ge r 0
115+a = evqnum r
116+if ne get gevqbad 0 0
117+ret 400
118+end
119+end
120+lreq = ulong 50
121+r2 = fqget tevql
122+if ge r2 0
123+lreq = evqnum r2
124+if or ne get gevqbad 0 0 eq lreq 0
125+ret 400
126+end
127+end
128+lim = lreq
129+cut = false
130+if gt lim 200
131+lim = ulong 200
132+cut = true
133+end
134+evcollect
135+if ne get gevok 0 1
136+put fretry 0 60
137+ret 503
138+end
139+evetag
140+if evinm
141+put fkind 0 1
142+ret 304
143+end
144+fjstart
145+fput tevj1
146+fputb
147+fput tevj2
148+fnum get gevn 0
149+fput tevj3
150+fnum a
151+fput tevj4
152+fnum lim
153+fput tevj5
154+fnum lreq
155+fput tevj6
156+fybool cut
157+fput tevj7
158+nx = evjlist a lim
159+fput tevj8
160+fnum get gevpe 0
161+fput tevj9
162+fputb
163+fput tevj10
164+fnum nx
165+fput tevj11
166+fnum lim
167+fput tevj12
168+ret 200
169+end
170+note evetag: "ev<head seq>-<social seq>-<hash of the public RIDs>-<base length>": the stream, the names
171+note in it and the visibility of its repositories are what a body depends on
172+fn evetag to void
173+put fetagl 0 0
174+fetc 34
175+fetc 101
176+fetc 118
177+evetn get gevn 0
178+fetc 45
179+evetn get gsseq 0
180+fetc 45
181+evetn and evpubh 1048575
182+fetc 45
183+evetn get fbasel 0
184+fetc 34
185+end
186+note evpubh: FNV-1a 64 of the public RIDs in allow-list order
187+fn evpubh to ulong
188+h = ulong 14695981039346656037
189+for i ulong get fan 0 bound FAMAX
190+for k ulong fridlen i bound 64
191+h = evfnv h fridbyte i k
192+end
193+h = evfnv h 10
194+end
195+ret h
196+end
197+fn evetn v ulong to void
198+d = new uchar 24 0
199+k = evdec v d
200+for j ulong k bound 24
201+fetc get d j
202+end
203+end
204+fn evinm to bool
205+n = get fetagl 0
206+if ne get finml 0 n
207+ret false
208+end
209+for i ulong n bound 128
210+if ne get finm i get fetag i
211+ret false
212+end
213+end
214+ret true
215+end
216+note evjlist a lim: the visible events after seq a, at most lim; returns the seq to read after next time.
217+note The count shown is left in gevpe (the pass counter is not read after collection).
218+fn evjlist a ulong lim ulong to ulong
219+put gevpe 0 0
220+n = get gevn 0
221+if ge a n
222+ret a
223+end
224+evpath tevlog
225+fd = fopen fpth 0 get fpthl 0 524288 0
226+if lt fd 0
227+ret a
228+end
229+k = a
230+for it ulong EVMAX
231+if or ge k n ge get gevpe 0 lim
232+break
233+end
234+if evshow int fd k 1
235+put gevpe 0 add get gevpe 0 1
236+end
237+k = add k 1
238+end
239+x = fclose int fd
240+ret k
241+end
242+note evshow fd k mode: read line k (seq k+1); when it is visible write it (mode 1 JSON, 2 the feed's
243+note list item) and return true
244+fn evshow fd int k ulong mode ulong to bool
245+o = get gevoff k
246+l = sub sub get gevoff add k 1 o 1
247+if ge l EVLMAX
248+ret false
249+end
250+ln = new uchar 8192 0
251+r = pread fd ln 0 l long o
252+if ne r long l
253+ret false
254+end
255+ret evshowl part ln 0 l mode
256+end
257+fn evshowl ln view uchar * mode ulong to bool
258+if not evtabs ln
259+ret false
260+end
261+kind = evfnum ln 2
262+ri = evlnrid ln
263+if eq ri 9998
264+ret false
265+end
266+if eq mode 1
267+evjev ln kind ri
268+else
269+evhli ln kind ri
270+end
271+ret true
272+end
273+note evlnrid ln: the allow-list index of the line's rid; 9999 when it has none or is an open shelf event,
274+note 9998 when the event must not be shown (a repository that is not public now, a refused RID)
275+fn evlnrid ln view uchar * to ulong
276+a = evfa 4
277+e = evfe 4 len ln
278+k = evfnum ln 2
279+if or eq k 13 eq k 14
280+if evlneq ln a e tfdnr1
281+ret 9998
282+end
283+ret 9999
284+end
285+if eq a e
286+ret 9999
287+end
288+for i ulong get fan 0 bound FAMAX
289+if eq fridlen i sub e a
290+same = true
291+for j ulong sub e a bound 64
292+if ne fridbyte i j get ln add a j
293+same = false
294+break
295+end
296+end
297+if same
298+ret i
299+end
300+end
301+end
302+ret 9998
303+end
304+fn evlneq ln view uchar * a ulong e ulong t view uchar * to bool
305+if ne sub e a len t
306+ret false
307+end
308+for i ulong len t bound 128
309+if ne get ln add a i get t i
310+ret false
311+end
312+end
313+ret true
314+end
315+fn evkname k ulong to void
316+if eq k 1
317+fput tevk1
318+end
319+if eq k 2
320+fput tevk2
321+end
322+if eq k 3
323+fput tevk3
324+end
325+if eq k 4
326+fput tevk4
327+end
328+if eq k 5
329+fput tevk5
330+end
331+if eq k 6
332+fput tevk6
333+end
334+if eq k 7
335+fput tevk7
336+end
337+evkname2 k
338+end
339+fn evkname2 k ulong to void
340+if eq k 8
341+fput tevk8
342+end
343+if eq k 9
344+fput tevk9
345+end
346+if eq k 10
347+fput tevk10
348+end
349+if eq k 11
350+fput tevk11
351+end
352+if eq k 12
353+fput tevk12
354+end
355+if eq k 13
356+fput tevk13
357+end
358+if eq k 14
359+fput tevk14
360+end
361+end
362+note ---- one event as JSON
363+fn evjev ln view uchar * kind ulong ri ulong to void
364+if gt get gevpe 0 0
365+fputc 44
366+end
367+fput teve1
368+fnum evfnum ln 0
369+fput teve2
370+fjisob evfnum ln 1
371+fput teve3
372+evkname kind
373+fput teve4
374+evjactor ln evfa 3 evfe 3 len ln
375+fput teve5
376+if lt ri 9998
377+evjrepo ri
378+else
379+fynull
380+end
381+fput teve6
382+evjfld ln 9 false
383+fput teve7
384+evjlink ln 6 kind
385+fput teve8
386+evjlink ln 7 kind
387+fput teve9
388+evjfld ln 5 false
389+fput teve10
390+if and eq kind 5 ne evfa 8 evfe 8 len ln
391+evjfld ln 8 false
392+else
393+fynull
394+end
395+evjbr ln kind
396+fput teve13
397+if eq kind 12
398+evjactor ln evfa 8 evfe 8 len ln
399+else
400+fynull
401+end
402+fputc 125
403+end
404+note evjfld ln f base: field f as a JSON string (with the base before it when base is true)
405+fn evjfld ln view uchar * f ulong base bool to void
406+fjtb
407+if base
408+for i ulong get fbasel 0 bound 64
409+fjtc get fbase i
410+end
411+end
412+a = evfa f
413+for i ulong sub evfe f len ln a bound 8192
414+fjtc get ln add a i
415+end
416+fjstr
417+end
418+note evjlink ln f kind: path (6) or json (7): the base and the stored address; a follow names the
419+note followed account's page (when the account exists), anything else without an address is null
420+fn evjlink ln view uchar * f ulong kind ulong to void
421+if ne evfa f evfe f len ln
422+evjfld ln f true
423+ret
424+end
425+if eq kind 12
426+d = evacct ln evfa 8 evfe 8 len ln
427+if ne d 0
428+sojpath d
429+ret
430+end
431+end
432+fynull
433+end
434+note evjbr: from and commits of a branch move (x = "<old sha> <count>" or "<old sha> -"), else null
435+fn evjbr ln view uchar * kind ulong to void
436+a = evfa 8
437+e = evfe 8 len ln
438+fput teve11
439+if or ne kind 10 lt sub e a 42
440+fynull
441+fput teve12
442+fynull
443+ret
444+end
445+fjtb
446+for i ulong 40
447+fjtc get ln add a i
448+end
449+fjstr
450+fput teve12
451+v = ulong 0
452+ok = false
453+for i ulong sub e add a 41 bound 20
454+c = get ln add add a 41 i
455+if not evdig c
456+ok = false
457+break
458+end
459+v = add mul v 10 ulong sub c 48
460+ok = true
461+end
462+if ok
463+fnum v
464+else
465+fynull
466+end
467+end
468+note evacct ln a e: the social account id of the did:key ln[a, e), 0 when there is no account
469+fn evacct ln view uchar * a ulong e ulong to ulong
470+if or eq a e gt sub e a 128
471+ret 0
472+end
473+sokclr
474+for i ulong sub e a bound 128
475+sokc get ln add a i
476+end
477+d = sofind
478+if eq d 0
479+ret 0
480+end
481+if ge d len gsacc
482+ret 0
483+end
484+if eq get gsacc d 0
485+ret 0
486+end
487+ret d
488+end
489+note evisown ln a e: ln[a, e) is did:key:<the node delegate>
490+fn evisown ln view uchar * a ulong e ulong to bool
491+if ne sub e a add len tevdidk len tfnid
492+ret false
493+end
494+for i ulong len tevdidk bound 16
495+if ne get ln add a i get tevdidk i
496+ret false
497+end
498+end
499+b = add a len tevdidk
500+for i ulong len tfnid bound 64
501+if ne get ln add b i get tfnid i
502+ret false
503+end
504+end
505+ret true
506+end
507+note evjactor ln a e: {"name", "did", "path"}: the owner, else a forge account (its display name or
508+note null, and its page), else the did alone; null when the event has no actor
509+fn evjactor ln view uchar * a ulong e ulong to void
510+if eq a e
511+fynull
512+ret
513+end
514+fput tevan
515+isown = evisown ln a e
516+d = ulong 0
517+if isown
518+fjtxt tfowner
519+else
520+d = evacct ln a e
521+if and ne d 0 ne get gsnm d 0
522+sojid get gsnm d 0
523+else
524+fynull
525+end
526+end
527+fput tevad
528+fjtb
529+for i ulong sub e a bound 128
530+fjtc get ln add a i
531+end
532+fjstr
533+fput tevap
534+if isown
535+fjtb
536+for i ulong get fbasel 0 bound 64
537+fjtc get fbase i
538+end
539+for i ulong len tfowner bound 64
540+fjtc get tfowner i
541+end
542+fjstr
543+else
544+if ne d 0
545+sojpath d
546+else
547+fynull
548+end
549+end
550+fputc 125
551+end
552+fn evjrepo i ulong to void
553+fput tevro
554+fput tfowner
555+fput tevrn
556+fjtname i
557+fjstr
558+fput tevrr
559+fputid i
560+fput tevrp2
561+fjpath i
562+fput tevrj
563+fjpath i
564+fput tevrje
565+end

door/ev5feed.om

new file mode 100644
@@ -0,0 +1,298 @@
1+note door/ev5feed.om: <base>feed, the stream for people: newest first, 50 a page, one plain sentence an
2+note event with who did it (their page) and what (a link to it); older pages with ?before=<seq>. Its
3+note JSON alternate is <base>events.json (fjalt 4); ?format=text is the server's plain-text form.
4+text tevfti "Feed"
5+note tevfh1 (the first lines of the page, naming the kinds) is the collector's: door/ev3col.om or
6+note store/evcol.om, whichever run.sh composed, says which kinds this build can have.
7+text tevfjs "events.json"
8+text tevfh2 "\">events.json</a> and continue from where they stopped (<a href=\""
9+text tevfag "agents.json"
10+text tevfh3 "\">agents.json</a> lists every address).</p>\n<ul class=\"feed\">\n"
11+text tevfnon "<li class=\"muted\">Nothing has happened yet.</li>\n"
12+text tevfh4 "</ul>\n"
13+text tevfol "<p><a href=\""
14+text tevfolq "feed?before="
15+text tevfol2 "\">Older</a>"
16+text tevfnw1 " <a href=\""
17+text tevfnw2 "\">Newest</a>"
18+text tevfend "</p>\n</section>\n"
19+text tevfend2 "</section>\n"
20+text tevli1 "<li>"
21+text tevli2 " <span class=\"muted\">"
22+text tevli3 " UTC</span></li>\n"
23+text teva1 "<a href=\""
24+text teva2 "\">"
25+text teva3 "</a>"
26+text tevsome "someone"
27+text tevv1 " proposed a change to "
28+text tevv2 " updated the change "
29+text tevv3 " merged "
30+text tevv3b " into "
31+text tevv4 " archived the change "
32+text tevv5 " reviewed "
33+text tevv6 " commented on "
34+text tevv7 " opened an issue in "
35+text tevv8 " closed the issue "
36+text tevv9 " tagged "
37+text tevv11 " starred "
38+text tevv12 " followed "
39+text tevv13 " brought "
40+text tevv13b " to the open builds shelf"
41+text tevv14 " withdrew "
42+text tevv14b " from the open builds shelf"
43+text tevin " in "
44+text tevcol ": "
45+text tevpo " ("
46+text tevpc ")"
47+text tevfnv "\">Feed</a>"
48+fn evnav to void
49+fput teva1
50+fputb
51+fput tevpfr
52+fput tevfnv
53+end
54+fn evfeed to long
55+b = ulong 0
56+r = fqget tevqb
57+if ge r 0
58+b = evqnum r
59+if or ne get gevqbad 0 0 eq b 0
60+ret 400
61+end
62+end
63+evcollect
64+if ne get gevok 0 1
65+put fretry 0 60
66+ret 503
67+end
68+n = get gevn 0
69+top = n
70+if and ne b 0 le sub b 1 n
71+top = sub b 1
72+end
73+put fjalt 0 4
74+fsetti tevfti
75+fput tevfh1
76+fputb
77+fput tevfjs
78+fput tevfh2
79+fputb
80+fput tevfag
81+fput tevfh3
82+evpath tevlog
83+fd = fopen fpth 0 get fpthl 0 524288 0
84+shown = ulong 0
85+low = ulong 0
86+k = top
87+if ge fd 0
88+for it ulong EVMAX
89+if or eq k 0 ge shown 50
90+break
91+end
92+if evshow int fd sub k 1 2
93+shown = add shown 1
94+low = k
95+end
96+k = sub k 1
97+end
98+x = fclose int fd
99+end
100+if eq shown 0
101+fput tevfnon
102+end
103+fput tevfh4
104+evfpage k low b
105+ret 200
106+end
107+note evfpage k low b: the Older link (when events older than the last shown remain) and Newest
108+fn evfpage k ulong low ulong b ulong to void
109+if and eq k 0 eq b 0
110+fput tevfend2
111+ret
112+end
113+fput tevfol
114+if gt k 0
115+fputb
116+fput tevfolq
117+fnum low
118+fput tevfol2
119+end
120+if ne b 0
121+fput tevfnw1
122+fputb
123+fput tevpfr
124+fput tevfnw2
125+end
126+fput tevfend
127+end
128+note ---- one list item
129+fn evhli ln view uchar * kind ulong ri ulong to void
130+fput tevli1
131+if ne kind 10
132+evhactor ln evfa 3 evfe 3 len ln
133+end
134+evhverb ln kind ri
135+fput tevli2
136+t = evfnum ln 1
137+fjday t
138+fputc 32
139+s = rem t 86400
140+fj2 div s 3600
141+fputc 58
142+fj2 div rem s 3600 60
143+fput tevli3
144+end
145+note evhactor: the owner or an account with a display name: a link to its page with the name; an account
146+note without one: "someone" linking its page; a key with no account here: "someone"
147+fn evhactor ln view uchar * a ulong e ulong to void
148+if evisown ln a e
149+fput teva1
150+fputb
151+fput tfowner
152+fput teva2
153+fput tfowner
154+fput teva3
155+ret
156+end
157+d = evacct ln a e
158+if eq d 0
159+fput tevsome
160+ret
161+end
162+fput teva1
163+fputb
164+sonmout d
165+fput teva2
166+if ne get gsnm d 0
167+sonmout d
168+else
169+fput tevsome
170+end
171+fput teva3
172+end
173+note evhthing ln: the subject, linked to the event's page
174+fn evhthing ln view uchar * to void
175+a = evfa 6
176+e = evfe 6 len ln
177+if eq a e
178+evhfld ln 9
179+ret
180+end
181+fput teva1
182+fputb
183+for i ulong sub e a bound 1024
184+fescc get ln add a i
185+end
186+fput teva2
187+evhfld ln 9
188+fput teva3
189+end
190+fn evhfld ln view uchar * f ulong to void
191+a = evfa f
192+for i ulong sub evfe f len ln a bound 8192
193+fescc get ln add a i
194+end
195+end
196+fn evhrepo ri ulong to void
197+if ge ri 9998
198+ret
199+end
200+fput teva1
201+fputb
202+fput tfowner
203+fputc 47
204+fputrn ri
205+fput teva2
206+fputrn ri
207+fput teva3
208+end
209+fn evhverb ln view uchar * kind ulong ri ulong to void
210+if eq kind 1
211+fput tevv1
212+evhrepo ri
213+fput tevcol
214+evhthing ln
215+end
216+if eq kind 2
217+fput tevv2
218+evhthing ln
219+fput tevin
220+evhrepo ri
221+end
222+if eq kind 3
223+fput tevv3
224+evhthing ln
225+fput tevv3b
226+evhrepo ri
227+end
228+if eq kind 4
229+fput tevv4
230+evhthing ln
231+fput tevin
232+evhrepo ri
233+end
234+if eq kind 5
235+fput tevv5
236+evhthing ln
237+fput tevin
238+evhrepo ri
239+if ne evfa 8 evfe 8 len ln
240+fput tevpo
241+evhfld ln 8
242+fput tevpc
243+end
244+end
245+evhverb2 ln kind ri
246+end
247+fn evhverb2 ln view uchar * kind ulong ri ulong to void
248+if eq kind 6
249+fput tevv6
250+evhthing ln
251+fput tevin
252+evhrepo ri
253+end
254+if eq kind 7
255+fput tevv7
256+evhrepo ri
257+fput tevcol
258+evhthing ln
259+end
260+if eq kind 8
261+fput tevv8
262+evhthing ln
263+fput tevin
264+evhrepo ri
265+end
266+if eq kind 9
267+fput tevv9
268+evhthing ln
269+fput tevin
270+evhrepo ri
271+end
272+if eq kind 10
273+evhrepo ri
274+fput tevcol
275+evhthing ln
276+end
277+evhverb3 ln kind ri
278+end
279+fn evhverb3 ln view uchar * kind ulong ri ulong to void
280+if eq kind 11
281+fput tevv11
282+evhrepo ri
283+end
284+if eq kind 12
285+fput tevv12
286+evhactor ln evfa 8 evfe 8 len ln
287+end
288+if eq kind 13
289+fput tevv13
290+evhthing ln
291+fput tevv13b
292+end
293+if eq kind 14
294+fput tevv14
295+evhfld ln 9
296+fput tevv14b
297+end
298+end

galaxy/page.om

@@ -4,7 +4,7 @@ note stdin "css" prints the stylesheet. Otherwise stdin is tab-separated public
44 note K key value a headline figure
55 note S name open done24 a hive cell (a factory station), at most 10
66 note R name tier a project star, tier core, rest or tail
7-note M repo head note a merged head on Radicle
7+note M repo head note a merged head
88 note stdout is the page. Every field is HTML-escaped. Exit 0 on success, 1 when stdout fails.
99 note Star positions use the golden angle: cos and sin of pi(3 - sqrt 5), Wolfram, 17 digits.
1010 const GCP f64 0.73736887807831990
@@ -26,6 +26,18 @@ text tgt "&gt;"
2626 text tquo "&quot;"
2727 text tapo "&#39;"
2828 text tna "not read"
29+note retired-network words: a fed field holding one of them is not printed as fed (rterm)
30+text rw1 "radicle"
31+text rw2 "heartwood"
32+text rw3 "rad:z"
33+text rw4 "/rad/"
34+text rw5 "rad clone"
35+text rw6 "rad init"
36+text rw7 "rad sync"
37+text rw8 "rad id"
38+text rw9 "rad patch"
39+text rw10 "rad auth"
40+text tretd "Retired"
2941 text kdel "delivered"
3042 text kver "verdicts"
3143 text kapp "approved"
@@ -50,8 +62,8 @@ text h14 "<g transform='translate(600 400)'>\n<circle class='orb' r='295'/><circ
5062 text h15 "</g>\n<g class='stars'>\n"
5163 text h16 "</g>\n</g>\n<g class='comb'>\n"
5264 text h17 "</g>\n</svg>\n"
53-text h18 "<aside id='proof'><p class='eyebrow'>Proof</p><h2>Latest merges on Radicle</h2>"
54-text h19 "<p class='sub'>Each line is a signed commit on a public peer network. Fetch it and compare the hash.</p><ol class='chain'>\n"
65+text h18 "<aside id='proof'><p class='eyebrow'>Proof</p><h2>Latest merges</h2>"
66+text h19 "<p class='sub'>Each line is a merged commit. Compare the hash with your copy.</p><ol class='chain'>\n"
5567 text h20 "</ol></aside></div>\n"
5668 text h21 "<p class='legend'>Each cell: jobs in work now, then delivered in 24 h. <i class='k ka'></i><b>"
5769 text h22 "</b> unverified, in review, inner ring <i class='k kb'></i><b>"
@@ -257,6 +269,53 @@ j = add j 1
257269 end
258270 ret p
259271 end
272+note rhas: does ib[a, b) hold t (t lowercase ASCII), compared without case
273+fn rhas a ulong b ulong t view uchar * to bool
274+n = len t
275+if lt sub b a n
276+ret false
277+end
278+if le b a
279+ret false
280+end
281+m = add sub sub b a n 1
282+i = ulong 0
283+while lt i m bound 65536
284+k = ulong 0
285+ok = true
286+while lt k n bound 64
287+c = get ib add add a i k
288+if and ge c 65 le c 90
289+c = uchar add c 32
290+end
291+if ne c get t k
292+ok = false
293+k = n
294+else
295+k = add k 1
296+end
297+end
298+if ok
299+ret true
300+end
301+i = add i 1
302+end
303+ret false
304+end
305+note rterm: the fed field ib[a, b) names the network Interplane no longer uses (Radicle was removed
306+note on 2026-11-14); the page then prints a plain replacement instead of the fed words
307+fn rterm a ulong b ulong to bool
308+if le b a
309+ret false
310+end
311+if or rhas a b rw1 or rhas a b rw2 or rhas a b rw3 rhas a b rw4
312+ret true
313+end
314+if or rhas a b rw5 or rhas a b rw6 or rhas a b rw7 rhas a b rw8
315+ret true
316+end
317+ret or rhas a b rw9 rhas a b rw10
318+end
260319 fn pnum a ulong b ulong to ulong
261320 v = ulong 0
262321 i = a
@@ -326,6 +385,21 @@ s = nextl add eol s 1 ty
326385 end
327386 ret n
328387 end
388+note cntr: the R lines (stars) the page draws: those whose name passes rterm
389+fn cntr to ulong
390+lim = get ibl 0
391+n = ulong 0
392+s = nextl 0 82
393+while lt s lim bound 65536
394+e = eol s
395+a = fld s e 1
396+if not rterm a find a e 9
397+n = add n 1
398+end
399+s = nextl add e 1 82
400+end
401+ret n
402+end
329403 note orbit: n dots (at most 400) on the circle of radius r, spread by the golden angle
330404 fn orbit n ulong r ulong to void
331405 x = 0.0f64
@@ -443,11 +517,14 @@ k = ulong 0
443517 s = nextl 0 82
444518 while lt s lim bound 400
445519 e = eol s
520+a = fld s e 1
521+if not rterm a find a e 9
446522 star s e k x y
447523 t = neg add mul x GCP mul y GS
448524 y = sub mul x GS mul y GCP
449525 x = t
450526 k = add k 1
527+end
451528 s = nextl add e 1 82
452529 if ge k 400
453530 s = lim
@@ -489,11 +566,19 @@ if gt lv 4
489566 lv = ulong 4
490567 end
491568 cellat j lv
569+if rterm a sp
570+em tretd
571+else
492572 emf a sp
573+end
493574 em c4
494575 if lt sp b
576+if rterm add sp 1 b
577+em tretd
578+else
495579 emf add sp 1 b
496580 end
581+end
497582 em c5
498583 emn n
499584 em c6
@@ -532,7 +617,10 @@ emf a b
532617 em m2
533618 emf h find h e 9
534619 em m3
535-emfn t find t e 9
620+te = find t e 9
621+if not rterm t te
622+emfn t te
623+end
536624 em m4
537625 n = add n 1
538626 s = nextl add e 1 77
@@ -620,6 +708,6 @@ emn knum kwai
620708 em h22
621709 emn knum kapp
622710 em h23
623-emn cnt 82
711+emn cntr
624712 em h24
625713 end

galaxy/tests/run.sh

@@ -34,8 +34,11 @@ chmod +x "$T/galaxy"
3434 eq "page exit" "$?" 0
3535 eq "no script element" "$(grep -ci '<script' "$T/page.html")" 0
3636 eq "no inline handler" "$(grep -ci ' on[a-z]*=' "$T/page.html")" 0
37-eq "stars equal R lines" "$(count "class='st " "$T/page.html")" "$(awk -F'\t' '$1=="R"' "$HERE/feed.tsv" | wc -l | tr -d ' ')"
37+eq "stars equal R lines, less the retired-network name" "$(count "class='st " "$T/page.html")" "$(awk -F'\t' '$1=="R" && tolower($2) !~ /radicle|heartwood/' "$HERE/feed.tsv" | wc -l | tr -d ' ')"
3838 eq "hive cells" "$(count "class='cell'" "$T/page.html")" 10
39+eq "feed names a retired network (control)" "$(grep -ci 'radicle' "$HERE/feed.tsv")" 1
40+eq "no retired-network words on the page" "$(grep -ciE 'radicle|heartwood|rad:z|/rad/|rad (clone|init|sync|id|patch|auth)' "$T/page.html")" 0
41+eq "its station is printed as Retired" "$(count "y='-22'>Retired</text>" "$T/page.html")" 1
3942 eq "merge rows equal M lines" "$(count '<li><a ' "$T/page.html")" "$(awk -F'\t' '$1=="M"' "$HERE/feed.tsv" | wc -l | tr -d ' ')"
4043 want=$(awk -F'\t' '$1=="K" && ($2=="waiting" || $2=="approved") {n += $3} END {print n + 0}' "$HERE/feed.tsv")
4144 eq "ring dots equal waiting plus approved" "$(count "class='pl'" "$T/page.html")" "$want"

growth/g1prep.om

@@ -26,14 +26,14 @@ global ggwin ulong 1
2626 global ggnow ulong 1
2727 global ggw0 ulong 1
2828 global ggord ulong 1
29-global ggcln ulong 64
30-global ggdlw ulong 64
31-global ggstw ulong 64
32-global ggstu ulong 64
33-global ggscr ulong 64
34-global ggix ulong 64
35-global gglst ulong 64
36-global ggslc ulong 64
29+global ggcln ulong 256
30+global ggdlw ulong 256
31+global ggstw ulong 256
32+global ggstu ulong 256
33+global ggscr ulong 256
34+global ggix ulong 256
35+global gglst ulong 256
36+global ggslc ulong 256
3737 global ggcon ulong 1
3838 global ggcnn ulong 1
3939 global ggctr ulong 1
@@ -168,7 +168,7 @@ fn grrix a ulong n ulong to ulong
168168 if eq n 0
169169 ret 9999
170170 end
171-for i ulong get fan 0 bound 64
171+for i ulong get fan 0 bound FAMAX
172172 if grrid i a n
173173 ret i
174174 end
@@ -269,7 +269,7 @@ p = add e 1
269269 end
270270 end
271271 fn grclr to void
272-for i ulong 64
272+for i ulong FAMAX
273273 put ggcln i 0
274274 put ggdlw i 0
275275 put ggstw i 0
@@ -412,7 +412,7 @@ note grscore: each part counts only when measured (grwm, gsok); an unmeasured pa
412412 fn grscore to void
413413 wc = grwm 0
414414 wd = grwm 2
415-for i ulong get fan 0 bound 64
415+for i ulong get fan 0 bound FAMAX
416416 s = ulong 0
417417 if wc
418418 s = add s get ggcln i
@@ -480,7 +480,7 @@ put ggix sub j 1 t
480480 end
481481 fn grsift i ulong to void
482482 j = i
483-while gt j 0 bound 64
483+while gt j 0 bound FAMAX
484484 if grless get ggix j get ggix sub j 1
485485 grswap j
486486 j = sub j 1
@@ -491,10 +491,10 @@ end
491491 end
492492 fn grsort to void
493493 n = get fan 0
494-for i ulong n bound 64
494+for i ulong n bound FAMAX
495495 put ggix i i
496496 end
497-for i ulong n bound 64
497+for i ulong n bound FAMAX
498498 grsift i
499499 end
500500 end

growth/g2page.om

@@ -50,9 +50,9 @@ text tgule "</ul>\n"
5050 text tgso1 "front-door nginx download log"
5151 text tgso2 "forged access log"
5252 text tgso3 "social log"
53-text tgso4 "this node's Radicle routing table"
53+text tgso4 "this node's routing table"
5454 text tgso5 "git log author names on the default branch"
55-text tgso6 "Radicle patch objects in this repository's storage"
55+text tgso6 "patch objects in this repository's storage"
5656 text tgso7 "front-door nginx access log"
5757 fn grjsuf to bool
5858 n = get fpathl 0
@@ -161,7 +161,6 @@ fescc get ggcnm add o k
161161 end
162162 end
163163 fn grjrid i ulong to void
164-fput tgrad
165164 for k ulong get fail i bound 64
166165 fputc fridbyte i k
167166 end
@@ -194,7 +193,7 @@ fput tgsrc2
194193 fput tgh3
195194 grhwin
196195 fput tgh4
197-for n ulong get fan 0 bound 64
196+for n ulong get fan 0 bound FAMAX
198197 i = get ggix n
199198 fput tgli1
200199 fnum get ggscr i
@@ -479,7 +478,7 @@ fputc 115
479478 fputc 34
480479 fputc 58
481480 fputc 91
482-for n ulong get fan 0 bound 64
481+for n ulong get fan 0 bound FAMAX
483482 grjitem get ggix n gt n 0
484483 end
485484 fputc 10

growth/tests/check.sh

@@ -226,9 +226,9 @@ check "$(jq -r '.repos[] | select(.name=="cuda-crack") | .path' "$T/b")" "/forge
226226 check "$(jq -r .clones.source "$T/ins.json")" "front-door nginx download log" "clone source"
227227 check "$(jq -r .downloads.source "$T/ins.json")" "forged access log" "download source"
228228 check "$(jq -r .stars.source "$T/ins.json")" "social log" "star source"
229-check "$(jq -r .seeds.source "$T/ins.json")" "this node's Radicle routing table" "seed source"
229+check "$(jq -r .seeds.source "$T/ins.json")" "this node's routing table" "seed source"
230230 check "$(jq -r .contributors.source "$T/ins.json")" "git log author names on the default branch" "contributor source"
231-check "$(jq -r .patches.source "$T/ins.json")" "Radicle patch objects in this repository's storage" "patch source"
231+check "$(jq -r .patches.source "$T/ins.json")" "patch objects in this repository's storage" "patch source"
232232 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/omega-mv/insights.json")
233233 check "$c" 200 "GET omega-mv insights.json"
234234 cp "$T/b" "$T/mv.json"

infra/DEPLOY.md

@@ -278,6 +278,12 @@ Evidence:
278278 | `test/edge-local.sh` in ubuntu:26.04 (nginx 1.28.3, curl 8.18.0), run as a non-root user, stand-in forged | HOST_TESTED | base b55b3389: 53 passed, 0 failed. This change: 85 passed, 0 failed. Mutants each fail: `method` (POST gets 301) 3, `query` (query dropped) 5, `headers` (no security headers) 20, `base` 1, `buffering` 2, `csp` 3, `cspfallback` 3 |
279279 | first draft with a numbered capture (`$1`) | HOST_TESTED, rejected | `%20` came back as `%2520` and `%0d%0a` as `%250d%250a`: fixed with the named capture |
280280 | `test/forge-redirect.sh`: `hub/forge-edge-update.sh` with this tree over a copy of hub /etc/nginx (sha256 b3f2cbc37d7765db) in ubuntu:26.04, old tree hub `/tmp/forge-infra-p23/infra`, the real forged (sha256 858eb9d1…, the b55b3389 build) on the real storage | HOST_TESTED | 33 passed, 0 failed: the hub copy equals the old tree; negative control (old edge) `/forge/drakestapleton` 200; UPDATE OK with its live checks; only aienos-forge.conf changed; 14 redirect rows (301 for GET and HEAD, 308 for POST, query and `%20` kept); the 308 carries all five headers; www.aienos.com/ and 7 interplane.io answers (pages, archive, css) byte-identical before and after; `forge-edge-rollback.sh` restores every file and `/forge/drakestapleton` 200. Two earlier runs differed only in forged's counts line on the repo page, which reads `/var/log/nginx/aienos.access.log` and changes from "not measured" once that log has a line; the test now writes one line before capturing |
281+| the Spark config itself (sudo tar of the Spark's /etc/nginx, certs replaced) on ubuntu:24.04 nginx 1.24.0 with this snippet, router moved to 127.0.0.1:443 (bay 5 F2) | HOST_TESTED | 13 passed, 0 failed: `nginx -t` before and after; 9 redirect rows incl. POST 308 and `%20`; HSTS on the 301; www.aienos.com/ unchanged (`~/handoffs/hive/one-site/ready/spark-config-probe-522b29a.log`) |
282+| Spark apply 2026-11-11T00:07:52Z of main 522b29ab (bay 5 VERDICT MERGE, landed 23:56:50Z, BOARD notice 23:57:27Z), backup `/etc/nginx/forge-backups/20261111T000752Z-forge-redirect/` (old file sha256 53b2c76d…, new 20c3c76e…) | DEPLOYED | `nginx -t` ok, `systemctl reload nginx`. Live from the Mac (00:08Z): `/forge/`, `/forge`, `/forge/explore`, `/forge/search?q=omega`, `/forge/drakestapleton/CUDApp`, `/forge/drakestapleton/hop/releases`, `/forge/login` each 301 to the matching interplane.io address with HSTS, and each target 200; POST `/forge/login` 308 to https://interplane.io/login. www.aienos.com/ (sha256 feb4243b…), /zh-CN/ (a304cf70…) and `/rad/<RID>.git/info/refs` for aienos.com (e933cb4a…) and interplane-forge (5a1b5830…) byte-identical before (00:07:38Z) and after. Spark sites-enabled/interplane.io (cbcd2a89…), forge-proxy/headers/archive unchanged. `smoke.sh` public: 62 passed, 0 site failures, 2 forge failures (Accept: application/json answered text/html on interplane.io, present before the apply; one-interplane's page cache) |
283+| hub `forge-edge-update.sh /tmp/forge-infra-redirect/infra /tmp/forge-infra-p23/infra`, 2026-11-11T00:09Z | NOT_RUN (refused) | "UPDATE ABORTED (nothing changed): only 5146244 KiB free under /var/lib/nginx, need 6291456 KiB". The hub keeps the proxy; it serves only if the router goes back to .192. Rerun the same command once 6 GiB are free there |
284+
285+Roll back (Spark), as applied: `sudo cp -a /etc/nginx/forge-backups/20261111T000752Z-forge-redirect/aienos-forge.conf /etc/nginx/snippets/aienos-forge.conf && sudo nginx -t && sudo systemctl reload nginx`.
286+A rollback does not reach browsers that cached the 301 (bay 5 F1).
281287
282288 ## forged binary: deploy rule and log (spark)
283289

infra/apache/omega-source.conf

new file mode 100644
@@ -0,0 +1,13 @@
1+Listen 127.0.0.1:17941
2+<VirtualHost 127.0.0.1:17941>
3+ ServerName localhost
4+ ScriptAlias /omega-read /usr/local/libexec/interplane/omega-read
5+ <Directory "/usr/local/libexec/interplane">
6+ AllowOverride None
7+ Options +ExecCGI -Indexes
8+ Require local
9+ </Directory>
10+ <Location "/">
11+ Require local
12+ </Location>
13+</VirtualHost>

infra/bazinga/omega-read

new file mode 100755
@@ -0,0 +1,43 @@
1+#!/bin/sh
2+# The clone and both main archives use the same public, filtered repository.
3+set -eu
4+export GIT_PROJECT_ROOT=/var/www/interplane-git
5+export GIT_HTTP_EXPORT_ALL=1
6+notfound() { printf 'Status: 404 Not Found\r\n\r\n'; exit 0; }
7+route=${PATH_INFO#/}
8+name=${route%%/*}
9+case "$name" in ''|[!a-zA-Z0-9]*|*[!a-zA-Z0-9._-]*) notfound ;; esac
10+repo="$GIT_PROJECT_ROOT/$name.git"
11+[ -d "$repo" ] && [ ! -L "$repo" ] || notfound
12+PATH_INFO="/${route#*/}"
13+export GIT_CONFIG_COUNT=3 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0="$repo"
14+export GIT_CONFIG_KEY_1=http.receivepack GIT_CONFIG_VALUE_1=false
15+# http-backend invokes upload-pack on dot after entering this fixed public repo.
16+cd "$repo"
17+export GIT_CONFIG_KEY_2=safe.directory GIT_CONFIG_VALUE_2=.
18+case "$REQUEST_METHOD $PATH_INFO" in
19+ "GET /info/refs"|"POST /git-upload-pack")
20+ case "$REQUEST_METHOD:$QUERY_STRING" in
21+ GET:service=git-upload-pack|GET:|POST:) ;;
22+ *) printf "Status: 403 Forbidden\r\n\r\n"; exit 0 ;;
23+ esac
24+ export PATH_INFO="/$name.git$PATH_INFO"
25+ exec /usr/lib/git-core/git-http-backend
26+ ;;
27+ "GET /archive/"*|"HEAD /archive/"*)
28+ case "$PATH_INFO" in
29+ *.zip) format=zip; mime=application/zip ;;
30+ *.tar.gz) format=tar.gz; mime=application/gzip ;;
31+ *) notfound ;;
32+ esac
33+ branch=${PATH_INFO#/archive/}
34+ branch=${branch%."$format"}
35+ case "$branch" in ''|*[!a-zA-Z0-9._/-]*) notfound ;; esac
36+ git check-ref-format "refs/heads/$branch" >/dev/null || notfound
37+ commit=$(git --git-dir="$repo" rev-parse --verify "refs/heads/$branch^{commit}" 2>/dev/null) || notfound
38+ label=$(printf '%s' "$branch" | tr / -)
39+ printf "Content-Type: %s\r\nContent-Disposition: attachment; filename=%s-%s.%s\r\nETag: \"%s\"\r\nCache-Control: no-cache\r\n\r\n" "$mime" "$name" "$label" "$format" "$commit"
40+ [ "$REQUEST_METHOD" = HEAD ] || exec git --git-dir="$repo" archive --format="$format" --prefix="$name-$label/" "$commit"
41+ ;;
42+ *) printf "Status: 405 Method Not Allowed\r\n\r\n" ;;
43+esac

infra/bazinga/post-update

new file mode 100755
@@ -0,0 +1,5 @@
1+#!/bin/sh
2+# Bazinga git: after every push, refresh the public clone copy of this repository
3+# (https://interplane.io/drakestapleton/<name>.git). Never fails the push.
4+n=$(basename "$(pwd)" .git)
5+"$HOME/.local/lib/bazinga-git/sync.sh" "$n" >> "$HOME/.local/state/bazinga-git/sync.log" 2>&1 || true

infra/bazinga/sync.sh

new file mode 100755
@@ -0,0 +1,53 @@
1+#!/usr/bin/env bash
2+# bazinga-git/sync.sh [name...]: fill the public read-only clone copies behind
3+# git clone https://interplane.io/drakestapleton/<name>.git
4+# from the canonical plain-git repositories spark:~/git/<name>.git (branches and tags only).
5+# Served by nginx as plain files (git "dumb" HTTP) from /var/www/interplane-git/<name>.git.
6+# A name is published only when the owner store catalog lists it as public and neither the name
7+# nor a ref contains pearl/crypto/private (the rule of the old /code page). Run with no names
8+# for all; each ~/git/<name>.git/hooks/post-update runs it for its own name after every push.
9+# Written 2026-11-15 (mac-cc/Recovery, Drake: "put git back in place over interplane.io").
10+set -u
11+unset GIT_DIR GIT_WORK_TREE GIT_QUARANTINE_PATH GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES
12+SRC=${BAZINGA_SRC:-$HOME/git}
13+DST=${BAZINGA_DST:-/var/www/interplane-git}
14+CAT=${BAZINGA_CATALOG:-$HOME/interplane-store-owner/catalog.tsv}
15+BAD='pearl|crypto|private'
16+[ -r "$CAT" ] || { echo "FAIL no catalog $CAT"; exit 2; }
17+if [ $# -gt 0 ]; then names=("$@"); else mapfile -t names < <(ls "$SRC" | sed -n 's/\.git$//p'); fi
18+rc=0
19+for n in "${names[@]}"; do
20+ s=$SRC/$n.git; d=$DST/$n.git
21+ case $n in ''|.*|*/*) echo "SKIP $n bad name"; continue ;; esac
22+ [ -d "$s" ] || { echo "SKIP $n no source"; continue; }
23+ if ! awk -F'\t' -v n="$n" '$1==n && $5=="public" {f=1} END {exit !f}' "$CAT" || echo "$n" | grep -qiE "$BAD"; then
24+ [ -d "$d" ] && rm -rf "$d"
25+ echo "SKIP $n not public"; continue
26+ fi
27+ if [ ! -d "$d" ]; then
28+ git init -q --bare "$d" || { echo "FAIL $n init"; rc=1; continue; }
29+ fi
30+ # Branch downloads represent the stored Git blobs, including export-ignored paths.
31+ attrs='* -export-ignore -export-subst -text -crlf !eol !working-tree-encoding -ident -filter'
32+ if ! grep -Fxq -- "$attrs" "$d/info/attributes" 2>/dev/null; then
33+ printf '\n%s\n' "$attrs" >> "$d/info/attributes" || { rc=1; continue; }
34+ fi
35+ head=$(git --git-dir "$s" symbolic-ref -q HEAD || echo refs/heads/main)
36+ git --git-dir "$d" symbolic-ref HEAD "$head"
37+ specs=()
38+ while read -r r; do
39+ echo "$r" | grep -qiE "$BAD" && continue
40+ specs+=("+$r:$r")
41+ done < <(git --git-dir "$s" for-each-ref --format='%(refname)' refs/heads refs/tags)
42+ [ ${#specs[@]} -gt 0 ] || { echo "SKIP $n no refs"; continue; }
43+ git --git-dir "$s" push -q "$d" "${specs[@]}" || { echo "FAIL $n push"; rc=1; continue; }
44+ # refs gone at the source go here too
45+ git --git-dir "$d" for-each-ref --format='%(refname)' refs/heads refs/tags | while read -r r; do
46+ git --git-dir "$s" show-ref --verify -q "$r" || git --git-dir "$d" update-ref -d "$r"
47+ done
48+ [ "$(find "$d/objects" -maxdepth 1 -type d -name '[0-9a-f][0-9a-f]' | wc -l)" -gt 64 ] && git --git-dir "$d" gc -q 2>/dev/null
49+ git --git-dir "$d" update-server-info
50+ chmod -R a+rX "$d"
51+ echo "OK $n $(git --git-dir "$d" rev-parse --short "$head" 2>/dev/null)"
52+done
53+exit $rc

infra/nginx/conf.d/bazinga-rad-map.conf

new file mode 100644
@@ -0,0 +1,109 @@
1+# Bazinga (2026-11-15): old Radicle clone addresses -> project names, from ~/handoffs/radicle/RIDS.md,
2+# only for projects with a public clone copy in /var/www/interplane-git. Used by snippets/aienos-rad-moved.conf.
3+map $bz_rid $bz_radname {
4+ default "";
5+ z2NwiYftdgkDqkFLMgZTLU3SvZZNw AienOS-nv;
6+ z4RxD8vXigmWg61nM8miQ8DVPAXEP CUDApp;
7+ z3VV142cwPHisuv2wA8oCsP3JegfL MojoLlama;
8+ z6hhF5wGXCqvkcvxYdcBb12qm3FB aegis-runtime-mv;
9+ z35JFzZSUQH3r5RTU58epFMZrY25E agent-archive;
10+ zDTnULpiVMniD2etkbUozUP5mn6U aien;
11+ z37zcFYooiuCCZsf5L74eeFJYiwWM aien-architecture-mv;
12+ z2Ajufz3KS3GompMJ2SJmAz8mRnk6 aien-edge;
13+ z3tjNacwmefzXhmChFjfp6jssEzmK aien-harness;
14+ z26m6Fte5NWoocLbz4DEYdJkzcnLy aien-local-stack;
15+ zzxgxYRc5tw6VwYXkQNLC2hqKkfb aien-protocols-mv;
16+ z4HXNamwwXyfN11ZBJXAQpdMKvojz aien-receipts;
17+ z2MPnsBZpJYeJJq39EXz1SYzLL7mc aien-rig;
18+ z2kdkm8HpiyFbMFpFmzzWZQgTn1EQ aien-sovereign-core;
19+ z44GqrPVAPjZkhoD2MWVjqy18ighN aien-sovereign-core-mv;
20+ zKrfazKqYNFuXDDkYdptxJicGLEq aien-train;
21+ z49FTK9M33MFjenns3vqDqqN66zj7 aien-translate;
22+ zissDAdxGuuY4MzdjZzcXzHfmEU6 aien-yardsticks;
23+ zV8VdbBDCPEZePcnBiseNyym3Wnk aienix;
24+ z3iwnx2pktbGhnfBpJSsaFcTmKgHU aienos.com;
25+ z2Q6ob2gL6Qo5oUMpyehukayVF7mN aienux;
26+ zy7ezZe718HN95wLKGzp4acD5zSX atlas;
27+ z3NKsT1A9VzBVsa5ycpHG2hKZTriE babel;
28+ z2nYCN9XZAPjNohqT8bz46rcs9zvZ benchmarks-mv;
29+ z2Jc5vLu6SJ7uhYDFhxyJsF8F4gsZ cJSON;
30+ zDrGjCcXxPwjWNYQj52Y9RYzBq1t cortex;
31+ z2VKEz9qeswAC7EGhPaTvDRirkXKf cortex-rs;
32+ z3w694J42BU3ztSSkBz319tb7pHky crumb-spec;
33+ z631r2JJiVT8it4tST7RK24hpowi cuda-crack;
34+ z3MVCMcy5dK4TVDTEjyTtPTZdwjV7 drakestapleton-aien-dev;
35+ zUHy4jerA33bbWpgU4DByVKGs3SF encounter;
36+ z3hXva8w8VWik8cUYQjaXnLxoNvpa ggml;
37+ zZnK5QhLTtJTmhHuRi2BtRWQdMU4 ggml-omega;
38+ zdvYzQkgYXvcbKevSqSrcrhQq1qj git;
39+ z3ZSvMF8VFFGa5FyyKXGh4Vv6NBpS gpu-head-to-head;
40+ zVPJPCdCgWVrw97UKxEBzMU3sCDY harvester;
41+ z3vAshKTvZpS5xnsPZHjiHobz4U2p hive-not-swarm;
42+ zimVqDToqH8NL2YvgM8fQBQrvgHa hive-view;
43+ z3KB1AovUygMJkSf56hW7HXWnxeD7 homebrew-omega;
44+ z3uek4Z9YSEAtFXmedDzEG4xvD4XR hop;
45+ z3KFmLGeYdvDAgwpCgdBd1ENW7nU5 interplane-forge;
46+ zNhNbqYvgSBEHBq9vvE8xpbcBzGa interplane-mv;
47+ z399yKvnXcBQNkKoq86iBDgTvQ5QV interplane.io;
48+ z3bQJ4fuRXymu7MN2DW3TV6moUVDK klib;
49+ z3uhnX57UwvzAk3YWM618GZnnkBfs lua;
50+ zrxqhWdxipypXFQ3F8D3HzxDiLRt lz4;
51+ z2gfFGqHPPuhzp6LqcGvRXUrMy2qj mailhand;
52+ z3Konv8McLhn67ZBUiCE4bFR5r9tC mobhub;
53+ z47VdC9EFsF4dFyH1QJ1C2JNJK4JS omega-blas;
54+ z3Hr9ZaiKHwwuNzPK5M8c7uw6pj7y omega-bridge;
55+ z3wKmtAMKXrdg4Lom9W5JeoPBp2iW omega-bridge-kit;
56+ z3EEujVZkpBNXbCVdnrENJuoMKBdg omega-dnn;
57+ z27S4Nwsz11ZjSTEYksmjEV83sNqm omega-gpu-bench;
58+ z2xjD5kxUTTBNCryJ6rg9QXpemzei omega-gpu-driver;
59+ z39gvwWsnkRZsAConQLjaKiNVLHfW omega-harness;
60+ z3dPuHqxqXNYknQg4oBafauWZXwvX omega-kernel-smoke;
61+ z22odFP9kDcxcbzmc2vapZy72ztjT omega-kernel-template;
62+ zvRv2p4QAt3tTmMVszEfnsWoF2r1 omega-lift;
63+ z3e8UBQVfwEcESJrcTWEbyMAHWFBZ omega-mcp;
64+ z6HYc7ot5JZD8FSfvU77pWdMUdru omega-mission;
65+ z3UFqn9qVawkj45izcxXEsLkubCSS omega-mp4;
66+ z6do9WDBhuSnvopDkgFdFr1yWA62 omega-mv;
67+ z46DgsNgCBNEZwcUk3XMDF9hYzhA4 omega-office;
68+ z2BMvbfiNQ7fxq2A3E1vAUsXDDE8r omega-packages;
69+ z3KEetRBZZ3kZVdcpzrBxCSrrhsKu omega-pdf;
70+ z4Yun5Auii2oWtmDnHrm2V4wcZkhU omega-projects;
71+ z3ZYVx6LRT6gkwLc13zR94wtENPn3 omega-rosetta;
72+ z3D8DQxXx82qjuTPhCMfHnphiBcSw omega-seed-challenge;
73+ z3Q6hwu6Ftcvru9NpmgF2XdF9q6pC omega-tool-model;
74+ z2Hxzn2TdMYH5oHb18ZYpP1ZY2SSb omega-zip;
75+ z2Q1eD3rqPUGnsxnhd4dDzFDMQqu omnet;
76+ zcBSb6QfXYD2tVRHF6GmXBALFx66 omtex;
77+ z3JZh1ERNq7y6v2V5yoArKFP3ELVJ omtls;
78+ z2jftNw1LLYTNgj8DNoh1TGGNmEmP open-humanity;
79+ zv2LrXa7mmHpfSKbS6ZAYMNrm9QS openaccel-lab;
80+ z21SQF1DVwRmpxbTMnSiYxXveiRp1 openclaw-rs;
81+ z49She8eifZpLd2aiSvk2pph3DMUo physics-mv;
82+ z2gdVWCB3NdhU8bR3twtT1vTf8Un1 physics0;
83+ z2G9MMmd9tz3RcFRWwjrSVQGXQUVE pi-register;
84+ z4YVa7BSf1MGTrHoJewK8iWQcyHbC rad-id-sync;
85+ z2Jhza2V51dFcMFUhNiFcXHpE5Ewy readings-window;
86+ z2tHGNRke38e8fYtvW1onat1QV8w8 rtl8127-omega;
87+ z2JJz4RDfZZxKGBLn6UhmW5p9VJQj sovereign-intelligence;
88+ z2L6KpjRgTCMbPeuEpggRmecH5Qpc spark-adapters;
89+ z2LKDxnAK3EFfqgr7HTZh6djts65P spark-connector;
90+ z2uQ4JsdQJ8zwrW2Fc3mDro8fJo4g spark-crumbs;
91+ zhE9hwwAEWUup6PaXBcVApAVwEUt spark-debugger;
92+ z4UHi17ttdBX6qAfFutgFaL6s1Aga spark-dream;
93+ z2RVudShJWi3She9WLw3DNZDwYvnB spark-hive;
94+ z4PuE5iVq1optfv8xaEYXp3B4nbt4 spark-inquisitor;
95+ z2zietej47ufRfzb4RNQKwemNxTJ9 spark-rsi;
96+ z4AauBRPXzPNMiAoHZpRpyCee61A2 spark-rsi-mv;
97+ z3HQENMJfT9o14N3oDQtY4YPFak73 spark-supervisor;
98+ z75HnBWg5wKjM6MLK5C3fCyhJbXs sqlite;
99+ zMGRREr2tmtRqpo4mMjpzkZdUGXN synapse;
100+ z4GbvxiCiGHVJdjHjodUSBkjSYKxw synapse-board;
101+ z49HbHSymTiZKMLfpMKRHJcuq2NQv synapse-claims;
102+ z3p7NNQByiXZGsJC4cCifdTybaajY synapse-map;
103+ z3WKv88a3DbKEkvxsu2uDSR7a22ap synapse-mcp;
104+ z3aHmQm9aSg8rD5jEcxJFCSQRh21i synapse-pulse;
105+ z3Jfv1utyaw4Nm83pgmJ4yQfVmpse tree-sitter-omega;
106+ z2cJRW4NtoaUva2wZCPiqxXpMBktn vscode-omega;
107+ z4LivPinyFn7bC3hCDgmXKsqA3beE zlib;
108+ z26aegmgSrbXddU8TS7UwG3WgzbgW zstd;
109+}

infra/nginx/conf.d/forge.conf

@@ -23,7 +23,8 @@ map "$request_method:$proxy_protocol_addr" $forge_post_noaddr {
2323 "POST:" 1;
2424 }
2525
26-# Downloads (archive, raw, release assets): nginx buffers them and spools to
26+# Downloads (archive, raw, release assets, bundles of imported proposals at
27+# /<owner>/<repo>/patches/<id>.bundle): nginx buffers them and spools to
2728 # /var/lib/nginx/proxy what a slow client has not taken yet (see forge-proxy.conf), so forged is
2829 # never held by a slow reader. At most 2 at a time per client, 6 in total: forged caps one
2930 # response at 512 MiB, so the spool stays under 3 GiB of the hub's 6.5 GiB free disk.
@@ -37,7 +38,8 @@ limit_conn_zone $forge_dl_all_key zone=forge_dl_all:1m;
3738 # keep the no-script, same-origin-forms rule: no header at all, or one that is neither a bare
3839 # `sandbox` (no allow-* tokens) nor has both script-src 'none' and form-action 'self'/'none'.
3940 # Browsers enforce every CSP header, so the effective policy is never weaker than the edge's.
40-# Downloads get a sandbox policy as the fallback, pages the edge page policy.
41+# Downloads (the bundle of an imported proposal, /patches/<id>.bundle, included) get a sandbox
42+# policy as the fallback, pages the edge page policy.
4143 map $upstream_http_content_security_policy $forge_csp_sandbox {
4244 default 0;
4345 "~(^|;) *sandbox *(;|$)" 1;
@@ -53,7 +55,7 @@ map $upstream_http_content_security_policy $forge_csp_form {
5355 map "$forge_csp_sandbox$forge_csp_noscript$forge_csp_form:$uri" $forge_csp_edge {
5456 "~^1" "";
5557 "~^011:" "";
56- "~^...:(/forge)?/[^/]+/[^/]+/(archive|raw|releases/download)/"
58+ "~^...:(/forge)?/[^/]+/[^/]+/((archive|raw|releases/download)/|patches/[0-9a-f]{16}\.bundle$)"
5759 "sandbox; default-src 'none'; img-src 'self'; style-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'";
5860 default "default-src 'self'; script-src 'none'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'none'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'";
5961 }
@@ -66,7 +68,20 @@ map $http_user_agent $forge_bot_key {
6668 "~*(bot|crawl|spider|slurp|GoogleOther)" "crawler";
6769 }
6870 limit_req_zone $forge_bot_key zone=forge_bots:1m rate=3r/s;
69-limit_req_zone $proxy_protocol_addr zone=forge_get_ip:10m rate=5r/s;
71+# Home, Files, and README reads have a separate per-address queue. Match the original
72+# request URI because repository homes are routed through the named @forged location.
73+map "$host:$request_method:$request_uri" $forge_source_read {
74+ default 0;
75+ "~^(?:www\.)?interplane\.io:(?:GET|HEAD):/drakestapleton/[A-Za-z0-9][A-Za-z0-9._-]*(?:/?(?:\?|$)|/tree/|/raw/[^?]+/(?i:README)(?:\.[^/?]+)?(?:\?|$))" 1;
76+}
77+map $forge_source_read $forge_page_addr { 1 $proxy_protocol_addr; default ""; }
78+map $forge_source_read $forge_other_addr { 1 ""; default $proxy_protocol_addr; }
79+limit_req_zone $forge_page_addr zone=forge_source_pages:10m rate=10r/s;
80+limit_req_zone $forge_other_addr zone=forge_other_reads:10m rate=5r/s;
81+
82+# Smart Git and branch archives stream without the buffered download disk spool.
83+limit_conn_zone $proxy_protocol_addr zone=forge_git_client:1m;
84+limit_conn_zone $server_name zone=forge_git_streams:1m;
7085
7186 # 2026-11-10 one-interplane (L1058): forged answers one request at a time, so one heavy page held
7287 # everyone (3 to 20 s waits seen). Pages for visitors who send no cookie are identical for everyone
@@ -74,8 +89,10 @@ limit_req_zone $proxy_protocol_addr zone=forge_get_ip:10m rate=5r/s;
7489 # while forged is busy or restarting. Any request with a cookie skips the cache entirely.
7590 # Note: cached hits do not reach forged, so counts taken from forged.log see fewer page reads.
7691 proxy_cache_path /var/cache/nginx/forge levels=1:2 keys_zone=forge_pages:20m max_size=1g inactive=10m use_temp_path=off;
77-map $http_cookie $forge_nocache {
78- "" 0;
92+# Repository HTML and source reads resolve moving refs at request time.
93+map "$http_cookie:$uri" $forge_nocache {
94+ ~^:/drakestapleton/[A-Za-z0-9._-]+(?:/?$|/(?:tree|blob|raw)/) 1;
95+ ~^: 0;
7996 default 1;
8097 }
8198

infra/nginx/sites-enabled/interplane.io

@@ -15,6 +15,10 @@ server {
1515 ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305;
1616 ssl_prefer_server_ciphers off;
1717 ssl_session_tickets off;
18+ # Keep first connections alive through packet loss during TLS and header exchange.
19+ # Returning clients can resume a session without enabling stateless tickets.
20+ client_header_timeout 120s;
21+ ssl_session_cache shared:interplane_sessions:4m;
1822 access_log off;
1923 root /var/www/interplane.io;
2024 index index.html;
@@ -27,6 +31,8 @@ server {
2731 add_header Referrer-Policy no-referrer always;
2832 add_header Content-Security-Policy "default-src 'self'; script-src 'none'; style-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'" always;
2933
34+ include /etc/nginx/snippets/bazinga-git.conf;
35+
3036 # L1057 guard, 2026-11-10 (one-interplane): the deployed forged build 408091d1 exits when the path
3137 # segment after /patches/ or /issues/ is longer than 128 bytes (collab copost scan). Refuse that
3238 # shape here so it never reaches forged. Remove after a build containing fix 5b6bbfd is deployed.
@@ -64,4 +70,28 @@ server {
6470 proxy_set_header X-Forge-Base "/";
6571 proxy_pass http://forged;
6672 }
73+
74+ # Git patch upload (POST /<owner>/<repo>/patches/new, docs/API.md "Git patches"): forged reads
75+ # a body of up to 3145728 bytes (server/main.om HBCAP), so this path alone gets that limit;
76+ # every other path keeps the server's 64k. Not cached (the form page carries a CSRF token).
77+ location ~ "^/[^/]+/[^/]+/patches/new$" {
78+ include /etc/nginx/snippets/forge-headers.conf;
79+ include /etc/nginx/snippets/forge-proxy.conf;
80+ client_max_body_size 3145728;
81+ proxy_set_header X-Forge-Base "/";
82+ proxy_pass http://forged;
83+ }
84+
85+ # Bundle of an imported proposal (GET /<owner>/<repo>/patches/<id>.bundle, up to forged's
86+ # 512 MiB): a download like the ones above, with the same includes, so it shares their
87+ # limits (2 at a time per client and 6 in total, counted together with archive, raw and
88+ # release downloads; 429 beyond) and is not kept in the page cache. Every other /patches
89+ # path (<id>, <id>.patch, <id>.diff, the list) stays in @forged.
90+ location ~ "^/[^/]+/[^/]+/patches/[0-9a-f]{16}\.bundle$" {
91+ include /etc/nginx/snippets/forge-headers.conf;
92+ include /etc/nginx/snippets/forge-proxy.conf;
93+ include /etc/nginx/snippets/forge-archive.conf;
94+ proxy_set_header X-Forge-Base "/";
95+ proxy_pass http://forged;
96+ }
6797 }

infra/nginx/snippets/aienos-rad-moved.conf

new file mode 100644
@@ -0,0 +1,11 @@
1+# Bazinga (2026-11-15): clone addresses printed before 2026-11-14
2+# https://www.aienos.com/rad/<id>.git
3+# keep working: they answer a redirect to the project's git address on interplane.io
4+# https://interplane.io/drakestapleton/<name>.git
5+# (git follows a redirect on its first request). Names come from conf.d/bazinga-rad-map.conf.
6+# No Radicle program or storage is involved. Included in the www.aienos.com server block.
7+# Undo: remove the include line and conf.d/bazinga-rad-map.conf, nginx -t, reload.
8+location ~ "^/rad/(?<bz_rid>z[1-9A-HJ-NP-Za-km-z]{20,60})\.git(?:/z6Mk[1-9A-HJ-NP-Za-km-z]+)?(?<bz_rest>/[A-Za-z0-9._/-]*)?$" {
9+ if ($bz_radname = "") { return 404; }
10+ return 301 https://interplane.io/drakestapleton/$bz_radname.git$bz_rest$is_args$args;
11+}

infra/nginx/snippets/bazinga-git.conf

new file mode 100644
@@ -0,0 +1,54 @@
1+# Bazinga git (2026-11-15, Drake: "put git back in place over interplane.io"): read-only
2+# git clone over HTTPS for the public projects:
3+# git clone https://interplane.io/drakestapleton/<name>.git
4+# (the address the forge pages and their JSON print). The same address without ".git" (the project
5+# page's own address, https://interplane.io/drakestapleton/<name>) answers git too (2026-11-16), and
6+# https://interplane.io/projects/<name>/repo.git, the store layout pages printed before DRA-515, is
7+# still answered so old clones keep working. The name is matched lazily, so "<name>.git/..." is
8+# <name>, never "<name>.git"; the forge itself has no page under HEAD, info/ or objects/.
9+# Plain files (git's "dumb" HTTP) from /var/www/interplane-git/<name>.git, filled from the canonical
10+# spark ~/git/<name>.git by ~/.local/lib/bazinga-git/sync.sh after every push (post-update hook).
11+# Only git's own fixed file names are answered; nothing else under the copies is reachable.
12+# Included inside the interplane.io server block. Undo: remove the include line, nginx -t, reload.
13+# Smart HTTP uses only the public mirror root maintained by sync.sh.
14+location ~ "^/(?:drakestapleton/(?<sr>[A-Za-z0-9][A-Za-z0-9._-]*?)(?:\.git)?|projects/(?<sp>[A-Za-z0-9][A-Za-z0-9._-]*)/repo\.git)/(?<op>info/refs|git-upload-pack)$" {
15+ set $read_uri /omega-read/$sr$sp/$op;
16+ rewrite ^ $read_uri break;
17+ proxy_read_timeout 300s;
18+ proxy_buffering off;
19+ gzip off;
20+ limit_conn forge_git_client 16;
21+ limit_conn forge_git_streams 24;
22+ limit_conn_status 429;
23+ proxy_set_header Host localhost;
24+ add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
25+ add_header X-Content-Type-Options nosniff always;
26+ proxy_pass http://127.0.0.1:17941;
27+}
28+location ~ "^/drakestapleton/(?<ar>[A-Za-z0-9][A-Za-z0-9._-]*)/archive/refs/heads/(?<af>[A-Za-z0-9._/-]+\.(?:zip|tar\.gz))$" {
29+ set $archive_uri /omega-read/$ar/archive/$af;
30+ rewrite ^ $archive_uri break;
31+ proxy_read_timeout 300s;
32+ proxy_buffering off;
33+ gzip off;
34+ limit_conn forge_git_client 16;
35+ limit_conn forge_git_streams 24;
36+ limit_conn_status 429;
37+ proxy_set_header Host localhost;
38+ add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
39+ add_header X-Content-Type-Options nosniff always;
40+ proxy_pass http://127.0.0.1:17941;
41+}
42+location ~ "^/(?:drakestapleton/(?<bzn>[A-Za-z0-9][A-Za-z0-9._-]*?)(?:\.git)?|projects/(?<bzm>[A-Za-z0-9][A-Za-z0-9._-]*)/repo\.git)/(?<bzp>HEAD|info/refs|objects/info/packs|objects/[0-9a-f][0-9a-f]/[0-9a-f]+|objects/pack/pack-[0-9a-f]+\.(?:pack|idx))$" {
43+ root /var/www/interplane-git;
44+ try_files /$bzn$bzm.git/$bzp =404;
45+ types { }
46+ default_type application/octet-stream;
47+ add_header Cache-Control "no-cache" always;
48+ add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
49+ add_header X-Content-Type-Options nosniff always;
50+}
51+# A browser opening the clone address lands on the project page.
52+location ~ "^/drakestapleton/(?<bzr>[A-Za-z0-9][A-Za-z0-9._-]*)\.git/?$" { return 302 /drakestapleton/$bzr; }
53+# One-command sign-in helper (source: interplane-forge social/signin.sh).
54+location = /signin.sh { alias /var/www/bazinga/signin.sh; types { } default_type "text/plain; charset=utf-8"; add_header Cache-Control "no-cache" always; add_header X-Content-Type-Options nosniff always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; }

infra/nginx/snippets/forge-archive.conf

@@ -1,5 +1,6 @@
11 # /etc/nginx/snippets/forge-archive.conf on hub - extra settings for downloads:
22 # /<owner>/<repo>/archive/..., /<owner>/<repo>/raw/..., /<owner>/<repo>/releases/download/...
3+# and /<owner>/<repo>/patches/<id>.bundle (the bundle of an imported proposal).
34 # Include AFTER forge-proxy.conf, which buffers and spools every forged response (forged is never
45 # held by a slow client). Downloads are the large responses, so their concurrency is capped:
56 # 2 per client and 6 in total (zones in conf.d/forge.conf), which bounds the disk spool.

infra/nginx/snippets/forge-proxy.conf

@@ -6,11 +6,14 @@
66 if ($forge_post_noaddr) { return 503; }
77 limit_except GET HEAD POST { deny all; }
88 limit_req zone=forge_post burst=10 nodelay;
9-limit_req zone=forge_get_ip burst=30 nodelay;
9+limit_req zone=forge_other_reads burst=30 nodelay;
10+limit_req zone=forge_source_pages burst=128 delay=8;
1011 limit_req zone=forge_bots burst=10;
1112 limit_req_status 429;
1213
13-client_max_body_size 64k;
14+# Body size: client_max_body_size is the including server block's (64k on interplane.io), so the
15+# one location that takes larger bodies (the git patch upload, 3145728 bytes) can raise it; set
16+# here too, it would be a duplicate directive in that location.
1417 client_body_buffer_size 64k;
1518
1619 # forged speaks HTTP/1.1, but nginx->upstream stays HTTP/1.0 + Connection: close: one

infra/smoke.sh

@@ -43,10 +43,15 @@ magic() { # magic PATH HEXPREFIX LABEL
4343 profile() { # profile NAME ROOT FBASE
4444 NAME=$1 ROOT=$2 FBASE=$3
4545 echo "== $NAME (base $FBASE)"
46- # 10 forge routes that must answer 200
47- for p in explore drakestapleton $R $R/tree/main $R/commits/main $R/blob/main/README.md $R/issues $R/patches; do
46+ # 10 forge routes that must answer 200. In the store-reading build (SANDBOX_STORE=1 / SMOKE_STORE=1)
47+ # collab/ is composed out: patches and issues answer the seam's 501.
48+ ST=${SMOKE_STORE:-${SANDBOX_STORE:-0}}
49+ for p in explore drakestapleton $R $R/tree/main $R/commits/main $R/blob/main/README.md; do
4850 want forge 200 GET "$p"
4951 done
52+ for p in $R/issues $R/patches; do
53+ if [ "$ST" = 1 ]; then want forge 501 GET "$p"; else want forge 200 GET "$p"; fi
54+ done
5055 magic "$R/archive/refs/heads/main.zip" 504b0304 zip
5156 magic "$R/archive/refs/heads/main.tar.gz" 1f8b gzip
5257 want forge 200 GET "$R/releases"
@@ -86,7 +91,9 @@ profile() { # profile NAME ROOT FBASE
8691 req forge GET explore.json
8792 grep -q '"schema":"forge/explore/1","base":"'"$FBASE"'"' "$T/b" && ok forge "explore.json schema forge/explore/1, base $FBASE" || bad forge "explore.json schema/base"
8893 req forge GET "$R.json"
89- grep -q '"schema":"forge/repo/1"' "$T/b" && grep -q '"rid":"rad:'"$RID_OK"'"' "$T/b" && grep -q '"git_fetches":{"count":' "$T/b" && ok forge "$R.json schema forge/repo/1, RID, counts" || bad forge "$R.json schema/rid/counts"
94+ # the repo id: the bare old id (Radicle build); the store build's git:<id> (its old id kept for /rad: links)
95+ idpat='"rid":"'"$RID_OK"'"'; [ "$ST" = 1 ] && idpat='"rid":"git:[0-9a-f]\{64\}"'
96+ grep -q '"schema":"forge/repo/1"' "$T/b" && grep -q "$idpat" "$T/b" && grep -q '"git_fetches":{"count":' "$T/b" && ok forge "$R.json schema forge/repo/1, RID, counts" || bad forge "$R.json schema/rid/counts"
9097 req forge GET explore -H 'Accept: application/json'
9198 case "$ctype" in application/json*) ok forge "explore with Accept: application/json is JSON";; *) bad forge "explore with Accept JSON: '$ctype'";; esac
9299 req forge GET "$R" -H 'Accept: application/json'
@@ -95,7 +102,12 @@ profile() { # profile NAME ROOT FBASE
95102 grep -q "<link rel=\"alternate\" type=\"application/json\" href=\"${FBASE}explore.json\">" "$T/b" && ok forge "explore links ${FBASE}explore.json" || bad forge "explore has no alternate link"
96103 req forge GET "$R"
97104 grep -q "<link rel=\"alternate\" type=\"application/json\" href=\"${FBASE}${R}.json\">" "$T/b" && ok forge "$R links ${FBASE}${R}.json" || bad forge "$R has no alternate link"
98- grep -q '<p class="meta">Clones and fetches over HTTPS: ' "$T/b" && grep -q '<p class="meta">Downloads: ' "$T/b" && grep -q '<p class="meta">Radicle: ' "$T/b" && ok forge "$R header shows clone, download and seeding counts" || bad forge "$R header lacks the count lines"
105+ # the store build has no node: no seeding line
106+ if [ "$ST" = 1 ]; then
107+ grep -q '<p class="meta">Clones and fetches over HTTPS: ' "$T/b" && grep -q '<p class="meta">Downloads: ' "$T/b" && ! grep -q '<p class="meta">Seeding: ' "$T/b" && ok forge "$R header shows clone and download count lines, no seeding line" || bad forge "$R header lacks the count lines"
108+ else
109+ grep -q '<p class="meta">Clones and fetches over HTTPS: ' "$T/b" && grep -q '<p class="meta">Downloads: ' "$T/b" && grep -q '<p class="meta">Seeding: ' "$T/b" && ok forge "$R header shows clone, download and seeding count lines" || bad forge "$R header lacks the count lines"
110+ fi
99111 want forge 404 GET drakestapleton/omega-pearl.json
100112 want forge 404 GET drakestapleton/aien-crypto.json
101113 want forge 404 GET drakestapleton/no-such-repo-smoke.json

infra/spark/forged-public.sh

@@ -60,20 +60,51 @@ public_sync() {
6060 if [[ ! ${wanted[$name]+yes} ]]; then rm -f -- "$f" || return 2; fi
6161 done
6262 }
63-# Match the first table and field/deny limits in server/repos.om.
63+# Match the first table and field/deny limits in server/repos.om and server/radsrc.om: radsrc reads
64+# at most FAMAX (256, server/util.om) rows of the first table. Nothing is dropped silently: a row past
65+# FAMAX and a row outside the row rules each get one stderr line naming the row (its table row number
66+# and the repo cell, control bytes shown as ?). A row on the deny list is left out on purpose, without one.
6467 public_rids() {
6568 [[ -f $PUBLIC/RIDS.md && ! -L $PUBLIC/RIDS.md ]] || return 0
6669 awk -F '|' '
70+ function warn(why) { r = $2; gsub(/[^ -~]/, "?", r); printf "forged-public: RIDS.md row %d (%s) not bound: %s\n", rows, substr(r, 1, 120), why > "/dev/stderr" }
6771 /^\| repo \| RID \| default branch/ { if (seen) exit; seen=1; getline; next }
6872 seen && !/^\|/ { exit }
69- seen { if (rows++ >= 64) exit; for(i=2;i<=4;i++) gsub(/^ +| +$/, "", $i)
70- if ($2 ~ /^[A-Za-z0-9_.-]+$/ && length($2)<=100 &&
71- $3 ~ /^rad:[A-Za-z0-9]+$/ && length($3)>=6 && length($3)<=64 &&
72- $4 ~ /^[A-Za-z0-9_.\/-]+$/ && length($4)<=60 &&
73- $2!="omega-pearl" && $2!="aien-crypto" &&
74- $3!="rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ") print substr($3,5)
73+ seen { rows++; for(i=2;i<=4;i++) gsub(/^ +| +$/, "", $i)
74+ if (rows > 256) { warn("past FAMAX (256 rows of the first table)"); next }
75+ if (!($2 ~ /^[A-Za-z0-9_.-]+$/ && length($2)<=100)) { warn("name outside the row rules"); next }
76+ if (!($3 ~ /^rad:[A-Za-z0-9]+$/ && length($3)>=6 && length($3)<=64)) { warn("RID outside the row rules"); next }
77+ if (!($4 ~ /^[A-Za-z0-9_.\/-]+$/ && length($4)<=60)) { warn("branch outside the row rules"); next }
78+ if ($2=="omega-pearl" || $2=="aien-crypto" || $3=="rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ") next
79+ print substr($3,5)
7580 }' "$PUBLIC/RIDS.md" | LC_ALL=C sort -u
7681 }
82+# store_names ROOT: the projects of the native store at ROOT that the store-reading build serves, one
83+# name a line, in catalog order: the forged-sandbox.sh FORGED_STORE path binds only these. The rule is
84+# store/repos.om's (every public catalog line, Drake 2026-11-14), less what forged would refuse by the
85+# line alone: a line without five tab-separated fields, a name outside [A-Za-z0-9_.-] or longer than
86+# 100 bytes (or . or ..), the deny list (server/repos.om fdeny: the names omega-pearl and
87+# aien-crypto, and a records/1 alias rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ), public lines past FAMAX (256).
88+# Each line left out for a rule or for FAMAX gets one stderr line naming it; private and denied lines
89+# are left out without one. A records/1 that is missing or a link is not read here (forged refuses
90+# that project itself; binding it gives the sandbox nothing the catalog does not name).
91+store_names() {
92+ local root=${1:?store_names ROOT} name rec
93+ [[ -f $root/catalog.tsv && ! -L $root/catalog.tsv ]] || return 0
94+ while IFS= read -r name; do
95+ rec=$root/projects/$name/records/1
96+ if [[ -f $rec && ! -L $rec ]] && grep -qx 'alias rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ' -- "$rec"; then continue; fi
97+ printf '%s\n' "$name"
98+ done < <(awk -F '\t' '
99+ function warn(why) { r = $1; gsub(/[^ -~]/, "?", r); printf "forged-public: catalog line %d (%s) not bound: %s\n", NR, substr(r, 1, 120), why > "/dev/stderr" }
100+ NF != 5 { warn("not five tab-separated fields"); next }
101+ $5 != "public" { next }
102+ { pub++ }
103+ pub > 256 { warn("past FAMAX (256 public lines)"); next }
104+ $1 !~ /^[A-Za-z0-9_.-]+$/ || length($1) > 100 || $1 == "." || $1 == ".." { warn("name outside the name rule"); next }
105+ $1 == "omega-pearl" || $1 == "aien-crypto" { next }
106+ { print $1 }' "$root/catalog.tsv")
107+}
77108 public_repos() {
78109 local rid repo resolved
79110 while IFS= read -r rid; do

infra/spark/forged-sandbox.sh

@@ -51,7 +51,34 @@ case "$bin" in "$PUBLIC"/*) die 'refusing a forged binary inside the export dire
5151 READ_HOME=$src
5252 source "${FORGED_PUBLIC_LIB:-$(dirname "$0")/forged-public.sh}"
5353 rids=$PUBLIC/RIDS.md
54-[[ -f $rids && ! -L $rids ]] || die 'public repository list missing or a symlink'
54+# The Radicle build reads the public list at run time; the store-reading build never does (its served
55+# set is the store's catalog), so a missing RIDS.md must not stop it.
56+if [[ -z ${FORGED_STORE:-} ]]; then
57+ [[ -f $rids && ! -L $rids ]] || die 'public repository list missing or a symlink'
58+fi
59+# The native store (store-reading build, interplane-native DESIGN.md step 2): FORGED_STORE is its
60+# root on the host. The root is bound read-only, whole (catalog.tsv is replaced by rename on every
61+# change, so a file bind would keep the old one), at the path the binary was built with: the same
62+# path, or under the compiled home when it lies under the published-inputs home. ROOT/projects is then
63+# covered by an empty read-only tmpfs and only the projects the build serves (forged-public.sh
64+# store_names: public lines, valid names, not on the deny list) are bound back, each read-only, with
65+# its staging/ (landings in progress) and repo.git.migration/ (import evidence) covered by empty
66+# tmpfs; import-notes/ is covered the same way and import.tsv and IMPORT-RECEIPT.txt by /dev/null.
67+# So a private, denied or unlisted project is not in the sandbox at all. A project created after the
68+# start is bound only at the next start (landings into bound projects are visible at once: the
69+# project folder is bound, not a snapshot of it). The store holds no key (the signing key is kept
70+# outside it). Without FORGED_STORE the Radicle repositories of the public list are bound as before.
71+store=
72+if [[ -n ${FORGED_STORE:-} ]]; then
73+ [[ $FORGED_STORE = /* && ! -L ${FORGED_STORE%/} ]] || die 'FORGED_STORE must be an absolute path and not a link'
74+ store=$(realpath -e "$FORGED_STORE") || die 'FORGED_STORE missing'
75+ [[ -d $store && -f $store/catalog.tsv && ! -L $store/catalog.tsv ]] || die 'FORGED_STORE has no catalog.tsv'
76+ [[ $store != / && $store != "$HOME" && $store != "$src" ]] || die 'FORGED_STORE is too broad'
77+ case "$store/" in "$data/"*|"$PUBLIC/"*) die 'FORGED_STORE is inside data or export';; esac
78+ case "$data/" in "$store/"*) die 'FORGED_STORE holds the data directory';; esac
79+ case "$bin" in "$store"/*) die 'refusing a forged binary inside the store';; esac
80+ case "$store/" in "$src/"*) store_at=$dst/${store#"$src"/} ;; *) store_at=$store ;; esac
81+fi
5582
5683 # Network. By default the server gets a network namespace of its own with nothing in it. It
5784 # serves on a listener made outside by the seeded-Omega helper forged-listen: the service
@@ -84,6 +111,8 @@ case ${FORGED_NETNS:-on} in
84111 keep=(HOME="$HOME" PATH=/usr/bin:/bin FORGED_SANDBOX=on FORGED_NETNS=on
85112 FORGED_READ_HOME="$src" FORGED_PATH_HOME="$dst" FORGE_DATA="$data" FORGED_PUBLIC_DIR="$PUBLIC"
86113 FORGED_SALVAGE="${FORGED_SALVAGE:-off}")
114+ keep+=(FORGED_PUBLIC_GIT="${FORGED_PUBLIC_GIT:-off}")
115+ [[ -z ${FORGED_STORE:-} ]] || keep+=(FORGED_STORE="$FORGED_STORE")
87116 [[ -z ${FORGED_PUBLIC_LIB:-} ]] || keep+=(FORGED_PUBLIC_LIB="$FORGED_PUBLIC_LIB")
88117 [[ -z ${FORGED_SECCOMP:-} ]] || keep+=(FORGED_SECCOMP="$FORGED_SECCOMP")
89118 [[ -z ${FORGED_COMMUNITY_PUB:-} ]] || keep+=(FORGED_COMMUNITY_PUB="$FORGED_COMMUNITY_PUB")
@@ -119,6 +148,43 @@ args=(--unshare-user --unshare-pid --unshare-ipc --unshare-uts "${net[@]}"
119148 --bind "$data" "$dst/forge-data"
120149 --ro-bind "$data/logs" "$dst/forge-data/logs"
121150 --ro-bind "$data/forged-supervisor.pid" "$dst/forge-data/forged-supervisor.pid")
151+if [[ -n $store ]]; then
152+ # Upload and bundle work trees use a separate, bounded filesystem. A restart discards them.
153+ patch_work=$data/patch-work
154+ [[ ! -L $patch_work ]] || die 'patch-work is a symlink'
155+ mkdir -p -m 0700 "$patch_work" || die 'cannot prepare patch-work'
156+ args+=(--size 268435456 --tmpfs "$dst/forge-data/patch-work" --chmod 0700 "$dst/forge-data/patch-work")
157+ [[ -d $store/projects && ! -L $store/projects ]] || die 'FORGED_STORE has no projects folder, or it is a link'
158+ args+=(--ro-bind "$store" "$store_at")
159+ args+=(--tmpfs "$store_at/projects")
160+ if [[ ${FORGED_PUBLIC_GIT:-off} = on ]]; then
161+ [[ -d /var/www/interplane-git && ! -L /var/www/interplane-git ]] || die 'public Git mirror missing'
162+ args+=(--dir /app/public-git)
163+ fi
164+ while IFS= read -r name; do
165+ p=$store/projects/$name
166+ [[ -d $p && ! -L $p ]] || continue
167+ args+=(--ro-bind "$p" "$store_at/projects/$name")
168+ if [[ ${FORGED_PUBLIC_GIT:-off} = on ]]; then
169+ mirror=/var/www/interplane-git/$name.git
170+ if [[ -d $mirror && ! -L $mirror ]]; then
171+ args+=(--ro-bind "$mirror" "/app/public-git/$name.git")
172+ fi
173+ fi
174+ for sub in staging repo.git.migration; do
175+ if [[ -d $p/$sub && ! -L $p/$sub ]]; then
176+ args+=(--tmpfs "$store_at/projects/$name/$sub" --remount-ro "$store_at/projects/$name/$sub")
177+ fi
178+ done
179+ done < <(store_names "$store")
180+ args+=(--remount-ro "$store_at/projects")
181+ if [[ -d $store/import-notes && ! -L $store/import-notes ]]; then
182+ args+=(--tmpfs "$store_at/import-notes" --remount-ro "$store_at/import-notes")
183+ fi
184+ for f in import.tsv IMPORT-RECEIPT.txt; do
185+ if [[ -f $store/$f && ! -L $store/$f ]]; then args+=(--ro-bind /dev/null "$store_at/$f"); fi
186+ done
187+fi
122188
123189 # The salvage store (submissions). Off unless FORGED_SALVAGE=on. The store is <data>/salvage/: the
124190 # server keeps drafts, records and the one job file there. Verification is not done in here: the
@@ -152,17 +218,21 @@ case ${FORGED_SALVAGE:-off} in
152218 *) die 'FORGED_SALVAGE must be on or off' ;;
153219 esac
154220
155-# Same selection as the supervisor digest. Only individually allowed bare repos.
156-while IFS=$'\t' read -r rid repo identity; do
157- [[ -n $rid ]] || continue
158- args+=(--ro-bind "$repo" "$dst/.radicle/storage/$rid")
159-done < <(public_repos)
221+# Same selection as the supervisor digest. Only individually allowed bare repos (the Radicle
222+# build; a store-reading build reads the store bound above instead).
223+if [[ -z $store ]]; then
224+ while IFS=$'\t' read -r rid repo identity; do
225+ [[ -n $rid ]] || continue
226+ args+=(--ro-bind "$repo" "$dst/.radicle/storage/$rid")
227+ done < <(public_repos)
228+fi
160229
161230 # Executables used by the server, plus prlimit, which sets the resource limits from inside the
162231 # user namespace and then execs forged. The installed Git uses its built-in gzip.
163232 # No shell or general /usr,
164233 # /etc, host /proc, sockets, home, working trees, credentials or SSH agent mount.
165234 programs=(/usr/bin/git /usr/bin/ssh-keygen /usr/bin/prlimit)
235+[[ -z $store ]] || programs+=(/usr/bin/stat)
166236 for program in "${programs[@]}"; do
167237 [[ -x $program ]] || die "missing $program"
168238 args+=(--ro-bind "$program" "$program")
@@ -172,10 +242,18 @@ dependencies=$(ldd "${programs[@]}") || die 'ldd failed'
172242 mapfile -t libs < <(printf '%s\n' "$dependencies" | awk '
173243 /=> \// {print $3} $1 ~ /^\// && $2 ~ /^\(/ {print $1}' | sort -u)
174244 ((${#libs[@]})) || die 'could not resolve dynamic libraries'
245+gconv=
175246 for lib in "${libs[@]}"; do
176247 resolved=$(realpath -e "$lib")
177248 args+=(--ro-bind "$resolved" "$lib")
249+ [[ ${lib##*/} != libc.so.* ]] || gconv=${resolved%/*}/gconv
178250 done
251+# The patch intake's git am converts a mail written in another charset to UTF-8 (git mailinfo,
252+# iconv), and glibc loads every such converter, ISO-8859-1 included, from its gconv folder beside
253+# libc (/usr/lib/aarch64-linux-gnu/gconv here). Without it git am stops with "cannot convert from
254+# ISO-8859-1 to UTF-8". Read-only system modules, mounted at the same path.
255+[[ -n $gconv && -d $gconv && ! -L $gconv ]] || die 'missing the glibc gconv folder beside libc'
256+args+=(--ro-bind "$gconv" "$gconv")
179257 # ssh-keygen looks up its own uid. Supply one synthetic entry, no host account database.
180258 exec {passwd_fd}<<<"forged:x:$(id -u):$(id -g):forged:/nonexistent:/bin/sh"
181259 args+=(--ro-bind-data "$passwd_fd" /etc/passwd)

infra/spark/forged-service.sh

@@ -70,6 +70,9 @@ service_env() {
7070 FORGED_COUNTS_INTERVAL="${FORGED_COUNTS_INTERVAL:-900}"
7171 FORGED_COUNTS_STATE="${FORGED_COUNTS_STATE:-$DATA/../forge-counts-state}"
7272 FORGED_MIRROR_INTERVAL="$INTERVAL" FORGED_SALVAGE="${FORGED_SALVAGE:-off}")
73+ # the native store root of a store-reading build (forged-sandbox.sh binds it read-only)
74+ svc_env+=(FORGED_PUBLIC_GIT="${FORGED_PUBLIC_GIT:-off}")
75+ [[ -z ${FORGED_STORE:-} ]] || svc_env+=(FORGED_STORE="$FORGED_STORE")
7376 [[ -z ${FORGED_PUBLIC_LIB:-} ]] || svc_env+=(FORGED_PUBLIC_LIB="$FORGED_PUBLIC_LIB")
7477 [[ -z ${FORGED_LISTEN_HELPER:-} ]] || svc_env+=(FORGED_LISTEN_HELPER="$FORGED_LISTEN_HELPER")
7578 [[ -z ${FORGED_SECCOMP:-} ]] || svc_env+=(FORGED_SECCOMP="$FORGED_SECCOMP")

infra/spark/interplane-chain.service

@@ -1,10 +1,10 @@
11 # INTERPLANE proof chain of the hive board. Install: chain/README.md "Service".
22 [Unit]
3-Description=INTERPLANE proof chain: one record per new line of the hive board, by digest only (continuous; inotify through aien-onchange, at most once a minute)
3+Description=INTERPLANE proof chain: one record per new line of the hive board, by digest only, and the page that shows the head (continuous; inotify through aien-onchange, at most once a minute)
44
55 [Service]
66 WorkingDirectory=%h/forge-data/proof
7-ExecStart=%h/.local/bin/aien-onchange 60 86400 %h/handoffs -- %h/.local/share/interplane-chain/chain feed %h/forge-data/proof/board.tsv %h/handoffs/BOARD.md MSG hive-board
7+ExecStart=%h/.local/bin/aien-onchange 60 86400 %h/handoffs -- %h/.local/share/interplane-chain/chain feed %h/forge-data/proof/board.tsv %h/handoffs/BOARD.md MSG hive-board %h/forge-data/proof/index.html
88 Restart=always
99 RestartSec=5
1010 Nice=15

infra/spark/nginx/sites-interplane.io

@@ -15,6 +15,10 @@ server {
1515 ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305;
1616 ssl_prefer_server_ciphers off;
1717 ssl_session_tickets off;
18+ # Keep first connections alive through packet loss during TLS and header exchange.
19+ # Returning clients can resume a session without enabling stateless tickets.
20+ client_header_timeout 120s;
21+ ssl_session_cache shared:interplane_sessions:4m;
1822 access_log off;
1923 root /var/www/interplane.io;
2024 index index.html;
@@ -64,4 +68,28 @@ server {
6468 proxy_set_header X-Forge-Base "/";
6569 proxy_pass http://forged;
6670 }
71+
72+ # Git patch upload (POST /<owner>/<repo>/patches/new, docs/API.md "Git patches"): forged reads
73+ # a body of up to 3145728 bytes (server/main.om HBCAP), so this path alone gets that limit;
74+ # every other path keeps the server's 64k. Not cached (the form page carries a CSRF token).
75+ location ~ "^/[^/]+/[^/]+/patches/new$" {
76+ include /etc/nginx/snippets/forge-headers.conf;
77+ include /etc/nginx/snippets/forge-proxy.conf;
78+ client_max_body_size 3145728;
79+ proxy_set_header X-Forge-Base "/";
80+ proxy_pass http://forged;
81+ }
82+
83+ # Bundle of an imported proposal (GET /<owner>/<repo>/patches/<id>.bundle, up to forged's
84+ # 512 MiB): a download like the ones above, with the same includes, so it shares their
85+ # limits (2 at a time per client and 6 in total, counted together with archive, raw and
86+ # release downloads; 429 beyond) and is not kept in the page cache. Every other /patches
87+ # path (<id>, <id>.patch, <id>.diff, the list) stays in @forged.
88+ location ~ "^/[^/]+/[^/]+/patches/[0-9a-f]{16}\.bundle$" {
89+ include /etc/nginx/snippets/forge-headers.conf;
90+ include /etc/nginx/snippets/forge-proxy.conf;
91+ include /etc/nginx/snippets/forge-archive.conf;
92+ proxy_set_header X-Forge-Base "/";
93+ proxy_pass http://forged;
94+ }
6795 }

infra/test/count-snapshot.py

@@ -33,9 +33,9 @@ def counts(): return json.loads(request(PREFIX+'.json'))['counts']
3333 def check_available():
3434 v = counts()
3535 assert v['git_fetches']['count'] == 7, v
36- assert v['upload_pack_requests']['count'] == 8, v
36+ assert v['upload_pack_requests']['count'] is None, v
3737 assert v['downloads']['count'] == 19, v
38- assert v['radicle_seeds']['count'] == 3, v
38+ assert v['seeds']['count'] is None, v
3939 assert b'<b>7</b>' in request(PREFIX)
4040
4141 def unavailable():
@@ -45,9 +45,12 @@ def unavailable():
4545 assert request('/')
4646
4747 def available():
48+ # since the Radicle-text removal (c1f107df) upload_pack_requests and seeds are retired: always null,
49+ # and the Seeding line always says "not measured"; the counts a snapshot carries are the other two
4850 v = counts()
49- assert all(x['count'] is not None for x in v.values()), v
50- assert b'not measured' not in request(PREFIX)
51+ assert v['git_fetches']['count'] is not None and v['downloads']['count'] is not None, v
52+ assert v['upload_pack_requests']['count'] is None and v['seeds']['count'] is None, v
53+ assert b'Clones and fetches over HTTPS: <b>not measured' not in request(PREFIX)
5154
5255 def good(stamp=None, **changes):
5356 stamp = int(time.time()) if stamp is None else stamp
@@ -102,15 +105,17 @@ try:
102105 if cap == 20:
103106 publish(b); check_available(); print('PASS numeric field at 20 digits')
104107 else: cases[f'numeric-field-{cap}'] = (b, snapshot(vals=good(f0='0'*19+'7')))
105- # 65 lines is valid. Unknown public IDs cannot give the current project a value.
106- many = snapshot()+b''.join(row('zfixture'+str(i)) for i in range(63))
107- publish(many); check_available(); print('PASS 65-line limit')
108- cases['lines-66'] = (many+row('zextra0'), many)
108+ # 257 lines (the header and FAMAX = 256 rows, server/util.om) is valid. Unknown public IDs cannot give
109+ # the current project a value. (The table and these caps were 64 rows / 65 lines / 16384 bytes before
110+ # 2026-11-14; server/count-snapshot.om grew them with the allow-list table.)
111+ many = snapshot()+b''.join(row('zfixture'+str(i)) for i in range(255))
112+ publish(many); check_available(); print('PASS 257-line limit')
113+ cases['lines-258'] = (many+row('zextra0'), many)
109114 # Far beyond the line limit while staying under the file-size cap, so only the line cap can refuse it.
110- short = b''.join(f'zs{i} 0 0 0 0 0 0 0 0 0 0\n'.encode() for i in range(335))
111- assert len((many+short).splitlines()) == 400 and len(many+short) < 16384, len(many+short)
112- cases['lines-400-under-file-cap'] = (many+short, many)
113- cases['lines-10000'] = (many+b''.join(row('zextra'+str(i)) for i in range(9935)), many)
115+ short = b''.join(f'zs{i} 0 0 0 0 0 0 0 0 0 0\n'.encode() for i in range(743))
116+ assert len((many+short).splitlines()) == 1000 and len(many+short) < 65536, len(many+short)
117+ cases['lines-1000-under-file-cap'] = (many+short, many)
118+ cases['lines-10000'] = (many+b''.join(row('zextra'+str(i)) for i in range(9743)), many)
114119 # RID length at its accepted limit, alongside the actual requested project.
115120 publish(snapshot()+row('z'+'a'*63)); check_available()
116121 print('PASS RID field at 64 bytes')
@@ -124,10 +129,10 @@ try:
124129 def sized(total):
125130 nums = good()
126131 rows = [row(vals=[v.zfill(20) for v in nums])]
127- rows += [row(('z'+str(i)).ljust(46,'a'), zero) for i in range(63)]
132+ rows += [row(('z'+str(i)).ljust(46,'a'), zero) for i in range(255)]
128133 header = snapshot().splitlines(keepends=True)[0]
129134 excess = len(header+b''.join(rows))-total
130- for i in range(1,64):
135+ for i in range(1,256):
131136 if excess <= 0: break
132137 rid, rest = rows[i].split(b' ',1)
133138 trim = min(excess, len(rid)-10)
@@ -136,10 +141,10 @@ try:
136141 out = header+b''.join(rows)
137142 assert len(out) == total, (total, len(out))
138143 return out
139- exact = sized(16384)
140- publish(exact); check_available(); print('PASS valid snapshot at 16384 bytes')
141- # A well-formed 16385-byte file: only the byte cap can refuse it.
142- cases['file-bytes-16385'] = (sized(16385), exact)
144+ exact = sized(65536)
145+ publish(exact); check_available(); print('PASS valid snapshot at 65536 bytes')
146+ # A well-formed 65537-byte file: only the byte cap can refuse it.
147+ cases['file-bytes-65537'] = (sized(65537), exact)
143148 cases['file-bytes-2000000'] = (exact+b'x'*(2000000-len(exact)), exact)
144149 for name, (bad, twin) in cases.items():
145150 publish(twin); available()

infra/test/edge-bundle-limit.sh

new file mode 100755
@@ -0,0 +1,253 @@
1+#!/usr/bin/env bash
2+# The download limit of the forge edge for the bundle of an imported proposal
3+# (GET /<owner>/<repo>/patches/<id>.bundle), WITHOUT touching a live nginx. As
4+# infra/test/edge-patch-limit.sh does: for each site copy (hub infra/nginx/sites-enabled/interplane.io,
5+# Spark infra/spark/nginx/sites-interplane.io) with the shared infra/nginx conf.d and snippets of the
6+# working tree, paths rewritten into a temp dir, `nginx -t -c` on the scratch copy, then a throwaway
7+# nginx whose only listener is one loopback port (EDGE_BUNDLE_PORT, default 19374; the site's 4444
8+# listen is dropped and 4448 becomes that port, ssl + proxy_protocol) and whose upstream is a stand-in
9+# on a Unix socket (a test oracle, not forged). The stand-in answers "got <path> base=<X-Forge-Base>
10+# ip=<X-Real-IP>"; a request whose query has hold=1 is held until the test removes $T/hold (a slow
11+# download), and csp=sandbox makes it send forged's raw sandbox policy.
12+# Clients: every request carries a PROXY v1 header (curl --haproxy-protocol --haproxy-clientip ADDR)
13+# and the scratch listener has proxy_protocol, so $proxy_protocol_addr, the key of the live zone
14+# forge_dl (conf.d/forge.conf), is ADDR: the zones are keyed exactly as live. Each 429 is matched to
15+# its zone by nginx's error log line `limiting connections by zone "forge_dl"` (or "forge_dl_all"),
16+# so a 429 of limit_req is never taken for the download limit.
17+# Checks per copy:
18+# 1. client A holds two .bundle downloads; its third .bundle answers 429 (zone forge_dl) and never
19+# reaches the upstream; client B's .bundle proceeds meanwhile; A's .patch, .diff and page of the
20+# same id, three at once while A still holds two downloads, all answer 200 from @forged
21+# (X-Forge-Cache set); after the release every held download is 200 with X-Forge-Base / and the
22+# client's address, no X-Forge-Cache, and A's next .bundle is 200 again
23+# 2. six downloads held over three addresses: a fourth address gets 429 (zone forge_dl_all)
24+# 3. the archive location still limits as before (two held, the third 429); a bundle and an archive
25+# share the client's two slots (one of each held: a third of either is 429)
26+# 4. CSP: a .bundle without forged's policy, its 429 included, gets the edge's sandbox fallback;
27+# with forged's sandbox policy the edge adds none; .diff keeps the page policy
28+# 5. paths that are not a bundle stay in @forged: 15 hex digits, upper-case hex, .bundle/x, a third
29+# path segment
30+# Control (must fail): the tree's site file without the bundle location: A's third .bundle is not
31+# refused and answers 200 after the release, so check 1 fails there.
32+# Usage: bash infra/test/edge-bundle-limit.sh (exit 0 = every check passed; KEEP=1 keeps the temp dir)
33+set -u
34+cd "$(dirname "$0")/../.."
35+PORT=${EDGE_BUNDLE_PORT:-19374}
36+T=$(mktemp -d "${TMPDIR:-/tmp}/edge-bundle.XXXXXX")
37+PASS=0; FAIL=0
38+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
39+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
40+UPPID=
41+ngstop() { [ -f "$T/run/nginx.pid" ] && kill "$(cat "$T/run/nginx.pid")" 2>/dev/null; rm -f "$T/run/nginx.pid"; sleep 0.3; }
42+cleanup() { rm -f "$T/hold"; ngstop; [ -n "$UPPID" ] && kill "$UPPID" 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; }
43+trap cleanup EXIT
44+[ -z "$(ss -ltnH "sport = :$PORT")" ] || { echo "port $PORT is taken - refusing to test"; exit 2; }
45+
46+mkdir -p "$T/certs" "$T/www" "$T/r"
47+openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj "/CN=interplane.io" -addext "subjectAltName=DNS:interplane.io" \
48+ -keyout "$T/certs/key.pem" -out "$T/certs/cert.pem" > /dev/null 2>&1 || { echo "openssl failed"; exit 2; }
49+echo STATIC > "$T/www/index.html"
50+
51+# The stand-in upstream: one HTTP/1.0 request per connection; every arrival is logged as "<ip> <path>".
52+cat > "$T/up.py" <<'EOF'
53+import os, socketserver, sys, time
54+sock, arrivals, hold = sys.argv[1], sys.argv[2], sys.argv[3]
55+class H(socketserver.StreamRequestHandler):
56+ def handle(self):
57+ line = self.rfile.readline().decode('latin-1').split()
58+ hdr = {}
59+ while True:
60+ h = self.rfile.readline()
61+ if h in (b'\r\n', b'\n', b''): break
62+ k, _, v = h.decode('latin-1').partition(':')
63+ hdr[k.strip().lower()] = v.strip()
64+ target = line[1] if len(line) > 1 else '?'
65+ path, _, query = target.partition('?')
66+ with open(arrivals, 'a') as f:
67+ f.write('%s %s\n' % (hdr.get('x-real-ip', '-'), target))
68+ if 'hold=1' in query.split('&'):
69+ end = time.time() + 30
70+ while os.path.exists(hold) and time.time() < end:
71+ time.sleep(0.05)
72+ body = ('got %s base=%s ip=%s\n' % (path, hdr.get('x-forge-base', '-'), hdr.get('x-real-ip', '-'))).encode()
73+ csp = b"Content-Security-Policy: sandbox; default-src 'none'\r\n" if 'csp=sandbox' in query.split('&') else b''
74+ self.wfile.write(b'HTTP/1.0 200 OK\r\nContent-Type: application/octet-stream\r\n' + csp +
75+ b'Content-Length: %d\r\n\r\n' % len(body) + body)
76+socketserver.ThreadingUnixStreamServer.daemon_threads = True
77+socketserver.ThreadingUnixStreamServer(sock, H).serve_forever()
78+EOF
79+: > "$T/arrivals"
80+python3 "$T/up.py" "$T/up.sock" "$T/arrivals" "$T/hold" & UPPID=$!
81+for i in $(seq 50); do [ -S "$T/up.sock" ] && break; sleep 0.1; done
82+[ -S "$T/up.sock" ] || { echo "stand-in upstream did not start"; exit 2; }
83+
84+# setup SITEFILE: the scratch configuration of SITEFILE with this tree's conf.d and snippets
85+setup() {
86+ rm -rf "$T/c" "$T/run"; mkdir -p "$T/c/snippets" "$T/c/conf.d" "$T/run/cache" "$T/run/tmp"
87+ rw() { sed -e "s#/etc/nginx/snippets/#$T/c/snippets/#g" -e "s#/var/cache/nginx/forge#$T/run/cache#g" \
88+ -e "s#server 127\.0\.0\.1:18480 #server unix:$T/up.sock #"; }
89+ for s in forge-proxy forge-headers forge-archive bazinga-git; do rw < "infra/nginx/snippets/$s.conf" > "$T/c/snippets/$s.conf"; done
90+ rw < infra/nginx/conf.d/forge.conf > "$T/c/conf.d/forge.conf"
91+ rw < "$1" | sed -e '/listen 127\.0\.0\.1:4444 ssl/d' \
92+ -e "s#listen 127\.0\.0\.1:4448 ssl http2 proxy_protocol;#listen 127.0.0.1:$PORT ssl proxy_protocol;#" \
93+ -e "s#/etc/nginx/certs/interplane.io/fullchain.pem#$T/certs/cert.pem#" \
94+ -e "s#/etc/nginx/certs/interplane.io/key.pem#$T/certs/key.pem#" \
95+ -e "s#root /var/www/interplane.io;#root $T/www;#" > "$T/c/site"
96+ grep -q "unix:$T/up.sock" "$T/c/conf.d/forge.conf" && grep -q "listen 127.0.0.1:$PORT ssl proxy_protocol;" "$T/c/site" \
97+ && ! grep -q 'listen 127.0.0.1:44' "$T/c/site" && ! grep -rqh '^[^#]*/etc/nginx/' "$T/c" || { echo "rewrite of $1 failed"; exit 2; }
98+ cat > "$T/c/nginx.conf" <<EOF
99+worker_processes 1;
100+pid $T/run/nginx.pid;
101+error_log $T/run/error.log;
102+events { worker_connections 64; }
103+http {
104+ client_body_temp_path $T/run/tmp/body;
105+ proxy_temp_path $T/run/tmp/proxy;
106+ fastcgi_temp_path $T/run/tmp/fastcgi;
107+ uwsgi_temp_path $T/run/tmp/uwsgi;
108+ scgi_temp_path $T/run/tmp/scgi;
109+ access_log off;
110+ include $T/c/conf.d/forge.conf;
111+ include $T/c/site;
112+}
113+EOF
114+}
115+# run SITEFILE LABEL: nginx -t, then start and leave running
116+run() {
117+ setup "$1"
118+ if nginx -t -c "$T/c/nginx.conf" -p "$T/run/" -e "$T/run/error.log" > "$T/t.out" 2>&1; then
119+ ok "$2: nginx -t -c (scratch copy of $1): $(grep -o 'syntax is ok' "$T/t.out"), $(grep -o 'test is successful' "$T/t.out")"
120+ else bad "$2: nginx -t: $(tr '\n' ' ' < "$T/t.out")"; return 1; fi
121+ nginx -c "$T/c/nginx.conf" -p "$T/run/" -e "$T/run/error.log" || { bad "$2: nginx did not start: $(tail -3 "$T/run/error.log")"; return 1; }
122+ for i in $(seq 50); do [ -n "$(ss -ltnH "sport = :$PORT")" ] && return 0; sleep 0.1; done
123+ bad "$2: nginx is not listening on $PORT"; return 1
124+}
125+
126+O=/drakestapleton/fixrepo
127+ID=0123456789abcdef
128+BUN=$O/patches/$ID.bundle
129+ARC=$O/archive/refs/heads/main.zip
130+N=0
131+# req NAME ADDR PATH: start a GET of PATH from client ADDR in the background (a unique query string,
132+# so no cache entry or cache lock joins two requests); answer in $T/r/NAME.{code,h,b}, then NAME.done
133+req() {
134+ local q; N=$((N+1)); case $3 in *\?*) q="&n=$N";; *) q="?n=$N";; esac
135+ rm -f "$T/r/$1".*
136+ ( curl -sk --haproxy-protocol --haproxy-clientip "$2" --max-time 60 --resolve "interplane.io:$PORT:127.0.0.1" \
137+ -D "$T/r/$1.h" -o "$T/r/$1.b" -w '%{http_code}' "https://interplane.io:$PORT$3$q" > "$T/r/$1.code" 2>/dev/null
138+ touch "$T/r/$1.done" ) &
139+}
140+# fin NAME: wait for it (60 s at most); its status
141+fin() { local i; for i in $(seq 600); do [ -e "$T/r/$1.done" ] && break; sleep 0.1; done; cat "$T/r/$1.code" 2>/dev/null; }
142+# done1 NAME SECONDS: the status if the request finished within SECONDS, else "held"
143+done1() {
144+ local i; for i in $(seq $(($2*10))); do [ -e "$T/r/$1.done" ] && { cat "$T/r/$1.code"; return; }; sleep 0.1; done; echo held
145+}
146+arr() { wc -l < "$T/arrivals"; }
147+# waitarr N: the stand-in has seen N requests (10 s at most)
148+waitarr() { local i; for i in $(seq 100); do [ "$(arr)" -ge "$1" ] && return 0; sleep 0.1; done; return 1; }
149+zlines() { grep -c "limiting connections by zone \"$1\"" "$T/run/error.log"; }
150+hdr() { grep -i "^$2:" "$T/r/$1.h" | cut -d' ' -f2- | tr -d '\r'; }
151+csps() { grep -ic '^content-security-policy:' "$T/r/$1.h"; }
152+# isdl NAME ADDR PATH: a 200 from the new location: the stand-in's answer, X-Forge-Base /, no X-Forge-Cache
153+isdl() { fin "$1" > /dev/null; [ "$(cat "$T/r/$1.code")" = 200 ] && [ "$(cat "$T/r/$1.b")" = "got $3 base=/ ip=$2" ] && [ -z "$(hdr "$1" x-forge-cache)" ]; }
154+# isfg NAME: a 200 answered through @forged (X-Forge-Cache set)
155+isfg() { fin "$1" > /dev/null; [ "$(cat "$T/r/$1.code")" = 200 ] && grep -q '^got ' "$T/r/$1.b" && [ -n "$(hdr "$1" x-forge-cache)" ]; }
156+# third NAME ADDR PATH ZONE LABEL: a request that must be refused 429 by ZONE at once, unseen upstream
157+third() {
158+ local a z c; a=$(arr); z=$(zlines "$4"); req "$1" "$2" "$3"; c=$(done1 "$1" 5); sleep 0.2
159+ if [ "$c" = 429 ] && [ "$(arr)" = "$a" ] && [ "$(zlines "$4")" -gt "$z" ]; then ok "$5: GET $3 from $2 -> 429 (zone $4 in the error log), not seen upstream"
160+ else bad "$5: GET $3 from $2: want 429 by zone $4, got $c (upstream saw $(( $(arr) - a )) more, zone lines $z -> $(zlines "$4"))"; fi
161+}
162+release() { rm -f "$T/hold"; }
163+
164+# suite LABEL SITEFILE: checks 1-5 against a running scratch nginx of SITEFILE
165+suite() {
166+ local L=$1 a0 n c ok1
167+ : > "$T/arrivals"
168+ echo "== $L 1. one client's third bundle download"
169+ touch "$T/hold"; a0=0
170+ req A1 192.0.2.10 "$BUN?hold=1"; req A2 192.0.2.10 "$BUN?hold=1"
171+ waitarr 2 && ok "$L: client A's two .bundle downloads reached the upstream and are held" || bad "$L: A's two downloads did not reach the upstream ($(arr))"
172+ third A3 192.0.2.10 "$BUN" forge_dl "$L third .bundle from client A"
173+ req B1 192.0.2.20 "$BUN?hold=1"
174+ waitarr 3 && ok "$L: client B's .bundle reached the upstream while A holds two" || bad "$L: B's .bundle was held back ($(arr) arrivals)"
175+ req AP 192.0.2.10 "$O/patches/$ID.patch?hold=1"; req AD 192.0.2.10 "$O/patches/$ID.diff?hold=1"; req AG 192.0.2.10 "$O/patches/$ID?hold=1"
176+ waitarr 6 && ok "$L: A's .patch, .diff and page of $ID reached the upstream together while A holds two downloads" \
177+ || bad "$L: A's .patch/.diff/page did not all reach the upstream ($(arr) arrivals, want 6)"
178+ release
179+ ok1=1; for r in A1 A2; do isdl $r 192.0.2.10 "$BUN" || ok1=; done; isdl B1 192.0.2.20 "$BUN" || ok1=
180+ [ -n "$ok1" ] && ok "$L: the held downloads (A twice, B) answer 200 with X-Forge-Base / and the client's address, no X-Forge-Cache" \
181+ || bad "$L: held downloads: A1 $(cat "$T/r/A1.code") $(cat "$T/r/A1.b"), A2 $(cat "$T/r/A2.code"), B1 $(cat "$T/r/B1.code") $(cat "$T/r/B1.b")"
182+ for r in AP AD AG; do fin $r > /dev/null; done
183+ isfg AP && isfg AD && isfg AG && ok "$L: A's .patch, .diff and page answer 200 through @forged (X-Forge-Cache $(hdr AD x-forge-cache))" \
184+ || bad "$L: A's .patch $(cat "$T/r/AP.code") .diff $(cat "$T/r/AD.code") page $(cat "$T/r/AG.code"), X-Forge-Cache '$(hdr AD x-forge-cache)'"
185+ req A4 192.0.2.10 "$BUN"; fin A4 > /dev/null
186+ isdl A4 192.0.2.10 "$BUN" && ok "$L: after the release A's next .bundle answers 200 (its slots are free)" || bad "$L: A's next .bundle: $(cat "$T/r/A4.code")"
187+
188+ echo "== $L 2. six downloads in total"
189+ : > "$T/arrivals"; touch "$T/hold"
190+ for x in 31 32 33; do req C${x}a 192.0.2.$x "$BUN?hold=1"; req C${x}b 192.0.2.$x "$BUN?hold=1"; done
191+ waitarr 6 && ok "$L: six .bundle downloads from three addresses are held at the upstream" || bad "$L: six held downloads: $(arr) arrivals"
192+ third D1 192.0.2.40 "$BUN" forge_dl_all "$L seventh download (a fourth address)"
193+ release
194+ n=0; for x in 31 32 33; do isdl C${x}a 192.0.2.$x "$BUN" && n=$((n+1)); isdl C${x}b 192.0.2.$x "$BUN" && n=$((n+1)); done
195+ [ "$n" = 6 ] && ok "$L: the six held downloads answer 200" || bad "$L: $n of the six held downloads answered 200"
196+
197+ echo "== $L 3. the archive location, and archive + bundle share the client's slots"
198+ : > "$T/arrivals"; touch "$T/hold"
199+ req G1 192.0.2.50 "$ARC?hold=1"; req G2 192.0.2.50 "$ARC?hold=1"
200+ req H1 192.0.2.60 "$ARC?hold=1"; req H2 192.0.2.60 "$BUN?hold=1"
201+ waitarr 4 && ok "$L: two archive downloads (client G) and one archive + one bundle (client H) are held" || bad "$L: held archive/bundle: $(arr) arrivals"
202+ third G3 192.0.2.50 "$ARC" forge_dl "$L third archive download from client G (as before)"
203+ third H3 192.0.2.60 "$BUN" forge_dl "$L .bundle from client H holding an archive and a bundle"
204+ third H4 192.0.2.60 "$ARC" forge_dl "$L archive from client H holding an archive and a bundle"
205+ release
206+ c=; for r in G1 G2 H1; do fin $r > /dev/null; [ "$(cat "$T/r/$r.code")" = 200 ] || c="$c $r"; done
207+ isdl H2 192.0.2.60 "$BUN" || c="$c H2"
208+ [ -z "$c" ] && ok "$L: the held archive and bundle downloads answer 200" || bad "$L: held downloads not 200:$c"
209+
210+ echo "== $L 4. Content-Security-Policy"
211+ [ "$(csps A1)" = 1 ] && hdr A1 content-security-policy | grep -q "^sandbox; default-src 'none'; img-src 'self'" \
212+ && ok "$L: .bundle without forged's policy: one CSP, the edge's sandbox fallback" || bad "$L: .bundle CSP: $(hdr A1 content-security-policy)"
213+ [ "$(csps A3)" = 1 ] && hdr A3 content-security-policy | grep -q "^sandbox; default-src 'none'" \
214+ && ok "$L: the 429 of a .bundle carries the sandbox fallback" || bad "$L: 429 CSP: $(hdr A3 content-security-policy)"
215+ req S1 192.0.2.70 "$BUN?csp=sandbox"; fin S1 > /dev/null
216+ [ "$(cat "$T/r/S1.code")" = 200 ] && [ "$(csps S1)" = 1 ] && [ "$(hdr S1 content-security-policy)" = "sandbox; default-src 'none'" ] \
217+ && ok "$L: .bundle with forged's sandbox policy: that policy alone, the edge adds none" || bad "$L: .bundle with forged's CSP: $(grep -ic '^content-security-policy' "$T/r/S1.h") headers"
218+ [ "$(csps AD)" = 1 ] && hdr AD content-security-policy | grep -q "^default-src 'self'; script-src 'none'" \
219+ && ok "$L: .diff without forged's policy keeps the edge page policy" || bad "$L: .diff CSP: $(hdr AD content-security-policy)"
220+
221+ echo "== $L 5. paths that are not a bundle stay in @forged"
222+ for p in "$O/patches/0123456789abcde.bundle" "$O/patches/0123456789ABCDEF.bundle" "$O/patches/$ID.bundle/x" "/a$O/patches/$ID.bundle"; do
223+ req NM 192.0.2.80 "$p"; fin NM > /dev/null
224+ isfg NM && ok "$L: GET $p -> 200 through @forged" || bad "$L: GET $p: $(cat "$T/r/NM.code"), X-Forge-Cache '$(hdr NM x-forge-cache)'"
225+ done
226+}
227+
228+nginx -v 2>&1
229+for site in infra/nginx/sites-enabled/interplane.io infra/spark/nginx/sites-interplane.io; do
230+ L=${site#infra/}
231+ run "$site" "$L" && suite "$L" "$site"
232+ release; ngstop
233+done
234+hub="$T/hub-site"
235+spark="$T/spark-site"
236+awk 'NF && $0 !~ /include \/etc\/nginx\/snippets\/bazinga-git\.conf;/' infra/nginx/sites-enabled/interplane.io > "$hub"
237+awk 'NF' infra/spark/nginx/sites-interplane.io > "$spark"
238+cmp -s "$hub" "$spark" && ok "both edges share the same forge routes" || bad "the edge forge routes differ"
239+
240+echo "== control: the site file without the bundle location (check 1 must fail)"
241+awk '/^ # Bundle of an imported proposal/{skip=1} skip&&/^ }$/{skip=0; next} !skip' infra/nginx/sites-enabled/interplane.io > "$T/mutant-site"
242+if cmp -s infra/nginx/sites-enabled/interplane.io "$T/mutant-site" || grep -q 'bundle\$"' "$T/mutant-site"; then bad "control: the mutant still has the bundle location"
243+elif run "$T/mutant-site" "control (no bundle location)"; then
244+ : > "$T/arrivals"; touch "$T/hold"
245+ req K1 192.0.2.90 "$BUN?hold=1"; req K2 192.0.2.90 "$BUN?hold=1"; waitarr 2
246+ req K3 192.0.2.90 "$BUN?hold=1"; c=$(done1 K3 5); waitarr 3; release
247+ [ "$c" = held ] && c=$(fin K3)
248+ if [ "$c" = 200 ] && [ "$(arr)" = 3 ]; then ok "control: without the location the third .bundle from one client answers 200 (reached the upstream): check 1 fails there, as it must"
249+ else bad "control: without the location the third .bundle answered $c ($(arr) arrivals): the limit does not come from the new location"; fi
250+fi
251+release; ngstop
252+echo "EDGE-BUNDLE: pass=$PASS fail=$FAIL"
253+[ "$FAIL" = 0 ]

infra/test/edge-patch-limit.sh

new file mode 100755
@@ -0,0 +1,130 @@
1+#!/usr/bin/env bash
2+# The per-path body limit of the forge edge for the git patch upload, WITHOUT touching a live
3+# nginx: for each site copy (hub infra/nginx/sites-enabled/interplane.io, Spark
4+# infra/spark/nginx/sites-interplane.io) with the shared infra/nginx conf.d and snippets, paths
5+# rewritten into a temp dir, it runs `nginx -t -c` on the scratch copy, then starts a throwaway nginx
6+# whose only listener is one loopback port (EDGE_PATCH_PORT, default 18488: the site's 4444 listen
7+# is dropped and 4448 becomes that port, ssl + proxy_protocol) and whose upstream is a stand-in on a
8+# Unix socket that answers 200 and the body length it received (a test oracle, not forged).
9+# Checks per copy: POST /<owner>/<repo>/patches/new passes 3145728 bytes and is refused 413 at
10+# 3145729; POST to every other path tried (/login, /<owner>/<repo>/issues/new,
11+# /<owner>/<repo>/patches/new2, /<a>/<b>/<c>/patches/new) passes 65536 bytes and is refused 413 at
12+# 65537. Control: the files of CONTROL (default 2dc1deda, before this limit) refuse the
13+# 3145728-byte upload with 413.
14+# Usage: bash infra/test/edge-patch-limit.sh [CONTROL] (exit 0 = every check passed)
15+set -u
16+cd "$(dirname "$0")/../.."
17+CONTROL=${1:-2dc1deda63fe50cbd7665495b51706f0814e79d4}
18+PORT=${EDGE_PATCH_PORT:-18488}
19+T=$(mktemp -d "${TMPDIR:-/tmp}/edge-patch.XXXXXX")
20+PASS=0; FAIL=0
21+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
22+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
23+NGPID=; UPPID=
24+ngstop() { [ -f "$T/run/nginx.pid" ] && kill "$(cat "$T/run/nginx.pid")" 2>/dev/null; rm -f "$T/run/nginx.pid"; sleep 0.3; }
25+cleanup() { ngstop; [ -n "$UPPID" ] && kill "$UPPID" 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; }
26+trap cleanup EXIT
27+[ -z "$(ss -ltnH "sport = :$PORT")" ] || { echo "port $PORT is taken - refusing to test"; exit 2; }
28+
29+mkdir -p "$T/certs" "$T/www"
30+openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj "/CN=interplane.io" -addext "subjectAltName=DNS:interplane.io" \
31+ -keyout "$T/certs/key.pem" -out "$T/certs/cert.pem" > /dev/null 2>&1 || { echo "openssl failed"; exit 2; }
32+echo STATIC > "$T/www/index.html"
33+for n in 65536 65537 3145728 3145729; do head -c "$n" /dev/zero | tr '\0' a > "$T/body.$n"; done
34+
35+# The stand-in upstream: one HTTP/1.0 request per connection, answers "got <body bytes> <path>".
36+cat > "$T/up.py" <<'EOF'
37+import socketserver, sys
38+class H(socketserver.StreamRequestHandler):
39+ def handle(self):
40+ line = self.rfile.readline().decode('latin-1').split()
41+ n = 0
42+ while True:
43+ h = self.rfile.readline()
44+ if h in (b'\r\n', b'\n', b''): break
45+ k, _, v = h.decode('latin-1').partition(':')
46+ if k.strip().lower() == 'content-length': n = int(v.strip())
47+ got = len(self.rfile.read(n)) if n else 0
48+ body = ('got %d %s\n' % (got, line[1] if len(line) > 1 else '?')).encode()
49+ self.wfile.write(b'HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n' % len(body) + body)
50+socketserver.ThreadingUnixStreamServer(sys.argv[1], H).serve_forever()
51+EOF
52+python3 "$T/up.py" "$T/up.sock" & UPPID=$!
53+for i in $(seq 50); do [ -S "$T/up.sock" ] && break; sleep 0.1; done
54+[ -S "$T/up.sock" ] || { echo "stand-in upstream did not start"; exit 2; }
55+
56+# file REV PATH: PATH at REV ("tree" = the working tree)
57+file() { if [ "$1" = tree ]; then cat "$2"; else git show "$1:$2"; fi; }
58+# setup REV SITE: the scratch configuration of SITE at REV in $T/c
59+setup() {
60+ rm -rf "$T/c" "$T/run"; mkdir -p "$T/c/snippets" "$T/c/conf.d" "$T/run/cache" "$T/run/tmp"
61+ rw() { sed -e "s#/etc/nginx/snippets/#$T/c/snippets/#g" -e "s#/var/cache/nginx/forge#$T/run/cache#g" \
62+ -e "s#server 127\.0\.0\.1:18480 #server unix:$T/up.sock #"; }
63+ for s in forge-proxy forge-headers forge-archive; do file "$1" "infra/nginx/snippets/$s.conf" | rw > "$T/c/snippets/$s.conf"; done
64+ file "$1" infra/nginx/snippets/bazinga-git.conf 2>/dev/null | rw > "$T/c/snippets/bazinga-git.conf"
65+ file "$1" infra/nginx/conf.d/forge.conf | rw > "$T/c/conf.d/forge.conf"
66+ file "$1" "$2" | rw | sed -e '/listen 127\.0\.0\.1:4444 ssl/d' \
67+ -e "s#listen 127\.0\.0\.1:4448 ssl http2 proxy_protocol;#listen 127.0.0.1:$PORT ssl proxy_protocol;#" \
68+ -e "s#/etc/nginx/certs/interplane.io/fullchain.pem#$T/certs/cert.pem#" \
69+ -e "s#/etc/nginx/certs/interplane.io/key.pem#$T/certs/key.pem#" \
70+ -e "s#root /var/www/interplane.io;#root $T/www;#" > "$T/c/site"
71+ grep -q "unix:$T/up.sock" "$T/c/conf.d/forge.conf" && grep -q "listen 127.0.0.1:$PORT ssl proxy_protocol;" "$T/c/site" \
72+ && ! grep -q 'listen 127.0.0.1:44' "$T/c/site" && ! grep -rqh '^[^#]*/etc/nginx/' "$T/c" || { echo "rewrite of $2 at $1 failed"; exit 2; }
73+ cat > "$T/c/nginx.conf" <<EOF
74+worker_processes 1;
75+pid $T/run/nginx.pid;
76+error_log $T/run/error.log;
77+events { worker_connections 64; }
78+http {
79+ client_body_temp_path $T/run/tmp/body;
80+ proxy_temp_path $T/run/tmp/proxy;
81+ fastcgi_temp_path $T/run/tmp/fastcgi;
82+ uwsgi_temp_path $T/run/tmp/uwsgi;
83+ scgi_temp_path $T/run/tmp/scgi;
84+ access_log off;
85+ include $T/c/conf.d/forge.conf;
86+ include $T/c/site;
87+}
88+EOF
89+}
90+# post PATH BYTES: the status of a POST of BYTES bytes to PATH (PROXY header from 127.0.0.1)
91+post() {
92+ curl -sk --haproxy-protocol --max-time 30 --resolve "interplane.io:$PORT:127.0.0.1" -o "$T/resp" -w '%{http_code}' \
93+ --data-binary "@$T/body.$2" "https://interplane.io:$PORT$1"
94+}
95+# expect LABEL PATH BYTES STATUS: 200 must be the stand-in's answer with every byte received
96+expect() {
97+ local c; c=$(post "$2" "$3")
98+ if [ "$c" = "$4" ] && { [ "$4" != 200 ] || [ "$(cat "$T/resp")" = "got $3 $2" ]; }; then ok "$1: POST $2 with $3 bytes -> $c"
99+ else bad "$1: POST $2 with $3 bytes: want $4, got $c $(head -c 120 "$T/resp" | tr '\n' ' ')"; fi
100+}
101+# run REV SITE LABEL: nginx -t, then start and leave running
102+run() {
103+ setup "$1" "$2"
104+ if nginx -t -c "$T/c/nginx.conf" -p "$T/run/" -e "$T/run/error.log" > "$T/t.out" 2>&1; then
105+ ok "$3: nginx -t -c (scratch copy of $2 at $1): $(grep -o 'syntax is ok' "$T/t.out"), $(grep -o 'test is successful' "$T/t.out")"
106+ else bad "$3: nginx -t: $(tr '\n' ' ' < "$T/t.out")"; return 1; fi
107+ nginx -c "$T/c/nginx.conf" -p "$T/run/" -e "$T/run/error.log" || { bad "$3: nginx did not start: $(tail -3 "$T/run/error.log")"; return 1; }
108+ for i in $(seq 50); do [ -n "$(ss -ltnH "sport = :$PORT")" ] && return 0; sleep 0.1; done
109+ bad "$3: nginx is not listening on $PORT"; return 1
110+}
111+
112+nginx -v 2>&1
113+for site in infra/nginx/sites-enabled/interplane.io infra/spark/nginx/sites-interplane.io; do
114+ L=${site#infra/}
115+ if run tree "$site" "$L"; then
116+ expect "$L patch upload at the limit" /drakestapleton/fixrepo/patches/new 3145728 200
117+ expect "$L patch upload over the limit" /drakestapleton/fixrepo/patches/new 3145729 413
118+ for p in /login /drakestapleton/fixrepo/issues/new /drakestapleton/fixrepo/patches/new2 /a/b/c/patches/new; do
119+ expect "$L other path at 64k" "$p" 65536 200
120+ expect "$L other path over 64k" "$p" 65537 413
121+ done
122+ fi
123+ ngstop
124+done
125+if run "$CONTROL" infra/nginx/sites-enabled/interplane.io "control nginx/sites-enabled/interplane.io"; then
126+ expect "control $CONTROL (64k everywhere)" /drakestapleton/fixrepo/patches/new 3145728 413
127+fi
128+ngstop
129+echo "EDGE-PATCH: pass=$PASS fail=$FAIL"
130+[ "$FAIL" = 0 ]

infra/test/sandbox-integrated.py

@@ -211,10 +211,10 @@ for mode in ('baseline', 'sandbox'):
211211 assert status == 200
212212 counts[mode] = json.loads(body)['counts']
213213 # Collection time can differ by the snapshot interval; every count and source is exact.
214- counts[mode]['radicle_seeds']['as_of'] = None
214+ counts[mode]['seeds']['as_of'] = None
215215 v = counts[mode]
216216 assert [v['git_fetches']['count'], v['upload_pack_requests']['count'], v['downloads']['archives'],
217- v['downloads']['release_assets'], v['radicle_seeds']['count']] == [1,1,1,1,3], v
217+ v['downloads']['release_assets'], v['seeds']['count']] == [1,None,1,1,None], v
218218 status, _, html = req(PREFIX)
219219 assert status == 200
220220 (T/f'integrated-counts-{mode}.html').write_bytes(html)

infra/test/sandbox-netns.sh

@@ -232,8 +232,11 @@ netns_trace() {
232232 stop || bad=1
233233 strace -f -e trace=network,ioctl,process,prctl -o "$T/netns-trace-tools.strace" bash "$WRAPPER" /usr/bin/ssh-keygen -Y verify \
234234 -f "$DATA/allowed" -I fixture -n sandbox -s "$DATA/message.sig" < "$DATA/message" || bad=1
235+ # the repository the wrapper binds: the fixture's Radicle copy, or in a store-reading build the store's
236+ local gd="$H/.radicle/storage/$RID"
237+ [[ ${SANDBOX_STORE:-0} = 1 ]] && gd="$H/interplane-store/projects/cuda-crack/repo.git"
235238 strace -f -e trace=network,ioctl,process,prctl -o "$T/netns-trace-git.strace" bash "$WRAPPER" /usr/bin/git \
236- --git-dir="$H/.radicle/storage/$RID" log --oneline -1 --all || bad=1
239+ --git-dir="$gd" log --oneline -1 --all || bad=1
237240 sha256sum "$T"/netns-trace*.strace
238241 echo '---- network and ioctl calls by name (server and its children)'
239242 grep -ohE '^[0-9]+ +[a-z_0-9]+\(' "$T/netns-trace.strace" | awk '{print $2}' | sort | uniq -c

infra/test/sandbox-patch.sh

new file mode 100755
@@ -0,0 +1,162 @@
1+#!/bin/bash
2+# The git patch intake inside the bubblewrap sandbox (infra/spark/forged-sandbox.sh, SANDBOX-NEEDS.md
3+# "Git patch intake"). HOST test on the Spark with scratch folders only: patch/tests/lib.sh makes
4+# the fixture repository, throwaway keys and the sign-in and upload helpers; this script builds a
5+# second test copy whose home paths name a scratch home (as infra/test/sandbox.sh does), with the
6+# listener helper, the socket filter and the public reader beside it, and starts it through the
7+# wrapper as the service does (FORGED_SANDBOX=on, FORGED_NETNS=on: no network, socket filter on,
8+# listener made outside by forged-listen). Nothing of the live forge, ~/git, ~/forge-data or
9+# ~/forge-public is read or written.
10+# Steps:
11+# 1. the public export and the repository mounts: the listed git store is mounted read-only at
12+# <home>/git/fixrepo.git; a listed name without a git store and an unlisted git store are not
13+# 2. a signed upload is accepted by the sandboxed forged (git init, git am with the store's
14+# objects borrowed through alternates, rev-list, diff; ssh-keygen -Y verify) and reads back
15+# 3. mails in ISO-8859-1 and KOI8-R (git mailinfo converts them to UTF-8 through glibc iconv,
16+# whose converters live in the gconv folder the wrapper mounts) are accepted
17+# 4. an upload to the listed repository without a git store is refused 404 and keeps nothing
18+# 5. controls: the wrapper and public library of CONTROL (default 2dc1deda, before the git store
19+# mounts) refuse an upload 404 "no git store"; this wrapper without its gconv mount refuses
20+# an ISO-8859-1 mail 422 (git am: "cannot convert from ISO-8859-1 to UTF-8")
21+# Usage: PATCH_TEST_PORT=18488 PATCH_TEST_CORES=18 bash infra/test/sandbox-patch.sh [CONTROL]
22+# KEEP=1 keeps the temp folder. Exit 0 only when every step held.
23+CONTROL=${1:-2dc1deda63fe50cbd7665495b51706f0814e79d4}
24+. "$(dirname "$0")/../../patch/tests/lib.sh"
25+REPOF=$OWNER/fixrepo
26+H=$T/sbhome
27+S=$T/sbx
28+DATA=$T/data
29+
30+echo "== build: the sandbox test copy, home paths at $H"
31+mkdir -p "$H/handoffs/radicle" "$H/handoffs/hive/manager/reviews" "$H/handoffs/hive/forge/receipts" \
32+ "$H/.local/state/aien-factory" "$H/.radicle/storage" "$H/git" "$S" "$DATA/logs"
33+printf 'private direct-launch fixture\n' > "$DATA/forged-supervisor.pid"
34+cp "$T/RIDS.md" "$H/handoffs/radicle/RIDS.md"
35+git clone -q --bare "$T/src" "$H/.radicle/storage/$RID1" || buildfail "storage fixture"
36+mkdir -p "$H/.radicle/storage/$RID2"
37+git clone -q --bare "$T/src" "$H/git/fixrepo.git" || buildfail "git store fixture"
38+git clone -q --bare "$T/src" "$H/git/unlisted.git" || buildfail "unlisted git store fixture"
39+{ printf 'om2\n'; cat $(cat "$T/units.txt"); } | sed -e "s|/home/drakestapleton/|$H/|g" \
40+ -e "s|^text tforg1 \".*\"|text tforg1 \"http://127.0.0.1:$PORT\"|" -e "s/18480/$PORT/g" > "$T/sb.om" || buildfail "compose"
41+for t in tfdata tfstore tfrids tpgroot; do
42+ grep -q "^text $t \"$H/" "$T/sb.om" || buildfail "the sandbox copy does not name the scratch home in $t"
43+done
44+compile "$T/sb.om" "$S/forged" || buildfail "$(cat "$T/omc.err")"
45+compile infra/spark/forged-listen.om "$S/forged-listen" || buildfail "forged-listen: $(cat "$T/omc.err")"
46+compile infra/spark/public-read.om "$S/public-read" || buildfail "public-read: $(cat "$T/omc.err")"
47+compile infra/spark/forged-seccomp.om "$S/forged-seccomp" || buildfail "forged-seccomp: $(cat "$T/omc.err")"
48+"$S/forged-seccomp" > "$S/forged-seccomp.bpf" || buildfail "forged-seccomp did not write the filter"
49+echo "built $(sha256sum < "$S/forged" | cut -c1-16) forged, filter $(sha256sum < "$S/forged-seccomp.bpf" | cut -c1-16), wrapper $(sha256sum < infra/spark/forged-sandbox.sh | cut -c1-16)"
50+
51+export FORGED_READ_HOME=$H FORGED_PATH_HOME=$H FORGE_DATA=$DATA FORGED_PUBLIC_READER=$S/public-read \
52+ FORGED_PUBLIC_DIR=$T/forge-public FORGED_SANDBOX=on FORGED_NETNS=on
53+unset FORGED_SECCOMP FORGED_SALVAGE FORGED_COMMUNITY_PUB
54+
55+stop() { [ -n "$PID" ] && kill -- -"$PID" 2>/dev/null; wait "$PID" 2>/dev/null; PID=; }
56+port_free() { for i in $(seq 100); do [ -z "$(ss -ltnH "sport = :$PORT")" ] && return 0; sleep 0.1; done; return 1; }
57+# sbstart DIR: start the sandboxed forged through DIR/forged-sandbox.sh with DIR/forged-public.sh
58+sbstart() {
59+ port_free || { echo "port $PORT is taken"; exit 1; }
60+ FORGED_PUBLIC_LIB=$1/forged-public.sh FORGED_LISTEN_PORT=$PORT setsid bash "$1/forged-sandbox.sh" "$S/forged" \
61+ >> "$T/sandbox.err" 2>&1 < /dev/null &
62+ PID=$!
63+ for i in $(seq 100); do curl -s -o /dev/null "$B/" && return 0; kill -0 "$PID" 2>/dev/null || break; sleep 0.1; done
64+ echo "sandboxed server did not start"; tail -5 "$T/sandbox.err"; exit 1
65+}
66+# the sandboxed forged: the /app/forged process below this run's bwrap (PID is bwrap after the
67+# wrapper's execs; bwrap's pid-1 child starts prlimit, which execs forged)
68+inner() {
69+ local p=$PID q i
70+ for i in 1 2 3 4; do
71+ q=$(pgrep -P "$p" | head -1); [ -n "$q" ] || return 1; p=$q
72+ case "$(tr '\0' ' ' < "/proc/$p/cmdline")" in /app/forged*) echo "$p"; return 0;; esac
73+ done
74+ return 1
75+}
76+
77+echo "== 1. public export and repository mounts"
78+mkdir -p "$T/new"; cp infra/spark/forged-sandbox.sh infra/spark/forged-public.sh "$T/new/"
79+(
80+ DATA=$DATA BIN=$S/forged; . "$T/new/forged-public.sh"
81+ public_init && public_sync && public_repos | cut -f1,2 | tr '\t' ' '
82+) > "$T/repos.txt" 2>&1
83+printf 'rad %s\ngit fixrepo\nrad %s\n' "$RID1" "$RID2" > "$T/repos.want"
84+cmp -s "$T/repos.txt" "$T/repos.want" && ok "public_repos: $(tr '\n' ',' < "$T/repos.txt") (no git row for nostore, nothing for unlisted)" \
85+ || bad "public_repos: $(tr '\n' '|' < "$T/repos.txt")"
86+sbstart "$T/new"
87+grep -q '^forged-sandbox: on; .*no network' "$T/sandbox.err" && ok "wrapper: $(grep '^forged-sandbox: on' "$T/sandbox.err" | tail -1 | cut -c1-120)" \
88+ || bad "wrapper did not report sandbox on with no network: $(tail -3 "$T/sandbox.err" | tr '\n' '|')"
89+FP=$(inner)
90+if [ -n "$FP" ] && awk '{print $5}' "/proc/$FP/mountinfo" > "$T/mounts.txt" 2>/dev/null; then
91+ grep "^$H/git" "$T/mounts.txt" > "$T/gitmounts.txt"
92+ [ "$(cat "$T/gitmounts.txt")" = "$H/git/fixrepo.git" ] && grep -qx "$H/.radicle/storage/$RID1" "$T/mounts.txt" \
93+ && ok "mounts of pid $FP under $H/git: exactly $H/git/fixrepo.git (no nostore.git, no unlisted.git)" \
94+ || bad "mounts under $H/git: $(tr '\n' '|' < "$T/gitmounts.txt")"
95+ awk -v p="$H/git/fixrepo.git" '$5 == p { split($6, o, ","); if (o[1] == "ro") f = 1 } END { exit !f }' "/proc/$FP/mountinfo" \
96+ && ok "the git store mount is read-only" || bad "the git store mount is not read-only: $(grep " $H/git/" "/proc/$FP/mountinfo")"
97+else bad "could not read the mount table of the sandboxed forged (pid '$FP')"; fi
98+
99+echo "== 2. a signed upload inside the sandbox"
100+newkey k1
101+signin k1 10.4.0.1 || { echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; }
102+ok "signed in inside the sandbox (ssh-keygen -Y verify)"
103+newclone w; commitf "$T/w" "notes/sandbox.txt" "sandbox line" "sandbox: one note"; mkmbox "$T/w" origin/main
104+TITLE="Sandbox note"; DESC="Written by infra/test/sandbox-patch.sh."; sigmake
105+KEPT=$(kept); C=$(upload); accepted "$C" "upload to the sandboxed forged (git am with alternates into the read-only store)"
106+c=$(code GET "$R/patches/$ID.diff")
107+git -C "$T/w" diff --full-index -M "$BASE" HEAD > "$T/want.diff"
108+[ "$c" = 200 ] && cmp -s "$T/body" "$T/want.diff" && ok "raw .diff of $ID: 200, byte-equal to git diff --full-index -M base HEAD" \
109+ || bad "raw .diff of $ID: $c"
110+c=$(code GET "$R/patches/$ID")
111+[ "$c" = 200 ] && grep -qF 'Sandbox note' "$T/body" && ok "patch page of $ID: 200 with the title" || bad "patch page of $ID: $c"
112+[ -z "$(ls -A "$H/git/fixrepo.git/objects/info" 2>/dev/null | grep -v '^packs$')" ] && [ "$(git -C "$H/git/fixrepo.git" rev-parse main)" = "$BASE" ] \
113+ && ok "the git store is unchanged (main at the base, no alternates of its own)" || bad "the git store changed"
114+
115+echo "== 3. mails in other charsets (git mailinfo converts them to UTF-8 through iconv)"
116+# mailcs CHARSET BYTES: a commit whose file and message hold BYTES in CHARSET, as a mail in CHARSET
117+mailcs() {
118+ newclone "cs$1"; git -C "$T/cs$1" config i18n.commitEncoding "$1"
119+ printf "$2\\n" > "$T/cs$1/text-$1.txt"
120+ G -C "$T/cs$1" add -A && GIT_AUTHOR_DATE=2026-11-10T10:00:00Z GIT_COMMITTER_DATE=2026-11-10T10:00:00Z \
121+ git -C "$T/cs$1" -c user.name=fixture -c user.email=fixture@example.org commit -q -F <(printf "text: $2\\n")
122+ mkmbox "$T/cs$1" origin/main
123+ grep -qix "Content-Type: text/plain; charset=$1" "$MBOX" || bad "the fixture mail is not $1: $(grep -i '^Content-Type' "$MBOX")"
124+ TITLE="Mail in $1"; DESC="git mailinfo converts it to UTF-8."; sigmake
125+ KEPT=$(kept); C=$(upload)
126+}
127+mailcs ISO-8859-1 'caf\351 au lait'
128+accepted "$C" "ISO-8859-1 mail (git mailinfo converts it with glibc's gconv modules)"
129+mailcs KOI8-R '\320\322\311\327\305\324'
130+accepted "$C" "KOI8-R mail (git mailinfo converts it with glibc's gconv modules)"
131+
132+echo "== 4. a listed repository without a git store"
133+newclone w2; commitf "$T/w2" "notes/nostore.txt" "nostore line" "nostore: one note"; mkmbox "$T/w2" origin/main
134+TITLE="No store"; DESC="nostore is listed and has no git store."; REPOF=$OWNER/nostore; UPATH=/$OWNER/nostore/patches/new; sigmake
135+KEPT=$(kept); C=$(upload); refused "$C" 404 "this repository has no git store on this forge" "listed repository without a git store"
136+REPOF=$OWNER/fixrepo; UPATH=
137+stop
138+
139+echo "== 5. control: the wrapper of $CONTROL"
140+mkdir -p "$T/old"
141+git show "$CONTROL:infra/spark/forged-sandbox.sh" > "$T/old/forged-sandbox.sh" && git show "$CONTROL:infra/spark/forged-public.sh" > "$T/old/forged-public.sh" \
142+ || { bad "control files of $CONTROL"; echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; }
143+sbstart "$T/old"
144+signin k1 10.4.0.1 || { echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; }
145+newclone w3; commitf "$T/w3" "notes/control.txt" "control line" "control: one note"; mkmbox "$T/w3" origin/main
146+TITLE="Control"; DESC="No git store mount in this wrapper."; sigmake
147+KEPT=$(kept); C=$(upload); refused "$C" 404 "this repository has no git store on this forge" "control wrapper $CONTROL (no git store mount)"
148+stop
149+
150+echo "== 5b. control: this wrapper without the gconv mount"
151+mkdir -p "$T/nogconv"; cp "$T/new/forged-public.sh" "$T/nogconv/"
152+sed '/^args+=(--ro-bind "\$gconv" "\$gconv")$/d' "$T/new/forged-sandbox.sh" > "$T/nogconv/forged-sandbox.sh"
153+if cmp -s "$T/new/forged-sandbox.sh" "$T/nogconv/forged-sandbox.sh"; then bad "the gconv mutant changed nothing"; else
154+ sbstart "$T/nogconv"
155+ signin k1 10.4.0.1 || { echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; }
156+ mailcs ISO-8859-1 'na\357ve'
157+ refused "$C" 422 "the mbox does not apply cleanly on base" "ISO-8859-1 mail without the gconv mount"
158+ stop
159+fi
160+echo "== forged-sandbox stderr"; grep -v '^$' "$T/sandbox.err" | cut -c1-200 | sort | uniq -c
161+echo "SANDBOX: pass=$PASS fail=$FAIL"
162+[ "$FAIL" = 0 ]

infra/test/sandbox.sh

@@ -90,6 +90,34 @@ for n in first second third fourth; do
9090 -c user.email=213298340+drakestapleton@users.noreply.github.com commit -qm "fixture $n"
9191 done
9292 git clone -q --bare --no-hardlinks "$T/source" "$H/.radicle/storage/$RID"
93+# SANDBOX_STORE=1 (with IPL_DIR): the store-reading build. The fixture becomes a store at
94+# $H/interplane-store (store/tests/fixstore.sh); the binary is built for /home/drakestapleton/
95+# interplane-store (rewritten to $H below, as every home path), serves every public line of that
96+# catalog less the deny list, and the wrapper binds the store read-only (FORGED_STORE) with only the
97+# served projects in ROOT/projects. Beside cuda-crack the store gets what the sandbox must not show
98+# (store-binds below): a private project, a public one under a denied name, a public one whose old id
99+# is the denied rad:z2ft64..., a staging/ and a repo.git.migration/ in cuda-crack, import-notes/,
100+# import.tsv and IMPORT-RECEIPT.txt, each holding a canary.
101+if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
102+ FIXSTORE_FROM=/nonexistent bash store/tests/fixstore.sh "$H/handoffs/radicle/RIDS.md" "$H/.radicle/storage" "$H/interplane-store" ||
103+ { echo 'BLOCKED fixture store'; exit 3; }
104+ S=$H/interplane-store
105+ sbproj() { # sbproj NAME VISIBILITY ALIAS: one more project in the fixture store, signed with fixstore's key
106+ git clone -q --bare --no-hardlinks "$T/source" "$S/projects/$1/repo.git" &&
107+ "${IPL_DIR:?}/ipl" init "$S" "$1" main "$2" "$3" "$S/.fixkey" > /dev/null &&
108+ echo "$1" > "$T/sb.ev" && "$IPL_DIR/ipl" import "$S" "$1" main "$T/sb.ev" "$T/sb.ev" "fix-$1" "$S/.fixkey" > /dev/null
109+ }
110+ sbproj sbpriv private rad:zSandboxPrivateFixtureAAA1 && sbproj omega-pearl public rad:zSandboxDenyByNameAAAAAA1 &&
111+ sbproj sbalias public rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ || { echo 'BLOCKED fixture store extras'; exit 3; }
112+ mkdir -p "$S/projects/cuda-crack/staging" "$S/projects/cuda-crack/repo.git.migration" "$S/import-notes"
113+ for f in projects/cuda-crack/staging/canary projects/cuda-crack/repo.git.migration/canary import-notes/canary import.tsv IMPORT-RECEIPT.txt; do
114+ printf 'sandbox-test-only canary\n' > "$S/$f"
115+ done
116+ [[ $(awk -F'\t' '$5 == "public"' "$S/catalog.tsv" | wc -l) = 3 && $(awk -F'\t' '$5 == "private"' "$S/catalog.tsv" | wc -l) = 1 ]] ||
117+ { echo "BLOCKED fixture store catalog: $(cut -f1,5 "$S/catalog.tsv" | tr '\n\t' '; ')"; exit 3; }
118+ export FORGE_STORE=/home/drakestapleton/interplane-store
119+ echo "SANDBOX_STORE: store-reading build, store $H/interplane-store"
120+fi
93121 OMC=$HOME/work/flux/omega-mv/seed/out/omc
94122 PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
95123 [[ $(sha256sum "$OMC" | cut -d' ' -f1) = "$PIN" ]] || { echo 'BLOCKED compiler pin mismatch'; exit 3; }
@@ -118,6 +146,7 @@ record netns-build netns_build
118146 export FORGED_SECCOMP=$T/forged-seccomp.bpf
119147 trap 'stop; private_listeners_stop; unit_cleanup' EXIT
120148 export FORGED_READ_HOME=$H FORGED_PATH_HOME=$H FORGE_DATA=$DATA
149+[[ ${SANDBOX_STORE:-0} = 1 ]] && export FORGED_STORE=$H/interplane-store
121150 WRAPPER=$ROOT/infra/spark/forged-sandbox.sh
122151 export FORGED_PUBLIC_READER=$T/public-read FORGED_PUBLIC_DIR=$H/forge-public
123152 export FORGED_PUBLIC_LIB=$ROOT/infra/spark/forged-public.sh
@@ -169,6 +198,8 @@ paths=(/ /explore /assets/forge.css /drakestapleton/cuda-crack
169198 /drakestapleton/cuda-crack/raw/main/README.md
170199 /drakestapleton/cuda-crack/archive/refs/heads/main.zip
171200 /drakestapleton/cuda-crack/archive/refs/heads/main.tar.gz /status.json)
201+# the store-reading build has no node status page (server/nostat.om, 501); its door answers instead
202+[[ ${SANDBOX_STORE:-0} = 1 ]] && paths=("${paths[@]/\/status.json/\/agents.json}" /events.json /feed)
172203 fetch() {
173204 local mode=$1 i=0 p code
174205 for p in "${paths[@]}"; do
@@ -200,8 +231,14 @@ record umask umask_check "$T/umask-marker"
200231 # (infra/test/sandbox-community.sh says why). Before the supervisor checks, so a red supervisor
201232 # check cannot hide it.
202233 source infra/test/sandbox-community.sh
234+if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
235+ # the store-reading build composes salvage/ and community/ out (their seams): it has no community
236+ # routes to walk. The wrapper's community mounts are still checked below (community-store and on).
237+ echo 'NOT_APPLICABLE community-routes, community-routes-mutant: salvage/ and community/ are not composed in the store-reading build'
238+else
203239 record community-routes community_routes_check
204240 record community-routes-mutant community_routes_mutant
241+fi
205242 rm -rf "$DATA/community" "$DATA/salvage" "$CMR_PUB"
206243 reload_check() {
207244 # Invoke the actual supervisor function without starting any tmux session.
@@ -289,7 +326,8 @@ for p in /escape /app/escape /tmp/escape "$home/escape" "$home/.radicle/storage/
289326 "$home/handoffs/radicle/RIDS.md" "$home/.local/state/aien-factory/nodes.txt" \
290327 "$home/handoffs/radicle/counts.snapshot" \
291328 "$home/handoffs/hive/manager/reviews/child.verdict.txt" "$home/handoffs/hive/forge/receipts/child.receipt.txt" \
292- "$home/forge-public/RIDS.md"; do
329+ "$home/forge-public/RIDS.md" "$home/interplane-store/catalog.tsv" \
330+ "$home/interplane-store/projects/cuda-crack/repo.git/config" "$home/interplane-store/projects/cuda-crack/chain.tsv"; do
293331 if (printf x >> "$p") 2>/dev/null; then echo "FAIL write $p"; fail=1; else echo "PASS denied write $p"; fi
294332 done
295333 printf ok > "$home/forge-data/probe-write"
@@ -310,6 +348,56 @@ chmod 755 "$T/probe"
310348 record isolation bash "$WRAPPER" /usr/bin/dash -s -- "$H" "$HOME" < "$T/probe"
311349 record no-new-privs bash "$WRAPPER" /usr/bin/grep NoNewPrivs /proc/self/status
312350 grep -qE '^NoNewPrivs:[[:space:]]+1$' "$T/no-new-privs.log"
351+# store-binds (SANDBOX_STORE=1, review P2): from inside the sandbox the store root is whole but
352+# ROOT/projects holds only the served projects. Private, denied-name and denied-old-id projects are
353+# absent; a served project's staging/ and repo.git.migration/, import-notes/ are empty and read-only,
354+# import.tsv and IMPORT-RECEIPT.txt read as nothing; a served project's repo.git and records read.
355+# Control: a wrapper without the tmpfs over ROOT/projects must fail the same probe. Then (review P3)
356+# the store build starts with no RIDS.md: the mirror revokes its copy without stopping, and the
357+# wrapper starts.
358+if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
359+ cat > "$T/store-probe" <<'PROBE'
360+s=$1/interplane-store
361+fail=0
362+absent() { if [ -e "$1" ]; then echo "FAIL present $1"; fail=1; else echo "PASS absent $1"; fi; }
363+empty() { if [ -s "$1" ]; then echo "FAIL not empty $1"; fail=1; else echo "PASS empty $1"; fi; }
364+readable() { if (exec 3< "$1") 2>/dev/null; then echo "PASS readable $1"; else echo "FAIL unreadable $1"; fail=1; fi; }
365+for p in sbpriv omega-pearl sbalias; do absent "$s/projects/$p"; done
366+for p in projects/cuda-crack/staging/canary projects/cuda-crack/repo.git.migration/canary import-notes/canary; do absent "$s/$p"; done
367+empty "$s/import.tsv"; empty "$s/IMPORT-RECEIPT.txt"
368+for p in catalog.tsv projects/cuda-crack/repo.git/HEAD projects/cuda-crack/repo.git/config projects/cuda-crack/records/1 projects/cuda-crack/chain.tsv; do readable "$s/$p"; done
369+read -r l < "$s/projects/cuda-crack/records/1"
370+if [ "$l" = "interplane-project 1" ]; then echo 'PASS served records/1 reads'; else echo "FAIL records/1 first line '$l'"; fail=1; fi
371+n=0; while read -r line; do n=$((n + 1)); done < "$s/catalog.tsv"
372+if [ "$n" = 4 ]; then echo 'PASS catalog.tsv whole (4 lines: the root is bound, not filtered)'; else echo "FAIL catalog.tsv $n lines"; fail=1; fi
373+for e in "$s"/projects/*; do
374+ case ${e##*/} in cuda-crack) echo "PASS projects/ holds $e" ;; *) echo "FAIL projects/ holds $e"; fail=1 ;; esac
375+done
376+for p in projects/cuda-crack/staging/x projects/new import-notes/x; do
377+ if (printf x > "$s/$p") 2>/dev/null; then echo "FAIL writable $s/$p"; fail=1; else echo "PASS denied write $s/$p"; fi
378+done
379+exit "$fail"
380+PROBE
381+ record store-binds bash "$WRAPPER" /usr/bin/dash -s -- "$H" < "$T/store-probe"
382+ [[ $(grep -c '^PASS' "$T/store-binds.log") = 19 && $(grep -c '^FAIL' "$T/store-binds.log") = 0 ]] || { echo 'FAIL store-binds: see store-binds.log'; exit 1; }
383+ sed -e 's|^ args+=(--tmpfs "$store_at/projects")$| : control, no tmpfs over projects|' \
384+ -e 's|^ args+=(--remount-ro "$store_at/projects")$| : control|' "$WRAPPER" > "$T/wrapper-wholestore.sh"
385+ bash -n "$T/wrapper-wholestore.sh" || { echo 'FAIL store-binds control: the mutant wrapper does not parse'; exit 1; }
386+ if cmp -s "$WRAPPER" "$T/wrapper-wholestore.sh"; then echo 'FAIL store-binds control: the mutation did not apply'; exit 1; fi
387+ if record store-binds-control bash "$T/wrapper-wholestore.sh" /usr/bin/dash -s -- "$H" < "$T/store-probe"; then
388+ echo 'FAIL store-binds control: a wrapper binding all of projects/ passed the probe'; exit 1
389+ fi
390+ grep -q '^FAIL present .*/projects/sbpriv$' "$T/store-binds-control.log" || { echo 'FAIL store-binds control: the mutant did not show sbpriv'; exit 1; }
391+ echo 'PASS store-binds: only served projects in the sandbox, staging, migration, import notes masked; control caught'
392+ mv "$H/handoffs/radicle/RIDS.md" "$T/RIDS.md.aside"
393+ record store-no-rids-sync public_sync
394+ [[ ! -e $FORGED_PUBLIC_DIR/RIDS.md ]]
395+ record store-no-rids-start bash "$WRAPPER" /usr/bin/true
396+ mv "$T/RIDS.md.aside" "$H/handoffs/radicle/RIDS.md"
397+ record store-rids-back public_sync
398+ [[ -f $FORGED_PUBLIC_DIR/RIDS.md ]]
399+ echo 'PASS store build without RIDS.md: the mirror revokes its copy without stopping and the wrapper starts'
400+fi
313401 # A canary in the starter's environment reaches no process the child can see.
314402 record env-clean env FORGED_R5_CANARY="$CANARY" bash "$WRAPPER" "$T/envprobe" "$CANARY"
315403 grep -q '^environ /proc/1/environ bytes 0 canary absent$' "$T/env-clean.log"
@@ -336,14 +424,34 @@ if record signature-negative bash "$WRAPPER" /usr/bin/ssh-keygen -Y verify -f "$
336424 -I fixture -n sandbox -s "$DATA/message.sig" < "$DATA/changed"; then
337425 echo 'FAIL invalid signature accepted'; exit 1
338426 fi
339-# Scratch-only mutation: remove read-only protection on the fixture repo.
340-sed 's/args+=(--ro-bind "$repo"/args+=(--bind "$repo"/' "$WRAPPER" > "$T/mutant.sh"
341-grep -q 'args+=(--bind "$repo"' "$T/mutant.sh"
427+# Scratch-only mutation: remove read-only protection on the fixture repo (the store root in a
428+# store-reading build).
429+if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
430+ sed 's/args+=(--ro-bind "$store" "$store_at")/args+=(--bind "$store" "$store_at")/' "$WRAPPER" > "$T/mutant.sh"
431+ grep -q 'args+=(--bind "$store" "$store_at")' "$T/mutant.sh"
432+else
433+ sed 's/args+=(--ro-bind "$repo"/args+=(--bind "$repo"/' "$WRAPPER" > "$T/mutant.sh"
434+ grep -q 'args+=(--bind "$repo"' "$T/mutant.sh"
435+fi
436+# the control writes into the scratch fixture when it is writable (that is what it shows): keep the
437+# store's files the probe appends to, and put them back after it, so the later steps read a whole store
438+SB=$T/store-before-mutation
439+if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
440+ mkdir -p "$SB"; cp -p "$H/interplane-store/catalog.tsv" "$H/interplane-store/projects/cuda-crack/repo.git/config" "$H/interplane-store/projects/cuda-crack/chain.tsv" "$SB/"
441+fi
342442 if record mutation bash "$T/mutant.sh" /usr/bin/dash -s -- "$H" "$HOME" < "$T/probe"; then
343443 echo 'FAIL mutation escaped the control'; exit 1
344444 fi
345-grep -q 'FAIL write .*storage.*/config' "$T/mutation.log"
346-echo 'PASS mutation: writable repository caught by same probe'
445+if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
446+ grep -q 'FAIL write .*interplane-store/' "$T/mutation.log"
447+ echo 'PASS mutation: writable store caught by same probe'
448+ cp -p "$SB/catalog.tsv" "$H/interplane-store/catalog.tsv"; cp -p "$SB/config" "$H/interplane-store/projects/cuda-crack/repo.git/config"
449+ cp -p "$SB/chain.tsv" "$H/interplane-store/projects/cuda-crack/chain.tsv"
450+ cmp -s "$SB/catalog.tsv" "$H/interplane-store/catalog.tsv" && cmp -s "$SB/chain.tsv" "$H/interplane-store/projects/cuda-crack/chain.tsv"
451+else
452+ grep -q 'FAIL write .*storage.*/config' "$T/mutation.log"
453+ echo 'PASS mutation: writable repository caught by same probe'
454+fi
347455 record rollback env FORGED_SANDBOX=off bash "$WRAPPER" /usr/bin/true
348456 grep -q 'OWNER ACCOUNT EXPOSED' "$T/rollback.log"
349457 # The community hub (community/, docs/COMMUNITY.md): with salvage on and <data>/community/ present,
@@ -448,9 +556,17 @@ if [[ $rc != 0 ]]; then
448556 fi
449557 mv "$T/nodes.before" "$H/.local/state/aien-factory/nodes.txt"
450558 public_sync
559+if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
560+ # it reads the node snapshot (status.json, a seam in the store-reading build), pushes into the
561+ # fixture's Radicle copy and adds projects through RIDS.md at run time; the store-reading build serves
562+ # the store's public catalog lines, follows catalog changes without a restart (store/tests/
563+ # agentdoor-store.sh, store/tests/compare.sh reloads) and binds a new project at its next start
564+ echo 'NOT_APPLICABLE refresh-supervisor: node snapshot, Radicle push and RIDS.md run-time additions are not inputs of the store-reading build'
565+else
451566 record refresh-supervisor python3 infra/test/sandbox-refresh.py "$T" "$ROOT" "$PORT"
452567 cp "$DATA/logs/forged.log" "$T/refresh-supervisor-service.log"
453568 sha256sum "$T/restarts.json" "$T/refresh-supervisor-process.log" "$T/refresh-supervisor-service.log" >> "$T/SHA256SUMS"
569+fi
454570 # netns r2: interface questions, starter descriptors, and the port held across restarts. Each
455571 # control runs the scripts of the head before r2 and must show the problem.
456572 record netns-ifleak netns_ifleak_check
@@ -480,7 +596,19 @@ for f in "$T"/restart-hold-*.json "$T"/restart-hold-*.process.log "$T"/race-*.pr
480596 done
481597 if [[ -f quiet/READY ]]; then
482598 integrated_rc=0
483- record integrated-routes python3 infra/test/sandbox-integrated.py "$T" "$ROOT" "$PORT" || integrated_rc=$?
599+ if [[ ${SANDBOX_STORE:-0} = 1 ]]; then
600+ # it walks the collab routes (patch receipts, issue pages) and the Radicle seeding count, which the
601+ # store-reading build composes out; the count snapshot below is the same code in both builds
602+ echo 'NOT_APPLICABLE integrated-routes: collab/ routes and the Radicle seeding count are not composed in the store-reading build'
603+ # the count inputs integrated-routes would make (fixtures, never the live logs or node)
604+ mkdir -p "$H/count-inputs"
605+ for prog in rad getent; do cp server/tests/fake/$prog "$H/count-inputs/$prog"; chmod 755 "$H/count-inputs/$prog"; done
606+ touch "$H/count-inputs/wal"
607+ printf '1794162545.332 203.0.113.5 200 "/rad/%s.git/info/refs?service=git-upload-pack" "git/2.56.0"\n' "$RID" > "$H/count-inputs/dl.log"
608+ printf '127.0.0.1 - - [08/Nov/2026:05:57:35 -0600] "POST /rad/%s.git/git-upload-pack HTTP/2.0" 200 145 "-" "git/2.43.0"\n' "$RID" > "$H/count-inputs/access.log"
609+ else
610+ record integrated-routes python3 infra/test/sandbox-integrated.py "$T" "$ROOT" "$PORT" || integrated_rc=$?
611+ fi
484612 record count-snapshot python3 infra/test/count-snapshot.py "$T" "$ROOT" "$PORT"
485613 record visits env OMC="$OMC" bash visits/tests/run.sh
486614 for f in "$T"/integrated-*.strace "$T"/integrated-*-server.log "$T"/integrated-counts-comparison.json; do

nodes/srch.om

@@ -110,7 +110,7 @@ end
110110 ret st
111111 end
112112 fn nscodesr to void
113-for i ulong get fan 0 bound 64
113+for i ulong get fan 0 bound FAMAX
114114 h = get fhits 0
115115 if ge h 100
116116 break

nodes/stat.om

@@ -9,11 +9,11 @@ text nssnap "/home/drakestapleton/.local/state/aien-factory/nodes.txt"
99 text tfst "/status"
1010 text tfstj "/status.json"
1111 text nstit "Node health"
12-text nsh1 "<h1>Node health</h1>\n<p class=\"muted\">This forge's own Radicle node. Source: the node's sync records (which other nodes hold our signed copy of each repository, and when they took it) and its live peer list, written by the node writer each time the node database changes.</p>\n<p>Checked "
12+text nsh1 "<h1>Node health</h1>\n<p class=\"muted\">The node this forge ran was shut down on 2026-11-14. What follows is its last snapshot (which other nodes held our signed copy of each repository, and when they took it), kept as history.</p>\n<p>Checked "
1313 text nsh2 " UTC, "
1414 text nsh3 " seconds before this page. Connected peers: <b>"
1515 text nsh4 "</b>.</p>\n<p class=\"muted\">Copies: other nodes holding our signed copy of the repository. Behind: how many of those do not have our latest version yet. Reach: seconds our latest version took to arrive at the slowest node that has it. Waiting: seconds our latest version has been out while some copy still lacks it; 0 when none is behind.</p>\n"
16-text nsold "<p class=\"bad\">This check is more than a day old; the node writer may be stopped.</p>\n"
16+text nsold "<p class=\"bad\">This snapshot is more than a day old: the node was shut down on 2026-11-14.</p>\n"
1717 text nsnone "<h1>Node health</h1>\n<p class=\"bad\">Node health is not measured: the node writer's snapshot is missing or unreadable.</p>\n"
1818 text nsth "<table class=\"stat\"><tr><th>Repository</th><th>We seed</th><th>Copies</th><th>Behind</th><th>Reach seconds</th><th>Waiting seconds</th></tr>\n"
1919 text nstd1 "<tr><td><a href=\""
@@ -25,14 +25,14 @@ text nstend "</table>\n"
2525 text nssall "all"
2626 text nssfol "followed"
2727 text nssno "no"
28-text nsjs1 "{\"source\":\"radicle-node sync records and peer list\",\"measured\":"
28+text nsjs1 "{\"source\":\"the last snapshot of this forge's node, shut down on 2026-11-14\",\"measured\":"
2929 text nsjs1b ",\"checked\":"
3030 text nsjs1c ",\"age_s\":"
3131 text nsjs2 ",\"peers\":"
3232 text nsjs3 ",\"node\":\"did:key:"
3333 text nsjs4 "\",\"repos\":["
3434 text nsjsn "{\"name\":\""
35-text nsjsr "\",\"rid\":\"rad:"
35+text nsjsr "\",\"rid\":\""
3636 text nsjss "\",\"seeding\":\""
3737 text nsjsd "\",\"copies\":"
3838 text nsjsb ",\"behind\":"
@@ -104,7 +104,7 @@ ret e
104104 end
105105 note nsrid: the RID at fxo[a, a+n) is allow-list row fridx (false when it is not listed)
106106 fn nsrid a ulong n ulong to bool
107-for i ulong get fan 0 bound 64
107+for i ulong get fan 0 bound FAMAX
108108 if eq n get fail i
109109 same = true
110110 for k ulong n bound 64

open/route.om

@@ -7,7 +7,7 @@ note rad. It appends one line to <data>open/queue and the intake service (open/i
77 note program outside the sandbox) seeds and fetches the project within limits and rewrites
88 note <data>open/list.tsv, which this unit shows.
99 note GET <base>open/ the shelf: every project the intake accepted, marked unfinished and not
10-note verified, with its rad clone line; JSON when the request asks for it
10+note verified; JSON when the request asks for it
1111 note GET <base>open/<rid> one listed project: its row and the snapshot the intake took (head,
1212 note last commits, top-level files, README); JSON interplane/open-build/1
1313 note GET <base>open.json and <base>open/<rid>.json the same JSON under names of their own
@@ -55,15 +55,15 @@ text toheld "held"
5555 text tob58 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
5656 text torad "rad:"
5757 text tologin "login"
58-text tomsg1 "The form was refused. Give the Radicle id of your project (rad:z...), tick the permission box, and keep the note under 200 bytes."
58+text tomsg1 "The form was refused. Give the id of your project, tick the permission box, and keep the note under 200 bytes."
5959 text tomsgq "The intake queue is full. Nothing was saved. Try again later."
60-text toh1 "<div class=\"sl\"><h1>Open builds</h1><p>Bring the project that is not finished, or not right yet. It stays open here so other builders and their agents can pick it up over Radicle. Nothing on this shelf is verified until a revision carries a receipt.</p>"
61-text toh2 "<article class=\"sl-card\"><h2>Bring a project</h2><p>Publish it to Radicle first (<code>rad init</code>, then <code>rad sync --announce</code>), then give its id. This node fetches it and keeps a copy available. There is no limit on how many projects one person brings and no size limit. This computer keeps part of its disk free for its own work; a bring that would use that part is refused with the reason (this computer is nearly full; try again later), and nothing is stored. Any signed-in Radicle key can bring a project while the operator keeps intake open; if it is limited to a list of keys, a key that is not on the list sees the refusal here. The operator can take down a listing, or every listing of a key. You can withdraw yours at any time.</p>"
60+text toh1 "<div class=\"sl\"><h1>Open builds</h1><p>Bring the project that is not finished, or not right yet. It stays open here so other builders and their agents can pick it up. Nothing on this shelf is verified until a revision carries a receipt.</p>"
61+text toh2 "<article class=\"sl-card\"><h2>Bring a project</h2><p>Bringing new projects is closed until Interplane's own store accepts them. There is no limit on how many projects one person brings and no size limit. This computer keeps part of its disk free for its own work; a bring that would use that part is refused with the reason (this computer is nearly full; try again later), and nothing is stored. Any signed-in key can bring a project while the operator keeps intake open; if it is limited to a list of keys, a key that is not on the list sees the refusal here. The operator can take down a listing, or every listing of a key. You can withdraw yours at any time.</p>"
6262 text toh3 "<p><a href=\""
63-text toh4 "\">Sign in with your Radicle key</a> to bring a project.</p></article>"
63+text toh4 "\">Sign in with your key</a> to bring a project.</p></article>"
6464 text tof1 "<form method=\"post\" action=\""
6565 text tof2 "\"><input type=\"hidden\" name=\"csrf\" value=\""
66-text tof3 "\"><input type=\"hidden\" name=\"action\" value=\"bring\"><p><label>Radicle id <input name=\"rid\" maxlength=\"48\" required placeholder=\"rad:z...\"></label></p><p><label>What is unfinished, in one line <input name=\"note\" maxlength=\"200\"></label></p><p><label><input type=\"checkbox\" name=\"consent\" value=\"yes\" required> I have the right to share this project and it carries an open license.</label></p><p><button type=\"submit\">Bring it</button></p></form></article>"
66+text tof3 "\"><input type=\"hidden\" name=\"action\" value=\"bring\"><p><label>Project id <input name=\"rid\" maxlength=\"48\" required></label></p><p><label>What is unfinished, in one line <input name=\"note\" maxlength=\"200\"></label></p><p><label><input type=\"checkbox\" name=\"consent\" value=\"yes\" required> I have the right to share this project and it carries an open license.</label></p><p><button type=\"submit\">Bring it</button></p></form></article>"
6767 text tol1 "<h2>On the shelf</h2>"
6868 text tol0 "<p>The shelf is waiting for its first project. Unfinished is welcome.</p>"
6969 text toc1 "<article class=\"sl-card\"><h3>"
@@ -71,15 +71,14 @@ text toc2 "</h3><p>"
7171 text toc3 "</p>"
7272 text tounf1 "<p><strong>Unfinished:</strong> "
7373 text tounf2 "</p>"
74-text toc4 "<pre>rad clone rad:"
75-text toc5 "</pre><p>Not verified. Brought by "
74+text toc5 "<p>Not verified. Brought by "
7675 text toc6 " on "
7776 text toc7 ", "
7877 text toc8 " KiB.</p>"
7978 text toc9 "</article>"
8079 text tow1 "\"><input type=\"hidden\" name=\"action\" value=\"withdraw\"><input type=\"hidden\" name=\"rid\" value=\""
8180 text tow2 "\"><button type=\"submit\">Withdraw</button></form>"
82-text tor1 "<article class=\"sl-card\"><h3>rad:"
81+text tor1 "<article class=\"sl-card\"><h3>"
8382 text tor2 "</h3><p>Only you see this. Intake result: "
8483 text tor3 "</p></article>"
8584 text toend "</div>"
@@ -92,10 +91,8 @@ text top1 "<div class=\"sl\"><p><a href=\""
9291 text top2 "\">Open builds</a></p><h1>"
9392 text top3 "</h1><p>"
9493 text top4 "</p>"
95-text top5 "<pre>rad clone rad:"
96-text tdv1 "<section class=\"pj-dev\" id=\"For-developers\"><h2>For developers</h2><dl class=\"pj-terms\"><dt>Radicle ID</dt><dd><code>rad:"
97-text tdv2 "</code></dd><dt>Clone</dt><dd><code>rad clone rad:"
98-text tdv3 "</code></dd><dt>Download</dt><dd>"
94+text top5 "<p>No public Git URL yet: Interplane does not serve Git clones yet.</p>"
95+text tdv1 "<section class=\"pj-dev\" id=\"For-developers\"><h2>For developers</h2><dl class=\"pj-terms\"><dt>Download</dt><dd>"
9996 text tdvtar ".tar\">"
10097 text tdvtar2 ".tar</a>, SHA-256 <code>"
10198 text tdvcode "</code>"
@@ -105,15 +102,15 @@ text tdv5 "</code></dd><dt>Their public key</dt><dd><code>"
105102 text tdv6 "</code></dd>"
106103 text tdv7 "</code></dd>"
107104 text tdvhub "<dt>The hub&#39;s key</dt><dd><code>"
108-text tdv8 "</dl><p>Stored on Radicle by the Interplane hub. The hub&#39;s key"
105+text tdv8 "</dl><p>Stored by the Interplane hub. The hub&#39;s key"
109106 text tdv9 " ("
110107 text tdv10 ")"
111-text tdv11 " created this Radicle repository and signs its history: that shows the hub stored these exact bytes, not who wrote them. The person who brought it signed the list of files (<code>.interplane/brought.txt</code>, signature <code>.interplane/brought.sig</code>) with a key made on their own computer: that shows the same key vouched for exactly these files; it does not show who that person is or that they wrote the code. To check it: <code>ssh-keygen -Y check-novalidate -n interplane-bring -f &lt;their public key&gt; -s .interplane/brought.sig</code>, reading the first five lines of <code>brought.txt</code> on standard input.</p></section>"
108+text tdv11 " created this repository and signs its history: that shows the hub stored these exact bytes, not who wrote them. The person who brought it signed the list of files (<code>.interplane/brought.txt</code>, signature <code>.interplane/brought.sig</code>) with a key made on their own computer: that shows the same key vouched for exactly these files; it does not show who that person is or that they wrote the code. To check it: <code>ssh-keygen -Y check-novalidate -n interplane-bring -f &lt;their public key&gt; -s .interplane/brought.sig</code>, reading the first five lines of <code>brought.txt</code> on standard input.</p></section>"
112109 text tdidp8 "did:key:"
113110 text tdvsshn "ssh-ed25519"
114-text top6 "</pre><p>Not verified. Brought by "
111+text top6 "<p>Not verified. Brought by "
115112 text top7 " on "
116-text top8 ". What follows is a snapshot taken when the project was listed; the Radicle copy is the source.</p>"
113+text top8 ". What follows is a snapshot taken when the project was listed.</p>"
117114 text toph "<p>Head <code>"
118115 text tophe "</code></p>"
119116 text topc "<h2>Latest commits</h2><ul>"
@@ -124,7 +121,7 @@ text toppre "</pre>"
124121 text topli "<li>"
125122 text toplie "</li>"
126123 text topno "<p>No snapshot of this project yet.</p>"
127-text topj1 "{\"schema\":\"interplane/open-build/1\",\"rid\":\"rad:"
124+text topj1 "{\"schema\":\"interplane/open-build/1\",\"rid\":\""
128125 text topj2 "\",\"verified\":false,\"head\":\""
129126 text topj3 "\",\"commits\":["
130127 text topj4 "],\"files\":["
@@ -135,14 +132,14 @@ text topa1 "<h2>Parts taken from this project</h2><p>Submissions whose origin is
135132 text topa2 " (Omega part, verified)"
136133 text topa3 " (source, not verified)"
137134 text topa4 "<h2>Parts taken from this project</h2><p>None yet. Submit one source from it at <a href=\""
138-text topa5 "salvage/new\">Bring your build</a> with the origin <code>rad:"
135+text topa5 "salvage/new\">Bring your build</a> with the origin <code>"
139136 text topa6 "</code>. A derived Omega part whose example is reproduced is listed here with its receipt.</p>"
140137 text topk1 "{\"id\":\""
141138 text topk2 "\",\"title\":\""
142139 text topk3 "\",\"kind\":\"omega-part\",\"verified\":true}"
143140 text topk4 "\",\"kind\":\"source\",\"verified\":false}"
144-text toj1 "{\"schema\":\"interplane/open-builds/1\",\"note\":\"unfinished projects brought over Radicle; nothing here is verified\",\"projects\":["
145-text toj2 "{\"rid\":\"rad:"
141+text toj1 "{\"schema\":\"interplane/open-builds/1\",\"note\":\"unfinished projects brought to this shelf; nothing here is verified\",\"projects\":["
142+text toj2 "{\"rid\":\""
146143 text toj3 "\",\"brought_by\":\""
147144 text toj4 "\",\"date\":\""
148145 text toj5 "\",\"kib\":"
@@ -154,6 +151,10 @@ text toj10 "]}\n"
154151 text toctj "application/json; charset=utf-8"
155152 text tohex "0123456789abcdef"
156153 text tou00 "\\u00"
154+note toterms: the terms ohterm looks for, lower case, split by |. Read by code only, never sent.
155+text toterms "radicle|heartwood|rad:z|rad clone|rad init|rad sync|rad id|rad patch|rad auth|/rad/"
156+text tocopy ": copy kept from its GitHub history"
157+text todnone "No description yet."
157158 global gorid uchar 48
158159 global goridl ulong 1
159160 global godid uchar 96
@@ -222,7 +223,7 @@ text toqd "queued "
222223 text tostor "stored"
223224 text tosgb "-----BEGIN SSH SIGNATURE-----"
224225 text tosge "-----END SSH SIGNATURE-----"
225-text tosbh "<p>Stored on Radicle by the Interplane hub: the hub's key signed the Radicle record. The person who brought it signed the list of files.</p>"
226+text tosbh "<p>Stored by the Interplane hub: the hub's key signs the repository's history. The person who brought it signed the list of files.</p>"
226227 text toj9a "\",\"verified\":false"
227228 text tosbh1 ",\"stored_by_hub\":"
228229 text totrue "true"
@@ -570,24 +571,20 @@ note ohunf: "<p><strong>Unfinished:</strong> <note></p>" for the row s..e, or no
570571 fn ohunf s ulong e ulong to void
571572 a = ohfld s e 7
572573 b = ohfe a e
573-if le b a
574+if le ohdend a b a
574575 ret
575576 end
576577 fput tounf1
577-ohesc s e 7 200
578+ohdsc s e 7 200 false
578579 fput tounf2
579580 end
580581 note ---- the developer section of a project the hub stored (classes of the curated project page,
581-note server/pages.om, in forge.css): Radicle ID, clone line, download and its SHA-256, the bringer's
582+note server/pages.om, in forge.css): download and its SHA-256, the bringer's
582583 note DID and public key (ssh form, encoded from the did:key), the hub's key as the intake read it from
583584 note the node (rad self --did, snapshot line N; left out when the snapshot has none), and what each
584585 note signature shows. Every value is escaped.
585586 fn ohdev s ulong e ulong to void
586587 fput tdv1
587-ohesc s e 0 44
588-fput tdv2
589-ohesc s e 0 44
590-fput tdv3
591588 h = new uchar 64 0
592589 if ohdlsha h
593590 fput tocl1
@@ -806,6 +803,10 @@ b = ohfe a e
806803 if gt sub b a cap
807804 b = add a cap
808805 end
806+ohescr a b
807+end
808+note ohescr: gol[a, b) HTML-escaped
809+fn ohescr a ulong b ulong to void
809810 i = a
810811 while lt i b bound 262144
811812 c = get gol i
@@ -821,6 +822,10 @@ b = ohfe a e
821822 if gt sub b a cap
822823 b = add a cap
823824 end
825+ohjsr a b
826+end
827+note ohjsr: gol[a, b) as JSON string bytes
828+fn ohjsr a ulong b ulong to void
824829 i = a
825830 while lt i b bound 262144
826831 c = get gol i
@@ -839,6 +844,97 @@ end
839844 i = add i 1
840845 end
841846 end
847+note ohterm: gol[a, b) (w 0, the list row) or gop[a, b) (w 1, the snapshot) holds a term of
848+note toterms, case-insensitive. Radicle was removed on 2026-11-14 and the shelf must not point
849+note anyone to it, but list.tsv rows and snapshots written before then still carry its wording
850+note (38 descriptions read "public Radicle home while GitHub is suspended (rad init ...)"). The
851+note stored data stays as it is: every description, note, state and snapshot line is checked
852+note here when it is shown (ohdend, ohdsc, ohpshow).
853+fn ohterm w ulong a ulong b ulong to bool
854+nt = len toterms
855+t = ulong 0
856+while lt t nt bound 64
857+k = ulong 0
858+while lt add t k nt bound 64
859+if eq get toterms add t k 124
860+break
861+end
862+k = add k 1
863+end
864+i = a
865+while le add i k b bound 262144
866+m = ulong 0
867+while lt m k bound 16
868+c = uchar 0
869+if eq w 0
870+c = get gol add i m
871+else
872+c = get gop add i m
873+end
874+if and ge c 65 le c 90
875+c = add c 32
876+end
877+if ne c get toterms add t m
878+break
879+end
880+m = add m 1
881+end
882+if eq m k
883+ret true
884+end
885+i = add i 1
886+end
887+t = add add t k 1
888+end
889+ret false
890+end
891+note ohdend: the end of the part of the list field gol[a, b) that may be shown: b when it has no
892+note term; else the place of its first ": " when the part before it has none (shown with tocopy);
893+note else a (nothing of it is shown)
894+fn ohdend a ulong b ulong to ulong
895+if not ohterm 0 a b
896+ret b
897+end
898+p = a
899+while lt add p 1 b bound 262144
900+if and eq get gol p 58 eq get gol add p 1 32
901+if ohterm 0 a p
902+ret a
903+end
904+ret p
905+end
906+p = add p 1
907+end
908+ret a
909+end
910+note ohdsc: field k (1 state, 6 description, 7 note) of the row s..e as ohesc (json false) or ohjs
911+note (json true) show it, through ohdend: a cut part is followed by tocopy (not for a state); a
912+note description with nothing left is todnone, a note or state with nothing left is empty
913+fn ohdsc s ulong e ulong k ulong cap ulong json bool to void
914+a = ohfld s e k
915+b = ohfe a e
916+r = ohdend a b
917+c = r
918+if gt sub c a cap
919+c = add a cap
920+end
921+if json
922+ohjsr a c
923+else
924+ohescr a c
925+end
926+if and gt r a lt r b
927+if ne k 1
928+fput tocopy
929+end
930+ret
931+end
932+if and eq r a lt a b
933+if eq k 6
934+fput todnone
935+end
936+end
937+end
842938 note ohis: field k of the row equals t
843939 fn ohis s ulong e ulong k ulong t view uchar * to bool
844940 a = ohfld s e k
@@ -918,11 +1014,9 @@ fput tocl2
9181014 ohesc s e 5 120
9191015 fput tocl3
9201016 fput toc2
921-ohesc s e 6 400
1017+ohdsc s e 6 400 false
9221018 fput toc3
9231019 ohunf s e
924-fput toc4
925-ohesc s e 0 44
9261020 fput toc5
9271021 ohesc s e 2 96
9281022 fput toc6
@@ -949,7 +1043,7 @@ fn ohrefused s ulong e ulong to void
9491043 fput tor1
9501044 ohesc s e 0 44
9511045 fput tor2
952-ohesc s e 1 80
1046+ohdsc s e 1 80 false
9531047 fput tor3
9541048 end
9551049 note ohnum: field 4 (kilobytes) as a number
@@ -988,9 +1082,9 @@ fnum ohnum s e
9881082 fput toj6
9891083 ohjs s e 5 120
9901084 fput toj7
991-ohjs s e 6 400
1085+ohdsc s e 6 400 true
9921086 fput toj8
993-ohjs s e 7 200
1087+ohdsc s e 7 200 true
9941088 fput toj9a
9951089 ohdlj s e
9961090 fputc 125
@@ -1282,13 +1376,21 @@ ret false
12821376 end
12831377 ret eq get gop add s 1 9
12841378 end
1379+note ohpshow: gop[s, e) is a snapshot line of this kind whose text has no ohterm term (a line
1380+note that has one is left out)
1381+fn ohpshow kind uchar s ulong e ulong to bool
1382+if not ohpk kind s e
1383+ret false
1384+end
1385+ret not ohterm 1 add s 2 e
1386+end
12851387 fn ohpcnt kind uchar to ulong
12861388 lim = get gopl 0
12871389 n = ulong 0
12881390 s = ulong 0
12891391 while lt s lim bound 65536
12901392 e = ohpeol s
1291-if ohpk kind s e
1393+if ohpshow kind s e
12921394 n = add n 1
12931395 end
12941396 s = add e 1
@@ -1341,7 +1443,7 @@ lim = get gopl 0
13411443 s = ulong 0
13421444 while lt s lim bound 65536
13431445 e = ohpeol s
1344-if ohpk kind s e
1446+if ohpshow kind s e
13451447 ohpitem kind s e
13461448 end
13471449 s = add e 1
@@ -1363,7 +1465,7 @@ n = ulong 0
13631465 s = ulong 0
13641466 while lt s lim bound 65536
13651467 e = ohpeol s
1366-if ohpk kind s e
1468+if ohpshow kind s e
13671469 if gt n 0
13681470 fputc 44
13691471 end
@@ -1390,7 +1492,7 @@ lim = get gopl 0
13901492 s = ulong 0
13911493 while lt s lim bound 65536
13921494 e = ohpeol s
1393-if ohpk kind s e
1495+if ohpshow kind s e
13941496 ohpjs add s 2 e
13951497 if first
13961498 ret
@@ -1403,7 +1505,7 @@ end
14031505 end
14041506 note ---- parts taken from the project: the link between the shelf and the submission journey
14051507 note A submission (salvage/) names where it came from in its origin field. A source whose origin
1406-note is exactly rad:<rid>, and an Omega part derived from such a source, are listed on the
1508+note is exactly <rid> or rad:<rid>, and an Omega part derived from such a source, are listed on the
14071509 note project page. The salvage slice publishes a derived part only with a passing receipt, so a
14081510 note listed part is a verified one; a source is listed as not verified. The project itself stays
14091511 note "Not verified": this is a list of facts, not a verdict on the project. Only the newest 200
@@ -1420,10 +1522,20 @@ put gotit i get glrec add o i
14201522 end
14211523 put gotitl 0 n
14221524 end
1423-note ohorig: the origin field of the loaded record is exactly rad:<gorid>
1525+note ohorig: the origin field of the loaded record is exactly <gorid>, or rad:<gorid> as sources
1526+note named it before the shelf showed the bare id
14241527 fn ohorig to bool
14251528 n = get gllen 2
14261529 m = get goridl 0
1530+if eq n m
1531+q = get gloff 2
1532+for i ulong m bound 44
1533+if ne get glrec add q i get gorid i
1534+ret false
1535+end
1536+end
1537+ret true
1538+end
14271539 if ne n add 4 m
14281540 ret false
14291541 end
@@ -1582,9 +1694,9 @@ fnum ohnum s e
15821694 fput toj6
15831695 ohjs s e 5 120
15841696 fput toj7
1585-ohjs s e 6 400
1697+ohdsc s e 6 400 true
15861698 fput toj8
1587-ohjs s e 7 200
1699+ohdsc s e 7 200 true
15881700 fput toj9a
15891701 ohdlj s e
15901702 fput topj2b
@@ -1624,11 +1736,10 @@ fput todir
16241736 fput top2
16251737 ohesc s e 5 120
16261738 fput top3
1627-ohesc s e 6 400
1739+ohdsc s e 6 400 false
16281740 fput top4
16291741 ohunf s e
16301742 fput top5
1631-ohesc s e 0 44
16321743 fput top6
16331744 ohesc s e 2 96
16341745 fput top7

open/tests/run.sh

@@ -641,7 +641,7 @@ start "$T/forged"
641641 R1=$(rid H1)
642642 c=$(code GET /open); check "$c" 301 "GET /open redirects"; check "$(hdr location)" /open/ "to /open/"
643643 c=$(code GET /open/); check "$c" 200 "GET /open/ signed out"
644-grep -q "Open builds" "$T/body" && grep -q "Sign in with your Radicle key" "$T/body" && ok "signed out: the page asks for a sign-in" || bad "signed-out page text"
644+grep -q "Open builds" "$T/body" && grep -q "Sign in with your key" "$T/body" && ok "signed out: the page asks for a sign-in" || bad "signed-out page text"
645645 grep -q 'name="rid"' "$T/body" && bad "signed out: the form is shown" || ok "signed out: no bring form"
646646 grep -q "waiting for its first project" "$T/body" && ok "an empty shelf says so" || bad "empty shelf text"
647647 c=$(code POST /open/ --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes"); [ "$c" != 200 ] && [ "$(qn)" = 0 ] && ok "NEG a POST without a session writes nothing ($c)" || bad "unsigned POST: $c, queue $(qn)"
@@ -694,7 +694,7 @@ cp "$T/data/open/p/$R1.txt" "$T/data/open/p/$(rid H4).txt"
694694 c=$(code GET /open/); check "$c" 200 "the shelf with rows"
695695 grep -q '<script' "$T/body" && bad "the page carries a script tag from a row" || ok "hostile row text is escaped (no <script in the page)"
696696 grep -q '&lt;script&gt;alert(1)&lt;/script&gt;&quot;&amp;' "$T/body" && ok "the hostile text is shown as text" || bad "escaped text not found"
697-check "$(grep -o 'rad clone rad:z[0-9A-Za-z]*' "$T/body" | sort | tr '\n' ' ')" "rad clone rad:$R1 rad clone rad:$(rid H3) rad clone rad:$(rid H8) " "exactly the two well-formed open rows and the held row are listed"
697+check "$(grep -o 'href="/open/z[0-9A-Za-z]*"' "$T/body" | sort | tr '\n' ' ')" "href=\"/open/$R1\" href=\"/open/$(rid H3)\" href=\"/open/$(rid H8)\" " "exactly the two well-formed open rows and the held row are listed"
698698 check "$(grep -o 'Not verified' "$T/body" | wc -l)" 3 "each listed project says Not verified"
699699 grep -q -e "bad-rid" -e "gone-project" -e "larger than 50 MiB" -e "not found" "$T/body" && bad "a refused, withdrawn or malformed row is public" || ok "refused, withdrawn and malformed rows are not public"
700700 grep -q 'value="withdraw"' "$T/body" && bad "signed out: a withdraw button" || ok "signed out: no withdraw button"
@@ -709,7 +709,7 @@ d = json.load(open(sys.argv[1], encoding='utf-8'))
709709 p = d['projects']
710710 assert d['schema'] == 'interplane/open-builds/1' and len(p) == 3, d
711711 a = p[0]
712-assert a['rid'] == 'rad:' + sys.argv[2] and a['name'] == sys.argv[3] and a['unfinished'] == 'note ' + sys.argv[3], a
712+assert a['rid'] == sys.argv[2] and a['name'] == sys.argv[3] and a['unfinished'] == 'note ' + sys.argv[3], a
713713 assert a['brought_by'] == sys.argv[4] and a['kib'] == 412 and a['date'] == '2026-11-10', a
714714 assert all(x['verified'] is False for x in p)
715715 EOF
@@ -718,7 +718,7 @@ c=$(code GET /open/); grep -q "href=\"/open/$R1\"" "$T/body" && ok "the shelf li
718718 c=$(code GET "/open/$R1"); check "$c" 200 "GET /open/<rid> of a listed project"
719719 grep -q -e '<script' -e '<img' "$T/body" && bad "the project page carries a tag from the snapshot" || ok "snapshot text is escaped on the project page"
720720 grep -q 'fix &lt;script&gt;alert(2)&lt;/script&gt;' "$T/body" && grep -q '&lt;img src=x onerror=alert(3)&gt;' "$T/body" && ok "the hostile commit subject and README line are shown as text" || bad "escaped snapshot text not found"
721-grep -q 'Latest commits' "$T/body" && grep -q '<li>src/</li>' "$T/body" && grep -q '<li>we&lt;ird&gt;&amp;name.txt</li>' "$T/body" && grep -q 'abc123def4567890abc123def4567890abc123de 2026-11-10' "$T/body" && grep -q "rad clone rad:$R1" "$T/body" && grep -q 'Not verified' "$T/body" && ok "the page shows head, commits, files (a folder with a slash), clone line, Not verified" || bad "project page content"
721+grep -q 'Latest commits' "$T/body" && grep -q '<li>src/</li>' "$T/body" && grep -q '<li>we&lt;ird&gt;&amp;name.txt</li>' "$T/body" && grep -q 'abc123def4567890abc123def4567890abc123de 2026-11-10' "$T/body" && grep -q 'No public Git URL yet: Interplane does not serve Git clones yet.' "$T/body" && grep -q 'Not verified' "$T/body" && ok "the page shows head, commits, files (a folder with a slash), no-clone-URL line, Not verified" || bad "project page content"
722722 grep -q -e 'unknown kind' -e 'junk without' "$T/body" && bad "an unknown snapshot line is shown" || ok "snapshot lines of an unknown kind are not shown"
723723 c=$(code GET "/open/$(rid H8)"); check "$c" 200 "a held project has a page"; grep -q 'No snapshot of this project yet' "$T/body" && ok "without a snapshot the page says so" || bad "no-snapshot text"
724724 c=$(code GET "/open/$(rid H4)"); check "$c" 404 "NEG a refused project has no page, even with a snapshot file there"
@@ -732,7 +732,7 @@ c=$(code GET "/open/$R1" -H 'Accept: application/json'); check "$c" 200 "the pro
732732 python3 -I - "$T/body" "$R1" "$K1" <<'EOF' && ok "project JSON: parses; head, commits, files and README round-trip as data" || bad "project JSON"
733733 import json, sys
734734 d = json.load(open(sys.argv[1], encoding='utf-8'))
735-assert d['schema'] == 'interplane/open-build/1' and d['rid'] == 'rad:' + sys.argv[2] and d['brought_by'] == sys.argv[3], d
735+assert d['schema'] == 'interplane/open-build/1' and d['rid'] == sys.argv[2] and d['brought_by'] == sys.argv[3], d
736736 assert d['verified'] is False and d['kib'] == 412
737737 assert d['head'] == 'abc123def4567890abc123def4567890abc123de 2026-11-10', d['head']
738738 assert d['commits'] == ['1a2b3c4 2026-11-10 Ada <b> fix <script>alert(2)</script>'], d['commits']
@@ -779,7 +779,7 @@ EOF
779779 c=$(code GET /open.json); check "$c" 200 "GET /open.json"
780780 python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["schema"]=="interplane/open-builds/1" and len(d["projects"])==3' "$T/body" && ok "/open.json is the shelf JSON without an Accept header" || bad "/open.json"
781781 c=$(code GET "/open/$R1.json"); check "$c" 200 "GET /open/<rid>.json"
782-python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["schema"]=="interplane/open-build/1" and d["rid"]=="rad:"+sys.argv[2] and len(d["commits"])==1' "$T/body" "$R1" && ok "/open/<rid>.json is the project JSON without an Accept header" || bad "/open/<rid>.json"
782+python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["schema"]=="interplane/open-build/1" and d["rid"]==sys.argv[2] and len(d["commits"])==1' "$T/body" "$R1" && ok "/open/<rid>.json is the project JSON without an Accept header" || bad "/open/<rid>.json"
783783 c=$(code GET "/open/$(rid H4).json"); check "$c" 404 "NEG the .json name of a refused project"
784784 c=$(code GET "/open/${R1}.jsonx"); check "$c" 404 "NEG a near-miss suffix is not a rid"
785785 c=$(code POST /open.json -H "$CK" --data-urlencode "csrf=$TOK"); [ "$c" != 200 ] && [ "$c" != 303 ] && ok "NEG POST to /open.json is refused ($c)" || bad "POST /open.json: $c"
@@ -803,7 +803,7 @@ shelfck() {
803803 python3 -I - "$1" "$2" <<'EOF'
804804 import json, sys
805805 want = [l.split('\t')[0] for l in open(sys.argv[1], encoding='utf-8') if l.split('\t')[1] in ('open', 'held', 'stored')]
806-got = [p['rid'][4:] for p in json.load(open(sys.argv[2], encoding='utf-8'))['projects']]
806+got = [p['rid'] for p in json.load(open(sys.argv[2], encoding='utf-8'))['projects']]
807807 assert got == want, (len(got), len(want))
808808 print(len(got))
809809 EOF
@@ -814,7 +814,7 @@ n=$(shelfck "$T/data/open/list.tsv" "$T/body" 2>&1) && ok "/open.json lists all
814814 check "$n" "$BPUB" "and that is every open and held row planted"
815815 c=$(code GET /open/); [ "$c" = 200 ] && grep -q "$BOPEN" "$T/body" && grep -q "$BLONG" "$T/body" && ok "/open/ shows the last open row and the 70,000-byte row" || bad "/open/ with a 1.2 MB list: $c"
816816 c=$(code GET "/open/$BOPEN"); check "$c" 200 "the project page of the last row answers"
817-c=$(code GET "/open/$BLONG.json"); [ "$c" = 200 ] && python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["rid"]=="rad:"+sys.argv[2] and len(d["description"])==400' "$T/body" "$BLONG" && ok "the 70,000-byte row has a page; its description is cut at the page's 400 as every row's is" || bad "long row page: $c $(head -c 200 "$T/body")"
817+c=$(code GET "/open/$BLONG.json"); [ "$c" = 200 ] && python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["rid"]==sys.argv[2] and len(d["description"])==400' "$T/body" "$BLONG" && ok "the 70,000-byte row has a page; its description is cut at the page's 400 as every row's is" || bad "long row page: $c $(head -c 200 "$T/body")"
818818 stop
819819 if build "$T/forged-mtr" '/^fn ohlfill /,/^fn ohlnext /s/^k = pread int sub get gost 0 1 goc 0 65536 long pos$/w = ulong 0\nif lt pos 262143\nw = sub 262143 pos\nend\nif gt w 65536\nw = ulong 65536\nend\nk = long 0\nif gt w 0\nk = pread int sub get gost 0 1 goc 0 w long pos\nend/'; then
820820 start "$T/forged-mtr"; c=$(code GET /open.json)

open/tests/up.sh

@@ -317,10 +317,10 @@ check "$(sed -n 6p "$T/bt")" "$(printf '%s\t17\tREADME.md' "$(printf '# demo, ha
317317 printf 'p %s\n' "$(cut -d' ' -f1,2 "$T/k1.pub")" > "$T/as"
318318 ssh-keygen -Y verify -f "$T/as" -I p -n interplane-bring -s "$T/bs" < "$T/bt5" > /dev/null 2>&1 && ok "anyone can verify brought.sig over the statement with ssh-keygen -Y verify" || bad "brought.sig does not verify"
319319 code GET /open/ > /dev/null
320-grep -q "Stored on Radicle by the Interplane hub: the hub's key signed the Radicle record. The person who brought it signed the list of files." "$T/body" && ok "the shelf row says who signed what" || bad "no who-signs-what sentence on the shelf"
321-grep -q "rad clone rad:$GOOD" "$T/body" && ok "the shelf lists the stored project" || bad "stored project not on the shelf"
320+grep -q "Stored by the Interplane hub: the hub's key signs the repository's history. The person who brought it signed the list of files." "$T/body" && ok "the shelf row says who signed what" || bad "no who-signs-what sentence on the shelf"
321+grep -q "href=\"/open/$GOOD\"" "$T/body" && ok "the shelf lists the stored project" || bad "stored project not on the shelf"
322322 code GET /open.json > /dev/null
323-python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); p=[x for x in d["projects"] if x["rid"]=="rad:"+sys.argv[2]][0]; assert p["stored_by_hub"] is True and p["download"]=="/open/"+sys.argv[2]+".tar" and len(p["download_sha256"])==64; print(p["download_sha256"])' "$T/body" "$GOOD" > "$T/dsha" && ok "shelf JSON: stored_by_hub true, download, download_sha256" || bad "shelf JSON fields: $(head -c 400 "$T/body")"
323+python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); p=[x for x in d["projects"] if x["rid"]==sys.argv[2]][0]; assert p["stored_by_hub"] is True and p["download"]=="/open/"+sys.argv[2]+".tar" and len(p["download_sha256"])==64; print(p["download_sha256"])' "$T/body" "$GOOD" > "$T/dsha" && ok "shelf JSON: stored_by_hub true, download, download_sha256" || bad "shelf JSON fields: $(head -c 400 "$T/body")"
324324 code GET "/open/$GOOD.json" > /dev/null
325325 python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["stored_by_hub"] is True and d["download"]=="/open/"+sys.argv[2]+".tar" and d["download_sha256"]==sys.argv[3] and "README.md" in d["files"]' "$T/body" "$GOOD" "$(cat "$T/dsha")" && ok "page JSON: the same fields and the snapshot" || bad "page JSON: $(head -c 400 "$T/body")"
326326 c=$(code GET "/open/$GOOD.tar"); check "$c" 200 "GET /open/<rid>.tar"
@@ -332,10 +332,10 @@ c=$(code GET "/open/z2abcdefghijkmnopqrstuvwxyzAB.tar"); check "$c" 404 "NEG no
332332 # the project page of a stored project: no empty label, the developer section, all of it escaped
333333 code GET "/open/$GOOD" > /dev/null; cp "$T/body" "$T/page.html"
334334 grep -q '<section class="pj-dev" id="For-developers"><h2>For developers</h2><dl class="pj-terms">' "$T/page.html" && ok "the page of a stored project has the developer section (pj-dev, pj-terms)" || bad "no developer section"
335-grep -q "<dt>Radicle ID</dt><dd><code>rad:$GOOD</code></dd><dt>Clone</dt><dd><code>rad clone rad:$GOOD</code>" "$T/page.html" && ok "it shows the Radicle ID and the clone line" || bad "developer section: id or clone line"
335+grep -q '<dl class="pj-terms"><dt>Download</dt><dd>' "$T/page.html" && ! grep -q -e 'Radicle ID' -e 'rad clone' -e "rad:$GOOD" "$T/page.html" && ok "it shows the download first, with no Radicle ID, clone line or rad: id" || bad "developer section: id or clone line"
336336 grep -q "/open/$GOOD.tar\">$GOOD.tar</a>, SHA-256 <code>$(cat "$T/dsha")</code>" "$T/page.html" && ok "it shows the download and its SHA-256" || bad "developer section: download"
337337 grep -q "<dt>The hub&#39;s key</dt><dd><code>did:key:z6MkHubStandInKeyabcdefghijkmnopqrstuvwxyzAB</code>" "$T/page.html" && ok "the hub's key comes from the node (rad self --did, read by the intake)" || bad "hub key not shown"
338-grep -q "Stored on Radicle by the Interplane hub. The hub&#39;s key (did:key:z6MkHubStandInKeyabcdefghijkmnopqrstuvwxyzAB) created this Radicle repository" "$T/page.html" && ok "the paragraph names the hub's key" || bad "paragraph without the hub key"
338+grep -q "Stored by the Interplane hub. The hub&#39;s key (did:key:z6MkHubStandInKeyabcdefghijkmnopqrstuvwxyzAB) created this repository" "$T/page.html" && ok "the paragraph names the hub's key" || bad "paragraph without the hub key"
339339 KEYLINE=$(sed -n 's|.*<dt>Their public key</dt><dd><code>\(ssh-ed25519 [A-Za-z0-9+/=]*\)</code>.*|\1|p' "$T/page.html")
340340 check "$KEYLINE" "$(cut -d' ' -f1,2 "$T/k1.pub")" "the bringer's public key, encoded from the did:key, equals their ssh key"
341341 printf '%s\n' "$KEYLINE" > "$T/their.pub"
@@ -623,7 +623,7 @@ world a15; plantbig "$K3" 1048576; cp "$W/work/list.tsv" "$T/a15.before"; up "$T
623623 check "$(upst "$USHA")" stored "an upload into a 1 MiB list is stored"
624624 n=$(stat -c %s "$T/a15.before"); cmp -s -n "$n" "$T/a15.before" "$W/work/list.tsv" && [ "$(( $(wc -l < "$W/work/list.tsv") - $(wc -l < "$T/a15.before") ))" = 1 ] && [ "$(tail -1 "$W/work/list.tsv" | cut -f2)" = stored ] && ok "every planted row kept byte for byte, the stored row last ($(stat -c %s "$W/work/list.tsv") bytes)" || bad "1 MiB list: rows lost or changed ($(wc -l < "$W/work/list.tsv") rows)"
625625 cmp -s "$W/work/list.tsv" "$T/data/open/list.tsv" && ok "the published 1 MiB list is the private list, byte for byte" || bad "the published list differs"
626-c=$(code GET /open.json); python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); n=int(sys.argv[2]); assert len(d["projects"])==n and d["projects"][-1]["rid"]=="rad:"+sys.argv[3], (len(d["projects"]), n)' "$T/body" "$(wc -l < "$W/work/list.tsv")" "$(tail -1 "$W/work/list.tsv" | cut -f1)" && ok "forged lists all $(wc -l < "$W/work/list.tsv") rows of the 1 MiB shelf, the stored one last ($c)" || bad "/open.json with a 1 MiB list: $c"
626+c=$(code GET /open.json); python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); n=int(sys.argv[2]); assert len(d["projects"])==n and d["projects"][-1]["rid"]==sys.argv[3], (len(d["projects"]), n)' "$T/body" "$(wc -l < "$W/work/list.tsv")" "$(tail -1 "$W/work/list.tsv" | cut -f1)" && ok "forged lists all $(wc -l < "$W/work/list.tsv") rows of the 1 MiB shelf, the stored one last ($c)" || bad "/open.json with a 1 MiB list: $c"
627627 # a 60 MiB project (no size limit): stored, and largest_project_kib names the key and the volume
628628 world a16; mktar "$T/big60.tar" "random.bin=@rand:62914560" a=b; spoolup "$T/k1" "$K1" "$T/big60.tar" sixty; intake
629629 check "$(ustate "$K1")" stored "a 60 MiB project is stored"
@@ -699,7 +699,7 @@ c=$(code GET "/open/$BIGR.tar"); check "$c" 404 "GET it: 404"
699699 [ -f "$T/data/open/a/$NEARR.tar" ] && [ "$(sha "$T/data/open/a/$NEARR.tar")" = "$(cat "$T/data/open/a/$NEARR.sha256")" ] && ok "a 10 MiB download within the room is written" || bad "no download within the room"
700700 printf 'OPEN_RESERVE_STORAGE_BYTES=1\nOPEN_RESERVE_DATA_BYTES=1\n' > "$W/work/reserve"; intake
701701 z=$(stat -c %s "$T/data/open/a/$BIGR.tar" 2>/dev/null || echo 0); [ "$z" -gt 52428800 ] && [ "$(sha "$T/data/open/a/$BIGR.tar")" = "$(cat "$T/data/open/a/$BIGR.sha256")" ] && ok "with room, a download past the former 50 MiB is written ($z bytes)" || bad "no big download with room: $z"
702-code GET /open/ > /dev/null; grep -q "rad clone rad:$NEARR" "$T/body" && ! grep -q "Unfinished:" "$T/body" && ok "a shelf card with an empty note has no Unfinished label" || bad "empty Unfinished label on the shelf"
702+code GET /open/ > /dev/null; grep -q "href=\"/open/$NEARR\"" "$T/body" && ! grep -q "Unfinished:" "$T/body" && ok "a shelf card with an empty note has no Unfinished label" || bad "empty Unfinished label on the shelf"
703703 code GET "/open/$NEARR" > /dev/null; ! grep -q "Unfinished:" "$T/body" && ! grep -q "pj-dev" "$T/body" && ok "its page has no empty label and, not stored by the hub, no developer section" || bad "empty label or developer section on a fetched row's page"
704704 code GET "/open/$NEARR.json" > /dev/null; grep -q '"unfinished":""' "$T/body" && ok "the JSON keeps \"unfinished\": \"\"" || bad "JSON unfinished"
705705 # a hostile hub DID line in the snapshot is escaped

patch/READY

new file mode 100644

patch/p1decl.om

new file mode 100644
@@ -0,0 +1,482 @@
1+note patch/p1decl.om: git patch intake (docs/API.md "Git patches"). Every text and global of the slice,
2+note declared before any use. Prefixes: functions pa*, globals gp*, texts tp*.
3+note A patch is a `git format-patch --stdout BASE..HEAD` mbox with a title and a description, uploaded
4+note by the local command `interplane patch` (tools/bring) in one signed POST. The forge checks it,
5+note applies it once on BASE in a throwaway work tree and keeps the bytes under
6+note <data>patches/<owner>/<repo>/<id>/. It never writes a repository and never signs for anyone.
7+note Repositories are the bare git stores of the Interplane store this build reads,
8+note <store>projects/<name>/repo.git (store/repos.om, server/util.om fksdir); nothing here reads
9+note Radicle storage. The slice is composed only in a store-reading build (run.sh).
10+text tpsdir "patches/"
11+text tpindex "index"
12+text tptmp "patch-work/"
13+text tppw "pw"
14+text tpfmb "mbox"
15+text tpfst "statement"
16+text tpfsg "signature"
17+text tpfhd "head"
18+text tpfss "status"
19+text tpftt "title"
20+text tpfds "description"
21+text tpfme "meta"
22+text tpfdf "diff"
23+text tpnewd ".new-"
24+text tpopen "open\n"
25+text tpwm "/m"
26+text tpww "/w"
27+text tpwalt "/w/.git/objects/info/alternates"
28+text tpobj "/objects\n"
29+text tpdot "."
30+text tpdd ".."
31+note ---- routes
32+text tppats "/patches"
33+text tppulls "/pulls"
34+text tppull "/pull"
35+text tppnew "/patches/new"
36+text tpsfxp ".patch"
37+text tpsfxd ".diff"
38+text tpqpage "page"
39+note ---- form fields of POST .../patches/new
40+text tpfcsrf "csrf"
41+text tpfrepo "repo"
42+text tpfbase "base"
43+text tpfttl "title"
44+text tpfdsc "description"
45+text tpfmbx "mbox"
46+text tpfsig "sig"
47+text tpcsrfe "csrf="
48+note ---- the signed statement and the signature check
49+text tpst1 "interplane-patch 1\n"
50+text tpns "interplane-patch"
51+text tpfrom "From "
52+text tpfrom2 " Mon Sep 17 00:00:00 2001"
53+text tpdg "diff --git "
54+text tpgbp "GIT binary patch"
55+text tpbf "Binary files "
56+text tprnf "rename from "
57+text tprnt "rename to "
58+text tpcpf "copy from "
59+text tpcpt "copy to "
60+text tpmcopy "patches with copy headers are not accepted"
61+note ---- git argv words (the argv-only exec path of server/util.om: fkb, fka, fexec; no shell)
62+text tpdC "-C"
63+note the empty tree as git's attribute source: no .gitattributes a patch writes is read (git 2.43 --attr-source)
64+text tpatsrc "--attr-source=4b825dc642cb6eb9a060e54bf8d69288fbee4904"
65+text tpc "-c"
66+text tpinit "init"
67+text tpq "-q"
68+text tpqq "--quiet"
69+text tptpl "--template="
70+text tpcatf "cat-file"
71+text tpde "-e"
72+text tpcmt "^{commit}"
73+text tpgmb "merge-base"
74+text tpisa "--is-ancestor"
75+text tprh "refs/heads/"
76+text tprdt "read-tree"
77+text tpupr "update-ref"
78+text tpnod "--no-deref"
79+text tphead "HEAD"
80+text tpam "am"
81+text tpamd "--committer-date-is-author-date"
82+text tpamk "--keep-cr"
83+text tpamn "--no-verify"
84+text tpam3 "--no-3way"
85+text tprevp "rev-parse"
86+text tprevl "rev-list"
87+text tpcnt "--count"
88+text tpdots ".."
89+text tpdiff "diff"
90+text tpraw "--raw"
91+text tpnumst "--numstat"
92+text tpnorn "--no-renames"
93+text tpfull "--full-index"
94+text tpdM "-M"
95+text tpnoext "--no-ext-diff"
96+text tpnotc "--no-textconv"
97+note the configuration every git run in the throwaway work tree carries: no hooks, no maintenance,
98+note no network transport, no filter program, symbolic links written as plain files, a fixed committer
99+text tpk1 "core.hooksPath=/dev/null"
100+text tpk2 "gc.auto=0"
101+text tpk3 "maintenance.auto=false"
102+text tpk4 "protocol.allow=never"
103+text tpk5 "core.fsmonitor=false"
104+text tpk6 "core.symlinks=false"
105+text tpk7 "core.autocrlf=false"
106+text tpk8 "commit.gpgSign=false"
107+text tpk9 "user.name=interplane-forge"
108+text tpk10 "user.email=forge@interplane.io"
109+text tpk11 "filter.lfs.clean="
110+text tpk12 "filter.lfs.smudge="
111+text tpk13 "filter.lfs.process="
112+text tpk14 "filter.lfs.required=false"
113+text tpk15 "core.attributesFile=/dev/null"
114+text tpk16 "submodule.recurse=false"
115+text tpk17 "init.defaultBranch=main"
116+note ---- text answers of the upload (plain text, one reason a refusal)
117+text tpctxt "text/plain; charset=utf-8"
118+text tprefu "refused: "
119+text tpacc "accepted\n"
120+text tpexi "exists\n"
121+text tpaid "id "
122+text tpapth "path "
123+text tpm403 "sign in first: this request carries no session"
124+text tpmcsrf "missing or wrong CSRF token"
125+text tpmrate "too many writes from this address or key; wait a minute"
126+text tpmoff "writes are switched off on this forge right now"
127+text tpmform "the body is not the patch form: fields csrf, repo, base, title, description, mbox and sig, each once"
128+text tpmnorp "no such public repository"
129+text tpmrepo "the repo field does not name this repository"
130+text tpmnogs "this repository has no git store on this forge"
131+text tpmbase "base is not a commit id of 40 lowercase hex digits"
132+text tpmunk "unknown base: the repository has no such commit"
133+text tpmnotm "base is not reachable from the repository's main branch"
134+text tpmttl "the title must be 1 to 256 bytes of UTF-8 text on one line"
135+text tpmdsc "the description must be at most 60000 bytes of UTF-8 text without control bytes"
136+text tpmbig "the mbox is larger than 2097152 bytes"
137+text tpmb64 "the mbox field is not base64url without padding"
138+text tpmnfp "the mbox is not git format-patch output"
139+text tpmmany "the mbox holds more than 100 commits"
140+text tpmsigf "the sig field is not an armored SSH signature"
141+text tpmsig "the signature does not verify for this session's key and this patch"
142+text tpmbin "binary patches are not accepted"
143+text tpmpath "a patch names a path outside the repository"
144+text tpmappl "the mbox does not apply cleanly on base"
145+text tpmcnt "git applied a different number of commits than the mbox holds"
146+text tpmsub "the patch adds a submodule"
147+text tpmdbig "the combined diff of the patch is larger than 16 MiB"
148+text tpmint "the forge could not check the patch (internal error)"
149+text tpmwr "the forge could not store the patch"
150+text tplrm "PATCH-TMP a work folder under <data>patch-work/ (pw...) could not be removed\n"
151+note ---- pages
152+text tptlist "Patches"
153+text tptnew "Open a patch"
154+text tppor1 "https://interplane.io"
155+text tppor2 "https://www.aienos.com"
156+text tph1 "<div class=\"bar\"><b>"
157+text tph1a " patch</b> "
158+text tph1b " patches</b> "
159+text tph2 "<a href=\""
160+text tph2n "/patches/new\">How to open a patch</a></div>\n"
161+text tphul "<ul class=\"commits\">\n"
162+text tphule "</ul>\n"
163+text tphli "<li><a class=\"subject\" href=\""
164+text tphq "\">"
165+text tphae "</a>"
166+text tphm1 "<div class=\"meta\"><span class=\"label\">open</span> <code>"
167+text tphm2 "</code> opened "
168+text tphby " by "
169+text tphm3 " &middot; "
170+text tphc1 " commit"
171+text tphc2 " commits"
172+text tphf1 " file"
173+text tphf2 " files"
174+text tphm4 "</div></li>\n"
175+text tphnone "<p class=\"empty\">No patches yet.</p>\n"
176+text tphpg1 "<div class=\"pager\">"
177+text tphpgn "\">Newer</a>"
178+text tphpgo "\">Older</a>"
179+text tphpg2 "</div>\n"
180+text tphqp "/patches?page="
181+text tphcode "<code>"
182+text tphcodz "</code>"
183+text tphp1 "<div class=\"box commit\"><h2>"
184+text tphp2 "</h2>\n<p class=\"meta\"><span class=\"label\">open</span> <code>"
185+text tphp3 "</p>\n<p class=\"meta\">"
186+text tphp4 " bytes. Base <a href=\""
187+text tphcm "/commit/"
188+text tphp5 "</code></a>. Applied head <code>"
189+text tphp6 "</code>: the last commit this forge's own <code>git am</code> made on the base. It is in no repository; the owner applies the patch by hand.</p>\n</div>\n"
190+text tphds1 "<pre class=\"msg\">"
191+text tphpre "</pre>\n"
192+text tphap1 "<div class=\"box\"><h3>Apply it</h3>\n<pre class=\"so-cmd\">git checkout -b patch-"
193+text tphap2 "\ncurl -fsSL "
194+text tphap3 " | git am</pre>\n<p><a href=\""
195+text tphap4 "\">Raw patch (mbox)</a> &middot; <a href=\""
196+text tphap5 "\">Diff</a></p></div>\n"
197+text tphsg1 "<div class=\"box\"><h3>Signature</h3>\n<p class=\"meta\">The author's key <code>"
198+text tphsg2 "</code> signed this statement with <code>ssh-keygen -Y sign -n interplane-patch</code>; the forge checked the signature before it kept the patch. The lines are: format, repository, base, SHA-256 of the mbox, SHA-256 of the title, a line feed and the description.</p>\n<pre class=\"hit\">"
199+text tphsg3 "<pre class=\"hit\">"
200+text tphdv "</div>\n"
201+text tphdf1 "<h3>Changes</h3>\n<pre class=\"hit\">"
202+text tphdfc "<p class=\"meta\">The diff is longer than this page shows; the raw diff has all of it.</p>\n"
203+text tphn1 "<div class=\"box\"><h2>Open a patch</h2>\n<p>A patch is a set of commits you propose for this project. You send it from your own clone with the <code>interplane</code> program; your key signs it on your computer and never leaves it. The owner applies a patch by hand.</p>\n<pre class=\"so-cmd\">interplane patch "
204+text tphn2 "</pre>\n<p class=\"meta\">Run it inside a git work tree with your commits on top of this project's main branch. It shows what will be sent (base, commits, files, bytes, title) and sends only after you type yes. Limits: 100 commits, 2 MiB of <code>git format-patch</code> output, no binary patches.</p>\n</div>\n"
205+note ---- JSON (docs/API.md forge/patch-list/1 and forge/patch/1)
206+text tpjl1 "{\"schema\":\"forge/patch-list/1\",\"base\":\""
207+text tpjp1 "{\"schema\":\"forge/patch/1\",\"base\":\""
208+text tpjown "\",\"owner\":\""
209+text tpjrep "\",\"repo\":\""
210+text tpjpage "\",\"page\":"
211+text tpjper ",\"per_page\":30,\"count\":"
212+text tpjpats ",\"patches\":[\n"
213+text tpjnext "\n],\"next\":"
214+text tpjprev ",\"prev\":"
215+text tpjend "}\n"
216+text tpjid "{\"id\":\""
217+text tpjid2 "\",\"id\":\""
218+text tpjttl "\",\"title\":"
219+text tpjdsc ",\"description\":"
220+text tpjnm ",\"name\":"
221+note the keys of SPEC section 3 after title, in their order (fyk / fyk0 of server/jsonp.om)
222+text tpkst "status"
223+text tpksd "state_derived"
224+text tpkau "author"
225+text tpkdid "did"
226+text tpkim "imported"
227+text tpkbc "base_commit"
228+text tpkhc "head_commit"
229+text tpkcm "commits"
230+text tpkfl "files"
231+text tpkby "bytes"
232+text tpkcd "code"
233+text tpksha "mbox_sha256"
234+text tpkop "opened"
235+text tpkcl "closed"
236+text tpkmg "merge"
237+text tpklb "labels"
238+text tpkco "comments"
239+text tpkcr "created"
240+text tpkcc "comments_count"
241+text tpkpt "path"
242+text tpkpa "patch"
243+text tpkdf "diff"
244+text tpkbn "bundle"
245+text tpkst2 "states"
246+text tpkdm "damaged"
247+text tpkdu "diff_unavailable"
248+text tpktt "thread_truncated"
249+text tpktr "thread_reason"
250+note the values of diff_unavailable (pajduw) and of thread_reason (pajtrw; "too-large" is in both)
251+text tpun1 "no-code-file"
252+text tpun2 "no-base"
253+text tpun3 "base-not-in-store"
254+text tpun4 "too-large"
255+text tpun5 "bundle-too-large"
256+text tpun6 "diff-failed"
257+text tptr1 "malformed-record"
258+text tptr3 "document-budget"
259+text tpkfrm "from"
260+text tpkow "owner"
261+text tpkrp "repo"
262+text tpknum "number"
263+text tpkurl "url"
264+text tpklog "login"
265+text tpkknd "kind"
266+text tpkstt "state"
267+text tpkln "line"
268+text tpktim "time"
269+text tpkbdy "body"
270+text tpkcmt "commit"
271+text tpkrch "reach"
272+text tpkmn "main"
273+text tpkobs "observed"
274+text tpkmb "mbox"
275+text tpknone "none"
276+text tpgith "github"
277+text tpdash "-"
278+text tpjnull "null"
279+text tpjsep ",\n"
280+note ---- request state
281+note gpfv: one percent-decoded form field (padec), read by the field checks and patch/p2utf8.om
282+global gpfv uchar 65536
283+note gpfo / gpfn / gpfs: offset, length and presence of the seven form fields in fbig, by index:
284+note 0 csrf, 1 repo, 2 base, 3 title, 4 description, 5 mbox, 6 sig
285+global gpfo ulong 8
286+global gpfn ulong 8
287+global gpfs ulong 8
288+note gpmb: the decoded mbox (F1: at most 2 MiB)
289+global gpmb uchar 2097152
290+global gpmbl ulong 1
291+note gpttl: the title; a signed patch's is at most 256 bytes (F2), an imported item's is cut to 1024
292+global gpttl uchar 1024
293+global gpttll ulong 1
294+global gpdsc uchar 60000
295+global gpdscl ulong 1
296+global gpsig uchar 4096
297+global gpsigl ulong 1
298+global gpbase uchar 40
299+global gphead uchar 40
300+global gpid uchar 16
301+global gpst uchar 512
302+global gpstl ulong 1
303+note gpncm: commits the mbox holds; gpnfl: files the applied patch changed; gpgrd: what the scan of
304+note the mbox found (0 nothing, 2 a binary patch, 3 a path outside the repository)
305+global gpncm ulong 1
306+global gpnfl ulong 1
307+global gpgrd ulong 1
308+note gpp: path builder; gpstm: the 16 hex digits that name this request's work folder and staging
309+note folder; gpde: one batch of directory entries (the work-folder remover)
310+global gpp uchar 4096
311+global gppl ulong 1
312+global gpstm uchar 16
313+global gpde uchar 32768
314+note ---- a stored patch read back (paload): author DID, creation time, commit and file counts, mbox
315+note bytes and its SHA-256 from the meta file; title, base and head in the globals above
316+global gpmdid uchar 128
317+global gpmdidl ulong 1
318+global gpmts ulong 1
319+global gpmcm ulong 1
320+global gpmfl ulong 1
321+global gpmby ulong 1
322+global gpmsha uchar 64
323+note gpix: the index file of one list request (paixld). The page loaders read every item through fxo,
324+note so the index cannot stay there while the items of the list are counted. As large as fxo: an index
325+note of 16777216 bytes or more (986896 lines) is the whole 500 of fincut, as before
326+global gpix uchar 16777216
327+note gpids: the ids of one list page (30 rows of 16 hex digits); gpln: a small line buffer
328+global gpids uchar 480
329+global gpln uchar 256
330+global gplnl ulong 1
331+note gpcur / gpbad: read position and failure flag of the meta file parser
332+global gpcur ulong 1
333+global gpbad ulong 1
334+note ---- imported proposals (SPEC prstore/r1 extension, patch/p5imp.om); files of an item folder
335+text tpfsj "source.json"
336+text tpfgh "gh"
337+text tpfth "thread"
338+text tpflb "labels"
339+text tpfmg "merged"
340+text tpfrc "reach"
341+text tpfbn "head.bundle"
342+text tpdpd "pdiff/"
343+text tpsfxg ".big"
344+text tpsw1 "closed\n"
345+text tpsw2 "merged\n"
346+text tpsjpre "{\"kind\":\"github-import\",\"owner\":\""
347+text tpsjow "\"owner\":\""
348+text tpsjrp "\"repo\":\""
349+text tpsjurl "\"url\":\""
350+text tpsjutc "\"imported_utc\":\""
351+text tpsjnum "\"number\":"
352+text tpsjder "\"state_derived\":true"
353+text tpghn "number "
354+text tpghl "login "
355+text tpgho "opened "
356+text tpghc "closed "
357+text tpghm "merged "
358+text tprcom "comment"
359+text tprrev "review"
360+text tprrc "review-comment"
361+text tprch1 "reachable"
362+text tprch2 "not-reachable"
363+text tprch3 "unknown"
364+text tpwopn "open"
365+text tpwclo "closed"
366+text tpwmrg "merged"
367+text tpsfxb ".bundle"
368+text tpctbin "application/octet-stream"
369+text tpbund "bundle"
370+text tpunb "unbundle"
371+text tpnocol "--no-color"
372+text tpdots3 "..."
373+text tpm409 "another item of this store holds this patch id"
374+text tpmdint "the diff could not be made (internal error)\n"
375+note ---- imported proposals: HTML
376+text tputc " UTC"
377+text tpimp1 "Imported from GitHub "
378+text tpimp2 ", by "
379+text tpimp3 " (code only)"
380+text tpbok "<b class=\"ok\">"
381+text tpbbad "<b class=\"bad\">"
382+text tpbmut "<b class=\"muted\">"
383+text tpboff "</b>"
384+text tpbder " <b class=\"muted\">derived</b>"
385+text tpnotl "(untitled)"
386+text tpiwi " imported "
387+text tpiwo " opened "
388+text tpir1 "<div class=\"meta\">"
389+text tpir2 " <code>"
390+text tpsth "<span class=\"states\">"
391+text tpsto " open &middot; "
392+text tpstc " closed &middot; "
393+text tpstm " merged</span> "
394+text tpdmg1 "<span class=\"muted\">"
395+text tpdmg2 " damaged item is not shown</span> "
396+text tpdmg3 " damaged items are not shown</span> "
397+text tpip2 "</h2>\n<p class=\"meta\">"
398+text tpipn " #"
399+text tpito " &middot; opened "
400+text tpitc " &middot; closed "
401+text tpitm " &middot; merged "
402+text tpipm "<p class=\"meta\">"
403+text tpipe "</p>\n"
404+text tpider "<p class=\"meta\">GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).</p>\n"
405+text tpilab "Labels: "
406+text tpisb "Base <code>"
407+text tpisb2 "</code> &middot; "
408+text tpisnb "No base commit &middot; "
409+text tpish "Head <code>"
410+text tpimg1 "Merged on GitHub as <code>"
411+text tpimr1 "; reachable from main <code>"
412+text tpimr2 "; not reachable from main <code>"
413+text tpimr3 "; reachability from main unknown"
414+text tpimro " (observed "
415+text tpibox "<div class=\"box\"><p class=\"meta\">"
416+text tpiwr " wrote on "
417+text tpidsc "Description"
418+text tpidbig "<p class=\"meta\">The description is too large for this page.</p>\n"
419+text tpirv1 " reviewed ("
420+text tpirv2 ") on "
421+text tpirc1 " commented on <code>"
422+text tpirc2 "</code> line "
423+text tpion " on "
424+text tpitbad "<p class=\"meta\">The thread stops here: its next record is malformed.</p>\n"
425+text tpitcut "<p class=\"meta\">The thread is too long for this page; the rest is not shown.</p>\n"
426+text tpitbig "<p class=\"meta\">The thread file is larger than this forge reads; the rest is not shown.</p>\n"
427+text tpibd1 "<div class=\"box\"><h3>Fetch it</h3>\n<p class=\"meta\">A git bundle of the pull request's head, "
428+text tpibd2 " bytes.</p>\n<pre class=\"so-cmd\">curl -fsSL "
429+text tpibd3 " -o "
430+text tpibd4 "\ngit fetch "
431+text tpibd4b " refs/pull/"
432+text tpibd5 "/head</pre>\n<p><a href=\""
433+text tpibd6 "\">Raw bundle</a>"
434+text tpibd7 " &middot; <a href=\""
435+text tpibd9 "</p></div>\n"
436+text tpicn1 "<div class=\"box\"><h3>Code</h3>\n<p class=\"meta\">The head commit is on main: <a href=\""
437+text tpicn2 "</code></a>.</p></div>\n"
438+text tpipv1 "<div class=\"box\"><h3>Provenance</h3>\n<p class=\"meta\">This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:</p>\n<pre class=\"hit\">"
439+text tpich "<h3>Changes</h3>\n<p class=\"meta\">"
440+text tpicg0 "There is no diff: the head commit is already on main."
441+text tpicg7 "There is no diff: this item holds no code file."
442+text tpicx "<div class=\"box\"><h3>Code</h3>\n<p class=\"meta\">This item holds no code file.</p></div>\n"
443+text tpicg1 "There is no stored diff for this mbox."
444+text tpicg2 "There is no diff: the bundle has no base commit."
445+text tpicg3 "There is no diff: the base commit is not in this project's git store."
446+text tpicg4 "The diff is larger than 16 MiB, too large to show: fetch the bundle instead."
447+text tpicg5 "The diff could not be made (internal error)."
448+text tpicg6 "The diff is empty."
449+text tpicg8 "This bundle is larger than the display limit. Fetch the bundle to see the changes."
450+note gpimp: the loaded item is imported (1) or signed (0); gpist: its status (0 open, 1 closed, 2
451+note merged); gpider: its state is derived (code-only); gpicode: its code file (0 none, 1 mbox, 2
452+note head.bundle; its size in gpmby); gpihb: it has a base (gpbase); gpnum: its GitHub number; gpbd:
453+note the bundle diff (pabdiff's answer; 9 not asked); gpsc: the items a list page shows by state (list
454+note head); gptr: why the comments of forge/patch/1 are not the whole thread (pajcoms: 0 they are, 1 a
455+note malformed record, 2 the thread file is larger than gpth, 3 the document budget PAJMX)
456+global gpimp ulong 1
457+global gpist ulong 1
458+global gpider ulong 1
459+global gpicode ulong 1
460+global gpihb ulong 1
461+global gpnum ulong 1
462+global gpbd ulong 1
463+global gpsc ulong 3
464+global gptr ulong 1
465+note gpr: offsets and lengths of the parsers (thread record, gh line, source.json value, reach line)
466+global gpr ulong 16
467+note gpsrc: source.json (its first 4096 bytes); gpgh: the gh file (its first 2048 bytes); gpth: the
468+note thread (as much as fxo reads; gpthc 1 when the file is larger)
469+global gpsrc uchar 4096
470+global gpsrcl ulong 1
471+global gpgh uchar 2048
472+global gpghl ulong 1
473+global gpth uchar 16777216
474+global gpthl ulong 1
475+global gpthc ulong 1
476+note PAPGMX: the most an imported page's description and thread take of fob (8 MiB), so the
477+note provenance box and a 400000-byte diff (6 bytes each at most, escaped) still fit after them
478+const PAPGMX ulong 5000000
479+note PAJMX: the most forge/patch/1 takes of fob (8388608 bytes) up to the end of its comments. The
480+note 65536 bytes left hold the rest of the document: at most 24578 bytes of "created" (a source.json
481+note value of up to 4096 bytes, 6 bytes each escaped), four links of under 250 bytes and the fixed keys
482+const PAJMX ulong 8323072

patch/p2base.om

new file mode 100644
@@ -0,0 +1,522 @@
1+note patch/p2base.om: the path builder, the byte sources and SHA-256 over them, file writes, the git
2+note argument lists and the remover of a request's work folder.
3+const PATMO long 20000000000
4+note ---- path builder gpp (host words take the global directly)
5+fn papc c uchar to void
6+n = get gppl 0
7+if lt n 4095
8+put gpp n c
9+put gppl 0 add n 1
10+end
11+end
12+fn papt t view uchar * to void
13+for i ulong len t bound 4096
14+papc get t i
15+end
16+end
17+note papb: gpp = <data>
18+fn papb to void
19+put gppl 0 0
20+papt tfdata
21+end
22+note paprn: the repository's name (the public-list row fridx) appended to gpp
23+fn paprn to void
24+i = get fridx 0
25+for k ulong get fanl i bound 128
26+papc frnbyte i k
27+end
28+end
29+note paprepo: gpp = <data>patches/<owner>/<repo>/
30+fn paprepo to void
31+papb
32+papt tpsdir
33+papt tfowner
34+papc 47
35+paprn
36+papc 47
37+end
38+note papid t: gpp = <data>patches/<owner>/<repo>/<gpid>/<t>
39+fn papid t view uchar * to void
40+paprepo
41+for k ulong 16
42+papc get gpid k
43+end
44+papc 47
45+papt t
46+end
47+note papnew t: gpp = <data>patches/<owner>/<repo>/.new-<gpstm>/<t>, this request's staging folder
48+fn papnew t view uchar * to void
49+paprepo
50+papt tpnewd
51+for k ulong 16
52+papc get gpstm k
53+end
54+papc 47
55+papt t
56+end
57+note papw t: gpp = <data>patch-work/pw<gpstm><t>, this request's work folder (t is empty or starts with /)
58+fn papw t view uchar * to void
59+papb
60+papt tptmp
61+papt tppw
62+for k ulong 16
63+papc get gpstm k
64+end
65+papt t
66+end
67+note papgs: gpp = <store>projects/<name>/repo.git, the repository's bare git store, built by the
68+note store's own path builder (store/repos.om xspproj, as xsfolders does) in fpth and copied
69+fn papgs to void
70+xspproj get fridx 0
71+fpt tfsrg
72+put gppl 0 0
73+for i ulong get fpthl 0 bound 4096
74+papc get fpth i
75+end
76+end
77+note paexist: the path in gpp exists
78+fn paexist to bool
79+r = stat gpp 0 get gppl 0 fstb 0 128
80+ret ge r 0
81+end
82+note pamkdir: make the folder gpp (0700); true when it exists afterwards
83+fn pamkdir to bool
84+r = makedir gpp 0 get gppl 0 448
85+if ge r 0
86+ret true
87+end
88+ret paexist
89+end
90+note ---- byte sources. pasb w i: byte i of source w: 0 the mbox, 1 the statement, 2 the signature,
91+note 3 the title, 4 the description, 5 the line buffer, 6 fxo, 7 title + line feed + description
92+fn pasb w ulong i ulong to uchar
93+if eq w 0
94+ret get gpmb i
95+end
96+if eq w 1
97+ret get gpst i
98+end
99+if eq w 2
100+ret get gpsig i
101+end
102+if eq w 3
103+ret get gpttl i
104+end
105+if eq w 4
106+ret get gpdsc i
107+end
108+if eq w 5
109+ret get gpln i
110+end
111+if eq w 6
112+ret get fxo i
113+end
114+ret patd i
115+end
116+fn patd i ulong to uchar
117+n = get gpttll 0
118+if lt i n
119+ret get gpttl i
120+end
121+if eq i n
122+ret uchar 10
123+end
124+ret get gpdsc sub sub i n 1
125+end
126+note pahs w n o: o = SHA-256 of the first n bytes of source w
127+fn pahs w ulong n ulong o edit uchar 32 to void
128+c = new ulong 40 0
129+b = new uchar 4096 0
130+sha256_init c
131+p = ulong 0
132+while lt p n bound 16777216
133+k = hmin sub n p 4096
134+for i ulong k bound 4096
135+put b i pasb w add p i
136+end
137+sha256_update c part b 0 k
138+p = add p k
139+end
140+sha256_final c o
141+end
142+note ---- the line buffer gpln
143+fn palb to void
144+put gplnl 0 0
145+end
146+fn palc c uchar to void
147+n = get gplnl 0
148+if lt n 255
149+put gpln n c
150+put gplnl 0 add n 1
151+end
152+end
153+fn paln v ulong to void
154+d = new uchar 20 0
155+k = sodec v d
156+for i ulong k bound 20
157+palc get d i
158+end
159+end
160+note ---- files
161+note pawall: all k bytes of b to fd
162+fn pawall fd int b view uchar 4096 k ulong to bool
163+q = ulong 0
164+for it ulong 8192
165+if ge q k
166+ret true
167+end
168+r = write fd b q sub k q
169+if le r 0
170+if ne r -4
171+ret false
172+end
173+else
174+q = add q ulong r
175+end
176+end
177+ret false
178+end
179+note pawf w n: create the file gpp (exclusive, 0600, no link followed) holding the first n bytes of
180+note source w, written through to the disk before it is closed
181+fn pawf w ulong n ulong to bool
182+fd = fopen gpp 0 get gppl 0 557249 384
183+if lt fd 0
184+ret false
185+end
186+b = new uchar 4096 0
187+p = ulong 0
188+ok = true
189+while lt p n bound 16777216
190+k = hmin sub n p 4096
191+for i ulong k bound 4096
192+put b i pasb w add p i
193+end
194+if not pawall int fd b k
195+ok = false
196+break
197+end
198+p = add p k
199+end
200+if ok
201+s = fsync int fd
202+if lt s 0
203+ok = false
204+end
205+end
206+x = fclose int fd
207+ret ok
208+end
209+note pawtxt t: the file gpp holding the text t
210+fn pawtxt t view uchar * to bool
211+palb
212+for i ulong len t bound 255
213+palc get t i
214+end
215+ret pawf 5 get gplnl 0
216+end
217+note ---- git argument lists (server/util.om fkb / fka / fkopen / fkc, run by fexec: no shell, empty
218+note environment, standard input and error /dev/null)
219+fn pakp to void
220+for i ulong get gppl 0 bound 4096
221+fkc get gpp i
222+end
223+end
224+fn pakbase to void
225+for i ulong 40
226+fkc get gpbase i
227+end
228+end
229+note pakst: argv = git --git-dir=<published store>/projects/<name>/repo.git
230+fn pakst to void
231+fkb
232+fka tfgit
233+fkopen
234+fkt tfgitdir
235+papgs
236+pakp
237+end
238+fn pakc1 t view uchar * to void
239+fka tpc
240+fka t
241+end
242+note pakwt: argv = git -C <work folder>/w --attr-source=<empty tree> -c <setting> ... for every git run in
243+note the throwaway work tree. The attribute source is the empty tree, so no .gitattributes file the
244+note patch writes (nor the index's) changes what git reports or converts: binary tests, diff drivers,
245+note textconv, filters and line endings all see no attributes.
246+fn pakwt to void
247+fkb
248+fka tfgit
249+fka tpdC
250+fkopen
251+papw tpww
252+pakp
253+fka tpatsrc
254+pakc1 tpk1
255+pakc1 tpk2
256+pakc1 tpk3
257+pakc1 tpk4
258+pakc1 tpk5
259+pakc1 tpk6
260+pakc1 tpk7
261+pakc1 tpk8
262+pakc1 tpk9
263+pakc1 tpk10
264+pakc1 tpk11
265+pakc1 tpk12
266+pakc1 tpk13
267+pakc1 tpk14
268+pakc1 tpk15
269+pakc1 tpk16
270+end
271+note ---- the work folder remover. git fills <data>patch-work/pw<stem>/ with the files and folders a patch
272+note names, so nothing about their names, depth or kind is assumed. A forked child changes into the
273+note folder and removes by relative name from the inside: a file, link or other entry is unlinked, an
274+note empty folder removed, and a folder that is not empty is entered through a descriptor opened with
275+note no-follow (a link is never entered) and emptied first. No path is built, so no path length or
276+note depth limits it, and it only ever steps back up as often as it stepped down.
277+fn parmnl o ulong to ulong
278+k = ulong 0
279+while lt k 256 bound 256
280+if eq get gpde add o k 0
281+ret k
282+end
283+k = add k 1
284+end
285+ret k
286+end
287+note parmdot: the entry name at o is . or ..
288+fn parmdot o ulong nl ulong to bool
289+if eq nl 1
290+ret eq get gpde o 46
291+end
292+if eq nl 2
293+if eq get gpde o 46
294+ret eq get gpde add o 1 46
295+end
296+end
297+ret false
298+end
299+note parment: remove the entry at o (type ty, 4 a folder): 1 removed, 2 entered it, 3 cannot
300+fn parment o ulong nl ulong ty uchar to ulong
301+r = long 0
302+if ne ty 4
303+r = unlink gpde o nl
304+if ge r 0
305+ret 1
306+end
307+if ne r -21
308+ret 3
309+end
310+end
311+r = rmdir gpde o nl
312+if ge r 0
313+ret 1
314+end
315+fd = fopen gpde o nl 573440 0
316+if lt fd 0
317+ret 3
318+end
319+r = fchdir int fd
320+x = fclose int fd
321+if lt r 0
322+ret 3
323+end
324+ret 2
325+end
326+note parmscan: one pass over the folder open as fd: 0 it is empty, 1 entries were removed (scan again),
327+note 2 entered a folder, 3 an entry could not be removed
328+fn parmscan fd int to ulong
329+seen = ulong 0
330+for it ulong 1000000
331+n = getdnts fd gpde 0 32768
332+if le n 0
333+break
334+end
335+p = ulong 0
336+while lt p ulong n bound 32768
337+rl = or ulong get gpde add p 16 shl ulong get gpde add p 17 8
338+if eq rl 0
339+ret 3
340+end
341+nl = parmnl add p 19
342+if not parmdot add p 19 nl
343+seen = add seen 1
344+r = parment add p 19 nl get gpde add p 18
345+if ge r 2
346+ret r
347+end
348+end
349+p = add p rl
350+end
351+end
352+if gt seen 0
353+ret 1
354+end
355+ret 0
356+end
357+note parmch: the child: empty the current folder and everything below it, then exit 0
358+fn parmch to void
359+dep = ulong 0
360+for it ulong 4000000000
361+fd = fopen tpdot 0 1 540672 0
362+if lt fd 0
363+exit 3
364+end
365+st = parmscan int fd
366+x = fclose int fd
367+if eq st 3
368+exit 4
369+end
370+if eq st 2
371+dep = add dep 1
372+end
373+if eq st 0
374+if eq dep 0
375+exit 0
376+end
377+r = chdir tpdd 0 2
378+if lt r 0
379+exit 5
380+end
381+dep = sub dep 1
382+end
383+end
384+exit 6
385+end
386+note parmtree: remove this request's work folder and all it holds (30 s, then the child is killed)
387+fn parmtree to bool
388+papw part tpdot 0 0
389+pid = fork
390+if lt pid 0
391+ret false
392+end
393+if eq pid 0
394+r = chdir gpp 0 get gppl 0
395+if lt r 0
396+exit 2
397+end
398+parmch
399+exit 0
400+end
401+dl = add long monons 30000000000
402+st = freap int pid dl
403+papw part tpdot 0 0
404+q = rmdir gpp 0 get gppl 0
405+ret and eq st 0 ge q 0
406+end
407+note ---- small files of an item (patch/p5imp.om): read without fxo, so a caller may keep a listing there
408+note pards: the file gpp into gpln (its first 256 bytes); the bytes read (256: the file has at least
409+note that many), or -errno
410+fn pards to long
411+put gplnl 0 0
412+fd = fopen gpp 0 get gppl 0 524288 0
413+if lt fd 0
414+ret fd
415+end
416+for it ulong 64
417+n = get gplnl 0
418+if ge n 256
419+break
420+end
421+r = read int fd gpln n sub 256 n
422+if le r 0
423+break
424+end
425+put gplnl 0 add n ulong r
426+end
427+x = fclose int fd
428+ret long get gplnl 0
429+end
430+note pal40: gpln is 40 lowercase hex digits and a line feed
431+fn pal40 to bool
432+if ne get gplnl 0 41
433+ret false
434+end
435+for i ulong 40
436+if lt sohexv get gpln i 0
437+ret false
438+end
439+end
440+ret eq get gpln 40 10
441+end
442+note palnis t: gpln is exactly t
443+fn palnis t view uchar * to bool
444+if ne get gplnl 0 len t
445+ret false
446+end
447+for i ulong len t bound 256
448+if ne get gpln i get t i
449+ret false
450+end
451+end
452+ret true
453+end
454+note pastrd: the status file of item gpid: 0 "open\n", 1 "closed\n", 2 "merged\n", 9 anything else
455+fn pastrd to ulong
456+papid tpfss
457+r = pards
458+if palnis tpopen
459+ret 0
460+end
461+if palnis tpsw1
462+ret 1
463+end
464+if palnis tpsw2
465+ret 2
466+end
467+ret 9
468+end
469+note pastsz: the size of the file paexist last found (st_size of struct stat, aarch64 offset 48)
470+fn pastsz to ulong
471+v = ulong 0
472+for i ulong 8
473+v = or v shl ulong get fstb add 48 i mul i 8
474+end
475+ret v
476+end
477+note ---- the bundle diff cache: <data>pdiff/<owner>/<repo>/<id> (derived data, safe to delete)
478+note papdr: gpp = <data>pdiff/<owner>/<repo>/
479+fn papdr to void
480+papb
481+papt tpdpd
482+papt tfowner
483+papc 47
484+paprn
485+papc 47
486+end
487+note papdf: gpp = the cache file of item gpid
488+fn papdf to void
489+papdr
490+for k ulong 16
491+papc get gpid k
492+end
493+end
494+note papdfg: gpp = the marker beside it, <id>.big: an empty file that says the bundle diff of item gpid
495+note was cut at 16 MiB (patch/p5imp.om pabbig)
496+fn papdfg to void
497+papdf
498+papt tpsfxg
499+end
500+note papdfn: gpp = this request's staging file beside it, .new-<gpstm>
501+fn papdfn to void
502+papdr
503+papt tpnewd
504+for k ulong 16
505+papc get gpstm k
506+end
507+end
508+note pamkpd: make <data>pdiff/<owner>/<repo>/ (0700 each); false when it is not there afterwards
509+fn pamkpd to bool
510+papb
511+papt tpdpd
512+if not pamkdir
513+ret false
514+end
515+papt tfowner
516+if not pamkdir
517+ret false
518+end
519+papc 47
520+paprn
521+ret pamkdir
522+end

patch/p2utf8.om

new file mode 100644
@@ -0,0 +1,79 @@
1+note patch/p2utf8.om: the text rules of a title and a description (docs/collab-write.md section 2),
2+note over the decoded field gpfv. The same code as collab/co9comp.om cowutf8, coctlok and coulen under
3+note this slice's names: the store-reading build composes collab out (server/nocollab.om), so the
4+note patch intake carries its own copy and needs no collab unit.
5+note pawutf8 n ml: well-formed UTF-8 (no overlong forms, surrogates or code points over U+10FFFF), no
6+note NUL, C0 control or DEL byte except tab and LF when ml
7+fn pawutf8 n ulong ml bool to bool
8+i = ulong 0
9+while lt i n bound 70000
10+c = get gpfv i
11+if lt c 128
12+if eq pactlok c ml false
13+ret false
14+end
15+i = add i 1
16+else
17+k = paulen i n
18+if eq k 0
19+ret false
20+end
21+i = add i k
22+end
23+end
24+ret true
25+end
26+fn pactlok c uchar ml bool to bool
27+if eq c 127
28+ret false
29+end
30+if ge c 32
31+ret true
32+end
33+if and ml or eq c 9 eq c 10
34+ret true
35+end
36+ret false
37+end
38+note paulen i n: byte length of the multi-byte sequence at gpfv[i], 0 when it is malformed
39+fn paulen i ulong n ulong to ulong
40+c = get gpfv i
41+k = ulong 0
42+lo = uchar 128
43+hi = uchar 191
44+if and ge c 194 le c 223
45+k = ulong 2
46+end
47+if and ge c 224 le c 239
48+k = ulong 3
49+if eq c 224
50+lo = uchar 160
51+end
52+if eq c 237
53+hi = uchar 159
54+end
55+end
56+if and ge c 240 le c 244
57+k = ulong 4
58+if eq c 240
59+lo = uchar 144
60+end
61+if eq c 244
62+hi = uchar 143
63+end
64+end
65+if or eq k 0 gt add i k n
66+ret ulong 0
67+end
68+d = get gpfv add i 1
69+if or lt d lo gt d hi
70+ret ulong 0
71+end
72+for j ulong sub k 2 bound 2
73+d = get gpfv add add i 2 j
74+if or lt d 128 gt d 191
75+ret ulong 0
76+end
77+end
78+ret k
79+end

patch/p3gate.om

new file mode 100644
@@ -0,0 +1,401 @@
1+note patch/p3gate.om: the upload form in fbig (server/main.om freqbig), the write gate, the text
2+note answers, and the field decoders.
3+note ---- text answers (kind 1, text/plain)
4+fn patext to void
5+put fobl 0 0
6+put fkind 0 1
7+fsetct tpctxt
8+end
9+note parefu: "refused: <reason>" with status st
10+fn parefu st ulong t view uchar * to long
11+patext
12+fput tprefu
13+fput t
14+fputc 10
15+ret long st
16+end
17+note ---- the form: name=value pairs joined by &, each of the seven names once, nothing else
18+fn pafis s ulong e ulong t view uchar * to bool
19+if ne sub e s len t
20+ret false
21+end
22+for i ulong len t bound 16
23+if ne get fbig add s i get t i
24+ret false
25+end
26+end
27+ret true
28+end
29+note pafidx: the index of the field name fbig[s, e), 9 when it is none of the seven
30+fn pafidx s ulong e ulong to ulong
31+if pafis s e tpfcsrf
32+ret 0
33+end
34+if pafis s e tpfrepo
35+ret 1
36+end
37+if pafis s e tpfbase
38+ret 2
39+end
40+if pafis s e tpfttl
41+ret 3
42+end
43+if pafis s e tpfdsc
44+ret 4
45+end
46+if pafis s e tpfmbx
47+ret 5
48+end
49+if pafis s e tpfsig
50+ret 6
51+end
52+ret 9
53+end
54+note pafend s n c: the first index in [s, n) holding c or &, else n
55+fn pafend s ulong n ulong c uchar to ulong
56+j = s
57+while lt j n bound 4194304
58+b = get fbig j
59+if or eq b c eq b 38
60+ret j
61+end
62+j = add j 1
63+end
64+ret n
65+end
66+note paparse: split fbig into the fields; false for a pair without =, an unknown name or a name twice
67+fn paparse to bool
68+for k ulong 8
69+put gpfo k 0
70+put gpfn k 0
71+put gpfs k 0
72+end
73+n = get fbigl 0
74+s = ulong 0
75+for it ulong 16
76+if ge s n
77+ret true
78+end
79+e = pafend s n 61
80+if ge e n
81+ret false
82+end
83+if ne get fbig e 61
84+ret false
85+end
86+a = pafend add e 1 n 38
87+k = pafidx s e
88+if eq k 9
89+ret false
90+end
91+if ne get gpfs k 0
92+ret false
93+end
94+put gpfo k add e 1
95+put gpfn k sub a add e 1
96+put gpfs k 1
97+s = add a 1
98+end
99+ret false
100+end
101+note pafall: all seven fields are present
102+fn pafall to bool
103+for k ulong 7
104+if eq get gpfs k 0
105+ret false
106+end
107+end
108+ret true
109+end
110+note padec k cap: field k percent-decoded (+ is a space) into gpfv (65536 bytes);
111+note the length, or -1 when an escape is malformed or the value is longer than cap (cap <= 65536)
112+fn padec k ulong cap ulong to long
113+o = get gpfo k
114+n = get gpfn k
115+j = ulong 0
116+m = ulong 0
117+while lt j n bound 4194304
118+c = get fbig add o j
119+j = add j 1
120+if eq c 43
121+c = uchar 32
122+end
123+if eq c 37
124+if gt add j 2 n
125+ret -1
126+end
127+h = fhexv get fbig add o j
128+l = fhexv get fbig add add o j 1
129+if or lt h 0 lt l 0
130+ret -1
131+end
132+c = uchar add mul h 16 l
133+j = add j 2
134+end
135+if ge m cap
136+ret -1
137+end
138+put gpfv m c
139+m = add m 1
140+end
141+ret long m
142+end
143+note ---- the write gate: the gate of every forge write (social/40auth.om sowpre: CSRF token 403,
144+note store off 503, 30 writes a minute an address and a key 429), with two differences an uploading
145+note program needs: signed out is 403 here, not a redirect to the sign-in page, and every answer is
146+note one line of text. sowpre reads the token from the form body fbody, which is empty on this route
147+note (the body is in fbig), so the csrf field is handed to it there.
148+fn pacsrf to bool
149+if eq get gpfs 0 0
150+ret false
151+end
152+if ne get gpfn 0 32
153+ret false
154+end
155+o = get gpfo 0
156+for i ulong len tpcsrfe
157+put fbody i get tpcsrfe i
158+end
159+for i ulong 32
160+put fbody add len tpcsrfe i get fbig add o i
161+end
162+put fbodyl 0 add len tpcsrfe 32
163+ret true
164+end
165+fn pagate to long
166+if eq get gscur 0 0
167+ret parefu 403 tpm403
168+end
169+if not paparse
170+ret parefu 400 tpmform
171+end
172+if not pacsrf
173+ret parefu 403 tpmcsrf
174+end
175+r = sowpre
176+put fbodyl 0 0
177+if eq r 0
178+soratev get gscur 0 get gsnow 0
179+ret 0
180+end
181+if eq r 429
182+ret parefu 429 tpmrate
183+end
184+if eq r 503
185+ret parefu 503 tpmoff
186+end
187+ret parefu 403 tpmcsrf
188+end
189+note paunl: POST /<owner>/<x>/patches/new where x is not a public repository (server/route.om asks
190+note before its 404): the gate first, then 404 in text. 0 = not that request.
191+fn paunl to long
192+if ne get fmeth 0 3
193+ret 0
194+end
195+if not frsteq tppnew
196+ret 0
197+end
198+r = pagate
199+if ne r 0
200+ret r
201+end
202+ret parefu 404 tpmnorp
203+end
204+note ---- field checks (after the gate)
205+note parepok: the repo field is exactly <owner>/<name> of the request path
206+fn parepok to bool
207+n = padec 1 256
208+if lt n 0
209+ret false
210+end
211+i = get fridx 0
212+l = get fanl i
213+w = len tfowner
214+if ne ulong n add add w 1 l
215+ret false
216+end
217+for k ulong w bound 64
218+if ne get gpfv k get tfowner k
219+ret false
220+end
221+end
222+if ne get gpfv w 47
223+ret false
224+end
225+for k ulong l bound 128
226+if ne get gpfv add add w 1 k frnbyte i k
227+ret false
228+end
229+end
230+ret true
231+end
232+note pabasef: the base field is 40 lowercase hex digits; copied into gpbase
233+fn pabasef to bool
234+if ne get gpfn 2 40
235+ret false
236+end
237+o = get gpfo 2
238+for i ulong 40
239+c = get fbig add o i
240+if lt sohexv c 0
241+ret false
242+end
243+put gpbase i c
244+end
245+ret true
246+end
247+note patitle: 1..256 bytes, UTF-8, one line, no control byte (the text rules of docs/collab-write.md
248+note section 2, checked and never rewritten: the bytes are what the author's key signed)
249+fn patitle to bool
250+n = padec 3 256
251+if lt n 1
252+ret false
253+end
254+if not pawutf8 ulong n false
255+ret false
256+end
257+for i ulong ulong n bound 256
258+put gpttl i get gpfv i
259+end
260+put gpttll 0 ulong n
261+ret true
262+end
263+note padescr: 0..60000 bytes, UTF-8, tab and line feed the only control bytes
264+fn padescr to bool
265+n = padec 4 60000
266+if lt n 0
267+ret false
268+end
269+if not pawutf8 ulong n true
270+ret false
271+end
272+for i ulong ulong n bound 60000
273+put gpdsc i get gpfv i
274+end
275+put gpdscl 0 ulong n
276+ret true
277+end
278+note ---- the mbox field: base64url without padding, canonical (unused bits zero)
279+fn pab64v c uchar to long
280+if and ge c 65 le c 90
281+ret long sub c 65
282+end
283+if and ge c 97 le c 122
284+ret long sub c 71
285+end
286+if and ge c 48 le c 57
287+ret long add c 4
288+end
289+if eq c 45
290+ret 62
291+end
292+if eq c 95
293+ret 63
294+end
295+ret -1
296+end
297+note pabq p k: the k digits at fbig[p] as one number, -1 when one is not a base64url digit
298+fn pabq p ulong k ulong to long
299+v = long 0
300+for i ulong k bound 4
301+d = pab64v get fbig add p i
302+if lt d 0
303+ret -1
304+end
305+v = add mul v 64 d
306+end
307+ret v
308+end
309+note pambtail: the last 2 or 3 digits (1 or 2 bytes) at fbig[p], written at gpmb[q]; false when bad
310+fn pambtail p ulong k ulong q ulong to bool
311+v = pabq p k
312+if lt v 0
313+ret false
314+end
315+if eq k 2
316+if ne and v 15 0
317+ret false
318+end
319+put gpmb q uchar shr v 4
320+ret true
321+end
322+if ne and v 3 0
323+ret false
324+end
325+put gpmb q uchar shr v 10
326+put gpmb add q 1 uchar and shr v 2 255
327+ret true
328+end
329+note pambdec: decode the mbox field into gpmb: 0, 413 over 2 MiB, 400 not base64url
330+fn pambdec to ulong
331+o = get gpfo 5
332+n = get gpfn 5
333+put gpmbl 0 0
334+if gt n 2796203
335+ret 413
336+end
337+k = rem n 4
338+if eq k 1
339+ret 400
340+end
341+q = ulong 0
342+for t ulong div n 4 bound 1048576
343+v = pabq add o mul t 4 4
344+if lt v 0
345+ret 400
346+end
347+put gpmb q uchar shr v 16
348+put gpmb add q 1 uchar and shr v 8 255
349+put gpmb add q 2 uchar and v 255
350+q = add q 3
351+end
352+if ne k 0
353+if not pambtail add o sub n k k q
354+ret 400
355+end
356+q = add q sub k 1
357+end
358+put gpmbl 0 q
359+ret 0
360+end
361+note ---- the sig field: an armored SSH signature, at most 4000 bytes; kept with one final line feed
362+fn pasigin to bool
363+n = padec 6 4000
364+if lt n 0
365+ret false
366+end
367+s = new uchar 4096 0
368+k = ulong 0
369+for i ulong ulong n bound 4096
370+c = get gpfv i
371+if ne c 13
372+if not sosigc c
373+ret false
374+end
375+put s k c
376+k = add k 1
377+end
378+end
379+for it ulong 4096
380+if eq k 0
381+break
382+end
383+c = get s sub k 1
384+if and ne c 10 ne c 32
385+break
386+end
387+k = sub k 1
388+end
389+if lt k add len tssigb len tssige
390+ret false
391+end
392+if not soarmok part s 0 k
393+ret false
394+end
395+for i ulong k bound 4096
396+put gpsig i get s i
397+end
398+put gpsig k 10
399+put gpsigl 0 add k 1
400+ret true
401+end

patch/p4take.om

new file mode 100644
@@ -0,0 +1,1179 @@
1+note patch/p4take.om: POST /<owner>/<repo>/patches/new. The checks in order, each refusal one line
2+note of text with nothing kept: session and CSRF (pagate); the repo field and the repository's git
3+note store; base a commit reachable from the default branch the public list names; sizes and shapes
4+note of title, description, mbox and sig; the signature by the session's key over the statement; then
5+note the mbox is applied once on base in a throwaway work tree and, only if that is clean (no file is
6+note binary, by git's marks and by the bytes of the applied diff, and no submodule is added), stored.
7+note ---- the mbox scan
8+note pamln s e t: the line gpmb[s, e) starts with t
9+fn pamln s ulong e ulong t view uchar * to bool
10+if lt sub e s len t
11+ret false
12+end
13+for i ulong len t bound 64
14+if ne get gpmb add s i get t i
15+ret false
16+end
17+end
18+ret true
19+end
20+note pafrom: the line is "From <40 lowercase hex> Mon Sep 17 00:00:00 2001", format-patch's first
21+note line of every commit
22+fn pafrom s ulong e ulong to bool
23+if ne sub e s 70
24+ret false
25+end
26+if not pamln s e tpfrom
27+ret false
28+end
29+for i ulong 40
30+if lt sohexv get gpmb add add s 5 i 0
31+ret false
32+end
33+end
34+ret pamln add s 45 e tpfrom2
35+end
36+fn paeol s ulong n ulong to ulong
37+j = s
38+while lt j n bound 4194304
39+if eq get gpmb j 10
40+ret j
41+end
42+j = add j 1
43+end
44+ret n
45+end
46+note padd: gpmb[j] and gpmb[j+1] are both a dot, inside [s, e)
47+fn padd j ulong e ulong to bool
48+if ge add j 1 e
49+ret false
50+end
51+if ne get gpmb j 46
52+ret false
53+end
54+ret eq get gpmb add j 1 46
55+end
56+note pasep: the byte bounds a path segment (/, space, quote)
57+fn pasep c uchar to bool
58+ret or or eq c 47 eq c 32 eq c 34
59+end
60+note paddseg j s e: the ".." at gpmb[j] is a whole segment of the path part gpmb[s, e): the byte
61+note before it (when there is one) and the byte after it (when there is one) each bound a segment
62+fn paddseg j ulong s ulong e ulong to bool
63+if gt j s
64+if not pasep get gpmb sub j 1
65+ret false
66+end
67+end
68+if lt add j 2 e
69+ret pasep get gpmb add j 2
70+end
71+ret true
72+end
73+note paout s e: the path part gpmb[s, e) of a diff header names a way out of the repository: a ".."
74+note segment, an empty segment (//) or a leading /
75+fn paout s ulong e ulong to bool
76+if ge s e
77+ret false
78+end
79+if eq get gpmb s 47
80+ret true
81+end
82+j = s
83+while lt j e bound 4194304
84+if padd j e
85+if paddseg j s e
86+ret true
87+end
88+end
89+if eq get gpmb j 47
90+if lt add j 1 e
91+if eq get gpmb add j 1 47
92+ret true
93+end
94+end
95+end
96+j = add j 1
97+end
98+ret false
99+end
100+note padiffl: a line of a diff: 2 a binary patch, 3 a header naming a path outside, else 0
101+fn padiffl s ulong e ulong to ulong
102+if pamln s e tpgbp
103+if eq sub e s len tpgbp
104+ret 2
105+end
106+end
107+if pamln s e tpbf
108+ret 2
109+end
110+if pamln s e tprnf
111+if paout add s len tprnf e
112+ret 3
113+end
114+end
115+if pamln s e tprnt
116+if paout add s len tprnt e
117+ret 3
118+end
119+end
120+ret 0
121+end
122+note pascan: one pass over the lines of the mbox. gpncm = commits (From lines); gpgrd = 2 for a
123+note binary patch or 3 for an outside path, otherwise 0. False when the first line
124+note is not a From line: not format-patch output.
125+fn pascan to bool
126+n = get gpmbl 0
127+put gpncm 0 0
128+put gpgrd 0 0
129+s = ulong 0
130+ind = false
131+for it ulong 4194304
132+if ge s n
133+break
134+end
135+e = paeol s n
136+if pafrom s e
137+put gpncm 0 add get gpncm 0 1
138+ind = false
139+else
140+if eq s 0
141+ret false
142+end
143+g = ulong 0
144+if pamln s e tpdg
145+ind = true
146+if paout add s len tpdg e
147+g = 3
148+end
149+else
150+if ind
151+g = padiffl s e
152+end
153+end
154+if and ne g 0 eq get gpgrd 0 0
155+put gpgrd 0 g
156+end
157+end
158+s = add e 1
159+end
160+ret gt get gpncm 0 0
161+end
162+note ---- base
163+note pabasec: 0 base is a commit on the main branch; else the refusal's status with its text written
164+fn pabasec to long
165+fkgit
166+fka tpcatf
167+fka tpde
168+fkopen
169+pakbase
170+fkt tpcmt
171+r = fexec PATMO
172+if lt r 0
173+ret parefu 500 tpmint
174+end
175+if ne r 0
176+ret parefu 422 tpmunk
177+end
178+fkgit
179+fka tpgmb
180+fka tpisa
181+fkopen
182+pakbase
183+fkopen
184+fkt tprh
185+i = get fridx 0
186+o = get fabo i
187+for k ulong get fabl i bound 64
188+fkc get fabr add o k
189+end
190+r = fexec PATMO
191+if eq r 0
192+ret 0
193+end
194+if eq r 1
195+ret parefu 422 tpmnotm
196+end
197+ret parefu 500 tpmint
198+end
199+note ---- the statement and the id
200+fn pastc c uchar to void
201+n = get gpstl 0
202+if lt n 511
203+put gpst n c
204+put gpstl 0 add n 1
205+end
206+end
207+fn pasthex h view uchar 32 to void
208+x = new uchar 64 0
209+sohex h x
210+for i ulong 64
211+pastc get x i
212+end
213+pastc 10
214+end
215+note pastmt: gpst = "interplane-patch 1\n<owner>/<repo>\n<base>\n<sha256 of the mbox>\n<sha256 of
216+note title, line feed, description>\n", all hex lowercase; gpid = the first 16 hex of its SHA-256
217+fn pastmt to void
218+put gpstl 0 0
219+for i ulong len tpst1
220+pastc get tpst1 i
221+end
222+for i ulong len tfowner
223+pastc get tfowner i
224+end
225+pastc 47
226+r = get fridx 0
227+for k ulong get fanl r bound 128
228+pastc frnbyte r k
229+end
230+pastc 10
231+for i ulong 40
232+pastc get gpbase i
233+end
234+pastc 10
235+h = new uchar 32 0
236+pahs 0 get gpmbl 0 h
237+pasthex h
238+pahs 7 add add get gpttll 0 1 get gpdscl 0 h
239+pasthex h
240+pahs 1 get gpstl 0 h
241+x = new uchar 64 0
242+sohex h x
243+for i ulong 16
244+put gpid i get x i
245+end
246+end
247+note ---- the signature: ssh-keygen -Y verify -f <allowed signers> -I forge-user -n interplane-patch
248+note -s <signature> with the statement on standard input (the argv exec and temp files of the
249+note sign-in check, social/20crypt.om and 40auth.om). The one allowed signer is the session's key.
250+note paspk: the ed25519 key of the session's did:key into pk
251+fn paspk pk edit uchar 32 to bool
252+d = get gscur 0
253+o = get gsso d
254+l = get gssl d
255+w = len tsdidp
256+if or le l w gt sub l w 64
257+ret false
258+end
259+z = new uchar 64 0
260+for i ulong sub l w bound 64
261+put z i get gsstr add add o w i
262+end
263+ret sodidpk part z 0 sub l w pk
264+end
265+note pasigw: the three temp files: a allowed signers, s signature, m statement
266+fn pasigw pk view uchar 32 to bool
267+al = new uchar 128 0
268+k = sopkline pk al
269+if not sotmpw 97 part al 0 k
270+ret false
271+end
272+sg = new uchar 4096 0
273+n = get gpsigl 0
274+for i ulong n bound 4096
275+put sg i get gpsig i
276+end
277+if not sotmpw 115 part sg 0 n
278+ret false
279+end
280+m = new uchar 512 0
281+n = get gpstl 0
282+for i ulong n bound 512
283+put m i get gpst i
284+end
285+ret sotmpw 109 part m 0 n
286+end
287+fn pasigrun to long
288+sotmpp 109
289+mfd = fopen gspth 0 get gspthl 0 524288 0
290+if lt mfd 0
291+ret -500
292+end
293+soavb
294+soava tssshkg
295+soava tsY
296+soava tsverify
297+soava tsdf
298+sotmpp 97
299+soavpth
300+soava tsdI
301+soava tsprinc
302+soava tsdn
303+soava tpns
304+soava tsds
305+sotmpp 115
306+soavpth
307+r = sorunv mfd 5000
308+x = fclose int mfd
309+if eq r -2
310+ret -500
311+end
312+if eq r -1
313+ret -500
314+end
315+ret r
316+end
317+note pasigck: 0 the signature verifies; else the refusal's status with its text written
318+fn pasigck to long
319+if not sovlim
320+ret parefu 429 tpmrate
321+end
322+pk = new uchar 32 0
323+if not paspk pk
324+ret parefu 500 tpmint
325+end
326+st = new uchar 8 0
327+if not sorand st
328+ret parefu 500 tpmint
329+end
330+for i ulong 8
331+put gsstem i get st i
332+end
333+r = long -500
334+if pasigw pk
335+r = pasigrun
336+end
337+sotmprm 97
338+sotmprm 115
339+sotmprm 109
340+if eq r 0
341+ret 0
342+end
343+if lt r 0
344+ret parefu 500 tpmint
345+end
346+ret parefu 403 tpmsig
347+end
348+note ---- apply once on base in a throwaway work tree
349+note pastem: gpstm = 16 random hex digits naming this request's work and staging folders
350+fn pastem to bool
351+r = new uchar 8 0
352+if not sorand r
353+ret false
354+end
355+x = new uchar 16 0
356+sohex r x
357+for i ulong 16
358+put gpstm i get x i
359+end
360+ret true
361+end
362+note pawinit: make <data>patch-work/pw<stem>/ with an empty git repository w whose objects are borrowed from
363+note the repository's store (objects/info/alternates): the store is only read, and nothing the work
364+note folder makes is ever written into it (the intake's pawork, and the bundle diff of patch/p5imp.om)
365+fn pawinit to bool
366+papb
367+papt tptmp
368+x = pamkdir
369+papw part tpdot 0 0
370+r = makedir gpp 0 get gppl 0 448
371+if lt r 0
372+ret false
373+end
374+fkb
375+fka tfgit
376+pakc1 tpk17
377+fka tpinit
378+fka tpq
379+fka tptpl
380+fkopen
381+papw tpww
382+pakp
383+r = fexec PATMO
384+if ne r 0
385+ret false
386+end
387+palb
388+papgs
389+if gt get gppl 0 240
390+ret false
391+end
392+for i ulong get gppl 0 bound 240
393+palc get gpp i
394+end
395+for i ulong len tpobj
396+palc get tpobj i
397+end
398+papw tpwalt
399+ret pawf 5 get gplnl 0
400+end
401+note pawork: the work folder of pawinit with the mbox as m
402+fn pawork to bool
403+if not pawinit
404+ret false
405+end
406+papw tpwm
407+ret pawf 0 get gpmbl 0
408+end
409+note pasteq: the stored statement of item gpid is byte-equal to this request's gpst[0, gpstl)
410+fn pasteq to bool
411+pafp tpfst
412+n = frdall
413+if ne n long get gpstl 0
414+ret false
415+end
416+for i ulong get gpstl 0 bound 512
417+if ne get fxo i get gpst i
418+ret false
419+end
420+end
421+ret true
422+end
423+note pahex40: fxo[0, 40) is 40 lowercase hex digits followed by a line feed; copied into gphead
424+fn pahex40 to bool
425+if ne get fxol 0 41
426+ret false
427+end
428+for i ulong 40
429+c = get fxo i
430+if lt sohexv c 0
431+ret false
432+end
433+put gphead i c
434+end
435+ret eq get fxo 40 10
436+end
437+note panum: the decimal number in fxo[0, n) before its line feed, 999999999 when it is not one
438+fn panum to ulong
439+n = get fxol 0
440+if or lt n 2 gt n 10
441+ret 999999999
442+end
443+v = ulong 0
444+for i ulong sub n 1 bound 16
445+c = get fxo i
446+if not fisdig c
447+ret 999999999
448+end
449+v = add mul v 10 ulong sub c 48
450+end
451+ret v
452+end
453+note pabinat s: fxo[s, s+4) is "-\t-\t" (the caller keeps s+4 inside the output)
454+fn pabinat s ulong to bool
455+a = and eq get fxo s 45 eq get fxo add s 1 9
456+b = and eq get fxo add s 2 45 eq get fxo add s 3 9
457+ret and a b
458+end
459+note pabinns: fxo holds `git diff --numstat --no-renames`: a line starts with "-\t-\t", git's mark of
460+note a binary file. The mbox scan (padiffl) sees only the bytes as sent; git am decodes a mail body
461+note sent base64 or quoted-printable first, so only git's own view after the apply covers every way in.
462+fn pabinns to bool
463+n = get fxol 0
464+s = ulong 0
465+for it ulong 16777216
466+if ge s n
467+break
468+end
469+if le add s 4 n
470+if pabinat s
471+ret true
472+end
473+end
474+e = s
475+while lt e n bound 16777216
476+if eq get fxo e 10
477+break
478+end
479+e = add e 1
480+end
481+s = add e 1
482+end
483+ret false
484+end
485+note pafxln s e t: the line fxo[s, e) starts with t
486+fn pafxln s ulong e ulong t view uchar * to bool
487+if lt sub e s len t
488+ret false
489+end
490+for i ulong len t bound 64
491+if ne get fxo add s i get t i
492+ret false
493+end
494+end
495+ret true
496+end
497+note Read the same normalized diff as Git, before applying any of the mail messages.
498+text tpmspl "mailsplit"
499+text tpmio "mailinfo"
500+text tpmd "/mails"
501+text tpmslash "/mails/"
502+text tpmsg "/mails/message"
503+text tpmpt "/mails/patch"
504+text tpmo "-o"
505+text tpmdig "-d4"
506+fn pamaid num ulong to void
507+papw tpmslash
508+d = ulong 1000
509+for i ulong 4
510+papc uchar add rem div num d 10 48
511+d = div d 10
512+end
513+end
514+fn pafxcpy to bool
515+n = get fxol 0
516+s = ulong 0
517+header = false
518+while lt s n bound 16777216
519+e = s
520+while lt e n bound 16777216
521+if eq get fxo e 10
522+break
523+end
524+e = add e 1
525+end
526+if pafxln s e tpdg
527+header = true
528+end
529+if and header or pafxln s e tpcpf pafxln s e tpcpt
530+ret true
531+end
532+s = add e 1
533+end
534+ret false
535+end
536+fn pamread idx ulong tmo long to long
537+pamaid idx
538+fd = fopen gpp 0 get gppl 0 524288 0
539+if lt fd 0
540+ret 500
541+end
542+pakwt
543+fka tpmio
544+fkopen
545+papw tpmsg
546+pakp
547+fkopen
548+papw tpmpt
549+pakp
550+r = fexecin tmo int fd
551+x = fclose int fd
552+if ne r 0
553+ret 422
554+end
555+papw tpmpt
556+fpb
557+for i ulong get gppl 0 bound 4096
558+fpc get gpp i
559+end
560+r = frdall
561+if or lt r 0 ne get fxotr 0 0
562+ret 422
563+end
564+put fxol 0 ulong r
565+if pafxcpy
566+ret 409
567+end
568+ret 0
569+end
570+fn pamail to long
571+papw tpmd
572+if not pamkdir
573+ret parefu 500 tpmint
574+end
575+dl = add long monons PATMO
576+pakwt
577+fka tpmspl
578+fka tpmdig
579+fkopen
580+fkt tpmo
581+papw tpmd
582+pakp
583+fkopen
584+papw tpwm
585+pakp
586+r = fexec PATMO
587+if or ne r 0 ne get fxotr 0 0
588+ret parefu 422 tpmappl
589+end
590+n = panum
591+if or ne n get gpncm 0 gt n 100
592+ret parefu 422 tpmcnt
593+end
594+for i ulong n bound 100
595+left = sub dl long monons
596+if le left 0
597+ret parefu 422 tpmappl
598+end
599+r = pamread add i 1 left
600+if eq r 409
601+ret parefu 422 tpmcopy
602+end
603+if ne r 0
604+ret parefu 422 tpmappl
605+end
606+end
607+ret 0
608+end
609+note pabinfx: the bytes of the full diff fxo[0, fxol) (paapply3's last git run) hold a NUL byte, a line
610+note that is exactly "GIT binary patch" or a line that starts "Binary files ". Every line of a diff's
611+note body starts with a space, + or -, so those two at column 0 are git's own markers. The bytes decide:
612+note git's own binary test reads only a file's first 8000 bytes (pabinns cannot see a later NUL).
613+fn pabinfx to bool
614+n = get fxol 0
615+s = ulong 0
616+for it ulong 16777216
617+if ge s n
618+break
619+end
620+e = s
621+while lt e n bound 16777216
622+c = get fxo e
623+if eq c 0
624+ret true
625+end
626+if eq c 10
627+break
628+end
629+e = add e 1
630+end
631+if pafxln s e tpbf
632+ret true
633+end
634+if eq sub e s len tpgbp
635+if pafxln s e tpgbp
636+ret true
637+end
638+end
639+s = add e 1
640+end
641+ret false
642+end
643+note paraw: fxo holds `git diff --raw --no-renames`: gpnfl = its lines (files changed); false when a
644+note line's new mode is 160000 (a submodule) or a line is not a raw line
645+fn paraw to bool
646+n = get fxol 0
647+c = ulong 0
648+s = ulong 0
649+for it ulong 16777216
650+if ge s n
651+break
652+end
653+if gt add s 14 n
654+ret false
655+end
656+if ne get fxo s 58
657+ret false
658+end
659+if pasubm add s 8
660+ret false
661+end
662+c = add c 1
663+e = s
664+while lt e n bound 16777216
665+if eq get fxo e 10
666+break
667+end
668+e = add e 1
669+end
670+s = add e 1
671+end
672+put gpnfl 0 c
673+ret true
674+end
675+note pasubm: fxo[p, p+6) is the mode 160000
676+fn pasubm p ulong to bool
677+if ne get fxo p 49
678+ret false
679+end
680+if ne get fxo add p 1 54
681+ret false
682+end
683+for i ulong 4
684+if ne get fxo add add p 2 i 48
685+ret false
686+end
687+end
688+ret true
689+end
690+note pakrange: one argument "<base>..HEAD"
691+fn pakrange to void
692+fkopen
693+pakbase
694+fkt tpdots
695+fkt tphead
696+end
697+note paapply2: the git runs in the work tree: read-tree base, HEAD at base, am, then head, commit
698+note count, raw diff (files, submodules), numstat (binary files) and the full diff left in fxo, whose
699+note bytes are checked too (pabinfx). 0, or the refusal's status.
700+fn paapply2 to long
701+pakwt
702+fka tprdt
703+fkopen
704+pakbase
705+r = fexec PATMO
706+if ne r 0
707+ret parefu 500 tpmint
708+end
709+pakwt
710+fka tpupr
711+fka tpnod
712+fka tphead
713+fkopen
714+pakbase
715+r = fexec PATMO
716+if ne r 0
717+ret parefu 500 tpmint
718+end
719+pakwt
720+fka tpam
721+fka tpqq
722+fka tpamd
723+fka tpamk
724+fka tpamn
725+fka tpam3
726+fkopen
727+papw tpwm
728+pakp
729+r = fexec PATMO
730+if ne r 0
731+ret parefu 422 tpmappl
732+end
733+pakwt
734+fka tprevp
735+fka tphead
736+r = fexec PATMO
737+if ne r 0
738+ret parefu 500 tpmint
739+end
740+if not pahex40
741+ret parefu 500 tpmint
742+end
743+pakwt
744+fka tprevl
745+fka tpcnt
746+pakrange
747+r = fexec PATMO
748+if ne r 0
749+ret parefu 500 tpmint
750+end
751+if ne panum get gpncm 0
752+ret parefu 422 tpmcnt
753+end
754+ret paapply3
755+end
756+fn paapply3 to long
757+pakwt
758+fka tpdiff
759+fka tpnoext
760+fka tpnotc
761+fka tpraw
762+fka tpnorn
763+fkopen
764+pakbase
765+fka tphead
766+r = fexec PATMO
767+if or ne r 0 ne get fxotr 0 0
768+ret parefu 500 tpmint
769+end
770+if not paraw
771+ret parefu 422 tpmsub
772+end
773+pakwt
774+fka tpdiff
775+fka tpnoext
776+fka tpnotc
777+fka tpnumst
778+fka tpnorn
779+fkopen
780+pakbase
781+fka tphead
782+r = fexec PATMO
783+if or ne r 0 ne get fxotr 0 0
784+ret parefu 500 tpmint
785+end
786+if pabinns
787+ret parefu 422 tpmbin
788+end
789+pakwt
790+fka tpdiff
791+fka tpnoext
792+fka tpnotc
793+fka tpfull
794+fka tpdM
795+fkopen
796+pakbase
797+fka tphead
798+r = fexec PATMO
799+if ne r 0
800+ret parefu 500 tpmint
801+end
802+if ne get fxotr 0 0
803+ret parefu 413 tpmdbig
804+end
805+if pabinfx
806+ret parefu 422 tpmbin
807+end
808+ret 0
809+end
810+note ---- the store: <data>patches/<owner>/<repo>/<id>/ with mbox, statement, signature, head,
811+note status, title, description, meta and diff. Written into a staging folder beside it and renamed
812+note into place, so an id folder is always whole and is never written again; the repository's index
813+note file gets one line "<id>\n" per patch, appended.
814+fn pamkst to bool
815+papb
816+papt tpsdir
817+if not pamkdir
818+ret false
819+end
820+papt tfowner
821+if not pamkdir
822+ret false
823+end
824+papc 47
825+paprn
826+if not pamkdir
827+ret false
828+end
829+papnew part tpdot 0 0
830+r = makedir gpp 0 get gppl 0 448
831+ret ge r 0
832+end
833+note pameta: the meta file's six lines: author DID, creation time (s), commits, files, mbox bytes,
834+note mbox SHA-256 (the statement's fourth line)
835+fn pameta to bool
836+palb
837+d = get gscur 0
838+o = get gsso d
839+for i ulong get gssl d bound 128
840+palc get gsstr add o i
841+end
842+palc 10
843+paln get gsnow 0
844+palc 10
845+paln get gpncm 0
846+palc 10
847+paln get gpnfl 0
848+palc 10
849+paln get gpmbl 0
850+palc 10
851+n = get gpstl 0
852+for i ulong 64
853+palc get gpst add sub n 130 i
854+end
855+palc 10
856+papnew tpfme
857+ret pawf 5 get gplnl 0
858+end
859+note pahdln: gpln = the head commit and a line feed
860+fn pahdln to void
861+palb
862+for i ulong 40
863+palc get gphead i
864+end
865+palc 10
866+end
867+note pawall9: the nine files into the staging folder; the diff is fxo[0, fxol) (paapply3 left it)
868+fn pawall9 to bool
869+papnew tpfdf
870+if not pawf 6 get fxol 0
871+ret false
872+end
873+papnew tpfmb
874+if not pawf 0 get gpmbl 0
875+ret false
876+end
877+papnew tpfst
878+if not pawf 1 get gpstl 0
879+ret false
880+end
881+papnew tpfsg
882+if not pawf 2 get gpsigl 0
883+ret false
884+end
885+papnew tpftt
886+if not pawf 3 get gpttll 0
887+ret false
888+end
889+papnew tpfds
890+if not pawf 4 get gpdscl 0
891+ret false
892+end
893+if not pameta
894+ret false
895+end
896+pahdln
897+papnew tpfhd
898+if not pawf 5 get gplnl 0
899+ret false
900+end
901+papnew tpfss
902+ret pawtxt tpopen
903+end
904+note padrop: remove the staging folder and the files it may hold
905+fn padrop1 t view uchar * to void
906+papnew t
907+x = unlink gpp 0 get gppl 0
908+end
909+fn padrop to void
910+padrop1 tpfdf
911+padrop1 tpfmb
912+padrop1 tpfst
913+padrop1 tpfsg
914+padrop1 tpftt
915+padrop1 tpfds
916+padrop1 tpfme
917+padrop1 tpfhd
918+padrop1 tpfss
919+papnew part tpdot 0 0
920+x = rmdir gpp 0 get gppl 0
921+end
922+note paidxhas: the index (read into fxo) lists gpid
923+fn paidxhas to bool
924+paprepo
925+papt tpindex
926+fpb
927+for i ulong get gppl 0 bound 4096
928+fpc get gpp i
929+end
930+n = frdall
931+if lt n 17
932+ret false
933+end
934+for r ulong div ulong n 17 bound 1048576
935+if paidxeq mul r 17
936+ret true
937+end
938+end
939+ret false
940+end
941+fn paidxeq o ulong to bool
942+for i ulong 16
943+if ne get fxo add o i get gpid i
944+ret false
945+end
946+end
947+ret true
948+end
949+note paidxadd: append "<id>\n" to the index (created 0600), written through
950+fn paidxadd to bool
951+paprepo
952+papt tpindex
953+fd = fopen gpp 0 get gppl 0 558145 384
954+if lt fd 0
955+ret false
956+end
957+b = new uchar 4096 0
958+for i ulong 16
959+put b i get gpid i
960+end
961+put b 16 10
962+ok = pawall int fd b 17
963+s = fsync int fd
964+x = fclose int fd
965+ret and ok ge s 0
966+end
967+note pakeep: staging folder -> <id>/ (rename), then the index line. false when nothing was kept.
968+fn pakeep to bool
969+if not pamkst
970+ret false
971+end
972+if not pawall9
973+padrop
974+ret false
975+end
976+soavb
977+papnew part tpdot 0 0
978+paavp
979+papid part tpdot 0 0
980+paavp
981+r = renames gspk 0 get gspkl 0 1
982+if lt r 0
983+padrop
984+ret false
985+end
986+ret paidxadd
987+end
988+note paavp: one record of the packed list gspk (social/20crypt.om) holding gpp without a final /
989+fn paavp to void
990+soavopen
991+n = get gppl 0
992+if gt n 0
993+if eq get gpp sub n 1 47
994+n = sub n 1
995+end
996+end
997+for i ulong n bound 4096
998+soavc get gpp i
999+end
1000+end
1001+note paok st w: the text answer of a kept (201, "accepted") or already known (200, "exists") patch:
1002+note its id and the path of its page
1003+fn paok st ulong w view uchar * to long
1004+patext
1005+fput w
1006+fput tpaid
1007+for i ulong 16
1008+fputc get gpid i
1009+end
1010+fputc 10
1011+fput tpapth
1012+fputrl
1013+fput tppats
1014+fputc 47
1015+for i ulong 16
1016+fputc get gpid i
1017+end
1018+fputc 10
1019+ret long st
1020+end
1021+note paapply: work folder, the git runs, the store; the work folder is removed whatever happened
1022+text tpfsbin "/usr/bin/stat"
1023+text tpfstype "-f"
1024+text tpfsfmt "--format=%a %S"
1025+text tpnosp "patch storage is temporarily unavailable"
1026+const PAPRES ulong 1073741824
1027+note Keep a reserve for the rest of the forge. Compare blocks without multiplying arbitrary values.
1028+fn pafree to bool
1029+fkb
1030+fka tpfsbin
1031+fka tpfstype
1032+fka tpfsfmt
1033+fka tfdata
1034+r = fexec 1000000000
1035+if or ne r 0 ne get fxotr 0 0
1036+ret false
1037+end
1038+n = get fxol 0
1039+a = ulong 0
1040+size = ulong 0
1041+p = ulong 0
1042+for i ulong n bound 48
1043+c = get fxo i
1044+if eq c 32
1045+p = add i 1
1046+break
1047+end
1048+if or ge i 18 not fisdig c
1049+ret false
1050+end
1051+a = add mul a 10 ulong sub c 48
1052+end
1053+if or le p 1 ge p n
1054+ret false
1055+end
1056+for i ulong sub n p bound 48
1057+c = get fxo add p i
1058+if eq c 10
1059+break
1060+end
1061+if or ge i 18 not fisdig c
1062+ret false
1063+end
1064+size = add mul size 10 ulong sub c 48
1065+end
1066+if eq size 0
1067+ret false
1068+end
1069+ret gt a div PAPRES size
1070+end
1071+fn paapply to long
1072+if not pafree
1073+ret parefu 503 tpnosp
1074+end
1075+if not pastem
1076+ret parefu 500 tpmint
1077+end
1078+r = long 0
1079+if pawork
1080+r = pamail
1081+if eq r 0
1082+r = paapply2
1083+end
1084+else
1085+r = parefu 500 tpmint
1086+end
1087+kept = false
1088+if eq r 0
1089+kept = pakeep
1090+end
1091+if not parmtree
1092+flog tplrm
1093+end
1094+if ne r 0
1095+ret r
1096+end
1097+if not kept
1098+ret parefu 503 tpmwr
1099+end
1100+ret paok 201 tpacc
1101+end
1102+note pasizes: title, description, mbox and sig, each to its own global; 0 or the refusal
1103+fn pasizes to long
1104+if not patitle
1105+ret parefu 400 tpmttl
1106+end
1107+if not padescr
1108+ret parefu 400 tpmdsc
1109+end
1110+r = pambdec
1111+if eq r 413
1112+ret parefu 413 tpmbig
1113+end
1114+if ne r 0
1115+ret parefu 400 tpmb64
1116+end
1117+if not pascan
1118+ret parefu 400 tpmnfp
1119+end
1120+if gt get gpncm 0 100
1121+ret parefu 413 tpmmany
1122+end
1123+if not pasigin
1124+ret parefu 400 tpmsigf
1125+end
1126+ret 0
1127+end
1128+note patake: POST /<owner>/<repo>/patches/new
1129+fn patake to long
1130+r = pagate
1131+if ne r 0
1132+ret r
1133+end
1134+if not pafall
1135+ret parefu 400 tpmform
1136+end
1137+if not parepok
1138+ret parefu 400 tpmrepo
1139+end
1140+papgs
1141+if not paexist
1142+ret parefu 404 tpmnogs
1143+end
1144+if not pabasef
1145+ret parefu 400 tpmbase
1146+end
1147+r = pabasec
1148+if ne r 0
1149+ret r
1150+end
1151+r = pasizes
1152+if ne r 0
1153+ret r
1154+end
1155+pastmt
1156+r = pasigck
1157+if ne r 0
1158+ret r
1159+end
1160+papid part tpdot 0 0
1161+if paexist
1162+if not pasteq
1163+ret parefu 409 tpm409
1164+end
1165+if not paidxhas
1166+if not paidxadd
1167+ret parefu 503 tpmwr
1168+end
1169+end
1170+ret paok 200 tpexi
1171+end
1172+if eq get gpgrd 0 2
1173+ret parefu 422 tpmbin
1174+end
1175+if eq get gpgrd 0 3
1176+ret parefu 422 tpmpath
1177+end
1178+ret paapply
1179+end

patch/p5imp.om

new file mode 100644
@@ -0,0 +1,1281 @@
1+note patch/p5imp.om: imported proposals (SPEC prstore/r1 extension, written only by tools/ghimport):
2+note reading an imported item back, its list row and page, and the diff of a bundle-backed item.
3+note Every imported byte goes out through fescc (HTML) or fjtc (JSON); a GitHub login is text. Each
4+note reader checks a length against its buffer before it reads, so a malformed or oversized file
5+note ends in "not an item", a cut value or a sentence on the page, never in a trap.
6+note ---- loading
7+note pafrd t cap: the file <t> of item gpid into fxo; its length cut to cap, 0 when it cannot be read
8+fn pafrd t view uchar * cap ulong to ulong
9+pafp t
10+n = frdall
11+if lt n 0
12+ret 0
13+end
14+ret hmin ulong n cap
15+end
16+note pasjat s t: gpsrc holds t at s (the caller keeps s + len t inside gpsrc)
17+fn pasjat s ulong t view uchar * to bool
18+for i ulong len t bound 64
19+if ne get gpsrc add s i get t i
20+ret false
21+end
22+end
23+ret true
24+end
25+note pasjf t: the offset in gpsrc of the first t, the length of gpsrc when it is not there
26+fn pasjf t view uchar * to ulong
27+n = get gpsrcl 0
28+k = len t
29+if gt k n
30+ret n
31+end
32+for s ulong add sub n k 1 bound 4097
33+if pasjat s t
34+ret s
35+end
36+end
37+ret n
38+end
39+note pasjv t: the string value after the key text t in gpsrc: its offset; its length in gpr 15, and gpr
40+note 14 is 1 when the key is there (0 and length 0 when it is not). The value ends at its closing
41+note quote; a backslash ends it too (the value is cut there, never decoded), and so does the end of
42+note the buffer
43+fn pasjv t view uchar * to ulong
44+n = get gpsrcl 0
45+s = pasjf t
46+put gpr 15 0
47+put gpr 14 0
48+if ge s n
49+ret 0
50+end
51+put gpr 14 1
52+p = add s len t
53+q = p
54+while lt q n bound 4097
55+c = get gpsrc q
56+if or eq c 34 eq c 92
57+break
58+end
59+q = add q 1
60+end
61+put gpr 15 sub q p
62+ret p
63+end
64+note pasjnum: the number of source.json ("number":N, 1..18 digits), 0 when it has none
65+fn pasjnum to ulong
66+n = get gpsrcl 0
67+s = pasjf tpsjnum
68+if ge s n
69+ret 0
70+end
71+p = add s len tpsjnum
72+v = ulong 0
73+k = ulong 0
74+while lt p n bound 19
75+c = get gpsrc p
76+if not fisdig c
77+break
78+end
79+if ge k 18
80+ret 0
81+end
82+v = add mul v 10 ulong sub c 48
83+k = add k 1
84+p = add p 1
85+end
86+ret v
87+end
88+note paghat s e t: the gh line gpgh[s, e) starts with t
89+fn paghat s ulong e ulong t view uchar * to bool
90+if lt sub e s len t
91+ret false
92+end
93+for i ulong len t bound 16
94+if ne get gpgh add s i get t i
95+ret false
96+end
97+end
98+ret true
99+end
100+note paghv t: the value of the gh line "<t><value>\n" in gpgh: its offset; its length in gpr 15 (0
101+note when there is no such whole line)
102+fn paghv t view uchar * to ulong
103+n = get gpghl 0
104+s = ulong 0
105+for i ulong n bound 2048
106+if eq get gpgh i 10
107+if paghat s i t
108+put gpr 15 sub sub i s len t
109+ret add s len t
110+end
111+s = add i 1
112+end
113+end
114+put gpr 15 0
115+ret 0
116+end
117+note paghnum: the GitHub number of the gh file ("number N", 1..18 digits), 0 when it has none
118+fn paghnum to ulong
119+o = paghv tpghn
120+k = get gpr 15
121+if or eq k 0 gt k 18
122+ret 0
123+end
124+v = ulong 0
125+for i ulong k bound 18
126+c = get gpgh add o i
127+if not fisdig c
128+ret 0
129+end
130+v = add mul v 10 ulong sub c 48
131+end
132+ret v
133+end
134+note paiload2: the optional files of the imported item: title (cut to 1024 bytes), base (40 hex and
135+note a line feed, else the item has no base), gh (cut to 2048 bytes), and the code file: mbox, else
136+note head.bundle, else none (its size in gpmby)
137+fn paiload2 to bool
138+n = pafrd tpftt 1024
139+for i ulong n bound 1024
140+put gpttl i get fxo i
141+end
142+put gpttll 0 n
143+put gpihb 0 0
144+papid tpfbase
145+r = pards
146+if pal40
147+put gpihb 0 1
148+for i ulong 40
149+put gpbase i get gpln i
150+end
151+end
152+n = pafrd tpfgh 2048
153+for i ulong n bound 2048
154+put gpgh i get fxo i
155+end
156+put gpghl 0 n
157+put gpnum 0 paghnum
158+if eq get gpnum 0 0
159+put gpnum 0 pasjnum
160+end
161+put gpicode 0 0
162+put gpmby 0 0
163+papid tpfbn
164+e = paexist
165+if e
166+put gpicode 0 2
167+put gpmby 0 pastsz
168+end
169+papid tpfmb
170+e = paexist
171+if e
172+put gpicode 0 1
173+put gpmby 0 pastsz
174+end
175+put gpmcm 0 0
176+put gpmfl 0 0
177+put gpmdidl 0 0
178+put gpmts 0 0
179+ret true
180+end
181+note paiload: the imported item gpid into the globals (SPEC section 1): false unless source.json
182+note starts with the import prefix, status is one of the three words and head is 40 hex and a line
183+note feed. source.json is kept up to 4096 bytes.
184+fn paiload to bool
185+put gpimp 0 1
186+n = pafrd tpfsj 4096
187+if lt n len tpsjpre
188+ret false
189+end
190+for i ulong len tpsjpre bound 64
191+if ne get fxo i get tpsjpre i
192+ret false
193+end
194+end
195+for i ulong n bound 4096
196+put gpsrc i get fxo i
197+end
198+put gpsrcl 0 n
199+put gpider 0 0
200+if lt pasjf tpsjder n
201+put gpider 0 1
202+end
203+s = pastrd
204+if gt s 2
205+ret false
206+end
207+put gpist 0 s
208+papid tpfhd
209+r = pards
210+if not pal40
211+ret false
212+end
213+for i ulong 40
214+put gphead i get gpln i
215+end
216+ret paiload2
217+end
218+note ---- the thread: records "comment <time> <login> <len>\n<body>\n", "review <time> <login>
219+note <STATE|-> <len>\n<body>\n" and "review-comment <time> <login> <line> <pathlen> <len>\n<path>\n
220+note <body>\n" (time: 20 bytes, or "-")
221+note pathld: the thread file of item gpid into gpth; gpthc is set when the file is larger than gpth
222+fn pathld to void
223+put gpthl 0 0
224+put gpthc 0 0
225+pafp tpfth
226+n = frdall
227+if le n 0
228+ret
229+end
230+if ne get fxotr 0 0
231+put gpthc 0 1
232+end
233+for i ulong ulong n bound 16777216
234+put gpth i get fxo i
235+end
236+put gpthl 0 ulong n
237+end
238+note patword a: the word at gpcur (1..256 bytes above 32) up to its space: offset in gpr a, length in
239+note gpr a+1; gpcur moves past the space. gpbad is set (length 0) when it is not such a word; with
240+note gpbad set nothing is read. At most 257 passes: the pass that sees 256 bytes returns.
241+fn patword a ulong to void
242+put gpr add a 1 0
243+if ne get gpbad 0 0
244+ret
245+end
246+p = get gpcur 0
247+n = get gpthl 0
248+q = p
249+while lt q n bound 257
250+if le get gpth q 32
251+break
252+end
253+if ge sub q p 256
254+put gpbad 0 1
255+ret
256+end
257+q = add q 1
258+end
259+if or ge q n eq q p
260+put gpbad 0 1
261+ret
262+end
263+if ne get gpth q 32
264+put gpbad 0 1
265+ret
266+end
267+put gpr a p
268+put gpr add a 1 sub q p
269+put gpcur 0 add q 1
270+end
271+note patnum t: the decimal at gpcur (1..18 digits) ended by the byte t; gpcur moves past t. gpbad is
272+note set when it is not one. At most 19 passes: the pass that sees an 19th digit returns.
273+fn patnum t uchar to ulong
274+if ne get gpbad 0 0
275+ret 0
276+end
277+p = get gpcur 0
278+n = get gpthl 0
279+v = ulong 0
280+k = ulong 0
281+while lt p n bound 19
282+c = get gpth p
283+if not fisdig c
284+break
285+end
286+if ge k 18
287+put gpbad 0 1
288+ret 0
289+end
290+v = add mul v 10 ulong sub c 48
291+k = add k 1
292+p = add p 1
293+end
294+if or eq k 0 ge p n
295+put gpbad 0 1
296+ret 0
297+end
298+if ne get gpth p t
299+put gpbad 0 1
300+ret 0
301+end
302+put gpcur 0 add p 1
303+ret v
304+end
305+note patis a t: the word of gpr a, a+1 is t
306+fn patis a ulong t view uchar * to bool
307+if ne get gpr add a 1 len t
308+ret false
309+end
310+o = get gpr a
311+for i ulong len t bound 16
312+if ne get gpth add o i get t i
313+ret false
314+end
315+end
316+ret true
317+end
318+note patkind: the record kind of the word in gpr 12, 13: 1 comment, 2 review, 3 review-comment, else 0
319+fn patkind to ulong
320+if patis 12 tprcom
321+ret 1
322+end
323+if patis 12 tprrev
324+ret 2
325+end
326+if patis 12 tprrc
327+ret 3
328+end
329+ret 0
330+end
331+note pattok: the time word (gpr 1, 2) is 20 bytes or "-"
332+fn pattok to bool
333+k = get gpr 2
334+if eq k 20
335+ret true
336+end
337+if ne k 1
338+ret false
339+end
340+ret eq get gpth get gpr 1 45
341+end
342+note patrec p: parse the record at p into gpr (0 kind, 1-2 time, 3-4 login, 5-6 state, 7 line, 8-9
343+note path, 10-11 body); the index after it. A malformed record leaves kind 0 and returns the thread's
344+note length, which stops the caller: every length is checked against the thread before the bytes it
345+note names are read (a path is at most 4096 bytes).
346+fn patrec p ulong to ulong
347+n = get gpthl 0
348+put gpr 0 0
349+put gpr 6 0
350+put gpr 7 0
351+put gpr 9 0
352+put gpbad 0 0
353+put gpcur 0 p
354+patword 12
355+k = patkind
356+if eq k 0
357+ret n
358+end
359+patword 1
360+patword 3
361+if eq k 2
362+patword 5
363+end
364+if eq k 3
365+put gpr 7 patnum 32
366+put gpr 9 patnum 32
367+end
368+b = patnum 10
369+if ne get gpbad 0 0
370+ret n
371+end
372+if not pattok
373+ret n
374+end
375+q = get gpcur 0
376+if eq k 3
377+m = get gpr 9
378+if or gt m 4096 ge add q m n
379+ret n
380+end
381+if ne get gpth add q m 10
382+ret n
383+end
384+put gpr 8 q
385+q = add add q m 1
386+end
387+if ge add q b n
388+ret n
389+end
390+if ne get gpth add q b 10
391+ret n
392+end
393+put gpr 10 q
394+put gpr 11 b
395+put gpr 0 k
396+ret add add q b 1
397+end
398+note patcnt: the records of the loaded thread up to its end or its first malformed record. A record
399+note is at least 15 bytes, so the passes stay far under the bound.
400+fn patcnt to ulong
401+p = ulong 0
402+c = ulong 0
403+n = get gpthl 0
404+while lt p n bound 16777216
405+p = patrec p
406+if ne get gpr 0 0
407+c = add c 1
408+end
409+end
410+ret c
411+end
412+note ---- pieces of the HTML pages
413+note patraw a: gpth[gpr a, + gpr a+1), HTML-escaped
414+fn patraw a ulong to void
415+o = get gpr a
416+for i ulong get gpr add a 1 bound 16777216
417+fescc get gpth add o i
418+end
419+end
420+note pattime: the record's time as YYYY-MM-DD HH:MM UTC, escaped ("-" when it has none)
421+fn pattime to void
422+if ne get gpr 2 20
423+fputc 45
424+ret
425+end
426+o = get gpr 1
427+for i ulong 10
428+fescc get gpth add o i
429+end
430+fputc 32
431+for i ulong 5
432+fescc get gpth add add o 11 i
433+end
434+fput tputc
435+end
436+note paghhas t: the gh file has a 20-byte time under t
437+fn paghhas t view uchar * to bool
438+o = paghv t
439+ret eq get gpr 15 20
440+end
441+note paghtm t: the gh time under t as YYYY-MM-DD HH:MM UTC, escaped ("-" when it is not 20 bytes)
442+fn paghtm t view uchar * to void
443+o = paghv t
444+if ne get gpr 15 20
445+fputc 45
446+ret
447+end
448+for i ulong 10
449+fescc get gpgh add o i
450+end
451+fputc 32
452+for i ulong 5
453+fescc get gpgh add add o 11 i
454+end
455+fput tputc
456+end
457+note paghp t: the gh value under t, HTML-escaped
458+fn paghp t view uchar * to void
459+o = paghv t
460+for i ulong get gpr 15 bound 2048
461+fescc get gpgh add o i
462+end
463+end
464+note pasjp t: the source.json string after the key text t, HTML-escaped
465+fn pasjp t view uchar * to void
466+o = pasjv t
467+for i ulong get gpr 15 bound 4096
468+fescc get gpsrc add o i
469+end
470+end
471+note paprov: the provenance text: Imported from GitHub <gho>/<ghr>#<n>, by <login>; a code-only item
472+note (no GitHub metadata) has no login: Imported from GitHub <gho>/<ghr>#<n> (code only)
473+note An item with metadata whose gh file names no login ends after the number: no ", by ".
474+fn paprov to void
475+fput tpimp1
476+pasjp tpsjow
477+fputc 47
478+pasjp tpsjrp
479+fputc 35
480+fnum get gpnum 0
481+if ne get gpider 0 0
482+fput tpimp3
483+ret
484+end
485+o = paghv tpghl
486+if eq get gpr 15 0
487+ret
488+end
489+fput tpimp2
490+paghp tpghl
491+end
492+note pabadge: the status word as a badge, and the word "derived" when the state is derived
493+fn pabadge to void
494+s = get gpist 0
495+if eq s 0
496+fput tpbok
497+fput tpwopn
498+end
499+if eq s 1
500+fput tpbbad
501+fput tpwclo
502+end
503+if eq s 2
504+fput tpbmut
505+fput tpwmrg
506+end
507+fput tpboff
508+if ne get gpider 0 0
509+fput tpbder
510+end
511+end
512+note paitl: the title, escaped; "(untitled)" when the item has none
513+fn paitl to void
514+if eq get gpttll 0 0
515+fput tpnotl
516+ret
517+end
518+paesct
519+end
520+note paiwhen: " opened YYYY-MM-DD" (gh opened); a code-only item: " imported <date of imported_utc>"
521+fn paiwhen to void
522+if ne get gpider 0 0
523+fput tpiwi
524+o = pasjv tpsjutc
525+if ge get gpr 15 10
526+for i ulong 10
527+fescc get gpsrc add o i
528+end
529+else
530+fputc 45
531+end
532+ret
533+end
534+fput tpiwo
535+o = paghv tpgho
536+if eq get gpr 15 20
537+for i ulong 10
538+fescc get gpgh add o i
539+end
540+else
541+fputc 45
542+end
543+end
544+note pairow: the list row of an imported item: title link, badge, id, date, provenance; no counts
545+fn pairow to void
546+fput tphli
547+papath
548+fput tphq
549+paitl
550+fput tphae
551+fput tpir1
552+pabadge
553+fput tpir2
554+paputid
555+fput tphcodz
556+paiwhen
557+fput tphm3
558+paprov
559+fput tphm4
560+end
561+note ---- the page of an imported item
562+note paitms: the opened, closed and merged times of the gh file (none for a code-only item)
563+fn paitms to void
564+if ne get gpider 0 0
565+ret
566+end
567+fput tpito
568+paghtm tpgho
569+if paghhas tpghc
570+fput tpitc
571+paghtm tpghc
572+end
573+if paghhas tpghm
574+fput tpitm
575+paghtm tpghm
576+end
577+end
578+note pailabs: "Labels: a, b" from the labels file (one per line; its first 65536 bytes)
579+fn pailabs to void
580+n = pafrd tpflb 65536
581+if eq n 0
582+ret
583+end
584+fput tpipm
585+fput tpilab
586+for i ulong n bound 65536
587+c = get fxo i
588+if eq c 10
589+if lt add i 1 n
590+fputc 44
591+fputc 32
592+end
593+else
594+fescc c
595+end
596+end
597+fput tpipe
598+end
599+note parchsp s n: the index of the first space of gpln at or after s, n when there is none (n is at
600+note most 255)
601+fn parchsp s ulong n ulong to ulong
602+q = s
603+while lt q n bound 257
604+if eq get gpln q 32
605+break
606+end
607+q = add q 1
608+end
609+ret q
610+end
611+note parchw a t: gpln[0, a) is t
612+fn parchw a ulong t view uchar * to bool
613+if ne a len t
614+ret false
615+end
616+for i ulong a bound 16
617+if ne get gpln i get t i
618+ret false
619+end
620+end
621+ret true
622+end
623+note parchld: the reach file of item gpid ("<reachable|not-reachable|unknown> <main sha|-> <utc>\n")
624+note into gpln: 1 reachable, 2 not-reachable, 3 unknown, 0 when there is none or it is not that
625+note line. The main sha is at gpr 12 (length gpr 13: 40, or 0 for "-"), the observation time at
626+note gpr 14 (length gpr 15: 1..32 bytes).
627+fn parchld to ulong
628+papid tpfrc
629+r = pards
630+if or lt r 5 gt r 255
631+ret 0
632+end
633+n = get gplnl 0
634+if ne get gpln sub n 1 10
635+ret 0
636+end
637+a = parchsp 0 n
638+if ge a n
639+ret 0
640+end
641+b = parchsp add a 1 n
642+if ge b n
643+ret 0
644+end
645+w = ulong 0
646+if parchw a tprch1
647+w = 1
648+end
649+if parchw a tprch2
650+w = 2
651+end
652+if parchw a tprch3
653+w = 3
654+end
655+if eq w 0
656+ret 0
657+end
658+m = sub sub b a 1
659+put gpr 12 add a 1
660+put gpr 13 0
661+if eq m 40
662+for i ulong 40
663+if lt sohexv get gpln add add a 1 i 0
664+ret 0
665+end
666+end
667+put gpr 13 40
668+else
669+if ne m 1
670+ret 0
671+end
672+if ne get gpln add a 1 45
673+ret 0
674+end
675+end
676+u = sub sub n b 2
677+if or lt u 1 gt u 32
678+ret 0
679+end
680+put gpr 14 add b 1
681+put gpr 15 u
682+ret w
683+end
684+note paimrg: a merged item with GitHub metadata: the merge commit (the merged file) and what the
685+note importer observed about this project's main (the reach file)
686+fn paimrg to void
687+papid tpfmg
688+r = pards
689+if not pal40
690+ret
691+end
692+fput tpipm
693+fput tpimg1
694+for i ulong 40
695+fputc get gpln i
696+end
697+fput tphcodz
698+w = parchld
699+if or eq w 1 eq w 2
700+if eq w 1
701+fput tpimr1
702+else
703+fput tpimr2
704+end
705+o = get gpr 12
706+for i ulong get gpr 13 bound 40
707+fputc get gpln add o i
708+end
709+fput tphcodz
710+end
711+if eq w 3
712+fput tpimr3
713+end
714+if ne w 0
715+fput tpimro
716+o = get gpr 14
717+for i ulong get gpr 15 bound 32
718+fescc get gpln add o i
719+end
720+fputc 41
721+end
722+fput tpipe
723+end
724+note paishas: the base and head commits, and the merge line of a merged item
725+fn paishas to void
726+fput tpipm
727+if ne get gpihb 0 0
728+fput tpisb
729+paput40 0
730+fput tpisb2
731+else
732+fput tpisnb
733+end
734+fput tpish
735+paput40 1
736+fput tphcodz
737+fput tpipe
738+if eq get gpist 0 2
739+paimrg
740+end
741+end
742+note pamd n: render fxo[0, n) using the browse renderer at the project root on its default branch
743+fn pamd n ulong to void
744+repo = get fridx 0
745+branch = get fabo repo
746+size = get fabl repo
747+for i ulong size bound 64
748+put gbref i get fabr add branch i
749+end
750+put gbrefl 0 size
751+put gbmdl 0 0
752+fput tbart1
753+brmd 0 n
754+fput tbart2
755+end
756+note papgfit f0 t0: true while the page is at most PAPGMX bytes and no byte was dropped; else the
757+note output goes back to f0 (and the cut flag to t0), so the caller writes one sentence in place of
758+note what it rendered and the rest of the page still fits fob
759+fn papgfit f0 ulong t0 ulong to bool
760+if and le get fobl 0 PAPGMX eq get fobtr 0 t0
761+ret true
762+end
763+put fobl 0 f0
764+put fobtr 0 t0
765+ret false
766+end
767+note paidesc: the description as Markdown under "<login> wrote on <time>"; nothing when there is
768+note none; one sentence when it is over fxo or takes the page over PAPGMX
769+fn paidesc to void
770+pafp tpfds
771+n = frdall
772+if le n 0
773+ret
774+end
775+huge = ne get fxotr 0 0
776+f0 = get fobl 0
777+t0 = get fobtr 0
778+fput tpibox
779+if eq get gpider 0 0
780+paghp tpghl
781+fput tpiwr
782+paghtm tpgho
783+else
784+fput tpidsc
785+end
786+fput tpipe
787+if huge
788+fput tpidbig
789+else
790+pamd ulong n
791+end
792+fput tphdv
793+if not papgfit f0 t0
794+fput tpidbig
795+end
796+end
797+note paibox: the parsed record (gpr) as a box: login (text), what it is, time, the body as Markdown
798+fn paibox to void
799+k = get gpr 0
800+fput tpibox
801+patraw 3
802+if eq k 1
803+fput tpiwr
804+end
805+if eq k 2
806+fput tpirv1
807+patraw 5
808+fput tpirv2
809+end
810+if eq k 3
811+fput tpirc1
812+patraw 8
813+fput tpirc2
814+fnum get gpr 7
815+fput tpion
816+end
817+pattime
818+fput tpipe
819+o = get gpr 10
820+b = get gpr 11
821+if gt b 0
822+for i ulong b bound 16777216
823+put fxo i get gpth add o i
824+end
825+pamd b
826+end
827+fput tphdv
828+end
829+note paithr: the thread, one box per record. It stops at the first malformed record (one sentence),
830+note and when a box takes the page over PAPGMX (that box is taken back, one sentence).
831+fn paithr to void
832+pathld
833+p = ulong 0
834+n = get gpthl 0
835+while lt p n bound 16777216
836+p = patrec p
837+if eq get gpr 0 0
838+if eq get gpthc 0 0
839+fput tpitbad
840+end
841+break
842+end
843+f0 = get fobl 0
844+t0 = get fobtr 0
845+paibox
846+if not papgfit f0 t0
847+fput tpitcut
848+break
849+end
850+end
851+if ne get gpthc 0 0
852+fput tpitbig
853+end
854+end
855+note paiapply: the code box of an mbox-backed item: the "Apply it" lines and raw links of a signed
856+note patch (no Signature box)
857+fn paiapply to void
858+fput tphap1
859+paputid
860+if ne get gpihb 0 0
861+fputc 32
862+paput40 0
863+end
864+fput tphap2
865+paorig
866+papath
867+fput tpsfxp
868+fput tphap3
869+papath
870+fput tpsfxp
871+fput tphap4
872+papath
873+fput tpsfxd
874+fput tphap5
875+end
876+note paibund: the code box of a bundle-backed item: size, the fetch lines, the raw link, and the
877+note diff link when the diff exists (gpbd 0)
878+fn paibund to void
879+fput tpibd1
880+fnum get gpmby 0
881+fput tpibd2
882+paorig
883+papath
884+fput tpsfxb
885+fput tpibd3
886+paputid
887+fput tpsfxb
888+fput tpibd4
889+paputid
890+fput tpsfxb
891+fput tpibd4b
892+fnum get gpnum 0
893+fput tpibd5
894+papath
895+fput tpsfxb
896+fput tpibd6
897+if eq get gpbd 0 0
898+fput tpibd7
899+papath
900+fput tpsfxd
901+fput tphap5
902+ret
903+end
904+fput tpibd9
905+end
906+note paonmn: the loaded imported item is the importer's on-main route: a code-only item (derived
907+note state) whose state is merged and whose base file names its head commit
908+fn paonmn to bool
909+if eq get gpider 0 0
910+ret false
911+end
912+if ne get gpist 0 2
913+ret false
914+end
915+if eq get gpihb 0 0
916+ret false
917+end
918+for i ulong 40
919+if ne get gpbase i get gphead i
920+ret false
921+end
922+end
923+ret true
924+end
925+note paicode: the Code box. Without a code file only the on-main route says the head is on main (with
926+note the link to its commit page); any other item says that it holds no code file.
927+fn paicode to void
928+k = get gpicode 0
929+if eq k 1
930+paiapply
931+ret
932+end
933+if eq k 2
934+paibund
935+ret
936+end
937+if not paonmn
938+fput tpicx
939+ret
940+end
941+fput tpicn1
942+fputrl
943+fput tphcm
944+paput40 1
945+fput tphq
946+fput tphcode
947+paput40 1
948+fput tpicn2
949+end
950+note paiprov: the Provenance box: imported, not signed; the statement and source.json, escaped
951+fn paiprov to void
952+fput tpipv1
953+n = pafrd tpfst 65536
954+fxesc 0 n
955+fput tphpre
956+fput tphsg3
957+for i ulong get gpsrcl 0 bound 4096
958+fescc get gpsrc i
959+end
960+fput tphpre
961+fput tphdv
962+end
963+note paichn t: the Changes heading with one sentence in place of a diff
964+fn paichn t view uchar * to void
965+fput tpich
966+fput t
967+fput tpipe
968+end
969+note pafpp: fpth = gpp, for frdall
970+fn pafpp to void
971+fpb
972+for i ulong get gppl 0 bound 4096
973+fpc get gpp i
974+end
975+end
976+note paichg: Changes: the stored diff of an mbox, the cached diff of a bundle with a base (gpbd is
977+note pabdiff's answer), else the sentence that says why there is none
978+fn paichg to void
979+k = get gpicode 0
980+if eq k 1
981+n = pardf tpfdf
982+if gt n 0
983+pashdn n
984+ret
985+end
986+paichn tpicg1
987+ret
988+end
989+if eq k 0
990+if paonmn
991+paichn tpicg0
992+else
993+paichn tpicg7
994+end
995+ret
996+end
997+if eq get gpihb 0 0
998+paichn tpicg2
999+ret
1000+end
1001+w = get gpbd 0
1002+if eq w 1
1003+paichn tpicg3
1004+ret
1005+end
1006+if eq w 2
1007+paichn tpicg4
1008+ret
1009+end
1010+if eq w 4
1011+paichn tpicg8
1012+ret
1013+end
1014+if ne w 0
1015+paichn tpicg5
1016+ret
1017+end
1018+papdf
1019+pafpp
1020+r = frdall
1021+if lt r 0
1022+paichn tpicg5
1023+ret
1024+end
1025+if eq r 0
1026+paichn tpicg6
1027+ret
1028+end
1029+pashdn ulong r
1030+end
1031+note paishow: the page of the loaded imported item
1032+fn paishow to long
1033+put gpbd 0 9
1034+if eq get gpicode 0 2
1035+if ne get gpihb 0 0
1036+put gpbd 0 pabdiff
1037+end
1038+end
1039+fyalt
1040+if eq get gpttll 0 0
1041+fsetti tptlist
1042+else
1043+patitl
1044+end
1045+frepohd 5
1046+fput tphp1
1047+paitl
1048+fput tpip2
1049+pabadge
1050+fput tpir2
1051+paputid
1052+fput tphcodz
1053+fput tpipn
1054+fnum get gpnum 0
1055+paitms
1056+fput tpipe
1057+fput tpipm
1058+paprov
1059+fput tpipe
1060+if ne get gpider 0 0
1061+fput tpider
1062+end
1063+pailabs
1064+paishas
1065+fput tphdv
1066+paidesc
1067+paithr
1068+paicode
1069+paiprov
1070+paichg
1071+ret 200
1072+end
1073+note ---- the diff of a bundle-backed item (SPEC section 4), made once and kept as the cache file
1074+note <data>pdiff/<owner>/<repo>/<id>: derived data outside the item folder, safe to delete
1075+note pabcat: git --git-dir=<store> cat-file -e <base>^{commit} for the loaded item's base (gpbase),
1076+note fexec's answer: 0 the project's git store holds the base commit, above 0 it does not, below 0
1077+note git did not run. One check for the diff (pabdiff) and for the JSON documents (pajdun)
1078+fn pabcat to long
1079+pakst
1080+fka tpcatf
1081+fka tpde
1082+fkopen
1083+pakbase
1084+fkt tpcmt
1085+ret fexec PATMO
1086+end
1087+note pabbig: leave the marker <data>pdiff/<owner>/<repo>/<id>.big, an empty file created exclusively
1088+note (one that is there stays; a failure leaves none and the next attempt tries again): the bundle
1089+note diff of item gpid was cut at 16 MiB. Derived data like the cache file, safe to delete
1090+fn pabbig to void
1091+if not pamkpd
1092+ret
1093+end
1094+papdfg
1095+x = pawf 6 0
1096+end
1097+note pabst: what the cache folder says of the loaded bundle-backed item, without running git: 0 the
1098+note cache file is there, 2 the marker is there, 9 neither
1099+fn pabst to ulong
1100+papdf
1101+if paexist
1102+ret 0
1103+end
1104+papdfg
1105+if paexist
1106+ret 2
1107+end
1108+ret 9
1109+end
1110+note pabkeep: fxo[0, fxol) -> this request's staging file -> the cache file (rename over it; the
1111+note staging file is removed when the write or the rename fails): 0 kept, 3 failed
1112+fn pabkeep to ulong
1113+if not pamkpd
1114+ret 3
1115+end
1116+papdfn
1117+if not pawf 6 get fxol 0
1118+x = unlink gpp 0 get gppl 0
1119+ret 3
1120+end
1121+soavb
1122+papdfn
1123+paavp
1124+papdf
1125+paavp
1126+r = renames gspk 0 get gspkl 0 0
1127+if lt r 0
1128+papdfn
1129+x = unlink gpp 0 get gppl 0
1130+ret 3
1131+end
1132+ret 0
1133+end
1134+note pabrun: in the work folder: git bundle unbundle <item>/head.bundle, then git diff --no-color
1135+note --no-ext-diff --no-textconv <base>...<head> (the importer's own diff form), both with pakwt's
1136+note settings through fexec (argv only): 0 the output is kept as the cache file, 2 it is over fxo
1137+note (not kept), 3 git or the disk failed
1138+fn pabrun to ulong
1139+pakwt
1140+fka tpbund
1141+fka tpunb
1142+fkopen
1143+papid tpfbn
1144+pakp
1145+r = fexec PATMO
1146+if ne r 0
1147+ret 3
1148+end
1149+pakwt
1150+fka tpdiff
1151+fka tpnocol
1152+fka tpnoext
1153+fka tpnotc
1154+fkopen
1155+pakbase
1156+fkt tpdots3
1157+for i ulong 40
1158+fkc get gphead i
1159+end
1160+r = fexec PATMO
1161+if ne r 0
1162+ret 3
1163+end
1164+if ne get fxotr 0 0
1165+ret 2
1166+end
1167+ret pabkeep
1168+end
1169+note Cache failed diff work briefly without changing imported data.
1170+global gpbkeys uchar 1024
1171+global gpbexp ulong 64
1172+global gpbslot ulong 1
1173+fn pabbad to bool
1174+now = ulong monons
1175+for slot ulong 64
1176+if gt get gpbexp slot now
1177+same = true
1178+for i ulong 16
1179+if ne get gpbkeys add mul slot 16 i get gpid i
1180+same = false
1181+break
1182+end
1183+end
1184+if same
1185+ret true
1186+end
1187+end
1188+end
1189+ret false
1190+end
1191+fn pabbset to void
1192+slot = get gpbslot 0
1193+for i ulong 16
1194+put gpbkeys add mul slot 16 i get gpid i
1195+end
1196+put gpbexp slot add ulong monons 120000000000
1197+put gpbslot 0 rem add slot 1 64
1198+end
1199+note Skip synchronous diff generation for large bundles. The bundle download stays available.
1200+fn pabbcap to bool
1201+papid tpfbn
1202+if not paexist
1203+ret false
1204+end
1205+ret gt pastsz 134217728
1206+end
1207+note pabdiff: the cache file of the loaded bundle-backed item (gpid, gpbase, gphead) exists, making
1208+note it when it does not: 0 it is there, 1 the base commit is not in the project's git store, 2 the
1209+note diff is over fxo (the marker is left beside the cache, pabbig; with the marker there git is not
1210+note run again: the page and the raw route answer from it), 3 git, the disk or the work folder
1211+note failed. The work folder is removed whatever happened.
1212+fn pabdiff to ulong
1213+papdf
1214+e = paexist
1215+if e
1216+ret 0
1217+end
1218+papdfg
1219+if paexist
1220+ret 2
1221+end
1222+if pabbcap
1223+ret 4
1224+end
1225+if pabbad
1226+ret 3
1227+end
1228+r = pabcat
1229+if lt r 0
1230+pabbset
1231+ret 3
1232+end
1233+if ne r 0
1234+ret 1
1235+end
1236+if not pastem
1237+ret 3
1238+end
1239+w = ulong 3
1240+if pawinit
1241+w = pabrun
1242+end
1243+if not parmtree
1244+flog tplrm
1245+end
1246+if eq w 2
1247+pabbig
1248+end
1249+if eq w 3
1250+pabbset
1251+end
1252+ret w
1253+end
1254+note pabraw: GET <id>.diff of an item that stores no diff file: 0 with gpp = the cache file of the
1255+note bundle diff (made now when it is not there), else the status: 404 (not an item, no bundle, no
1256+note base, the base is not in the git store, the diff is over fxo), 500 (the diff could not be made)
1257+fn pabraw to long
1258+if not paany
1259+ret 404
1260+end
1261+if eq get gpimp 0 0
1262+ret 404
1263+end
1264+if ne get gpicode 0 2
1265+ret 404
1266+end
1267+if eq get gpihb 0 0
1268+ret 404
1269+end
1270+w = pabdiff
1271+if eq w 0
1272+papdf
1273+ret 0
1274+end
1275+if eq w 3
1276+patext
1277+fput tpmdint
1278+ret 500
1279+end
1280+ret 404
1281+end

patch/p5page.om

new file mode 100644
@@ -0,0 +1,614 @@
1+note patch/p5page.om: reading the store back, the HTML pages (list, one patch, how to open one) and
2+note the raw routes (.patch: the stored mbox bytes; .diff: the diff the forge made when it applied them).
3+note ---- reading a stored patch
4+note pafp t: fpth = the file <t> of patch gpid, for frdall
5+fn pafp t view uchar * to void
6+papid t
7+fpb
8+for i ulong get gppl 0 bound 4096
9+fpc get gpp i
10+end
11+end
12+note pamnum: the decimal number at fxo[gpcur] up to its line feed; gpcur moves past the line feed;
13+note gpbad is set when it is not 1..18 digits followed by a line feed
14+fn pamnum to ulong
15+p = get gpcur 0
16+n = get fxol 0
17+v = ulong 0
18+k = ulong 0
19+while lt p n bound 32
20+c = get fxo p
21+if eq c 10
22+break
23+end
24+if or not fisdig c ge k 18
25+put gpbad 0 1
26+ret 0
27+end
28+v = add mul v 10 ulong sub c 48
29+k = add k 1
30+p = add p 1
31+end
32+if or eq k 0 ge p n
33+put gpbad 0 1
34+end
35+put gpcur 0 add p 1
36+ret v
37+end
38+note pameld: the meta file into gpmdid, gpmts, gpmcm, gpmfl, gpmby, gpmsha
39+fn pameld to bool
40+pafp tpfme
41+n = frdall
42+if or lt n 80 gt n 250
43+ret false
44+end
45+e = ulong 0
46+while lt e ulong n bound 256
47+if eq get fxo e 10
48+break
49+end
50+e = add e 1
51+end
52+if or lt e 9 gt e 120
53+ret false
54+end
55+for i ulong e bound 128
56+put gpmdid i get fxo i
57+end
58+put gpmdidl 0 e
59+put gpbad 0 0
60+put gpcur 0 add e 1
61+put gpmts 0 pamnum
62+put gpmcm 0 pamnum
63+put gpmfl 0 pamnum
64+put gpmby 0 pamnum
65+p = get gpcur 0
66+if or ne get gpbad 0 0 ne add p 65 ulong n
67+ret false
68+end
69+for i ulong 64
70+put gpmsha i get fxo add p i
71+end
72+ret true
73+end
74+note pastld: the statement into gpst and its base line into gpbase (the statement ends with base,
75+note line feed, two lines of 64 hex and a line feed each: the base is 171 bytes before the end)
76+fn pastld to bool
77+pafp tpfst
78+n = frdall
79+if or lt n 180 gt n 511
80+ret false
81+end
82+for i ulong ulong n bound 512
83+put gpst i get fxo i
84+end
85+put gpstl 0 ulong n
86+o = sub ulong n 171
87+for i ulong 40
88+c = get fxo add o i
89+if lt sohexv c 0
90+ret false
91+end
92+put gpbase i c
93+end
94+ret true
95+end
96+note paload: patch gpid of this repository into the globals; false when it is not a whole stored patch
97+fn paload to bool
98+if not pameld
99+ret false
100+end
101+pafp tpftt
102+n = frdall
103+if or lt n 1 gt n 256
104+ret false
105+end
106+for i ulong ulong n bound 256
107+put gpttl i get fxo i
108+end
109+put gpttll 0 ulong n
110+if not pastld
111+ret false
112+end
113+pafp tpfhd
114+n = frdall
115+if lt n 0
116+ret false
117+end
118+ret pahex40
119+end
120+note paany: item gpid of this repository into the globals, signed (its meta file exists: paload) or
121+note imported (patch/p5imp.om paiload); false when it is neither a whole signed patch nor a loadable
122+note imported item
123+fn paany to bool
124+put gpimp 0 0
125+put gpist 0 0
126+put gpider 0 0
127+put gpicode 0 1
128+put gpihb 0 1
129+put gpnum 0 0
130+papid tpfme
131+e = paexist
132+if e
133+ret paload
134+end
135+ret paiload
136+end
137+note paqst: the state of item gpid for the list head: 0 open, 1 closed, 2 merged when its page loader
138+note loads it (paany: paload for a signed patch, which is open; paiload for an imported item), 9 when
139+note it does not. The loaders read through fxo, so the caller keeps the index in gpix
140+fn paqst to ulong
141+if not paany
142+ret 9
143+end
144+ret get gpist 0
145+end
146+note pastcnt tot: the items of the index in gpix (tot lines) that load, by state, into gpsc: exactly
147+note the items a list page shows. A line that is not an id, or whose folder does not load as an item,
148+note is in no count (palist: damaged = tot less the three counts)
149+fn pastcnt tot ulong to void
150+for s ulong 3
151+put gpsc s 0
152+end
153+for r ulong tot bound 1048576
154+if paidrow mul r 17
155+s = paqst
156+if lt s 3
157+put gpsc s add get gpsc s 1
158+end
159+end
160+end
161+end
162+note paidrow o: gpid = gpix[o, o+16) when it is 16 lowercase hex
163+fn paidrow o ulong to bool
164+for i ulong 16
165+c = get gpix add o i
166+if lt sohexv c 0
167+ret false
168+end
169+put gpid i c
170+end
171+ret true
172+end
173+note pardf t: the file <t> of patch gpid into fxo; its length, 0 when it cannot be read
174+fn pardf t view uchar * to ulong
175+pafp t
176+n = frdall
177+if lt n 0
178+ret 0
179+end
180+ret ulong n
181+end
182+note ---- pieces
183+note padid: the social store's id of the author DID in gpmdid, 0 when it holds no such account
184+fn padid to ulong
185+sokclr
186+for i ulong get gpmdidl 0 bound 128
187+sokc get gpmdid i
188+end
189+ret sofind
190+end
191+note paauth: the author as the pages show an account (its name linked, else the shortened DID
192+note linked; social/50route.om souser); the full DID in code when the store has no such account
193+fn paauth to void
194+d = padid
195+if ne d 0
196+souser d
197+ret
198+end
199+fput tphcode
200+for i ulong get gpmdidl 0 bound 128
201+fescc get gpmdid i
202+end
203+fput tphcodz
204+end
205+fn paputid to void
206+for i ulong 16
207+fputc get gpid i
208+end
209+end
210+note papath: the page path of patch gpid: <base><owner>/<repo>/patches/<id>
211+fn papath to void
212+fputrl
213+fput tppats
214+fputc 47
215+paputid
216+end
217+fn paput40 w ulong to void
218+for i ulong 40
219+if eq w 0
220+fputc get gpbase i
221+else
222+fputc get gphead i
223+end
224+end
225+end
226+note pacnts: "N commits &middot; M files"
227+fn pacnts to void
228+c = get gpmcm 0
229+fnum c
230+if eq c 1
231+fput tphc1
232+else
233+fput tphc2
234+end
235+fput tphm3
236+f = get gpmfl 0
237+fnum f
238+if eq f 1
239+fput tphf1
240+else
241+fput tphf2
242+end
243+end
244+fn paesct to void
245+for i ulong get gpttll 0 bound 1024
246+fescc get gpttl i
247+end
248+end
249+note ---- the list: the index file holds one line "<16 hex>\n" per patch, oldest first; a page shows
250+note 30, newest first
251+note paidxn: the index into fxo; the number of patches
252+fn paidxn to ulong
253+paprepo
254+papt tpindex
255+fpb
256+for i ulong get gppl 0 bound 4096
257+fpc get gpp i
258+end
259+n = frdall
260+if lt n 0
261+ret 0
262+end
263+if ne get fxotr 0 0
264+fincut
265+end
266+ret div ulong n 17
267+end
268+note pacount: the patches the store holds for the repository fridx (growth/g1prep.om grpatch)
269+fn pacount to ulong
270+ret paidxn
271+end
272+note papage: the ?page= number, 1 when absent or not a number of 1 to 9 digits above zero
273+fn papage to ulong
274+n = fqget tpqpage
275+if or lt n 1 gt n 9
276+ret 1
277+end
278+v = ulong 0
279+for i ulong ulong n bound 9
280+c = get fval i
281+if not fisdig c
282+ret 1
283+end
284+v = add mul v 10 ulong sub c 48
285+end
286+if eq v 0
287+ret 1
288+end
289+ret v
290+end
291+note paixld: the index into gpix (read through fxo, paidxn); the number of its lines
292+fn paixld to ulong
293+tot = paidxn
294+for i ulong mul tot 17 bound 16777216
295+put gpix i get fxo i
296+end
297+ret tot
298+end
299+note papick: the ids of page pg (of tot lines in gpix) into gpids, newest first; how many
300+fn papick tot ulong pg ulong to ulong
301+a = mul sub pg 1 30
302+c = ulong 0
303+for j ulong 30
304+k = add a j
305+if ge k tot
306+break
307+end
308+o = mul sub sub tot 1 k 17
309+for i ulong 16
310+put gpids add mul c 16 i get gpix add o i
311+end
312+c = add c 1
313+end
314+ret c
315+end
316+note paidset: gpid = row j of gpids; false when it is not 16 lowercase hex
317+fn paidset j ulong to bool
318+for i ulong 16
319+c = get gpids add mul j 16 i
320+if lt sohexv c 0
321+ret false
322+end
323+put gpid i c
324+end
325+ret true
326+end
327+fn parow to void
328+fput tphli
329+papath
330+fput tphq
331+paesct
332+fput tphae
333+fput tphm1
334+paputid
335+fput tphm2
336+fjday get gpmts 0
337+fput tphby
338+paauth
339+fput tphm3
340+pacnts
341+fput tphm4
342+end
343+fn papgln pg ulong t view uchar * to void
344+fput tph2
345+fputrl
346+fput tphqp
347+fnum pg
348+fput t
349+end
350+note padmg n: the list head's words for n index lines whose folder does not load as an item
351+fn padmg n ulong to void
352+fput tpdmg1
353+fnum n
354+if eq n 1
355+fput tpdmg2
356+ret
357+end
358+fput tpdmg3
359+end
360+note palist: the list. tot: the lines of the index (the pages go by index position, 30 lines each);
361+note lst: the items that load (count; gpsc by state); dmg: the lines that do not (damaged)
362+fn palist to long
363+tot = paixld
364+if ne get fobtr 0 0
365+ret 500
366+end
367+pg = papage
368+pages = div add tot 29 30
369+if eq pages 0
370+pages = 1
371+end
372+if gt pg pages
373+ret 404
374+end
375+cnt = papick tot pg
376+pastcnt tot
377+lst = add add get gpsc 0 get gpsc 1 get gpsc 2
378+dmg = sub tot lst
379+if fjwant
380+ret pajlist lst dmg pg pages cnt
381+end
382+fyalt
383+fsetti tptlist
384+frepohd 5
385+fput tph1
386+fnum lst
387+if eq lst 1
388+fput tph1a
389+else
390+fput tph1b
391+end
392+fput tpsth
393+fnum get gpsc 0
394+fput tpsto
395+fnum get gpsc 1
396+fput tpstc
397+fnum get gpsc 2
398+fput tpstm
399+if gt dmg 0
400+padmg dmg
401+end
402+fput tph2
403+fputrl
404+fput tph2n
405+if eq tot 0
406+fput tphnone
407+ret 200
408+end
409+fput tphul
410+for j ulong cnt bound 30
411+if paidset j
412+if paany
413+if eq get gpimp 0 0
414+parow
415+else
416+pairow
417+end
418+end
419+end
420+end
421+fput tphule
422+fput tphpg1
423+if gt pg 1
424+papgln sub pg 1 tphpgn
425+end
426+if lt pg pages
427+papgln add pg 1 tphpgo
428+end
429+fput tphpg2
430+ret 200
431+end
432+note ---- one patch
433+fn paorig to void
434+if eq get fbasel 0 1
435+fput tppor1
436+ret
437+end
438+fput tppor2
439+end
440+note patitl: the page title: the patch title when it is at most 200 bytes, else "Patches"
441+fn patitl to void
442+n = get gpttll 0
443+if gt n 200
444+fsetti tptlist
445+ret
446+end
447+put ftil 0 0
448+for i ulong n bound 200
449+ftic get gpttl i
450+end
451+end
452+note pashdf: the stored diff of the loaded patch, as pashdn shows it
453+fn pashdf to void
454+n = pardf tpfdf
455+if eq n 0
456+ret
457+end
458+pashdn n
459+end
460+note pashdn n: the diff fxo[0, n), at most 400000 bytes of it cut at a line's end, with a note when it
461+note is cut
462+fn pashdn n ulong to void
463+m = n
464+if gt n 400000
465+m = ulong 400000
466+for it ulong 400000
467+if eq m 0
468+break
469+end
470+if eq get fxo sub m 1 10
471+break
472+end
473+m = sub m 1
474+end
475+end
476+fput tphdf1
477+fxesc 0 m
478+fput tphpre
479+if lt m n
480+fput tphdfc
481+end
482+end
483+fn pashow2 to void
484+fput tphap1
485+paputid
486+fputc 32
487+paput40 0
488+fput tphap2
489+paorig
490+papath
491+fput tpsfxp
492+fput tphap3
493+papath
494+fput tpsfxp
495+fput tphap4
496+papath
497+fput tpsfxd
498+fput tphap5
499+fput tphsg1
500+for i ulong get gpmdidl 0 bound 128
501+fescc get gpmdid i
502+end
503+fput tphsg2
504+for i ulong get gpstl 0 bound 512
505+fescc get gpst i
506+end
507+fput tphpre
508+n = pardf tpfsg
509+fput tphsg3
510+fxesc 0 n
511+fput tphpre
512+fput tphdv
513+pashdf
514+end
515+fn pashow to long
516+if not paany
517+ret 404
518+end
519+if fjwant
520+ret pajone
521+end
522+if ne get gpimp 0 0
523+ret paishow
524+end
525+fyalt
526+patitl
527+frepohd 5
528+fput tphp1
529+paesct
530+fput tphp2
531+paputid
532+fput tphm2
533+fjday get gpmts 0
534+fput tphby
535+paauth
536+fput tphp3
537+pacnts
538+fput tphm3
539+fnum get gpmby 0
540+fput tphp4
541+fputrl
542+fput tphcm
543+paput40 0
544+fput tphq
545+fput tphcode
546+paput40 0
547+fput tphp5
548+paput40 1
549+fput tphp6
550+n = pardf tpfds
551+if gt n 0
552+fput tphds1
553+fxesc 0 n
554+fput tphpre
555+end
556+pashow2
557+ret 200
558+end
559+note panewpg: GET .../patches/new: how to open a patch (the upload itself is the POST)
560+fn panewpg to long
561+fsetti tptnew
562+frepohd 5
563+fput tphn1
564+fput tfowner
565+fputc 47
566+fputrnm
567+fput tphn2
568+ret 200
569+end
570+note ---- raw: w 0 <id>.patch (the stored mbox), 1 <id>.diff (the stored diff; else the bundle diff of
571+note an imported item, patch/p5imp.om pabraw), 2 <id>.bundle (head.bundle). Streamed from the store or
572+note the diff cache (kind 3) under the sandbox policy; no JSON form. An item without a meta file must
573+note load as an imported item first.
574+fn paraws w ulong to long
575+papid tpfme
576+e = paexist
577+if not e
578+if not paiload
579+ret 404
580+end
581+end
582+if eq w 0
583+papid tpfmb
584+end
585+if eq w 1
586+papid tpfdf
587+end
588+if eq w 2
589+papid tpfbn
590+end
591+e = paexist
592+if not e
593+if ne w 1
594+ret 404
595+end
596+r = pabraw
597+if ne r 0
598+ret r
599+end
600+end
601+put ffilel 0 0
602+for i ulong get gppl 0 bound 4096
603+ffilc get gpp i
604+end
605+put fobl 0 0
606+put fkind 0 3
607+if eq w 2
608+fsetct tpctbin
609+else
610+fsetct tpctxt
611+end
612+fsetsbx
613+ret 200
614+end

patch/p6json.om

new file mode 100644
@@ -0,0 +1,637 @@
1+note patch/p6json.om: the JSON form of the patch pages (docs/API.md forge/patch-list/1, forge/patch/1).
2+note The documents name the repository by owner and name only.
3+note pajhead t: t (the schema and the base key up to its opening quote), then base, owner and repo
4+fn pajhead t view uchar * to void
5+fjstart
6+fput t
7+fputb
8+fput tpjown
9+fput tfowner
10+fput tpjrep
11+i = get fridx 0
12+for k ulong get fanl i bound 128
13+fputc frnbyte i k
14+end
15+end
16+note pajname: the author's social name as a JSON string, null when the account has none
17+fn pajname to void
18+d = padid
19+if eq d 0
20+fput tpjnull
21+ret
22+end
23+n = get gsnm d
24+if eq n 0
25+fput tpjnull
26+ret
27+end
28+o = get gsso n
29+fjtb
30+for i ulong get gssl n bound 64
31+fjtc get gsstr add o i
32+end
33+fjstr
34+end
35+note pajbody full: the keys of the loaded item (signed or imported) from its id's value on, in the order
36+note of SPEC section 3, up to its closing brace (the caller writes it). full: forge/patch/1 (adds
37+note description, mbox_sha256, opened, closed, merge, labels, comments, thread_truncated and
38+note thread_reason); else a list row (adds comments_count). Both end with path, patch, diff,
39+note diff_unavailable and bundle. The key set is the same for both kinds of item.
40+fn pajbody full bool to void
41+paputid
42+fput tpjttl
43+fjtb
44+for i ulong get gpttll 0 bound 1024
45+fjtc get gpttl i
46+end
47+fjstr
48+if full
49+fput tpjdsc
50+n = pardf tpfds
51+fjfx 0 n
52+end
53+imp = ne get gpimp 0 0
54+fyk tpkst
55+pajstw
56+fyk tpksd
57+fybool ne get gpider 0 0
58+fyk tpkau
59+if imp
60+fynull
61+else
62+pajauth
63+end
64+fyk tpkim
65+if imp
66+pajimp
67+else
68+fynull
69+end
70+fyk tpkbc
71+pajsha 0
72+fyk tpkhc
73+pajsha 1
74+pajcnts imp
75+fyk tpkcd
76+pajcode
77+if full
78+pajfull imp
79+end
80+fyk tpkcr
81+if imp
82+pajsv tpsjutc
83+else
84+fjiso get gpmts 0
85+end
86+if not full
87+fyk tpkcc
88+if imp
89+pathld
90+fnum patcnt
91+else
92+fputc 48
93+end
94+end
95+pajlinks
96+end
97+note pajstw: the status word as a JSON string
98+fn pajstw to void
99+fputc 34
100+s = get gpist 0
101+if eq s 0
102+fput tpwopn
103+end
104+if eq s 1
105+fput tpwclo
106+end
107+if eq s 2
108+fput tpwmrg
109+end
110+fputc 34
111+end
112+note pajauth: {"did":...,"name":...} of a signed patch
113+fn pajauth to void
114+fputc 123
115+fyk0 tpkdid
116+fjtb
117+for i ulong get gpmdidl 0 bound 128
118+fjtc get gpmdid i
119+end
120+fjstr
121+fput tpjnm
122+pajname
123+fputc 125
124+end
125+note pajsha w: the base (w 0; null when the item has none) or head commit as a JSON string
126+fn pajsha w ulong to void
127+if eq w 0
128+if eq get gpihb 0 0
129+fynull
130+ret
131+end
132+end
133+fputc 34
134+paput40 w
135+fputc 34
136+end
137+note pajcnts imp: commits and files (null for an imported item), bytes (of the code file)
138+fn pajcnts imp bool to void
139+fyk tpkcm
140+if imp
141+fynull
142+else
143+fnum get gpmcm 0
144+end
145+fyk tpkfl
146+if imp
147+fynull
148+else
149+fnum get gpmfl 0
150+end
151+fyk tpkby
152+fnum get gpmby 0
153+end
154+fn pajcode to void
155+k = get gpicode 0
156+if eq k 1
157+fysv tpkmb
158+ret
159+end
160+if eq k 2
161+fysv tpkbn
162+ret
163+end
164+fysv tpknone
165+end
166+note pajfull imp: the keys only forge/patch/1 has, from mbox_sha256 to comments
167+fn pajfull imp bool to void
168+fyk tpksha
169+if imp
170+fynull
171+else
172+fputc 34
173+for i ulong 64
174+fputc get gpmsha i
175+end
176+fputc 34
177+end
178+fyk tpkop
179+if imp
180+pajgh tpgho
181+else
182+fynull
183+end
184+fyk tpkcl
185+if imp
186+pajgh tpghc
187+else
188+fynull
189+end
190+fyk tpkmg
191+pajmrg
192+fyk tpklb
193+pajlabs
194+fyk tpkco
195+pajcoms
196+t = get gptr 0
197+fyk tpktt
198+fybool ne t 0
199+fyk tpktr
200+pajtrw t
201+end
202+note pajtrw t: thread_reason: null for a whole thread (0), else why the comments stop
203+fn pajtrw t ulong to void
204+if eq t 1
205+fysv tptr1
206+ret
207+end
208+if eq t 2
209+fysv tpun4
210+ret
211+end
212+if eq t 3
213+fysv tptr3
214+ret
215+end
216+fynull
217+end
218+note pajdun: why the loaded bundle-backed item with a base has no diff, asked without making one: 0
219+note it has or can have one (the cache file is there; or neither file is and the project's git store
220+note holds the base commit, or git did not run), 3 the store does not hold the base commit (pabcat,
221+note the check pabdiff makes), 4 the marker says its diff was cut at 16 MiB
222+fn pajdun to ulong
223+w = pabst
224+if eq w 0
225+ret 0
226+end
227+if eq w 2
228+ret 4
229+end
230+if pabbcap
231+ret 5
232+end
233+if pabbad
234+ret 6
235+end
236+r = pabcat
237+if lt r 0
238+pabbset
239+ret 6
240+end
241+if gt r 0
242+ret 3
243+end
244+ret 0
245+end
246+note pajduw u: diff_unavailable: null when diff is a link (0), else the reason
247+fn pajduw u ulong to void
248+if eq u 1
249+fysv tpun1
250+ret
251+end
252+if eq u 2
253+fysv tpun2
254+ret
255+end
256+if eq u 3
257+fysv tpun3
258+ret
259+end
260+if eq u 4
261+fysv tpun4
262+ret
263+end
264+if eq u 5
265+fysv tpun5
266+ret
267+end
268+if eq u 6
269+fysv tpun6
270+ret
271+end
272+fynull
273+end
274+note pajlinks: path, patch (null without an mbox), diff (a link for an mbox, and for a bundle whose
275+note diff exists or can be made; else null), diff_unavailable (null beside a link; else no-code-file,
276+note no-base, base-not-in-store or too-large), bundle (null without head.bundle)
277+fn pajlinks to void
278+fyk tpkpt
279+fputc 34
280+papath
281+fputc 34
282+k = get gpicode 0
283+fyk tpkpa
284+if eq k 1
285+fputc 34
286+papath
287+fput tpsfxp
288+fputc 34
289+else
290+fynull
291+end
292+fyk tpkdf
293+d = or eq k 1 and eq k 2 ne get gpihb 0 0
294+u = ulong 0
295+if d
296+if eq k 2
297+u = pajdun
298+end
299+else
300+u = 2
301+if eq k 0
302+u = 1
303+end
304+end
305+if eq u 0
306+fputc 34
307+papath
308+fput tpsfxd
309+fputc 34
310+else
311+fynull
312+end
313+fyk tpkdu
314+pajduw u
315+fyk tpkbn
316+if eq k 2
317+fputc 34
318+papath
319+fput tpsfxb
320+fputc 34
321+else
322+fynull
323+end
324+end
325+note pajgh t: the gh value t as a JSON string; null when the line is absent, empty or "-"
326+fn pajgh t view uchar * to void
327+o = paghv t
328+n = get gpr 15
329+if eq n 0
330+fynull
331+ret
332+end
333+if eq n 1
334+if eq get gpgh o 45
335+fynull
336+ret
337+end
338+end
339+fjtb
340+for i ulong n bound 2048
341+fjtc get gpgh add o i
342+end
343+fjstr
344+end
345+note pajsv t: the source.json string after the key text t as a JSON string; null without the key
346+fn pajsv t view uchar * to void
347+o = pasjv t
348+if eq get gpr 14 0
349+fynull
350+ret
351+end
352+fjtb
353+for i ulong get gpr 15 bound 4096
354+fjtc get gpsrc add o i
355+end
356+fjstr
357+end
358+note pajimp: {"from":"github","owner","repo","number","url","login"} (login null for a code-only item)
359+fn pajimp to void
360+fputc 123
361+fyk0 tpkfrm
362+fysv tpgith
363+fyk tpkow
364+pajsv tpsjow
365+fyk tpkrp
366+pajsv tpsjrp
367+fyk tpknum
368+fnum get gpnum 0
369+fyk tpkurl
370+pajsv tpsjurl
371+fyk tpklog
372+if ne get gpider 0 0
373+fynull
374+else
375+pajgh tpghl
376+end
377+fputc 125
378+end
379+note pajmrg: null, or for a merged imported item with a valid merged file {"commit","time","reach",
380+note "main","observed"} (reach "unknown" with main and observed null when the reach file is not valid)
381+fn pajmrg to void
382+if eq get gpimp 0 0
383+fynull
384+ret
385+end
386+if ne get gpist 0 2
387+fynull
388+ret
389+end
390+papid tpfmg
391+r = pards
392+if not pal40
393+fynull
394+ret
395+end
396+fputc 123
397+fyk0 tpkcmt
398+fputc 34
399+for i ulong 40
400+fputc get gpln i
401+end
402+fputc 34
403+fyk tpktim
404+pajgh tpghm
405+w = parchld
406+fyk tpkrch
407+if eq w 1
408+fysv tprch1
409+end
410+if eq w 2
411+fysv tprch2
412+end
413+if or eq w 0 eq w 3
414+fysv tprch3
415+end
416+fyk tpkmn
417+if and ne w 0 eq get gpr 13 40
418+fjtb
419+o = get gpr 12
420+for i ulong 40
421+fjtc get gpln add o i
422+end
423+fjstr
424+else
425+fynull
426+end
427+fyk tpkobs
428+if ne w 0
429+fjtb
430+o = get gpr 14
431+for i ulong get gpr 15 bound 32
432+fjtc get gpln add o i
433+end
434+fjstr
435+else
436+fynull
437+end
438+fputc 125
439+end
440+note pajlabs: the labels file as an array of strings (one per line; empty lines are left out; its
441+note first 65536 bytes)
442+fn pajlabs to void
443+fputc 91
444+if eq get gpimp 0 0
445+fputc 93
446+ret
447+end
448+n = pafrd tpflb 65536
449+s = ulong 0
450+c = ulong 0
451+for i ulong add n 1 bound 65537
452+e = eq i n
453+if not e
454+e = eq get fxo i 10
455+end
456+if e
457+if gt i s
458+if gt c 0
459+fputc 44
460+end
461+fjtb
462+for j ulong sub i s bound 65536
463+fjtc get fxo add s j
464+end
465+fjstr
466+c = add c 1
467+end
468+s = add i 1
469+end
470+end
471+fputc 93
472+end
473+note pajfit f0 t0: true while the document is at most PAJMX bytes and no byte was dropped; else the
474+note output goes back to f0 (and the cut flag to t0): the comment just written is taken back whole
475+fn pajfit f0 ulong t0 ulong to bool
476+if and le get fobl 0 PAJMX eq get fobtr 0 t0
477+ret true
478+end
479+put fobl 0 f0
480+put fobtr 0 t0
481+ret false
482+end
483+note pajcoms: the thread records (the description is not one of them) up to the first malformed one,
484+note or up to the one that takes the document over PAJMX (taken back, so the document stays whole).
485+note gptr says why they are not the whole thread: 3 the document budget; else 2 the thread file is
486+note larger than gpth; else 1 a malformed record (when the page prints its sentence); 0 they are
487+fn pajcoms to void
488+put gptr 0 0
489+fputc 91
490+if eq get gpimp 0 0
491+fputc 93
492+ret
493+end
494+pathld
495+p = ulong 0
496+c = ulong 0
497+n = get gpthl 0
498+w = ulong 0
499+while lt p n bound 16777216
500+p = patrec p
501+if eq get gpr 0 0
502+w = 1
503+break
504+end
505+f0 = get fobl 0
506+t0 = get fobtr 0
507+if gt c 0
508+fputc 44
509+end
510+fputc 10
511+pajcom
512+if not pajfit f0 t0
513+w = 3
514+break
515+end
516+c = add c 1
517+end
518+fputc 93
519+if ne w 3
520+if ne get gpthc 0 0
521+w = 2
522+end
523+end
524+put gptr 0 w
525+end
526+note pajcom: the parsed record (gpr): {"author":null,"login","kind",["state"],["path","line"],"time",
527+note "body"}; a review's state "-" is null
528+fn pajcom to void
529+k = get gpr 0
530+fputc 123
531+fyk0 tpkau
532+fynull
533+fyk tpklog
534+pajtr 3
535+fyk tpkknd
536+if eq k 1
537+fysv tprcom
538+end
539+if eq k 2
540+fysv tprrev
541+fyk tpkstt
542+if patis 5 tpdash
543+fynull
544+else
545+pajtr 5
546+end
547+end
548+if eq k 3
549+fysv tprrc
550+fyk tpkpt
551+pajtr 8
552+fyk tpkln
553+fnum get gpr 7
554+end
555+fyk tpktim
556+if eq get gpr 2 20
557+pajtr 1
558+else
559+fynull
560+end
561+fyk tpkbdy
562+pajtr 10
563+fputc 125
564+end
565+note pajtr a: gpth[gpr a, + gpr a+1) as a JSON string
566+fn pajtr a ulong to void
567+fjtb
568+o = get gpr a
569+for i ulong get gpr add a 1 bound 16777216
570+fjtc get gpth add o i
571+end
572+fjstr
573+end
574+fn pajone to long
575+pajhead tpjp1
576+fput tpjid2
577+pajbody true
578+fput tpjend
579+ret 200
580+end
581+note pajpg pg: the path of list page pg as a JSON string
582+fn pajpg pg ulong to void
583+fputc 34
584+fputrl
585+fput tphqp
586+fnum pg
587+fputc 34
588+end
589+note pajlist: forge/patch-list/1. count: the items the pages list (lst); states: the same items by
590+note state (signed patches open); damaged: the index lines whose folder does not load as an item
591+fn pajlist lst ulong dmg ulong pg ulong pages ulong cnt ulong to long
592+pajhead tpjl1
593+fput tpjpage
594+fnum pg
595+fput tpjper
596+fnum lst
597+fyk tpkst2
598+fputc 123
599+fyk0 tpwopn
600+fnum get gpsc 0
601+fyk tpwclo
602+fnum get gpsc 1
603+fyk tpwmrg
604+fnum get gpsc 2
605+fputc 125
606+fyk tpkdm
607+fnum dmg
608+fput tpjpats
609+first = true
610+for j ulong cnt bound 30
611+if paidset j
612+if paany
613+if not first
614+fput tpjsep
615+end
616+first = false
617+fput tpjid
618+pajbody false
619+fputc 125
620+end
621+end
622+end
623+fput tpjnext
624+if lt pg pages
625+pajpg add pg 1
626+else
627+fput tpjnull
628+end
629+fput tpjprev
630+if gt pg 1
631+pajpg sub pg 1
632+else
633+fput tpjnull
634+end
635+fput tpjend
636+ret 200
637+end

patch/p7route.om

new file mode 100644
@@ -0,0 +1,133 @@
1+note patch/p7route.om: paroute, the slice's entry point (server/route.om fslices asks it before collab).
2+note GET /<o>/<r>/patches[?page=N] the list (HTML, or forge/patch-list/1)
3+note GET /<o>/<r>/patches/new how to open a patch
4+note POST /<o>/<r>/patches/new the upload (patch/p4take.om)
5+note GET /<o>/<r>/patches/<id> one item, signed or imported (HTML, or forge/patch/1); <id> is
6+note 16 lowercase hex
7+note GET /<o>/<r>/patches/<id>.patch the stored mbox bytes
8+note GET /<o>/<r>/patches/<id>.diff the stored diff, or the bundle diff of an imported item
9+note GET /<o>/<r>/patches/<id>.bundle the stored head.bundle of an imported item
10+note GET /<o>/<r>/pulls 302 to .../patches; /pulls/<id> and /pull/<id> 302 to
11+note .../patches/<id> (the names other forges use)
12+note Returns 0 when the path is not one of these.
13+note paseg t: frest starts with the segment t, followed by its end or a slash
14+fn paseg t view uchar * to bool
15+if not frstpre t
16+ret false
17+end
18+n = len t
19+if eq n get frestl 0
20+ret true
21+end
22+ret eq get frest n 47
23+end
24+note paidrq a: frest[a, a+16) is 16 lowercase hex; copied into gpid
25+fn paidrq a ulong to bool
26+for i ulong 16
27+c = get frest add a i
28+if lt sohexv c 0
29+ret false
30+end
31+put gpid i c
32+end
33+ret true
34+end
35+note pasfx a t: frest from a to its end equals t
36+fn pasfx a ulong t view uchar * to bool
37+if ne sub get frestl 0 a len t
38+ret false
39+end
40+for i ulong len t bound 16
41+if ne get frest add a i get t i
42+ret false
43+end
44+end
45+ret true
46+end
47+note paalias o: /pulls or /pull (o its length): the same pages under the names other forges use
48+fn paalias o ulong to long
49+if ne get fmeth 0 1
50+ret 405
51+end
52+n = get frestl 0
53+id = false
54+if and ne n o ne n add o 1
55+if ne sub n add o 1 16
56+ret 404
57+end
58+if not paidrq add o 1
59+ret 404
60+end
61+id = true
62+else
63+if eq o len tppull
64+ret 404
65+end
66+end
67+put fkind 0 2
68+flocrepo
69+floct tppats
70+if id
71+flocc 47
72+for i ulong 16
73+flocc get gpid i
74+end
75+end
76+ret 302
77+end
78+fn paroute to long
79+if ge get fridx 0 get fan 0
80+ret 0
81+end
82+if paseg tppulls
83+ret paalias len tppulls
84+end
85+if paseg tppull
86+ret paalias len tppull
87+end
88+if not paseg tppats
89+ret 0
90+end
91+m = get fmeth 0
92+n = get frestl 0
93+o = len tppats
94+if or eq n o eq n add o 1
95+if ne m 1
96+ret 405
97+end
98+ret palist
99+end
100+if frsteq tppnew
101+if eq m 3
102+ret patake
103+end
104+if ne m 1
105+ret 405
106+end
107+ret panewpg
108+end
109+if ne m 1
110+ret 405
111+end
112+a = add o 1
113+l = sub n a
114+if lt l 16
115+ret 404
116+end
117+if not paidrq a
118+ret 404
119+end
120+if eq l 16
121+ret pashow
122+end
123+if pasfx add a 16 tpsfxp
124+ret paraws 0
125+end
126+if pasfx add a 16 tpsfxd
127+ret paraws 1
128+end
129+if pasfx add a 16 tpsfxb
130+ret paraws 2
131+end
132+ret 404
133+end

patch/tests/e2e-import.sh

new file mode 100755
@@ -0,0 +1,511 @@
1+#!/bin/bash
2+# ORACLE: host test driver (bash + curl + git + jq + python3 through lib.sh), not product code.
3+# End-to-end run for imported proposals in the git patch store (SPEC prstore/r1 extension, sections
4+# 1, 3 and 4): the forge shows what the importer stored. HOST test on the Spark: the test copy of
5+# forged that patch/tests/lib.sh builds (scratch data folder, list, storage root, git store root,
6+# loopback port), the importer built from a COMMITTED head of the import lane, the real GitHub
7+# export and the owner-signed project stores (PROJECT_STORE_ROOT), both only read: every git run of the test
8+# uses a self-contained scratch copy of each store, and a listing of every real store and export file (size,
9+# mtime in ns, inode, link count, type) taken before the run is compared with one taken at the end.
10+# One kind of difference is a NOTE, not a FAIL: only the mtime (or link count) moved on a regular file with
11+# more than one hard link, same size and inode. In a scratch experiment, git bundle unbundle and read-only git
12+# runs did not touch a pack (a git object write did: it freshens the pack holding that object). The store's
13+# packs are hard-linked into about 170 other repositories that other lanes write while a run lasts.
14+# Nothing of the live forge, the project stores, ~/git, ~/forge-data or the export is written. Steps:
15+# 1. tools/ghimport of GHIMPORT_REF (git archive into scratch) is built with its own build.sh
16+# 2. each project store is copied (git clone --bare --no-hardlinks) to $T/git/<name>.git, the test forge's
17+# git store; every export root that holds the project is imported into $T/data with that copy as the
18+# importer's 4th argument (PROJECT_STORE), and the project gets a row in $T/RIDS.md
19+# 3. a signed patch reaches fixrepo through `interplane patch --yes` (as patch/tests/e2e.sh step 2)
20+# 4. STORE counts from the scratch store itself, compared with the importer's ITEM lines
21+# 5. FORGE counts from the JSON list (every page), compared with the store; item types; the first
22+# and last five items as JSON and HTML; the raw .patch/.diff/.bundle routes byte for byte
23+# 6. the signed patch still shows author.did, imported null, status open
24+# 7. READONLY real stores and export: differences=<n> fail=<n> shared_mtime_moved=<n>, then the last line:
25+# E2E-IMPORT: pass=<n> fail=<n> importer=<sha12> forge=<sha12>[+dirty] shared_mtime_moved=<n>
26+# Usage: bash patch/tests/e2e-import.sh (it takes the CPU pool lock itself, per command: E2E_IMPORT_LOCK,
27+# default ~/handoffs/hive/queen/pool-14-15.lock, around the forge build of lib.sh, the importer build, each
28+# import, the tool build and the bundle-diff git runs; set it empty to take no lock)
29+# Environment: GHIMPORT_REPO (the import lane's clone), GHIMPORT_REF (ghimport/r1), EXPORT_ROOTS (the
30+# <gh owner> folders of the export, space separated; each one's parent holds MANIFEST.sha256),
31+# PROJECT_STORE_ROOT (~/interplane-store-owner/projects, read only: the store of project <name> is
32+# <root>/<name>/repo.git, the owner-signed Interplane store; its scratch copy is what the importer and the
33+# test forge both read),
34+# E2E_IMPORT_PROJECTS ("omega-mv atlas"), PATCH_TEST_PORT (19331), PATCH_TEST_CORES (14),
35+# E2E_OUT=<dir> keeps the importer logs, the count lines (counts.txt), the store rows and the JSON and
36+# HTML answers; KEEP=1 keeps the scratch folder.
37+# E2E_IMPORT_STEPS=store stops after step 4 (steps 5-6 NOT_RUN, exit 3).
38+# Exit 0 only with fail=0; 3 with a NOT_RUN line when the importer source, the export or a project's
39+# store repo is absent.
40+GHIMPORT_REPO=${GHIMPORT_REPO:-$HOME/work/lanes/gh-import/interplane-forge}
41+GHIMPORT_REF=${GHIMPORT_REF:-ghimport/r1}
42+EXPORT_ROOTS=${EXPORT_ROOTS:-$HOME/handoffs/github-import-20261117/export/drakestapleton $HOME/handoffs/github-import-20261117/export-aien/aien-dev}
43+PROJECT_STORE_ROOT=${PROJECT_STORE_ROOT:-$HOME/interplane-store-owner/projects}
44+LOCK=${E2E_IMPORT_LOCK-$HOME/handoffs/hive/queen/pool-14-15.lock}
45+PROJECTS=${E2E_IMPORT_PROJECTS:-omega-mv atlas}
46+STEPS=${E2E_IMPORT_STEPS:-all}
47+: "${PATCH_TEST_PORT:=19331}" "${PATCH_TEST_CORES:=14}"
48+export PATCH_TEST_PORT PATCH_TEST_CORES
49+case ${E2E_OUT:-} in ''|/*) ;; *) E2E_OUT=$PWD/$E2E_OUT;; esac
50+
51+# ---- what must exist before anything is built
52+notrun() { echo "NOT_RUN $*"; exit 3; }
53+ISHA=$(git -C "$GHIMPORT_REPO" rev-parse --verify -q "$GHIMPORT_REF^{commit}" 2>/dev/null) \
54+ || notrun "importer source: no commit $GHIMPORT_REF in $GHIMPORT_REPO"
55+git -C "$GHIMPORT_REPO" cat-file -e "$ISHA:tools/ghimport/build.sh" 2>/dev/null \
56+ || notrun "importer source: $GHIMPORT_REF ($ISHA) has no tools/ghimport/build.sh"
57+ROOTS=
58+for r in $EXPORT_ROOTS; do
59+ [ -d "$r" ] && [ -f "$r/../MANIFEST.sha256" ] && ROOTS="$ROOTS $(cd "$r" && pwd)"
60+done
61+for p in $PROJECTS; do
62+ found=
63+ for r in $ROOTS; do [ -f "$r/$p/pulls.json" ] && found=1; done
64+ [ -n "$found" ] || notrun "export: no <root>/$p/pulls.json with a MANIFEST.sha256 above the root, roots: $EXPORT_ROOTS"
65+ git --git-dir="$PROJECT_STORE_ROOT/$p/repo.git" rev-parse -q --verify HEAD^{commit} > /dev/null 2>&1 \
66+ || notrun "project store: $PROJECT_STORE_ROOT/$p/repo.git is absent or has no HEAD commit"
67+done
68+PSR=$(cd "$PROJECT_STORE_ROOT" && pwd)
69+# L CMD...: CMD under the CPU pool lock, held for that command only
70+L() { if [ -n "$LOCK" ]; then flock "$LOCK" "$@"; else "$@"; fi; }
71+# rolist: every file and folder of the real project stores, the export project folders and the export roots'
72+# own files, with size, mtime (ns), inode, hard-link count and type; taken before anything runs and again at
73+# the end (the run must leave them as they were: it works on scratch copies only)
74+rolist() {
75+ { for p in $PROJECTS; do
76+ find "$PSR/$p/repo.git" -printf '%p\t%s\t%T@\t%i\t%n\t%y\n'
77+ for r in $ROOTS; do [ -d "$r/$p" ] && find "$r/$p" -printf '%p\t%s\t%T@\t%i\t%n\t%y\n'; done
78+ done
79+ for r in $ROOTS; do find "$(dirname "$r")" -maxdepth 1 -type f -printf '%p\t%s\t%T@\t%i\t%n\t%y\n'; done; } | LC_ALL=C sort -u
80+}
81+ROB=$(command mktemp /tmp/prsf-c-ro.XXXXXX); rolist > "$ROB"
82+
83+# ---- the test forge of lib.sh. Its scratch folder is made with mktemp -d /tmp/forgepatch.XXXXXX; this
84+# run's scratch prefix is /tmp/prsf-c, so mktemp is shadowed while lib.sh is read (lib.sh is not edited)
85+# the forge the last line names: the clone's HEAD when lib.sh builds the test copy (right below), +dirty
86+# when the tree differs from it then; the build reads the working tree
87+FROOT=$(cd "$(dirname "$0")/../.." && pwd)
88+FHEAD=$(git -C "$FROOT" rev-parse --short=12 HEAD 2>/dev/null)$([ -n "$(git -C "$FROOT" status --porcelain 2>/dev/null)" ] && echo +dirty)
89+trap 'rm -f "$ROB"; echo "E2E-IMPORT: pass=0 fail=1 importer=${ISHA:0:12} forge=$FHEAD (stopped in lib.sh: the forge test copy was not built)"' EXIT
90+mktemp() { command mktemp -d "${E2E_IMPORT_SCRATCH:-/tmp/prsf-c}.XXXXXX"; }
91+[ -n "$LOCK" ] && { exec 9>> "$LOCK"; flock 9; }
92+. "$(dirname "$0")/lib.sh"
93+[ -n "$LOCK" ] && { flock -u 9; exec 9>&-; }
94+unset -f mktemp
95+mv "$ROB" "$T/ro.before"
96+# rodiff BEFORE AFTER: one line per differing path, "<NOTE|FAIL>\t<path>\t<why>\t<before>\t<after>". NOTE: a
97+# regular file present before and after with the same size and inode and more than one hard link, whose mtime
98+# (or link count) moved (shared with other repositories); every other difference (size, inode, type, added,
99+# removed, an mtime change on a file with one link) is FAIL
100+rodiff() {
101+ awk -F'\t' 'function d(l, x) { split(l, x, "\t"); return x[2] " bytes, mtime " x[3] ", inode " x[4] ", " x[5] " links" }
102+ NR == FNR { B[$1] = $0; next } { A[$1] = $0 }
103+ END {
104+ for (p in B) if (!(p in A)) print "FAIL\t" p "\tremoved\t" d(B[p]) "\tabsent"
105+ for (p in A) {
106+ if (!(p in B)) { print "FAIL\t" p "\tadded\tabsent\t" d(A[p]); continue }
107+ if (A[p] == B[p]) continue
108+ split(B[p], b, "\t"); split(A[p], a, "\t")
109+ k = (b[2] == a[2] && b[4] == a[4] && b[6] == "f" && a[6] == "f" && (b[5] > 1 || a[5] > 1)) ? "NOTE" : "FAIL"
110+ w = (b[2] != a[2]) ? "size" : (b[4] != a[4]) ? "inode" : (b[6] != a[6]) ? "type" : (b[3] != a[3]) ? "mtime" : "links"
111+ print k "\t" p "\t" w "\t" d(B[p]) "\t" d(A[p])
112+ }
113+ }' "$1" "$2" | LC_ALL=C sort -t "$(printf '\t')" -k2,2
114+}
115+# rocheck: the listing again, compared with the first; one line READONLY ... and RO_SHARED for the last line
116+RO_SHARED=0
117+rocheck() {
118+ local n k f w b a nd nf
119+ rolist > "$T/ro.after"
120+ n=$(wc -l < "$T/ro.before")
121+ rodiff "$T/ro.before" "$T/ro.after" > "$T/ro.changed"
122+ nd=$(wc -l < "$T/ro.changed"); nf=$(grep -c '^FAIL' "$T/ro.changed"); RO_SHARED=$(grep -c '^NOTE' "$T/ro.changed")
123+ [ "$nd" = 0 ] && ok "read only: all $n entries under the real stores, the export project folders and the export roots' files kept size, mtime (ns), inode and link count"
124+ while IFS=$'\t' read -r k f w b a; do
125+ if [ "$k" = NOTE ]; then say "NOTE shared inode (${a##*, }) $w moved, outside this run: $f $b -> $a"
126+ else bad "read only: $f changed ($w): before $b; after $a"; fi
127+ done < <(grep '^FAIL' "$T/ro.changed" | head -20; grep '^NOTE' "$T/ro.changed" | head -20)
128+ [ "$nf" -gt 20 ] && { bad "read only: $((nf - 20)) more changed entries (FAIL each, all in ro.changed)"; FAIL=$((FAIL + nf - 21)); }
129+ [ "$RO_SHARED" -gt 20 ] && say "NOTE read only: $((RO_SHARED - 20)) more shared-inode entries are not named here (all in ro.changed)"
130+ say "READONLY real stores and export: differences=$nd fail=$nf shared_mtime_moved=$RO_SHARED"
131+ [ -n "${E2E_OUT:-}" ] && [ "$nd" != 0 ] && cp "$T/ro.changed" "$OUT/"
132+ return 0
133+}
134+OUT=${E2E_OUT:-$T/out}
135+mkdir -p "$OUT/json" "$OUT/html"
136+: > "$OUT/counts.txt"
137+say() { echo "$*"; echo "$*" >> "$OUT/counts.txt"; }
138+jget() { : > "$T/body"; : > "$T/hdr"; curl -s -o "$T/body" -D "$T/hdr" -w '%{http_code}' -H 'Accept: application/json' "$B$1"; }
139+hget() { : > "$T/body"; : > "$T/hdr"; curl -s -o "$T/body" -D "$T/hdr" -w '%{http_code}' -H 'Accept: text/html' "$B$1"; }
140+rawget() { : > "$T/raw"; : > "$T/hdr"; curl -s -o "$T/raw" -D "$T/hdr" -w '%{http_code}' "$B$1"; }
141+starts() { head -c 200 "$1" | tr '\n' '|'; }
142+# cmpcounts LABEL ANAME "k=v ..." BNAME "k=v ...": one PASS/FAIL line per key of the first list
143+cmpcounts() {
144+ local kv k va vb
145+ for kv in $3; do
146+ k=${kv%%=*}; va=${kv#*=}; vb=$(printf '%s\n' $5 | sed -n "s/^$k=//p")
147+ if [ "$va" = "$vb" ]; then ok "$1 $k: $2 $va = $4 $vb"; else bad "$1 $k: $2 $va, $4 ${vb:-absent}"; fi
148+ done
149+}
150+# rawsame PATH FILE LABEL WHAT: the raw route answers 200 with exactly the bytes of FILE
151+rawsame() {
152+ local c; c=$(rawget "$1")
153+ if [ "$c" = 200 ] && cmp -s "$T/raw" "$2"; then ok "$3: GET $1 200, $(wc -c < "$2") bytes, byte-equal to $4"
154+ else bad "$3: GET $1 -> $c, $(wc -c < "$T/raw") bytes; want 200 and the $(wc -c < "$2") bytes of $4; $(cmp "$T/raw" "$2" 2>&1 | head -1); answer starts: $(starts "$T/raw")"; fi
155+}
156+# rawcode PATH STATUS LABEL: the raw route answers exactly that status
157+rawcode() {
158+ local c; c=$(rawget "$1")
159+ if [ "$c" = "$2" ]; then ok "$3: GET $1 $c"; else bad "$3: GET $1 -> $c, want $2; answer starts: $(starts "$T/raw")"; fi
160+}
161+
162+echo "== 1. the importer of $GHIMPORT_REF"
163+mkdir -p "$T/imp"
164+git -C "$GHIMPORT_REPO" archive "$ISHA" tools/ghimport | tar -x -C "$T/imp"
165+GI=$T/imp/bin/ghimport
166+if OMV="$OMV" OMC="$OMC" L taskset -c "$CORES" nice -n 10 sh "$T/imp/tools/ghimport/build.sh" "$T/imp/bin" > "$OUT/importer-build.log" 2>&1 && [ -x "$GI" ]; then
167+ ok "importer built from $GHIMPORT_REF with its build.sh, ghimport sha256 $(sha256sum < "$GI" | cut -c1-16)"
168+else
169+ bad "importer build: $(tail -3 "$OUT/importer-build.log" | tr '\n' ' ')"
170+ echo "E2E-IMPORT: pass=$PASS fail=$FAIL importer=${ISHA:0:12} forge=$FHEAD shared_mtime_moved=$RO_SHARED"; exit 1
171+fi
172+say "IMPORTER commit=$ISHA ref=$GHIMPORT_REF repo=$GHIMPORT_REPO"
173+
174+echo "== 2. import into the scratch store"
175+# The importer (r2) binds REFS.txt, the export root's file of every mirror ref, to a ./REFS.txt line of
176+# MANIFEST.sha256. An export made before r2 has no such line, and the importer refuses the run (exit 2)
177+# after storing the pulls.json items. As tools/ghimport/tests/e2e.sh does, the line is added, but to a
178+# scratch stand-in root: $T/x/r<k>/ holds copies of MANIFEST.sha256 and REFS.txt and a symlink per
179+# project folder to the real one (read only), so no export byte is copied or written.
180+k=0; SROOTS=
181+for r in $ROOTS; do
182+ k=$((k+1)); x=$T/x/r$k; o=$(basename "$r"); mkdir -p "$x/$o"
183+ cp "$r/../MANIFEST.sha256" "$x/"
184+ [ -f "$r/../REFS.txt" ] && cp "$r/../REFS.txt" "$x/"
185+ if [ -f "$x/REFS.txt" ] && ! grep -q ' \./REFS\.txt$' "$x/MANIFEST.sha256"; then
186+ (cd "$x" && sha256sum ./REFS.txt >> MANIFEST.sha256)
187+ say "NOTE $(dirname "$r")/MANIFEST.sha256 has no ./REFS.txt line (export from before importer r2): added to the stand-in copy $x/MANIFEST.sha256"
188+ fi
189+ for p in $PROJECTS; do [ -d "$r/$p" ] && ln -s "$r/$p" "$x/$o/$p"; done
190+ SROOTS="$SROOTS $r=$x/$o"
191+done
192+i=0
193+for p in $PROJECTS; do
194+ i=$((i+1)); rid=zImportedRepo$(printf "\\$(printf '%03o' $((64+i)))")11111111111111
195+ # a self-contained scratch copy of the real store (objects copied, no hard links, no alternates): the test
196+ # forge's git store AND the importer's PROJECT_STORE, so no git run of this test can touch the real store
197+ # (git freshens the mtime of a pack that already holds an object it is asked to write, through alternates too)
198+ RS=$PSR/$p/repo.git; PG=$T/git/$p.git
199+ br=$(git --git-dir="$RS" symbolic-ref --short HEAD 2>/dev/null || echo main)
200+ rm_=$(git --git-dir="$RS" rev-parse "refs/heads/$br" 2>/dev/null)
201+ L git clone -q --bare --no-hardlinks "$RS" "$PG" || { echo "STORE COPY FAILED $RS"; exit 1; }
202+ cm=$(git --git-dir="$PG" rev-parse "refs/heads/$br" 2>/dev/null)
203+ say "PROJECT $p store=$RS $br=$rm_ copy=$PG $br=$cm"
204+ check "$(git --git-dir="$PG" symbolic-ref --short HEAD 2>/dev/null) $cm" "$br $rm_" "$p scratch store copy: HEAD branch $br and its commit equal the real store's"
205+ check "$([ -e "$PG/objects/info/alternates" ] && echo present || echo absent)" absent "$p scratch store copy has no objects/info/alternates"
206+ if L git --git-dir="$PG" fsck --no-progress --connectivity-only > "$T/fsck.$p" 2>&1; then ok "$p scratch store copy: git fsck --connectivity-only passes"
207+ else bad "$p scratch store copy: git fsck --connectivity-only failed: $(head -3 "$T/fsck.$p" | tr '\n' ' ')"; fi
208+ git clone -q --bare --shared "$PG" "$T/store/$rid" || { echo "CLONE FAILED $PG"; exit 1; }
209+ echo "| $p | rad:$rid | $br | - |" >> "$T/RIDS.md"
210+ n=0
211+ for rs in $SROOTS; do
212+ r=${rs%%=*}; s=${rs#*=}
213+ [ -f "$r/$p/pulls.json" ] || continue
214+ n=$((n+1)); log=$OUT/import.$p.$n.log
215+ L taskset -c "$CORES" nice -n 10 "$GI" import "$s/$p" "$p" "$T/data" "$PG" > "$log" 2>&1; rc=$?
216+ say "IMPORT $p <- $r/$p (as $s/$p) rc=$rc $(grep '^RESULT' "$log" | tail -1)"
217+ # the importer names the store main it derived from (r2 review 3): RESULT ... project_main=<store path>
218+ # <ref> <sha> ...; it must be this store's HEAD branch, the store the test forge reads too
219+ pm=$(grep '^RESULT ' "$log" | tail -1 | sed -n 's/.* project_main=\([^ ]*\) \([^ ]*\) \([0-9a-f]\{40\}\)\( .*\)\{0,1\}$/\1 \2 \3/p')
220+ sm=$(git --git-dir="$PG" rev-parse "refs/heads/$br" 2>/dev/null)
221+ say "MAIN $p store $br=$sm importer project_main=${pm:-absent}"
222+ check "$pm" "$PG refs/heads/$br $sm" "$p: the importer's project_main is this store's $br"
223+ # 1 = some item skipped (its reason is on its ITEM line, quoted below): what the forge must show is what
224+ # was stored, so a skip is reported, not failed; 2 (run refused) and 3 (an item differs) are failures
225+ case $rc in
226+ 0) ok "import $r/$p: exit 0 (every item new or unchanged)";;
227+ 1) ok "import $r/$p: exit 1 (some item skipped; the ITEM skip lines are quoted below)";;
228+ *) bad "import $r/$p: exit $rc: $(grep -v '^ITEM new \|^RESULT' "$log" | head -3 | tr '\n' '|')";;
229+ esac
230+ done
231+done
232+# what the importer said beyond "new": skips, refusals, nonzero orphan counts of RESULT, and every line
233+# that is not ITEM, RESULT or the three lines of the import statement (STATEMENT, SIGN, VERIFY)
234+for f in "$OUT"/import.*.log; do
235+ grep -E '^ITEM (skip|refused) ' "$f"
236+ grep -E '^RESULT ' "$f" | grep -E 'orphan_[a-z_]+=[1-9]' | sed "s|^|$(basename "$f"): |"
237+ grep -v -E '^(ITEM |RESULT |STATEMENT |SIGN |VERIFY: )' "$f"
238+done > "$OUT/import-notable.txt"
239+say "IMPORTER-NOTES lines=$(wc -l < "$OUT/import-notable.txt") (ITEM skip/refused, RESULT with orphans, other output; first 40 below, all in import-notable.txt)"
240+head -40 "$OUT/import-notable.txt" | sed 's/^/ | /'
241+grep -h -E '^(STATEMENT |SIGN |VERIFY: )' "$OUT"/import.*.log > "$OUT/import-statements.txt"
242+
243+echo "== 3. a signed patch through interplane patch --yes"
244+start
245+mkdir -p "$T/tool" "$T/home"
246+TOOL=$T/tool/interplane-linux-aarch64
247+if OMC="$OMC" L taskset -c "$CORES" nice -n 19 sh tools/bring/build.sh linux "$T/tool" > "$T/tool.build" 2>&1; then
248+ ok "tool built: tools/bring/build.sh linux, ${TOOL##*/} sha256 $(sha256sum < "$TOOL" | cut -c1-16)"
249+else bad "tool build: $(tail -3 "$T/tool.build" | tr '\n' ' ')"; fi
250+newclone tc
251+commitf "$T/tc" "docs/e2e.md" "# End to end" "docs: add the e2e page"
252+commitf "$T/tc" "src/e2e.txt" "e2e source line" "src: e2e line, the patch title"
253+KEPT=$(kept)
254+(cd "$T/tc" && env -i HOME="$T/home" INTERPLANE_BASE="$B" "$TOOL" patch --yes "$OWNER/fixrepo") > "$OUT/tool.out" 2>&1; rc=$?
255+URL=$(sed -n 's/^Patch page: //p' "$OUT/tool.out")
256+PID16=${URL##*/}
257+if [ "$rc" = 0 ] && [ "$(kept)" = $((KEPT+1)) ] && [ "$URL" = "$B$R/patches/$PID16" ] && [ -f "$T/home/.interplane/key" ]; then
258+ ok "interplane patch --yes: exit 0, one patch kept, page $URL, key made in the scratch HOME"
259+else bad "interplane patch --yes: rc $rc, kept $(kept) (was $KEPT), out: $(tr '\n' '|' < "$OUT/tool.out")"; fi
260+
261+echo "== 4. store-side counts"
262+PFX='{"kind":"github-import","owner":"'
263+# storescan PROJECT: one row per id of the index into $OUT/store.<project>.tsv, in index order:
264+# id, kind (signed|imported|other), status, code, derived, bytes of the code file, and whether a
265+# .patch, .diff and .bundle can exist, then the GitHub source of the statement, then the reason no diff
266+# can be served ("-" when one can; SPEC 6 diff_unavailable): a bundle's diff exists only when it has a base
267+# file and that commit is in the project's git store (the scratch copy the test forge reads)
268+storescan() {
269+ local p=$1 d=$T/data/patches/$OWNER/$1 id kind st cd dv by fp fd fb gh du
270+ : > "$OUT/store.$p.tsv"
271+ [ -f "$d/index" ] || return 0
272+ while read -r id; do
273+ kind=other; st=-; cd=none; dv=0; by=0; fp=0; fd=0; fb=0; gh=-; du=no-code-file
274+ if [ -f "$d/$id/meta" ]; then kind=signed; st=open
275+ elif [ "$(head -c ${#PFX} "$d/$id/source.json" 2>/dev/null)" = "$PFX" ]; then
276+ st=$(cat "$d/$id/status" 2>/dev/null)
277+ case $st in
278+ open|closed|merged)
279+ [ "$(wc -c < "$d/$id/status")" = $((${#st}+1)) ] && [ "$(wc -c < "$d/$id/head" 2>/dev/null)" = 41 ] \
280+ && grep -qxE '[0-9a-f]{40}' "$d/$id/head" && kind=imported;;
281+ *) st=-;;
282+ esac
283+ grep -q '"state_derived":true' "$d/$id/source.json" && dv=1
284+ gh="$(sed -n 2p "$d/$id/statement" 2>/dev/null)#$(sed -n 3p "$d/$id/statement" 2>/dev/null)"
285+ fi
286+ if [ -f "$d/$id/mbox" ]; then cd=mbox; by=$(stat -c %s "$d/$id/mbox"); fp=1; fd=1; du=-
287+ elif [ -f "$d/$id/head.bundle" ]; then
288+ cd=bundle; by=$(stat -c %s "$d/$id/head.bundle"); fb=1
289+ if [ ! -f "$d/$id/base" ]; then du=no-base
290+ elif git --git-dir="$T/git/$p.git" cat-file -e "$(cat "$d/$id/base")^{commit}" 2>/dev/null; then fd=1; du=-
291+ else du=base-not-in-store; fi
292+ fi
293+ printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$id" "$kind" "$st" "$cd" "$dv" "$by" "$fp" "$fd" "$fb" "$gh" "$du" >> "$OUT/store.$p.tsv"
294+ done < <(grep -xE '[0-9a-f]{16}' "$d/index" | awk '!seen[$0]++')
295+}
296+declare -A SC
297+for p in $PROJECTS fixrepo; do
298+ storescan "$p"
299+ SC[$p]=$(awk -F'\t' '$2!="other"{s[$3]++; c[$4]++; dv+=$5; ds[$3]+=$5; if($4=="none") ns[$3]++} END{printf "open=%d closed=%d merged=%d mbox=%d bundle=%d none=%d derived=%d derived_open=%d derived_closed=%d derived_merged=%d none_open=%d none_closed=%d none_merged=%d", s["open"],s["closed"],s["merged"],c["mbox"],c["bundle"],c["none"],dv,ds["open"],ds["closed"],ds["merged"],ns["open"],ns["closed"],ns["merged"]}' "$OUT/store.$p.tsv")
300+ oth=$(awk -F'\t' '$2=="other"' "$OUT/store.$p.tsv" | wc -l)
301+ say "STORE $p ${SC[$p]}$([ "$oth" = 0 ] || echo " other=$oth")"
302+ [ "$p" = fixrepo ] && continue
303+ # ITEM lines of proposals ("proposal") and of code-only proposals (G7, "code-only": state derived); the
304+ # code word "-" or "on-main" means no code file (SPEC code "none")
305+ IC=$(cat "$OUT"/import."$p".*.log | awk '$1=="ITEM"&&($2=="new"||$2=="same")&&($3=="proposal"||$3=="code-only"){
306+ s[$6]++; k=($7=="mbox"||$7=="bundle")?$7:"none"; c[k]++; if(k=="none") ns[$6]++; if($3=="code-only"){dv++; ds[$6]++}}
307+ END{printf "open=%d closed=%d merged=%d mbox=%d bundle=%d none=%d derived=%d derived_open=%d derived_closed=%d derived_merged=%d none_open=%d none_closed=%d none_merged=%d",
308+ s["open"],s["closed"],s["merged"],c["mbox"],c["bundle"],c["none"],dv,ds["open"],ds["closed"],ds["merged"],ns["open"],ns["closed"],ns["merged"]}')
309+ say "ITEMS $p $IC | $(cat "$OUT"/import."$p".*.log | awk '$1=="ITEM"{n[$3" "$2]++} END{for(k in n) printf "%s=%d ", k, n[k]}')"
310+ cmpcounts "$p proposals" "importer ITEM lines" "$IC" store "${SC[$p]}"
311+done
312+
313+FSHA=$FHEAD
314+if [ "$STEPS" = store ]; then
315+ say "NOT_RUN steps 5-6 (forge JSON, HTML and raw routes of imported items): E2E_IMPORT_STEPS=store"
316+ rocheck
317+ say "WALL seconds=$SECONDS"
318+ say "E2E-IMPORT: pass=$PASS fail=$FAIL importer=${ISHA:0:12} forge=$FSHA shared_mtime_moved=$RO_SHARED"
319+ [ "$FAIL" = 0 ] && exit 3; exit 1
320+fi
321+
322+echo "== 5. forge-side counts (JSON only)"
323+LISTKEYS='["id","title","status","state_derived","author","imported","base_commit","head_commit","commits","files","bytes","code","created","comments_count","path","patch","diff","diff_unavailable","bundle"]'
324+DOCKEYS='["id","title","description","status","state_derived","author","imported","base_commit","head_commit","commits","files","bytes","code","mbox_sha256","opened","closed","merge","labels","comments","thread_truncated","thread_reason","created","path","patch","diff","diff_unavailable","bundle"]'
325+# forgewalk PROJECT: every page of the JSON list, following next; the items (one a line) into
326+# $T/items.<project>.jsonl, each page without its items into $T/tops.<project>.jsonl; PAGES
327+forgewalk() {
328+ local p=$1 next="/$OWNER/$1/patches?page=1" n=0 c max
329+ max=$(( $(wc -l < "$OUT/store.$p.tsv") / 30 + 3 ))
330+ : > "$T/items.$p.jsonl"; : > "$T/tops.$p.jsonl"; PAGES=0
331+ while [ -n "$next" ]; do
332+ n=$((n+1))
333+ if [ "$n" -gt "$max" ]; then bad "$p list: the next links did not end after $max pages (last: $next)"; return 1; fi
334+ c=$(jget "$next")
335+ if [ "$c" != 200 ] || ! jq -e 'type=="object" and (.patches|type)=="array"' "$T/body" > /dev/null 2>&1; then
336+ bad "$p list: GET $next (Accept: application/json) -> $c; answer starts: $(starts "$T/body")"; return 1
337+ fi
338+ cp "$T/body" "$OUT/json/list.$p.$n.json"
339+ jq -c '.patches[]' "$T/body" >> "$T/items.$p.jsonl"
340+ jq -c 'del(.patches)' "$T/body" >> "$T/tops.$p.jsonl"
341+ next=$(jq -r '.next // empty' "$T/body")
342+ case $next in http://*|https://*) next=/${next#*://*/};; esac
343+ done
344+ PAGES=$n
345+}
346+for p in $PROJECTS fixrepo; do
347+ S=$OUT/store.$p.tsv; I=$T/items.$p.jsonl; d=$T/data/patches/$OWNER/$p; RP=/$OWNER/$p/patches
348+ if ! forgewalk "$p"; then say "FORGE $p NOT_COUNTED (the list walk stopped on page $((PAGES+1)))"; continue; fi
349+ FC=$(jq -s -r 'def n(f): map(select(f))|length; "open=\(n(.status=="open")) closed=\(n(.status=="closed")) merged=\(n(.status=="merged")) mbox=\(n(.code=="mbox")) bundle=\(n(.code=="bundle")) none=\(n(.code=="none")) derived=\(n(.state_derived==true))" + ([("open","closed","merged") as $s|" derived_\($s)=\(n(.state_derived==true and .status==$s))"]|add) + ([("open","closed","merged") as $s|" none_\($s)=\(n(.code=="none" and .status==$s))"]|add)' "$I")
350+ say "FORGE $p $FC pages=$PAGES items=$(wc -l < "$I")"
351+ cmpcounts "$p items" "forge JSON" "$FC" store "${SC[$p]}"
352+ tot=$(awk -F'\t' '$2!="other"' "$S" | wc -l)
353+ check "$(jq -s -c 'map(.count)|unique' "$T/tops.$p.jsonl")" "[$tot]" "$p count of every page = items of the store"
354+ want=$(printf '%s\n' ${SC[$p]} | awk -F= '{v[$1]=$2} END{printf "{\"closed\":%d,\"merged\":%d,\"open\":%d}", v["closed"], v["merged"], v["open"]}')
355+ check "$(jq -s -c -S 'map(.states)|unique|.[]' "$T/tops.$p.jsonl" | tr '\n' ' ' | sed 's/ $//')" "$want" "$p top-level states of every page = store"
356+ check "$(jq -s -c 'map(keys_unsorted as $k|(($k|index("states"))//-9)-($k|index("count")))|unique' "$T/tops.$p.jsonl")" "[1]" "$p states is the key after count"
357+ check "$(jq -s -c 'map(keys_unsorted as $k|(($k|index("damaged"))//-9)-($k|index("states")))|unique' "$T/tops.$p.jsonl")" "[1]" "$p damaged is the key after states"
358+ check "$(jq -s -c 'map(.damaged)|unique' "$T/tops.$p.jsonl")" "[0]" "$p damaged of every page is 0 (every index line of the import loads; count + damaged = $(grep -xE '[0-9a-f]{16}' "$d/index" 2>/dev/null | wc -l) index lines)"
359+ check "$tot" "$(grep -xE '[0-9a-f]{16}' "$d/index" 2>/dev/null | awk '!seen[$0]++' | wc -l)" "$p count = index lines of the store"
360+ # why no diff can be served, tallied from the list rows and from the store (SPEC 6 diff_unavailable)
361+ DJ=$(jq -s -r 'def n(f): map(select(f))|length; "link=\(n(.diff!=null)) base-not-in-store=\(n(.diff_unavailable=="base-not-in-store")) no-base=\(n(.diff_unavailable=="no-base")) no-code-file=\(n(.diff_unavailable=="no-code-file")) too-large=\(n(.diff_unavailable=="too-large"))"' "$I")
362+ DS=$(awk -F'\t' '$2!="other"{c[$11]++} END{printf "link=%d base-not-in-store=%d no-base=%d no-code-file=%d too-large=%d", c["-"], c["base-not-in-store"], c["no-base"], c["no-code-file"], 0}' "$S")
363+ say "DIFF $p $DJ"
364+ cmpcounts "$p diff links" "forge JSON" "$DJ" store "$DS"
365+ # every item against its store row, in the list's order (newest first: the index read backwards)
366+ awk -F'\t' '$2!="other"' "$S" | tac > "$T/want.rows"
367+ jq -r '[.id, (if .author!=null then "signed" else "imported" end), .status, .code, (if .state_derived==true then 1 else 0 end), .bytes,
368+ (if .patch then 1 else 0 end), (if .diff then 1 else 0 end), (if .bundle then 1 else 0 end),
369+ (if (.imported|type)=="object" then "\(.imported.owner)/\(.imported.repo)#\(.imported.number)" else "-" end),
370+ (if .diff!=null and .diff_unavailable==null then "-" elif .diff==null and (.diff_unavailable|type)=="string" then .diff_unavailable else "link-and-reason-disagree" end)]|@tsv' "$I" > "$T/got.rows" 2> "$T/jq.err"
371+ if cmp -s "$T/want.rows" "$T/got.rows"; then
372+ ok "$p: all $tot items newest first, each with the store's id, kind, status, code, derived, bytes, patch/diff/bundle links, GitHub source and diff_unavailable (null with a diff link, else its reason)"
373+ else
374+ bad "$p: items differ from the store rows (id kind status code derived bytes patch diff bundle source diff_unavailable; < store, > forge): $(diff "$T/want.rows" "$T/got.rows" | grep '^[<>]' | head -4 | tr '\t\n' ' |') $(head -c 200 "$T/jq.err")"
375+ fi
376+ [ -s "$I" ] && check "$(jq -c 'keys_unsorted' "$I" | sort -u)" "$LISTKEYS" "$p list item keys in the order of SPEC 3 and 6"
377+ wrong=$(jq -s -c '[.[]|select(((.state_derived|type)=="boolean" and (.bytes|type)=="number" and (
378+ (.author==null and (.imported|type)=="object" and .imported.from=="github" and (.imported.owner|type)=="string"
379+ and (.imported.repo|type)=="string" and (.imported.number|type)=="number" and (.imported.url|type)=="string"
380+ and (.imported.login|type|IN("string","null")) and .commits==null and .files==null)
381+ or (.imported==null and (.author|type)=="object" and (.author.did|type)=="string" and (.commits|type)=="number"
382+ and (.files|type)=="number" and .state_derived==false)))|not)|{id,state_derived,author,imported,commits,files,bytes}]' "$I" 2>&1)
383+ ni=$(jq -s 'map(select(.author==null))|length' "$I"); ns=$(jq -s 'map(select(.author!=null))|length' "$I")
384+ if [ "$wrong" = "[]" ]; then
385+ ok "$p: $ni imported items have author null, imported.from github, owner/repo/url strings, number a number, login string or null, commits and files null; $ns signed items have author.did and imported null"
386+ else bad "$p: items with other types than SPEC 3 says: $(printf '%s' "$wrong" | head -c 600)"; fi
387+ [ "$p" = fixrepo ] && continue
388+
389+ # the first five and the last five items: the page as JSON and as HTML
390+ for id in $( { head -5 "$I"; tail -5 "$I"; } | jq -r .id | awk '!seen[$0]++'); do
391+ row=$(jq -c --arg id "$id" 'select(.id==$id)' "$I" | head -1)
392+ path=$(jq -r .path <<< "$row"); lst=$(jq -r .status <<< "$row"); lcc=$(jq -r .comments_count <<< "$row")
393+ c=$(jget "$path"); cp "$T/body" "$OUT/json/patch.$p.$id.json"
394+ got=$(jq -r --argjson w "$DOCKEYS" '[.schema, .id, .status, (.comments|length|tostring), (([keys_unsorted[]|select(IN($w[]))]==$w)|tostring), (.thread_truncated|tostring), (.thread_reason|tostring), ((.diff_unavailable|tostring)==($r.diff_unavailable|tostring) and .diff==$r.diff|tostring)]|join(" ")' --argjson r "$row" "$T/body" 2>/dev/null)
395+ if [ "$c" = 200 ] && [ "$got" = "forge/patch/1 $id $lst $lcc true false null true" ]; then
396+ ok "$p sample $id JSON: GET $path 200, forge/patch/1, same id, status $lst as listed, $lcc comments as counted, keys in the order of SPEC 3 and 6, thread_truncated false with reason null, diff and diff_unavailable as in the list row"
397+ else
398+ bad "$p sample $id JSON: GET $path (Accept: application/json) -> $c; want \"forge/patch/1 $id $lst $lcc true false null true\" (schema id status comments keys-in-order thread_truncated thread_reason diff-as-listed), got \"$got\"; answer starts: $(starts "$T/body")"
399+ fi
400+ c=$(hget "$path"); cp "$T/body" "$OUT/html/patch.$p.$id.html"
401+ if [ "$c" = 200 ] && grep -qF 'Imported from GitHub' "$T/body" && ! grep -qF 'did:key:' "$T/body"; then
402+ ok "$p sample $id HTML: GET $path 200, says Imported from GitHub, no did:key:"
403+ else
404+ bad "$p sample $id HTML: GET $path (Accept: text/html) -> $c, Imported from GitHub: $(grep -cF 'Imported from GitHub' "$T/body") lines, did:key: $(grep -cF 'did:key:' "$T/body") lines; answer starts: $(starts "$T/body")"
405+ fi
406+ done
407+
408+ # the raw routes (SPEC 4): one mbox item, one bundle item with a diff, one without, one with no code
409+ mb=$(awk -F'\t' '$2=="imported"&&$4=="mbox"{print $1; exit}' "$S")
410+ if [ -n "$mb" ]; then
411+ rawsame "$RP/$mb.patch" "$d/$mb/mbox" "$p mbox item $mb .patch" "the stored mbox"
412+ if [ -f "$d/$mb/diff" ]; then rawsame "$RP/$mb.diff" "$d/$mb/diff" "$p mbox item $mb .diff" "the stored diff"
413+ else rawcode "$RP/$mb.diff" 404 "$p mbox item $mb .diff (the store has no diff file)"; fi
414+ rawcode "$RP/$mb.bundle" 404 "$p mbox item $mb .bundle (it has none)"
415+ else say "NOTE $p: the import made no mbox-backed item"; fi
416+ bd=; bn=
417+ for id in $(awk -F'\t' '$2=="imported"&&$4=="bundle"{print $1}' "$S"); do
418+ if [ -f "$d/$id/base" ] && [ -e "$T/git/$p.git" ] && git --git-dir="$T/git/$p.git" cat-file -e "$(cat "$d/$id/base")^{commit}" 2>/dev/null; then
419+ [ -n "$bd" ] || bd=$id
420+ else [ -n "$bn" ] || bn=$id; fi
421+ [ -n "$bd" ] && [ -n "$bn" ] && break
422+ done
423+ if [ -n "$bd" ]; then
424+ rawsame "$RP/$bd.bundle" "$d/$bd/head.bundle" "$p bundle item $bd .bundle" "the stored head.bundle"
425+ ct=$(hdr content-type); check "${ct%%;*}" application/octet-stream "$p bundle item $bd .bundle content type"
426+ rawcode "$RP/$bd.patch" 404 "$p bundle item $bd .patch (it has no mbox)"
427+ base=$(cat "$d/$bd/base"); head=$(cat "$d/$bd/head"); rm -rf "$T/bd.git"
428+ # the scratch repository borrows the objects of the SCRATCH store copy through alternates, as the forge's
429+ # work folder does: the same object set gives the same abbreviated ids on the index lines (a fetch of the
430+ # refs alone copies fewer objects and git abbreviates differently). A freshen can touch only the copy.
431+ if git clone -q --bare --shared "$T/git/$p.git" "$T/bd.git" 2> "$T/bd.err" \
432+ && L git -C "$T/bd.git" fetch -q "$d/$bd/head.bundle" '+refs/*:refs/bd/*' 2>> "$T/bd.err" \
433+ && L env GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null git -C "$T/bd.git" --attr-source=4b825dc642cb6eb9a060e54bf8d69288fbee4904 \
434+ -c core.attributesFile=/dev/null diff --no-color --no-ext-diff --no-textconv "$base...$head" > "$T/want.diff" 2>> "$T/bd.err"; then
435+ rawsame "$RP/$bd.diff" "$T/want.diff" "$p bundle item $bd .diff" "git diff --no-color --no-ext-diff --no-textconv $base...$head in a scratch repository on the scratch store copy's objects with the bundle"
436+ else bad "$p bundle item $bd .diff: the scratch repository could not make the diff to compare with: $(tail -2 "$T/bd.err" | tr '\n' ' ')"; fi
437+ rm -rf "$T/bd.git"
438+ else say "NOTE $p: the import made no bundle-backed item whose base is in the project's git store"; fi
439+ if [ -n "$bn" ]; then
440+ rawsame "$RP/$bn.bundle" "$d/$bn/head.bundle" "$p bundle item $bn .bundle" "the stored head.bundle"
441+ rawcode "$RP/$bn.diff" 404 "$p bundle item $bn .diff ($([ -f "$d/$bn/base" ] && echo "its base is not in the project's git store" || echo "it has no base"))"
442+ fi
443+ no=$(awk -F'\t' '$2=="imported"&&$4=="none"{print $1; exit}' "$S")
444+ if [ -n "$no" ]; then
445+ for x in patch diff bundle; do rawcode "$RP/$no.$x" 404 "$p item $no without a code file .$x"; done
446+ fi
447+ # code-only items (contract r2 G7: GitHub metadata unavailable, state derived): one of each derived state
448+ for st in open closed merged; do
449+ row=$(awk -F'\t' -v s="$st" '$2=="imported"&&$5==1&&$3==s{print; exit}' "$S")
450+ if [ -z "$row" ]; then say "NOTE $p: no code-only (derived) item with status $st in the store"; continue; fi
451+ id=$(cut -f1 <<< "$row"); cd=$(cut -f4 <<< "$row"); hd=$(cat "$d/$id/head"); path=/$OWNER/$p/patches/$id
452+ c=$(jget "$path"); cp "$T/body" "$OUT/json/patch.$p.$id.codeonly.json"
453+ got=$(jq -r '[.status, (.state_derived|tostring), (.imported.login|tostring), .code, (.imported.from|tostring)]|join(" ")' "$T/body" 2>/dev/null)
454+ if [ "$c" = 200 ] && [ "$got" = "$st true null $cd github" ]; then
455+ ok "$p code-only $st item $id JSON: 200, status $st, state_derived true, imported.login null, code $cd as stored"
456+ else bad "$p code-only $st item $id JSON: GET $path (Accept: application/json) -> $c; want \"$st true null $cd github\" (status state_derived imported.login code imported.from), got \"$got\"; answer starts: $(starts "$T/body")"; fi
457+ c=$(hget "$path"); cp "$T/body" "$OUT/html/patch.$p.$id.codeonly.html"
458+ h1=$(grep -cF 'code only' "$T/body"); h2=$(grep -cF 'did:key:' "$T/body")
459+ if [ "$cd" = none ]; then
460+ h3=$(grep -cF "$hd" "$T/body"); h4=$(grep -cF "$id.diff" "$T/body")
461+ if [ "$c" = 200 ] && [ "$h1" != 0 ] && [ "$h2" = 0 ] && [ "$h3" != 0 ] && [ "$h4" = 0 ]; then
462+ ok "$p code-only $st on-main item $id HTML: 200, says code only, names head $hd, no $id.diff link, no did:key:"
463+ else bad "$p code-only $st on-main item $id HTML: GET $path (Accept: text/html) -> $c; lines with: code only $h1 (want >0), head $hd $h3 (want >0), $id.diff $h4 (want 0), did:key: $h2 (want 0); answer starts: $(starts "$T/body")"; fi
464+ elif [ "$c" = 200 ] && [ "$h1" != 0 ] && [ "$h2" = 0 ]; then
465+ ok "$p code-only $st item $id ($cd) HTML: 200, says code only, no did:key:"
466+ else bad "$p code-only $st item $id ($cd) HTML: GET $path (Accept: text/html) -> $c; lines with: code only $h1 (want >0), did:key: $h2 (want 0); answer starts: $(starts "$T/body")"; fi
467+ done
468+ # a code-only item with a thread (comments matched to its number): the page shows the first comment
469+ tid=
470+ for id in $(awk -F'\t' '$2=="imported"&&$5==1{print $1}' "$S"); do [ -s "$d/$id/thread" ] && { tid=$id; break; }; done
471+ if [ -z "$tid" ]; then say "NOTE $p: no code-only item has a thread"
472+ else
473+ read -r tk _ tl _ < "$d/$tid/thread"
474+ bl=2; [ "$tk" = review-comment ] && bl=3
475+ snip=$(sed -n "$bl,$((bl+10))p" "$d/$tid/thread" | grep -oE '[A-Za-z0-9]+( [A-Za-z0-9]+){2,}' | head -1 | cut -c1-40)
476+ path=/$OWNER/$p/patches/$tid; lcc=$(jq -r --arg id "$tid" 'select(.id==$id)|.comments_count' "$I")
477+ c=$(jget "$path"); cp "$T/body" "$OUT/json/patch.$p.$tid.codeonly-thread.json"
478+ got=$(jq -r '[(.state_derived|tostring), (.comments|length|tostring), (.comments[0].login|tostring), (.comments[0].kind|tostring)]|join(" ")' "$T/body" 2>/dev/null)
479+ if [ "$c" = 200 ] && [ "${lcc:-0}" -gt 0 ] 2>/dev/null && [ "$got" = "true $lcc $tl $tk" ]; then
480+ ok "$p code-only item $tid with a thread JSON: 200, state_derived true, comments_count $lcc > 0, first comment $tk by $tl"
481+ else bad "$p code-only item $tid with a thread JSON: GET $path (Accept: application/json) -> $c; list comments_count ${lcc:-absent} (want > 0); want \"true $lcc $tl $tk\" (state_derived comments first-login first-kind), got \"$got\""; fi
482+ c=$(hget "$path"); cp "$T/body" "$OUT/html/patch.$p.$tid.codeonly-thread.html"
483+ h1=$(grep -cF "$tl" "$T/body"); h2=0; [ -n "$snip" ] && h2=$(grep -cF "$snip" "$T/body")
484+ if [ "$c" = 200 ] && [ "$h1" != 0 ] && { [ -z "$snip" ] || [ "$h2" != 0 ]; }; then
485+ ok "$p code-only item $tid with a thread HTML: 200, shows the first comment's login $tl$([ -n "$snip" ] && echo " and its text \"$snip\"")"
486+ else bad "$p code-only item $tid with a thread HTML: GET $path (Accept: text/html) -> $c; lines with login $tl: $h1, with \"$snip\": $h2 (want both > 0)"; fi
487+ fi
488+done
489+
490+echo "== 6. the signed patch is as before"
491+TDID=$(did "$T/home/.interplane/key.pub" 2> /dev/null)
492+c=$(jget "$R/patches/$PID16"); cp "$T/body" "$OUT/json/patch.fixrepo.signed.json"
493+got=$(jq -r '[.status, (.imported|tostring), (.author.did|tostring)]|join(" ")' "$T/body" 2>/dev/null)
494+if [ -n "$PID16" ] && [ -n "$TDID" ] && [ "$c" = 200 ] && [ "$got" = "open null $TDID" ]; then
495+ ok "signed patch $PID16 JSON: 200, status open, imported null, author.did the tool's key"
496+else bad "signed patch JSON: GET $R/patches/$PID16 (Accept: application/json) -> $c; want \"open null $TDID\" (status imported author.did), got \"$got\"; answer starts: $(starts "$T/body")"; fi
497+got=$(jq -r --arg id "$PID16" 'select(.id==$id)|[.status, (.imported|tostring), (.author.did|tostring)]|join(" ")' "$T/items.fixrepo.jsonl" 2>/dev/null)
498+check "$got" "open null $TDID" "signed patch in the JSON list: status, imported, author.did"
499+c=$(hget "$R/patches/$PID16")
500+cp "$T/body" "$OUT/html/patch.fixrepo.signed.html"
501+if [ "$c" = 200 ] && ! grep -qF 'Imported from GitHub' "$T/body"; then
502+ ok "signed patch HTML: 200, does not say Imported from GitHub"
503+else bad "signed patch HTML: GET $R/patches/$PID16 -> $c, Imported from GitHub: $(grep -cF 'Imported from GitHub' "$T/body") lines (want 200 and 0)"; fi
504+
505+echo "== read only: the real project stores and the export"
506+rocheck
507+alive && ok "forged still answers" || bad "forged stopped: $(tail -3 "$T/forged.err" | tr '\n' ' ')"
508+
509+say "WALL seconds=$SECONDS"
510+say "E2E-IMPORT: pass=$PASS fail=$FAIL importer=${ISHA:0:12} forge=$FSHA shared_mtime_moved=$RO_SHARED"
511+[ "$FAIL" = 0 ]

patch/tests/e2e.sh

new file mode 100755
@@ -0,0 +1,122 @@
1+#!/bin/bash
2+# End-to-end loopback run of the git patch intake (contract interplane-connector r1, Change item 5;
3+# docs/API.md "Git patches", docs/BRING.md "patch"). HOST test on the Spark: a private copy of forged
4+# with scratch folders (patch/tests/lib.sh: fixture repository, data folder, git store, port), a
5+# throwaway key in a scratch HOME, the interplane program built from this tree. Nothing of the live
6+# forge, ~/git or ~/forge-data is written; the build reads the site's git store as lib.sh says.
7+# Steps, one line each:
8+# 1. an upload without a session, and one whose statement another key signed, are refused (403)
9+# and keep nothing
10+# 2. interplane patch --yes, run in a scratch clone with an empty environment, is accepted (exit 0)
11+# 3. the patch page, the JSON list, the JSON patch and the raw .patch and .diff routes answer
12+# 4. the raw mbox is byte-equal to git format-patch --stdout with the tool's flags
13+# 5. git am of the raw route onto the base in a fresh clone succeeds and gives the tool's tree
14+# Usage: PATCH_TEST_PORT=18488 PATCH_TEST_CORES=18 bash patch/tests/e2e.sh
15+# E2E_TARGET=x86linux builds and runs interplane-linux-x86_64 instead (on the AArch64 Spark it runs
16+# under qemu-x86_64 through binfmt); the default is linux (interplane-linux-aarch64).
17+# E2E_OUT=<dir> keeps the answers (upload texts, JSON, headers) there for docs/API.md examples;
18+# KEEP=1 keeps the temp folder. Exit 0 only when every step held.
19+. "$(dirname "$0")/lib.sh"
20+REPOF=$OWNER/fixrepo
21+OUT=${E2E_OUT:-$T/out}
22+mkdir -p "$OUT"
23+start
24+save() { cp "$T/body" "$OUT/$1"; tr -d '\r' < "$T/hdr" > "$OUT/$1.hdr"; }
25+
26+echo "== 1. unsigned uploads are refused"
27+newkey k1; newkey k2
28+signin k1 10.4.0.1 || exit 1
29+newclone w; commitf "$T/w" "notes/e2e.txt" "e2e line" "e2e: one note"; mkmbox "$T/w" origin/main
30+TITLE="E2E note"; DESC="Written by patch/tests/e2e.sh."; sigmake
31+KEPT=$(kept); s=$SES; SES=; C=$(upload); SES=$s; save refused-nosession.txt
32+refused "$C" 403 "sign in first: this request carries no session" "upload without a session"
33+KEPT=$(kept); sigmake "$T/k2"; C=$(upload); save refused-otherkey.txt
34+refused "$C" 403 "the signature does not verify for this session's key and this patch" "statement signed by a key that is not the session's"
35+
36+echo "== 2. interplane patch --yes from a scratch clone"
37+mkdir -p "$T/tool" "$T/home"
38+case ${E2E_TARGET:-linux} in
39+ linux) TOOL=$T/tool/interplane-linux-aarch64;;
40+ x86linux) TOOL=$T/tool/interplane-linux-x86_64;;
41+ *) echo "E2E_TARGET must be linux or x86linux"; exit 2;;
42+esac
43+if OMC="$OMC" taskset -c "$CORES" nice -n 19 sh tools/bring/build.sh "${E2E_TARGET:-linux}" "$T/tool" > "$T/tool.build" 2>&1; then
44+ ok "tool built: tools/bring/build.sh ${E2E_TARGET:-linux}, ${TOOL##*/} sha256 $(sha256sum < "$TOOL" | cut -c1-16)"
45+else bad "tool build: $(tail -3 "$T/tool.build" | tr '\n' ' ')"; fi
46+newclone tc
47+commitf "$T/tc" "docs/e2e.md" "# End to end" "docs: add the e2e page"
48+commitf "$T/tc" "src/e2e.txt" "e2e source line" "src: e2e line, the patch title"
49+MAIN=$(git -C "$T/tc" rev-parse origin/main); HEAD=$(git -C "$T/tc" rev-parse HEAD)
50+KEPT=$(kept)
51+(cd "$T/tc" && env -i HOME="$T/home" INTERPLANE_BASE="$B" "$TOOL" patch --yes "$OWNER/fixrepo") > "$OUT/tool.out" 2>&1; rc=$?
52+URL=$(sed -n 's/^Patch page: //p' "$OUT/tool.out")
53+PID16=${URL##*/}
54+if [ "$rc" = 0 ] && [ "$(kept)" = $((KEPT+1)) ] && [ "$URL" = "$B$R/patches/$PID16" ] && [ -f "$T/home/.interplane/key" ]; then
55+ ok "interplane patch --yes: exit 0, one patch kept, page $URL, key made in the scratch HOME"
56+else bad "interplane patch --yes: rc $rc, kept $(kept) (was $KEPT), out: $(tr '\n' '|' < "$OUT/tool.out")"; fi
57+grep -qx "Base: $MAIN" "$OUT/tool.out" && grep -qx 'Commits: 2' "$OUT/tool.out" && grep -qx 'Files changed: 2' "$OUT/tool.out" \
58+ && grep -qx 'Title: src: e2e line, the patch title' "$OUT/tool.out" \
59+ && ok "the tool showed base $MAIN, 2 commits, 2 files and the HEAD subject as title" || bad "tool summary: $(tr '\n' '|' < "$OUT/tool.out")"
60+
61+echo "== 3. read routes"
62+c=$(code GET "$R/patches/$PID16"); save page.html
63+ct=$(hdr content-type)
64+[ "$c" = 200 ] && [ "${ct%%;*}" = text/html ] && grep -qF 'src: e2e line, the patch title' "$T/body" \
65+ && ok "patch page: 200 text/html with the title" || bad "patch page: $c $ct"
66+c=$(code GET "$R/patches" -H 'Accept: application/json'); save patch-list.json
67+TDID=$(did "$T/home/.interplane/key.pub")
68+python3 - "$T/body" "$PID16" "$TDID" "$MAIN" "$HEAD" > "$T/py.out" 2>&1 <<'EOF'
69+import json, sys
70+d = json.load(open(sys.argv[1]))
71+assert d["schema"] == "forge/patch-list/1" and d["per_page"] == 30 and d["page"] == 1, d
72+assert d["count"] == len(d["patches"]) and d["next"] is None and d["prev"] is None, d
73+r = d["patches"][0]
74+assert r["id"] == sys.argv[2] and r["author"]["did"] == sys.argv[3], r
75+assert r["base_commit"] == sys.argv[4] and r["head_commit"] != sys.argv[4] and r["commits"] == 2 and r["files"] == 2, r
76+print("ok")
77+EOF
78+[ "$c" = 200 ] && grep -qx ok "$T/py.out" && ok "JSON list: forge/patch-list/1, newest first is the tool's patch, its key as author" || bad "JSON list $c: $(tail -2 "$T/py.out")"
79+c=$(code GET "$R/patches/$PID16" -H 'Accept: application/json'); save patch.json
80+python3 - "$T/body" "$PID16" "$TDID" > "$T/py.out" 2>&1 <<'EOF'
81+import json, sys
82+d = json.load(open(sys.argv[1]))
83+assert d["schema"] == "forge/patch/1" and d["id"] == sys.argv[2] and d["author"]["did"] == sys.argv[3], d
84+assert d["title"] == "src: e2e line, the patch title" and d["description"] == "" and d["status"] == "open", d
85+print("ok")
86+EOF
87+[ "$c" = 200 ] && grep -qx ok "$T/py.out" && ok "JSON patch: forge/patch/1 with id, title, empty description, status open" || bad "JSON patch $c: $(tail -2 "$T/py.out")"
88+c=$(code GET "$R/patches/$PID16.patch"); cp "$T/body" "$T/raw.mbox"; save raw.patch
89+[ "$c" = 200 ] && [ -s "$T/raw.mbox" ] && ok "raw .patch: 200, $(wc -c < "$T/raw.mbox") bytes, $(hdr content-type)" || bad "raw .patch: $c"
90+c=$(code GET "$R/patches/$PID16.diff"); cp "$T/body" "$T/raw.diff"; save raw.diff
91+git -C "$T/tc" diff --full-index -M "$MAIN" HEAD > "$T/want.diff"
92+[ "$c" = 200 ] && cmp -s "$T/raw.diff" "$T/want.diff" && ok "raw .diff: 200, byte-equal to git diff --full-index -M base HEAD" || bad "raw .diff: $c, $(wc -c < "$T/raw.diff") bytes vs $(wc -c < "$T/want.diff")"
93+c=$(code GET "$R/pulls/$PID16"); l=$(hdr location)
94+[ "$c" = 302 ] && [ "$l" = "$R/patches/$PID16" ] && ok "/pulls/<id>: 302 to $l" || bad "/pulls/<id>: $c $l"
95+
96+echo "== 4. raw mbox against git format-patch"
97+git -C "$T/tc" format-patch --stdout --no-color --no-ext-diff --no-textconv --no-attach --no-thread --no-cover-letter \
98+ --src-prefix=a/ --dst-prefix=b/ --no-signature --no-relative --no-notes "$MAIN..HEAD" > "$T/want.mbox"
99+cmp -s "$T/raw.mbox" "$T/want.mbox" && ok "the raw route is byte-equal to git format-patch --stdout of $MAIN..HEAD with the tool's flags ($(sha256sum < "$T/raw.mbox" | cut -c1-16))" \
100+ || bad "raw mbox differs from format-patch: $(cmp "$T/raw.mbox" "$T/want.mbox" 2>&1)"
101+
102+echo "== 5. git am of the raw route in a fresh clone"
103+git clone -q "$GITS" "$T/am" && git -C "$T/am" checkout -q --detach "$MAIN" || {
104+ bad "could not clone the signed-store fixture at $MAIN"
105+ exit 1
106+}
107+curl -s "$B$R/patches/$PID16.patch" | G -C "$T/am" am -q > "$T/am.out" 2>&1; rc=${PIPESTATUS[1]}
108+if [ "$rc" = 0 ] && [ "$(git -C "$T/am" rev-parse 'HEAD^{tree}')" = "$(git -C "$T/tc" rev-parse 'HEAD^{tree}')" ] \
109+ && [ "$(git -C "$T/am" rev-list --count "$MAIN..HEAD")" = 2 ]; then
110+ ok "git am onto base $MAIN: exit 0, 2 commits, the tree of the tool's HEAD"
111+else bad "git am: rc $rc $(tr '\n' ' ' < "$T/am.out")"; fi
112+
113+echo "== upload answers (curl, for docs/API.md)"
114+newclone w2; commitf "$T/w2" "notes/answer.txt" "answer line" "notes: an answer"; mkmbox "$T/w2" origin/main
115+TITLE="Answer example"; DESC="Sent with curl."; sigmake
116+KEPT=$(kept); C=$(upload); save upload-201.txt; accepted "$C" "a signed upload with curl"
117+C=$(upload); save upload-200.txt
118+[ "$C" = 200 ] && [ "$(head -1 "$T/body")" = exists ] && ok "the same statement again: 200 exists, nothing new kept ($(kept) kept)" || bad "replay: $C"
119+c=$(code GET "$R/patches" -H 'Accept: application/json'); save patch-list2.json
120+
121+echo "E2E: pass=$PASS fail=$FAIL"
122+[ "$FAIL" = 0 ]

patch/tests/lib.sh

new file mode 100644
@@ -0,0 +1,305 @@
1+# Git patch intake test library, sourced by patch/tests/run.sh and patch/tests/e2e.sh (run from the
2+# repository root on spark). It builds a TEST copy of forged from the build's own unit list
3+# (FORGE_STORE=<fixture store> ./run.sh units: the patch slice is composed only in a store-reading
4+# build) on a private port with private folders. The store is a fixture made by
5+# store/tests/fixstore.sh (IPL_DIR: interplane-native with bin/ built); in the test copy only, the
6+# data folder (every /home/drakestapleton/forge-data/ path), the port, and the first of the two
7+# origins a POST may name (tforg1, so the interplane program can post to this loopback copy) are
8+# rewritten. Nothing of the live forge, the real store (~/interplane-store-owner) or ~/forge-data is
9+# read or written. It makes a fixture repository, throwaway ed25519 keys and the sign-in and upload
10+# helpers.
11+set -u
12+cd "$(dirname "$0")/../.."
13+ROOT=$(pwd)
14+tree_status=$(git status --porcelain) || exit 1
15+if [ -n "$tree_status" ]; then
16+ echo "BUILD FAILED: patch fixtures require a clean Git checkout" >&2
17+ exit 1
18+fi
19+OMV=${OMV:-$HOME/work/flux/omega-mv}
20+OMC=$OMV/seed/out/omc
21+PORT=${PATCH_TEST_PORT:-18487}
22+CORES=${PATCH_TEST_CORES:-2}
23+T=$(mktemp -d /tmp/forgepatch.XXXXXX)
24+mkdir -p "$T/data" "$T/social" "$T/storage" "$T/home"
25+IPL_DIR=${IPL_DIR:-$HOME/work/hive/agent-door/interplane-native}
26+PASS=0; FAIL=0
27+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
28+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
29+check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
30+G() { git -c user.name=fixture -c user.email=fixture@example.org -c init.defaultBranch=main -c commit.gpgSign=false "$@"; }
31+
32+# The site chrome is generated from the interplane.io site source. A store-reading build takes it
33+# from the store's interplane.io project, which the fixture store does not hold; the site's git
34+# store stands in when no source is named.
35+if [ -z "${FORGE_SITE_STORE:-}${FORGE_SITE_SRC:-}" ] && [ -d "$HOME/git/interplane.io.git" ]; then
36+ export FORGE_SITE_STORE=$HOME/git/interplane.io.git
37+fi
38+
39+# ---- fixture: a Radicle-shaped list and a bare repository per row, turned into a native store
40+# ($T/store, catalog.tsv and projects/NAME/repo.git) by store/tests/fixstore.sh. fixrepo has main
41+# (three commits) and side (one commit that is not on main); nostore is a second public project
42+# whose repo.git a test moves away while the server runs (GITS is the store's fixrepo repository).
43+RID1=zFixtureRepoOne1111111111111
44+RID2=zFixtureRepoTwo2222222222222
45+OWNER=drakestapleton
46+R=/$OWNER/fixrepo
47+cat > "$T/RIDS.md" <<EOF
48+# fixture list
49+
50+| repo | RID | default branch | head |
51+|---|---|---|---|
52+| fixrepo | rad:$RID1 | main | - |
53+| nostore | rad:$RID2 | main | - |
54+EOF
55+fixture() {
56+ G init -q "$T/src" && cd "$T/src" || return 1
57+ printf 'fixture project\n' > README.md
58+ mkdir -p src docs
59+ printf 'one\ntwo\nthree\n' > src/a.txt
60+ printf 'alpha\n' > docs/note.md
61+ G add -A && GIT_AUTHOR_DATE=2026-11-01T10:00:00Z GIT_COMMITTER_DATE=2026-11-01T10:00:00Z G commit -q -m 'first' || return 1
62+ A=$(git rev-parse HEAD)
63+ printf 'four\n' >> src/a.txt
64+ GIT_AUTHOR_DATE=2026-11-02T10:00:00Z GIT_COMMITTER_DATE=2026-11-02T10:00:00Z G commit -q -am 'second' || return 1
65+ printf 'beta\n' >> docs/note.md
66+ GIT_AUTHOR_DATE=2026-11-03T10:00:00Z GIT_COMMITTER_DATE=2026-11-03T10:00:00Z G commit -q -am 'third' || return 1
67+ MAIN=$(git rev-parse HEAD)
68+ G checkout -q -b side "$A"
69+ printf 'side\n' > side.txt
70+ G add -A && GIT_AUTHOR_DATE=2026-11-04T10:00:00Z GIT_COMMITTER_DATE=2026-11-04T10:00:00Z G commit -q -m 'side work' || return 1
71+ SIDE=$(git rev-parse HEAD)
72+ G checkout -q main
73+ git clone -q --bare "$T/src" "$T/storage/$RID1" || return 1
74+ git clone -q --bare "$T/src" "$T/storage/$RID2" || return 1
75+ cd "$ROOT" || return 1
76+ [ -x "$IPL_DIR/ipl" ] || { echo "IPL_DIR=$IPL_DIR has no ipl program (store/tests/fixstore.sh needs it)"; return 1; }
77+ # fixstore.sh signs the fixture's records with a throwaway key it keeps at <store>/.fixkey. An ipl with
78+ # owner pins (IPL_OWNER_PINS, default ~/.config/interplane/owner-pins: the real owner) refuses any other
79+ # key, so the key is made here first and pinned in a private file for this run; an older ipl ignores it.
80+ mkdir -p "$T/store" && ssh-keygen -q -t ed25519 -N '' -C 'patch/tests/lib.sh throwaway key' -f "$T/store/.fixkey" || return 1
81+ (umask 077; printf '* %s\n' "$(ssh-keygen -lf "$T/store/.fixkey.pub" | cut -d' ' -f2)" > "$T/pins") || return 1
82+ export IPL_OWNER_PINS=$T/pins
83+ FIXSTORE_FROM=/nonexistent IPL_DIR=$IPL_DIR bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store" > "$T/fixstore.log" 2>&1 \
84+ || { cat "$T/fixstore.log"; return 1; }
85+ GITS=$T/store/projects/fixrepo/repo.git
86+ [ -d "$GITS" ] && [ -d "$T/store/projects/nostore/repo.git" ] || { echo "the fixture store lacks a project"; cat "$T/fixstore.log"; return 1; }
87+ [ "$(git --git-dir="$GITS" rev-parse refs/heads/main)" = "$MAIN" ] || { echo "the fixture store's main is not the fixture's"; return 1; }
88+}
89+fixture || { echo "FIXTURE FAILED"; rm -rf "$T"; exit 1; }
90+export FORGE_STORE=$T/store
91+
92+# ---- build
93+buildfail() { echo "BUILD FAILED: $*"; [ -n "${KEEP:-}" ] || rm -rf "$T"; exit 1; }
94+FORGED_CPUS=$CORES ./run.sh units > "$T/units.txt" 2> "$T/units.err" || buildfail "./run.sh units: $(cat "$T/units.err")"
95+grep -qx 'patch/p4take.om' "$T/units.txt" || buildfail "the patch slice is not composed (FORGE_STORE, patch/READY, social/READY)"
96+rewrite() {
97+ sed -e "s|/home/drakestapleton/forge-data/|$T/data/|g" \
98+ -e "s|^text tforg1 \".*\"|text tforg1 \"http://127.0.0.1:$PORT\"|" -e "s/18480/$PORT/g"
99+}
100+{ printf 'om2\n'; cat $(cat "$T/units.txt"); } | rewrite > "$T/all.om" || buildfail "compose"
101+for t in "tfdata \"$T/data/\"" "tfsroot \"$T/store/\""; do
102+ grep -q "^text $t\$" "$T/all.om" || buildfail "the test copy does not name the private $t"
103+done
104+if grep -qE '/home/drakestapleton/(forge-data|interplane-store|git/)' "$T/all.om"; then
105+ buildfail "the test copy still names a live folder: $(grep -oE '/home/drakestapleton/(forge-data|interplane-store|git/)[^\" ]*' "$T/all.om" | sort -u | head -3 | tr '\n' ' ')"
106+fi
107+compile() { # SRC OUT
108+ taskset -c "$CORES" nice -n 19 "$OMC" < "$1" > "$2" 2> "$T/omc.err" || return 1
109+ chmod +x "$2"
110+}
111+compile "$T/all.om" "$T/forged" || buildfail "$(cat "$T/omc.err")"
112+echo "built $(sha256sum < "$T/forged" | cut -c1-16) in $T (omc $(sha256sum < "$OMC" | cut -c1-16), port $PORT)"
113+git log -1 --format='fixture head=%H tree=%T' 2>/dev/null || :
114+sha256sum "$T/all.om" "$T/forged" "$OMC"
115+
116+# mutant NAME SED...: the test copy with one guard removed, as $T/forged.NAME; the sed program must
117+# change the source, else the mutant is void and the run stops
118+mutant() {
119+ n=$1; shift
120+ sed "$@" "$T/all.om" > "$T/all.$n.om"
121+ if cmp -s "$T/all.om" "$T/all.$n.om"; then echo "MUTANT VOID: $n changed nothing"; exit 1; fi
122+ compile "$T/all.$n.om" "$T/forged.$n" || { echo "MUTANT $n DID NOT COMPILE: $(cat "$T/omc.err")"; exit 1; }
123+}
124+
125+PID=
126+start() { # [binary]
127+ FORGE_SOCIAL_DIR="$T/social/" taskset -c "$CORES" nice -n 19 "${1:-$T/forged}" 2>> "$T/forged.err" &
128+ PID=$!
129+ for i in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && return 0; sleep 0.1; done
130+ echo "server did not start"; tail -5 "$T/forged.err"; exit 1
131+}
132+stop() { [ -n "$PID" ] && kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null; PID=; }
133+# alive: forged still answers. kill -0 alone is not enough: a forged that exited stays a zombie (kill -0 succeeds)
134+# until stop reaps it, so the process must not be in state Z and the port must still answer
135+alive() { kill -0 "$PID" 2>/dev/null && [ "$(sed 's/^.*) //' "/proc/$PID/stat" | cut -c1)" != Z ] && curl -s -o /dev/null --max-time 5 "$B/"; }
136+trap 'stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
137+B="http://127.0.0.1:$PORT"
138+
139+# code METHOD PATH [curl args]: the status; body in $T/body, headers in $T/hdr (both emptied first: curl leaves the
140+# file of an answer without a body untouched, which would show the previous answer's body)
141+code() {
142+ m=$1; p=$2; shift 2; : > "$T/body"; : > "$T/hdr"
143+ curl -s -o "$T/body" -D "$T/hdr" -X "$m" "$@" "$B$p" -w '%{http_code}'
144+}
145+hdr() { grep -i "^$1:" "$T/hdr" | head -1 | cut -d' ' -f2- | tr -d '\r'; }
146+field() { grep -o "name=\"$1\" value=\"[^\"]*\"" "$T/body" | head -1 | sed 's/.*value="//; s/"$//'; }
147+
148+# ---- throwaway keys and the did:key oracle (z + base58btc(0xed 0x01 || public key))
149+did() { python3 - "$1" <<'EOF'
150+import sys, base64
151+blob = base64.b64decode(open(sys.argv[1]).read().split()[1])
152+raw = b'\xed\x01' + blob[-32:]
153+A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
154+n = int.from_bytes(raw, 'big'); s = ''
155+while n: n, r = divmod(n, 58); s = A[r] + s
156+print('did:key:z' + s)
157+EOF
158+}
159+newkey() { ssh-keygen -q -t ed25519 -N '' -C "$1" -f "$T/$1"; }
160+
161+# signin KEY IP: sign in with $T/KEY from address IP; sets SES (session), TOK (CSRF token), DID, KEY, IP
162+signin() {
163+ KEY=$T/$1; IP=$2; DID=$(did "$KEY.pub")
164+ c=$(code GET /login -H "X-Real-IP: $IP"); [ "$c" = 200 ] || { bad "GET /login for $1: $c"; return 1; }
165+ pre=$(hdr set-cookie | sed -n 's/^__Host-forge_pre=\([0-9a-f]*\);.*/\1/p')
166+ lcsrf=$(field csrf); nonce=$(field nonce); ts=$(field ts)
167+ printf '%s' "interplane-forge-login:$nonce:$ts" | ssh-keygen -Y sign -f "$KEY" -n interplane-forge > "$T/login.sig" 2>/dev/null
168+ c=$(code POST /login -H "X-Real-IP: $IP" -H "Cookie: __Host-forge_pre=$pre" --data-urlencode "csrf=$lcsrf" \
169+ --data-urlencode "nonce=$nonce" --data-urlencode "ts=$ts" --data-urlencode "did=$DID" --data-urlencode "sig@$T/login.sig")
170+ [ "$c" = 303 ] || { bad "POST /login for $1: $c"; return 1; }
171+ SES=$(hdr set-cookie | sed -n 's/^__Host-forge_session=\([0-9a-f]*\);.*/\1/p')
172+ c=$(code GET /settings -H "X-Real-IP: $IP" -H "Cookie: __Host-forge_session=$SES")
173+ TOK=$(field csrf)
174+ [ ${#SES} = 64 ] && [ ${#TOK} = 32 ] || { bad "session for $1: ses ${#SES} tok ${#TOK}"; return 1; }
175+}
176+
177+# ---- a patch: work in a clone of the fixture, then mkmbox makes the mbox of BASE..HEAD
178+# newclone NAME [START]: a clone $T/NAME of the store's repository on a new branch at START (default main)
179+newclone() {
180+ rm -rf "$T/$1"; git clone -q "$GITS" "$T/$1" && G -C "$T/$1" checkout -q -b work "${2:-origin/main}"
181+}
182+# commitf DIR PATH TEXT MESSAGE: append TEXT to PATH and commit, at a fixed time
183+commitf() {
184+ mkdir -p "$(dirname "$1/$2")"; printf '%s\n' "$3" >> "$1/$2"
185+ G -C "$1" add -A && GIT_AUTHOR_DATE=2026-11-10T10:00:00Z GIT_COMMITTER_DATE=2026-11-10T10:00:00Z G -C "$1" commit -q -m "$4"
186+}
187+# mkmbox DIR BASE: $MBOX = git format-patch --stdout BASE..HEAD of DIR; BASE is kept in $BASE
188+mkmbox() {
189+ BASE=$(git -C "$1" rev-parse "$2"); MBOX=$T/mbox.$$.$RANDOM
190+ git -C "$1" format-patch --stdout "$BASE..HEAD" > "$MBOX"
191+}
192+sha() { sha256sum "$@" | cut -d' ' -f1; }
193+# statement: the text the author's key signs, from REPOF BASE MBOX TITLE DESC
194+statement() {
195+ printf 'interplane-patch 1\n%s\n%s\n%s\n%s\n' "$REPOF" "$BASE" "$(sha < "$MBOX")" "$(printf '%s\n%s' "$TITLE" "$DESC" | sha)"
196+}
197+# sigmake [KEYFILE]: sign the statement into $SIGF (default: the signed-in key)
198+sigmake() {
199+ statement > "$T/stmt"; rm -f "$T/stmt.sig"
200+ ssh-keygen -Y sign -f "${1:-$KEY}" -n interplane-patch "$T/stmt" > /dev/null 2>&1
201+ SIGF=$T/stmt.sig
202+}
203+# upload [curl args]: POST the form (SES TOK IP REPOF BASE TITLE DESC MBOX SIGF) to $UPATH; the status
204+upload() {
205+ : > "$T/body"; : > "$T/hdr"
206+ basenc --base64url -w0 "$MBOX" | tr -d '=' > "$T/mb64"
207+ curl -s -o "$T/body" -D "$T/hdr" -w '%{http_code}' -X POST -H "X-Real-IP: $IP" ${SES:+-H "Cookie: __Host-forge_session=$SES"} \
208+ --data-urlencode "csrf=$TOK" --data-urlencode "repo=$REPOF" --data-urlencode "base=$BASE" \
209+ --data-urlencode "title=$TITLE" --data-urlencode "description=$DESC" --data-urlencode "mbox@$T/mb64" \
210+ --data-urlencode "sig@$SIGF" "$@" "$B${UPATH:-$R/patches/new}"
211+}
212+reason() { sed -n 's/^refused: //p' "$T/body"; }
213+newid() { sed -n 's/^id //p' "$T/body"; }
214+# kept: how many patches the store holds for the fixture; tmpleft: work folders left behind
215+kept() { ls "$T/data/patches/$OWNER/fixrepo" 2>/dev/null | grep -c '^[0-9a-f]\{16\}$'; }
216+staged() { ls -a "$T/data/patches/$OWNER/fixrepo" 2>/dev/null | grep -c '^\.new-'; }
217+tmpleft() { ls "$T/data/patch-work" 2>/dev/null | grep -c '^pw'; }
218+# refused WANT_STATUS WANT_REASON LABEL: the last upload was refused with exactly that status and
219+# reason and nothing was kept (the store count is unchanged from $KEPT, nothing staged, no work folder)
220+refused() {
221+ got="$1"; want="$2"; why="$3"; label="$4"
222+ if [ "$got" = "$want" ] && [ "$(reason)" = "$why" ] && [ "$(kept)" = "$KEPT" ] && [ "$(staged)" = 0 ] && [ "$(tmpleft)" = 0 ]; then
223+ ok "NEG $label: $got \"$why\", nothing kept"
224+ else
225+ bad "NEG $label: want $want \"$why\" and $KEPT kept; got $got \"$(head -c 200 "$T/body")\" kept $(kept) staged $(staged) work $(tmpleft)"
226+ fi
227+}
228+# accepted LABEL: the last upload answered 201 "accepted", one more patch is kept, nothing left over
229+accepted() {
230+ got="$1"; label="$2"
231+ if [ "$got" = 201 ] && [ "$(head -1 "$T/body")" = accepted ] && [ "$(kept)" = $((KEPT+1)) ] && [ "$(staged)" = 0 ] && [ "$(tmpleft)" = 0 ]; then
232+ KEPT=$((KEPT+1)); ID=$(newid); ok "POS $label: 201 accepted, id $ID"
233+ else
234+ bad "POS $label: want 201 accepted and $((KEPT+1)) kept; got $got \"$(head -c 200 "$T/body")\" kept $(kept) staged $(staged) work $(tmpleft)"
235+ KEPT=$(kept)
236+ fi
237+}
238+
239+# ---- imported proposals (SPEC prstore/r1 extension, section 1). The forge never writes one: tools/ghimport does
240+# (branch ghimport/r1, tools/ghimport/src). These helpers plant item folders in the scratch store in the byte
241+# layout of that writer: 35imp.om prfiles/prgh/prmbox/prbund/oreach and 30item.om osrc for a pull request with
242+# GitHub metadata, 37code.om cfiles/ocsrc for a code-only one. The code file is made by git from a clone of the
243+# fixture repository, with the writer's own arguments. I is the folder of the item last made, IID its id (the
244+# first 16 hex of the SHA-256 of its statement), IMPD the store folder of the fixture repository.
245+GHO=aien-dev; GHR=gh-repo; IMPUTC=2026-11-17T09:00:00Z
246+IMPD=$T/data/patches/$OWNER/fixrepo
247+impstmt() { printf 'github-import 1\n%s/%s\n%s\n%s\n' "$GHO" "$GHR" "$1" "$2"; } # N HEAD
248+impid() { impstmt "$1" "$2" | sha256sum | cut -c1-16; }
249+# impsrc N [code]: source.json (osrc; with a second argument ocsrc, the code-only form)
250+impsrc() {
251+ { printf '{"kind":"github-import","owner":"%s","repo":"%s","number":%s,"url":"https://github.com/%s/%s/pull/%s","export_sha256":"%s","imported_utc":"%s"' \
252+ "$GHO" "$GHR" "$1" "$GHO" "$GHR" "$1" "$(printf 'export %s' "$1" | sha256sum | cut -c1-64)" "$IMPUTC"
253+ if [ -n "${2:-}" ]; then printf ',"metadata":"unavailable","state_derived":true}\n'; else printf '}\n'; fi; } > "$I/source.json"
254+}
255+# impgh N LOGIN OPENED CLOSED MERGED [DRAFT]: the gh file (prgh); a time is 20 bytes or "-"
256+impgh() { printf 'number %s\nlogin %s\nopened %s\nclosed %s\nmerged %s\nbase-ref main\nhead-ref feature-%s\ndraft %s\n' "$1" "$2" "$3" "$4" "$5" "$1" "${6:-false}" > "$I/gh"; }
257+# impnew N HEAD STATUS BASE: a pull request with GitHub metadata (prfiles), without its code file: statement,
258+# title, description (empty), status, labels (none), head, base, gh (login octo, open), thread (no record),
259+# source.json, and its line in the index
260+impnew() {
261+ IID=$(impid "$1" "$2"); I=$IMPD/$IID; mkdir -p "$I" || return 1
262+ impstmt "$1" "$2" > "$I/statement"; printf 'Imported pull request %s' "$1" > "$I/title"; : > "$I/description"
263+ printf '%s\n' "$3" > "$I/status"; : > "$I/labels"; printf '%s\n' "$2" > "$I/head"; printf '%s\n' "$4" > "$I/base"
264+ impgh "$1" octo 2026-11-10T11:00:00Z - -; : > "$I/thread"; impsrc "$1"
265+ printf '%s\n' "$IID" >> "$IMPD/index"
266+}
267+# impcnew N HEAD STATUS [BASE]: a code-only pull request (cfiles), without its code file: statement, the fixed
268+# title, description (empty), head, thread (no record), gh (metadata unavailable), status, base when it has
269+# one, source.json (state_derived), and its line in the index. No labels file.
270+impcnew() {
271+ IID=$(impid "$1" "$2"); I=$IMPD/$IID; mkdir -p "$I" || return 1
272+ impstmt "$1" "$2" > "$I/statement"; printf 'GitHub %s/%s#%s (code only)' "$GHO" "$GHR" "$1" > "$I/title"; : > "$I/description"
273+ printf '%s\n' "$2" > "$I/head"; : > "$I/thread"; printf 'number %s\nmetadata unavailable\nstate derived\n' "$1" > "$I/gh"
274+ printf '%s\n' "$3" > "$I/status"; [ -z "${4:-}" ] || printf '%s\n' "$4" > "$I/base"; impsrc "$1" code
275+ printf '%s\n' "$IID" >> "$IMPD/index"
276+}
277+# impmbox REPO: mbox and diff of the item's base..head from the work tree REPO (prmbox)
278+impmbox() {
279+ git --git-dir="$1/.git" format-patch --stdout --no-relative --no-notes --no-signature "$(cat "$I/base")..$(cat "$I/head")" > "$I/mbox" \
280+ && git --git-dir="$1/.git" diff --no-color --no-ext-diff --no-textconv "$(cat "$I/base")...$(cat "$I/head")" > "$I/diff"
281+}
282+# impbundle REPO N: head.bundle of refs/pull/N/head ^base from REPO (prbund); of the head alone without a base file
283+impbundle() {
284+ git -C "$1" update-ref "refs/pull/$2/head" "$(cat "$I/head")" || return 1
285+ if [ -f "$I/base" ]; then git -C "$1" bundle create -q "$I/head.bundle" "refs/pull/$2/head" "^$(cat "$I/base")"
286+ else git -C "$1" bundle create -q "$I/head.bundle" "refs/pull/$2/head"; fi
287+}
288+# impreach WORD MAIN|- [UTC]: the reach file of a merged pull request (oreach)
289+impreach() { printf '%s %s %s\n' "$1" "$2" "${3:-2026-11-17T09:30:00Z}" > "$I/reach"; }
290+# thread records (30item.om trec/trc3), appended to the item's thread; lengths are byte counts
291+blen() { printf '%s' "$1" | wc -c; }
292+thc() { printf 'comment %s %s %s\n%s\n' "$1" "$2" "$(blen "$3")" "$3" >> "$I/thread"; } # TIME LOGIN BODY
293+thr() { printf 'review %s %s %s %s\n%s\n' "$1" "$2" "$3" "$(blen "$4")" "$4" >> "$I/thread"; } # TIME LOGIN STATE|- BODY
294+thrc() { printf 'review-comment %s %s %s %s %s\n%s\n%s\n' "$1" "$2" "$3" "$(blen "$4")" "$(blen "$5")" "$4" "$5" >> "$I/thread"; } # TIME LOGIN LINE PATH BODY
295+# imphash: one hash over the SHA-256 of every file of every item folder without a meta file (the imported ones),
296+# the index, and the names the store folder holds
297+imphash() { (cd "$IMPD" && for d in */; do [ -f "$d/meta" ] || find "$d" -type f | sort | xargs -r sha256sum; done; sha256sum index; ls -a) | sha256sum | cut -d' ' -f1; }
298+# pdstaged: staging files left in the bundle diff cache folder
299+pdstaged() { ls -a "$T/data/pdiff/$OWNER/fixrepo" 2>/dev/null | grep -c '^\.new-'; }
300+# fold FILE: the PASS and FAIL lines an oracle program wrote, added to the counters; an oracle that did not
301+# reach its last line (DONE) is a failure of its own
302+fold() {
303+ grep -a '^PASS \|^FAIL ' "$1"; p=$(grep -ac '^PASS ' "$1"); f=$(grep -ac '^FAIL ' "$1"); PASS=$((PASS+p)); FAIL=$((FAIL+f))
304+ [ "$(tail -1 "$1")" = DONE ] || bad "the oracle did not finish ($1): $(tail -3 "$1" | tr '\n' ' ' | cut -c1-300)"
305+}

patch/tests/resilience.sh

new file mode 100755
@@ -0,0 +1,56 @@
1+#!/usr/bin/env bash
2+# Exercise bundle work limits and the upload storage reserve on a private fixture.
3+. "$(dirname "$0")/lib.sh"
4+set -e
5+trap 'rc=$?; set +e; stop; rm -rf "$T"; exit "$rc"' EXIT
6+newclone work
7+commitf "$T/work" "notes/recovery.txt" "test fixture" "Fixture note"
8+tip=$(git -C "$T/work" rev-parse HEAD)
9+impnew 201 "$tip" open "$MAIN"
10+failed=$IID
11+printf 'fixture with invalid bundle data\n' > "$I/head.bundle"
12+impnew 202 "$tip" open "$MAIN"
13+large=$IID
14+truncate -s 134217729 "$I/head.bundle"
15+start
16+test "$(code GET "$R/patches/$failed")" = 200
17+test "$(code GET "$R/patches/$failed" -H 'Accept: application/json')" = 200
18+jq -e '.diff == null and .diff_unavailable == "diff-failed" and .bundle != null' "$T/body" >/dev/null
19+echo 'PASS a failed bundle diff is remembered and JSON reports its state'
20+test "$(code GET "$R/patches/$large" -H 'Accept: application/json')" = 200
21+jq -e '.diff == null and .diff_unavailable == "bundle-too-large" and .bundle != null' "$T/body" >/dev/null
22+test "$(code GET "$R/patches/$large.diff")" = 404
23+test "$(tmpleft)" = 0
24+echo 'PASS an oversized bundle bypasses diff generation and remains downloadable'
25+set +e
26+stop
27+set -e
28+# Force the base check to fail, recording every call. No changes to the real Git executable.
29+mutant jsonfailure '/^fn pabcat to long$/,/^end$/c\fn pabcat to long\nflog tplrm\nret -1\nend'
30+start "$T/forged.jsonfailure"
31+: > "$T/forged.err"
32+for _ in 1 2; do
33+ test "$(code GET "$R/patches/$failed" -H 'Accept: application/json')" = 200
34+ jq -e '.diff == null and .diff_unavailable == "diff-failed"' "$T/body" >/dev/null
35+done
36+test "$(grep -cF 'PATCH-TMP' "$T/forged.err")" = 1
37+echo 'PASS two JSON reads make one failed base check'
38+set +e
39+stop
40+set -e
41+mutant lowspace 's/^const PAPRES ulong 1073741824$/const PAPRES ulong 1000000000000000000/'
42+start "$T/forged.lowspace"
43+REPOF=$OWNER/fixrepo
44+newkey k1
45+signin k1 10.4.0.1
46+mkmbox "$T/work" origin/main
47+TITLE="Storage reserve fixture"
48+DESC=""
49+sigmake
50+before=$(kept)
51+status=$(upload)
52+test "$status" = 503
53+test "$(kept)" = "$before"
54+test "$(tmpleft)" = 0
55+grep -q 'patch storage is temporarily unavailable' "$T/body"
56+echo 'PASS insufficient available space refuses a signed patch before creating a work tree'

patch/tests/run.sh

new file mode 100755
@@ -0,0 +1,1642 @@
1+#!/bin/bash
2+# Git patch intake test (docs/API.md "Git patches"; ./run.sh check-patch). HOST test on spark, on a
3+# private copy of forged with fixture folders (patch/tests/lib.sh); nothing of the live forge is used.
4+# Every refusal of the upload has a negative control that must be refused with exactly its status
5+# and reason and must keep nothing (no stored patch, no staging folder, no work folder), and a
6+# matching positive that is accepted. Then the read routes, the interplane patch program against
7+# this forged, the imported proposals (SPEC prstore/r1 extension: item folders planted in the layout
8+# tools/ghimport writes, read back through every page, document and raw route, never writable by a
9+# POST; the list's count, states and damaged lines; diff_unavailable and the marker of a diff over 16 MiB;
10+# thread_truncated and the document budget; the id guard of the upload), and the mutants: each removes one guard from the test copy and
11+# must make the control that names it fail.
12+# Usage: bash patch/tests/run.sh (PATCH_TEST_CORES, default 2; PATCH_TEST_PORT, default 18487;
13+# KEEP=1 keeps the temp folder). Exit 0 only when every check passed and every mutant was killed.
14+. "$(dirname "$0")/lib.sh"
15+start
16+REPOF=$OWNER/fixrepo
17+N=0
18+# fresh NAME: a clone with one small text commit that no other test made (so its statement is new)
19+fresh() { N=$((N+1)); newclone "$1" && commitf "$T/$1" "notes/n$N.txt" "line $N" "note $N"; }
20+# std: a new one-commit patch with its own title, signed by the signed-in key
21+std() { fresh w; mkmbox "$T/w" origin/main; TITLE="Patch $N"; DESC="Description $N."; sigmake; }
22+# isref STATUS REASON: the last upload was refused exactly so and kept nothing
23+isref() { [ "$C" = "$1" ] && [ "$(reason)" = "$2" ] && [ "$(kept)" = "$KEPT" ] && [ "$(staged)" = 0 ] && [ "$(tmpleft)" = 0 ]; }
24+
25+# ---- the negative controls, each a function that sends one upload: C is the status, WANT and WHY
26+# what a correct forge answers
27+n_unsigned() { std; s=$SES; SES=; C=$(upload); SES=$s; WANT=403; WHY="sign in first: this request carries no session"; }
28+n_csrf_stale() { std; t=$TOK; TOK=$OLDTOK; C=$(upload); TOK=$t; WANT=403; WHY="missing or wrong CSRF token"; }
29+n_csrf_foreign() { std; t=$TOK; TOK=$TOK2; C=$(upload); TOK=$t; WANT=403; WHY="missing or wrong CSRF token"; }
30+n_sig_forged() { # one letter of the armored signature's last full line is changed
31+ std; python3 - "$SIGF" <<'EOF'
32+import sys
33+p = sys.argv[1]; L = open(p).read().split('\n'); i = len(L) - 4
34+c = L[i][10]; L[i] = L[i][:10] + ('A' if c != 'A' else 'B') + L[i][11:]
35+open(p, 'w').write('\n'.join(L))
36+EOF
37+ C=$(upload); WANT=403; WHY="the signature does not verify for this session's key and this patch"; }
38+n_sig_other_text() { std; t=$TITLE; TITLE="another title"; sigmake; TITLE=$t; C=$(upload); WANT=403; WHY="the signature does not verify for this session's key and this patch"; }
39+n_sig_other_key() { std; sigmake "$T/k3"; C=$(upload); WANT=403; WHY="the signature does not verify for this session's key and this patch"; }
40+n_base_unknown() { std; BASE=1234567890123456789012345678901234567890; sigmake; C=$(upload); WANT=422; WHY="unknown base: the repository has no such commit"; }
41+n_base_side() { N=$((N+1)); newclone w origin/side; commitf "$T/w" "notes/n$N.txt" "line $N" "note $N"; mkmbox "$T/w" origin/side
42+ TITLE="Patch $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="base is not reachable from the repository's main branch"; }
43+n_mbox_big() { # one commit adding 21500 lines of 100 digits: the mbox is over 2 MiB, and its base64 form stays under
44+ # the 3 MiB body the route reads (a larger mbox is refused before any handler, 413 with no reason)
45+ N=$((N+1)); newclone w; yes 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 | head -n 21500 > "$T/w/big$N.txt"
46+ G -C "$T/w" add -A; G -C "$T/w" commit -q -m "big $N"; mkmbox "$T/w" origin/main
47+ m=$(stat -c %s "$MBOX"); [ "$m" -gt 2097152 ] && [ "$m" -lt 2300000 ] || bad "FIXTURE: the big mbox is $m bytes, not between 2 MiB and 2300000"
48+ TITLE="Big $N"; DESC=; sigmake; C=$(upload); WANT=413; WHY="the mbox is larger than 2097152 bytes"; }
49+n_commits_101() { N=$((N+1)); newclone w; for i in $(seq 101); do commitf "$T/w" "many/m$N.txt" "$i" "c $i"; done; mkmbox "$T/w" origin/main
50+ TITLE="Many $N"; DESC=; sigmake; C=$(upload); WANT=413; WHY="the mbox holds more than 100 commits"; }
51+n_noapply() { # a patch made on main, sent with the first commit as its base: the context is not there
52+ N=$((N+1)); newclone w; sed -i 's/^four$/FOUR '"$N"'/' "$T/w/src/a.txt"; G -C "$T/w" commit -q -am "edit four $N"; mkmbox "$T/w" origin/main
53+ BASE=$A; TITLE="Edit $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="the mbox does not apply cleanly on base"; }
54+n_path_out() { std; sed -i "s|^diff --git a/notes/n$N.txt b/notes/n$N.txt|diff --git a/../n$N.txt b/../n$N.txt|; s|^+++ b/notes/n$N.txt|+++ b/../n$N.txt|" "$MBOX"
55+ grep -q '^diff --git a/\.\./' "$MBOX" || bad "FIXTURE: the path was not rewritten"
56+ sigmake; C=$(upload); WANT=422; WHY="a patch names a path outside the repository"; }
57+n_path_abs() { std; sed -i "s|^diff --git a/notes/n$N.txt b/notes/n$N.txt|diff --git a//tmp/n$N.txt b//tmp/n$N.txt|; s|^+++ b/notes/n$N.txt|+++ b//tmp/n$N.txt|" "$MBOX"
58+ grep -q '^diff --git a//tmp/' "$MBOX" || bad "FIXTURE: the path was not rewritten"
59+ sigmake; C=$(upload); WANT=422; WHY="a patch names a path outside the repository"; }
60+n_path_rename() { N=$((N+1)); newclone w; G -C "$T/w" mv docs/note.md "docs/moved$N.md"; G -C "$T/w" commit -q -m "move $N"; mkmbox "$T/w" origin/main
61+ sed -i "s|^rename to docs/moved$N.md|rename to ../moved$N.md|" "$MBOX"; grep -q '^rename to \.\./' "$MBOX" || bad "FIXTURE: no rename line"
62+ TITLE="Move $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="a patch names a path outside the repository"; }
63+n_copy_header() {
64+ N=$((N+1))
65+ newclone w
66+ cp "$T/w/docs/note.md" "$T/w/docs/copy.md"
67+ G -C "$T/w" add docs/copy.md
68+ G -C "$T/w" commit -q -m "copy fixture note"
69+ mkmbox "$T/w" origin/main
70+ G -C "$T/w" format-patch --stdout --no-signature --find-copies-harder origin/main..HEAD > "$MBOX"
71+ grep -q '^copy to docs/copy.md$' "$MBOX" || bad "FIXTURE: expected a copy header"
72+ if [ "$#" != 0 ]; then
73+ encmail "$1"
74+ fi
75+ TITLE="Copy fixture"
76+ DESC=
77+ sigmake
78+ C=$(upload)
79+ WANT=422
80+ WHY="patches with copy headers are not accepted"
81+}
82+n_path_plain() { # a plain diff without the git header: only git's own apply sees the path
83+ std; sed -i "/^diff --git /d; /^new file mode /d; /^index /d; s|^+++ b/notes/n$N.txt|+++ b/../n$N.txt|" "$MBOX"
84+ sigmake; C=$(upload); WANT=422; WHY="the mbox does not apply cleanly on base"; }
85+n_path_quoted() { # a C-quoted header ("a/\056\056/x" is a/../x): the header scan sees no literal .., git apply refuses it
86+ std; sed -i 's|^diff --git a/notes/n'"$N"'.txt b/notes/n'"$N"'.txt|diff --git "a/\\056\\056/n'"$N"'.txt" "b/\\056\\056/n'"$N"'.txt"|; s|^+++ b/notes/n'"$N"'.txt|+++ "b/\\056\\056/n'"$N"'.txt"|' "$MBOX"
87+ grep -qF "diff --git \"a/\\056\\056/n$N.txt\"" "$MBOX" || bad "FIXTURE: the path was not quoted"
88+ sigmake; C=$(upload); WANT=422; WHY="the mbox does not apply cleanly on base"; }
89+n_binary() { N=$((N+1)); newclone w; printf 'bin\000\001\002%s' "$N" > "$T/w/blob$N.dat"; G -C "$T/w" add -A; G -C "$T/w" commit -q -m "binary $N"; mkmbox "$T/w" origin/main
90+ grep -q '^GIT binary patch$' "$MBOX" || bad "FIXTURE: no binary patch in the mbox"
91+ TITLE="Binary $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="binary patches are not accepted"; }
92+# encmail CTE: $MBOX (one commit) with its mail body sent in that Content-Transfer-Encoding (base64 or
93+# quoted-printable); git am decodes it before it applies, the mbox as sent shows none of the diff's lines
94+encmail() { python3 - "$MBOX" "$1" <<'EOF'
95+import sys, base64, quopri
96+p, cte = sys.argv[1], sys.argv[2]
97+h, b = open(p, 'rb').read().split(b'\n\n', 1)
98+h = [l for l in h.split(b'\n') if not l.lower().startswith((b'content-transfer-encoding:', b'mime-version:', b'content-type:'))]
99+h += [b'MIME-Version: 1.0', b'Content-Type: text/plain; charset=UTF-8', b'Content-Transfer-Encoding: ' + cte.encode()]
100+b = base64.encodebytes(b) if cte == 'base64' else quopri.encodestring(b)
101+open(p, 'wb').write(b'\n'.join(h) + b'\n\n' + b)
102+EOF
103+}
104+n_binary_b64() { # the binary patch with its mail body base64: only git's own numstat after the apply sees it
105+ N=$((N+1)); newclone w; printf 'bin\000\001\002%s' "$N" > "$T/w/blob$N.dat"; G -C "$T/w" add -A; G -C "$T/w" commit -q -m "binary $N"; mkmbox "$T/w" origin/main
106+ grep -q '^GIT binary patch$' "$MBOX" || bad "FIXTURE: no binary patch in the mbox"
107+ encmail base64; ! grep -q '^GIT binary patch$\|^Binary files \|^diff --git ' "$MBOX" || bad "FIXTURE: the base64 mail still shows a diff line"
108+ TITLE="Binary base64 $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="binary patches are not accepted"; }
109+n_binary_noapply() { # a binary file and an edit whose context the base lacks: the early scan refuses it before any git run
110+ N=$((N+1)); newclone w; printf 'bin\000\001\002%s' "$N" > "$T/w/blob$N.dat"; sed -i 's/^four$/FOUR '"$N"'/' "$T/w/src/a.txt"
111+ G -C "$T/w" add -A; G -C "$T/w" commit -q -m "binary and edit $N"; mkmbox "$T/w" origin/main
112+ grep -q '^GIT binary patch$' "$MBOX" || bad "FIXTURE: no binary patch in the mbox"
113+ BASE=$A; TITLE="Binary edit $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="binary patches are not accepted"; }
114+EMPTYT=4b825dc642cb6eb9a060e54bf8d69288fbee4904 # the empty tree: git --attr-source=$EMPTYT reads no attributes
115+NOMARK='^GIT binary patch$\|^Binary files '
116+tab=$'\t'
117+# n_binary_attr: the commit adds .gitattributes "*.dat diff" and a .dat file holding NUL bytes. The sender's
118+# git reads that attribute and formats the file as text (no marker in the mbox, the NUL bytes raw in it), and
119+# so would the forge's git (numstat counts lines) if it read the patch's attributes. The forge's git runs with
120+# --attr-source=<empty tree>, so its numstat marks the file binary (the byte check would refuse it as well)
121+n_binary_attr() { N=$((N+1)); newclone w; printf '*.dat diff\n' > "$T/w/.gitattributes"; printf 'bin\000\001\002\377zz %s\n' "$N" > "$T/w/blob$N.dat"
122+ G -C "$T/w" add -A; G -C "$T/w" commit -q -m "attr binary $N"; mkmbox "$T/w" origin/main
123+ ! grep -aq "$NOMARK" "$MBOX" && [ "$(tr -cd '\000' < "$MBOX" | wc -c)" -gt 0 ] || bad "FIXTURE: the attribute mbox shows a binary marker or holds no NUL byte"
124+ G -C "$T/w" diff --numstat "$BASE" HEAD | grep -qx "1${tab}0${tab}blob$N.dat" || bad "FIXTURE: with its attribute git does not count blob$N.dat as text"
125+ G -C "$T/w" --attr-source=$EMPTYT diff --numstat "$BASE" HEAD | grep -qx -- "-${tab}-${tab}blob$N.dat" || bad "FIXTURE: without attributes git does not mark blob$N.dat binary"
126+ TITLE="Attr binary $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="binary patches are not accepted"; }
127+# n_binary_late: a file whose first NUL byte is after byte 8000 (8200 bytes of "a", then NUL bytes). git's
128+# binary test reads only the first 8000 bytes, so git calls it text everywhere (no marker in the mbox, numstat
129+# counts lines); only the byte check of the combined diff after the apply refuses it
130+n_binary_late() { N=$((N+1)); newclone w; { head -c 8200 /dev/zero | tr '\0' a; printf '\000\001\002\377 tail %s\n' "$N"; } > "$T/w/late$N.dat"
131+ G -C "$T/w" add -A; G -C "$T/w" commit -q -m "late NUL $N"; mkmbox "$T/w" origin/main
132+ ! grep -aq "$NOMARK" "$MBOX" && [ "$(tr -cd '\000' < "$MBOX" | wc -c)" -gt 0 ] || bad "FIXTURE: the late-NUL mbox shows a binary marker or holds no NUL byte"
133+ G -C "$T/w" --attr-source=$EMPTYT diff --numstat "$BASE" HEAD | grep -qx "1${tab}0${tab}late$N.dat" || bad "FIXTURE: git does not count late$N.dat as text"
134+ TITLE="Late NUL $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="binary patches are not accepted"; }
135+# p_attr_text: the commit adds .gitattributes ("*.dat diff" and "*.txt -diff") and text files blob.dat and
136+# plain.txt; the mbox is made with no attributes read (the sender's own git would mark plain.txt binary). It is
137+# accepted and the stored diff is git's diff with no attributes (the .txt's line is in it, its -diff is not
138+# read); a forge that read the patch's attributes would refuse it as binary. C=ok when so; WANT=ok.
139+p_attr_text() { N=$((N+1)); newclone w; printf '*.dat diff\n*.txt -diff\n' > "$T/w/.gitattributes"; printf 'text %s\n' "$N" > "$T/w/blob$N.dat"; printf 'plain %s\n' "$N" > "$T/w/plain$N.txt"
140+ G -C "$T/w" add -A; G -C "$T/w" commit -q -m "attr text $N"; mkmbox "$T/w" origin/main
141+ git -C "$T/w" --attr-source=$EMPTYT format-patch --stdout "$BASE..HEAD" > "$MBOX"
142+ git -C "$T/w" diff "$BASE" HEAD | grep -qx "Binary files /dev/null and b/plain$N.txt differ" || bad "FIXTURE: -diff does not mark plain$N.txt binary in the sender's own diff"
143+ ! grep -aq "$NOMARK" "$MBOX" || bad "FIXTURE: the attribute text mbox shows a binary marker"
144+ git -C "$T/w" --attr-source=$EMPTYT diff --full-index -M "$BASE" HEAD > "$T/attr.oracle"
145+ TITLE="Attr text $N"; DESC=; sigmake; C=$(upload); ID=$(newid)
146+ if [ "$C" = 201 ] && [ "$(staged)" = 0 ] && [ "$(tmpleft)" = 0 ] && grep -qx "+plain $N" "$T/attr.oracle" \
147+ && cmp -s "$T/data/patches/$OWNER/fixrepo/$ID/diff" "$T/attr.oracle"; then C=ok; fi
148+ WANT=ok; WHY=; KEPT=$(kept); }
149+n_submodule() { N=$((N+1)); newclone w; G -C "$T/w" update-index --add --cacheinfo "160000,$A,sub$N"; G -C "$T/w" commit -q -m "submodule $N"; mkmbox "$T/w" origin/main
150+ grep -q '^new file mode 160000$' "$MBOX" || bad "FIXTURE: no submodule entry in the mbox"
151+ TITLE="Submodule $N"; DESC=; sigmake; C=$(upload); WANT=422; WHY="the patch adds a submodule"; }
152+n_title_long() { std; TITLE=$(printf '%257s' '' | tr ' ' t); sigmake; C=$(upload); WANT=400; WHY="the title must be 1 to 256 bytes of UTF-8 text on one line"; }
153+n_title_empty() { std; TITLE=; sigmake; C=$(upload); WANT=400; WHY="the title must be 1 to 256 bytes of UTF-8 text on one line"; }
154+n_title_lines() { std; TITLE=$'two\nlines'; sigmake; C=$(upload); WANT=400; WHY="the title must be 1 to 256 bytes of UTF-8 text on one line"; }
155+n_title_utf8() { std; TITLE=$'bad \xff byte'; sigmake; C=$(upload); WANT=400; WHY="the title must be 1 to 256 bytes of UTF-8 text on one line"; }
156+n_desc_long() { std; DESC=$(printf '%60001s' '' | tr ' ' d); sigmake; C=$(upload); WANT=400; WHY="the description must be at most 60000 bytes of UTF-8 text without control bytes"; }
157+n_desc_ctl() { std; DESC=$'bell \a here'; sigmake; C=$(upload); WANT=400; WHY="the description must be at most 60000 bytes of UTF-8 text without control bytes"; }
158+# n_repo_field: the statement is signed for this repository, the repo field names another (only the field check sees it)
159+n_repo_field() { std; r=$REPOF; REPOF=$OWNER/nostore; C=$(upload); REPOF=$r; WANT=400; WHY="the repo field does not name this repository"; }
160+# n_repo_signed: the statement and the repo field both name another repository
161+n_repo_signed() { std; r=$REPOF; REPOF=$OWNER/nostore; sigmake; C=$(upload); REPOF=$r; WANT=400; WHY="the repo field does not name this repository"; }
162+n_replay() { C=$(upload); WANT=200; WHY=; } # the last accepted upload again (not a refusal: see below)
163+RATE="too many writes from this address or key; wait a minute"
164+# minute: wait until at most second 20 of a wall-clock minute, so a flood and its count sit in one minute of the
165+# per-key counter (social/30store.om soratev and sordok count a key's writes per minute, ts / 60)
166+minute() { s=$(( $(date +%s) % 60 )); [ "$s" -le 20 ] || sleep $((60 - s)); }
167+# events DID: the events of DID in the social log in the current minute (each counts as a write of that key)
168+events() { m=$(( $(date +%s) / 60 )); grep -F "\"did\":\"$1\"" "$T/social/social.log" | sed -n 's/^{"seq":[0-9]*,"ts":\([0-9]*\),.*/\1/p' | awk -v m="$m" 'int($1 / 60) == m' | wc -l; }
169+# n_perkey: 30 writes of the signed-in key in one minute, each from its own address (so no address limit is
170+# reached), then its signed upload from one more address
171+n_perkey() { minute; std; b=$BASE; BASE=zz; for i in $(seq 30); do IP=10.9.$((N % 200)).$i; upload > /dev/null; done
172+ BASE=$b; IP=10.9.250.$((N % 200)); C=$(upload); WANT=429; WHY=$RATE; }
173+# n_perip: from the signed-in key's address, 20 writes by another key's session (SESA, TOKA) and 10 by this key,
174+# each key under its own limit, then this key's signed upload from that address
175+n_perip() { std; s=$SES; t=$TOK; b=$BASE; BASE=zz; SES=$SESA; TOK=$TOKA; for i in $(seq 20); do upload > /dev/null; done
176+ SES=$s; TOK=$t; for i in $(seq 10); do upload > /dev/null; done; BASE=$b; C=$(upload); WANT=429; WHY=$RATE; }
177+
178+neg() { # LABEL FUNCTION
179+ KEPT=$(kept); "$2"
180+ if isref "$WANT" "$WHY"; then ok "NEG $1: $C \"$WHY\", nothing kept"
181+ else bad "NEG $1: want $WANT \"$WHY\" and $KEPT kept; got $C \"$(head -c 160 "$T/body" | tr '\n' ' ')\" kept $(kept) staged $(staged) work $(tmpleft)"; fi
182+}
183+pos() { KEPT=$(kept); C=$(upload "${@:2}"); accepted "$C" "$1"; }
184+
185+# ---- keys and sessions. Each key stays under the gate's 30 writes a minute; addresses differ.
186+for k in k1 k2 k3 k4 k5 k6 k7 k8 k9 kp1 kp2; do newkey $k; done
187+signin k1 10.1.0.1 || exit 1; OLDSES=$SES; OLDTOK=$TOK
188+signin k3 10.1.0.3 || exit 1; SES3=$SES; TOK2=$TOK
189+signin k1 10.1.0.1 || exit 1; SES1=$SES; TOK1=$TOK; DID1=$DID
190+[ "$OLDTOK" != "$TOK1" ] && ok "a new session has a new CSRF token" || bad "the CSRF token did not change with the session"
191+
192+echo "== session and CSRF"
193+neg "unsigned upload (no session)" n_unsigned
194+neg "stale CSRF token (of this key's earlier session)" n_csrf_stale
195+neg "foreign CSRF token (of another key's session)" n_csrf_foreign
196+std; pos "the same kind of upload with its session and token"
197+FIRST=$ID; FIRSTMB=$MBOX; FIRSTBASE=$BASE; FIRSTTITLE=$TITLE; FIRSTDESC=$DESC; cp "$T/stmt" "$T/first.stmt"; cp "$SIGF" "$T/first.sig"
198+
199+echo "== replay of the same statement"
200+KEPT=$(kept); n_replay
201+if [ "$C" = 200 ] && [ "$(head -1 "$T/body")" = exists ] && [ "$(newid)" = "$FIRST" ] && [ "$(kept)" = "$KEPT" ] && [ "$(staged)" = 0 ] && [ "$(tmpleft)" = 0 ] \
202+ && [ "$(grep -c "^$FIRST\$" "$T/data/patches/$OWNER/fixrepo/index")" = 1 ]; then
203+ ok "NEG replay: 200 exists with the first id $FIRST, nothing new kept, one index line"
204+else bad "NEG replay: got $C \"$(head -c 120 "$T/body" | tr '\n' ' ')\" kept $(kept) (was $KEPT)"; fi
205+
206+echo "== signature"
207+neg "forged signature (one letter changed)" n_sig_forged
208+neg "signature over another title" n_sig_other_text
209+neg "signature by another key than the session's" n_sig_other_key
210+std; pos "the same kind of upload signed by the session's key"
211+
212+echo "== base"
213+neg "unknown base" n_base_unknown
214+neg "base on a branch that is not main" n_base_side
215+std; pos "the same kind of upload with a base on main"
216+N=$((N+1)); newclone w "$A"; commitf "$T/w" "notes/n$N.txt" "line $N" "note $N"; mkmbox "$T/w" "$A"; TITLE="Old base $N"; DESC=; sigmake
217+pos "a base that is an older commit of main"
218+
219+signin k2 10.1.0.2 || exit 1
220+echo "== sizes"
221+neg "mbox over 2 MiB" n_mbox_big
222+N=$((N+1)); newclone w; seq 1 250000 > "$T/w/large$N.txt"; G -C "$T/w" add -A; G -C "$T/w" commit -q -m "large $N"; mkmbox "$T/w" origin/main
223+TITLE="Large $N"; DESC=; sigmake; echo "the large mbox is $(stat -c %s "$MBOX") bytes"
224+pos "an mbox of more than 1.5 MiB and under 2 MiB"
225+neg "101 commits" n_commits_101
226+N=$((N+1)); newclone w; for i in $(seq 100); do commitf "$T/w" "many/m$N.txt" "$i" "c $i"; done; mkmbox "$T/w" origin/main; TITLE="Hundred $N"; DESC=; sigmake
227+pos "100 commits"
228+curl -s -H 'Accept: application/json' "$B$R/patches/$ID" | grep -q '"commits":100,' && ok "the 100-commit patch is stored as 100 commits" || bad "commit count of the 100-commit patch"
229+neg "title of 257 bytes" n_title_long
230+neg "empty title" n_title_empty
231+neg "title of two lines" n_title_lines
232+neg "title that is not UTF-8" n_title_utf8
233+std; TITLE=$(printf '%254s' '' | tr ' ' t)é; sigmake; pos "a title of exactly 256 bytes"
234+neg "description of 60001 bytes" n_desc_long
235+neg "description with a control byte" n_desc_ctl
236+std; DESC=$(printf '%59998s' '' | tr ' ' d)$'\n\t'; sigmake; pos "a description of exactly 60000 bytes with a tab and a line feed"
237+# a body over the 3 MiB the route reads is refused before any handler: 413, nothing kept
238+KEPT=$(kept); head -c 3200000 /dev/zero | tr '\0' a > "$T/huge"
239+C=$(curl -s -o "$T/body" -w '%{http_code}' -X POST -H "Cookie: __Host-forge_session=$SES" --data-binary "@$T/huge" "$B$R/patches/new")
240+[ "$C" = 413 ] && [ "$(kept)" = "$KEPT" ] && alive && ok "NEG a body over 3 MiB: 413 before any handler, nothing kept" || bad "NEG body over 3 MiB: $C"
241+# another POST keeps its 64 KiB body cap
242+head -c 70000 /dev/zero | tr '\0' a > "$T/mid"
243+C=$(curl -s -o /dev/null -w '%{http_code}' -X POST -H "Cookie: __Host-forge_session=$SES" --data-binary "@$T/mid" "$B$R/star")
244+check "$C" 413 "NEG a 70000-byte body on another POST route is still refused"
245+for route in "$R/extra/patches/new" "/$OWNER//patches/new"; do
246+ C=$(curl -s -o /dev/null -w '%{http_code}' -X POST --data-binary "@$T/mid" "$B$route")
247+ check "$C" 413 "only the exact patch upload route gets the larger request limit ($route)"
248+done
249+
250+signin k4 10.1.0.4 || exit 1
251+echo "== the mbox applies"
252+neg "mbox that does not apply on its base" n_noapply
253+BASE=$MAIN; sigmake; pos "the same mbox with the base it was made on"
254+neg "path outside the repository (.. in the git diff header)" n_path_out
255+neg "absolute path in the git diff header" n_path_abs
256+neg "rename to a path outside the repository" n_path_rename
257+neg "Git copy headers are refused" n_copy_header
258+n_copy_encoded() { n_copy_header base64; }
259+neg "Git copy headers are refused after mail decoding" n_copy_encoded
260+neg "path outside the repository in a plain diff (refused by git apply)" n_path_plain
261+neg "C-quoted path outside the repository (\"a/\\056\\056/x\", refused by git apply)" n_path_quoted
262+std; pos "the same kind of patch with its path inside the repository"
263+neg "binary patch" n_binary
264+N=$((N+1)); newclone w; printf 'text %s\n' "$N" > "$T/w/blob$N.dat"; G -C "$T/w" add -A; G -C "$T/w" commit -q -m "text $N"; mkmbox "$T/w" origin/main; TITLE="Text $N"; DESC=; sigmake
265+pos "the same file as text"
266+neg "binary patch in a base64 mail body (git numstat after the apply)" n_binary_b64
267+neg "binary patch that also does not apply on its base (the early scan, before any git run)" n_binary_noapply
268+signin k7 10.1.0.7 || exit 1 # the binary controls below and the rest of this part: k4 has used most of its 30 writes a minute
269+neg "a .gitattributes (*.dat diff) that makes git call a file with NUL bytes text (no attribute file of the patch is read)" n_binary_attr
270+neg "a file whose first NUL byte is after byte 8000 (git's binary test misses it; the byte check of the applied diff)" n_binary_late
271+K0=$(kept); p_attr_text
272+[ "$C" = ok ] && [ "$(kept)" = $((K0 + 1)) ] && ok "POS a .gitattributes (*.dat diff, *.txt -diff) with text files: 201, the stored diff is git's diff without attributes (the -diff file's line is in it)" \
273+ || bad "POS attribute text: $C \"$(head -c 120 "$T/body" | tr '\n' ' ')\" kept $(kept) (was $K0)"
274+N=$((N+1)); newclone w; { head -c 8200 /dev/zero | tr '\0' a; printf '\001\002\377 tail %s\n' "$N"; } > "$T/w/late$N.dat"; G -C "$T/w" add -A; G -C "$T/w" commit -q -m "late text $N"
275+mkmbox "$T/w" origin/main; TITLE="Late text $N"; DESC=; sigmake
276+pos "the late shape without the NUL byte (8200 bytes of a, then bytes 1, 2 and 377)"
277+LC_ALL=C grep -aqxF "+$(head -c 8200 /dev/zero | tr '\0' a)"$'\001\002\377'" tail $N" "$T/data/patches/$OWNER/fixrepo/$ID/diff" && ok "the stored diff holds the late line as sent" || bad "late text: stored diff lacks the line"
278+N=$((N+1)); newclone w; printf 'text=%s\n' "$N" > "$T/w/blob$N.dat"; G -C "$T/w" add -A; G -C "$T/w" commit -q -m "text $N"; mkmbox "$T/w" origin/main; encmail quoted-printable
279+grep -q '^Content-Transfer-Encoding: quoted-printable$' "$MBOX" && grep -q '^+text=3D' "$MBOX" || bad "FIXTURE: the mail body is not quoted-printable"
280+TITLE="Text QP $N"; DESC=; sigmake
281+pos "the same file as text in a quoted-printable mail body"
282+grep -qx "+text=$N" "$T/data/patches/$OWNER/fixrepo/$ID/diff" && ok "the stored diff holds the decoded line (git am decoded the quoted-printable body)" \
283+ || bad "QP stored diff: $(grep '^+text' "$T/data/patches/$OWNER/fixrepo/$ID/diff")"
284+neg "submodule entry" n_submodule
285+neg "repo field naming another repository (the statement signed for this one)" n_repo_field
286+neg "repo field and signed statement both naming another repository" n_repo_signed
287+# a symbolic link and a deep folder are ordinary git content: accepted, and the work folder is gone
288+N=$((N+1)); newclone w; ln -s ../../../etc/passwd "$T/w/link$N"; mkdir -p "$T/w/$(printf 'd/%.0s' $(seq 40))"; echo deep > "$T/w/$(printf 'd/%.0s' $(seq 40))f$N"
289+G -C "$T/w" add -A; G -C "$T/w" commit -q -m "link and deep $N"; mkmbox "$T/w" origin/main; TITLE="Link $N"; DESC=; sigmake
290+pos "a symbolic link and a file 40 folders deep"
291+[ -z "$(find "$T/data" -type l)" ] && ok "no symbolic link was left in the data folder" || bad "a symbolic link exists under the data folder"
292+
293+echo "== the form and the repository"
294+UPATH=/$OWNER/nope/patches/new; std; KEPT=$(kept); C=$(upload)
295+isref 404 "no such public repository" && ok "NEG a repository outside the public list: 404 after the gate" || bad "NEG unlisted repository: $C $(reason)"
296+s=$SES; SES=; C=$(upload); SES=$s
297+isref 403 "sign in first: this request carries no session" && ok "NEG unlisted repository, unsigned: the gate answers first (403)" || bad "NEG unlisted unsigned: $C $(reason)"
298+# the catalog serves a project only while its repo.git is there when the list is loaded, so the store's nostore
299+# repository is moved away while the server runs (and put back): the row is still listed, its git store is gone
300+check "$(code GET "/$OWNER/nostore/patches")" 200 "the second project's patch list answers before its git store is moved away"
301+mv "$T/store/projects/nostore/repo.git" "$T/nostore.away"
302+UPATH=/$OWNER/nostore/patches/new; REPOF=$OWNER/nostore; sigmake; C=$(upload); REPOF=$OWNER/fixrepo
303+isref 404 "this repository has no git store on this forge" && ok "NEG a listed repository whose git store is gone: 404" || bad "NEG no git store: $C $(reason)"
304+mv "$T/nostore.away" "$T/store/projects/nostore/repo.git"
305+UPATH=
306+form() { : > "$T/body"; curl -s -o "$T/body" -w '%{http_code}' -X POST -H "X-Real-IP: $IP" -H "Cookie: __Host-forge_session=$SES" "$@" "$B$R/patches/new"; }
307+F=(--data-urlencode "csrf=$TOK" --data-urlencode "repo=$REPOF" --data-urlencode "base=$MAIN" --data-urlencode "title=t" --data-urlencode "description=" --data-urlencode "sig@$SIGF")
308+KEPT=$(kept)
309+C=$(form "${F[@]}"); isref 400 "the body is not the patch form: fields csrf, repo, base, title, description, mbox and sig, each once" && ok "NEG a form without the mbox field: 400" || bad "NEG missing field: $C $(reason)"
310+C=$(form "${F[@]}" --data-urlencode "mbox=AAAA" --data-urlencode "mbox=AAAA"); isref 400 "the body is not the patch form: fields csrf, repo, base, title, description, mbox and sig, each once" && ok "NEG a field twice: 400" || bad "NEG field twice: $C $(reason)"
311+C=$(form "${F[@]}" --data-urlencode "mbox=AAAA" --data-urlencode "extra=1"); isref 400 "the body is not the patch form: fields csrf, repo, base, title, description, mbox and sig, each once" && ok "NEG an unknown field: 400" || bad "NEG unknown field: $C $(reason)"
312+C=$(form "${F[@]}" --data-urlencode "mbox=not base64!"); isref 400 "the mbox field is not base64url without padding" && ok "NEG an mbox that is not base64url: 400" || bad "NEG not base64url: $C $(reason)"
313+C=$(form "${F[@]}" --data-urlencode "mbox=QQ=="); isref 400 "the mbox field is not base64url without padding" && ok "NEG a padded mbox: 400" || bad "NEG padded: $C $(reason)"
314+C=$(form "${F[@]}" --data-urlencode "mbox=QR"); isref 400 "the mbox field is not base64url without padding" && ok "NEG an mbox with unused bits set: 400" || bad "NEG unused bits: $C $(reason)"
315+C=$(form "${F[@]}" --data-urlencode "mbox=aGVsbG8K"); isref 400 "the mbox is not git format-patch output" && ok "NEG an mbox that is not format-patch output: 400" || bad "NEG not format-patch: $C $(reason)"
316+F[5]="base=${MAIN:0:39}G"
317+C=$(form "${F[@]}" --data-urlencode "mbox=AAAA"); isref 400 "base is not a commit id of 40 lowercase hex digits" && ok "NEG a base that is not 40 hex: 400" || bad "NEG bad base: $C $(reason)"
318+std; echo "not a signature" > "$T/bad.sig"; SIGF=$T/bad.sig; KEPT=$(kept); C=$(upload)
319+isref 400 "the sig field is not an armored SSH signature" && ok "NEG a sig that is not an armored signature: 400" || bad "NEG bad sig field: $C $(reason)"
320+sigmake; C=$(upload -H 'Origin: https://evil.example'); [ "$C" = 403 ] && [ "$(kept)" = "$KEPT" ] && ok "NEG an upload naming another Origin: 403" || bad "NEG other origin: $C"
321+C=$(code POST "$R/patches" -H "Cookie: __Host-forge_session=$SES" -d x=1); check "$C" 405 "NEG POST to the list"
322+C=$(code POST "$R/patches/$FIRST" -H "Cookie: __Host-forge_session=$SES" -d x=1); check "$C" 405 "NEG POST to a patch page"
323+alive && ok "forged is still running after every refusal" || { bad "forged ended"; start; }
324+
325+echo "== read routes"
326+SD=$T/data/patches/$OWNER/fixrepo/$FIRST
327+cmp -s "$SD/mbox" "$FIRSTMB" && ok "the stored mbox is byte-equal to the mbox that was sent" || bad "stored mbox differs"
328+cmp -s "$SD/statement" "$T/first.stmt" && ok "the stored statement is the signed statement" || bad "stored statement differs"
329+cmp -s "$SD/signature" "$T/first.sig" && ok "the stored signature is the signature that was sent" || bad "stored signature differs"
330+[ "$(cat "$SD/status")" = open ] && ok "status file says open" || bad "status file"
331+[ "$(sha < "$T/first.stmt" | cut -c1-16)" = "$FIRST" ] && ok "the id is the first 16 hex of the statement's SHA-256" || bad "id is not sha256(statement)[0:16]"
332+printf '%s' "$(cat "$T/first.stmt")" | ssh-keygen -Y check-novalidate -n interplane-patch -f "$T/k1.pub" -s "$SD/signature" > /dev/null 2>&1 < "$T/first.stmt" \
333+ && ok "ssh-keygen verifies the stored signature over the stored statement with the author's key" || bad "ssh-keygen does not verify the stored pair"
334+[ "$(ls "$SD" | tr '\n' ' ')" = "description diff head mbox meta signature statement status title " ] && ok "the patch folder holds exactly the nine files" || bad "patch folder: $(ls "$SD" | tr '\n' ' ')"
335+# oracle: git am of the raw route onto the base in a fresh clone, with the forge's committer, gives the stored head
336+curl -s -o "$T/raw.patch" -w '%{http_code}' "$B$R/patches/$FIRST.patch" > "$T/rc"
337+[ "$(cat "$T/rc")" = 200 ] && cmp -s "$T/raw.patch" "$FIRSTMB" && ok "GET .patch is byte-equal to the mbox that was sent" || bad "raw .patch route"
338+rm -rf "$T/am"; git clone -q "$GITS" "$T/am"; git -C "$T/am" checkout -q --detach "$FIRSTBASE"
339+git -C "$T/am" -c user.name=interplane-forge -c user.email=forge@interplane.io am -q --committer-date-is-author-date "$T/raw.patch" 2> "$T/am.err"
340+[ "$(git -C "$T/am" rev-parse HEAD)" = "$(cat "$SD/head")" ] && ok "git am of the raw route onto the base in a fresh clone gives the stored head $(cut -c1-12 "$SD/head")" || bad "git am oracle: $(git -C "$T/am" rev-parse HEAD) is not $(cat "$SD/head") $(cat "$T/am.err")"
341+curl -s -o "$T/raw.diff" "$B$R/patches/$FIRST.diff"
342+git -C "$T/am" diff --full-index -M "$FIRSTBASE" HEAD > "$T/oracle.diff"
343+cmp -s "$T/raw.diff" "$T/oracle.diff" && ok "GET .diff equals git diff --full-index -M base head of that clone" || bad ".diff differs from the oracle"
344+grep -qi '^content-type: text/plain' <(curl -s -D- -o /dev/null "$B$R/patches/$FIRST.patch") && ok ".patch is text/plain" || bad ".patch content type"
345+# jsoncheck LABEL: forge/patch/1 of the first patch and every page of forge/patch-list/1, under both bases
346+jsoncheck() {
347+python3 - "$B" "$R" "$FIRST" "$DID1" "$FIRSTBASE" "$(cat "$SD/head")" "$(sha < "$FIRSTMB")" "$(stat -c %s "$FIRSTMB")" "$FIRSTTITLE" "$FIRSTDESC" "$(kept)" > "$T/json.out" 2>&1 <<'EOF'
348+import json, sys, urllib.request
349+B, R, ID, DID, BASE, HEAD, SHA, BYTES, TITLE, DESC, KEPT = sys.argv[1:]
350+def get(path, base='/'):
351+ rq = urllib.request.Request(B + path, headers={'Accept': 'application/json', 'X-Forge-Base': base})
352+ with urllib.request.urlopen(rq) as r:
353+ assert r.headers['Content-Type'] == 'application/json; charset=utf-8', r.headers['Content-Type']
354+ return json.loads(r.read().decode('utf-8'))
355+for base in ('/', '/forge/'):
356+ p = base.rstrip('/') + R + '/patches/' + ID
357+ d = get(R + '/patches/' + ID, base)
358+ # the key set of SPEC-ext section 3: the same keys for a signed patch and an imported item, in this order
359+ want = {'schema': 'forge/patch/1', 'base': base, 'owner': R.split('/')[1], 'repo': R.split('/')[2], 'id': ID, 'title': TITLE,
360+ 'description': DESC, 'status': 'open', 'state_derived': False, 'author': {'did': DID, 'name': None}, 'imported': None,
361+ 'base_commit': BASE, 'head_commit': HEAD, 'commits': 1, 'files': 1, 'bytes': int(BYTES), 'code': 'mbox', 'mbox_sha256': SHA,
362+ 'opened': None, 'closed': None, 'merge': None, 'labels': [], 'comments': [], 'thread_truncated': False, 'thread_reason': None,
363+ 'created': None, 'path': p, 'patch': p + '.patch', 'diff': p + '.diff', 'diff_unavailable': None, 'bundle': None}
364+ assert list(d.keys()) == list(want.keys()), list(d.keys())
365+ created = d.pop('created'); want.pop('created')
366+ assert len(created) == 20 and created.endswith('Z'), created
367+ assert d == want, (d, want)
368+ assert list(d['author'].keys()) == ['did', 'name'], d['author']
369+ rows = []; page = 1; l = None
370+ while True:
371+ l = get(R + '/patches?page=%d' % page, base)
372+ assert l['schema'] == 'forge/patch-list/1' and l['base'] == base and l['page'] == page and l['per_page'] == 30, l
373+ assert l['count'] == int(KEPT), (l['count'], KEPT)
374+ assert list(l.keys()) == ['schema', 'base', 'owner', 'repo', 'page', 'per_page', 'count', 'states', 'damaged', 'patches', 'next', 'prev'], list(l.keys())
375+ # the listed items by state, on every page; here the store holds signed patches only: each counts as open, no index line is damaged
376+ assert l['states'] == {'open': int(KEPT), 'closed': 0, 'merged': 0} and list(l['states'].keys()) == ['open', 'closed', 'merged'], l['states']
377+ assert l['damaged'] == 0 and type(l['damaged']) is int, l['damaged']
378+ assert len(l['patches']) <= 30
379+ rows += l['patches']
380+ assert (l['prev'] is None) == (page == 1)
381+ if l['next'] is None: break
382+ assert l['next'] == base.rstrip('/') + R + '/patches?page=%d' % (page + 1), l['next']
383+ page += 1
384+ assert len(rows) == int(KEPT), (len(rows), KEPT)
385+ assert len(set(x['id'] for x in rows)) == len(rows)
386+ assert rows[-1]['id'] == ID, 'the first patch is the last row (newest first)'
387+ row = dict(rows[-1])
388+ assert list(row.keys()) == ['id', 'title', 'status', 'state_derived', 'author', 'imported', 'base_commit', 'head_commit', 'commits', 'files',
389+ 'bytes', 'code', 'created', 'comments_count', 'path', 'patch', 'diff', 'diff_unavailable', 'bundle'], list(row.keys())
390+ for k in ('schema', 'base', 'owner', 'repo', 'description', 'mbox_sha256', 'opened', 'closed', 'merge', 'labels', 'comments', 'thread_truncated', 'thread_reason'): want.pop(k)
391+ rc = row.pop('created'); assert rc == created
392+ want['comments_count'] = 0
393+ assert row == want, (row, want)
394+ ts = [x['created'] for x in rows]; assert ts == sorted(ts, reverse=True), 'newest first'
395+print('json ok')
396+EOF
397+grep -qx 'json ok' "$T/json.out" && ok "$1: forge/patch/1 and forge/patch-list/1 under both bases: every key, value, order and page" || bad "JSON ($1): $(tail -3 "$T/json.out")"
398+}
399+jsoncheck "read routes, $(kept) patches"
400+untr() { sed -i 's/<span translate="no">\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$T/body"; }
401+# listcheck BASE: list page 1 under BASE, and page 2 when the store holds more than 30 (at most 60): rows,
402+# the newest patch ($ID) on page 1, the first patch on the last page, and the pager links
403+listcheck() {
404+ P=${1%/}; k=$(kept); r1=$k; [ "$k" -gt 30 ] && r1=30
405+ c=$(code GET "$R/patches" -H "X-Forge-Base: $1"); untr; n=$(grep -o '<li><a class="subject"' "$T/body" | wc -l)
406+ if [ "$k" -gt 30 ]; then grep -qF "href=\"$P$R/patches?page=2\">Older</a>" "$T/body"; o=$?; else ! grep -qF '">Older</a>' "$T/body"; o=$?; fi
407+ [ "$c" = 200 ] && [ "$n" = "$r1" ] && [ "$o" = 0 ] && grep -qF "href=\"$P$R/patches/$ID\"" "$T/body" && ! grep -qF '">Newer</a>' "$T/body" \
408+ && { [ "$k" -gt 30 ] || grep -qF "href=\"$P$R/patches/$FIRST\"" "$T/body"; } \
409+ && ok "[$1] list page 1: $n rows of $k, the newest first, a link to page 2 exactly when more than 30" || bad "[$1] list page 1 ($c, $n rows of $k, older-link check $o)"
410+ [ "$k" -gt 30 ] || return 0
411+ c=$(code GET "$R/patches?page=2" -H "X-Forge-Base: $1"); untr; n=$(grep -o '<li><a class="subject"' "$T/body" | wc -l)
412+ [ "$c" = 200 ] && [ "$n" = $((k - 30)) ] && grep -qF "href=\"$P$R/patches/$FIRST\"" "$T/body" && grep -qF "href=\"$P$R/patches?page=1\">Newer</a>" "$T/body" \
413+ && ! grep -qF '">Older</a>' "$T/body" && ok "[$1] list page 2: the other $n rows, the first patch among them, a link back to page 1" || bad "[$1] list page 2 ($c, $n rows of $k)"
414+}
415+for base in / /forge/; do
416+ P=${base%/}
417+ c=$(code GET "$R/patches/$FIRST" -H "X-Forge-Base: $base")
418+ untr
419+ if [ "$c" = 200 ] && grep -qF "<h2>$FIRSTTITLE</h2>" "$T/body" && grep -qF "href=\"$P$R/patches/$FIRST.patch\"" "$T/body" && grep -qF "href=\"$P$R/commit/$FIRSTBASE\"" "$T/body" \
420+ && grep -qF "${DID1}" "$T/body" && grep -qF "interplane-patch 1" "$T/body" && grep -qF -- "-----BEGIN SSH SIGNATURE-----" "$T/body"; then
421+ ok "[$base] the patch page shows title, author, base, statement, signature and the raw links"
422+ else bad "[$base] patch page ($c)"; fi
423+ listcheck "$base"
424+ c=$(code GET "$R/patches/new" -H "X-Forge-Base: $base"); [ "$c" = 200 ] && grep -qF "interplane patch $OWNER/fixrepo" "$T/body" && ok "[$base] the how-to page names the command" || bad "[$base] how-to page ($c)"
425+done
426+# markup in a title and a description is shown as text
427+std; TITLE='<b>bold</b> & "q"'; DESC='<script>x</script>'; sigmake; pos "a title and a description holding markup"
428+c=$(code GET "$R/patches/$ID"); grep -qF '&lt;b&gt;bold&lt;/b&gt; &amp; &quot;q&quot;' "$T/body" && grep -qF '&lt;script&gt;x&lt;/script&gt;' "$T/body" && ! grep -qF '<script>' "$T/body" \
429+ && ok "markup in the title and description is escaped on the page" || bad "escaping on the patch page"
430+check "$(code GET "$R/patches/0123456789abcdef")" 404 "NEG an id the store does not hold"
431+check "$(code GET "$R/patches/${FIRST:0:15}")" 404 "NEG an id of 15 digits"
432+check "$(code GET "$R/patches/${FIRST}0")" 404 "NEG an id of 17 digits"
433+check "$(code GET "$R/patches/$(echo "$FIRST" | tr a-f A-F | tr 0-9 A-J)")" 404 "NEG an id that is not lowercase hex"
434+check "$(code GET "$R/patches/$FIRST.receipt")" 404 "NEG the old .receipt name"
435+check "$(code GET "$R/patches/$FIRST/compose")" 404 "NEG the old compose path"
436+check "$(code GET "$R/patches?page=99")" 404 "NEG a list page past the end"
437+check "$(code GET "/$OWNER/nope/patches")" 404 "NEG the list of a repository outside the public list"
438+c=$(code GET "$R/pulls"); [ "$c" = 302 ] && [ "$(hdr location)" = "$R/patches" ] && ok "/pulls redirects to /patches" || bad "/pulls: $c $(hdr location)"
439+c=$(code GET "$R/pull/$FIRST"); [ "$c" = 302 ] && [ "$(hdr location)" = "$R/patches/$FIRST" ] && ok "/pull/<id> redirects to /patches/<id>" || bad "/pull/<id>: $c $(hdr location)"
440+# Dropped on this line, with the reason: "insights counts the stored patches as opened". The store-reading build
441+# composes growth out (store/mvgrowth.om), so /insights answers 404 and shows no patch count.
442+# Changed on this line: /issues is collab's, which the store-reading build composes out (server/nocollab.om); it
443+# must answer what it answered before the patch slice was composed, 501.
444+echo "DROPPED insights patch count: growth is composed out of the store-reading build (the address answers 404, no count)"
445+check "$(code GET "$R/insights")" 404 "insights answers as before the patch slice (404, growth composed out)"
446+check "$(code GET "$R/issues" -H 'Accept: application/json')" 200 "the issues list answers beside the patch slice"
447+jq -e '.schema == "forge/issues/1" and .issues == []' "$T/body" > /dev/null \
448+ && ok "the issues list uses the native issue schema" || bad "the issues list returned the wrong schema"
449+
450+echo "== list pages"
451+# more than 30 patches: two more keys add patches until the store holds 33, then both list pages and the JSON pages
452+signin kp1 10.1.0.11 || exit 1; i=0
453+while [ "$(kept)" -lt 33 ]; do
454+ i=$((i+1)); [ "$i" -le 40 ] || { bad "the list filler stopped at $(kept) patches"; break; }
455+ [ "$i" = 13 ] && { signin kp2 10.1.0.12 || exit 1; }
456+ std; pos "list filler $i"
457+done
458+for base in / /forge/; do listcheck "$base"; done
459+jsoncheck "$(kept) patches on two pages"
460+
461+echo "== rate flood"
462+# per key: a fresh key signs in, then writes from a new address each time until the gate answers. Its budget
463+# is 30 writes a minute less the events its sign-in logged in that minute (social/30store.om soevent counts every
464+# logged event of the key; a first sign-in logs two: account and session).
465+minute; signin k5 10.1.0.5 || exit 1; std; KEPT=$(kept); b=$BASE; BASE=zz; n=0
466+for i in $(seq 40); do IP=10.1.5.$i; C=$(upload); [ "$C" = 400 ] || break; n=$((n+1)); done
467+BASE=$b; e=$(events "$DID")
468+[ $((n + e)) = 30 ] && isref 429 "$RATE" && ok "NEG rate flood (key): $n writes from $n addresses pass the gate beside the key's $e sign-in events of the minute; the next is 429, nothing kept" \
469+ || bad "NEG rate flood (key): $n passed beside $e events, then $C \"$(reason)\" kept $(kept) (was $KEPT)"
470+IP=10.1.5.99; C=$(upload); isref 429 "$RATE" && ok "NEG rate flood (key): the key's signed upload from yet another address is 429, nothing kept" || bad "NEG per-key limit: $C $(reason)"
471+signin k6 10.1.0.6 || exit 1; std; pos "at the same time another key from another address is accepted"
472+# per address: two keys, each under its own limit, write 30 times from one address; the next write from it is 429
473+signin k8 10.1.0.8 || exit 1; SESA=$SES; TOKA=$TOK; signin k9 10.1.0.9 || exit 1
474+neg "rate flood (address): the 31st write in a minute from one address, by two keys under their own limits" n_perip
475+IP=10.1.0.90; pos "the same key and patch from another address is accepted"
476+
477+echo "== interplane patch (tools/bring) against this forged"
478+mkdir -p "$T/tool"; OMC="$OMC" taskset -c "$CORES" nice -n 19 sh tools/bring/build.sh linux "$T/tool" > "$T/tool.build" 2>&1 || bad "tool build: $(cat "$T/tool.build")"
479+TOOL=$T/tool/interplane-linux-aarch64
480+# temp folders of other runs of the tool on this machine (other suites, other lanes) are not this run's
481+TMP0=$(ls -d /tmp/interplane-tool-* 2>/dev/null | sort)
482+tool() { (cd "$T/tc" && env -i HOME="$T/home" INTERPLANE_BASE="$B" "$TOOL" "$@"); }
483+N=$((N+1)); newclone tc; commitf "$T/tc" "tool/t$N.txt" one "tool commit one"; commitf "$T/tc" "tool/u$N.txt" two "tool commit two: the title"
484+LOG0=$(grep -c . "$T/forged.err")
485+tool patch $OWNER/fixrepo < /dev/null > "$T/tool.out" 2>&1; rc=$?
486+if [ "$rc" = 1 ] && grep -qx 'Nothing sent.' "$T/tool.out" && [ ! -e "$T/home/.interplane" ] && [ "$(grep -c . "$T/forged.err")" = "$LOG0" ]; then
487+ ok "NEG tool without --yes and without a terminal: Nothing sent, exit 1, no key made, no request reached the forge"
488+else bad "NEG tool without consent: rc $rc, $(tail -2 "$T/tool.out" | tr '\n' ' ')"; fi
489+grep -qx "Base: $MAIN" "$T/tool.out" && grep -qx 'Commits: 2' "$T/tool.out" && grep -qx 'Files changed: 2' "$T/tool.out" && grep -qx "Repository: $OWNER/fixrepo" "$T/tool.out" \
490+ && grep -qx 'Title: tool commit two: the title' "$T/tool.out" && grep -q '^Bytes: [0-9]*$' "$T/tool.out" \
491+ && ok "the tool shows repository, base (merge base with origin/main), commits, files, bytes and title before asking" || bad "tool summary: $(tr '\n' '|' < "$T/tool.out")"
492+printf 'no\n' | (cd "$T/tc" && env -i HOME="$T/home" INTERPLANE_BASE="$B" script -qec "$TOOL patch $OWNER/fixrepo" /dev/null) > "$T/tool.out" 2>&1; rc=$?
493+[ "$rc" = 1 ] && grep -q 'Nothing sent.' "$T/tool.out" && [ ! -e "$T/home/.interplane" ] && ok "NEG a typed no on the terminal: Nothing sent, exit 1, no key" || bad "NEG typed no: rc $rc"
494+KEPT=$(kept)
495+printf 'yes\n' | (cd "$T/tc" && env -i HOME="$T/home" INTERPLANE_BASE="$B" script -qec "$TOOL patch $OWNER/fixrepo" /dev/null) > "$T/tool.out" 2>&1; rc=$?
496+URL=$(tr -d '\r' < "$T/tool.out" | sed -n 's/^Patch page: //p')
497+if [ "$rc" = 0 ] && [ "$(kept)" = $((KEPT+1)) ] && [ -f "$T/home/.interplane/key" ] && [ "$(stat -c %a "$T/home/.interplane/key")" = 600 ]; then
498+ ok "POS a typed yes on the terminal sends the patch: exit 0, $URL"
499+else bad "POS typed yes: rc $rc, kept $(kept) (was $KEPT): $(tail -3 "$T/tool.out" | tr '\n' '|')"; fi
500+TID=${URL##*/}
501+git -C "$T/tc" format-patch --stdout --no-color --no-ext-diff --no-textconv --no-attach --no-thread --no-cover-letter --src-prefix=a/ --dst-prefix=b/ --no-signature --no-relative --no-notes "$MAIN..HEAD" > "$T/tool.mbox"
502+check "$(curl -s -o "$T/tool.raw" -w '%{http_code}' "$URL.patch")" 200 "the patch page address the tool printed has a raw route"
503+cmp -s "$T/tool.raw" "$T/tool.mbox" && ok "the raw route is byte-equal to git format-patch of the tool's range" || bad "tool raw differs from format-patch"
504+TDID=$(did "$T/home/.interplane/key.pub")
505+curl -s -H 'Accept: application/json' "$URL" > "$T/tool.json"
506+grep -qF "\"did\":\"$TDID\"" "$T/tool.json" && grep -qF '"title":"tool commit two: the title"' "$T/tool.json" && grep -qF '"description":""' "$T/tool.json" \
507+ && ok "the stored patch names the tool's key as author, the HEAD subject as title and an empty description" || bad "tool patch JSON: $(head -c 300 "$T/tool.json")"
508+ssh-keygen -Y check-novalidate -n interplane-patch -f "$T/home/.interplane/key.pub" -s "$T/data/patches/$OWNER/fixrepo/$TID/signature" < "$T/data/patches/$OWNER/fixrepo/$TID/statement" > /dev/null 2>&1 \
509+ && ok "the tool's signature verifies with its own public key and namespace interplane-patch" || bad "tool signature does not verify"
510+KEPT=$(kept); tool patch --yes $OWNER/fixrepo > "$T/tool.out" 2>&1; rc=$?
511+[ "$rc" = 0 ] && grep -qx 'Interplane already has this patch.' "$T/tool.out" && grep -qx "Patch page: $URL" "$T/tool.out" && [ "$(kept)" = "$KEPT" ] && ok "the same patch again: exit 0, the same page, nothing new kept" || bad "tool replay: rc $rc"
512+printf 'Line one.\r\nLine two.\r\n\r\n \n' > "$T/msg.txt"
513+KEPT=$(kept); tool patch --base "$A" --title "Chosen title" --message-file "$T/msg.txt" --yes $OWNER/fixrepo > "$T/tool.out" 2>&1; rc=$?
514+U2=$(sed -n 's/^Patch page: //p' "$T/tool.out")
515+if [ "$rc" = 0 ] && [ "$(kept)" = $((KEPT+1)) ] && grep -qx "Base: $A" "$T/tool.out" && grep -qx 'Commits: 4' "$T/tool.out" \
516+ && curl -s -H 'Accept: application/json' "$U2" | grep -qF '"title":"Chosen title","description":"Line one.\u000aLine two."'; then
517+ ok "POS --base, --title, --message-file and --yes: the base, the title and the description (line ends made LF, end trimmed) are what was asked"
518+else bad "POS tool options: rc $rc $(tail -2 "$T/tool.out" | tr '\n' '|')"; fi
519+KEPT=$(kept); tool patch --base origin/side --title "from side" --yes $OWNER/fixrepo > "$T/tool.out" 2>&1; rc=$?
520+[ "$rc" = 2 ] && grep -qx "interplane: Interplane refused the patch: base is not reachable from the repository's main branch" "$T/tool.out" && [ "$(kept)" = "$KEPT" ] \
521+ && ok "NEG the tool with a base that is not on main: exit 2 with the forge's reason" || bad "NEG tool refusal: rc $rc $(tail -1 "$T/tool.out")"
522+tool patch --yes $OWNER/nope > "$T/tool.out" 2>&1; rc=$?
523+[ "$rc" = 2 ] && grep -q 'refused the patch: no such public repository' "$T/tool.out" && ok "NEG the tool for a repository outside the public list: exit 2" || bad "NEG tool unlisted: rc $rc"
524+(cd "$T" && env -i HOME="$T/home" INTERPLANE_BASE="$B" "$TOOL" patch --yes $OWNER/fixrepo) > "$T/tool.out" 2>&1; rc=$?
525+[ "$rc" = 1 ] && grep -q 'not inside a git work tree' "$T/tool.out" && ok "NEG the tool outside a git work tree: exit 1" || bad "NEG outside work tree: rc $rc"
526+for a in "" "--yes" "--base" "--bogus $OWNER/fixrepo" "$OWNER" "a/b/c" "--yes ../x"; do
527+ # shellcheck disable=SC2086
528+ tool patch $a > "$T/tool.out" 2>&1; rc=$?
529+ [ "$rc" = 1 ] && grep -q '^interplane: usage: interplane patch' "$T/tool.out" || bad "NEG tool arguments '$a': rc $rc $(tail -1 "$T/tool.out")"
530+done
531+ok "NEG the tool with missing or malformed arguments: usage, exit 1 (7 forms)"
532+KEPT=$(kept); for n in 9 70; do
533+ args=(); for i in $(seq $((n - 1))); do args+=(--yes); done
534+ tool patch "${args[@]}" $OWNER/fixrepo > "$T/tool.out" 2>&1; rc=$?
535+ [ "$rc" = 1 ] && grep -q '^interplane: usage: interplane patch' "$T/tool.out" && [ "$(kept)" = "$KEPT" ] \
536+ && ok "NEG the tool with $n arguments after patch (it takes at most 8): usage, exit 1, nothing sent" || bad "NEG tool with $n arguments: rc $rc $(tail -1 "$T/tool.out")"
537+done
538+[ "$(ls -d /tmp/interplane-tool-* 2>/dev/null | sort)" = "$TMP0" ] && ok "the tool left no temp folder of its own" || bad "tool temp folder left: $(ls -d /tmp/interplane-tool-* | sort | comm -13 <(printf '%s\n' "$TMP0") - | head -2)"
539+
540+echo "== imported proposals: fixtures (SPEC prstore/r1 extension section 1, the importer's layout)"
541+# Until here the store held signed patches only. Each fixture is one item folder as tools/ghimport writes it
542+# (patch/tests/lib.sh impnew, impcnew and the helpers beside them), with its line in the index. Nothing below
543+# asks the forge to write one. want NAME STATE: the fixture last made gets the name NAME (a variable holding
544+# its id) and a correct forge shows it in STATE (open, closed, merged) or does not hold it as an item (404).
545+SIGNED=$(kept); IMPX=$T/imp.exp; : > "$IMPX"; mkdir -p "$T/imp"; PD=$T/data/pdiff/$OWNER/fixrepo
546+# lsum: count, the states and damaged of the list document asked now. lbar: the head bar of the list page asked now,
547+# from its <b> to the link that ends it (the page stays in $T/body). withindex LINE...: the index holds exactly
548+# these lines while the list is asked once in each form (LJ, LH; LR the rows of the page), then is put back
549+lsum() { curl -s -H 'Accept: application/json' "$B$R/patches" | python3 -c "import json, sys
550+try:
551+ l = json.load(sys.stdin); print('count=%d open=%d closed=%d merged=%d damaged=%d' % (l['count'], l['states']['open'], l['states']['closed'], l['states']['merged'], l['damaged']))
552+except Exception: print('?')"; }
553+lbar() { c=$(code GET "$R/patches"); untr; grep -o '<div class="bar"><b>.*How to open a patch</a>' "$T/body" | head -1 | sed "s|^<div class=\"bar\">||; s| <a href=\"$R/patches/new\">How to open a patch</a>\$||"; }
554+withindex() { cp "$IMPD/index" "$T/index.keep"; printf '%s\n' "$@" > "$IMPD/index"; LJ=$(lsum); LH=$(lbar); LR=$(grep -o '<li><a class="subject"' "$T/body" | wc -l); mv "$T/index.keep" "$IMPD/index"; }
555+check "$(lsum) | $(lbar)" "count=$SIGNED open=$SIGNED closed=0 merged=0 damaged=0 | <b>$SIGNED patches</b> <span class=\"states\">$SIGNED open &middot; 0 closed &middot; 0 merged</span>" "before any imported fixture every index line is a signed patch: count = index lines, all open, damaged 0, no sentence about damaged items"
556+want() { eval "$1=$IID"; printf '%s\t%s\t%s\n' "$IID" "$1" "$2" >> "$IMPX"; }
557+# gh: the source repository of the pull requests, a clone of the git store. pr N START: its branch pr-N at START
558+# with one commit of its own (H its head). prmerge N START: the same with a second branch merged in, so the range
559+# holds a merge commit: the writer stores such a range as a bundle, an mbox cannot carry it.
560+newclone gh "$A"
561+pr() { G -C "$T/gh" checkout -q -B "pr-$1" "$2" && commitf "$T/gh" "pr/f$1.txt" "change of pull request $1" "pull request $1" && H=$(git -C "$T/gh" rev-parse HEAD); }
562+prmerge() {
563+ pr "$1" "$2" && G -C "$T/gh" checkout -q -B "pr-$1-side" "$2" && commitf "$T/gh" "pr/s$1.txt" "side of pull request $1" "side of $1" && G -C "$T/gh" checkout -q "pr-$1" \
564+ && GIT_AUTHOR_DATE=2026-11-10T10:00:00Z GIT_COMMITTER_DATE=2026-11-10T10:00:00Z G -C "$T/gh" merge -q --no-ff -m "merge the side of $1" "pr-$1-side" && H=$(git -C "$T/gh" rev-parse HEAD); }
565+instore() { git --git-dir="$GITS" cat-file -e "$1^{commit}" 2>/dev/null; }
566+
567+# open: mbox and diff, labels, a thread holding the three record kinds (a review without state or body, a comment without a time)
568+pr 101 "$MAIN"; impnew 101 "$H" open "$MAIN"; impmbox "$T/gh"; want IOPEN open
569+printf 'Add the first imported change' > "$I/title"
570+printf '# Why\n\nThis change adds a file.\n\n- item one\n- item two\n' > "$I/description"
571+printf 'bug\nhelp wanted\n' > "$I/labels"
572+thc 2026-11-10T11:05:00Z alice 'First comment with **bold** text.'
573+thr 2026-11-10T12:00:00Z bob APPROVED 'Looks good.'
574+thr 2026-11-10T12:30:00Z carol - ''
575+thrc 2026-11-10T13:00:00Z bob 3 src/a.txt 'Inline note.'
576+thc - dave 'A comment without a time.'
577+# closed
578+pr 102 "$MAIN"; impnew 102 "$H" closed "$MAIN"; impmbox "$T/gh"; impgh 102 erin 2026-11-10T11:00:00Z 2026-11-12T08:00:00Z -; want ICLOSED closed
579+# merged, with GitHub's merge commit and what the importer saw of this project's main: reachable, not reachable
580+# (bundle-backed), unknown (no main: "-"), unknown (git could not tell: the main it asked about)
581+pr 103 "$A"; impnew 103 "$H" merged "$A"; impmbox "$T/gh"; impgh 103 frank 2026-11-10T11:00:00Z 2026-11-13T08:00:00Z 2026-11-13T08:00:00Z
582+printf '%s\n' "$MAIN" > "$I/merged"; impreach reachable "$MAIN"; want IMREACH merged
583+prmerge 104 "$A"; impnew 104 "$H" merged "$MAIN"; impbundle "$T/gh" 104; impgh 104 grace 2026-11-10T11:00:00Z 2026-11-13T09:00:00Z 2026-11-13T09:00:00Z
584+printf '%s\n' "$SIDE" > "$I/merged"; impreach not-reachable "$MAIN"; want IMNOTR merged; HNOTR=$H
585+pr 105 "$A"; impnew 105 "$H" merged "$A"; impmbox "$T/gh"; impgh 105 heidi 2026-11-10T11:00:00Z 2026-11-13T10:00:00Z 2026-11-13T10:00:00Z
586+printf '%s\n' "$SIDE" > "$I/merged"; impreach unknown -; want IMUNK merged
587+pr 106 "$A"; impnew 106 "$H" merged "$A"; impmbox "$T/gh"; impgh 106 ivan 2026-11-10T11:00:00Z 2026-11-13T11:00:00Z 2026-11-13T11:00:00Z
588+printf '%s\n' "$SIDE" > "$I/merged"; impreach unknown "$MAIN"; want IMUNKM merged
589+# bundle-backed, base in the git store. The branch starts at main's first commit and the base is main's tip, so
590+# base...head (from their merge base) is another diff than base..head
591+prmerge 110 "$A"; impnew 110 "$H" open "$MAIN"; impbundle "$T/gh" 110; want IBUND open; HBUND=$H
592+instore "$MAIN" && ! instore "$H" || bad "FIXTURE: the bundle item's base must be in the git store and its head must not"
593+# bundle whose base commit the git store does not hold
594+pr 111 "$A"; Z1=$H; prmerge 111b "$Z1"; impnew 111 "$H" open "$Z1"; impbundle "$T/gh" 111; want IBNS open
595+! instore "$Z1" || bad "FIXTURE: the base of the base-not-in-store item is in the git store"
596+# an mbox item with that base: its stored diff file is its diff, the git store is not asked
597+pr 117 "$Z1"; impnew 117 "$H" open "$Z1"; impmbox "$T/gh"; want IMBNS open
598+# code-only (GitHub's metadata is gone, the state is derived). A head without a merge base with main: a bundle
599+# of the head alone, no base file
600+G -C "$T/gh" checkout -q --orphan pr-112 && commitf "$T/gh" "pr/f112.txt" "an orphan head" "orphan 112"; H=$(git -C "$T/gh" rev-parse HEAD)
601+impcnew 112 "$H" open; impbundle "$T/gh" 112; want ICNOBASE open
602+[ -z "$(git -C "$T/gh" merge-base "$H" "$MAIN")" ] && [ ! -e "$I/base" ] || bad "FIXTURE: the head-alone item has a merge base with main or a base file"
603+# code-only open (mbox), closed (bundle: the range holds a merge), merged (the head is on main: base = head, no code file)
604+pr 113 "$A"; impcnew 113 "$H" open "$A"; impmbox "$T/gh"; want ICOPEN open
605+prmerge 114 "$A"; impcnew 114 "$H" closed "$A"; impbundle "$T/gh" 114; want ICCLOSED closed; HCCLOSED=$H
606+impcnew 115 "$MAIN" merged "$MAIN"; want ICMAIN merged
607+# code-only with a thread (importer head 19caca79: GitHub comments that matched the number): still no login in gh
608+pr 116 "$MAIN"; impcnew 116 "$H" open "$MAIN"; impmbox "$T/gh"; want ICTHREAD open
609+thc 2026-11-11T09:00:00Z judy 'A comment on a code-only pull request.'
610+thrc 2026-11-11T09:30:00Z mallory 7 docs/note.md 'An inline note on a code-only pull request.'
611+
612+# an item with GitHub metadata whose gh file names no login: no login line; a login line with an empty value
613+pr 180 "$MAIN"; impnew 180 "$H" open "$MAIN"; impmbox "$T/gh"; sed -i '/^login /d' "$I/gh"; want INOLOGIN open
614+pr 181 "$MAIN"; impnew 181 "$H" open "$MAIN"; impmbox "$T/gh"; sed -i 's/^login .*/login /' "$I/gh"; want IEMPTYLOGIN open
615+grep -q '^login' "$IMPD/$INOLOGIN/gh" || ! grep -qx 'login ' "$IMPD/$IEMPTYLOGIN/gh" && bad "FIXTURE: the gh files without a login"
616+# items without a code file that are not the importer's on-main route (code-only, merged, base file = head). Each
617+# misses one of its four conditions and holds the other three: an item with metadata; code-only open; code-only
618+# merged with another base; code-only merged without a base file. And code-only closed.
619+impnew 182 "$MAIN" merged "$MAIN"; impgh 182 olga 2026-11-10T11:00:00Z 2026-11-13T08:00:00Z 2026-11-13T08:00:00Z; want XNCMETA merged
620+impcnew 183 "$MAIN" open "$MAIN"; want XNCOPEN open
621+impcnew 184 "$MAIN" closed "$MAIN"; want XNCCLOSED closed
622+impcnew 185 "$MAIN" merged "$A"; want XNCBASE merged
623+impcnew 186 "$MAIN" merged; want XNCNOBASE merged
624+
625+# hostile bytes in everything a GitHub user wrote: title, description (Markdown with raw HTML and script links),
626+# labels, the login, every field of every thread record, and the patch itself
627+G -C "$T/gh" checkout -q -B pr-120 "$MAIN" && commitf "$T/gh" "pr/h120.txt" '<script>pwn(17)</script> & "x"' 'hostile <script>pwn(18)</script> subject'; H=$(git -C "$T/gh" rev-parse HEAD)
628+impnew 120 "$H" open "$MAIN"; impmbox "$T/gh"; want IHOST open
629+printf 'Fix <script>pwn(1)</script> "quoted" & <b>more</b>' > "$I/title"
630+printf '# Head <script>pwn(2)</script>\n\nRaw HTML: <img src=x onerror=pwn(3)> <b>bold</b> <a href="javascript:pwn(4)">a</a>\n\n[link](javascript:pwn(5)) [link2](JaVaScRiPt:pwn(6)) [data](data:text/html,<script>pwn(7)</script>) ![img](javascript:pwn(8)) <javascript:pwn(20)>\n\n"quoted" & ampersand &lt; entity\n\n<script>pwn(9)</script>\n' > "$I/description"
631+printf 'bug\n<script>pwn(10)</script>\nla"bel & <b>\n' > "$I/labels"
632+impgh 120 'ev"il<b>&x' 2026-11-10T11:00:00Z - -
633+thc 2026-11-10T11:05:00Z 'ev"il<b>&x' 'Comment <script>pwn(11)</script> [x](javascript:pwn(12)) "q" & <img src=x onerror=pwn(13)>'
634+thr 2026-11-10T12:00:00Z 'rev<i>' '<script>pwn(14)</script>' 'Review <script>pwn(15)</script>'
635+thrc 2026-11-10T13:00:00Z 'rc"<u>' 3 'src/<x>&"y".txt' 'Inline <script>pwn(16)</script>'
636+# hostile owner and repository names in source.json; and a name holding a JSON escape (the reader cuts the value at
637+# the backslash and never decodes it)
638+GHO='ev<il>'; GHR='re&po'; impnew 121 "$MAIN" open "$A"; want IHOSTSRC open
639+GHO='back\"sl<script>pwn(19)</script>'; GHR=gh-repo; impnew 122 "$MAIN" open "$A"; want IHOSTESC open
640+GHO=aien-dev
641+# bytes that are not text: control bytes, a NUL and ill-formed UTF-8 in title, description, labels, login and a body
642+impnew 123 "$MAIN" open "$A"; want IBYTES open
643+printf 'ctl \001\037\177 bad \377\376 end' > "$I/title"; printf 'nul \000 and \377 here\n' > "$I/description"; printf 'l\001a\nb\377\n' > "$I/labels"
644+impgh 123 $'lo\200gin' 2026-11-10T11:00:00Z - -; printf 'comment 2026-11-10T11:05:00Z b\200b 6\nx\377\000y\001z\n' >> "$I/thread"
645+
646+# ---- malformed items (each must give its documented answer and never end forged)
647+# status not one of the three words (the first also holds an mbox, a diff and a bundle: no raw route may serve them)
648+pr 130 "$MAIN"; impnew 130 "$H" open "$MAIN"; impmbox "$T/gh"; cp "$IMPD/$IBUND/head.bundle" "$I/head.bundle"; printf 'draft\n' > "$I/status"; want XSTATUS 404
649+impnew 131 "$MAIN" open "$A"; printf 'Open\n' > "$I/status"; want XSTATCAP 404
650+impnew 132 "$MAIN" open "$A"; printf 'open' > "$I/status"; want XSTATNOLF 404
651+# head not 40 lowercase hex and a line feed: uppercase, 39 digits, a line after it, another byte in place of the line feed
652+U=$(printf '%s' "$MAIN" | tr a-f A-F); [ "$U" != "$MAIN" ] || bad "FIXTURE: main's id holds no letter"
653+impnew 133 "$MAIN" open "$A"; printf '%s\n' "$U" > "$I/head"; want XHEADUP 404
654+impnew 134 "$MAIN" open "$A"; printf '%s\n' "${MAIN:0:39}" > "$I/head"; want XHEADSHORT 404
655+impnew 135 "$MAIN" open "$A"; printf '%s\nmore\n' "$MAIN" > "$I/head"; want XHEADLONG 404
656+impnew 136 "$MAIN" open "$A"; printf '%sx' "$MAIN" > "$I/head"; want XHEADNOLF 404
657+# a thread whose second record is malformed: the item is whole, the thread stops after its first record
658+thbad() { impnew "$1" "$MAIN" open "$A"; thc 2026-11-10T11:05:00Z bob 'ok first'; printf "$2" >> "$I/thread"; want "$3" open; XTHREADS="$XTHREADS $3"; }
659+XTHREADS=; W300=$(printf '%300s' '' | tr ' ' a); P5000=$(printf '%5000s' '' | tr ' ' p)
660+thbad 140 'comment 2026-11-10T11:06:00Z bob 99999999\nshort\n' XTPAST # a body length past the end of the file
661+thbad 141 'note 2026-11-10T11:06:00Z bob 1\nx\n' XTKIND # a kind that is not one of the three
662+thbad 142 "comment 2026-11-10T11:06:00Z $W300 1\nx\n" XTWORD # a login of 300 bytes
663+thbad 143 'comment 2026-11-10T11:06:00Z bob 1234567890123456789012\nx\n' XTDIGITS # a length of 22 digits
664+thbad 144 'comment 2026-11-10T11:06:00Z bob \n' XTNOLEN # no length
665+thbad 145 "review-comment 2026-11-10T11:06:00Z bob 1 5000 1\n$P5000\nx\n" XTPATHBIG # a path of 5000 bytes
666+thbad 146 'review-comment 2026-11-10T11:06:00Z bob 3 4 5\nabcdX12345\n' XTPATHLF # a path not followed by a line feed
667+thbad 147 'comment 2026-11-10T11:06:00Z bob 3\nabcX' XTBODYLF # a body not followed by a line feed
668+thbad 148 'comment 2026-11-10 bob 1\nx\n' XTTIME # a time that is neither 20 bytes nor "-"
669+# thread, labels and gh missing; and the least a loadable item holds (source.json, status, head)
670+impnew 150 "$MAIN" open "$A"; rm "$I/thread" "$I/labels" "$I/gh"; want XMISSING open
671+impnew 151 "$MAIN" closed "$A"; rm "$I/thread" "$I/labels" "$I/gh" "$I/title" "$I/description" "$I/base" "$I/statement"; want XBARE closed
672+# a merged item whose reach file is not the importer's line, one without a reach file, one without the merged file
673+pr 170 "$A"; impnew 170 "$H" merged "$A"; impmbox "$T/gh"; impgh 170 nina 2026-11-10T11:00:00Z 2026-11-13T08:00:00Z 2026-11-13T08:00:00Z
674+printf '%s\n' "$SIDE" > "$I/merged"; printf 'sideways %s 2026-11-17T09:30:00Z\n' "$MAIN" > "$I/reach"; want XREACHBAD merged
675+pr 171 "$A"; impnew 171 "$H" merged "$A"; impmbox "$T/gh"; impgh 171 nina 2026-11-10T11:00:00Z 2026-11-13T08:00:00Z 2026-11-13T08:00:00Z
676+printf '%s\n' "$SIDE" > "$I/merged"; want XREACHNONE merged
677+pr 172 "$A"; impnew 172 "$H" merged "$A"; impmbox "$T/gh"; impgh 172 nina 2026-11-10T11:00:00Z 2026-11-13T08:00:00Z 2026-11-13T08:00:00Z; impreach reachable "$MAIN"; want XMERGEDNONE merged
678+# source.json without the github-import start: another kind (same length, the difference inside the start), cut
679+# inside the start, absent
680+impnew 152 "$MAIN" open "$A"; sed -i 's/^{"kind":"github-import"/{"kind":"github-export"/' "$I/source.json"; want XSRCKIND 404
681+impnew 153 "$MAIN" open "$A"; printf '{"kind":"github-import"' > "$I/source.json"; want XSRCSHORT 404
682+impnew 154 "$MAIN" open "$A"; rm "$I/source.json"; want XSRCNONE 404
683+# an item folder with both a meta file and source.json: with a meta that does not load it is no item at all
684+impnew 155 "$MAIN" open "$A"; printf 'not a meta file\n' > "$I/meta"; want XBOTH 404
685+# titles of 1024 bytes (kept), 1025 bytes (cut to 1024) and 1023 bytes followed by a two-byte letter (the cut
686+# falls inside the letter)
687+impnew 156 "$MAIN" open "$A"; printf '%1024s' '' | tr ' ' t > "$I/title"; want XT1024 open
688+impnew 157 "$MAIN" open "$A"; printf '%1025s' '' | tr ' ' t > "$I/title"; want XT1025 open
689+impnew 158 "$MAIN" open "$A"; { printf '%1023s' '' | tr ' ' t; printf 'é tail'; } > "$I/title"; want XT1025U open
690+# a description and a thread that together pass the 5,000,000 bytes an imported page gives them (NOTES-A PAPGMX):
691+# 2,600,000 bytes of description, then 30 comments of 100,000 bytes each
692+impnew 160 "$MAIN" open "$A"; want XBIG open
693+python3 - "$I" <<'EOF'
694+import sys
695+d = sys.argv[1]
696+line = b'Words of a long description, line %07d of many, in Markdown.\n\n'
697+open(d + '/description', 'wb').write(b''.join(line % i for i in range(2600000 // len(line % 0))))
698+body = b''.join(b'comment body line %07d of a very long thread\n\n' % i for i in range(100000 // 47))[:100000]
699+open(d + '/thread', 'wb').write(b''.join(b'comment 2026-11-10T11:%02d:00Z bob %d\n' % (i, len(body)) + body + b'\n' for i in range(30)))
700+EOF
701+# a description that alone passes it
702+impnew 161 "$MAIN" open "$A"; want XBIGD open
703+python3 -c "import sys; l = b'A long description line %07d.\n\n'; open(sys.argv[1], 'wb').write(b''.join(l % i for i in range(5500000 // len(l % 0))))" "$I/description"
704+# a thread file larger than the 16 MiB the forge reads of a file: 170 comments of 100,000 bytes (167 of them whole
705+# inside the first 16 MiB)
706+impnew 163 "$MAIN" open "$A"; want XTHUGE open
707+python3 - "$I/thread" <<'EOF'
708+import sys
709+body = b''.join(b'comment body line %07d of a very long thread\n\n' % i for i in range(100000 // 47))[:100000]
710+open(sys.argv[1], 'wb').write(b''.join(b'comment 2026-11-10T11:00:00Z bob %d\n' % len(body) + body + b'\n' for i in range(170)))
711+EOF
712+[ "$(stat -c %s "$I/thread")" -gt 16777216 ] || bad "FIXTURE: the huge thread is $(stat -c %s "$I/thread") bytes"
713+# a thread whose second record is larger than the 16 MiB the forge reads of a file: a small comment, then one of 17,000,000 bytes
714+impnew 164 "$MAIN" open "$A"; want XTLARGE open; thc 2026-11-10T11:05:00Z bob 'ok first'
715+python3 -c "import sys; open(sys.argv[1], 'ab').write(b'comment 2026-11-10T11:06:00Z bob 17000000\n' + b'x' * 17000000 + b'\n')" "$I/thread"
716+# a description whose JSON form (8,334,920 bytes: 75772 paragraphs of 98 bytes and two line feeds, 6 bytes each) takes the
717+# document past its budget of 8,323,072 bytes and still fits a response of 8,388,608; and one small comment
718+impnew 165 "$MAIN" open "$A"; want XDESCBUD open; thc 2026-11-10T11:05:00Z bob 'a small comment'
719+python3 -c "import sys; open(sys.argv[1], 'wb').write(b''.join(b'paragraph %07d ' % i + b'a' * 80 + b'\n\n' for i in range(75772)))" "$I/description"
720+# a description that alone does not fit a response (8,500,000 bytes)
721+impnew 166 "$MAIN" open "$A"; want XDESC500 open
722+python3 -c "import sys; open(sys.argv[1], 'wb').write(b''.join(b'paragraph %07d ' % i + b'a' * 80 + b'\n\n' for i in range(85000)))" "$I/description"
723+[ "$(stat -c %s "$IMPD/$XDESCBUD/description") $(stat -c %s "$I/description")" = "7577200 8500000" ] || bad "FIXTURE: the two long descriptions"
724+# a bundle whose diff is larger than the 16 MiB the forge reads of a command's output: one commit adding 18 MB
725+G -C "$T/gh" checkout -q -B pr-162 "$MAIN"; yes 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 | head -n 180000 > "$T/gh/huge.txt"
726+G -C "$T/gh" add -A; G -C "$T/gh" commit -q -m "a huge file"; H=$(git -C "$T/gh" rev-parse HEAD); rm -f "$T/gh/huge.txt"
727+impnew 162 "$H" open "$MAIN"; impbundle "$T/gh" 162; want XDIFF open
728+n=$(git -C "$T/gh" diff --no-color --no-ext-diff --no-textconv "$MAIN...$H" | wc -c)
729+[ "$n" -gt 16777216 ] && ok "FIXTURE the huge bundle's diff is $n bytes (over 16777216), its bundle $(stat -c %s "$I/head.bundle")" || bad "FIXTURE: the huge diff is $n bytes"
730+G -C "$T/gh" checkout -q work
731+NIMP=$(grep -c . "$IMPX"); echo "$NIMP imported fixtures beside $SIGNED signed patches"
732+[ "$(kept)" = $((SIGNED + NIMP)) ] && [ "$(grep -c . "$IMPD/index")" = $((SIGNED + NIMP)) ] && [ "$(cut -f1 "$IMPX" | sort -u | wc -l)" = "$NIMP" ] \
733+ && ok "FIXTURE every fixture has its own folder and index line ($NIMP)" || bad "FIXTURE: $(kept) folders, $(grep -c . "$IMPD/index") index lines, $NIMP fixtures"
734+H0=$(imphash)
735+
736+echo "== imported proposals: pages and documents"
737+# every fixture: its page and its JSON document (kept in $T/imp for the oracle below); 200 for an item, 404 for the rest
738+while IFS=$tab read -r i name st; do
739+ w=200; [ "$st" = 404 ] && w=404
740+ c1=$(code GET "$R/patches/$i"); cp "$T/body" "$T/imp/$i.html"; t1=$(hdr content-type)
741+ c2=$(code GET "$R/patches/$i" -H 'Accept: application/json'); cp "$T/body" "$T/imp/$i.json"; t2=$(hdr content-type)
742+ echo "$c1 $c2" > "$T/imp/$i.code"; [ "$name $c2" = "XDESC500 500" ] && c2=200 && t2="application/json; charset=utf-8"
743+ if [ "$c1 $c2" = "$w $w" ] && { [ "$w" = 404 ] || [ "$t1 | $t2" = "text/html; charset=utf-8 | application/json; charset=utf-8" ]; }; then ok "$name ($st): page $c1, JSON $c2"
744+ else bad "$name ($st): page $c1 ($t1) and JSON $c2 ($t2), want $w"; fi
745+done < "$IMPX"
746+alive && ok "forged is still running after every imported page, the malformed ones among them" || { bad "forged ended on an imported page"; start; }
747+# the list: every page of it, HTML and JSON
748+LP=$(( ($(grep -c . "$IMPD/index") + 29) / 30 ))
749+for p in $(seq $LP); do
750+ c1=$(code GET "$R/patches?page=$p"); cp "$T/body" "$T/imp/list.$p.html"; c2=$(code GET "$R/patches?page=$p" -H 'Accept: application/json'); cp "$T/body" "$T/imp/list.$p.json"
751+ check "$c1 $c2" "200 200" "list page $p of $LP with the imported items"
752+done
753+check "$(code GET "$R/patches?page=$((LP + 1))")" 404 "NEG the list page after the last"
754+# The oracle: an independent reader of the item folders (SPEC section 1) gives the forge/patch/1 document and the
755+# list row of every fixture (SPEC section 3 and NOTES-G: key order, types, every value; the document budget; diff and
756+# diff_unavailable as they are after each item's first page view, which the loop above made), the provenance line and the list row
757+# of the HTML (SPEC section 2), and looks for what must never be on a page.
758+python3 - "$T" "$R" "$IMPD" "$IMPX" "$SIGNED" "$LP" "$GITS" > "$T/imp.out" 2>&1 <<'EOF'
759+import json, os, re, sys
760+from html.parser import HTMLParser
761+import subprocess
762+T, R, IMPD, EXPF, SIGNED, LP, GITS = sys.argv[1:8]; SIGNED = int(SIGNED); LP = int(LP)
763+FXO = 16777216; FOB = 8388608; PAJMX = 8323072 # what the forge reads of a file or a command; a response; the document budget
764+GENV = {'PATH': os.environ['PATH'], 'HOME': T + '/home'}
765+def instore(c): return subprocess.run(['git', '--git-dir=' + GITS, 'cat-file', '-e', c + '^{commit}'], env=GENV, stderr=subprocess.DEVNULL).returncode == 0
766+def difflen(b, h): return len(subprocess.run(['git', '-C', T + '/gh', 'diff', '--no-color', '--no-ext-diff', '--no-textconv', b + '...' + h], env=GENV, stdout=subprocess.PIPE, check=True).stdout)
767+NC = {} # the records of each item's thread, whatever the document leaves out (comments_count of its list row)
768+OWNER, REPO = R.split('/')[1:3]
769+def P(c, msg):
770+ print(('PASS ' if c else 'FAIL ') + msg); return c
771+def nodup(pairs):
772+ assert len(set(k for k, _ in pairs)) == len(pairs), 'a key twice: %r' % [k for k, _ in pairs]
773+ return dict(pairs)
774+def J(b): return json.loads(b.decode('utf-8'), object_pairs_hook=nodup)
775+def rd(d, f, cap=None):
776+ try: b = open(os.path.join(d, f), 'rb').read()
777+ except OSError: return None
778+ return b if cap is None else b[:cap]
779+def txt(b): return b.decode('utf-8', 'replace') # an ill-formed byte is U+FFFD in a JSON string
780+def esc(b): return b.replace(b'&', b'&amp;').replace(b'<', b'&lt;').replace(b'>', b'&gt;').replace(b'"', b'&quot;')
781+PRE = b'{"kind":"github-import","owner":"'
782+HEX = re.compile(rb'[0-9a-f]{40}\n')
783+def sjv(sj, key): # the string after the key text, up to its closing quote or a backslash
784+ i = sj.find(key)
785+ if i < 0: return None
786+ p = q = i + len(key)
787+ while q < len(sj) and sj[q] not in (0x22, 0x5c): q += 1
788+ return sj[p:q]
789+def ghv(gh, key): # the value of the first whole line "<key><value>\n"
790+ for l in gh.split(b'\n')[:-1]:
791+ if l.startswith(key): return l[len(key):]
792+ return None
793+def record(b, p): # one thread record at p: (comment, index after it), or None when it is malformed
794+ n = len(b)
795+ def word(p):
796+ q = p
797+ while q < n and b[q] > 32: q += 1
798+ return None if q >= n or q == p or q - p > 256 or b[q] != 32 else (b[p:q], q + 1)
799+ def num(p, t):
800+ q = p
801+ while q < n and 48 <= b[q] <= 57: q += 1
802+ return None if q == p or q - p > 18 or q >= n or b[q] != t else (int(b[p:q]), q + 1)
803+ w = word(p)
804+ if not w or w[0] not in (b'comment', b'review', b'review-comment'): return None
805+ kind, p = w
806+ w = word(p)
807+ if not w: return None
808+ tm, p = w
809+ w = word(p)
810+ if not w: return None
811+ c = {'author': None, 'login': txt(w[0]), 'kind': kind.decode()}; p = w[1]
812+ if kind == b'review':
813+ w = word(p)
814+ if not w: return None
815+ c['state'] = None if w[0] == b'-' else txt(w[0]); p = w[1]
816+ if kind == b'review-comment':
817+ w = num(p, 32)
818+ if not w: return None
819+ line, p = w
820+ w = num(p, 32)
821+ if not w: return None
822+ plen, p = w
823+ w = num(p, 10)
824+ if not w or not (len(tm) == 20 or tm == b'-'): return None
825+ blen, p = w
826+ if kind == b'review-comment':
827+ if plen > 4096 or p + plen >= n or b[p + plen] != 10: return None
828+ c['path'] = txt(b[p:p + plen]); c['line'] = line; p += plen + 1
829+ if p + blen >= n or b[p + blen] != 10: return None
830+ c['time'] = txt(tm) if len(tm) == 20 else None
831+ c['body'] = txt(b[p:p + blen])
832+ return c, p + blen + 1
833+def thread(b): # the records up to the first malformed one, and whether one stopped them
834+ out = []; p = 0
835+ while p < len(b):
836+ r = record(b, p)
837+ if r is None: return out, True
838+ out.append(r[0]); p = r[1]
839+ return out, False
840+def jstr(t): # a string as the forge writes it (server/json.om fjstr): \" \\, \u00XX for control bytes, DEL, < > &; an ill-formed byte \ufffd
841+ return b'"' + re.sub(r'["\\\x00-\x1f\x7f<>&\ufffd]', lambda m: {'"': '\\"', '\\': '\\\\', '\ufffd': '\\ufffd'}.get(m.group(0)) or '\\u%04x' % ord(m.group(0)), t).encode('utf-8') + b'"'
842+def jcom(c): # one comment as the forge writes it
843+ o = b'{"author":null,"login":' + jstr(c['login']) + b',"kind":"' + c['kind'].encode() + b'"'
844+ if c['kind'] == 'review': o += b',"state":' + (b'null' if c['state'] is None else jstr(c['state']))
845+ if c['kind'] == 'review-comment': o += b',"path":' + jstr(c['path']) + b',"line":%d' % c['line']
846+ return o + b',"time":' + (b'null' if c['time'] is None else jstr(c['time'])) + b',"body":' + jstr(c['body']) + b'}'
847+def budget(raw, coms): # the records that fit the document budget from where the served comments start: how many, their bytes, the start, the size of the next
848+ pos = raw.find(b',"comments":[') + 13; seg = []; at = pos
849+ for n, c in enumerate(coms):
850+ piece = (b',\n' if n else b'\n') + jcom(c)
851+ if at + len(piece) > PAJMX: return n, b''.join(seg), pos, len(piece)
852+ seg.append(piece); at += len(piece)
853+ return len(coms), b''.join(seg), pos, 0
854+def reach(d):
855+ b = rd(d, 'reach')
856+ if b is None or not 5 <= len(b) <= 255 or b[-1] != 10: return 'unknown', None, None
857+ w = b[:-1].split(b' ', 2)
858+ if len(w) != 3 or w[0] not in (b'reachable', b'not-reachable', b'unknown') or not (re.fullmatch(rb'[0-9a-f]{40}', w[1]) or w[1] == b'-') \
859+ or not 1 <= len(w[2]) <= 32: return 'unknown', None, None
860+ return w[0].decode(), (w[1].decode() if len(w[1]) == 40 else None), txt(w[2])
861+def item(i): # the forge/patch/1 document of the imported item folder i under base "/", None when it is not an item
862+ d = os.path.join(IMPD, i)
863+ if os.path.exists(os.path.join(d, 'meta')): return None
864+ sj = rd(d, 'source.json', 4096)
865+ st = {b'open\n': 'open', b'closed\n': 'closed', b'merged\n': 'merged'}.get(rd(d, 'status'))
866+ hd = rd(d, 'head')
867+ if sj is None or not sj.startswith(PRE) or st is None or hd is None or not HEX.fullmatch(hd): return None
868+ derived = b'"state_derived":true' in sj
869+ gh = rd(d, 'gh', 2048) or b''
870+ def ghs(k):
871+ v = ghv(gh, k)
872+ return None if v in (None, b'', b'-') else txt(v)
873+ def s(k):
874+ v = sjv(sj, k)
875+ return None if v is None else txt(v)
876+ num = ghv(gh, b'number ')
877+ if num is not None and re.fullmatch(rb'[0-9]{1,18}', num): num = int(num)
878+ else:
879+ m = re.search(rb'"number":([0-9]*)', sj); num = int(m.group(1)) if m and 1 <= len(m.group(1)) <= 18 else 0
880+ bs = rd(d, 'base'); bs = bs[:40].decode() if bs is not None and HEX.fullmatch(bs) else None
881+ code, size = 'none', 0
882+ for f, k in (('head.bundle', 'bundle'), ('mbox', 'mbox')):
883+ if os.path.exists(os.path.join(d, f)): code, size = k, os.path.getsize(os.path.join(d, f))
884+ merge = None; mg = rd(d, 'merged')
885+ if st == 'merged' and mg is not None and HEX.fullmatch(mg):
886+ w, m, o = reach(d)
887+ merge = {'commit': mg[:40].decode(), 'time': ghs(b'merged '), 'reach': w, 'main': m, 'observed': o}
888+ p = '/%s/%s/patches/%s' % (OWNER, REPO, i)
889+ tb = rd(d, 'thread') or b''; coms, stopped = thread(tb[:FXO]); NC[i] = len(coms)
890+ why = 'too-large' if len(tb) >= FXO else 'malformed-record' if stopped else None
891+ if code == 'mbox': diff, du = p + '.diff', None
892+ elif code == 'none': diff, du = None, 'no-code-file'
893+ elif bs is None: diff, du = None, 'no-base'
894+ elif not instore(bs): diff, du = None, 'base-not-in-store'
895+ elif difflen(bs, hd[:40].decode()) >= FXO: diff, du = None, 'too-large'
896+ else: diff, du = p + '.diff', None
897+ return {'schema': 'forge/patch/1', 'base': '/', 'owner': OWNER, 'repo': REPO, 'id': i, 'title': txt(rd(d, 'title', 1024) or b''),
898+ 'description': txt(rd(d, 'description', 16777216) or b''), 'status': st, 'state_derived': derived, 'author': None,
899+ 'imported': {'from': 'github', 'owner': s(b'"owner":"'), 'repo': s(b'"repo":"'), 'number': num, 'url': s(b'"url":"'),
900+ 'login': None if derived else ghs(b'login ')},
901+ 'base_commit': bs, 'head_commit': hd[:40].decode(), 'commits': None, 'files': None, 'bytes': size, 'code': code, 'mbox_sha256': None,
902+ 'opened': ghs(b'opened '), 'closed': ghs(b'closed '), 'merge': merge,
903+ 'labels': [txt(x) for x in (rd(d, 'labels', 65536) or b'').split(b'\n') if x], 'comments': coms, 'thread_truncated': why is not None, 'thread_reason': why,
904+ 'created': s(b'"imported_utc":"'), 'path': p, 'patch': p + '.patch' if code == 'mbox' else None,
905+ 'diff': diff, 'diff_unavailable': du, 'bundle': p + '.bundle' if code == 'bundle' else None}
906+FULL = ['schema', 'base', 'owner', 'repo', 'id', 'title', 'description', 'status', 'state_derived', 'author', 'imported', 'base_commit', 'head_commit',
907+ 'commits', 'files', 'bytes', 'code', 'mbox_sha256', 'opened', 'closed', 'merge', 'labels', 'comments', 'thread_truncated', 'thread_reason',
908+ 'created', 'path', 'patch', 'diff', 'diff_unavailable', 'bundle']
909+ROW = ['id', 'title', 'status', 'state_derived', 'author', 'imported', 'base_commit', 'head_commit', 'commits', 'files', 'bytes', 'code', 'created',
910+ 'comments_count', 'path', 'patch', 'diff', 'diff_unavailable', 'bundle']
911+def row(d):
912+ r = {k: d[k] for k in ROW if k != 'comments_count'}; r['comments_count'] = NC[d['id']]
913+ return {k: r[k] for k in ROW}
914+def deep(a, b, at=''): # where two documents differ first (keys in order, types, values)
915+ if type(a) != type(b): return '%s: %r is not %r' % (at, a if not isinstance(a, (str, list, dict)) else type(a).__name__, b if not isinstance(b, (str, list, dict)) else type(b).__name__)
916+ if isinstance(a, dict):
917+ if list(a) != list(b): return '%s: keys %r, want %r' % (at, list(a), list(b))
918+ for k in a:
919+ x = deep(a[k], b[k], at + '/' + k)
920+ if x: return x
921+ elif isinstance(a, list):
922+ if len(a) != len(b): return '%s: %d elements, want %d' % (at, len(a), len(b))
923+ for k in range(len(a)):
924+ x = deep(a[k], b[k], '%s/%d' % (at, k))
925+ if x: return x
926+ elif a != b: return '%s: %r, want %r' % (at, a[:80] if isinstance(a, str) else a, b[:80] if isinstance(b, str) else b)
927+ return ''
928+def types(d): # SPEC section 3, said without the oracle
929+ S = str; N = type(None); im = d['imported']
930+ return (isinstance(d['title'], S) and isinstance(d['description'], S) and d['status'] in ('open', 'closed', 'merged') and type(d['state_derived']) is bool
931+ and d['author'] is None and type(im) is dict and list(im) == ['from', 'owner', 'repo', 'number', 'url', 'login'] and im['from'] == 'github'
932+ and type(im['number']) is int and isinstance(im['login'], (S, N)) and isinstance(d['base_commit'], (S, N)) and isinstance(d['head_commit'], S)
933+ and d['commits'] is None and d['files'] is None and type(d['bytes']) is int and d['code'] in ('mbox', 'bundle', 'none') and d['mbox_sha256'] is None
934+ and isinstance(d['opened'], (S, N)) and isinstance(d['closed'], (S, N)) and isinstance(d['merge'], (dict, N))
935+ and type(d['labels']) is list and all(isinstance(x, S) for x in d['labels']) and type(d['comments']) is list
936+ and all(c['author'] is None and isinstance(c['login'], S) and c['kind'] in ('comment', 'review', 'review-comment') and isinstance(c['body'], S)
937+ and isinstance(c['time'], (S, N)) for c in d['comments'])
938+ and isinstance(d['created'], (S, N)) and isinstance(d['path'], S) and all(isinstance(d[k], (S, N)) for k in ('patch', 'diff', 'bundle'))
939+ and type(d['thread_truncated']) is bool and d['thread_reason'] in (None, 'malformed-record', 'too-large', 'document-budget') and (d['thread_reason'] is None) == (not d['thread_truncated'])
940+ and d['diff_unavailable'] in (None, 'no-code-file', 'no-base', 'base-not-in-store', 'too-large') and (d['diff'] is None) == (d['diff_unavailable'] is not None))
941+def untr(b): return re.sub(rb' translate="no"', b'', re.sub(rb'<span translate="no">([^<]*)</span>', rb'\1', b))
942+class Scan(HTMLParser): # what must never come out of imported bytes: a marker in a tag, an attribute or a script; a script link; a login as a link
943+ def __init__(s, logins):
944+ super().__init__(convert_charrefs=True); s.bad = []; s.a = 0; s.raw = None; s.logins = logins
945+ def handle_starttag(s, tag, attrs):
946+ if tag == 'a': s.a += 1
947+ if tag in ('script', 'style'): s.raw = tag
948+ for k, v in attrs:
949+ v = v or ''
950+ if 'pwn' in k or 'pwn(' in v or '<' in v or 'pwn' in tag: s.bad.append('marker in <%s %s="%s">' % (tag, k, v[:60]))
951+ if k in ('href', 'src', 'action', 'formaction') and re.match(r'[\s\x00-\x20]*(javascript|data|vbscript)\s*:', v, re.I): s.bad.append('%s="%s"' % (k, v[:60]))
952+ def handle_endtag(s, tag):
953+ if tag == 'a': s.a -= 1
954+ if tag == s.raw: s.raw = None
955+ def handle_data(s, data):
956+ if s.raw and 'pwn' in data: s.bad.append('marker inside <%s>' % s.raw)
957+ if s.a > 0:
958+ for l in s.logins:
959+ if l in data: s.bad.append('login %r inside a link' % l)
960+exp = [l.rstrip('\n').split('\t') for l in open(EXPF)]
961+docs = {}
962+for i, name, st in exp:
963+ raw = open('%s/imp/%s.json' % (T, i), 'rb').read(); page = untr(open('%s/imp/%s.html' % (T, i), 'rb').read()); w = item(i)
964+ jcode = open('%s/imp/%s.code' % (T, i)).read().split()[1]
965+ if st == '404':
966+ P(w is None, '%s: the oracle too reads no item in the folder' % name); continue
967+ if not P(w is not None and w['status'] == st, '%s: the fixture is a loadable item in state %s' % (name, st)): continue
968+ try: d = J(raw)
969+ except Exception as e:
970+ P(False, '%s: JSON does not parse: %s' % (name, e)); continue
971+ docs[i] = w
972+ desc = rd(os.path.join(IMPD, i), 'description') or b''
973+ if jcode == '500': # a document that does not fit a response without any comment: the forge's whole 500, never a cut 200
974+ P(len(desc) >= FOB and len(raw) < 1000 and 'description' not in d, '%s: its description of %d bytes alone does not fit a response: a whole 500 notice (%d bytes of valid JSON), not a cut document' % (name, len(desc), len(raw)))
975+ else:
976+ full = w['comments']; n, seg, pos, nxt = budget(raw, full)
977+ if n < len(full): w['comments'] = full[:n]; w['thread_truncated'] = True; w['thread_reason'] = 'document-budget'
978+ x = deep(d, w)
979+ P(x == '' and list(d) == FULL, '%s: forge/patch/1 has the documented keys in order and every value the folder gives%s' % (name, x and ' -- ' + x))
980+ P(list(d) == FULL and types(d), '%s: forge/patch/1 value types (author null, imported object, commits/files/mbox_sha256 null, thread_truncated bool, exactly one of diff and diff_unavailable null)' % name)
981+ P(pos > 12 and raw[pos:pos + len(seg) + 1] == seg + b']', '%s: the comments array is byte for byte the %d of %d records that fit the document' % (name, n, len(full)))
982+ if n < len(full):
983+ e = pos + len(seg)
984+ P(len(raw) < FOB and (e <= PAJMX or n == 0) and PAJMX < e + nxt and d.get('thread_truncated') is True and d.get('thread_reason') == 'document-budget',
985+ '%s: the document budget: a valid document of %d bytes (under %d) says document-budget; its %d comments end whole at byte %d (budget %d) and the next record of %d bytes would pass it' % (name, len(raw), FOB, n, e, PAJMX, nxt))
986+ im = w['imported']; own = esc((im['owner'] or '').encode()); rep = esc((im['repo'] or '').encode())
987+ gh = rd(os.path.join(IMPD, i), 'gh', 2048) or b''
988+ login = ghv(gh, b'login ')
989+ if w['state_derived']: prov = b'Imported from GitHub %s/%s#%d (code only)' % (own, rep, im['number'])
990+ elif not login: prov = b'Imported from GitHub %s/%s#%d' % (own, rep, im['number']) # no login line, or an empty one: the line ends after the number
991+ else: prov = b'Imported from GitHub %s/%s#%d, by %s' % (own, rep, im['number'], esc(login))
992+ w['_prov'] = prov
993+ if prov is not None:
994+ P(page.count(b'<p class="meta">' + prov + b'</p>') == 1 and page.count(b'Imported from GitHub') == 1,
995+ '%s: the page has the provenance line once, as text: %s' % (name, prov.decode('utf-8', 'replace')[:90]))
996+ logins = set(c['login'] for c in w['comments'] if len(c['login']) > 2) | ({im['login']} if im['login'] and len(im['login']) > 2 else set())
997+ sc = Scan(logins); sc.feed(page.decode('utf-8', 'replace')); sc.close()
998+ P(not sc.bad and b'did:key:' not in page, '%s: no did:key: on the page, no login inside a link, no imported byte in a tag, an attribute or a script%s' % (name, sc.bad and ' -- ' + '; '.join(sc.bad[:3]) or ''))
999+ P(page.rstrip().endswith(b'</html>') and page.count(b'</html>') == 1, '%s: the page is a whole document' % name)
1000+# ---- the list: every page
1001+states = {'open': SIGNED, 'closed': 0, 'merged': 0}
1002+for i, name, st in exp:
1003+ if st != '404': states[st] += 1
1004+index = [l for l in open(os.path.join(IMPD, 'index')).read().split('\n') if l]
1005+gone = set(i for i, name, st in exp if st == '404')
1006+wantids = [i for i in reversed(index) if i not in gone]
1007+count = sum(states.values()); damaged = len(index) - count # the items the pages list; the index lines whose folder is no item
1008+rows = []; html = b''; ok = True; why = ''
1009+for p in range(1, LP + 1):
1010+ l = J(open('%s/imp/list.%d.json' % (T, p), 'rb').read()); html += untr(open('%s/imp/list.%d.html' % (T, p), 'rb').read())
1011+ if not (list(l) == ['schema', 'base', 'owner', 'repo', 'page', 'per_page', 'count', 'states', 'damaged', 'patches', 'next', 'prev'] and l['schema'] == 'forge/patch-list/1'
1012+ and l['page'] == p and l['count'] == count and l['states'] == states and list(l['states']) == ['open', 'closed', 'merged'] and l['damaged'] == damaged
1013+ and (l['next'] is None) == (p == LP) and (l['prev'] is None) == (p == 1)):
1014+ ok = False; why = 'page %d: %r' % (p, {k: l[k] for k in l if k != 'patches'})
1015+ want = [i for i in list(reversed(index))[(p - 1) * 30:p * 30] if i not in gone]
1016+ if [r['id'] for r in l['patches']] != want: ok = False; why = 'page %d holds %d rows, want %d' % (p, len(l['patches']), len(want))
1017+ rows += l['patches']
1018+ h = untr(open('%s/imp/list.%d.html' % (T, p), 'rb').read())
1019+ hs = b'<b>%d patches</b> <span class="states">%d open &middot; %d closed &middot; %d merged</span> <span class="muted">%d damaged items are not shown</span> <a href="' % (count, states['open'], states['closed'], states['merged'], damaged)
1020+ P(h.count(hs) == 1 and h.count(b'<li><a class="subject"') == len(want) and h.count(b'damaged') == 1,
1021+ 'list page %d (HTML): %d rows for its 30 index lines (%d of them damaged); the head says %d patches, %d open, %d closed, %d merged, %d damaged items are not shown'
1022+ % (p, len(want), len(index[::-1][(p - 1) * 30:p * 30]) - len(want), count, states['open'], states['closed'], states['merged'], damaged))
1023+P(ok, 'forge/patch-list/1 on every page: count %d (the listed items), states %r (signed patches open), damaged %d, the rows of each page newest first by index position%s' % (count, states, damaged, why and ' -- ' + why))
1024+P(count == len(wantids) == len(rows) and count + damaged == len(index) and damaged == len(gone) > 1,
1025+ 'count (%d) is the sum of the states and the rows of all pages; count + damaged (%d) is the index lines (%d); the damaged are the %d fixtures that are no item' % (count, damaged, len(index), len(gone)))
1026+byid = {r['id']: r for r in rows}
1027+for i, name, st in exp:
1028+ if st == '404':
1029+ P(i not in byid and html.count(i.encode()) == 0, '%s: left out of the list (JSON rows and HTML)' % name); continue
1030+ if i not in docs: continue
1031+ w = docs[i]; x = deep(byid.get(i), row(w))
1032+ P(x == '', '%s: its forge/patch-list/1 row has the keys in order and every value%s' % (name, x and ' -- ' + x))
1033+ if w['_prov'] is None: continue
1034+ badge = {'open': b'<b class="ok">open</b>', 'closed': b'<b class="bad">closed</b>', 'merged': b'<b class="muted">merged</b>'}[w['status']]
1035+ if w['state_derived']: badge += b' <b class="muted">derived</b>'; when = b' imported ' + (w['created'] or '-')[:10].encode()
1036+ else: when = b' opened ' + (w['opened'][:10].encode() if w['opened'] and len(w['opened']) == 20 else b'-')
1037+ title = esc(rd(os.path.join(IMPD, i), 'title', 1024) or b'') or b'(untitled)'
1038+ li = b'<li><a class="subject" href="%s">%s</a><div class="meta">%s <code>%s</code>%s &middot; %s</div></li>' % (w['path'].encode(), title, badge, i.encode(), when, w['_prov'])
1039+ P(html.count(li) == 1, '%s: its HTML list row is title link, badge, id, date and the provenance text, no counts' % name)
1040+sc = Scan(set()); sc.feed(html.decode('utf-8', 'replace')); sc.close()
1041+P(not sc.bad and b'<script>pwn' not in html, 'the list pages hold no imported byte in a tag, an attribute or a script%s' % (sc.bad and ' -- ' + '; '.join(sc.bad[:3]) or ''))
1042+print('DONE')
1043+EOF
1044+fold "$T/imp.out"
1045+
1046+echo "== imported proposals: what the pages say (SPEC-ext section 2)"
1047+# pg ID: the page kept above without the chrome's translate marks; has / hasnot ID TEXT LABEL
1048+pg() { sed 's/<span translate="no">\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$T/imp/$1.html"; }
1049+has() { if pg "$1" | grep -qF -- "$2"; then ok "$3"; else bad "$3: the page lacks: $2"; fi; }
1050+hasnot() { if pg "$1" | grep -qF -- "$2"; then bad "$3: the page holds: $2"; else ok "$3"; fi; }
1051+UTC=2026-11-17T09:30:00Z
1052+has "$IOPEN" "<h2>Add the first imported change</h2>" "open item: the title"
1053+has "$IOPEN" "<p class=\"meta\"><b class=\"ok\">open</b> <code>$IOPEN</code> #101 &middot; opened 2026-11-10 11:00 UTC</p>" "open item: badge, id, number and the opened time, no closed or merged time"
1054+has "$IOPEN" '<p class="meta">Labels: bug, help wanted</p>' "open item: the labels line"
1055+has "$IOPEN" "<p class=\"meta\">Base <code>$MAIN</code> &middot; Head <code>$(cat "$IMPD/$IOPEN/head")</code></p>" "open item: base and head"
1056+has "$IOPEN" '<div class="box"><p class="meta">octo wrote on 2026-11-10 11:00 UTC</p>' "open item: the description box is headed by the login as text and the opened time"
1057+has "$IOPEN" '<div class="box"><p class="meta">alice wrote on 2026-11-10 11:05 UTC</p>' "thread: a comment box"
1058+has "$IOPEN" '<div class="box"><p class="meta">bob reviewed (APPROVED) on 2026-11-10 12:00 UTC</p>' "thread: a review box with its state"
1059+has "$IOPEN" '<div class="box"><p class="meta">carol reviewed (-) on 2026-11-10 12:30 UTC</p>' "thread: a review without a state or a body"
1060+has "$IOPEN" '<div class="box"><p class="meta">bob commented on <code>src/a.txt</code> line 3 on 2026-11-10 13:00 UTC</p>' "thread: a review comment box with path and line"
1061+has "$IOPEN" '<div class="box"><p class="meta">dave wrote on -</p>' "thread: a comment without a time"
1062+has "$IOPEN" '<strong>bold</strong>' "thread: a body is rendered as Markdown"
1063+hasnot "$IOPEN" '**bold**' "thread: the Markdown source is not shown raw"
1064+has "$IOPEN" "<h3>Apply it</h3>" "mbox item: the Apply it box"
1065+has "$IOPEN" "href=\"$R/patches/$IOPEN.patch\">Raw patch (mbox)</a> &middot; <a href=\"$R/patches/$IOPEN.diff\">Diff</a>" "mbox item: the raw links"
1066+hasnot "$IOPEN" "<h3>Signature</h3>" "imported item: no Signature box"
1067+c=$(code GET "$R/patches/$FIRST"); grep -qF '<h3>Signature</h3>' "$T/body" && grep -qF 'did:key:' "$T/body" && ! grep -qF 'Imported from GitHub' "$T/body" && ! grep -qF '<h3>Provenance</h3>' "$T/body" \
1068+ && ok "TWIN a signed patch's page has the Signature box and its author's did:key:, no provenance line and no Provenance box" || bad "TWIN signed page ($c)"
1069+has "$IOPEN" "<h3>Provenance</h3>" "imported item: the Provenance box"
1070+has "$IOPEN" "This proposal is imported from GitHub; it is not signed by its author." "Provenance box: imported, not signed"
1071+has "$IOPEN" "{&quot;kind&quot;:&quot;github-import&quot;,&quot;owner&quot;:&quot;aien-dev&quot;,&quot;repo&quot;:&quot;gh-repo&quot;,&quot;number&quot;:101," "Provenance box: source.json, escaped"
1072+has "$IOPEN" "+change of pull request 101" "mbox item: Changes shows the stored diff"
1073+has "$ICLOSED" "<p class=\"meta\"><b class=\"bad\">closed</b> <code>$ICLOSED</code> #102 &middot; opened 2026-11-10 11:00 UTC &middot; closed 2026-11-12 08:00 UTC</p>" "closed item: badge and the closed time"
1074+has "$IMREACH" "<p class=\"meta\"><b class=\"muted\">merged</b> <code>$IMREACH</code> #103 &middot; opened 2026-11-10 11:00 UTC &middot; closed 2026-11-13 08:00 UTC &middot; merged 2026-11-13 08:00 UTC</p>" "merged item: badge and the three times"
1075+has "$IMREACH" "<p class=\"meta\">Merged on GitHub as <code>$MAIN</code>; reachable from main <code>$MAIN</code> (observed $UTC)</p>" "merged item: merge commit, reachable from main, observation time"
1076+has "$IMNOTR" "<p class=\"meta\">Merged on GitHub as <code>$SIDE</code>; not reachable from main <code>$MAIN</code> (observed $UTC)</p>" "merged item: not reachable from main"
1077+has "$IMUNK" "<p class=\"meta\">Merged on GitHub as <code>$SIDE</code>; reachability from main unknown (observed $UTC)</p>" "merged item: reachability unknown (no main)"
1078+has "$IMUNKM" "<p class=\"meta\">Merged on GitHub as <code>$SIDE</code>; reachability from main unknown (observed $UTC)</p>" "merged item: reachability unknown (git could not tell)"
1079+hasnot "$ICLOSED" "Merged on GitHub as" "TWIN a closed item has no merge line"
1080+has "$IBUND" "<h3>Fetch it</h3>" "bundle item: the Fetch it box"
1081+has "$IBUND" "A git bundle of the pull request's head, $(stat -c %s "$IMPD/$IBUND/head.bundle") bytes." "bundle item: the bundle's size"
1082+has "$IBUND" "git fetch $IBUND.bundle refs/pull/110/head</pre>" "bundle item: the fetch line names refs/pull/<n>/head"
1083+has "$IBUND" "<p><a href=\"$R/patches/$IBUND.bundle\">Raw bundle</a> &middot; <a href=\"$R/patches/$IBUND.diff\">Diff</a></p>" "bundle item with a base in the store: raw bundle and diff links"
1084+has "$IBUND" "+change of pull request 110" "bundle item with a base in the store: Changes shows the bundle diff"
1085+hasnot "$IBUND" "<h3>Apply it</h3>" "bundle item: no Apply it box"
1086+has "$IBNS" "<p class=\"meta\">There is no diff: the base commit is not in this project's git store.</p>" "bundle whose base is not in the store: the sentence"
1087+hasnot "$IBNS" "$IBNS.diff" "bundle whose base is not in the store: no diff link"
1088+has "$ICNOBASE" "<p class=\"meta\">No base commit &middot; Head <code>$(cat "$IMPD/$ICNOBASE/head")</code></p>" "bundle of the head alone: no base commit"
1089+has "$ICNOBASE" "<p class=\"meta\">There is no diff: the bundle has no base commit.</p>" "bundle of the head alone: the sentence"
1090+hasnot "$ICNOBASE" "$ICNOBASE.diff" "bundle of the head alone: no diff link"
1091+DERS="<p class=\"meta\">GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).</p>"
1092+has "$ICOPEN" "<p class=\"meta\"><b class=\"ok\">open</b> <b class=\"muted\">derived</b> <code>$ICOPEN</code> #113</p>" "code-only open: badge open, derived, no times"
1093+has "$ICCLOSED" "<p class=\"meta\"><b class=\"bad\">closed</b> <b class=\"muted\">derived</b> <code>$ICCLOSED</code> #114</p>" "code-only closed: badge closed, derived"
1094+has "$ICMAIN" "<p class=\"meta\"><b class=\"muted\">merged</b> <b class=\"muted\">derived</b> <code>$ICMAIN</code> #115</p>" "code-only merged: badge merged, derived"
1095+for i in ICNOBASE ICOPEN ICCLOSED ICMAIN ICTHREAD; do has "${!i}" "$DERS" "$i: the page says the state is derived and how"; done
1096+hasnot "$IOPEN" "DERIVED" "TWIN an item with GitHub metadata does not say derived"; hasnot "$IOPEN" ">derived<" "TWIN an item with GitHub metadata has no derived badge"
1097+has "$ICMAIN" "<h3>Code</h3>" "code-only on main: the Code box"
1098+has "$ICMAIN" "The head commit is on main: <a href=\"$R/commit/$MAIN\"><code>$MAIN</code></a>." "code-only on main: the page names its head sha, linked to the commit"
1099+has "$ICMAIN" "<p class=\"meta\">There is no diff: the head commit is already on main.</p>" "code-only on main: the sentence in place of a diff"
1100+for s in .diff .patch .bundle; do hasnot "$ICMAIN" "$ICMAIN$s" "code-only on main: the page offers no $s"; done
1101+hasnot "$ICMAIN" "Merged on GitHub as" "code-only on main: no merge line (GitHub's merge commit is unknown)"
1102+has "$ICTHREAD" '<div class="box"><p class="meta">judy wrote on 2026-11-11 09:00 UTC</p>' "code-only with a thread: the comment box, its login as text"
1103+has "$ICTHREAD" '<div class="box"><p class="meta">mallory commented on <code>docs/note.md</code> line 7 on 2026-11-11 09:30 UTC</p>' "code-only with a thread: the review comment box, its login as text"
1104+has "$ICTHREAD" "An inline note on a code-only pull request." "code-only with a thread: the bodies are shown"
1105+# hostile bytes: shown escaped, never as markup
1106+has "$IHOST" '<h2>Fix &lt;script&gt;pwn(1)&lt;/script&gt; &quot;quoted&quot; &amp; &lt;b&gt;more&lt;/b&gt;</h2>' "hostile title: shown escaped"
1107+has "$IHOST" '<p class="meta">Labels: bug, &lt;script&gt;pwn(10)&lt;/script&gt;, la&quot;bel &amp; &lt;b&gt;</p>' "hostile labels: shown escaped"
1108+has "$IHOST" '<div class="box"><p class="meta">ev&quot;il&lt;b&gt;&amp;x wrote on 2026-11-10 11:00 UTC</p>' "hostile login: shown escaped over the description"
1109+has "$IHOST" '<div class="box"><p class="meta">rev&lt;i&gt; reviewed (&lt;script&gt;pwn(14)&lt;/script&gt;) on 2026-11-10 12:00 UTC</p>' "hostile review login and state: shown escaped"
1110+has "$IHOST" '<div class="box"><p class="meta">rc&quot;&lt;u&gt; commented on <code>src/&lt;x&gt;&amp;&quot;y&quot;.txt</code> line 3 on 2026-11-10 13:00 UTC</p>' "hostile review comment login and path: shown escaped"
1111+has "$IHOST" '+&lt;script&gt;pwn(17)&lt;/script&gt; &amp; &quot;x&quot;' "hostile diff line: shown escaped"
1112+has "$IHOST" '&quot;quoted&quot; &amp; ampersand' "hostile description: its text is shown escaped"
1113+n=0; for s in '<script>pwn' '<img src=x' 'onerror=pwn(3)>' '<b>more' '<b>bold' '<a href="javascript' 'href="javascript' 'href="JaVaScRiPt' 'href="data:' 'src="javascript' 'ev"il<b>' 'rev<i>' 'rc"<u>' 'src/<x>' 'la"bel'; do
1114+ for f in "$T/imp/$IHOST.html" "$T/imp/$IHOSTESC.html" "$T"/imp/list.*.html; do grep -qiF -- "$s" "$f" && { n=$((n+1)); echo " raw $s in $f"; }; done; done
1115+check "$n" 0 "hostile bytes: none of 15 raw forms (script, img, onerror, bold, script links, quotes in a login, a path or a label) is on the item pages or the list"
1116+has "$IHOSTSRC" '<p class="meta">Imported from GitHub ev&lt;il&gt;/re&amp;po#121, by octo</p>' "hostile owner and repository names of source.json: shown escaped in the provenance line"
1117+has "$IHOSTESC" '<p class="meta">Imported from GitHub back/gh-repo#122, by octo</p>' "a source.json value holding a JSON escape is cut at the backslash"
1118+# malformed threads: the record before the malformed one is shown, then one sentence
1119+for n in $XTHREADS; do i=${!n}
1120+ if pg "$i" | grep -qF 'The thread stops here: its next record is malformed.' && [ "$(pg "$i" | grep -o '<div class="box"><p class="meta">bob wrote on 2026-11-10 11:05 UTC</p>' | wc -l)" = 1 ] \
1121+ && [ "$(pg "$i" | grep -o '<div class="box"><p class="meta">bob ' | wc -l)" = 1 ]; then ok "$n: the page shows the first record, then says the thread stops at a malformed record"
1122+ else bad "$n: malformed thread page"; fi
1123+done
1124+hasnot "$IOPEN" "The thread stops here" "TWIN a well-formed thread has no such sentence"
1125+has "$XMISSING" '<p class="meta">Imported from GitHub aien-dev/gh-repo#150</p>' "thread, labels and gh missing: the page is there, the number comes from source.json, the provenance line ends after it"
1126+hasnot "$XMISSING" "Labels:" "thread, labels and gh missing: no labels line"
1127+has "$XBARE" "<h2>(untitled)</h2>" "an item of source.json, status and head alone: shown as untitled"
1128+has "$XBARE" "<p class=\"meta\">No base commit &middot; Head <code>$MAIN</code></p>" "an item of source.json, status and head alone: no base"
1129+has "$XT1024" "<h2>$(printf '%1024s' '' | tr ' ' t)</h2>" "a title of 1024 bytes is shown whole"
1130+has "$XT1025" "<h2>$(printf '%1024s' '' | tr ' ' t)</h2>" "a title of 1025 bytes is shown cut to 1024"
1131+# the page budget: the page stays a whole answer and says what it left out
1132+z=$(stat -c %s "$T/imp/$XBIG.html"); b=$(pg "$XBIG" | grep -o '<div class="box"><p class="meta">bob wrote on ' | wc -l)
1133+[ "$(pg "$XBIG" | grep -cF '<p class="meta">The thread is too long for this page; the rest is not shown.</p>')" = 1 ] && [ "$b" -ge 1 ] && [ "$b" -lt 30 ] && [ "$z" -gt 4000000 ] && [ "$z" -lt 8388608 ] \
1134+ && pg "$XBIG" | grep -qF '<h3>Provenance</h3>' && pg "$XBIG" | grep -qF '<h3>Code</h3>' && tail -c 200 "$T/imp/$XBIG.html" | grep -q '</html>' \
1135+ && ok "description and thread over the page budget: $b of 30 comments shown, the sentence that the rest is not, then the code and provenance boxes; a whole page of $z bytes" \
1136+ || bad "page budget (thread): $b boxes, $z bytes, sentence $(pg "$XBIG" | grep -cF 'The thread is too long for this page')"
1137+z=$(stat -c %s "$T/imp/$XBIGD.html")
1138+[ "$(pg "$XBIGD" | grep -cF '<p class="meta">The description is too large for this page.</p>')" = 1 ] && [ "$z" -lt 100000 ] && pg "$XBIGD" | grep -qF '<h3>Provenance</h3>' && tail -c 200 "$T/imp/$XBIGD.html" | grep -q '</html>' \
1139+ && ok "a description over the page budget: one sentence in its place, a whole page of $z bytes" || bad "page budget (description): $z bytes"
1140+z=$(stat -c %s "$T/imp/$XTHUGE.html")
1141+[ "$(pg "$XTHUGE" | grep -cF '<p class="meta">The thread is too long for this page; the rest is not shown.</p>')" = 1 ] && [ "$(pg "$XTHUGE" | grep -cF '<p class="meta">The thread file is larger than this forge reads; the rest is not shown.</p>')" = 1 ] \
1142+ && [ "$z" -lt 8388608 ] && pg "$XTHUGE" | grep -qF '<h3>Provenance</h3>' && tail -c 200 "$T/imp/$XTHUGE.html" | grep -q '</html>' \
1143+ && ok "a thread file over 16 MiB: the page says the thread is cut and that the file is larger than the forge reads; a whole page of $z bytes" || bad "thread over 16 MiB: $z bytes"
1144+has "$XTLARGE" '<p class="meta">The thread file is larger than this forge reads; the rest is not shown.</p>' "a thread record past the 16 MiB the forge reads: the page says the file is larger than it reads"
1145+hasnot "$XTLARGE" "The thread stops here" "a thread record past the 16 MiB the forge reads: not called malformed"
1146+check "$(pg "$XTLARGE" | grep -o '<div class="box"><p class="meta">bob wrote on 2026-11-10 11:05 UTC</p>' | wc -l)" 1 "a thread record past the 16 MiB the forge reads: the record before it is shown"
1147+for i in XDESCBUD XDESC500; do
1148+ [ "$(pg "${!i}" | grep -cF '<p class="meta">The description is too large for this page.</p>')" = 1 ] && pg "${!i}" | grep -qF '<h3>Provenance</h3>' && tail -c 200 "$T/imp/${!i}.html" | grep -q '</html>' \
1149+ && ok "$i: the page says the description is too large and stays whole ($(stat -c %s "$T/imp/${!i}.html") bytes)" || bad "$i: page of a very long description"
1150+done
1151+hasnot "$IOPEN" "too long for this page" "TWIN a small item's page says nothing of a cut"; hasnot "$IOPEN" "too large for this page" "TWIN a small description is shown"
1152+python3 -c "
1153+import json, sys
1154+d = json.load(open(sys.argv[1], 'rb')); e = json.load(open(sys.argv[2], 'rb'))
1155+assert len(d['comments']) == 30 and len(d['description']) > 2500000 and len(e['description']) > 5400000" "$T/imp/$XBIG.json" "$T/imp/$XBIGD.json" 2> "$T/py.err" \
1156+ && ok "the documents of the two large items are whole (30 comments; descriptions of 2.6 and 5.5 MB)" || bad "large item JSON: $(tail -1 "$T/py.err")"
1157+for i in XREACHBAD XREACHNONE; do has "${!i}" "<p class=\"meta\">Merged on GitHub as <code>$SIDE</code></p>" "$i: the merge commit without a reach clause"; done
1158+hasnot "$XMERGEDNONE" "Merged on GitHub as" "a merged item without its merged file: no merge line"
1159+# cc ID: comments_count of the item's row in the list documents kept above
1160+cc() { python3 -c "import glob, json, sys
1161+for f in sorted(glob.glob(sys.argv[1] + '/imp/list.*.json')):
1162+ for r in json.load(open(f))['patches']:
1163+ if r['id'] == sys.argv[2]: print(r['comments_count'])" "$T" "$1"; }
1164+check "$(cc "$IOPEN") $(cc "$ICTHREAD") $(cc "$ICLOSED") $(cc "$XTPAST") $(cc "$XTHUGE") $(cc "$FIRST") $(cc "$XTLARGE") $(cc "$XDESCBUD")" "5 2 0 1 167 0 1 1" "comments_count in the list: the thread's records (5), a code-only thread (2), none (0), up to a malformed record (1), the whole records of the first 16 MiB (167, more than its document holds), a signed patch (0), up to a record past 16 MiB (1), a record its document leaves out (1)"
1165+has "$XDIFF" "<p class=\"meta\">The diff is larger than 16 MiB, too large to show: fetch the bundle instead.</p>" "a bundle diff over 16 MiB: the page says it is too large and names the bundle"
1166+has "$XDIFF" "href=\"$R/patches/$XDIFF.bundle\">Raw bundle</a></p>" "a bundle diff over 16 MiB: the raw bundle link, no diff link"
1167+
1168+echo "== imported proposals: named controls (each is the control of one or more mutants below)"
1169+# ictl LABEL COMMAND: COMMAND asks the forge and sets C (what it answered) and WANT (what a correct forge answers)
1170+ictl() { eval "$2"; if [ "$C" = "$WANT" ]; then ok "$1: $C"; else bad "$1: want \"$WANT\", got \"$(printf '%s' "$C" | head -c 200)\""; fi; }
1171+yn() { if "$@" 2> /dev/null; then echo yes; else echo no; fi; }
1172+# raw PATH FILE: GET PATH into FILE (headers in $T/hdr); the status
1173+raw() { : > "$2"; : > "$T/hdr"; curl -s -o "$2" -D "$T/hdr" -w '%{http_code}' "$B$1"; }
1174+# pgnow ID: the page of item ID asked now, in $T/body without the translate marks; the status
1175+pgnow() { c=$(code GET "$R/patches/$1"); untr; echo "$c"; }
1176+# jf ID EXPR: a python expression over d, the forge/patch/1 document of item ID asked now; "?" when it is not JSON
1177+jf() { curl -s -H 'Accept: application/json' "$B$R/patches/$1" | python3 -c "import json, sys
1178+try:
1179+ d = json.load(sys.stdin); print($2)
1180+except Exception: print('?')"; }
1181+# statesnow: what a correct list says of the index, read from the folders: count (the lines whose folder is an item:
1182+# a signed patch whose meta, title, statement and head files are whole, which is open; or an imported item by the rule
1183+# of SPEC section 1), these by state, and damaged (every other line)
1184+statesnow() { python3 - "$IMPD" <<'EOF'
1185+import os, re, sys
1186+D = sys.argv[1]; s = {'open': 0, 'closed': 0, 'merged': 0}
1187+def rd(p):
1188+ try: return open(p, 'rb').read()
1189+ except OSError: return b''
1190+HEX = rb'[0-9a-f]{40}\n'
1191+lines = open(D + '/index', 'rb').read().split(b'\n')[:-1]
1192+for l in lines:
1193+ if not re.fullmatch(rb'[0-9a-f]{16}', l): continue
1194+ d = D + '/' + l.decode(); st = {b'open\n': 'open', b'closed\n': 'closed', b'merged\n': 'merged'}.get(rd(d + '/status'))
1195+ if os.path.exists(d + '/meta'):
1196+ if re.fullmatch(rb'[^\n]{9,120}\n([0-9]{1,18}\n){4}[0-9a-f]{64}\n', rd(d + '/meta')) and 1 <= len(rd(d + '/title')) <= 256 \
1197+ and 180 <= len(rd(d + '/statement')) <= 511 and re.fullmatch(HEX, rd(d + '/head')): s['open'] += 1
1198+ elif rd(d + '/source.json').startswith(b'{"kind":"github-import","owner":"') and st and re.fullmatch(HEX, rd(d + '/head')): s[st] += 1
1199+c = sum(s.values())
1200+print('count=%d open=%d closed=%d merged=%d damaged=%d' % (c, s['open'], s['closed'], s['merged'], len(lines) - c))
1201+EOF
1202+}
1203+c_states() { C=$(lsum); WANT=$(statesnow); }
1204+# the damaged lines, each with the index made for it: none; one (a line without a folder); three (a line that is no id
1205+# right after an item's line, a folder that is no item, a line without a folder) between an open, a closed and a merged item
1206+BAR1='<b>1 patch</b> <span class="states">1 open &middot; 0 closed &middot; 0 merged</span>'
1207+c_dmg0() { withindex "$FIRST"; C="$LJ | $LH | rows=$LR"; WANT="count=1 open=1 closed=0 merged=0 damaged=0 | $BAR1 | rows=1"; }
1208+c_dmg1() { withindex "$FIRST" 0123456789abcdef; C="$LJ | $LH | rows=$LR"; WANT="count=1 open=1 closed=0 merged=0 damaged=1 | $BAR1 <span class=\"muted\">1 damaged item is not shown</span> | rows=1"; }
1209+c_dmg3() { withindex "$FIRST" zzzzzzzzzzzzzzzz "$ICLOSED" "$XSTATUS" "$IMREACH" 0123456789abcdef; C="$LJ | $LH | rows=$LR"
1210+ WANT="count=3 open=1 closed=1 merged=1 damaged=3 | <b>3 patches</b> <span class=\"states\">1 open &middot; 1 closed &middot; 1 merged</span> <span class=\"muted\">3 damaged items are not shown</span> | rows=3"; }
1211+# thread_truncated and thread_reason of the document, with the comments it holds
1212+tt() { jf "$1" "d['thread_truncated'], d['thread_reason'], len(d['comments'])"; }
1213+c_trunc() { C="$(tt "$IOPEN") | $(tt "$XTPAST") | $(tt "$XTKIND") | $(tt "$FIRST") | $(tt "$XMISSING") | $(tt "$XBIG")"; WANT="False None 5 | True malformed-record 1 | True malformed-record 1 | False None 0 | False None 0 | False None 30"; }
1214+c_trunclarge() { C=$(tt "$XTLARGE"); WANT="True too-large 1"; }
1215+# c_docbudget: the document of the 17 MB thread is a whole valid answer under 8388608 bytes that holds some of its 167 whole records
1216+c_docbudget() { c=$(code GET "$R/patches/$XTHUGE" -H 'Accept: application/json'); C="$c $(python3 -c "import json, sys
1217+try:
1218+ b = open(sys.argv[1], 'rb').read(); d = json.loads(b.decode('utf-8')); print(len(b) < 8388608, d['thread_truncated'], d['thread_reason'], 0 < len(d['comments']) < 167, all(len(c['body']) == 100000 for c in d['comments']))
1219+except Exception: print('?')" "$T/body")"; WANT="200 True True document-budget True True"; }
1220+c_descbud() { C=$(jf "$XDESCBUD" "len(d['comments']), d['thread_truncated'], d['thread_reason'], len(d['description'])"); WANT="0 True document-budget 7577200"; }
1221+c_desc500() { c=$(code GET "$R/patches/$XDESC500" -H 'Accept: application/json'); C="$c $(python3 -c "import json, sys
1222+try:
1223+ b = open(sys.argv[1], 'rb').read(); d = json.loads(b.decode('utf-8')); print(len(b) < 1000, 'description' not in d)
1224+except Exception: print('?')" "$T/body") $(code GET "$R/patches/$XDESC500")"; WANT="500 True True 200"; }
1225+# dun ID: diff ("link" when it is the item's .diff path) and diff_unavailable of item ID asked now, in its document and in its list row
1226+dun() { python3 - "$B" "$R" "$1" <<'EOF'
1227+import json, sys, urllib.request
1228+B, R, I = sys.argv[1:]
1229+def get(p):
1230+ with urllib.request.urlopen(urllib.request.Request(B + p, headers={'Accept': 'application/json'})) as r: return json.loads(r.read().decode('utf-8'))
1231+def f(x): return '%s/%s' % ('link' if x['diff'] == x['path'] + '.diff' else x['diff'], x['diff_unavailable'])
1232+try:
1233+ out = 'doc=' + f(get(R + '/patches/' + I)); p = 1; row = None
1234+ while p and row is None:
1235+ l = get(R + '/patches?page=%d' % p); row = next((r for r in l['patches'] if r['id'] == I), None); p = p + 1 if l['next'] else 0
1236+ print(out + ' row=' + (f(row) if row else '?'))
1237+except Exception as e: print('? %s' % e)
1238+EOF
1239+}
1240+LINK="doc=link/None row=link/None"
1241+c_dunlink() { C="$(dun "$FIRST") | $(dun "$IOPEN") | $(dun "$IBUND")"; WANT="$LINK | $LINK | $LINK"; }
1242+c_dunmbox() { C=$(dun "$IMBNS"); WANT=$LINK; }
1243+c_dunnocode() { C="$(dun "$ICMAIN") | $(dun "$XNCMETA")"; WANT="doc=None/no-code-file row=None/no-code-file | doc=None/no-code-file row=None/no-code-file"; }
1244+c_dunnobase() { C=$(dun "$ICNOBASE"); WANT="doc=None/no-base row=None/no-base"; }
1245+c_dunbns() { rm -f "$PD/$IBNS" "$PD/$IBNS.big"; C=$(dun "$IBNS"); WANT="doc=None/base-not-in-store row=None/base-not-in-store"; }
1246+# c_duncache: a cache file comes first: with one planted for the item whose base the store lacks, its diff is a link
1247+c_duncache() { mkdir -p "$PD"; printf 'planted\n' > "$PD/$IBNS"; C=$(dun "$IBNS"); rm -f "$PD/$IBNS"; WANT=$LINK; }
1248+# c_duntoolarge: the documents make no diff: before the first attempt the diff over 16 MiB is still a link; the attempt
1249+# (GET .diff: 404) leaves the marker, and from then on diff is null with too-large
1250+c_duntoolarge() { rm -f "$PD/$XDIFF" "$PD/$XDIFF.big"; a=$(dun "$XDIFF"); m=$(yn test -e "$PD/$XDIFF.big"); c=$(code GET "$R/patches/$XDIFF.diff"); C="$a marker=$m | $c | $(dun "$XDIFF")"; WANT="$LINK marker=no | 404 | doc=None/too-large row=None/too-large"; }
1251+# the marker <data>pdiff/<owner>/<repo>/<id>.big. c_marker: the first .diff request of the diff over 16 MiB runs git
1252+# (<data>tmp changes) and leaves the empty marker; the second answers from the marker: no git run, the marker as it was
1253+# (inode, time, size), the same files in the cache folder, no cache file, no work folder, nothing staged
1254+dstat() { stat -c '%i %y %s' "$1" 2>&1; }
1255+c_marker() { rm -f "$PD/$XDIFF" "$PD/$XDIFF.big"; m0=$(dstat "$T/data/patch-work"); c1=$(code GET "$R/patches/$XDIFF.diff"); m1=$(dstat "$T/data/patch-work"); s1=$(dstat "$PD/$XDIFF.big"); l1=$(ls -A "$PD")
1256+ c2=$(code GET "$R/patches/$XDIFF.diff"); m2=$(dstat "$T/data/patch-work"); s2=$(dstat "$PD/$XDIFF.big"); l2=$(ls -A "$PD")
1257+ C="$c1 $c2 size=$(stat -c %s "$PD/$XDIFF.big" 2>&1) once=$(yn [ "$s1" = "$s2" ]) git1=$(yn [ "$m0" != "$m1" ]) git2=$(yn [ "$m1" != "$m2" ]) files=$(yn [ "$l1" = "$l2" ]) cache=$(yn test -e "$PD/$XDIFF") work=$(tmpleft) staged=$(pdstaged)"
1258+ WANT="404 404 size=0 once=yes git1=yes git2=no files=yes cache=no work=0 staged=0"; }
1259+# c_markerkeep: a marker that is already there (here with one byte in it) is left as it is, and answers the page and the raw route
1260+c_markerkeep() { rm -f "$PD/$XDIFF" "$PD/$XDIFF.big"; mkdir -p "$PD"; printf x > "$PD/$XDIFF.big"; s1=$(dstat "$PD/$XDIFF.big"); c=$(code GET "$R/patches/$XDIFF.diff"); p=$(pgnow "$XDIFF")
1261+ C="$c $p $(yn grep -qF 'The diff is larger than 16 MiB, too large to show: fetch the bundle instead.' "$T/body") kept=$(yn [ "$(dstat "$PD/$XDIFF.big")" = "$s1" ]) work=$(tmpleft)"; WANT="404 200 yes kept=yes work=0"; : > "$PD/$XDIFF.big"; }
1262+# c_markerpar: four first requests at once: each 404, one empty marker, no cache file, no work folder, nothing staged
1263+c_markerpar() { rm -f "$PD/$XDIFF" "$PD/$XDIFF.big"; : > "$T/par.out"; pp=; for k in 1 2 3 4; do curl -s -o /dev/null -w '%{http_code}\n' "$B$R/patches/$XDIFF.diff" >> "$T/par.out" & pp="$pp $!"; done; wait $pp
1264+ C="$(tr '\n' ' ' < "$T/par.out")size=$(stat -c %s "$PD/$XDIFF.big" 2>&1) cache=$(yn test -e "$PD/$XDIFF") work=$(tmpleft) staged=$(pdstaged)"; WANT="404 404 404 404 size=0 cache=no work=0 staged=0"; }
1265+# c_markersmall: the marker is read before git is asked: planted beside the small bundle item (base in the store, no cache
1266+# file) it makes .diff 404 with no cache file made, the page and the documents say too large; with it removed the diff is made
1267+c_markersmall() { rm -f "$PD/$IBUND"; mkdir -p "$PD"; : > "$PD/$IBUND.big"; c=$(code GET "$R/patches/$IBUND.diff"); p=$(pgnow "$IBUND")
1268+ C="$c $p $(yn grep -qF 'The diff is larger than 16 MiB, too large to show: fetch the bundle instead.' "$T/body") cache=$(yn test -e "$PD/$IBUND") $(dun "$IBUND")"; rm -f "$PD/$IBUND.big"
1269+ c=$(raw "$R/patches/$IBUND.diff" "$T/raw"); C="$C | $c cache=$(yn cmp -s "$PD/$IBUND" "$T/oracle.bund") $(dun "$IBUND")"; WANT="404 200 yes cache=no doc=None/too-large row=None/too-large | 200 cache=yes $LINK"; }
1270+# c_bigfresh: the first diff over 16 MiB of a forge whose cache folder does not exist yet still leaves its marker
1271+c_bigfresh() { rm -rf "$T/data/pdiff"; c=$(code GET "$R/patches/$XDIFF.diff"); C="$c marker=$(yn test -f "$PD/$XDIFF.big") size=$(stat -c %s "$PD/$XDIFF.big" 2>&1)"; WANT="404 marker=yes size=0"; }
1272+c_status() { C=$(code GET "$R/patches/$XSTATUS"); WANT=404; }
1273+c_head() { C=$(code GET "$R/patches/$XHEADUP"); WANT=404; }
1274+c_headlong() { C=$(code GET "$R/patches/$XHEADLONG"); WANT=404; }
1275+c_headnolf() { C=$(code GET "$R/patches/$XHEADNOLF"); WANT=404; }
1276+c_src() { C=$(code GET "$R/patches/$XSRCKIND"); WANT=404; }
1277+# c_srcshort: a source.json cut inside the start, asked right after an item whose source.json is whole (its bytes are
1278+# then still in the forge's read buffer behind the short file's)
1279+c_srcshort() { code GET "$R/patches/$XSTATUS" > /dev/null; C=$(code GET "$R/patches/$XSRCSHORT"); WANT=404; }
1280+c_both() { C=$(code GET "$R/patches/$XBOTH"); WANT=404; }
1281+c_rawbad() { C="$(code GET "$R/patches/$XSTATUS.patch") $(code GET "$R/patches/$XSTATUS.diff") $(code GET "$R/patches/$XSTATUS.bundle")"; WANT="404 404 404"; }
1282+# thrctl ID: a thread whose second record is malformed: the page, the comments of the document, the sentence, the boxes
1283+thrctl() { c=$(pgnow "$1"); C="$c $(jf "$1" "len(d['comments'])") $(yn grep -qF 'The thread stops here: its next record is malformed.' "$T/body") $(grep -o '<div class="box"><p class="meta">bob ' "$T/body" | wc -l)"; WANT="200 1 yes 1"; }
1284+c_pgcut() { c=$(pgnow "$XBIG"); C="$c $(grep -cF 'The thread is too long for this page; the rest is not shown.' "$T/body") $(yn grep -qF '<h3>Provenance</h3>' "$T/body") $(yn grep -q '</html>' "$T/body")"; WANT="200 1 yes yes"; }
1285+c_title() { C="$(jf "$XT1024" "len(d['title'])") $(jf "$XT1025" "len(d['title'])") $(jf "$XT1025U" "len(d['title']), d['title'][-1] == chr(0xfffd)") $(code GET "$R/patches/$XT1025")"; WANT="1024 1024 1024 True 200"; }
1286+c_jdash() { C=$(jf "$IOPEN" "d['closed'], d['imported']['login'], d['comments'][2]['state'], d['comments'][4]['time']"); WANT="None octo None None"; }
1287+c_prov() { c=$(pgnow "$IOPEN"); C=$(grep -o '<p class="meta">Imported from GitHub[^<]*</p>' "$T/body"); WANT='<p class="meta">Imported from GitHub aien-dev/gh-repo#101, by octo</p>'; }
1288+c_provcode() { c=$(pgnow "$ICOPEN"); C=$(grep -o '<p class="meta">Imported from GitHub[^<]*</p>' "$T/body"); WANT='<p class="meta">Imported from GitHub aien-dev/gh-repo#113 (code only)</p>'; }
1289+# c_nologin: gh without a login line and with an empty login: the provenance line ends after the number, login null
1290+c_nologin() { c=$(pgnow "$INOLOGIN"); C="$(grep -o '<p class="meta">Imported from GitHub[^<]*</p>' "$T/body") $(jf "$INOLOGIN" "d['imported']['login']")"; c=$(pgnow "$IEMPTYLOGIN")
1291+ C="$C $(grep -o '<p class="meta">Imported from GitHub[^<]*</p>' "$T/body") $(jf "$IEMPTYLOGIN" "d['imported']['login']")"
1292+ WANT='<p class="meta">Imported from GitHub aien-dev/gh-repo#180</p> None <p class="meta">Imported from GitHub aien-dev/gh-repo#181</p> None'; }
1293+# nocode ID: an item without a code file that is not the on-main route: one Code box with the plain sentence, the plain
1294+# sentence under Changes, no "on main" wording, no link to a commit page, and code none with null links in the document
1295+nocode() { c=$(pgnow "$1"); C="$c $(grep -cF '<div class="box"><h3>Code</h3>' "$T/body") $(yn grep -qF '<p class="meta">This item holds no code file.</p></div>' "$T/body") $(yn grep -qF '<p class="meta">There is no diff: this item holds no code file.</p>' "$T/body") $(yn grep -qF 'The head commit is on main' "$T/body") $(yn grep -qF 'already on main' "$T/body") $(yn grep -qF "href=\"$R/commit/" "$T/body") $(jf "$1" "d['code'], d['diff'], d['patch'], d['bundle'], d['bytes']")"
1296+ WANT="200 1 yes yes no no no none None None None 0"; }
1297+# c_ncnobase: asked right after the on-main item, whose base is this item's head (a reader that forgot "no base file" would compare with that one)
1298+c_ncnobase() { code GET "$R/patches/$ICMAIN" > /dev/null; nocode "$XNCNOBASE"; }
1299+# c_onmainpg: the on-main route keeps its wording and its link to the commit page
1300+c_onmainpg() { c=$(pgnow "$ICMAIN"); C="$c $(yn grep -qF "The head commit is on main: <a href=\"$R/commit/$MAIN\"><code>$MAIN</code></a>." "$T/body") $(yn grep -qF '<p class="meta">There is no diff: the head commit is already on main.</p>' "$T/body") $(yn grep -qF 'holds no code file' "$T/body")"; WANT="200 yes yes no"; }
1301+c_derived() { c=$(pgnow "$ICOPEN"); C="$(jf "$ICOPEN" "d['state_derived'], d['imported']['login']") $(yn grep -qF '<b class="ok">open</b> <b class="muted">derived</b>' "$T/body") $(yn grep -qF 'its state is DERIVED from the commits' "$T/body")"; WANT="True None yes yes"; }
1302+c_cthread() { c=$(pgnow "$ICTHREAD"); C="$(jf "$ICTHREAD" "d['state_derived'], d['imported']['login'], d['author'], [(c['login'], c['kind'], c['author']) for c in d['comments']]") $(grep -o '<p class="meta">Imported from GitHub[^<]*</p>' "$T/body")"
1303+ WANT="True None None [('judy', 'comment', None), ('mallory', 'review-comment', None)] <p class=\"meta\">Imported from GitHub aien-dev/gh-repo#116 (code only)</p>"; }
1304+c_esclogin() { c=$(pgnow "$IHOST"); C="$(yn grep -qF ', by ev&quot;il&lt;b&gt;&amp;x</p>' "$T/body") $(yn grep -qF 'ev"il<b>' "$T/body")"; WANT="yes no"; }
1305+c_escthread() { c=$(pgnow "$IHOST"); C="$(yn grep -qF 'rev&lt;i&gt; reviewed (&lt;script&gt;pwn(14)&lt;/script&gt;) on' "$T/body") $(yn grep -qF '<script>pwn(14)' "$T/body") $(yn grep -qF 'rev<i>' "$T/body")"; WANT="yes no no"; }
1306+c_esclabel() { c=$(pgnow "$IHOST"); C="$(yn grep -qF 'la&quot;bel &amp; &lt;b&gt;' "$T/body") $(yn grep -qF '<script>pwn(10)' "$T/body")"; WANT="yes no"; }
1307+# the bundle diff. gdiff BASE HEAD: the importer's own diff form, by git in the source repository
1308+gdiff() { env -i PATH="$PATH" HOME="$T/home" git -C "$T/gh" diff --no-color --no-ext-diff --no-textconv "$1...$2"; }
1309+gdiff "$MAIN" "$HBUND" > "$T/oracle.bund"; gdiff "$A" "$HCCLOSED" > "$T/oracle.cclosed"; gdiff "$MAIN" "$HNOTR" > "$T/oracle.notr"
1310+git -C "$T/gh" diff --no-color "$MAIN..$HBUND" | cmp -s - "$T/oracle.bund" && bad "FIXTURE: base...head and base..head of the bundle item are the same diff" || ok "FIXTURE base...head of the bundle item ($(stat -c %s "$T/oracle.bund") bytes) is not base..head"
1311+c_bdiff() { rm -f "$PD/$IBUND"; c=$(raw "$R/patches/$IBUND.diff" "$T/raw"); C="$c $(sha < "$T/raw")"; WANT="200 $(sha < "$T/oracle.bund")"; }
1312+c_bdtmp() { rm -f "$PD/$IBUND"; c=$(raw "$R/patches/$IBUND.diff" "$T/raw"); C="$c work=$(tmpleft) staged=$(pdstaged) cache=$(yn cmp -s "$PD/$IBUND" "$T/oracle.bund")"; WANT="200 work=0 staged=0 cache=yes"; }
1313+# c_cache: with the cache file there, its bytes are what the route serves: nothing is made again
1314+c_cache() { raw "$R/patches/$IBUND.diff" "$T/raw" > /dev/null; if [ -f "$PD/$IBUND" ]; then printf 'CACHED MARKER\n' > "$PD/$IBUND"; C=$(curl -s "$B$R/patches/$IBUND.diff"); else C="no cache file"; fi; WANT="CACHED MARKER"; rm -f "$PD/$IBUND"; }
1315+c_basens() { c=$(code GET "$R/patches/$IBNS.diff"); p=$(pgnow "$IBNS"); C="$c $p $(yn grep -qF "There is no diff: the base commit is not in this project's git store." "$T/body") work=$(tmpleft) cache=$(yn test -e "$PD/$IBNS")"; WANT="404 200 yes work=0 cache=no"; }
1316+c_big() { rm -f "$PD/$XDIFF" "$PD/$XDIFF.big"; c=$(code GET "$R/patches/$XDIFF.diff"); p=$(pgnow "$XDIFF"); C="$c $p $(yn grep -qF 'The diff is larger than 16 MiB, too large to show: fetch the bundle instead.' "$T/body") work=$(tmpleft) cache=$(yn test -e "$PD/$XDIFF") marker=$(yn test -f "$PD/$XDIFF.big")"; WANT="404 200 yes work=0 cache=no marker=yes"; rm -f "$PD/$XDIFF"; }
1317+# c_nobase / c_jnobase: the item before it is one with a base in the store, so a reader that forgot "no base" would use that one
1318+c_nobase() { code GET "$R/patches/$IBUND" > /dev/null; C=$(code GET "$R/patches/$ICNOBASE.diff"); WANT=404; }
1319+c_jnobase() { code GET "$R/patches/$IBUND" -H 'Accept: application/json' > /dev/null; C=$(jf "$ICNOBASE" "d['base_commit'], d['diff'], d['code'], d['bundle'] is not None"); WANT="None None bundle True"; }
1320+c_onmain() { C="$(code GET "$R/patches/$ICMAIN.diff") $(code GET "$R/patches/$ICMAIN.patch") $(code GET "$R/patches/$ICMAIN.bundle") $(jf "$ICMAIN" "d['code'], d['diff'], d['patch'], d['bundle'], d['bytes'], d['base_commit'] == d['head_commit']")"; WANT="404 404 404 none None None None 0 True"; }
1321+c_patchbund() { C="$(code GET "$R/patches/$IBUND.patch") $(code GET "$R/patches/$IOPEN.bundle") $(code GET "$R/patches/$FIRST.bundle")"; WANT="404 404 404"; }
1322+ictl "NEG status not one of the three words: no item" c_status
1323+ictl "NEG head in uppercase hex: no item" c_head
1324+ictl "NEG head followed by another line: no item" c_headlong
1325+ictl "NEG head of 40 hex without its line feed: no item" c_headnolf
1326+ictl "NEG source.json of another kind: no item" c_src
1327+ictl "NEG source.json cut inside its start: no item" c_srcshort
1328+ictl "NEG an item folder with a meta file that does not load beside source.json: no item" c_both
1329+ictl "NEG the raw routes of a malformed item that holds an mbox, a diff and a bundle" c_rawbad
1330+# a whole signed patch with a source.json put beside its meta file stays the signed patch (SPEC section 1: meta loads)
1331+I0=$I; I=$IMPD/$FIRST; impsrc 199; I=$I0; c=$(code GET "$R/patches/$FIRST")
1332+[ "$c" = 200 ] && grep -qF '<h3>Signature</h3>' "$T/body" && ! grep -qF 'Imported from GitHub' "$T/body" && [ "$(jf "$FIRST" "d['imported'], d['author']['did'][:8], d['state_derived'], d['code']")" = "None did:key: False mbox" ] \
1333+ && ok "TWIN a signed patch with a source.json beside its meta file is still the signed patch (page and document)" || bad "signed patch with a source.json ($c)"
1334+rm -f "$IMPD/$FIRST/source.json"
1335+ictl "the list counts the items that load, by state, and the damaged lines (count + damaged = index lines)" c_states
1336+ictl "TWIN no damaged line: count 1, no sentence about damaged items, one row" c_dmg0
1337+ictl "NEG one damaged line (no folder): count 1, damaged 1, the sentence in the singular, one row" c_dmg1
1338+ictl "NEG three damaged lines (no id, a folder that is no item, no folder): count 3 = 1 + 1 + 1, damaged 3, the sentence in the plural, three rows" c_dmg3
1339+ictl "thread_truncated: false for a whole thread, a signed patch, no thread file and a thread only its page cuts; true with malformed-record for a malformed record" c_trunc
1340+ictl "NEG thread_truncated for a thread file past the 16 MiB the forge reads: too-large" c_trunclarge
1341+ictl "NEG thread_truncated for a thread whose document form passes the budget: a whole valid 200 under 8388608 bytes, document-budget, whole records only" c_docbudget
1342+ictl "NEG a description that fills the document past its budget: 200, the one comment left out whole, document-budget" c_descbud
1343+ictl "NEG a description that alone does not fit a response: the whole 500 as valid JSON, its page 200" c_desc500
1344+for n in $XTHREADS; do ictl "NEG $n: page, one comment in the document, the sentence, one box" "thrctl \$$n"; done
1345+ictl "the page budget cuts the thread with one sentence and the page stays whole" c_pgcut
1346+ictl "titles of 1024, 1025 and 1023+2 bytes: 1024 bytes kept, an ill-formed last byte is U+FFFD in the document" c_title
1347+ictl "a time or a state of \"-\" is null in the document, the login a string" c_jdash
1348+ictl "the provenance line of an item with GitHub metadata, exactly, with no markup in it" c_prov
1349+ictl "the provenance line of a code-only item, exactly" c_provcode
1350+ictl "NEG gh without a login line, and with an empty login: the provenance line ends after the number (no \", by \"), login null" c_nologin
1351+ictl "NEG an item with metadata (merged, base = head) without a code file: the plain sentence, no on-main wording or commit link, code none" 'nocode $XNCMETA'
1352+ictl "NEG code-only open (base = head) without a code file: the same" 'nocode $XNCOPEN'
1353+ictl "NEG code-only closed (base = head) without a code file: the same" 'nocode $XNCCLOSED'
1354+ictl "NEG code-only merged with a base that is not its head, without a code file: the same" 'nocode $XNCBASE'
1355+ictl "NEG code-only merged without a base file or a code file: the same" c_ncnobase
1356+ictl "TWIN the on-main item (code-only, merged, base = head) keeps the on-main wording and its link to the commit" c_onmainpg
1357+ictl "code-only: state_derived true, login null, the derived badge and sentence" c_derived
1358+ictl "code-only with a thread: derived, login null, the records in the document, the code-only provenance line" c_cthread
1359+ictl "hostile login in the provenance line: escaped, not raw" c_esclogin
1360+ictl "hostile thread login and state: escaped, not raw" c_escthread
1361+ictl "hostile label: escaped, not raw" c_esclabel
1362+
1363+echo "== imported proposals: raw routes and the bundle diff (SPEC-ext section 4)"
1364+c=$(raw "$R/patches/$IOPEN.patch" "$T/raw"); cmp -s "$T/raw" "$IMPD/$IOPEN/mbox" && [ "$c" = 200 ] && [ "$(hdr content-type)" = "text/plain; charset=utf-8" ] && ok "GET .patch of an imported mbox item is the stored mbox, text/plain" || bad ".patch of the imported mbox item ($c $(hdr content-type))"
1365+c=$(raw "$R/patches/$IOPEN.diff" "$T/raw"); cmp -s "$T/raw" "$IMPD/$IOPEN/diff" && [ "$c" = 200 ] && ok "GET .diff of an imported mbox item is the stored diff file" || bad ".diff of the imported mbox item ($c)"
1366+c=$(raw "$R/patches/$ICOPEN.diff" "$T/raw"); cmp -s "$T/raw" "$IMPD/$ICOPEN/diff" && [ "$c" = 200 ] && ok "GET .diff of a code-only mbox item is the stored diff file" || bad ".diff of the code-only mbox item ($c)"
1367+c=$(raw "$R/patches/$IMBNS.diff" "$T/raw"); cmp -s "$T/raw" "$IMPD/$IMBNS/diff" && [ "$c" = 200 ] && ok "GET .diff of an mbox item whose base is not in the git store is the stored diff file" || bad ".diff of the mbox item with a base outside the store ($c)"
1368+for i in IBUND IBNS ICNOBASE XDIFF; do
1369+ c=$(raw "$R/patches/${!i}.bundle" "$T/raw"); cmp -s "$T/raw" "$IMPD/${!i}/head.bundle" && [ "$c" = 200 ] && [ "$(hdr content-type)" = "application/octet-stream" ] \
1370+ && ok "GET .bundle of $i is the stored head.bundle ($(stat -c %s "$T/raw") bytes), application/octet-stream" || bad ".bundle of $i ($c $(hdr content-type))"
1371+done
1372+ictl "NEG .patch of a bundle item, .bundle of an mbox item and of a signed patch" c_patchbund
1373+# the page of each bundle item above already made its cache file once
1374+pdfiles() { ls -A "$PD" | LC_ALL=C sort | tr '\n' ' '; }
1375+PDWANT=$(printf '%s\n' "$IBUND" "$ICCLOSED" "$IMNOTR" "$XDIFF.big" | LC_ALL=C sort | tr '\n' ' ')
1376+cmp -s "$PD/$IBUND" "$T/oracle.bund" && cmp -s "$PD/$ICCLOSED" "$T/oracle.cclosed" && cmp -s "$PD/$IMNOTR" "$T/oracle.notr" && [ "$(pdfiles)" = "$PDWANT" ] && [ ! -s "$PD/$XDIFF.big" ] \
1377+ && ok "the pages made one cache file per bundle item with a base in the store (3), each git's base...head diff, and the empty marker of the diff over 16 MiB; nothing for the others" || bad "cache files after the pages: $(pdfiles)"
1378+ictl "GET .diff of a bundle item, the cache file gone: git diff --no-color --no-ext-diff --no-textconv base...head" c_bdiff
1379+ino=$(stat -c '%i %Y %s' "$PD/$IBUND"); c=$(raw "$R/patches/$IBUND.diff" "$T/raw2")
1380+[ "$c" = 200 ] && cmp -s "$T/raw2" "$T/oracle.bund" && [ "$(stat -c '%i %Y %s' "$PD/$IBUND")" = "$ino" ] && [ "$(tmpleft)" = 0 ] && [ "$(pdstaged)" = 0 ] \
1381+ && ok "the second .diff request: the same bytes, the cache file untouched, no work folder in <data>tmp, nothing staged" || bad "second .diff request ($c, work $(tmpleft))"
1382+ictl "the second .diff request is served from the cache file (its bytes changed under the forge are what comes back)" c_cache
1383+ictl "TWIN with the cache file removed the diff is made again: served, kept as the cache file, no work folder, nothing staged" c_bdtmp
1384+c=$(raw "$R/patches/$ICCLOSED.diff" "$T/raw"); cmp -s "$T/raw" "$T/oracle.cclosed" && [ "$c" = 200 ] && ok "GET .diff of the code-only bundle item is git's base...head diff" || bad ".diff of the code-only bundle item ($c)"
1385+c=$(raw "$R/patches/$IMNOTR.diff" "$T/raw"); cmp -s "$T/raw" "$T/oracle.notr" && [ "$c" = 200 ] && ok "GET .diff of the merged bundle item is git's base...head diff" || bad ".diff of the merged bundle item ($c)"
1386+check "$(ls -A "$IMPD/$IBUND" | tr '\n' ' ')" "base description gh head head.bundle labels source.json statement status thread title " "the bundle item's folder holds the importer's files only (the cache is outside it)"
1387+ictl "NEG bundle whose base is not in the store: .diff 404, the page says why, no work folder, no cache file" c_basens
1388+check "$(jf "$IBNS" "d['base_commit'] is not None, d['diff'], d['diff_unavailable'], d['bundle'] is not None")" "True None base-not-in-store True" "bundle whose base is not in the store: the document names base and bundle; diff is null and diff_unavailable says base-not-in-store"
1389+ictl "NEG bundle of the head alone: .diff 404" c_nobase
1390+ictl "NEG bundle of the head alone: base_commit and diff null in the document" c_jnobase
1391+ictl "NEG code-only on main: .diff, .patch and .bundle 404; code none, the links null, 0 bytes, base = head" c_onmain
1392+ictl "NEG a bundle diff over 16 MiB: .diff 404, the page says so, not cached, no work folder, the marker left" c_big
1393+ictl "the marker of a diff over 16 MiB: .diff 404 before and after it; made once by the request that ran git, the second runs none and changes nothing" c_marker
1394+check "$(pdfiles)" "$PDWANT" "the cache folder after those two requests: the three cache files and the marker, nothing else"
1395+ictl "a marker that is already there is left as it is (inode, time, its one byte) and answers .diff and the page" c_markerkeep
1396+ictl "four first requests of the diff over 16 MiB at once: each 404, one empty marker, nothing else left" c_markerpar
1397+ictl "NEG a marker beside a small bundle: .diff 404 and no cache file made, too large on the page and in the documents; TWIN without it the diff is made" c_markersmall
1398+ictl "TWIN diff is a link and diff_unavailable null (document and list row): a signed patch, an imported mbox, a bundle with its base in the store" c_dunlink
1399+ictl "TWIN an mbox item whose base is not in the git store keeps its diff link" c_dunmbox
1400+ictl "NEG no code file (on main, and not on main): diff null, diff_unavailable no-code-file (document and list row)" c_dunnocode
1401+ictl "NEG a bundle of the head alone: diff null, diff_unavailable no-base" c_dunnobase
1402+ictl "NEG a bundle whose base is not in the git store: diff null, diff_unavailable base-not-in-store" c_dunbns
1403+ictl "TWIN the same item with a cache file planted: a link (the cache file is asked before git)" c_duncache
1404+ictl "NEG a diff over 16 MiB: a link until the first attempt, then diff null and too-large (document and list row)" c_duntoolarge
1405+ictl "a forge without a cache folder still leaves the marker of its first diff over 16 MiB" c_bigfresh
1406+for i in XSTATCAP XSTATNOLF XHEADSHORT XSRCSHORT XSRCNONE XBOTH; do
1407+ check "$(code GET "$R/patches/${!i}.patch") $(code GET "$R/patches/${!i}.diff") $(code GET "$R/patches/${!i}.bundle")" "404 404 404" "NEG the raw routes of $i"
1408+done
1409+check "$(code GET "$R/patches/$IBUND.bundlex") $(code GET "$R/patches/$IBUND.bundle/") $(code GET "$R/patches/$IBUND.zip")" "404 404 404" "NEG other suffixes after an id"
1410+alive && ok "forged is still running after the raw routes and the oversized diff" || { bad "forged ended in the raw routes"; start; }
1411+[ "$(imphash)" = "$H0" ] && ok "every file of every imported fixture folder and the index are unchanged by all the reads" || bad "the reads changed the store"
1412+
1413+echo "== imported proposals: no POST writes one (SPEC-ext section 5)"
1414+newkey ki; signin ki 10.1.0.40 || exit 1
1415+wpost() { code "$1" "$R$2" -H "X-Real-IP: $IP" -H "Cookie: __Host-forge_session=$SES" --data-urlencode "csrf=$TOK" --data-urlencode "status=closed" --data-urlencode "title=changed" --data-urlencode "body=changed"; }
1416+n=0; m=0
1417+for i in "$IOPEN" "$IBUND" "$ICMAIN" "$XSTATUS"; do
1418+ for s in "" .patch .diff .bundle /compose /status /close /merge /comment /edit /delete /new /; do
1419+ n=$((n+1)); c=$(wpost POST "/patches/$i$s"); case $c in 405|404) ;; *) m=$((m+1)); echo " POST /patches/$i$s answered $c";; esac
1420+ done
1421+done
1422+check "$m" 0 "NEG POST to an imported id and 12 paths under it (4 items, $n requests, signed in, valid CSRF token): each 405 or 404"
1423+n=0; m=0
1424+for s in "" / /import /new/ /new/x /new.patch /newer /0123456789abcdef; do
1425+ n=$((n+1)); c=$(wpost POST "/patches$s"); case $c in 405|404) ;; *) m=$((m+1)); echo " POST /patches$s answered $c";; esac
1426+done
1427+check "$m" 0 "NEG POST to $n other paths under /patches that are not /patches/new: each 405 or 404"
1428+n=0; m=0
1429+for me in PUT DELETE PATCH; do for s in "/$IOPEN" "/$IOPEN.patch" "/$IBUND.bundle" /new ""; do
1430+ n=$((n+1)); c=$(wpost $me "/patches$s"); [ "$c" = 405 ] || { m=$((m+1)); echo " $me /patches$s answered $c"; }
1431+done; done
1432+check "$m" 0 "NEG PUT, DELETE and PATCH on the patch routes ($n requests): each 405"
1433+[ "$(imphash)" = "$H0" ] && [ "$(tmpleft)" = 0 ] && [ "$(staged)" = 0 ] && alive && ok "after them every file of every imported fixture folder and the index are unchanged, nothing staged, forged running" || bad "a POST changed the store"
1434+std; pos "TWIN the same session and token on POST /patches/new"
1435+
1436+echo "== the id guard of POST /patches/new (SPEC-ext section 5)"
1437+# collide KIND: a new signed upload is prepared (its id CID is the first 16 hex of its statement's SHA-256) and,
1438+# before it is sent, an item folder is planted under CID with its index line: imported (an imported item, whose
1439+# statement is another text), longer (the upload's own statement and one more line), samelen (the upload's
1440+# statement with its last digit changed). CH is the hash of that folder and the index before the upload.
1441+collide() {
1442+ std; CID=$(sha < "$T/stmt" | cut -c1-16); NC=$((${NC:-900} + 1)); impnew "$NC" "$MAIN" open "$A"
1443+ mv "$I" "$IMPD/$CID"; sed -i "s/^$IID\$/$CID/" "$IMPD/index"; I=$IMPD/$CID
1444+ case $1 in
1445+ longer) { cat "$T/stmt"; printf 'one more line\n'; } > "$I/statement";;
1446+ samelen) sed '$ s/.$/g/' "$T/stmt" > "$I/statement"; [ "$(stat -c %s "$I/statement")" = "$(stat -c %s "$T/stmt")" ] && ! cmp -s "$I/statement" "$T/stmt" || bad "FIXTURE: the changed statement";;
1447+ esac
1448+ CH=$(cd "$IMPD" && { find "$CID" -type f | sort | xargs sha256sum; sha256sum index; ls -a; } | sha256sum)
1449+}
1450+unchanged() { [ "$(cd "$IMPD" && { find "$CID" -type f | sort | xargs sha256sum; sha256sum index; ls -a; } | sha256sum)" = "$CH" ]; }
1451+n_collide() { collide imported; KEPT=$(kept); C=$(upload); WANT=409; WHY="another item of this store holds this patch id"; }
1452+n_collide_longer() { collide longer; KEPT=$(kept); C=$(upload); WANT=409; WHY="another item of this store holds this patch id"; }
1453+n_collide_samelen() { collide samelen; KEPT=$(kept); C=$(upload); WANT=409; WHY="another item of this store holds this patch id"; }
1454+for k in "n_collide|an imported item" "n_collide_longer|an item whose statement starts with the upload's and is longer" "n_collide_samelen|an item whose statement differs in its last digit"; do
1455+ "${k%%|*}"
1456+ if isref "$WANT" "$WHY" && unchanged && [ "$(grep -c "^$CID\$" "$IMPD/index")" = 1 ]; then ok "NEG upload whose id folder holds ${k#*|}: 409 \"$WHY\", folder, index and store unchanged"
1457+ else bad "NEG id guard (${k#*|}): got $C \"$(head -c 160 "$T/body" | tr '\n' ' ')\" kept $(kept) (was $KEPT)"; fi
1458+ c=$(code GET "$R/patches/$CID"); grep -qF 'Imported from GitHub' "$T/body" && [ "$c" = 200 ] && ok "the id still shows the item that held it" || bad "the page of the held id ($c)"
1459+done
1460+std; pos "TWIN the same kind of upload with a free id"
1461+KEPT=$(kept); C=$(upload)
1462+[ "$C" = 200 ] && [ "$(head -1 "$T/body")" = exists ] && [ "$(newid)" = "$ID" ] && [ "$(kept)" = "$KEPT" ] && [ "$(staged)" = 0 ] && [ "$(tmpleft)" = 0 ] && [ "$(grep -c "^$ID\$" "$IMPD/index")" = 1 ] \
1463+ && ok "TWIN the true replay of that accepted upload: 200 exists with its id, nothing new kept, one index line" || bad "replay after the id guard: $C \"$(head -c 120 "$T/body" | tr '\n' ' ')\""
1464+alive && ok "forged is still running after the imported part" || { bad "forged ended"; start; }
1465+
1466+echo "== restart"
1467+TOTAL=$(statesnow); stop; start
1468+c_states; check "$C" "$TOTAL" "after a restart the list still counts every item that loads, by state, and the damaged lines"
1469+cmp -s <(curl -s "$B$R/patches/$FIRST.patch") "$FIRSTMB" && ok "after a restart the first patch's raw route is unchanged" || bad "raw route after restart"
1470+stop
1471+
1472+echo "== mutants: one guard removed each; the named control must fail"
1473+# kill1 NAME FUNCTION SED...: a mutant that still refuses the control exactly as the real forge does survives. Each
1474+# mutant gets two fresh keys (a key's sign-ins are logged writes, replayed at every start): ma signs in twice, so
1475+# OLDTOK is its first session's token, stale after the second; mb's session gives the foreign token and SESA/TOKA.
1476+# A control that meets the write gate (429) instead of the guard shows nothing and fails the run.
1477+KILLED=0; SURV=0; M=0
1478+kill1() {
1479+ name=$1; fn=$2; shift 2
1480+ mutant "$name" "$@"
1481+ start "$T/forged.$name"
1482+ M=$((M+1)); newkey ma$M; newkey mb$M
1483+ if signin ma$M 10.2.$M.1 > /dev/null && OLDTOK=$TOK && signin mb$M 10.3.$M.1 > /dev/null && TOK2=$TOK && SESA=$SES && TOKA=$TOK \
1484+ && signin ma$M 10.2.$M.1 > /dev/null; then :; else bad "mutant $name: sign-in"; stop; return; fi
1485+ KEPT=$(kept); "$fn"
1486+ if isref "$WANT" "$WHY"; then SURV=$((SURV+1)); bad "MUTANT $name SURVIVED: $fn still answers $C \"$WHY\""
1487+ elif [ "$C" = 429 ] && [ "$WANT" != 429 ]; then bad "MUTANT $name VOID: $fn met the write gate (429), which shows nothing about the guard"
1488+ else KILLED=$((KILLED+1)); if alive; then a=running; else kill "$PID" 2>/dev/null; wait "$PID"; a="gone, status $? (143: hung and killed here)"; PID=; fi
1489+ ok "mutant $name killed by $fn: got $C \"$(head -c 90 "$T/body" | tr '\n' ' ')\" (forged $a)"; fi
1490+ stop
1491+}
1492+p_first() { fresh w; mkmbox "$T/w" origin/main; TITLE="Mutant $N"; DESC=; sigmake; C=$(upload); WANT=201; WHY=; }
1493+p_accept() { p_first; if [ "$C" = 201 ] && [ "$(tmpleft)" = 0 ] && [ "$(staged)" = 0 ]; then C=ok; fi; WANT=ok; KEPT=$(kept); }
1494+n_replay2() { p_first; C=$(upload); KEPT=$(kept); if [ "$C" = 200 ] && [ "$(head -1 "$T/body")" = exists ]; then C=ok; fi; WANT=ok; WHY=; }
1495+WP='/^fn sowpre to long$/,/^fn sosetname to long$/'
1496+kill1 session n_unsigned '/^fn pagate to long$/,/^fn paunl to long$/s/^if eq get gscur 0 0$/if eq get gscur 0 99999999/'
1497+kill1 gate n_csrf_foreign '/^fn pagate to long$/,/^fn paunl to long$/s/^r = sowpre$/r = long 0/'
1498+kill1 csrf-stale n_csrf_stale "${WP}s/^if not socsrfok\$/if false/"
1499+kill1 csrf-foreign n_csrf_foreign "${WP}s/^if not socsrfok\$/if false/"
1500+kill1 ipcount n_perip "${WP}s/^if not fratelim\$/if false/"
1501+kill1 keylimit n_perkey "${WP}s/^if not sordok get gscur 0\$/if false/"
1502+kill1 keycount n_perkey '/^fn pagate to long$/,/^fn paunl to long$/s/^soratev get gscur 0 get gsnow 0$/r = long 0/'
1503+kill1 base-unknown n_base_unknown 's/^ret parefu 422 tpmunk$/r = long 0/'
1504+kill1 base-main n_base_side 's/^ret parefu 422 tpmnotm$/ret 0/'
1505+kill1 commits n_commits_101 's/^if gt get gpncm 0 100$/if gt get gpncm 0 100000/'
1506+kill1 mbox-size n_mbox_big '/^fn pambdec to ulong$/,/^fn pasigin to bool$/s/^if gt n 2796203$/if gt n 9999999/'
1507+kill1 signature n_sig_forged '/^fn pasigck to long$/,/^fn pastem to bool$/s/^r = pasigrun$/r = long 0/'
1508+kill1 signature-text n_sig_other_text '/^fn pasigck to long$/,/^fn pastem to bool$/s/^r = pasigrun$/r = long 0/'
1509+# the key binding alone: ssh-keygen -Y check-novalidate still checks the signature and its namespace but takes any
1510+# key (it ignores -f and -I), so only the control signed by another key can see it
1511+kill1 signature-key n_sig_other_key -e '/^fn pasigrun to long$/i text tpnoval "check-novalidate"' -e '/^fn pasigrun to long$/,/^fn pasigck to long$/s/^soava tsverify$/soava tpnoval/'
1512+kill1 namespace p_accept '/^fn pasigrun to long$/,/^fn pasigck to long$/s/^soava tpns$/soava tsns/'
1513+kill1 apply n_noapply 's/^ret parefu 422 tpmappl$/r = long 0/'
1514+kill1 copy-mail n_copy_encoded '/^fn pamread /,/^fn pamail /s/^if pafxcpy$/if false/'
1515+kill1 path n_path_out '/^fn pascan to bool$/,/^fn pabasec to long$/s/^g = 3$/g = 0/'
1516+kill1 path-empty n_path_abs '/^fn paout /,/^fn padiffl /s/^if eq get gpmb add j 1 47$/if false/'
1517+kill1 path-rename n_path_rename '/^fn padiffl /,/^fn pascan to bool$/s/^ret 3$/ret 0/'
1518+kill1 binary n_binary_noapply '/^fn padiffl /,/^fn pascan to bool$/s/^ret 2$/ret 0/'
1519+# binary-git: numstat alone is no longer the only check after the apply: the byte check of the combined diff
1520+# sees the "Binary files" line of the same file, so this mutant removes both layers after the apply (numstat
1521+# and bytes) and is killed by the base64 control, which the early scan cannot see
1522+kill1 binary-git n_binary_b64 -e '/^fn paapply3 to long$/,/^fn pamkst to bool$/s/^if pabinns$/if false/' -e '/^fn paapply3 to long$/,/^fn pamkst to bool$/s/^if pabinfx$/if false/'
1523+# binary-bytes: only the new byte check removed. Killed by n_binary_late (git's numstat calls that file text);
1524+# n_binary_attr is still refused by numstat under this mutant, since the attributes are not read
1525+kill1 binary-bytes n_binary_late '/^fn paapply3 to long$/,/^fn pamkst to bool$/s/^if pabinfx$/if false/'
1526+# attr-source: pakwt without --attr-source=<empty tree>: the patch's "*.txt -diff" makes numstat mark its text
1527+# file binary, so the attribute positive is refused (n_binary_attr is still refused then, by the byte check)
1528+kill1 attr-source p_attr_text '/^fn pakwt to void$/,/^end$/{/^fka tpatsrc$/d}'
1529+kill1 submodule n_submodule 's/^ret parefu 422 tpmsub$/r = long 0/'
1530+kill1 title n_title_lines '/^fn patitle to bool$/,/^fn padescr to bool$/s/^if not pawutf8 ulong n false$/if false/'
1531+kill1 description n_desc_ctl '/^fn padescr to bool$/,/^fn pab64v /s/^if not pawutf8 ulong n true$/if false/'
1532+kill1 repo-field n_repo_field '/^fn patake to long$/,$s/^if not parepok$/if false/'
1533+kill1 replay n_replay2 '/^fn patake to long$/,$s/^if paexist$/if false/'
1534+kill1 work-folder p_accept '/^fn paapply to long$/,/^fn pasizes to long$/s/^if not parmtree$/if false/'
1535+# ---- mutants of the imported reader and of the id guard (SPEC-ext sections 1 to 5). First one mutant per guard
1536+# NOTES-A lists, then the guards of the new code it does not list. kill2 NAME CONTROL SED...: CONTROL is a control
1537+# of the imported part above, where it gave C = WANT on the real forge; under the mutant it must give something
1538+# else. The store still holds every fixture. The three id-guard mutants are uploads and go through kill1.
1539+kill2() {
1540+ name=$1; fn=$2; shift 2
1541+ mutant "$name" "$@"; start "$T/forged.$name"
1542+ eval "$fn"
1543+ if [ "$C" = "$WANT" ]; then SURV=$((SURV+1)); bad "MUTANT $name SURVIVED: $fn still gives \"$(printf '%s' "$C" | head -c 120 | tr '\n' ' ')\""
1544+ else KILLED=$((KILLED+1)); if alive; then a=running; else a=gone; fi
1545+ ok "mutant $name killed by $fn: got \"$(printf '%s' "$C" | head -c 120 | tr '\n' ' ')\", want \"$(printf '%s' "$WANT" | head -c 90 | tr '\n' ' ')\" (forged $a)"; fi
1546+ stop; rm -rf "$T/data/patch-work"/pw* 2>/dev/null; rm -f "$PD/$XDIFF" "$PD"/.new-* 2>/dev/null; [ ! -f "$T/index.keep" ] || { mv "$T/index.keep" "$IMPD/index"; bad "mutant $name: a control left the index changed (put back here)"; }
1547+}
1548+IL='/^fn paiload to bool$/,/^fn pathld to void$/'; L40='/^fn pal40 to bool$/,/^fn palnis /'; QS='/^fn paqst to ulong$/,/^fn pastcnt /'
1549+RC='/^fn patrec p ulong to ulong$/,/^fn patcnt to ulong$/'; BD='/^fn pabdiff to ulong$/,/^fn pabraw to long$/'; BR='/^fn pabraw to long$/,/^fn pafp /'
1550+RW='/^fn paraws w ulong to long$/,/^fn pajhead /'
1551+# -- the guards of NOTES-A
1552+kill2 imp-src c_src "${IL}s/^if ne get fxo i get tpsjpre i\$/if false/"
1553+kill2 imp-status c_status "${IL}s/^if gt s 2\$/if false/"
1554+kill2 imp-head c_head "${IL}s/^if not pal40\$/if false/"
1555+kill2 imp-hex40 c_head "${L40}s/^if lt sohexv get gpln i 0\$/if false/"
1556+# (no list-status mutant: the status check it removed from paqst was redundant with pastrd and pastcnt, see list-state3, and is gone from the forge)
1557+# (no list-head and list-src mutants: the file-peeking paqst they edited is gone; paqst is the page loader now, see list-load below)
1558+kill2 thread-word 'thrctl $XTWORD' '/^fn patword a ulong to void$/,/^fn patnum t uchar to ulong$/s/^if ge sub q p 256$/if false/'
1559+kill2 thread-digits 'thrctl $XTDIGITS' '/^fn patnum t uchar to ulong$/,/^fn patis /s/^if ge k 18$/if false/'
1560+kill2 thread-header 'thrctl $XTNOLEN' "${RC}s/^if ne get gpbad 0 0\$/if false/"
1561+kill2 thread-pathlen 'thrctl $XTPATHBIG' "${RC}s/^if or gt m 4096 ge add q m n\$/if false/"
1562+kill2 thread-pathlf 'thrctl $XTPATHLF' "${RC}s/^if ne get gpth add q m 10\$/if false/"
1563+kill2 thread-past 'thrctl $XTPAST' "${RC}s/^if ge add q b n\$/if false/"
1564+kill2 thread-bodylf 'thrctl $XTBODYLF' "${RC}s/^if ne get gpth add q b 10\$/if false/"
1565+kill2 thread-time 'thrctl $XTTIME' "${RC}s/^if not pattok\$/if false/"
1566+kill2 thread-kind 'thrctl $XTKIND' '/^fn patkind to ulong$/,/^fn pattok to bool$/s/^ret 0$/ret 1/'
1567+kill2 thread-stop 'thrctl $XTKIND' '/^fn paithr to void$/,/^fn paiapply to void$/s/^if eq get gpr 0 0$/if false/'
1568+kill2 page-budget c_pgcut '/^fn papgfit /,/^fn paidesc to void$/s/^if and le get fobl 0 PAPGMX eq get fobtr 0 t0$/if true/'
1569+kill2 bdiff-base c_basens "${BD}s/^if ne r 0\$/if false/"
1570+kill2 bdiff-workdir c_bdtmp "${BD}s/^if not parmtree\$/if false/"
1571+kill2 bdiff-16m c_big '/^fn pabrun to ulong$/,/^fn pabdiff to ulong$/s/^if ne get fxotr 0 0$/if false/'
1572+kill2 diff-nobase c_nobase "${BR}s/^if eq get gpihb 0 0\$/if false/"
1573+kill2 diff-onmain c_onmain "${BR}s/^if ne get gpicode 0 2\$/if false/"
1574+kill2 raw-load c_rawbad "${RW}s/^if not paiload\$/if false/"
1575+kill1 id-guard n_collide '/^fn patake to long$/,$s/^if not pasteq$/if false/'
1576+kill1 id-guard-length n_collide_longer '/^fn pasteq to bool$/,/^fn pahex40 to bool$/s/^if ne n long get gpstl 0$/if false/'
1577+kill1 id-guard-bytes n_collide_samelen '/^fn pasteq to bool$/,/^fn pahex40 to bool$/s/^if ne get fxo i get gpst i$/if false/'
1578+kill2 json-nobase c_jnobase '/^fn pajsha w ulong to void$/,/^fn pajcnts /s/^if eq get gpihb 0 0$/if false/'
1579+kill2 json-nodiff c_jnobase '/^fn pajlinks to void$/,/^fn pajgh /s/^d = or eq k 1 and eq k 2 ne get gpihb 0 0$/d = or eq k 1 eq k 2/'
1580+# -- guards of the new code that NOTES-A does not list
1581+kill2 imp-srclen c_srcshort "${IL}s/^if lt n len tpsjpre\$/if false/"
1582+kill2 imp-len41 c_headlong "${L40}s/^if ne get gplnl 0 41\$/if false/"
1583+kill2 imp-lf41 c_headnolf "${L40}s/^ret eq get gpln 40 10\$/ret true/"
1584+kill2 imp-metafirst c_both '/^fn paany to bool$/,/^fn paqst to ulong$/s/^if e$/if false/'
1585+kill2 imp-derived c_derived "${IL}s/^if lt pasjf tpsjder n\$/if false/"
1586+kill2 imp-titlecap c_title '/^fn paiload2 to bool$/,/^fn paiload to bool$/s/^n = pafrd tpftt 1024$/n = pafrd tpftt 2048/'
1587+kill2 list-state3 c_states '/^fn pastcnt tot ulong to void$/,/^fn paidrow /s/^if lt s 3$/if true/'
1588+kill2 raw-kind c_patchbund "${RW}s/^if ne w 1\$/if false/"
1589+kill2 bdiff-cache c_cache "${BD}s/^if e\$/if false/"
1590+kill2 bdiff-threedot c_bdiff 's/^text tpdots3 "\.\.\."$/text tpdots3 ".."/'
1591+kill2 json-dash c_jdash '/^fn pajgh t view uchar \* to void$/,/^fn pajsv /s/^if eq get gpgh o 45$/if false/'
1592+kill2 json-state c_jdash '/^fn pajcom to void$/,/^fn pajtr /s/^if patis 5 tpdash$/if false/'
1593+# -- the guards of NOTES-G (findings round): the list
1594+PL='/^fn palist to long$/,/^fn paorig to void$/'; JL='/^fn pajlist /,$'
1595+kill2 list-load c_states "${QS}s/^if not paany\$/if false/"
1596+kill2 list-idline c_dmg3 '/^fn pastcnt tot ulong to void$/,/^fn paidrow /s/^if paidrow mul r 17$/if true/'
1597+kill2 list-dmgzero c_dmg0 "${PL}s/^if gt dmg 0\$/if true/"
1598+kill2 list-dmgone c_dmg1 '/^fn padmg n ulong to void$/,/^fn palist to long$/s/^if eq n 1$/if false/'
1599+kill2 list-dmgcalc c_dmg1 "${PL}s/^dmg = sub tot lst\$/dmg = tot/"
1600+kill2 list-hcount c_dmg1 "${PL}s/^fnum lst\$/fnum tot/"
1601+kill2 list-hsingular c_dmg0 "${PL}s/^if eq lst 1\$/if false/"
1602+kill2 list-jcount c_states "${JL}s/^fnum lst\$/fnum add lst dmg/"
1603+kill2 list-jdamaged c_states "${JL}s/^fnum dmg\$/fnum sub dmg dmg/"
1604+# -- diff_unavailable and the marker
1605+LK='/^fn pajlinks to void$/,/^fn pajgh /'; DU='/^fn pajdun to ulong$/,/^fn pajduw /'; ST='/^fn pabst to ulong$/,/^fn pabkeep to ulong$/'
1606+kill2 dun-mbox c_dunmbox "${LK}{/^if d\$/,/^u = pajdun\$/s/^if eq k 2\$/if true/;}"
1607+kill2 dun-nocode c_dunnocode "${LK}s/^if eq k 0\$/if false/"
1608+kill2 dun-cache c_duncache "${DU}s/^if eq w 0\$/if false/"
1609+kill2 dun-marker c_duntoolarge "${DU}s/^if eq w 2\$/if false/"
1610+kill2 dun-catfile c_dunbns "${DU}s/^if gt r 0\$/if false/"
1611+kill2 bst-cache c_duncache '/^fn pabst to ulong$/,/^ret 0$/s/^if paexist$/if false/'
1612+kill2 bst-marker c_duntoolarge "${ST}{/^papdfg\$/,/^ret 2\$/s/^if paexist\$/if false/;}"
1613+kill2 bdiff-markerfirst c_markersmall "${BD}s/^if paexist\$/if false/"
1614+kill2 big-marker c_big "${BD}s/^if eq w 2\$/if false/"
1615+kill2 big-mkdir c_bigfresh '/^fn pabbig to void$/,/^fn pabst to ulong$/s/^if not pamkpd$/if false/'
1616+# -- thread_truncated and the document budget
1617+JC='/^fn pajcoms to void$/,/^fn pajcom to void$/'
1618+kill2 json-threadstop 'thrctl $XTKIND' "${JC}s/^if eq get gpr 0 0\$/if false/"
1619+kill2 trunc-malformed c_trunc "${JC}s/^w = 1\$/w = 0/"
1620+kill2 trunc-large c_trunclarge "${JC}s/^if ne get gpthc 0 0\$/if false/"
1621+kill2 trunc-rank c_docbudget "${JC}s/^if ne w 3\$/if true/"
1622+kill2 trunc-bool c_trunc 's/^fybool ne t 0$/fybool false/'
1623+kill2 budget-fit c_docbudget "${JC}s/^if not pajfit f0 t0\$/if false/"
1624+kill2 budget-limit c_docbudget '/^fn pajfit /,/^fn pajcoms to void$/s/^if and le get fobl 0 PAJMX eq get fobtr 0 t0$/if true/'
1625+kill2 budget-size c_descbud 's/^const PAJMX ulong 8323072$/const PAJMX ulong 8388608/'
1626+# -- round 2 of the forge (ad6f85d)
1627+kill2 prov-nologin c_nologin '/^fn paprov to void$/,/^fn pabadge to void$/s/^if eq get gpr 15 0$/if false/'
1628+OM='/^fn paonmn to bool$/,/^fn paicode to void$/'
1629+kill2 onmain-derived 'nocode $XNCMETA' "${OM}s/^if eq get gpider 0 0\$/if false/"
1630+kill2 onmain-merged 'nocode $XNCOPEN' "${OM}s/^if ne get gpist 0 2\$/if false/"
1631+kill2 onmain-base c_ncnobase "${OM}s/^if eq get gpihb 0 0\$/if false/"
1632+kill2 onmain-equal 'nocode $XNCBASE' "${OM}s/^if ne get gpbase i get gphead i\$/if false/"
1633+kill2 onmain-route c_onmainpg "${OM}s/^ret true\$/ret false/"
1634+kill2 prov-codeonly c_provcode '/^fn paprov to void$/,/^fn pabadge to void$/s/^if ne get gpider 0 0$/if false/'
1635+kill2 esc-login c_esclogin '/^fn paghp t view uchar \* to void$/,/^fn pasjp /s/^fescc get gpgh add o i$/fputc get gpgh add o i/'
1636+kill2 esc-thread c_escthread '/^fn patraw a ulong to void$/,/^fn pattime to void$/s/^fescc get gpth add o i$/fputc get gpth add o i/'
1637+kill2 esc-label c_esclabel '/^fn pailabs to void$/,/^fn parchsp /s/^fescc c$/fputc c/'
1638+echo "mutants killed $KILLED, survived $SURV"
1639+rm -rf "$T/data/patch-work"/pw* 2>/dev/null
1640+
1641+echo "PATCH TESTS: pass=$PASS fail=$FAIL mutants_killed=$KILLED mutants_survived=$SURV"
1642+[ "$FAIL" = 0 ] && [ "$SURV" = 0 ]

research/build.om

@@ -1580,7 +1580,7 @@ text madid "did:key:z"
15801580 text marad "rad:z"
15811581 text mazen "https://zenodo.org/records/"
15821582 text maself "drakestapleton"
1583-text mafoot "</main><footer class='foot'><p>DOIs are minted by Zenodo. The research registry records the source and the Radicle key that requested or brought each record; that key gains no ownership and is not shown to be an author. No scripts run on this page.</p><p><a href='/research.json'>JSON</a><a href='/research.bib'>BibTeX</a><a href='/research.txt'>Guide for agents</a></p></footer></body></html>\n"
1583+text mafoot "</main><footer class='foot'><p>DOIs are minted by Zenodo. The research registry records the source and the key that requested or brought each record; that key gains no ownership and is not shown to be an author. No scripts run on this page.</p><p><a href='/research.json'>JSON</a><a href='/research.bib'>BibTeX</a><a href='/research.txt'>Guide for agents</a></p></footer></body></html>\n"
15841584 text mahero "<section class='hero'><p class='eyebrow'>Research</p><h1>Ask the research.</h1><p class='sub'>Published work, connected by its sources. The agent answers from the open full text in this collection and names the papers it used. Some records contain metadata only.</p><p class='acts'><a class='btn' href='/research/add'>Add your work</a><a class='btn ghost' href='/research/doi'>Get a DOI</a></p>"
15851585 text maas "<section class='card'><h2>Authors</h2><ul class='edges'>"
15861586 text maalink "<li><a href='/research/authors/"
@@ -1589,21 +1589,23 @@ text maend "</ol></section>\n"
15891589 text mauhead "<section class='card'><p class='eyebrow'>Author</p><h1>"
15901590 text mauid "</h1><p class='meta'>Author ID: "
15911591 text maun "</p><p class='meta'>Added by "
1592-text maureq "</p><p class='meta'>Requester: Radicle key "
1592+text maureq "</p><p class='meta'>Requester: key "
15931593 text mauvia ". Source: "
15941594 text maucheck ". Checked: "
15951595 text mauclose "</p></section>\n"
15961596 text mabyline "<p class='by'><a href='/research/authors/"
15971597 text maprov "<section class='card'><h2>Source</h2><p>Added through "
1598-text mapkey " by Radicle key "
1598+text mapkey " by key "
1599+note mashelf: records whose source is the retired network (field "radicle") came through the shelf
1600+text mashelf "the shelf"
15991601 text maprovz "<section class='card'><h2>Source</h2><p>Public metadata from "
1600-text mapreq ". Requester: Radicle key "
1602+text mapreq ". Requester: key "
16011603 text mapdate ". Checked "
16021604 text mapsrc ". Source: "
16031605 text maptext "</p><p>Open full text may be included in the agent corpus.</p></section>\n"
16041606 text mapmeta "<section class='card'><p>Metadata only. The agent does not use this work as full-text evidence.</p></section>\n"
1605-text mazdisc "<section class='card'><h2>Zenodo records</h2><p>Zenodo records listed here are public metadata, requested by a Radicle key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to the person named on this page.</p></section>\n"
1606-text mazwork "<section class='card'><h2>Zenodo record</h2><p>This Zenodo record is public metadata, requested by a Radicle key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to a person named on this page.</p></section>\n"
1607+text mazdisc "<section class='card'><h2>Zenodo records</h2><p>Zenodo records listed here are public metadata, requested by a key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to the person named on this page.</p></section>\n"
1608+text mazwork "<section class='card'><h2>Zenodo record</h2><p>This Zenodo record is public metadata, requested by a key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to a person named on this page.</p></section>\n"
16071609 text mapttl "<article class='work'><p class='eyebrow'><a href='/research'>Research</a></p><h1>"
16081610 text mapacts "</p><p class='acts'><a class='btn ghost' href='/research/"
16091611 text mapdoi "<p class='acts'><a class='btn' href='https://doi.org/"
@@ -1612,7 +1614,7 @@ text mapclose "</a></p>"
16121614 text maplead "<p class='lead'>"
16131615 text mapp "</p>"
16141616 text maquote "> "
1615-text maadd "<section class='hero'><p class='eyebrow'>Research</p><h1>Add your work</h1><p class='sub'>Sign in with your Radicle key, then add an ORCID iD or a repository you brought to the shelf.</p><p><a class='btn' href='/research/add/'>Open the submission form</a></p></section><section class='card'><h2>From Zenodo</h2><p>Give an ORCID iD. The sync worker checks public Zenodo records whose creators name that iD. The records are public metadata, and the page labels the Radicle key that asked for them as the requester. Requesting gives that key no ownership, and an ORCID match is not proof that the key belongs to that person.</p></section><section class='card'><h2>From a repository</h2><p>Bring the repository to the shelf with your Radicle key. Include .zenodo.json, a license file, and paper.md, paper.txt or paper.pdf at its root. The worker checks the shelf entry and metadata before listing the work.</p></section><section class='card'><h2>What is shown</h2><p>The registry keeps the source, the Radicle key that requested or brought it and the check date. Requesting a record gives the key no ownership of it. Full text joins the question corpus only when its recorded license permits it. Metadata-only records can still have pages. The operator can remove a record, author or key, and a withdrawn shelf entry is removed on the next sync.</p></section>"
1617+text maadd "<section class='hero'><p class='eyebrow'>Research</p><h1>Add your work</h1><p class='sub'>Sign in with your key, then add an ORCID iD or a repository you brought to the shelf.</p><p><a class='btn' href='/research/add/'>Open the submission form</a></p></section><section class='card'><h2>From Zenodo</h2><p>Give an ORCID iD. The sync worker checks public Zenodo records whose creators name that iD. The records are public metadata, and the page labels the key that asked for them as the requester. Requesting gives that key no ownership, and an ORCID match is not proof that the key belongs to that person.</p></section><section class='card'><h2>From a repository</h2><p>Bringing a repository to the shelf is closed until Interplane's own store accepts it. Include .zenodo.json, a license file, and paper.md, paper.txt or paper.pdf at its root. The worker checks the shelf entry and metadata before listing the work.</p></section><section class='card'><h2>What is shown</h2><p>The registry keeps the source, the key that requested or brought it and the check date. Requesting a record gives the key no ownership of it. Full text joins the question corpus only when its recorded license permits it. Metadata-only records can still have pages. The operator can remove a record, author or key, and a withdrawn shelf entry is removed on the next sync.</p></section>"
16161618 text madoi "<section class='hero'><p class='eyebrow'>Research</p><h1>Get a DOI</h1><p class='sub'>Zenodo mints the DOI. The local tool prepares a draft; you decide whether to publish.</p></section><section class='card'><h2>Prepare a repository</h2><p>At its root, include a nonempty LICENSE file, a PDF, and .zenodo.json with title, creators (name for each), description, license, upload_type and publication_type. Check those fields and the paper before uploading. A repository that already has a DOI is refused to avoid a duplicate deposit.</p></section><section class='card'><h2>Run on your own machine</h2><p>From the Interplane forge repository root, run <code>sh tools/doi/build.sh</code>. Keep ZENODO_TOKEN in your local shell environment, outside the repository. Do not send it to Interplane.</p><p>Try the sandbox: <code>sh tools/doi/doi.sh /path/to/paper-repo</code>. To make a real deposit, use <code>sh tools/doi/doi.sh /path/to/paper-repo --production</code>. An optional <code>--source /path/to/source.tar.gz</code> uploads a source archive with the PDF.</p></section><section class='card'><h2>Review before publishing</h2><p>The tool creates a draft, prints the reserved DOI, adds it to .zenodo.json while preserving the other metadata, and uploads the files. Review the draft on <a href='https://zenodo.org/uploads'>Zenodo</a>. Only an exact <code>yes</code> at the local terminal publishes it. Another answer, or no terminal, leaves an unpublished draft. A reserved DOI is not a published record.</p></section><section class='card'><h2>Link the published work</h2><p>After publication, commit the updated metadata and <a href='/research/add'>add your work</a>. Interplane links the published record; it does not mint a second DOI.</p></section>"
16171619 text majas "],\"authors\":[{\"id\":\"drakestapleton\",\"name\":\""
16181620 text maju "{\"id\":\""
@@ -1995,7 +1997,12 @@ emwh p 2 16
19951997 em mapreq
19961998 else
19971999 em maprov
2000+a = wf p 2
2001+if feqt a fe a eol p mar
2002+em mashelf
2003+else
19982004 emwh p 2 16
2005+end
19992006 em mapkey
20002007 end
20012008 emwh p 3 128

research/intake-route.om

@@ -14,9 +14,8 @@ text rqzpre "10.5281/zenodo."
1414 text rqmsg "Give a repository ID, an ORCID iD or a Zenodo DOI. Links and files are not accepted here."
1515 text rqwait "The request is queued. Public metadata will be listed with the key that asked. A repository appears only after the open shelf accepts it. Not verified."
1616 text rqh "<section class=\"sl\"><h1>Add your work</h1><p>Bring a paper repository, sync public Zenodo records, or <a href=\"/research/doi\">get a DOI for your work</a>. <a href=\"/research/add\">Read the steps</a>.</p><p>A listing is not proof that a key belongs to an author. Public metadata and repository text are not verified. The operator can take a listing down by key or repository.</p>"
17-text rql "<p><a href=\"/login\">Sign in with your Radicle key</a> to add work.</p></section>"
18-text rqf1 "<h2>Bring a repository</h2><p>Publish from your machine with Radicle. Include .zenodo.json, a LICENSE file and paper.pdf, paper.md or paper.txt. This uses the open shelf intake, not an upload.</p><form method=\"post\" action=\"/research/add/\"><input type=\"hidden\" name=\"csrf\" value=\""
19-text rqf2 "\"><input type=\"hidden\" name=\"action\" value=\"bring\"><label>Radicle ID <input name=\"rid\" maxlength=\"48\" required placeholder=\"rad:z...\"></label><input type=\"hidden\" name=\"note\" value=\"Paper for research\"><label><input type=\"checkbox\" name=\"consent\" value=\"yes\" required>I have the right to share this project and it carries an open license.</label><button type=\"submit\">Bring it</button></form>"
17+text rql "<p><a href=\"/login\">Sign in with your key</a> to add work.</p></section>"
18+text rqf1 "<h2>Bring a repository</h2><p>Bringing new projects is closed until Interplane's own store accepts them.</p>"
2019 text rqf3 "<h2>Sync public records</h2><p>Give an ORCID iD, a Zenodo DOI, or both. A record is filed under an author only if that record carries the ORCID iD among its creators. This is a listing from public metadata by the key that asked, not an ORCID sign-in.</p><form method=\"post\" action=\"/research/add/\"><input type=\"hidden\" name=\"csrf\" value=\""
2120 text rqf4 "\"><input type=\"hidden\" name=\"action\" value=\"sync\"><label>ORCID iD <input name=\"orcid\" maxlength=\"19\" placeholder=\"0000-0000-0000-0000\"></label><label>Zenodo DOI <input name=\"doi\" maxlength=\"26\" placeholder=\"10.5281/zenodo.123456\"></label><button type=\"submit\">Sync records</button></form></section>"
2221 global rqo uchar 20
@@ -35,8 +34,6 @@ fput rql
3534 ret 200
3635 end
3736 fput rqf1
38-socsrfout
39-fput rqf2
4037 fput rqf3
4138 socsrfout
4239 fput rqf4
@@ -173,7 +170,7 @@ ret soerr 503 tomsgq
173170 end
174171 ret 0
175172 end
176-text rqpart "<section class=\"sl\"><h1>Shelf request accepted</h1><p>The shelf accepted this repository. Research indexing was not queued because storage changed after admission. The shelf retains the repository ID, the requesting key and the paper note. Retry the ID below at <a href=\"/research/add/\">Add your work</a>.</p><pre>rad:"
173+text rqpart "<section class=\"sl\"><h1>Shelf request accepted</h1><p>The shelf accepted this repository. Research indexing was not queued because storage changed after admission. The shelf retains the repository ID, the requesting key and the paper note. Retry the ID below at <a href=\"/research/add/\">Add your work</a>.</p><pre>"
177174 text rqp2 "</pre><p>This is a partial acceptance, not a claim that nothing was saved. The shelf listing is not verified.</p></section>"
178175 fn rqpartial to long
179176 put fobl 0 0

research/tests/authors.sh

@@ -79,14 +79,14 @@ for mode in add doi; do
7979 done
8080 # Requesters. A Zenodo record is public metadata that a Radicle key requested: the key gains no
8181 # ownership, is labelled Requester, and is never displayed as an author. Radicle keeps "Added through".
82-zdisc='Zenodo records listed here are public metadata, requested by a Radicle key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to the person named on this page.'
83-wdisc='This Zenodo record is public metadata, requested by a Radicle key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to a person named on this page.'
82+zdisc='Zenodo records listed here are public metadata, requested by a key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to the person named on this page.'
83+wdisc='This Zenodo record is public metadata, requested by a key. Requesting a record gives that key no ownership of the record or the work, and the registry makes no claim that the key belongs to a person named on this page.'
8484 # reqpage FILE DISCLAIMER KEY prints the first failed reason; a passing page prints nothing.
8585 reqpage() {
8686 grep -Fq "$2" "$1" || { echo 'Zenodo public-metadata disclaimer missing'; return; }
87- grep -Fq "Requester: Radicle key $3" "$1" || { echo "requester $3 not labelled"; return; }
87+ grep -Fq "Requester: key $3" "$1" || { echo "requester $3 not labelled"; return; }
8888 ! grep -Fq 'Added by' "$1" || { echo 'requester shown as Added by'; return; }
89- [ "$(grep -oF "$3" "$1" | wc -l)" = "$(grep -oF "Requester: Radicle key $3" "$1" | wc -l)" ] || { echo "requester $3 shown outside its label"; return; }
89+ [ "$(grep -oF "$3" "$1" | wc -l)" = "$(grep -oF "Requester: key $3" "$1" | wc -l)" ] || { echo "requester $3 shown outside its label"; return; }
9090 }
9191 reqfix() {
9292 printf 'O\tid\t%s\nO\tname\t%s\nO\torcid\t\nO\tadded-by\t%s\nO\tvia\tzenodo\nO\tchecked\t2026-11-11\n' "$1" "$2" "$3"
@@ -122,7 +122,7 @@ python3 -I -c 'import json,sys; [json.load(open(f, encoding="utf-8")) for f in s
122122 is "$(reqpage "$T/authors/alice.html" "$zdisc" did:key:zAlice)" '' 'Alice Zenodo author page labels requester and disclaims ownership'
123123 is "$(reqpage "$T/authors/work" "$wdisc" did:key:zAlice)" '' 'Alice Zenodo work page labels requester and disclaims ownership'
124124 gen work foreign-b "$ac" > "$T/authors/req-radicle.html"
125-grep -Fq 'Added through radicle by Radicle key did:key:zBob' "$T/authors/req-radicle.html" && ok 'Radicle work keeps its brought-by provenance' || bad 'Radicle provenance wording changed'
125+grep -Fq 'Added through the shelf by key did:key:zBob' "$T/authors/req-radicle.html" && ok 'shelf work keeps its brought-by provenance, without the retired network name' || bad 'shelf provenance wording changed'
126126 is "$(cat "$T/authors/bob.html" "$T/authors/req-radicle.html" | grep -c 'Zenodo record' || :)" 0 'Radicle pages carry no Zenodo disclaimer'
127127 grep -Fq '"requester":"did:key:zBob","requester_role":"brought the repository to the shelf; not verified"}' "$T/authors/index.json" && ok 'hub JSON keeps Radicle meaning: brought, not verified' || bad 'Radicle requester role wrong'
128128 # Negative control: a builder whose two disclaimers are blanked must fail the same oracle for that reason,

research/tests/intake.sh

@@ -51,7 +51,7 @@ immutable_before=$(genhash)
5151 [ "$(code GET /research/doi)" = 200 ] && grep -q 'Zenodo mints' "$T/body" && ok 'DOI help page is served' || bad 'DOI information route'
5252 [ "$(code GET /research/authors/../outside --path-as-is)" = 400 ] && ok 'author traversal refused by request parser' || bad 'author traversal'
5353 # Signed out: no key, no queue.
54-[ "$(code GET /research/add/)" = 200 ] && grep -q 'Sign in with your Radicle key' "$T/body" && ok 'sign-in page' || bad 'sign-in page'
54+[ "$(code GET /research/add/)" = 200 ] && grep -q 'Sign in with your key' "$T/body" && ok 'sign-in page' || bad 'sign-in page'
5555 [ "$(code POST /research/add/ --data 'action=sync&orcid=0009-0002-6890-7111&doi=')" = 303 ] && [ ! -e "$T/data/research/add/queue" ] && ok 'signed-out request writes nothing' || bad 'signed-out request'
5656 code GET /login > /dev/null
5757 PREN=$(hdr set-cookie | sed -n 's/^\([A-Za-z_-]*forge_pre\)=.*/\1/p'); PRE=$(hdr set-cookie | sed -n 's/^[^=]*=\([^;]*\).*/\1/p')
@@ -63,6 +63,7 @@ SES=$(hdr set-cookie | sed -n 's/^__Host-forge_session=\([^;]*\).*/\1/p'); CK="C
6363 code GET /research/add/ -H "$CK" > /dev/null
6464 TOK=$(field csrf)
6565 [ "${#TOK}" = 32 ] && ok 'shared CSRF form token' || bad 'csrf field'
66+grep -q "Bringing new projects is closed until Interplane's own store accepts them." "$T/body" && ! grep -q 'name="rid"' "$T/body" && ok 'bring form states the flow is closed, no repository ID field' || bad 'bring form closed text'
6667 [ "$(code POST /research/add/ -H "$CK" --data 'action=sync&orcid=0009-0002-6890-7111&doi=')" = 403 ] && ok 'missing CSRF refused' || bad 'CSRF refusal'
6768 post(){ code POST /research/add/ -H "$CK" --data-urlencode "csrf=$TOK" "$@"; }
6869 [ "$(post --data-urlencode action=sync --data-urlencode orcid=bad --data-urlencode doi=)" = 400 ] && ok 'malformed ORCID refused' || bad 'ORCID form'

run.sh

@@ -13,11 +13,21 @@
1313 # ~/forge-data/reload, which forged polls between connections)
1414 # ./run.sh restart build, then restart the service
1515 # ./run.sh check-salvage run targeted native storage, sandbox, journey and collector checks
16+# ./run.sh check-patch run the git patch intake tests (patch/tests/run.sh: every refusal of
17+# docs/API.md with its accepted twin, guard mutants, the interplane patch tool)
1618 # ./run.sh collector compile salvage/collector.om (its own program: the verifier that runs
1719 # outside the server's namespace) -> server/salvage-collector (COLLECTOR_OUT)
1820 # ./run.sh units print the unit list that build composes (makes .build/chrome.om when it is
1921 # missing or FORGE_SITE_REF / FORGE_SITE_SRC is set, below)
22+# ./run.sh seams tests only: the same list in the same order with every slice as its seam
23+# server/no<slice>.om, whatever READY or FORGE_TRY say (social/tests/units.sh
24+# puts the slice under test in place of its seam); build never reads it.
25+# door/ is server/nodoor.om there. With FORGE_STORE the list keeps the store
26+# source (.build/store.om, store/repos.om, store/head.om, server/nostat.om)
27+# and names server/no<slice>.om, not store/mv<slice>.om or store/moving.om
2028 # ./run.sh chrome make .build/chrome.om afresh and print its path
29+# ./run.sh agents make .build/agents.om (and .build/agents.tsv, the table it holds) from
30+# server/agents.tsv for the units of this build, and print the .om path
2131 # Site chrome: the interplane.io header, footer and their stylesheet lines are generated by
2232 # server/chromegen.om (seeded Omega) from content/_layout.html and public/style.css of the site's
2333 # canonical main in local Radicle storage (rad:z399yKvnXcBQNkKoq86iBDgTvQ5QV refs/heads/main), afresh
@@ -30,8 +40,27 @@
3040 # reason on stderr (server/chromegen.om lists them).
3141 # A slice directory (browse dl collab social quiet) is composed only when it holds a READY file;
3242 # otherwise its seam server/no<slice>.om is used. ForgeServer touches READY after integration.
43+# patch (the git patch intake) reads the store's repositories and social's sessions: it is composed
44+# only in a store-reading build (FORGE_STORE) with patch/READY and social composed, else
45+# server/nopatch.om.
3346 # Trial build of unready slices: FORGE_TRY="dl collab" FORGED_OUT=/tmp/forged.try ./run.sh build
3447 # Cores: FORGED_CPUS (taskset list, default 4,5) pins the build and the service; never 3, 7 or 15.
48+# Store-reading build (interplane-native DESIGN.md step 2): FORGE_STORE=<absolute store root>, with
49+# FORGED_OUT set (never server/forged), and optionally FORGE_CLONE_BASE=https://<host>/<path>/:
50+# FORGE_STORE=/path/to/store FORGED_OUT=/tmp/x/forged ./run.sh build
51+# composes .build/store.om, store/repos.om, store/head.om and store/clone.om in place of
52+# server/radsrc.om, nodes/head.om and dl/dlclone.om (the project list is the store's catalog.tsv; Git
53+# is read from projects/NAME/repo.git) and the seams of the slices that read Radicle-only data or need one that
54+# does: collab and quiet (server/no<slice>.om), growth, salvage, community and open (store/mv<slice>.om,
55+# which answer their addresses with the 503 "moving" page of store/moving.om in place of the 404 of
56+# server/no<slice>.om) and the research intake (research/noadd.om). Without FORGE_STORE every unit is
57+# the default and the old path stays.
58+# A store-reading build serves every public line of the catalog (less the deny list, server/repos.om
59+# fdeny), takes the site chrome from the store's interplane.io project (FORGE_SITE_STORE overrides),
60+# composes door/ with store/evcol.om, the collector that reads the store, in place of door/ev3col.om,
61+# and answers the addresses of salvage, community, open and trending with the store seams
62+# store/mv*.om: 503, "This part is moving to the new Interplane store and is not available yet."
63+# deploy and restart refuse FORGE_STORE: nothing here switches the live service.
3564 set -eu
3665 # unit order: `ls <slice>/*.om` must sort by byte (dl/dl.om before dl/dljson.om, whose code reads
3766 # dl.om globals); under en_US collation the order flips and omc stops with error 3
@@ -57,6 +86,8 @@ for part in $(echo "$CORES" | tr ',' ' '); do
5786 done
5887
5988 SITE_RID=z399yKvnXcBQNkKoq86iBDgTvQ5QV
89+# seams: 1 only under the `seams` command (a command word, never an environment value)
90+seams=0
6091 # chromegen: (re)make $ROOT/.build/chrome.om from the site source; only diagnostics on stderr
6192 chromegen() {
6293 b=$ROOT/.build
@@ -72,7 +103,11 @@ chromegen() {
72103 sha=$(git -C "$FORGE_SITE_SRC" rev-parse --verify HEAD^{commit} 2> /dev/null || echo 0000000000000000000000000000000000000000)
73104 { cat "$FORGE_SITE_SRC/content/_layout.html"; printf '\0'; cat "$FORGE_SITE_SRC/public/style.css"; printf '\0'; echo "$sha"; } > "$b/site.$$"
74105 else
75- s=${FORGE_SITE_STORE:-$HOME/.radicle/storage/$SITE_RID}
106+ if [ -n "${FORGE_STORE:-}" ]; then
107+ s=${FORGE_SITE_STORE:-${FORGE_STORE%/}/projects/interplane.io/repo.git}
108+ else
109+ s=${FORGE_SITE_STORE:-$HOME/.radicle/storage/$SITE_RID}
110+ fi
76111 sha=$(git --git-dir="$s" rev-parse --verify "${FORGE_SITE_REF:-refs/heads/main}^{commit}") || { echo "run.sh: no site commit ${FORGE_SITE_REF:-refs/heads/main} in $s" >&2; return 1; }
77112 { git --git-dir="$s" show "$sha:content/_layout.html"; printf '\0'; git --git-dir="$s" show "$sha:public/style.css"; printf '\0'; echo "$sha"; } > "$b/site.$$"
78113 fi
@@ -85,8 +120,125 @@ chromegen() {
85120 mv "$b/chrome.om.$$" "$b/chrome.om"
86121 }
87122
88-# units: a failed generation lists a path that does not exist, so a caller's cat and omc fail loudly
123+# composed SLICE: true when this list composes SLICE's own units, not its seam server/no<slice>.om:
124+# the slice holds a READY file or FORGE_TRY names it. Never in the seams list (`./run.sh seams`).
125+composed() {
126+ [ "$seams" = 0 ] || return 1
127+ [ -f "$1/READY" ] && return 0
128+ case " ${FORGE_TRY:-} " in *" $1 "*) return 0 ;; esac
129+ return 1
130+}
131+# ready SLICE: SLICE holds a READY file (false in the seams list)
132+ready() { [ "$seams" = 0 ] && [ -f "$1/READY" ]; }
133+
134+# storegen: (re)make $ROOT/.build/store.om from FORGE_STORE and FORGE_CLONE_BASE: the store root
135+# (tfsroot, with a final "/"), FSCB (1 when a clone base is set) and the clone base (tfcbase, "-" when
136+# unset). Unfinished migration: shell glue beside chromegen; every decision about the store itself is
137+# made in Omega by store/repos.om. The byte rules keep the values plain text literals that need no
138+# escaping in Omega, HTML or JSON.
139+storegen() {
140+ r=${FORGE_STORE%/}/
141+ case $r in
142+ /*) ;;
143+ *) echo "run.sh: FORGE_STORE must be an absolute path: '$FORGE_STORE'" >&2; return 1 ;;
144+ esac
145+ case $r in
146+ *[!A-Za-z0-9._/+-]*) echo "run.sh: FORGE_STORE may hold only A-Z a-z 0-9 . _ / + -: '$FORGE_STORE'" >&2; return 1 ;;
147+ esac
148+ cb=${FORGE_CLONE_BASE:-}
149+ f=0
150+ if [ -n "$cb" ]; then
151+ case $cb in
152+ https://?*/) ;;
153+ *) echo "run.sh: FORGE_CLONE_BASE must start with https:// and end with /: '$cb'" >&2; return 1 ;;
154+ esac
155+ case $cb in
156+ *[!A-Za-z0-9._/:+-]*) echo "run.sh: FORGE_CLONE_BASE may hold only A-Z a-z 0-9 . _ / : + -: '$cb'" >&2; return 1 ;;
157+ esac
158+ f=1
159+ else
160+ cb=-
161+ fi
162+ mkdir -p "$ROOT/.build"
163+ printf 'note .build/store.om: generated by run.sh storegen (store-reading build)\ntext tfsroot "%s"\nconst FSCB ulong %s\ntext tfcbase "%s"\n' "$r" "$f" "$cb" > "$ROOT/.build/store.om.$$"
164+ mv "$ROOT/.build/store.om.$$" "$ROOT/.build/store.om"
165+}
166+
167+# stout SLICE: true when the store-reading build composes SLICE out through its seam
168+stout() {
169+ [ -n "${FORGE_STORE:-}" ] || return 1
170+ case " collab quiet growth salvage community open " in *" $1 "*) return 0 ;; esac
171+ return 1
172+}
173+# mvseam SLICE: true when the store-reading build answers SLICE's addresses with its store seam
174+# store/mv<SLICE>.om (the 503 "moving" page). Never in the seams list, where every slice is
175+# server/no<slice>.om and store/moving.om is not listed.
176+mvseam() { [ "$seams" = 0 ] && stout "$1"; }
177+
178+# agentsgen UNITS: (re)make $ROOT/.build/agents.om from server/agents.tsv for the build whose unit list
179+# is UNITS: one text tfqatsv, tabs and newlines written as \t and \n, comment lines (#) left out; the
180+# same rows as plain TSV in $ROOT/.build/agents.tsv (what the tests read). The table's first column is
181+# the part that answers the row: forge (always composed), nodes (the node health snapshot of
182+# nodes/stat.om, composed when UNITS holds server/radsrc.om, the Radicle source: a store-reading
183+# build has no node), - (a not_available row as written), or a slice folder
184+# (composed when a unit of UNITS is in that folder). A row whose part this build does not compose
185+# becomes a not_available row ("none") naming the part, so agents.json lists only what answers. When
186+# UNITS holds store/mv<part>.om (the store build: growth, salvage, community, open), that part is
187+# moving to the new Interplane store: its rows say so, and say whether their address answers 503
188+# (store/moving.om) or not; and not_available rows for salvage/ and community/ name those addresses.
189+# Refused with the reason on stderr, nothing written: a byte that is not printable ASCII or tab, a
190+# double quote or a backslash (they would end or change the text), or a row without 8 fields.
191+agentsgen() {
192+ b=$ROOT/.build
193+ mkdir -p "$b"
194+ if grep -q "$(printf '[^ -~\t]')" server/agents.tsv || grep -q '["\\]' server/agents.tsv; then
195+ echo "run.sh: server/agents.tsv holds a byte that is not printable ASCII or tab, a quote or a backslash" >&2
196+ return 1
197+ fi
198+ parts=$(printf '%s\n' "$1" | awk -F/ '$0 == "server/radsrc.om" { print "nodes" } $0 == "collab/native/write.om" { print "issue-write" } NF > 1 && $1 !~ /^(server|nodes|store)$/ && $0 !~ /^\// { print $1 }' | sort -u | tr '\n' ' ')
199+ mv=$(printf '%s\n' "$1" | sed -n 's|^store/mv\([a-z]*\)\.om$|\1|p' | sort -u | tr '\n' ' ')
200+ if ! grep -v '^#' server/agents.tsv | awk -F '\t' -v OFS='\t' -v parts=" $parts " -v mv=" $mv " '
201+ NF != 8 { bad = 1; exit }
202+ NR == 1 { $1 = ""; sub(/^\t/, ""); print; next }
203+ $1 == "collab" && $3 ~ /\/patches(\/|$)/ && index(parts, " patch ") { next }
204+ $1 == "patch" && !index(parts, " patch ") { next }
205+ $1 == "-" || $1 == "forge" || index(parts, " " $1 " ") { $1 = ""; sub(/^\t/, ""); print; next }
206+ index(mv, " " $1 " ") && $3 ~ /^((salvage|community|open)(\/.*)?|open\.json|trending(\.json)?|bring\.sh|get\.sh|withdraw\.sh)$/ {
207+ print "none", $3, "-", "-", "-", $7, "not answered by this build: its " $1 " part is moving to the new Interplane store and is not available yet; the address answers 503 with that text (forge/error/1 with reason moving to a JSON request), no Retry-After"; next }
208+ index(mv, " " $1 " ") {
209+ print "none", $3, "-", "-", "-", $7, "not answered by this build: its " $1 " part is moving to the new Interplane store and is not available yet; this address answers 404, or without this schema"; next }
210+ { print "none", $3, "-", "-", "-", $7, "not answered by this build: its " $1 " part is not composed (the address answers 404 or 501, or without this schema)" }
211+ END {
212+ if (bad) exit 1
213+ if (index(mv, " salvage ")) print "none", "salvage/", "-", "-", "-", "docs/AGENT-DOOR.md", "the Salvage Yard is moving to the new Interplane store and is not available yet; salvage/, and every address under it, answers 503 with that text (forge/error/1 with reason moving to a JSON request), no Retry-After"
214+ if (index(mv, " community ")) print "none", "community/", "-", "-", "-", "docs/AGENT-DOOR.md", "Community Machines are moving to the new Interplane store and are not available yet; community/, and every address under it, answers 503 with that text (forge/error/1 with reason moving to a JSON request), no Retry-After"
215+ }' > "$b/agents.tsv.$$"; then
216+ rm -f "$b/agents.tsv.$$"
217+ echo "run.sh: server/agents.tsv has a row without 8 tab-separated fields" >&2
218+ return 1
219+ fi
220+ {
221+ printf 'note generated by run.sh from server/agents.tsv at every build; edit the table, not this file\ntext tfqatsv "'
222+ sed 's/\t/\\t/g' "$b/agents.tsv.$$" | awk '{printf "%s\\n", $0}'
223+ printf '"\n'
224+ } > "$b/agents.om.$$"
225+ mv "$b/agents.tsv.$$" "$b/agents.tsv"
226+ mv "$b/agents.om.$$" "$b/agents.om"
227+}
228+
229+# units: the unit list; agentsgen reads it (the parts it composes) and fills the AGENTS slot
89230 units() {
231+ u=$(units_core)
232+ if agentsgen "$u"; then
233+ a=$ROOT/.build/agents.om
234+ else
235+ a=$ROOT/.build/AGENTS-NOT-GENERATED-see-stderr
236+ fi
237+ printf '%s\n' "$u" | awk -v a="$a" '$0 == "@AGENTS@" { print a; next } { print }'
238+}
239+
240+# units: a failed generation lists a path that does not exist, so a caller's cat and omc fail loudly
241+units_core() {
90242 if [ ! -s "$ROOT/.build/chrome.om" ] || [ -n "${FORGE_SITE_REF:-}${FORGE_SITE_SRC:-}" ]; then
91243 if ! chromegen; then
92244 echo "$ROOT/.build/CHROME-NOT-GENERATED-see-stderr"
@@ -98,48 +250,91 @@ units() {
98250 echo "server/util.om"
99251 echo "$ROOT/.build/chrome.om"
100252 echo "server/repos.om"
101- echo "nodes/head.om"
253+ if [ -n "${FORGE_STORE:-}" ]; then
254+ if storegen; then
255+ echo "$ROOT/.build/store.om"
256+ else
257+ echo "$ROOT/.build/STORE-NOT-GENERATED-see-stderr"
258+ fi
259+ echo "store/repos.om"
260+ echo "store/head.om"
261+ else
262+ echo "server/radsrc.om"
263+ echo "nodes/head.om"
264+ fi
102265 for s in browse dl collab social quiet; do
103- case " ${FORGE_TRY:-} " in *" $s "*) try=1 ;; *) try=0 ;; esac
104- if [ -f "$s/READY" ] || [ "$try" = 1 ]; then
105- ls "$s"/*.om
266+ if [ "$s" = collab ] && [ -n "${FORGE_STORE:-}" ] && composed collab && composed browse; then
267+ echo collab/co0form.om
268+ ls collab/native/*.om | grep -v "^collab/native/write.om$"
269+ elif ! stout "$s" && composed "$s"; then
270+ if [ "$s" = dl ] && [ -n "${FORGE_STORE:-}" ]; then
271+ ls dl/*.om | grep -v '^dl/dlclone\.om$'
272+ echo "store/clone.om"
273+ else
274+ ls "$s"/*.om
275+ fi
106276 else
107277 echo "server/no$s.om"
108278 fi
109279 done
110- echo "nodes/stat.om"
280+ if [ -n "${FORGE_STORE:-}" ] && composed collab && composed browse; then
281+ if composed social; then echo collab/native/write.om; else echo server/noissuewrite.om; fi
282+ fi
283+ # the git patch intake (patch/, docs/API.md "Git patches") reads the store's repositories
284+ # (projects/NAME/repo.git) and social's sessions: composed only in a store-reading build, when
285+ # patch and social are composed; every other build keeps the seam server/nopatch.om
286+ if [ -n "${FORGE_STORE:-}" ] && composed patch && composed social && composed browse; then
287+ ls patch/*.om
288+ else
289+ echo "server/nopatch.om"
290+ fi
291+ # the node health pages read the Radicle node's snapshot; the store-reading build has no node
292+ if [ -n "${FORGE_STORE:-}" ]; then
293+ echo "server/nostat.om"
294+ else
295+ echo "nodes/stat.om"
296+ fi
111297 echo "server/json.om"
112298 echo "server/counts.om"
113299 echo "server/count-snapshot.om"
114- case " ${FORGE_TRY:-} " in *" growth "*) try=1 ;; *) try=0 ;; esac
115- if [ -f growth/READY ] || [ "$try" = 1 ]; then
300+ # the store build answers the addresses of the parts it composes out with one 503 (store/moving.om)
301+ if [ -n "${FORGE_STORE:-}" ] && [ "$seams" = 0 ]; then
302+ echo "store/moving.om"
303+ fi
304+ if ! stout growth && composed growth; then
116305 ls growth/*.om
306+ elif mvseam growth; then
307+ echo "store/mvgrowth.om"
117308 else
118309 echo "server/nogrowth.om"
119310 fi
120- case " ${FORGE_TRY:-} " in *" salvage "*) try=1 ;; *) try=0 ;; esac
121- if [ -f salvage/READY ] || [ "$try" = 1 ]; then
311+ if ! stout salvage && composed salvage; then
122312 ls salvage/[0-9][0-9]*.om
313+ elif mvseam salvage; then
314+ echo "store/mvsalvage.om"
123315 else
124316 echo "server/nosalvage.om"
125317 fi
126318 case " ${FORGE_TRY:-} " in *" community "*) try=1 ;; *) try=0 ;; esac
127- if { [ -f community/READY ] && [ -f salvage/READY ]; } || [ "$try" = 1 ]; then
319+ if ! stout community && { { ready community && ready salvage; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; }; then
128320 echo "$OMV/om/tls/ec.om"
129321 ls community/[0-9][0-9]*.om
322+ elif mvseam community; then
323+ echo "store/mvcommunity.om"
130324 else
131325 echo "server/nocommunity.om"
132326 fi
133327 case " ${FORGE_TRY:-} " in *" open "*) try=1 ;; *) try=0 ;; esac
134- if { [ -f open/READY ] && [ -f salvage/READY ]; } || [ "$try" = 1 ]; then
328+ if ! stout open && { { ready open && ready salvage; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; }; then
135329 echo "open/route.om"
330+ elif mvseam open; then
331+ echo "store/mvopen.om"
136332 else
137333 echo "server/noopen.om"
138334 fi
139- case " ${FORGE_TRY:-} " in *" research "*) try=1 ;; *) try=0 ;; esac
140- if [ -f research/READY ] || [ "$try" = 1 ]; then
335+ if composed research; then
141336 echo "research/route.om"
142- if [ -f open/READY ] && [ -f salvage/READY ]; then
337+ if ! stout open && ready open && ready salvage; then
143338 echo "research/intake-route.om"
144339 else
145340 echo "research/noadd.om"
@@ -147,6 +342,20 @@ units() {
147342 else
148343 echo "server/noresearch.om"
149344 fi
345+ # door/ (the event stream and the feed, docs/AGENT-DOOR.md): with Radicle storage it reads collab's
346+ # COB model and social's log (door/ev3col.om), so it needs both composed, else the seam
347+ # server/nodoor.om answers 501; a store-reading build reads the store and social's log
348+ # (store/evcol.om in place of door/ev3col.om) and needs social only
349+ case " ${FORGE_TRY:-} " in *" door "*) try=1 ;; *) try=0 ;; esac
350+ if [ -n "${FORGE_STORE:-}" ] && { { ready door && ready social; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; }; then
351+ ls door/*.om | sed 's|^door/ev3col\.om$|store/evcol.om|'
352+ elif { ready door && ready collab && ready social; } || { [ "$seams" = 0 ] && [ "$try" = 1 ]; }; then
353+ ls door/*.om
354+ else
355+ echo "server/nodoor.om"
356+ fi
357+ echo "@AGENTS@"
358+ echo "server/agents.om"
150359 echo "server/state.om"
151360 echo "server/pages.om"
152361 echo "nodes/srch.om"
@@ -172,7 +381,7 @@ compile() { # compile OUT: compose the units of the current directory, compile,
172381 # dirty trial build stays "unrecorded" and never names a wrong commit
173382 st='s/^x$/x/'
174383 # shellcheck disable=SC2046
175- if c=$(git rev-parse HEAD 2> /dev/null) && [ -z "$(git status --porcelain -- $(units | grep -v '^/'))" ]; then
384+ if c=$(git rev-parse HEAD 2> /dev/null) && [ -z "$(git status --porcelain -- $(units | grep -v '^/') server/agents.tsv)" ]; then
176385 st="s/^text tcbldc \"unrecorded\"\$/text tcbldc \"$c\"/"
177386 fi
178387 # shellcheck disable=SC2046
@@ -225,10 +434,18 @@ helperc() { # helperc SRC OUT: compile a supervisor helper, install OUT atomical
225434
226435 build() {
227436 out=${FORGED_OUT:-server/forged}
437+ if [ -n "${FORGE_STORE:-}" ] && [ -z "${FORGED_OUT:-}" ]; then
438+ echo "run.sh: a store-reading build needs FORGED_OUT (it never writes server/forged)" >&2
439+ exit 1
440+ fi
228441 if [ "$(realpath -m "$out")" = "$ROOT/server/forged" ] && [ -n "$(git status --porcelain)" ]; then
229442 echo "run.sh: working tree is not clean; the live binary is built only from a commit (./run.sh deploy)" >&2
230443 exit 1
231444 fi
445+ if [ "$(realpath -m "$out")" = "$ROOT/server/forged" ] && [ -n "${FORGE_STORE:-}" ]; then
446+ echo "run.sh: a store-reading build never writes server/forged" >&2
447+ exit 1
448+ fi
232449 compile "$out"
233450 publicc "$(dirname "$out")/public-read"
234451 listenc "$(dirname "$out")/forged-listen"
@@ -365,10 +582,18 @@ svc() {
365582
366583 case "${1:-}" in
367584 units) units ;;
585+seams)
586+ seams=1
587+ units
588+ ;;
368589 chrome)
369590 chromegen
370591 echo "$ROOT/.build/chrome.om"
371592 ;;
593+agents)
594+ units > /dev/null
595+ echo "$ROOT/.build/agents.om"
596+ ;;
372597 build) build ;;
373598 check-salvage) checks ;;
374599 collector)
@@ -383,12 +608,24 @@ intake)
383608 ;;
384609 check-open) sh open/tests/run.sh ;;
385610 check-open-up) bash open/tests/up.sh ;;
386-deploy) deploy "${2:-}" ;;
611+check-patch) bash patch/tests/run.sh && bash patch/tests/resilience.sh ;;
612+check-issues) bash collab/tests/native-issues-store.sh ;;
613+deploy)
614+ if [ -n "${FORGE_STORE:-}" ]; then
615+ echo "run.sh: deploy refuses FORGE_STORE: the store-reading build is not deployed by this script" >&2
616+ exit 1
617+ fi
618+ deploy "${2:-}"
619+ ;;
387620 start) svc start ;;
388621 stop) svc stop ;;
389622 reload) svc reload ;;
390623 status) svc status ;;
391624 restart)
625+ if [ -n "${FORGE_STORE:-}" ]; then
626+ echo "run.sh: restart refuses FORGE_STORE: nothing here switches the live service" >&2
627+ exit 1
628+ fi
392629 "$0" build
393630 svc restart
394631 ;;

salvage/15bundle.om

@@ -10,7 +10,7 @@ text tlinnm "stdin"
1010 text tlexnm "expected"
1111 text tlreadnm "README.txt"
1212 text tlustar "ustar"
13-text tlreadme "INTERPLANE declared-example bundle v1\n\nrecord.ip is the canonical exact revision. Its filename-independent SHA-256 is the revision ID shown by the hub. Fields and replay instructions: docs/SALVAGE.md in the public Interplane Forge patch at https://radicle.network/nodes/iris.radicle.network/rad:z3KFmLGeYdvDAgwpCgdBd1ENW7nU5/patches/9ec6028e5a04a52ef1e2c0e19d3d9944179071a0\n\nUse salvage/replay.om with 00core.om, 10verify.om and the pinned Omega sha2.om. The compiler pin is 3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194. Verify the compiler's seed chain before replay. Set OMEGA_COMPILER privately to the absolute path of that verified compiler. Run the native replay tool with RECORD_PATH EXPECTED_RECORD_SHA256 FRESH_PRIVATE_DIRECTORY_WITH_TRAILING_SLASH RECEIPT_PATH. The fresh directory must be empty. Linux AArch64 with bwrap, prlimit, Landlock ABI 3 and seccomp is required. Missing isolation fails closed.\n\nThe input and output are UTF-8 LF-normalized bytes, not approximate text matches. The tool recompiles and executes the exact source under the sandbox, checks exit zero and exact output, rejects an altered expected output, and compares rebuilt binary/output hashes to the receipt.\n\nThe receipt's HMAC authenticates the collector only to the hub; it is not a publicly verifiable digital signature. Independent replay is the public verification. A passing example is not a proof of general correctness, safety, authorship or license validity. Source and attribution claims are supplied by the submitting builder. No speed or mathematical claims are made.\n"
13+text tlreadme "INTERPLANE declared-example bundle v1\n\nrecord.ip is the canonical exact revision. Its filename-independent SHA-256 is the revision ID shown by the hub. Fields and replay instructions: docs/SALVAGE.md in the Interplane Forge source. No public Git URL yet: Interplane does not serve Git clones yet.\n\nUse salvage/replay.om with 00core.om, 10verify.om and the pinned Omega sha2.om. The compiler pin is 3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194. Verify the compiler's seed chain before replay. Set OMEGA_COMPILER privately to the absolute path of that verified compiler. Run the native replay tool with RECORD_PATH EXPECTED_RECORD_SHA256 FRESH_PRIVATE_DIRECTORY_WITH_TRAILING_SLASH RECEIPT_PATH. The fresh directory must be empty. Linux AArch64 with bwrap, prlimit, Landlock ABI 3 and seccomp is required. Missing isolation fails closed.\n\nThe input and output are UTF-8 LF-normalized bytes, not approximate text matches. The tool recompiles and executes the exact source under the sandbox, checks exit zero and exact output, rejects an altered expected output, and compares rebuilt binary/output hashes to the receipt.\n\nThe receipt's HMAC authenticates the collector only to the hub; it is not a publicly verifiable digital signature. Independent replay is the public verification. A passing example is not a proof of general correctness, safety, authorship or license validity. Source and attribution claims are supplied by the submitting builder. No speed or mathematical claims are made.\n"
1414 fn sloct hdr edit uchar * pos ulong width ulong value ulong to void
1515 v = value
1616 for i ulong width bound 16

salvage/20web.om

@@ -106,7 +106,7 @@ text tlrawc "/receipt"
106106 text tlrecord "Exact source record"
107107 text tlmsg7 "Collector receipt"
108108 text tlmsg8 "Download source"
109-text tlnosess "Sign in with your Radicle key to bring a build or create a part."
109+text tlnosess "Sign in with your key to bring a build or create a part."
110110 text tlemptyy "The yard is waiting for its first public build. Unfinished is welcome."
111111 text tlmsg9 "The form was refused. Check the byte limits, required text, permission checkbox, and license. Duplicate fields and malformed text are not accepted."
112112 text tloff "The salvage workspace is not configured on this instance. No submission was saved."

server/agents.om

new file mode 100644
@@ -0,0 +1,195 @@
1+note forged server/agents.om (ForgeServer, prefix fqa / tfqa): <base>agents.json, schema interplane/agents/1
2+note (docs/API.md, docs/AGENT-DOOR.md): the one document an agent reads first. Its routes come from
3+note server/agents.tsv, which run.sh compiles into .build/agents.om (the text tfqatsv, composed just
4+note above this unit) at every build, so the list cannot drift from the table; server/tests/agentdoor.sh
5+note fetches every row and checks the schema it answers. Rows whose first field is "none" are the
6+note not_available list. The event rows move to not_available in a build without the event store
7+note (server/nodoor.om: evon is false, those pages answer 501).
8+text tfqapj "/agents.json"
9+text tfqa1 "{\"schema\":\"interplane/agents/1\",\"base\":\""
10+text tfqa2 "\",\n\"read_first\":\""
11+text tfqa3 "agents.json\",\n\"how_to_ask\":{\"suffix\":\"the path itself is the JSON name\",\"accept\":\"send Accept: application/json (and not text/html); the HTML page names the same address in <link rel=alternate type=application/json>\",\"always\":\"JSON whatever the headers say\"},\n\"text_form\":\"add format=text to the query of any HTML page for its plain-text form (text/plain; charset=utf-8)\",\n\"error_schema\":\"forge/error/1\",\n\"events\":"
12+text tfqae1 "{\"path\":\""
13+text tfqae2 "events.json\",\"schema\":\"interplane/events/1\",\"after\":\"after=<seq> answers the events with a higher seq, oldest first; next is the address to read next\",\"limit_default\":50,\"limit_max\":200,\"etag\":\"send If-None-Match with the ETag of the last answer: an unchanged stream answers 304\",\"feed\":\""
14+text tfqae3 "feed\"}"
15+text tfqar ",\n\"routes\":["
16+text tfqan "\n],\n\"not_available\":["
17+text tfqaz "\n]}\n"
18+text tfqanone "none"
19+text tfqameth "method"
20+text tfqadash "-"
21+text tfqaevs "interplane/events/1"
22+text tfqano "this build has no event store (server/nodoor.om): the address answers 501"
23+text tfqk1 "\n{\"method\":"
24+text tfqk2 ",\"path\":"
25+text tfqk3 ",\"json\":"
26+text tfqk4 ",\"schema\":"
27+text tfqk5 ",\"auth\":"
28+text tfqk6 ",\"doc\":"
29+text tfqk7 ",\"purpose\":"
30+text tfqw1 "\n{\"what\":"
31+text tfqw2 ",\"why\":"
32+global fqan ulong 1
33+global fqatb ulong 8
34+note fqajsn: a request for a .json name asks for JSON, so its errors are forge/error/1 documents too
35+note (ferrpage answers JSON when fjwant is true)
36+fn fqajsn to void
37+for i ulong len tfjaj bound 64
38+put facc i get tfjaj i
39+end
40+put faccl 0 len tfjaj
41+end
42+fn fqaroute to long
43+if not fpeq tfqapj
44+ret 0
45+end
46+fqajsn
47+if not fget
48+ret 405
49+end
50+fjstart
51+fput tfqa1
52+fputb
53+fput tfqa2
54+fputb
55+fput tfqa3
56+if evon
57+fput tfqae1
58+fputb
59+fput tfqae2
60+fputb
61+fput tfqae3
62+else
63+fynull
64+end
65+fput tfqar
66+fqarows 1
67+fput tfqan
68+fqarows 2
69+fput tfqaz
70+ret 200
71+end
72+note fqarows mode: walk the lines of tfqatsv; mode 1 the routes, mode 2 the not_available list
73+fn fqarows mode ulong to void
74+put fqan 0 0
75+n = len tfqatsv
76+p = ulong 0
77+for it ulong 4096
78+if ge p n
79+break
80+end
81+q = p
82+for k ulong 65536
83+if ge q n
84+break
85+end
86+if eq get tfqatsv q 10
87+break
88+end
89+q = add q 1
90+end
91+fqaline p q mode
92+p = add q 1
93+end
94+end
95+note fqaline p q mode: one row tfqatsv[p, q) with 7 tab-separated fields (the header row is skipped)
96+fn fqaline p ulong q ulong mode ulong to void
97+k = ulong 0
98+for i ulong sub q p bound 65536
99+if eq get tfqatsv add p i 9
100+if lt k 8
101+put fqatb k add p i
102+end
103+k = add k 1
104+end
105+end
106+if ne k 6
107+ret
108+end
109+if fqaeq p get fqatb 0 tfqameth
110+ret
111+end
112+none = fqaeq p get fqatb 0 tfqanone
113+ev = fqaeq fqafa 3 get fqatb 3 tfqaevs
114+off = and ev not evon
115+if eq mode 1
116+if or none off
117+ret
118+end
119+fqasep
120+fput tfqk1
121+fqastr p get fqatb 0 false
122+fput tfqk2
123+fqastr fqafa 1 get fqatb 1 true
124+fqarow2 q
125+ret
126+end
127+if none
128+fqasep
129+fput tfqw1
130+fqastr fqafa 1 get fqatb 1 false
131+fput tfqw2
132+fqastr fqafa 6 q false
133+fputc 125
134+ret
135+end
136+if off
137+fqasep
138+fput tfqw1
139+fqastr fqafa 1 get fqatb 1 true
140+fput tfqw2
141+fjtxt tfqano
142+fputc 125
143+end
144+end
145+fn fqarow2 q ulong to void
146+fput tfqk3
147+fqastr fqafa 2 get fqatb 2 false
148+fput tfqk4
149+if fqaeq fqafa 3 get fqatb 3 tfqadash
150+fynull
151+else
152+fqastr fqafa 3 get fqatb 3 false
153+end
154+fput tfqk5
155+fqastr fqafa 4 get fqatb 4 false
156+fput tfqk6
157+fqastr fqafa 5 get fqatb 5 false
158+fput tfqk7
159+fqastr fqafa 6 q false
160+fputc 125
161+end
162+note fqafa f: the start of field f (f >= 1): just after tab f-1
163+fn fqafa f ulong to ulong
164+ret add get fqatb sub f 1 1
165+end
166+fn fqasep to void
167+if gt get fqan 0 0
168+fputc 44
169+end
170+put fqan 0 add get fqan 0 1
171+end
172+fn fqaeq a ulong e ulong t view uchar * to bool
173+if ne sub e a len t
174+ret false
175+end
176+for i ulong len t bound 64
177+if ne get tfqatsv add a i get t i
178+ret false
179+end
180+end
181+ret true
182+end
183+note fqastr a e base: tfqatsv[a, e) as a JSON string, after the base when base is true
184+fn fqastr a ulong e ulong base bool to void
185+fjtb
186+if base
187+for i ulong get fbasel 0 bound 64
188+fjtc get fbase i
189+end
190+end
191+for i ulong sub e a bound 65536
192+fjtc get tfqatsv add a i
193+end
194+fjstr
195+end

server/agents.tsv

new file mode 100644
@@ -0,0 +1,61 @@
1+# server/agents.tsv: the one source table of <base>agents.json (schema interplane/agents/1).
2+# run.sh compiles it into .build/agents.om (text tfqatsv) and .build/agents.tsv at every build, for that
3+# build's units; server/tests/agentdoor.sh fetches every row (templates filled from its fixture) and
4+# checks the answered schema, and checks that every schema heading of docs/API.md is a row. Tab-separated,
5+# ASCII only, one row a line. part: the part of the forge that answers the row: forge (always composed),
6+# nodes (the node health snapshot: composed with the Radicle source server/radsrc.om only), - (a
7+# not_available row), or a slice folder; a row whose part the build does not compose is listed under
8+# not_available in that build's agents.json (run.sh agentsgen).
9+# path is relative to the base (/ or /forge/); json: suffix = the path itself is the JSON name,
10+# accept = send Accept: application/json, always = JSON whatever the headers; schema - = none.
11+part method path json schema auth doc purpose
12+forge GET accept forge/explore/1 none docs/API.md the public repositories (the front page) as JSON
13+forge GET explore.json suffix forge/explore/1 none docs/API.md the public repositories, the explore list
14+growth GET explore?order={order} accept forge/explore-order/1 none docs/GROWTH.md the public list ordered by trending or new
15+growth GET trending.json suffix forge/explore-order/1 none docs/GROWTH.md the public list ordered by trending
16+forge GET search?q={q} accept forge/search/1 none docs/API.md repositories and code lines matching words, forge-wide
17+social GET {user} accept forge/user/1 none docs/API.md an account profile; ?tab=stars|followers|following
18+social GET {user}/followers accept forge/user/1 none docs/API.md the accounts that follow a user
19+social GET {user}/following accept forge/user/1 none docs/API.md the accounts a user follows
20+social GET stars accept forge/stars/1 session docs/API.md the signed-in user's starred and favorite lists (signed out: 303 to login)
21+forge GET {owner}/{repo}.json suffix forge/repo/1 none docs/API.md one repository: description, branch, last commit, clone, counts
22+forge GET {owner}/{repo} accept forge/repo/1 none docs/API.md one repository, the repository home
23+browse GET {owner}/{repo}/tree/{ref} accept forge/tree/1 none docs/API.md a directory listing at a ref; add /{path} for a sub-directory
24+browse GET {owner}/{repo}/blob/{ref}/{path} accept forge/blob/1 none docs/API.md one file at a ref
25+browse GET {owner}/{repo}/blame/{ref}/{path} accept forge/blame/1 none docs/API.md every line of a file with the commit that last changed it
26+forge GET {owner}/{repo}/search?q={q} accept forge/repo-search/1 none docs/API.md lines of the default branch matching a text
27+browse GET {owner}/{repo}/commits/{ref} accept forge/commits/1 none docs/API.md 30 commits a page of a ref's history; ?page=N
28+browse GET {owner}/{repo}/commit/{sha} accept forge/commit/1 none docs/API.md one commit with its numstat and diff
29+browse GET {owner}/{repo}/compare/{a}...{b} accept forge/compare/1 none docs/API.md what ref b has that ref a does not
30+browse GET {owner}/{repo}/branches accept forge/branches/1 none docs/API.md the branches, newest commit first
31+browse GET {owner}/{repo}/tags accept forge/tags/1 none docs/API.md the tags
32+dl GET {owner}/{repo}/releases accept forge/releases/1 none docs/API.md the releases (tags with their notes and assets)
33+dl GET {owner}/{repo}/releases/tag/{tag} accept forge/release/1 none docs/API.md one release
34+collab GET {owner}/{repo}/patches accept forge/patches/1 none docs/API.md the patches; ?state=open|draft|archived|merged|all
35+collab GET {owner}/{repo}/patches/{id} accept forge/patch/1 none docs/API.md one patch: revisions, reviews, comments, merges, verdicts
36+patch GET {owner}/{repo}/patches accept forge/patch-list/1 none docs/API.md signed patches and imported proposals; ?page=N
37+patch GET {owner}/{repo}/patches/{id} accept forge/patch/1 none docs/API.md one signed patch or imported proposal
38+collab GET {owner}/{repo}/issues accept forge/issues/1 none docs/API.md the issues; ?state=open|closed|all
39+collab GET {owner}/{repo}/issues/{id} accept forge/issue/1 none docs/API.md one issue with its comments
40+issue-write GET {owner}/{repo}/issues/new accept forge/issue-form/1 session docs/API.md authenticated new issue fields
41+issue-write GET {owner}/{repo}/issues/{id}/comments accept forge/issue-form/1 session docs/API.md authenticated comment fields
42+issue-write POST {owner}/{repo}/issues/new accept forge/issue-write/1 session docs/API.md open an issue using the form fields
43+issue-write POST {owner}/{repo}/issues/{id}/comments accept forge/issue-write/1 session docs/API.md post a comment to a full issue ID
44+social GET {owner}/{repo}/stargazers accept forge/stargazers/1 none docs/API.md the accounts that starred the repository
45+social GET {owner}/{repo}/watchers accept forge/watchers/1 none docs/API.md the accounts that watch the repository
46+growth GET {owner}/{repo}/insights accept forge/insights/1 none docs/GROWTH.md the repository's counted numbers and their sources
47+open GET open.json suffix interplane/open-builds/1 none docs/OPEN-BUILDS.md the open builds shelf
48+open GET open/{project}.json suffix interplane/open-build/1 none docs/OPEN-BUILDS.md one project on the open builds shelf
49+open GET open/alarms.json suffix interplane/open-alarms/1 none docs/OPEN-BUILDS.md the open builds intake's alarms
50+research GET research.json suffix interplane/research/1 none research/build.om the research index (base / only)
51+research GET research/{slug}.json suffix interplane/research-work/1 none research/build.om one research work (base / only)
52+nodes GET status.json always - none nodes/stat.om the last health snapshot of this forge's node, shut down on 2026-11-14 (no schema key)
53+forge GET agents.json always interplane/agents/1 none docs/API.md this list: every machine-readable address, read it first
54+door GET events.json?after={seq}&limit={n} always interplane/events/1 none docs/API.md the public activity stream, read from where you stopped
55+door GET events?after={seq} accept interplane/events/1 none docs/API.md the same stream at the address without .json
56+door GET feed accept interplane/events/1 none docs/API.md the feed page; with Accept JSON the same stream as events.json
57+- none writes over HTTP without a browser session - - - docs/collab-write.md every POST needs the forge session cookie and its CSRF field (a signed-in browser); there is no token or key API. Sign in with /login before using an HTTP write route
58+- none MCP server - - - docs/AGENT-DOOR.md this forge runs no MCP server; read these addresses over plain HTTPS
59+- none git clone or fetch from this address - - - docs/API.md the forge pages are read-only views; clone with a line of the clone object of forge/repo/1
60+- none webhooks and push notifications - - - docs/AGENT-DOOR.md nothing is pushed to you; read events.json after the last seq you saw, with If-None-Match for a cheap 304
61+- none an HTML page at /agents - - - docs/AGENT-DOOR.md interplane.io serves /agents/ from the static site; the forge answers agents.json only

server/count-snapshot.om

@@ -1,19 +1,19 @@
1-note Public count snapshot v1. ASCII: header "1 <collection epoch>\n", then at most 64 rows.
1+note Public count snapshot v1. ASCII: header "1 <collection epoch>\n", then at most FAMAX (256) rows.
22 note Row: RID git upload archives assets since0 since1 since2 seeds seed-status seed-epoch LF.
33 note Fields separated by one space. RID alphanumeric, 1..64 bytes. Numbers unsigned decimal,
44 note 1..20 digits, no overflow. Status 0/1/2; only 1 means available. No private log content.
5-note Cap 16384 bytes, 256 bytes per line excluding LF, 65 lines, 11 fields, 64-byte fields.
5+note Cap 65536 bytes, 256 bytes per line excluding LF, FAMAX + 1 lines, 11 fields, 64-byte fields.
66 note Missing/malformed/future/older-than-3600s snapshots clear all availability, never trap.
77 text tfzsenv "FORGED_COUNTS_SNAPSHOT=1"
88 text tfzspth "/home/drakestapleton/handoffs/radicle/counts.snapshot"
99 text tfzmode "--counts-snapshot"
10-global fzsbuf uchar 16385
10+global fzsbuf uchar 65537
1111 global fzsen uchar 4096
1212 global fzfo ulong 11
1313 global fzfl ulong 11
1414 global fzval ulong 11
15-global fzseen uchar 4096
16-global fzsl ulong 64
15+global fzseen uchar 16384
16+global fzsl ulong 256
1717 global fzsnum ulong 1
1818 fn fzboxed to bool
1919 nn = envcnt
@@ -40,12 +40,12 @@ fn fzclear to void
4040 for k ulong 4
4141 put fzsnc k 0
4242 end
43-for k ulong 64
43+for k ulong FAMAX
4444 put fzsdk k 0
4545 put fzsdt k 0
4646 put fzsd k 0
4747 end
48-for k ulong 256
48+for k ulong 1024
4949 put fzcnt k 0
5050 end
5151 end
@@ -119,7 +119,7 @@ end
119119 put fzseen add mul row 64 j c
120120 end
121121 put fzsl row n
122-for r ulong row bound 64
122+for r ulong row bound FAMAX
123123 if eq get fzsl r n
124124 if fzssame row r n
125125 ret false
@@ -166,10 +166,10 @@ end
166166 if gt get fzval 10 get fzsnum 0
167167 ret false
168168 end
169-for i ulong get fan 0 bound 64
169+for i ulong get fan 0 bound FAMAX
170170 if and eq i get fridx 0 fzsmatch i
171171 for k ulong 4
172-put fzcnt add mul k 64 i get fzval add k 1
172+put fzcnt add mul k FAMAX i get fzval add k 1
173173 end
174174 note Rendering uses global source timestamps, identical across all producer rows.
175175 for k ulong 3
@@ -185,9 +185,9 @@ end
185185 fn fzsparse n ulong to bool
186186 a = ulong 0
187187 line = ulong 0
188-for q ulong n bound 16384
188+for q ulong n bound 65536
189189 if eq get fzsbuf q 10
190-if or ge line 65 gt sub q a 256
190+if or gt line FAMAX gt sub q a 256
191191 ret false
192192 end
193193 nf = fzfields a q
@@ -237,7 +237,7 @@ if ne and mode 61440 32768
237237 ret -1
238238 end
239239 n = ulong 0
240-for tries ulong 16386
240+for tries ulong 65538
241241 if eq n len fzsbuf
242242 ret -1
243243 end
@@ -261,7 +261,7 @@ ret
261261 end
262262 n = fzscapture int fd
263263 c = fclose int fd
264-if or or le n 0 gt n 16384 ne c 0
264+if or or le n 0 gt n 65536 ne c 0
265265 ret
266266 end
267267 if not fzsparse ulong n
@@ -303,7 +303,7 @@ put fzhomel 0 0
303303 fzsync 0
304304 fzsync 1
305305 fzsync 2
306-for i ulong get fan 0 bound 64
306+for i ulong get fan 0 bound FAMAX
307307 fzseeds i
308308 end
309309 put fzjbl 0 0
@@ -311,7 +311,7 @@ fzjn 1
311311 fzjc 32
312312 fzjn div ulong realns 1000000000
313313 fzjc 10
314-for i ulong get fan 0 bound 64
314+for i ulong get fan 0 bound FAMAX
315315 for k ulong get fail i bound 64
316316 fzjc fridbyte i k
317317 end
@@ -332,7 +332,7 @@ fzjn get fzsdt i
332332 fzjc 10
333333 end
334334 outn = get fzjbl 0
335-if gt outn 16384
335+if gt outn 65536
336336 ret 4
337337 end
338338 w = write 1 fzjb 0 outn

server/counts.om

@@ -57,20 +57,20 @@ global fzsj ulong 4
5757 global fzspen ulong 4
5858 global fzz0 ulong 1
5959 global fzfail ulong 1
60-note fzcnt / fzpnd: committed / pending counts, index k*64 + repo, k 0 git fetch 1 upload-pack 2 archive 3 release asset
61-global fzcnt ulong 256
62-global fzpnd ulong 256
60+note fzcnt / fzpnd: committed / pending counts, index k*FAMAX + repo, k 0 git fetch 1 upload-pack 2 archive 3 release asset
61+global fzcnt ulong 1024
62+global fzpnd ulong 1024
6363 global fznev ulong 1
64-global fzjb uchar 65536
64+global fzjb uchar 131072
6565 global fzjbl ulong 1
6666 note fzjend: journal byte offset after the last committed cursor; any later bytes are abandoned.
6767 global fzjend ulong 1
6868 global fzhome uchar 64
6969 global fzhomel ulong 1
70-global fzsd ulong 64
71-global fzsdk ulong 64
72-global fzsdm ulong 64
73-global fzsdt ulong 64
70+global fzsd ulong 256
71+global fzsdk ulong 256
72+global fzsdm ulong 256
73+global fzsdt ulong 256
7474 note ---- small readers over fzbuf
7575 fn fzb i ulong to uchar
7676 ret get fzbuf i
@@ -155,7 +155,7 @@ end
155155 ret true
156156 end
157157 fn fzrix a ulong n ulong to ulong
158-for i ulong get fan 0 bound 64
158+for i ulong get fan 0 bound FAMAX
159159 if fzrideq i a n
160160 ret i
161161 end
@@ -189,7 +189,7 @@ end
189189 ret true
190190 end
191191 fn fznix a ulong n ulong dt ulong to ulong
192-for i ulong get fan 0 bound 64
192+for i ulong get fan 0 bound FAMAX
193193 if fznmeq i a n dt
194194 ret i
195195 end
@@ -354,7 +354,7 @@ fn fzev k ulong i ulong ep ulong to void
354354 if ge i get fan 0
355355 ret
356356 end
357-j = add mul k 64 i
357+j = add mul k FAMAX i
358358 put fzpnd j add get fzpnd j 1
359359 put fznev 0 add get fznev 0 1
360360 fzjc 101
@@ -572,7 +572,7 @@ i = fzrix add p 1 sub sub e p 1
572572 if ge i 9999
573573 ret
574574 end
575-j = add mul k 64 i
575+j = add mul k FAMAX i
576576 put fzpnd j add get fzpnd j 1
577577 put fznev 0 add get fznev 0 1
578578 end
@@ -585,14 +585,14 @@ end
585585 ret 9
586586 end
587587 fn fzcommit to void
588-for j ulong 256
588+for j ulong mul 4 FAMAX
589589 put fzcnt j add get fzcnt j get fzpnd j
590590 put fzpnd j 0
591591 end
592592 put fznev 0 0
593593 end
594594 fn fzdrop to void
595-for j ulong 256
595+for j ulong mul 4 FAMAX
596596 put fzpnd j 0
597597 end
598598 for s ulong 4
@@ -882,7 +882,7 @@ if fzboxed
882882 fzclear
883883 ret
884884 end
885-for j ulong 256
885+for j ulong mul 4 FAMAX
886886 put fzcnt j 0
887887 end
888888 fzdrop
@@ -894,7 +894,7 @@ put fzinit s 0
894894 put fzsnc s 0
895895 put fzsj s 0
896896 end
897-for i ulong 64
897+for i ulong FAMAX
898898 put fzsdk i 0
899899 end
900900 put fzfail 0 0
@@ -920,126 +920,41 @@ fzsync 1
920920 fzsync 2
921921 fzseeds i
922922 end
923-note ---- seeds: rad node routing --rid rad:<RID> --json, read again when the node database changed
924-text tfzenv "/usr/bin/env"
925-text tfzhenv "HOME=/home/drakestapleton"
926-text tfzrad "/home/drakestapleton/.radicle/bin/rad"
927-text tfznode "node"
928-text tfzrout "routing"
929-text tfzrid "--rid"
930-text tfzjson "--json"
931-text tfzradp "rad:"
932-text tfzwal "/home/drakestapleton/.radicle/node/node.db-wal"
933-text tfzrow "{\"rid\":\"rad:"
934-text tfznid "\"nid\":\""
935-fn fzwalk to ulong
936-fpb
937-fpt tfzwal
938-r = stat fpth 0 get fpthl 0 fzst 0 128
939-if lt r 0
940-ret 0
941-end
942-ret add mul fzle8 88 1000000000 fzle8 96
943-end
923+note fzseeds: the number of nodes seeding repo i from this node's routing table (fradseeds,
924+note server/radsrc.om), read again when the node database changed (fradwalk). The store-reading build
925+note has no routing table (fradsrc false): nothing runs or is read, and fzsdk stays 0 (not measured).
944926 fn fzseeds i ulong to void
945-key = fzwalk
927+if not fradsrc
928+ret
929+end
930+key = fradwalk
946931 if and ne get fzsdk i 0 and ne key 0 eq key get fzsdm i
947932 ret
948933 end
949934 put fzsdm i key
950-fkb
951-fka tfzenv
952-fka tfzhenv
953-fka tfzrad
954-fka tfznode
955-fka tfzrout
956-fka tfzrid
957-fkopen
958-fkt tfzradp
959-for k ulong get fail i bound 64
960-fkc fridbyte i k
961-end
962-fka tfzjson
963-st = fexec 5000000000
964-if ne st 0
935+n = fradseeds i
936+if lt n 0
965937 put fzsdk i 2
966938 ret
967939 end
968-put fzsd i fzrows i
940+put fzsd i ulong n
969941 put fzsdk i 1
970942 put fzsdt i div ulong realns 1000000000
971943 end
972-note fzrows: lines of fxo that are {"rid":"rad:<RID of i>",...,"nid":"...
973-fn fzrows i ulong to ulong
974-ln = get fxol 0
975-p = ulong 0
976-n = ulong 0
977-for it ulong 1000000
978-if ge p ln
979-break
980-end
981-e = fleol p ln
982-if fzrowok i p e
983-n = add n 1
984-end
985-p = add e 1
986-end
987-ret n
988-end
989-fn fzxpre a ulong e ulong t view uchar * to bool
990-if gt add a len t e
991-ret false
992-end
993-for k ulong len t bound 64
994-if ne get fxo add a k get t k
995-ret false
996-end
997-end
998-ret true
999-end
1000-fn fzrowok i ulong p ulong e ulong to bool
1001-if not fzxpre p e tfzrow
1002-ret false
1003-end
1004-a = add p len tfzrow
1005-l = get fail i
1006-if gt add a add l 2 e
1007-ret false
1008-end
1009-for k ulong l bound 64
1010-if ne get fxo add a k fridbyte i k
1011-ret false
1012-end
1013-end
1014-if ne get fxo add a l 34
1015-ret false
1016-end
1017-q = add add a l 1
1018-for it ulong sub e q bound 16777216
1019-if fzxpre q e tfznid
1020-ret true
1021-end
1022-q = add q 1
1023-end
1024-ret false
1025-end
1026944 note ---- output: the header lines (HTML) and the counts object (JSON)
1027945 fn fzc k ulong i ulong to ulong
1028-ret get fzcnt add mul k 64 i
946+ret get fzcnt add mul k FAMAX i
1029947 end
1030948 text tfzh1 "\n<p class=\"meta\">Clones and fetches over HTTPS: "
1031949 text tfzh2 " by visitors (git smart-HTTP <code>info/refs</code> requests answered 200 in the front-door download log; our own addresses and bots left out"
1032950 text tfzh3 ") &#183; "
1033-text tfzh4 " <code>git-upload-pack</code> requests from all clients, our own agents included (front-door access log; a clone is usually two"
951+text tfzh4 " <code>git-upload-pack</code> requests from all clients (the source of this count is retired"
1034952 text tfzh5 ")</p>\n<p class=\"meta\">Downloads: "
1035953 text tfzh6 " by visitors ("
1036954 text tfzh7 " source archives, "
1037955 text tfzh8 " release assets; forged access log; our own addresses left out"
1038-text tfzh9 ")</p>\n<p class=\"meta\">Radicle: "
1039-text tfzh10 "seeded by "
1040-text tfzh11 " nodes, this node included (this node's routing table, <code>rad node routing</code>; read "
1041-text tfzh12 " UTC)</p>\n"
1042-text tfzh13 "seeding <b>not measured</b> (<code>rad node routing</code> did not answer)</p>\n"
956+text tfzh9 ")</p>\n<p class=\"meta\">Seeding: <b>not measured</b> (the source of this count is retired)</p>\n"
957+text tfzh9s ")</p>\n"
1043958 text tfzh14 " (forged access log not read yet"
1044959 text tfzsn " since "
1045960 text tfznm "<b>not measured</b>"
@@ -1068,25 +983,16 @@ fzhn fzc 0 i 0
1068983 fput tfzh2
1069984 fzhs 0
1070985 fput tfzh3
1071-fzhn fzc 1 i 1
986+fput tfznm
1072987 fput tfzh4
1073-fzhs 1
1074988 fput tfzh5
1075989 fzhdl i
1076-fput tfzh9
1077-if ne get fzsdk i 1
1078-fput tfzh13
990+if not fradsrc
991+fput tfzh9s
1079992 ret
1080993 end
1081-fput tfzh10
1082-fput tfzb1
1083-fnum get fzsd i
1084-fput tfzb2
1085-fput tfzh11
1086-fzhtm get fzsdt i
1087-fput tfzh12
994+fput tfzh9
1088995 end
1089-note fzhtm: YYYY-MM-DD HH:MM
1090996 fn fzhdl i ulong to void
1091997 if eq get fzsnc 2 0
1092998 fput tfznm
@@ -1101,23 +1007,12 @@ fnum fzc 3 i
11011007 fput tfzh8
11021008 fzhs 2
11031009 end
1104-fn fzhtm t ulong to void
1105-s = rem t 86400
1106-fjday t
1107-fputc 32
1108-fj2 div s 3600
1109-fputc 58
1110-fj2 div rem s 3600 60
1111-end
11121010 text tfzj1 "{\n\"git_fetches\":{\"count\":"
11131011 text tfzjs "\"since\":"
1114-text tfzj2 ",\"source\":\"front-door nginx download log\",\"counts\":\"git smart-HTTP info/refs?service=git-upload-pack requests answered 200 (one per clone or fetch), /rad/<RID>.git and /code/git/<name>.git\",\"excludes\":\"our own addresses (loopback, LAN, tailnet, the home address of www.aienos.com) and user agents naming bot, crawl or spider\"},\n\"upload_pack_requests\":{\"count\":"
1115-text tfzj3 ",\"source\":\"front-door nginx access log\",\"counts\":\"POST /rad/<RID>.git/git-upload-pack answered 200 (a clone is usually two)\",\"excludes\":\"nothing: every client, our own agents included\"},\n\"downloads\":{\"count\":"
1012+text tfzj2 ",\"source\":\"front-door nginx download log\",\"counts\":\"git smart-HTTP info/refs?service=git-upload-pack requests answered 200 (one per clone or fetch), /code/git/<name>.git and the retired clone path\",\"excludes\":\"our own addresses (loopback, LAN, tailnet, the home address of www.aienos.com) and user agents naming bot, crawl or spider\"},\n\"upload_pack_requests\":{\"count\":null,\"since\":null,\"source\":\"retired\",\"counts\":\"not measured: the source of this count is retired\",\"excludes\":null},\n\"downloads\":{\"count\":"
11161013 text tfzj4 ",\"archives\":"
11171014 text tfzj5 ",\"release_assets\":"
1118-text tfzj6 ",\"source\":\"forged access log\",\"counts\":\"GET or HEAD of /<owner>/<repo>/archive/... and /releases/download/... answered 200\",\"excludes\":\"our own addresses (loopback, LAN, tailnet, the home address of www.aienos.com)\"},\n\"radicle_seeds\":{\"count\":"
1119-text tfzj7 ",\"as_of\":"
1120-text tfzj8 ",\"source\":\"this node's Radicle routing table (rad node routing --rid <RID> --json)\",\"counts\":\"nodes that announced they seed this repository, this node included\"}\n}"
1015+text tfzj6 ",\"source\":\"forged access log\",\"counts\":\"GET or HEAD of /<owner>/<repo>/archive/... and /releases/download/... answered 200\",\"excludes\":\"our own addresses (loopback, LAN, tailnet, the home address of www.aienos.com)\"},\n\"seeds\":{\"count\":null,\"as_of\":null,\"source\":\"retired\",\"counts\":\"not measured: the source of this count is retired\"}\n}"
11211016 fn fzjv v ulong s ulong to void
11221017 if eq get fzsnc s 0
11231018 fput tfjnull
@@ -1132,24 +1027,12 @@ fn fzjson i ulong to void
11321027 fput tfzj1
11331028 fzjv fzc 0 i 0
11341029 fput tfzj2
1135-fzjv fzc 1 i 1
1136-fput tfzj3
11371030 fzjv add fzc 2 i fzc 3 i 2
11381031 fput tfzj4
11391032 fzj0 fzc 2 i 2
11401033 fput tfzj5
11411034 fzj0 fzc 3 i 2
11421035 fput tfzj6
1143-if eq get fzsdk i 1
1144-fnum get fzsd i
1145-fput tfzj7
1146-fjiso get fzsdt i
1147-else
1148-fput tfjnull
1149-fput tfzj7
1150-fput tfjnull
1151-end
1152-fput tfzj8
11531036 end
11541037 fn fzj0 v ulong s ulong to void
11551038 if eq get fzsnc s 0

server/json.om

@@ -258,7 +258,7 @@ end
258258 note ---- fields shared by explore items and the repo object
259259 text tfjo1 "\"owner\":\""
260260 text tfjo2 "\",\"name\":"
261-text tfjo3 ",\"rid\":\"rad:"
261+text tfjo3 ",\"rid\":\""
262262 text tfjo4 "\",\"path\":\""
263263 text tfjo5 "\",\"json\":\""
264264 text tfjo6 ".json\",\"description\":"
@@ -330,7 +330,7 @@ fput tfjo2
330330 fjtname i
331331 fjstr
332332 fput tfjo3
333-fputrid i
333+fputid i
334334 fput tfjo4
335335 fjpath i
336336 fput tfjo5
@@ -370,7 +370,7 @@ fputb
370370 fput tfjex2
371371 fnum get fan 0
372372 fput tfjex3
373-for i ulong get fan 0 bound 64
373+for i ulong get fan 0 bound FAMAX
374374 if gt i 0
375375 fput tfjsep
376376 end
@@ -383,10 +383,6 @@ end
383383 note ---- /<owner>/<repo>.json (also /<owner>/<repo> with Accept: application/json)
384384 text tfjr1 "{\"schema\":\"forge/repo/1\",\n"
385385 text tfjr2 ",\n\"favorites\":"
386-text tfjcl1 ",\n\"clone\":{\"rad\":\"rad:"
387-text tfjcl2 "\",\"rad_clone\":\"rad clone rad:"
388-text tfjcl3 "\",\"git_https\":\"https://www.aienos.com/rad/"
389-text tfjcl4 ".git\"}"
390386 text tfjar1 ",\n\"archives\":{\"zip\":\""
391387 text tfjarh "/archive/refs/heads/"
392388 text tfjar2 ".zip\",\"tar_gz\":\""
@@ -400,13 +396,7 @@ fput tfjr1
400396 fjcore i
401397 fput tfjr2
402398 fnum sofavn i
403-fput tfjcl1
404-fputrid i
405-fput tfjcl2
406-fputrid i
407-fput tfjcl3
408-fputrid i
409-fput tfjcl4
399+fjclone i
410400 fput tfjar1
411401 fjarch i
412402 fput tfjar2

server/jsonp.om

@@ -8,12 +8,13 @@ text tfyuser "forge/user/1"
88 text tfyerr1 "{\"schema\":\"forge/error/1\",\"status\":"
99 text tfyerr2 ",\"error\":"
1010 text tfyerr3 ",\"message\":"
11+text tfyrmvg ",\"reason\":\"moving\""
1112 text tfyend "}\n"
1213 text tfyh1 "{\"schema\":\""
1314 text tfyh2 "\",\"base\":\""
1415 text tfyh3 "\",\"repo\":{\"owner\":\""
1516 text tfyh4 "\",\"name\":\""
16-text tfyh5 "\",\"rid\":\"rad:"
17+text tfyh5 "\",\"rid\":\""
1718 text tfyh6 "\",\"path\":\""
1819 text tfyh7 "\",\"json\":\""
1920 text tfyh8 ".json\"}"
@@ -43,6 +44,9 @@ fjtc get fob add a k
4344 end
4445 put fobl 0 a
4546 fjstr
47+if and eq st 503 ne get fmvng 0 0
48+fput tfyrmvg
49+end
4650 fput tfyend
4751 end
4852 note fyrhead t: open a repo page document: {"schema":"<t>","base":"<base>","repo":{owner, name, rid,
@@ -61,7 +65,7 @@ for k ulong get fanl i bound 128
6165 fputc frnbyte i k
6266 end
6367 fput tfyh5
64-fputrid i
68+fputid i
6569 fput tfyh6
6670 fjpath i
6771 fput tfyh7
@@ -179,7 +183,7 @@ text tfysr3 ",\n\"repos\":["
179183 text tfysr4 "],\n\"code\":["
180184 text tfysr5 "],\n\"code_truncated\":"
181185 text tfysc1 "{\"repo\":"
182-text tfysc2 ",\"rid\":\"rad:"
186+text tfysc2 ",\"rid\":\""
183187 text tfysc3 "\",\"path\":"
184188 text tfysc4 ",\"line\":"
185189 text tfysc5 ",\"text\":"
@@ -205,7 +209,7 @@ end
205209 fput tfysr3
206210 n = ulong 0
207211 if gt q 0
208-for i ulong get fan 0 bound 64
212+for i ulong get fan 0 bound FAMAX
209213 if fsrmatch i
210214 if gt n 0
211215 fput tfjsep
@@ -220,7 +224,7 @@ end
220224 fput tfysr4
221225 put fhits 0 0
222226 if gt q 0
223-for i ulong get fan 0 bound 64
227+for i ulong get fan 0 bound FAMAX
224228 if lt get fhits 0 100
225229 fyjcsr i
226230 end
@@ -273,7 +277,7 @@ fput tfysc1
273277 fjtname i
274278 fjstr
275279 fput tfysc2
276-fputrid i
280+fputid i
277281 fput tfysc3
278282 fjfx a sub c1 a
279283 fput tfysc4
@@ -317,7 +321,7 @@ fnum sofolln
317321 fput tfypr3
318322 fnum sofollg
319323 fput tfypr4
320-for i ulong get fan 0 bound 64
324+for i ulong get fan 0 bound FAMAX
321325 if gt i 0
322326 fput tfjsep
323327 end

server/main.om

@@ -34,6 +34,9 @@ text tfcsp "default-src 'none'; style-src 'self'; img-src 'self'; script-src 'no
3434 text tfnosnf "nosniff"
3535 text tfsameo "same-origin"
3636 text tfnostor "no-store"
37+text tfnaxp "X-Accel-Expires"
38+text tfezero "0"
39+global fepnoc ulong 1
3740 text tfcspsb "sandbox; default-src 'none'; script-src 'none'; img-src 'self'; style-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'"
3841 text tfnra "Retry-After"
3942 text tfhtml "text/html; charset=utf-8"
@@ -205,12 +208,17 @@ if hismeth cs io tfpost
205208 put fmeth 0 3
206209 end
207210 end
208-note freqbody: read a POST body (cap 64 KiB) into fbody; returns 0 or the status to answer
211+note freqbody: read a POST body (cap 64 KiB) into fbody; returns 0 or the status to answer. The one
212+note path with a larger body, .../patches/new, goes through freqbig into fbig (cap 3 MiB).
209213 fn freqbody cs edit ulong 320 io edit uchar 131072 bd edit uchar 65536 to ulong
210214 put fbodyl 0 0
215+put fbigl 0 0
211216 if ne get fmeth 0 3
212217 ret 0
213218 end
219+if fbigrt
220+ret freqbig cs io bd
221+end
214222 put cs HBCAP 65536
215223 n = hbodyall cs io bd
216224 if lt n 0
@@ -225,6 +233,62 @@ end
225233 put fbodyl 0 ulong n
226234 ret 0
227235 end
236+text tfpnew "/patches/new"
237+note fbigrt: reserve the larger body only for /<owner>/<repo>/patches/new
238+fn fbigrt to bool
239+n = get fpathl 0
240+m = len tfpnew
241+if or lt n add m 4 ne get fpath 0 47
242+ret false
243+end
244+start = sub n m
245+e1 = fsegend 1
246+rstart = add e1 1
247+if or le e1 1 ge rstart start
248+ret false
249+end
250+if ne fsegend rstart start
251+ret false
252+end
253+for i ulong m bound 16
254+if ne get fpath add start i get tfpnew i
255+ret false
256+end
257+end
258+ret true
259+end
260+note freqbig: the body into fbig through the 64 KiB chunk bd; 413 when it passes 3 MiB
261+fn freqbig cs edit ulong 320 io edit uchar 131072 bd edit uchar 65536 to ulong
262+put cs HBCAP 3145728
263+got = ulong 0
264+for it ulong 4194304
265+r = hbodyrd cs io bd
266+if lt r 0
267+if eq r HEBIG
268+ret 413
269+end
270+ret 400
271+end
272+if eq r 0
273+put fbigl 0 got
274+ret 0
275+end
276+if gt add got ulong r len fbig
277+put cs HKEEP 0
278+ret 413
279+end
280+for i ulong ulong r bound 65536
281+put fbig add got i get bd i
282+end
283+got = add got ulong r
284+end
285+put cs HKEEP 0
286+ret 413
287+end
288+note Opt mutable application pages out of the shared edge cache.
289+fn fsetepno to void
290+put fepnoc 0 1
291+end
228292 fn fresetr to void
229293 put fobl 0 0
230294 put fobtr 0 0
@@ -250,6 +314,8 @@ put frepol 0 0
250314 put frestl 0 0
251315 put fretry 0 0
252316 put fcspsb 0 0
317+put fepnoc 0 0
318+put fmvng 0 0
253319 put fjalt 0 0
254320 end
255321 note ---- response writing
@@ -317,6 +383,9 @@ end
317383 r = hfe r fhdrt cs io tfnxcto tfnosnf
318384 r = hfe r fhdrt cs io tfnref tfsameo
319385 r = hfe r fhdrg cs io tfnsck 3
386+if ne get fepnoc 0 0
387+r = hfe r fhdrt cs io tfnaxp tfezero
388+end
320389 if ne get fretry 0 0
321390 r = hfe r hhname cs io tfnra
322391 r = hfe r hhnum cs io get fretry 0
@@ -777,6 +846,10 @@ ret
777846 end
778847 hsettmo cs 15000000000 15000000000
779848 hsetbdl cs 60000000000
849+note http.om refuses a Content-Length above HBCAP when it reads the head (413), before the path is
850+note known here: the head-time cap is the patch intake's 3 MiB, and freqbody sets 64 KiB for every
851+note other POST before it reads the body
852+put cs HBCAP 3145728
780853 for k ulong 100
781854 r = hreqrd cs io
782855 if le r 0
@@ -786,6 +859,7 @@ end
786859 break
787860 end
788861 r = fhandle cs io bd
862+put cs HBCAP 3145728
789863 if lt r 0
790864 break
791865 end
@@ -795,14 +869,21 @@ end
795869 end
796870 r = hclose cs
797871 end
798-note ---- reload: allow-list + social log
872+note ---- reload: allow-list + social log. fload gives a negative count when the source could not be
873+note read or was refused (fan is 0, every repository URL is 404); the log line then says 0. Before
874+note 2026-11-13 the negative count went through `ulong n`, which traps 5 (exit 105), so an unreadable
875+note RIDS.md stopped forged instead of serving nothing.
799876 fn freload to void
800877 n = fload
801878 fzload
802879 x = soload
803880 flog tfrld
804881 put flgl 0 0
805-flgn ulong n
882+c = ulong 0
883+if gt n 0
884+c = ulong n
885+end
886+flgn c
806887 flgc 10
807888 w = write 2 flg 0 get flgl 0
808889 end
@@ -819,10 +900,7 @@ x = unlink fpth 0 get fpthl 0
819900 freload
820901 ret
821902 end
822-fpb
823-fpt tfrids
824-m = fmtime
825-if ne m get famt 0
903+if fsrcchg
826904 freload
827905 end
828906 end

server/nodoor.om

new file mode 100644
@@ -0,0 +1,22 @@
1+note server/nodoor.om: the seam of door/ (the event stream and the feed) for a build that does not
2+note compose it (door/READY missing, or collab/ or social/ not composed, as in a store-reading build):
3+note <base>events.json, <base>events and <base>feed answer 501, the forge row has no Feed entry, and
4+note agents.json lists those addresses under not_available.
5+text tevpj "/events.json"
6+text tevpe "/events"
7+text tevpf "/feed"
8+fn evroute to long
9+if fpeq tevpj
10+fqajsn
11+ret 501
12+end
13+if or fpeq tevpe fpeq tevpf
14+ret 501
15+end
16+ret 0
17+end
18+fn evnav to void
19+end
20+fn evon to bool
21+ret false
22+end

server/noissuewrite.om

new file mode 100644
@@ -0,0 +1,17 @@
1+note Store reads can be composed without the social slice.
2+fn niwform k ulong opening bool to void
3+end
4+fn niwlink to void
5+end
6+fn niwnew to long
7+ret 404
8+end
9+fn niwpost opening bool to long
10+ret 404
11+end
12+fn niwnewjson to void
13+fynull
14+end
15+fn niwcform to long
16+ret 404
17+end

server/nopatch.om

new file mode 100644
@@ -0,0 +1,12 @@
1+note server/nopatch.om: seam used when patch/ is not composed (no READY file, or social or browse is
2+note a seam). /patches stays unclaimed (501 "coming" from server/route.om) and no upload is taken.
3+fn paroute to long
4+ret 0
5+end
6+fn paunl to long
7+ret 0
8+end
9+note pacount: patches of the repository fridx; 9999 = not measured (growth/g1prep.om grpatch)
10+fn pacount to ulong
11+ret 9999
12+end

server/nostat.om

new file mode 100644
@@ -0,0 +1,14 @@
1+note server/nostat.om: the seam of nodes/stat.om (<base>status and <base>status.json, the health of this
2+note forge's own Radicle node) for the store-reading build, which has no such node: its snapshot file
3+note (~/.local/state/aien-factory/nodes.txt) is left over from the node removed on 2026-11-14 and
4+note describes Radicle copies of the old ids, not anything this build serves. Both addresses answer 501
5+note (forge/error/1 for status.json), and agents.json lists status.json under not_available (run.sh
6+note agentsgen: the "nodes" part is composed only with server/radsrc.om).
7+text tfst "/status"
8+text tfstj "/status.json"
9+fn nsstat to long
10+if fpeq tfstj
11+fqajsn
12+end
13+ret 501
14+end

server/pages.om

@@ -17,6 +17,7 @@ text tfh3b "</head>\n<body><a class=\"skip\" href=\"#main\">Skip to content</a>"
1717 text tfhal1 "<link rel=\"alternate\" type=\"application/json\" href=\""
1818 text tfhal2 "explore.json"
1919 text tfhal3 ".json"
20+text tfhal4 "events.json"
2021 note ---- the site chrome: the interplane.io header and footer and their stylesheet lines are not kept
2122 note here. server/chromegen.om makes them at every build from the site's own source (canonical main of
2223 note rad:z399yKvnXcBQNkKoq86iBDgTvQ5QV, content/_layout.html and public/style.css) into the generated
@@ -43,7 +44,6 @@ text tfso2 "\"><input type=\"hidden\" name=\"csrf\" value=\""
4344 text tfso3 "\"><button type=\"submit\">Sign out</button></form>"
4445 text tfh8 "</div></div></div>\n<main id=\"main\" tabindex=\"-1\">\n"
4546 text tff1 "\n</main>\n<footer class=\"site-foot\"><div class=\"shell\">\n"
46-text tfsf4 "<p class=\"foot-fine\">INTERPLANE Forge: agents express intent; the forge retains authority. Built on Radicle (Heartwood): repositories are Radicle projects served by forged, a seeded-Omega web server, with no JavaScript.</p>\n<p class=\"foot-fine\"><a href=\""
4747 text tff2 "\">Explore</a> &#183; <a href=\""
4848 text tff3 "\">Search</a> &#183; <a href=\""
4949 text tfstars "stars"
@@ -66,8 +66,8 @@ text tfm429 "Too many write requests from this address. Wait a minute and try ag
6666 text tfm500 "The forge hit an internal error serving this page."
6767 text tfm501 "Coming soon. This part of the forge is being built and is not served yet; the feature list says what works today."
6868 text tfmoth "The forge could not serve this request."
69-text tfmicut "The stored data behind this page is larger than the forge reads in one piece, so an answer built from it would have been incomplete. The forge sent this notice and no part of it. The data is whole in the repository: read it with git or rad."
70-text tfmovf "This page is too large for the forge to send in one piece (the limit is 8 MiB), so the forge sent this notice and no part of the page. The data is whole in the repository: read it with git or rad."
69+text tfmicut "The stored data behind this page is larger than the forge reads in one piece, so an answer built from it would have been incomplete. The forge sent this notice and no part of it. The data is whole in the repository: read it with git."
70+text tfmovf "This page is too large for the forge to send in one piece (the limit is 8 MiB), so the forge sent this notice and no part of the page. The data is whole in the repository: read it with git."
7171 text tfctj "application/json"
7272 note fovf: 0, or why this response is the too-large notice (1 page, 2 JSON document); flay: the
7373 note lengths of the fragment, the head and the foot of a page (flayout)
@@ -81,6 +81,8 @@ text tft413 "Too large"
8181 text tft429 "Slow down"
8282 text tft500 "Server error"
8383 text tft501 "Coming soon"
84+text tftmvg "Moving"
85+text tfmmvg "This part is moving to the new Interplane store and is not available yet."
8486 fn ferrmsg st ulong to void
8587 if ne get fovf 0 0
8688 if ne get ficut 0 0
@@ -90,6 +92,10 @@ end
9092 fput tfmovf
9193 ret
9294 end
95+if and eq st 503 ne get fmvng 0 0
96+fput tfmmvg
97+ret
98+end
9399 if eq st 400
94100 fput tfm400
95101 ret
@@ -125,6 +131,10 @@ end
125131 fput tfmoth
126132 end
127133 fn ferrti st ulong to void
134+if and eq st 503 ne get fmvng 0 0
135+fsetti tftmvg
136+ret
137+end
128138 if eq st 400
129139 fsetti tft400
130140 ret
@@ -289,6 +299,7 @@ note each slice may add one entry to the forge row (its seam adds nothing)
289299 ohnav
290300 slnav
291301 rxnav
302+evnav
292303 fput tfh5b
293304 fputb
294305 fput tfsrch
@@ -298,13 +309,20 @@ fput tfh7
298309 fwho
299310 fput tfh8
300311 end
301-note fhalt: the page's JSON form (docs/API.md): 1 explore, 2 the repo home, 3 the page's own URL
312+note fhalt: the page's JSON form (docs/API.md): 1 explore, 2 the repo home, 3 the page's own URL,
313+note 4 the event stream (door/ev5feed.om, the feed page)
302314 fn fhalt to void
303315 k = get fjalt 0
304316 if eq k 0
305317 ret
306318 end
307319 fput tfhal1
320+if eq k 4
321+fputb
322+fput tfhal4
323+fput tfqgt
324+ret
325+end
308326 if eq k 3
309327 fhself
310328 fput tfqgt
@@ -378,7 +396,7 @@ text tfcss7 ".crumbs{margin:8px 0;font-size:15px}.ref{display:inline-block;paddi
378396 text tfcss8 ".commits{list-style:none;padding:0;margin:0;border:1px solid var(--line);border-radius:6px}.commits li{padding:8px 12px;border-bottom:1px solid var(--line)}.commits li:last-child{border-bottom:0}\n.box.commit h2{margin:0 0 6px;font-size:18px}pre.msg{white-space:pre-wrap;background:none;border:0;padding:0;margin:6px 0}.stat{font-size:13px;color:var(--mut)}table.stat{width:auto}table.stat td{padding:2px 8px}\n.df{border:1px solid var(--line);border-radius:6px;margin:14px 0;overflow-x:auto}.dfh{padding:6px 12px;background:var(--box);border-bottom:1px solid var(--line);font-family:ui-monospace,Menlo,monospace;font-size:13px}\ntable.diff{font-family:ui-monospace,Menlo,monospace;font-size:13px}table.diff td{border:0;padding:0 8px}td.dc{white-space:pre}tr.da{background:rgba(0,210,148,.15)}tr.dd{background:rgba(255,101,104,.15)}tr.dh,tr.dm{background:var(--box);color:var(--mut)}\ntable.refs td{white-space:nowrap}.badge{display:inline-block;padding:0 8px;border:1px solid var(--acc);border-radius:10px;font-size:12px;color:var(--acc);margin-left:6px}\ntable.code.blame td.bl{white-space:nowrap;color:var(--mut);font-size:12px;border-right:1px solid var(--line);width:1%}tr.bs td{border-top:1px solid var(--line)}p.hit{margin:2px 0}form.inline{display:inline}\n"
379397 note tfcss9: the project page (server/state.om, frepohd, the "For developers" section) and the marker
380398 note of a README link that leaves the site (browse/b_md.om class "ext")
381-text tfcss9 ".pj-head h1{font-size:34px;line-height:1.15;margin:4px 0 6px;font-weight:700}.pj-head h1 a{color:var(--ink);text-decoration:none}.pj-head h1 a.rname,.pj-by a.rname{font-size:inherit;font-weight:inherit}.pj-head .desc{font-size:19px;margin:0 0 6px;max-width:44em}.pj-by{color:var(--mut);font-size:15px;margin:0 0 10px}\n.state{margin:6px 0 2px;font-size:16px}.state b{display:inline-block;padding:1px 10px;border-radius:999px;margin-right:6px;font-size:14px}.state.ok b{background:var(--panel);color:var(--ok)}.state.no b{background:var(--panel);color:var(--ink)}.state-more{font-size:14px;color:var(--mut);margin:2px 0 8px;max-width:48em}\n.pj-get{display:flex;flex-wrap:wrap;align-items:center;gap:8px 14px;margin:14px 0 6px}.pj-btn{display:inline-flex;align-items:center;min-height:44px;padding:8px 22px;border-radius:var(--r2);background:var(--btn-dark-bg);color:var(--btn-dark-ink);font-weight:700;text-decoration:none}.pj-btn:hover{background:var(--btn-dark-hover);color:var(--btn-dark-ink)}.pj-btn:active{background:var(--btn-dark-press)}.pj-what{color:var(--mut);font-size:14px;max-width:36em}\n.pj-tabs+.readme{border:0;padding:0;margin-top:8px}.pj-tabs+.readme .md{font-size:18px;line-height:1.65}.pj-nordme{font-size:17px;margin:16px 0 8px}\n.pj-dev{margin-top:40px;padding-top:18px;border-top:2px solid var(--line)}.pj-dev h2{font-size:24px;margin:0 0 6px}.pj-terms{display:grid;grid-template-columns:max-content 1fr;gap:6px 16px;margin:10px 0 16px;font-size:15px}.pj-terms dt{font-weight:700}.pj-terms dd{margin:0;overflow-wrap:anywhere}.pj-recs{margin:16px 0}\n.repos .state{font-size:14px;margin:4px 0}.repos .meta .stars{float:none;display:inline}\n.md a.ext::after{content:\" \\2197\";content:\" \\2197\" / \" (leaves this site)\"}\n@media (max-width:640px){.pj-head h1{font-size:28px}.pj-head .desc{font-size:17px}.pj-terms{grid-template-columns:1fr}.pj-terms dd{margin-bottom:8px}}\n"
399+text tfcss9 ".pj-head h1{font-size:34px;line-height:1.15;margin:4px 0 6px;font-weight:700}.pj-head h1 a{color:var(--ink);text-decoration:none}.pj-head h1 a.rname,.pj-by a.rname{font-size:inherit;font-weight:inherit}.pj-head .desc{font-size:19px;margin:0 0 6px;max-width:44em}.pj-by{color:var(--mut);font-size:15px;margin:0 0 10px}\n.state{margin:6px 0 2px;font-size:16px}.state b{display:inline-block;padding:1px 10px;border-radius:999px;margin-right:6px;font-size:14px}.state.ok b{background:var(--panel);color:var(--ok)}.state.no b{background:var(--panel);color:var(--ink)}.state-more{font-size:14px;color:var(--mut);margin:2px 0 8px;max-width:48em}\n.pj-get{margin:14px 0 6px}.pj-get summary{cursor:pointer}.pj-get summary::after{content:\" ▾\"}.pj-get[open] summary::after{content:\" ▴\"}.pj-get code{user-select:all;overflow-wrap:anywhere}.pj-get dd{margin-inline-start:0}.pj-btn{display:inline-flex;align-items:center;min-height:44px;padding:8px 22px;border-radius:var(--r2);background:var(--btn-dark-bg);color:var(--btn-dark-ink);font-weight:700;text-decoration:none}.pj-btn:hover{background:var(--btn-dark-hover);color:var(--btn-dark-ink)}.pj-btn:active{background:var(--btn-dark-press)}.pj-what{color:var(--mut);font-size:14px;max-width:36em}\n.pj-tabs+.readme{border:0;padding:0;margin-top:8px}.pj-tabs+.readme .md{font-size:18px;line-height:1.65}.pj-nordme{font-size:17px;margin:16px 0 8px}\n.pj-dev{margin-top:40px;padding-top:18px;border-top:2px solid var(--line)}.pj-dev h2{font-size:24px;margin:0 0 6px}.pj-terms{display:grid;grid-template-columns:max-content 1fr;gap:6px 16px;margin:10px 0 16px;font-size:15px}.pj-terms dt{font-weight:700}.pj-terms dd{margin:0;overflow-wrap:anywhere}.pj-recs{margin:16px 0}\n.repos .state{font-size:14px;margin:4px 0}.repos .meta .stars{float:none;display:inline}\n.md a.ext::after{content:\" \\2197\";content:\" \\2197\" / \" (leaves this site)\"}\n@media (max-width:640px){.pj-head h1{font-size:28px}.pj-head .desc{font-size:17px}.pj-terms{grid-template-columns:1fr}.pj-terms dd{margin-bottom:8px}}\n"
382400 fn fcssout to void
383401 put fkind 0 1
384402 fsetct tfctcss
@@ -461,7 +479,7 @@ fpjload
461479 fput tfex1
462480 fnum get fan 0
463481 fput tfex2
464-for i ulong get fan 0 bound 64
482+for i ulong get fan 0 bound FAMAX
465483 frepoli i
466484 end
467485 fput tfulend
@@ -481,14 +499,14 @@ text tfpr9 ")</h2>\n<ul class=\"repos\">\n"
481499 text tfpr10 "<h2>Starred</h2>\n"
482500 fn fstarsum to ulong
483501 s = ulong 0
484-for i ulong get fan 0 bound 64
502+for i ulong get fan 0 bound FAMAX
485503 s = add s sostarn i
486504 end
487505 ret s
488506 end
489507 fn ffavsum to ulong
490508 s = ulong 0
491-for i ulong get fan 0 bound 64
509+for i ulong get fan 0 bound FAMAX
492510 s = add s sofavn i
493511 end
494512 ret s
@@ -521,7 +539,7 @@ fput tfpr8
521539 fnum get fan 0
522540 fput tfpr9
523541 fpjload
524-for i ulong get fan 0 bound 64
542+for i ulong get fan 0 bound FAMAX
525543 frepoli i
526544 end
527545 fput tfulend
@@ -531,8 +549,8 @@ end
531549 note Project and owner names carry class rname: server/tr.om marks that class translate="no" when it
532550 note sends the page, so the page holds no hint of its own (fob sizes stay exact; server/tests/overflow.sh).
533551 note ---- repo header: a short friendly header (name, the plain sentence, who brought it; on the repo
534-note home also the state and one action to get it), then the tabs. Words for developers (the Radicle
535-note ID, the clone command, the counts) are in the "For developers" section of the repo home
552+note home also the state and one action to get it), then the tabs. Words for developers (the
553+note project id, the clone notice, the counts) are in the "For developers" section of the repo home
536554 note (fpjdev1 / fpjdev2), whose stable address is <repo>#For-developers. The id has an upper-case
537555 note letter, so no README heading anchor (browse/b_md.om brmslug: lower case only) can take it.
538556 text tfrh1 "<section class=\"rhead pj-head\"><h1><a class=\"rname\" href=\""
@@ -562,9 +580,6 @@ text tfpdev "#For-developers"
562580 text tfpjson ".json"
563581 text tfpzip "/archive/refs/heads/"
564582 text tfpzipx ".zip"
565-text tfget1 "<p class=\"pj-get\"><a class=\"pj-btn\" href=\""
566-text tfget2 "\">Get it</a> <span class=\"pj-what\">The newest release, each file with its SHA-256 fingerprint</span></p>\n"
567-text tfget3 "\">Get it</a> <span class=\"pj-what\">All of its files, as one zip</span></p>\n"
568583 text tfget4 "<p class=\"pj-get pj-what\">Nothing to download yet.</p>\n"
569584 note fpjempty: set by frepohome: the page has no files to offer (no zip link)
570585 global fpjempty ulong 1
@@ -604,7 +619,11 @@ if and home ok
604619 put fjalt 0 2
605620 fpjload
606621 fpjfull i
607-fpjget i
622+if ne get fpjempty 0 0
623+fput tfget4
624+else
625+dlclone
626+end
608627 end
609628 fput tfrh5
610629 sobar
@@ -637,34 +656,11 @@ ftab 6 on tfpiss tfiss
637656 ftab 20 on tfpdev tfdevt
638657 fput tfrh7
639658 end
640-note fpjget: the one primary action of the repo home: the releases page when the project has a tag
641-note (dl/dl.om dlanytag), else the zip of the default branch
642-fn fpjget i ulong to void
643-if ne get fpjempty 0 0
644-fput tfget4
645-ret
646-end
647-fput tfget1
648-fputrl
649-if dlanytag
650-fput tfprel
651-fput tfget2
652-ret
653-end
654-fput tfpzip
655-fputbr i
656-fput tfpzipx
657-fput tfget3
658-end
659659 note ---- the "For developers: proof and records" section of the repo home. fpjdev1 opens it: the
660660 note words that are kept off the top of the page, each with one line of explanation, then the counts
661661 note (server/counts.om fzhtml). The caller adds the branch bar, the clone panel, the newest commit and
662662 note the file list, then fpjdev2 closes it with a link to every record page.
663663 text tfdv1 "<section class=\"pj-dev\" id=\"For-developers\" tabindex=\"-1\" aria-labelledby=\"pj-dev-h\"><h2 id=\"pj-dev-h\">For developers: proof and records</h2>\n<p class=\"pj-lead\">The full record of this project. Words that are used only here are explained once:</p>\n<dl class=\"pj-terms\">\n"
664-text tfdv2 "<dt>RID</dt><dd>The Radicle ID: the project's permanent name on Radicle, the open network that stores and signs it. This one is <code>rad:"
665-text tfdv3 "</code>.</dd>\n<dt>Delegate</dt><dd>A key that may sign the project's official versions. This forge lists the project under "
666-text tfdv4 "; <code>rad inspect rad:"
667-text tfdv5 " --delegates</code> prints the project's own list.</dd>\n<dt>Seed</dt><dd>A Radicle node that keeps a copy of the project and serves it to others. The count below is read from this node's routing table.</dd>\n<dt>Refs and HEAD</dt><dd>Refs are the names that point at versions: branches and tags. HEAD is the version a fresh copy starts from, the newest commit of the default branch.</dd>\n<dt>Patch</dt><dd>A proposed change, sent over Radicle and reviewed before it is merged. The list is under <a href=\""
668664 text tfdv6 "\">Proposed changes</a>.</dd>\n<dt>Receipt</dt><dd>A public record that someone checked a claim, with the fingerprint of its evidence file. The state at the top of this page is read from the list at <a href=\"https://interplane.io/receipts/\">interplane.io/receipts</a>. "
669665 text tfdv6b "</dd>\n</dl>"
670666 text tfdv7 "<p class=\"pj-recs\">Every record: <a href=\""
@@ -676,21 +672,10 @@ text tfdv12 "\">Patches</a> &#183; <a href=\""
676672 text tfdv13 "\">Issues</a> &#183; <a href=\""
677673 text tfdv14 "\">This project as JSON</a></p>\n</section>\n"
678674 text tfdvnl "\n"
679-fn fpjrid to void
680-for k ulong get fridl 0 bound 64
681-fescc get frid k
682-end
683-end
684675 fn fpjdev1 to void
685676 i = get fridx 0
686677 fput tfdv1
687-fput tfdv2
688-fpjrid
689-fput tfdv3
690-fputown
691-fput tfdv4
692-fpjrid
693-fput tfdv5
678+fpjterms
694679 fputrl
695680 fput tfppat
696681 fput tfdv6
@@ -746,7 +731,6 @@ fputbr i
746731 fput tfrhm2
747732 fputlc i
748733 fput tfrhm3
749-dlclone
750734 fpjdev2
751735 end
752736 note ---- /search?q=: repo names and descriptions (case-insensitive), then code via git grep
@@ -817,7 +801,7 @@ fput tfsr2
817801 ret
818802 end
819803 n = ulong 0
820-for i ulong get fan 0 bound 64
804+for i ulong get fan 0 bound FAMAX
821805 if fsrmatch i
822806 n = add n 1
823807 end
@@ -830,7 +814,7 @@ fput tfsr5
830814 else
831815 fpjload
832816 fput tfulrep
833-for i ulong get fan 0 bound 64
817+for i ulong get fan 0 bound FAMAX
834818 if fsrmatch i
835819 frepoli i
836820 end

server/radsrc.om

new file mode 100644
@@ -0,0 +1,300 @@
1+note forged server/radsrc.om: the Radicle source of the default build (the live binary), composed after
2+note server/repos.om (the shared allow-list helpers and per-repo metadata). It defines what a
3+note repository source gives the rest of forged: fload (the public allow-list), fsrcchg (the source
4+note changed: reload), fputid (a repository's identifier in machine forms), fhasal (it has an old
5+note Radicle id), fradsrc (Radicle node data may be read) with fradwalk / fradseeds (the routing
6+note table), fpjterms (the identity words of the "For developers" section), fjclone (the JSON clone
7+note object) and tfsf4 (the footer line). Git paths are server/util.om fkgit / fkgiti (tfstore + RID).
8+note The store-reading build composes store/repos.om in place of this unit (run.sh units, FORGE_STORE).
9+note Allow-list: the FIRST table of ~/handoffs/radicle/RIDS.md (header "| repo | RID | default
10+note branch"). A row is kept only when the name, RID and branch are well formed and
11+note ~/.radicle/storage/<rid> exists. Fail closed: when the file cannot be read or has no table, fan
12+note is 0 and every repo URL is 404.
13+text tfrids "/home/drakestapleton/handoffs/radicle/RIDS.md"
14+text tfthd "| repo | RID | default branch"
15+fn flmat s ulong ln ulong to bool
16+if gt add s len tfthd ln
17+ret false
18+end
19+for k ulong len tfthd bound 64
20+if ne get fxo add s k get tfthd k
21+ret false
22+end
23+end
24+ret true
25+end
26+fn flfind ln ulong to ulong
27+p = ulong 0
28+for it ulong 100000
29+if ge p ln
30+ret ln
31+end
32+if flmat p ln
33+ret p
34+end
35+p = flnext p ln
36+end
37+ret ln
38+end
39+fn flbar p ulong e ulong to ulong
40+j = p
41+while lt j e bound 16777216
42+if eq get fxo j 124
43+ret j
44+end
45+j = add j 1
46+end
47+ret e
48+end
49+fn fidput k ulong a ulong b ulong to bool
50+s = ftrs a b
51+t = ftre s b
52+if lt sub t s 6
53+ret false
54+end
55+if or ne get fxo s 114 ne get fxo add s 1 97
56+ret false
57+end
58+if or ne get fxo add s 2 100 ne get fxo add s 3 58
59+ret false
60+end
61+s = add s 4
62+n = sub t s
63+if gt n 60
64+ret false
65+end
66+cur = fidcur k
67+if gt add cur n len faid
68+ret false
69+end
70+put faio k cur
71+put fail k n
72+for i ulong n bound 64
73+c = get fxo add s i
74+if not fisaln c
75+ret false
76+end
77+put faid add cur i c
78+end
79+ret true
80+end
81+note fstok: ~/.radicle/storage/<rid of k> exists
82+fn fstok k ulong to bool
83+fpb
84+fpt tfstore
85+for i ulong get fail k bound 64
86+fpc fridbyte k i
87+end
88+r = stat fpth 0 get fpthl 0 fstb 0 128
89+ret ge r 0
90+end
91+fn frow p ulong e ulong to void
92+b1 = flbar add p 1 e
93+b2 = flbar add b1 1 e
94+b3 = flbar add b2 1 e
95+if ge b3 e
96+ret
97+end
98+k = get fan 0
99+if ge k FAMAX
100+ret
101+end
102+if not fnmput k add p 1 b1
103+ret
104+end
105+if not fidput k add b1 1 b2
106+ret
107+end
108+if not fbrput k add b2 1 b3
109+ret
110+end
111+put fan 0 add k 1
112+end
113+fn fload to long
114+put fan 0 0
115+fpb
116+fpt tfrids
117+put famt 0 fmtime
118+n = frdall
119+if le n 0
120+ret -1
121+end
122+ln = ulong n
123+p = flfind ln
124+if ge p ln
125+ret -2
126+end
127+p = flnext p ln
128+p = flnext p ln
129+for it ulong FAMAX
130+if ge p ln
131+break
132+end
133+if ne get fxo p 124
134+break
135+end
136+e = fleol p ln
137+frow p e
138+p = flnext p ln
139+end
140+fdrop
141+for i ulong get fan 0 bound FAMAX
142+fmeta i
143+end
144+ret long get fan 0
145+end
146+note fdrop: remove denied rows and rows whose storage dir is missing (keeps order; areas stay valid)
147+fn fdrop to void
148+w = ulong 0
149+for i ulong get fan 0 bound FAMAX
150+if and not fdeny i fstok i
151+fmove w i
152+w = add w 1
153+end
154+end
155+put fan 0 w
156+end
157+note fsrcchg: true when RIDS.md changed since fload read it (main.om fchkrl reloads then)
158+fn fsrcchg to bool
159+fpb
160+fpt tfrids
161+m = fmtime
162+ret ne m get famt 0
163+end
164+note fputid: the identifier of allow-list repo i in the machine forms ("rid" fields): the bare RID
165+note (z then base58; the rad: prefix is no longer shown since Radicle was removed on 2026-11-14)
166+fn fputid i ulong to void
167+fputrid i
168+end
169+note fhasal: every repository of this source has a Radicle id
170+fn fhasal i ulong to bool
171+ret true
172+end
173+note fradsrc: Radicle node data (the routing table, server/counts.om fzseeds) belongs to this source
174+fn fradsrc to bool
175+ret true
176+end
177+note ---- seeds: rad node routing --rid rad:<RID> --json, read again when the node database changed
178+text tfzenv "/usr/bin/env"
179+text tfzhenv "HOME=/home/drakestapleton"
180+text tfzrad "/home/drakestapleton/.radicle/bin/rad"
181+text tfznode "node"
182+text tfzrout "routing"
183+text tfzrid "--rid"
184+text tfzjson "--json"
185+text tfzradp "rad:"
186+text tfzwal "/home/drakestapleton/.radicle/node/node.db-wal"
187+text tfzrow "{\"rid\":\"rad:"
188+text tfznid "\"nid\":\""
189+note fradwalk: the change key of the node database (node.db-wal mtime in ns), 0 when it is missing
190+fn fradwalk to ulong
191+fpb
192+fpt tfzwal
193+r = stat fpth 0 get fpthl 0 fstb 0 128
194+if lt r 0
195+ret 0
196+end
197+ret add mul fradle8 88 1000000000 fradle8 96
198+end
199+fn fradle8 o ulong to ulong
200+v = ulong 0
201+for i ulong 8
202+v = or v shl ulong get fstb add o i mul i 8
203+end
204+ret v
205+end
206+note fradseeds: the nodes this node's routing table says seed repo i (this node included), or -1 when
207+note rad did not answer
208+fn fradseeds i ulong to long
209+fkb
210+fka tfzenv
211+fka tfzhenv
212+fka tfzrad
213+fka tfznode
214+fka tfzrout
215+fka tfzrid
216+fkopen
217+fkt tfzradp
218+for k ulong get fail i bound 64
219+fkc fridbyte i k
220+end
221+fka tfzjson
222+st = fexec 5000000000
223+if ne st 0
224+ret -1
225+end
226+ret long fzrows i
227+end
228+note fzrows: lines of fxo that are {"rid":"rad:<RID of i>",...,"nid":"...
229+fn fzrows i ulong to ulong
230+ln = get fxol 0
231+p = ulong 0
232+n = ulong 0
233+for it ulong 1000000
234+if ge p ln
235+break
236+end
237+e = fleol p ln
238+if fzrowok i p e
239+n = add n 1
240+end
241+p = add e 1
242+end
243+ret n
244+end
245+fn fzxpre a ulong e ulong t view uchar * to bool
246+if gt add a len t e
247+ret false
248+end
249+for k ulong len t bound 64
250+if ne get fxo add a k get t k
251+ret false
252+end
253+end
254+ret true
255+end
256+fn fzrowok i ulong p ulong e ulong to bool
257+if not fzxpre p e tfzrow
258+ret false
259+end
260+a = add p len tfzrow
261+l = get fail i
262+if gt add a add l 2 e
263+ret false
264+end
265+for k ulong l bound 64
266+if ne get fxo add a k fridbyte i k
267+ret false
268+end
269+end
270+if ne get fxo add a l 34
271+ret false
272+end
273+q = add add a l 1
274+for it ulong sub e q bound 16777216
275+if fzxpre q e tfznid
276+ret true
277+end
278+q = add q 1
279+end
280+ret false
281+end
282+note ---- the footer line that says what forged serves (server/pages.om ffoot)
283+text tfsf4 "<p class=\"foot-fine\">INTERPLANE Forge: agents express intent; the forge retains authority. Repositories are served by forged, a seeded-Omega web server, with no JavaScript.</p>\n<p class=\"foot-fine\"><a href=\""
284+note ---- the identity words of the "For developers" section (server/pages.om fpjdev1): Delegate,
285+note Refs and HEAD, and Patch up to its link
286+text tfdv3 "<dt>Delegate</dt><dd>A key that may sign the project's official versions. This forge lists the project under "
287+text tfdv4 ".</dd>\n<dt>Refs and HEAD</dt><dd>Refs are the names that point at versions: branches and tags. HEAD is the version a fresh copy starts from, the newest commit of the default branch.</dd>\n<dt>Patch</dt><dd>A proposed change, stored in the repository and reviewed before it is merged. The list is under <a href=\""
288+fn fpjterms to void
289+fput tfdv3
290+fputown
291+fput tfdv4
292+end
293+note ---- the clone object of the JSON repo form (server/json.om fjrepo)
294+text tfjcl1 ",\n\"clone\":{\"rad\":\""
295+text tfjcl2 "\",\"rad_clone\":null,\"git_https\":null}"
296+fn fjclone i ulong to void
297+fput tfjcl1
298+fputrid i
299+fput tfjcl2
300+end

server/repos.om

@@ -1,7 +1,7 @@
1-note forged server/repos.om: the public allow-list loader. Source: the FIRST table of
2-note ~/handoffs/radicle/RIDS.md (header "| repo | RID | default branch"). A row is kept only when the
3-note name, RID and branch are well formed and ~/.radicle/storage/<rid> exists. Fail closed: when the
4-note file cannot be read or has no table, fan is 0 and every repo URL is 404.
1+note forged server/repos.om: the allow-list helpers and per-repo metadata (description from the identity
2+note document, last commit) that both repository sources use: server/radsrc.om (RIDS.md and Radicle
3+note storage, the default build) and store/repos.om (the native store, the store-reading build). A
4+note source fills fan / fanm / faid / fabr with fnmput, fbrput and its own key, and calls fmeta.
55 note ficut: stored data behind this response was longer than the buffer it was read into, and the code
66 note that follows would have treated the cut copy as the whole (a list with entries missing, an empty
77 note list, a 404 for something that exists). fincut sets it and fobtr, so fsend (server/main.om) throws
@@ -12,8 +12,6 @@ fn fincut to void
1212 put ficut 0 1
1313 put fobtr 0 1
1414 end
15-text tfrids "/home/drakestapleton/handoffs/radicle/RIDS.md"
16-text tfthd "| repo | RID | default branch"
1715 text tfshow "show"
1816 text tfidref "refs/rad/id:embeds/radicle.json"
1917 text tfdkey "\"description\":\""
@@ -22,9 +20,9 @@ text tfm1 "-1"
2220 text tflcfmt "--format=%H %ct %cs %h %s"
2321 note falsh / falsl / falct: full sha (40 hex, or length 0) and committer time (epoch s) of the last
2422 note commit of repo i, for the JSON form (server/json.om); falc keeps "%cs %h %s" for the HTML pages.
25-global falsh uchar 2560
26-global falsl ulong 64
27-global falct ulong 64
23+global falsh uchar 10240
24+global falsl ulong 256
25+global falct ulong 256
2826 text tfrh "refs/heads/"
2927 text tfrns "refs/namespaces/"
3028 text tfrnsh "/refs/heads/"
@@ -45,40 +43,6 @@ ret add e 1
4543 end
4644 ret ln
4745 end
48-fn flmat s ulong ln ulong to bool
49-if gt add s len tfthd ln
50-ret false
51-end
52-for k ulong len tfthd bound 64
53-if ne get fxo add s k get tfthd k
54-ret false
55-end
56-end
57-ret true
58-end
59-fn flfind ln ulong to ulong
60-p = ulong 0
61-for it ulong 100000
62-if ge p ln
63-ret ln
64-end
65-if flmat p ln
66-ret p
67-end
68-p = flnext p ln
69-end
70-ret ln
71-end
72-fn flbar p ulong e ulong to ulong
73-j = p
74-while lt j e bound 16777216
75-if eq get fxo j 124
76-ret j
77-end
78-j = add j 1
79-end
80-ret e
81-end
8246 fn ftrs a ulong b ulong to ulong
8347 j = a
8448 while lt j b bound 16777216
@@ -151,38 +115,6 @@ put fanm add cur i c
151115 end
152116 ret true
153117 end
154-fn fidput k ulong a ulong b ulong to bool
155-s = ftrs a b
156-t = ftre s b
157-if lt sub t s 6
158-ret false
159-end
160-if or ne get fxo s 114 ne get fxo add s 1 97
161-ret false
162-end
163-if or ne get fxo add s 2 100 ne get fxo add s 3 58
164-ret false
165-end
166-s = add s 4
167-n = sub t s
168-if gt n 60
169-ret false
170-end
171-cur = fidcur k
172-if gt add cur n len faid
173-ret false
174-end
175-put faio k cur
176-put fail k n
177-for i ulong n bound 64
178-c = get fxo add s i
179-if not fisaln c
180-ret false
181-end
182-put faid add cur i c
183-end
184-ret true
185-end
186118 fn fbrput k ulong a ulong b ulong to bool
187119 s = ftrs a b
188120 t = ftre s b
@@ -205,71 +137,6 @@ put fabr add cur i c
205137 end
206138 ret true
207139 end
208-note fstok: ~/.radicle/storage/<rid of k> exists
209-fn fstok k ulong to bool
210-fpb
211-fpt tfstore
212-for i ulong get fail k bound 64
213-fpc fridbyte k i
214-end
215-r = stat fpth 0 get fpthl 0 fstb 0 128
216-ret ge r 0
217-end
218-fn frow p ulong e ulong to void
219-b1 = flbar add p 1 e
220-b2 = flbar add b1 1 e
221-b3 = flbar add b2 1 e
222-if ge b3 e
223-ret
224-end
225-k = get fan 0
226-if ge k 64
227-ret
228-end
229-if not fnmput k add p 1 b1
230-ret
231-end
232-if not fidput k add b1 1 b2
233-ret
234-end
235-if not fbrput k add b2 1 b3
236-ret
237-end
238-put fan 0 add k 1
239-end
240-fn fload to long
241-put fan 0 0
242-fpb
243-fpt tfrids
244-put famt 0 fmtime
245-n = frdall
246-if le n 0
247-ret -1
248-end
249-ln = ulong n
250-p = flfind ln
251-if ge p ln
252-ret -2
253-end
254-p = flnext p ln
255-p = flnext p ln
256-for it ulong 64
257-if ge p ln
258-break
259-end
260-if ne get fxo p 124
261-break
262-end
263-e = fleol p ln
264-frow p e
265-p = flnext p ln
266-end
267-fdrop
268-for i ulong get fan 0 bound 64
269-fmeta i
270-end
271-ret long get fan 0
272-end
273140 note fdeny: withdrawn or never-public repositories, refused even when a RIDS.md row lists them
274141 note (by RID without "rad:" or by name); checked before the storage test, independent of the table
275142 text tfdnr1 "z2ft64NFLsKzWttCXw6NWNbRQLggQ"
@@ -306,17 +173,6 @@ ret true
306173 end
307174 ret fdnmeq k tfdnn2
308175 end
309-note fdrop: remove denied rows and rows whose storage dir is missing (keeps order; areas stay valid)
310-fn fdrop to void
311-w = ulong 0
312-for i ulong get fan 0 bound 64
313-if and not fdeny i fstok i
314-fmove w i
315-w = add w 1
316-end
317-end
318-put fan 0 w
319-end
320176 fn fmove w ulong i ulong to void
321177 if eq w i
322178 ret
@@ -406,6 +262,7 @@ n = add n 1
406262 j = add j 1
407263 end
408264 put fadl i n
265+fdclean i
409266 end
410267 fn fdunesc c uchar to uchar
411268 if or eq c 110 eq c 116

server/route.om

@@ -295,7 +295,9 @@ end
295295 put fridl 0 l
296296 ret true
297297 end
298-note ---- /rad:<RID>[/rest] -> 302 to /<owner>/<name>[/rest] when public, else 404
298+note ---- /rad:<RID>[/rest] -> 302 to /<owner>/<name>[/rest] when public, else 404. Only a project
299+note that has an old Radicle id (fhasal) answers to one: in the store-reading build the key of a
300+note project without one is its git id, which is never a /rad: link.
299301 fn fridat i ulong to bool
300302 l = get fail i
301303 if ne get fownl 0 add l 4
@@ -312,8 +314,8 @@ fn fradredir to long
312314 if not fpre tfprad
313315 ret 0
314316 end
315-for i ulong get fan 0 bound 64
316-if fridat i
317+for i ulong get fan 0 bound FAMAX
318+if and fhasal i fridat i
317319 fradloc i
318320 ret 302
319321 end
@@ -375,6 +377,11 @@ r = dlroute
375377 if ne r 0
376378 ret r
377379 end
380+note the git patch store (patch/, docs/API.md) holds /patches, /pulls and /pull; collab keeps /issues
381+r = paroute
382+if ne r 0
383+ret r
384+end
378385 r = coroute
379386 if ne r 0
380387 ret r
@@ -461,6 +468,12 @@ r = fjsfx
461468 if ne r 0
462469 ret r
463470 end
471+note a patch upload to a repository outside the public list is refused by the write gate first
472+note (session, CSRF), then answered 404 in the plain text the uploader reads (patch/p3gate.om)
473+r = paunl
474+if ne r 0
475+ret r
476+end
464477 ret fnorepo
465478 end
466479 if eq get frestl 0 1
@@ -632,6 +645,15 @@ r = grorder
632645 if ne r 0
633646 ret r
634647 end
648+note agents.json (server/agents.om) and the event stream and feed (door/, or the seam server/nodoor.om)
649+r = fqaroute
650+if ne r 0
651+ret r
652+end
653+r = evroute
654+if ne r 0
655+ret r
656+end
635657 if fpeq tfpexj
636658 if not fget
637659 ret 405

server/state.om

@@ -68,7 +68,7 @@ text tfpjm7 "This project has no receipt in that list yet."
6868 note ---- reading and verifying the list
6969 note fpjsite: the allow-list index of the site repository, or fan when it is not listed
7070 fn fpjsite to ulong
71-for i ulong get fan 0 bound 64
71+for i ulong get fan 0 bound FAMAX
7272 if eq get fail i len tfpjsite
7373 m = true
7474 for k ulong len tfpjsite

server/tests/agentdoor.py

new file mode 100644
@@ -0,0 +1,492 @@
1+# ORACLE: host test harness (Python 3 standard library only), not product code. Checks of the agent
2+# door (docs/AGENT-DOOR.md) against a test forged built and fed by server/tests/agentdoor.sh.
3+# agentdoor.py social DIR FIXTURE.json write a hash-chained social.log + social.head (and record the
4+# seq of every line in FIXTURE.json under "social")
5+# agentdoor.py walk PORT BASE LIMIT OUT read the stream with after= from 0 to its end, LIMIT a page,
6+# write one canonical JSON line per event to OUT; checks paging
7+# agentdoor.py check PORT API_MD TSV FIXTURE.json every other check (both bases)
8+# Exit 0 only when every check passed. Each failure is one "FAIL ..." line.
9+import hashlib
10+import html
11+import json
12+import re
13+import sys
14+import urllib.error
15+import urllib.request
16+
17+fails, passes = [], 0
18+
19+
20+def ok(msg):
21+ global passes
22+ passes += 1
23+ print("PASS " + msg, flush=True)
24+
25+
26+def bad(msg):
27+ fails.append(msg)
28+ print("FAIL " + msg, flush=True)
29+
30+
31+def expect(cond, msg):
32+ (ok if cond else bad)(msg)
33+ return cond
34+
35+
36+class NoRedirect(urllib.request.HTTPRedirectHandler):
37+ def redirect_request(self, *a, **k):
38+ return None
39+
40+
41+OPENER = urllib.request.build_opener(NoRedirect)
42+
43+
44+def fetch(port, base, path, accept=None, headers=None):
45+ req = urllib.request.Request("http://127.0.0.1:%d/%s" % (port, path))
46+ req.add_header("X-Forge-Base", base)
47+ req.add_header("X-Real-IP", "10.9.9.8")
48+ if accept:
49+ req.add_header("Accept", accept)
50+ for k, v in (headers or {}).items():
51+ req.add_header(k, v)
52+ try:
53+ r = OPENER.open(req, timeout=300)
54+ return r.status, r.headers, r.read()
55+ except urllib.error.HTTPError as e:
56+ return e.code, e.headers, e.read()
57+
58+
59+def strip_hints(b):
60+ s = b.decode("utf-8", "replace")
61+ s = re.sub(r'<span translate="no">([^<]*)</span>', r"\1", s)
62+ return s.replace(' translate="no"', "")
63+
64+
65+# ---- social log writer (the format of docs/social.md; the chain is sha256 of the previous line)
66+def social(d, fixture):
67+ fx = json.load(open(fixture))
68+ d1, d2, own = fx["d1"], fx["d2"], "did:key:" + fx["nid"]
69+ rfix, rpriv, rden = fx["rid_fix"], fx["rid_priv"], fx["rid_den"]
70+ sess = "a" * 64 + "." + "b" * 32
71+ rows = [
72+ ("account", d1, ""), ("name", d1, "fixdev"), ("session", d1, sess),
73+ ("account", d2, ""), ("session", d2, sess.replace("a", "c")),
74+ ("star", d1, "rad:" + rfix), ("fav", d1, "rad:" + rfix), ("fav", d2, "rad:" + rfix),
75+ ("star", d2, "rad:" + rpriv), ("star", d2, "rad:" + rden), ("watch", d1, "rad:" + rfix),
76+ ("follow", d2, d1), ("unstar", d1, "rad:" + rfix), ("star", d2, "rad:" + rfix),
77+ ("logout", d1, "a" * 64), ("follow", d1, own),
78+ ]
79+ prev, lines, seqs = "0" * 64, [], []
80+ for i, (a, who, tgt) in enumerate(rows):
81+ seq = i + 1
82+ ln = '{"seq":%d,"ts":%d,"did":"%s","action":"%s","target":"%s","prev":"%s"}' % (
83+ seq, 1794600000 + 60 * i, who, a, tgt, prev)
84+ lines.append(ln)
85+ prev = hashlib.sha256(ln.encode()).hexdigest()
86+ seqs.append({"seq": seq, "action": a, "did": who, "target": tgt})
87+ open(d + "/social.log", "w").write("\n".join(lines) + "\n")
88+ open(d + "/social.head", "w").write("%d %s\n" % (len(lines), prev))
89+ fx["social"] = seqs
90+ json.dump(fx, open(fixture, "w"), indent=1)
91+
92+
93+# ---- the stream
94+def getjson(port, base, path, accept=None):
95+ st, hd, body = fetch(port, base, path, accept)
96+ try:
97+ return st, hd, json.loads(body.decode("utf-8")), body
98+ except Exception: # noqa: BLE001
99+ return st, hd, None, body
100+
101+
102+def walk(port, base, limit, out=None):
103+ """follow next from after=0; returns the events. Checks: strictly increasing seq, no repeats,
104+ next always moves forward until the end, every page at most limit long."""
105+ evs, seen, after, pages = [], set(), 0, 0
106+ path = "events.json?after=0&limit=%d" % limit
107+ while pages < 100000:
108+ pages += 1
109+ st, hd, doc, body = getjson(port, base, path)
110+ if st != 200 or doc is None:
111+ bad("walk %s%s: status %d %r" % (base, path, st, body[:200]))
112+ return evs
113+ page = doc.get("events", [])
114+ if len(page) > limit:
115+ bad("walk %s%s: %d events, limit %d" % (base, path, len(page), limit))
116+ if doc.get("count") != len(page):
117+ bad("walk %s%s: count %r, %d events" % (base, path, doc.get("count"), len(page)))
118+ for e in page:
119+ s = e.get("seq")
120+ if s in seen:
121+ bad("walk %s: seq %r repeated" % (base, s))
122+ if evs and s <= evs[-1]["seq"]:
123+ bad("walk %s: seq %r after %r (not increasing)" % (base, s, evs[-1]["seq"]))
124+ if s <= after:
125+ bad("walk %s: seq %r not after %d" % (base, s, after))
126+ seen.add(s)
127+ evs.append(e)
128+ nx = doc.get("next", "")
129+ m = re.fullmatch(re.escape(base) + r"events\.json\?after=(\d+)&limit=(\d+)", nx)
130+ if not m:
131+ bad("walk %s%s: next %r" % (base, path, nx))
132+ return evs
133+ na = int(m.group(1))
134+ if not page:
135+ if na != after:
136+ bad("walk %s: empty page moved next from %d to %d" % (base, after, na))
137+ if after != doc.get("head_seq"):
138+ bad("walk %s: stopped at %d, head_seq %r" % (base, after, doc.get("head_seq")))
139+ break
140+ if na <= after:
141+ bad("walk %s: next %d does not move past %d" % (base, na, after))
142+ break
143+ after = na
144+ path = nx[len(base):]
145+ if out:
146+ with open(out, "w") as f:
147+ for e in evs:
148+ f.write(json.dumps(e, sort_keys=True) + "\n")
149+ return evs
150+
151+
152+# ---- docs/API.md tables (the format server/tests/jsonpages.py parses, any schema name)
153+TYPES = ("string", "integer", "boolean", "object", "array")
154+
155+
156+def parse_api(path):
157+ out, cur, sub = {}, None, None
158+ for ln in open(path, encoding="utf-8").read().split("\n"):
159+ m = re.match(r"^## `([a-z]+/[a-z-]+/\d+)`", ln)
160+ if m:
161+ cur, sub = m.group(1), ""
162+ out[cur] = {"": {}}
163+ continue
164+ if ln.startswith("## "):
165+ cur = None
166+ continue
167+ if cur is None:
168+ continue
169+ m = re.match(r"^### `([a-z_.]+)` (items|object)\s*$", ln)
170+ if m:
171+ sub = m.group(1) + " " + m.group(2)
172+ out[cur][sub] = {}
173+ continue
174+ if ln.startswith("### "):
175+ sub = None
176+ continue
177+ m = re.match(r"^\| `([a-z_0-9]+)` \| ([^|]+) \|", ln)
178+ if m and sub is not None:
179+ c = m.group(2).strip().lower()
180+ w = c.split()[0] if c else ""
181+ if w not in TYPES:
182+ bad("API.md %s %s: key %s type %r outside the vocabulary" % (cur, sub, m.group(1), c))
183+ continue
184+ out[cur][sub][m.group(1)] = (w, c.endswith("or null"))
185+ return out
186+
187+
188+def keycheck(where, obj, table):
189+ if not isinstance(obj, dict):
190+ bad("%s: not an object" % where)
191+ return
192+ for k in table:
193+ if k not in obj:
194+ bad("%s: documented key %s missing" % (where, k))
195+ for k, v in obj.items():
196+ if k not in table:
197+ bad("%s: key %s not documented" % (where, k))
198+ continue
199+ w, nul = table[k]
200+ if v is None:
201+ if not nul:
202+ bad("%s: %s is null, documented %s" % (where, k, w))
203+ continue
204+ py = {"string": str, "integer": int, "boolean": bool, "object": dict, "array": list}[w]
205+ if (w == "integer" and isinstance(v, bool)) or not isinstance(v, py):
206+ bad("%s: %s is %s, documented %s" % (where, k, type(v).__name__, w))
207+
208+
209+def validate(where, doc, schemas):
210+ s = doc.get("schema") if isinstance(doc, dict) else None
211+ if s not in schemas:
212+ bad("%s: schema %r not documented" % (where, s))
213+ return
214+ if list(doc)[0] != "schema":
215+ bad("%s: first key is not schema" % where)
216+ sc = schemas[s]
217+ keycheck(where, doc, sc[""])
218+ for sub, table in sc.items():
219+ if not sub:
220+ continue
221+ dotted, kind = sub.rsplit(" ", 1)
222+ nodes = [doc]
223+ for p in dotted.split("."):
224+ nxt = []
225+ for n in nodes:
226+ for x in (n if isinstance(n, list) else [n]):
227+ if isinstance(x, dict) and x.get(p) is not None:
228+ nxt.append(x[p])
229+ nodes = nxt
230+ for n in nodes:
231+ if kind == "items":
232+ for i, x in enumerate(n if isinstance(n, list) else []):
233+ keycheck("%s %s[%d]" % (where, dotted, i), x, table)
234+ else:
235+ keycheck("%s %s" % (where, dotted), n, table)
236+ ok("%s: valid %s" % (where, s))
237+
238+
239+KINDS = ["patch_opened", "patch_revised", "patch_merged", "patch_archived", "review", "comment",
240+ "issue_opened", "issue_closed", "release", "branch_moved", "star", "follow", "open_brought",
241+ "open_withdrawn"]
242+ISO = re.compile(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ")
243+
244+
245+def stream_checks(port, base, fx, schemas):
246+ st, hd, doc, body = getjson(port, base, "events.json?limit=200")
247+ expect(st == 200 and hd.get("Content-Type") == "application/json; charset=utf-8",
248+ "[%s] events.json 200 application/json (%d %s)" % (base, st, hd.get("Content-Type")))
249+ if doc is None:
250+ bad("[%s] events.json is not JSON: %r" % (base, body[:300]))
251+ return []
252+ validate("[%s] events.json" % base, doc, schemas)
253+ evs = doc["events"]
254+ expect(doc["head_seq"] == len(evs) == fx["expect_events"],
255+ "[%s] head_seq %d, %d events, the fixture makes %d" % (base, doc["head_seq"], len(evs), fx["expect_events"]))
256+ kinds = {e["kind"] for e in evs}
257+ for k in KINDS:
258+ expect(k in kinds, "[%s] kind %s present" % (base, k))
259+ text = body.decode("utf-8")
260+ # exclusions: nothing from a private or refused repository, no favorite, account, name, session,
261+ # logout, watch, unstar or star of a non-public repo; the refused open shelf RID never named
262+ for r in (fx["rid_priv"], fx["rid_den"], fx["open_denied"]):
263+ expect(r not in text, "[%s] %s never appears" % (base, r))
264+ for name in ("adpriv", "omega-pearl"):
265+ expect('"name":"%s"' % name not in text, "[%s] repository %s never appears" % (base, name))
266+ srcs = {e["source"] for e in evs}
267+ for s in fx["social"]:
268+ src = "social.log:%d" % s["seq"]
269+ should = (s["action"] == "star" and s["target"] == "rad:" + fx["rid_fix"]) or s["action"] == "follow"
270+ expect((src in srcs) == should, "[%s] social line %d (%s %s) %s" % (
271+ base, s["seq"], s["action"], s["target"][:16], "is an event" if should else "is not an event"))
272+ times_ok = all(ISO.fullmatch(e["time"]) for e in evs)
273+ expect(times_ok, "[%s] every time is ISO-8601 UTC" % base)
274+ links_ok = all(e[k] is None or e[k].startswith(base) for e in evs for k in ("path", "json"))
275+ expect(links_ok, "[%s] every path and json starts with the base" % base)
276+ for e in evs:
277+ if e["repo"] is not None:
278+ r = e["repo"]
279+ if not (r["name"] == "adfix" and r["rid"] == fx["rid_fix"] and r["path"] == base + "drakestapleton/adfix"
280+ and r["json"] == base + "drakestapleton/adfix.json" and r["owner"] == "drakestapleton"):
281+ bad("[%s] seq %d repo %r" % (base, e["seq"], r))
282+ by = {}
283+ for e in evs:
284+ by.setdefault(e["kind"], []).append(e)
285+ pat = fx["patch1"]
286+ po = [e for e in by.get("patch_opened", []) if e["source"] == pat]
287+ expect(len(po) == 1 and po[0]["subject"] == "fixture change one" and po[0]["path"] == base + "drakestapleton/adfix/patches/" + pat
288+ and po[0]["actor"] == {"name": "fixdev", "did": fx["d1"], "path": base + "fixdev"},
289+ "[%s] patch_opened: source = COB id, title, path, actor fixdev with page" % base)
290+ rv = by.get("review", [])
291+ expect(len(rv) == 1 and rv[0]["verdict"] == "accept", "[%s] review with verdict accept" % base)
292+ bm = by.get("branch_moved", [])
293+ expect(len(bm) == 1 and bm[0]["from"] == fx["main0"] and bm[0]["source"] == fx["main1"] and bm[0]["commits"] == 2
294+ and bm[0]["subject"] == "2 new commits on main"
295+ and bm[0]["path"] == base + "drakestapleton/adfix/compare/%s...%s" % (fx["main0"], fx["main1"]),
296+ "[%s] branch_moved main0 -> main1, 2 commits, compare link" % base)
297+ rl = by.get("release", [])
298+ expect(len(rl) == 1 and rl[0]["subject"] == "v1" and rl[0]["source"] == fx["tag_v1"]
299+ and rl[0]["path"] == base + "drakestapleton/adfix/releases/tag/v1", "[%s] release v1 from the tag object" % base)
300+ stv = by.get("star", [])
301+ expect(len(stv) == 2 and all(e["repo"] and e["repo"]["name"] == "adfix" for e in stv), "[%s] two stars of adfix" % base)
302+ fol = by.get("follow", [])
303+ expect(len(fol) == 2 and any(e["target"] and e["target"]["name"] == "fixdev" and e["path"] == base + "fixdev" for e in fol)
304+ and any(e["target"] and e["target"]["name"] == "drakestapleton" for e in fol), "[%s] follows name their target" % base)
305+ ob = by.get("open_brought", [])
306+ expect(len(ob) == 1 and ob[0]["path"] == base + "open/" + fx["open_held"] and ob[0]["subject"] == "shelf-a"
307+ and ob[0]["time"] == "2026-11-10T00:00:00Z", "[%s] open_brought shelf-a at its list date" % base)
308+ ow = by.get("open_withdrawn", [])
309+ expect(len(ow) == 1 and ow[0]["subject"] == "shelf-b" and ow[0]["path"] == base + "open/", "[%s] open_withdrawn shelf-b" % base)
310+ # the first pass is appended in time order (seq order equals time order inside one pass)
311+ ts = [e["time"] for e in evs]
312+ expect(ts == sorted(ts), "[%s] the fixture pass is in time order" % base)
313+ return evs
314+
315+
316+def limits_etag(port, base, schemas):
317+ st, hd, doc, _ = getjson(port, base, "events.json?limit=1000")
318+ expect(st == 200 and doc and doc["limit"] == 200 and doc["limit_requested"] == 1000 and doc["limited"] is True,
319+ "[%s] limit=1000 answers the maximum 200 and says so" % base)
320+ st, hd, doc, _ = getjson(port, base, "events.json")
321+ expect(st == 200 and doc and doc["limit"] == 50 and doc["limited"] is False, "[%s] default limit 50" % base)
322+ for q in ("after=x", "after=-1", "limit=0", "limit=abc", "after=1234567890123456789012"):
323+ st, hd, doc, body = getjson(port, base, "events.json?" + q)
324+ expect(st == 400 and doc and doc.get("schema") == "forge/error/1" and doc.get("status") == 400,
325+ "[%s] %s is 400 forge/error/1" % (base, q))
326+ st, hd, body = fetch(port, base, "events.json?after=2&limit=3")
327+ et = hd.get("ETag")
328+ expect(st == 200 and et and et.startswith('"ev'), "[%s] ETag %r" % (base, et))
329+ st2, hd2, body2 = fetch(port, base, "events.json?after=2&limit=3", headers={"If-None-Match": et or "x"})
330+ expect(st2 == 304 and body2 == b"" and hd2.get("ETag") == et, "[%s] If-None-Match -> 304, empty body" % base)
331+ st3, _, _ = fetch(port, base, "events.json?after=2&limit=3", headers={"If-None-Match": '"ev0-0-0-0"'})
332+ expect(st3 == 200, "[%s] another ETag -> 200" % base)
333+ a = fetch(port, base, "events.json?after=1&limit=4")
334+ b = fetch(port, base, "events?after=1&limit=4", "application/json")
335+ c = fetch(port, base, "feed?after=1&limit=4", "application/json")
336+ expect(a[0] == b[0] == c[0] == 200 and a[2] == b[2] == c[2], "[%s] events and feed with Accept JSON = events.json" % base)
337+ st, hd, _ = fetch(port, base, "events")
338+ expect(st == 302 and hd.get("Location") == base + "feed", "[%s] events (HTML) -> 302 %sfeed" % (base, base))
339+ st, _, _ = fetch(port, base, "events.json", headers={})
340+ req = urllib.request.Request("http://127.0.0.1:%d/events.json" % port, method="POST", data=b"x=1")
341+ req.add_header("X-Forge-Base", base)
342+ try:
343+ code = OPENER.open(req, timeout=60).status
344+ except urllib.error.HTTPError as e:
345+ code = e.code
346+ expect(code in (403, 405), "[%s] POST events.json refused (%d)" % (base, code))
347+
348+
349+def feed_checks(port, base, evs, fx):
350+ st, hd, body = fetch(port, base, "feed")
351+ h = strip_hints(body)
352+ expect(st == 200 and hd.get("Content-Type", "").startswith("text/html"), "[%s] feed 200 HTML" % base)
353+ expect('<link rel="alternate" type="application/json" href="%sevents.json">' % base in h,
354+ "[%s] feed names %sevents.json as its JSON alternate" % (base, base))
355+ expect('<a href="%sfeed">Feed</a>' % base in h, "[%s] forge row has the Feed entry" % base)
356+ want = [
357+ '<a href="%sfixdev">fixdev</a> proposed a change to <a href="%sdrakestapleton/adfix">adfix</a>: <a href="%sdrakestapleton/adfix/patches/%s">fixture change one</a>'
358+ % (base, base, base, fx["patch1"]),
359+ '<a href="%sdrakestapleton/adfix">adfix</a>: <a href="%sdrakestapleton/adfix/compare/%s...%s">2 new commits on main</a>'
360+ % (base, base, fx["main0"], fx["main1"]),
361+ '<a href="%sfixdev">fixdev</a> starred <a href="%sdrakestapleton/adfix">adfix</a>' % (base, base),
362+ 'starred <a href="%sdrakestapleton/adfix">adfix</a>' % base,
363+ '<a href="%sdrakestapleton">drakestapleton</a> tagged <a href="%sdrakestapleton/adfix/releases/tag/v1">v1</a> in' % (base, base),
364+ ' reviewed <a href="%sdrakestapleton/adfix/patches/%s">fixture change one</a> in <a href="%sdrakestapleton/adfix">adfix</a> (accept)'
365+ % (base, fx["patch1"], base),
366+ ' followed <a href="%sfixdev">fixdev</a>' % base,
367+ ' brought <a href="%sopen/%s">shelf-a</a> to the open builds shelf' % (base, fx["open_held"]),
368+ ]
369+ for w in want:
370+ expect(w in h, "[%s] feed sentence: %s" % (base, html.unescape(re.sub("<[^>]+>", "", w))[:70]))
371+ expect("someone" in h, "[%s] an account without a display name is someone" % base)
372+ expect(h.count("<li>") == min(50, len(evs)), "[%s] feed lists %d items (%d)" % (base, min(50, len(evs)), h.count("<li>")))
373+ # newest first and paged with before=
374+ seqs_html = [int(m) for m in re.findall(r'feed\?before=(\d+)', h)]
375+ if len(evs) > 50:
376+ expect(len(seqs_html) == 1, "[%s] Older link present" % base)
377+ mid = evs[len(evs) // 2]["seq"]
378+ st, _, b2 = fetch(port, base, "feed?before=%d" % mid)
379+ h2 = strip_hints(b2)
380+ older = [e for e in evs if e["seq"] < mid][-50:]
381+ expect(st == 200 and h2.count("<li>") == len(older) and '<a href="%sfeed">Newest</a>' % base in h2,
382+ "[%s] feed?before=%d lists the %d older events and links Newest" % (base, mid, len(older)))
383+ for q in ("before=0", "before=x"):
384+ st, _, _ = fetch(port, base, "feed?" + q)
385+ expect(st == 400, "[%s] feed?%s is 400" % (base, q))
386+ st, hd, tb = fetch(port, base, "feed?format=text")
387+ t = tb.decode("utf-8", "replace")
388+ expect(st == 200 and hd.get("Content-Type", "").startswith("text/plain") and "proposed a change to" in t and "fixdev" in t,
389+ "[%s] feed?format=text is the plain-text form" % base)
390+
391+
392+def fill(tmpl, fx):
393+ v = {"owner": "drakestapleton", "repo": "adfix", "ref": "main", "path": "a.txt", "sha": fx["main1"],
394+ "a": fx["main0"], "b": fx["main1"], "tag": "v1", "user": "drakestapleton", "q": "hi",
395+ "order": "trending", "project": fx["open_held"], "slug": "fixture-work", "seq": "0", "n": "5"}
396+ out = tmpl
397+ for k, x in v.items():
398+ out = out.replace("{%s}" % k, x)
399+ if "/patches/{id}" in tmpl:
400+ out = out.replace("{id}", fx["patch1"])
401+ if "/issues/{id}" in tmpl:
402+ out = out.replace("{id}", fx["issue1"])
403+ return out
404+
405+
406+def agents_checks(port, base, apimd, tsv, fx, schemas):
407+ st, hd, doc, body = getjson(port, base, "agents.json")
408+ expect(st == 200 and doc is not None, "[%s] agents.json 200 JSON" % base)
409+ if doc is None:
410+ return
411+ validate("[%s] agents.json" % base, doc, schemas)
412+ # tsv is the table this build compiled in (.build/agents.tsv, made by run.sh agentsgen from
413+ # server/agents.tsv: rows of parts the build does not compose are already "none" rows)
414+ rows = [ln.split("\t") for ln in open(tsv).read().split("\n") if ln and not ln.startswith("#")]
415+ hdr, rows = rows[0], rows[1:]
416+ expect(hdr == ["method", "path", "json", "schema", "auth", "doc", "purpose"], "agents.tsv header")
417+ expect(all(len(r) == 7 for r in rows), "agents.tsv: every row has 7 fields")
418+ routes = [r for r in rows if r[0] != "none"]
419+ na = [r for r in rows if r[0] == "none"]
420+ # the document is the table: same rows, same order (the build compiled the table in)
421+ expect([(x["method"], x["path"], x["json"], x["schema"] or "-") for x in doc["routes"]]
422+ == [(r[0], base + r[1], r[2], r[3]) for r in routes], "[%s] agents.json routes are the table's rows" % base)
423+ expect([x["what"] for x in doc["not_available"]] == [r[1] for r in na], "[%s] not_available is the table's none rows" % base)
424+ whats = " | ".join(x["what"] for x in doc["not_available"])
425+ expect("writes over HTTP without a browser session" in whats and "MCP server" in whats,
426+ "[%s] not_available names writes without a browser session and the MCP server" % base)
427+ # every listed address answers its listed schema (templates filled from the fixture)
428+ for x in doc["routes"]:
429+ path = fill(x["path"][len(base):], fx)
430+ acc = "application/json" if x["json"] == "accept" else None
431+ st, hd, d, b = getjson(port, base, path, acc)
432+ if "(base / only)" in x["purpose"] and base != "/":
433+ expect(st == 404, "[%s] %s (base / only) is 404 under %s" % (base, path, base))
434+ continue
435+ if x["auth"] == "session":
436+ expect(st == 303 and (hd.get("Location") or "").endswith("login"), "[%s] %s (session) signed out -> 303 login" % (base, path))
437+ continue
438+ if x["schema"] is None:
439+ expect(st == 200 and d is not None, "[%s] %s answers JSON (no schema key)" % (base, path))
440+ continue
441+ got = d.get("schema") if isinstance(d, dict) else None
442+ expect(st == 200 and got == x["schema"], "[%s] %s answers %s (%d %s)" % (base, path, x["schema"], st, got))
443+ # both directions: every schema heading of docs/API.md is a row, every row's schema is documented
444+ # in the file its doc column names
445+ # the source table (every build's rows, first column the part) lists every documented schema
446+ src = [ln.split("\t") for ln in open("server/agents.tsv").read().split("\n") if ln and not ln.startswith("#")]
447+ listed = {r[4] for r in src[1:] if len(r) == 8 and r[4] != "-"}
448+ for s in schemas:
449+ expect(s in listed or s in ("forge/error/1",), "docs/API.md schema %s is listed in server/agents.tsv" % s)
450+ for r in routes:
451+ if r[3] == "-":
452+ continue
453+ try:
454+ txt = open(r[5]).read()
455+ except OSError:
456+ bad("agents.tsv row %s: doc %s cannot be read" % (r[1], r[5]))
457+ continue
458+ expect(r[3] in txt, "agents.tsv row %s: %s is documented in %s" % (r[1], r[3], r[5]))
459+
460+
461+def check(port, apimd, tsv, fixture):
462+ fx = json.load(open(fixture))
463+ schemas = parse_api(apimd)
464+ for s in ("interplane/events/1", "interplane/agents/1"):
465+ expect(s in schemas, "docs/API.md documents %s" % s)
466+ for base in ("/", "/forge/"):
467+ evs = stream_checks(port, base, fx, schemas)
468+ limits_etag(port, base, schemas)
469+ feed_checks(port, base, evs, fx)
470+ agents_checks(port, base, apimd, tsv, fx, schemas)
471+
472+
473+def main():
474+ cmd = sys.argv[1]
475+ if cmd == "social":
476+ social(sys.argv[2], sys.argv[3])
477+ return
478+ if cmd == "walk":
479+ walk(int(sys.argv[2]), sys.argv[3], int(sys.argv[4]), sys.argv[5])
480+ elif cmd == "check":
481+ check(int(sys.argv[2]), sys.argv[3], sys.argv[4], sys.argv[5])
482+ elif cmd == "agents":
483+ # agents.json alone, both bases (the store-reading build: store/tests/agentdoor-store.sh)
484+ fx = json.load(open(sys.argv[5]))
485+ schemas = parse_api(sys.argv[3])
486+ for base in ("/", "/forge/"):
487+ agents_checks(int(sys.argv[2]), base, sys.argv[3], sys.argv[4], fx, schemas)
488+ print("agentdoor.py %s: %d passed, %d failed" % (cmd, passes, len(fails)))
489+ sys.exit(1 if fails else 0)
490+
491+
492+main()

server/tests/agentdoor.sh

new file mode 100755
@@ -0,0 +1,320 @@
1+#!/usr/bin/env bash
2+# ORACLE: host test driver (bash + curl + rad + git + server/tests/agentdoor.py), not product code.
3+# server/tests/agentdoor.sh: gates of the agent door (docs/AGENT-DOOR.md): <base>agents.json,
4+# <base>events.json (and events / feed with Accept JSON), the feed page, the event log.
5+# bash server/tests/agentdoor.sh (spark; FORGED_CPUS default 16-18, run under its pool lock;
6+# AGENTDOOR_PORT default 19984, private ports 19980..19989 only;
7+# AGENTDOOR_LIVE=0 skips the live-sized cost run; KEEP=1 keeps the temp dir)
8+# Everything is private to a temp dir: a throwaway Radicle profile (RAD_HOME) with three repositories:
9+# adfix public, on the test allow-list: commits, an annotated tag v1 (root refs/tags), patch one
10+# (two revisions, an accept review, a comment, merged), patch two (archived), an issue (a
11+# comment, closed); after the first pass two more commits move main
12+# adpriv private, not on the allow-list, with a patch and an issue: must never appear
13+# adden on the allow-list under the refused name omega-pearl, with a patch: must never appear
14+# a social log written by agentdoor.py (accounts, names, sessions, stars of public, private and refused
15+# repositories, favorites, a watch, follows, an unstar, a logout) and an open shelf list (held,
16+# withdrawn, and the refused RID z2ft64...). Only star (public repo), follow, brought and withdrawn
17+# may become events. The test forged is built from this tree (run.sh units) with its port, data dir,
18+# storage and allow-list rewritten; never 18480, ~/forge-data or ~/.radicle.
19+# Gates: every kind, every exclusion, schemas against docs/API.md, after= paging (no gap, no repeat,
20+# strictly increasing), limit cap, 400s, ETag 304, both bases, the feed HTML and its text form, every
21+# agents.json row answering its listed schema, table <-> docs/API.md both ways, change-triggered
22+# collection (no pass on unchanged requests), seq stability across a restart, a new event after it.
23+# Negative controls (each must FAIL the same checks): a broken agents.tsv row, a collector that leaks
24+# favorites, a log that numbers seq downwards. Then the measured costs, and (AGENTDOOR_LIVE=1) the same
25+# build on the live-sized data, read-only: real storage and allow-list, copies of the social log and
26+# the open list in the temp dir.
27+set -u
28+cd "$(dirname "$0")/../.."
29+ROOT=$(pwd)
30+H=$ROOT/server/tests
31+CORES=${FORGED_CPUS:-16-18}
32+PORT=${AGENTDOOR_PORT:-19984}
33+LIVE=${AGENTDOOR_LIVE:-1}
34+case $PORT in 1998[0-9]) ;; *) echo "REFUSED: use a private port in 19980..19989"; exit 2 ;; esac
35+OMC=$HOME/work/flux/omega-mv/seed/out/omc
36+T=$(mktemp -d /tmp/agentdoor.XXXXXX)
37+PASS=0; FAIL=0; PID=
38+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
39+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
40+check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
41+stop() { [ -n "$PID" ] && kill "$PID" 2> /dev/null; [ -n "$PID" ] && wait "$PID" 2> /dev/null; PID=; }
42+trap 'stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
43+if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
44+U=http://127.0.0.1:$PORT
45+
46+# ---- fixture storage
47+export RAD_HOME=$T/rad RAD_PASSPHRASE=
48+rad auth --alias adfix < /dev/null > /dev/null 2>&1 || { echo "rad auth failed"; exit 1; }
49+D1=$(rad self --did)
50+NID=${D1#did:key:}
51+G=(-c user.name=fixture -c user.email=fixture@t.invalid)
52+mkrepo() { # mkrepo NAME VISIBILITY: a working copy in $T/w-NAME with one commit, initialised; prints the RID
53+ local w=$T/w-$1
54+ git init -q -b main "$w" && echo "$1" > "$w/a.txt" && git -C "$w" add a.txt && git -C "$w" "${G[@]}" commit -qm init \
55+ && (cd "$w" && rad init "--$2" --name "$1" --description "agent door fixture" --default-branch main --no-confirm --no-seed > "$T/init-$1.out" 2>&1) \
56+ || { echo "rad init $1 failed: $(cat "$T/init-$1.out")"; exit 1; }
57+ (cd "$w" && rad . | sed 's/^rad://')
58+}
59+patchref() { git --git-dir="$RAD_HOME/storage/$1" for-each-ref --format='%(refname)' "refs/namespaces/*/refs/cobs/xyz.radicle.$2/*" | sed 's|.*/||'; }
60+RF=$(mkrepo adfix public); RP=$(mkrepo adpriv private); RD=$(mkrepo adden public)
61+S=$RAD_HOME/storage/$RF
62+W=$T/w-adfix
63+set -e
64+(
65+ cd "$W"
66+ git checkout -q -b f1 && echo one > b.txt && git add b.txt && git "${G[@]}" commit -qm "change one"
67+ git push -q -o patch.message="fixture change one" rad HEAD:refs/patches > "$T/p1.out" 2>&1
68+)
69+P1=$(patchref "$RF" patch)
70+(
71+ cd "$W"
72+ echo two >> b.txt && git add b.txt && git "${G[@]}" commit -qm "change one, revision two"
73+ git push -q rad f1 > "$T/p1b.out" 2>&1
74+ rad patch review "$P1" --accept -m "looks right" --no-announce > "$T/rv.out" 2>&1
75+ rad patch comment "$P1" -m "a comment on change one" --no-announce > "$T/pc.out" 2>&1
76+ git checkout -q main && git merge -q --ff-only f1 && git push -q rad main > "$T/merge.out" 2>&1
77+ git checkout -q -b f2 && echo x > c.txt && git add c.txt && git "${G[@]}" commit -qm "change two"
78+ git push -q -o patch.message="fixture change two" rad HEAD:refs/patches > "$T/p2.out" 2>&1
79+)
80+P2=$(patchref "$RF" patch | grep -v "$P1")
81+(
82+ cd "$W"
83+ rad patch archive "$P2" --no-announce > "$T/pa.out" 2>&1
84+ rad issue open --title "fixture issue" --description "issue body" --no-announce > "$T/io.out" 2>&1
85+)
86+I1=$(patchref "$RF" issue)
87+(
88+ cd "$W"
89+ rad issue comment "$I1" --message "a comment on the issue" --no-announce > "$T/ic.out" 2>&1
90+ rad issue state "$I1" --closed --no-announce > "$T/is.out" 2>&1
91+ git checkout -q main && git tag -a v1 -m "release one" && git push -q rad v1 > "$T/tag.out" 2>&1
92+)
93+# the root (canonical) tag, as the node keeps it for a delegate's tag
94+git --git-dir="$S" update-ref refs/tags/v1 "$(git -C "$W" rev-parse v1)"
95+TAGV1=$(git --git-dir="$S" rev-parse refs/tags/v1)
96+MAIN0=$(git --git-dir="$S" rev-parse refs/heads/main)
97+# the private and the refused repository: a patch and an issue each
98+for r in adpriv adden; do
99+ (cd "$T/w-$r" && git checkout -q -b f && echo p > p.txt && git add p.txt && git "${G[@]}" commit -qm "hidden change" \
100+ && git push -q -o patch.message="hidden change $r" rad HEAD:refs/patches > "$T/h-$r.out" 2>&1 \
101+ && rad issue open --title "hidden issue $r" --description x --no-announce > "$T/hi-$r.out" 2>&1)
102+done
103+set +e
104+check "$(git --git-dir="$S" cat-file -t "$TAGV1")" tag "fixture: v1 is an annotated tag object"
105+check "$(patchref "$RF" patch | wc -l)" 2 "fixture: two patches in adfix"
106+check "$(rad patch list --repo "rad:$RF" --merged 2> /dev/null | grep -c "${P1:0:7}")" 1 "fixture: patch one merged (rad patch list oracle)"
107+
108+# ---- allow-list, data dir, social log, open shelf
109+printf '# test allow-list\n\n| repo | RID | default branch |\n|---|---|---|\n| adfix | rad:%s | main |\n| omega-pearl | rad:%s | main |\n' "$RF" "$RD" > "$T/rids.md"
110+mkdir -p "$T/data/open" "$T/data/open/p" "$T/social"
111+OWN=z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK
112+D2=did:key:z6MkotherFixtureAccountKeyAbCdEfGhJkLmNpQrStUvWxYz
113+OH=z3AgentDoorHeadFixtureProject OW=z4AgentDoorWithdrawnFixture ODN=z2ft64NFLsKzWttCXw6NWNbRQLggQ
114+printf '%s\theld\t%s\t2026-11-10\t10\tshelf-a\tfixture project a\tnote a\n%s\twithdrawn\t%s\t2026-11-11\t0\tshelf-b\t\t\n%s\theld\t%s\t2026-11-09\t10\tpearl\tthe refused one\t\n' \
115+ "$OH" "$D2" "$OW" "$D2" "$ODN" "$D2" > "$T/data/open/list.tsv"
116+# the files the other agents.json rows read (as the open intake and research-build write them)
117+printf 'H\t%s\t2026-11-10\nC\t%s\t2026-11-10\tFixture\tinit\nT\tb\tREADME.md\nR\t# shelf-a\n' "$MAIN0" "${MAIN0:0:7}" > "$T/data/open/p/$OH.txt"
118+printf '{"schema":"interplane/open-alarms/1","alarms":[]}\n' > "$T/data/open/alarms.json"
119+mkdir -p "$T/data/research/gen/public.fixture1/w" && ln -s gen/public.fixture1 "$T/data/research/current"
120+printf '{"schema":"interplane/research/1","works":[]}\n' > "$T/data/research/gen/public.fixture1/index.json"
121+printf '{"schema":"interplane/research-work/1","work":{"slug":"fixture-work"}}\n' > "$T/data/research/gen/public.fixture1/w/fixture-work.json"
122+cat > "$T/fixture.json" <<EOF
123+{"d1": "$D1", "d2": "$D2", "nid": "$OWN", "rid_fix": "$RF", "rid_priv": "$RP", "rid_den": "$RD",
124+ "patch1": "$P1", "patch2": "$P2", "issue1": "$I1", "tag_v1": "$TAGV1", "main0": "$MAIN0", "main1": "",
125+ "open_held": "$OH", "open_withdrawn": "$OW", "open_denied": "$ODN", "expect_events": 18}
126+EOF
127+python3 "$H/agentdoor.py" social "$T/social" "$T/fixture.json" || { bad "social fixture"; exit 1; }
128+
129+# ---- builds: build OUT [SED expression]: this tree's units, the test copy rewritten
130+build() {
131+ local out=$1 extra=${2:-}
132+ { printf 'om2\n'; cat $(sh run.sh units); } > "$out.src.om" || return 1
133+ local s=(-e "s/18480/$PORT/g" -e "s|^text tfdata \".*\"|text tfdata \"$3\"|"
134+ -e "s|^text tfstore \".*\"|text tfstore \"${4:-$RAD_HOME/storage/}\"|" -e "s|^text tfrids \".*\"|text tfrids \"${5:-$T/rids.md}\"|")
135+ [ -n "$extra" ] && s+=(-e "$extra")
136+ sed "${s[@]}" "$out.src.om" > "$out.om"
137+ taskset -c "$CORES" nice -n 10 "$OMC" < "$out.om" > "$out" 2> "$out.err" || { echo "BUILD FAILED $out: $(cat "$out.err")"; return 1; }
138+ chmod 755 "$out"
139+}
140+start() { # start BIN SOCIALDIR
141+ FORGE_SOCIAL_DIR=$2 taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" &
142+ PID=$!
143+ for _ in $(seq 100); do curl -s -o /dev/null "$U/explore" -H 'X-Forge-Base: /' && return 0; sleep 0.1; done
144+ return 1
145+}
146+passes() { grep -c '^events: pass ' "$1.log"; }
147+get() { curl -s -o "$T/b" -D "$T/h" -w '%{http_code}' -H "X-Forge-Base: ${2:-/}" "$U/$1"; }
148+
149+build "$T/forged" "" "$T/data/" || { bad "test build"; exit 1; }
150+ok "test build $(sha256sum < "$T/forged" | cut -c1-16)"
151+grep -q '^fn evcollect' "$T/forged.om" && ok "door/ composed" || bad "door/ not composed (seam used)"
152+start "$T/forged" "$T/social/" || { bad "test forged did not start: $(tail -3 "$T/forged.log")"; exit 1; }
153+
154+# first pass: the backfill of the fixture
155+check "$(get events.json)" 200 "first events.json"
156+check "$(passes "$T/forged")" 1 "one collection pass after the first request"
157+grep '^events: pass ' "$T/forged.log" | tail -1
158+# change-triggered: unchanged requests read nothing
159+for _ in 1 2 3 4 5; do get "events.json?limit=200" > /dev/null; get feed > /dev/null; done
160+check "$(passes "$T/forged")" 1 "ten unchanged requests: no further pass (fingerprints only)"
161+# main moves by two commits: the next request reads that repository alone
162+(cd "$W" && git checkout -q main && echo 3 > d.txt && git add d.txt && git "${G[@]}" commit -qm three \
163+ && echo 4 > e.txt && git add e.txt && git "${G[@]}" commit -qm four && git push -q rad main > "$T/m2.out" 2>&1)
164+MAIN1=$(git --git-dir="$S" rev-parse refs/heads/main)
165+python3 - "$T/fixture.json" "$MAIN1" <<'EOF'
166+import json, sys
167+f = json.load(open(sys.argv[1])); f["main1"] = sys.argv[2]; json.dump(f, open(sys.argv[1], "w"), indent=1)
168+EOF
169+check "$(get events.json)" 200 "events.json after main moved"
170+check "$(passes "$T/forged")" 2 "one more pass after main moved"
171+L=$(grep '^events: pass ' "$T/forged.log" | tail -1); echo "$L"
172+check "$(echo "$L" | sed -n 's/.*sources read \([0-9]*\),.*/\1/p')" 1 "that pass read one source (the moved repository)"
173+check "$(echo "$L" | sed -n 's/.*events added \([0-9]*\)$/\1/p')" 1 "that pass added one event (branch_moved)"
174+
175+# ---- the checks of agentdoor.py, both bases
176+python3 "$H/agentdoor.py" check "$PORT" docs/API.md "$ROOT/.build/agents.tsv" "$T/fixture.json" > "$T/check.log" 2>&1
177+rc=$?; grep '^FAIL' "$T/check.log" | head -30; tail -1 "$T/check.log"
178+check "$rc" 0 "agentdoor.py check (both bases): $(tail -1 "$T/check.log")"
179+for b in / /forge/; do
180+ python3 "$H/agentdoor.py" walk "$PORT" "$b" 3 "$T/walk3-${b//\//_}.jsonl" > "$T/walk.log" 2>&1
181+ check "$?" 0 "walk $b with limit 3: no gap, no repeat, increasing ($(tail -1 "$T/walk.log"))"
182+done
183+python3 "$H/agentdoor.py" walk "$PORT" / 200 "$T/walk200.jsonl" > /dev/null 2>&1
184+cmp -s "$T/walk3-_.jsonl" "$T/walk200.jsonl" && ok "pages of 3 and of 200 give the same events" || bad "pages of 3 and of 200 differ"
185+check "$(wc -l < "$T/walk200.jsonl")" 18 "18 events"
186+
187+# ---- restart: the same seq numbers, then a new event continues the stream
188+cp "$T/data/events/log" "$T/log.before"
189+stop
190+start "$T/forged" "$T/social/" || bad "restart"
191+python3 "$H/agentdoor.py" walk "$PORT" / 200 "$T/walk-restart.jsonl" > /dev/null 2>&1
192+cmp -s "$T/walk200.jsonl" "$T/walk-restart.jsonl" && ok "after a restart every event has the same seq and content" || bad "events differ after restart"
193+cmp -s "$T/log.before" "$T/data/events/log" && ok "the restart pass appended nothing (log byte-identical)" || bad "restart changed the log"
194+L=$(grep '^events: pass ' "$T/forged.log" | tail -1); echo "restart $L"
195+(cd "$W" && rad issue comment "$I1" --message "after the restart" --no-announce > "$T/ic2.out" 2>&1)
196+python3 "$H/agentdoor.py" walk "$PORT" / 200 "$T/walk-new.jsonl" > /dev/null 2>&1
197+check "$(wc -l < "$T/walk-new.jsonl")" 19 "a comment after the restart is event 19"
198+check "$(head -18 "$T/walk-new.jsonl" | cmp -s - "$T/walk200.jsonl" && echo same)" same "events 1..18 unchanged"
199+check "$(tail -1 "$T/walk-new.jsonl" | python3 -c 'import json,sys; e=json.loads(sys.stdin.read()); print(e["seq"], e["kind"], e["repo"]["name"])')" "19 comment adfix" "event 19"
200+# the chain: an independent check of every line's prev
201+python3 - "$T/data/events/log" <<'EOF' && ok "events/log hash chain verified independently" || bad "events/log chain"
202+import hashlib, sys
203+prev = "0" * 64
204+for i, ln in enumerate(open(sys.argv[1], "rb").read().split(b"\n")[:-1]):
205+ f = ln.split(b"\t")
206+ assert len(f) == 11 and int(f[0]) == i + 1 and f[10].decode() == prev, (i, f[:3])
207+ prev = hashlib.sha256(ln).hexdigest()
208+EOF
209+# a changed line switches the stream off (fail closed)
210+stop
211+cp "$T/data/events/log" "$T/log.good"
212+sed -i '3s/^3\t/3\t9/' "$T/data/events/log"
213+start "$T/forged" "$T/social/" || bad "start on a tampered log"
214+check "$(get events.json)" 503 "tampered log: events.json 503"
215+check "$(grep -c 'EVENTS-LOG TAMPER' "$T/forged.log")" 1 "tampered log: one TAMPER line on stderr"
216+stop
217+cp "$T/log.good" "$T/data/events/log"
218+
219+# ---- measured costs (fixture): request without change, 20 samples
220+start "$T/forged" "$T/social/" || bad "restart for costs"
221+get events.json > /dev/null
222+for _ in $(seq 20); do curl -s -o /dev/null -w '%{time_total}\n' -H 'X-Forge-Base: /' "$U/events.json?limit=200"; done > "$T/cost-fixture.txt"
223+echo "COST fixture events.json?limit=200 (19 events) seconds: $(sort -n "$T/cost-fixture.txt" | tr '\n' ' ')"
224+grep '^events: pass ' "$T/forged.log" | sed 's/^/COST fixture /'
225+stop
226+
227+# ---- negative controls. Each mutant runs on a fresh data dir (its own first pass), so the stream
228+# has no branch_moved there; the twin (no mutation) runs the same way, and a control counts only when
229+# the mutant shows its own failure line and the twin does not.
230+negrun() { # negrun NAME SED: build, start, run check and walk into $T/neg-NAME
231+ local d=$T/neg-$1
232+ rm -rf "$d"; mkdir -p "$d/data/open" "$d/social"
233+ cp "$T/data/open/list.tsv" "$d/data/open/"
234+ cp "$T/social/social.log" "$T/social/social.head" "$d/social/"
235+ build "$d/forged" "$2" "$d/data/" || return 1
236+ start "$d/forged" "$d/social/" || return 1
237+ python3 "$H/agentdoor.py" check "$PORT" docs/API.md "$ROOT/.build/agents.tsv" "$T/fixture.json" > "$d/check.log" 2>&1
238+ python3 "$H/agentdoor.py" walk "$PORT" / 3 "$d/walk.jsonl" > "$d/walk.log" 2>&1
239+ stop
240+ cat "$d/check.log" "$d/walk.log" | grep '^FAIL' > "$d/fails.txt"
241+ return 0
242+}
243+negrun twin 's/^x$/x/' || bad "negative control twin did not run"
244+neg() { # neg NAME SED MARKER PATTERN: MARKER proves the mutation is in the source; PATTERN is its failure
245+ negrun "$1" "$2" || { bad "negative control $1 did not build or start"; return; }
246+ grep -qF -- "$3" "$T/neg-$1/forged.om" || { bad "negative control $1: mutation not applied"; return; }
247+ if grep -qE -- "$4" "$T/neg-twin/fails.txt"; then
248+ bad "negative control $1: the twin already fails with /$4/"
249+ elif grep -qE -- "$4" "$T/neg-$1/fails.txt"; then
250+ ok "negative control $1 fails: $(grep -m1 -E -- "$4" "$T/neg-$1/fails.txt" | cut -c1-200)"
251+ else
252+ bad "negative control $1: no failure /$4/ ($(wc -l < "$T/neg-$1/fails.txt") other failures)"
253+ fi
254+}
255+# (1) a broken agents.tsv row: the blob row lists forge/tree/1
256+neg broken-row 's|\\tforge/blob/1\\tnone\\t|\\tforge/tree/1\\tnone\\t|' '{path}\taccept\tforge/tree/1' 'blob/main/a.txt answers forge/tree/1'
257+# (2) the collector leaks favorites (a fav line read as a star)
258+neg leak-fav '/^fn evsocln/,/^fn evsstar/s/^if eq a 1$/if or eq a 1 eq a 3/' 'if or eq a 1 eq a 3' 'social line 7 \(fav .* is not an event'
259+# (3) seq numbered downwards
260+neg seq-down 's/^evlnum add get gevn 0 1$/evlnum sub 1000000 get gevn 0/' 'evlnum sub 1000000 get gevn 0' 'not increasing'
261+
262+# ---- the seam (a build without door/: as a store-reading build composes it): 501, consistently
263+SEAMD=$T/seam
264+mkdir -p "$SEAMD/data" "$SEAMD/social"
265+{ printf 'om2\n'; cat $(sh run.sh units | sed 's|^door/.*\.om$||' | awk 'NF' | awk '/server\/agents.om/{print "server/nodoor.om"} {print}'); } \
266+ | sed -e "s/18480/$PORT/g" -e "s|^text tfdata \".*\"|text tfdata \"$SEAMD/data/\"|" \
267+ -e "s|^text tfstore \".*\"|text tfstore \"$RAD_HOME/storage/\"|" -e "s|^text tfrids \".*\"|text tfrids \"$T/rids.md\"|" > "$SEAMD/forged.om"
268+if taskset -c "$CORES" nice -n 10 "$OMC" < "$SEAMD/forged.om" > "$SEAMD/forged" 2> "$SEAMD/forged.err"; then
269+ chmod 755 "$SEAMD/forged"
270+ start "$SEAMD/forged" "$SEAMD/social/" || bad "seam build did not start"
271+ for b in / /forge/; do
272+ check "$(get events.json "$b")" 501 "[$b] seam: events.json 501"
273+ check "$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["schema"], d["status"])' "$T/b")" "forge/error/1 501" "[$b] seam: forge/error/1"
274+ check "$(get feed "$b")" 501 "[$b] seam: feed 501"
275+ check "$(curl -s -o /dev/null -w '%{http_code}' -H "X-Forge-Base: $b" -H 'Accept: application/json' "$U/events")" 501 "[$b] seam: events (JSON) 501"
276+ get agents.json "$b" > /dev/null
277+ check "$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["events"], any(r["schema"]=="interplane/events/1" for r in d["routes"]), sum("events" in r["what"] or "feed" in r["what"] for r in d["not_available"]))' "$T/b")" "None False 3" "[$b] seam: agents.json lists the stream under not_available"
278+ get explore "$b" > /dev/null
279+ grep -q '>Feed</a>' "$T/b" && bad "[$b] seam: Feed entry shown" || ok "[$b] seam: no Feed entry in the forge row"
280+ done
281+ stop
282+else
283+ bad "seam build: $(cat "$SEAMD/forged.err")"
284+fi
285+
286+# ---- live-sized data, read-only: real storage and allow-list; copies of the social log and the open list
287+if [ "$LIVE" = 1 ]; then
288+ LD=$T/live
289+ mkdir -p "$LD/data/open" "$LD/social"
290+ cp "$HOME/forge-data/social.log" "$HOME/forge-data/social.head" "$LD/social/"
291+ cp "$HOME/forge-data/open/list.tsv" "$LD/data/open/"
292+ build "$LD/forged" "" "$LD/data/" "$HOME/.radicle/storage/" "$HOME/handoffs/radicle/RIDS.md" || bad "live-sized build"
293+ start "$LD/forged" "$LD/social/" || bad "live-sized start"
294+ t1=$(curl -s -o "$LD/first.json" -w '%{time_total}' -H 'X-Forge-Base: /' "$U/events.json?limit=200")
295+ echo "COST live first request (backfill pass included) seconds: $t1"
296+ grep '^events: pass ' "$LD/forged.log" | sed 's/^/COST live backfill /'
297+ for _ in $(seq 20); do curl -s -o /dev/null -w '%{time_total}\n' -H 'X-Forge-Base: /' "$U/events.json?limit=200"; done > "$LD/cost.txt"
298+ echo "COST live events.json?limit=200, unchanged, seconds: $(sort -n "$LD/cost.txt" | tr '\n' ' ')"
299+ for _ in $(seq 5); do curl -s -o /dev/null -w '%{time_total}\n' -H 'X-Forge-Base: /' "$U/feed"; done > "$LD/costf.txt"
300+ echo "COST live feed, unchanged, seconds: $(sort -n "$LD/costf.txt" | tr '\n' ' ')"
301+ check "$(passes "$LD/forged")" 1 "live-sized: one pass, none on the 25 unchanged requests"
302+ stop
303+ start "$LD/forged" "$LD/social/" || bad "live-sized restart"
304+ t2=$(curl -s -o /dev/null -w '%{time_total}' -H 'X-Forge-Base: /' "$U/events.json?limit=200")
305+ echo "COST live first request after a restart (every repository read again, nothing new) seconds: $t2"
306+ grep '^events: pass ' "$LD/forged.log" | tail -1 | sed 's/^/COST live restart /'
307+ echo "COST live events: $(wc -l < "$LD/data/events/log") lines, $(wc -c < "$LD/data/events/log") bytes; snapshots $(du -sb "$LD/data/events/r" | cut -f1) bytes"
308+ python3 "$H/agentdoor.py" walk "$PORT" / 200 "$LD/walk.jsonl" > "$LD/walk.log" 2>&1
309+ check "$?" 0 "live-sized: walk with no gap or repeat ($(tail -1 "$LD/walk.log"))"
310+ python3 - "$LD/walk.jsonl" <<'EOF'
311+import collections, json, sys
312+c = collections.Counter(json.loads(l)["kind"] for l in open(sys.argv[1]))
313+print("COST live kinds: " + ", ".join("%s %d" % kv for kv in sorted(c.items())))
314+EOF
315+ grep -c '^events: COB not loaded' "$LD/forged.log" | sed 's/^/live COBs not loaded: /'
316+ stop
317+fi
318+
319+echo "agentdoor.sh: $PASS passed, $FAIL failed"
320+[ "$FAIL" = 0 ]

server/tests/bigrepo.sh

@@ -32,7 +32,12 @@ bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
3232 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
3333 trap "[ -n \"\$PID\" ] && kill \$PID 2>/dev/null; wait 2>/dev/null; [ -n \"\${KEEP:-}\" ] || rm -rf \"$T\"" EXIT
3434 if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
35+# STORE_VARIANT=1 (with IPL_DIR): the same gates on the store-reading build. Every start makes the
36+# store afresh from the fixture storage (store/tests/fixstore.sh: the repository as it is then, its
37+# head recorded), so what the gate wrote into the storage is what the store holds. The id is longer
38+# there (the store's old-id rule wants 20..60 letters).
3539 RID=zBigRepoFixture1
40+[ "${STORE_VARIANT:-0}" = 1 ] && RID=zBigRepoFixtureStore1
3641 S=$T/storage/$RID
3742 G() { git -C "$S" -c user.name=fixture -c user.email=fixture@t.invalid "$@"; }
3843 mkdir -p "$T/storage" "$T/data" "$T/social"
@@ -42,7 +47,12 @@ git init -q -b main "$W" && echo hi > "$W/a.txt" && git -C "$W" add a.txt \
4247 printf "# test allow-list\n\n| repo | RID | default branch |\n|---|---|---|\n| bigrepo | rad:%s | main |\n" "$RID" > "$T/rids.md"
4348 BASE=$(G rev-parse refs/heads/main); BTREE=$(G rev-parse "$BASE^{tree}"); ABLOB=$(G rev-parse "$BASE:a.txt")
4449 U=http://127.0.0.1:$PORT/drakestapleton/bigrepo
50+. "$H/../../store/tests/svlib.sh"
4551 start() { # start OUT [SEDX]: build and start a test forged; PID set
52+ if [ "${STORE_VARIANT:-0}" = 1 ]; then
53+ rm -f "$T/store.fp"; svsync "$S" "$T/rids.md" "$T/storage" "$T/store" "$PORT" || return 1
54+ export FORGE_STORE=$T/store
55+ fi
4656 DATA=$T/data/ STORE=$T/storage/ RIDS=$T/rids.md SEDX=${2:-} "$H/../../collab/tests/tbuild.sh" "$1" || return 1
4757 FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" &
4858 PID=$!
@@ -55,6 +65,7 @@ rcwait() { # RC = the exit code of the server if it ends within 10 s, else "ali
5565 if kill -0 $PID 2> /dev/null; then stop; RC=alive; else wait $PID 2> /dev/null; RC=$?; PID=; fi
5666 }
5767 get() { # get FORM URL: prints the status (000 = no answer); body in $T/body
68+ svsync "$S" "$T/rids.md" "$T/storage" "$T/store" "$PORT" || { echo "svsync failed" >&2; echo 000; return; }
5869 if [ "$1" = json ]; then curl -s -o "$T/body" --max-time 60 -w "%{http_code}" -H "Accept: application/json" "$2"
5970 else curl -s -o "$T/body" --max-time 60 -w "%{http_code}" "$2"; fi
6071 }

server/tests/check.sh

@@ -10,18 +10,31 @@
1010 # refuse them. Negative control: a mutant with fdeny and the Origin check removed must serve
1111 # the denied rows (200) and accept a foreign Origin.
1212 # Read-only on real storage; never touches 18480, ~/forge-data or port 18091.
13+# The Radicle storage the fixtures link to is FORGE_TEST_RSTORE (default ~/radicle-storage-frozen/storage,
14+# the read-only copy kept after the Radicle removal of 2026-11-14), and the site chrome comes from its
15+# interplane.io repository. STORE_VARIANT=1 (with IPL_DIR) runs the same gates against the
16+# store-reading build: the fixture becomes a store (store/tests/fixstore.sh) whose public lines are
17+# the test RIDS.md rows (the store build serves every public line), and the deny mutant removes the
18+# store's deny step (store/repos.om xscheck).
1319 set -u
1420 cd "$(dirname "$0")/../.."
1521 ROOT=$(pwd)
1622 CORES=${FORGED_CPUS:-4,5}
1723 PORT=${FORGE_TEST_PORT:-18488}
1824 OMC=$HOME/work/flux/omega-mv/seed/out/omc
19-STORE=$HOME/.radicle/storage
25+STORE=${FORGE_TEST_RSTORE:-$HOME/radicle-storage-frozen/storage}
26+export FORGE_SITE_STORE=${FORGE_SITE_STORE:-$STORE/z399yKvnXcBQNkKoq86iBDgTvQ5QV}
27+SV=${STORE_VARIANT:-0}
2028 OK_RID=z631r2JJiVT8it4tST7RK24hpowi # cuda-crack
2129 R1=z44GqrPVAPjZkhoD2MWVjqy18ighN # aien-sovereign-core-mv storage, listed as omega-pearl
2230 R2=z6do9WDBhuSnvopDkgFdFr1yWA62 # omega-mv storage, listed as aien-crypto
2331 DENY=z2ft64NFLsKzWttCXw6NWNbRQLggQ # withdrawn omega-pearl RID
2432 T=$(mktemp -d)
33+if [ "$SV" = 1 ]; then
34+ # the unit gate (section 1) compiles the store units against the real table; section 2 its own
35+ export FORGE_STORE=$T/store
36+ echo "STORE_VARIANT: store-reading build, store $T/store"
37+fi
2538 pid=
2639 pass=0; fail=0
2740 ok() { pass=$((pass+1)); echo "PASS $*"; }
@@ -46,14 +59,22 @@ if run "$OMC" < "$T/rl.om" > "$T/rl" 2> "$T/rl.err"; then
4659 [ "$rc" = 0 ] && ok "ratelim: 30/60s per IP, other IPs and old-bucket colliders unaffected, 300-IP fill" || bad "ratelim exit $rc"
4760 else bad "ratelim compile: $(cat "$T/rl.err")"; fi
4861 git show 687e03a:server/util.om > "$T/oldutil.om"
49-printf 'global fretry ulong 1\nglobal fcspsb ulong 1\nglobal ftxmore ulong 1\nglobal fag uchar 256\nglobal fagl ulong 1\nglobal frf uchar 256\nglobal frfl ulong 1\nfn fsetsbx to void\nput fcspsb 0 1\nend\n' >> "$T/oldutil.om"
62+printf 'global fretry ulong 1\nglobal fcspsb ulong 1\nglobal ftxmore ulong 1\nglobal fag uchar 256\nglobal fagl ulong 1\nglobal frf uchar 256\nglobal frfl ulong 1\nglobal fbig uchar 3145728\nglobal fbigl ulong 1\nfn fsetsbx to void\nput fcspsb 0 1\nend\n' >> "$T/oldutil.om"
63+# the allow-list size the current units loop to (server/util.om FAMAX, 2026-11-14); the old table stays
64+printf 'const FAMAX ulong 64\n' >> "$T/oldutil.om"
65+# the "moving" 503 flag the current pages and JSON errors read (server/util.om fmvng, restore 2026-11-14)
66+printf 'global fmvng ulong 1\n' >> "$T/oldutil.om"
5067 # the streaming exec of the current util.om (browse reads ref lists through it); the limiter under test
5168 # stays the unkeyed one of 687e03a
69+# Keep the current file-input exec path available to the patch handlers in the negative-control build.
70+sed -n '/^fn fchildin /,/^fn fdrain /{ /^fn fdrain /!p; }; /^fn fexecin /,/^fn fxput /{ /^fn fxput /!p; }' server/util.om >> "$T/oldutil.om"
5271 sed -n '/^note streaming exec (fsopen/,/^global fsrs /p; /^note ---- streaming exec/,/^note ---- path builder/{/^note ---- path builder/!p}' server/util.om >> "$T/oldutil.om"
5372 if grep -q '^global frlk ' "$T/oldutil.om"; then
5473 bad "ratelim negative control: 687e03a util.om is unexpectedly keyed"
5574 else
56- compose "$T/rln.om" "$T/oldutil.om"
75+ # the old util.om has none of the store words, so this control composes the default units in
76+ # both variants (the limiter is the same code in both builds)
77+ (unset FORGE_STORE; compose "$T/rln.om" "$T/oldutil.om")
5778 sed -i 's/^fn main to int$/fn fmainx to int/' "$T/rln.om"
5879 cat server/tests/ratelim.om >> "$T/rln.om"
5980 if run "$OMC" < "$T/rln.om" > "$T/rln" 2> "$T/rln.err"; then
@@ -84,6 +105,9 @@ cat > "$T/RIDS.md" <<EOF
84105 | pearl-alias | rad:$DENY | main | - | - | - |
85106 | benchmarks-mv | rad:$LONG_RID | main | - | - | - |
86107 EOF
108+if [ "$SV" = 1 ]; then
109+ bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store" || { bad "fixture store"; exit 1; }
110+fi
87111 redirect() { # redirect FILE: port, allow-list, storage, data dir and the count sources into $T
88112 sed -i -e "s|haddr4 a 2130706433 18480|haddr4 a 2130706433 $PORT|" \
89113 -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|" \
@@ -95,7 +119,9 @@ redirect() { # redirect FILE: port, allow-list, storage, data dir and the count
95119 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \
96120 -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \
97121 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "$1"
98- for p in "2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/"; do
122+ local marks=("2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/")
123+ [ "$SV" = 1 ] && marks=("2130706433 $PORT" "$T/store/" "$T/data/")
124+ for p in "${marks[@]}"; do
99125 grep -qF "$p" "$1" || { bad "redirect: '$p' not substituted"; exit 1; }
100126 done
101127 if grep -q '2130706433 18480\|/home/drakestapleton/forge-data\|/home/drakestapleton/.radicle\|/home/drakestapleton/handoffs/radicle' "$1"; then bad "redirect: a live path or port remains"; exit 1; fi
@@ -189,7 +215,12 @@ want "GET explore after the long agent (server still up)" "$(get explore)" 200
189215 stop
190216
191217 compose "$T/m.om"; redirect "$T/m.om"
192-grep -c '^if and not fdeny i fstok i$' "$T/m.om" | grep -qx 1 || { bad "mutant: fdeny call site not found"; exit 1; }
218+if [ "$SV" = 1 ]; then
219+ grep -c '^if fdeny k$' "$T/m.om" | grep -qx 1 || { bad "mutant: store deny site not found"; exit 1; }
220+ sed -i 's/^if fdeny k$/if false/' "$T/m.om"
221+else
222+ grep -c '^if and not fdeny i fstok i$' "$T/m.om" | grep -qx 1 || { bad "mutant: fdeny call site not found"; exit 1; }
223+fi
193224 grep -c '^if and eq get fmeth 0 3 not forigok$' "$T/m.om" | grep -qx 1 || { bad "mutant: Origin gate not found"; exit 1; }
194225 grep -c '^for i ulong hmin n 120 bound 120$' "$T/m.om" | grep -qx 1 || { bad "mutant: title loop not found"; exit 1; }
195226 grep -c '^flga get fag i$' "$T/m.om" | grep -qx 1 || { bad "mutant: agent log site not found"; exit 1; }

server/tests/counts.sh

@@ -138,31 +138,31 @@ forged: reloaded, public repos 28
138138 EOF
139139 cp "$T/data/logs/forged.log" "$T/datab/logs/forged.log"
140140 iso() { TZ=UTC date -u -d "@$1" +%Y-%m-%dT%H:%M:%SZ; } # oracle for the since times
141-S0=$(iso 1794162545); S1=$(iso "$(TZ=UTC date -d '2026-11-08 05:48:05 -0600' +%s)"); S2=$(iso 1794049338)
141+S0=$(iso 1794162545); S2=$(iso 1794049338)
142142
143-counts() { # base -> "fetches posts downloads archives releases seeds" from the JSON
143+counts() { # base -> "fetches posts downloads archives releases seeds" from the JSON (posts and seeds: retired, null)
144144 get "$PORT" "$1" "$R.json" > /dev/null
145- jq -r '[.counts.git_fetches.count, .counts.upload_pack_requests.count, .counts.downloads.count, .counts.downloads.archives, .counts.downloads.release_assets, .counts.radicle_seeds.count] | map(tostring) | join(" ")' "$T/b"
145+ jq -r '[.counts.git_fetches.count, .counts.upload_pack_requests.count, .counts.downloads.count, .counts.downloads.archives, .counts.downloads.release_assets, .counts.seeds.count] | map(tostring) | join(" ")' "$T/b"
146146 }
147147
148148 # A torn FIRST batch must not retain its uncommitted since marker after its bytes are discarded.
149149 printf 'e g 1794162545 %s\ns 0 1794000000\n' "$RID" > "$T/data/counts.log" # a since that differs from the log's: it must not survive
150150 start
151151 # ---- 1. first read of the fixtures
152-check "$(counts /)" "4 3 2 1 1 3" "counts from the fixture logs (fetches posts downloads archives releases seeds)"
152+check "$(counts /)" "4 null 2 1 1 null" "counts from the fixture logs (fetches downloads archives releases; posts and seeds retired)"
153153 check "$(jv .counts.git_fetches.since)" "$S0" "git_fetches since = first line of the download log"
154-check "$(jv .counts.upload_pack_requests.since)" "$S1" "upload_pack since = first line of the access log (CLF -0600 to UTC)"
154+check "$(jv .counts.upload_pack_requests.since)" "null" "upload_pack: source retired, since is null"
155155 check "$(jv .counts.downloads.since)" "$S2" "downloads since = first access line of forged.log"
156156 stop; start
157-check "$(counts /)" "4 3 2 1 1 3" "restart after recovery of the torn first journal batch"
157+check "$(counts /)" "4 null 2 1 1 null" "restart after recovery of the torn first journal batch"
158158 check "$(jv .counts.git_fetches.since)" "$S0" "since survives recovery of the torn first batch"
159-case "$(jv .counts.radicle_seeds.as_of)" in 20[0-9][0-9]-*Z) ok "radicle_seeds.as_of is an ISO time";; *) bad "as_of '$(jv .counts.radicle_seeds.as_of)'";; esac
159+check "$(jv .counts.seeds.as_of)" "null" "seeds: source retired, as_of is null"
160160 c=$(get "$PORT" /forge/ "$R"); check "$c" 200 "GET /forge/ repo home"
161161 grep -q 'Clones and fetches over HTTPS: <b>4</b> by visitors' "$T/b" && ok "HTML: 4 visitor fetches" || bad "HTML fetch line: $(grep -o 'Clones and fetches[^<]*<b>[^<]*' "$T/b")"
162-grep -q "<b>3</b> <code>git-upload-pack</code> requests" "$T/b" && ok "HTML: 3 upload-pack requests" || bad "HTML upload-pack line"
162+grep -q "<b>not measured</b> <code>git-upload-pack</code> requests from all clients (the source of this count is retired)" "$T/b" && ok "HTML: upload-pack requests not measured (source retired)" || bad "HTML upload-pack line"
163163 grep -q "Downloads: <b>2</b> by visitors (1 source archives, 1 release assets" "$T/b" && ok "HTML: 2 downloads (1 + 1)" || bad "HTML downloads: $(grep -o 'Downloads:.\{0,80\}' "$T/b")"
164164 grep -q "since ${S0%%T*})" "$T/b" && grep -q "since ${S2%%T*})" "$T/b" && ok "HTML: each count names its since date" || bad "HTML since dates"
165-grep -q "Radicle: seeded by <b>3</b> nodes, this node included" "$T/b" && ok "HTML: seeded by 3 nodes (fake routing table, foreign row ignored)" || bad "HTML seeds"
165+grep -q "Seeding: <b>not measured</b> (the source of this count is retired)" "$T/b" && ok "HTML: seeding not measured (source retired)" || bad "HTML seeds"
166166 grep -q "<link rel=\"alternate\" type=\"application/json\" href=\"/forge/$R.json\">" "$T/b" && ok "repo home links its JSON form" || bad "repo home alternate link"
167167 J=$(grep -c '^e ' "$T/data/counts.log"); check "$J" 9 "journal holds the 9 counted events"
168168 sz=$(stat -c %s "$T/data/counts.log")
@@ -174,53 +174,45 @@ counts / > /dev/null; check "$(stat -c %s "$T/data/counts.log")" "$sz" "a log gr
174174 echo "1794162600.000 203.0.113.20 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
175175 echo "127.0.0.1 - - [08/Nov/2026:07:00:00 -0600] \"POST /rad/$RID.git/git-upload-pack HTTP/2.0\" 200 65 \"-\" \"git/2.43.0\"" >> "$T/ng/access.log"
176176 echo "1794049600 203.0.113.21 1 $A/archive/refs/tags/v1.tar.gz 200 1000 5" >> "$T/data/logs/forged.log"
177-check "$(counts /forge/)" "5 4 3 2 1 3" "one more line in each log counts once"
177+check "$(counts /forge/)" "5 null 3 2 1 null" "one more line in each log counts once"
178178 printf '1794162601.000 203.0.113.22 200 "/rad/%s.git%s" "git' "$RID" "$Q" >> "$T/ng/dl.log"
179-check "$(counts /)" "5 4 3 2 1 3" "a half-written last line is not counted yet"
179+check "$(counts /)" "5 null 3 2 1 null" "a half-written last line is not counted yet"
180180 printf '/2.43.0"\n' >> "$T/ng/dl.log"
181-check "$(counts /)" "6 4 3 2 1 3" "the line counts once it is complete"
181+check "$(counts /)" "6 null 3 2 1 null" "the line counts once it is complete"
182182
183183 # ---- 3. restart: journal replay, no double count
184184 stop; start
185-check "$(counts /)" "6 4 3 2 1 3" "restart replays the journal without counting twice"
185+check "$(counts /)" "6 null 3 2 1 null" "restart replays the journal without counting twice"
186186
187187 # ---- 4. rotation: rest of <log>.1, then the new <log>
188188 echo "1794162700.000 203.0.113.30 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
189189 mv "$T/ng/dl.log" "$T/ng/dl.log.1"
190190 echo "1794249000.000 203.0.113.31 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" > "$T/ng/dl.log"
191-check "$(counts /)" "8 4 3 2 1 3" "after a rotation: the rest of .1 and the new log count once each"
191+check "$(counts /)" "8 null 3 2 1 null" "after a rotation: the rest of .1 and the new log count once each"
192192 check "$(jv .counts.git_fetches.since)" "$S0" "since stays the start of the oldest log read"
193193 stop; start
194-check "$(counts /)" "8 4 3 2 1 3" "restart after the rotation"
194+check "$(counts /)" "8 null 3 2 1 null" "restart after the rotation"
195195 # ---- 5. a torn batch at the end of the journal is ignored
196196 printf 'e g 1794162999 %s\ne g 1794163000 %s\n' "$RID" "$RID" >> "$T/data/counts.log"
197197 stop; start
198-check "$(counts /)" "8 4 3 2 1 3" "a journal batch without its cursor line is ignored"
198+check "$(counts /)" "8 null 3 2 1 null" "a journal batch without its cursor line is ignored"
199199 # An abandoned batch must not be committed by the NEXT real batch's cursor.
200200 echo "1794249001.000 203.0.113.32 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
201-check "$(counts /)" "9 4 3 2 1 3" "new event after a torn journal batch"
201+check "$(counts /)" "9 null 3 2 1 null" "new event after a torn journal batch"
202202 stop; start
203-check "$(counts /)" "9 4 3 2 1 3" "later cursor cannot resurrect abandoned journal events"
203+check "$(counts /)" "9 null 3 2 1 null" "later cursor cannot resurrect abandoned journal events"
204204 # Also discard a byte-torn event line before a later append.
205205 printf 'e g 1794163000 z63' >> "$T/data/counts.log"
206206 stop; start
207-check "$(counts /)" "9 4 3 2 1 3" "partial journal line is ignored"
207+check "$(counts /)" "9 null 3 2 1 null" "partial journal line is ignored"
208208 echo "1794249002.000 203.0.113.33 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
209-check "$(counts /)" "10 4 3 2 1 3" "new event after a partial journal line"
209+check "$(counts /)" "10 null 3 2 1 null" "new event after a partial journal line"
210210 stop; start
211-check "$(counts /)" "10 4 3 2 1 3" "partial journal line cannot swallow the next event"
211+check "$(counts /)" "10 null 3 2 1 null" "partial journal line cannot swallow the next event"
212212 # ---- 5b. the old logs are gone (rotated away and compressed): the counts stay, from the journal
213213 mv "$T/ng/dl.log.1" "$T/ng/dl.log.2.gone"
214214 stop; start
215-check "$(counts /)" "10 4 3 2 1 3" "older logs gone: the counts come from the journal"
216-# ---- 6. seeding not measured when rad fails (read again because the node db changed)
217-touch "$T/bin/radfail"; sleep 0.01; echo x >> "$T/ng/wal"
218-check "$(counts /)" "10 4 3 2 1 null" "rad failing: radicle_seeds.count is null"
219-check "$(jv .counts.radicle_seeds.as_of)" "null" "rad failing: as_of is null"
220-get "$PORT" / "$R" > /dev/null
221-grep -q "Radicle: seeding <b>not measured</b>" "$T/b" && ok "HTML: seeding not measured" || bad "HTML not measured"
222-rm -f "$T/bin/radfail"; echo y >> "$T/ng/wal"
223-check "$(counts /)" "10 4 3 2 1 3" "rad answering again"
215+check "$(counts /)" "10 null 3 2 1 null" "older logs gone: the counts come from the journal"
224216
225217 # ---- 7. JSON form under both bases
226218 for b in / /forge/; do
@@ -234,19 +226,21 @@ for b in / /forge/; do
234226 check "$(jv .base)" "$b" "explore base ($b)"
235227 check "$(jv '.repos | length')" "$(jv .count)" "explore count = number of repos ($b)"
236228 check "$(jv "[.repos[] | select(.name == \"cuda-crack\")][0].path")" "${b}$R" "explore path built from the base ($b)"
237- check "$(jv "[.repos[] | select(.name == \"cuda-crack\")][0].rid")" "rad:$RID" "explore id is the RID ($b)"
229+ check "$(jv "[.repos[] | select(.name == \"cuda-crack\")][0].rid")" "$RID" "explore id is the bare RID ($b)"
238230 get "$PORT" "$b" "$R.json" > /dev/null
239231 check "$(jv .schema)" "forge/repo/1" "repo schema ($b)"
240232 check "$(jv .json)" "${b}$R.json" "repo json link ($b)"
241233 check "$(jv .archives.zip)" "${b}$R/archive/refs/heads/main.zip" "repo zip link ($b)"
242- check "$(jv .clone.git_https)" "https://www.aienos.com/rad/$RID.git" "repo git clone URL ($b)"
234+ check "$(jv .clone.git_https)" "null" "no public Git URL: git_https is null ($b)"
235+ check "$(jv .clone.rad_clone)" "null" "no clone command: rad_clone is null ($b)"
236+ check "$(jv .clone.rad)" "$RID" "clone id is the bare RID ($b)"
243237 check "$(jv .readme.raw)" "${b}$R/raw/main/README.md" "repo readme raw link ($b)"
244238 done
245239 # every public repo: last_commit sha and time equal git; the subject equals git (valid UTF-8)
246240 get "$PORT" / explore.json > /dev/null
247241 n=$(jv '.repos | length'); bad_lc=0
248242 for k in $(seq 0 $((n - 1))); do
249- rid=$(jv ".repos[$k].rid"); rid=${rid#rad:}; br=$(jv ".repos[$k].default_branch")
243+ rid=$(jv ".repos[$k].rid"); br=$(jv ".repos[$k].default_branch")
250244 ref=refs/heads/$br
251245 git --git-dir="$STORE/$rid" rev-parse -q --verify "$ref^{commit}" > /dev/null 2>&1 || ref=refs/namespaces/$NSID/refs/heads/$br
252246 want=$(git --git-dir="$STORE/$rid" log -1 --format='%H %ct' "$ref" 2> /dev/null)
@@ -280,7 +274,7 @@ get "$PORT" / "$R/tree/main" > /dev/null; grep -q "<link rel=\"alternate\" type=
280274 # ---- 8. HTML unchanged against the BASE build, apart from the known additions
281275 taskset -c "$CORES" nice -n 10 "$T/forged.base" 2>> "$T/forged.base.err" & pidb=$!; up "$PORTB"
282276 # The site icon link (ham/forge-favicon) is the third addition: every page head names <base>assets/favicon.svg.
283-strip() { sed -z -e 's|<link rel="alternate" type="application/json" href="[^"]*">||' -e 's|<link rel="icon" type="image/svg+xml" href="[^"]*assets/favicon.svg">||' -e 's|\n<p class="meta">Clones and fetches over HTTPS: [^\n]*\n<p class="meta">Downloads: [^\n]*\n<p class="meta">Radicle: [^\n]*\n||' "$1"; }
277+strip() { sed -z -e 's|<link rel="alternate" type="application/json" href="[^"]*">||' -e 's|<link rel="icon" type="image/svg+xml" href="[^"]*assets/favicon.svg">||' -e 's|\n<p class="meta">Clones and fetches over HTTPS: [^\n]*\n<p class="meta">Downloads: [^\n]*\n<p class="meta">\(Radicle\|Seeding\): [^\n]*\n||' "$1"; }
284278 # The fourth (one site, server/tests/sitechrome.sh): the interplane.io header and footer replace the
285279 # forge's, so only the page content, <main> to </main>, is compared with the base build.
286280 mainpart() { sed -n '/^<main[ >]/,/^<\/main>$/p' | sed '1s/^<main[^>]*>$/<main>/'; }
@@ -296,7 +290,7 @@ nocomment() { sed -z -e 's|<p>&lt;!-- [^\n]*--&gt;\n|<p>|g' -e 's|\n&lt;!-- [^\n
296290 # explore introduction and the forge home box, reduces each repo list row to its records (link,
297291 # description, last commit, stars) and drops the "ext" class; the lines are then compared as sorted
298292 # lists, because the home moved its lines below the README. Every other line must still be equal.
299-pjpre() { sed -e '/^<section class="pj-dev"/,/^<\/dl>$/d' -e '/^<p class="pj-recs">/,/^<\/section>$/d' -e '/^<p class="pj-nordme">/d' -e '/^<p class="meta">Clones and fetches over HTTPS: /d' -e '/^<p class="meta">Downloads: /d' -e '/^<p class="meta">Radicle: /d' "$1"; }
293+pjpre() { sed -e '/^<section class="pj-dev"/,/^<\/dl>$/d' -e '/^<p class="pj-recs">/,/^<\/section>$/d' -e '/^<p class="pj-nordme">/d' -e '/^<p class="meta">Clones and fetches over HTTPS: /d' -e '/^<p class="meta">Downloads: /d' -e '/^<p class="meta">\(Radicle\|Seeding\): /d' "$1"; }
300294 pjcanon() {
301295 sed -E -e '/^<section class="rhead/,/^<nav class="tabs/d' -e '/^<h1>Explore repositories<\/h1>/d' -e '/^<section class="box"><h1>INTERPLANE Forge<\/h1>/d' \
302296 -e 's|^<li><span class="stars" title="stars">&#9733; ([0-9]+)</span><a class="rname" href="([^"]*)">[^<]*</a><p class="desc">(.*)</p><p class="meta">Last commit: (.*)</p></li>$|ROW \2 \3 \4 \1|' \

server/tests/cutdata.sh

@@ -35,7 +35,12 @@ bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
3535 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
3636 trap "[ -n \"\$PID\" ] && kill \$PID 2>/dev/null; wait 2>/dev/null; [ -n \"\${KEEP:-}\" ] || rm -rf \"$T\"" EXIT
3737 if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
38+# STORE_VARIANT=1 (with IPL_DIR): the same gates on the store-reading build. Every start makes the
39+# store afresh from the fixture storage (store/tests/fixstore.sh: the repository as it is then, its
40+# head recorded), so what the gate wrote into the storage is what the store holds. The id is longer
41+# there (the store's old-id rule wants 20..60 letters).
3842 RID=zCutDataFixture1
43+[ "${STORE_VARIANT:-0}" = 1 ] && RID=zCutDataFixtureStore1
3944 S=$T/storage/$RID
4045 G() { git -C "$S" -c user.name=fixture -c user.email=fixture@t.invalid "$@"; }
4146 mkdir -p "$T/storage" "$T/data" "$T/social"
@@ -45,7 +50,12 @@ git init -q -b main "$W" && echo hi > "$W/a.txt" && git -C "$W" add a.txt \
4550 printf "# test allow-list\n\n| repo | RID | default branch |\n|---|---|---|\n| cutdata | rad:%s | main |\n" "$RID" > "$T/rids.md"
4651 BASE=$(G rev-parse refs/heads/main); ABLOB=$(G rev-parse "$BASE:a.txt")
4752 U=http://127.0.0.1:$PORT/drakestapleton/cutdata
53+. "$H/../../store/tests/svlib.sh"
4854 start() { # start OUT [SEDX]
55+ if [ "${STORE_VARIANT:-0}" = 1 ]; then
56+ rm -f "$T/store.fp"; svsync "$S" "$T/rids.md" "$T/storage" "$T/store" "$PORT" || return 1
57+ export FORGE_STORE=$T/store
58+ fi
4959 DATA=$T/data/ STORE=$T/storage/ RIDS=$T/rids.md SEDX=${2:-} "$H/../../collab/tests/tbuild.sh" "$1" || return 1
5060 FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" &
5161 PID=$!
@@ -54,6 +64,7 @@ start() { # start OUT [SEDX]
5464 }
5565 stop() { [ -n "$PID" ] && { kill $PID 2> /dev/null; wait $PID 2> /dev/null; }; PID=; sleep 0.3; }
5666 get() { # get FORM URL: prints the status; body in $T/body
67+ svsync "$S" "$T/rids.md" "$T/storage" "$T/store" "$PORT" || { echo "svsync failed" >&2; echo 000; return; }
5768 if [ "$1" = json ]; then curl -s -o "$T/body" --max-time 120 -w "%{http_code}" -H "Accept: application/json" "$2"
5869 else curl -s -o "$T/body" --max-time 120 -w "%{http_code}" "$2"; fi
5970 }
@@ -258,6 +269,11 @@ for i in range(1, 32):
258269 refused "31 commit subjects over 16 MiB" "$U/commits/longlog" "$CUTW"
259270 c=$(get html "$U/commits/main"); check "$c" 200 "a short history still lists"
260271 G update-ref -d refs/heads/longlog
272+# the issue sections read collaborative objects (COBs) from Radicle storage through collab/, which the
273+# store-reading build composes out (server/nocollab.om): not applicable there
274+if [ "${STORE_VARIANT:-0}" = 1 ]; then
275+ echo "NOT_APPLICABLE changes of one issue, 1,100 issues: collab/ (COBs) is not composed in the store-reading build"
276+else
261277 # ---- changes of one issue (fast-import: change 1 sets the title, change i comments body-i). Every change
262278 # holds a manifest beside its action blobs, and change 1 an embed, as a Radicle COB change does.
263279 mkissue() { # mkissue N: an issue of N changes; ISS = its id, IREF its ref, the last body holds last-N
@@ -325,6 +341,7 @@ G for-each-ref "--format=delete %(refname)" refs/tmp | G update-ref --stdin
325341 check "$(G for-each-ref refs/namespaces/fixture/refs/cobs/xyz.radicle.issue | wc -l | tr -d " ")" 1100 "fixture: 1,100 issue refs"
326342 whole "the oldest of 1,100 issues (was 404)" "$U/issues/$OLD" "issue number 0000"
327343 c=$(get html "$U/issues"); check "$c" 200 "1,100 issues: the list"
344+fi
328345 stop
329346 if [ -n "${NONEG:-}" ]; then echo "server cutdata: $PASS passed, $FAIL failed (negative controls skipped)"; [ "$FAIL" = 0 ]; exit; fi
330347 # ---- negative controls: one mechanism out, the old cut is back
@@ -335,6 +352,9 @@ neg() { # neg NAME SEDX FORM URL WANTSTATUS [WORD WANTHAS]
335352 if [ "$c" = "$5" ] && { [ -z "${6:-}" ] || [ "$(has "$6")" = "$7" ]; }; then ok "NEG $1: without it the answer is $5 again"; else bad "NEG $1: got $c"; fi
336353 stop
337354 }
355+if [ "${STORE_VARIANT:-0}" = 1 ]; then
356+ echo "NOT_APPLICABLE NEG cobrefs, changes, chunks, manifest: collab/ (COBs) is not composed in the store-reading build"
357+else
338358 neg cobrefs "/^fn corefln /,/^fincut\$/s/^if ge i CORFMAX\$/if ge i 1024/" html "$U/issues/$OLD" 500
339359 for r in $(G for-each-ref "--format=%(refname)" refs/namespaces/fixture/refs/cobs/xyz.radicle.issue); do echo "delete $r"; done | G update-ref --stdin
340360 mkissue 513
@@ -347,6 +367,7 @@ G update-ref -d "$IREF"
347367 mkissue 3
348368 neg manifest "/^fn coxln /,/^k = conum add a 41 z\$/s/^if not coisnum add a 41 z\$/if false/" html "$U/issues/$ISS" 500
349369 G update-ref -d "$IREF"
370+fi
350371 mktag t-old 10 "2026-01-01T00:00:00Z"; mktag t-new 10 "2026-02-01T00:00:00Z"
351372 neg tagcount "/^fn dltags to bool\$/,/^dlkns tdsrt0\$/s/^fka tdsortd\$/fka tdcnt1/" html "$U/releases/tag/t-old" 404
352373 G tag -d t-old > /dev/null; G tag -d t-new > /dev/null

server/tests/jsonpages.sh

@@ -24,7 +24,12 @@ PORT=${FORGE_TEST_PORT:-18478}
2424 BPORT=$((PORT + 1))
2525 BASEC=${FORGE_BASE_COMMIT:-e2feabcbf0cf56e1a4dae20f4d724b3169054747}
2626 OMC=$HOME/work/flux/omega-mv/seed/out/omc
27-STORE=$HOME/.radicle/storage
27+# the Radicle storage the table links to: FORGE_TEST_RSTORE (default ~/radicle-storage-frozen/storage,
28+# the read-only copy kept after the Radicle removal of 2026-11-14); the chrome from its interplane.io.
29+# STORE_VARIANT=1 (with IPL_DIR): both builds are store-reading builds of the same table, made into a
30+# store by store/tests/fixstore.sh (the live projects hard-linked from ~/interplane-store-owner, read only).
31+STORE=${FORGE_TEST_RSTORE:-$HOME/radicle-storage-frozen/storage}
32+export FORGE_SITE_STORE=${FORGE_SITE_STORE:-$STORE/z399yKvnXcBQNkKoq86iBDgTvQ5QV}
2833 R1=z44GqrPVAPjZkhoD2MWVjqy18ighN # aien-sovereign-core-mv storage, listed as omega-pearl
2934 R2=z6do9WDBhuSnvopDkgFdFr1yWA62 # omega-mv storage, listed as aien-crypto
3035 DENY=z2ft64NFLsKzWttCXw6NWNbRQLggQ # withdrawn omega-pearl RID
@@ -62,6 +67,7 @@ fi
6267 # commit and compare JSON must stop at the reserve with diff_truncated true and still parse. The walk
6368 # visits this repo too (both commits, the compare of the two).
6469 FXR=zJsonPagesBigDiff1
70+[ "${STORE_VARIANT:-0}" = 1 ] && FXR=zJsonPagesBigDiffStore1
6571 FXW=$T/fxw
6672 export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture \
6773 GIT_COMMITTER_EMAIL=fixture@invalid GIT_AUTHOR_DATE=2026-11-09T00:00:00Z GIT_COMMITTER_DATE=2026-11-09T00:00:00Z
@@ -83,6 +89,11 @@ fxcheck() {
8389 return $r
8490 }
8591 echo "allow-list: $(grep -c ' | rad:' "$T/RIDS.md") rows, $(ls "$T/storage" | wc -l) storage links"
92+if [ "${STORE_VARIANT:-0}" = 1 ]; then
93+ bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store" || { bad "fixture store"; exit 1; }
94+ export FORGE_STORE=$T/store
95+ echo "STORE_VARIANT: store-reading builds, store $T/store ($(wc -l < "$T/store/catalog.tsv") projects)"
96+fi
8697
8798 compose() { # compose DIR OUT DATA PORT: every unit of the tree in DIR, redirected into $T
8899 (cd "$1" && { printf 'om2\n'; cat $(./run.sh units); }) > "$2"
@@ -146,8 +157,13 @@ neg "renamed key forge/search/1 line" "$T/n2.om"
146157 sed -e 's/^ret brjroute w$/ret brroute2 w/' "$T/new.om" > "$T/n3.om"
147158 grep -q '^ret brjroute w$' "$T/n3.om" && bad "mutant n3 not applied"
148159 neg "browse ignores Accept" "$T/n3.om"
149-sed -e 's/^if and not fdeny i fstok i$/if fstok i/' "$T/new.om" > "$T/n4.om"
150-grep -q '^if fstok i$' "$T/n4.om" || bad "mutant n4 not applied"
160+if [ "${STORE_VARIANT:-0}" = 1 ]; then
161+ sed -e 's/^if fdeny k$/if false/' "$T/new.om" > "$T/n4.om"
162+ grep -q '^if fdeny k$' "$T/n4.om" && bad "mutant n4 not applied"
163+else
164+ sed -e 's/^if and not fdeny i fstok i$/if fstok i/' "$T/new.om" > "$T/n4.om"
165+ grep -q '^if fstok i$' "$T/n4.om" || bad "mutant n4 not applied"
166+fi
151167 neg "deny list removed" "$T/n4.om"
152168 # n5: brzxs without its BRYCAP stop (the 4270c80d code): the fixture JSON overflows fob and is cut
153169 sed -e '/^put gbzful 0 1$/{n;d}' "$T/new.om" > "$T/n5.om"

server/tests/overflow.sh

@@ -39,10 +39,19 @@ cp server/tests/fake/rad server/tests/fake/getent "$T/bin/"; chmod 755 "$T/bin/r
3939 git init -q -b main "$T/w" && echo fixture > "$T/w/a.txt" && git -C "$T/w" add a.txt \
4040 && git -C "$T/w" -c user.name=Fixture -c user.email=fixture@example.invalid commit -qm fixture || { echo 'FAIL fixture repo'; exit 1; }
4141 printf '| repo | RID | default branch |\n|---|---|---|\n' > "$T/RIDS.md"
42+# STORE_VARIANT=1 (with IPL_DIR): the same gates on the store-reading build; the fixture becomes a
43+# store (store/tests/fixstore.sh) and its ids are longer (the store's old-id rule wants 20..60 letters)
44+RIDP=zOverflowFixture
45+[ "${STORE_VARIANT:-0}" = 1 ] && RIDP=zOverflowFixtureStore
4246 for n in a b c d e; do
43- git clone -q --bare "$T/w" "$T/storage/zOverflowFixture$n"
44- printf '| overflow-fixture-%s | rad:zOverflowFixture%s | main |\n' "$n" "$n" >> "$T/RIDS.md"
47+ git clone -q --bare "$T/w" "$T/storage/$RIDP$n"
48+ printf '| overflow-fixture-%s | rad:%s%s | main |\n' "$n" "$RIDP" "$n" >> "$T/RIDS.md"
4549 done
50+if [ "${STORE_VARIANT:-0}" = 1 ]; then
51+ bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store" || { echo 'FAIL fixture store'; exit 1; }
52+ export FORGE_STORE=$T/store
53+ echo "STORE_VARIANT: store-reading build, store $T/store"
54+fi
4655 { printf 'om2\n'; for u in $(./run.sh units); do cat "$u"; done; } > "$T/base.om"
4756 sed -e "s|2130706433 18480|2130706433 $PORT|" \
4857 -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|g" \
@@ -89,7 +98,7 @@ want "GET /explore.json" "$(get /explore.json)" 200; JE=$(size)
8998 want "GET /no-such-page" "$(get /no-such-page)" 404; E4=$(fobsize)
9099 echo "sizes: explore page $TE, explore.json $JE, 404 page $E4"
91100 [ "$TE" -gt $((E4 + 700)) ] && [ "$JE" -gt 600 ] && ok "fixture: the pages are larger than the notice" || bad "fixture: explore $TE, json $JE, 404 $E4"
92-RID=zOverflowFixturea
101+RID=${RIDP}a
93102 short=/rad:$RID/tree/main
94103 want "GET $short" "$(get "$short")" 302
95104 want "its Location" "$(hdr location)" /drakestapleton/overflow-fixture-a/tree/main

server/tests/readmefirst.sh

@@ -8,11 +8,13 @@
88 # the real repositories, read-only) and data dirs; nothing live is touched (not 18480, not ~/forge-data).
99 # A. Records, for 5 sample projects (hop, omega-harness, omega-mv, interplane.io, aien-receipts) and
1010 # every page address they had: the same status (and redirect target) on both builds; JSON and raw
11-# bodies byte-identical; on every HTML page, every record of the base page (each link target, each
12-# <code> text, each 7 to 64 digit hex run, each bold number) is still in the head page outside the
13-# project header (the header is checked on its own: description, owner link, the counts lines and
14-# the rad clone line, which moved to the "For developers" section of the project home); the README
15-# article is the same apart from the "leaves this site" class.
11+# bodies byte-identical (the repo JSON apart from the Radicle removal: bare rid, clone and counts
12+# objects checked on their own); on every HTML page, every record of the base page (each link
13+# target, each <code> text, each 7 to 64 digit hex run, each bold number) is still in the head page
14+# outside the project header, except the Radicle records removed on purpose (the header is checked
15+# on its own: description, owner link, the counts lines and the clone panel, which moved to the
16+# "For developers" section of the project home); the README article is the same apart from the
17+# "leaves this site" class.
1618 # Negative control: a head mutant whose project home drops the clone panel must fail A.
1719 # B. State: the label of each project equals an independent reading of the receipts list (a shell walk
1820 # of the chain the way verify.sh does it, plus the evidence file hashes), on the real list (hop
@@ -25,7 +27,8 @@
2527 # event handler or remote image in the page; the page's Content-Security-Policy is sent; every link
2628 # that leaves the site is marked. A made-up project without a README: the plain note and its files.
2729 # D. Words: the project header and tabs (everything above the README) and the explore page's own text
28-# hold none of RID, delegate, seed, patch, refs, HEAD; the "For developers" section explains each.
30+# hold none of RID, delegate, seed, patch, refs, HEAD; the "For developers" section explains the
31+# words it uses (delegate, refs and HEAD, patch, receipt).
2932 set -u
3033 cd "$(dirname "$0")/../.."
3134 ROOT=$(pwd)
@@ -125,9 +128,17 @@ mainpart() { sed -n '/^<main[ >]/,/^<\/main>$/p' "$1"; }
125128 nohead() { mainpart "$1" | sed '/^<section class="rhead/,/^<nav class="tabs/d'; }
126129 headpart() { mainpart "$1" | sed -n '/^<section class="rhead/,/^<nav class="tabs/p'; }
127130 recs() { # recs FILE: the records of a page outside its project header, one per line, sorted, unique
128- nohead "$1" > "$1.nh"
131+ nohead "$1" | sed '/<p class="meta">Radicle: /d' > "$1.nh" # the retired seed-count line (its <b>N</b>)
129132 { grep -o 'href="[^"]*"' "$1.nh"; grep -o '<code>[^<]*</code>' "$1.nh"; grep -oE '(^|[^0-9a-f])[0-9a-f]{7,64}([^0-9a-f]|$)' "$1.nh" | grep -oE '[0-9a-f]{7,64}'; grep -o '<b>[0-9]*</b>' "$1.nh"; } | sort -u
130133 }
134+gone() { # the base records removed on purpose with Radicle (ids, rad commands, /rad/ clone URLs)
135+ grep -viE 'radicle|\brad:z[1-9A-HJ-NP-Za-km-z]{10,}|\brad (clone|init|sync|patch|auth|node|issue|seed|inspect)|git push rad\b|/rad/|heartwood'
136+}
137+jnorm() { # jnorm FILE: the repo JSON without the clone and counts objects, with a bare rid, and the
138+ # description cut the way server/util.om fdclean cuts it (sentences naming the retired network)
139+ jq -S 'del(.clone, .counts) | if type == "object" and has("rid") then .rid |= sub("^rad:"; "") else . end
140+ | if type == "object" and (.description | type) == "string" then .description |= ([splits("(?<=\\.) +")] | map(select(test("radicle|heartwood|rad:z|/rad/|rad (clone|init|sync|id|patch|auth)"; "i") | not)) | join(" ")) else . end' "$1"
141+}
131142 readme() { mainpart "$1" | sed -n '/^<div class="box readme">/,/^<\/article><\/div>$/p' | sed 's| class="ext" rel="nofollow| rel="nofollow|g; s|\(href="mailto:[^"]*"\) rel="nofollow noopener noreferrer">|\1>|g'; }
132143
133144 # ---- builds
@@ -155,22 +166,32 @@ checkrecs() { # checkrecs BUILDPORT LABEL: compare every page of the 5 projects
155166 sh=$(get "$p" "$path" "$T/h.html" | sed "s|http://127.0.0.1:$p/|/|"); sb=$(get "$PORTB" "$path" "$T/b.html" | sed "s|http://127.0.0.1:$PORTB/|/|")
156167 if [ "$sh" != "$sb" ]; then echo " $2 $path: status '$sh', base '$sb'"; nf=$((nf+1)); continue; fi
157168 case "$sh" in 200*) ;; *) continue ;; esac
158- # a repo's JSON carries the second each server first read its seeds (counts.om fzseeds as_of): left out
159- case $u in .json|raw/*) cmp -s <(sed 's/"as_of":"[^"]*"/"as_of":""/g' "$T/h.html") <(sed 's/"as_of":"[^"]*"/"as_of":""/g' "$T/b.html") || { echo " $2 $path: body differs"; nf=$((nf+1)); }; continue ;; esac
160- missing=$(comm -23 <(recs "$T/b.html") <(recs "$T/h.html"))
169+ # the repo JSON: the clone and counts objects and the rid prefix changed with the Radicle removal
170+ case $u in
171+ .json) cmp -s <(jnorm "$T/h.html") <(jnorm "$T/b.html") || { echo " $2 $path: body differs"; nf=$((nf+1)); }
172+ [ "$(jq -c .clone "$T/h.html")" = "{\"rad\":\"$(rid "$n")\",\"rad_clone\":null,\"git_https\":null}" ] || { echo " $2 $path: clone object is not bare rid + nulls"; nf=$((nf+1)); }
173+ [ "$(jq -c '[.counts.upload_pack_requests.count, .counts.seeds.count, .counts.seeds.as_of]' "$T/h.html")" = "[null,null,null]" ] || { echo " $2 $path: retired counts are not null"; nf=$((nf+1)); }
174+ continue ;;
175+ raw/*) cmp -s "$T/h.html" "$T/b.html" || { echo " $2 $path: body differs"; nf=$((nf+1)); }; continue ;;
176+ esac
177+ missing=$(comm -23 <(recs "$T/b.html" | gone) <(recs "$T/h.html"))
161178 [ -z "$missing" ] || { echo " $2 $path: records missing: $(echo "$missing" | head -3 | tr '\n' ' ')"; nf=$((nf+1)); }
162179 hb=$(headpart "$T/b.html")
163180 d=$(echo "$hb" | sed -n 's|.*<p class="desc">\([^<]*\)</p>.*|\1|p' | head -1)
164- [ -z "$d" ] || grep -qF "<p class=\"desc\">$d</p>" "$T/h.html" || { echo " $2 $path: description missing"; nf=$((nf+1)); }
181+ # a description naming the retired network is shown cut (server/util.om fdclean): compare its first sentence that does not
182+ d=$(printf '%s' "$d" | sed 's/\. /.\n/g' | grep -viE 'radicle|heartwood|rad:z|/rad/|rad (clone|init|sync|id|patch|auth)' | head -1)
183+ [ -z "$d" ] || grep -qF "$d" "$T/h.html" || { echo " $2 $path: description missing"; nf=$((nf+1)); }
165184 if grep -q '^<section class="rhead' "$T/b.html"; then
166185 grep -qF 'href="/drakestapleton"' "$T/h.html" || { echo " $2 $path: owner link missing"; nf=$((nf+1)); }
167186 fi
168187 if [ "$u" = . ]; then
169- for l in 'Clones and fetches over HTTPS: ' 'Downloads: ' 'Radicle: '; do
170- a=$(grep -F "<p class=\"meta\">$l" "$T/b.html" | sed 's/; read [0-9: -]* UTC)/)/'); b=$(grep -F "<p class=\"meta\">$l" "$T/h.html" | sed 's/; read [0-9: -]* UTC)/)/')
188+ # the fetch count (before the retired upload-pack count) and the downloads line are kept
189+ for l in 'Clones and fetches over HTTPS: ' 'Downloads: '; do
190+ a=$(grep -F "<p class=\"meta\">$l" "$T/b.html" | sed 's/ &#183; .*//'); b=$(grep -F "<p class=\"meta\">$l" "$T/h.html" | sed 's/ &#183; .*//')
171191 [ -n "$a" ] && [ "$a" = "$b" ] || { echo " $2 $path: count line '$l' differs"; nf=$((nf+1)); }
172192 done
173- grep -qF "rad clone rad:$(rid "$n")" "$T/h.html" || { echo " $2 $path: rad clone line missing"; nf=$((nf+1)); }
193+ grep -qF '<p class="meta">Seeding: <b>not measured</b> (the source of this count is retired)</p>' "$T/h.html" || { echo " $2 $path: seeding line is not 'not measured'"; nf=$((nf+1)); }
194+ grep -qF '<div class="clone">' "$T/h.html" || { echo " $2 $path: clone panel missing"; nf=$((nf+1)); }
174195 grep -q 'id="For-developers"' "$T/h.html" || { echo " $2 $path: no For-developers section"; nf=$((nf+1)); }
175196 [ "$(readme "$T/h.html")" = "$(readme "$T/b.html")" ] || { echo " $2 $path: README differs"; nf=$((nf+1)); }
176197 fi
@@ -189,7 +210,7 @@ done
189210 stop "$pid" "$PORT"; pid=
190211 start mutA "$PORT" "$T/data"; pid=$spid
191212 checkrecs "$PORT" mutA > "$T/mutA.out"; nf=$?
192-[ "$nf" -gt 0 ] && grep -q 'records missing\|rad clone line missing' "$T/mutA.out" && ok "A negative control: the home without its clone panel fails ($nf differences)" || bad "A negative control: mutant A passed"
213+[ "$nf" -gt 0 ] && grep -q 'records missing\|clone panel missing' "$T/mutA.out" && ok "A negative control: the home without its clone panel fails ($nf differences)" || bad "A negative control: mutant A passed"
193214 stop "$pid" "$PORT"; pid=
194215 stop "$pidb" "$PORTB"; pidb=
195216
@@ -323,7 +344,7 @@ for n in $NAMES hostile noreadme; do
323344 d=$(headpart "$T/w.html" | sed 's|<p class="desc">[^<]*</p>||; s|<[^>]*>| |g')
324345 hit=$(printf '%s' "$d" | grep -oiE "$words" | sort -u | tr '\n' ' ')
325346 [ -z "$hit" ] && ok "D: $n: no developer word above the README" || bad "D: $n above the README: $hit"
326- for t in '<dt>RID</dt>' '<dt>Delegate</dt>' '<dt>Seed</dt>' '<dt>Refs and HEAD</dt>' '<dt>Patch</dt>' '<dt>Receipt</dt>'; do
347+ for t in '<dt>Delegate</dt>' '<dt>Refs and HEAD</dt>' '<dt>Patch</dt>' '<dt>Receipt</dt>'; do
327348 grep -qF "$t" "$T/w.html" || bad "D: $n: the For developers section lacks $t"
328349 done
329350 done

server/tests/sitechrome.sh

@@ -39,7 +39,7 @@ PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
3939 PORT=${FORGE_CHROME_PORT:-18574}
4040 SITE_RID=z399yKvnXcBQNkKoq86iBDgTvQ5QV
4141 CSP="default-src 'none'; style-src 'self'; img-src 'self'; script-src 'none'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'"
42-case "$PORT" in 185[5-9][0-9]) ;; *) echo 'REFUSED: use a private port in 18550..18599'; exit 2;; esac
42+case "$PORT" in 185[5-9][0-9]|1999[0-9]) ;; *) echo 'REFUSED: use a private port in 18550..18599 or 19990..19999'; exit 2;; esac
4343 [ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo 'FAIL compiler pin'; exit 1; }
4444 if ss -ltnH "sport = :$PORT" | grep -q .; then echo "NOT_RUN: private port $PORT busy"; exit 3; fi
4545 T=$(mktemp -d)
@@ -62,7 +62,9 @@ if [ -n "${SITE_SRC:-}" ]; then
6262 REF="$SITE_SRC at $(git -C "$SITE_SRC" rev-parse HEAD 2>/dev/null || echo 'no git')"
6363 export FORGE_SITE_SRC=$SITE_SRC
6464 else
65- S=$HOME/.radicle/storage/$SITE_RID
65+ # the site repository: FORGE_SITE_STORE, else the frozen copy kept after the Radicle removal
66+ S=${FORGE_SITE_STORE:-$HOME/radicle-storage-frozen/storage/$SITE_RID}
67+ export FORGE_SITE_STORE=$S
6668 SITE_SHA=$(git --git-dir="$S" rev-parse refs/heads/main)
6769 git --git-dir="$S" archive "$SITE_SHA" content/_layout.html public/style.css | tar -x -C "$T/ref"
6870 mv "$T/ref/content/_layout.html" "$T/ref/layout.html"; mv "$T/ref/public/style.css" "$T/ref/style.css"
@@ -133,6 +135,13 @@ git -C "$T/repo" add .
133135 git -C "$T/repo" -c user.name=Fixture -c user.email=fixture@example.invalid commit -qm 'chrome fixture'
134136 git clone -q --bare "$T/repo" "$T/storage/$RID"
135137 printf '| repo | RID | default branch |\n|---|---|---|\n| chromefixture | rad:%s | main |\n' "$RID" > "$T/RIDS.md"
138+# STORE_VARIANT=1 (with IPL_DIR): the same gates on the store-reading build (the fixture made a store)
139+SV=${STORE_VARIANT:-0}
140+if [ "$SV" = 1 ]; then
141+ bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store" || die "fixture store"
142+ export FORGE_STORE=$T/store
143+ echo "STORE_VARIANT: store-reading build, store $T/store"
144+fi
136145 # build NAME [SED]: compose this tree's units with every live target moved into $T, compile to $T/NAME.bin
137146 build() {
138147 local name=$1 extra=()
@@ -148,7 +157,9 @@ build() {
148157 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \
149158 -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \
150159 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "${extra[@]}" "$T/$name.base.om" > "$T/$name.om"
151- for marker in "2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/"; do grep -qF "$marker" "$T/$name.om"; done
160+ local marks=("2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/")
161+ [ "$SV" = 1 ] && marks=("2130706433 $PORT" "$T/store/" "$T/data/")
162+ for marker in "${marks[@]}"; do grep -qF "$marker" "$T/$name.om"; done
152163 if grep -qE '2130706433 18480|/home/drakestapleton/(forge-data|\.radicle|handoffs/radicle)' "$T/$name.om"; then
153164 die "live target remains in $name"
154165 fi
@@ -173,6 +184,9 @@ get() {
173184 }
174185 hdr() { grep -i "^$1:" "$T/hdr" | head -1 | tr -d '\r' | cut -d' ' -f2-; }
175186 PAGES="explore:200 drakestapleton/chromefixture:200 drakestapleton/chromefixture/patches:200 drakestapleton/chromefixture/issues:200 search?q=chrome:200 stars:303 login:200 no-such-page-xyz:404"
187+# the store-reading build composes collab/ out: its patch and issue pages are the 501 page, which carries
188+# the same chrome
189+[ "$SV" = 1 ] && PAGES=${PAGES//patches:200/patches:501} && PAGES=${PAGES//issues:200/issues:501}
176190 # pagechecks BASE: checks 1 to 3 and 6 on every page; returns 1 with the reason on the first failure
177191 pagechecks() {
178192 local b=$1 pc page want code body cur
@@ -197,8 +211,11 @@ pagechecks() {
197211 [ "$cur" = '<a href="https://interplane.io/explore" aria-current="true">Forge</a>' ] || { echo "$b$page: current entry is '$cur'"; return 1; }
198212 grep -qF '<a class="brand" href="https://interplane.io/" aria-label="Interplane home">' <<< "$body" || { echo "$b$page: brand target"; return 1; }
199213 # slice entries after Stars: Open builds on every base; Research on base / only; Bring your build
200- # only while the salvage store is on, and it is off in this build
201- more="<a href=\"${b}open/\">Open builds</a>"; [ "$b" = / ] && more="$more<a href=\"/research\">Research</a>"
214+ # only while the salvage store is on, and it is off in this build; Feed (door/ evnav) on every base
215+ # (the store-reading build composes open/ out: no Open builds entry there)
216+ more="<a href=\"${b}open/\">Open builds</a>"; [ "$SV" = 1 ] && more=""
217+ [ "$b" = / ] && more="$more<a href=\"/research\">Research</a>"
218+ more="$more<a href=\"${b}feed\">Feed</a>"
202219 grep -qF "<nav class=\"forge-nav\" aria-label=\"Forge\"><a href=\"${b}explore\">Explore</a><a href=\"${b}stars\">Stars</a>$more</nav><form class=\"search\" method=\"get\" action=\"${b}search\" role=\"search\">" <<< "$body" || { echo "$b$page: forge row controls"; return 1; }
203220 grep -qF "<div class=\"who\"><a href=\"${b}login\">Sign in</a></div>" <<< "$body" || { echo "$b$page: Sign in"; return 1; }
204221 done

server/tests/title.sh

@@ -9,7 +9,7 @@ cd "$(dirname "$0")/../.."
99 OMC=$HOME/work/flux/omega-mv/seed/out/omc
1010 PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
1111 PORT=${FORGE_TITLE_PORT:-18557}
12-case "$PORT" in 185[5-9][0-9]) ;; *) echo 'REFUSED: use a private port in 18550..18599'; exit 2;; esac
12+case "$PORT" in 185[5-9][0-9]|1999[0-9]) ;; *) echo 'REFUSED: use a private port in 18550..18599 or 19990..19999'; exit 2;; esac
1313 [ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo 'FAIL compiler pin'; exit 1; }
1414 if ss -ltnH "sport = :$PORT" | grep -q .; then echo "NOT_RUN: private port $PORT busy"; exit 3; fi
1515 T=$(mktemp -d)
@@ -56,6 +56,15 @@ git -C "$T/repo" add .
5656 git -C "$T/repo" -c user.name=Fixture -c user.email=fixture@example.invalid commit -qm 'L1057 fixture'
5757 git clone -q --bare "$T/repo" "$T/storage/$RID"
5858 printf '| repo | RID | default branch |\n|---|---|---|\n| crashfixture | rad:%s | main |\n' "$RID" > "$T/RIDS.md"
59+# STORE_VARIANT=1 (with IPL_DIR): the HTTP part on the store-reading build; the fixture made a store and
60+# the units composed again for it (the unit part above is the same code in both builds)
61+SV=${STORE_VARIANT:-0}
62+if [ "$SV" = 1 ]; then
63+ FIXSTORE_FROM=/nonexistent bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store"
64+ export FORGE_STORE=$T/store
65+ { printf 'om2\n'; for u in $(./run.sh units); do cat "$u"; done; } > "$T/base.om"
66+ echo "STORE_VARIANT: store-reading build, store $T/store"
67+fi
5968 sed -e "s|2130706433 18480|2130706433 $PORT|" \
6069 -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|g" \
6170 -e "s|/home/drakestapleton/.radicle/storage/|$T/storage/|g" \
@@ -66,7 +75,9 @@ sed -e "s|2130706433 18480|2130706433 $PORT|" \
6675 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \
6776 -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \
6877 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "$T/base.om" > "$T/http.om"
69-for marker in "2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/"; do grep -qF "$marker" "$T/http.om"; done
78+marks=("2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/")
79+[ "$SV" = 1 ] && marks=("2130706433 $PORT" "$T/store/" "$T/data/")
80+for marker in "${marks[@]}"; do grep -qF "$marker" "$T/http.om"; done
7081 if grep -qE '2130706433 18480|/home/drakestapleton/(forge-data|\.radicle|handoffs/radicle)' "$T/http.om"; then
7182 echo 'FAIL live target remains'; exit 1
7283 fi

server/tests/translate.sh

@@ -13,7 +13,7 @@
1313 # and markup leaves every protected string, every link target and every hash/id byte-identical;
1414 # 4. the hints change nothing else: each page's <main> minus the hints is byte-identical to the same
1515 # page from this head built with the hint pass taken out of fsend0 (the send path before server/tr.om);
16-# 5. ?format=text answers text/plain with the same CSP, the clone command in backticks, no markup;
16+# 5. ?format=text answers text/plain with the same CSP, inline code in backticks, no markup;
1717 # Negative controls (each must FAIL for its reason): a fixture page with a bare hash; a forged built
1818 # without the translate="no" attribute (tftrno emptied); a forged whose page CSP lacks
1919 # script-src 'none'; a hostile run on the fixture page; a hint pass that adds visible text (check 4).
@@ -82,8 +82,7 @@ respchecks() {
8282 cspok "$f.h" "$tg $R1?format=text"
8383 ct=$(tr -d '\r' < "$f.h" | sed -n 's/^[Cc]ontent-[Tt]ype: //p')
8484 [ "$ct" = "text/plain; charset=utf-8" ] && ok "$tg text: content type $ct" || bad "$tg text: content type '$ct'"
85- rid=$(grep -m1 -E '^\| aienux \| rad:' "$HOME/handoffs/radicle/RIDS.md" | cut -d'|' -f3 | tr -d ' ')
86- grep -qF "\`rad clone $rid\`" "$f" && ok "$tg text: clone command in backticks ($rid)" || bad "$tg text: no \`rad clone $rid\`"
85+ grep -qE '`[^`]+`' "$f" && ok "$tg text: inline code in backticks" || bad "$tg text: no inline code in backticks"
8786 grep -qE '<(p|div|a|span|code|pre|table|section|main|h[1-6])[ >]' "$f" && bad "$tg text: HTML markup left in the text" || ok "$tg text: no HTML markup"
8887 head -1 "$f" | grep -q '^Interplane page as plain text' && ok "$tg text: preface line" || bad "$tg text: no preface"
8988 grep -q '^# ' "$f" && ok "$tg text: README headings as #" || bad "$tg text: no # heading"
@@ -156,8 +155,8 @@ while read -r p f; do
156155 mh=$(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$f.strip" | sha256sum | cut -c1-16)
157156 mb=$(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$T/base-$i.html" | sha256sum | cut -c1-16)
158157 # the counts lines move with the logs between the two reads; compare without them
159- mh2=$(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$f.strip" | grep -v '^<p class="meta">\(Clones\|Downloads\|Radicle\)' | sha256sum | cut -c1-16)
160- mb2=$(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$T/base-$i.html" | grep -v '^<p class="meta">\(Clones\|Downloads\|Radicle\)' | sha256sum | cut -c1-16)
158+ mh2=$(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$f.strip" | grep -v '^<p class="meta">\(Clones\|Downloads\|Seeding\)' | sha256sum | cut -c1-16)
159+ mb2=$(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$T/base-$i.html" | grep -v '^<p class="meta">\(Clones\|Downloads\|Seeding\)' | sha256sum | cut -c1-16)
161160 if [ "$mh" = "$mb" ] || [ "$mh2" = "$mb2" ]; then ok "unchanged $p: <main> minus hints = base ($mh2)"; else bad "changed $p: <main> minus hints $mh2, base $mb2"; diff <(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$f.strip") <(awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$T/base-$i.html") | head -6; fi
162161 done < "$T/head.list"
163162 stop
@@ -186,7 +185,7 @@ if [ "$fail" -gt "$f0" ]; then fail=$f0; pass=$p0; ok "NEG forged whose page CSP
186185
187186 # check 4's controls, on the build under test and its build without the hint pass
188187 # main4 FILE: <main> of a page without the counts lines, which move with the logs between two reads
189-main4() { awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$1" | grep -v '^<p class="meta">\(Clones\|Downloads\|Radicle\)'; }
188+main4() { awk '/<main id="main"/{on=1} on{print} /<\/main>/{on=0}' "$1" | grep -v '^<p class="meta">\(Clones\|Downloads\|Seeding\)'; }
190189 # same4 HINTED PLAIN: HINTED minus the hints has the same <main> as PLAIN
191190 same4() { "$PY" "$CHK" strip "$1" "$1.strip" && [ "$(main4 "$1.strip" | sha256sum)" = "$(main4 "$2" | sha256sum)" ]; }
192191 # page4 BIN OUT: R1 from that build

server/tests/trial-real.sh

@@ -27,13 +27,13 @@ echo "repo home, first read of the logs: $(t drakestapleton/cuda-crack) s"
2727 echo "repo home, next read: $(t drakestapleton/cuda-crack) s"
2828 echo "repo home JSON: $(t drakestapleton/cuda-crack.json) s"
2929 echo "explore JSON: $(t explore.json) s"
30-t drakestapleton/cuda-crack > /dev/null; grep '<p class="meta">\(Clones\|Downloads\|Radicle\)' "$T/b" | sed 's/<[^>]*>//g'
30+t drakestapleton/cuda-crack > /dev/null; grep '<p class="meta">\(Clones\|Downloads\|Seeding\)' "$T/b" | sed 's/<[^>]*>//g'
3131 echo "journal: $(grep -c '^e ' "$T/data/counts.log" 2> /dev/null || echo 0) events, $(grep -c '^k ' "$T/data/counts.log" 2> /dev/null || echo 0) cursor lines"
3232 for n in $(curl -s -H "X-Forge-Base: /" "http://127.0.0.1:$PORT/explore.json" | jq -r '.repos[].name'); do
3333 curl -s -H "X-Forge-Base: /" "http://127.0.0.1:$PORT/drakestapleton/$n.json" |
34- jq -r --arg n "$n" '[$n, .counts.git_fetches.count, .counts.upload_pack_requests.count, .counts.downloads.count, .counts.radicle_seeds.count] | map(tostring) | join(" ")'
34+ jq -r --arg n "$n" '[$n, .counts.git_fetches.count, .counts.upload_pack_requests.count, .counts.downloads.count, .counts.seeds.count] | map(tostring) | join(" ")'
3535 done | column -t | sed '1i name fetches upload_pack downloads seeds'
36-echo "since: $(curl -s -H "X-Forge-Base: /" "http://127.0.0.1:$PORT/drakestapleton/cuda-crack.json" | jq -c '[.counts.git_fetches.since, .counts.upload_pack_requests.since, .counts.downloads.since, .counts.radicle_seeds.as_of]')"
36+echo "since: $(curl -s -H "X-Forge-Base: /" "http://127.0.0.1:$PORT/drakestapleton/cuda-crack.json" | jq -c '[.counts.git_fetches.since, .counts.upload_pack_requests.since, .counts.downloads.since, .counts.seeds.as_of]')"
3737 FORGE_SMOKE_PORT=$PORT bash infra/smoke.sh local | grep -E '^(FAIL|smoke:)'
3838 if [ -n "${EXTRA:-}" ]; then # the slices' own HTTP gates against this trial (dl writes dl/evidence/http-*.txt)
3939 bash dl/tests/http-check.sh "$PORT" 2>&1 | grep -E "^(FAIL|RESULT)"

server/util.om

@@ -8,6 +8,12 @@ global fqs uchar 4096
88 global fqsl ulong 1
99 global fbody uchar 65536
1010 global fbodyl ulong 1
11+note fbig: the body of a POST whose path ends in /patches/new (git patch intake, docs/API.md), at most
12+note 3 MiB (3145728 bytes: a 2 MiB mbox as base64url is 2796203 bytes, a 60000-byte description
13+note percent-encoded at most 180000, the rest under 20000). server/main.om freqbig fills it and leaves
14+note fbody empty; every other POST keeps the 64 KiB fbody and has fbigl 0.
15+global fbig uchar 3145728
16+global fbigl ulong 1
1117 global fck uchar 4096
1218 global fckl ulong 1
1319 global fip uchar 64
@@ -58,23 +64,28 @@ global fetagl ulong 1
5864 global fcc uchar 128
5965 global fccl ulong 1
6066 global fval uchar 4096
61-note ---- allow-list (server/repos.om fills it)
67+note ---- allow-list (server/repos.om fills it). FAMAX rows: every table below indexed by the row has
68+note FAMAX entries, and every loop over the rows is bound FAMAX. The pools hold FAMAX rows at the
69+note longest each row may be (name 100 + slack, id 64, branch 60, description and last commit as
70+note before, times four). Sized 2026-11-14 from 64 to 256 for the native store (105 public projects
71+note in it); store/tests/capacity.sh fails loudly when a store or RIDS.md table passes 192 rows.
72+const FAMAX ulong 256
6273 global fan ulong 1
63-global fanm uchar 8192
64-global fano ulong 64
65-global fanl ulong 64
66-global faid uchar 4096
67-global faio ulong 64
68-global fail ulong 64
69-global fabr uchar 4096
70-global fabo ulong 64
71-global fabl ulong 64
72-global fadesc uchar 65536
73-global fado ulong 64
74-global fadl ulong 64
75-global falc uchar 65536
76-global falco ulong 64
77-global falcl ulong 64
74+global fanm uchar 32768
75+global fano ulong 256
76+global fanl ulong 256
77+global faid uchar 16384
78+global faio ulong 256
79+global fail ulong 256
80+global fabr uchar 16384
81+global fabo ulong 256
82+global fabl ulong 256
83+global fadesc uchar 262144
84+global fado ulong 256
85+global fadl ulong 256
86+global falc uchar 262144
87+global falco ulong 256
88+global falcl ulong 256
7889 global famt ulong 1
7990 note ---- exec
8091 global fpk uchar 8192
@@ -106,6 +117,18 @@ note fretry: nonzero = send "Retry-After: <fretry>" (seconds) with the response
106117 global fretry ulong 1
107118 note fcspsb: nonzero = send the sandbox CSP instead of the page CSP (browse /raw/), see fsetsbx
108119 global fcspsb ulong 1
120+note fmvng: 1 = this 503 is the "moving" answer of a part that is moving to the new Interplane store
121+note (store/moving.om, store build only): ferrti, ferrmsg and fyerr then give its title, its text and
122+note "reason":"moving"; every other 503 (door fail-closed, dl Retry-After) keeps its own words
123+global fmvng ulong 1
124+note fsrcst: 1 when the repositories are a native Interplane store (store/repos.om sets it when it
125+note loads; the default build never does): fkgit / fkgiti then name <fsrt>projects/<name>/repo.git,
126+note fsrt being the store root with its final "/". 0: <tfstore><RID>, Radicle storage.
127+global fsrcst ulong 1
128+global fsrt uchar 4096
129+global fsrtl ulong 1
130+text tfsprj "projects/"
131+text tfsrg "/repo.git"
109132 text tfstore "/home/drakestapleton/.radicle/storage/"
110133 text tfgit "/usr/bin/git"
111134 text tfdata "/home/drakestapleton/forge-data/"
@@ -265,7 +288,7 @@ end
265288 ret true
266289 end
267290 fn frepoix to ulong
268-for i ulong get fan 0 bound 64
291+for i ulong get fan 0 bound FAMAX
269292 if fnmeq i
270293 ret i
271294 end
@@ -542,12 +565,38 @@ for i ulong get fridl 0 bound 64
542565 fkc get frid i
543566 end
544567 end
545-note fkgit: argv = /usr/bin/git --git-dir=<storage>/<frid>
568+note fkgit: argv = /usr/bin/git --git-dir=<storage>/<frid> (store: the current repo's repo.git)
569+global fpubgit ulong 1
570+text tfpubgit "/app/public-git/"
571+text tfpubext ".git"
572+note fksource: public browse and download objects. Signed catalog, records and proposal checks use fkgit/fkgiti.
573+fn fksource to void
574+if eq get fpubgit 0 0
575+fkgit
576+ret
577+end
578+fkb
579+fka tfgit
580+fkopen
581+fkt tfgitdir
582+fkt tfpubgit
583+i = get fridx 0
584+if lt i get fan 0
585+for k ulong get fanl i bound 128
586+fkc frnbyte i k
587+end
588+end
589+fkt tfpubext
590+end
546591 fn fkgit to void
547592 fkb
548593 fka tfgit
549594 fkopen
550595 fkt tfgitdir
596+if eq get fsrcst 0 1
597+fksdir get fridx 0
598+ret
599+end
551600 fkt tfstore
552601 fkrid
553602 end
@@ -557,11 +606,28 @@ fkb
557606 fka tfgit
558607 fkopen
559608 fkt tfgitdir
609+if eq get fsrcst 0 1
610+fksdir i
611+ret
612+end
560613 fkt tfstore
561614 for k ulong get fail i bound 64
562615 fkc fridbyte i k
563616 end
564617 end
618+note fksdir: <fsrt>projects/<name of i>/repo.git into the open argument (no name past the list)
619+fn fksdir i ulong to void
620+for k ulong get fsrtl 0 bound 4096
621+fkc get fsrt k
622+end
623+fkt tfsprj
624+if lt i get fan 0
625+for k ulong get fanl i bound 128
626+fkc frnbyte i k
627+end
628+end
629+fkt tfsrg
630+end
565631 note ---- run argv fpk: no shell, no PATH, empty environment, stdout into fxo
566632 fn fpfdv i ulong to int
567633 b = mul i 4
@@ -571,11 +637,21 @@ v = or v shl ulong get fpfd add b 3 24
571637 ret int v
572638 end
573639 fn fchild wfd int to void
640+fchildin wfd -1
641+end
642+fn fchildin wfd int infd int to void
574643 nul = fopen tfdevnul 0 len tfdevnul 2 0
575644 if lt nul 0
576645 exit 126
577646 end
578-x = dupfd int nul 0 0
647+input = infd
648+if lt input 0
649+input = int nul
650+end
651+x = dupfd input 0 0
652+if lt x 0
653+exit 126
654+end
579655 x = dupfd wfd 1 0
580656 x = dupfd int nul 2 0
581657 x = execprog fpk 0 get fpkl 0
@@ -651,6 +727,9 @@ end
651727 ret -4
652728 end
653729 fn fexec tmo long to long
730+ret fexecin tmo -1
731+end
732+fn fexecin tmo long infd int to long
654733 put fxol 0 0
655734 put fxotr 0 0
656735 r = pipefds fpfd 0 8 524288
@@ -667,7 +746,7 @@ x = fclose wfd
667746 ret -2
668747 end
669748 if eq pid 0
670-fchild wfd
749+fchildin wfd infd
671750 exit 127
672751 end
673752 x = fclose wfd
@@ -1011,3 +1090,130 @@ end
10111090 end
10121091 ret true
10131092 end
1093+note ---- fdclean: the description of repo i as the forge shows it (fadesc[fado i, +fadl i]).
1094+note Radicle was removed from Interplane on 2026-11-14 and some identity documents still name it.
1095+note The stored document is not changed; the copy loaded into fadesc is cut once, at load
1096+note (server/repos.om fdcopy): sentences (ending ". ") that name the retired network are dropped;
1097+note when none is left, the text before the first " (" or ": " is kept if it names nothing retired;
1098+note otherwise the description is empty.
1099+text tfdt1 "radicle"
1100+text tfdt2 "heartwood"
1101+text tfdt3 "rad:z"
1102+text tfdt4 "/rad/"
1103+text tfdt5 "rad clone"
1104+text tfdt6 "rad init"
1105+text tfdt7 "rad sync"
1106+text tfdt8 "rad id"
1107+text tfdt9 "rad patch"
1108+text tfdt10 "rad auth"
1109+note fdhas: does fadesc[a, b) hold t (lowercase ASCII), compared without case
1110+fn fdhas a ulong b ulong t view uchar * to bool
1111+n = len t
1112+if lt b add a n
1113+ret false
1114+end
1115+m = add sub sub b a n 1
1116+for i ulong m bound 65536
1117+ok = true
1118+for k ulong n bound 16
1119+c = get fadesc add add a i k
1120+if and ge c 65 le c 90
1121+c = add c 32
1122+end
1123+if ne c get t k
1124+ok = false
1125+end
1126+end
1127+if ok
1128+ret true
1129+end
1130+end
1131+ret false
1132+end
1133+fn fdterm a ulong b ulong to bool
1134+if or fdhas a b tfdt1 or fdhas a b tfdt2 or fdhas a b tfdt3 fdhas a b tfdt4
1135+ret true
1136+end
1137+if or fdhas a b tfdt5 or fdhas a b tfdt6 or fdhas a b tfdt7 fdhas a b tfdt8
1138+ret true
1139+end
1140+ret or fdhas a b tfdt9 fdhas a b tfdt10
1141+end
1142+note fdfind: the first p in [a, b-1) with fadesc[p] = c1 and fadesc[p+1] = c2, else b
1143+fn fdfind a ulong b ulong c1 uchar c2 uchar to ulong
1144+if le b add a 1
1145+ret b
1146+end
1147+for i ulong sub sub b a 1 bound 65536
1148+p = add a i
1149+x = get fadesc p
1150+y = get fadesc add p 1
1151+if and eq x c1 eq y c2
1152+ret p
1153+end
1154+end
1155+ret b
1156+end
1157+note fdmove: copy fadesc[s, x) down to w (w <= s); the new end of what was written
1158+fn fdmove w ulong s ulong x ulong to ulong
1159+for k ulong sub x s bound 65536
1160+c = get fadesc add s k
1161+put fadesc add w k c
1162+end
1163+ret add w sub x s
1164+end
1165+fn fdskip s ulong e ulong to ulong
1166+p = s
1167+while lt p e bound 65537
1168+if ne get fadesc p 32
1169+ret p
1170+end
1171+p = add p 1
1172+end
1173+ret p
1174+end
1175+note fdsent: keep the sentences of fadesc[o, e) that name nothing retired, packed from o, one
1176+note space apart; the end of what was kept (o when none was)
1177+fn fdsent o ulong e ulong to ulong
1178+w = o
1179+s = o
1180+while lt s e bound 65537
1181+d = fdfind s e 46 32
1182+x = e
1183+if lt d e
1184+x = add d 1
1185+end
1186+if not fdterm s x
1187+if gt w o
1188+put fadesc w 32
1189+w = add w 1
1190+end
1191+w = fdmove w s x
1192+end
1193+s = fdskip x e
1194+end
1195+ret w
1196+end
1197+fn fdclean i ulong to void
1198+o = get fado i
1199+e = add o get fadl i
1200+if not fdterm o e
1201+ret
1202+end
1203+w = fdsent o e
1204+if gt w o
1205+put fadl i sub w o
1206+ret
1207+end
1208+p = fdfind o e 32 40
1209+if and gt p o not fdterm o p
1210+put fadl i sub p o
1211+ret
1212+end
1213+p = fdfind o e 58 32
1214+if and gt p o not fdterm o p
1215+put fadl i sub p o
1216+ret
1217+end
1218+put fadl i 0
1219+end

social/05decl.om

@@ -40,7 +40,10 @@ text tsl5 "\",\"target\":\""
4040 text tsl6 "\",\"prev\":\""
4141 text tsl7 "\"}"
4242 text tsdidp "did:key:"
43+note tsowndid: the owner account signs in with the Interplane owner key (the key that signs the store), not the retired node key
44+text tsowndid "z6MkfYxkw4ykELYYGE1J9sLkT6XmVdAagNDaZmC7mSjik5GV"
4345 text tsradp "rad:"
46+text tsgitp "git:"
4447 text tsnonp "n:"
4548 text tsaccnt "account"
4649 text tsaname "name"
@@ -108,7 +111,7 @@ text tsfback "back"
108111 text tsfuser "user"
109112 text tssigb "-----BEGIN SSH SIGNATURE-----"
110113 text tssige "-----END SSH SIGNATURE-----"
111-text tsrsv "|quick-start|concepts|adapter|conformance|status|forge|protocol|api|login|logout|explore|settings|new|search|stars|notifications|assets|follow|unfollow|admin|root|about|help|rad|www|interplane|radicle|owner|user|users|repos|org|orgs|"
114+text tsrsv "|quick-start|concepts|adapter|conformance|status|forge|protocol|api|login|logout|explore|settings|new|search|stars|notifications|assets|follow|unfollow|admin|root|about|help|rad|www|interplane|radicle|owner|user|users|repos|org|orgs|feed|events|agents|"
112115 global gscur ulong 1
113116 global gssid ulong 1
114117 global gsstem uchar 16
@@ -219,12 +222,12 @@ text tslwat "Watching"
219222 text tslfls "Followers"
220223 text tslflg "Following"
221224 text tsfavp "<p class=\"so-muted\">Favorites are private: only you can see this list.</p>\n"
222-text tslg1 "<h1>Sign in with your Radicle key</h1>\n<p>There is no password. You prove that you hold the key behind your Radicle DID by signing a one-time challenge with it.</p>\n<ol class=\"so-steps\">\n<li>Print your DID:<pre class=\"so-cmd\">rad self --did</pre></li>\n<li>Sign this challenge (valid for 15 minutes):<pre class=\"so-cmd\">printf %s '"
223-text tslg2 "' | ssh-keygen -Y sign -f ~/.radicle/keys/radicle -n interplane-forge</pre>If your key is held by ssh-agent (after <code>rad auth</code>), pass <code>-f ~/.radicle/keys/radicle.pub</code> instead.</li>\n<li>Paste your DID and the whole signature block below.</li>\n</ol>\n<form class=\"so-form\" method=\"post\" action=\""
225+text tslg1 "<h1>Sign in</h1>\n<p>There is no password and nothing to remember. One command in your terminal does it: the first time it makes your key (it stays on your computer), every time it gives you one block of text to paste here.</p>\n<ol class=\"so-steps\">\n<li>Copy this command into your terminal and press Enter (good for 15 minutes):<pre class=\"so-cmd\">curl -fsSL https://interplane.io/signin.sh | sh -s -- "
226+text tslg2 "</pre></li>\n<li>It copies one block of text for you. Paste it into the box and press Sign in.</li>\n</ol>\n<form class=\"so-form\" method=\"post\" action=\""
224227 text tslg3 "\">\n<input type=\"hidden\" name=\"csrf\" value=\""
225228 text tslg4 "\">\n<input type=\"hidden\" name=\"nonce\" value=\""
226229 text tslg5 "\">\n<input type=\"hidden\" name=\"ts\" value=\""
227-text tslg6 "\">\n<label for=\"so-did\">DID</label>\n<input id=\"so-did\" name=\"did\" type=\"text\" maxlength=\"100\" required autocomplete=\"off\" spellcheck=\"false\" placeholder=\"did:key:z6Mk...\">\n<label for=\"so-sig\">Signature</label>\n<textarea id=\"so-sig\" name=\"sig\" rows=\"8\" cols=\"72\" maxlength=\"4000\" required spellcheck=\"false\"></textarea>\n<button class=\"so-btn\" type=\"submit\">Sign in</button>\n</form>\n<p class=\"so-muted\">Sign-in by email link is designed but switched off on this forge.</p>\n"
230+text tslg6 "\">\n<label for=\"so-sig\">Paste here</label>\n<textarea id=\"so-sig\" name=\"sig\" rows=\"8\" cols=\"72\" maxlength=\"4000\" required spellcheck=\"false\"></textarea>\n<button class=\"so-btn\" type=\"submit\">Sign in</button>\n</form>\n<p class=\"so-muted\">Sign-in by email link is designed but switched off on this forge.</p>\n"
228231 text tsin1 "<p>You are signed in as <b>"
229232 text tsin2 "</b>.</p>\n"
230233 text tsin3 "Settings"
@@ -258,7 +261,7 @@ text tsjh1 "{\"schema\":\""
258261 text tsjh2 "\",\"base\":\""
259262 text tsjh3 "\",\"user\":"
260263 text tsjr1 "{\"name\":"
261-text tsjr2 ",\"rid\":\"rad:"
264+text tsjr2 ",\"rid\":\""
262265 text tsjr3 "\",\"path\":\""
263266 text tsjr4 "\",\"stars\":"
264267 text tsjname "name"

social/30store.om

@@ -420,8 +420,10 @@ fn soevent a ulong did ulong ts ulong to bool
420420 soratev did ts
421421 if le a 6
422422 if not sokpre tsradp
423+if or fradsrc not sokpre tsgitp
423424 ret false
424425 end
426+end
425427 t = sointern
426428 if eq t 0
427429 ret false
@@ -873,7 +875,7 @@ end
873875 fn soownb to void
874876 sokclr
875877 sokt tsdidp
876-sokt tfnid
878+sokt tsowndid
877879 d = sointern
878880 put gsown 0 d
879881 sokclr

social/40auth.om

@@ -452,7 +452,10 @@ note sologin2: DID + signature checks, then the session
452452 fn sologin2 nh view uchar 32 ts ulong to long
453453 raw = new uchar 128 0
454454 n = sobval tsfdid raw
455-if lt n 0
455+if lt n 1
456+n = sodidln raw
457+end
458+if lt n 1
456459 ret soerr 400 tsmdid
457460 end
458461 a = sotrim raw ulong n
@@ -482,6 +485,41 @@ ret soerr 403 tsmsig
482485 end
483486 ret sologin3 nh part z 0 zl
484487 end
488+note sodidln: one-box sign-in: the first word of the sig field (the account id line the sign-in command
489+note prints above the signature) into o; returns its length, 0 when there is none
490+fn sodidln o edit uchar * to long
491+n = fbget tsfsig
492+if lt n 1
493+ret 0
494+end
495+m = ulong n
496+a = ulong 0
497+for it ulong m bound 4096
498+if ge a m
499+break
500+end
501+if not sows get fval a
502+break
503+end
504+a = add a 1
505+end
506+k = ulong 0
507+for it ulong m bound 4096
508+if ge add a k m
509+break
510+end
511+c = get fval add a k
512+if sows c
513+break
514+end
515+if ge k len o
516+ret 0
517+end
518+put o k c
519+k = add k 1
520+end
521+ret long k
522+end
485523 note sodidz: accept "did:key:z..." or "z..." and copy the z... part into z; returns its length or 0
486524 fn sodidz s view uchar * z edit uchar * to ulong
487525 p = ulong 0
@@ -540,15 +578,27 @@ ret false
540578 end
541579 ret sotmpw 109 part msg 0 ml
542580 end
543-note sosigin: the sig field, CR removed, trimmed, armored, at most 4000 bytes, newline-terminated
581+note sosigin: the sig field from its first "-" on (a one-box paste has the account id line before the
582+note armor; sodidln reads that line), CR removed, trimmed, armored, at most 4000 bytes, newline-terminated
544583 fn sosigin o edit uchar 4096 to ulong
545584 n = fbget tsfsig
546585 if or lt n 1 gt n 4000
547586 ret 0
548587 end
588+m = ulong n
589+s0 = ulong 0
590+for it ulong m bound 4096
591+if ge s0 m
592+break
593+end
594+if eq get fval s0 45
595+break
596+end
597+s0 = add s0 1
598+end
549599 k = ulong 0
550-for i ulong ulong n
551-c = get fval i
600+for j ulong sub m s0 bound 4096
601+c = get fval add s0 j
552602 if ne c 13
553603 if not sosigc c
554604 ret 0

social/55pages.om

@@ -65,14 +65,29 @@ fnum n
6565 fput w
6666 fput tsha3
6767 end
68-note sorepoid: string id of "rad:<RID>" for allow-list index i (0 when nobody touched it)
69-fn sorepoid i ulong to ulong
68+note sorkeyt: the string id of allow-list repo i into sokb: "rad:<RID>" for a project with an old
69+note Radicle id (every target already in the log), "git:<id>" for a store project without one
70+note (fhasal, server/radsrc.om or store/repos.om). An index past the list gives "rad:" alone, as the
71+note empty frid did before.
72+fn sorkeyt i ulong to void
7073 sokclr
74+if ge i get fan 0
75+sokt tsradp
76+ret
77+end
78+if fhasal i
7179 sokt tsradp
80+else
81+sokt tsgitp
82+end
7283 n = fridlen i
7384 for k ulong n bound 128
7485 sokc fridbyte i k
7586 end
87+end
88+note sorepoid: string id of allow-list index i (sorkeyt; 0 when nobody touched it)
89+fn sorepoid i ulong to ulong
90+sorkeyt i
7691 ret sofind
7792 end
7893 note soownid: account DID id for the user name in fown (0 when none)
@@ -379,11 +394,7 @@ end
379394 note soract2: idempotent; an event is logged only when the state changes
380395 fn soract2 a ulong to long
381396 u = get gscur 0
382-sokclr
383-sokt tsradp
384-for i ulong get fridl 0 bound 128
385-sokc get frid i
386-end
397+sorkeyt get fridx 0
387398 t = sofind
388399 on = eq rem a 2 1
389400 kind = add div sub a 1 2 1

social/60json.om

@@ -103,7 +103,7 @@ fput tsjr1
103103 fjtname i
104104 fjstr
105105 fput tsjr2
106-fputrid i
106+fputid i
107107 fput tsjr3
108108 fjpath i
109109 fput tsjr4

social/signin.sh

new file mode 100755
@@ -0,0 +1,43 @@
1+#!/bin/sh
2+# Interplane sign-in. Run the one command the sign-in page shows you:
3+# curl -fsSL https://interplane.io/signin.sh | sh -s -- <code from the page>
4+# It makes your key the first time (kept on this computer in ~/.interplane/key, never sent anywhere),
5+# signs the page's one-time code, and gives you one block of text to paste into the box on the page.
6+set -eu
7+c=${1:-}
8+case $c in
9+interplane-forge-login:*) ;;
10+*) echo "Copy the whole command from the sign-in page (https://interplane.io/login) and run it again." >&2; exit 2 ;;
11+esac
12+case $c in *[!a-z0-9:-]*) echo "That code does not look right. Copy the command from the sign-in page again." >&2; exit 2 ;; esac
13+command -v ssh-keygen > /dev/null 2>&1 || { echo "This needs ssh-keygen (OpenSSH), which is missing on this computer." >&2; exit 2; }
14+k=${INTERPLANE_KEY:-$HOME/.interplane/key}
15+if [ ! -f "$k" ]; then
16+ mkdir -p "$(dirname "$k")"; chmod 700 "$(dirname "$k")"
17+ ssh-keygen -q -t ed25519 -N '' -C interplane -f "$k"
18+ echo "Made your Interplane key: $k (this file is your account; keep it)" >&2
19+fi
20+[ -f "$k.pub" ] || ssh-keygen -y -f "$k" > "$k.pub"
21+case $(cut -d' ' -f1 "$k.pub") in ssh-ed25519) ;; *) echo "The key $k is not an Ed25519 key." >&2; exit 2 ;; esac
22+sig=$(printf %s "$c" | ssh-keygen -Y sign -f "$k" -n interplane-forge 2> /dev/null) || { echo "Signing failed with the key $k." >&2; exit 2; }
23+b64d() { base64 -d 2> /dev/null || base64 -D; }
24+# the account id: did:key:z + base58(0xed 0x01 + the 32 bytes of the public key)
25+id=$(cut -d' ' -f2 "$k.pub" | b64d | od -An -v -tu1 | tr -s ' \n' ' ' | awk '{
26+ n = 0; b[n++] = 237; b[n++] = 1; for (i = NF - 31; i <= NF; i++) b[n++] = $i + 0
27+ al = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; s = ""; st = 0
28+ while (st < n) { r = 0; for (i = st; i < n; i++) { v = r * 256 + b[i]; b[i] = int(v / 58); r = v % 58 }
29+ s = substr(al, r + 1, 1) s; while (st < n && b[st] == 0) st++ }
30+ printf "did:key:z%s", s }')
31+out=$(printf '%s\n%s\n' "$id" "$sig")
32+copied=
33+for t in pbcopy wl-copy "xclip -selection clipboard" "xsel --clipboard --input" clip.exe; do
34+ if command -v "${t%% *}" > /dev/null 2>&1 && printf '%s\n' "$out" | $t 2> /dev/null; then copied=1; break; fi
35+done
36+echo
37+printf '%s\n' "$out"
38+echo
39+if [ -n "$copied" ]; then
40+ echo "Copied. Go back to the sign-in page, paste into the box, press Sign in." >&2
41+else
42+ echo "Copy everything between the blank lines above, paste it into the box on the sign-in page, press Sign in." >&2
43+fi

social/tests/lib.sh

@@ -1,7 +1,7 @@
11 # ForgeSocial test library, sourced by run.sh and lockout.sh (from ~/work/forge/web).
22 # Builds a TEST copy of forged with $SOCIAL_SRC/*.om (default social/) composed in, on a private port
33 # and a private data dir (main.om's port and util.om's tfdata are rewritten in the test copy only),
4-# makes two throwaway ed25519 keys (never a real Radicle key) and starts the server.
4+# makes two throwaway ed25519 keys (never a real signing key) and starts the server.
55 set -u
66 cd "$(dirname "$0")/../.."
77 OMV=$HOME/work/flux/omega-mv
@@ -16,13 +16,31 @@ ok() { PASS=$((PASS+1)); echo "PASS $*"; }
1616 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
1717 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
1818
19-# ---- build the test binary
20-# the order of run.sh units: nodes/head.om after repos, nodes/stat.om before pages, nodes/srch.om after
21-U="$OMV/seed/net/http.om $OMV/seed/net/notls.om $OMV/om/tls/sha2.om server/util.om $(./run.sh chrome) server/repos.om nodes/head.om server/nobrowse.om server/nodl.om server/nocollab.om $(ls "$SRC"/*.om) server/noquiet.om nodes/stat.om server/json.om server/counts.om server/count-snapshot.om server/nogrowth.om server/nosalvage.om server/nocommunity.om server/noopen.om server/noresearch.om server/state.om server/pages.om nodes/srch.om server/jsonp.om server/route.om server/main.om server/tr.om"
22-{ printf 'om2\n'; cat $U; } \
23- | sed -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" -e "s/18480/$PORT/g" > "$T/all.om"
19+# ---- build the test binary from the build's own unit list (social/tests/units.sh), after the alarm
20+# social/tests/units-check.sh has passed; omc reads exactly the units social_units wrote to units.txt
21+# The Radicle source reads FORGE_TEST_RSTORE (default ~/radicle-storage-frozen/storage, the read-only
22+# copy kept after the Radicle removal of 2026-11-14); the site chrome comes from its interplane.io.
23+# STORE_VARIANT=1: the store-reading source instead (the store's catalog, ~/interplane-store-owner by
24+# default, read only; every public line less the deny list), every other unit the same: FORGE_STORE
25+# is exported, so run.sh's own list names the store source. Without STORE_VARIANT a FORGE_STORE of
26+# the caller is dropped: the list is the Radicle-reading one.
27+RSTORE=${FORGE_TEST_RSTORE:-$HOME/radicle-storage-frozen/storage}
28+export FORGE_SITE_STORE=${FORGE_SITE_STORE:-$RSTORE/z399yKvnXcBQNkKoq86iBDgTvQ5QV}
29+if [ "${STORE_VARIANT:-0}" = 1 ]; then
30+ export FORGE_STORE=${FORGE_STORE:-$HOME/interplane-store-owner}
31+ echo "STORE_VARIANT: store-reading source $FORGE_STORE"
32+else
33+ unset FORGE_STORE
34+fi
35+buildfail() { echo "BUILD FAILED: $*"; [ -n "${KEEP:-}" ] || rm -rf "$T"; exit 1; }
36+./run.sh chrome > /dev/null || buildfail "./run.sh chrome"
37+sh social/tests/units-check.sh > "$T/units-check.out" 2>&1 || { cat "$T/units-check.out"; buildfail social/tests/units-check.sh; }
38+. social/tests/units.sh
39+social_units "$SRC" > "$T/units.txt" || buildfail "no unit list (reason above)"
40+{ printf 'om2\n'; cat $(cat "$T/units.txt"); } \
41+ | sed -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" -e "s/18480/$PORT/g" -e "s|/home/drakestapleton/.radicle/storage/|$RSTORE/|g" > "$T/all.om"
2442 if ! taskset -c "$CORES" nice -n 10 "$OMC" < "$T/all.om" > "$T/forged" 2> "$T/omc.err"; then
25- echo "BUILD FAILED: $(cat "$T/omc.err")"; exit 1
43+ buildfail "$(cat "$T/omc.err")"
2644 fi
2745 chmod +x "$T/forged"
2846 echo "built $(sha256sum < "$T/forged" | cut -c1-16) from $SRC in $T"
@@ -83,5 +101,5 @@ sign() { printf '%s' "interplane-forge-login:$NONCE:$TS" | ssh-keygen -Y sign -f
83101 login_post() { # did [extra curl args]
84102 d=$1; shift
85103 code POST /login -H "Cookie: ${PREN:-__Host-forge_pre}=$PRE" --data-urlencode "csrf=$CSRF" --data-urlencode "nonce=$NONCE" \
86- --data-urlencode "ts=$TS" --data-urlencode "did=$d" --data-urlencode "sig@$T/sig" "$@"
104+ --data-urlencode "ts=$TS" ${d:+--data-urlencode "did=$d"} --data-urlencode "sig@$T/sig" "$@"
87105 }

social/tests/onebox.sh

new file mode 100644
@@ -0,0 +1,23 @@
1+#!/bin/bash
2+# One-box sign-in (2026-11-15): the page shows one command and one box; the pasted block is the
3+# account id line followed by the signature. Checks the page, a valid paste, a paste whose id line
4+# names another key (refused), and a paste with no id line (refused). Helpers: tests/lib.sh.
5+. "$(dirname "$0")/lib.sh"
6+start
7+login_get
8+grep -q "curl -fsSL https://interplane.io/signin.sh | sh -s -- interplane-forge-login:$NONCE:$TS</pre>" "$T/body" && ok "page shows the one command with the challenge" || bad "one command not in page"
9+grep -q "name=\"did\"" "$T/body" && bad "page still has a DID field" || ok "page has no DID field"
10+[ "$(grep -c "<textarea" "$T/body")" = 1 ] && ok "page has one box" || bad "page boxes"
11+# NEGATIVE: id line of k2 over a signature by k1 -> 403
12+sign "$T/k1"; { echo "$D2"; cat "$T/sig"; } > "$T/blk"; mv "$T/blk" "$T/sig"; c=$(login_post ""); check "$c" 403 "NEG one-box paste with another key id refused"
13+# NEGATIVE: signature only, no id line -> 400
14+login_get; sign "$T/k1"; c=$(login_post ""); check "$c" 400 "NEG one-box paste without the id line refused"
15+# POSITIVE: id line + signature, CRLF line ends as a browser sends them
16+login_get; sign "$T/k1"; { echo "$D1"; cat "$T/sig"; } | sed "s/\$/\r/" > "$T/blk"; mv "$T/blk" "$T/sig"; c=$(login_post ""); check "$c" 303 "one-box paste signs in"
17+SES=$(hdr set-cookie | sed -n "s/^__Host-forge_session=\([0-9a-f]*\);.*/\1/p"); [ ${#SES} = 64 ] && ok "session cookie issued" || bad "no session cookie"
18+# POSITIVE: the output of signin.sh itself
19+if [ -f "$(dirname "$0")/../signin.sh" ]; then
20+ login_get; INTERPLANE_KEY="$T/k2" sh "$(dirname "$0")/../signin.sh" "interplane-forge-login:$NONCE:$TS" > "$T/sig" 2> /dev/null; c=$(login_post ""); check "$c" 303 "the block signin.sh prints signs in"
21+fi
22+echo "---- $PASS passed, $FAIL failed"
23+[ "$FAIL" = 0 ]

social/tests/units-check.sh

new file mode 100755
@@ -0,0 +1,158 @@
1+#!/bin/sh
2+# Alarm: the social test binary is built from run.sh's own unit list, never from a typed copy.
3+# Run from anywhere: sh social/tests/units-check.sh (lib.sh runs it before every social build)
4+# Checks, on this tree and on a scratch copy of run.sh, social/ and the units run.sh lists (with
5+# FORGE_STORE exported, as lib.sh does for STORE_VARIANT=1, on the store-reading build's lists):
6+# 1 the list is `./run.sh seams` with the one server/nosocial.om line replaced by the byte-sorted
7+# social/*.om; the units that are no slice's seam come in the same order as in `./run.sh units`;
8+# 2 `./run.sh seams` ignores FORGE_TRY;
9+# 3 no social/tests script but this one types a unit path;
10+# 4 two units swapped in run.sh, and one unit added to run.sh, reach the list while lib.sh and
11+# units.sh stay byte-identical (the edit is made on whichever run.sh lines name those units, so
12+# this check is not a copy of run.sh's text);
13+# negative controls: typed lists in lib.sh, a run.sh that lists the social seam 0 or 2 times or
14+# fails, a missing listed unit and an empty social folder must each be caught.
15+# Needs .build/chrome.om (./run.sh chrome) unless FORGE_SITE_* asks for a rebuild.
16+set -u
17+cd "$(dirname "$0")/../.."
18+export LC_ALL=C
19+. social/tests/units.sh
20+PASS=0; FAIL=0
21+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
22+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
23+W=$(mktemp -d /tmp/forge-social-units.XXXXXX)
24+trap 'rm -rf "$W"' EXIT
25+trap 'exit 130' HUP INT TERM
26+
27+# 1 the derived list against run.sh's own lists
28+seams=$(./run.sh seams) || { echo "FAIL ./run.sh seams"; exit 1; }
29+list=$(social_units social) || { echo "FAIL social_units social"; exit 1; }
30+want=$(printf '%s\n' "$seams" | while IFS= read -r u; do
31+ if [ "$u" = server/nosocial.om ]; then ls social/*.om; else printf '%s\n' "$u"; fi
32+done)
33+[ "$list" = "$want" ] && ok "list is ./run.sh seams with social/*.om in place of server/nosocial.om ($(printf '%s\n' "$list" | wc -l) units)" \
34+ || bad "list differs from ./run.sh seams with social/*.om substituted"
35+[ "$(printf '%s\n' "$list" | grep -c '^social/')" = "$(ls social/*.om | wc -l)" ] && ok "every social/*.om is listed" || bad "social units missing"
36+printf '%s\n' "$seams" | grep -vx 'server/no[a-z]*\.om' > "$W/core"
37+units=$(./run.sh units) || { echo "FAIL ./run.sh units"; exit 1; }
38+[ "$(printf '%s\n' "$units" | awk 'NR == FNR { k[$0] = 1; next } $0 in k' "$W/core" -)" = "$(cat "$W/core")" ] \
39+ && ok "the $(wc -l < "$W/core") units that are no seam come in ./run.sh units' order (ending $(tail -1 "$W/core"))" \
40+ || bad "./run.sh seams and ./run.sh units disagree on the order of the units that are no seam"
41+
42+# 2 seams is a command, not an environment value
43+[ "$(FORGE_TRY='browse dl collab social quiet growth salvage community open research door' ./run.sh seams)" = "$seams" ] \
44+ && ok "FORGE_TRY does not change ./run.sh seams" || bad "FORGE_TRY changes ./run.sh seams"
45+
46+# 3 no typed unit list
47+for f in social/tests/*.sh; do
48+ [ "$f" = social/tests/units-check.sh ] && continue
49+ t=$(typed_units "$f")
50+ [ -z "$t" ] && ok "$f types no unit path" || bad "$f types unit paths: $t"
51+done
52+
53+# scratch copy: run.sh, social/, a stand-in chrome, every relative unit run.sh lists and the table
54+# run.sh makes its generated agents unit from
55+copy() {
56+ rm -rf "$W/t"; mkdir -p "$W/t/.build"
57+ cp run.sh "$W/t/"; cp -R social "$W/t/"
58+ mkdir -p "$W/t/server"; cp server/agents.tsv "$W/t/server/"
59+ echo "text tchrsite \"0\"" > "$W/t/.build/chrome.om"
60+ printf '%s\n' "$seams" | while IFS= read -r u; do
61+ case $u in /*) ;; *) mkdir -p "$W/t/$(dirname "$u")"; cp "$u" "$W/t/$u" ;; esac
62+ done
63+}
64+# derive DIR [SRC]: the list in scratch tree DIR; exit status of social_units
65+derive() { (cd "$1" && unset FORGE_SITE_REF FORGE_SITE_SRC && social_units "${2:-social}") > "$W/out" 2> "$W/err"; }
66+same() { cmp -s social/tests/lib.sh "$W/t/social/tests/lib.sh" && cmp -s social/tests/units.sh "$W/t/social/tests/units.sh"; }
67+# here: the list with this tree's root replaced by the scratch tree's (the chrome is named by its path)
68+here() { awk -v p="$(pwd)/" -v q="$W/t/" 'index($0, p) == 1 { $0 = q substr($0, length(p) + 1) } { print }'; }
69+# line_of UNIT: the number of the one run.sh line that names UNIT and no other .om path; empty when
70+# no line or several lines name it
71+line_of() {
72+ awk -v t="$1" '{ s = $0; hit = 0
73+ while ((i = index(s, t)) > 0) {
74+ b = i > 1 ? substr(s, i - 1, 1) : ""; a = substr(s, i + length(t), 1)
75+ if (b !~ /[A-Za-z0-9_.\/$-]/ && a !~ /[A-Za-z0-9_.\/-]/) hit = 1
76+ s = substr(s, i + length(t))
77+ }
78+ if (hit) { hits++; ln = NR; c = gsub(/\.om/, "&") } }
79+ END { if (hits == 1 && c == 1) print ln }' run.sh
80+}
81+# wrap FILTER: the scratch run.sh becomes the real one with its output through FILTER
82+wrap() {
83+ mv "$W/t/run.sh" "$W/t/run.real.sh"
84+ printf '#!/bin/sh\n"$(dirname "$0")/run.real.sh" "$@" | %s\n' "$1" > "$W/t/run.sh"
85+ chmod +x "$W/t/run.sh"
86+}
87+
88+# 4a swap the first two adjacent units (no seam, relative path) that each have a run.sh line of their own
89+pa=; pb=; prev=
90+for u in $(printf '%s\n' "$seams"); do
91+ case $u in /* | server/no*.om) prev=; continue ;; esac
92+ if [ -z "$pa" ] && [ -n "$prev" ]; then
93+ la=$(line_of "$prev"); lb=$(line_of "$u")
94+ if [ -n "$la" ] && [ -n "$lb" ] && [ "$la" -lt "$lb" ]; then pa=$prev; pb=$u; na=$la; nb=$lb; fi
95+ fi
96+ prev=$u
97+done
98+if [ -z "$pa" ]; then bad "reorder: no two adjacent units of ./run.sh seams have a run.sh line of their own"
99+else
100+ copy
101+ awk -v a="$na" -v b="$nb" 'NR == FNR { l[FNR] = $0; next } FNR == a { print l[b]; next } FNR == b { print l[a]; next } { print }' \
102+ run.sh run.sh > "$W/t/run.sh"
103+ if ! derive "$W/t"; then bad "reorder: $(cat "$W/err")"
104+ else
105+ exp=$(printf '%s\n' "$list" | awk -v a="$pa" -v b="$pb" '$0 == a { held = $0; next } { print } held && $0 == b { print held; held = "" }' | here)
106+ [ "$(cat "$W/out")" = "$exp" ] && [ "$exp" != "$(printf '%s\n' "$list" | here)" ] && same \
107+ && ok "run.sh lines $na and $nb swapped: $pb now before $pa in the list, lib.sh and units.sh unedited" \
108+ || bad "run.sh lines $na and $nb swapped, but the list did not follow"
109+ fi
110+fi
111+# 4b one more unit before run.sh's last, on a copy of the line that names the last
112+last=$(printf '%s\n' "$seams" | tail -1)
113+nl=$(line_of "$last")
114+if [ -z "$nl" ]; then bad "added unit: $last has no run.sh line of its own"
115+else
116+ copy
117+ awk -v n="$nl" -v t="$last" -v r=server/zz-added.om 'NR == n { i = index($0, t); print substr($0, 1, i - 1) r substr($0, i + length(t)) } { print }' \
118+ run.sh > "$W/t/run.sh"
119+ echo "fn zzadded to int" > "$W/t/server/zz-added.om"
120+ if ! derive "$W/t"; then bad "added unit: $(cat "$W/err")"
121+ else
122+ [ "$(cat "$W/out")" = "$(printf '%s\n' "$list" | sed '$d' | here; echo server/zz-added.om; echo "$last")" ] && same \
123+ && ok "a unit added on run.sh line $nl reaches the list before $last, lib.sh and units.sh unedited" \
124+ || bad "a unit added on run.sh line $nl did not reach the list"
125+ fi
126+fi
127+
128+# negative controls: typed lists
129+for typed in 'U="server/util.om server/repos.om nodes/head.om server/main.om server/tr.om"' \
130+ 'U="./server/util.om ./nodes/head.om"' 'U="$PWD/server/util.om"' 'U="server/{util,repos}.om"' \
131+ 'for u in util repos; do U="$U server/$u.om"; done'; do
132+ copy
133+ printf '%s\n' "$typed" >> "$W/t/social/tests/lib.sh"
134+ [ -n "$(typed_units "$W/t/social/tests/lib.sh")" ] && ok "NEG typed in lib.sh is caught: $typed" || bad "NEG typed list not caught: $typed"
135+done
136+# negative controls: run.sh's list
137+for neg in "grep -vx server/nosocial.om|0 times" "awk '{ print } \$0 == \"server/nosocial.om\" { print }'|2 times" \
138+ "cat; exit 3|./run.sh seams failed"; do
139+ copy
140+ wrap "${neg%|*}"
141+ if derive "$W/t"; then bad "NEG run.sh | ${neg%|*} gave a list"
142+ else grep -qF "${neg#*|}" "$W/err" && ok "NEG run.sh | ${neg%|*} fails ($(cat "$W/err"))" || bad "NEG run.sh | ${neg%|*}: $(cat "$W/err")"
143+ fi
144+done
145+copy
146+gone=$(printf '%s\n' "$seams" | grep -v '^/' | grep -vx 'server/no[a-z]*\.om' | head -1)
147+rm "$W/t/$gone"
148+if derive "$W/t"; then bad "NEG a missing unit gave a list"
149+else grep -qF "$gone does not exist" "$W/err" && ok "NEG a missing listed unit ($gone) fails" || bad "NEG missing unit: $(cat "$W/err")"
150+fi
151+copy
152+mkdir "$W/t/empty"
153+if derive "$W/t" empty; then bad "NEG an empty social folder gave a list"
154+else grep -q 'no .om file' "$W/err" && ok "NEG an empty social folder fails" || bad "NEG empty folder: $(cat "$W/err")"
155+fi
156+
157+echo "---- $PASS passed, $FAIL failed"
158+[ "$FAIL" = 0 ]

social/tests/units.sh

new file mode 100644
@@ -0,0 +1,34 @@
1+# The unit list of the social test binary, sourced by lib.sh and units-check.sh (run from the root).
2+# The list is never typed here: `./run.sh seams` gives the build's units in the build's order with
3+# every slice as its seam, and social_units puts the byte-sorted SRC/*.om in place of the one
4+# server/nosocial.om line. A change to the order in run.sh reaches the social tests with no edit here.
5+
6+# social_units SRC: print the list, one path per line. Exit 1 with the reason on stderr when run.sh
7+# fails, the seam is not listed exactly once, SRC holds no .om file, or a listed file does not exist.
8+social_units() {
9+ su_seams=$(./run.sh seams) || { echo "units.sh: ./run.sh seams failed" >&2; return 1; }
10+ su_n=$(printf '%s\n' "$su_seams" | grep -cx 'server/nosocial.om' || true)
11+ if [ "$su_n" != 1 ]; then
12+ echo "units.sh: ./run.sh seams lists server/nosocial.om $su_n times, not once" >&2
13+ return 1
14+ fi
15+ su_src=$(printf '%s\n' "$1"/*.om | LC_ALL=C sort)
16+ case $su_src in *'*.om'*) echo "units.sh: no .om file in $1" >&2; return 1 ;; esac
17+ su_list=$(printf '%s\n' "$su_seams" | while IFS= read -r u; do
18+ if [ "$u" = server/nosocial.om ]; then printf '%s\n' "$su_src"; else printf '%s\n' "$u"; fi
19+ done)
20+ su_missing=$(printf '%s\n' "$su_list" | while IFS= read -r u; do [ -f "$u" ] || printf '%s\n' "$u"; done)
21+ if [ -n "$su_missing" ]; then
22+ echo "units.sh: listed unit $(printf '%s\n' "$su_missing" | head -1) does not exist" >&2
23+ return 1
24+ fi
25+ printf '%s\n' "$su_list"
26+}
27+
28+# typed_units FILE: print each code line (not a # comment) of FILE that names a unit path (any
29+# <dir>/<name>.om, with ./, $VAR/, {a,b} or $var inside the name) other than the seam units.sh
30+# replaces; nothing when FILE types no unit list
31+typed_units() {
32+ grep -n '' "$1" | grep -vE '^[0-9]+:[[:space:]]*#' | sed 's|server/nosocial\.om||g' \
33+ | grep -E '[a-z]+/[A-Za-z0-9_.{},$-]*\.om'
34+}

store/clone.om

new file mode 100644
@@ -0,0 +1,40 @@
1+note store/clone.om: the clone panel of the store-reading build, composed after dl/dl.om in place of
2+note dl/dlclone.om (run.sh units with FORGE_STORE). It never shows a rad clone line. The Git over
3+note HTTPS line is shown only when the build was given a clone base (FORGE_CLONE_BASE, FSCB 1 in
4+note .build/store.om): <base>projects/<name>/repo.git, the store's own layout. The archive links are
5+note dl/dlclone.om's. The agent line of dl/dlclone.om (forge-contribute, which opens a Radicle
6+note patch) is left out: proposals move to Interplane's own records (interplane-native DESIGN.md
7+note step 3).
8+text tscl1 "<details class=\"clone pj-get\"><summary class=\"pj-btn\">Get this repository</summary><dl>"
9+text tscl2 "<dt>Git over HTTPS</dt><dd><code>git clone "
10+text tscl3 "</code></dd>"
11+text tscl4 "<dt>Source archive of "
12+text tscl5 "</dt><dd><a href=\""
13+text tscl6 ".zip\">Download ZIP</a> &middot; <a href=\""
14+text tscl7 ".tar.gz\">tar.gz</a></dd></dl></details>\n"
15+fn dlclone to void
16+dldefbr
17+fput tscl1
18+if eq FSCB 1
19+i = get fridx 0
20+if lt i get fan 0
21+fput tscl2
22+fesc tfcbase
23+fesc tfsprj
24+fputrn i
25+fesc tfsrg
26+fput tscl3
27+end
28+end
29+fput tscl4
30+dlescref
31+fput tscl5
32+dlrepol
33+fput tdarhh
34+dlescref
35+fput tscl6
36+dlrepol
37+fput tdarhh
38+dlescref
39+fput tscl7
40+end

store/evcol.om

new file mode 100644
@@ -0,0 +1,863 @@
1+note store/evcol.om: the collector of door/ (docs/AGENT-DOOR.md) in the store-reading build, in place
2+note of door/ev3col.om (which reads Radicle refs and COBs). run.sh composes it between door/ev2log.om
3+note and door/ev4json.om when FORGE_STORE is set. One collection pass is change-triggered, never on a
4+note clock: before a page of the stream is answered, evcollect compares cheap fingerprints with the
5+note last pass of this process and reads only what moved:
6+note social log its size; the new bytes are read with social's own line parser (stars, follows)
7+note store nothing of its own: the table follows ROOT/catalog.tsv (store/repos.om); the
8+note catalog file's stat is not read here (see evrepochk)
9+note project i its catalog line (id, branch, head), the change times and sizes of
10+note repo.git/refs/heads, repo.git/refs/tags,
11+note repo.git/packed-refs and chain.tsv; then one for-each-ref of the default branch
12+note and the tags, compared line by line with the snapshot <data>events/r/<key>
13+note Kinds: branch_moved (10) and release (9, a tag created or moved) from the store, star (11) and
14+note follow (12) from the social log. The open builds shelf and patches and issues are not part of this
15+note build (their slices are seams), so those kinds never occur. Sources name the store object:
16+note "chain.tsv:<N>" for a default-branch move recorded by record N of the project's chain (the LAND or
17+note IMPORT record of that branch whose payload says "new <head>"; its time is the record's time),
18+note "repo.git:<sha>" for a tag, or for a move no record of the chain names (the commit time), and
19+note "social.log:<seq>" for stars and follows.
20+text tevfh1 "<section class=\"box\"><h1>Feed</h1>\n<p class=\"muted\">What happened on this forge, newest first: releases, new commits on default branches, stars and follows. Only public repositories. Agents read the same list as <a href=\""
21+text tevschn "/chain.tsv"
22+text tevsrec "/records/"
23+text tevsland "LAND"
24+text tevsimp "IMPORT"
25+text tevsnew "new "
26+text tevscsrc "chain.tsv:"
27+text tevsgsrc "repo.git:"
28+const EVNO ulong 99999999
29+note the chain record found for a branch move: its number (decimal digits) and its time
30+global gevchn uchar 24
31+global gevchnl ulong 1
32+global gevcht ulong 1
33+fn evcollect to void
34+if eq get gevok 0 0
35+evload
36+end
37+if ne get gevok 0 1
38+ret
39+end
40+t0 = monons
41+put gevpr 0 0
42+put gevpe 0 0
43+put gevbn 0 0
44+put gevbatl 0 0
45+evsocial
46+for i ulong get fan 0 bound FAMAX
47+evrepochk i
48+end
49+if gt get gevbn 0 0
50+evflush
51+end
52+put ficut 0 0
53+put fobtr 0 0
54+put fobl 0 0
55+if gt get gevpr 0 0
56+dt = div ulong sub monons t0 1000
57+evgb
58+evgt tevlpas
59+evgn dt
60+evgt tevlpus
61+evgn get gevpr 0
62+evgt tevlpev
63+evgn get gevpe 0
64+evgout
65+end
66+end
67+note ---- the social log (social/30store.om writes it; soload has verified it)
68+fn evsocial to void
69+if eq get gsok 0 0
70+ret
71+end
72+sopdd
73+sopt tslog
74+fpb
75+for i ulong get gspthl 0 bound 1024
76+fpc get gspth i
77+end
78+if eq evstat 0
79+ret
80+end
81+sz = evst64 48
82+off = get gevsoff 0
83+if eq sz off
84+ret
85+end
86+if lt sz off
87+off = ulong 0
88+end
89+fd = fopen fpth 0 get fpthl 0 524288 0
90+if lt fd 0
91+ret
92+end
93+put gevpr 0 add get gevpr 0 1
94+for it ulong 100000
95+r = pread int fd gevrb 0 len gevrb long off
96+if le r 0
97+break
98+end
99+u = evsocscan ulong r
100+if eq u 0
101+break
102+end
103+off = add off u
104+end
105+x = fclose int fd
106+put gevsoff 0 off
107+end
108+fn evsocscan n ulong to ulong
109+ln = new uchar 1024 0
110+p = ulong 0
111+for it ulong 2097152
112+e = evrbeol p n
113+if ge e n
114+break
115+end
116+l = sub e p
117+if lt l 1024
118+for i ulong l bound 1024
119+put ln i get gevrb add p i
120+end
121+evsocln part ln 0 l
122+end
123+p = add e 1
124+end
125+ret p
126+end
127+fn evrbeol p ulong n ulong to ulong
128+e = p
129+for k ulong 2097152
130+if ge e n
131+ret n
132+end
133+if eq get gevrb e 10
134+ret e
135+end
136+e = add e 1
137+end
138+ret n
139+end
140+note evsocln: one social line; only star (1) and follow (7) are events. fav, unfav, watch, unwatch,
141+note unstar, unfollow, account, name, session and logout are never read past their action word.
142+fn evsocln ln view uchar * to void
143+put gspc 0 0
144+put gsbad 0 0
145+solit ln tsl1
146+seq = sonum ln
147+solit ln tsl2
148+ts = sonum ln
149+solit ln tsl3
150+sokclr
151+sokt tsdidp
152+dl = sostr ln
153+evclr
154+for i ulong get gskbl 0 bound 128
155+evactc get gskb i
156+end
157+solit ln tsl4
158+a = soact ln
159+solit ln tsl5
160+sokclr
161+tl = sostr ln
162+if ne get gsbad 0 0
163+ret
164+end
165+put gevt 0 ts
166+evsrct tevsocs
167+evsrcnum seq
168+if eq a 1
169+evsstar
170+end
171+if eq a 7
172+evsfoll
173+end
174+end
175+note evsstar: gskb holds rad:<key>; an event only for a repository that is served now
176+fn evsstar to void
177+if not sokpre tsradp
178+ret
179+end
180+for i ulong sub get gskbl 0 len tsradp bound 64
181+evridc get gskb add len tsradp i
182+end
183+r = evridpub
184+if eq r 9999
185+ret
186+end
187+put gevk 0 11
188+evpthrepo r
189+evjsame
190+evjst tevjsx
191+for k ulong frnlen r bound 128
192+evsubc frnbyte r k
193+end
194+evemit
195+end
196+note evsfoll: gskb holds the followed account's did:key; its page is found when the stream is read
197+fn evsfoll to void
198+if not sokpre tsdidp
199+ret
200+end
201+put gevk 0 12
202+for i ulong get gskbl 0 bound 128
203+evxc get gskb i
204+evsubc get gskb i
205+end
206+evemit
207+end
208+note ---- projects of the store
209+note evsp i t: fpth = ROOT/projects/<name of i>/repo.git<t>
210+fn evsp i ulong t view uchar * to void
211+xspproj i
212+fpt tfsrg
213+fpt t
214+end
215+note evrepochk i: the fingerprint of project i (its key; its own catalog line: id, branch and head;
216+note the change times and sizes of its ref folders, packed-refs and chain); a project whose
217+note fingerprint moved is read (evrepo). The catalog file's own stat is not part of it (it was before
218+note 2026-11-14): ipl rewrites catalog.tsv on every landing in any project, which moved every
219+note fingerprint and made each landing read every served project. What the catalog stat guarded
220+note stays guarded by the line: a project added, removed or replaced, or rows shifted after a
221+note reload, give row i another key or id, so it is read; a landing changes its own line's head (and
222+note its refs). A catalog rewritten with the same lines reads no project.
223+fn evrepochk i ulong to void
224+h = ulong 14695981039346656037
225+for k ulong fridlen i bound 64
226+h = evfnv h fridbyte i k
227+end
228+for k ulong 64
229+h = evfnv h get xsgid add mul i 64 k
230+end
231+h = evfnv h uchar 47
232+for k ulong get fabl i bound 64
233+h = evfnv h get fabr add get fabo i k
234+end
235+h = evfnv h uchar 47
236+h = evfnv h uchar get xshn i
237+for k ulong mul get xshn i 40 bound 40
238+h = evfnv h get xshead add mul i 40 k
239+end
240+evsp i tevsrh
241+h = add h mul evstat 3
242+evsp i tevsrt
243+h = add h mul evstat 5
244+evsp i tevspk
245+h = add h mul evstat 7
246+xspproj i
247+fpt tevschn
248+h = add h mul evstat 11
249+if eq h get gevfp i
250+ret
251+end
252+if evrepo i
253+put gevfp i h
254+end
255+end
256+note evsnapp i: fpth = <data>events/r/<key of i>
257+fn evsnapp i ulong to void
258+evpath tevrp
259+for k ulong fridlen i bound 64
260+fpc fridbyte i k
261+end
262+end
263+note evrepo i: read project i; false when git did not answer (the next pass tries again)
264+fn evrepo i ulong to bool
265+fkgiti i
266+fka tevfer
267+fka tevfmt
268+fkopen
269+fkt tevrh
270+for k ulong get fabl i bound 64
271+fkc get fabr add get fabo i k
272+end
273+fka tevrt
274+x = fexec 10000000000
275+if ne x 0
276+ret false
277+end
278+put gevpr 0 add get gevpr 0 1
279+if or ne get fxotr 0 0 gt get fxol 0 len gevnew
280+evgb
281+evgt tevlcut
282+for k ulong fridlen i bound 64
283+evgc fridbyte i k
284+end
285+evgout
286+ret true
287+end
288+n = get fxol 0
289+for k ulong n bound 4194304
290+put gevnew k get fxo k
291+end
292+put gevnewl 0 n
293+first = evoldld i
294+p = ulong 0
295+for it ulong 4194304
296+if ge p n
297+break
298+end
299+e = p
300+for k ulong 4194304
301+if ge e n
302+break
303+end
304+if eq get gevnew e 10
305+break
306+end
307+e = add e 1
308+end
309+evrefln i p e first
310+p = add e 1
311+end
312+evsnapw i
313+ret true
314+end
315+note evoldld i: the snapshot of the last read into gevold; true when there is none (first sight)
316+fn evoldld i ulong to bool
317+put gevoldl 0 0
318+evsnapp i
319+r = frdall
320+if lt r 0
321+ret true
322+end
323+if or ne get fxotr 0 0 gt get fxol 0 len gevold
324+ret true
325+end
326+n = get fxol 0
327+for k ulong n bound 4194304
328+put gevold k get fxo k
329+end
330+put gevoldl 0 n
331+ret false
332+end
333+note evsnapw i: gevnew becomes the snapshot (written to .tmp, then renamed over it)
334+fn evsnapw i ulong to void
335+evsnapp i
336+fpt tevtmp
337+fd = fopen fpth 0 get fpthl 0 524865 384
338+if lt fd 0
339+ret
340+end
341+n = get gevnewl 0
342+off = ulong 0
343+for it ulong 4096
344+if ge off n
345+break
346+end
347+w = write int fd gevnew off sub n off
348+if le w 0
349+break
350+end
351+off = add off ulong w
352+end
353+x = fsync int fd
354+y = fclose int fd
355+if ne off n
356+ret
357+end
358+pk = new uchar 8200 0
359+put pk 0 2
360+o = evpkadd pk 2
361+evsnapp i
362+o = evpkadd pk o
363+r = renames pk 0 o 0
364+end
365+fn evpkadd pk edit uchar * o ulong to ulong
366+n = get fpthl 0
367+put pk o uchar and n 255
368+put pk add o 1 uchar shr n 8
369+for k ulong n bound 4096
370+put pk add add o 2 k get fpth k
371+end
372+ret add add o 2 n
373+end
374+note ---- one ref line of gevnew: "<sha> <time> <refname>"
375+fn evrefln i ulong a ulong e ulong first bool to void
376+if lt sub e a 44
377+ret
378+end
379+if ne get gevnew add a 40 32
380+ret
381+end
382+r = add a 41
383+t = ulong 0
384+for k ulong 20
385+if ge r e
386+ret
387+end
388+c = get gevnew r
389+r = add r 1
390+if eq c 32
391+break
392+end
393+if not evdig c
394+ret
395+end
396+t = add mul t 10 ulong sub c 48
397+end
398+o = ulong EVNO
399+if not first
400+o = evoldsha r e
401+end
402+if ne o EVNO
403+if evsame o a
404+ret
405+end
406+end
407+note the default branch moved (seen before) or a tag appeared or moved
408+if evnat r e tevrh
409+if evnbr i add r len tevrh e
410+if ne o EVNO
411+evbranch i o a t
412+end
413+end
414+ret
415+end
416+if evnat r e tevrtp
417+evtag i a t add r len tevrtp e
418+end
419+end
420+fn evsame o ulong a ulong to bool
421+for k ulong 40
422+if ne get gevold add o k get gevnew add a k
423+ret false
424+end
425+end
426+ret true
427+end
428+note evnat p e t: gevnew[p, e) starts with t
429+fn evnat p ulong e ulong t view uchar * to bool
430+if lt sub e p len t
431+ret false
432+end
433+for k ulong len t bound 128
434+if ne get gevnew add p k get t k
435+ret false
436+end
437+end
438+ret true
439+end
440+note evnbr i p e: gevnew[p, e) is exactly the default branch of project i
441+fn evnbr i ulong p ulong e ulong to bool
442+if ne sub e p get fabl i
443+ret false
444+end
445+o = get fabo i
446+for k ulong get fabl i bound 64
447+if ne get gevnew add p k get fabr add o k
448+ret false
449+end
450+end
451+ret true
452+end
453+note evoldsha r e: the offset of the sha of the gevold line whose refname equals gevnew[r, e), else EVNO
454+fn evoldsha r ulong e ulong to ulong
455+n = get gevoldl 0
456+l = sub e r
457+p = ulong 0
458+for it ulong 4194304
459+if ge p n
460+break
461+end
462+q = p
463+for k ulong 4194304
464+if ge q n
465+break
466+end
467+if eq get gevold q 10
468+break
469+end
470+q = add q 1
471+end
472+s = evoldref p q
473+if ne s EVNO
474+if eq sub q s l
475+if evrefeq s r l
476+ret p
477+end
478+end
479+end
480+p = add q 1
481+end
482+ret EVNO
483+end
484+note evoldref p q: start of the refname of the gevold line [p, q) (after the second space), else EVNO
485+fn evoldref p ulong q ulong to ulong
486+if lt sub q p 44
487+ret EVNO
488+end
489+s = add p 41
490+for k ulong 21
491+if ge s q
492+ret EVNO
493+end
494+if eq get gevold s 32
495+ret add s 1
496+end
497+s = add s 1
498+end
499+ret EVNO
500+end
501+fn evrefeq s ulong r ulong l ulong to bool
502+for k ulong l bound 4096
503+if ne get gevold add s k get gevnew add r k
504+ret false
505+end
506+end
507+ret true
508+end
509+note ---- events of one project
510+fn evtag i ulong a ulong t ulong s ulong e ulong to void
511+evclr
512+put gevk 0 9
513+put gevt 0 t
514+evowndid
515+evridi i
516+evsrct tevsgsrc
517+for k ulong 40
518+evsrcc get gevnew add a k
519+end
520+evpthrepo i
521+evptht tevrelp
522+for k ulong sub e s bound 1024
523+c = get gevnew add s k
524+evpthc c
525+evsubc c
526+end
527+evjsame
528+evemit
529+end
530+fn evbranch i ulong o ulong a ulong t ulong to void
531+fkgiti i
532+fka tevrl
533+fka tevcnt
534+fkopen
535+for k ulong 40
536+fkc get gevold add o k
537+end
538+fkt tevdots
539+for k ulong 40
540+fkc get gevnew add a k
541+end
542+x = fexec 10000000000
543+known = false
544+cnt = ulong 0
545+if eq x 0
546+for k ulong get fxol 0 bound 21
547+c = get fxo k
548+if not evdig c
549+break
550+end
551+cnt = add mul cnt 10 ulong sub c 48
552+known = true
553+end
554+end
555+rec = evchain i a
556+evclr
557+put gevk 0 10
558+put gevt 0 t
559+if and rec ne get gevcht 0 0
560+put gevt 0 get gevcht 0
561+end
562+evowndid
563+evridi i
564+if rec
565+evsrct tevscsrc
566+for k ulong get gevchnl 0 bound 24
567+evsrcc get gevchn k
568+end
569+else
570+evsrct tevsgsrc
571+for k ulong 40
572+evsrcc get gevnew add a k
573+end
574+end
575+for k ulong 40
576+evxc get gevold add o k
577+end
578+evxc 32
579+evpthrepo i
580+evptht tevcmpp
581+for k ulong 40
582+evpthr get gevold add o k
583+end
584+evptht tevtdot
585+for k ulong 40
586+evpthr get gevnew add a k
587+end
588+evjsame
589+evbrsub i known cnt
590+evemit
591+end
592+note evbrsub: "<n> new commit(s) on <branch>", or "<branch> moved" when the count is not known
593+fn evbrsub i ulong known bool cnt ulong to void
594+o = get fabo i
595+if not known
596+evxc 45
597+for k ulong get fabl i bound 64
598+evsubc get fabr add o k
599+end
600+evsubt tevmovd
601+ret
602+end
603+d = new uchar 24 0
604+n = evdec cnt d
605+for k ulong n bound 24
606+evxc get d k
607+evsubc get d k
608+end
609+evsubt tevncom
610+if ne cnt 1
611+evsubt tevncs
612+end
613+evsubt tevon
614+for k ulong get fabl i bound 64
615+evsubc get fabr add o k
616+end
617+end
618+note ---- the chain record of a branch move
619+note evchain i a: the last LAND or IMPORT record of project i's chain for its default branch, when its
620+note payload (records/N) says "new <gevnew[a, a+40)>": gevchn / gevchnl hold N and gevcht its time;
621+note false otherwise (no such record, or a chain or record that cannot be read whole)
622+fn evchain i ulong a ulong to bool
623+put gevchnl 0 0
624+put gevcht 0 0
625+xspproj i
626+fpt tevschn
627+r = frdall
628+if or lt r 0 ne get fxotr 0 0
629+ret false
630+end
631+n = get fxol 0
632+p = ulong 0
633+for it ulong n bound 16777216
634+if ge p n
635+break
636+end
637+e = p
638+for k ulong sub n p bound 16777216
639+if eq get fxo e 10
640+break
641+end
642+e = add e 1
643+end
644+evchln i p e
645+p = add e 1
646+end
647+if eq get gevchnl 0 0
648+ret false
649+end
650+xspproj i
651+fpt tevsrec
652+for k ulong get gevchnl 0 bound 24
653+fpc get gevchn k
654+end
655+r2 = frdall
656+if or lt r2 0 ne get fxotr 0 0
657+put gevchnl 0 0
658+ret false
659+end
660+if evhasnew a
661+ret true
662+end
663+put gevchnl 0 0
664+ret false
665+end
666+note evchln i p e: chain line fxo[p, e) "N TAB time TAB KIND TAB actor TAB branch TAB ...": when KIND is
667+note LAND or IMPORT and branch is i's default branch, N and the time are kept
668+fn evchln i ulong p ulong e ulong to void
669+tb = new ulong 5 0
670+k = ulong 0
671+for j ulong sub e p bound 16777216
672+if eq get fxo add p j 9
673+if lt k 5
674+put tb k add p j
675+end
676+k = add k 1
677+end
678+end
679+if lt k 5
680+ret
681+end
682+if not evchkk get tb 1 get tb 2
683+ret
684+end
685+if not evchkb i add get tb 3 1 get tb 4
686+ret
687+end
688+evchkn p get tb 0 get tb 1
689+end
690+note evchkk t1 t2: KIND, fxo(t1, t2), is LAND or IMPORT
691+fn evchkk t1 ulong t2 ulong to bool
692+ks = add t1 1
693+ret or evcfx ks t2 tevsland evcfx ks t2 tevsimp
694+end
695+note evchkb i bs be: fxo[bs, be) is i's default branch
696+fn evchkb i ulong bs ulong be ulong to bool
697+if ne sub be bs get fabl i
698+ret false
699+end
700+o = get fabo i
701+n = sub be bs
702+for j ulong n bound 64
703+if ne get fxo add bs j get fabr add o j
704+ret false
705+end
706+end
707+ret true
708+end
709+note evchkn p t0 t1: keep the record number fxo[p, t0) (1..20 digits) and the time fxo(t0, t1)
710+fn evchkn p ulong t0 ulong t1 ulong to void
711+nl = sub t0 p
712+if or eq nl 0 gt nl 20
713+ret
714+end
715+for j ulong nl bound 20
716+if not evdig get fxo add p j
717+ret
718+end
719+end
720+for j ulong nl bound 20
721+put gevchn j get fxo add p j
722+end
723+put gevchnl 0 nl
724+ts = add t0 1
725+put gevcht 0 0
726+if eq sub t1 ts 20
727+put gevcht 0 evisot ts
728+end
729+end
730+fn evcfx a ulong e ulong t view uchar * to bool
731+if ne sub e a len t
732+ret false
733+end
734+for i ulong len t bound 64
735+if ne get fxo add a i get t i
736+ret false
737+end
738+end
739+ret true
740+end
741+note evhasnew a: the record payload in fxo has the line "new <gevnew[a, a+40)>"
742+fn evhasnew a ulong to bool
743+n = get fxol 0
744+p = ulong 0
745+for it ulong n bound 16777216
746+if ge p n
747+break
748+end
749+e = p
750+for k ulong sub n p bound 16777216
751+if eq get fxo e 10
752+break
753+end
754+e = add e 1
755+end
756+if evnewln p e a
757+ret true
758+end
759+p = add e 1
760+end
761+ret false
762+end
763+note evnewln p e a: fxo[p, e) is exactly "new " and gevnew[a, a+40)
764+fn evnewln p ulong e ulong a ulong to bool
765+if ne sub e p add len tevsnew 40
766+ret false
767+end
768+q = add p len tevsnew
769+if not evcfx p q tevsnew
770+ret false
771+end
772+for k ulong 40
773+if ne get fxo add q k get gevnew add a k
774+ret false
775+end
776+end
777+ret true
778+end
779+note evisot p: fxo[p, p+20) "YYYY-MM-DDTHH:MM:SSZ" as epoch seconds (UTC); 0 when it is not that shape
780+fn evisot p ulong to ulong
781+for k ulong 20
782+c = get fxo add p k
783+if or eq k 4 eq k 7
784+if ne c 45
785+ret 0
786+end
787+continue
788+end
789+if eq k 10
790+if ne c 84
791+ret 0
792+end
793+continue
794+end
795+if or eq k 13 eq k 16
796+if ne c 58
797+ret 0
798+end
799+continue
800+end
801+if eq k 19
802+if ne c 90
803+ret 0
804+end
805+continue
806+end
807+if not evdig c
808+ret 0
809+end
810+end
811+days = evisod p
812+if eq days 0
813+ret 0
814+end
815+hh = evcnum add p 11 2
816+mi = evcnum add p 14 2
817+ss = evcnum add p 17 2
818+if or or gt hh 23 gt mi 59 gt ss 60
819+ret 0
820+end
821+s = add mul hh 3600 add mul mi 60 ss
822+ret add mul days 86400 s
823+end
824+note evisod p: the date fxo[p, p+10) as days since 1970-01-01, 0 when out of range
825+fn evisod p ulong to ulong
826+y = evcnum p 4
827+mo = evcnum add p 5 2
828+d = evcnum add p 8 2
829+if or lt y 1970 or lt mo 1 gt mo 12
830+ret 0
831+end
832+if or lt d 1 gt d 31
833+ret 0
834+end
835+ret evcdays y mo d
836+end
837+fn evcnum p ulong n ulong to ulong
838+v = ulong 0
839+for k ulong n bound 8
840+v = add mul v 10 ulong sub get fxo add p k 48
841+end
842+ret v
843+end
844+note evcdays y m d: days from 1970-01-01 to the proleptic Gregorian date (y >= 1970)
845+fn evcdays y ulong m ulong d ulong to ulong
846+mp = add m 9
847+yy = sub y 1
848+if gt m 2
849+mp = sub m 3
850+yy = y
851+end
852+doy = add div add mul 153 mp 2 5 sub d 1
853+ret evcdz yy doy
854+end
855+note evcdz yy doy: days since 1970-01-01 of day doy (0 = 1 March) of the March-based year yy
856+fn evcdz yy ulong doy ulong to ulong
857+era = div yy 400
858+yoe = sub yy mul era 400
859+doe = add mul yoe 365 div yoe 4
860+doe = add doe doy
861+doe = sub doe div yoe 100
862+ret sub add mul era 146097 doe 719468
863+end

store/head.om

new file mode 100644
@@ -0,0 +1,25 @@
1+note store/head.om: nodes/head.om of the store-reading build (run.sh units with FORGE_STORE). The
2+note default branch of the current repository is the default-branch field of its catalog line
3+note (store/repos.om put it into fabr after checking it against the branch rule of om/landrec.om and
4+note against record 1), so no HEAD file is read. Callers (browse brdefref, dl dldefbr) fall back to
5+note "main" when nshead is false, as with nodes/head.om; here that happens only without a current
6+note repository.
7+global nshb uchar 256
8+global nshbl ulong 1
9+fn nshead to bool
10+put nshbl 0 0
11+i = get fridx 0
12+if ge i get fan 0
13+ret false
14+end
15+n = get fabl i
16+if or eq n 0 gt n len nshb
17+ret false
18+end
19+o = get fabo i
20+for k ulong n bound 256
21+put nshb k get fabr add o k
22+end
23+put nshbl 0 n
24+ret true
25+end

store/moving.om

new file mode 100644
@@ -0,0 +1,42 @@
1+note store/moving.om: the one answer of the addresses whose part the store build composes out while
2+note it moves to the new Interplane store (salvage, community, open, trending; store/mvsalvage.om,
3+note store/mvcommunity.om, store/mvopen.om, store/mvgrowth.om, composed by run.sh in place of
4+note server/no<part>.om when FORGE_STORE is set). Status 503 with no Retry-After (no time is promised),
5+note title "Moving" and the text "This part is moving to the new Interplane store and is not
6+note available yet." (server/pages.om ferrti, ferrmsg); a JSON request (a .json name, or Accept JSON)
7+note gets the forge/error/1 document with "reason":"moving" (server/jsonp.om fyerr). The request flag
8+note fmvng (server/util.om, reset by fresetr) is what tells those words apart from every other 503.
9+text tmvjs ".json"
10+note mvans: answer this request as moving; any method
11+fn mvans to long
12+put fmvng 0 1
13+put fretry 0 0
14+if mvjsnm
15+fyerr 503
16+end
17+ret 503
18+end
19+note mvjsnm: the path ends with ".json" (a JSON name needs no Accept header)
20+fn mvjsnm to bool
21+n = get fpathl 0
22+m = len tmvjs
23+if lt n m
24+ret false
25+end
26+for i ulong m
27+if ne get fpath add sub n m i get tmvjs i
28+ret false
29+end
30+end
31+ret true
32+end
33+note mvunder t: the path is t, or t then "/" and anything
34+fn mvunder t view uchar * to bool
35+if not fpre t
36+ret false
37+end
38+if eq get fpathl 0 len t
39+ret true
40+end
41+ret eq get fpath len t 47
42+end

store/mvcommunity.om

new file mode 100644
@@ -0,0 +1,13 @@
1+note store/mvcommunity.om: the store build's seam for community/ (defines the names of
2+note server/nocommunity.om). /community, /community/ and everything under it answer the 503 of
3+note store/moving.om; no part page shows a community record.
4+text tmvcm "/community"
5+fn cm_route to long
6+if mvunder tmvcm
7+ret mvans
8+end
9+ret 0
10+end
11+fn cm_partln id view uchar * to void
12+ret
13+end

store/mvgrowth.om

new file mode 100644
@@ -0,0 +1,15 @@
1+note store/mvgrowth.om: the store build's seam for growth/ (defines the names of server/nogrowth.om).
2+note /trending and /trending.json answer the 503 of store/moving.om; every other address growth
3+note reads (explore?order=, insights) is answered as without growth.
4+text tmvtr "/trending"
5+text tmvtrj "/trending.json"
6+fn grroute to long
7+if or fpeq tmvtr fpeq tmvtrj
8+ret mvans
9+end
10+ret 0
11+end
12+note grorder: what fpgone and fpgroot ask first (the one-segment pages): the same as grroute
13+fn grorder to long
14+ret grroute
15+end

store/mvopen.om

new file mode 100644
@@ -0,0 +1,27 @@
1+note store/mvopen.om: the store build's seam for open/ (defines the names of server/noopen.om).
2+note /open, /open/ and everything under it, /open.json, /bring.sh, /get.sh and /withdraw.sh answer
3+note the 503 of store/moving.om; the forge row has no Open builds entry.
4+text tmvop "/open"
5+text tmvopj "/open.json"
6+text tmvbr "/bring.sh"
7+text tmvgt "/get.sh"
8+text tmvwd "/withdraw.sh"
9+fn ohroute to long
10+if or fpeq tmvopj or fpeq tmvbr or fpeq tmvgt fpeq tmvwd
11+ret mvans
12+end
13+if mvunder tmvop
14+ret mvans
15+end
16+ret 0
17+end
18+fn ohnav to void
19+ret
20+end
21+global gobody ulong 3
22+fn ohbody to bool
23+ret false
24+end
25+fn ohbodyend to void
26+ret
27+end

store/mvsalvage.om

new file mode 100644
@@ -0,0 +1,14 @@
1+note store/mvsalvage.om: the store build's seam for salvage/ (defines the names of server/nosalvage.om).
2+note /salvage, /salvage/ and everything under /salvage/ answer the 503 of store/moving.om; the forge
3+note row has no Salvage Yard entry and the stylesheet adds nothing.
4+text tmvsl "/salvage"
5+text tlcss ""
6+fn slroute to long
7+if mvunder tmvsl
8+ret mvans
9+end
10+ret 0
11+end
12+fn slnav to void
13+ret
14+end

store/repos.om

new file mode 100644
@@ -0,0 +1,1112 @@
1+note store/repos.om: the native-store source of the store-reading build. run.sh composes it in place
2+note of server/repos.om when FORGE_STORE is set, after .build/store.om (tfsroot, the store root with a
3+note final "/", and FSCB / tfcbase, the HTTPS clone base). It defines the words server/repos.om
4+note defines (fload, fsrcchg, fkgit, fkgiti, fputid, fhasal, fradsrc, fpjterms, fjclone, tfsf4) from
5+note the store that interplane-native CONTRACT.md v0 describes:
6+note ROOT/catalog.tsv name TAB id TAB default-branch TAB head TAB visibility LF
7+note ROOT/projects/NAME/repo.git the project's bare Git repository
8+note ROOT/projects/NAME/records/1 record 1: name, branch, visibility, owner key, alias, nonce
9+note The project list is the catalog and nothing else: no folder is scanned, and RIDS.md and
10+note ~/.radicle are never read on this path. Fail closed: a catalog that cannot be read or is a link,
11+note is longer than fxo, has a line without exactly five tab-separated fields or without its final
12+note line feed, holds a control byte, a name, id, branch, head or visibility outside the rules of
13+note om/landrec.om in interplane-native, two names that differ only in case or two equal ids: then
14+note fan is 0 (every repository URL is 404) and one "forged: catalog refused" line on stderr gives
15+note the reason and the line. Private lines are skipped. Every public line is served (Drake's
16+note decision: the store build serves the whole public catalog, minus the deny list), except one the
17+note allow-list table cannot hold (FAMAX rows, server/util.om; store/tests/capacity.sh alarms long
18+note before), left out with one line each. A public line is served only when (xsok):
19+note ROOT/projects, the project folder, its repo.git and records are folders, not links (lstat);
20+note records/1 (opened without following a link) hashes to the line's id with SHA-256, and is the
21+note PROJECT record of the same name, branch and visibility public;
22+note the deny list (server/repos.om fdeny) names neither the name nor the old Radicle id;
23+note no project already served has the same old Radicle id;
24+note refs/heads/<branch> in repo.git is exactly the line's head (or is absent when the head is none);
25+note the name fits the table (100 bytes, fnmput) and the branch too (60 bytes, fbrput).
26+note Otherwise that project alone is left out with one "forged: project NAME left out" line on stderr.
27+note The key of a project (faid: social targets, counts, receipts, the archive cache folder, /rad:
28+note links) is its old Radicle id from record 1 (alias) without "rad:", or its 64-hex id when it has
29+note none. New identifiers in pages and machine forms are git:<id> (fputid).
30+global xsgid uchar 16384
31+global xshead uchar 10240
32+global xshn ulong 256
33+global xsown uchar 16384
34+global xsownl ulong 256
35+global xsal ulong 256
36+global xskeep ulong 256
37+global xsck ulong 4
38+global xsmsg uchar 8192
39+global xsml ulong 1
40+text tfsprjd "projects"
41+text tfsrec "/records"
42+text tfsrec1 "/records/1"
43+text tfscat "catalog.tsv"
44+text tfsgitp "git:"
45+text tfradp "rad:"
46+text tfsnone "none"
47+text tfspub "public"
48+text tfspriv "private"
49+text tfsrevp "rev-parse"
50+text tfsq "-q"
51+text tfsvfy "--verify"
52+text tfscmt "^{commit}"
53+text tfsr1a "interplane-project 1\nproject "
54+text tfsr1b "branch "
55+text tfsr1c "visibility public\nowner "
56+text tfsr1d "alias "
57+text tfsr1e "nonce "
58+text tfsfp "SHA256:"
59+text tfsm1 "forged: catalog refused ("
60+text tfsm2 " at line "
61+text tfsm3 "); no repositories are served\n"
62+text tfsm4 "forged: project "
63+text tfsm5 " left out ("
64+text tfsm6 ")\n"
65+text tfsrd "cannot be read or is a link"
66+text tfsbig "longer than the read buffer"
67+text tfsnolf "no final line feed"
68+text tfsctl "control byte"
69+text tfsnf "not five tab-separated fields"
70+text tfsbn "name outside the name rule"
71+text tfsbi "id is not 64 lowercase hex digits"
72+text tfsbb "branch outside the branch rule"
73+text tfsbh "head is not 40 lowercase hex digits or none"
74+text tfsbv "visibility is not public or private"
75+text tfsdn "two names that differ only in case"
76+text tfsdn2 "two equal names"
77+text tfsdi "two equal ids"
78+text tfsful "the allow-list table is full (FAMAX rows, server/util.om)"
79+text tfsplk "ROOT/projects is a link or not a folder"
80+text tfslnm "name longer than 100 bytes (server/repos.om fnmput)"
81+text tfslbr "branch longer than 60 bytes (server/repos.om fbrput)"
82+text tfslpf "project folder is a link or not a folder"
83+text tfslrg "repo.git is a link or not a folder"
84+text tfslrc "records is a link or not a folder"
85+text tfslr1 "records/1 cannot be read or is a link"
86+text tfslhs "records/1 does not hash to the catalog id"
87+text tfslpr "records/1 is not the PROJECT record of this name, branch and visibility public"
88+text tfsldn "on the deny list"
89+text tfsldl "old Radicle id already used by a project listed before it"
90+text tfslhd "refs/heads/<branch> in repo.git is not the catalog head"
91+text tfslpl "path longer than the system allows"
92+note ---- stderr lines
93+fn xsmb to void
94+put xsml 0 0
95+end
96+fn xsmc c uchar to void
97+n = get xsml 0
98+if lt n len xsmsg
99+put xsmsg n c
100+put xsml 0 add n 1
101+end
102+end
103+fn xsmt t view uchar * to void
104+for i ulong len t bound 8192
105+xsmc get t i
106+end
107+end
108+fn xsmn v ulong to void
109+d = new uchar 20 0
110+i = ulong 20
111+x = v
112+for it ulong 20
113+i = sub i 1
114+put d i uchar add rem x 10 48
115+x = div x 10
116+if eq x 0
117+break
118+end
119+end
120+for k ulong sub 20 i bound 20
121+xsmc get d add i k
122+end
123+end
124+fn xsmw to void
125+w = write 2 xsmsg 0 get xsml 0
126+end
127+note xsrefuse: the whole catalog is refused (line 0: no line)
128+fn xsrefuse t view uchar * ln ulong to long
129+put fan 0 0
130+xsmb
131+xsmt tfsm1
132+xsmt t
133+if gt ln 0
134+xsmt tfsm2
135+xsmn ln
136+end
137+xsmt tfsm3
138+xsmw
139+ret -1
140+end
141+note xsleave: project k is left out
142+fn xsleave k ulong t view uchar * to void
143+put xskeep k 0
144+xsmb
145+xsmt tfsm4
146+for i ulong get fanl k bound 128
147+xsmc frnbyte k i
148+end
149+xsmt tfsm5
150+xsmt t
151+xsmt tfsm6
152+xsmw
153+end
154+note ---- byte rules (om/landrec.om of interplane-native: isname, isref, hex)
155+fn xsaln c uchar to bool
156+ret fisaln c
157+end
158+fn xsnamec c uchar to bool
159+ret or xsaln c or eq c 46 or eq c 95 eq c 45
160+end
161+fn xshexc c uchar to bool
162+ret or fisdig c and ge c 97 le c 102
163+end
164+fn xsisname a ulong b ulong to bool
165+if ge a b
166+ret false
167+end
168+if not xsaln get fxo a
169+ret false
170+end
171+if eq get fxo sub b 1 46
172+ret false
173+end
174+j = a
175+while lt j b bound 16777216
176+if not xsnamec get fxo j
177+ret false
178+end
179+j = add j 1
180+end
181+ret true
182+end
183+fn xsishex a ulong b ulong n ulong to bool
184+if ne sub b a n
185+ret false
186+end
187+j = a
188+while lt j b bound 16777216
189+if not xshexc get fxo j
190+ret false
191+end
192+j = add j 1
193+end
194+ret true
195+end
196+fn xsrefc c uchar to bool
197+ret or xsnamec c eq c 47
198+end
199+note xslock: fxo[e-5, e) is ".lock" and starts at or after a
200+fn xslock a ulong e ulong to bool
201+if lt sub e a 5
202+ret false
203+end
204+s = sub e 5
205+if ne get fxo s 46
206+ret false
207+end
208+if ne get fxo add s 1 108
209+ret false
210+end
211+if ne get fxo add s 2 111
212+ret false
213+end
214+if ne get fxo add s 3 99
215+ret false
216+end
217+ret eq get fxo add s 4 107
218+end
219+fn xsisref a ulong b ulong to bool
220+if ge a b
221+ret false
222+end
223+f = get fxo a
224+if or eq f 45 or eq f 46 eq f 47
225+ret false
226+end
227+l = get fxo sub b 1
228+if or eq l 46 eq l 47
229+ret false
230+end
231+p = uchar 0
232+j = a
233+while lt j b bound 16777216
234+c = get fxo j
235+if not xsrefc c
236+ret false
237+end
238+if and eq c 46 or eq p 46 eq p 47
239+ret false
240+end
241+if and eq c 47 eq p 47
242+ret false
243+end
244+if eq c 47
245+if xslock a j
246+ret false
247+end
248+end
249+p = c
250+j = add j 1
251+end
252+ret not xslock a b
253+end
254+fn xstxeq a ulong b ulong t view uchar * to bool
255+if ne sub b a len t
256+ret false
257+end
258+for k ulong len t bound 64
259+if ne get fxo add a k get t k
260+ret false
261+end
262+end
263+ret true
264+end
265+note ---- catalog lines: fxo[p, e) is one line without its line feed
266+fn xstab p ulong e ulong k ulong to ulong
267+note start of field k (0..4); fields are known to exist
268+j = p
269+n = ulong 0
270+while lt j e bound 16777216
271+if eq n k
272+ret j
273+end
274+if eq get fxo j 9
275+n = add n 1
276+end
277+j = add j 1
278+end
279+ret e
280+end
281+fn xsfend s ulong e ulong to ulong
282+j = s
283+while lt j e bound 16777216
284+if eq get fxo j 9
285+ret j
286+end
287+j = add j 1
288+end
289+ret e
290+end
291+note xsline: the reason line p..e breaks a rule, or 0 when it is well formed
292+fn xsline p ulong e ulong to ulong
293+t = ulong 0
294+j = p
295+while lt j e bound 16777216
296+c = get fxo j
297+if eq c 9
298+t = add t 1
299+else
300+if or lt c 32 eq c 127
301+ret 1
302+end
303+end
304+j = add j 1
305+end
306+if ne t 4
307+ret 2
308+end
309+ret xsfields p e
310+end
311+note xsfields: the five fields of a line with four tabs and no control byte
312+fn xsfields p ulong e ulong to ulong
313+s = p
314+f = xsfend s e
315+if not xsisname s f
316+ret 3
317+end
318+s = add f 1
319+f = xsfend s e
320+if not xsishex s f 64
321+ret 4
322+end
323+s = add f 1
324+f = xsfend s e
325+if not xsisref s f
326+ret 5
327+end
328+s = add f 1
329+f = xsfend s e
330+if not xshdok s f
331+ret 6
332+end
333+s = add f 1
334+if not xsvisok s e
335+ret 7
336+end
337+ret 0
338+end
339+fn xshdok s ulong f ulong to bool
340+if xsishex s f 40
341+ret true
342+end
343+ret xstxeq s f tfsnone
344+end
345+fn xsvisok s ulong e ulong to bool
346+if xstxeq s e tfspub
347+ret true
348+end
349+ret xstxeq s e tfspriv
350+end
351+fn xsreason r ulong ln ulong to long
352+if eq r 1
353+ret xsrefuse tfsctl ln
354+end
355+if eq r 2
356+ret xsrefuse tfsnf ln
357+end
358+if eq r 3
359+ret xsrefuse tfsbn ln
360+end
361+if eq r 4
362+ret xsrefuse tfsbi ln
363+end
364+if eq r 5
365+ret xsrefuse tfsbb ln
366+end
367+if eq r 6
368+ret xsrefuse tfsbh ln
369+end
370+if eq r 7
371+ret xsrefuse tfsbv ln
372+end
373+if eq r 8
374+ret xsrefuse tfsdn ln
375+end
376+if eq r 10
377+ret xsrefuse tfsdn2 ln
378+end
379+ret xsrefuse tfsdi ln
380+end
381+fn xsfold c uchar to uchar
382+if and ge c 65 le c 90
383+ret add c 32
384+end
385+ret c
386+end
387+note xsdupat: line [p, e) repeats the name (10 the same bytes, 8 apart from case) or the id (9) of
388+note line [q, f); 0 if neither
389+fn xsdupat p ulong e ulong q ulong f ulong to ulong
390+b = xsfend p e
391+d = xsfend q f
392+if xsfoldeq p b q d
393+if xsexeq p b q
394+ret 10
395+end
396+ret 8
397+end
398+if xsideq add b 1 add d 1
399+ret 9
400+end
401+ret 0
402+end
403+note xsexeq: fxo[a, b) equals the same number of bytes at c
404+fn xsexeq a ulong b ulong c ulong to bool
405+for k ulong sub b a bound 16777216
406+if ne get fxo add a k get fxo add c k
407+ret false
408+end
409+end
410+ret true
411+end
412+note xsfoldeq: fxo[a, b) and fxo[c, d) are equal apart from the case of A-Z
413+fn xsfoldeq a ulong b ulong c ulong d ulong to bool
414+if ne sub b a sub d c
415+ret false
416+end
417+for k ulong sub b a bound 16777216
418+x = xsfold get fxo add a k
419+y = xsfold get fxo add c k
420+if ne x y
421+ret false
422+end
423+end
424+ret true
425+end
426+fn xsideq a ulong c ulong to bool
427+for k ulong 64
428+if ne get fxo add a k get fxo add c k
429+ret false
430+end
431+end
432+ret true
433+end
434+note xsdup: line [p, e) repeats a line before it (8 or 9), or 0
435+fn xsdup p ulong e ulong to ulong
436+q = ulong 0
437+while lt q p bound 16777216
438+f = fleol q p
439+r = xsdupat p e q f
440+if ne r 0
441+ret r
442+end
443+q = add f 1
444+end
445+ret 0
446+end
447+fn xsispub p ulong e ulong to bool
448+s4 = xstab p e 4
449+ret xstxeq s4 e tfspub
450+end
451+note ---- paths
452+fn xspfold to void
453+fpb
454+fpt tfsroot
455+fpt tfsprj
456+end
457+note xspdir: ROOT/projects without the final "/", so that lstat sees a link as a link
458+fn xspdir to void
459+fpb
460+fpt tfsroot
461+fpt tfsprjd
462+end
463+fn xspproj k ulong to void
464+xspfold
465+for i ulong get fanl k bound 128
466+fpc frnbyte k i
467+end
468+end
469+fn xspfull to bool
470+ret ge get fpthl 0 4095
471+end
472+note xsisdir: lstat of fpth is a folder (a link is not)
473+fn xsisdir to bool
474+if xspfull
475+ret false
476+end
477+r = lstat fpth 0 get fpthl 0 fstb 0 128
478+if lt r 0
479+ret false
480+end
481+m = or ulong get fstb 16 shl ulong get fstb 17 8
482+ret eq and m 61440 16384
483+end
484+note xsrdnf: read the file at fpth into fxo without following a link (O_NOFOLLOW | O_CLOEXEC);
485+note the length, or -1 when it cannot be opened or is longer than fxo
486+fn xsrdnf to long
487+b = new uchar 1 0
488+put fxol 0 0
489+put fxotr 0 0
490+if xspfull
491+ret -1
492+end
493+fd = fopen fpth 0 get fpthl 0 557056 0
494+if lt fd 0
495+ret -1
496+end
497+ok = true
498+for it ulong 16777217
499+n = get fxol 0
500+if ge n len fxo
501+q = read int fd b 0 1
502+if ne q 0
503+put fxotr 0 1
504+ok = false
505+end
506+break
507+end
508+r = read int fd fxo n sub len fxo n
509+if lt r 0
510+ok = false
511+break
512+end
513+if eq r 0
514+break
515+end
516+put fxol 0 add n ulong r
517+end
518+x = fclose int fd
519+if not ok
520+ret -1
521+end
522+ret long get fxol 0
523+end
524+note xsstat: the change key of the catalog (inode, size, mtime s, mtime ns), all 0 when missing
525+fn xsstat k edit ulong 4 to void
526+fpb
527+fpt tfsroot
528+fpt tfscat
529+for i ulong 4
530+put k i 0
531+end
532+r = stat fpth 0 get fpthl 0 fstb 0 128
533+if lt r 0
534+ret
535+end
536+put k 0 xsle8 8
537+put k 1 xsle8 48
538+put k 2 xsle8 88
539+put k 3 xsle8 96
540+end
541+fn xsle8 o ulong to ulong
542+v = ulong 0
543+for i ulong 8
544+v = or v shl ulong get fstb add o i mul i 8
545+end
546+ret v
547+end
548+fn fsrcchg to bool
549+k = new ulong 4 0
550+xsstat k
551+for i ulong 4
552+if ne get k i get xsck i
553+ret true
554+end
555+end
556+ret false
557+end
558+note ---- the catalog
559+fn fload to long
560+put fan 0 0
561+put fsrcst 0 1
562+fd = fopen tfpubgit 0 len tfpubgit 0 0
563+put fpubgit 0 0
564+if ge fd 0
565+put fpubgit 0 1
566+x = fclose int fd
567+end
568+put fsrtl 0 0
569+for i ulong len tfsroot bound 4096
570+put fsrt i get tfsroot i
571+put fsrtl 0 add i 1
572+end
573+k = new ulong 4 0
574+xsstat k
575+for i ulong 4
576+put xsck i get k i
577+end
578+xspdir
579+if not xsisdir
580+ret xsrefuse tfsplk 0
581+end
582+n = xscatrd
583+if lt n 0
584+if ne get fxotr 0 0
585+ret xsrefuse tfsbig 0
586+end
587+ret xsrefuse tfsrd 0
588+end
589+ln = ulong n
590+if and gt ln 0 ne get fxo sub ln 1 10
591+ret xsrefuse tfsnolf 0
592+end
593+p = ulong 0
594+li = ulong 0
595+while lt p ln bound 16777216
596+e = fleol p ln
597+li = add li 1
598+r = xsline p e
599+if ne r 0
600+ret xsreason r li
601+end
602+r = xsdup p e
603+if ne r 0
604+ret xsreason r li
605+end
606+p = add e 1
607+end
608+m = xsfill ln
609+put fan 0 m
610+for i ulong m bound FAMAX
611+xscheck i
612+end
613+w = ulong 0
614+for i ulong m bound FAMAX
615+if eq get xskeep i 1
616+xsmove w i
617+w = add w 1
618+end
619+end
620+put fan 0 w
621+for i ulong w bound FAMAX
622+fmeta i
623+end
624+ret long w
625+end
626+note xscatrd: ROOT/catalog.tsv into fxo, opened without following a link. The project list is this
627+note file and nothing else (store/tests/compare.sh mutant "scan" replaces this word with a reader
628+note of the project folders and must be caught).
629+fn xscatrd to long
630+fpb
631+fpt tfsroot
632+fpt tfscat
633+ret xsrdnf
634+end
635+note xsfill: every public line of the catalog in fxo[0, ln) into the table, in catalog order; the
636+note number of rows. A name or branch the table cannot hold, or a line past FAMAX rows, leaves that
637+note project out here.
638+fn xsfill ln ulong to ulong
639+k = ulong 0
640+p = ulong 0
641+while lt p ln bound 16777216
642+e = fleol p ln
643+if xsispub p e
644+e0 = xsfend p e
645+if ge k FAMAX
646+xsleavr p e0 tfsful
647+else
648+if xsrow k p e
649+k = add k 1
650+end
651+end
652+end
653+p = add e 1
654+end
655+ret k
656+end
657+fn xsrow k ulong p ulong e ulong to bool
658+e0 = xsfend p e
659+if not fnmput k p e0
660+xsleavr p e0 tfslnm
661+ret false
662+end
663+s = xstab p e 2
664+if not fbrput k s xsfend s e
665+xsleavr p e0 tfslbr
666+ret false
667+end
668+xsrowid k xstab p e 1
669+xsrowhd k xstab p e 3 e
670+put faio k mul k 64
671+put fail k 0
672+put xsal k 0
673+put xsownl k 0
674+put xskeep k 1
675+ret true
676+end
677+fn xsrowid k ulong s ulong to void
678+g = mul k 64
679+for j ulong 64
680+put xsgid add g j get fxo add s j
681+end
682+end
683+fn xsrowhd k ulong s ulong e ulong to void
684+if xstxeq s xsfend s e tfsnone
685+put xshn k 0
686+ret
687+end
688+put xshn k 1
689+g = mul k 40
690+for j ulong 40
691+put xshead add g j get fxo add s j
692+end
693+end
694+note xsleavr: a project left out while its name is still in fxo[a, b)
695+fn xsleavr a ulong b ulong t view uchar * to void
696+xsmb
697+xsmt tfsm4
698+for j ulong sub b a bound 16777216
699+xsmc get fxo add a j
700+end
701+xsmt tfsm5
702+xsmt t
703+xsmt tfsm6
704+xsmw
705+end
706+note ---- one project (xscheck sets xskeep k to 1 when it is served)
707+fn xscheck k ulong to void
708+put xskeep k 0
709+if not xsfolders k
710+ret
711+end
712+if not xsrec1 k
713+ret
714+end
715+if fdeny k
716+xsleave k tfsldn
717+ret
718+end
719+if xsaldup k
720+xsleave k tfsldl
721+ret
722+end
723+if not xsheadok k
724+xsleave k tfslhd
725+ret
726+end
727+put xskeep k 1
728+end
729+fn xsfolders k ulong to bool
730+xspproj k
731+if xspfull
732+xsleave k tfslpl
733+ret false
734+end
735+if not xsisdir
736+xsleave k tfslpf
737+ret false
738+end
739+xspproj k
740+fpt tfsrg
741+if not xsisdir
742+xsleave k tfslrg
743+ret false
744+end
745+xspproj k
746+fpt tfsrec
747+if not xsisdir
748+xsleave k tfslrc
749+ret false
750+end
751+ret true
752+end
753+note xsrec1: records/1 of project k hashes to its id and is its PROJECT record; sets the key, the
754+note owner and xsal
755+fn xsrec1 k ulong to bool
756+xspproj k
757+fpt tfsrec1
758+n = xsrdnf
759+if lt n 0
760+xsleave k tfslr1
761+ret false
762+end
763+if not xshashok k ulong n
764+xsleave k tfslhs
765+ret false
766+end
767+if not xsparse k ulong n
768+xsleave k tfslpr
769+ret false
770+end
771+ret true
772+end
773+fn xshashok k ulong n ulong to bool
774+c = new ulong 40 0
775+b = new uchar 4096 0
776+h = new uchar 32 0
777+sha256_init c
778+o = ulong 0
779+while lt o n bound 16777216
780+m = hmin sub n o 4096
781+for j ulong m bound 4096
782+put b j get fxo add o j
783+end
784+sha256_update c part b 0 m
785+o = add o m
786+end
787+sha256_final c h
788+ret xsdgeq k h
789+end
790+note xsdgeq: the 64-hex id of row k spells the digest h
791+fn xsdgeq k ulong h view uchar 32 to bool
792+g = mul k 64
793+for j ulong 32
794+v = get h j
795+a = add g mul j 2
796+if ne get xsgid a xshexd shr v 4
797+ret false
798+end
799+if ne get xsgid add a 1 xshexd and v 15
800+ret false
801+end
802+end
803+ret true
804+end
805+fn xshexd v uchar to uchar
806+if lt v 10
807+ret add v 48
808+end
809+ret add v 87
810+end
811+note xsat: fxo[p, ...) starts with text t (within n)
812+fn xsat p ulong n ulong t view uchar * to bool
813+if gt add p len t n
814+ret false
815+end
816+for j ulong len t bound 64
817+if ne get fxo add p j get t j
818+ret false
819+end
820+end
821+ret true
822+end
823+note xsparse: fxo[0, n) is exactly "interplane-project 1\nproject NAME\nbranch BRANCH\nvisibility
824+note public\nowner SHA256:<43 base64>\nalias <rad:z... or ->\nnonce <32 hex>\n" for project k
825+fn xsparse k ulong n ulong to bool
826+if not xsat 0 n tfsr1a
827+ret false
828+end
829+p = len tfsr1a
830+e = fleol p n
831+if not xsnmeq k p e
832+ret false
833+end
834+p = add e 1
835+if not xsat p n tfsr1b
836+ret false
837+end
838+p = add p len tfsr1b
839+e = fleol p n
840+if not xsbreq k p e
841+ret false
842+end
843+p = add e 1
844+if not xsat p n tfsr1c
845+ret false
846+end
847+p = add p len tfsr1c
848+e = fleol p n
849+if not xsowner k p e
850+ret false
851+end
852+p = add e 1
853+if not xsat p n tfsr1d
854+ret false
855+end
856+p = add p len tfsr1d
857+e = fleol p n
858+if not xsalias k p e
859+ret false
860+end
861+p = add e 1
862+if not xsat p n tfsr1e
863+ret false
864+end
865+p = add p len tfsr1e
866+e = fleol p n
867+if not xsishex p e 32
868+ret false
869+end
870+ret eq add e 1 n
871+end
872+fn xsnmeq k ulong a ulong b ulong to bool
873+if ne sub b a get fanl k
874+ret false
875+end
876+for j ulong sub b a bound 128
877+if ne get fxo add a j frnbyte k j
878+ret false
879+end
880+end
881+ret true
882+end
883+fn xsbreq k ulong a ulong b ulong to bool
884+if ne sub b a get fabl k
885+ret false
886+end
887+o = get fabo k
888+for j ulong sub b a bound 64
889+if ne get fxo add a j get fabr add o j
890+ret false
891+end
892+end
893+ret true
894+end
895+fn xsb64c c uchar to bool
896+ret or xsaln c or eq c 43 eq c 47
897+end
898+fn xsowner k ulong a ulong b ulong to bool
899+if ne sub b a 50
900+ret false
901+end
902+if not xsat a b tfsfp
903+ret false
904+end
905+for j ulong 43
906+if not xsb64c get fxo add add a 7 j
907+ret false
908+end
909+end
910+for j ulong 50
911+put xsown add mul k 64 j get fxo add a j
912+end
913+put xsownl k 50
914+ret true
915+end
916+note xsalias: "-" (no old id: the key is the 64-hex id) or "rad:z" and 20..60 letters and digits in
917+note all after "rad:" (the key is that RID)
918+fn xsalias k ulong a ulong b ulong to bool
919+g = mul k 64
920+if and eq sub b a 1 eq get fxo a 45
921+for j ulong 64
922+put faid add g j get xsgid add g j
923+end
924+put fail k 64
925+put xsal k 0
926+ret true
927+end
928+if lt sub b a 5
929+ret false
930+end
931+if not xsat a b tfradp
932+ret false
933+end
934+s = add a 4
935+l = sub b s
936+if or lt l 21 gt l 61
937+ret false
938+end
939+if ne get fxo s 122
940+ret false
941+end
942+for j ulong l bound 64
943+if not xsaln get fxo add s j
944+ret false
945+end
946+end
947+for j ulong l bound 64
948+put faid add g j get fxo add s j
949+end
950+put fail k l
951+put xsal k 1
952+ret true
953+end
954+note xsaldup: an earlier project still served has the same old Radicle id
955+fn xsaldup k ulong to bool
956+if eq get xsal k 0
957+ret false
958+end
959+for j ulong k bound FAMAX
960+if and eq get xskeep j 1 eq get xsal j 1
961+if xskeyeq j k
962+ret true
963+end
964+end
965+end
966+ret false
967+end
968+fn xskeyeq a ulong b ulong to bool
969+if ne get fail a get fail b
970+ret false
971+end
972+for j ulong get fail a bound 64
973+if ne fridbyte a j fridbyte b j
974+ret false
975+end
976+end
977+ret true
978+end
979+note xsheadok: refs/heads/<branch> of repo.git is the catalog head, or is absent when the head is none
980+fn xsheadok k ulong to bool
981+fkgiti k
982+fka tfsrevp
983+fka tfsq
984+fka tfsvfy
985+fkopen
986+fkt tfrh
987+o = get fabo k
988+for j ulong get fabl k bound 64
989+fkc get fabr add o j
990+end
991+fkt tfscmt
992+st = fexec 5000000000
993+if eq get xshn k 0
994+ret ne st 0
995+end
996+if ne st 0
997+ret false
998+end
999+if ne get fxol 0 41
1000+ret false
1001+end
1002+if ne get fxo 40 10
1003+ret false
1004+end
1005+g = mul k 40
1006+for j ulong 40
1007+if ne get fxo j get xshead add g j
1008+ret false
1009+end
1010+end
1011+ret true
1012+end
1013+note xsmove: row i to row w (w < i), with the store's own columns
1014+fn xsmove w ulong i ulong to void
1015+if eq w i
1016+ret
1017+end
1018+fmove w i
1019+put xshn w get xshn i
1020+put xsal w get xsal i
1021+put xsownl w get xsownl i
1022+put xskeep w get xskeep i
1023+for j ulong 64
1024+put xsgid add mul w 64 j get xsgid add mul i 64 j
1025+put xsown add mul w 64 j get xsown add mul i 64 j
1026+end
1027+for j ulong 40
1028+put xshead add mul w 40 j get xshead add mul i 40 j
1029+end
1030+end
1031+note ---- git on a project: server/util.om fkgit / fkgiti name <fsrt>projects/NAME/repo.git once
1032+note fsrcst is 1 (fload sets it and fsrt before it runs any git)
1033+note ---- identity in pages and machine forms
1034+fn fputid i ulong to void
1035+fput tfsgitp
1036+for k ulong 64
1037+fputc get xsgid add mul i 64 k
1038+end
1039+end
1040+fn fhasal i ulong to bool
1041+ret eq get xsal i 1
1042+end
1043+fn fradsrc to bool
1044+ret false
1045+end
1046+note fradwalk / fradseeds: the store has no routing table; server/counts.om fzseeds never calls them
1047+note here (fradsrc is false), they exist so that counts.om composes unchanged
1048+fn fradwalk to ulong
1049+ret 0
1050+end
1051+fn fradseeds i ulong to long
1052+ret -1
1053+end
1054+text tfsf4 "<p class=\"foot-fine\">INTERPLANE Forge: agents express intent; the forge retains authority. Repositories are plain Git kept in Interplane's own signed store, served by forged, a seeded-Omega web server, with no JavaScript.</p>\n<p class=\"foot-fine\"><a href=\""
1055+note ---- the identity words of the "For developers" section (server/pages.om fpjdev1): ID, Owner,
1056+note Refs and HEAD, and Patch up to its link. The Seed word is gone: this build reads no routing table.
1057+text tsdv1 "<dt>ID</dt><dd>The project's permanent id on Interplane: the SHA-256 of its first signed record. This one is <code>git:"
1058+text tsdv2 "</code>."
1059+text tsdv3 " Its old id, kept only so that old links still work: <code>"
1060+text tsdv4 "</dd>\n<dt>Owner</dt><dd>The key that signs every record of the project. This forge lists the project under "
1061+text tsdv5 "; its key is <code>"
1062+text tsdv6 "</code>.</dd>\n<dt>Refs and HEAD</dt><dd>Refs are the names that point at versions: branches and tags. HEAD is the version a fresh copy starts from, the newest commit of the default branch.</dd>\n<dt>Patch</dt><dd>A proposed change, reviewed before it is merged. This forge does not show proposed changes from its own store yet. The list is under <a href=\""
1063+fn fpjterms to void
1064+i = get fridx 0
1065+if ge i get fan 0
1066+ret
1067+end
1068+fput tsdv1
1069+fputid4 i
1070+fput tsdv2
1071+if fhasal i
1072+fput tsdv3
1073+for k ulong get fail i bound 64
1074+fescc fridbyte i k
1075+end
1076+fput tsdv2
1077+end
1078+fput tsdv4
1079+fputown
1080+fput tsdv5
1081+for k ulong get xsownl i bound 64
1082+fescc get xsown add mul i 64 k
1083+end
1084+fput tsdv6
1085+end
1086+fn fputid4 i ulong to void
1087+for k ulong 64
1088+fputc get xsgid add mul i 64 k
1089+end
1090+end
1091+note ---- the clone object of the JSON repo form. Its keys stay those of forge/repo/1 (docs/API.md: keys
1092+note are never removed): rad and rad_clone are null (no Radicle copy is served), git_https is the
1093+note HTTPS address when the build has a clone base (FSCB 1), else null.
1094+text tsjcl1 ",\n\"clone\":{\"rad\":null,\"rad_clone\":null,\"git_https\":"
1095+text tsjcl2 "\""
1096+text tsjcl3 "\"}"
1097+text tsjcl4 "null}"
1098+fn fjclone i ulong to void
1099+fput tsjcl1
1100+if eq FSCB 1
1101+fput tsjcl2
1102+fput tfcbase
1103+fput tfsprj
1104+for k ulong get fanl i bound 128
1105+fputc frnbyte i k
1106+end
1107+fput tfsrg
1108+fput tsjcl3
1109+ret
1110+end
1111+fput tsjcl4
1112+end

store/tests/agentdoor-store.sh

new file mode 100755
@@ -0,0 +1,340 @@
1+#!/usr/bin/env bash
2+# ORACLE: host test driver (bash + curl + git + interplane-native ipl + server/tests/agentdoor.py), not
3+# product code.
4+# store/tests/agentdoor-store.sh: the agent door (docs/AGENT-DOOR.md) of the store-reading build: the
5+# event stream and the feed read from a native store (store/evcol.om), agents.json generated for the
6+# build's units, the served set (every public catalog line less the deny list) and the 503 "moving"
7+# answers of the parts the store build composes out (store/moving.om).
8+# IPL_DIR=<interplane-native checkout with bin/ built> bash store/tests/agentdoor-store.sh
9+# (spark; FORGED_CPUS default 0-2, run under its pool lock; AGENTDOOR_PORT default 19994, private
10+# ports 19990..19999 only; KEEP=1 keeps the temp dir)
11+# Everything is private to a temp dir: a store made with ipl and a throwaway key, holding
12+# adfix public: commits, an annotated tag v1
13+# adtwo public, no tag: served, so that "a landing reads one project" has another to skip
14+# adhid a private catalog line: must never appear (pages, JSON, stream)
15+# omega-pearl public under a denied name (server/repos.om fdeny): must never appear
16+# adrid public, its old id the denied rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ: must never appear
17+# the social log of server/tests/agentdoor.py (stars of served, private and denied projects,
18+# favorites, a watch, follows, an unstar, accounts, sessions, a logout) and an open shelf list (its
19+# kinds must not occur: the open slice is not composed). The expected served set is computed from the
20+# catalog (store/tests/expect_served.py). The site chrome is read from the real store's interplane.io
21+# project (read only). Never 18480, ~/forge-data, ~/interplane-store or ~/interplane-store-owner writes.
22+# Gates: kinds (release, branch_moved, star, follow only), sources name store objects (chain.tsv:<N>
23+# for a landing, repo.git:<sha> for a tag, social.log:<seq>), times (the chain record's time for a
24+# landing), change-triggered collection (no pass on unchanged requests; a landing reads one of the two
25+# served projects; a tag written into repo.git reads one project; a catalog rewritten with the same
26+# lines reads nothing; a project added to the catalog is served and adds no event), seq stable
27+# across a restart and continued after it, every agents.json route answering its schema (agentdoor.py
28+# agents), not_available holding the composed-out parts (salvage/, community/, open and trending
29+# with the moving reason), no Radicle words in agents.json or the feed page, the private and denied
30+# projects 404 on their pages, their JSON and absent from stream and feed; every moving address
31+# (salvage, community, open, open.json, bring.sh, get.sh, withdraw.sh, trending, on both bases)
32+# answers 503 with no Retry-After, title "Moving" and exactly "This part is moving to the new
33+# Interplane store and is not available yet.", and as JSON forge/error/1 with "reason":"moving".
34+# Negative controls (each must FAIL the check it targets): a collector whose star check accepts any
35+# repository, a collector that never finds the chain record, an agents table that calls a collab row
36+# part of the forge, a moving seam that does not mark its 503 as moving.
37+set -u
38+cd "$(dirname "$0")/../.."
39+ROOT=$(pwd)
40+H=$ROOT/server/tests
41+CORES=${FORGED_CPUS:-0-2}
42+PORT=${AGENTDOOR_PORT:-19994}
43+case $PORT in 1999[0-9]) ;; *) echo "REFUSED: use a private port in 19990..19999"; exit 2 ;; esac
44+IPLD=${IPL_DIR:?IPL_DIR: an interplane-native checkout with bin/ built}
45+[ -x "$IPLD/ipl" ] && [ -x "$IPLD/bin/landrec" ] && [ -x "$IPLD/bin/chain" ] || { echo "NOT_RUN: $IPLD has no built ipl"; exit 3; }
46+SITE=${FORGE_SITE_STORE:-$HOME/interplane-store-owner/projects/interplane.io/repo.git}
47+[ -d "$SITE" ] || { echo "NOT_RUN: no site repository $SITE for the chrome"; exit 3; }
48+OMC=$HOME/work/flux/omega-mv/seed/out/omc
49+T=$(mktemp -d /tmp/agentdoor-store.XXXXXX)
50+chmod 700 "$T"
51+PASS=0; FAIL=0; PID=
52+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
53+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
54+check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
55+stop() { [ -n "$PID" ] && kill "$PID" 2> /dev/null; [ -n "$PID" ] && wait "$PID" 2> /dev/null; PID=; }
56+trap 'stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
57+if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
58+U=http://127.0.0.1:$PORT
59+
60+# ---- fixture store
61+ssh-keygen -q -t ed25519 -N "" -C "agentdoor-store test key" -f "$T/key" || exit 1
62+export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@invalid
63+export GIT_AUTHOR_DATE=2026-11-13T00:00:00Z GIT_COMMITTER_DATE=2026-11-13T00:00:00Z
64+mkproj() { # mkproj NAME ALIAS [VISIBILITY [notag]]: a working copy $T/w-NAME with a.txt and (unless notag) an annotated tag v1, then init + import
65+ local n=$1 w=$T/w-$1 vis=${3:-public}
66+ git init -q -b main "$w" && echo "$n" > "$w/a.txt" && git -C "$w" add a.txt && git -C "$w" commit -qm "first $n" || return 1
67+ [ "${4:-}" = notag ] || git -C "$w" tag -a v1 -m "release one of $n" || return 1
68+ mkdir -p "$T/store/projects/$n" && git clone -q --bare "$w" "$T/store/projects/$n/repo.git" || return 1
69+ "$IPLD/ipl" init "$T/store" "$n" main "$vis" "$2" "$T/key" > /dev/null 2>> "$T/ipl.err" || return 1
70+ printf 'fixture %s\n' "$n" > "$T/ev-$n"; printf 'note %s\n' "$n" > "$T/note-$n"
71+ "$IPLD/ipl" import "$T/store" "$n" main "$T/ev-$n" "$T/note-$n" "import-$n" "$T/key" > /dev/null 2>> "$T/ipl.err" || return 1
72+}
73+RF=zAgentDoorStoreFixtureAdfix1 RP=zAgentDoorStoreFixtureHidden RD=zAgentDoorStoreFixtureDenied RT=zAgentDoorStoreFixtureAdtwo1
74+DENYRID=z2ft64NFLsKzWttCXw6NWNbRQLggQ # server/repos.om fdeny (an old id, not a store id)
75+mkproj adfix "rad:$RF" && mkproj adtwo "rad:$RT" public notag && mkproj adhid "rad:$RP" private && mkproj omega-pearl "rad:$RD" \
76+ && mkproj adrid "rad:$DENYRID" public notag || { bad "fixture store: $(tail -3 "$T/ipl.err")"; exit 1; }
77+for n in adfix adtwo adhid omega-pearl adrid; do "$IPLD/ipl" verify "$T/store" "$n" > /dev/null || bad "fixture $n does not verify"; done
78+check "$(wc -l < "$T/store/catalog.tsv")" 5 "fixture catalog lines"
79+check "$(awk -F'\t' '$1 == "adhid" {print $5}' "$T/store/catalog.tsv")" private "adhid is a private catalog line"
80+WANT=$(python3 store/tests/expect_served.py "$T/store" | sort | tr '\n' ' ')
81+check "$WANT" "adfix adtwo " "expected served set computed from the catalog"
82+MAIN0=$(git --git-dir="$T/store/projects/adfix/repo.git" rev-parse refs/heads/main)
83+TAGV1=$(git --git-dir="$T/store/projects/adfix/repo.git" rev-parse refs/tags/v1)
84+
85+# ---- data dir, social log, open shelf, research files (as server/tests/agentdoor.sh)
86+mkdir -p "$T/data/logs" "$T/data/open/p" "$T/social"
87+OWN=z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK
88+D1=did:key:z6MkfixtureAccountOneKeyAbCdEfGhJkLmNpQrStUvWxY
89+D2=did:key:z6MkotherFixtureAccountKeyAbCdEfGhJkLmNpQrStUvWxYz
90+OH=z3AgentDoorHeadFixtureProject
91+printf '%s\theld\t%s\t2026-11-10\t10\tshelf-a\tfixture project a\tnote a\n' "$OH" "$D2" > "$T/data/open/list.tsv"
92+mkdir -p "$T/data/research/gen/public.fixture1/w" && ln -s gen/public.fixture1 "$T/data/research/current"
93+printf '{"schema":"interplane/research/1","works":[]}\n' > "$T/data/research/gen/public.fixture1/index.json"
94+printf '{"schema":"interplane/research-work/1","work":{"slug":"fixture-work"}}\n' > "$T/data/research/gen/public.fixture1/w/fixture-work.json"
95+cat > "$T/fixture.json" <<EOF
96+{"d1": "$D1", "d2": "$D2", "nid": "$OWN", "rid_fix": "$RF", "rid_priv": "$RP", "rid_den": "$RD",
97+ "main0": "$MAIN0", "main1": "$MAIN0", "tag_v1": "$TAGV1", "open_held": "$OH", "patch1": "-", "issue1": "-"}
98+EOF
99+python3 "$H/agentdoor.py" social "$T/social" "$T/fixture.json" > /dev/null || { bad "social fixture"; exit 1; }
100+
101+# ---- builds: build OUT [SED] [AGENTS_TSV]: this tree's store units, port and data dir rewritten
102+build() {
103+ local out=$1 extra=${2:-} at=${3:-}
104+ if [ -n "$at" ]; then cp server/agents.tsv "$T/agents.tsv.keep" && cp "$at" server/agents.tsv; fi
105+ (export FORGE_STORE=$T/store FORGE_SITE_STORE=$SITE FORGE_CLONE_BASE=https://interplane.io/
106+ { printf 'om2\n'; cat $(./run.sh units); } > "$out.src.om" && cp .build/agents.tsv "$out.agents.tsv")
107+ local rc=$?
108+ if [ -n "$at" ]; then cp "$T/agents.tsv.keep" server/agents.tsv; fi
109+ [ "$rc" = 0 ] || return 1
110+ local s=(-e "s/haddr4 a 2130706433 18480/haddr4 a 2130706433 $PORT/" -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|")
111+ [ -n "$extra" ] && s+=(-e "$extra")
112+ sed "${s[@]}" "$out.src.om" > "$out.om"
113+ taskset -c "$CORES" nice -n 10 "$OMC" < "$out.om" > "$out" 2> "$out.err" || { echo "BUILD FAILED $out: $(cat "$out.err")"; return 1; }
114+ chmod 755 "$out"
115+}
116+start() { # start BIN
117+ FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" &
118+ PID=$!
119+ for _ in $(seq 100); do curl -s -o /dev/null "$U/explore" && return 0; sleep 0.1; done
120+ return 1
121+}
122+passes() { grep -c '^events: pass ' "$1.log"; }
123+get() { curl -s -o "$T/b" -D "$T/h" -w '%{http_code}' -H "X-Forge-Base: ${2:-/}" "$U/$1"; }
124+ev() { curl -s "$U/events.json?limit=200" | python3 -c "$1"; }
125+lastpass() { grep '^events: pass ' "$1.log" | tail -1; }
126+field() { echo "$1" | sed -n "s/.*$2 \([0-9]*\).*/\1/p"; }
127+
128+build "$T/forged" || { bad "test build"; exit 1; }
129+ok "test build $(sha256sum < "$T/forged" | cut -c1-16)"
130+grep -q '^fn evcollect' "$T/forged.om" && grep -q '^text tevschn' "$T/forged.om" && ok "door/ composed with store/evcol.om" || bad "store collector not composed"
131+! grep -q '^fn evcobs' "$T/forged.om" && ok "door/ev3col.om (Radicle refs and COBs) not composed" || bad "door/ev3col.om composed in a store build"
132+start "$T/forged" || { bad "test forged did not start: $(tail -3 "$T/forged.log")"; exit 1; }
133+
134+# ---- the served set: every public line less the deny list
135+check "$(get drakestapleton/adfix)" 200 "served project page"
136+check "$(get drakestapleton/adtwo)" 200 "second served project page"
137+check "$(get drakestapleton/adhid)" 404 "private project page"
138+check "$(get drakestapleton/adhid.json)" 404 "private project JSON"
139+check "$(curl -s -o /dev/null -w '%{http_code}' -H 'Accept: application/json' "$U/drakestapleton/adhid")" 404 "private project with Accept JSON"
140+check "$(get drakestapleton/omega-pearl)" 404 "denied project page (name)"
141+check "$(get drakestapleton/adrid)" 404 "denied project page (old id)"
142+check "$(get drakestapleton/adrid.json)" 404 "denied project JSON (old id)"
143+get explore.json > /dev/null
144+check "$(python3 -c 'import json,sys; print("".join(n + " " for n in sorted(r["name"] for r in json.load(open(sys.argv[1]))["repos"])))' "$T/b")" "$WANT" "explore lists exactly the expected served set"
145+check "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["count"])' "$T/b")" "$(python3 store/tests/expect_served.py --count "$T/store")" "explore.json count = public lines less the deny list"
146+! grep -q "forged: project adhid" "$T/forged.log" && ok "stderr: the private line is skipped without a line" || bad "a stderr line names the private adhid"
147+grep -q "forged: project omega-pearl left out (on the deny list" "$T/forged.log" && ok "stderr: omega-pearl left out by the deny list" || bad "no deny line for omega-pearl"
148+grep -q "forged: project adrid left out (on the deny list" "$T/forged.log" && ok "stderr: adrid left out by the deny list (its old id)" || bad "no deny line for adrid"
149+
150+# ---- the moving parts: 503, no Retry-After, title Moving, exactly the text; JSON reason moving
151+MVTXT='This part is moving to the new Interplane store and is not available yet.'
152+MVHTML="salvage salvage/ salvage/new salvage/x/y community community/ community/join community/dl/x open open/ open/$OH open/alarms trending bring.sh get.sh withdraw.sh"
153+MVJSON="open.json trending.json open/$OH.json open/alarms.json salvage/x.json"
154+mvpage() { # mvpage PATH BASE [ACCEPT]: fetch; prints status, then mvpage.py's verdict
155+ curl -s -o "$T/mv.body" -D "$T/mv.h" -w '%{http_code} ' -H "X-Forge-Base: $2" ${3:+-H "Accept: $3"} "$U/$1"
156+ grep -qi '^retry-after:' "$T/mv.h" && printf 'retry-after ' || printf 'no-retry '
157+ python3 - "$T/mv.body" "$MVTXT" <<'EOF'
158+import json, re, sys
159+b = open(sys.argv[1], encoding="utf-8", errors="replace").read()
160+try:
161+ d = json.loads(b)
162+ ok = (d.get("schema") == "forge/error/1" and d.get("status") == 503 and d.get("reason") == "moving"
163+ and d.get("message") == sys.argv[2] and d.get("error") == "Moving")
164+ print("json-moving" if ok else "json-other")
165+except ValueError:
166+ b = re.sub(r'<span translate="no">([^<]*)</span>', r"\1", b).replace(' translate="no"', "")
167+ m = re.search(r'<section class="err"><h1>(.*?)</h1><p>(.*?)</p>', b)
168+ t = re.search(r"<title>(.*?)</title>", b)
169+ ok = m and m.group(1) == "503 Moving" and m.group(2) == sys.argv[2] and t and "Moving" in t.group(1)
170+ print("html-moving" if ok else "html-other")
171+EOF
172+}
173+mvall() { # every moving address on both bases; prints one line per address that is wrong
174+ for b in / /forge/; do
175+ for p in $MVHTML; do r=$(mvpage "$p" "$b"); [ "$r" = "503 no-retry html-moving" ] || echo "[$b] $p: $r"; done
176+ for p in salvage/ community/ open/; do r=$(mvpage "$p" "$b" application/json); [ "$r" = "503 no-retry json-moving" ] || echo "[$b] $p (Accept JSON): $r"; done
177+ for p in $MVJSON; do r=$(mvpage "$p" "$b"); [ "$r" = "503 no-retry json-moving" ] || echo "[$b] $p: $r"; done
178+ done
179+ r=$(curl -s -o /dev/null -w '%{http_code}' -X POST "$U/salvage/"); [ "$r" = 503 ] || echo "POST /salvage/: $r"
180+}
181+mvall > "$T/mv.bad"
182+[ ! -s "$T/mv.bad" ] && ok "every moving address answers 503, no Retry-After, title Moving, the exact text; JSON forge/error/1 reason moving ($(echo $MVHTML $MVJSON | wc -w) addresses, both bases, Accept JSON too)" || bad "moving answers: $(head -5 "$T/mv.bad" | tr '\n' ';')"
183+for p in salvagex community-x opening open.jsonx trendingx salvagex/y; do
184+ s=$(get "$p"); [ "$s" != 503 ] && ok "$p is not a moving address ($s)" || bad "$p answers 503"
185+done
186+check "$(mvpage explore /)" "200 no-retry html-other" "the front list is not moving"
187+
188+# ---- first pass: the backfill
189+check "$(get events.json)" 200 "first events.json"
190+check "$(passes "$T/forged")" 1 "one collection pass after the first request"
191+lastpass "$T/forged"
192+check "$(ev 'import json,sys; print(" ".join(sorted(e["kind"] for e in json.load(sys.stdin)["events"])))')" "follow follow release star star" "backfill kinds: tag v1, two stars of the served project, two follows"
193+check "$(ev 'import json,sys; print(" ".join(e["source"] for e in json.load(sys.stdin)["events"] if e["kind"]=="release"))')" "repo.git:$TAGV1" "release source names the tag object in repo.git"
194+check "$(ev 'import json,sys; print(" ".join(e["source"] for e in json.load(sys.stdin)["events"] if e["kind"]=="star"))')" "social.log:6 social.log:14" "star sources are social.log lines"
195+for x in "$RP" "$RD" adhid omega-pearl; do
196+ n=$(curl -s "$U/events.json?limit=200" | grep -c "$x"); m=$(curl -s "$U/feed" | grep -c "$x")
197+ check "$n $m" "0 0" "$x appears in neither events.json nor the feed"
198+done
199+# change-triggered: unchanged requests read nothing
200+for _ in 1 2 3 4 5; do get "events.json?limit=200" > /dev/null; get feed > /dev/null; done
201+check "$(passes "$T/forged")" 1 "ten unchanged requests: no further pass"
202+# the log itself (not only the stream, which also filters at read time) holds no star of a project
203+# that is not served
204+check "$(awk -F'\t' '$3 == 11' "$T/data/events/log" | wc -l)" 2 "event log: two stars, both of the served project"
205+
206+# ---- a landing: two commits on adfix main through ipl land
207+(cd "$T/w-adfix" && echo 3 > d.txt && git add d.txt && git commit -qm three && echo 4 > e.txt && git add e.txt && git commit -qm four)
208+MAIN1=$(git -C "$T/w-adfix" rev-parse HEAD)
209+printf 'receipt\n' > "$T/receipt"; printf 'verdict\n' > "$T/verdict"
210+"$IPLD/ipl" land "$T/store" adfix main "$MAIN1" "$T/w-adfix" "$T/receipt" "$T/verdict" land-1 "$T/key" > "$T/land.out" 2>> "$T/ipl.err" \
211+ && ok "ipl land adfix $(cut -c1-60 "$T/land.out")" || bad "ipl land: $(tail -2 "$T/ipl.err")"
212+LANDN=$(awk -F'\t' '$3 == "LAND" {n = $1} END {print n}' "$T/store/projects/adfix/chain.tsv")
213+LANDT=$(awk -F'\t' -v n="$LANDN" '$1 == n {print $2}' "$T/store/projects/adfix/chain.tsv")
214+python3 - "$T/fixture.json" "$MAIN1" <<'EOF'
215+import json, sys
216+f = json.load(open(sys.argv[1])); f["main1"] = sys.argv[2]; json.dump(f, open(sys.argv[1], "w"), indent=1)
217+EOF
218+# the forge follows the catalog (it changed with the landing) before the stream is read
219+for _ in $(seq 50); do get drakestapleton/adfix.json > /dev/null; grep -q "$MAIN1" "$T/b" && break; sleep 0.2; done
220+check "$(get events.json)" 200 "events.json after the landing"
221+check "$(passes "$T/forged")" 2 "one more pass after the landing"
222+L=$(lastpass "$T/forged"); echo "$L"
223+check "$(echo "$L" | sed -n 's/.*sources read \([0-9]*\),.*/\1/p')" 1 "that pass read one source (the landed project)"
224+check "$(echo "$L" | sed -n 's/.*events added \([0-9]*\)$/\1/p')" 1 "that pass added one event"
225+B=$(ev 'import json,sys; e=[e for e in json.load(sys.stdin)["events"] if e["kind"]=="branch_moved"]; print(len(e), e[-1]["source"], e[-1]["commits"], e[-1]["from"], e[-1]["time"], e[-1]["subject"]) if e else print(0)')
226+check "$B" "1 chain.tsv:$LANDN 2 $MAIN0 $LANDT 2 new commits on main" "branch_moved: chain record source, 2 commits, from the old head, the record's time"
227+
228+# ---- a tag written into repo.git (the chain has no tag records): release, source repo.git:<sha>
229+git --git-dir="$T/store/projects/adfix/repo.git" tag -a v2 -m "release two" "$MAIN1"
230+TAGV2=$(git --git-dir="$T/store/projects/adfix/repo.git" rev-parse refs/tags/v2)
231+check "$(get events.json)" 200 "events.json after tag v2"
232+L=$(lastpass "$T/forged"); check "$(passes "$T/forged") $(echo "$L" | sed -n 's/.*events added \([0-9]*\)$/\1/p')" "3 1" "one pass, one event for tag v2"
233+check "$(ev 'import json,sys; print([e["source"] for e in json.load(sys.stdin)["events"] if e["kind"]=="release"][-1])')" "repo.git:$TAGV2" "release v2 source"
234+
235+# ---- the catalog rewritten with the same lines (ipl catalog): no project read, nothing added
236+HEAD_BEFORE=$(ev 'import json,sys; print(json.load(sys.stdin)["head_seq"])')
237+"$IPLD/ipl" catalog "$T/store" > /dev/null 2>> "$T/ipl.err"; touch "$T/store/catalog.tsv"
238+check "$(get events.json)" 200 "events.json after the catalog was rewritten"
239+check "$(passes "$T/forged")" 3 "catalog rewritten with the same lines: no pass (store/evcol.om has no catalog stat)"
240+check "$(ev 'import json,sys; print(json.load(sys.stdin)["head_seq"])')" "$HEAD_BEFORE" "head_seq unchanged by the catalog rewrite"
241+# ---- a project added to the catalog: served at once, read by one pass, no event (it has no tag)
242+mkproj adnew rad:zAgentDoorStoreFixtureAdnew1 public notag || bad "adnew: $(tail -2 "$T/ipl.err")"
243+for _ in $(seq 50); do [ "$(get drakestapleton/adnew.json)" = 200 ] && break; sleep 0.2; done
244+check "$(get drakestapleton/adnew.json)" 200 "a project added to the catalog is served"
245+check "$(get events.json)" 200 "events.json after a project was added"
246+L=$(lastpass "$T/forged"); check "$(passes "$T/forged") $(echo "$L" | sed -n 's/.*events added \([0-9]*\)$/\1/p')" "4 0" "project added: one pass, no event"
247+check "$(ev 'import json,sys; print(json.load(sys.stdin)["head_seq"])')" "$HEAD_BEFORE" "head_seq unchanged by the added project"
248+
249+# ---- kinds that this build never has
250+check "$(ev 'import json,sys; print(sorted({e["kind"] for e in json.load(sys.stdin)["events"]} - {"release","branch_moved","star","follow"}))')" "[]" "only release, branch_moved, star, follow"
251+check "$(ev 'import json,sys; d=json.load(sys.stdin)["events"]; print(all(d[i]["seq"]==i+1 for i in range(len(d))))')" "True" "seq 1..n with no gap"
252+check "$(ev 'import json,sys; print(sorted({e["repo"]["rid"][:4] for e in json.load(sys.stdin)["events"] if e["repo"]}))')" "['git:']" "event repo ids are the store identifiers (git:<id>), as forge/repo/1"
253+check "$(curl -s "$U/events.json?limit=200" | grep -c -i -E 'radicle|rad:')" 0 "no Radicle words in events.json"
254+
255+# ---- restart: seq stable, then continued
256+cp "$T/data/events/log" "$T/log.before"
257+curl -s "$U/events.json?limit=200" > "$T/ev.before"
258+stop; start "$T/forged" || { bad "restart"; exit 1; }
259+curl -s "$U/events.json?limit=200" > "$T/ev.after"
260+cmp -s "$T/ev.before" "$T/ev.after" && ok "events.json identical across a restart" || bad "events.json changed across a restart"
261+cmp -s "$T/log.before" "$T/data/events/log" && ok "event log unchanged by the restart pass" || bad "restart pass appended to the log"
262+(cd "$T/w-adfix" && echo 5 > f.txt && git add f.txt && git commit -qm five)
263+MAIN2=$(git -C "$T/w-adfix" rev-parse HEAD)
264+"$IPLD/ipl" land "$T/store" adfix main "$MAIN2" "$T/w-adfix" "$T/receipt" "$T/verdict" land-2 "$T/key" > /dev/null 2>> "$T/ipl.err" || bad "second landing"
265+for _ in $(seq 50); do get drakestapleton/adfix.json > /dev/null; grep -q "$MAIN2" "$T/b" && break; sleep 0.2; done
266+check "$(ev 'import json,sys; d=json.load(sys.stdin); print(d["head_seq"], d["events"][-1]["kind"], d["events"][-1]["commits"])')" "$((HEAD_BEFORE + 1)) branch_moved 1" "after the restart the next landing is seq head+1"
267+
268+# ---- agents.json and the feed page
269+python3 "$H/agentdoor.py" agents "$PORT" docs/API.md "$T/forged.agents.tsv" "$T/fixture.json" > "$T/agents.log" 2>&1 \
270+ && ok "agentdoor.py agents: $(tail -1 "$T/agents.log")" || bad "agentdoor.py agents: $(grep -m5 FAIL "$T/agents.log" | tr '\n' ' ')"
271+NA=$(curl -s "$U/agents.json" | python3 -c 'import json,sys; d=json.load(sys.stdin); print(" ".join(sorted({w["what"] for w in d["not_available"] if "part is not composed" in w["why"]})))')
272+for p in "{owner}/{repo}/patches" "{owner}/{repo}/issues" status.json; do
273+ case " $NA " in *" $p "*) ok "not_available lists $p (not composed)" ;; *) bad "not_available lacks $p" ;; esac
274+done
275+MV=$(curl -s "$U/agents.json" | python3 -c 'import json,sys; d=json.load(sys.stdin); print(" ".join(sorted({w["what"] for w in d["not_available"] if "moving to the new Interplane store" in w["why"] and "answers 503" in w["why"]})))')
276+for p in open.json "open/{project}.json" open/alarms.json trending.json salvage/ community/; do
277+ case " $MV " in *" $p "*) ok "not_available lists $p as moving, answering 503" ;; *) bad "not_available lacks $p as moving (got: $MV)" ;; esac
278+done
279+curl -s "$U/agents.json" | python3 -c 'import json,sys; d=json.load(sys.stdin); sys.exit(any(k in r["path"] for r in d["routes"] for k in ("patches", "issues", "open", "salvage", "community", "trending")))' \
280+ && ok "routes list no patches, issues, open, salvage, community or trending address" || bad "routes list a composed-out address"
281+for p in agents.json feed; do
282+ n=$(curl -s "$U/$p" | grep -c -i -E 'radicle|rad:|rad clone|\bRIDs?\b|\bCOBs?\b|delegate|heartwood')
283+ check "$n" 0 "no Radicle words in $p"
284+done
285+check "$(curl -s "$U/feed" | grep -c 'changes proposed\|open builds shelf')" 0 "feed intro names only this build's kinds"
286+# every not_available address of a part this build does not compose, or of a moving part that does
287+# not answer 503, does not answer its listed schema (filled from the fixture, Accept JSON, both
288+# bases); every moving address that answers 503 answers it as moving; the node health pages answer
289+# 501 (server/nostat.om)
290+curl -s "$U/agents.json" | python3 -c 'import json,sys; [print(w["what"]) for w in json.load(sys.stdin)["not_available"] if "part is not composed" in w["why"] or "this address answers 404" in w["why"]]' > "$T/na.txt"
291+curl -s "$U/agents.json" | python3 -c 'import json,sys; [print(w["what"]) for w in json.load(sys.stdin)["not_available"] if "answers 503" in w["why"]]' > "$T/mv.txt"
292+check "$(grep -c . "$T/mv.txt")" 6 "six moving addresses answering 503 in not_available"
293+while read -r p; do
294+ q=$(printf '%s' "$p" | sed -e "s|{project}|$OH|")
295+ for b in / /forge/; do
296+ r=$(mvpage "$q" "$b" application/json)
297+ check "$r" "503 no-retry json-moving" "not_available [$b] $q answers 503 as moving"
298+ done
299+done < "$T/mv.txt"
300+while read -r p; do
301+ sch=$(awk -F'\t' -v p="$p" '$3 == p {print $5}' server/agents.tsv)
302+ q=$(printf '%s' "$p" | sed -e "s|{owner}|drakestapleton|; s|{repo}|adfix|; s|{id}|$TAGV1|; s|{project}|$OH|; s|{order}|trending|")
303+ for b in / /forge/; do
304+ s=$(curl -s -o "$T/na.body" -w '%{http_code}' -H "X-Forge-Base: $b" -H 'Accept: application/json' "$U/$q")
305+ g=$(python3 -c 'import json,sys
306+try: print(json.load(open(sys.argv[1])).get("schema") or "-")
307+except Exception: print("-")' "$T/na.body")
308+ if [ "$s" = 200 ] && [ "$g" = "$sch" ]; then bad "not_available [$b] $q answers $s with its schema $sch"
309+ else ok "not_available [$b] $q does not answer $sch ($s, schema $g)"; fi
310+ done
311+done < "$T/na.txt"
312+check "$(get status) $(get status.json)" "501 501" "node health pages answer 501 in the store build"
313+stop
314+
315+# ---- negative controls
316+neg() { # neg NAME SED AGENTS_TSV CHECK...: build the mutant, run, the named check must fail
317+ local name=$1; shift
318+ build "$T/m-$name" "$1" "$2" || { bad "control $name: build"; return; }
319+ start "$T/m-$name" || { bad "control $name: start"; return; }
320+ get events.json > /dev/null
321+ shift 2
322+ if "$@"; then bad "control $name: the check passed on the mutant"; else ok "control $name: caught"; fi
323+ stop
324+}
325+rm -rf "$T/data/events"
326+c_star() { [ "$(awk -F'\t' '$3 == 11' "$T/data/events/log" | wc -l)" = 2 ]; }
327+neg star-any 's/^r = evridpub$/r = ulong 0/' "" c_star
328+rm -rf "$T/data/events"
329+# the mutant starts from an empty log after both landings: a branch move is only seen against a
330+# snapshot, so land once more under it first
331+c_src2() { (cd "$T/w-adfix" && echo 6 > g.txt && git add g.txt && git commit -qm six) && "$IPLD/ipl" land "$T/store" adfix main "$(git -C "$T/w-adfix" rev-parse HEAD)" "$T/w-adfix" "$T/receipt" "$T/verdict" "land-m$RANDOM" "$T/key" > /dev/null 2>&1; sleep 1; get drakestapleton/adfix.json > /dev/null; get events.json > /dev/null; [ "$(curl -s "$U/events.json?limit=200" | python3 -c 'import json,sys; print(sum(e["source"].startswith("chain.tsv:") for e in json.load(sys.stdin)["events"]))')" = 1 ]; }
332+neg no-chain 's/^rec = evchain i a$/rec = false/' "" c_src2
333+awk -F'\t' -v OFS='\t' '$3 == "{owner}/{repo}/patches" {$1 = "forge"} 1' server/agents.tsv > "$T/agents-bad.tsv"
334+c_agents() { python3 "$H/agentdoor.py" agents "$PORT" docs/API.md "$T/m-agents.agents.tsv" "$T/fixture.json" > "$T/agents-m.log" 2>&1; }
335+neg agents "" "$T/agents-bad.tsv" c_agents
336+c_moving() { mvall > "$T/mv-m.bad"; [ ! -s "$T/mv-m.bad" ]; }
337+neg moving-unmarked 's/^put fmvng 0 1$/put fmvng 0 0/' "" c_moving
338+
339+echo "store/tests/agentdoor-store.sh: $PASS passed, $FAIL failed"
340+[ "$FAIL" = 0 ]

store/tests/capacity.sh

new file mode 100755
@@ -0,0 +1,106 @@
1+#!/usr/bin/env bash
2+# ORACLE: host test driver (bash + curl + git + interplane-native ipl), not product code.
3+# store/tests/capacity.sh: the allow-list table (FAMAX rows, server/util.om) against what fills it.
4+# IPL_DIR=<interplane-native checkout with bin/ built> bash store/tests/capacity.sh [RIDS_MD [STORE]]
5+# (spark; FORGED_CPUS default 0-2 under its pool lock; CAPACITY_PORT default 19995, 19990..19999 only)
6+# 1. ALARM: the public lines of STORE/catalog.tsv (default ~/interplane-store-owner; the store build serves
7+# every public line less the deny list) must stay at or under 192 rows (three quarters of FAMAX
8+# 256). When RIDS_MD exists (default ~/handoffs/radicle/RIDS.md: the allow-list of the Radicle
9+# build, which the store build does not read), its first table gets the same alarm; when it does
10+# not exist that line says so and is not counted. Passing the alarm is not a refusal anywhere:
11+# this test fails loudly so someone grows the table before the forge has to leave projects out
12+# ("table is full" lines). The numbers are printed either way.
13+# Negative control: a catalog with 193 public lines (and private lines, which do not count) must
14+# raise the alarm; one with 192 public lines and 30 private ones must not.
15+# 2. The store build at FAMAX: a fixture store of a public project under a denied name (aien-crypto),
16+# a private project and 264 public projects. The expected served list is computed from the
17+# catalog (store/tests/expect_served.py: the first FAMAX public lines less the deny list): explore
18+# lists exactly it, its first and last project pages answer 200, the private and denied projects
19+# and every public line past the table 404, each public line past the table has its "table is
20+# full" line on stderr, the event stream's first pass reads one source per served project and the
21+# feed answers.
22+set -u
23+cd "$(dirname "$0")/../.."
24+ROOT=$(pwd)
25+RIDS=${1:-$HOME/handoffs/radicle/RIDS.md}
26+STORE=${2:-$HOME/interplane-store-owner}
27+CORES=${FORGED_CPUS:-0-2}
28+PORT=${CAPACITY_PORT:-19995}
29+case $PORT in 1999[0-9]) ;; *) echo "REFUSED: use a private port in 19990..19999"; exit 2 ;; esac
30+IPLD=${IPL_DIR:?IPL_DIR: an interplane-native checkout with bin/ built}
31+SITE=${FORGE_SITE_STORE:-$HOME/interplane-store-owner/projects/interplane.io/repo.git}
32+OMC=$HOME/work/flux/omega-mv/seed/out/omc
33+ALARM=192
34+PASS=0; FAIL=0; PID=
35+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
36+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
37+T=$(mktemp -d /tmp/forge-capacity.XXXXXX); chmod 700 "$T"
38+trap '[ -n "$PID" ] && kill "$PID" 2> /dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
39+U=http://127.0.0.1:$PORT
40+
41+rows() { awk -F '|' '/^\| repo \| RID \| default branch/ { if (seen) exit; seen=1; getline; next }
42+ seen && !/^\|/ { exit } seen { n++ } END { print n + 0 }' "$1"; }
43+pub() { awk -F'\t' '$5 == "public" { n++ } END { print n + 0 }' "$1"; }
44+alarm() { # alarm NAME COUNT: ok at or under ALARM, else the loud line
45+ if [ "$2" -le "$ALARM" ]; then ok "$1: $2 rows, at or under $ALARM (FAMAX 256)"
46+ else bad "ALARM $1: $2 rows, over $ALARM of the 256 the allow-list table holds; grow FAMAX (server/util.om) before it fills"; fi
47+}
48+alarm "public lines of $STORE/catalog.tsv" "$(pub "$STORE/catalog.tsv")"
49+if [ -f "$RIDS" ]; then
50+ alarm "Radicle-build allow-list (first table of $RIDS)" "$(rows "$RIDS")"
51+else
52+ echo "NOTE: no $RIDS (the Radicle-build allow-list); the store build does not read it"
53+fi
54+# controls on catalogs made here: private lines never count
55+fl() { printf '%s\t%064d\tmain\tnone\t%s\n' "$1" "$2" "$3"; }
56+{ for i in $(seq 193); do fl "p$i" "$i" public; done; for i in $(seq 30); do fl "q$i" "$((i + 500))" private; done; } > "$T/193.tsv"
57+{ for i in $(seq 192); do fl "p$i" "$i" public; done; for i in $(seq 30); do fl "q$i" "$((i + 500))" private; done; } > "$T/192.tsv"
58+n=$(pub "$T/193.tsv"); [ "$n" -gt "$ALARM" ] && ok "control: $n public lines (and 30 private) raise the alarm" || bad "control: $n public lines did not raise the alarm"
59+n=$(pub "$T/192.tsv"); [ "$n" -le "$ALARM" ] && ok "control: $n public lines and 30 private do not raise the alarm" || bad "control: 192 public + 30 private counted as $n"
60+
61+# ---- 2. a store of one denied, one private and 264 public projects
62+ssh-keygen -q -t ed25519 -N "" -f "$T/key" || exit 1
63+export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@invalid
64+export GIT_AUTHOR_DATE=2026-11-13T00:00:00Z GIT_COMMITTER_DATE=2026-11-13T00:00:00Z
65+git init -q -b main "$T/w" && echo x > "$T/w/a.txt" && git -C "$T/w" add a.txt && git -C "$T/w" commit -qm one || exit 1
66+mk() { # mk NAME VISIBILITY ALIAS
67+ mkdir -p "$T/store/projects/$1" && git clone -q --bare "$T/w" "$T/store/projects/$1/repo.git" || exit 1
68+ "$IPLD/ipl" init "$T/store" "$1" main "$2" "$3" "$T/key" > /dev/null 2>> "$T/ipl.err" || { bad "ipl init $1: $(tail -1 "$T/ipl.err")"; exit 1; }
69+ echo "$1" > "$T/ev"
70+ "$IPLD/ipl" import "$T/store" "$1" main "$T/ev" "$T/ev" "import-$1" "$T/key" > /dev/null 2>> "$T/ipl.err" || { bad "ipl import $1: $(tail -1 "$T/ipl.err")"; exit 1; }
71+}
72+t0=$SECONDS
73+mk aien-crypto public rad:zCapacityFixtureDeniedAbCdEf
74+mk cappriv private rad:zCapacityFixturePrivateAbCdEf
75+for i in $(seq 264); do mk "$(printf 'cap%03d' "$i")" public "$(printf 'rad:zCapacityFixture%03dAbCdEf' "$i")"; done
76+python3 store/tests/expect_served.py "$T/store" > "$T/want"
77+awk -F'\t' '$5 == "public" { n++; if (n > 256) print $1 }' "$T/store/catalog.tsv" > "$T/over"
78+W=$(grep -c . "$T/want")
79+ok "fixture store: $(wc -l < "$T/store/catalog.tsv") lines, $(pub "$T/store/catalog.tsv") public, $W expected served, $(grep -c . "$T/over") public lines past the table ($((SECONDS - t0)) s)"
80+[ "$(grep -c . "$T/over")" -gt 0 ] && [ "$W" -gt 200 ] || bad "fixture does not fill the table (expected served $W)"
81+mkdir -p "$T/data/logs" "$T/social"
82+(export FORGE_STORE=$T/store FORGE_SITE_STORE=$SITE
83+ { printf 'om2\n'; cat $(./run.sh units); }) | sed -e "s/haddr4 a 2130706433 18480/haddr4 a 2130706433 $PORT/" \
84+ -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" > "$T/f.om" || { bad "compose"; exit 1; }
85+taskset -c "$CORES" nice -n 10 "$OMC" < "$T/f.om" > "$T/forged" 2> "$T/omc.err" && chmod 755 "$T/forged" || { bad "build: $(cat "$T/omc.err")"; exit 1; }
86+FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$T/forged" 2> "$T/forged.log" &
87+PID=$!
88+for _ in $(seq 100); do curl -s -o /dev/null "$U/explore" && break; sleep 0.1; done
89+curl -s "$U/explore.json" > "$T/ex.json"
90+c=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["count"])' "$T/ex.json")
91+[ "$c" = "$W" ] && ok "explore.json count $c = expected served" || bad "explore.json count $c, want $W"
92+python3 -c 'import json,sys; print("\n".join(r["name"] for r in json.load(open(sys.argv[1]))["repos"]))' "$T/ex.json" | sort > "$T/got.s"
93+sort "$T/want" > "$T/want.s"
94+cmp -s "$T/got.s" "$T/want.s" && ok "explore lists exactly the expected served projects" || bad "explore names differ: $(diff "$T/want.s" "$T/got.s" | head -5 | tr '\n' ' ')"
95+for n in "$(head -1 "$T/want")" "$(tail -1 "$T/want")"; do s=$(curl -s -o /dev/null -w '%{http_code}' "$U/drakestapleton/$n"); [ "$s" = 200 ] && ok "$n page 200" || bad "$n page $s"; done
96+for n in cappriv aien-crypto $(head -1 "$T/over") $(tail -1 "$T/over"); do s=$(curl -s -o /dev/null -w '%{http_code}' "$U/drakestapleton/$n"); [ "$s" = 404 ] && ok "$n (not served) page 404" || bad "$n page $s"; done
97+lo=$(grep -o 'project cap[0-9]* left out (the allow-list table is full' "$T/forged.log" | cut -d' ' -f2 | sort -u)
98+[ "$lo" = "$(sort "$T/over")" ] && ok "each public line past the table left out with a 'table is full' line ($(echo $lo | tr '\n' ' '))" || bad "table-full lines: $(echo $lo) want $(sort "$T/over" | tr '\n' ' ')"
99+grep -q "project aien-crypto left out (on the deny list" "$T/forged.log" && ok "aien-crypto left out by the deny list" || bad "no deny line for aien-crypto"
100+! grep -q 'project cappriv' "$T/forged.log" && ok "the private line is skipped without a line" || bad "a line names cappriv"
101+! grep -q 'catalog refused' "$T/forged.log" && ok "no catalog refusal" || bad "catalog refused: $(grep 'catalog refused' "$T/forged.log")"
102+s=$(curl -s -o /dev/null -w '%{http_code}' "$U/events.json"); L=$(grep '^events: pass ' "$T/forged.log" | tail -1)
103+[ "$s" = 200 ] && echo "$L" | grep -q "sources read $W," && ok "events.json 200, first pass read $W sources ($L)" || bad "events.json $s, $L (want $W sources)"
104+s=$(curl -s -o /dev/null -w '%{http_code}' "$U/feed"); [ "$s" = 200 ] && ok "feed 200" || bad "feed $s"
105+echo "store/tests/capacity.sh: $PASS passed, $FAIL failed"
106+[ "$FAIL" = 0 ]

store/tests/compare-controls.sh

new file mode 100755
@@ -0,0 +1,155 @@
1+#!/usr/bin/env bash
2+# Controls for `compare.py radicle` (review-b1 finding 1). Each control builds two tiny fetch folders
3+# (MAIN and STORE, the index.tsv + body files that `compare.py fetch` writes) in a temporary folder
4+# and runs the comparator on them; nothing is fetched and no server is started.
5+# sh store/tests/compare-controls.sh [OLD_REV]
6+# The table gives the expected and observed exit of each run; the script exits 0 only when every
7+# observed exit is the expected one. OLD_REV (default babf1706) is the commit whose compare.py is run on
8+# the controls marked "old": they show what the earlier per-line presence test accepted.
9+set -u
10+D=$(cd "$(dirname "$0")" && pwd)
11+OLD_REV=${1:-babf1706080e75dff2f8dd412e0d62ecbc538d44}
12+T=$(mktemp -d)
13+trap 'rm -rf "$T"' EXIT
14+git -C "$D" show "$OLD_REV:store/tests/compare.py" > "$T/compare-old.py" || { echo "cannot read compare.py at $OLD_REV"; exit 2; }
15+
16+python3 - "$T" <<'EOF'
17+import hashlib, os, sys
18+T = sys.argv[1]
19+O = "drakestapleton"
20+RID, RID2 = "z3uek4Z9YSEAtFXmedDzEG4xvD4XR", "z44GqrPVAPjZkhoD2MWVjqy18ighN"
21+GID, GID2, GID3 = "ab" * 32, "cd" * 32, "ef" * 32
22+KEY = "SHA256:VY3HfHMNlI1gw6laxupXOx2vj2zSOOjYcQS1sC3S6t0"
23+NAV = ('<div class="forge-row"><nav class="forge-nav" aria-label="Forge"><a href="/explore">Explore</a>'
24+ '<a href="/open/">Open builds</a><a href="/research">Research</a></nav></div>')
25+FOOT_A = ('<p class="foot-fine">INTERPLANE Forge: agents express intent; the forge retains authority. Built on Radicle'
26+ ' (Heartwood): repositories are Radicle projects served by forged, a seeded-Omega web server, with no'
27+ ' JavaScript.</p>')
28+FOOT_B = ('<p class="foot-fine">INTERPLANE Forge: agents express intent; the forge retains authority. Repositories are'
29+ " plain Git kept in Interplane's own signed store, served by forged, a seeded-Omega web server, with no"
30+ ' JavaScript.</p>')
31+C = '<code translate="no">'
32+DEV_A = [
33+ "<dt>RID</dt><dd>The Radicle ID: the project's permanent name on Radicle, the open network that stores and signs"
34+ " it. This one is " + C + "rad:" + RID + "</code>.</dd>",
35+ "<dt>Delegate</dt><dd>A key that may sign the project's official versions. This forge lists the project under "
36+ + O + "; " + C + "rad inspect rad:" + RID + " --delegates</code> prints the project's own list.</dd>",
37+ "<dt>Seed</dt><dd>A Radicle node that keeps a copy of the project and serves it to others. The count below is"
38+ " read from this node's routing table.</dd>"]
39+DEV_B = [
40+ "<dt>ID</dt><dd>The project's permanent id on Interplane: the SHA-256 of its first signed record. This one is "
41+ + C + 'git:<span translate="no">' + GID + "</span></code>. Its old Radicle ID, kept only so that old links still"
42+ " work: " + C + "rad:" + RID + "</code>.</dd>",
43+ "<dt>Owner</dt><dd>The key that signs every record of the project. This forge lists the project under " + O +
44+ "; its key is " + C + KEY + "</code>.</dd>"]
45+ARCH = ('<dt>Source archive of main</dt><dd><a href="/%s/hop/archive/refs/heads/main.zip">zip</a></dd></dl></div>' % O)
46+PANEL_A = ('<div class="clone"><h3>Get this repository</h3><dl><dt>Radicle</dt><dd>' + C + "rad clone rad:" + RID +
47+ "</code></dd><dt>Git over HTTPS</dt><dd>" + C + "git clone https://www.aienos.com/rad/" + RID +
48+ ".git</code></dd>" + ARCH)
49+PANEL_B = ('<div class="clone"><h3>Get this repository</h3><dl><dt>Git over HTTPS</dt><dd>' + C +
50+ "git clone https://interplane.io/projects/hop/repo.git</code></dd>" + ARCH)
51+CONTRIB = ('<p class="meta">One command for agents: ' + C + "forge-contribute " + RID +
52+ " DIR BRANCH</code> opens a Radicle patch.</p>")
53+
54+
55+def item(rid, tags="[]", name="hop"):
56+ return ('{"owner":"%s","name":"%s","rid":"%s","path":"/%s/%s","tags":%s,"default_branch":"main"}'
57+ % (O, name, rid, O, name, tags))
58+
59+
60+def repo_json(rid, store):
61+ clone = ('"clone":{"rad":null,"rad_clone":null,"git_https":"https://interplane.io/projects/hop/repo.git"}'
62+ if store else '"clone":{"rad":"rad:%s","rad_clone":"rad clone rad:%s","git_https":'
63+ '"https://www.aienos.com/rad/%s.git"}' % (RID, RID, RID))
64+ return "{\n" + item(rid)[1:-1] + ",\n" + clone + "\n}\n"
65+
66+
67+def html(*lines):
68+ return "\n".join(["<!doctype html>", "<html><body>", *lines, "</body></html>", ""])
69+
70+
71+def pages(store):
72+ rid = "git:" + GID if store else "rad:" + RID
73+ rid2 = "git:" + GID2 if store else "rad:" + RID2
74+ return { # (path, kind): (status, content type, body)
75+ ("/", "html"): (200, "text/html; charset=utf-8",
76+ html(NAV.replace('<a href="/open/">Open builds</a>', "") if store else NAV, "<p>Home</p>",
77+ FOOT_B if store else FOOT_A)),
78+ ("/", "json"): (200, "application/json", "[\n" + item(rid) + ",\n" + item(rid2, name="core") + "\n]\n"),
79+ ("/%s/hop" % O, "html"): (200, "text/html; charset=utf-8",
80+ html(*(DEV_B if store else DEV_A), PANEL_B if store else PANEL_A, "<p>same</p>")),
81+ ("/%s/hop" % O, "json"): (200, "application/json", repo_json(rid, store)),
82+ ("/%s/hop/tags/1" % O, "json"): (200, "application/json",
83+ '{"schema":"forge/tags/1","repo":' + item(rid) + ',"count":0}\n'),
84+ ("/%s/hop/archive/refs/heads/main.zip" % O, "html"): (200, "application/zip", "PK\x03\x04 same bytes"),
85+ ("/%s/hop/raw/main/README.md" % O, "html"): (200, "text/plain; charset=utf-8", "readme\n"),
86+ }
87+
88+
89+def mutate(control, p):
90+ k = ("/%s/hop/tags/1" % O, "json")
91+ if control == "b": # a non-id JSON field changed, on a one-line body that also holds an id
92+ st, ct, body = p[k]
93+ p[k] = (st, ct, body.replace('"tags":[]', '"tags":["v1","v2","v3"]'))
94+ elif control == "c": # status differs
95+ p[k] = (404, p[k][1], p[k][2])
96+ elif control == "d": # a binary page differs
97+ z = ("/%s/hop/archive/refs/heads/main.zip" % O, "html")
98+ p[z] = (p[z][0], p[z][1], "PK\x03\x04 other bytes")
99+ elif control == "e": # footer replaced by other text that carries a store id
100+ h = ("/", "html")
101+ p[h] = (p[h][0], p[h][1], p[h][2].replace(FOOT_B, "<p>Nothing to see; git:" + GID3 + "</p>"))
102+ elif control == "f": # one Radicle id given two different store ids on two pages
103+ j = ("/", "json")
104+ p[j] = (p[j][0], p[j][1], p[j][2].replace("git:" + GID, "git:" + GID3, 1))
105+ elif control == "g": # the clone panel names another project's repository
106+ h = ("/%s/hop" % O, "html")
107+ p[h] = (p[h][0], p[h][1], p[h][2].replace("projects/hop/repo.git", "projects/other/repo.git"))
108+ elif control == "h": # a MAIN-only Radicle line with no STORE counterpart (the kept run's agent line)
109+ return "main-extra"
110+ return None
111+
112+
113+def write(d, p):
114+ os.makedirs(d)
115+ idx = []
116+ for (path, kind), (st, ct, body) in p.items():
117+ b = body.encode("utf-8")
118+ name = hashlib.sha256((kind + " " + path).encode()).hexdigest()[:32]
119+ open(os.path.join(d, name), "wb").write(b)
120+ idx.append("\t".join([name, kind, path, str(st), ct, "", str(len(b)), hashlib.sha256(b).hexdigest()]))
121+ open(os.path.join(d, "index.tsv"), "w", encoding="utf-8").write("\n".join(idx) + "\n")
122+
123+
124+for control in "abcdefgh":
125+ main, store = pages(False), pages(True)
126+ if mutate(control, store) == "main-extra":
127+ h = ("/%s/hop" % O, "html")
128+ main[h] = (main[h][0], main[h][1], main[h][2].replace("<p>same</p>", CONTRIB + "\n<p>same</p>"))
129+ write(os.path.join(T, control, "main"), main)
130+ write(os.path.join(T, control, "store"), store)
131+EOF
132+[ -d "$T/h/store" ] || { echo "fixtures not written"; exit 2; }
133+
134+fail=0
135+printf '%-8s %-5s %-70s %-8s %s\n' control code what expected observed
136+run() { # run CONTROL CODE EXPECTED WHAT
137+ if [ "$2" = old ]; then py="$T/compare-old.py"; else py="$D/compare.py"; fi
138+ python3 "$py" radicle "$T/$1/main" "$T/$1/store" > "$T/$1.$2.out" 2>&1
139+ got=$?
140+ [ "$got" = "$3" ] || fail=1
141+ printf '%-8s %-5s %-70s %-8s %s%s\n' "$1" "$2" "$4" "$3" "$got" "$([ "$got" = "$3" ] || echo ' MISMATCH')"
142+ { grep -m3 '^BAD' "$T/$1.$2.out"; tail -1 "$T/$1.$2.out"; } | cut -c1-200 | sed 's/^/ /'
143+}
144+run a new 0 "identical apart from id forms and the listed rules"
145+run b new 1 'tags [] vs three tags in a one-line JSON body with an id'
146+run b old 0 "same, earlier presence test (the defect: it passes)"
147+run c new 1 "status 200 vs 404"
148+run d new 1 "binary (application/zip) page bytes differ"
149+run e new 1 "footer replaced by other text carrying git:<hex>"
150+run e old 0 "same, earlier presence test"
151+run f new 1 "one Radicle id mapped to two store ids"
152+run g new 1 "clone panel names another project's repository"
153+run h new 1 "MAIN-only Radicle agent line, no STORE counterpart"
154+[ "$fail" = 0 ] && echo "controls: all exits as expected" || echo "controls: MISMATCH"
155+exit "$fail"

store/tests/compare.py

new file mode 100755
@@ -0,0 +1,488 @@
1+#!/usr/bin/env python3
2+# ORACLE: host test helper for store/tests/compare.sh (outside tool, not product code).
3+# sample CATALOG PROJECTS FIXTURE the sampled project names, one per line (rule in compare.sh)
4+# fetch PORT DIR LISTFILE every page of LISTFILE; HTML-like pages also with the JSON Accept
5+# key PATH KIND the file name fetch gives PATH (KIND html or json)
6+# same A B every page of fetch dir A equals B (status, type, bytes)
7+# radicle A B B equals A apart from the rules listed in RULES: the Radicle id
8+# replaced by the store id, the forge-nav row without "Open builds"
9+# (server/noopen.om ohnav), the footer, the developer rows, the
10+# clone panel and the JSON clone object. A STORE line must be
11+# exactly what its rule makes of the MAIN line; any other difference
12+# is printed as BAD with its page and line, and the exit is 1
13+# replay LISTING the same rules over a kept `radicle` listing, offline (no pages)
14+# manylines CATALOG N N well-formed public lines (names many-NNN)
15+# signin PORT KEY / star PORT SESSION REPO / stars PORT REPO social helpers (forge sign-in)
16+# env (radicle, replay): COMPARE_FIXTURES, the names of the fixture projects compare.sh signs with its
17+# KEY (space-separated), and COMPARE_FIXTURE_KEY, the SHA256 fingerprint of that key. The owner key of a
18+# fixture page must be exactly COMPARE_FIXTURE_KEY, and fixtures keep their own one-to-one table
19+# ("owner key of fixtures"): KEY need not be the store's owner key (the store's own projects keep the
20+# "owner key" table, one key for the owner name over all of them).
21+import base64, difflib, hashlib, http.client, json, os, re, subprocess, sys, urllib.parse
22+
23+OWNER = "drakestapleton"
24+JSON = "application/json"
25+SEAM = '<a href="/open/">Open builds</a>'
26+PLAIN = re.compile(r"/(raw|archive)/|\.(patch|diff|json)$|\.json\?")
27+FIXTURES = set(os.environ.get("COMPARE_FIXTURES", "").split())
28+FIXKEY = os.environ.get("COMPARE_FIXTURE_KEY", "")
29+
30+
31+def owner_pair(name, delegate, fp):
32+ # the owner-key pair of a page: fixtures are signed with compare.sh's KEY, which must be exactly
33+ # COMPARE_FIXTURE_KEY; the store's own projects pair the owner name with one key over the run
34+ if name in FIXTURES:
35+ return ("owner key of fixtures", delegate, fp) if fp == FIXKEY else None
36+ return ("owner key", delegate, fp)
37+
38+
39+def key(path, kind):
40+ return hashlib.sha256((kind + " " + path).encode()).hexdigest()[:32]
41+
42+
43+def get(port, path, headers=None):
44+ c = http.client.HTTPConnection("127.0.0.1", port, timeout=900)
45+ c.request("GET", path, headers=headers or {})
46+ r = c.getresponse()
47+ body = r.read()
48+ out = (r.status, r.getheader("Content-Type", ""), r.getheader("Location", ""), body, r.getheaders())
49+ c.close()
50+ return out
51+
52+
53+def fetch(port, d, listfile):
54+ paths = [l.rstrip("\n") for l in open(listfile, encoding="utf-8") if l.strip()]
55+ idx = []
56+ for p in paths:
57+ kinds = ["html"] if PLAIN.search(p) else ["html", "json"]
58+ for k in kinds:
59+ st, ct, loc, body, _ = get(port, p, {"Accept": JSON} if k == "json" else {})
60+ name = key(p, k)
61+ open(os.path.join(d, name), "wb").write(body)
62+ idx.append("\t".join([name, k, p, str(st), ct, loc.replace(str(port), "PORT"), str(len(body)),
63+ hashlib.sha256(body).hexdigest()]))
64+ open(os.path.join(d, "index.tsv"), "w", encoding="utf-8").write("\n".join(idx) + "\n")
65+
66+
67+def index(d):
68+ rows = {}
69+ for l in open(os.path.join(d, "index.tsv"), encoding="utf-8"):
70+ f = l.rstrip("\n").split("\t")
71+ rows[f[0]] = f
72+ return rows
73+
74+
75+def same(a, b):
76+ A, B = index(a), index(b)
77+ bad = 0
78+ for k, ra in A.items():
79+ rb = B.get(k)
80+ if rb is None or ra[3:] != rb[3:]:
81+ bad += 1
82+ print("DIFFER %s %s: %s / %s" % (ra[1], ra[2], ra[3:7], rb[3:7] if rb else None))
83+ print("pages=%d identical=%d differ=%d" % (len(A), len(A) - bad, bad))
84+ return 1 if bad or len(A) != len(B) else 0
85+
86+
87+# radicle A B: the only differences STORE may show against MAIN. Every rule is a form that the kept
88+# listing of the run at babf1706 shows (differing-lines-babf1706080e75dff2f8dd412e0d62ecbc538d44.txt),
89+# and a STORE line is accepted only when it is exactly what the rule makes of the MAIN line or lines
90+# it replaces. No line passes for merely naming an id. A rule gets the MAIN lines, the STORE lines and
91+# the project name of the page; it returns None, or the (table, MAIN value, STORE value) pairs that
92+# must stay one to one over the whole run (a Radicle id and its store id, an owner and its key).
93+# ids: rad:z... (the Radicle build before the Radicle-text removal), a bare z... in a "rid" value (after it,
94+# c1f107df: the old id without its prefix), git:<64 hex> (the store build)
95+IDS = re.compile(r'rad:z[0-9A-Za-z]+|git:[0-9a-f]{64}|(?<="rid":")z[0-9A-Za-z]+')
96+RIDF = r'((?:<span translate="no">)?z[0-9A-Za-z]+(?:</span>)?)' # a Radicle id as an HTML page prints it
97+CODE = '<code translate="no">'
98+FOOT = ('<p class="foot-fine">INTERPLANE Forge: agents express intent; the forge retains authority. %s'
99+ " served by forged, a seeded-Omega web server, with no JavaScript.</p>")
100+FOOT_A = FOOT % "Built on Radicle (Heartwood): repositories are Radicle projects"
101+FOOT_A2 = FOOT % "Repositories are" # the footer after the Radicle-text removal (c1f107df)
102+FOOT_B = FOOT % "Repositories are plain Git kept in Interplane's own signed store,"
103+PATCH = "<dt>Patch</dt><dd>A proposed change, %s The list is under "
104+PATCH_A = PATCH % "sent over Radicle and reviewed before it is merged."
105+PATCH_B = PATCH % "reviewed before it is merged. This forge does not show proposed changes from its own store yet."
106+PANEL = '<div class="clone"><h3>Get this repository</h3><dl>'
107+PANEL_A = re.compile(PANEL + "<dt>Radicle</dt><dd>" + CODE + "rad clone rad:" + RIDF + "</code></dd>"
108+ "(<dt>Git over HTTPS</dt><dd>" + CODE + r"git clone )https://www\.aienos\.com/rad/\1\.git"
109+ "(</code></dd><dt>Source archive of .*)", re.S)
110+OBJECT_A = re.compile(r'"clone":\{"rad":"rad:(z[0-9A-Za-z]+)","rad_clone":"rad clone rad:\1",'
111+ r'"git_https":"https://www\.aienos\.com/rad/\1\.git"(.*)', re.S)
112+STORE_GIT = "https://interplane.io/projects/%s/repo.git"
113+DEV_RID = re.compile(r"<dt>RID</dt><dd>The Radicle ID: the project's permanent name on Radicle, the open network"
114+ r" that stores and signs it\. This one is " + CODE + "rad:" + RIDF + r"</code>\.</dd>")
115+DEV_DELEGATE = re.compile(r"<dt>Delegate</dt><dd>A key that may sign the project's official versions\. This forge"
116+ r" lists the project under ([^;<]+); " + CODE + "rad inspect rad:" + RIDF +
117+ r" --delegates</code> prints the project's own list\.</dd>")
118+DEV_SEED = ("<dt>Seed</dt><dd>A Radicle node that keeps a copy of the project and serves it to others. The count"
119+ " below is read from this node's routing table.</dd>")
120+DEV_ID = (r"<dt>ID</dt><dd>The project's permanent id on Interplane: the SHA-256 of its first signed record\."
121+ " This one is " + CODE + r'git:<span translate="no">([0-9a-f]{64})</span></code>\. Its old Radicle ID,'
122+ " kept only so that old links still work: " + CODE + r"rad:%s</code>\.</dd>")
123+DEV_OWNER = (r"<dt>Owner</dt><dd>The key that signs every record of the project\. This forge lists the project"
124+ " under %s; its key is " + CODE + r"(SHA256:[A-Za-z0-9+/]{43})</code>\.</dd>")
125+
126+
127+def project(path):
128+ f = path.split("?")[0].split("/")
129+ n = f[2] if len(f) > 2 else ""
130+ return n[:-5] if len(f) == 3 and n.endswith(".json") else n
131+
132+
133+def r_ids(a, b, name):
134+ # the same line with a Radicle id where STORE has the store id; ids equal on both sides stay as they are
135+ if IDS.split(a[0]) != IDS.split(b[0]):
136+ return None
137+ d = [(x, y) for x, y in zip(IDS.findall(a[0]), IDS.findall(b[0])) if x != y]
138+ if not d or not all(x.startswith(("rad:", "z")) and y.startswith("git:") for x, y in d):
139+ return None
140+ # a bare old id (MAIN after c1f107df) is the same id as rad:<it>: one name for the one-to-one check
141+ return [("id", x if x.startswith("rad:") else "rad:" + x, y) for x, y in d]
142+
143+
144+def r_nav(a, b, name):
145+ return [] if SEAM in a[0] and '<nav class="forge-nav"' in a[0] and a[0].replace(SEAM, "") == b[0] else None
146+
147+
148+def r_footer(a, b, name):
149+ return [] if a[0] in (FOOT_A, FOOT_A2) and b[0] == FOOT_B else None
150+
151+
152+def r_patch(a, b, name):
153+ return [] if a[0].startswith(PATCH_A) and b[0] == PATCH_B + a[0][len(PATCH_A):] else None
154+
155+
156+def r_panel(a, b, name):
157+ m = PANEL_A.fullmatch(a[0])
158+ return [] if m and name and b[0] == PANEL + m.group(2) + STORE_GIT % name + m.group(3) else None
159+
160+
161+def r_object(a, b, name):
162+ m = OBJECT_A.fullmatch(a[0])
163+ want = '"clone":{"rad":null,"rad_clone":null,"git_https":"' + STORE_GIT % name + '"'
164+ return [] if m and name and b[0] == want + m.group(2) else None
165+
166+
167+def r_dev(a, b, name):
168+ # RID, Delegate and Seed rows of MAIN; ID and Owner rows of STORE, naming the same Radicle id and owner
169+ r, d = DEV_RID.fullmatch(a[0]), DEV_DELEGATE.fullmatch(a[1])
170+ if not r or not d or d.group(2) != r.group(1) or a[2] != DEV_SEED:
171+ return None
172+ i = re.fullmatch(DEV_ID % re.escape(r.group(1)), b[0])
173+ o = re.fullmatch(DEV_OWNER % re.escape(d.group(1)), b[1])
174+ p = owner_pair(name, d.group(1), o.group(1)) if i and o else None
175+ if not p:
176+ return None
177+ return [("id", "rad:" + re.sub(r"</?span[^>]*>", "", r.group(1)), "git:" + i.group(1)), p]
178+
179+
180+# ---- the forms of MAIN after the Radicle-text removal (c1f107df, merged as restore-rad-free 9a4420ab):
181+# MAIN no longer names Radicle, so its lines that the store build replaces are these instead.
182+DEV_DELEGATE2 = re.compile(r"<dt>Delegate</dt><dd>A key that may sign the project's official versions\. This forge"
183+ r" lists the project under ([^;<.]+)\.</dd>")
184+DEV_ID2 = re.compile(r"<dt>ID</dt><dd>The project's permanent id on Interplane: the SHA-256 of its first signed record\."
185+ " This one is " + CODE + r'git:<span translate="no">([0-9a-f]{64})</span></code>\. Its old id, kept'
186+ " only so that old links still work: " + CODE + r'(?:<span translate="no">)?(z[0-9A-Za-z]+)(?:</span>)?</code>\.</dd>')
187+PATCH_A2 = PATCH % "stored in the repository and reviewed before it is merged."
188+SEED_A2 = '<p class="meta">Seeding: <b>not measured</b> (the source of this count is retired)</p>'
189+PANEL_A2 = re.compile(re.escape(PANEL[:-4]) + r'<p class="meta">No public Git URL yet: Interplane does not serve Git'
190+ r' clones yet\.</p><dl>(<dt>Source archive of .*)', re.S)
191+AGENT_A2 = '<p class="meta">For agents: ' + CODE + "forge-contribute "
192+OBJECT_A2 = re.compile(r'"clone":\{"rad":"(z[0-9A-Za-z]+)","rad_clone":null,"git_https":null\}(.*)', re.S)
193+
194+
195+def r_dev2(a, b, name):
196+ # the Delegate row of MAIN; the ID and Owner rows of STORE, naming the same owner
197+ d = DEV_DELEGATE2.fullmatch(a[0])
198+ i = DEV_ID2.fullmatch(b[0])
199+ if not d or not i:
200+ return None
201+ o = re.fullmatch(DEV_OWNER % re.escape(d.group(1)), b[1])
202+ p = owner_pair(name, d.group(1), o.group(1)) if o else None
203+ if not p:
204+ return None
205+ return [("id", "rad:" + i.group(2), "git:" + i.group(1)), p]
206+
207+
208+def r_patch2(a, b, name):
209+ return [] if a[0].startswith(PATCH_A2) and b[0] == PATCH_B + a[0][len(PATCH_A2):] else None
210+
211+
212+def r_seed2(a, b, name):
213+ # the seeding line of MAIN (its source, the node's routing table, is retired); the store build has none
214+ return [] if a[0] == SEED_A2 else None
215+
216+
217+def r_panel2(a, b, name):
218+ # MAIN's panel without a Git URL and its closed agent line; STORE's panel with the store's HTTPS URL
219+ m = PANEL_A2.fullmatch(a[0])
220+ if not m or not name or not a[1].startswith(AGENT_A2):
221+ return None
222+ want = PANEL + "<dt>Git over HTTPS</dt><dd>" + CODE + "git clone " + STORE_GIT % name + "</code></dd>" + m.group(1)
223+ return [] if b[0] == want else None
224+
225+
226+def r_object2(a, b, name):
227+ m = OBJECT_A2.fullmatch(a[0])
228+ want = '"clone":{"rad":null,"rad_clone":null,"git_https":"' + STORE_GIT % name + '"}'
229+ return [] if m and name and b[0] == want + m.group(2) else None
230+
231+
232+RULES = (("dev-rows", 3, 2, r_dev), ("nav", 1, 1, r_nav), ("footer", 1, 1, r_footer), ("dev-patch-row", 1, 1, r_patch),
233+ ("clone-panel", 1, 1, r_panel), ("clone-object", 1, 1, r_object),
234+ ("dev-rows-2", 1, 2, r_dev2), ("dev-patch-row-2", 1, 1, r_patch2), ("seeding-2", 1, 0, r_seed2),
235+ ("clone-panel-2", 2, 1, r_panel2), ("clone-object-2", 1, 1, r_object2), ("id", 1, 1, r_ids))
236+
237+
238+def state():
239+ return {"n": dict.fromkeys([r[0] for r in RULES], 0), "pairs": {}}
240+
241+
242+def clash(st, pairs, where):
243+ # a value paired with one value here and another elsewhere is a difference, not a form
244+ for t, x, y in pairs:
245+ for side, p, q in ((t + " of MAIN", x, y), (t + " of STORE", y, x)):
246+ seen = st["pairs"].get((side, p))
247+ if seen and seen[0] != q:
248+ return "%s %s goes with %s here and with %s at %s" % (side, p, q, seen[0], seen[1])
249+ for t, x, y in pairs:
250+ st["pairs"].setdefault((t + " of MAIN", x), (y, where))
251+ st["pairs"].setdefault((t + " of STORE", y), (x, where))
252+ return None
253+
254+
255+def block(where, path, rem, add, st):
256+ # rem, add: the (number, line) lists of one differing block of MAIN and of STORE. One
257+ # (sign, number, rule, line, reason) comes back per line; rule None is a line that nothing accepts.
258+ out, i, j, name = [], 0, 0, project(path)
259+ while i < len(rem) or j < len(add):
260+ hit = why = None
261+ for cls, n, m, rule in RULES:
262+ if len(rem) - i < n or len(add) - j < m:
263+ continue
264+ pairs = rule([l for _, l in rem[i:i + n]], [l for _, l in add[j:j + m]], name)
265+ if pairs is None:
266+ continue
267+ why = clash(st, pairs, "%s line %d" % (where, rem[i][0]))
268+ hit = None if why else (cls, n, m)
269+ break
270+ if hit:
271+ cls, n, m = hit
272+ st["n"][cls] += 1
273+ out += [("-", k, cls, l, None) for k, l in rem[i:i + n]]
274+ out += [("+", k, cls, l, None) for k, l in add[j:j + m]]
275+ i, j = i + n, j + m
276+ elif i < len(rem):
277+ out.append(("-", rem[i][0], None, rem[i][1], why or "no listed rule gives this MAIN line a STORE line"))
278+ i += 1
279+ else:
280+ out.append(("+", add[j][0], None, add[j][1], why or "no listed rule produces this STORE line"))
281+ j += 1
282+ return out
283+
284+
285+def tally(st):
286+ return " ".join("%s=%d" % (r[0], st["n"][r[0]]) for r in RULES)
287+
288+
289+def radicle(a, b):
290+ A, B = index(a), index(b)
291+ st = state()
292+ bad = ok = fine = 0
293+ for k, ra in A.items():
294+ rb = B.get(k)
295+ where = "%s %s" % (ra[1], ra[2])
296+ if rb is None:
297+ bad += 1
298+ print("BAD page missing from STORE %s" % where)
299+ continue
300+ if ra[3:6] != rb[3:6]:
301+ bad += 1
302+ print("BAD status/type/location %s: %s / %s" % (where, ra[3:6], rb[3:6]))
303+ continue
304+ if ra[7] == rb[7]:
305+ ok += 1
306+ continue
307+ ba = open(os.path.join(a, k), "rb").read()
308+ bb = open(os.path.join(b, k), "rb").read()
309+ if not (ra[4].startswith("text/html") or ra[4].startswith(JSON)):
310+ bad += 1
311+ print("BAD bytes differ in a non-text page %s (%s)" % (where, ra[4]))
312+ continue
313+ la = ba.decode("utf-8", "replace").split("\n")
314+ lb = bb.decode("utf-8", "replace").split("\n")
315+ print("DIFF %s" % where)
316+ refused = 0
317+ for op, i1, i2, j1, j2 in difflib.SequenceMatcher(None, la, lb, autojunk=False).get_opcodes():
318+ if op == "equal":
319+ continue
320+ rem, add = list(enumerate(la[i1:i2], i1 + 1)), list(enumerate(lb[j1:j2], j1 + 1))
321+ for sign, num, cls, l, why in block(where, ra[2], rem, add, st):
322+ print(" %s [%s] %s" % (sign, cls or "NOT ACCEPTED", l))
323+ if not cls:
324+ refused += 1
325+ print("BAD %s line %d of %s: %s" % (where, num, "MAIN" if sign == "-" else "STORE", why))
326+ if refused:
327+ bad += 1
328+ else:
329+ fine += 1
330+ for k, rb in B.items():
331+ if k not in A:
332+ bad += 1
333+ print("BAD page only in STORE %s %s" % (rb[1], rb[2]))
334+ print("pages=%d identical=%d differing-by-listed-rules-only=%d bad=%d %s" % (len(A), ok, fine, bad, tally(st)))
335+ return 1 if bad or len(A) != len(B) else 0
336+
337+
338+def replay(listing):
339+ # The rules over a kept `radicle` listing in the format of the run at babf1706: a "DIFF kind path"
340+ # line per page, then " - " MAIN lines and " + " STORE lines, with "[SEAM open] " before a nav
341+ # pair. A MAIN line after STORE lines starts the next block. Line numbers are the listing's. Status,
342+ # type, location, non-text bytes and the identical pages are not in a listing, so they are not replayed.
343+ st = state()
344+ blocks, other, nmain, nstore = [], [], 0, 0
345+ for n, l in enumerate(open(listing, encoding="utf-8", newline="").read().split("\n"), 1):
346+ if l.startswith("DIFF "):
347+ blocks.append((l[5:], True, [], []))
348+ elif l[:4] in (" - ", " + ") and blocks:
349+ t = l[4:]
350+ t = t[12:] if t.startswith("[SEAM open] ") else t
351+ if l[2] == "-" and blocks[-1][3]:
352+ blocks.append((blocks[-1][0], False, [], []))
353+ blocks[-1][2 if l[2] == "-" else 3].append((n, t))
354+ nmain, nstore = nmain + (l[2] == "-"), nstore + (l[2] == "+")
355+ elif l and not l.startswith("pages="):
356+ other.append(n)
357+ pages, badpages, refused = 0, set(), 0
358+ for where, first, rem, add in blocks:
359+ pages += first
360+ for sign, num, cls, l, why in block(where, where.split(" ", 1)[1], rem, add, st):
361+ if not cls:
362+ refused += 1
363+ badpages.add(pages)
364+ print("REFUSED listing line %d (%s of %s): %s: %s" % (num, "MAIN" if sign == "-" else "STORE", where,
365+ why, l[:160]))
366+ badpages = len(badpages)
367+ for n in other:
368+ print("UNREAD listing line %d" % n)
369+ print("replay: differing-pages=%d accepted=%d refused=%d lines-main=%d lines-store=%d lines-refused=%d "
370+ "unread-lines=%d %s" % (pages, pages - badpages, badpages, nmain, nstore, refused, len(other), tally(st)))
371+ return 1 if refused or other else 0
372+
373+
374+def sample(catalog, projects, fixture):
375+ names = [l.split("\t")[0] for l in open(catalog, encoding="utf-8") if l.strip()]
376+ others = [n for n in names if n != fixture]
377+
378+ def size(n):
379+ t = 0
380+ for r, _, fs in os.walk(os.path.join(projects, n, "repo.git")):
381+ for f in fs:
382+ t += os.lstat(os.path.join(r, f)).st_size
383+ return t
384+ largest = max(others, key=size)
385+ rest = sorted([n for n in others if n != largest], key=lambda n: hashlib.sha256(n.encode()).hexdigest())
386+ for n in [largest, fixture] + rest[:9]:
387+ print(n)
388+
389+
390+def manylines(catalog, n):
391+ first = open(catalog, encoding="utf-8").readline()
392+ for i in range(int(n)):
393+ nm = "many-%03d" % i
394+ print("\t".join([nm, hashlib.sha256(nm.encode()).hexdigest(), "main", "none", "public"]))
395+
396+
397+def did(pub):
398+ blob = base64.b64decode(open(pub).read().split()[1])
399+ raw = b"\xed\x01" + blob[-32:]
400+ alpha = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
401+ v = int.from_bytes(raw, "big")
402+ s = ""
403+ while v:
404+ v, r = divmod(v, 58)
405+ s = alpha[r] + s
406+ return "did:key:z" + s
407+
408+
409+def field(body, name):
410+ m = re.search(r'name="%s" value="([^"]*)"' % name, body)
411+ return m.group(1) if m else ""
412+
413+
414+def cookie(headers, suffix):
415+ for h, v in headers:
416+ if h.lower() == "set-cookie":
417+ m = re.match(r"([A-Za-z_-]*%s)=([0-9a-f]*);" % suffix, v)
418+ if m:
419+ return m.group(1), m.group(2)
420+ return None, None
421+
422+
423+def post(port, path, form, hdr):
424+ c = http.client.HTTPConnection("127.0.0.1", port, timeout=60)
425+ h = {"Content-Type": "application/x-www-form-urlencoded"}
426+ h.update(hdr)
427+ c.request("POST", path, urllib.parse.urlencode(form), h)
428+ r = c.getresponse()
429+ r.read()
430+ out = (r.status, r.getheaders())
431+ c.close()
432+ return out
433+
434+
435+def signin(port, keyf):
436+ st, _, _, body, hs = get(port, "/login")
437+ body = body.decode()
438+ pn, pre = cookie(hs, "forge_pre")
439+ nonce, ts, csrf = field(body, "nonce"), field(body, "ts"), field(body, "csrf")
440+ sig = subprocess.run(["ssh-keygen", "-Y", "sign", "-f", keyf, "-n", "interplane-forge"],
441+ input=("interplane-forge-login:%s:%s" % (nonce, ts)).encode(),
442+ capture_output=True).stdout.decode()
443+ st, hs = post(port, "/login", {"csrf": csrf, "nonce": nonce, "ts": ts, "did": did(keyf + ".pub"), "sig": sig},
444+ {"Cookie": "%s=%s" % (pn, pre)})
445+ sn, ses = cookie(hs, "forge_session")
446+ print("%s=%s" % (sn, ses) if st == 303 and ses else "SIGNIN-FAILED %d" % st)
447+
448+
449+def star(port, ses, repo):
450+ st, _, _, body, _ = get(port, "/settings", {"Cookie": ses})
451+ csrf = field(body.decode(), "csrf")
452+ st, _ = post(port, "/%s/%s/star" % (OWNER, repo), {"csrf": csrf}, {"Cookie": ses})
453+ print(st)
454+
455+
456+def stars(port, repo):
457+ st, _, _, body, _ = get(port, "/%s/%s/stargazers" % (OWNER, repo), {"Accept": JSON})
458+ print(json.loads(body)["count"] if st == 200 else "status-%d" % st)
459+
460+
461+def main():
462+ c, a = sys.argv[1], sys.argv[2:]
463+ if c == "sample":
464+ sample(*a)
465+ elif c == "fetch":
466+ fetch(int(a[0]), a[1], a[2])
467+ elif c == "key":
468+ print(key(a[0], a[1]))
469+ elif c == "same":
470+ sys.exit(same(*a))
471+ elif c == "radicle":
472+ sys.exit(radicle(*a))
473+ elif c == "replay":
474+ sys.exit(replay(*a))
475+ elif c == "manylines":
476+ manylines(*a)
477+ elif c == "signin":
478+ signin(int(a[0]), a[1])
479+ elif c == "star":
480+ star(int(a[0]), a[1], a[2])
481+ elif c == "stars":
482+ stars(int(a[0]), a[1])
483+ else:
484+ sys.exit("compare.py: unknown command " + c)
485+
486+
487+if __name__ == "__main__":
488+ main()

store/tests/compare.sh

new file mode 100755
@@ -0,0 +1,588 @@
1+#!/usr/bin/env bash
2+# ORACLE: host test driver (bash, curl, git, bwrap, python3 store/tests/compare.py), not product code.
3+# store/tests/compare.sh: the store-reading build of this tree against main's binary reading Radicle
4+# storage (interplane-native DESIGN.md step 2 acceptance), with the negative controls and mutants.
5+# bash store/tests/compare.sh STORE KEY IPL_DIR
6+# STORE a trial store root made by interplane-native's tools/import-radicle.sh (read only:
7+# its project folders are hard-linked into a private test root, never written)
8+# KEY a key to sign the fixture projects with (any Ed25519 key; it need not be the store's
9+# owner; read only, the fixtures stay in the test root). compare.py pairs the owner name with
10+# one key over the store's own projects, and requires every fixture page to name exactly
11+# KEY's fingerprint (COMPARE_FIXTURES, COMPARE_FIXTURE_KEY)
12+# env COMPARE_RSTORE: the Radicle storage MAIN and DEF read (default ~/radicle-storage-frozen/storage,
13+# the read-only copy kept after the Radicle removal of 2026-11-14; ~/.radicle no longer exists), and
14+# the site chrome comes from its interplane.io repository (FORGE_SITE_STORE) for every build.
15+# The STORE builds serve every public line of the test root's catalog less the deny list (Drake,
16+# 2026-11-14: no served list), so a project without an old id (no-alias) is served under its git:<id>
17+# (C8) and can be starred (C9).
18+# IPL_DIR a checkout of interplane-native at 7db470da with bin/ built (its ipl makes the fixtures)
19+# env: FORGED_CPUS (default 4,5), STORE_TEST_PORT (default 18610; uses PORT..PORT+5),
20+# FORGE_MAIN_COMMIT (default 4ed98366d73a435e1f8477da6902b3f6411bdba4), KEEP=1 keeps $T.
21+# Builds, all from the pinned omc and one chrome unit:
22+# MAIN main at FORGE_MAIN_COMMIT, default units: reads Radicle storage (the current binary)
23+# DEF this tree, default units (no FORGE_STORE): must answer byte for byte as MAIN
24+# STORE this tree, FORGE_STORE=<test root>, FORGE_CLONE_BASE=https://interplane.io/
25+# STORE0 the same without FORGE_CLONE_BASE (the clone panel without an HTTPS line)
26+# TWIN this tree, default units reading the REAL ~/.radicle/storage and RIDS.md (port and data
27+# only redirected): run in the same sandbox as STORE, it must list no repository, which
28+# shows that sandbox has no Radicle storage
29+# MAIN and DEF read the first table of ~/handoffs/radicle/RIDS.md (less the projects the store does
30+# not hold) through symlinks into the real storage, as server/tests/jsonpages.sh does, plus the
31+# fixtures as bare repositories under made-up RIDs. STORE and STORE0 run under bwrap with tmpfs over
32+# ~/.radicle and ~/handoffs/radicle, so Radicle storage is absent from their file system.
33+# Sample rule (at least ten projects): the largest repo.git (du) of the compared projects, the fixture
34+# "slice-b-fixture" (tags, an annotated tag, and paths with non-ASCII bytes; the store's own tags are
35+# only under refs/namespaces/<id>/refs/tags, e.g. Hop v0.2.0..v0.5.0, counted below; the fixture is
36+# the tag coverage of this gate), then the rest in order
37+# of sha256(name) until there are eleven. Pages per sampled project: repo home, tree (root and the
38+# first folder), blob (README or the first file, a nested file, the fixture's non-ASCII files), raw,
39+# blame, commits (default and by branch), commit (head, .patch, .diff), compare (parent...head and
40+# the bare form), branches, tags, archives (zip and tar.gz of the default branch, and of a tag for
41+# the fixture), each HTML page also with Accept: application/json; plus /, /explore, /explore.json.
42+# Every page pair MAIN/STORE must be byte-identical apart from lines that name Radicle in MAIN and
43+# their replacements in STORE (store/tests/compare.py lists every such line); MAIN/DEF must be
44+# byte-identical on every page, plus the patch, issue, release, profile, search and status pages.
45+# Never touches 18480, 18091, ~/forge-data, ~/.radicle or the STORE folder.
46+set -u
47+STORE=${1:?usage: compare.sh STORE KEY IPL_DIR}
48+KEY=${2:?usage: compare.sh STORE KEY IPL_DIR}
49+IPLD=${3:?usage: compare.sh STORE KEY IPL_DIR}
50+cd "$(dirname "$0")/../.."
51+ROOT=$(pwd)
52+CORES=${FORGED_CPUS:-4,5}
53+P0=${STORE_TEST_PORT:-18610}
54+# MAIN: the Radicle-reading binary the store build must match apart from Radicle lines: the restore
55+# branch below the store work, i.e. restore-rad-free 9a4420ab (main 4ed98366 + the agent door c12ca793 +
56+# the Radicle-text removal c1f107df, the live build since 2026-11-14 19:04Z, merged by RadFreeForgeAndSI).
57+MAINC=${FORGE_MAIN_COMMIT:-9a4420ab61b7437bed2b64346482dd0ff0fcd59f}
58+OMC=$HOME/work/flux/omega-mv/seed/out/omc
59+PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
60+RSTORE=${COMPARE_RSTORE:-$HOME/radicle-storage-frozen/storage}
61+export FORGE_SITE_STORE=${FORGE_SITE_STORE:-$RSTORE/z399yKvnXcBQNkKoq86iBDgTvQ5QV}
62+OWNER=drakestapleton
63+CB=https://interplane.io/
64+export LC_ALL=C
65+T=$(mktemp -d /tmp/forge-storecmp.XXXXXX)
66+chmod 700 "$T"
67+pids=()
68+pass=0; fail=0; invalid=0
69+ok() { pass=$((pass+1)); echo "PASS $*"; }
70+bad() { fail=$((fail+1)); echo "FAIL $*"; }
71+inval() { invalid=$((invalid+1)); echo "INVALID $*"; }
72+cleanup() { for p in "${pids[@]}"; do kill "$p" 2>/dev/null; done; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; }
73+trap cleanup EXIT
74+run() { taskset -c "$CORES" nice -n 10 "$@"; }
75+[ "$(sha256sum < "$OMC" | cut -c1-64)" = "$PIN" ] || { echo "NOT_RUN: omc is not the pin"; exit 3; }
76+command -v bwrap > /dev/null || { echo "NOT_RUN: bwrap missing"; exit 3; }
77+[ -f "$STORE/catalog.tsv" ] || { echo "NOT_RUN: no catalog in $STORE"; exit 3; }
78+for p in $(seq "$P0" $((P0 + 5))); do
79+ if ss -ltn | grep -q "127.0.0.1:$p "; then echo "NOT_RUN: port $p busy"; exit 3; fi
80+done
81+PMAIN=$P0; PDEF=$((P0 + 1)); PSTORE=$((P0 + 2)); PSTORE0=$((P0 + 3)); PTWIN=$((P0 + 4)); PMUT=$((P0 + 5))
82+echo "tree $(git rev-parse HEAD) dirty=$(git status --porcelain | wc -l) main $MAINC omc $PIN"
83+echo "store $STORE catalog sha256 $(sha256sum < "$STORE/catalog.tsv" | cut -c1-64) lines $(wc -l < "$STORE/catalog.tsv")"
84+# ---------------------------------------------------------------- fixtures and the two allow-lists
85+mkdir -p "$T/radstorage" "$T/store/projects" "$T/ng" "$T/bin" "$T/out"
86+cp server/tests/fake/rad server/tests/fake/getent "$T/bin/"
87+chmod 755 "$T/bin/rad" "$T/bin/getent"
88+: > "$T/bin/radfail" # the fake rad answers "not measured": no minute-stamped line to race
89+: > "$T/ng/dl.log"; : > "$T/ng/access.log"
90+awk 'f==0 && /^\|---/ {f=1; next} f==1 && !/^\|/ {exit} f==1 {print}' "$HOME/handoffs/radicle/RIDS.md" > "$T/rids-live.md"
91+# the fixture allow-list keeps the table's header and separator lines (server/repos.om flfind needs them)
92+awk '/^\| repo \| RID \| default branch/ {print; getline; print; exit}' "$HOME/handoffs/radicle/RIDS.md" > "$T/RIDS.md"
93+[ "$(wc -l < "$T/RIDS.md")" = 2 ] || { echo "NOT_RUN: RIDS.md has no first table header"; exit 3; }
94+: > "$T/cat-live.tsv"; : > "$T/excluded.txt"
95+while IFS= read -r row; do
96+ name=$(printf '%s' "$row" | awk -F'|' '{gsub(/ /,"",$2); print $2}')
97+ rid=$(printf '%s' "$row" | awk -F'|' '{gsub(/ /,"",$3); print $3}')
98+ line=$(awk -F'\t' -v n="$name" '$1 == n' "$STORE/catalog.tsv")
99+ if [ -z "$line" ]; then echo "$name $rid not in the store catalog" >> "$T/excluded.txt"; continue; fi
100+ al=$(sed -n 's/^alias //p' "$STORE/projects/$name/records/1")
101+ [ "$al" = "$rid" ] || { bad "store alias of $name is $al, RIDS.md says $rid"; continue; }
102+ # MAIN reads the frozen Radicle storage: a project landed in the store after the freeze has another
103+ # head there, so its pages cannot be equal; it is left out with both heads named
104+ sbr=$(printf '%s' "$line" | cut -f3) shead=$(printf '%s' "$line" | cut -f4)
105+ rhead=$(git --git-dir="$RSTORE/${rid#rad:}" rev-parse -q --verify "refs/heads/$sbr" 2>/dev/null)
106+ if [ "$shead" != "$rhead" ]; then echo "$name $rid landed after the Radicle freeze (store $sbr ${shead:0:12}, frozen ${rhead:0:12})" >> "$T/excluded.txt"; continue; fi
107+ printf '%s\n' "$row" >> "$T/RIDS.md"
108+ printf '%s\n' "$line" >> "$T/cat-live.tsv"
109+ ln -s "$RSTORE/${rid#rad:}" "$T/radstorage/${rid#rad:}"
110+ cp -al "$STORE/projects/$name" "$T/store/projects/$name"
111+done < "$T/rids-live.md"
112+echo "compared projects $(wc -l < "$T/cat-live.tsv") of $(wc -l < "$T/rids-live.md") live; left out: $(tr '\n' ';' < "$T/excluded.txt")"
113+# measurement behind the fixture: tags and non-ASCII paths on the default branch of every public line
114+ntag=0; nna=0
115+while IFS=$'\t' read -r n _ br _ vis; do
116+ [ "$vis" = public ] || continue
117+ g=$STORE/projects/$n/repo.git
118+ [ -n "$(git --git-dir="$g" for-each-ref refs/tags 'refs/namespaces/*/refs/tags/*' | head -1)" ] && ntag=$((ntag + 1))
119+ git --git-dir="$g" -c core.quotepath=false ls-tree -r --name-only "refs/heads/$br" | LC_ALL=C grep -q -P '[\x80-\xff]' && nna=$((nna + 1))
120+done < "$STORE/catalog.tsv"
121+echo "public store projects with a tag: $ntag; with a non-ASCII path on the default branch: $nna"
122+# fixture projects, made with the lane's own ipl and KEY: slice-b-fixture (tags, non-ASCII paths),
123+# omega-pearl (deny list by name), pearl-alias (deny list by the withdrawn RID), pearl-twin (their
124+# positive twin), no-alias (a project without an old Radicle id)
125+export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@invalid
126+mkfix() { # mkfix NAME ALIAS(rad:... or -) KIND [rids]: KIND tags or plain; rids also lists it for MAIN
127+ local n=$1 al=$2 w=$T/fxw-$1 rid
128+ git init -q -b main "$w" || return 1
129+ export GIT_AUTHOR_DATE=2026-11-13T00:00:00Z GIT_COMMITTER_DATE=2026-11-13T00:00:00Z
130+ printf '# %s\n\nfixture for store/tests/compare.sh\n' "$n" > "$w/README.md"
131+ mkdir -p "$w/docs"; printf 'one\n' > "$w/docs/a.txt"
132+ git -C "$w" add -A && git -C "$w" commit -q -m "first $n" || return 1
133+ if [ "$3" = tags ]; then
134+ git -C "$w" tag v0.1
135+ mkdir -p "$w/日本" "$w/docs/naïve résumé"
136+ printf 'ファイル\n' > "$w/日本/ファイル.txt"
137+ printf 'déjà vu\n' > "$w/docs/naïve résumé/café.md"
138+ export GIT_AUTHOR_DATE=2026-11-13T00:01:00Z GIT_COMMITTER_DATE=2026-11-13T00:01:00Z
139+ git -C "$w" add -A && git -C "$w" commit -q -m "non-ASCII paths" || return 1
140+ git -C "$w" tag -a v0.2 -m "annotated v0.2"
141+ printf 'two\n' >> "$w/docs/a.txt"
142+ export GIT_AUTHOR_DATE=2026-11-13T00:02:00Z GIT_COMMITTER_DATE=2026-11-13T00:02:00Z
143+ git -C "$w" commit -q -am "third" || return 1
144+ fi
145+ mkdir -p "$T/store/projects/$n"
146+ git clone -q --bare "$w" "$T/store/projects/$n/repo.git" || return 1
147+ "$IPLD/ipl" init "$T/store" "$n" main public "$al" "$KEY" > /dev/null 2>> "$T/ipl.err" || return 1
148+ printf 'fixture %s\n' "$n" > "$T/fx-$n.ev"; printf 'note %s\n' "$n" > "$T/fx-$n.note"
149+ "$IPLD/ipl" import "$T/store" "$n" main "$T/fx-$n.ev" "$T/fx-$n.note" "fx-$n" "$KEY" > /dev/null 2>> "$T/ipl.err" || return 1
150+ "$IPLD/ipl" verify "$T/store" "$n" > /dev/null 2>> "$T/ipl.err" || return 1
151+ if [ "${4:-}" = rids ]; then
152+ rid=${al#rad:}
153+ git clone -q --bare "$w" "$T/radstorage/$rid" || return 1
154+ printf '| %s | %s | main | - | test only | - |\n' "$n" "$al" >> "$T/RIDS.md"
155+ fi
156+}
157+FXRID=zSliceBFixtureTagsNonAscii1
158+mkfix slice-b-fixture "rad:$FXRID" tags rids || { bad "fixture slice-b-fixture: $(tail -3 "$T/ipl.err")"; exit 1; }
159+mkfix omega-pearl rad:zSliceBDenyByNameAAAAAA1 plain || { bad "fixture omega-pearl"; exit 1; }
160+mkfix pearl-alias rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ plain || { bad "fixture pearl-alias"; exit 1; }
161+mkfix pearl-twin rad:zSliceBDenyTwinAAAAAAAAA1 plain || { bad "fixture pearl-twin"; exit 1; }
162+mkfix no-alias - plain || { bad "fixture no-alias"; exit 1; }
163+# (the fixture off-list, a public project kept off the served list, is gone with the served list: the
164+# store build serves every public line; what must not appear is a private line (C1, mutant private)
165+# or a deny-list name or old id (C6, mutant deny))
166+# link fixtures (C3): real projects made by ipl, then the folder (link-project) or its repo.git
167+# (link-repo) moved aside and replaced by a symlink to it
168+LP=link-project; LR=link-repo
169+mkfix "$LP" rad:zSliceBLinkProjectAAAAA1 plain || { bad "fixture $LP"; exit 1; }
170+mkfix "$LR" rad:zSliceBLinkRepoAAAAAAAA1 plain || { bad "fixture $LR"; exit 1; }
171+mv "$T/store/projects/$LP" "$T/store/projects/.lp-real"; ln -s "$T/store/projects/.lp-real" "$T/store/projects/$LP"
172+mv "$T/store/projects/$LR/repo.git" "$T/store/projects/$LR/.repo-real.git"; ln -s "$T/store/projects/$LR/.repo-real.git" "$T/store/projects/$LR/repo.git"
173+unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE
174+# a public project of the store that is not in the compared list: present in the folder only
175+EXTRA=$(cut -f1 "$STORE/catalog.tsv" | grep -v -x -F -f <(cut -f1 "$T/cat-live.tsv") | head -1)
176+cp -al "$STORE/projects/$EXTRA" "$T/store/projects/$EXTRA"
177+EXTRALINE=$(awk -F'\t' -v n="$EXTRA" '$1 == n' "$STORE/catalog.tsv")
178+fxline() { if [ -f "$T/store/projects/$1/catalog.row" ]; then cat "$T/store/projects/$1/catalog.row"; else cat "$T/store/projects/.lp-real/catalog.row"; fi; }
179+# the compared catalog: the store's own lines of the live projects in RIDS.md order, then the
180+# fixture; every live line is byte-for-byte a line of STORE/catalog.tsv
181+{ cat "$T/cat-live.tsv"; fxline slice-b-fixture; } > "$T/cat-base.tsv"
182+n_sub=$(grep -c -x -F -f "$STORE/catalog.tsv" "$T/cat-live.tsv")
183+[ "$n_sub" = "$(wc -l < "$T/cat-live.tsv")" ] && ok "compared catalog lines are lines of the store's catalog ($n_sub)" || bad "compared catalog has lines the store does not ($n_sub)"
184+setcat() { cp "$1" "$T/store/catalog.tsv.new" && mv "$T/store/catalog.tsv.new" "$T/store/catalog.tsv"; }
185+setcat "$T/cat-base.tsv"
186+# the fixtures are signed with KEY, which need not be the store's owner key: compare.py checks their
187+# owner key against KEY's own fingerprint and keeps them out of the store projects' owner-key table
188+export COMPARE_FIXTURES="slice-b-fixture omega-pearl pearl-alias pearl-twin no-alias $LP $LR"
189+COMPARE_FIXTURE_KEY=$(ssh-keygen -lf "$KEY" | awk '{print $2}'); export COMPARE_FIXTURE_KEY
190+case $COMPARE_FIXTURE_KEY in SHA256:?*) ;; *) echo "NOT_RUN: no SHA256 fingerprint of $KEY"; exit 3 ;; esac
191+NCMP=$(wc -l < "$T/cat-base.tsv")
192+# ---------------------------------------------------------------- builds
193+mkdir -p "$T/main"
194+git archive "$MAINC" | tar -x -C "$T/main"
195+FORGE_SITE_REF=${FORGE_SITE_REF:-} ./run.sh chrome > /dev/null || { bad "chrome"; exit 1; }
196+mkdir -p "$T/main/.build"; cp .build/chrome.om "$T/main/.build/chrome.om"
197+SEDS=(-e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|"
198+ -e "s|/home/drakestapleton/.radicle/storage/|$T/radstorage/|g"
199+ -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|"
200+ -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|"
201+ -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|"
202+ -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|"
203+ -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|"
204+ -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|")
205+compose() { # compose DIR OUT PORT DATA [twin]: every unit of the tree in DIR (env selects the build)
206+ (cd "$1" && { printf 'om2\n'; cat $(./run.sh units); }) > "$2" || return 1
207+ if [ "${5:-}" = twin ]; then
208+ # the real RIDS.md and the Radicle storage MAIN reads (RSTORE, the frozen copy); only the port,
209+ # data and count sources move
210+ sed -i -e "s|haddr4 a 2130706433 18480|haddr4 a 2130706433 $3|" -e "s|/home/drakestapleton/forge-data/|$4/|g" \
211+ -e "s|/home/drakestapleton/.radicle/storage/|$RSTORE/|g" "${SEDS[@]:4}" "$2"
212+ else
213+ sed -i -e "s|haddr4 a 2130706433 18480|haddr4 a 2130706433 $3|" -e "s|/home/drakestapleton/forge-data/|$4/|g" "${SEDS[@]}" "$2"
214+ if grep -q '2130706433 18480\|/home/drakestapleton/forge-data\|/home/drakestapleton/.radicle\|/home/drakestapleton/handoffs/radicle' "$2"; then
215+ echo "compose $2: a live path or port remains"; return 1
216+ fi
217+ fi
218+ mkdir -p "$4/logs"
219+}
220+build() { run "$OMC" < "$1" > "$1.bin" 2> "$1.err" && chmod 755 "$1.bin"; }
221+compose "$T/main" "$T/main.om" "$PMAIN" "$T/dmain" && build "$T/main.om" || { bad "MAIN build: $(cat "$T/main.om.err" 2>/dev/null)"; exit 1; }
222+compose "$ROOT" "$T/def.om" "$PDEF" "$T/ddef" && build "$T/def.om" || { bad "DEF build: $(cat "$T/def.om.err" 2>/dev/null)"; exit 1; }
223+FORGE_STORE=$T/store FORGE_CLONE_BASE=$CB compose "$ROOT" "$T/store.om" "$PSTORE" "$T/dstore" && build "$T/store.om" || { bad "STORE build: $(cat "$T/store.om.err" 2>/dev/null)"; exit 1; }
224+FORGE_STORE=$T/store compose "$ROOT" "$T/store0.om" "$PSTORE0" "$T/dstore0" && build "$T/store0.om" || { bad "STORE0 build: $(cat "$T/store0.om.err" 2>/dev/null)"; exit 1; }
225+compose "$ROOT" "$T/twin.om" "$PTWIN" "$T/dtwin" twin && build "$T/twin.om" || { bad "TWIN build"; exit 1; }
226+compose "$T/main" "$T/maintwin.om" "$PTWIN" "$T/dmaintwin" twin && build "$T/maintwin.om" || { bad "MAINTWIN build"; exit 1; }
227+for b in main def store store0 twin maintwin; do echo "binary $b sha256 $(sha256sum < "$T/$b.om.bin" | cut -c1-64)"; done
228+# what ./run.sh build itself makes (no test redirections): the store-reading binary holds no RIDS.md
229+# path, no rad command, no node database path and no rad clone line; the default binary of the same
230+# tree holds each of them. The Radicle storage path text tfstore stays in server/util.om (its
231+# fkgit / fkgiti and the units that compose a historical util.om need it), so for it the check is on the
232+# composed source: no line of the store-reading build uses tfstore apart from util.om's own default
233+# branch of fkgit / fkgiti, which runs only while fsrcst is 0
234+mkdir -p "$T/rs-store" "$T/rs-def"
235+FORGE_STORE=$T/store FORGED_OUT=$T/rs-store/forged FORGED_CPUS=$CORES ./run.sh build > "$T/rs-store.log" 2>&1 || bad "run.sh build (store): $(tail -2 "$T/rs-store.log")"
236+FORGED_OUT=$T/rs-def/forged FORGED_CPUS=$CORES ./run.sh build > "$T/rs-def.log" 2>&1 || bad "run.sh build (default): $(tail -2 "$T/rs-def.log")"
237+echo "run.sh build: store $(sha256sum < "$T/rs-store/forged" | cut -c1-64) default $(sha256sum < "$T/rs-def/forged" | cut -c1-64)"
238+for s in handoffs/radicle/RIDS.md .radicle/bin/rad node.db-wal; do
239+ c=$(grep -c -a -F -- "$s" "$T/rs-store/forged"); d=$(grep -c -a -F -- "$s" "$T/rs-def/forged")
240+ [ "$c" = 0 ] && [ "$d" -gt 0 ] && ok "store binary has no '$s' (default binary has $d)" || bad "store binary '$s' $c, default $d"
241+done
242+# the clone command 'rad clone rad:' is in neither binary since the Radicle-text removal (c1f107df; the
243+# words 'rad clone' alone are a pattern server/util.om cuts out of descriptions): the store binary has none
244+c=$(grep -c -a -F -- 'rad clone rad:' "$T/rs-store/forged"); [ "$c" = 0 ] && ok "store binary has no 'rad clone rad:'" || bad "store binary 'rad clone rad:' $c"
245+c=$(FORGE_STORE=$T/store ./run.sh units | grep -v '^/' | grep -v '^server/util.om$' | xargs cat | grep -w tfstore | grep -c -v '^note')
246+d=$(./run.sh units | grep -v '^/' | grep -v '^server/util.om$' | xargs cat | grep -w tfstore | grep -c -v '^note')
247+e=$(grep -w tfstore server/util.om | grep -v '^note' | grep -c -v '^text tfstore')
248+[ "$c" = 0 ] && [ "$d" -gt 0 ] && [ "$e" = 2 ] && ok "no unit of the store-reading build names tfstore (default units: $d uses); util.om uses it only in the fsrcst-0 branch of fkgit and fkgiti" || bad "tfstore uses: store units $c, default units $d, util.om $e"
249+# ---------------------------------------------------------------- servers
250+# the sandbox of the STORE runs: tmpfs over the Radicle storage MAIN reads (its parent folder), over
251+# ~/.radicle when it still exists, and over ~/handoffs/radicle
252+BW=(bwrap --die-with-parent --ro-bind / / --bind "$T" "$T" --tmpfs "$(dirname "$RSTORE")" --tmpfs "$HOME/handoffs/radicle" --dev /dev --proc /proc)
253+[ -d "$HOME/.radicle" ] && BW+=(--tmpfs "$HOME/.radicle")
254+waitup() { for _ in $(seq 150); do curl -s -o /dev/null "http://127.0.0.1:$1/explore" && return 0; sleep 0.2; done; return 1; }
255+start() { # start NAME PORT sandbox|plain [SOCIALDIR]: the binary (or bwrap) is the background job
256+ # itself, not a shell function around it, so its pid is the one stopone and cleanup kill
257+ local sd=${4:-$T/soc-$1/}
258+ mkdir -p "$sd"
259+ if [ "$3" = sandbox ]; then
260+ FORGE_SOCIAL_DIR=$sd taskset -c "$CORES" nice -n 10 "${BW[@]}" "$T/$1.om.bin" >> "$T/$1.log" 2>&1 &
261+ else
262+ FORGE_SOCIAL_DIR=$sd taskset -c "$CORES" nice -n 10 "$T/$1.om.bin" >> "$T/$1.log" 2>&1 &
263+ fi
264+ eval "PID_$1=$! PORT_$1=$2"; pids+=($!)
265+ waitup "$2" || { bad "$1 did not listen on $2: $(tail -3 "$T/$1.log")"; return 1; }
266+}
267+stopone() { # stopone NAME: stop it and wait until its port is free
268+ local v="PID_$1" w="PORT_$1"
269+ kill "${!v}" 2>/dev/null; wait "${!v}" 2>/dev/null
270+ for _ in $(seq 50); do ss -ltn | grep -q "127.0.0.1:${!w} " || return 0; sleep 0.1; done
271+ bad "$1 still listens on ${!w} after it was stopped"
272+}
273+# sandbox: no Radicle storage and no RIDS.md inside, both present outside
274+run "${BW[@]}" test ! -e "$RSTORE" && test ! -e "$HOME/.radicle/storage" && test -e "$RSTORE" && ok "sandbox: $RSTORE and ~/.radicle/storage absent inside, $RSTORE present outside" || bad "sandbox storage visibility"
275+run "${BW[@]}" test ! -e "$HOME/handoffs/radicle/RIDS.md" && ok "sandbox: RIDS.md absent inside" || bad "sandbox RIDS.md visible"
276+start twin "$PTWIN" sandbox || exit 1
277+tin=$(curl -s "http://127.0.0.1:$PTWIN/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])')
278+stopone twin
279+start twin "$PTWIN" plain || exit 1
280+tout=$(curl -s "http://127.0.0.1:$PTWIN/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])')
281+stopone twin
282+[ "$tin" = 0 ] && [ "$tout" -gt 0 ] && ok "a Radicle-path binary lists $tin repositories in the sandbox and $tout outside" || bad "twin in=$tin out=$tout"
283+# the same in main's binary: with RIDS.md unreadable its reload traps 5 (exit 105) in freload instead of
284+# serving nothing; this tree's server/main.om says 0 instead (TWIN above listened in the sandbox)
285+timeout 60 taskset -c "$CORES" "${BW[@]}" "$T/maintwin.om.bin" > "$T/maintwin.log" 2>&1; rc=$?
286+# measured: 4ed98366 exits 105 (trap 5 in freload); MAIN since the Radicle-text removal keeps listening
287+# (timeout 124) and serves nothing; either way it never serves a repository there
288+case $rc in 105|124) ok "main's binary with RIDS.md unreadable: exit $rc (105 = trap 5 in freload, 124 = still listening at the 60 s timeout); this tree's listens and serves nothing" ;; *) bad "main's binary in the sandbox exit $rc (expected 105 or 124)" ;; esac
289+start main "$PMAIN" plain || exit 1
290+start def "$PDEF" plain || exit 1
291+start store "$PSTORE" sandbox || exit 1
292+start store0 "$PSTORE0" sandbox || exit 1
293+# ---------------------------------------------------------------- pages
294+q() { python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))' "$1"; }
295+pages=(/ /explore /explore.json)
296+extra=()
297+sample=$(python3 store/tests/compare.py sample "$T/cat-base.tsv" "$T/store/projects" slice-b-fixture)
298+echo "sample: $(echo $sample)"
299+for n in $sample; do
300+ g=$T/store/projects/$n/repo.git
301+ br=$(awk -F'\t' -v n="$n" '$1 == n {print $3}' "$T/cat-base.tsv")
302+ r=/$OWNER/$n
303+ h=$(git --git-dir="$g" rev-parse "refs/heads/$br")
304+ par=$(git --git-dir="$g" rev-parse -q --verify "$h^" || true)
305+ pages+=("$r" "$r.json" "$r/tree/$(q "$br")" "$r/commits" "$r/commits/$(q "$br")" "$r/commit/$h" "$r/commit/$h.patch" "$r/commit/$h.diff"
306+ "$r/compare" "$r/branches" "$r/tags" "$r/archive/refs/heads/$(q "$br").zip" "$r/archive/refs/heads/$(q "$br").tar.gz")
307+ [ -n "$par" ] && pages+=("$r/compare/$par...$h")
308+ d=$(git --git-dir="$g" ls-tree "refs/heads/$br" | awk '$2 == "tree" {sub(/^[^\t]*\t/, ""); print; exit}')
309+ [ -n "$d" ] && pages+=("$r/tree/$(q "$br")/$(q "$d")")
310+ files=$(git --git-dir="$g" -c core.quotepath=false ls-tree -r --name-only "refs/heads/$br" | awk 'NR==1 || /^README/ || /\// {print}' | head -3)
311+ [ "$n" = slice-b-fixture ] && files=$(git --git-dir="$g" -c core.quotepath=false ls-tree -r --name-only "refs/heads/$br")
312+ while IFS= read -r f; do
313+ [ -n "$f" ] || continue
314+ e=$(python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe="/"))' "$f")
315+ pages+=("$r/blob/$(q "$br")/$e" "$r/raw/$(q "$br")/$e" "$r/blame/$(q "$br")/$e")
316+ done <<< "$files"
317+ if [ "$n" = slice-b-fixture ]; then
318+ pages+=("$r/archive/refs/tags/v0.2.zip" "$r/archive/refs/tags/v0.1.tar.gz" "$r/tree/v0.2" "$r/commits/v0.1")
319+ fi
320+ extra+=("$r/patches" "$r/issues" "$r/releases" "$r/stargazers" "$r/search?q=a")
321+done
322+printf '%s\n' "${pages[@]}" > "$T/pages.txt"
323+# /status, /status.json and /trending are left out: they print the time of the request (the snapshot's
324+# age in seconds, the trending window's ends)
325+printf '%s\n' /drakestapleton /search?q=omega "${extra[@]}" > "$T/pages-extra.txt"
326+fetch() { # fetch PORT DIR LISTFILE: every page as HTML/raw and with Accept: application/json
327+ mkdir -p "$2"
328+ python3 store/tests/compare.py fetch "$1" "$2" "$3"
329+}
330+fetch "$PMAIN" "$T/out/main" "$T/pages.txt"
331+fetch "$PSTORE" "$T/out/store" "$T/pages.txt"
332+fetch "$PDEF" "$T/out/def" "$T/pages.txt"
333+fetch "$PMAIN" "$T/out/main-x" "$T/pages-extra.txt"
334+fetch "$PDEF" "$T/out/def-x" "$T/pages-extra.txt"
335+fetch "$PSTORE0" "$T/out/store0" "$T/pages.txt"
336+if python3 store/tests/compare.py same "$T/out/main" "$T/out/def" > "$T/main-def.txt"; then ok "DEF = MAIN byte for byte: $(tail -1 "$T/main-def.txt")"; else bad "DEF differs from MAIN: $(head -5 "$T/main-def.txt")"; fi
337+if python3 store/tests/compare.py same "$T/out/main-x" "$T/out/def-x" > "$T/main-def-x.txt"; then ok "DEF = MAIN on the other pages: $(tail -1 "$T/main-def-x.txt")"; else bad "DEF differs from MAIN (other pages): $(head -5 "$T/main-def-x.txt")"; fi
338+if python3 store/tests/compare.py radicle "$T/out/main" "$T/out/store" > "$T/main-store.txt"; then ok "STORE = MAIN apart from lines that name Radicle: $(tail -1 "$T/main-store.txt")"; else bad "STORE differs from MAIN beyond Radicle lines: $(grep -m5 '^BAD' "$T/main-store.txt")"; fi
339+cp "$T/main-store.txt" "${STORE_TEST_DIFF:-/dev/null}" 2>/dev/null || true
340+# the clone panel (its line starts <div class="clone">) never has a rad clone line, and the agent line
341+# of dl/dlclone.om (forge-contribute, a Radicle patch) is not there; repository files that mention
342+# rad clone (READMEs, blame) are content, not the panel
343+c=$(grep -h -a '^<div class="clone">' -r "$T/out/store" "$T/out/store0" | grep -c -F 'rad clone'); d=$(grep -l -a -F 'One command for agents' -r "$T/out/store" "$T/out/store0" | wc -l); e=$(grep -h -a '^<div class="clone">' -r "$T/out/main" | grep -c -F 'rad clone')
344+# (MAIN shows no rad clone line either since the Radicle-text removal; its count is printed)
345+[ "$c" = 0 ] && [ "$d" = 0 ] && ok "no store clone panel has a rad clone line or the agent line (MAIN panels with rad clone: $e)" || bad "store clone panels with rad clone $c, agent lines $d, MAIN panels $e"
346+c=$(grep -c -a -F "git clone ${CB}projects/slice-b-fixture/repo.git</code>" "$T/out/store/$(python3 store/tests/compare.py key "/$OWNER/slice-b-fixture" html)"); [ "$c" = 1 ] && ok "STORE clone panel: git clone ${CB}projects/slice-b-fixture/repo.git" || bad "STORE clone line count $c"
347+c=$(grep -l -a -F 'Git over HTTPS' -r "$T/out/store0" | wc -l); d=$(grep -l -a -F 'Git over HTTPS' -r "$T/out/store" | wc -l); [ "$c" = 0 ] && [ "$d" -gt 0 ] && ok "STORE0 (no clone base) shows no HTTPS line; STORE shows it on $d pages" || bad "HTTPS line: store0 $c store $d"
348+c=$(grep -c -a -F '"clone":{"rad":null,"rad_clone":null,"git_https":null}' "$T/out/store0/$(python3 store/tests/compare.py key "/$OWNER/slice-b-fixture.json" html)"); [ "$c" = 1 ] && ok "STORE0 JSON clone object: rad, rad_clone and git_https null" || bad "STORE0 JSON clone object ($c)"
349+c=$(grep -c -a -F "\"clone\":{\"rad\":null,\"rad_clone\":null,\"git_https\":\"${CB}projects/slice-b-fixture/repo.git\"}" "$T/out/store/$(python3 store/tests/compare.py key "/$OWNER/slice-b-fixture.json" html)"); [ "$c" = 1 ] && ok "STORE JSON clone object: git_https ${CB}projects/slice-b-fixture/repo.git" || bad "STORE JSON clone object ($c)"
350+# ---------------------------------------------------------------- negative controls (STORE, live reloads)
351+U=http://127.0.0.1:$PSTORE
352+st() { curl -s -o /dev/null -w '%{http_code}' "$U$1"; }
353+excount() { curl -s "$U/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])'; }
354+# reload: forged checks the catalog's inode, size and mtime between connections; wait for the
355+# expected project count, and say how many reload lines the log gained
356+reloadto() { # reloadto CATFILE WANTCOUNT
357+ local before; before=$(grep -c '^forged: reloaded' "$T/store.log")
358+ setcat "$1"
359+ for _ in $(seq 100); do
360+ curl -s -o /dev/null "$U/explore"
361+ [ "$(grep -c '^forged: reloaded' "$T/store.log")" -gt "$before" ] && [ "$(excount)" = "$2" ] && return 0
362+ sleep 0.2
363+ done
364+ return 1
365+}
366+# every repository URL of project N under its catalog branch (main when the catalog does not list
367+# it): home, JSON, tree, blob, raw, commits, branches, tags, archive; allst adds /rad:<ALIAS>
368+urls() {
369+ local r=/$OWNER/$1 br f
370+ br=$(awk -F'\t' -v n="$1" '$1 == n {print $3}' "$T/store/catalog.tsv"); br=${br:-main}
371+ f=$(git --git-dir="$T/store/projects/$1/repo.git" ls-tree --name-only "refs/heads/$br" 2>/dev/null | head -1); f=${f:-README.md}
372+ br=$(q "$br"); f=$(q "$f")
373+ echo "$r $r.json $r/tree/$br $r/blob/$br/$f $r/raw/$br/$f $r/commits $r/branches $r/tags $r/archive/refs/heads/$br.zip"
374+}
375+allst() { local s=""; for u in $(urls "$1"); do s="$s$(st "$u") "; done; [ -n "${2:-}" ] && s="$s$(st "/rad:$2")"; echo "$s"; }
376+listed() { curl -s "$U/explore.json" | python3 -c 'import json,sys; print(int(any(r["name"]==sys.argv[1] for r in json.load(sys.stdin)["repos"])))' "$1"; }
377+ctl() { # ctl NAME CATFILE WANTCOUNT PROJECT WANT(404|200) [ALIAS]: one control row
378+ if ! reloadto "$2" "$3"; then inval "$1: the store did not reload to $3 projects (setup)"; return 1; fi
379+ local s; s=$(allst "$4" "${6:-}")
380+ local want=$5; local l; l=$(listed "$4")
381+ if [ "$want" = 404 ]; then
382+ case "$s" in *[1235]0[0-9]*) bad "$1: $4 answered [$s] listed=$l"; return 1 ;; esac
383+ [ "$l" = 0 ] || { bad "$1: $4 listed on explore"; return 1; }
384+ else
385+ case "$s" in *404*|*500*) bad "$1: twin $4 answered [$s]"; return 1 ;; esac
386+ [ "$l" = 1 ] || { bad "$1: twin $4 not listed"; return 1; }
387+ fi
388+ ok "$1: $4 [$s] listed=$l"
389+}
390+FXA=slice-b-fixture
391+grep -v -P "^$FXA\t" "$T/cat-base.tsv" > "$T/c-nofx.tsv"
392+fxl=$(fxline $FXA)
393+B=$NCMP; B1=$((NCMP - 1))
394+printf '%s\n' "${fxl%public}private" > "$T/fxpriv"; cat "$T/c-nofx.tsv" "$T/fxpriv" > "$T/c-priv.tsv"
395+ctl "C1 private line" "$T/c-priv.tsv" "$B1" $FXA 404 $FXRID
396+ctl "C1 twin: the same line public" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
397+ctl "C2 project in the folder, not in the catalog" "$T/cat-base.tsv" "$B" "$EXTRA" 404
398+{ cat "$T/cat-base.tsv"; printf '%s\n' "$EXTRALINE"; } > "$T/c-extra.tsv"
399+ctl "C2 twin: its line added" "$T/c-extra.tsv" $((B + 1)) "$EXTRA" 200
400+# C3: a symlinked project folder and a symlinked repo.git (each points at a real project made by ipl)
401+{ cat "$T/cat-base.tsv"; fxline "$LP"; } > "$T/c-lp.tsv"
402+{ cat "$T/cat-base.tsv"; fxline "$LR"; } > "$T/c-lr.tsv"
403+ctl "C3a symlinked project folder" "$T/c-lp.tsv" "$B" "$LP" 404 zSliceBLinkProjectAAAAA1
404+grep -q "project $LP left out (project folder is a link or not a folder)" "$T/store.log" && ok "C3a stderr names the rule" || bad "C3a stderr"
405+rm "$T/store/projects/$LP"; mv "$T/store/projects/.lp-real" "$T/store/projects/$LP"
406+ctl "C3a twin: the same project in a real folder" "$T/c-lp.tsv" $((B + 1)) "$LP" 200 zSliceBLinkProjectAAAAA1
407+mv "$T/store/projects/$LP" "$T/store/projects/.lp-real"; ln -s "$T/store/projects/.lp-real" "$T/store/projects/$LP"
408+ctl "C3b symlinked repo.git" "$T/c-lr.tsv" "$B" "$LR" 404 zSliceBLinkRepoAAAAAAAA1
409+grep -q "project $LR left out (repo.git is a link or not a folder)" "$T/store.log" && ok "C3b stderr names the rule" || bad "C3b stderr"
410+rm "$T/store/projects/$LR/repo.git"; mv "$T/store/projects/$LR/.repo-real.git" "$T/store/projects/$LR/repo.git"
411+ctl "C3b twin: repo.git a real folder" "$T/c-lr.tsv" $((B + 1)) "$LR" 200 zSliceBLinkRepoAAAAAAAA1
412+mv "$T/store/projects/$LR/repo.git" "$T/store/projects/$LR/.repo-real.git"; ln -s "$T/store/projects/$LR/.repo-real.git" "$T/store/projects/$LR/repo.git"
413+# C4: malformed catalogs fail closed; each twin is the well-formed catalog it came from
414+malformed() { # malformed NAME FILE REASON
415+ if ! reloadto "$2" 0; then bad "$1: the store still serves projects"; return; fi
416+ local s; s=$(allst $FXA $FXRID)
417+ case "$s" in *[1235]0[0-9]*) bad "$1: $FXA answered [$s]"; return ;; esac
418+ grep -q "forged: catalog refused ($3" "$T/store.log" && ok "$1: no repositories [$s], stderr says $3" || bad "$1: stderr lacks '$3'"
419+ ctl "$1 twin: the well-formed catalog" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
420+}
421+awk -F'\t' -v OFS='\t' 'NR==2 {$6="extra"} {print}' "$T/cat-base.tsv" > "$T/m-fields6.tsv"
422+awk -F'\t' -v OFS='\t' 'NR==2 {NF=4} {print}' "$T/cat-base.tsv" > "$T/m-fields4.tsv"
423+{ cat "$T/cat-base.tsv"; sed -n 1p "$T/cat-base.tsv"; } > "$T/m-dupline.tsv"
424+l1=$(sed -n 1p "$T/cat-base.tsv"); n1=${l1%%$'\t'*}
425+{ cat "$T/cat-base.tsv"; fxline "$LP" | awk -F'\t' -v OFS='\t' -v n="$n1" '{$1=n; print}'; } > "$T/m-dupname.tsv"
426+{ cat "$T/cat-base.tsv"; fxline "$LP" | awk -F'\t' -v OFS='\t' -v n="${n1^^}" '{$1=n; print}'; } > "$T/m-dupcase.tsv"
427+{ cat "$T/cat-base.tsv"; printf '%s\n' "$l1" | awk -F'\t' -v OFS='\t' '{$1="dup-id-other"; print}'; } > "$T/m-dupid.tsv"
428+awk -F'\t' -v OFS='\t' 'NR==2 {$4="12345"} {print}' "$T/cat-base.tsv" > "$T/m-badhead.tsv"
429+awk -F'\t' -v OFS='\t' 'NR==2 {$4=toupper($4)} {print}' "$T/cat-base.tsv" > "$T/m-headcase.tsv"
430+head -c -1 "$T/cat-base.tsv" > "$T/m-nolf.tsv"
431+awk -F'\t' -v OFS='\t' 'NR==2 {$5="public\r"} {print}' "$T/cat-base.tsv" > "$T/m-cr.tsv"
432+awk -F'\t' -v OFS='\t' 'NR==2 {$1=$1 "\001"} {print}' "$T/cat-base.tsv" > "$T/m-ctl.tsv"
433+awk -F'\t' -v OFS='\t' 'NR==2 {$5="Public"} {print}' "$T/cat-base.tsv" > "$T/m-vis.tsv"
434+awk -F'\t' -v OFS='\t' 'NR==2 {$1="-bad"} {print}' "$T/cat-base.tsv" > "$T/m-name.tsv"
435+awk -F'\t' -v OFS='\t' 'NR==2 {$3="a..b"} {print}' "$T/cat-base.tsv" > "$T/m-branch.tsv"
436+awk -F'\t' -v OFS='\t' 'NR==2 {$2=substr($2,2)} {print}' "$T/cat-base.tsv" > "$T/m-id.tsv"
437+{ cat "$T/cat-base.tsv"; echo; } > "$T/m-empty.tsv"
438+malformed "C4a six fields" "$T/m-fields6.tsv" "not five tab-separated fields at line 2"
439+malformed "C4b four fields" "$T/m-fields4.tsv" "not five tab-separated fields at line 2"
440+malformed "C4c duplicate line" "$T/m-dupline.tsv" "two equal names at line $((B + 1))"
441+malformed "C4d duplicate name" "$T/m-dupname.tsv" "two equal names at line $((B + 1))"
442+malformed "C4e names that differ only in case" "$T/m-dupcase.tsv" "two names that differ only in case at line $((B + 1))"
443+malformed "C4f duplicate id" "$T/m-dupid.tsv" "two equal ids at line $((B + 1))"
444+malformed "C4g bad head" "$T/m-badhead.tsv" "head is not 40 lowercase hex digits or none at line 2"
445+malformed "C4h upper-case head" "$T/m-headcase.tsv" "head is not 40 lowercase hex digits or none at line 2"
446+malformed "C4i missing final line feed" "$T/m-nolf.tsv" "no final line feed"
447+malformed "C4j carriage return" "$T/m-cr.tsv" "control byte at line 2"
448+malformed "C4k control byte in a name" "$T/m-ctl.tsv" "control byte at line 2"
449+malformed "C4l visibility Public" "$T/m-vis.tsv" "visibility is not public or private at line 2"
450+malformed "C4m name rule" "$T/m-name.tsv" "name outside the name rule at line 2"
451+malformed "C4n branch rule" "$T/m-branch.tsv" "branch outside the branch rule at line 2"
452+malformed "C4o id of 63 digits" "$T/m-id.tsv" "id is not 64 lowercase hex digits at line 2"
453+malformed "C4p empty line" "$T/m-empty.tsv" "not five tab-separated fields at line $((B + 1))"
454+# unreadable catalog: a link, then absent
455+ln -s "$T/cat-base.tsv" "$T/store/catalog.tsv.lnk"; mv "$T/store/catalog.tsv.lnk" "$T/store/catalog.tsv"
456+for _ in $(seq 50); do curl -s -o /dev/null "$U/explore"; [ "$(excount)" = 0 ] && break; sleep 0.2; done
457+[ "$(excount)" = 0 ] && grep -q "forged: catalog refused (cannot be read or is a link)" "$T/store.log" && ok "C4q catalog.tsv a link: no repositories" || bad "C4q catalog link"
458+ctl "C4q twin: a regular catalog" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
459+# more public lines than the old 64-row table: the well-formed catalog plus 65 more public lines. The
460+# table holds FAMAX (256) rows and nothing past it refuses the whole catalog any more (2026-11-14): the
461+# fixture is still served, the 65 lines (no project folder) are each left out alone
462+python3 store/tests/compare.py manylines "$T/cat-base.tsv" 65 > "$T/m-65.tsv"
463+cat "$T/cat-base.tsv" "$T/m-65.tsv" > "$T/c-65.tsv"
464+ctl "C4r 65 public lines more than the well-formed catalog: no refusal, the fixture still served" "$T/c-65.tsv" "$B" $FXA 200 $FXRID
465+grep -q "forged: catalog refused (more public" "$T/store.log" && bad "C4r stderr still has a whole-catalog refusal for too many lines" || ok "C4r no whole-catalog refusal for too many lines"
466+# C5: a head the catalog names that repo.git does not have, and a head that is not the branch tip
467+fxh=$(printf '%s' "$fxl" | cut -f4); fxp=$(git --git-dir="$T/store/projects/$FXA/repo.git" rev-parse "$fxh^")
468+printf '%s\n' "$fxl" | awk -F'\t' -v OFS='\t' '{$4="0123456789abcdef0123456789abcdef01234567"; print}' > "$T/fxh"; cat "$T/c-nofx.tsv" "$T/fxh" > "$T/c-head.tsv"
469+printf '%s\n' "$fxl" | awk -F'\t' -v OFS='\t' -v h="$fxp" '{$4=h; print}' > "$T/fxp"; cat "$T/c-nofx.tsv" "$T/fxp" > "$T/c-head2.tsv"
470+ctl "C5a head repo.git does not have" "$T/c-head.tsv" "$B1" $FXA 404 $FXRID
471+ctl "C5a twin" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
472+ctl "C5b head that is not the branch tip" "$T/c-head2.tsv" "$B1" $FXA 404 $FXRID
473+ctl "C5b twin" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
474+# C6: the deny list by name (omega-pearl) and by the withdrawn RID (pearl-alias); twin pearl-twin
475+{ cat "$T/cat-base.tsv"; fxline omega-pearl; fxline pearl-alias; fxline pearl-twin; } > "$T/c-deny.tsv"
476+ctl "C6a deny list by name" "$T/c-deny.tsv" $((B + 1)) omega-pearl 404 zSliceBDenyByNameAAAAAA1
477+ctl "C6b deny list by id (alias rad:z2ft64...)" "$T/c-deny.tsv" $((B + 1)) pearl-alias 404 z2ft64NFLsKzWttCXw6NWNbRQLggQ
478+ctl "C6 twin: the same fixture, another name and id" "$T/c-deny.tsv" $((B + 1)) pearl-twin 200 zSliceBDenyTwinAAAAAAAAA1
479+# C7: record 1 that no longer hashes to the catalog id (a replaced copy, not the hard link), seen
480+# after the reload flag (the existing reload signal; the catalog itself does not change)
481+r1=$T/store/projects/pearl-twin/records/1
482+cp "$r1" "$T/r1.keep"; { cat "$T/r1.keep"; } | sed 's/^nonce \(.\)/nonce 0/' > "$T/r1.new"
483+cmp -s "$T/r1.new" "$T/r1.keep" && sed -i 's/^nonce \(.\)/nonce 1/' "$T/r1.new"
484+rm "$r1"; cp "$T/r1.new" "$r1"
485+before=$(grep -c '^forged: reloaded' "$T/store.log"); : > "$T/dstore/reload"
486+for _ in $(seq 100); do curl -s -o /dev/null "$U/explore"; [ "$(grep -c '^forged: reloaded' "$T/store.log")" -gt "$before" ] && break; sleep 0.2; done
487+s=$(allst pearl-twin)
488+case "$s" in *[1235]0[0-9]*) bad "C7 tampered record 1 still served [$s]" ;; *) grep -q "project pearl-twin left out (records/1 does not hash to the catalog id)" "$T/store.log" && ok "C7 tampered record 1: pearl-twin [$s], stderr names the rule (reload flag)" || bad "C7 stderr" ;; esac
489+rm "$r1"; cp "$T/r1.keep" "$r1"; : > "$T/dstore/reload"
490+for _ in $(seq 100); do curl -s -o /dev/null "$U/explore"; [ "$(listed pearl-twin)" = 1 ] && break; sleep 0.2; done
491+[ "$(listed pearl-twin)" = 1 ] && ok "C7 twin: the original record 1 is served again after the reload flag" || bad "C7 twin"
492+# C8: old links and a project without an old id
493+reloadto "$T/c-deny.tsv" $((B + 1)) || inval "C8 setup"
494+for n in $(cut -f1 "$T/cat-live.tsv" | head -3) $FXA; do
495+ a=$(sed -n 's/^alias rad://p' "$T/store/projects/$n/records/1")
496+ lm=$(curl -s -o /dev/null -w '%{http_code} %{redirect_url}' "http://127.0.0.1:$PMAIN/rad:$a/tree/main")
497+ ls=$(curl -s -o /dev/null -w '%{http_code} %{redirect_url}' "$U/rad:$a/tree/main")
498+ lm=${lm//$PMAIN/P}; ls=${ls//$PSTORE/P}
499+ [ "$lm" = "$ls" ] && [ "${ls%% *}" = 302 ] && ok "C8 /rad:$a/tree/main answers as MAIN: $ls" || bad "C8 /rad:$a main [$lm] store [$ls]"
500+done
501+{ cat "$T/c-deny.tsv"; fxline no-alias; } > "$T/c-noal.tsv"
502+ctl "C8 project without an old id: served under its git:<id> (every public line is served)" "$T/c-noal.tsv" $((B + 2)) no-alias 200
503+w=$(python3 store/tests/expect_served.py --count "$T/store"); [ "$(excount)" = "$w" ] && ok "C8 explore.json count $w = the catalog's public lines less the deny list (expect_served.py)" || bad "C8 explore count $(excount), expect_served.py $w"
504+gid=$(fxline no-alias | cut -f2)
505+grep -q "forged: project no-alias left out" "$T/store.log" && bad "C8 stderr: no-alias left out" || ok "C8 stderr: no line leaves no-alias out"
506+c=$(curl -s "$U/$OWNER/no-alias.json" | grep -c -F "\"rid\":\"git:$gid\""); [ "$c" = 1 ] && ok "C8 no-alias.json names rid git:<its id>" || bad "C8 no-alias.json rid (count $c)"
507+s=$(st "/rad:$gid"); [ "$s" = 404 ] && ok "C8 /rad:<git id> is not a link (404)" || bad "C8 /rad:<git id> answered $s"
508+# C9: star targets already in the social log (written by MAIN as rad:<RID>) resolve in STORE and
509+# survive a restart; a star written by STORE on a project without an old id (no-alias, git:<id>)
510+# too
511+stargz() { python3 store/tests/compare.py stars "$1" "$2"; }
512+ssh-keygen -q -t ed25519 -N '' -C 'throwaway social key, store/tests/compare.sh' -f "$T/k1"
513+L1=$(sed -n 1p "$T/cat-live.tsv" | cut -f1); L2=$(sed -n 2p "$T/cat-live.tsv" | cut -f1)
514+SM=$(python3 store/tests/compare.py signin "$PMAIN" "$T/k1")
515+case "$SM" in *SIGNIN-FAILED*) inval "C9 setup: sign-in on MAIN: $SM" ;; esac
516+python3 store/tests/compare.py star "$PMAIN" "$SM" "$L1" > /dev/null
517+python3 store/tests/compare.py star "$PMAIN" "$SM" "$FXA" > /dev/null
518+[ "$(stargz "$PMAIN" "$L1") $(stargz "$PMAIN" "$FXA")" = "1 1" ] && ok "C9 setup: MAIN wrote two stars (rad:<RID> targets)" || inval "C9 setup: MAIN stars $(stargz "$PMAIN" "$L1") $(stargz "$PMAIN" "$FXA")"
519+grep -c -F "rad:${FXRID}" "$T/soc-main/social.log" > /dev/null && ok "C9 MAIN's log names rad:$FXRID" || bad "C9 MAIN log lacks rad:$FXRID"
520+stopone store; rm -rf "$T/soc-store"; cp -a "$T/soc-main" "$T/soc-store"
521+start store "$PSTORE" sandbox || exit 1
522+reloadto "$T/c-noal.tsv" $((B + 2)) || inval "C9 setup: store reload"
523+s="$(stargz "$PSTORE" "$L1") $(stargz "$PSTORE" "$FXA") $(stargz "$PSTORE" "$L2")"
524+[ "$s" = "1 1 0" ] && ok "C9 STORE resolves the stars MAIN logged: $L1 1, $FXA 1, twin $L2 0" || bad "C9 STORE stars [$s] want [1 1 0]"
525+SS=$(python3 store/tests/compare.py signin "$PSTORE" "$T/k1")
526+case "$SS" in *SIGNIN-FAILED*) inval "C9 setup: sign-in on STORE: $SS" ;; esac
527+python3 store/tests/compare.py star "$PSTORE" "$SS" no-alias > /dev/null
528+s="$(stargz "$PSTORE" no-alias) $(stargz "$PSTORE" pearl-twin)"
529+[ "$s" = "1 0" ] && ok "C9 STORE stars no-alias (git:<id>): no-alias 1, twin pearl-twin 0" || bad "C9 no-alias star [$s] want [1 0]"
530+stopone store; start store "$PSTORE" sandbox || exit 1
531+reloadto "$T/c-noal.tsv" $((B + 2)) || inval "C9 setup: store restart"
532+s="$(stargz "$PSTORE" "$L1") $(stargz "$PSTORE" "$FXA") $(stargz "$PSTORE" no-alias)"
533+[ "$s" = "1 1 1" ] && ok "C9 after a restart the log replays: $L1 1, $FXA 1, no-alias 1" || bad "C9 after restart [$s]"
534+setcat "$T/cat-base.tsv"
535+# ---------------------------------------------------------------- mutants
536+# each mutant: the STORE units with one decision changed, built and started in the sandbox on PMUT;
537+# its fresh unmutated baseline must pass the control first (setup failure = INVALID, not caught)
538+mutant() { # mutant NAME SEDEXPR TARGETLINE CONTROLFN [APPENDFILE]
539+ local m=$T/mut-$1.om
540+ cp "$T/store.om" "$m"
541+ [ "$(grep -c -x -F -- "$3" "$m")" = 1 ] || { inval "mutant $1: target line not found once"; return; }
542+ sed -i -e "s|haddr4 a 2130706433 $PSTORE|haddr4 a 2130706433 $PMUT|" -e "s|$T/dstore/|$T/dmut/|g" -e "$2" "$m"
543+ grep -q -x -F -- "$3" "$m" && { inval "mutant $1: sed did not change the target"; return; }
544+ [ -n "${5:-}" ] && cat "$5" >> "$m"
545+ if ! run "$OMC" < "$m" > "$m.bin" 2> "$m.err"; then inval "mutant $1 did not compile: $(cat "$m.err")"; return; fi
546+ chmod 755 "$m.bin"
547+ mkdir -p "$T/dmut/logs"
548+ "$4" "$1"
549+}
550+# control functions: each starts the mutant, sets the catalog, and returns via pass/fail counters
551+mctl() { # mctl MUTANT CATFILE PROJECT: caught when PROJECT is served (200 on its home)
552+ FORGE_SOCIAL_DIR=$T/soc-mut/ taskset -c "$CORES" nice -n 10 "${BW[@]}" "$T/mut-$1.om.bin" > "$T/mut-$1.log" 2>&1 &
553+ eval "PID_mut=$! PORT_mut=$PMUT"; pids+=($!)
554+ if ! waitup "$PMUT"; then inval "mutant $1 did not listen: $(tail -2 "$T/mut-$1.log")"; stopone mut; return; fi
555+ # a mutant that no longer serves the well-formed catalog (the fixture's home 200) is INVALID, not caught
556+ setcat "$T/cat-base.tsv"; local s=404
557+ for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PMUT/explore"; s=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PMUT/$OWNER/$FXA"); [ "$s" = 200 ] && break; sleep 0.2; done
558+ if [ "$s" != 200 ]; then inval "mutant $1 does not serve the well-formed catalog ($FXA answered $s)"; stopone mut; return; fi
559+ setcat "$2"; s=404
560+ for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PMUT/explore"; s=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PMUT/$OWNER/$3"); [ "$s" = 200 ] && break; sleep 0.2; done
561+ stopone mut; setcat "$T/cat-base.tsv"
562+ [ "$s" = 200 ] && ok "mutant $1 caught: it serves $3 (200), the unmutated build answers 404" || bad "mutant $1 survived: $3 answered $s"
563+}
564+m_private() { mctl "$1" "$T/c-priv.tsv" $FXA; }
565+m_scan() { mctl "$1" "$T/cat-base.tsv" "$EXTRA"; }
566+m_link() { mctl "$1" "$T/c-lr.tsv" "$LR"; }
567+m_deny() { mctl "$1" "$T/c-deny.tsv" omega-pearl; }
568+m_head() { mctl "$1" "$T/c-head.tsv" $FXA; }
569+m_dup() { mctl "$1" "$T/m-dupname.tsv" $FXA; }
570+m_nolf() { mctl "$1" "$T/m-nolf.tsv" $FXA; }
571+# fresh baselines: the unmutated STORE refuses each of these (rows above), checked again here
572+for c in "$T/c-priv.tsv:$FXA" "$T/cat-base.tsv:$EXTRA" "$T/c-lr.tsv:$LR" "$T/c-deny.tsv:omega-pearl" "$T/c-head.tsv:$FXA" "$T/m-dupname.tsv:$FXA" "$T/m-nolf.tsv:$FXA"; do
573+ f=${c%%:*}; n=${c#*:}; setcat "$f"
574+ for _ in $(seq 30); do curl -s -o /dev/null "$U/explore"; sleep 0.1; done
575+ s=$(st "/$OWNER/$n"); [ "$s" = 404 ] && ok "baseline: unmutated STORE answers 404 for $n under $(basename "$f")" || bad "baseline $n under $(basename "$f") answered $s"
576+done
577+setcat "$T/cat-base.tsv"
578+mutant private 's/^ret xstxeq s4 e tfspub$/ret true/' 'ret xstxeq s4 e tfspub' m_private
579+mutant scan 's/^n = xscatrd$/n = xscatsc/' 'n = xscatrd' m_scan store/tests/mutant-scan.om
580+mutant link 's/^r = lstat fpth 0 get fpthl 0 fstb 0 128$/r = stat fpth 0 get fpthl 0 fstb 0 128/' 'r = lstat fpth 0 get fpthl 0 fstb 0 128' m_link
581+mutant deny 's/^if fdeny k$/if false/' 'if fdeny k' m_deny
582+mutant head 's/^if not xsheadok k$/if false/' 'if not xsheadok k' m_head
583+mutant dup 's/^r = xsdup p e$/r = ulong 0/' 'r = xsdup p e' m_dup
584+mutant nolf 's/^if and gt ln 0 ne get fxo sub ln 1 10$/if false/' 'if and gt ln 0 ne get fxo sub ln 1 10' m_nolf
585+echo "STORE stderr: $(grep -a -o 'forged: catalog refused ([^)]*)' "$T/store.log" | wc -l) catalog refusals, $(grep -a -o 'forged: project [^ ]* left out' "$T/store.log" | wc -l) projects left out, $(grep -a -o 'forged: reloaded' "$T/store.log" | wc -l) reloads"
586+[ -n "${KEEP:-}" ] && echo "kept $T"
587+echo "RESULT pass=$pass fail=$fail invalid=$invalid"
588+[ "$fail" = 0 ] && [ "$invalid" = 0 ]

store/tests/crawl-store.sh

new file mode 100755
@@ -0,0 +1,59 @@
1+#!/usr/bin/env bash
2+# ORACLE: host test driver (bash + curl + python3 store/tests/radcrawl.py), not product code.
3+# store/tests/crawl-store.sh: the store-reading build of this tree, on the production store (read only,
4+# STORE default ~/interplane-store-owner; it serves every public catalog line less the deny list), crawled from /
5+# (radcrawl.py: /, /explore, /agents.json, /events.json, /feed, project homes, ?format=text forms and
6+# the links they lead to, up to CRAWL_LIMIT addresses, default 400): no Radicle pattern of
7+# RadFreeForgeAndSI's crawl may appear in what the forge writes; repository content (READMEs,
8+# descriptions, commit subjects, files) is counted apart and allowed.
9+# Negative control: the same build with one forge-written sentence (the feed intro) naming Radicle
10+# must give a forge hit on /feed.
11+# Private port CRAWL_PORT (default 19996, 19990..19999 only), data dir and social dir in a temp dir;
12+# FORGED_CPUS default 0-2. Never 18480, ~/forge-data or a write to the store.
13+set -u
14+cd "$(dirname "$0")/../.."
15+STORE=${STORE:-$HOME/interplane-store-owner}
16+CORES=${FORGED_CPUS:-0-2}
17+PORT=${CRAWL_PORT:-19996}
18+case $PORT in 1999[0-9]) ;; *) echo "REFUSED: use a private port in 19990..19999"; exit 2 ;; esac
19+OMC=$HOME/work/flux/omega-mv/seed/out/omc
20+T=$(mktemp -d /tmp/crawl-store.XXXXXX); chmod 700 "$T"
21+PASS=0; FAIL=0; PID=
22+ok() { PASS=$((PASS+1)); echo "PASS $*"; }
23+bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
24+stop() { [ -n "$PID" ] && kill "$PID" 2> /dev/null; [ -n "$PID" ] && wait "$PID" 2> /dev/null; PID=; }
25+trap 'stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
26+if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
27+mkdir -p "$T/data/logs" "$T/social"
28+(export FORGE_STORE=$STORE; { printf 'om2\n'; cat $(./run.sh units); }) \
29+ | sed -e "s/haddr4 a 2130706433 18480/haddr4 a 2130706433 $PORT/" -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" > "$T/f.om" || { bad "compose"; exit 1; }
30+grep -q '2130706433 18480\|/home/drakestapleton/forge-data/' "$T/f.om" && { bad "a live port or data path remains"; exit 1; }
31+build() { taskset -c "$CORES" nice -n 10 "$OMC" < "$1.om" > "$1" 2> "$1.err" && chmod 755 "$1"; }
32+start() {
33+ FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$1" 2> "$1.log" &
34+ PID=$!
35+ for _ in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0; sleep 0.1; done
36+ return 1
37+}
38+build "$T/f" || { bad "build: $(cat "$T/f.err")"; exit 1; }
39+ok "store build $(sha256sum < "$T/f" | cut -c1-16), catalog $(grep -c . "$STORE/catalog.tsv") lines"
40+start "$T/f" || { bad "start"; exit 1; }
41+want=$(python3 store/tests/expect_served.py --count "$STORE")
42+got=$(curl -s "http://127.0.0.1:$PORT/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])')
43+[ "$got" = "$want" ] && ok "explore.json count $got = public catalog lines less the deny list (store/tests/expect_served.py)" || bad "explore.json count $got, want $want"
44+python3 store/tests/radcrawl.py "http://127.0.0.1:$PORT" "${CRAWL_LIMIT:-400}" "$T/crawl.json" > "$T/crawl.out" 2>&1; rc=$?
45+cat "$T/crawl.out"
46+L=$(grep '^RADCRAWL ' "$T/crawl.out")
47+[ "$rc" = 0 ] && ok "crawl: no Radicle pattern in forge-written text ($L)" || bad "crawl: forge-written Radicle text ($L)"
48+n=$(echo "$L" | sed -n 's/.*urls=\([0-9]*\).*/\1/p'); [ "${n:-0}" -ge 100 ] && ok "crawl reached $n addresses" || bad "crawl reached only ${n:-0} addresses"
49+stop
50+# negative control: the feed intro names Radicle
51+sed 's/What happened on this forge, newest first/What happened on this Radicle forge, newest first/' "$T/f.om" > "$T/m.om"
52+cmp -s "$T/f.om" "$T/m.om" && { bad "control: mutation did not apply"; exit 1; }
53+build "$T/m" || { bad "control build"; exit 1; }
54+start "$T/m" || { bad "control start"; exit 1; }
55+CRAWL_SEEDS_ONLY=1 python3 store/tests/radcrawl.py "http://127.0.0.1:$PORT" 40 "$T/crawl-m.json" > "$T/crawl-m.out" 2>&1; rc=$?
56+grep -q '^FORGE 200 [0-9]* /feed ' "$T/crawl-m.out" && [ "$rc" = 1 ] && ok "control: a Radicle word in the feed intro is a forge hit on /feed" || bad "control not caught: $(grep '^RADCRAWL' "$T/crawl-m.out")"
57+stop
58+echo "store/tests/crawl-store.sh: $PASS passed, $FAIL failed"
59+[ "$FAIL" = 0 ]

store/tests/expect_served.py

new file mode 100755
@@ -0,0 +1,58 @@
1+#!/usr/bin/env python3
2+# ORACLE: host test helper, not product code.
3+# store/tests/expect_served.py ROOT: the projects the store-reading build is expected to serve from
4+# the store at ROOT, one name a line, in catalog order; with --count only their number. Written apart
5+# from the forge (store/repos.om) and from infra/spark/forged-public.sh store_names, so a test that
6+# compares the forge's explore list with this does not compare a rule with itself.
7+# The rule (Drake, 2026-11-14: the store build serves every public catalog line): every line of
8+# ROOT/catalog.tsv whose fifth field is "public", less the deny list of server/repos.om fdeny
9+# (the names omega-pearl and aien-crypto, and the old id rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ read from
10+# the "alias" line of projects/NAME/records/1), less a line whose old id an earlier kept line already
11+# has, less lines past FAMAX (256). A store the forge refuses as a whole (store/repos.om) is not
12+# modelled here: the tests use stores that verify.
13+import sys
14+
15+DENY_NAMES = {"omega-pearl", "aien-crypto"}
16+DENY_IDS = {"z2ft64NFLsKzWttCXw6NWNbRQLggQ"}
17+FAMAX = 256
18+
19+
20+def alias(root, name):
21+ try:
22+ with open(f"{root}/projects/{name}/records/1", "rb") as f:
23+ for line in f.read().decode("ascii", "replace").split("\n"):
24+ if line.startswith("alias "):
25+ a = line[len("alias "):]
26+ return a[4:] if a.startswith("rad:") else ""
27+ except OSError:
28+ pass
29+ return ""
30+
31+
32+def served(root):
33+ out, seen, pub = [], set(), 0
34+ with open(f"{root}/catalog.tsv", encoding="ascii") as f:
35+ for line in f:
36+ p = line.rstrip("\n").split("\t")
37+ if len(p) != 5 or p[4] != "public":
38+ continue
39+ pub += 1
40+ if pub > FAMAX: # the table takes the first FAMAX public lines, then the deny list
41+ break
42+ name, a = p[0], alias(root, p[0])
43+ if name in DENY_NAMES or a in DENY_IDS:
44+ continue
45+ if a and a in seen:
46+ continue
47+ if a:
48+ seen.add(a)
49+ out.append(name)
50+ return out
51+
52+
53+if __name__ == "__main__":
54+ args = [a for a in sys.argv[1:] if a != "--count"]
55+ if len(args) != 1:
56+ sys.exit("usage: expect_served.py [--count] ROOT")
57+ s = served(args[0].rstrip("/"))
58+ print(len(s) if "--count" in sys.argv else "\n".join(s))

store/tests/fixstore.sh

new file mode 100755
@@ -0,0 +1,46 @@
1+#!/usr/bin/env bash
2+# ORACLE: host test helper (bash, git, interplane-native ipl), not product code.
3+# store/tests/fixstore.sh RIDS_MD STORAGE ROOT: turn a test's Radicle-shaped fixture (the first table
4+# of RIDS_MD, and STORAGE/<RID> bare repositories or links to them) into a native store at ROOT, so a
5+# suite written for the Radicle build runs against the store-reading build (its STORE_VARIANT=1). For
6+# every row of the first table whose STORAGE/<RID> exists: when FIXSTORE_FROM (default
7+# ~/interplane-store-owner) holds a project of that name with that old id and the same head on the row's
8+# branch, its folder is hard-linked into ROOT (cp -al; read only: nothing here writes it); otherwise
9+# the repository is cloned bare into ROOT/projects/NAME/repo.git and recorded with ipl init and ipl
10+# import (old id rad:<RID>, signed by a throwaway key made here). ROOT/catalog.tsv is the projects'
11+# own catalog lines in table order. Rows the record rules refuse (ipl init fails) are left out and
12+# named on stderr. env: IPL_DIR (required, interplane-native with bin/ built); FIXSTORE_HARDLINK=1
13+# clones with hard-linked objects (only for a STORAGE the test made itself, never a shared one: git
14+# never rewrites an object file, and the forge only reads). Exit 0, or 1 when no row could be recorded.
15+set -u
16+RIDS=${1:?RIDS_MD} STORAGE=${2:?STORAGE} ROOT=${3:?ROOT}
17+IPLD=${IPL_DIR:?IPL_DIR}
18+FROM=${FIXSTORE_FROM:-$HOME/interplane-store-owner}
19+mkdir -p "$ROOT/projects" || exit 1
20+[ -f "$ROOT/.fixkey" ] || ssh-keygen -q -t ed25519 -N "" -C "store/tests/fixstore.sh throwaway key" -f "$ROOT/.fixkey" || exit 1
21+og() { env -i PATH=/usr/bin:/bin HOME=/nonexistent GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null git "$@"; }
22+n_ok=0; : > "$ROOT/.rows"
23+while IFS=$'\t' read -r name rid br; do
24+ repo=$STORAGE/${rid#rad:}
25+ [ -e "$repo" ] || continue
26+ [ -e "$ROOT/projects/$name" ] && continue
27+ head=$(og --git-dir="$repo" rev-parse -q --verify "refs/heads/$br" 2>/dev/null) || { echo "fixstore: $name has no refs/heads/$br" >&2; continue; }
28+ if [ -f "$FROM/projects/$name/records/1" ] && grep -qx "alias $rid" "$FROM/projects/$name/records/1" \
29+ && [ "$(og --git-dir="$FROM/projects/$name/repo.git" rev-parse -q --verify "refs/heads/$br" 2>/dev/null)" = "$head" ]; then
30+ cp -al "$FROM/projects/$name" "$ROOT/projects/$name" || exit 1
31+ else
32+ hl=--no-hardlinks; [ "${FIXSTORE_HARDLINK:-0}" = 1 ] && hl=
33+ og clone -q --bare $hl "$repo" "$ROOT/projects/$name/repo.git" 2> /dev/null || { echo "fixstore: clone of $name failed" >&2; rm -rf "${ROOT:?}/projects/$name"; continue; }
34+ if ! "$IPLD/ipl" init "$ROOT" "$name" "$br" public "$rid" "$ROOT/.fixkey" > /dev/null 2>> "$ROOT/.ipl.err"; then
35+ echo "fixstore: $name left out: ipl init refused it ($(tail -1 "$ROOT/.ipl.err"))" >&2; rm -rf "${ROOT:?}/projects/$name"; continue
36+ fi
37+ echo "$name" > "$ROOT/.ev"
38+ "$IPLD/ipl" import "$ROOT" "$name" "$br" "$ROOT/.ev" "$ROOT/.ev" "fix-$name" "$ROOT/.fixkey" > /dev/null 2>> "$ROOT/.ipl.err" \
39+ || { echo "fixstore: $name left out: ipl import failed ($(tail -1 "$ROOT/.ipl.err"))" >&2; rm -rf "${ROOT:?}/projects/$name"; continue; }
40+ fi
41+ echo "$name" >> "$ROOT/.rows"; n_ok=$((n_ok + 1))
42+done < <(awk -F '|' '/^\| repo \| RID \| default branch/ { if (seen) exit; seen=1; getline; next }
43+ seen && !/^\|/ { exit } seen { for (i = 2; i <= 4; i++) gsub(/^ +| +$/, "", $i); print $2 "\t" $3 "\t" $4 }' "$RIDS")
44+while read -r n; do cat "$ROOT/projects/$n/catalog.row"; done < "$ROOT/.rows" > "$ROOT/catalog.tsv.new" && mv "$ROOT/catalog.tsv.new" "$ROOT/catalog.tsv"
45+echo "fixstore: $n_ok projects in $ROOT ($(grep -c . "$ROOT/catalog.tsv") catalog lines)" >&2
46+[ "$n_ok" -gt 0 ]

store/tests/mutant-scan.om

new file mode 100644
@@ -0,0 +1,55 @@
1+note store/tests/mutant-scan.om: TEST-ONLY mutant for store/tests/compare.sh, never composed into
2+note forged. compare.sh appends it to the composed store-reading build and turns "n = xscatrd" into
3+note "n = xscatsc": the project list then comes from scanning ROOT/projects and joining every
4+note project's catalog.row (what interplane-native's ipl join_catalog does) instead of from
5+note ROOT/catalog.tsv. Control C2 (a project in the folder that the catalog does not list) must catch it.
6+text tmtrow "/catalog.row"
7+global mtdb uchar 65536
8+fn xscatsc to long
9+put fxol 0 0
10+put fxotr 0 0
11+xspdir
12+note O_RDONLY | O_DIRECTORY (040000 on arm64) | O_CLOEXEC
13+fd = fopen fpth 0 get fpthl 0 540672 0
14+if lt fd 0
15+ret -1
16+end
17+for it ulong 100000
18+n = getdnts int fd mtdb 0 len mtdb
19+if le n 0
20+break
21+end
22+p = ulong 0
23+while lt p ulong n bound 65536
24+rl = or ulong get mtdb add p 16 shl ulong get mtdb add p 17 8
25+mtone add p 19
26+p = add p rl
27+end
28+end
29+x = fclose int fd
30+ret long get fxol 0
31+end
32+fn mtone a ulong to void
33+if eq get mtdb a 46
34+ret
35+end
36+xspfold
37+for k ulong 255
38+c = get mtdb add a k
39+if eq c 0
40+break
41+end
42+fpc c
43+end
44+fpt tmtrow
45+fd = fopen fpth 0 get fpthl 0 524288 0
46+if lt fd 0
47+ret
48+end
49+n = get fxol 0
50+r = read int fd fxo n sub len fxo n
51+if gt r 0
52+put fxol 0 add n ulong r
53+end
54+x = fclose int fd
55+end

store/tests/radcrawl.py

new file mode 100755
@@ -0,0 +1,106 @@
1+#!/usr/bin/env python3
2+# ORACLE: host test driver, not product code.
3+# store/tests/radcrawl.py BASE LIMIT OUT.json: crawl a running forge from BASE (seeds below, then the
4+# links it finds on the same host, up to LIMIT addresses) and count the Radicle patterns of
5+# RadFreeForgeAndSI's crawl (~/work/hive/rad-free-si/crawl.py, the same regular expression) in what the
6+# forge itself writes. Repository content is left out of the count: every page of a repository below
7+# its home (blob, raw, blame, tree, commit, commits, compare, releases, archive, search), the result
8+# lines of the forge-wide code search (/search?q=: lines of repository files), and, on a
9+# project home, the README, the description and the last commit subject (HTML: the readme box, the
10+# desc paragraph and the Last commit line; JSON: the readme, description and last_commit values;
11+# text form: from the README.md heading on, and the description and last commit lines).
12+# Prints one FORGE line per address with forge-written hits, then
13+# RADCRAWL urls=N forge_hits=H content_hits=C codes={...}
14+# and exits 1 when H > 0, 0 otherwise. OUT.json gets every row.
15+import json, re, sys, urllib.error, urllib.parse, urllib.request
16+from collections import deque
17+
18+P = re.compile(r'radicle|\brad:z[1-9A-HJ-NP-Za-km-z]{10,}|\brad (clone|init|sync|id|patch|auth)|/rad/|heartwood|radicle\.(xyz|network|garden|dev)', re.I)
19+BASE, LIMIT, OUT = sys.argv[1], int(sys.argv[2]), sys.argv[3]
20+SEEDS = ['/', '/explore', '/explore.json', '/explore?format=text', '/agents.json', '/agents.json?format=text',
21+ '/events.json', '/events.json?limit=200', '/feed', '/feed?format=text', '/drakestapleton',
22+ '/drakestapleton?format=text', '/drakestapleton.json', '/login', '/stars', '/search?q=forge',
23+ '/drakestapleton/hop', '/drakestapleton/hop.json', '/drakestapleton/hop?format=text',
24+ '/drakestapleton/omega-mv', '/drakestapleton/omega-mv.json', '/drakestapleton/omega-mv?format=text',
25+ '/drakestapleton/cuda-crack', '/drakestapleton/cuda-crack.json', '/drakestapleton/interplane.io',
26+ '/status', '/status.json', '/open/', '/drakestapleton/hop/patches', '/no-such-page-x']
27+CONTENT = re.compile(r'^(/[^/?]+/[^/?]+/(blob|raw|blame|tree|commit|commits|compare|releases|archive|search)(/|\?|$)|/search\?)')
28+HOME = re.compile(r'^/[^/?]+/([^/?]+?)(\.json)?(\?format=text)?$')
29+host = urllib.parse.urlparse(BASE).netloc
30+
31+def fetch(u):
32+ class NR(urllib.request.HTTPRedirectHandler):
33+ def redirect_request(self, *a, **k): return None
34+ try:
35+ r = urllib.request.build_opener(NR).open(urllib.request.Request(BASE + u, headers={'User-Agent': 'radcrawl'}), timeout=60)
36+ return r.status, r.headers.get('Content-Type', ''), r.read()
37+ except urllib.error.HTTPError as e:
38+ return e.code, e.headers.get('Content-Type', ''), e.read()
39+
40+def forge_part(u, ct, t):
41+ """the text the forge itself wrote on page u (repository content cut out)"""
42+ if CONTENT.match(u.split('#')[0]):
43+ return ''
44+ m = HOME.match(u)
45+ if not m or u.startswith(('/drakestapleton?', '/drakestapleton.json')) or m.group(1) in ('followers', 'following'):
46+ return t
47+ if 'json' in ct:
48+ try:
49+ d = json.loads(t)
50+ except ValueError:
51+ return t
52+ if isinstance(d, dict) and d.get('schema') == 'forge/repo/1':
53+ for k in ('readme', 'description', 'last_commit', 'files'):
54+ d.pop(k, None)
55+ return json.dumps(d)
56+ return t
57+ if 'text/plain' in ct:
58+ t = t.split('\nREADME.md', 1)[0]
59+ return '\n'.join(l for l in t.split('\n') if not l.startswith(('Last commit', 'Description')))
60+ # HTML: the readme box up to the developer section, the description, the last commit line
61+ t = re.sub(r'<div class="box readme".*?(?=<section class="pj-dev")', '', t, flags=re.S)
62+ t = re.sub(r'<p class="desc">.*?</p>', '', t, flags=re.S)
63+ t = re.sub(r'<p class="meta">Last commit:.*?</p>', '', t, flags=re.S)
64+ return t
65+
66+seen, q, rows = set(), deque(SEEDS), []
67+while q and len(seen) < LIMIT:
68+ u = q.popleft()
69+ if u in seen:
70+ continue
71+ seen.add(u)
72+ try:
73+ c, ct, b = fetch(u)
74+ except Exception as e:
75+ rows.append(dict(url=u, code='ERR', forge=0, content=0, ex=str(e)[:80]))
76+ continue
77+ t = b.decode('utf-8', 'replace')
78+ allh = len(P.findall(t))
79+ f = forge_part(u, ct, t)
80+ fm = list(P.finditer(f))
81+ rows.append(dict(url=u, code=c, forge=len(fm), content=allh - len(fm),
82+ ex=f[max(0, fm[0].start() - 70):fm[0].end() + 30].replace('\n', ' ') if fm else ''))
83+ if any(x in ct for x in ('html', 'json', 'text')):
84+ for h in re.findall(r'''(?:href|src)=["']([^"'#]+)''', t) + re.findall(r'"(/[A-Za-z0-9_./?=&%-]+)"', t):
85+ h = h.replace('&amp;', '&')
86+ pu = urllib.parse.urlparse(urllib.parse.urljoin(BASE + u, h))
87+ if pu.netloc != host:
88+ continue
89+ p = pu.path + ('?' + pu.query if pu.query else '')
90+ if p.startswith('/assets/') or p.endswith(('.css', '.svg', '.png', '.ico', '.tar', '.woff2', '.zip', '.gz')):
91+ continue
92+ if p not in seen:
93+ q.append(p)
94+codes = {}
95+for r in rows:
96+ codes[str(r['code'])] = codes.get(str(r['code']), 0) + 1
97+ if r['forge']:
98+ print('FORGE', r['code'], r['forge'], r['url'], '|', r['ex'])
99+for s in SEEDS:
100+ r = next((r for r in rows if r['url'] == s), None)
101+ if r:
102+ print('SEED', r['code'], r['forge'], r['content'], s)
103+fh, ch = sum(r['forge'] for r in rows), sum(r['content'] for r in rows)
104+print('RADCRAWL urls=%d forge_hits=%d content_hits=%d codes=%s' % (len(rows), fh, ch, json.dumps(codes, sort_keys=True)))
105+json.dump(rows, open(OUT, 'w'), indent=1)
106+sys.exit(1 if fh else 0)

store/tests/svlib.sh

new file mode 100644
@@ -0,0 +1,20 @@
1+# ORACLE: host test helper, not product code. Sourced by a suite written for the Radicle build when it
2+# runs as STORE_VARIANT=1: its fixture repository changes while the server runs (refs added, moved and
3+# deleted between requests), and a store is a recorded copy, so before every request the store is made
4+# again from the fixture when the fixture's refs changed since the last time (store/tests/fixstore.sh,
5+# objects hard-linked from the test's own storage), and the server is given the new catalog (it reloads
6+# when catalog.tsv gets another inode, size or mtime; two requests make sure the next one sees it).
7+# svsync GITDIR RIDS_MD STORAGE ROOT PORT
8+# Needs IPL_DIR. Prints nothing; returns 1 when the store could not be made.
9+svsync() {
10+ [ "${STORE_VARIANT:-0}" = 1 ] || return 0
11+ local f
12+ f=$(git --git-dir="$1" for-each-ref --format='%(refname) %(objectname)' | sha256sum | cut -c1-64)
13+ [ "$f" = "$(cat "$4.fp" 2> /dev/null)" ] && return 0
14+ rm -rf "$4.new"
15+ FIXSTORE_FROM=/nonexistent FIXSTORE_HARDLINK=1 bash "$(dirname "${BASH_SOURCE[0]}")/fixstore.sh" "$2" "$3" "$4.new" 2>> "$4.log" || return 1
16+ rm -rf "$4"; mv "$4.new" "$4"; echo "$f" > "$4.fp"
17+ # a running server reloads the catalog between connections; none may be running yet (start)
18+ curl -s -o /dev/null --max-time 60 "http://127.0.0.1:$5/explore"; curl -s -o /dev/null --max-time 60 "http://127.0.0.1:$5/explore"
19+ return 0
20+}

tools/bring/PLATFORMS.md

@@ -26,7 +26,18 @@ OMEGESE section 10 at the installed source provides:
2626 - `execprog A off n`: u16 record count, then u16 length and bytes per argument; argv[0] is the absolute executable. No shell, PATH search or inherited environment. Closes descriptors >=3 with close_range before exec; fails closed if closure fails. Packet <=4096 bytes, 1..64 records are compiler limitations, not project policy.
2727 - `dupfd fd target flags`, `pipefds A off n flags`, `waitpid pid A off n options` (four-byte status), `fchdir`, `pread` and `pwrite` supply stream redirection and file-backed processing.
2828
29-Paths are length-delimited, at most 4095 bytes under this compiler; argument reads internally scan at most 1 MiB. Neither is a new tool cap. No git process is needed or permitted.
29+Paths are length-delimited, at most 4095 bytes under this compiler; argument reads internally scan at most 1 MiB. Neither is a new tool cap. `bring`, `get`, `withdraw`, `pack` and `unpack` start no git process. `interplane patch` (since 2026-11-17, `src/50patch.om`) starts `/usr/bin/git` through the same `execprog` path (argument list, empty environment, no shell) for read-only commands; see `docs/BRING.md` "patch" and the section below.
30+
31+### interplane patch: what was run, per target (2026-11-17)
32+
33+Only what was run is listed; the tree is `patch/docs` 8a19474e7c18 (the `patch/git-intake` a9c887f code with this branch's docs, `patch/tests/e2e.sh` and infra), on the Spark under pool 18, against a scratch forged on 127.0.0.1:18488 (fixture repository, scratch data folder, throwaway key in a scratch HOME).
34+
35+| Target | interplane patch |
36+|---|---|
37+| Linux aarch64 | EXERCISED (loopback): `patch/tests/e2e.sh`, 15 pass 0 fail, exit 0. `patch --yes` in a scratch clone with `env -i`: git runs, the summary, key made, sign-in, upload accepted (exit 0, the page printed); the raw route is byte-equal to `git format-patch` with the tool's flags; `git am` of it onto the base gives the tool's tree. Log `~/work/lanes/ipl-forge-patch/logs/e2e-8a19474e7c18.log` (sha256 `d115eadadf83c3a785d340d003809b4141f9252168426731490706825e0ab590`). Consent without `--yes` (no terminal, typed no, typed yes), replay, options and server refusals are in `patch/tests/run.sh`, not run by me |
38+| Linux x86_64 | EXERCISED under emulation only: the same e2e with `E2E_TARGET=x86linux` (`build.sh x86linux`, run by qemu-x86_64 8.2.2 through binfmt on the AArch64 Spark; it starts the native `/usr/bin/git`, `/usr/bin/ssh-keygen` and `/usr/bin/curl`), 15 pass 0 fail, exit 0, log `~/work/lanes/ipl-forge-patch/logs/e2e-x86linux-8a19474e7c18.log` (sha256 `833202e4d905b580ab12c5abcf8d660b1882b14077db64fc4b026001147cb6ba`). Not run on x86-64 hardware |
39+| macOS arm64 | BUILT only: `build.sh macos` with ng `5ed20188...` exited 0 and gave a Mach-O arm64 PIE executable (unsigned sha256 `f482447d760c99c5...`). NOT_RUN: not copied to a Mac or run; whether `posix_spawn` of `/usr/bin/git` works there is unknown |
40+| Intel macOS | CANNOT YET (no x86_64 Mach-O emitter, below) |
3041
3142 ## macOS arm64
3243
@@ -111,6 +122,6 @@ No x86-64 Mach-O emitter is supplied by these toolchains. ng explicitly excludes
111122
112123 ## Dependencies
113124
114-Runtime external processes are restricted to `/usr/bin/curl` for HTTP(S) and `/usr/bin/ssh-keygen` for key creation/signing, after exact consent for bring. They are contract-authorized host dependencies, not claimed to be Omega. No git, shell, tar, Radicle or package manager is invoked by the tool. The tests use outside checks only as oracles and glue: GNU tar, strace, script, ssh-keygen -Y verify, basenc, git (to make the partial clone and its fetch control, and `git archive` fixtures), qemu-x86_64, and python3 for the one-line mutant edits (the pattern of open/tests/run.sh); on the Mac, expect, codesign and macOS tar.
125+Runtime external processes are restricted to `/usr/bin/curl` for HTTP(S) and `/usr/bin/ssh-keygen` for key creation/signing, after exact consent for bring, and, for `interplane patch` only, `/usr/bin/git` for read-only commands (`rev-parse`, `merge-base`, `rev-list`, `format-patch`, `diff`, `log`) before consent. They are contract-authorized host dependencies (git by contract interplane-connector r1 F7), not claimed to be Omega. No shell, tar, Radicle or package manager is invoked by the tool, and no git command that fetches, pushes or writes. The tests use outside checks only as oracles and glue: GNU tar, strace, script, ssh-keygen -Y verify, basenc, git (to make the partial clone and its fetch control, `git archive` fixtures, and in `patch/tests/` the fixture repository, `format-patch` and `am` oracles), qemu-x86_64, and python3 for the one-line mutant edits (the pattern of open/tests/run.sh); on the Mac, expect, codesign and macOS tar.
115126
116127 SHA reuse search found `social/20crypt.om` (base64, base58 decoding and argv-only signing verification), `dl/`, and ng's `seed/ng/sha256.om`. `om/tls/sha2.om` is the existing streaming SHA API; no new cryptographic algorithm is needed.

tools/bring/build.sh

@@ -15,7 +15,7 @@ mkdir -p "$out"
1515 sha() { sha256sum "$1" | cut -d" " -f1; }
1616 [ "$(sha "$OMC")" = "$PIN" ] || { echo "build.sh: omc is not the pin" >&2; exit 2; }
1717 [ "$(sha "$SHA2")" = "$SHA2PIN" ] || { echo "build.sh: sha2.om is not the pin" >&2; exit 2; }
18-core() { cat "$SHA2" src/10base.om src/20walk.om src/30tar.om src/35enc.om src/40net.om src/90main.om; }
18+core() { cat "$SHA2" src/10base.om src/20walk.om src/30tar.om src/35enc.om src/40net.om src/50patch.om src/90main.om; }
1919 case $what in all|linux)
2020 { echo om2; core; cat src/plat-linux.om src/arch-a64.om; } > "$out/interplane-linux-aarch64.om"
2121 "$OMC" < "$out/interplane-linux-aarch64.om" > "$out/interplane-linux-aarch64"

tools/bring/src/10base.om

@@ -12,7 +12,7 @@ global gtmpok uchar 1
1212 global gavn ulong 1
1313 text tavlong "a program's argument list does not fit the 4096 bytes the process start word carries"
1414 text ttmpf "cannot open the temp file "
15-text tnames "reqh\nfiles\ndirs\nkeep\nlist.tar\nstmt\nstmt.sig\nchal\nchal.sig\nbody\nhdr\ncode\ncerr\nform\nget.tar\n"
15+text tnames "reqh\nfiles\ndirs\nkeep\nlist.tar\nstmt\nstmt.sig\nchal\nchal.sig\nbody\nhdr\ncode\ncerr\nform\nget.tar\nmbox\ngout\n"
1616
1717 fn wall fd int b view uchar * to bool
1818 n = ulong 0

tools/bring/src/40net.om

@@ -635,7 +635,8 @@ mustwrite fd part o 0 k
635635 end
636636 pl_close int src
637637 end
638-fn signin pk view uchar 32 to void
638+note signin0 pk: sign in (GET /login, the signed challenge, POST /login); the session cookie is kept
639+fn signin0 pk view uchar 32 to void
639640 put gprel 0 0
640641 put gsessl 0 0
641642 c = http tlogin false tbody
@@ -681,7 +682,10 @@ getcookie tsess 3
681682 if eq get gsessl 0 0
682683 die t403
683684 end
684-c = http topenp false tbody
685+end
686+note csrfof p: the session's write csrf, read from the page p
687+fn csrfof p view uchar * to void
688+c = http p false tbody
685689 if ne c 200
686690 checkhttp c
687691 end
@@ -689,6 +693,13 @@ cs2 = new uchar 4096 0
689693 k2 = mustval tcsrf 34 cs2
690694 gset 4 part cs2 0 k2
691695 end
696+note signin pk: sign in, then take the write csrf from GET /open/ (bring, withdraw). interplane patch
697+note takes it from /settings instead (50patch.om): a store-reading forge answers /open/ with its 503
698+note "moving" page, and the session's settings page carries the same token on every build
699+fn signin pk view uchar 32 to void
700+signin0 pk
701+csrfof topenp
702+end
692703 fn formenc fd int s view uchar * to void
693704 o = new uchar 12288 0
694705 k = formw s o 0

tools/bring/src/50patch.om

new file mode 100644
@@ -0,0 +1,760 @@
1+note tools/bring/src/50patch.om: interplane patch [--base REF] [--title T] [--message-file F] [--yes]
2+note OWNER/REPO. Run inside a git work tree. It resolves the base (default: the merge base of HEAD
3+note and refs/remotes/origin/main), builds the mbox with /usr/bin/git format-patch (an argument list,
4+note no shell, an empty environment), shows what would be sent and sends only after --yes or the
5+note exact "yes" typed on /dev/tty: the key (made once, as bring makes it), the statement signed with
6+note namespace interplane-patch, the sign-in of bring, one POST to <base>/OWNER/REPO/patches/new.
7+note Exit 0 sent (the patch page is printed), 1 nothing sent, 2 the server refused it (its reason
8+note is printed). The key never leaves this computer; the forge never signs for anyone.
9+text tqprog "/usr/bin/git"
10+text tqrp "rev-parse"
11+text tqiw "--is-inside-work-tree"
12+text tqtrue "true"
13+text tqver "--verify"
14+text tqqt "--quiet"
15+text tqeoo "--end-of-options"
16+text tqcmt "^{commit}"
17+text tqhd "HEAD"
18+text tqmb "merge-base"
19+text tqorg "refs/remotes/origin/main"
20+text tqfp "format-patch"
21+text tqso "--stdout"
22+text tqo1 "--no-color"
23+text tqo2 "--no-ext-diff"
24+text tqo3 "--no-textconv"
25+text tqo4 "--no-attach"
26+text tqo5 "--no-thread"
27+text tqo6 "--no-cover-letter"
28+text tqo7 "--src-prefix=a/"
29+text tqo8 "--dst-prefix=b/"
30+text tqo9 "--no-signature"
31+text tqo10 "--no-relative"
32+text tqo11 "--no-notes"
33+text tqrl "rev-list"
34+text tqcnt "--count"
35+text tqdf "diff"
36+text tqnmo "--name-only"
37+text tqz "-z"
38+text tqlog "log"
39+text tqm1 "-1"
40+text tqfs "--format=%s"
41+text tqdots ".."
42+text tqmbox "mbox"
43+text tqgout "gout"
44+text tqfb "--base"
45+text tqft "--title"
46+text tqfm "--message-file"
47+text tqfy "--yes"
48+text tqns "interplane-patch"
49+text tqst1 "interplane-patch 1\n"
50+text tqslash "/"
51+text tqpnew "/patches/new"
52+text tqfrepo "&repo="
53+text tqfbase "&base="
54+text tqfttl "&title="
55+text tqfdsc "&description="
56+text tqfmbx "&mbox="
57+text tqfsig "&sig="
58+text tqpath "path "
59+text tqrefu "refused: "
60+text tqusage "usage: interplane patch [--base REF] [--title T] [--message-file F] [--yes] OWNER/REPO"
61+text tqnowt "this folder is not inside a git work tree"
62+text tqnohd "this work tree has no commit at HEAD"
63+text tqnobs "cannot find the remote's main (refs/remotes/origin/main); name the base with --base REF"
64+text tqbadb "the --base value does not name a commit here"
65+text tqnone "there is no commit between the base and HEAD: nothing to send"
66+text tqmany "more than 100 commits between the base and HEAD: a patch holds at most 100"
67+text tqbig "the patch is larger than 2097152 bytes: nothing sent"
68+text tqgit "git could not build the patch"
69+text tqttlb "the title must be 1 to 256 bytes on one line; give one with --title"
70+text tqdscb "the message file must hold at most 60000 bytes"
71+text tqdscf "cannot read the message file"
72+text tqs1 "Repository: "
73+text tqs2 "Base: "
74+text tqs3 "Commits: "
75+text tqs4 "Files changed: "
76+text tqs5 "Bytes: "
77+text tqs6 "Title: "
78+text tqs7 "Send to: "
79+text tqask "Type yes to send this patch, anything else to stop:\n"
80+text tqpage "Patch page: "
81+text tqhave "Interplane already has this patch.\n"
82+text tqref "Interplane refused the patch: "
83+text tqno "Nothing sent.\n"
84+text tqsetp "/settings"
85+global gqrepo uchar 256
86+global gqrepol ulong 1
87+global gqbref uchar 4096
88+global gqbrefl ulong 1
89+global gqmsgf uchar 4096
90+global gqmsgfl ulong 1
91+global gqbase uchar 40
92+global gqttl uchar 256
93+global gqttll ulong 1
94+global gqdsc uchar 60000
95+global gqdscl ulong 1
96+global gqyes ulong 1
97+global gqncm ulong 1
98+global gqnfl ulong 1
99+global gqbytes ulong 1
100+note ---- arguments
101+fn ptrepoc c uchar to bool
102+if isaln c
103+ret true
104+end
105+ret or or eq c 45 eq c 46 eq c 95
106+end
107+note ptrepo: OWNER/REPO: two names of letters, digits, '.', '-' and '_' around one slash
108+fn ptrepo a view uchar * to void
109+sl = ulong 0
110+ns = ulong 0
111+for i ulong len a bound 256
112+c = get a i
113+if eq c 47
114+ns = add ns 1
115+sl = i
116+else
117+if not ptrepoc c
118+die tqusage
119+end
120+end
121+end
122+if or ne ns 1 eq sl 0
123+die tqusage
124+end
125+if or eq add sl 1 len a eq get a 0 46
126+die tqusage
127+end
128+if eq get a add sl 1 46
129+die tqusage
130+end
131+for i ulong len a bound 256
132+put gqrepo i get a i
133+end
134+put gqrepol 0 len a
135+end
136+fn ptflag a view uchar * t view uchar * to bool
137+ret beq a t
138+end
139+note ptval i ac w: the value of the flag at argument i (the next argument) into its global: w 0
140+note --base (no leading '-'), 1 --title (1..256 bytes), 2 --message-file
141+fn ptval i ulong ac ulong w ulong to void
142+a = new uchar 4096 0
143+if ge add i 1 ac
144+die tqusage
145+end
146+n = getarg add i 1 a
147+if eq n 0
148+die tqusage
149+end
150+if eq w 0
151+if eq get a 0 45
152+die tqbadb
153+end
154+for k ulong n bound 4096
155+put gqbref k get a k
156+end
157+put gqbrefl 0 n
158+end
159+if eq w 1
160+if gt n 256
161+die tqttlb
162+end
163+for k ulong n bound 256
164+put gqttl k get a k
165+end
166+put gqttll 0 n
167+end
168+if eq w 2
169+for k ulong n bound 4096
170+put gqmsgf k get a k
171+end
172+put gqmsgfl 0 n
173+end
174+end
175+note ptargs: ac counts the program and "patch". The tool takes at most 8 arguments after "patch"
176+note (--base REF, --title T, --message-file F, --yes, OWNER/REPO): more is the usage line (exit 1),
177+note answered before the loop, so the loop runs at most 8 times whatever the argument count.
178+fn ptargs ac ulong to void
179+if gt ac 10
180+die tqusage
181+end
182+a = new uchar 4096 0
183+got = false
184+i = ulong 2
185+while lt i ac bound 8
186+n = getarg i a
187+w = ulong 9
188+if ptflag part a 0 n tqfb
189+w = ulong 0
190+end
191+if ptflag part a 0 n tqft
192+w = ulong 1
193+end
194+if ptflag part a 0 n tqfm
195+w = ulong 2
196+end
197+if ptflag part a 0 n tqfy
198+w = ulong 3
199+end
200+if lt w 3
201+ptval i ac w
202+i = add i 1
203+end
204+if eq w 3
205+put gqyes 0 1
206+end
207+if eq w 9
208+if or got eq n 0
209+die tqusage
210+end
211+if or eq get a 0 45 gt n 200
212+die tqusage
213+end
214+ptrepo part a 0 n
215+got = true
216+end
217+i = add i 1
218+end
219+if not got
220+die tqusage
221+end
222+end
223+note ---- git: an argument list, standard output into the temp file gout (or mbox), no shell
224+note gitline: the first line of gout into o; its length
225+fn gitline o edit uchar 4096 to ulong
226+fd = topen tqgout 0
227+n = read fd o 0 4096
228+pl_close fd
229+if lt n 0
230+die terrio
231+end
232+k = ulong 0
233+while lt k ulong n bound 4096
234+if eq get o k 10
235+break
236+end
237+k = add k 1
238+end
239+ret k
240+end
241+fn ishex40 o view uchar * to bool
242+if ne len o 40
243+ret false
244+end
245+for i ulong 40
246+c = get o i
247+h = or isdig c and ge c 97 le c 102
248+if not h
249+ret false
250+end
251+end
252+ret true
253+end
254+note gitcommit ref eoo: rev-parse --verify --quiet [--end-of-options] <ref>^{commit}: the 40 hex
255+note digits into o; false when ref names no commit
256+fn gitcommit ref view uchar * eoo bool o edit uchar 40 to bool
257+a = new uchar 4096 0
258+q = new uchar 4200 0
259+l = new uchar 4096 0
260+avinit a
261+avadd a tqprog
262+avadd a tqrp
263+avadd a tqver
264+avadd a tqqt
265+if eoo
266+avadd a tqeoo
267+end
268+n = cpy q 0 ref
269+n = cpy q n tqcmt
270+avadd a part q 0 n
271+if ne runprog a tqgout 0
272+ret false
273+end
274+k = gitline l
275+if not ishex40 part l 0 k
276+ret false
277+end
278+for i ulong 40
279+put o i get l i
280+end
281+ret true
282+end
283+note ptrange: "<base>..HEAD" into q; its length
284+fn ptrange q edit uchar 64 to ulong
285+for i ulong 40
286+put q i get gqbase i
287+end
288+n = cpy q 40 tqdots
289+ret cpy q n tqhd
290+end
291+fn ptbase to void
292+b = new uchar 40 0
293+a = new uchar 4096 0
294+l = new uchar 4096 0
295+r = new uchar 4096 0
296+if gt get gqbrefl 0 0
297+n = get gqbrefl 0
298+for i ulong n bound 4096
299+put r i get gqbref i
300+end
301+if not gitcommit part r 0 n true b
302+die tqbadb
303+end
304+else
305+avinit a
306+avadd a tqprog
307+avadd a tqmb
308+avadd a tqhd
309+avadd a tqorg
310+if ne runprog a tqgout 0
311+die tqnobs
312+end
313+k = gitline l
314+if not ishex40 part l 0 k
315+die tqnobs
316+end
317+for i ulong 40
318+put b i get l i
319+end
320+end
321+for i ulong 40
322+put gqbase i get b i
323+end
324+end
325+note ptcount: the commits of base..HEAD (1..100)
326+fn ptcount to void
327+a = new uchar 4096 0
328+l = new uchar 4096 0
329+q = new uchar 64 0
330+v = new ulong 1 0
331+avinit a
332+avadd a tqprog
333+avadd a tqrl
334+avadd a tqcnt
335+n = ptrange q
336+avadd a part q 0 n
337+if ne runprog a tqgout 0
338+die tqgit
339+end
340+k = gitline l
341+if not pdec part l 0 k v
342+die tqgit
343+end
344+if eq get v 0 0
345+die tqnone
346+end
347+if gt get v 0 100
348+die tqmany
349+end
350+put gqncm 0 get v 0
351+end
352+note ptmbox: git format-patch --stdout base..HEAD into the temp file mbox; its size in gqbytes
353+fn ptmbox to void
354+a = new uchar 4096 0
355+q = new uchar 64 0
356+st = new uchar 256 0
357+avinit a
358+avadd a tqprog
359+avadd a tqfp
360+avadd a tqso
361+avadd a tqo1
362+avadd a tqo2
363+avadd a tqo3
364+avadd a tqo4
365+avadd a tqo5
366+avadd a tqo6
367+avadd a tqo7
368+avadd a tqo8
369+avadd a tqo9
370+avadd a tqo10
371+avadd a tqo11
372+n = ptrange q
373+avadd a part q 0 n
374+if ne runprog a tqmbox 0
375+die tqgit
376+end
377+fd = topen tqmbox 0
378+if lt pl_fstat fd st 0
379+die terrio
380+end
381+pl_close fd
382+sz = pl_size st
383+if gt sz 2097152
384+die tqbig
385+end
386+put gqbytes 0 sz
387+end
388+note ptfiles: the files base and HEAD differ in (the names of git diff --name-only -z, counted)
389+fn ptfiles to void
390+a = new uchar 4096 0
391+b = new uchar 65536 0
392+avinit a
393+avadd a tqprog
394+avadd a tqdf
395+avadd a tqnmo
396+avadd a tqz
397+for i ulong 40
398+put b i get gqbase i
399+end
400+avadd a part b 0 40
401+avadd a tqhd
402+if ne runprog a tqgout 0
403+die tqgit
404+end
405+fd = topen tqgout 0
406+c = ulong 0
407+while true bound 9223372036854775807
408+r = read fd b 0 65536
409+if eq r -4
410+continue
411+end
412+if lt r 0
413+die terrio
414+end
415+if eq r 0
416+break
417+end
418+for i ulong ulong r bound 65536
419+if eq get b i 0
420+c = add c 1
421+end
422+end
423+end
424+pl_close fd
425+put gqnfl 0 c
426+end
427+note pttitle: the title: --title, else the subject of the HEAD commit; 1..256 bytes, no control byte
428+fn pttitle to void
429+a = new uchar 4096 0
430+l = new uchar 4096 0
431+if eq get gqttll 0 0
432+avinit a
433+avadd a tqprog
434+avadd a tqlog
435+avadd a tqm1
436+avadd a tqfs
437+avadd a tqhd
438+if ne runprog a tqgout 0
439+die tqgit
440+end
441+k = gitline l
442+if or eq k 0 gt k 256
443+die tqttlb
444+end
445+for i ulong k bound 256
446+put gqttl i get l i
447+end
448+put gqttll 0 k
449+end
450+for i ulong get gqttll 0 bound 256
451+c = get gqttl i
452+if or lt c 32 eq c 127
453+die tqttlb
454+end
455+end
456+end
457+note ptdesc: the description from --message-file (none: empty): carriage returns dropped, blanks
458+note and line feeds at the end trimmed, at most 60000 bytes
459+fn ptdesc to void
460+p = new uchar 4096 0
461+b = new uchar 65536 0
462+put gqdscl 0 0
463+n = get gqmsgfl 0
464+if eq n 0
465+ret
466+end
467+for i ulong n bound 4096
468+put p i get gqmsgf i
469+end
470+fd = pl_open part p 0 n 4 0
471+if lt fd 0
472+die tqdscf
473+end
474+k = ulong 0
475+while true bound 9223372036854775807
476+r = read int fd b 0 65536
477+if eq r -4
478+continue
479+end
480+if lt r 0
481+die tqdscf
482+end
483+if eq r 0
484+break
485+end
486+for i ulong ulong r bound 65536
487+c = get b i
488+if ne c 13
489+if ge k 60000
490+die tqdscb
491+end
492+put gqdsc k c
493+k = add k 1
494+end
495+end
496+end
497+pl_close int fd
498+while gt k 0 bound 60000
499+c = get gqdsc sub k 1
500+if and and ne c 10 ne c 32 ne c 9
501+break
502+end
503+k = sub k 1
504+end
505+put gqdscl 0 k
506+end
507+note ---- what would be sent
508+fn ptshow to void
509+t = new uchar 4096 0
510+n = get gqrepol 0
511+for i ulong n bound 256
512+put t i get gqrepo i
513+end
514+say tqs1
515+say part t 0 n
516+say tnl
517+for i ulong 40
518+put t i get gqbase i
519+end
520+say tqs2
521+say part t 0 40
522+say tnl
523+say tqs3
524+sayd get gqncm 0
525+say tnl
526+say tqs4
527+sayd get gqnfl 0
528+say tnl
529+say tqs5
530+sayd get gqbytes 0
531+say tnl
532+n = get gqttll 0
533+for i ulong n bound 256
534+put t i get gqttl i
535+end
536+say tqs6
537+sayp part t 0 n
538+say tnl
539+n = gcopy 0 t
540+say tqs7
541+say part t 0 n
542+say tnl
543+end
544+note ---- the statement: "interplane-patch 1\n<owner>/<repo>\n<base>\n<sha256 of the mbox>\n<sha256 of
545+note title, line feed, description>\n" into the temp file stmt
546+fn ptstmt to void
547+d = new uchar 32 0
548+x = new uchar 64 0
549+t = new uchar 60300 0
550+fd = topen tqmbox 0
551+shafd fd d
552+pl_close fd
553+k = hexw d x 0
554+fd = tmpfd tstmt
555+mustwrite fd tqst1
556+n = get gqrepol 0
557+for i ulong n bound 256
558+put t i get gqrepo i
559+end
560+mustwrite fd part t 0 n
561+mustwrite fd tnl
562+for i ulong 40
563+put t i get gqbase i
564+end
565+mustwrite fd part t 0 40
566+mustwrite fd tnl
567+mustwrite fd x
568+mustwrite fd tnl
569+n = get gqttll 0
570+for i ulong n bound 256
571+put t i get gqttl i
572+end
573+put t n 10
574+m = get gqdscl 0
575+for i ulong m bound 60000
576+put t add add n 1 i get gqdsc i
577+end
578+y = sha2_digest 256 part t 0 add add n 1 m d
579+k = hexw d x 0
580+mustwrite fd x
581+mustwrite fd tnl
582+pl_close fd
583+end
584+note ---- the form: csrf, repo, base, title, description, mbox (base64url, no padding), sig
585+fn ptfdesc fd int to void
586+b = new uchar 4096 0
587+n = get gqdscl 0
588+p = ulong 0
589+while lt p n bound 60000
590+k = sub n p
591+if gt k 4096
592+k = ulong 4096
593+end
594+for i ulong k bound 4096
595+put b i get gqdsc add p i
596+end
597+formenc fd part b 0 k
598+p = add p k
599+end
600+end
601+fn ptfmbox fd int to void
602+b = new uchar 45000 0
603+e = new uchar 60000 0
604+src = topen tqmbox 0
605+while true bound 9223372036854775807
606+k = ulong 0
607+while lt k 45000 bound 9223372036854775807
608+r = read src b k sub 45000 k
609+if eq r -4
610+continue
611+end
612+if lt r 0
613+die terrio
614+end
615+if eq r 0
616+break
617+end
618+k = add k ulong r
619+end
620+if eq k 0
621+break
622+end
623+el = b64u part b 0 k e
624+mustwrite fd part e 0 el
625+if lt k 45000
626+break
627+end
628+end
629+pl_close src
630+end
631+fn ptform to void
632+t = new uchar 4096 0
633+fd = tmpfd tform
634+csrfform fd
635+mustwrite fd tqfrepo
636+n = get gqrepol 0
637+for i ulong n bound 256
638+put t i get gqrepo i
639+end
640+formenc fd part t 0 n
641+mustwrite fd tqfbase
642+for i ulong 40
643+put t i get gqbase i
644+end
645+mustwrite fd part t 0 40
646+mustwrite fd tqfttl
647+n = get gqttll 0
648+for i ulong n bound 256
649+put t i get gqttl i
650+end
651+formenc fd part t 0 n
652+mustwrite fd tqfdsc
653+ptfdesc fd
654+mustwrite fd tqfmbx
655+ptfmbox fd
656+mustwrite fd tqfsig
657+formsig fd tstsig
658+pl_close fd
659+end
660+note ptsend: POST the form. A 429 (the write gate: 30 writes a minute) sends the same form again at
661+note most 3 times, after 2, 4 and 8 seconds (4 POSTs and 14 seconds of waiting at most; the tool
662+note reads no Retry-After); a 429 after that is a refusal like any other code. 201 and 200 print the
663+note patch page and return; anything else prints the server's reason in one line and leaves with
664+note status 2.
665+fn ptsend to void
666+p = new uchar 4096 0
667+v = new uchar 4096 0
668+e = new uchar 24 0
669+n = cpy p 0 tqslash
670+m = get gqrepol 0
671+for i ulong m bound 256
672+put p add n i get gqrepo i
673+end
674+n = cpy p add n m tqpnew
675+c = http part p 0 n true tbody
676+w = ulong 2
677+while and eq c 429 le w 8 bound 3
678+for i ulong w bound 8
679+pl_sleep
680+end
681+c = http part p 0 n true tbody
682+w = mul w 2
683+end
684+if or eq c 201 eq c 200
685+k = mustval tqpath 10 v
686+if eq c 200
687+say tqhave
688+end
689+say tqpage
690+m = gcopy 0 p
691+say part p 0 m
692+say part v 0 k
693+say tnl
694+ret
695+end
696+r = fval tbody tqrefu 10
697+warn tpfx
698+if ge r 0
699+for i ulong ulong r bound 4096
700+put v i get gval i
701+end
702+warn tqref
703+warn part v 0 ulong r
704+else
705+k = decw c e 0
706+warn thttpbad
707+warn part e 0 k
708+end
709+warn tnl
710+cleanup
711+exit 2
712+end
713+note patchflow: the whole command; ac is the argument count. Returns the exit status 0 or 1.
714+fn patchflow ac ulong to int
715+pk = new uchar 32 0
716+a = new uchar 4096 0
717+l = new uchar 4096 0
718+h = new uchar 40 0
719+ptargs ac
720+tmpsetup
721+setbase
722+avinit a
723+avadd a tqprog
724+avadd a tqrp
725+avadd a tqiw
726+if ne runprog a tqgout 0
727+die tqnowt
728+end
729+k = gitline l
730+if not beq part l 0 k tqtrue
731+die tqnowt
732+end
733+if not gitcommit tqhd false h
734+die tqnohd
735+end
736+ptbase
737+ptcount
738+ptmbox
739+ptfiles
740+pttitle
741+ptdesc
742+ptshow
743+if eq get gqyes 0 0
744+if not consent tqask
745+say tqno
746+cleanup
747+ret 1
748+end
749+end
750+makekey
751+readpk pk
752+ptstmt
753+sign tstmt tqns
754+signin0 pk
755+csrfof tqsetp
756+ptform
757+ptsend
758+cleanup
759+ret 0
760+end

tools/bring/src/90main.om

@@ -3,8 +3,9 @@ text tget "get"
33 text twithdr "withdraw"
44 text tpack "pack"
55 text tunpack "unpack"
6+text tpatch "patch"
67 text tvarg "--version"
7-text tusage "usage: interplane bring [folder] | get <page or rid> | withdraw <page or rid> | pack <folder> <archive> | unpack <archive> <folder>"
8+text tusage "usage: interplane bring [folder] | get <page or rid> | withdraw <page or rid> | patch [--base REF] [--title T] [--message-file F] [--yes] OWNER/REPO | pack <folder> <archive> | unpack <archive> <folder>"
89 text tconsent "Your project will be published on an open network called Radicle, through Interplane.\nPublishing is permanent: copies may stay on other computers even if you withdraw it later.\nType yes to publish it, anything else to stop:\n"
910 text ttty "/dev/tty"
1011 text tyes "yes"
@@ -85,6 +86,9 @@ if beq part cmd 0 n tvarg
8586 say tver
8687 ret 0
8788 end
89+if beq part cmd 0 n tpatch
90+ret patchflow ulong ac
91+end
8892 if beq part cmd 0 n tunpack
8993 if ne ac 4
9094 die tusage

tools/bring/tests/run.sh

@@ -11,6 +11,7 @@
1111 # the installer generator and the scripts it writes (the same busy rule for their download);
1212 # withdraw: the key, the bringer check, the text and the yes before anything is sent, the POST, the
1313 # poll until 404;
14+# patch against a 429: at most 3 resends (2, 4, 8 s), then the server's reason and exit 2;
1415 # the x86_64 build under qemu (EMULATED);
1516 # mutants: each removes one guard and the check that guards it must fail.
1617 # Process and network audit uses strace -f (execve, connect): an outside oracle, not part of the tool.
@@ -407,6 +408,38 @@ out=$(run "$T" "$T/h1" 'yes\n' "$T/stw5" "$IP" withdraw "$WR" 2>&1); st=$?
407408 && ok "withdraw: a 303 to /login is reported as signed out (status 1, no poll)" || bad "withdraw signout: $st $out"
408409 rm -f "$T/hub/signout"
409410
411+# ------------------------------------------------------------------ patch: the write gate's 429
412+# patch sends the same form again at most 3 times on a 429 (after 2, 4 and 8 seconds), then prints the
413+# server's reason in one line and exits 2; other codes stop at once. The stand-in counts the POSTs.
414+G=$T/pg; mkdir -p "$G"
415+gc() { git -c user.name=T -c user.email=t@example.invalid "$@"; }
416+(cd "$G" && git init -q -b main && echo one > a.txt && git add a.txt && gc commit -qm base \
417+ && git update-ref refs/remotes/origin/main HEAD && echo two >> a.txt && gc commit -qam "a: second line") \
418+ || bad "patch: the test repository was not made"
419+GATE='too many writes from this address or key; wait a minute'
420+ptposts() { grep -c '^POST /alice/demo/patches/new ' "$T/hub/log" 2>/dev/null; }
421+# ptrun TRACE [RUNTO]: ${PT:-$IP} patch --yes alice/demo in $G; sets out (no CRs), st and el (seconds)
422+ptrun() {
423+ rm -f "$T/hub/log" "$T/hub/patch.form"; local t0=$SECONDS
424+ out=$(RUNTO=${2:-60} run "$G" "$T/h1" '' "$1" "${PT:-$IP}" patch --yes alice/demo 2>&1); st=$?
425+ el=$((SECONDS - t0)); out=$(printf '%s\n' "$out" | tr -d '\r')
426+}
427+printf '429+' > "$T/hub/busyq"; ptrun "$T/stq1"; n=$(ptposts)
428+[ "$st" = 2 ] && [ "$n" = 4 ] && [ "$el" -ge 14 ] && [ "$el" -le 40 ] && [ ! -e "$T/hub/patch.form" ] \
429+ && [ "$(printf '%s\n' "$out" | grep -c "^interplane: Interplane refused the patch: $GATE\$")" = 1 ] \
430+ && [ "$(printf '%s\n' "$out" | grep -c 'refused\|HTTP')" = 1 ] \
431+ && ok "patch: a server that always answers 429 gets 4 POSTs in ${el}s (waits 2, 4, 8), then one line with its reason, status 2" \
432+ || bad "patch always-429: status $st, $n POSTs, ${el}s, out: $(printf '%s' "$out" | tr '\n' '|')"
433+printf 429 > "$T/hub/busyq"; ptrun "$T/stq2"; n=$(ptposts)
434+[ "$st" = 0 ] && [ "$n" = 2 ] && [ "$el" -ge 2 ] && [ "$(field "$T/hub/patch.form" repo)" = alice/demo ] \
435+ && case $out in *"Patch page: "*"/alice/demo/patches/1"*) true;; *) false;; esac \
436+ && ok "patch: 429 once, then 201: 2 POSTs, the form kept, the patch page printed, status 0" \
437+ || bad "patch 429-then-201: status $st, $n POSTs, ${el}s, out: $(printf '%s' "$out" | tr '\n' '|')"
438+printf 409 > "$T/hub/busyq"; ptrun "$T/stq3"; n=$(ptposts)
439+[ "$st" = 2 ] && [ "$n" = 1 ] && case $out in *"Interplane answered with HTTP 409"*) true;; *) false;; esac \
440+ && ok "patch: another code (409) is not sent again: 1 POST, status 2" || bad "patch 409: status $st, $n POSTs, out: $(printf '%s' "$out" | tr '\n' '|')"
441+rm -f "$T/hub/busyq"
442+
410443 # ------------------------------------------------------------------ installer
411444 I=$T/inst; mkdir -p "$I/bin" "$I/run"
412445 cp "$IP" "$I/interplane-linux-aarch64"
@@ -583,6 +616,12 @@ mut wdloc 40net.om 'if wdopen part lo 0 ln=>if true' && {
583616 wjson "$did"; rm -f "$T/hub/withdraw.form" "$T/hub/gone"; touch "$T/hub/signout"
584617 out=$(RUNTO=10 run "$T" "$T/h1" 'yes\n' "$T/stm8" "$M" withdraw "$WR" 2>&1); st=$?; rm -f "$T/hub/signout"
585618 case "$st:$out" in "1:"*"signed you out"*) bad "mutant wdloc still stopped";; *) ok "MUTANT accepting any 303 does not stop on a 303 to /login (status $st)";; esac; } || bad "mutant wdloc did not build"
619+# the patch 429 loop as it was (a second apart, no count): the always-429 control must fail (30 s cap)
620+mut ptcap 50patch.om 'w = ulong 2|while and eq c 429 le w 8 bound 3|for i ulong w bound 8|pl_sleep|end|c = http part p 0 n true tbody|w = mul w 2|end=>while eq c 429 bound 9223372036854775807|pl_sleep|c = http part p 0 n true tbody|end' && {
621+ printf '429+' > "$T/hub/busyq"; PT=$M ptrun "$T/stm9" 30; n=$(ptposts)
622+ pkill -f "^$T/m/out/" 2>/dev/null; rm -f "$T/hub/busyq"
623+ [ "$st" != 2 ] && [ "$n" -gt 4 ] && ok "MUTANT with the unbounded patch 429 loop fails the always-429 control (status $st, $n POSTs in ${el}s)" \
624+ || bad "mutant ptcap still stopped: status $st, $n POSTs"; } || bad "mutant ptcap did not build"
586625
587626 stopall
588627 echo "TOOL TESTS pass=$PASS fail=$FAIL"

tools/bring/tests/standin.om

@@ -19,6 +19,10 @@ note DIR/withdraw.form, answers 303 with Location: /open/ and writes DIR/gone =
1919 note JSON GET still serves DIR/shelf.json (the intake has not run yet) and sets it to "2"; from then on
2020 note the JSON is 404. When DIR/signout exists it answers 303 with Location: /login and saves nothing
2121 note (the hub when the session is gone).
22+note Patch: POST /alice/demo/patches/new (session and csrf as for /open/up) is answered from DIR/busyq,
23+note 3-digit codes as in DIR/busyp: a 429 with the forge's write-gate reason ("refused: too many
24+note writes ..."), any other code with an empty body; no code saves the form to DIR/patch.form and
25+note answers 201 with "path /alice/demo/patches/1". Every POST is one line of DIR/log.
2226 text tserve "serve"
2327 text tcount "count"
2428 text tlog "log"
@@ -35,6 +39,12 @@ text tbusyj "busyj"
3539 text tbusyt "busyt"
3640 text tbusyp "busyp"
3741 text tbusyf "busyf"
42+text tbusyq "busyq"
43+text tptform "patch.form"
44+text tpostpt "POST /alice/demo/patches/new "
45+text tgetset "GET /settings "
46+text tptpath "path /alice/demo/patches/1\n"
47+text tptgate "refused: too many writes from this address or key; wait a minute\n"
3848 text tgone "gone"
3949 text twdform "withdraw.form"
4050 text tpostop "POST /open/ "
@@ -432,6 +442,18 @@ if bat part rq 0 n 0 tgetup
432442 status fd
433443 ret
434444 end
445+if bat part rq 0 n 0 tgetset
446+answer fd 200 1 0 topage
447+ret
448+end
449+if bat part rq 0 n 0 tpostpt
450+if not has rq n tcsrf2
451+answer fd 403 0 0 part tlog 0 0
452+ret
453+end
454+postpt rq fd n
455+ret
456+end
435457 answer fd 404 0 0 part tlog 0 0
436458 end
437459 note public: the shelf JSON and the archive need no session (as forged serves them)
@@ -475,15 +497,24 @@ ret true
475497 end
476498 note busyans: the first 3-digit code in DIR/nm, answered with an empty body; true when one was sent
477499 fn busyans fd int nm view uchar * to bool
500+c = busycode nm
501+if eq c 0
502+ret false
503+end
504+answer fd c 0 0 part tlog 0 0
505+ret true
506+end
507+note busycode: the first 3-digit code in DIR/nm, dropped unless a "+" follows it; 0 when there is none
508+fn busycode nm view uchar * to ulong
478509 f = fopen nm 0 len nm 524290 0
479510 if lt f 0
480-ret false
511+ret 0
481512 end
482513 b = new uchar 4096 0
483514 r = read int f b 0 len b
484515 if lt r 3
485516 x = fclose int f
486-ret false
517+ret 0
487518 end
488519 k = ulong r
489520 c = decat part b 0 3 0
@@ -492,8 +523,21 @@ w = pwrite int f b 3 sub k 3 0
492523 t = ftrunc int f long sub k 3
493524 end
494525 x = fclose int f
526+ret c
527+end
528+note postpt: the patch upload; DIR/busyq first (a 429 carries the write gate's reason line)
529+fn postpt rq edit uchar * fd int n ulong to void
530+c = busycode tbusyq
531+if eq c 429
532+answer fd 429 0 0 tptgate
533+ret
534+end
535+if ne c 0
495536 answer fd c 0 0 part tlog 0 0
496-ret true
537+ret
538+end
539+savebody rq n tptform
540+answer fd 201 0 0 tptpath
497541 end
498542 fn origin rq edit uchar * n ulong port ulong to bool
499543 o = new uchar 64 0

visits/README.md

@@ -16,7 +16,7 @@ log). Not installed as a service.
1616 | `visits.css` | the page's stylesheet; colours only through `tokens.css` |
1717
1818 ```sh
19-OMV=$HOME/work/flux/omega-mv; OMC=$OMV/seed/out/omc # omc sha256 3ad9f10f…93194
19+OMV=$HOME/canon/omega-mv; OMC=$OMV/seed/out/omc # the omc whose sha256 is PIN in visits/tests/run.sh
2020 $OMC < visits/visits.om > visits
2121 { printf 'om2\n'; cat $OMV/seed/net/http.om $OMV/seed/net/notls.om visits/owner.om; } | $OMC > owner
2222 ./visits ~/forge-data/logs/forged.log # writes visits.tsv and visits.html in the working directory
@@ -34,12 +34,16 @@ and last request. `visits.tsv` carries the same figures as `T`, `A`, `D`, `P` an
3434
3535 forged logs the request's `User-Agent` and `Referer` as fields 8 and 9 (at most 200 bytes each, a
3636 space as `+`, `-` when absent); lines written before that have seven fields and still count. A
37-named crawler is a request whose agent says `bot`, `crawl`, `spider` or `slurp` in any letter case;
38-any other name counts as a browser or tool. The name is whatever the client sent: a tool can call
39-itself a browser, so the split is a lower bound on crawlers, not proof of people. An address that
40-ever used a crawler name is listed as a crawler. The `A` line is: requests from named crawlers,
41-from other names, with no name, from seven-field lines, then visitors that are named crawlers and
42-visitors that are other names; each `V` line ends with `c`, `o` or `-`.
37+crawler or tool is a request whose agent contains one of the words of `kws` in `visits.om`, in
38+any letter case (among them `bot`, `crawl`, `googleother`, `curl` and `python`; `kws` is the list,
39+and the gate checks its own copy against it). Any
40+other name counts as a browser. The name is whatever the client sent: a tool can call itself a
41+browser, so the split is a lower bound on crawlers and tools, not proof of people. An address that
42+ever used a crawler or tool name is listed as one. The list came from the log: on the first minutes
43+of agent logging (2026-11-09) Google's general crawler, which calls itself `GoogleOther`, was 525
44+of 553 named requests and has none of the four usual words in it. The `A` line is: requests from
45+crawlers and tools, from browsers, with no name, from seven-field lines, then visitors that are
46+crawlers or tools and visitors that are browsers; each `V` line ends with `c`, `o` or `-`.
4347
4448 Limits: 65,536 visitors, 8,192 projects, 512 days, a line of at most 4,095 bytes; a visitor or
4549 project that does not fit its table is counted under "not listed" on the page. A request whose UTC day is
@@ -78,16 +82,18 @@ remove `~/forge-data/owner`.
7882 ## Gates
7983
8084 ```sh
81-sh visits/tests/run.sh # the reducer: RESULT pass=30 fail=0
82-bash visits/tests/owner.sh # the server: RESULT pass=27 fail=0 (127.0.0.1, port 18492)
85+sh visits/tests/run.sh # the reducer: prints RESULT pass=<count> fail=0 when every case holds
86+bash visits/tests/owner.sh # the server, on 127.0.0.1 port 18492: the same RESULT form
8387 ```
8488
8589 The reducer's oracle is awk, sort and uniq over the same 6,037-line log (6,000 requests, half of
8690 them in the seven-field form, 31 addresses, 9 projects, 37 lines of seven kinds that must be
8791 skipped); `visits.tsv` must equal it. Negative controls: a mutant that counts every request as a
8892 new daily visitor does not match, a mutant that drops the group marks does not show the grouped
89-total, and a mutant that matches crawler names in lower case only does not match. The page groups
90-digits in threes (1,417,491); `visits.tsv` keeps plain numbers. The
93+total, a mutant that matches names in lower case only does not match, and a mutant that tries only
94+the first word of the list is caught by a log with one request per word. Each word with its first
95+or its last byte removed must count as a browser, so a match that skips a byte fails. The page groups
96+digits in threes (1,417,491), checked on the total and on every day row; `visits.tsv` keeps plain numbers. The
9197 server gate compares the three files byte for byte (one of 405,000 bytes), checks the headers,
9298 404 and 405, and that six addresses outside loopback and the tailnet are refused; its negative
9399 control shows a mutant without the address rule does start on 0.0.0.0.

visits/tests/owner.sh

@@ -7,9 +7,9 @@
77 set -u
88 HERE=$(cd "$(dirname "$0")" && pwd)
99 V=$HERE/..
10-OMV=${OMV:-$HOME/work/flux/omega-mv}
10+OMV=${OMV:-$HOME/canon/omega-mv}
1111 OMC=${OMC:-$OMV/seed/out/omc}
12-PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
12+PIN=34d611ca0415eab1728d3234911d90e74af17ba9ab0c581d559f48274d7ca6d3
1313 PORT=${OWNER_TEST_PORT:-18492}
1414 T=$(mktemp -d) || exit 2
1515 pid=

visits/tests/run.sh

@@ -5,13 +5,13 @@
55 # the seven-field form (before forged logged the agent) and the rest with agent and referrer, with
66 # seven kinds of line that must be skipped, and requires visits.tsv to equal what awk, sort and uniq
77 # compute from the same log (the oracle never runs the program under test). Then the page and the
8-# file modes. Negative controls: a mutant that counts every request as a new visitor of its day, one
9-# that drops the group marks and one that matches crawler names in lower case only must not pass.
8+# file modes. Negative controls: each mutant at the end of this file changes one line of visits.om
9+# and must not pass.
1010 set -u
1111 HERE=$(cd "$(dirname "$0")" && pwd)
1212 V=$HERE/..
13-OMC=${OMC:-$HOME/work/flux/omega-mv/seed/out/omc}
14-PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
13+OMC=${OMC:-$HOME/canon/omega-mv/seed/out/omc}
14+PIN=34d611ca0415eab1728d3234911d90e74af17ba9ab0c581d559f48274d7ca6d3
1515 T=$(mktemp -d) || exit 2
1616 trap 'rm -rf "$T"' EXIT
1717 pass=0
@@ -38,8 +38,8 @@ awk 'BEGIN {
3838 t += (i * 7) % 61
3939 ip = (i % 31 < 4) ? sprintf("2001:db8::%x", i % 31) : sprintf("203.0.113.%d", i % 31)
4040 p = P[(i * 7 + int(i / 13)) % 10 + 1]; s = S[(i * 3) % 10 + 1]
41- split("Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) Mozilla/5.0+(X11;+Linux+x86_64)+Firefox/130.0 - AhrefsBOT/7.0 ExampleCRAWLer/1.0 Baiduspider+2 Yahoo!+Slurp curl/8.5.0", A, " ")
42- m = i % 31; ag = A[m % 8 + 1]; if (m == 9 && i % 2) ag = A[1]
41+ split("Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) Mozilla/5.0+(X11;+Linux+x86_64)+Firefox/130.0 - AhrefsBOT/7.0 ExampleCRAWLer/1.0 Baiduspider+2 Yahoo!+Slurp curl/8.5.0 Mozilla/5.0+(compatible;+GoogleOther) Mozilla/5.0+(Macintosh)+Version/17.0+Safari/605.1.15 python-requests/2.32.3 Mozilla/5.0+(X11;+Linux+x86_64)+HeadlessChrome/140.0.0.0+Safari/537.36", A, " ")
42+ m = i % 31; ag = A[m % 12 + 1]; if (m == 9 && i % 2) ag = A[1]
4343 if (i < 3000) printf "%d %s %d %s %s %d %d\n", t, ip, 1 + (i % 3 == 0), p, s, (i * 37) % 9000, i % 50
4444 else printf "%d %s %d %s %s %d %d %s %s\n", t, ip, 1 + (i % 3 == 0), p, s, (i * 37) % 9000, i % 50, ag, (i % 4) ? "-" : "https://example.org/a+page"
4545 if (i % 1000 == 500) print "forged: reloaded, public repos 30"
@@ -67,7 +67,7 @@ function key(p, q) { q = p; sub(/\?.*/, "", q); if (match(q, /^\/[^\/]*(\/[^\/
6767 pr[k]++; if (!((k, $2) in pu)) { pu[k, $2] = 1; pn[k]++ }
6868 if (NF == 7) un++
6969 else if ($8 == "-") nn++
70- else if (tolower($8) ~ /bot|crawl|spider|slurp/) { cr++; kind[$2] = "c" }
70+ else if (tolower($8) ~ /bot|crawl|spider|slurp|googleother|google-|mediapartners|feedfetcher|facebookexternalhit|preview|curl|wget|python|go-http|java\/|scrapy|httpclient|libwww|headless|okhttp|aiohttp|axios|node-fetch/) { cr++; kind[$2] = "c" }
7171 else { ot++; if (kind[$2] != "c") kind[$2] = "o" }
7272 }
7373 END {
@@ -90,7 +90,31 @@ eq "seven kinds of bad line were skipped" "$(grep '^T' "$T/want.tsv" | cut -f12)
9090 AL=$(grep '^A' "$T/want.tsv")
9191 eq "oracle saw all four kinds of request and both kinds of visitor" "$(printf '%s\n' "$AL" | awk -F'\t' '{ print ($2 > 0 && $3 > 0 && $4 > 0 && $5 == 3000 && $6 > 0 && $7 > 0) }')" 1
9292 eq "an address that used a crawler name and a browser name is a crawler" "$(grep -c "^V 203.0.113.9 .* c$" "$T/want.tsv")" 1
93-eq "page names a crawler and a browser or tool" "$(grep -c '<td>crawler</td></tr>' "$T/w/visits.html") $(grep -c '<td>browser or tool</td></tr>' "$T/w/visits.html")" "$(printf '%s\n' "$AL" | cut -f6) $(printf '%s\n' "$AL" | cut -f7)"
93+eq "page names crawlers or tools and browsers" "$(grep -c '<td>crawler or tool</td></tr>' "$T/w/visits.html") $(grep -c '<td>browser</td></tr>' "$T/w/visits.html")" "$(printf '%s\n' "$AL" | cut -f6) $(printf '%s\n' "$AL" | cut -f7)"
94+
95+# every word of the list, one request each in upper case inside other text; then two real browsers.
96+# The gate keeps its own copy of the words: a word altered in the program is then a failed case.
97+WORDS="bot crawl spider slurp googleother google- mediapartners feedfetcher facebookexternalhit preview curl wget python go-http java/ scrapy httpclient libwww headless okhttp aiohttp axios node-fetch"
98+NW=$(printf '%s\n' "$WORDS" | wc -w | tr -d ' ')
99+eq "the program's word list is the gate's" "$(sed -n 's/^text kws "\(.*\)"$/\1/p' "$V/visits.om")" "$WORDS"
100+n=0
101+for w in $WORDS; do n=$((n + 1)); printf '1794182400 10.1.0.%d 1 / 200 5 1 zz%szz -\n' "$n" "$(printf '%s' "$w" | tr 'a-z' 'A-Z')"; done >"$T/wlog"
102+printf '1794182400 10.2.0.1 1 / 200 5 1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/141.0.0.0+Safari/537.36 -\n' >>"$T/wlog"
103+printf '1794182400 10.2.0.2 1 / 200 5 1 Mozilla/5.0+(iPhone;+CPU+iPhone+OS+18_0+like+Mac+OS+X)+AppleWebKit/605.1.15+(KHTML,+like+Gecko)+Version/18.0+Mobile/15E148+Safari/604.1 -\n' >>"$T/wlog"
104+mkdir "$T/ww"
105+(cd "$T/ww" && "$T/visits" "$T/wlog")
106+eq "each word alone makes a crawler or tool; Chrome and Safari are browsers" "$(grep '^A' "$T/ww/visits.tsv")" "$(printf 'A\t%d\t2\t0\t0\t%d\t2' "$NW" "$NW")"
107+# near misses: each word without its last byte, then without its first, is a browser. A program
108+# that skips the first or last byte of a word would call all of these crawlers or tools.
109+n=0
110+for w in $WORDS; do
111+ n=$((n + 1)); u=$(printf '%s' "$w" | tr 'a-z' 'A-Z')
112+ printf '1794182400 10.3.0.%d 1 / 200 5 1 zz%szz -\n' "$n" "${u%?}"
113+ printf '1794182400 10.4.0.%d 1 / 200 5 1 zz%szz -\n' "$n" "${u#?}"
114+done >"$T/nlog"
115+mkdir "$T/nw"
116+(cd "$T/nw" && "$T/visits" "$T/nlog")
117+eq "a word missing its first or last byte is a browser" "$(grep '^A' "$T/nw/visits.tsv")" "$(printf 'A\t0\t%d\t0\t0\t0\t%d' $((2 * NW)) $((2 * NW)))"
94118 eq "files are for the owner only" "$(stat -c %a "$T/w/visits.tsv" "$T/w/visits.html" | tr '\n' ' ')" "600 600 "
95119 eq "no temporary file left" "$(ls "$T/w" | grep -c 'tmp$')" 0
96120 eq "page has no script" "$(grep -ci '<script' "$T/w/visits.html")" 0
@@ -104,6 +128,9 @@ eq "grouping oracle" "$(grp 1417491) $(grp 999) $(grp 1000) $(grp 0)" "1,417,491
104128 case "$(grp "$REQ")" in *,*) ok "fixture total has a group mark" ;; *) no "fixture total has a group mark" ;; esac
105129 eq "page shows the request count" "$(grep -c "<dt>Requests</dt><dd>$(grp "$REQ")</dd>" "$T/w/visits.html")" 1
106130 eq "tsv keeps plain numbers" "$(grep -c ',' "$T/w/visits.tsv")" 0
131+DG=$(grep '^D' "$T/want.tsv" | while IFS=' ' read -r _ d r u; do grep -c "<tr><td>$d</td><td>$(grp "$r")</td><td>$(grp "$u")</td></tr>" "$T/w/visits.html"; done | grep -c '^1$')
132+eq "page shows every day row grouped" "$DG" "$(grep -c '^D' "$T/want.tsv")"
133+case "$(grep '^D' "$T/want.tsv" | cut -f3 | while read -r r; do grp "$r"; done)" in *,*) ok "a fixture day total has a group mark" ;; *) no "a fixture day total has a group mark" ;; esac
107134
108135 (cd "$T/w" && "$T/visits") >/dev/null 2>&1; eq "no argument exit" "$?" 1
109136 (cd "$T/w" && "$T/visits" "$T/none") >/dev/null 2>&1; eq "unreadable log exit" "$?" 2
@@ -144,7 +171,7 @@ else
144171 if [ "$(grep -c "<dt>Requests</dt><dd>$(grp "$REQ")</dd>" "$T/m2/visits.html")" = 1 ]; then no "mutant without group marks is caught"; else ok "mutant without group marks is caught"; fi
145172 fi
146173
147-# negative control: crawler names are matched in lower case only
174+# negative control: names are matched in lower case only
148175 sed 's/^if and ge x 65 le x 90$/if false/' "$V/visits.om" >"$T/mutant3.om"
149176 if cmp -s "$V/visits.om" "$T/mutant3.om"; then
150177 no "mutant 3 differs from source"
@@ -156,5 +183,17 @@ else
156183 if cmp -s "$T/m3got.tsv" "$T/want.tsv"; then no "mutant that misses AhrefsBOT and ExampleCRAWLer is caught"; else ok "mutant that misses AhrefsBOT and ExampleCRAWLer is caught"; fi
157184 fi
158185
186+# negative control: every word after the first is looked for together with the space before it in
187+# the list, so an agent holding such a word with no space in front of it is no longer caught
188+sed 's/^s = add i 1$/s = i/' "$V/visits.om" >"$T/mutant4.om"
189+if cmp -s "$V/visits.om" "$T/mutant4.om"; then
190+ no "mutant 4 differs from source"
191+else
192+ "$OMC" <"$T/mutant4.om" >"$T/mutant4" 2>/dev/null && chmod +x "$T/mutant4"
193+ mkdir "$T/m4"
194+ (cd "$T/m4" && "$T/mutant4" "$T/wlog")
195+ if [ "$(grep '^A' "$T/m4/visits.tsv" | cut -f2)" = "$NW" ]; then no "mutant that looks for later words with a leading space is caught"; else ok "mutant that looks for later words with a leading space is caught"; fi
196+fi
197+
159198 echo "RESULT pass=$pass fail=$fail"
160199 [ "$fail" -eq 0 ]

visits/visits.om

@@ -45,21 +45,21 @@ global pl uchar 64
4545 note gs: 0 requests, 1 bytes, 2 skipped lines, 3 first epoch, 4 last epoch, 5 visitors, 6 projects,
4646 note 7 visitors not listed, 8 projects not listed, 9 status 2xx, 10 3xx, 11 4xx, 12 5xx, 13 first day,
4747 note 14 line too long flag, 15 new-slot flag, 16 requests outside the day table, 17 requests from
48-note named crawlers, 18 from other named agents, 19 with no agent name, 20 from lines written before
49-note forged logged the agent (seven fields), 21 fields in the current line, 22 visitors that are named
50-note crawlers, 23 visitors that are other named agents, 24 the current line's visitor slot
51-note vkd: 0 no agent name seen for the visitor, 1 a crawler name seen, 2 only other names seen
52-text kw1 "bot"
53-text kw2 "crawl"
54-text kw3 "spider"
55-text kw4 "slurp"
48+note crawlers and tools, 18 from other named agents (browsers), 19 with no agent name, 20 from lines
49+note written before forged logged the agent (seven fields), 21 fields in the current line, 22 visitors
50+note that are crawlers or tools, 23 visitors that are browsers, 24 the current line's visitor slot
51+note vkd: 0 no agent name seen for the visitor, 1 a crawler or tool name seen, 2 only other names seen
52+note kws: an agent that contains one of these words, in any letter case, is a crawler or a tool. Lower
53+note case, one space between words, each at most 32 bytes. GoogleOther is Google's general crawler and
54+note has none of the usual words in it; on the first day of logging it was 525 of 553 named requests.
55+text kws "bot crawl spider slurp googleother google- mediapartners feedfetcher facebookexternalhit preview curl wget python go-http java/ scrapy httpclient libwww headless okhttp aiohttp axios node-fetch"
5656 text fhtml "visits.html"
5757 text fhtmp "visits.html.tmp"
5858 text ftsv "visits.tsv"
5959 text fttmp "visits.tsv.tmp"
6060 text x01 "<!doctype html><html lang='en' data-theme='dark'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><meta name='robots' content='noindex'>"
6161 text x02 "<title>Who visited INTERPLANE</title><link rel='stylesheet' href='tokens.css'><link rel='stylesheet' href='visits.css'></head><body><main>\n"
62-text x03 "<p class='eyebrow'>Owner only</p><h1>Who visited INTERPLANE</h1><p class='sub'>From the server's own log on your machine. Nothing here leaves it. A visitor is one network address. A named crawler is a visitor whose browser name says bot, crawl, spider or slurp; any other name counts as a browser or tool, and a tool can use any name it likes.</p>\n<dl class='stats'>"
62+text x03 "<p class='eyebrow'>Owner only</p><h1>Who visited INTERPLANE</h1><p class='sub'>From the server's own log on your machine. Nothing here leaves it. A visitor is one network address. A crawler or tool is a visitor whose name says so (bot, crawl, spider, GoogleOther, curl, python and the like); any other name counts as a browser, and a tool can still call itself one.</p>\n<dl class='stats'>"
6363 text x04 "<div><dt>Requests</dt><dd>"
6464 text x05 "</dd></div><div><dt>Visitors</dt><dd>"
6565 text x06 "</dd></div><div><dt>Projects visited</dt><dd>"
@@ -72,14 +72,14 @@ text x12 " redirected, "
7272 text x13 " refused or not found, "
7373 text x14 " server errors. Lines not understood: "
7474 text y1 ".</p>\n<p class='sub'>Who asked: "
75-text y2 " requests from named crawlers, "
76-text y3 " from browsers and tools, "
75+text y2 " requests from crawlers and tools, "
76+text y3 " from browsers, "
7777 text y4 " gave no name, "
7878 text y5 " are from before names were recorded. Visitors: "
79-text y6 " named crawlers, "
80-text y7 " browsers and tools"
81-text ykc "crawler"
82-text yko "browser or tool"
79+text y6 " crawlers and tools, "
80+text y7 " browsers"
81+text ykc "crawler or tool"
82+text yko "browser"
8383 text x15 ".</p>\n<h2>By day</h2><table><thead><tr><th>Day (UTC)</th><th>Requests</th><th>Visitors</th></tr></thead><tbody>\n"
8484 text x16 "</tbody></table>\n<h2>Most visited projects</h2><table><thead><tr><th>Project</th><th>Requests</th><th>Visitors</th></tr></thead><tbody>\n"
8585 text x17 "</tbody></table>\n<h2>Most active visitors</h2><table><thead><tr><th>Address</th><th>Requests</th><th>Megabytes</th><th>First seen (UTC)</th><th>Last seen (UTC)</th><th>Kind</th></tr></thead><tbody>\n"
@@ -403,20 +403,23 @@ put vby v add get vby v by
403403 put vls v t
404404 ret h
405405 end
406-note phas: ln[a, b) contains the lower-case word w, in any letter case
407-fn phas a ulong b ulong w view uchar * to bool
408-m = len w
406+note phas: ln[a, b) contains kws[s, e), in any letter case; e - s is at most 32. A position is
407+note left at its first byte that differs, so most positions cost one compare.
408+fn phas a ulong b ulong s ulong e ulong to bool
409+m = sub e s
409410 i = a
410411 while le add i m b bound 4096
411412 hit = true
412-for j ulong m bound 8
413+j = ulong 0
414+while and hit lt j m bound 32
413415 x = ulong get ln add i j
414416 if and ge x 65 le x 90
415417 x = add x 32
416418 end
417-if ne x ulong get w j
419+if ne x ulong get kws add s j
418420 hit = false
419421 end
422+j = add j 1
420423 end
421424 if hit
422425 ret true
@@ -425,6 +428,28 @@ i = add i 1
425428 end
426429 ret false
427430 end
431+note pauto: ln[a, b) contains one of the words of kws
432+fn pauto a ulong b ulong to bool
433+n = len kws
434+s = ulong 0
435+i = ulong 0
436+while le i n bound 512
437+cut = eq i n
438+if lt i n
439+cut = eq get kws i 32
440+end
441+if cut
442+if and gt i s le sub i s 32
443+if phas a b s i
444+ret true
445+end
446+end
447+s = add i 1
448+end
449+i = add i 1
450+end
451+ret false
452+end
428453 note pagent: count the request by its agent name (field 8) and mark its visitor. A crawler name
429454 note wins over any other name the same address used.
430455 fn pagent to void
@@ -439,7 +464,7 @@ if or ge a b and eq sub b a 1 eq get ln a 45
439464 put gs 19 add get gs 19 1
440465 ret
441466 end
442-if or or phas a b kw1 phas a b kw2 or phas a b kw3 phas a b kw4
467+if pauto a b
443468 put gs 17 add get gs 17 1
444469 if lt v NV
445470 put vkd v 1