interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / ipl / tests / import-identity.sh

83 lines · 6818 bytes Raw Blame History
1#!/bin/bash
2# tests/import-identity.sh REFERENCE_ROOT OLD_STORAGE NID RID...: the import that reads the identity
3# document with git (no `rad` program) must give what the earlier `rad inspect` route gave.
4# REFERENCE_ROOT is a store made by the old route (the 2026-11-13 trial store). For each RID, a scratch
5# old store holds only that repository (a symlink into OLD_STORAGE, read only), tools/import-radicle.sh
6# runs with IMPORT_NID=NID and a scratch key, and the test compares with the reference:
7# - the import.tsv line, byte for byte;
8# - for an imported project: record 1 with only the owner and nonce lines removed (they name the
9# signing key and a fresh random nonce); the evidence file's digests of every migration file that
10# holds no path; the files that do hold paths (every *.argv, the snapshot's argument vectors as
11# u16le argc then u16le length and bytes per argument, and clone.stderr) decoded, with the old
12# repository's path replaced by OLDSTORE and the store root by ROOT, since those two paths differ
13# between the runs by construction; the note's first line without its date; the catalog line
14# without its id (a digest over record 1); every ref of repo.git; and `ipl verify`.
15# A RID whose head moved in OLD_STORAGE after the reference was made cannot be compared and is refused
16# as an argument (exit 2). Needs bin/ built by build.sh with the snapshot source.
17# Negative controls: a reference line with one field changed, and a decoded argv with one argument
18# changed, must not compare equal.
19# Prints PASS/FAIL per check, ends "IDENTITY PASS checks=N" (exit 0) or "IDENTITY FAIL ..." (exit 1).
20set -u
21cd "$(dirname "$0")/.." || exit 2
22REF=${1:?REFERENCE_ROOT} OLDS=${2:?OLD_STORAGE} NID=${3:?NID}; shift 3
23[ $# -gt 0 ] || { echo "usage: tests/import-identity.sh REFERENCE_ROOT OLD_STORAGE NID RID..." >&2; exit 2; }
24T=$(mktemp -d /tmp/ipl-identity.XXXXXX) || exit 2; trap 'rm -rf "$T"' EXIT
25ssh-keygen -q -t ed25519 -N "" -C "import-identity test key" -f "$T/key" || exit 2
26printf '* %s\n' "$(ssh-keygen -lf "$T/key.pub" | awk '{print $2}')" > "$T/owner-pins"
27chmod 600 "$T/owner-pins"
28export IPL_OWNER_PINS="$T/owner-pins"
29pass=0; fail=0
30ok() { pass=$((pass + 1)); echo "PASS $1"; }
31no() { fail=$((fail + 1)); echo "FAIL $1"; }
32same() { if cmp -s "$2" "$3"; then ok "$1"; else no "$1: $(diff "$2" "$3" | head -4 | tr '\n' ' ')"; fi; }
33og() { env -i PATH=/usr/bin:/bin HOME=/nonexistent GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null git "$@"; }
34# argv FILE: one argument per line; "BAD" when the file is not exactly argc and that many arguments
35argv() { od -An -v -tu1 "$1" | LC_ALL=C awk '{ for (i = 1; i <= NF; i++) b[n++] = $i }
36 END { if (n < 2) { print "BAD"; exit } argc = b[0] + 256 * b[1]; p = 2
37 for (a = 0; a < argc; a++) { if (p + 2 > n) { print "BAD"; exit } l = b[p] + 256 * b[p + 1]; p += 2
38 if (p + l > n) { print "BAD"; exit } s = ""; for (j = 0; j < l; j++) s = s sprintf("%c", b[p + j]); p += l; print s }
39 if (p != n) print "BAD" }'; }
40# paths DIR OLDREPO OLDREPO_RESOLVED ROOT: every path-holding migration file of DIR, decoded, both paths
41# replaced (the snapshot names the old repository both as given and resolved through the symlink)
42paths() { local f; for f in "$1"/repo.git.migration/*.argv; do
43 echo "== ${f##*/}"; argv "$f" | awk -v o="$2" -v o2="$3" -v r="$4/" '$0 == o || $0 == o2 { print "OLDSTORE"; next } index($0, r) == 1 { print "ROOT/" substr($0, length(r) + 1); next } { print }'
44 done
45 echo "== clone.stderr"; awk -v r="$4/" '{ while ((i = index($0, r)) > 0) $0 = substr($0, 1, i - 1) "ROOT/" substr($0, i + length(r)); print }' "$1/repo.git.migration/clone.stderr"; }
46pathfree() { grep -v '\.argv$\|/clone\.stderr$' "$1"; }
47for rid in "$@"; do
48 refrow=$(awk -F'\t' -v r="rad:$rid" '$2 == r' "$REF/import.tsv")
49 [ -n "$refrow" ] || { echo "identity: rad:$rid has no line in $REF/import.tsv" >&2; exit 2; }
50 name=$(printf '%s' "$refrow" | cut -f1) br=$(printf '%s' "$refrow" | cut -f3) refhead=$(printf '%s' "$refrow" | cut -f4)
51 if [ "$refhead" != - ] && [ "$(og --git-dir="$OLDS/$rid" rev-parse -q --verify "refs/heads/$br")" != "$refhead" ]; then
52 echo "identity: rad:$rid moved after the reference was made; pick another" >&2; exit 2
53 fi
54 H=$T/$rid; mkdir -p "$H/old/storage" || exit 2; ln -s "$OLDS/$rid" "$H/old/storage/$rid" || exit 2
55 RAD_HOME=$H/old IMPORT_NID=$NID PATH=/usr/bin:/bin tools/import-radicle.sh "$H/root" "$T/key" > "$H/import.out" 2>&1
56 echo " import exit $? for rad:$rid: $(head -1 "$H/import.out")"
57 printf '%s\n' "$refrow" > "$H/want.tsv"
58 same "row rad:$rid" "$H/want.tsv" "$H/root/import.tsv"
59 printf '%s\n' "$refrow" | awk -F'\t' -v OFS='\t' '{$3 = $3 "x"} 1' > "$H/bad.tsv"
60 if cmp -s "$H/bad.tsv" "$H/root/import.tsv"; then no "control-row rad:$rid: an altered line compared equal"; else ok "control-row rad:$rid"; fi
61 case $(printf '%s' "$refrow" | cut -f6) in OK) ;; *) continue ;; esac
62 P=$H/root/projects/$name R=$REF/projects/$name
63 grep -v '^owner \|^nonce ' "$R/records/1" > "$H/r1.want"; grep -v '^owner \|^nonce ' "$P/records/1" > "$H/r1.got"
64 same "record-1 $name" "$H/r1.want" "$H/r1.got"
65 pathfree "$REF/import-notes/$name.evidence" > "$H/e.want"; pathfree "$H/root/import-notes/$name.evidence" > "$H/e.got"
66 same "evidence-pathfree $name ($(wc -l < "$H/e.got") files)" "$H/e.want" "$H/e.got"
67 paths "$R" "$HOME/.radicle/storage/$rid" "$HOME/.radicle/storage/$rid" "$REF" > "$H/p.want"
68 paths "$P" "$H/old/storage/$rid" "$(realpath "$H/old/storage/$rid")" "$H/root" > "$H/p.got"
69 if grep -q '^BAD$' "$H/p.want" "$H/p.got"; then no "evidence-paths $name: an argv file did not decode"
70 else same "evidence-paths $name ($(grep -c '^== ' "$H/p.got") files)" "$H/p.want" "$H/p.got"; fi
71 awk '!d && $0 == "--mirror" { $0 = "--bare"; d = 1 } 1' "$H/p.got" > "$H/p.bad"
72 if cmp -s "$H/p.want" "$H/p.bad"; then no "control-argv $name: an altered argument compared equal"; else ok "control-argv $name"; fi
73 head -1 "$REF/import-notes/$name.note" | sed 's/ on [0-9-]* by / on DATE by /' > "$H/n.want"
74 head -1 "$H/root/import-notes/$name.note" | sed 's/ on [0-9-]* by / on DATE by /' > "$H/n.got"
75 same "note $name" "$H/n.want" "$H/n.got"
76 cut -f1,3- "$R/catalog.row" > "$H/c.want"; cut -f1,3- "$P/catalog.row" > "$H/c.got"
77 same "catalog $name" "$H/c.want" "$H/c.got"
78 og --git-dir="$R/repo.git" for-each-ref --format='%(refname) %(objectname)' > "$H/refs.want"
79 og --git-dir="$P/repo.git" for-each-ref --format='%(refname) %(objectname)' > "$H/refs.got"
80 same "refs $name" "$H/refs.want" "$H/refs.got"
81 if ./ipl verify "$H/root" "$name" > "$H/verify.out" 2>&1; then ok "verify $name"; else no "verify $name: $(head -1 "$H/verify.out")"; fi
82done
83if [ "$fail" = 0 ]; then echo "IDENTITY PASS checks=$pass"; else echo "IDENTITY FAIL failed=$fail passed=$pass"; exit 1; fi