interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / patch / tests / run.sh
| 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 '<b>bold</b> & "q"' "$T/body" && grep -qF '<script>x</script>' "$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 · 0 closed · 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>) ) <javascript:pwn(20)>\n\n"quoted" & ampersand < 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'&').replace(b'<', b'<').replace(b'>', b'>').replace(b'"', b'"') |
| 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 · %d closed · %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 · %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 · 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> · 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> · <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" "{"kind":"github-import","owner":"aien-dev","repo":"gh-repo","number":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 · opened 2026-11-10 11:00 UTC · 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 · opened 2026-11-10 11:00 UTC · closed 2026-11-13 08:00 UTC · 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> · <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 · 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 <script>pwn(1)</script> "quoted" & <b>more</b></h2>' "hostile title: shown escaped" |
| 1107 | has "$IHOST" '<p class="meta">Labels: bug, <script>pwn(10)</script>, la"bel & <b></p>' "hostile labels: shown escaped" |
| 1108 | has "$IHOST" '<div class="box"><p class="meta">ev"il<b>&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<i> reviewed (<script>pwn(14)</script>) 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"<u> commented on <code>src/<x>&"y".txt</code> line 3 on 2026-11-10 13:00 UTC</p>' "hostile review comment login and path: shown escaped" |
| 1111 | has "$IHOST" '+<script>pwn(17)</script> & "x"' "hostile diff line: shown escaped" |
| 1112 | has "$IHOST" '"quoted" & 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<il>/re&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 · 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 · 0 closed · 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 · 1 closed · 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"il<b>&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<i> reviewed (<script>pwn(14)</script>) 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"bel & <b>' "$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 ] |