interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / scripts / test_check_candidate_pins.sh

170 lines · 11093 bytes Raw Blame History
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).
4set -u
5here="$(cd "$(dirname "$0")" && pwd)"
6src="$here/../tools/candidate/check_pins.om"
7omc="${AIEN_OMC:-}"
8[ -n "$omc" ] && [ -x "$omc" ] || { echo "test_check_candidate_pins: AIEN_OMC is not an executable omc (NOT_RUN)" >&2; exit 3; }
9tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
10chk="$tmp/check_pins"
11"$omc" < "$src" > "$chk" && chmod +x "$chk" || { echo "TEST FAIL: $src does not compile with $omc"; exit 1; }
12OM=1111111111111111111111111111111111111111; SC=2222222222222222222222222222222222222222
13AO=3333333333333333333333333333333333333333; PH=4444444444444444444444444444444444444444
14PR=5555555555555555555555555555555555555555; CS=6666666666666666666666666666666666666666
15SP=7777777777777777777777777777777777777777; AR=8888888888888888888888888888888888888888
16OTHER=9999999999999999999999999999999999999999
17cat > "$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
20cat "$tmp/files/\$1/\$2/\$3" 2>/dev/null || { echo "{\"message\":\"No commit found for the ref \$2\"}"; exit 1; }
21S
22chmod +x "$tmp/stub.sh"; export CAND_FILE_AT="$tmp/stub.sh"
23
24serve() { mkdir -p "$(dirname "$tmp/files/$1")"; cat > "$tmp/files/$1"; }
25tree() { # 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]]
30name = "aien-protocol-types"
31source = "git+https://github.com/aien-dev/aien-protocols?rev=$PR#$PR"
32
33[[package]]
34name = "aien-probe"
35source = "git+https://github.com/aien-dev/aien-protocols?rev=$PR#$PR"
36
37[[package]]
38name = "crumb-spec"
39source = "git+https://github.com/aien-dev/crumb-spec?rev=$CS#$CS"
40
41[[package]]
42name = "spark-crumbs"
43source = "git+https://github.com/aien-dev/spark-crumbs?rev=$SP#$SP"
44
45[[package]]
46name = "serde"
47source = "registry+https://github.com/rust-lang/crates.io-index"
48L
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}
53manifest() { # manifest <out> : manifest that agrees with tree
54 cat > "$1" <<M
55schema = "CandidateManifestV1"
56id = "CAND-T"
57[commits]
58omega = "$OM"
59aienos = "$AO"
60aien-sovereign-core = "$SC"
61aien-protocols = "$PR"
62physics = "$PH"
63[contracts]
64crumb-spec = "$CS"
65spark-crumbs = "$SP"
66[consumed_pins]
67sovereign-core-omega-lock = "$OM"
68sovereign-core-cargo-lock-aien-protocols = "$PR"
69omega-physics-lock = "$PH"
70omega-aienos-lock = "$AO"
71omega-argus-lock = "$AR"
72something-else = "not read"
73M
74}
75pass=0; bad=0
76expect() { # 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}
81tree; manifest "$tmp/m.toml"
82expect 0 "consistent pins agree" "$tmp/m.toml" "PINS AGREE"
83sed "s/^crumb-spec = .*/crumb-spec = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/a.toml"
84expect 1 "contract pinned to a revision the code does not consume" "$tmp/a.toml" "contracts.crumb-spec: manifest pins $OTHER"
85sed "s/^aien-protocols = .*/aien-protocols = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/b.toml"
86expect 1 "aien-protocols pin differs from Cargo.lock" "$tmp/b.toml" "aien-protocols -> commits.aien-protocols"
87sed "s/^aienos = .*/aienos = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/c.toml"
88expect 1 "aienos pin differs from omega aienos.lock" "$tmp/c.toml" "omega aienos.lock"
89sed "s/^physics = .*/physics = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/d.toml"
90expect 1 "physics pin differs from omega physics.lock" "$tmp/d.toml" "omega physics.lock"
91sed "s/^omega-argus-lock = .*/omega-argus-lock = \"$OTHER\"/" "$tmp/m.toml" > "$tmp/e.toml"
92expect 1 "consumed_pins entry differs" "$tmp/e.toml" "consumed_pins.omega-argus-lock"
93sed '/^physics = /d;/^omega-physics-lock/d' "$tmp/m.toml" > "$tmp/f.toml"
94expect 0 "physics unpinned is allowed" "$tmp/f.toml"
95sed '/^spark-crumbs = /d' "$tmp/m.toml" > "$tmp/g.toml"
96expect 1 "contract missing from the manifest" "$tmp/g.toml" "not pinned"
97# lock-file side
98echo "$OTHER" | serve "aien-sovereign-core/$SC/omega.lock"
99expect 1 "sovereign-core omega.lock points elsewhere" "$tmp/m.toml" "omega.lock -> commits.omega"
100tree; rm "$tmp/files/aien-sovereign-core/$SC/Cargo.lock"
101expect 1 "unreadable Cargo.lock" "$tmp/m.toml" "cannot read Cargo.lock"
102tree; rm "$tmp/files/omega/$OM/aienos.lock"
103expect 1 "unreadable aienos.lock" "$tmp/m.toml" "cannot read aienos.lock"
104tree; 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"
106expect 1 "two revisions of one repo in Cargo.lock" "$tmp/m.toml" "several"
107tree; sed -i "s/crumb-spec?rev=$CS#$CS/crumb-spec-fork?rev=$CS#$CS/" "$tmp/files/aien-sovereign-core/$SC/Cargo.lock"
108expect 1 "a repo whose name only starts with the contract name does not count" "$tmp/m.toml" "crumb-spec: git revision none"
109tree
110# a missing lock whose error body carries the omega ref must not read as "argus.lock pins omega"
111tree; rm "$tmp/files/omega/$OM/argus.lock"; sed "s/^omega-argus-lock = .*/omega-argus-lock = \"$OM\"/" "$tmp/m.toml" > "$tmp/i.toml"
112expect 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"
113tree; printf '# pinned after %s\n%s\n' "$OTHER" "$AO" | serve "omega/$OM/aienos.lock"
114expect 0 "a leading comment with a sha is skipped" "$tmp/m.toml"
115tree; printf '%s %s\n' "$AO" "trailing words" | serve "omega/$OM/aienos.lock"
116expect 1 "first line must be exactly the sha" "$tmp/m.toml" "cannot read aienos.lock"
117tree
118sed '/^aien-sovereign-core = /d' "$tmp/m.toml" > "$tmp/h.toml"
119expect 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
121lock="$tmp/files/aien-sovereign-core/$SC/Cargo.lock"
122tree; 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"
124expect 0 "every pin under its -mv name agrees" "$tmp/m.toml" "PINS AGREE"
125cp -r "$tmp/files" "$tmp/files-mv" # kept for the -mv mutant below
126tree; sed -i "s|aien-protocols?rev=$PR#$PR|aien-protocols-mv?rev=$OTHER#$OTHER|" "$lock"
127expect 1 "-mv at a wrong revision is refused" "$tmp/m.toml" "aien-protocols -> commits.aien-protocols: manifest pins $PR, the code consumes $OTHER"
128tree; printf '\n[[package]]\nname = "aien-provenance"\nsource = "git+https://github.com/aien-dev/aien-protocols-mv?rev=%s#%s"\n' "$OTHER" "$OTHER" >> "$lock"
129expect 1 "old and -mv name at two revisions are refused" "$tmp/m.toml" "aien-protocols: git revision several:$PR $OTHER"
130tree; sed -i 's|aien-dev/crumb-spec?|aien-dev/crumb-spec-mvx?|' "$lock"
131expect 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
133intree() { tree; sed -i "/spark-crumbs?rev=$SP#$SP/d" "$lock"; }
134sed 's/^spark-crumbs = .*/&\nspark-crumbs-consumed = "in-tree"/' "$tmp/m.toml" > "$tmp/t.toml"
135intree
136expect 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"
137cp -r "$tmp/files" "$tmp/files-intree" # kept for the in-tree word mutant below
138expect 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"
139intree; head -n -4 "$lock" > "$tmp/l"; cat "$tmp/l" > "$lock"
140expect 0 "the in-tree path package may be the last block" "$tmp/t.toml" "PINS AGREE"
141intree; 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"
142expect 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"
143cp -r "$tmp/files" "$tmp/files-git" # kept for the git-source mutant below
144intree; printf '\n[[package]]\nname = "x"\nsource = "git+https://github.com/aien-dev/spark-crumbs-mv?rev=%s#%s"\n' "$SP" "$SP" >> "$lock"
145expect 1 "in-tree with a -mv git source is refused" "$tmp/t.toml" "has a git source for it at $SP"
146intree; sed -i 's/^name = "spark-crumbs"$/name = "spark-crumbs-extra"/' "$lock"
147expect 1 "in-tree with no package of that name is refused" "$tmp/t.toml" "no path package named spark-crumbs"
148cp -r "$tmp/files" "$tmp/files-nopkg" # kept for the path-package mutant below
149tree; 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"
150expect 1 "in-tree with a registry package of that name is refused" "$tmp/t.toml" "no path package named spark-crumbs"
151cp -r "$tmp/files" "$tmp/files-reg" # kept for the source-line mutant below
152intree; sed 's/^spark-crumbs-consumed = .*/spark-crumbs-consumed = "intree"/' "$tmp/t.toml" > "$tmp/w.toml"
153expect 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.
156mutant() { # 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}
164mutant "-mv name not read" '/^p = add p capk p z 38$/d' "$tmp/files-mv" "$tmp/m.toml" 1
165mutant "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
166mutant "in-tree path package not required" '/^fn itcheck /,/^oflush 1$/s/^if not pathpkg p$/if false/' "$tmp/files-nopkg" "$tmp/t.toml" 0
167mutant "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
168mutant "in-tree word not checked" '/^fn itcheck /,/^oflush 1$/s/^if not valis e 41$/if false/' "$tmp/files-intree" "$tmp/w.toml" 0
169echo "check_candidate_pins tests: $pass passed, $bad failed"
170[ "$bad" -eq 0 ]