interplane.Get Omega
Read in your language

interplane-install

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

interplane-install / tests / run.sh

704 lines · 48761 bytes Raw Blame History
1#!/bin/bash
2# tests/run.sh SOURCE: the gate. Installs into fresh home folders and checks what a person gets,
3# and that each thing that must be refused is refused.
4# SOURCE a directory holding omega-mv/repo.git and interplane-forge/repo.git (a copy of what
5# interplane.io serves), or an https base such as https://interplane.io/projects (then the
6# piped-install case N takes this installer from there too, as a person would)
7# Run it from a clone of this repository whose main is the commit under test. Needs a 64-bit Arm
8# Linux host. Ends with "GATE PASS cases=N" or "GATE FAIL ...".
9set -u
10SRC=${1:?usage: tests/run.sh SOURCE}
11HERE=$(cd "$(dirname "$0")/.." && pwd)
12[ "$(git -C "$HERE" rev-parse HEAD)" = "$(git -C "$HERE" rev-parse refs/heads/main)" ] || { echo "GATE FAIL: run from a checkout of main" >&2; exit 2; }
13# check takes ONE command. `check NAME [ a ] && [ b ]` would test only a, and `check NAME cmd; cmd2`
14# would run cmd2 outside the check, so the gate refuses to run while any check line (also an indented
15# one, and a kill_check) holds && || or ; outside single quotes (reviews of 175e9ef9 and 69cc9475).
16bad=$(grep -E '^[[:space:]]*(kill_)?check ' "$0" | sed "s/'[^']*'//g" | grep -E '&&|\|\||;' || true)
17if [ -n "$bad" ]; then printf '%s\n' "$bad"; echo "GATE FAIL: a check line joins two commands; use one command (none_of, not, bash -c)" >&2; exit 2; fi
18W=$(mktemp -d "${TMPDIR:-/tmp}/interplane-install-gate.XXXXXX")
19trap 'pkill -f "git-daemon.*$W" 2>/dev/null; rm -rf "$W"' 0
20# A folder source (a live copy of what interplane.io serves) can move while the gate runs, and a case that
21# compares two installs would then see a change that is not the installer's. Take main of each project
22# once, and use that for every case.
23if [ -d "$SRC/omega-mv/repo.git" ]; then
24 for n in omega-mv interplane-forge; do
25 mkdir -p "$W/source/$n" && git init -q --bare -b main "$W/source/$n/repo.git" &&
26 git --git-dir="$W/source/$n/repo.git" fetch -q --no-tags "$SRC/$n/repo.git" +refs/heads/main:refs/heads/main || { echo "GATE FAIL: could not copy $SRC/$n" >&2; exit 2; }
27 done
28 SRC=$W/source
29fi
30exec 8>&1
31pass=0 fail=0 killed=0 nmut=0 INV=1 invn=0
32: > "$W/names"
33ok() { pass=$((pass + 1)); echo "PASS $1" >&8; printf '%s\n' "$1" >> "$W/names"; }
34no() { fail=$((fail + 1)); echo "FAIL $1" >&8; }
35check() { local n=$1; shift; if "$@" >/dev/null 2>&1; then ok "$n"; else no "$n"; fi; }
36# kill_check NAME cmd...: the gate's own mutant check. cmd is a case's check run against an installer
37# with one deliberate fault; it must FAIL there, and then the mutant counts as killed.
38kill_check() { local n=$1; shift; if "$@" >/dev/null 2>&1; then no "$n (the faulty installer passed it)"; else ok "$n"; killed=$((killed + 1)); fi; }
39not() { ! "$@"; }
40# home NAME: a fresh, empty home folder; sets H
41home() { H=$W/$1; mkdir -p "$H"; }
42# inst: the installer, then (after a run that exits 0) the invariants of what the person has
43inst() {
44 local rc=0 out=$W/.inst.out
45 env -i HOME="$H" PATH="$H/.local/bin:${P:-/usr/bin:/bin}" INTERPLANE_SOURCE="${SOURCE:-$SRC}" ${STOP:+IPL_TEST_STOP=$STOP} sh "${INSTALLER:-$HERE}/install.sh" "$@" > "$out" 2>&1 || rc=$?
46 cat "$out"
47 if [ "$rc" = 0 ] && [ "$INV" = 1 ]; then invariants "$out"; fi
48 return "$rc"
49}
50none_of() { local f; for f; do [ ! -e "$f" ] && [ ! -L "$f" ] || return 1; done; }
51empty_store() { [ -z "$(ls -A "$H/$DATA/store/projects" 2>/dev/null)" ]; }
52mode_is() { [ "$(stat -c %a "$2")" = "$1" ]; }
53commit() { git -C "$1" -c user.name=t -c user.email=t@t commit -q --allow-empty -m "$2"; }
54store_hash() { cat "$H/$DATA/store/catalog.tsv" "$H"/$DATA/store/projects/*/chain.tsv | sha256sum; }
55ipc() { env -i HOME="$H" PATH="$H/.local/bin:/usr/bin:/bin" interplane "$@"; }
56OMC_SHA=$(sed -n 's/^OMEGA_RELEASE_OMC_SHA256=//p' "$HERE/install.sh")
57DATA=.local/share/interplane
58pin_of() { sed -n "s/^$2=//p" "$1/install.sh"; }
59inv_ipc() { env -i HOME="$H" PATH=/usr/bin:/bin bash "$H/$DATA/install/bin/interplane" "$@"; }
60bin_omc_sha() { sha256sum < "$H/.local/bin/omc" | cut -d' ' -f1; }
61store_install_main() { git --git-dir="$H/$DATA/store/projects/interplane-install/repo.git" rev-parse main 2> /dev/null; }
62# inv_why LOG: after a run of the installer that exits 0, what the person has must be what the installer
63# says and what its pins say, whatever way it was run: the compiler in lib and in bin is the pinned one (or
64# bin has a file of theirs that the run said it kept, and that is not one the installer put there), the
65# store tool is the pinned commit, the command is the store's installer, the final line names that
66# installer, and the store verifies. A promise that the installer's words make about what was installed
67# is checked here for every run of every case, not once. Prints what is wrong (nothing when all holds).
68inv_why() {
69 local log=$1 dir=${INSTALLER:-$HERE} why= want forge store smain
70 want=$(pin_of "$dir" OMEGA_RELEASE_OMC_SHA256); forge=$(pin_of "$dir" FORGE_COMMIT)
71 [ "$(sha256sum < "$H/$DATA/lib/omc" | cut -d' ' -f1)" = "$want" ] || why="$why lib-omc"
72 if [ "$(bin_omc_sha)" != "$want" ]; then
73 grep -q '^kept your existing .*/omc' "$log" || why="$why bin-omc-stale"
74 if grep -qxF "$(bin_omc_sha)" "$H/$DATA/omc-installed" 2> /dev/null; then why="$why bin-omc-is-ours-and-stale"; fi
75 fi
76 [ "$(git -C "$H/$DATA/interplane" rev-parse HEAD 2> /dev/null)" = "$forge" ] || why="$why tools-commit"
77 store=$(inv_ipc where | sed -n 's/^store //p')
78 smain=$(git --git-dir="$store/projects/interplane-install/repo.git" rev-parse main 2> /dev/null)
79 { [ -n "$smain" ] && [ "$(git -C "$H/$DATA/install" rev-parse HEAD 2> /dev/null)" = "$smain" ]; } || why="$why command-commit"
80 grep -qx "Installer: interplane-install ${smain:0:12}" "$log" || why="$why final-line"
81 inv_ipc verify > /dev/null 2>&1 || why="$why verify"
82 echo "$why"
83}
84inv_holds() { [ -z "$(inv_why "$1")" ]; }
85invariants() {
86 local why
87 invn=$((invn + 1)); why=$(inv_why "$1")
88 if [ -z "$why" ]; then ok "INV-$invn"; else no "INV-$invn:$why ($1)"; fi
89}
90
91# --- cases that the gate also runs against a faulty copy of the installer (the mutants at the end) --
92# so each is a function of the installer folder; they use the installed home H.
93# src_update_run INSTALLER NAME: the source's omega-mv main has one more commit than the store's
94# (made without a checkout); run the installer against it. Sets SU_NEW, SU_LINES, SU_RC.
95src_update_run() {
96 local s4=$W/src4-$2 g4 t
97 rm -rf "$s4"; mkdir -p "$s4/omega-mv" "$s4/interplane-forge"
98 git clone -q --bare "$H/$DATA/store/projects/omega-mv/repo.git" "$s4/omega-mv/repo.git"
99 git clone -q --bare "$H/$DATA/store/projects/interplane-forge/repo.git" "$s4/interplane-forge/repo.git"
100 g4=$s4/omega-mv/repo.git
101 t=$(git --git-dir="$g4" rev-parse 'main^{tree}')
102 SU_NEW=$(git --git-dir="$g4" -c user.name=t -c user.email=t@t commit-tree "$t" -p "$(git --git-dir="$g4" rev-parse main)" -m newer)
103 git --git-dir="$g4" update-ref refs/heads/main "$SU_NEW"
104 SU_LINES=$(wc -l < "$H/$DATA/store/projects/omega-mv/chain.tsv")
105 INSTALLER=$1 SOURCE=$s4 inst --quick > "$W/su-$2.log" 2>&1; SU_RC=$?
106}
107su_new_main() { [ "$(git --git-dir="$H/$DATA/store/projects/omega-mv/repo.git" rev-parse main)" = "$SU_NEW" ]; }
108su_two_more_lines() { [ "$(wc -l < "$H/$DATA/store/projects/omega-mv/chain.tsv")" = $((SU_LINES + 2)) ]; }
109# share_with_stray_mark SCRIPT PROJECT: a stray export mark in the private PROJECT, then `interplane
110# share` (SCRIPT) is started and waited for. Sets port; log in $W/share-PROJECT.log.
111share_with_stray_mark() {
112 port=$((20000 + RANDOM % 20000))
113 : > "$H/$DATA/store/projects/$2/repo.git/git-daemon-export-ok"
114 env -i HOME="$H" PATH="$H/.local/bin:/usr/bin:/bin" setsid bash "$1" share --port "$port" > "$W/share-$2.log" 2>&1 &
115 for _ in $(seq 50); do grep -q '^Read-only' "$W/share-$2.log" && (exec 3<>"/dev/tcp/127.0.0.1/$port") 2>/dev/null && break; sleep 0.2; done
116}
117stop_share() { pkill -f "git-daemon.*--port=$port" 2>/dev/null; pkill -f "git daemon.*--port=$port" 2>/dev/null; return 0; }
118# The password used in the address cases is made fresh each run, so that no file of any project (this
119# gate's own text is installed into the store too) can hold it by accident. It has an @ in it: both
120# halves must stay out of everything the installer prints or writes.
121PWHEAD=pw$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')
122PWTAIL=tail$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')
123PWSEC=$PWHEAD@$PWTAIL
124# pw_run INSTALLER LOGNAME: a source address with a password in it (rewritten by git to the real source)
125pw_run() {
126 PW_LOG=$2.log
127 printf '[url "%s/"]\n\tinsteadOf = https://tok:%s@example.invalid/\n' "$SRC" "$PWSEC" > "$H/.gitconfig"
128 INSTALLER=$1 SOURCE=https://tok:$PWSEC@example.invalid inst --quick > "$W/$PW_LOG" 2>&1; PW_RC=$?
129}
130pw_clean() { ! grep -rqF -e "$PWHEAD" -e "$PWTAIL" "$H/.local" "$H/.config" "$W/$PW_LOG"; }
131
132# --- A: a full install, with the store tool's own gate --------------------------------------------
133home a
134inst > "$W/a.log" 2>&1; rc=$?
135check A-installs-exit-0 [ "$rc" = 0 ]
136check A-store-gate-passed grep -q '^ok: GATE PASS' "$W/a.log"
137check A-omc-is-the-release [ "$(sha256sum < "$H/.local/bin/omc" | cut -d' ' -f1)" = "$OMC_SHA" ]
138printf 'fn main to int\nret 42\nend\n' > "$W/p.om"
139"$H/.local/bin/omc" < "$W/p.om" > "$W/p" 2>/dev/null && chmod +x "$W/p" && "$W/p"; rc=$?
140check A-omc-compiles-and-runs [ "$rc" = 42 ]
141check A-three-private-projects [ "$(ipc list | awk 'NR > 1 && $2 == "no"' | wc -l)" = 3 ]
142check A-verify-all ipc verify
143check A-key-private [ "$(stat -c %a "$H/.config/interplane/owner-key")" = 600 ]
144check A-pins-private [ "$(stat -c %a "$H/.config/interplane/owner-pins")" = 600 ]
145check A-store-only-yours mode_is 700 "$H/$DATA/store"
146check A-repo-only-yours mode_is 700 "$H/$DATA/store/projects/omega-mv/repo.git"
147check A-chain-only-yours mode_is 600 "$H/$DATA/store/projects/omega-mv/chain.tsv"
148check A-omc-runs-for-you mode_is 755 "$H/.local/bin/omc"
149sh "$HERE/install.sh" --help > "$W/help.txt" 2>&1; ipc help > "$W/help2.txt" 2>&1
150check A-help-is-text-only bash -c '! grep -q "^set \|^umask" "$1" "$2" && grep -q "^What it does" "$1" && grep -q "interplane list" "$2"' _ "$W/help.txt" "$W/help2.txt"
151
152check A-installer-line bash -c 'grep -q "^Installer: interplane-install [0-9a-f]\{12\}$" "$1"' _ "$W/a.log"
153# help is text, also when the file is piped into sh (no file of its own to read it from)
154( cd "$W" && env -i HOME="$H" PATH=/usr/bin:/bin sh -s -- --help < "$HERE/install.sh" ) > "$W/phelp.txt" 2>&1; rc=$?
155check A-piped-help-exit-0 [ "$rc" = 0 ]
156check A-piped-help-has-the-text grep -q '^What it does' "$W/phelp.txt"
157sh "$HERE/install.sh" --help > "$W/help3.txt" 2>&1; rc=$?
158check A-help-exit-0 [ "$rc" = 0 ]
159check A-help-has-the-text grep -q '^What it does' "$W/help3.txt"
160check A-help-prints-no-code bash -c '! grep -q "^set \|^umask" "$1" "$2"' _ "$W/phelp.txt" "$W/help3.txt"
161
162# --- B: running it again changes nothing ----------------------------------------------------------
163before=$(cat "$H/$DATA/store/catalog.tsv" "$H/$DATA"/store/projects/*/chain.tsv | sha256sum)
164inst --quick > "$W/b.log" 2>&1; rc=$?
165check B-rerun-exit-0 [ "$rc" = 0 ]
166check B-rerun-changes-nothing [ "$(cat "$H/$DATA/store/catalog.tsv" "$H/$DATA"/store/projects/*/chain.tsv | sha256sum)" = "$before" ]
167
168# --- C: a new project, a change, a landing; a rewrite of history is refused -----------------------
169( cd "$W" && ipc new notes >/dev/null && ipc get notes "$W/notes" >/dev/null )
170check C-new-and-get [ -d "$W/notes/.git" ]
171commit "$W/notes" one
172check C-land ipc land notes "$W/notes"
173commit "$W/notes" two
174check C-land-again ipc land notes "$W/notes"
175chain=$(sha256sum < "$H/$DATA/store/projects/notes/chain.tsv")
176git -C "$W/notes" reset -q --hard HEAD~1
177commit "$W/notes" other
178ipc land notes "$W/notes" >/dev/null 2>&1; rc=$?
179check C-rewrite-refused [ "$rc" != 0 ]
180check C-rewrite-left-no-record [ "$(sha256sum < "$H/$DATA/store/projects/notes/chain.tsv")" = "$chain" ]
181check C-head-is-two [ "$(git --git-dir="$H/$DATA/store/projects/notes/repo.git" log -1 --format=%s main)" = two ]
182
183# a landing that stops part-way is finished by the same command; a different head first finishes the old one
184( cd "$W" && ipc new notes2 >/dev/null && ipc get notes2 "$W/notes2" >/dev/null )
185commit "$W/notes2" one
186env -i HOME="$H" PATH="$H/.local/bin:/usr/bin:/bin" IPL_TEST_STOP=after-record interplane land notes2 "$W/notes2" > "$W/land1.log" 2>&1; rc=$?
187check LAND-stopped-exits-nonzero [ "$rc" != 0 ]
188check LAND-stopped-says-how grep -q 'the landing stopped part-way; run the same command again to finish it' "$W/land1.log"
189check LAND-stopped-left-its-request test -f "$H/$DATA/records/notes2.land-pending"
190check LAND-same-command-finishes-it ipc land notes2 "$W/notes2"
191check LAND-finished-verifies ipc verify notes2
192check LAND-head-is-the-landed-commit [ "$(git --git-dir="$H/$DATA/store/projects/notes2/repo.git" rev-parse main)" = "$(git -C "$W/notes2" rev-parse HEAD)" ]
193check LAND-request-is-gone none_of "$H/$DATA/records/notes2.land-pending"
194commit "$W/notes2" two
195env -i HOME="$H" PATH="$H/.local/bin:/usr/bin:/bin" IPL_TEST_STOP=after-record interplane land notes2 "$W/notes2" > "$W/land2.log" 2>&1; rc=$?
196check LAND-second-stopped [ "$rc" != 0 ]
197commit "$W/notes2" three
198check LAND-another-head-finishes-the-old-one-first ipc land notes2 "$W/notes2"
199check LAND-another-head-verifies ipc verify notes2
200check LAND-another-head-is-in [ "$(git --git-dir="$H/$DATA/store/projects/notes2/repo.git" rev-parse main)" = "$(git -C "$W/notes2" rev-parse HEAD)" ]
201check LAND-both-landings-recorded [ "$(grep -c " LAND " "$H/$DATA/store/projects/notes2/chain.tsv")" = 3 ]
202# a new project that stops part-way is finished by the same command
203env -i HOME="$H" PATH="$H/.local/bin:/usr/bin:/bin" IPL_TEST_STOP=after-record interplane new halfnew > "$W/new1.log" 2>&1; rc=$?
204check NEW-stopped-exits-nonzero [ "$rc" != 0 ]
205check NEW-stopped-says-how grep -q 'run the same command again' "$W/new1.log"
206check NEW-same-command-finishes-it ipc new halfnew
207check NEW-finished-verifies ipc verify halfnew
208check NEW-finished-is-listed bash -c 'env -i HOME="$1" PATH="$1/.local/bin:/usr/bin:/bin" interplane list | grep -q "^halfnew "' _ "$H"
209# leftovers of killed commands: a folder with only a half-made repository, one with a repository and no chain
210mkdir -p "$H/$DATA/store/projects/leftover/repo.git.new" "$H/$DATA/store/projects/leftover2/repo.git"
211check NEW-over-a-leftover ipc new leftover2
212
213# --- D: import what you choose; share only what is public -----------------------------------------
214git init -q -b main "$W/mine" && commit "$W/mine" mine
215check D-import-public ipc import "$W/mine" --public
216ipc import "$W/mine" mine >/dev/null 2>&1; rc=$?
217check D-import-same-name-refused [ "$rc" = 2 ]
218check D-import-private ipc import "$W/mine" secret
219# an address with a password in it: the password is not written into the signed evidence
220printf '[url "%s"]\n\tinsteadOf = https://tok:%s@example.invalid/mine.git\n' "$W/mine" "$PWSEC" > "$H/.gitconfig"
221check D-import-url-with-password ipc import "https://tok:$PWSEC@example.invalid/mine.git" withpw
222check D-password-not-recorded bash -c '! grep -rqF -e "$2" -e "$3" "$1" && grep -q "^source https://example.invalid/mine.git$" "$1/withpw.import-evidence"' _ "$H/$DATA/records" "$PWHEAD" "$PWTAIL"
223rm -f "$H/.gitconfig"
224# an import that stops part-way is finished by the same command, and by nothing else
225env -i HOME="$H" PATH="$H/.local/bin:/usr/bin:/bin" IPL_TEST_STOP=after-ref interplane import "$W/mine" halfway > "$W/half.log" 2>&1; rc=$?
226check D-import-stopped-says-how bash -c '[ "$1" != 0 ] && grep -q "run the same command again" "$2"' _ "$rc" "$W/half.log"
227ipc import "$W/notes" halfway >/dev/null 2>&1; rc=$?
228check D-other-source-cannot-finish-it [ "$rc" = 2 ]
229check D-same-command-finishes-it ipc import "$W/mine" halfway
230check D-finished-import-verifies ipc verify halfway
231# the same when it stopped before the first record was signed (inside ipl init), and a leftover folder does not stop an import
232env -i HOME="$H" PATH="$H/.local/bin:/usr/bin:/bin" IPL_TEST_STOP=after-record interplane import "$W/mine" halfinit > "$W/half2.log" 2>&1; rc=$?
233check D-import-stopped-in-init-says-how bash -c '[ "$1" != 0 ] && grep -q "run the same command again" "$2"' _ "$rc" "$W/half2.log"
234check D-import-stopped-in-init-finishes ipc import "$W/mine" halfinit
235check D-import-stopped-in-init-verifies ipc verify halfinit
236check D-import-over-a-leftover ipc import "$W/mine" leftover
237check D-import-over-a-leftover-verifies ipc verify leftover
238# a private project that has a stray export mark is not served, and the mark is taken away
239share_with_stray_mark "$H/.local/bin/interplane" secret
240git clone -q "git://127.0.0.1:$port/mine/repo.git" "$W/got-mine" 2>/dev/null
241check D-says-only-this-machine grep -q 'Only this machine can reach it' "$W/share-secret.log"
242check D-stray-export-mark-is-removed none_of "$H/$DATA/store/projects/secret/repo.git/git-daemon-export-ok"
243check D-public-is-served [ "$(git -C "$W/got-mine" log -1 --format=%s 2>/dev/null)" = mine ]
244git clone -q "git://127.0.0.1:$port/secret/repo.git" "$W/got-secret" 2>/dev/null; rc=$?
245check D-private-is-not-served [ "$rc" != 0 ]
246git clone -q "git://127.0.0.1:$port/omega-mv/repo.git" "$W/got-omega" 2>/dev/null; rc=$?
247check D-installed-private-is-not-served [ "$rc" != 0 ]
248git push -q "git://127.0.0.1:$port/mine/repo.git" HEAD:refs/heads/x 2>/dev/null; rc=$?
249check D-share-is-read-only [ "$rc" != 0 ]
250stop_share
251
252# --- E: one altered byte in a signed chain is caught ----------------------------------------------
253f=$H/$DATA/store/projects/mine/chain.tsv
254cp "$f" "$W/chain.bak"; sed -i '1s/PROJECT/PROJECTX/' "$f"
255ipc verify mine >/dev/null 2>&1; rc=$?
256check E-tamper-caught [ "$rc" = 3 ]
257cp "$W/chain.bak" "$f"
258check E-restored-verifies ipc verify mine
259
260# --- M: a run that was killed part-way is finished by the next run ----------------------------------
261home m
262STOP=after-record inst --quick > "$W/m1.log" 2>&1; rc=$? # the first record is written, not yet signed
263check M-stopped-run-fails [ "$rc" = 3 ]
264mkdir -p "$H/$DATA/.stage.dead" "$H/$DATA/store/projects/interplane-forge/repo.git.new" "$H/$DATA/interplane.new" "$H/$DATA/install.new" # what a kill -9 leaves
265printf 'half' > "$H/$DATA/records/omega-mv.import-evidence.new"
266inst --quick > "$W/m2.log" 2>&1; rc=$?
267check M-next-run-finishes [ "$rc" = 0 ]
268check M-leftovers-removed none_of "$H/$DATA/.stage.dead" "$H/$DATA/store/projects/interplane-forge/repo.git.new" "$H/$DATA/interplane.new" "$H/$DATA/install.new" "$H/$DATA/records/omega-mv.import-evidence.new"
269check M-verify-all ipc verify
270check M-three-projects [ "$(wc -l < "$H/$DATA/store/catalog.tsv")" = 3 ]
271home m2
272STOP=after-ref inst --quick > "$W/m3.log" 2>&1; rc=$? # the first import is recorded and signed, then killed
273check M2-stopped-run-fails [ "$rc" = 3 ]
274inst --quick > "$W/m4.log" 2>&1; rc=$?
275check M2-next-run-finishes [ "$rc" = 0 ]
276check M2-verify-all ipc verify
277
278# --- F: a machine that cannot run Omega gets a plain no, and nothing is written ---------------------
279home f; mkdir -p "$W/fakebin"; printf '#!/bin/sh\n[ "$1" = -m ] && echo x86_64 || /usr/bin/uname "$@"\n' > "$W/fakebin/uname"; chmod +x "$W/fakebin/uname"
280P="$W/fakebin:/usr/bin:/bin" inst > "$W/f.log" 2>&1; rc=$?
281check F-other-cpu-refused [ "$rc" = 2 ]
282check F-says-why grep -q '64-bit Arm Linux' "$W/f.log"
283check F-wrote-nothing none_of "$H/.local" "$H/.config"
284
285# --- G: a missing program is named, and nothing is written ------------------------------------------
286home g; mkdir -p "$W/nossh"
287for t in /usr/bin/* /bin/*; do b=$(basename "$t"); [ "$b" = ssh-keygen ] || [ -e "$W/nossh/$b" ] || ln -s "$t" "$W/nossh/$b"; done
288P="$W/nossh" inst > "$W/g.log" 2>&1; rc=$?
289check G-missing-tool-refused [ "$rc" = 2 ]
290check G-names-it grep -q 'missing: ssh-keygen' "$W/g.log"
291check G-wrote-nothing none_of "$H/.local" "$H/.config"
292
293# --- H: an omc that is already there is kept ---------------------------------------------------------
294home h; mkdir -p "$H/.local/bin"; printf '#!/bin/sh\necho mine\n' > "$H/.local/bin/omc"; chmod +x "$H/.local/bin/omc"
295cp "$H/.local/bin/omc" "$H/.local/bin/interplane"
296inst --quick > "$W/h.log" 2>&1; rc=$?
297check H-installs-exit-0 [ "$rc" = 0 ]
298check H-existing-omc-kept [ "$("$H/.local/bin/omc")" = mine ]
299check H-says-so grep -q 'kept your existing .*/omc' "$W/h.log"
300check H-existing-interplane-kept [ "$("$H/.local/bin/interplane")" = mine ]
301check H-says-that-too grep -q 'kept your existing .*/interplane' "$W/h.log"
302
303# --- I: a source without the pinned commit is refused before anything is built or recorded -----------
304home i; mkdir -p "$W/badsrc/omega-mv" "$W/badsrc/interplane-forge"
305git init -q -b main "$W/bad" && commit "$W/bad" impostor
306git clone -q --bare "$W/bad" "$W/badsrc/omega-mv/repo.git"
307git clone -q --bare "$SRC/interplane-forge/repo.git" "$W/badsrc/interplane-forge/repo.git"
308env -i HOME="$H" PATH=/usr/bin:/bin INTERPLANE_SOURCE="$W/badsrc" sh "$HERE/install.sh" --quick > "$W/i.log" 2>&1; rc=$?
309check I-impostor-source-refused [ "$rc" = 3 ]
310check I-says-pinned grep -q 'pinned commit' "$W/i.log"
311check I-recorded-nothing empty_store
312check I-installed-no-compiler none_of "$H/.local/bin/omc" "$H/$DATA/lib/omc" "$H/$DATA/lib/omc-ipl"
313# the same for an impostor Interplane beside the real Omega (the copy home a already holds)
314home pp; mkdir -p "$W/badsrc2/omega-mv" "$W/badsrc2/interplane-forge"
315git clone -q --bare "$W/a/$DATA/store/projects/omega-mv/repo.git" "$W/badsrc2/omega-mv/repo.git"
316git clone -q --bare "$W/bad" "$W/badsrc2/interplane-forge/repo.git"
317env -i HOME="$H" PATH=/usr/bin:/bin INTERPLANE_SOURCE="$W/badsrc2" sh "$HERE/install.sh" --quick > "$W/pp.log" 2>&1; rc=$?
318check P-impostor-interplane-refused [ "$rc" = 3 ]
319check P-says-which grep -q 'interplane-forge .* does not have the pinned commit' "$W/pp.log"
320check P-recorded-nothing empty_store
321check P-built-nothing none_of "$H/$DATA/interplane" "$H/.local/bin/omc"
322
323# --- S: the source has a newer main of Omega; it is brought up, kept out when it is not a descendant, and an
324# unreachable source does no harm (home a again: Omega and Interplane are installed there)
325H=$W/a
326src_update_run "$HERE" a
327check S-newer-source-exit-0 [ "$SU_RC" = 0 ]
328check S-store-has-the-new-main su_new_main
329check S-two-more-chain-lines su_two_more_lines
330check S-says-omega-was-brought-up grep -q "ok: omega-mv brought up to ${SU_NEW:0:12}" "$W/su-a.log"
331check S-forge-is-up-to-date grep -q 'ok: interplane-forge is up to date' "$W/su-a.log"
332check S-verify-all ipc verify
333h0=$(store_hash)
334SOURCE=$W/badsrc inst --quick > "$W/s2.log" 2>&1; rc=$?
335check S-unrelated-source-exit-0 [ "$rc" = 0 ]
336check S-unrelated-source-is-said grep -q 'main of omega-mv at the source does not descend from your copy; using your copy' "$W/s2.log"
337check S-unrelated-source-changes-nothing [ "$(store_hash)" = "$h0" ]
338check S-unrelated-source-keeps-main su_new_main
339SOURCE=/nonexistent-source inst --quick > "$W/s3.log" 2>&1; rc=$?
340check S-unreachable-source-exit-0 [ "$rc" = 0 ]
341check S-unreachable-source-is-said grep -q 'could not reach /nonexistent-source/omega-mv/repo.git' "$W/s3.log"
342check S-unreachable-source-changes-nothing [ "$(store_hash)" = "$h0" ]
343check S-verify-all-after ipc verify
344
345# --- T: checkouts that a kill left half-made (the store tool's tree, the command's tree) are made again
346rm -rf "$H/$DATA/interplane/ipl" "$H/$DATA/interplane/.git/index" "$H/$DATA/install/bin"
347inst --quick > "$W/t.log" 2>&1; rc=$?
348check T-killed-checkouts-exit-0 [ "$rc" = 0 ]
349check T-says-the-old-ones-are-kept grep -q 'was not as it should be; it is kept as' "$W/t.log"
350check T-tool-is-whole test -f "$H/$DATA/interplane/ipl/ipl"
351check T-command-is-whole test -f "$H/$DATA/install/bin/interplane"
352check T-verify-all ipc verify
353check T-list-works ipc list
354
355# --- L: a newer installer brings an existing install up to date (home a again) ----------------------
356H=$W/a
357git clone -q "$HERE" "$W/up"; printf '# upgraded\n' >> "$W/up/bin/interplane"; git -C "$W/up" -c user.name=t -c user.email=t@t commit -q -am newer
358upnew=$(git -C "$W/up" rev-parse HEAD)
359lines=$(wc -l < "$H/$DATA/store/projects/interplane-install/chain.tsv")
360INSTALLER=$W/up inst --quick > "$W/l.log" 2>&1; rc=$?
361check L-upgrade-exit-0 [ "$rc" = 0 ]
362check L-store-has-new-head [ "$(git --git-dir="$H/$DATA/store/projects/interplane-install/repo.git" rev-parse main)" = "$upnew" ]
363check L-new-head-is-a-signed-landing [ "$(wc -l < "$H/$DATA/store/projects/interplane-install/chain.tsv")" = $((lines + 2)) ]
364check L-command-is-the-new-one grep -q '^# upgraded' "$H/$DATA/install/bin/interplane"
365check L-others-untouched grep -q 'ok: omega-mv is up to date' "$W/l.log"
366check L-final-line-names-the-checkout-head [ "$(grep '^Installer:' "$W/l.log" | tail -n 1)" = "Installer: interplane-install ${upnew:0:12}" ]
367check L-verify-all ipc verify
368# an older installer run afterwards is refused, and nothing is changed (it would put its older pins under a newer store)
369h1=$(store_hash)
370inst --quick > "$W/l2.log" 2>&1; rc=$?
371check L-older-installer-refused [ "$rc" = 3 ]
372check L-older-installer-says-the-newer-one-is-there grep -q 'your store already has a newer installer' "$W/l2.log"
373check L-older-installer-changes-nothing [ "$(store_hash)" = "$h1" ]
374check L-older-installer-keeps-new-head [ "$(git --git-dir="$H/$DATA/store/projects/interplane-install/repo.git" rev-parse main)" = "$upnew" ]
375# an installer that neither contains nor continues the one in the store: its pins are installed, the store keeps its own installer, and the last lines say so
376git clone -q "$HERE" "$W/ldiv"; printf '# sideways\n' >> "$W/ldiv/bin/interplane"; git -C "$W/ldiv" -c user.name=t -c user.email=t@t commit -q -am sideways
377INSTALLER=$W/ldiv inst --quick > "$W/l3.log" 2>&1; rc=$?
378check L-diverged-installer-exit-0 [ "$rc" = 0 ]
379check L-diverged-installer-keeps-the-stores-head [ "$(git --git-dir="$H/$DATA/store/projects/interplane-install/repo.git" rev-parse main)" = "$upnew" ]
380check L-diverged-installer-says-whose-pins-were-installed grep -q "^ (this run's compilers and store tool are the pins of installer $(git -C "$W/ldiv" rev-parse HEAD | cut -c1-12)," "$W/l3.log"
381
382# --- J: an owner pin for another key is never overwritten -------------------------------------------
383home j; mkdir -p "$H/.config/interplane"; printf '* SHA256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n' > "$H/.config/interplane/owner-pins"
384pin=$(sha256sum < "$H/.config/interplane/owner-pins")
385inst --quick > "$W/j.log" 2>&1; rc=$?
386check J-other-owner-refused [ "$rc" = 3 ]
387check J-pin-unchanged [ "$(sha256sum < "$H/.config/interplane/owner-pins")" = "$pin" ]
388check J-recorded-nothing empty_store
389
390# --- K: a compiler whose SHA-256 is not the pinned one is refused (mutant of this installer) ---------
391home k; git clone -q "$HERE" "$W/mut"
392sed -i 's/^OMEGA_RELEASE_OMC_SHA256=.*/OMEGA_RELEASE_OMC_SHA256=0000000000000000000000000000000000000000000000000000000000000000/' "$W/mut/install.sh"
393check K-mutant-is-a-mutant bash -c '! cmp -s "$1" "$2"' _ "$HERE/install.sh" "$W/mut/install.sh"
394git -C "$W/mut" -c user.name=t -c user.email=t@t commit -q -am mutant
395INSTALLER=$W/mut inst --quick > "$W/k.log" 2>&1; rc=$?
396check K-wrong-compiler-refused [ "$rc" = 3 ]
397check K-says-sha grep -q "SHA-256 is not the pinned one" "$W/k.log"
398check K-recorded-nothing empty_store
399check K-installed-nothing none_of "$H/.local/bin/omc" "$H/$DATA/lib/omc"
400
401# --- O: the same for the compiler the store tool is built with ---------------------------------------
402home o; git clone -q "$HERE" "$W/mut2"
403sed -i 's/IPL_OMC_SHA=\$(pin omc-sha256)/IPL_OMC_SHA=00/' "$W/mut2/install.sh"
404check O-mutant-is-a-mutant grep -q 'IPL_OMC_SHA=00;' "$W/mut2/install.sh"
405git -C "$W/mut2" -c user.name=t -c user.email=t@t commit -q -am mutant
406INSTALLER=$W/mut2 inst --quick > "$W/o.log" 2>&1; rc=$?
407check O-wrong-store-compiler-refused [ "$rc" = 3 ]
408check O-says-which grep -q "store tool's compiler is not the one ipl/PIN names" "$W/o.log"
409check O-recorded-nothing empty_store
410check O-built-nothing none_of "$H/$DATA/interplane" "$H/$DATA/lib/omc-ipl"
411
412# --- N: the piped form (no clone of this installer on the machine): it fetches itself ----------------
413home n
414case $SRC in
415/*) S3=$W/src3; mkdir -p "$S3/interplane-install"; ln -s "$SRC/omega-mv" "$S3/omega-mv"; ln -s "$SRC/interplane-forge" "$S3/interplane-forge"
416 git clone -q --bare "$HERE" "$S3/interplane-install/repo.git" ;;
417*) S3=$SRC ;;
418esac
419( cd "$H" && env -i HOME="$H" PATH=/usr/bin:/bin INTERPLANE_SOURCE="$S3" sh -s -- --quick < "$HERE/install.sh" ) > "$W/n.log" 2>&1; rc=$?
420check N-piped-install-exit-0 [ "$rc" = 0 ]
421check N-fetched-itself grep -q 'downloading interplane-install' "$W/n.log"
422check N-verify-all ipc verify
423invariants "$W/n.log"
424
425# --- Q: a store where you say ------------------------------------------------------------------------
426home q
427inst --quick --store "$H/mystore" > "$W/q.log" 2>&1; rc=$?
428check Q-store-option-exit-0 [ "$rc" = 0 ]
429check Q-store-is-there [ "$(wc -l < "$H/mystore/catalog.tsv")" = 3 ]
430check Q-no-default-store none_of "$H/$DATA/store"
431check Q-command-uses-it bash -c '[ "$(env -i HOME="$1" PATH="$1/.local/bin:/usr/bin:/bin" interplane where | sed -n "s/^store //p")" = "$1/mystore" ]' _ "$H"
432inst --quick > "$W/q2.log" 2>&1; rc=$?
433check Q-rerun-exit-0 [ "$rc" = 0 ]
434check Q-rerun-remembers-it none_of "$H/$DATA/store"
435inst --quick --store "$H/other" > "$W/q3.log" 2>&1; rc=$?
436check Q-other-store-refused-exit-1 [ "$rc" = 1 ]
437check Q-refusal-names-the-store grep -q "your store is already $H/mystore" "$W/q3.log"
438check Q-other-store-not-made none_of "$H/other" "$H/$DATA/store"
439check Q-config-unchanged [ "$(sed -n 's/^store=//p' "$H/.config/interplane/config")" = "$H/mystore" ]
440# an existing folder given as the store is made private, and the run says so
441home q2; mkdir -m 755 "$H/shared"
442inst --quick --store "$H/shared" > "$W/q4.log" 2>&1; rc=$?
443check Q-existing-folder-exit-0 [ "$rc" = 0 ]
444check Q-existing-folder-made-private mode_is 700 "$H/shared"
445check Q-existing-folder-says-so grep -q "^note: $H/shared already exists and was accessible to other accounts (mode 755)" "$W/q4.log"
446# a folder that already has other files is not a store: refused, and left as it was
447home q3; mkdir -m 755 "$H/docs"; printf 'mine\n' > "$H/docs/a.txt"
448inst --quick --store "$H/docs" > "$W/q5.log" 2>&1; rc=$?
449check Q-non-store-folder-refused-exit-1 [ "$rc" = 1 ]
450check Q-non-store-folder-says-why grep -q 'already has files in it and is not an Interplane store' "$W/q5.log"
451check Q-non-store-folder-unchanged mode_is 755 "$H/docs"
452check Q-non-store-folder-gets-nothing none_of "$H/docs/projects" "$H/docs/catalog.tsv" "$H/.local" "$H/.config"
453
454# --- R: a key you already have, even without its public half -----------------------------------------
455home r; mkdir -p "$H/.config/interplane"; ssh-keygen -q -t ed25519 -N '' -f "$H/.config/interplane/owner-key"
456fp=$(ssh-keygen -lf "$H/.config/interplane/owner-key.pub" | awk '{print $2}'); rm "$H/.config/interplane/owner-key.pub"
457inst --quick > "$W/r.log" 2>&1; rc=$?
458check R-existing-key-exit-0 [ "$rc" = 0 ]
459check R-your-key-is-the-owner grep -qx "\* $fp" "$H/.config/interplane/owner-pins"
460check R-verify-all ipc verify
461
462# an owner key whose public half is empty (a kill, or a failed ssh-keygen -y) is made again
463home r2; mkdir -p "$H/.config/interplane"; ssh-keygen -q -t ed25519 -N '' -f "$H/.config/interplane/owner-key"
464fp=$(ssh-keygen -lf "$H/.config/interplane/owner-key.pub" | awk '{print $2}'); : > "$H/.config/interplane/owner-key.pub"
465inst --quick > "$W/r2.log" 2>&1; rc=$?
466check R-empty-pub-exit-0 [ "$rc" = 0 ]
467check R-empty-pub-is-made-again [ "$(ssh-keygen -lf "$H/.config/interplane/owner-key.pub" | awk '{print $2}')" = "$fp" ]
468check R-empty-pub-leaves-no-new-file none_of "$H/.config/interplane/owner-key.pub.new" "$H/.config/interplane/owner-pins.new"
469
470# --- U: the clone form installs exactly the commit that is checked out, not a branch, and says what it leaves out
471home u; git clone -q "$HERE" "$W/det"; git -C "$W/det" checkout -q --detach; git -C "$W/det" branch -q -D main
472printf '# detached\n' >> "$W/det/bin/interplane"; git -C "$W/det" -c user.name=t -c user.email=t@t commit -q -am detached
473printf '# not committed\n' >> "$W/det/README.md"
474INSTALLER=$W/det inst --quick > "$W/u.log" 2>&1; rc=$?
475dethead=$(git -C "$W/det" rev-parse HEAD)
476check U-detached-checkout-exit-0 [ "$rc" = 0 ]
477check U-store-has-the-checkout-head [ "$(git --git-dir="$H/$DATA/store/projects/interplane-install/repo.git" rev-parse main)" = "$dethead" ]
478check U-command-is-the-checkout-head [ "$(git -C "$H/$DATA/install" rev-parse HEAD)" = "$dethead" ]
479check U-says-uncommitted-is-left-out grep -q 'uncommitted changes to tracked files; they are not installed' "$W/u.log"
480check U-final-line-names-it [ "$(grep '^Installer:' "$W/u.log" | tail -n 1)" = "Installer: interplane-install ${dethead:0:12}" ]
481check U-uncommitted-is-not-in-the-command bash -c '! grep -q "^# not committed" "$1/README.md"' _ "$H/$DATA/install"
482
483# --- W: a password or token in the source address is never printed or written
484home w
485pw_run "$HERE" w
486check W-password-source-exit-0 [ "$PW_RC" = 0 ]
487check W-used-that-source grep -q '^downloading omega-mv from https://example.invalid ' "$W/$PW_LOG"
488check W-evidence-holds-the-address-without-it grep -qx 'source https://example.invalid/omega-mv/repo.git' "$H/$DATA/records/omega-mv.import-evidence"
489check W-no-password-anywhere pw_clean
490check W-verify-all ipc verify
491
492# --- X: the clone form through a symlinked workspace, from a pipe inside a clone, from a copy -----------
493# (review 3: a symlinked path turned the clone form into a download without a word)
494home x
495mkdir -p "$W/xreal" && ln -s "$W/xreal" "$W/xlink" && git clone -q "$HERE" "$W/xreal/inst"
496SX=$W/srcx; mkdir -p "$SX/omega-mv" "$SX/interplane-forge" "$SX/interplane-install"
497git clone -q --bare "$W/a/$DATA/store/projects/omega-mv/repo.git" "$SX/omega-mv/repo.git"
498git clone -q --bare "$W/a/$DATA/store/projects/interplane-forge/repo.git" "$SX/interplane-forge/repo.git"
499git clone -q "$HERE" "$W/xother"; printf '# the source serves another installer\n' >> "$W/xother/bin/interplane"
500git -C "$W/xother" -c user.name=t -c user.email=t@t commit -q -am other
501git clone -q --bare "$W/xother" "$SX/interplane-install/repo.git"
502xhead=$(git -C "$W/xreal/inst" rev-parse HEAD); xother=$(git -C "$W/xother" rev-parse HEAD); xphys=$(cd "$W/xreal/inst" && pwd -P)
503INSTALLER=$W/xlink/inst SOURCE=$SX inst --quick > "$W/x1.log" 2>&1; rc=$?
504check X-symlinked-workspace-exit-0 [ "$rc" = 0 ]
505check X-symlinked-workspace-installs-the-checkout [ "$(store_install_main)" = "$xhead" ]
506check X-symlinked-workspace-is-the-clone-form grep -q "^ok: this installer is $xphys at ${xhead:0:12}" "$W/x1.log"
507check X-symlinked-workspace-does-not-download bash -c '! grep -q "not run from a checkout" "$1"' _ "$W/x1.log"
508# the same through a symlink to install.sh itself
509home x1b; mkdir -p "$W/xfile"; ln -s "$W/xreal/inst/install.sh" "$W/xfile/install.sh"
510INSTALLER=$W/xfile SOURCE=$SX inst --quick > "$W/x1b.log" 2>&1; rc=$?
511check X-symlinked-file-exit-0 [ "$rc" = 0 ]
512check X-symlinked-file-installs-the-checkout [ "$(store_install_main)" = "$xhead" ]
513# piped from a folder that is a clone: the piped form, said so, and the source's installer is the one installed
514home x2
515( cd "$W/xreal/inst" && env -i HOME="$H" PATH=/usr/bin:/bin INTERPLANE_SOURCE="$SX" sh -s -- --quick < install.sh ) > "$W/x2.log" 2>&1; rc=$?
516check X-piped-in-a-clone-exit-0 [ "$rc" = 0 ]
517check X-piped-in-a-clone-takes-the-sources-installer [ "$(store_install_main)" = "$xother" ]
518check X-piped-in-a-clone-says-so grep -q 'not run from a checkout' "$W/x2.log"
519invariants "$W/x2.log"
520# a copy of the files with no Git checkout behind it is refused (never replaced by a download), and nothing is written
521home x3; mkdir -p "$W/xcopy"; cp -R "$W/xreal/inst/." "$W/xcopy/"; rm -rf "$W/xcopy/.git"
522INSTALLER=$W/xcopy SOURCE=$SX inst --quick > "$W/x3.log" 2>&1; rc=$?
523check X-a-copy-is-refused [ "$rc" = 3 ]
524check X-a-copy-says-why grep -q 'is not a Git checkout of it' "$W/x3.log"
525check X-a-copy-does-not-download bash -c '! grep -q "downloading interplane-install" "$1"' _ "$W/x3.log"
526check X-a-copy-wrote-nothing none_of "$H/.local" "$H/.config"
527# a lone install.sh with no checkout beside it is the piped form: it says so and takes the source's installer
528home x4; mkdir -p "$W/xlone"; cp "$W/xreal/inst/install.sh" "$W/xlone/install.sh"
529INSTALLER=$W/xlone SOURCE=$SX inst --quick > "$W/x4.log" 2>&1; rc=$?
530check X-a-lone-file-exit-0 [ "$rc" = 0 ]
531check X-a-lone-file-takes-the-sources-installer [ "$(store_install_main)" = "$xother" ]
532check X-a-lone-file-says-so grep -q 'not run from a checkout' "$W/x4.log"
533
534# --- V: an install.sh with changes that are not committed decides what is installed, so it is refused ---
535# edited_run BASE NAME: a clone of BASE with one uncommitted line added to install.sh, run in a fresh home (sets EV_RC)
536edited_run() { home "$2"; rm -rf "$W/ev-$2"; git clone -q "$1" "$W/ev-$2"; printf '# my note\n' >> "$W/ev-$2/install.sh"; INSTALLER=$W/ev-$2 inst --quick > "$W/ev-$2.log" 2>&1; EV_RC=$?; }
537edited_run "$HERE" v
538check V-edited-install-is-refused [ "$EV_RC" = 3 ]
539check V-says-what-to-do grep -q 'it has changes that are not committed' "$W/ev-v.log"
540check V-edited-install-wrote-nothing none_of "$H/.local" "$H/.config"
541git -C "$W/ev-v" -c user.name=t -c user.email=t@t commit -q -am note
542INSTALLER=$W/ev-v inst --quick > "$W/v2.log" 2>&1; rc=$?
543check V-committed-it-installs [ "$rc" = 0 ]
544check V-committed-store-has-that-commit [ "$(store_install_main)" = "$(git -C "$W/ev-v" rev-parse HEAD)" ]
545
546# --- Y: the next Omega release (review 3: a changed pin left the first omc in ~/.local/bin for good) -----
547# next_release: from the store of the home H, a source that serves the next Omega release (one more omega-mv
548# commit whose seed/out/omc is one byte longer) and an installer, a child of this one, pinned to it.
549# Sets NEXT_SRC, NEXT_INST, NEXT_COMMIT, NEXT_SHA.
550next_release() {
551 local sp=$H/$DATA/store/projects g mode blob tree
552 NEXT_SRC=$W/srcy; rm -rf "$NEXT_SRC" "$W/ynext" "$W/idx-y"; mkdir -p "$NEXT_SRC/omega-mv" "$NEXT_SRC/interplane-forge"
553 git clone -q --bare "$sp/interplane-forge/repo.git" "$NEXT_SRC/interplane-forge/repo.git"
554 git clone -q --bare "$sp/omega-mv/repo.git" "$NEXT_SRC/omega-mv/repo.git"
555 g=$NEXT_SRC/omega-mv/repo.git
556 mode=$(git --git-dir="$g" ls-tree main seed/out/omc | cut -d' ' -f1)
557 { git --git-dir="$g" show main:seed/out/omc; printf x; } > "$W/omc-next"
558 NEXT_SHA=$(sha256sum < "$W/omc-next" | cut -d' ' -f1)
559 blob=$(git --git-dir="$g" hash-object -w "$W/omc-next")
560 GIT_INDEX_FILE=$W/idx-y git --git-dir="$g" read-tree main
561 GIT_INDEX_FILE=$W/idx-y git --git-dir="$g" update-index --add --cacheinfo "$mode,$blob,seed/out/omc"
562 tree=$(GIT_INDEX_FILE=$W/idx-y git --git-dir="$g" write-tree)
563 NEXT_COMMIT=$(git --git-dir="$g" -c user.name=t -c user.email=t@t commit-tree "$tree" -p main -m "next release")
564 git --git-dir="$g" update-ref refs/heads/main "$NEXT_COMMIT"
565 git clone -q "$HERE" "$W/ynext"
566 sed -i -e "s/^OMEGA_RELEASE=.*/OMEGA_RELEASE=$NEXT_COMMIT/" -e "s/^OMEGA_RELEASE_OMC_SHA256=.*/OMEGA_RELEASE_OMC_SHA256=$NEXT_SHA/" "$W/ynext/install.sh"
567 git -C "$W/ynext" -c user.name=t -c user.email=t@t commit -q -am "next Omega release"
568 NEXT_INST=$W/ynext
569}
570home y
571inst --quick > "$W/y1.log" 2>&1; rc=$?
572check Y-first-install-exit-0 [ "$rc" = 0 ]
573next_release
574INSTALLER=$NEXT_INST SOURCE=$NEXT_SRC inst --quick > "$W/y2.log" 2>&1; rc=$?
575check Y-upgrade-exit-0 [ "$rc" = 0 ]
576check Y-omc-in-bin-is-the-new-release [ "$(bin_omc_sha)" = "$NEXT_SHA" ]
577check Y-says-it-updated grep -q "^updated $H/.local/bin/omc to the compiler of Omega $NEXT_COMMIT" "$W/y2.log"
578check Y-final-line-names-the-new-omc grep -q "^Omega: $H/.local/bin/omc " "$W/y2.log"
579check Y-store-has-the-new-omega [ "$(git --git-dir="$H/$DATA/store/projects/omega-mv/repo.git" rev-parse main)" = "$NEXT_COMMIT" ]
580# the installer of the old release run again is refused: nothing goes back
581h1=$(store_hash)
582SOURCE=$NEXT_SRC inst --quick > "$W/y3.log" 2>&1; rc=$?
583check Y-older-installer-refused [ "$rc" = 3 ]
584check Y-older-installer-left-the-new-omc [ "$(bin_omc_sha)" = "$NEXT_SHA" ]
585check Y-older-installer-left-the-new-compiler-in-lib [ "$(sha256sum < "$H/$DATA/lib/omc" | cut -d' ' -f1)" = "$NEXT_SHA" ]
586check Y-older-installer-left-the-store [ "$(store_hash)" = "$h1" ]
587# an omc of your own is kept through the upgrade: one that was there first, and one you put in place afterwards
588home y2; mkdir -p "$H/.local/bin"; printf '#!/bin/sh\necho mine\n' > "$H/.local/bin/omc"; chmod +x "$H/.local/bin/omc"
589inst --quick > /dev/null 2>&1
590INSTALLER=$NEXT_INST SOURCE=$NEXT_SRC inst --quick > "$W/y4.log" 2>&1; rc=$?
591check Y-own-omc-upgrade-exit-0 [ "$rc" = 0 ]
592check Y-own-omc-is-kept [ "$("$H/.local/bin/omc")" = mine ]
593check Y-own-omc-says-so grep -q '^kept your existing .*/omc' "$W/y4.log"
594check Y-own-omc-final-line-says-so grep -q '^Omega: your own .*/omc is kept' "$W/y4.log"
595home y3
596inst --quick > /dev/null 2>&1
597rm -f "$H/.local/bin/omc"; printf '#!/bin/sh\necho mine\n' > "$H/.local/bin/omc"; chmod +x "$H/.local/bin/omc"
598INSTALLER=$NEXT_INST SOURCE=$NEXT_SRC inst --quick > "$W/y5.log" 2>&1; rc=$?
599check Y-replaced-omc-upgrade-exit-0 [ "$rc" = 0 ]
600check Y-replaced-omc-is-kept [ "$("$H/.local/bin/omc")" = mine ]
601# a piped installer whose pins are not the pins of the installer the source serves is refused before anything is built or recorded
602mkdir -p "$NEXT_SRC/interplane-install"; git clone -q --bare "$NEXT_INST" "$NEXT_SRC/interplane-install/repo.git"
603home y4
604( cd "$H" && env -i HOME="$H" PATH=/usr/bin:/bin INTERPLANE_SOURCE="$NEXT_SRC" sh -s -- --quick < "$HERE/install.sh" ) > "$W/y6.log" 2>&1; rc=$?
605check Y-piped-with-other-pins-is-refused [ "$rc" = 3 ]
606check Y-piped-with-other-pins-says-why grep -q 'is not the one it would put in your store' "$W/y6.log"
607check Y-piped-with-other-pins-built-and-recorded-nothing none_of "$H/$DATA/interplane" "$H/.local/bin/omc" "$H/$DATA/lib/omc"
608check Y-piped-with-other-pins-recorded-no-project empty_store
609
610# --- GV: a git that is too old is named, and nothing is written -----------------------------------------
611home gv; mkdir -p "$W/oldgit"
612printf '#!/bin/sh\nif [ "$1" = --version ]; then echo "git version 2.25.1"; else exec /usr/bin/git "$@"; fi\n' > "$W/oldgit/git"; chmod +x "$W/oldgit/git"
613P="$W/oldgit:/usr/bin:/bin" inst --quick > "$W/gv.log" 2>&1; rc=$?
614check GV-old-git-refused [ "$rc" = 2 ]
615check GV-names-the-version grep -q 'git 2.25 is too old: this installer needs git 2.29' "$W/gv.log"
616check GV-wrote-nothing none_of "$H/.local" "$H/.config"
617
618# --- GET: a working copy of a private project follows your umask and says when others can read it (home a) ---
619H=$W/a
620( umask 022 && ipc get secret "$W/got-open" ) > "$W/get1.log" 2>&1
621check GET-private-open-says-so grep -q '^note: secret is a private project, and .* is accessible to other accounts' "$W/get1.log"
622check GET-private-open-follows-umask mode_is 755 "$W/got-open"
623( umask 077 && ipc get secret "$W/got-closed" ) > "$W/get2.log" 2>&1
624check GET-private-closed-has-no-note bash -c '! grep -q "^note:" "$1"' _ "$W/get2.log"
625check GET-private-closed-follows-umask mode_is 700 "$W/got-closed"
626( umask 022 && ipc get mine "$W/got-pub" ) > "$W/get3.log" 2>&1
627check GET-public-has-no-note bash -c '! grep -q "^note:" "$1"' _ "$W/get3.log"
628
629# --- mutants: the gate's own cases must fail against an installer with one fault each ---------------
630# The invariants are not run on these (they are expected to be wrong).
631INV=0
632# mutate NAME FILE SED-EXPR: a copy of MUTBASE (this repository unless set) with that one edit, committed on its main (MUT)
633MUTBASE=$HERE
634mutate() {
635 MUT=$W/mut-$1
636 git clone -q "$MUTBASE" "$MUT"
637 sed -i "$3" "$MUT/$2"
638 check "MUT-$1-is-a-mutant" bash -c '! cmp -s "$1" "$2"' _ "$MUTBASE/$2" "$MUT/$2"
639 git -C "$MUT" -c user.name=t -c user.email=t@t commit -q -am "mutant $1"
640 nmut=$((nmut + 1))
641}
642# (i) the update of main from the source removed: S must fail
643mutate no-source-fetch install.sh 's#--no-write-fetch-head "\$SRC/\$1/repo.git" "+refs/heads/main:refs/heads/source"#--no-write-fetch-head "/nonexistent/\$1.git" "+refs/heads/main:refs/heads/source"#'
644home mu1; inst --quick > /dev/null 2>&1
645src_update_run "$MUT" mu1
646check MUT-no-source-fetch-run-finished [ "$SU_RC" = 0 ]
647kill_check MUT-no-source-fetch-fails-S-store-has-the-new-main su_new_main
648# (ii) the removal of export marks in share removed: the stray-mark case must fail
649mutate no-mark-removal bin/interplane 's#; rm -f "\$d/repo.git/git-daemon-export-ok"##'
650home mu2; inst --quick > /dev/null 2>&1; ipc new pub --public > /dev/null 2>&1
651share_with_stray_mark "$MUT/bin/interplane" omega-mv
652stop_share
653kill_check MUT-no-mark-removal-fails-D-stray-export-mark-is-removed none_of "$H/$DATA/store/projects/omega-mv/repo.git/git-daemon-export-ok"
654# (iii) the removal of the password from the shown source removed: the password case must fail
655mutate no-shown install.sh 's/^SHOWN=.*/SHOWN=$SRC/'
656home mu3
657pw_run "$MUT" mu3
658check MUT-no-shown-run-finished [ "$PW_RC" = 0 ]
659kill_check MUT-no-shown-fails-W-no-password-anywhere pw_clean
660# (iv) an omc this installer put there earlier is never replaced: the next-release case must fail
661MUTBASE=$W/ynext
662mutate omc-never-replaced install.sh 's#elif \[ -n "\$OMCCUR" \] \&\& grep -qxF#elif false \&\& grep -qxF#'
663MUTBASE=$HERE
664home mu4; inst --quick > /dev/null 2>&1
665INSTALLER=$MUT SOURCE=$NEXT_SRC inst --quick > "$W/mu4.log" 2>&1; rc=$?
666check MUT-omc-never-replaced-run-finished [ "$rc" = 0 ]
667kill_check MUT-omc-never-replaced-fails-Y-omc-in-bin-is-the-new-release [ "$(bin_omc_sha)" = "$NEXT_SHA" ]
668# the invariants themselves catch it too (this is the tool broken once: they must say what is wrong)
669INSTALLER=$MUT check INV-catches-an-omc-of-ours-left-stale not inv_holds "$W/mu4.log"
670# (v) the checkout found by its logical path instead of its physical one: the symlinked workspace case must fail
671mutate logical-path install.sh 's#ME=\$(dirname "\$(realpath "\$0")")#ME=$(cd "$(dirname "$0")" \&\& pwd)#'
672rm -rf "$W/xreal/mutinst"; git clone -q "$MUT" "$W/xreal/mutinst"
673home mu5; INSTALLER=$W/xlink/mutinst SOURCE=$SX inst --quick > "$W/mu5.log" 2>&1
674kill_check MUT-logical-path-fails-X-symlinked-workspace-installs-the-checkout [ "$(store_install_main)" = "$(git -C "$W/xreal/mutinst" rev-parse HEAD)" ]
675# (vi) an edited install.sh accepted: the edited-installer case must fail
676mutate allow-edited-install install.sh 's#\[ -n "\$myblob" \] \&\& \[ "\$myblob" = "\$cblob" \] ||#true ||#'
677edited_run "$MUT" mu6
678kill_check MUT-allow-edited-install-fails-V-edited-install-is-refused [ "$EV_RC" = 3 ]
679# (vii) an installer older than the one in the store accepted: the older-installer case must fail
680mutate allow-older install.sh 's#if \[ -n "\$have" \] \&\&#if false \&\&#'
681rm -rf "$W/mut7up"; git clone -q "$MUT" "$W/mut7up"; printf '# newer\n' >> "$W/mut7up/bin/interplane"; git -C "$W/mut7up" -c user.name=t -c user.email=t@t commit -q -am newer
682home mu7; INSTALLER=$W/mut7up inst --quick > /dev/null 2>&1
683INSTALLER=$MUT inst --quick > "$W/mu7.log" 2>&1; rc=$?
684kill_check MUT-allow-older-fails-L-older-installer-refused [ "$rc" = 3 ]
685# (viii) a password with an @ in it cut at the first @: the password case must fail
686mutate first-at install.sh 's#\[^/\]\*@#[^/@]*@#'
687home mu8
688pw_run "$MUT" mu8
689check MUT-first-at-run-finished [ "$PW_RC" = 0 ]
690kill_check MUT-first-at-fails-W-no-password-anywhere pw_clean
691# (ix) the installer that runs and the one recorded may have other pins: the other-pins case must fail
692mutate allow-other-pins install.sh 's#\[ "\$STOREPINS" = #true || [ "$STOREPINS" = #'
693home mu9
694( cd "$H" && env -i HOME="$H" PATH=/usr/bin:/bin INTERPLANE_SOURCE="$NEXT_SRC" sh -s -- --quick < "$MUT/install.sh" ) > "$W/mu9.log" 2>&1; rc=$?
695kill_check MUT-allow-other-pins-fails-Y-piped-with-other-pins-is-refused [ "$rc" = 3 ]
696echo "host: $(uname -sm), $(git --version), $(ssh -V 2>&1), $(bash --version | head -n 1)"
697# every kind of defect in tests/LESSONS.tsv has at least one passing case of each name it lists
698while IFS="$(printf '\t')" read -r kind what prefixes; do
699 case $kind in '' | '#'*) continue ;; esac
700 for p in $(printf '%s' "$prefixes" | tr ',' ' '); do
701 if grep -q "^$p" "$W/names"; then ok "LESSON-$kind-has-a-case-$p"; else no "LESSON-$kind-has-no-case-$p"; fi
702 done
703done < "$HERE/tests/LESSONS.tsv"
704if [ "$fail" = 0 ] && [ "$nmut" -gt 0 ] && [ "$killed" = "$nmut" ]; then echo "GATE PASS cases=$pass mutants_killed=$killed"; else echo "GATE FAIL pass=$pass fail=$fail mutants_killed=$killed of $nmut"; for l in "$W"/*.log; do echo "--- $l"; tail -n 5 "$l"; done; exit 1; fi