Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/interplane-forge/blob/main/patch/tests/e2e.sh
# interplane-forge
INTERPLANE Forge
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`interplane-forge / patch / tests / e2e.sh`
122 lines ยท 8215 bytes Raw Blame History
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=
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/: 302 to $l" || bad "/pulls/: $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 ]