Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-architecture-mv/blob/main/tools/ops/test-store-post-update.sh # aien-architecture-mv Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-architecture-mv / tools / ops / test-store-post-update.sh` 77 lines ยท 4726 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # test-store-post-update.sh: the store hook in a scratch home (its own ~/.gitconfig, git store, sync, 3 # spark-cleanup and disk-alarm stand-ins). Real pushes; nothing outside the scratch folder is read or written. 4 # Usage: bash tools/ops/test-store-post-update.sh exit 0 all pass, 1 any fail. 5 set -u 6 here=$(cd "$(dirname "$0")" && pwd) 7 T=$(mktemp -d "${TMPDIR:-/tmp}/test-store-hook.XXXXXX") 8 trap 'rm -rf "$T"' EXIT 9 fails=0 10 ok() { echo "PASS $1"; } 11 bad() { echo "FAIL $1"; fails=$((fails + 1)); } 12 13 H="$T/home" 14 mkdir -p "$H/.local/bin" "$H/.local/lib/store-hooks" "$H/.local/lib/bazinga-git" "$H/.config/git" "$H/git/nest" "$H/elsewhere" 15 cp "$here/store-post-update" "$H/.local/lib/store-hooks/post-update" 16 # the install, as README "Store hook" gives it 17 printf '[includeIf "gitdir:~/git/"]\n\tpath = .config/git/store.inc\n[user]\n\tname = t\n\temail = t@t\n[init]\n\tdefaultBranch = main\n' > "$H/.gitconfig" 18 printf '[core]\n\thooksPath = %s/.local/lib/store-hooks\n' "$H" > "$H/.config/git/store.inc" 19 # stand-ins: each records its arguments, every GIT_ variable it can see, and its working folder 20 for f in spark-cleanup disk-alarm; do 21 printf '#!/bin/sh\n[ -f "%s/%s.fail" ] && exit 9\nprintf "%%s|%%s|%%s\\n" "$*" "$(env | grep -c "^GIT_")" "$(pwd)" >> "%s/%s.calls"\n' \ 22 "$T" "$f" "$T" "$f" > "$H/.local/bin/$f" 23 done 24 printf '#!/bin/sh\n[ -f "%s/sync.fail" ] && exit 9\necho "$1" >> "%s/sync.calls"\n' "$T" "$T" > "$H/.local/lib/bazinga-git/sync.sh" 25 chmod +x "$H/.local/bin/"* "$H/.local/lib/bazinga-git/sync.sh" "$H/.local/lib/store-hooks/post-update" 26 27 export HOME="$H" GIT_CONFIG_NOSYSTEM=1 GIT_TERMINAL_PROMPT=0 28 unset XDG_CONFIG_HOME GIT_DIR GIT_WORK_TREE 29 git init -q --bare "$H/git/alpha.git" 30 git init -q --bare "$H/git/nest/beta.git" 31 git init -q --bare "$H/elsewhere/gamma.git" 32 git init -q "$T/w" 33 git -C "$T/w" commit -q --allow-empty -m one 34 n=0 35 push() { n=$((n + 1)); git -C "$T/w" commit -q --allow-empty -m "c$n"; git -C "$T/w" push -q "$1" HEAD:main 2> "$T/push.err"; } 36 # the detached steps finish within a moment; wait for the expected count of lines, at most 10 s 37 lines() { local i=0; while [ "$i" -lt 100 ]; do [ "$(cat "$T/$1.calls" 2>/dev/null | wc -l)" -ge "$2" ] && break; sleep 0.1; i=$((i + 1)); done 38 cat "$T/$1.calls" 2>/dev/null | wc -l; } 39 40 # 1. a landing on a store repository: sync, spark-cleanup --landed NAME, then disk-alarm --quiet; no GIT_ variable leaks 41 push "$H/git/alpha.git"; r=$? 42 [ "$r" = 0 ] && [ "$(lines spark-cleanup 1)" = 1 ] && [ "$(lines disk-alarm 1)" = 1 ] && 43 grep -qx 'alpha' "$T/sync.calls" && grep -qx -- '--landed alpha|0|/' "$T/spark-cleanup.calls" && 44 grep -qx -- '--quiet|0|/' "$T/disk-alarm.calls" && ok "landing runs sync, spark-cleanup --landed, disk-alarm" || 45 bad "landing (push $r): $(cat "$T"/*.calls 2>/dev/null | tr '\n' ' ')" 46 47 # 2. a repository in a nested store folder, created after the install, gets the hook with no step of its own 48 push "$H/git/nest/beta.git" 49 [ "$(lines spark-cleanup 2)" = 2 ] && grep -qx -- '--landed beta|0|/' "$T/spark-cleanup.calls" && 50 ok "nested store repository" || bad "nested store repository: $(cat "$T/spark-cleanup.calls" | tr '\n' ' ')" 51 52 # 3. negative control: a bare repository outside the store runs none of it 53 push "$H/elsewhere/gamma.git"; sleep 1 54 [ "$(lines spark-cleanup 2)" = 2 ] && ! grep -qx gamma "$T/sync.calls" && ok "repository outside the store: no hook" || 55 bad "repository outside the store ran the hook" 56 57 # 4. every step failing still lands the push (exit 0), and the steps after a failed one still run 58 touch "$T/sync.fail" "$T/spark-cleanup.fail" 59 push "$H/git/alpha.git"; r=$? 60 [ "$r" = 0 ] && [ "$(lines disk-alarm 3)" = 3 ] && ok "failing steps never fail the push" || bad "failing steps (push $r, alarms $(lines disk-alarm 3))" 61 rm -f "$T/sync.fail" "$T/spark-cleanup.fail" 62 63 # 5. the push does not wait for a slow step 64 printf '#!/bin/sh\nsleep 5\n' > "$H/.local/bin/spark-cleanup" 65 s=$(date +%s); push "$H/git/alpha.git"; e=$(( $(date +%s) - s )) 66 [ "$e" -lt 4 ] && ok "push does not wait for the clean-up (${e} s)" || bad "push waited ${e} s" 67 68 # 6. mutant: the same hook without its GIT_ variable reset must fail case 1's check 69 grep -v '^for v in ' "$here/store-post-update" > "$H/.local/lib/store-hooks/post-update" 70 for f in spark-cleanup; do 71 printf '#!/bin/sh\nprintf "%%s|%%s\\n" "$*" "$(env | grep -c "^GIT_")" >> "%s/mut.calls"\n' "$T" > "$H/.local/bin/$f" 72 done 73 push "$H/git/alpha.git"; lines mut 1 > /dev/null 74 grep -qx -- '--landed alpha|0' "$T/mut.calls" && bad "mutant without the GIT_ reset passed" || ok "mutant without the GIT_ reset caught" 75 76 [ "$fails" = 0 ] && echo "TEST PASS store-post-update" || echo "TEST FAIL store-post-update fails=$fails" 77 [ "$fails" = 0 ]