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