aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / scripts / test_check_candidate_pins.sh
| 1 | #!/usr/bin/env bash |
| 2 | # Test for tools/candidate/check_pins.om. Offline: lock files are served from a temp tree by a CAND_FILE_AT stub. |
| 3 | # The checker is compiled here with the pinned seeded compiler named by AIEN_OMC (exit 3 = NOT_RUN without it). |
| 4 | set -u |
| 5 | here="$(cd "$(dirname "$0")" && pwd)" |
| 6 | src="$here/../tools/candidate/check_pins.om" |
| 7 | omc="${AIEN_OMC:-}" |
| 8 | [ -n "$omc" ] && [ -x "$omc" ] || { echo "test_check_candidate_pins: AIEN_OMC is not an executable omc (NOT_RUN)" >&2; exit 3; } |
| 9 | tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT |
| 10 | chk="$tmp/check_pins" |
| 11 | "$omc" < "$src" > "$chk" && chmod +x "$chk" || { echo "TEST FAIL: $src does not compile with $omc"; exit 1; } |
| 12 | OM=1111111111111111111111111111111111111111; SC=2222222222222222222222222222222222222222 |
| 13 | AO=3333333333333333333333333333333333333333; PH=4444444444444444444444444444444444444444 |
| 14 | PR=5555555555555555555555555555555555555555; CS=6666666666666666666666666666666666666666 |
| 15 | SP=7777777777777777777777777777777777777777; AR=8888888888888888888888888888888888888888 |
| 16 | OTHER=9999999999999999999999999999999999999999 |
| 17 | cat > "$tmp/stub.sh" <<S |
| 18 | #!/usr/bin/env bash |
| 19 | # like gh api on a missing file or commit: an error body that contains the requested ref, and exit 1 |
| 20 | cat "$tmp/files/\$1/\$2/\$3" 2>/dev/null || { echo "{\"message\":\"No commit found for the ref \$2\"}"; exit 1; } |
| 21 | S |
| 22 | chmod +x "$tmp/stub.sh"; export CAND_FILE_AT="$tmp/stub.sh" |
| 23 | |
| 24 | serve() { mkdir -p "$(dirname "$tmp/files/$1")"; cat > "$tmp/files/$1"; } |
| 25 | tree() { # tree : the consistent lock files |
| 26 | rm -rf "$tmp/files" |
| 27 | echo "$OM" | serve "aien-sovereign-core/$SC/omega.lock" |
| 28 | serve "aien-sovereign-core/$SC/Cargo.lock" <<L |
| 29 | [[package]] |
| 30 | name = "aien-protocol-types" |
| 31 | source = "git+https://github.com/aien-dev/aien-protocols?rev=$PR#$PR" |
| 32 | |
| 33 | [[package]] |
| 34 | name = "aien-probe" |
| 35 | source = "git+https://github.com/aien-dev/aien-protocols?rev=$PR#$PR" |
| 36 | |
| 37 | [[package]] |
| 38 | name = "crumb-spec" |
| 39 | source = "git+https://github.com/aien-dev/crumb-spec?rev=$CS#$CS" |
| 40 | |
| 41 | [[package]] |
| 42 | name = "spark-crumbs" |
| 43 | source = "git+https://github.com/aien-dev/spark-crumbs?rev=$SP#$SP" |
| 44 | |
| 45 | [[package]] |
| 46 | name = "serde" |
| 47 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 48 | L |
| 49 | echo "$PH" | serve "omega/$OM/physics.lock" |
| 50 | echo "$AO" | serve "omega/$OM/aienos.lock" |
| 51 | printf '%s\n# argus pin, comment with no hex\n' "$AR" | serve "omega/$OM/argus.lock" |
| 52 | } |
| 53 | manifest() { # manifest <out> : manifest that agrees with tree |
| 54 | cat > "$1" <<M |
| 55 | schema = "CandidateManifestV1" |
| 56 | id = "CAND-T" |
| 57 | [commits] |
| 58 | omega = "$OM" |
| 59 | aienos = "$AO" |
| 60 | aien-sovereign-core = "$SC" |
| 61 | aien-protocols = "$PR" |
| 62 | physics = "$PH" |
| 63 | [contracts] |
| 64 | crumb-spec = "$CS" |
| 65 | spark-crumbs = "$SP" |
| 66 | [consumed_pins] |
| 67 | sovereign-core-omega-lock = "$OM" |
| 68 | sovereign-core-cargo-lock-aien-protocols = "$PR" |
| 69 | omega-physics-lock = "$PH" |
| 70 | omega-aienos-lock = "$AO" |
| 71 | omega-argus-lock = "$AR" |
| 72 | something-else = "not read" |
| 73 | M |
| 74 | } |
| 75 | pass=0; bad=0 |
| 76 | expect() { # expect <0|1> <label> <file> [grep pattern that the output must contain] |
| 77 | out=$("$chk" "$3" 2>&1); rc=$? |
| 78 | if [ "$rc" = "$1" ] && { [ -z "${4:-}" ] || grep -q -- "$4" <<<"$out"; }; then pass=$((pass+1)) |
| 79 | else bad=$((bad+1)); echo "TEST FAIL: $2 (rc=$rc)"; echo "$out" | sed 's/^/ /'; fi |
| 80 | } |
| 81 | tree; manifest "$tmp/m.toml" |
| 82 | expect 0 "consistent pins agree" "$tmp/m.toml" "PINS AGREE" |
| 83 | sed "s/^crumb-spec = .*/crumb-spec = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/a.toml" |
| 84 | expect 1 "contract pinned to a revision the code does not consume" "$tmp/a.toml" "contracts.crumb-spec: manifest pins $OTHER" |
| 85 | sed "s/^aien-protocols = .*/aien-protocols = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/b.toml" |
| 86 | expect 1 "aien-protocols pin differs from Cargo.lock" "$tmp/b.toml" "aien-protocols -> commits.aien-protocols" |
| 87 | sed "s/^aienos = .*/aienos = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/c.toml" |
| 88 | expect 1 "aienos pin differs from omega aienos.lock" "$tmp/c.toml" "omega aienos.lock" |
| 89 | sed "s/^physics = .*/physics = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/d.toml" |
| 90 | expect 1 "physics pin differs from omega physics.lock" "$tmp/d.toml" "omega physics.lock" |
| 91 | sed "s/^omega-argus-lock = .*/omega-argus-lock = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/e.toml" |
| 92 | expect 1 "consumed_pins entry differs" "$tmp/e.toml" "consumed_pins.omega-argus-lock" |
| 93 | sed '/^physics = /d;/^omega-physics-lock/d' "$tmp/m.toml" > "$tmp/f.toml" |
| 94 | expect 0 "physics unpinned is allowed" "$tmp/f.toml" |
| 95 | sed '/^spark-crumbs = /d' "$tmp/m.toml" > "$tmp/g.toml" |
| 96 | expect 1 "contract missing from the manifest" "$tmp/g.toml" "not pinned" |
| 97 | # lock-file side |
| 98 | echo "$OTHER" | serve "aien-sovereign-core/$SC/omega.lock" |
| 99 | expect 1 "sovereign-core omega.lock points elsewhere" "$tmp/m.toml" "omega.lock -> commits.omega" |
| 100 | tree; rm "$tmp/files/aien-sovereign-core/$SC/Cargo.lock" |
| 101 | expect 1 "unreadable Cargo.lock" "$tmp/m.toml" "cannot read Cargo.lock" |
| 102 | tree; rm "$tmp/files/omega/$OM/aienos.lock" |
| 103 | expect 1 "unreadable aienos.lock" "$tmp/m.toml" "cannot read aienos.lock" |
| 104 | tree; printf '\n[[package]]\nname = "crumb-spec-extra"\nsource = "git+https://github.com/aien-dev/crumb-spec?rev=%s#%s"\n' "$OTHER" "$OTHER" \ |
| 105 | >> "$tmp/files/aien-sovereign-core/$SC/Cargo.lock" |
| 106 | expect 1 "two revisions of one repo in Cargo.lock" "$tmp/m.toml" "several" |
| 107 | tree; sed -i "s/crumb-spec?rev=$CS#$CS/crumb-spec-fork?rev=$CS#$CS/" "$tmp/files/aien-sovereign-core/$SC/Cargo.lock" |
| 108 | expect 1 "a repo whose name only starts with the contract name does not count" "$tmp/m.toml" "crumb-spec: git revision none" |
| 109 | tree |
| 110 | # a missing lock whose error body carries the omega ref must not read as "argus.lock pins omega" |
| 111 | tree; rm "$tmp/files/omega/$OM/argus.lock"; sed "s/^omega-argus-lock = .*/omega-argus-lock = \"$OM\"/" "$tmp/m.toml" > "$tmp/i.toml" |
| 112 | expect 1 "error body with the ref is not a lock file" "$tmp/i.toml" "consumed_pins.omega-argus-lock: its lock file could not be read" |
| 113 | tree; printf '# pinned after %s\n%s\n' "$OTHER" "$AO" | serve "omega/$OM/aienos.lock" |
| 114 | expect 0 "a leading comment with a sha is skipped" "$tmp/m.toml" |
| 115 | tree; printf '%s %s\n' "$AO" "trailing words" | serve "omega/$OM/aienos.lock" |
| 116 | expect 1 "first line must be exactly the sha" "$tmp/m.toml" "cannot read aienos.lock" |
| 117 | tree |
| 118 | sed '/^aien-sovereign-core = /d' "$tmp/m.toml" > "$tmp/h.toml" |
| 119 | expect 1 "manifest without sovereign-core" "$tmp/h.toml" "lacks" |
| 120 | # -mv sources (issue 815, sovereign-core #906): the -mv name is the same pin; both names together are one pin |
| 121 | lock="$tmp/files/aien-sovereign-core/$SC/Cargo.lock" |
| 122 | tree; sed -i -e 's|aien-dev/aien-protocols?|aien-dev/aien-protocols-mv?|' -e 's|aien-dev/crumb-spec?|aien-dev/crumb-spec-mv?|' \ |
| 123 | -e 's|aien-dev/spark-crumbs?|aien-dev/spark-crumbs-mv.git?|' "$lock" |
| 124 | expect 0 "every pin under its -mv name agrees" "$tmp/m.toml" "PINS AGREE" |
| 125 | cp -r "$tmp/files" "$tmp/files-mv" # kept for the -mv mutant below |
| 126 | tree; sed -i "s|aien-protocols?rev=$PR#$PR|aien-protocols-mv?rev=$OTHER#$OTHER|" "$lock" |
| 127 | expect 1 "-mv at a wrong revision is refused" "$tmp/m.toml" "aien-protocols -> commits.aien-protocols: manifest pins $PR, the code consumes $OTHER" |
| 128 | tree; printf '\n[[package]]\nname = "aien-provenance"\nsource = "git+https://github.com/aien-dev/aien-protocols-mv?rev=%s#%s"\n' "$OTHER" "$OTHER" >> "$lock" |
| 129 | expect 1 "old and -mv name at two revisions are refused" "$tmp/m.toml" "aien-protocols: git revision several:$PR $OTHER" |
| 130 | tree; sed -i 's|aien-dev/crumb-spec?|aien-dev/crumb-spec-mvx?|' "$lock" |
| 131 | expect 1 "a -mvx repo is not the -mv name" "$tmp/m.toml" "crumb-spec: git revision none" |
| 132 | # in-tree contracts (sovereign-core #892): contracts.<name>-consumed = "in-tree" needs a path package and no git source |
| 133 | intree() { tree; sed -i "/spark-crumbs?rev=$SP#$SP/d" "$lock"; } |
| 134 | sed 's/^spark-crumbs = .*/&\nspark-crumbs-consumed = "in-tree"/' "$tmp/m.toml" > "$tmp/t.toml" |
| 135 | intree |
| 136 | expect 0 "in-tree stated with a path package and no git source agrees" "$tmp/t.toml" "contracts.spark-crumbs-consumed = in-tree (a path package" |
| 137 | cp -r "$tmp/files" "$tmp/files-intree" # kept for the in-tree word mutant below |
| 138 | expect 1 "a path package the manifest does not state as in-tree is refused" "$tmp/m.toml" "does not state with contracts.spark-crumbs-consumed" |
| 139 | intree; head -n -4 "$lock" > "$tmp/l"; cat "$tmp/l" > "$lock" |
| 140 | expect 0 "the in-tree path package may be the last block" "$tmp/t.toml" "PINS AGREE" |
| 141 | intree; printf '\n[[package]]\nname = "spark-crumbs"\nversion = "0.0.9"\nsource = "git+https://github.com/aien-dev/spark-crumbs?rev=%s#%s"\n' "$OTHER" "$OTHER" >> "$lock" |
| 142 | expect 1 "in-tree with a git source is refused" "$tmp/t.toml" "in-tree, but Cargo.lock has a git source for it at $OTHER" |
| 143 | cp -r "$tmp/files" "$tmp/files-git" # kept for the git-source mutant below |
| 144 | intree; printf '\n[[package]]\nname = "x"\nsource = "git+https://github.com/aien-dev/spark-crumbs-mv?rev=%s#%s"\n' "$SP" "$SP" >> "$lock" |
| 145 | expect 1 "in-tree with a -mv git source is refused" "$tmp/t.toml" "has a git source for it at $SP" |
| 146 | intree; sed -i 's/^name = "spark-crumbs"$/name = "spark-crumbs-extra"/' "$lock" |
| 147 | expect 1 "in-tree with no package of that name is refused" "$tmp/t.toml" "no path package named spark-crumbs" |
| 148 | cp -r "$tmp/files" "$tmp/files-nopkg" # kept for the path-package mutant below |
| 149 | tree; sed -i "s|^source = \"git+https://github.com/aien-dev/spark-crumbs?rev=$SP#$SP\"|source = \"registry+https://github.com/rust-lang/crates.io-index\"|" "$lock" |
| 150 | expect 1 "in-tree with a registry package of that name is refused" "$tmp/t.toml" "no path package named spark-crumbs" |
| 151 | cp -r "$tmp/files" "$tmp/files-reg" # kept for the source-line mutant below |
| 152 | intree; sed 's/^spark-crumbs-consumed = .*/spark-crumbs-consumed = "intree"/' "$tmp/t.toml" > "$tmp/w.toml" |
| 153 | expect 1 "a misspelt in-tree word is refused" "$tmp/w.toml" "the only accepted value is" |
| 154 | # --- mutants. Each broken copy of the checker (one sed edit of the .om source, recompiled) must give the |
| 155 | # wrong verdict on the case it names, proving the test above depends on that check. |
| 156 | mutant() { # mutant <label> <sed-expr> <files-dir> <manifest> <wrong-rc> |
| 157 | sed "$2" "$src" > "$tmp/mut.om" |
| 158 | if cmp -s "$src" "$tmp/mut.om"; then bad=$((bad+1)); echo "TEST FAIL: mutant '$1' did not change the checker"; return; fi |
| 159 | "$omc" < "$tmp/mut.om" > "$tmp/mut" 2>/dev/null && chmod +x "$tmp/mut" || { bad=$((bad+1)); echo "TEST FAIL: mutant '$1' does not compile"; return; } |
| 160 | rm -rf "$tmp/files"; cp -r "$3" "$tmp/files" |
| 161 | "$tmp/mut" "$4" >/dev/null 2>&1; rc=$? |
| 162 | if [ "$rc" = "$5" ]; then pass=$((pass+1)); else bad=$((bad+1)); echo "TEST FAIL: mutant '$1' gave rc=$rc, not the wrong $5: the test does not bite"; fi |
| 163 | } |
| 164 | mutant "-mv name not read" '/^p = add p capk p z 38$/d' "$tmp/files-mv" "$tmp/m.toml" 1 |
| 165 | mutant "in-tree git source not checked" '/^fn itcheck /,/^oflush 1$/s/^if gt get revn 0 0$/if false/' "$tmp/files-git" "$tmp/t.toml" 0 |
| 166 | mutant "in-tree path package not required" '/^fn itcheck /,/^oflush 1$/s/^if not pathpkg p$/if false/' "$tmp/files-nopkg" "$tmp/t.toml" 0 |
| 167 | mutant "source line of the package ignored" '/^fn pathpkg /,/^ret and nm not sr$/s/^sr = true$/sr = false/' "$tmp/files-reg" "$tmp/t.toml" 0 |
| 168 | mutant "in-tree word not checked" '/^fn itcheck /,/^oflush 1$/s/^if not valis e 41$/if false/' "$tmp/files-intree" "$tmp/w.toml" 0 |
| 169 | echo "check_candidate_pins tests: $pass passed, $bad failed" |
| 170 | [ "$bad" -eq 0 ] |