interplane.io
Source of interplane.io: a Rust generator that renders the page from the protocol repository's public record, deployed hourly from the Spark.
Brought by drakestapleton
interplane.io / scripts / tests / check-sync.sh
| 1 | #!/bin/sh |
| 2 | # Controls for scripts/sync-to-hub.sh. Nothing here contacts a server or writes outside its own |
| 3 | # temporary folder. git is the real git, working on local repositories made here (the history, |
| 4 | # and the project repository of a signed store that holds it); the git wrapper only traces calls |
| 5 | # and refuses any remote, clone, fetch or ref change. ipl is a stand-in for `ipl verify`: it answers |
| 6 | # with the real tool's OK line for the store's actual main, or refuses (exit 3) as the real tool |
| 7 | # does when the project does not verify or the owner asked for is not the pinned one. quietlock, |
| 8 | # uname, the compiler, the builder, rsync and sudo are stubs. The sudo stub replays the root copy |
| 9 | # into a temporary folder so that "the destination is empty" is measured, not assumed. |
| 10 | set -eu |
| 11 | ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) |
| 12 | TEST_ROOT=$(mktemp -d) |
| 13 | trap 'rm -rf "$TEST_ROOT"' 0 |
| 14 | trap 'exit 1' 1 2 15 |
| 15 | REAL_SHA256=$(command -v sha256sum) |
| 16 | REAL_GIT=$(command -v git) |
| 17 | REAL_RSYNC=$(command -v rsync) |
| 18 | GIT_CONFIG_GLOBAL=/dev/null |
| 19 | GIT_CONFIG_NOSYSTEM=1 |
| 20 | GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture |
| 21 | GIT_AUTHOR_DATE='2000-01-01T00:00:00Z' GIT_COMMITTER_DATE='2000-01-01T00:00:00Z' |
| 22 | export TEST_ROOT REAL_SHA256 REAL_GIT REAL_RSYNC GIT_CONFIG_GLOBAL GIT_CONFIG_NOSYSTEM |
| 23 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_DATE GIT_COMMITTER_DATE |
| 24 | OWNER_FP=SHA256:FixtureOwnerKey0000000000000000000000000000 |
| 25 | OTHER_FP=SHA256:SomeOtherOwnerKey11111111111111111111111111 |
| 26 | mkdir -p "$TEST_ROOT/bin" |
| 27 | |
| 28 | # ---- the history (A, then B, then C) and the signed store's repository for the project |
| 29 | UP="$TEST_ROOT/upstream" |
| 30 | STORE="$TEST_ROOT/store" |
| 31 | SRC="$STORE/projects/interplane.io/repo.git" |
| 32 | mkdir -p "$UP/scripts" "$UP/native/lib" "$UP/content" |
| 33 | "$REAL_GIT" -C "$UP" init -q |
| 34 | "$REAL_GIT" -C "$UP" symbolic-ref HEAD refs/heads/main |
| 35 | cp "$ROOT/scripts/build-native.sh" "$UP/scripts/build-native.sh" |
| 36 | cp "$ROOT/native/site.om" "$UP/native/site.om" |
| 37 | cp "$ROOT/native/translate.om" "$UP/native/translate.om" |
| 38 | cp "$ROOT/native/lib/sha2.om" "$UP/native/lib/sha2.om" |
| 39 | cp "$ROOT/native/omc.sha256" "$UP/native/omc.sha256" |
| 40 | read -r PIN_HASH _ < "$ROOT/native/omc.sha256" |
| 41 | export PIN_HASH |
| 42 | commit() { |
| 43 | printf '%s\n' "$1" > "$UP/content/marker.txt" |
| 44 | "$REAL_GIT" -C "$UP" add -A |
| 45 | "$REAL_GIT" -C "$UP" commit -q -m "$1" |
| 46 | "$REAL_GIT" -C "$UP" rev-parse HEAD |
| 47 | } |
| 48 | A=$(commit release-a) |
| 49 | B=$(commit release-b) |
| 50 | printf 'note changed\n' >> "$UP/native/lib/sha2.om" |
| 51 | C=$(commit release-c-with-a-changed-sha2-unit) |
| 52 | "$REAL_GIT" init -q --bare "$SRC" |
| 53 | "$REAL_GIT" -C "$SRC" symbolic-ref HEAD refs/heads/main |
| 54 | "$REAL_GIT" -C "$UP" push -q "$SRC" "$A:refs/heads/main" "$C:refs/heads/history" |
| 55 | # store_main COMMIT: what `ipl land` would leave, the store's main at COMMIT |
| 56 | store_main() { "$REAL_GIT" -C "$SRC" update-ref refs/heads/main "$1"; } |
| 57 | |
| 58 | cat > "$TEST_ROOT/bin/git" <<'STUB' |
| 59 | #!/bin/sh |
| 60 | set -eu |
| 61 | printf 'git %s\n' "$*" >> "$TEST_ROOT/trace" |
| 62 | for a in "$@"; do |
| 63 | case "$a" in |
| 64 | ls-remote|clone|fetch|pull|push|remote|update-ref|*://*) echo "git $a in deployment test: the source is the store, read in place" >&2; exit 90 ;; |
| 65 | esac |
| 66 | done |
| 67 | exec "$REAL_GIT" "$@" |
| 68 | STUB |
| 69 | cat > "$TEST_ROOT/bin/ipl" <<'STUB' |
| 70 | #!/bin/sh |
| 71 | set -eu |
| 72 | printf 'ipl %s\n' "$*" >> "$TEST_ROOT/trace" |
| 73 | [ "$#" -eq 5 ] && [ "$1" = verify ] && [ "$2" = "$STORE" ] && [ "$3" = interplane.io ] && [ "$4" = --expect-owner ] || { echo 'unexpected ipl command' >&2; exit 90; } |
| 74 | # As the real tool: exit 3 when the owner asked for is not the pinned owner, or nothing verifies. |
| 75 | [ "$5" = "$OWNER_FP" ] || { printf 'ipl: current owner pin is %s, not %s\n' "$OWNER_FP" "$5" >&2; exit 3; } |
| 76 | [ "${STUB_IPL:-ok}" != fail ] || { echo 'ipl: interplane.io: does not verify: fixture' >&2; exit 3; } |
| 77 | HEAD=$("$REAL_GIT" --git-dir="$STORE/projects/interplane.io/repo.git" rev-parse refs/heads/main) |
| 78 | ID=$(printf '%064d' 1) CH=$(printf '%064d' 2) |
| 79 | ok() { printf 'OK %s %s %s %s public %s 8 %s\n' "$1" "$ID" "$2" "$HEAD" "$3" "$CH"; } |
| 80 | case "${STUB_IPL:-ok}" in |
| 81 | ok) ok interplane.io main "$5" ;; |
| 82 | other-owner) ok interplane.io main "$OTHER_FP" ;; |
| 83 | other-project) ok interplane-forge main "$5" ;; |
| 84 | other-branch) ok interplane.io next "$5" ;; |
| 85 | two) ok interplane.io main "$5"; ok interplane.io main "$5" ;; |
| 86 | empty) ;; |
| 87 | *) exit 95 ;; |
| 88 | esac |
| 89 | STUB |
| 90 | cat > "$TEST_ROOT/bin/quietlock" <<'STUB' |
| 91 | #!/bin/sh |
| 92 | exit "${STUB_QUIET:-0}" |
| 93 | STUB |
| 94 | cat > "$TEST_ROOT/bin/uname" <<'STUB' |
| 95 | #!/bin/sh |
| 96 | printf '%s\n' "${STUB_MACHINE:-aarch64}" |
| 97 | STUB |
| 98 | cat > "$TEST_ROOT/bin/sha256sum" <<'STUB' |
| 99 | #!/bin/sh |
| 100 | set -eu |
| 101 | case "$1" in |
| 102 | "$TEST_ROOT/compiler"|"$TEST_ROOT/omega/seed/out/omc") |
| 103 | if [ "${STUB_BAD_COMPILER:-0}" = 1 ]; then |
| 104 | printf '%s %s\n' invalid "$1" |
| 105 | else |
| 106 | printf '%s %s\n' "$PIN_HASH" "$1" |
| 107 | fi ;; |
| 108 | */native/lib/sha2.om) exec "$REAL_SHA256" "$@" ;; |
| 109 | *) [ "${STUB_HASH_FAIL:-0}" = 0 ] || exit 91 |
| 110 | exec "$REAL_SHA256" "$@" ;; |
| 111 | esac |
| 112 | STUB |
| 113 | cat > "$TEST_ROOT/compiler" <<'STUB' |
| 114 | #!/bin/sh |
| 115 | set -eu |
| 116 | echo compile >> "$TEST_ROOT/trace" |
| 117 | cat > "$TEST_ROOT/compiled-input" |
| 118 | [ "${STUB_COMPILE_FAIL:-0}" = 0 ] || exit 92 |
| 119 | cat "$TEST_ROOT/builder-template" |
| 120 | STUB |
| 121 | # The stand-in builder runs from the exported commit, like the real one, and copies the commit's |
| 122 | # marker into the page so a control can tell which commit was built. |
| 123 | cat > "$TEST_ROOT/builder-template" <<'STUB' |
| 124 | #!/bin/sh |
| 125 | set -eu |
| 126 | printf 'builder %s\n' "$1" >> "$TEST_ROOT/trace" |
| 127 | case "$1" in |
| 128 | build) |
| 129 | [ "${STUB_BUILD_FAIL:-0}" = 0 ] || exit 93 |
| 130 | test ! -e "$2" |
| 131 | mkdir -p "$2/public" |
| 132 | BANNER= |
| 133 | [ "${STUB_TESTDATA:-}" != banner ] || BANNER='<p data-test-data>TEST DATA</p>' |
| 134 | printf '<!doctype html><title>Fixture</title><p>%s</p>%s\n' "$(cat content/marker.txt)" "$BANNER" > "$2/index.html" |
| 135 | cp "$2/index.html" "$TEST_ROOT/built-index" |
| 136 | printf '%s\n' '{"source":"committed"}' > "$2/facts.json" |
| 137 | printf '%s\n' "${STUB_ASSET:-base}" > "$2/public/style.css" |
| 138 | [ "${STUB_TESTDATA:-}" != file ] || printf 'fixture output\n' > "$2/TEST-DATA" |
| 139 | [ "${STUB_TESTDATA:-}" != manifest ] || printf '%064d TEST-DATA\n' 0 > "$2/manifest.sha256" |
| 140 | if [ "${STUB_HOP:-0}" != 0 ]; then |
| 141 | mkdir -p "$3" |
| 142 | printf '<!doctype html><title>Hop fixture %s</title>\n' "$STUB_HOP" > "$3/index.html" |
| 143 | printf '#!/bin/sh\n' > "$3/install.sh" |
| 144 | [ "${STUB_TESTDATA:-}" != hopfile ] || printf 'fixture output\n' > "$3/TEST-DATA" |
| 145 | fi |
| 146 | ;; |
| 147 | verify) [ "${STUB_VERIFY_FAIL:-0}" = 0 ] || exit 94 ;; |
| 148 | *) exit 95 ;; |
| 149 | esac |
| 150 | STUB |
| 151 | cat > "$TEST_ROOT/bin/rsync" <<'STUB' |
| 152 | #!/bin/sh |
| 153 | set -eu |
| 154 | printf 'rsync %s\n' "$*" >> "$TEST_ROOT/trace" |
| 155 | [ "${STUB_RSYNC_FAIL:-0}" = 0 ] || exit 96 |
| 156 | STUB |
| 157 | # sudo: records the exact command, then replays the copy into the temporary destination without |
| 158 | # the ownership change (the test is not root). Only the one expected command shape is accepted. |
| 159 | cat > "$TEST_ROOT/bin/sudo" <<'STUB' |
| 160 | #!/bin/sh |
| 161 | set -eu |
| 162 | printf 'sudo %s\n' "$*" >> "$TEST_ROOT/trace" |
| 163 | [ "$#" -eq 9 ] && [ "$1" = -n ] && [ "$2" = /usr/bin/rsync ] && [ "$3" = -rt ] && [ "$4" = --delete ] && |
| 164 | [ "$5" = --chmod=D755,F644 ] && [ "$6" = --chown=root:root ] && [ "$7" = --exclude=.well-known ] || { echo 'unexpected root command' >&2; exit 97; } |
| 165 | case "$8" in "$TEST_ROOT"/*/hopbot.stage/) ;; *) exit 97 ;; esac |
| 166 | case "$9" in "$TEST_ROOT"/*) ;; *) exit 97 ;; esac |
| 167 | [ "${STUB_SUDO_FAIL:-0}" = 0 ] || exit 98 |
| 168 | exec "$REAL_RSYNC" -rt --delete --chmod=D755,F644 --exclude=.well-known "$8" "$9" |
| 169 | STUB |
| 170 | chmod +x "$TEST_ROOT/bin/"* "$TEST_ROOT/compiler" |
| 171 | PATH="$TEST_ROOT/bin:$PATH" |
| 172 | OMC="$TEST_ROOT/compiler" |
| 173 | IPL="$TEST_ROOT/bin/ipl" |
| 174 | HUB=fixture-hub |
| 175 | WEBDIR=/fixture-web |
| 176 | export PATH OMC IPL STORE OWNER_FP OTHER_FP HUB WEBDIR |
| 177 | unset OMC_RUNNER IPL_OWNER_PINS |
| 178 | |
| 179 | N=0 |
| 180 | passed() { N=$((N + 1)); printf 'PASS control %02d: %s\n' "$N" "$1"; } |
| 181 | fail() { printf 'FAIL control: %s\n' "$1" >&2; exit 1; } |
| 182 | # prepare NAME: a new receipt folder and hopbot.org folder, every stub at its quiet default, |
| 183 | # the store's main at A and the pinned owner set. |
| 184 | prepare() { |
| 185 | LOGDIR="$TEST_ROOT/log-$1" |
| 186 | HOPWEBDIR="$TEST_ROOT/www-$1/hopbot.org" |
| 187 | mkdir -p "$HOPWEBDIR" |
| 188 | store_main "$A"; STUB_IPL=ok; IPL_EXPECT_OWNER=$OWNER_FP |
| 189 | STUB_QUIET=0 STUB_BAD_COMPILER=0 STUB_HASH_FAIL=0 STUB_COMPILE_FAIL=0 STUB_BUILD_FAIL=0 |
| 190 | STUB_VERIFY_FAIL=0 STUB_RSYNC_FAIL=0 STUB_SUDO_FAIL=0 STUB_MACHINE=aarch64 STUB_ASSET=base |
| 191 | STUB_HOP=0 STUB_TESTDATA= |
| 192 | export LOGDIR HOPWEBDIR STUB_IPL IPL_EXPECT_OWNER STUB_QUIET STUB_BAD_COMPILER STUB_HASH_FAIL STUB_COMPILE_FAIL |
| 193 | export STUB_BUILD_FAIL STUB_VERIFY_FAIL STUB_RSYNC_FAIL STUB_SUDO_FAIL STUB_MACHINE STUB_ASSET |
| 194 | export STUB_HOP STUB_TESTDATA |
| 195 | : > "$TEST_ROOT/trace" |
| 196 | } |
| 197 | again() { : > "$TEST_ROOT/trace"; } |
| 198 | run() { RC=0; sh "$ROOT/scripts/sync-to-hub.sh" "$@" > "$TEST_ROOT/stdout" 2> "$TEST_ROOT/stderr" || RC=$?; } |
| 199 | transfers() { grep -c -e '^rsync ' -e '^sudo ' "$TEST_ROOT/trace" || :; } |
| 200 | no_transfer() { [ "$(transfers)" -eq 0 ] || fail "$1: a transfer was started"; } |
| 201 | # refused NAME CODE TEXT [COMMIT]: that exit code, the reason in the output, no transfer, no receipt |
| 202 | refused() { |
| 203 | run ${4:+"$4"} |
| 204 | [ "$RC" -eq "$2" ] || { cat "$TEST_ROOT/stdout" "$TEST_ROOT/stderr" >&2; fail "$1: expected exit $2, got $RC"; } |
| 205 | grep -q -- "$3" "$TEST_ROOT/stdout" "$TEST_ROOT/stderr" || { cat "$TEST_ROOT/stdout" "$TEST_ROOT/stderr" >&2; fail "$1: the refusal does not say: $3"; } |
| 206 | no_transfer "$1" |
| 207 | if ls "$LOGDIR"/receipt.* > /dev/null 2>&1; then fail "$1: a refusal left a receipt"; fi |
| 208 | passed "$1 refused, exit $RC, no transfer, no receipt" |
| 209 | } |
| 210 | published() { run "$1"; [ "$RC" -eq 0 ] || { cat "$TEST_ROOT/stdout" "$TEST_ROOT/stderr" >&2; fail "expected a publish, got exit $RC"; }; } |
| 211 | field() { sed -n "s/^$2 //p" "$1" | head -n 1; } |
| 212 | receipt() { # receipt SITE STATE DESTINATION COMMIT |
| 213 | f="$LOGDIR/receipt.$1" |
| 214 | [ "$(field "$f" state)" = "$2" ] && [ "$(field "$f" destination)" = "$3" ] && [ "$(field "$f" commit)" = "$4" ] || |
| 215 | { cat "$f" >&2; fail "receipt.$1 is not: $2 $3 $4"; } |
| 216 | [ ! -e "$LOGDIR/pending.$1" ] || fail "a pending marker for $1 is left after success" |
| 217 | } |
| 218 | SUDO_LINE() { printf 'sudo -n /usr/bin/rsync -rt --delete --chmod=D755,F644 --chown=root:root --exclude=.well-known %s/hopbot.stage/ %s/' "$LOGDIR" "$HOPWEBDIR"; } |
| 219 | |
| 220 | # ---- usage: the approved commit is required, in full |
| 221 | prepare usage |
| 222 | for bad in '' "${A%????????}" "$(printf %s "$A" | tr a-f A-F)x" main; do |
| 223 | RC=0 |
| 224 | sh "$ROOT/scripts/sync-to-hub.sh" "$bad" > "$TEST_ROOT/stdout" 2> "$TEST_ROOT/stderr" || RC=$? |
| 225 | [ "$RC" -eq 2 ] && grep -q '^usage: sync-to-hub.sh \[--log-dir DIR\] \[COMMIT\]' "$TEST_ROOT/stderr" || fail "commit argument '$bad' gave exit $RC" |
| 226 | [ ! -s "$TEST_ROOT/trace" ] && [ ! -e "$LOGDIR" ] || fail "a usage refusal did some work" |
| 227 | done |
| 228 | passed 'an empty, a short and a malformed commit and a branch name are usage refusals, exit 2, before any work' |
| 229 | run "$A" extra; [ "$RC" -eq 2 ] && [ ! -s "$TEST_ROOT/trace" ] || fail "two arguments gave exit $RC" |
| 230 | passed 'a second argument is a usage refusal, exit 2' |
| 231 | |
| 232 | prepare quiet |
| 233 | STUB_QUIET=1 |
| 234 | run "$A" |
| 235 | [ "$RC" -eq 0 ] && [ ! -s "$TEST_ROOT/trace" ] || fail 'quiet flag did not skip' |
| 236 | passed 'quiet flag held: skipped before any work' |
| 237 | |
| 238 | # ---- the signed head: ipl verify of the store for the pinned owner, and COMMIT is the store's main |
| 239 | VERIFY_LINE="ipl verify $STORE interplane.io --expect-owner $OWNER_FP" |
| 240 | no_export() { if grep -q -e ' archive ' -e '^compile$' "$TEST_ROOT/trace"; then fail "$1: the source was exported or compiled"; fi; } |
| 241 | prepare owner-unset; store_main "$B"; unset IPL_EXPECT_OWNER |
| 242 | refused 'no owner pinned (IPL_EXPECT_OWNER unset)' 5 'no owner is pinned' "$B" |
| 243 | if grep -q '^ipl ' "$TEST_ROOT/trace"; then fail 'ipl was run with no owner pinned'; fi |
| 244 | no_export 'owner unset' |
| 245 | prepare owner-empty; store_main "$B"; IPL_EXPECT_OWNER= |
| 246 | refused 'no owner pinned (IPL_EXPECT_OWNER empty)' 5 'no owner is pinned' "$B" |
| 247 | prepare owner-unset-nocommit; store_main "$B"; unset IPL_EXPECT_OWNER |
| 248 | refused 'no owner pinned and no commit named' 5 'no owner is pinned' |
| 249 | no_export 'owner unset, no commit' |
| 250 | prepare verify-refused; store_main "$B"; STUB_IPL=fail |
| 251 | refused 'the store project does not verify (ipl exit 3)' 5 'does not verify for owner' "$B" |
| 252 | no_export 'verify refused' |
| 253 | prepare verify-refused-nocommit; store_main "$B"; STUB_IPL=fail |
| 254 | refused 'the store project does not verify and no commit named' 5 'does not verify for owner' |
| 255 | no_export 'verify refused, no commit' |
| 256 | prepare owner-mismatch; store_main "$B"; IPL_EXPECT_OWNER=$OTHER_FP |
| 257 | refused 'pinned owner is not the current owner (ipl refuses --expect-owner)' 5 'does not verify for owner' "$B" |
| 258 | grep -q 'current owner pin is' "$LOGDIR/sync.log" || fail 'the owner mismatch from ipl is not in the log' |
| 259 | no_export 'owner mismatch' |
| 260 | prepare owner-reported-other; store_main "$B"; STUB_IPL=other-owner |
| 261 | refused 'verify names a current owner other than the pinned one' 5 'no single OK line' "$B" |
| 262 | no_export 'other owner reported' |
| 263 | for kind in other-project other-branch two empty; do |
| 264 | prepare "verify-$kind"; store_main "$B"; STUB_IPL=$kind |
| 265 | refused "verify answer is not one OK line for interplane.io main ($kind)" 5 'no single OK line' "$B" |
| 266 | no_export "verify $kind" |
| 267 | done |
| 268 | prepare ipl-missing; store_main "$B"; IPL="$TEST_ROOT/absent-ipl" |
| 269 | refused 'ipl missing' 5 'does not verify for owner' "$B" |
| 270 | IPL="$TEST_ROOT/bin/ipl" |
| 271 | prepare not-main; store_main "$B" |
| 272 | refused 'commit that is not the store main (main moved on)' 5 'is not the signed main' "$A" |
| 273 | grep -Fxq "$VERIFY_LINE" "$TEST_ROOT/trace" || fail 'the head was not taken from ipl verify of the store for the pinned owner' |
| 274 | no_export 'not main' |
| 275 | prepare not-landed; store_main "$A" |
| 276 | refused 'commit ahead of the store main (not landed)' 5 'is not the signed main' "$B" |
| 277 | no_export 'not landed' |
| 278 | |
| 279 | # ---- exactly the signed main is built, read in place from the store, which is left as it was |
| 280 | prepare exact-commit; store_main "$B" |
| 281 | "$REAL_GIT" -C "$SRC" for-each-ref > "$TEST_ROOT/refs.before" |
| 282 | : > "$TEST_ROOT/store.mark" |
| 283 | published "$B" |
| 284 | grep -q '<p>release-b</p>' "$TEST_ROOT/built-index" || fail 'the page was not built from the signed main' |
| 285 | [ "$(sed -n 1p "$TEST_ROOT/trace")" = "$VERIFY_LINE" ] || fail 'ipl verify was not the first step' |
| 286 | grep -Fq "git --git-dir=$SRC archive --format=tar " "$TEST_ROOT/trace" || fail 'the source was not exported from the store' |
| 287 | "$REAL_GIT" -C "$SRC" for-each-ref | cmp -s - "$TEST_ROOT/refs.before" || fail 'the publisher changed a ref in the store' |
| 288 | [ -z "$(find "$STORE" -newer "$TEST_ROOT/store.mark" -print)" ] || fail 'the publisher wrote into the store' |
| 289 | if grep -q -e 'rad:' -e 'ls-remote' -e ' clone ' -e ' fetch ' "$TEST_ROOT/trace"; then fail 'the publisher asked a remote'; fi |
| 290 | receipt interplane.io published fixture-hub:/fixture-web "$B" |
| 291 | passed 'signed main named: verify first, then an export of exactly that commit from the store; the store is not written and no remote is asked' |
| 292 | |
| 293 | prepare no-commit; store_main "$B" |
| 294 | run |
| 295 | [ "$RC" -eq 0 ] || { cat "$TEST_ROOT/stdout" "$TEST_ROOT/stderr" >&2; fail "no commit named: expected a publish, got exit $RC"; } |
| 296 | grep -q "commit: the signed main of interplane.io, $B" "$TEST_ROOT/stdout" && grep -q '<p>release-b</p>' "$TEST_ROOT/built-index" || fail 'no commit named: the signed main was not the commit built' |
| 297 | receipt interplane.io published fixture-hub:/fixture-web "$B" |
| 298 | passed 'no commit named (the service start): the verified signed main is resolved, built and published' |
| 299 | |
| 300 | # ---- compiler, build, verify and digest refusals |
| 301 | prepare bad-compiler; store_main "$B"; STUB_BAD_COMPILER=1 |
| 302 | refused 'compiler with the wrong SHA-256' 3 'compilation failed' "$B" |
| 303 | if grep -q '^compile$' "$TEST_ROOT/trace"; then fail 'a compiler with the wrong hash was run'; fi |
| 304 | prepare missing-compiler; store_main "$B"; OMC="$TEST_ROOT/absent" |
| 305 | refused 'missing compiler' 3 'compilation failed' "$B" |
| 306 | OMC="$TEST_ROOT/compiler" |
| 307 | prepare compile-failed; store_main "$B"; STUB_COMPILE_FAIL=1 |
| 308 | refused 'compilation failure' 3 'compilation failed' "$B" |
| 309 | prepare build-failed; store_main "$B"; STUB_BUILD_FAIL=1 |
| 310 | refused 'build failure' 4 'native build failed' "$B" |
| 311 | prepare verify-failed; store_main "$B"; STUB_VERIFY_FAIL=1 |
| 312 | refused 'verify failure' 4 'verify failed' "$B" |
| 313 | prepare hash-failed; store_main "$B"; STUB_HASH_FAIL=1 |
| 314 | refused 'digest failure' 8 'could not take the digest' "$B" |
| 315 | prepare changed-sha2; store_main "$C" |
| 316 | refused 'commit whose SHA-2 unit is not the pinned one' 3 'compilation failed' "$C" |
| 317 | if grep -q '^compile$' "$TEST_ROOT/trace"; then fail 'a changed SHA-2 unit reached the compiler'; fi |
| 318 | prepare unit-composition; store_main "$B" |
| 319 | published "$B" |
| 320 | "$REAL_GIT" -C "$UP" show "$B:native/lib/sha2.om" > "$TEST_ROOT/sha2.b" |
| 321 | "$REAL_GIT" -C "$UP" show "$B:native/site.om" > "$TEST_ROOT/site.b" |
| 322 | "$REAL_GIT" -C "$UP" show "$B:native/translate.om" > "$TEST_ROOT/translate.b" |
| 323 | { printf 'om2\n'; cat "$TEST_ROOT/sha2.b" "$TEST_ROOT/site.b" "$TEST_ROOT/translate.b"; } > "$TEST_ROOT/expected-unit.om" |
| 324 | cmp "$TEST_ROOT/compiled-input" "$TEST_ROOT/expected-unit.om" || fail 'compiler input differs' |
| 325 | passed "compiler input is the om2 line, the commit's SHA-2 unit, then the commit's builder and translation unit" |
| 326 | |
| 327 | # ---- fixture output is never published |
| 328 | for kind in file manifest banner; do |
| 329 | prepare "testdata-$kind"; store_main "$B"; STUB_TESTDATA=$kind |
| 330 | refused "fixture output ($kind marker) in the interplane.io build" 6 'fixture output is never published' "$B" |
| 331 | done |
| 332 | prepare testdata-hop; store_main "$B"; STUB_HOP=1; STUB_TESTDATA=hopfile |
| 333 | refused 'fixture output (file marker) in the hopbot.org build' 6 'fixture output is never published' "$B" |
| 334 | |
| 335 | # ---- interplane.io: transfer, receipt, unchanged, pending |
| 336 | prepare publish; store_main "$B" |
| 337 | published "$B" |
| 338 | grep -q '^rsync -a --delete --exclude .well-known .*/dist/ fixture-hub:/fixture-web/$' "$TEST_ROOT/trace" || fail 'transfer options or destination differ' |
| 339 | [ "$(transfers)" -eq 1 ] || fail 'a build without a Hop release made more than one transfer' |
| 340 | receipt interplane.io published fixture-hub:/fixture-web "$B" |
| 341 | [ ! -e "$LOGDIR/receipt.hopbot.org" ] && [ -z "$(ls -A "$HOPWEBDIR")" ] || fail 'the hopbot.org folder was touched without a Hop release' |
| 342 | D1=$(field "$LOGDIR/receipt.interplane.io" digest) |
| 343 | [ "${#D1}" -eq 64 ] || fail 'the receipt holds no digest' |
| 344 | passed 'publish without a Hop release: one transfer to the hub, a receipt with destination, digest and the full commit; hopbot.org untouched' |
| 345 | again; published "$B" |
| 346 | no_transfer unchanged; grep -q '^.* unchanged: interplane.io' "$TEST_ROOT/stdout" || fail 'unchanged run did not say so' |
| 347 | [ "$(field "$LOGDIR/receipt.interplane.io" digest)" = "$D1" ] || fail 'unchanged run rewrote the receipt' |
| 348 | passed 'same commit, same content, same destination: nothing is transferred' |
| 349 | STUB_ASSET=changed; again; published "$B" |
| 350 | [ "$(transfers)" -eq 1 ] && [ "$(field "$LOGDIR/receipt.interplane.io" digest)" != "$D1" ] || fail 'a stylesheet-only change was not published' |
| 351 | passed 'a stylesheet-only change is published' |
| 352 | D2=$(field "$LOGDIR/receipt.interplane.io" digest) |
| 353 | STUB_ASSET=changed-again STUB_RSYNC_FAIL=1; again; run "$B" |
| 354 | [ "$RC" -eq 8 ] && [ "$(field "$LOGDIR/receipt.interplane.io" digest)" = "$D2" ] && [ -f "$LOGDIR/pending.interplane.io" ] || fail 'failed transfer: receipt or pending marker wrong' |
| 355 | passed 'a failed transfer exits 8, keeps the old receipt and leaves the pending marker' |
| 356 | STUB_ASSET=changed STUB_RSYNC_FAIL=0; again; published "$B" |
| 357 | [ "$(transfers)" -eq 1 ] && [ ! -e "$LOGDIR/pending.interplane.io" ] && [ "$(field "$LOGDIR/receipt.interplane.io" digest)" = "$D2" ] || fail 'a pending transfer was not repaired' |
| 358 | passed 'content back at the last published digest is still transferred while a pending marker is left' |
| 359 | STUB_ASSET=changed-again; again; published "$B" |
| 360 | [ "$(transfers)" -eq 1 ] && [ "$(field "$LOGDIR/receipt.interplane.io" digest)" != "$D2" ] || fail 'later release not published' |
| 361 | passed 'the later release is then published' |
| 362 | |
| 363 | # A receipt belongs to one commit: the same bytes from another commit are transferred and recorded anew. |
| 364 | prepare commit-bound; store_main "$A" |
| 365 | published "$A" |
| 366 | E=$("$REAL_GIT" -C "$UP" commit-tree -p "$B" -m 'same tree as A' "$A^{tree}") |
| 367 | "$REAL_GIT" -C "$UP" update-ref refs/heads/same-tree "$E" |
| 368 | "$REAL_GIT" -C "$UP" push -q "$SRC" "$E:refs/heads/same-tree" |
| 369 | store_main "$E"; again; published "$E" |
| 370 | [ "$(transfers)" -eq 1 ] || fail 'a new commit with the same content was not transferred' |
| 371 | receipt interplane.io published fixture-hub:/fixture-web "$E" |
| 372 | passed 'a new approved commit with identical content is transferred and its receipt names the new commit' |
| 373 | |
| 374 | # ---- destinations: interplane.io |
| 375 | prepare main-dest; store_main "$B" |
| 376 | published "$B" |
| 377 | WEBDIR=/fixture-web-two; again; published "$B" |
| 378 | grep -q ' fixture-hub:/fixture-web-two/$' "$TEST_ROOT/trace" && grep -q 'destination changed from fixture-hub:/fixture-web to fixture-hub:/fixture-web-two' "$TEST_ROOT/stdout" || fail 'changed interplane.io destination was skipped' |
| 379 | receipt interplane.io published fixture-hub:/fixture-web-two "$B" |
| 380 | WEBDIR=/fixture-web |
| 381 | passed 'interplane.io destination change: the same content is transferred to the new destination and the receipt names it' |
| 382 | |
| 383 | # ---- destinations: hopbot.org, on this machine, by one root command |
| 384 | prepare hop-missing; store_main "$B"; STUB_HOP=1; rmdir "$HOPWEBDIR" |
| 385 | refused 'Hop release while the hopbot.org folder is missing' 7 'hopbot.org folder is missing' "$B" |
| 386 | prepare hop-unnamed; store_main "$B"; STUB_HOP=1; HOPWEBDIR= |
| 387 | refused 'Hop release while HOPWEBDIR is empty' 7 'hopbot.org folder is missing' "$B" |
| 388 | |
| 389 | prepare hop; store_main "$B"; STUB_HOP=1 |
| 390 | published "$B" |
| 391 | [ "$(grep -c '^rsync ' "$TEST_ROOT/trace")" -eq 1 ] && [ "$(grep -c '^sudo ' "$TEST_ROOT/trace")" -eq 1 ] || fail 'a Hop release must make one hub transfer and one root copy' |
| 392 | grep -Fxq "$(SUDO_LINE)" "$TEST_ROOT/trace" || { cat "$TEST_ROOT/trace" >&2; fail 'the root command is not the one documented command'; } |
| 393 | if grep '^rsync ' "$TEST_ROOT/trace" | grep -q hopbot; then fail 'hopbot.org was sent to the hub'; fi |
| 394 | cmp "$HOPWEBDIR/index.html" "$LOGDIR/hopbot.stage/index.html" && [ -f "$HOPWEBDIR/install.sh" ] || fail 'the hopbot.org folder does not hold the built page and installer' |
| 395 | receipt interplane.io published fixture-hub:/fixture-web "$B" |
| 396 | receipt hopbot.org published "local:$HOPWEBDIR" "$B" |
| 397 | passed 'Hop release: interplane.io to the hub, hopbot.org to its folder on this machine by the one documented root command, one receipt each' |
| 398 | again; published "$B" |
| 399 | no_transfer 'unchanged with Hop' |
| 400 | passed 'same Hop release again: neither destination is transferred' |
| 401 | |
| 402 | # The reviewer's case: the content was already published when the Hop destination comes into play. |
| 403 | prepare enable; store_main "$B" |
| 404 | published "$B" |
| 405 | [ "$(transfers)" -eq 1 ] && [ ! -e "$LOGDIR/receipt.hopbot.org" ] || fail 'enable-after-skip: unexpected first run' |
| 406 | STUB_HOP=1; again; published "$B" |
| 407 | grep -q '^.* unchanged: interplane.io' "$TEST_ROOT/stdout" || fail 'enable-after-skip: interplane.io content was unchanged in this control' |
| 408 | [ "$(grep -c '^rsync ' "$TEST_ROOT/trace")" -eq 0 ] && [ "$(grep -c '^sudo ' "$TEST_ROOT/trace")" -eq 1 ] || fail 'a newly enabled hopbot.org destination was skipped' |
| 409 | receipt hopbot.org published "local:$HOPWEBDIR" "$B" |
| 410 | passed 'enable after skip: interplane.io unchanged and skipped, the newly enabled hopbot.org destination is still transferred' |
| 411 | |
| 412 | prepare hop-fail; store_main "$B"; STUB_HOP=1; STUB_SUDO_FAIL=1 |
| 413 | run "$B" |
| 414 | [ "$RC" -eq 8 ] && [ -f "$LOGDIR/pending.hopbot.org" ] && [ ! -e "$LOGDIR/receipt.hopbot.org" ] || fail 'failed root copy: wrong exit, receipt or marker' |
| 415 | receipt interplane.io published fixture-hub:/fixture-web "$B" |
| 416 | STUB_SUDO_FAIL=0; again; published "$B" |
| 417 | [ "$(grep -c '^rsync ' "$TEST_ROOT/trace")" -eq 0 ] && [ "$(grep -c '^sudo ' "$TEST_ROOT/trace")" -eq 1 ] || fail 'retry did not transfer hopbot.org alone' |
| 418 | receipt hopbot.org published "local:$HOPWEBDIR" "$B" |
| 419 | passed 'a failed root copy exits 8 with interplane.io receipted and hopbot.org pending; the retry transfers hopbot.org alone' |
| 420 | |
| 421 | prepare hop-dest; store_main "$B"; STUB_HOP=1 |
| 422 | published "$B" |
| 423 | OLDHOP=$HOPWEBDIR |
| 424 | HOPWEBDIR="$TEST_ROOT/www-hop-dest/hopbot-two"; mkdir -p "$HOPWEBDIR" |
| 425 | again; published "$B" |
| 426 | [ "$(grep -c '^rsync ' "$TEST_ROOT/trace")" -eq 0 ] && grep -Fxq "$(SUDO_LINE)" "$TEST_ROOT/trace" || fail 'changed hopbot.org destination was skipped' |
| 427 | [ -f "$HOPWEBDIR/index.html" ] && [ -f "$OLDHOP/index.html" ] || fail 'destination change: new folder empty or old folder altered' |
| 428 | grep -q "destination changed from local:$OLDHOP to local:$HOPWEBDIR" "$TEST_ROOT/stdout" || fail 'the log does not name the destination change' |
| 429 | receipt hopbot.org published "local:$HOPWEBDIR" "$B" |
| 430 | passed 'hopbot.org destination change: the same content is transferred to the new folder; the old folder is left as it was and the log says so' |
| 431 | |
| 432 | # ---- withdrawal |
| 433 | prepare withdraw; store_main "$B"; STUB_HOP=1 |
| 434 | published "$B" |
| 435 | [ -f "$HOPWEBDIR/index.html" ] || fail 'withdrawal control: nothing was published first' |
| 436 | STUB_HOP=0; again; published "$B" |
| 437 | grep -Fxq "$(SUDO_LINE)" "$TEST_ROOT/trace" || fail 'withdrawal did not use the one documented root command' |
| 438 | [ -d "$HOPWEBDIR" ] && [ -z "$(ls -A "$HOPWEBDIR")" ] || fail 'withdrawal left files in the hopbot.org folder' |
| 439 | [ "$(field "$LOGDIR/receipt.hopbot.org" state)" = withdrawn ] && [ "$(field "$LOGDIR/receipt.hopbot.org" digest)" = none ] || fail 'no withdrawal record' |
| 440 | receipt hopbot.org withdrawn "local:$HOPWEBDIR" "$B" |
| 441 | passed 'withdrawal: a commit without a Hop release empties the hopbot.org folder with the same root command and leaves a withdrawal record' |
| 442 | again; published "$B" |
| 443 | no_transfer 'after withdrawal' |
| 444 | passed 'after a withdrawal nothing more is transferred' |
| 445 | STUB_HOP=2; again; published "$B" |
| 446 | [ "$(grep -c '^sudo ' "$TEST_ROOT/trace")" -eq 1 ] && [ -f "$HOPWEBDIR/index.html" ] || fail 'a Hop release after a withdrawal was not published' |
| 447 | receipt hopbot.org published "local:$HOPWEBDIR" "$B" |
| 448 | passed 'a Hop release after a withdrawal is published again' |
| 449 | |
| 450 | prepare withdraw-missing; store_main "$B"; STUB_HOP=1 |
| 451 | published "$B" |
| 452 | cp "$LOGDIR/receipt.hopbot.org" "$TEST_ROOT/hop-receipt" |
| 453 | STUB_HOP=0; HOPWEBDIR="$TEST_ROOT/www-withdraw-missing/elsewhere"; mkdir -p "$HOPWEBDIR"; again; run "$B" |
| 454 | [ "$RC" -eq 7 ] && grep -q 'name that folder in HOPWEBDIR to withdraw it' "$TEST_ROOT/stdout" || fail 'withdrawal from another folder was not refused' |
| 455 | no_transfer 'withdrawal from another folder'; cmp "$LOGDIR/receipt.hopbot.org" "$TEST_ROOT/hop-receipt" || fail 'refused withdrawal changed the receipt' |
| 456 | HOPWEBDIR="$TEST_ROOT/www-withdraw-missing/hopbot.org"; rm -rf "$HOPWEBDIR"; again; run "$B" |
| 457 | [ "$RC" -eq 7 ] && grep -q 'withdrawn and the hopbot.org folder is missing' "$TEST_ROOT/stdout" || fail 'withdrawal with a missing folder was not refused' |
| 458 | no_transfer 'withdrawal with a missing folder'; cmp "$LOGDIR/receipt.hopbot.org" "$TEST_ROOT/hop-receipt" || fail 'refused withdrawal changed the receipt' |
| 459 | passed 'withdrawal is refused, exit 7, with no transfer and the receipt kept, when HOPWEBDIR names another folder or the folder is missing' |
| 460 | |
| 461 | # ---- the log: a run that names no folder leaves the default (live) folder alone unless it publishes |
| 462 | prepare log-default; store_main "$B" |
| 463 | OLDHOME=$HOME; HOME="$TEST_ROOT/home-log"; mkdir -p "$HOME"; export HOME |
| 464 | LIVE="$HOME/.local/share/interplane-site" |
| 465 | unset LOGDIR |
| 466 | run "$A" |
| 467 | [ "$RC" -eq 5 ] && grep -q 'is not the signed main' "$TEST_ROOT/stdout" || fail "default log folder: expected refusal 5, got $RC" |
| 468 | grep -q 'not logged: no log folder was named' "$TEST_ROOT/stderr" || fail 'the refusal does not say that it was not logged' |
| 469 | [ ! -e "$LIVE" ] || fail 'a refused run that named no log folder wrote to the default log folder' |
| 470 | passed 'no log folder named: a refusal (commit is not the signed main) is printed, exit 5, and the default log folder is not created or written' |
| 471 | STUB_QUIET=1; run "$B"; STUB_QUIET=0 |
| 472 | [ "$RC" -eq 0 ] && [ ! -e "$LIVE" ] || fail 'the quiet-flag skip wrote to the default log folder' |
| 473 | passed 'no log folder named: the quiet-flag skip leaves the default log folder alone' |
| 474 | NAMEDDIR="$TEST_ROOT/log-named" |
| 475 | run --log-dir "$NAMEDDIR" "$A" |
| 476 | [ "$RC" -eq 5 ] && grep -q 'refuse: .* is not the signed main' "$NAMEDDIR/sync.log" || fail '--log-dir: the refusal is not in the named log' |
| 477 | [ ! -e "$LIVE" ] || fail '--log-dir: the default log folder was written' |
| 478 | passed '--log-dir DIR: the same refusal is recorded in DIR/sync.log and the default folder stays untouched' |
| 479 | LOGDIR="$TEST_ROOT/log-env"; export LOGDIR |
| 480 | run "$A" |
| 481 | [ "$RC" -eq 5 ] && grep -q 'refuse: .* is not the signed main' "$LOGDIR/sync.log" || fail 'LOGDIR: the refusal is not in the named log' |
| 482 | [ ! -e "$LIVE" ] || fail 'LOGDIR: the default log folder was written' |
| 483 | passed 'LOGDIR set: the refusal is recorded there' |
| 484 | unset LOGDIR; again |
| 485 | run "$B" |
| 486 | [ "$RC" -eq 0 ] && [ "$(transfers)" -eq 1 ] || { cat "$TEST_ROOT/stdout" "$TEST_ROOT/stderr" >&2; fail "default log folder: a publish gave $RC"; } |
| 487 | grep -q "published interplane.io $B" "$LIVE/sync.log" && [ "$(field "$LIVE/receipt.interplane.io" commit)" = "$B" ] || fail 'a publish with no log folder named did not write the default log and receipt' |
| 488 | LINES=$(wc -l < "$LIVE/sync.log"); again; run "$B" |
| 489 | [ "$RC" -eq 0 ] && [ "$(transfers)" -eq 0 ] && [ "$(wc -l < "$LIVE/sync.log")" -eq "$LINES" ] || fail 'an unchanged run added a line to the default log' |
| 490 | again; run "$A" |
| 491 | [ "$RC" -eq 5 ] && [ "$(wc -l < "$LIVE/sync.log")" -eq "$LINES" ] || fail 'a refusal after a publish added a line to the default log' |
| 492 | passed 'no log folder named: a publish writes the default log and receipt; a later unchanged run and a later refusal add no line to it' |
| 493 | HOME=$OLDHOME; export HOME |
| 494 | LOGDIR="$TEST_ROOT/log-after"; export LOGDIR |
| 495 | |
| 496 | # ---- the default compiler lookup is local and still passes the checksum gate |
| 497 | prepare default-compiler; store_main "$B" |
| 498 | OMEGA_SRC="$TEST_ROOT/omega" |
| 499 | export OMEGA_SRC |
| 500 | mkdir -p "$OMEGA_SRC/seed/out" |
| 501 | cp "$TEST_ROOT/compiler" "$OMEGA_SRC/seed/out/omc" |
| 502 | unset OMC |
| 503 | published "$B" |
| 504 | [ "$(transfers)" -eq 1 ] || fail 'default compiler lookup did not publish' |
| 505 | passed 'default compiler lookup' |
| 506 | |
| 507 | printf 'RESULT pass=%d fail=0 (publisher controls; git is real and local, ipl, compiler, builder, rsync and sudo are stubbed)\n' "$N" |