| 1 | # shellcheck shell=bash |
| 2 | # valley changes and valley pending, end to end and unmocked, over the |
| 3 | # repositories one test host serves. The host is made by the integrator |
| 4 | # host's rendered valley-init, relocated as init-e2e relocates it, so the |
| 5 | # project list discovery reads is the one a host publishes, and every |
| 6 | # record is pushed through the hook that host installs. What the |
| 7 | # integrator writes on disk when it lands a change — main, the outcome |
| 8 | # record, the transfer statement — is written here the same way, with a |
| 9 | # key generated for the run. |
| 10 | # Paths and fixtures come from the derivation environment. |
| 11 | # shellcheck disable=SC2154 |
| 12 | set -euo pipefail |
| 13 | |
| 14 | w="$TMPDIR/valley-changes" |
| 15 | mkdir -p "$w" |
| 16 | export HOME="$w" |
| 17 | export XDG_CACHE_HOME="$w/cache" |
| 18 | export GIT_CONFIG_NOSYSTEM=1 |
| 19 | git config --global user.name valley-changes-check |
| 20 | git config --global user.email valley-changes-check@localhost |
| 21 | git config --global init.defaultBranch main |
| 22 | git config --global advice.detachedHead false |
| 23 | unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER |
| 24 | |
| 25 | fail() { |
| 26 | printf 'valley-changes: %s\n' "$*" >&2 |
| 27 | for f in "$w"/out "$w"/err; do |
| 28 | if [ -s "$f" ]; then cat "$f" >&2; fi |
| 29 | done |
| 30 | exit 1 |
| 31 | } |
| 32 | |
| 33 | # ok <command…>: the command succeeds, and its output is kept. |
| 34 | ok() { |
| 35 | "$@" > "$w/out" 2> "$w/err" || fail "$* failed" |
| 36 | } |
| 37 | |
| 38 | # holds <jq condition…>: the last JSON printed holds each. |
| 39 | holds() { |
| 40 | local cond |
| 41 | for cond in "$@"; do |
| 42 | jq -e "$cond" "$w/out" > /dev/null || fail "$cond does not hold" |
| 43 | done |
| 44 | } |
| 45 | |
| 46 | # line <ERE>: the last output has a line matching it. |
| 47 | line() { |
| 48 | grep -qE -- "$1" "$w/out" || fail "no line matches $1" |
| 49 | } |
| 50 | |
| 51 | no_line() { |
| 52 | if grep -qE -- "$1" "$w/out"; then fail "a line matches $1"; fi |
| 53 | } |
| 54 | |
| 55 | # after <ERE> <ERE…>: the first line of the last output that matches the |
| 56 | # first is followed, line by line, by lines matching the rest. |
| 57 | after() { |
| 58 | local n re |
| 59 | n="$(grep -nE -m 1 -- "$1" "$w/out" | cut -d: -f1 || true)" |
| 60 | [ -n "$n" ] || fail "no line matches $1" |
| 61 | for re in "${@:2}"; do |
| 62 | n=$((n + 1)) |
| 63 | sed -n "${n}p" "$w/out" | grep -qE -- "$re" || fail "line $n, after $1, does not match $re" |
| 64 | done |
| 65 | } |
| 66 | |
| 67 | # The host: guarded, open, released and sealed, with sealed the instance |
| 68 | # repository. valley-init creates them, wires their hooks, and publishes |
| 69 | # the project list in sealed. |
| 70 | data="$w/srv/git" |
| 71 | mkdir -p "$data" |
| 72 | sed "s|/srv/git|$data|g" "$initScriptPath" > "$w/init.sh" |
| 73 | bash "$w/init.sh" 2> "$w/init.err" || fail "valley-init failed: $(cat "$w/init.err")" |
| 74 | instance="$data/sealed.git" |
| 75 | # The integrator's repositories are group-shared, and git then sets the |
| 76 | # setgid bit on every directory it makes, which this sandbox refuses. The |
| 77 | # setting is dropped so the pushes below can write objects; it decides |
| 78 | # nothing this check reads. |
| 79 | for name in guarded open released sealed; do |
| 80 | git -C "$data/$name.git" config --unset core.sharedRepository || true |
| 81 | done |
| 82 | [ "$(git -C "$instance" cat-file blob refs/the-valley/projects)" = "$(printf '%s\n' guarded open released sealed)" ] || |
| 83 | fail "valley-init published another project list" |
| 84 | |
| 85 | # A change's ID, by the letter it repeats. Each is 32 letters from k to z. |
| 86 | id() { printf '%s%s' "$1" "$(printf 'k%.0s' $(seq $((32 - ${#1}))))"; } |
| 87 | A="$(id nxvpwlkm)" B="$(id mmmm)" C="$(id pppp)" D="$(id qqqq)" E="$(id rrrr)" |
| 88 | W="$(id ssss)" F="$(id tttt)" G="$(id uuuu)" U="$(id vvvv)" H="$(id wwww)" |
| 89 | X="$(id oooo)" I="$(id zzzz)" J="$(id lmlm)" X2="$(id pqpq)" |
| 90 | R="$(id nxvpwlkz)" D2="$(id xxxx)" E2="$(id yyyy)" |
| 91 | |
| 92 | # A checkout of a project, whose main names sealed as its owning valley. |
| 93 | # Every push carries the principal, as the key sshd authenticated would. |
| 94 | export VALLEY_PRINCIPAL=klaus-env |
| 95 | checkout() { |
| 96 | local name="$1" dir="$w/$1" |
| 97 | git clone --quiet "$data/$name.git" "$dir" 2> /dev/null |
| 98 | git -C "$dir" config valley.principal klaus-env |
| 99 | mkdir -p "$dir/policy" |
| 100 | printf '# the owning valley\n%s\n' "$instance" > "$dir/policy/valley" |
| 101 | git -C "$dir" add policy/valley |
| 102 | git -C "$dir" commit --quiet -m base |
| 103 | VALLEY_PRINCIPAL=integrator git -C "$dir" push --quiet origin main |
| 104 | } |
| 105 | |
| 106 | # branch <name> <from> <subject…>: a branch from a commit, with a commit |
| 107 | # per subject, each adding a file of its own, pushed to origin. |
| 108 | branch() { |
| 109 | local name="$1" from="$2" s |
| 110 | shift 2 |
| 111 | git checkout --quiet -b "$name" "$from" |
| 112 | for s in "$@"; do |
| 113 | echo "$s" > "$s.txt" |
| 114 | git add "$s.txt" |
| 115 | git commit --quiet -m "$s" |
| 116 | done |
| 117 | git push --quiet origin "$name" |
| 118 | } |
| 119 | |
| 120 | # ready <id> <branch>: the branch's head readied as the change. |
| 121 | ready() { |
| 122 | ok valley ready --change "$1" "$2" |
| 123 | } |
| 124 | |
| 125 | # ---------------------------------------------------------------------- |
| 126 | # open: a stack of three, a draft, a withdrawn change with a ready change |
| 127 | # on top of it, a change landed by fast-forward, one landed as a new |
| 128 | # commit with its transfer statement, one whose request was consumed with |
| 129 | # no evidence stored, one whose transfer statement another key signed, |
| 130 | # and a branch no record is on. |
| 131 | checkout open |
| 132 | cd "$w/open" |
| 133 | base="$(git rev-parse HEAD)" |
| 134 | branch stack-a "$base" stack-a |
| 135 | ready "$A" stack-a |
| 136 | branch stack-b stack-a stack-b |
| 137 | ready "$B" stack-b |
| 138 | branch stack-c stack-b stack-c |
| 139 | ready "$C" stack-c |
| 140 | branch paused "$base" paused |
| 141 | ready "$D" paused |
| 142 | ok valley unready "$D" |
| 143 | branch gone "$base" gone |
| 144 | ready "$E" gone |
| 145 | ok valley withdraw "$E" |
| 146 | branch atop-gone gone atop-gone |
| 147 | ready "$W" atop-gone |
| 148 | branch ff "$base" ff |
| 149 | ready "$F" ff |
| 150 | branch reparent "$base" reparent |
| 151 | ready "$G" reparent |
| 152 | branch lost "$base" lost |
| 153 | ready "$U" lost |
| 154 | branch forged "$base" forged |
| 155 | ready "$H" forged |
| 156 | branch loose "$base" loose |
| 157 | |
| 158 | # Before anything lands, ff names its change. |
| 159 | ok valley-go resolve ff |
| 160 | line "^change"$'\t'"$F"$'\t' |
| 161 | |
| 162 | # The integrator's keys: the integrator's own, and another a known |
| 163 | # signer holds, which may sign evidence and not a landing. |
| 164 | ssh-keygen -q -t ed25519 -N '' -C integrator -f "$w/integrator.key" |
| 165 | ssh-keygen -q -t ed25519 -N '' -C mallory -f "$w/mallory.key" |
| 166 | { |
| 167 | attest key --key "$w/integrator.key" --name integrator |
| 168 | attest key --key "$w/mallory.key" --name mallory |
| 169 | } > "$w/known-signers" |
| 170 | |
| 171 | # F lands by fast-forward. |
| 172 | VALLEY_PRINCIPAL=integrator git push --quiet origin ff:main |
| 173 | fhead="$(git rev-parse ff)" |
| 174 | |
| 175 | # G lands as a new commit on main, and the integrator records it: main |
| 176 | # moves, the outcome record says land, the request is consumed, and the |
| 177 | # transfer statement is stored under the landed tree. |
| 178 | git checkout --quiet -b landing ff |
| 179 | git cherry-pick reparent > /dev/null |
| 180 | landed="$(git rev-parse HEAD)" |
| 181 | VALLEY_PRINCIPAL=integrator git push --quiet origin landing:main |
| 182 | tree_digest() { attest digest --repo "$w/open" --rev "$1" | cut -d: -f2; } |
| 183 | |
| 184 | # memo <name> <head> <decision…>: the integrator's outcome record. |
| 185 | memo() { |
| 186 | local name="$1" head="$2" blob |
| 187 | shift 2 |
| 188 | blob="$(printf '%s %s %s %s\n' "$head" "$fhead" 0123456789abcdef "$*" | git -C "$data/open.git" hash-object -w --stdin)" |
| 189 | git -C "$data/open.git" update-ref "refs/the-valley/integration-outcomes/main/$name" "$blob" |
| 190 | } |
| 191 | |
| 192 | # transfer <change> <head> <landed> <key> <name>: a transfer statement, |
| 193 | # as the integrator composes, signs and stores one. |
| 194 | transfer() { |
| 195 | local change="$1" head="$2" at="$3" key="$4" name="$5" ldigest blob tree |
| 196 | ldigest="$(tree_digest "$at")" |
| 197 | jq -n --arg change "$change" --arg base "$(tree_digest "$head")" --arg landed "$ldigest" \ |
| 198 | --arg commit "$at" --arg tip "$fhead" '{ |
| 199 | statementType: "the-valley/attestation/v1", |
| 200 | subject: {primary: "valley-tree-v1", digest: {"valley-tree-v1": $landed, "git-sha1": $commit}}, |
| 201 | predicateType: "the-valley/integration/transfer/v1", |
| 202 | predicate: {change: $change, target: "refs/heads/main", base: {"valley-tree-v1": $base}, |
| 203 | policy: {sha256: ("ab" * 32), "git-sha1": $tip}, required: "none"} |
| 204 | }' > "$w/statement.json" |
| 205 | attest render "$w/statement.json" | attest sign --key "$key" --name "$name" > "$w/transfer.note" |
| 206 | blob="$(git -C "$data/open.git" hash-object -w "$w/transfer.note")" |
| 207 | tree="$(printf '100644 blob %s\ttransfer.note\n' "$blob" | git -C "$data/open.git" mktree)" |
| 208 | git -C "$data/open.git" update-ref "refs/the-valley/attestations/$ldigest/$(printf '%08x' "${#name}")" "$tree" |
| 209 | } |
| 210 | memo reparent "$(git rev-parse reparent)" land |
| 211 | transfer reparent "$(git rev-parse reparent)" "$landed" "$w/integrator.key" integrator |
| 212 | |
| 213 | # U's request was consumed, and no evidence was stored. |
| 214 | memo lost "$(git rev-parse lost)" land |
| 215 | # H's request was consumed too, and its transfer statement is signed by a |
| 216 | # known key that is not the integrator's: it is no record of a landing. |
| 217 | memo forged "$(git rev-parse forged)" land |
| 218 | git checkout --quiet -b landing-h landing |
| 219 | git cherry-pick forged > /dev/null |
| 220 | VALLEY_PRINCIPAL=integrator git push --quiet origin landing-h:main |
| 221 | transfer forged "$(git rev-parse forged)" "$(git rev-parse HEAD)" "$w/mallory.key" mallory |
| 222 | # A's request is pending. |
| 223 | git -C "$data/open.git" update-ref refs/the-valley/integration-requests/main/stack-a "$(git rev-parse stack-a)" |
| 224 | |
| 225 | # I lands as a new commit, L2, filed as c-<I>, and the integrator records |
| 226 | # it. Then I's next version, H', has H's tree with L2 as its parent. Its |
| 227 | # name and its tree digest match the transfer statement, but it is another |
| 228 | # delta: merged onto L2's parent it does not give L2's tree. I is then made |
| 229 | # a draft. |
| 230 | branch again "$base" again |
| 231 | ready "$I" again |
| 232 | hhead="$(git rev-parse again)" |
| 233 | git checkout --quiet -b landing-i landing-h |
| 234 | git cherry-pick again > /dev/null |
| 235 | landed2="$(git rev-parse HEAD)" |
| 236 | VALLEY_PRINCIPAL=integrator git push --quiet origin landing-i:main |
| 237 | memo "c-$I" "$hhead" land |
| 238 | transfer "c-$I" "$hhead" "$landed2" "$w/integrator.key" integrator |
| 239 | hprime="$(git commit-tree "again^{tree}" -p "$landed2" -m again)" |
| 240 | git push --quiet --force origin "$hprime:refs/heads/again" |
| 241 | ready "$I" again |
| 242 | ok valley unready "$I" |
| 243 | |
| 244 | # J lands by fast-forward, and the integrator records it: its outcome |
| 245 | # record says land at J's head, and its transfer statement is about J's |
| 246 | # tree. Then main moves on to Q, which adds a file, and J's next version, |
| 247 | # J', has J's tree with Q as its parent: it deletes Q's file. J' matches |
| 248 | # the statement's name and tree, and merged onto the parent of the commit |
| 249 | # that landed it gives that commit's tree. But the outcome record names |
| 250 | # J's head, not J', so J' has not landed. J is then made a draft. |
| 251 | branch ffrec landing-i ffrec |
| 252 | ready "$J" ffrec |
| 253 | jhead="$(git rev-parse ffrec)" |
| 254 | VALLEY_PRINCIPAL=integrator git push --quiet origin ffrec:main |
| 255 | memo ffrec "$jhead" land |
| 256 | transfer ffrec "$jhead" "$jhead" "$w/integrator.key" integrator |
| 257 | git checkout --quiet -b moved-on ffrec |
| 258 | echo q > q.txt |
| 259 | git add q.txt |
| 260 | git commit --quiet -m q |
| 261 | VALLEY_PRINCIPAL=integrator git push --quiet origin moved-on:main |
| 262 | jprime="$(git commit-tree "ffrec^{tree}" -p moved-on -m ffrec)" |
| 263 | git push --quiet --force origin "$jprime:refs/heads/ffrec" |
| 264 | ready "$J" ffrec |
| 265 | ok valley unready "$J" |
| 266 | |
| 267 | # ---------------------------------------------------------------------- |
| 268 | # guarded: a ready change whose ID shares seven letters with A's, a draft |
| 269 | # and a withdrawn change. |
| 270 | checkout guarded |
| 271 | cd "$w/guarded" |
| 272 | gbase="$(git rev-parse HEAD)" |
| 273 | branch g-ready "$gbase" g-ready |
| 274 | ready "$R" g-ready |
| 275 | branch g-draft "$gbase" g-draft |
| 276 | ready "$D2" g-draft |
| 277 | ok valley unready "$D2" |
| 278 | branch g-gone "$gbase" g-gone |
| 279 | ready "$E2" g-gone |
| 280 | ok valley withdraw "$E2" |
| 281 | # B's change ID, recorded here too. |
| 282 | branch g-dup "$gbase" g-dup |
| 283 | ready "$B" g-dup |
| 284 | |
| 285 | # A merge on main can drop the content of either parent, so no head below |
| 286 | # one has landed by ancestry. X is ready, and a merge of it whose tree |
| 287 | # drops its changes lands on main by fast-forward: M = (main, X), with |
| 288 | # main's tree. Then X2, branched from that main, is dropped by a merge with |
| 289 | # its parents reversed: M2 = (X2, main), with main's tree. X2 is on main's |
| 290 | # first-parent history, below the merge that dropped it. |
| 291 | branch dropped "$gbase" dropped |
| 292 | ready "$X" dropped |
| 293 | merge="$(git commit-tree "$gbase^{tree}" -p "$gbase" -p dropped -m 'merge, dropping X')" |
| 294 | VALLEY_PRINCIPAL=integrator git push --quiet origin "$merge:refs/heads/main" |
| 295 | branch reversed "$merge" reversed |
| 296 | ready "$X2" reversed |
| 297 | merge2="$(git commit-tree "$merge^{tree}" -p reversed -p "$merge" -m 'merge, dropping X2')" |
| 298 | VALLEY_PRINCIPAL=integrator git push --quiet origin "$merge2:refs/heads/main" |
| 299 | |
| 300 | # origin: a project named origin, recording B's change ID too. A host that |
| 301 | # declared it would list it, so it is added to the list on disk, as |
| 302 | # valley-init writes the list. |
| 303 | git init --quiet --bare "$data/origin.git" |
| 304 | checkout origin |
| 305 | cd "$w/origin" |
| 306 | branch o-dup "$(git rev-parse HEAD)" o-dup |
| 307 | ready "$B" o-dup |
| 308 | projects="$(printf '%s\n' guarded open origin released sealed | git -C "$instance" hash-object -w --stdin)" |
| 309 | git -C "$instance" update-ref refs/the-valley/projects "$projects" |
| 310 | |
| 311 | # released is listed and cannot be read. |
| 312 | mv "$data/released.git" "$data/released.moved" |
| 313 | |
| 314 | export VALLEY_KNOWN_SIGNERS="$w/known-signers" VALLEY_INTEGRATOR_SIGNER=integrator |
| 315 | |
| 316 | # ---------------------------------------------------------------------- |
| 317 | # One repository: every record in every state, as valley-changes/v1. |
| 318 | cd "$w/open" |
| 319 | ok valley changes --json |
| 320 | [ "$(wc -l < "$w/out")" = 1 ] || fail "changes printed more than one line" |
| 321 | holds '.schema == "valley-changes/v1"' '.host == "localhost"' '(.repos | length) == 1' \ |
| 322 | '.repos[0].repo == "open"' ".repos[0].url == \"$data/open.git\"" '.repos[0].error == null' \ |
| 323 | '(.repos[0].changes | length) == 12' '.repos[0] | has("drafts") | not' |
| 324 | c() { printf '.repos[0].changes[] | select(.change_id == "%s")' "$1"; } |
| 325 | holds "$(c "$A") | .handle == \"nxvp\" and .state == \"ready\" and .owner == \"klaus-env\" and .target == \"main\" and .active == 1 and .seq == 1" \ |
| 326 | "$(c "$A") | .record == \"$(git -C "$data/open.git" rev-parse "refs/the-valley/changes/main/$A")\"" \ |
| 327 | "$(c "$A") | .versions[0] | .n == 1 and .title == \"stack-a\" and .branch == \"stack-a\" and .uploader == \"klaus-env\"" \ |
| 328 | "$(c "$A") | .versions[0] | .head == \"$(git rev-parse stack-a)\" and .landing == \"not-landed\" and .landed_commit == null" \ |
| 329 | "$(c "$A") | .versions[0].request == {ref: \"refs/the-valley/integration-requests/main/stack-a\", commit: \"$(git rev-parse stack-a)\"}" \ |
| 330 | "$(c "$A") | .versions[0].outcome == null" \ |
| 331 | "$(c "$D") | .state == \"draft\" and .seq == 2" \ |
| 332 | "$(c "$E") | .state == \"withdrawn\"" |
| 333 | # Landing evidence, one version each way. |
| 334 | holds "$(c "$F") | .versions[0] | .landing == \"landed\" and .landed_commit == \"$fhead\"" \ |
| 335 | "$(c "$G") | .versions[0] | .landing == \"landed-recorded\" and .landed_commit == \"$landed\"" \ |
| 336 | "$(c "$G") | .versions[0].outcome == {decision: \"land\", head: \"$(git rev-parse reparent)\", tip: \"$fhead\"}" \ |
| 337 | "$(c "$G") | .versions[0].request == null" \ |
| 338 | "$(c "$U") | .versions[0] | .landing == \"uncertain\" and .landed_commit == null" \ |
| 339 | "$(c "$H") | .versions[0].landing == \"uncertain\"" \ |
| 340 | "$(c "$J") | .versions[0] | .landing == \"landed\" and .landed_commit == \"$jhead\"" \ |
| 341 | "$(c "$J") | .versions[1] | .head == \"$jprime\" and .landing == \"not-landed\" and .landed_commit == null" \ |
| 342 | "$(c "$J") | .state == \"draft\" and .active == 2" \ |
| 343 | "$(c "$I") | .versions[0] | .landing == \"landed-recorded\" and .landed_commit == \"$landed2\"" \ |
| 344 | "$(c "$I") | .versions[1] | .head == \"$hprime\" and .landing == \"not-landed\" and .landed_commit == null" \ |
| 345 | "$(c "$I") | .state == \"draft\" and .active == 2" |
| 346 | # includes is ancestry, nearest only. |
| 347 | holds "$(c "$A") | .includes == []" "$(c "$B") | .includes == [\"$A\"]" \ |
| 348 | "$(c "$C") | .includes == [\"$B\"]" "$(c "$W") | .includes == [\"$E\"]" |
| 349 | # The one branch no record is on, and no branch main reaches. |
| 350 | holds '.repos[0].branches == [{branch: "loose", head: "'"$(git rev-parse loose)"'"}]' |
| 351 | |
| 352 | # Without the registry's keys, the transfer statement is not believed, and |
| 353 | # that is said. |
| 354 | env -u VALLEY_KNOWN_SIGNERS valley changes --json > "$w/out" 2> "$w/err" || fail "changes failed without the keys" |
| 355 | holds "$(c "$G") | .versions[0].landing == \"uncertain\"" |
| 356 | grep -q 'could not be verified' "$w/err" || fail "an unverified transfer statement was not reported" |
| 357 | |
| 358 | # ---------------------------------------------------------------------- |
| 359 | # Every project the host publishes. Handles are unique across both |
| 360 | # repositories, the repository that cannot be read carries its error, and |
| 361 | # the others are listed all the same. |
| 362 | ok valley changes --json --all |
| 363 | holds '[.repos[].repo] == ["guarded", "open", "origin", "released", "sealed"]' \ |
| 364 | '.repos[] | select(.repo == "released") | .error != null and .changes == [] and .url == "'"$data/released.git"'"' \ |
| 365 | '.repos[] | select(.repo != "released") | .error == null' \ |
| 366 | '.repos[] | select(.repo == "sealed") | .changes == []' \ |
| 367 | '[.repos[].changes[].handle] | length == (unique | length)' \ |
| 368 | "[.repos[].changes[] | select(.change_id == \"$A\" or .change_id == \"$R\") | .handle] == [\"nxvpwlkz\", \"nxvpwlkm\"]" \ |
| 369 | "[.repos[].changes[] | select(.change_id == \"$B\") | .handle] == [\"guarded:mmmm\", \"open:mmmm\", \"origin:mmmm\"]" \ |
| 370 | '.repos[] | select(.repo == "guarded") | [.changes[].state] == ["ready", "ready", "ready", "ready", "draft", "withdrawn"]' |
| 371 | # ls-remote matches a ref's tail, so refs whose names end like the |
| 372 | # refs discovery reads must not stand in for them: one in open whose |
| 373 | # policy/valley names another instance, and one in the instance listing |
| 374 | # another project. |
| 375 | git checkout --quiet -b decoy "$base" |
| 376 | printf '%s\n' "$w/elsewhere.git" > policy/valley |
| 377 | git commit --quiet -am decoy |
| 378 | git push --quiet origin decoy:refs/heads/a/refs/heads/main |
| 379 | decoy_list="$(printf 'decoy\n' | git -C "$instance" hash-object -w --stdin)" |
| 380 | git -C "$instance" update-ref refs/tags/a/refs/the-valley/projects "$decoy_list" |
| 381 | git checkout --quiet landing |
| 382 | ok valley changes --json --all |
| 383 | holds '[.repos[].repo] == ["guarded", "open", "origin", "released", "sealed"]' |
| 384 | git push --quiet origin :refs/heads/a/refs/heads/main |
| 385 | git -C "$instance" update-ref -d refs/tags/a/refs/the-valley/projects |
| 386 | # --repo limits the listing to one repository, read through its clone. |
| 387 | ok valley changes --json --repo guarded |
| 388 | holds '[.repos[].repo] == ["guarded"]' "[.repos[0].changes[].change_id] == [\"$B\", \"$R\", \"$X\", \"$X2\", \"$D2\", \"$E2\"]" \ |
| 389 | '[.repos[0].changes[].handle] == ["mmmm", "nxvp", "oooo", "pqpq", "xxxx", "yyyy"]' \ |
| 390 | "[.repos[0].changes[] | select(.change_id == \"$X\" or .change_id == \"$X2\") | .versions[0] | [.landing, .landed_commit]] == [[\"not-landed\", null], [\"not-landed\", null]]" |
| 391 | cd "$w/guarded" |
| 392 | ok valley changes --json |
| 393 | holds '[.repos[].repo] == ["guarded"]' '[.repos[0].changes[].handle] == ["mmmm", "nxvp", "oooo", "pqpq", "xxxx", "yyyy"]' |
| 394 | # A qualified handle names the change in the repository it qualifies, and |
| 395 | # a qualifier naming another repository is refused. |
| 396 | ok valley-go resolve guarded:mmmm |
| 397 | line "^change"$'\t'"$B"$'\t'"mmmm"$'\t'"1"$'\t'"$(git rev-parse g-dup)"$'\t' |
| 398 | cd "$w/open" |
| 399 | ok valley-go resolve open:mmmm |
| 400 | line "^change"$'\t'"$B"$'\t'"mmmm"$'\t'"1"$'\t'"$(git rev-parse stack-b)"$'\t' |
| 401 | if valley-go resolve origin:mmmm > "$w/out" 2> "$w/err"; then fail "open resolved a handle qualified by origin"; fi |
| 402 | grep -q 'origin:mmmm names a change in origin, and this repository is open' "$w/err" || fail "origin:mmmm was refused without saying why" |
| 403 | cd "$w/origin" |
| 404 | ok valley-go resolve origin:mmmm |
| 405 | line "^change"$'\t'"$B"$'\t'"mmmm"$'\t'"1"$'\t'"$(git rev-parse o-dup)"$'\t' |
| 406 | ok valley status origin:mmmm |
| 407 | cd "$w/guarded" |
| 408 | if valley changes --json --repo nowhere > "$w/out" 2> "$w/err"; then fail "--repo took a project the host does not list"; fi |
| 409 | grep -q 'lists no project nowhere' "$w/err" || fail "--repo nowhere was refused without saying why" |
| 410 | cd "$w/open" |
| 411 | |
| 412 | # A repository whose main names no owning valley lists itself alone, and |
| 413 | # says discovery is unavailable. |
| 414 | git init --quiet --bare "$w/solo.git" |
| 415 | git clone --quiet "$w/solo.git" "$w/solo" 2> /dev/null |
| 416 | git -C "$w/solo" commit --quiet --allow-empty -m solo |
| 417 | git -C "$w/solo" push --quiet origin main |
| 418 | (cd "$w/solo" && valley changes --json --all) > "$w/out" 2> "$w/err" || fail "changes --all failed without discovery" |
| 419 | holds '[.repos[].repo] == ["solo"]' |
| 420 | grep -q 'discovery is unavailable' "$w/err" || fail "changes --all did not say discovery is unavailable" |
| 421 | |
| 422 | # A policy/valley that git would read as an option, or that names a remote |
| 423 | # helper, is refused before git sees it, and nothing it names runs, even |
| 424 | # where the caller's own configuration allows ext::. |
| 425 | for url in "--upload-pack=touch $w/pwned; git-upload-pack" "ext::sh -c touch% $w/pwned"; do |
| 426 | rm -rf "$w/evil.git" "$w/evil" |
| 427 | git init --quiet --bare "$w/evil.git" |
| 428 | git clone --quiet "$w/evil.git" "$w/evil" 2> /dev/null |
| 429 | mkdir -p "$w/evil/policy" |
| 430 | printf '%s\n' "$url" > "$w/evil/policy/valley" |
| 431 | git -C "$w/evil" add policy |
| 432 | git -C "$w/evil" commit --quiet -m evil |
| 433 | git -C "$w/evil" push --quiet origin main |
| 434 | export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=protocol.ext.allow GIT_CONFIG_VALUE_0=always |
| 435 | (cd "$w/evil" && valley changes --json --all) > "$w/out" 2> "$w/err" || fail "changes --all failed over policy/valley $url" |
| 436 | holds '[.repos[].repo] == ["evil"]' |
| 437 | grep -q 'discovery is unavailable' "$w/err" || fail "policy/valley $url was not refused" |
| 438 | if (cd "$w/evil" && valley changes --json --repo other) > "$w/out" 2> "$w/err"; then |
| 439 | fail "--repo read through policy/valley $url" |
| 440 | fi |
| 441 | unset GIT_CONFIG_COUNT GIT_CONFIG_KEY_0 GIT_CONFIG_VALUE_0 |
| 442 | [ ! -e "$w/pwned" ] || fail "policy/valley $url ran a command" |
| 443 | done |
| 444 | |
| 445 | # ---------------------------------------------------------------------- |
| 446 | # pending: a block per entry, in three sections. A stack is its top |
| 447 | # entry, then every entry the top contains, as one list, each counted from |
| 448 | # the entry it contains. atop-lost is a branch no record is on, holding U, |
| 449 | # a ready change. a-parked is a branch last committed to eleven days ago. |
| 450 | # deep-4 tops a chain of four branches. fork-left and fork-right are two |
| 451 | # branches on one base, fork-base. The chain and the fork were last |
| 452 | # committed to twenty days ago. |
| 453 | branch atop-lost lost atop-lost |
| 454 | parked="@$(($(date +%s) - 11 * 86400))" |
| 455 | GIT_AUTHOR_DATE="$parked" GIT_COMMITTER_DATE="$parked" branch a-parked "$base" a-parked |
| 456 | old="@$(($(date +%s) - 20 * 86400))" |
| 457 | export GIT_AUTHOR_DATE="$old" GIT_COMMITTER_DATE="$old" |
| 458 | branch deep-1 "$base" deep-1 |
| 459 | branch deep-2 deep-1 deep-2 |
| 460 | branch deep-3 deep-2 deep-3 |
| 461 | branch deep-4 deep-3 deep-4 |
| 462 | branch fork-base "$base" fork-base |
| 463 | branch fork-left fork-base fork-left |
| 464 | branch fork-right fork-base fork-right |
| 465 | unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE |
| 466 | ok valley pending |
| 467 | no_line $'\x1b' |
| 468 | line '^ready$' |
| 469 | # The stack of three, outermost first, each layer counted on its own. |
| 470 | after '^pppp v1 +[0-9]+ [a-z]+ ago · valley-changes-check$' '^ stack-c$' '^ 1 commit · 1 file \+1 −0$' \ |
| 471 | '^ approving it lands the 2 below too$' \ |
| 472 | '^ ├ mmmm v1 +.* ago · valley-changes-check$' '^ │ stack-b$' '^ │ 1 commit · 1 file \+1 −0$' \ |
| 473 | '^ └ nxvp v1 +.* ago · valley-changes-check$' '^ stack-a$' '^ 1 commit · 1 file \+1 −0$' '^$' |
| 474 | # W includes E, which is withdrawn, so it is counted from main. |
| 475 | after '^ssss v1 ' '^ atop-gone$' '^ 2 commits · 2 files \+2 −0$' '^ includes rrrr \(withdrawn\)$' '^$' |
| 476 | after '^wwww v1 ' '^ forged$' '^ 1 commit · 1 file \+1 −0$' '^ uncertain: it may have landed without its evidence being stored$' |
| 477 | no_line '(tttt|uuuu|rrrr) v1' |
| 478 | no_line 'qqqq v1 ' |
| 479 | # The branches, latest first, and atop-lost with U listed under it, |
| 480 | # marked as ready. |
| 481 | after '^branches$' '^atop-lost +.* ago · valley-changes-check$' '^ atop-lost$' '^ 1 commit · 1 file \+1 −0$' \ |
| 482 | '^ approving it lands the one below too$' \ |
| 483 | '^ └ vvvv v1 \(ready\) +.* ago · valley-changes-check$' '^ lost$' '^ 1 commit · 1 file \+1 −0$' \ |
| 484 | '^ uncertain: ' '^$' '^loose +.* ago · valley-changes-check$' '^ loose$' '^ 1 commit · 1 file \+1 −0$' '^$' \ |
| 485 | '^a-parked +11 days ago · valley-changes-check$' '^ a-parked$' '^ 1 commit · 1 file \+1 −0$' '^$' '^deep-4 ' |
| 486 | # A chain four deep is one flat list, with no on line: each entry is on |
| 487 | # the one listed after it. |
| 488 | after '^deep-4 +3 weeks ago · valley-changes-check$' '^ deep-4$' '^ 1 commit · 1 file \+1 −0$' \ |
| 489 | '^ approving it lands the 3 below too$' \ |
| 490 | '^ ├ deep-3 +3 weeks ago · valley-changes-check$' '^ │ deep-3$' '^ │ 1 commit · 1 file \+1 −0$' \ |
| 491 | '^ ├ deep-2 +3 weeks ago · valley-changes-check$' '^ │ deep-2$' '^ │ 1 commit · 1 file \+1 −0$' \ |
| 492 | '^ └ deep-1 +3 weeks ago · valley-changes-check$' '^ deep-1$' '^ 1 commit · 1 file \+1 −0$' '^$' |
| 493 | no_line '^ *(│ *)?on deep-' |
| 494 | # Of two branches on one base, one lists the base, and the other says it |
| 495 | # is on it. The base is listed once. |
| 496 | [ "$(grep -cE '(^|├ |└ )fork-base ' "$w/out")" = 1 ] || fail "pending did not list fork-base exactly once" |
| 497 | [ "$(grep -cx ' on fork-base' "$w/out")" = 1 ] || fail "not exactly one of the fork says it is on fork-base" |
| 498 | after '^fork-left ' '^ fork-left$' '^ 1 commit · 1 file \+1 −0$' '^ approving it lands the one below too$' \ |
| 499 | '^ └ fork-base ' '^ fork-base$' '^ 1 commit · 1 file \+1 −0$' '^$' |
| 500 | after '^fork-right ' '^ fork-right$' '^ 1 commit · 1 file \+1 −0$' '^ on fork-base$' '^$' '^drafts$' |
| 501 | after '^qqqq v1 on paused +.* ago · valley-changes-check$' '^ paused$' '^ 1 commit · 1 file \+1 −0$' |
| 502 | after '^zzzz v2 on again ' '^ again$' '^ 1 commit · ' |
| 503 | after '^lmlm v2 on ffrec ' '^ ffrec$' '^ 1 commit · 1 file \+0 −1$' |
| 504 | [ "$(grep -n '^ready$' "$w/out" | cut -d: -f1)" -lt "$(grep -n '^branches$' "$w/out" | cut -d: -f1)" ] || |
| 505 | fail "pending listed the branches before the ready changes" |
| 506 | # --json is the same listing in valley-changes/v1's shape: the pending |
| 507 | # changes alone in changes, and the drafts in drafts. |
| 508 | ok valley pending --json |
| 509 | holds '.schema == "valley-pending/v1"' \ |
| 510 | '[.repos[0].changes[].handle] == ["mmmm", "nxvp", "pppp", "ssss", "vvvv", "wwww"]' \ |
| 511 | '[.repos[0].changes[].state] | unique == ["ready"]' \ |
| 512 | '[.repos[0].drafts[] | [.handle, .state]] == [["lmlm", "draft"], ["qqqq", "draft"], ["zzzz", "draft"]]' \ |
| 513 | '[.repos[0].branches[].branch] == ["a-parked", "atop-lost", "deep-1", "deep-2", "deep-3", "deep-4", "fork-base", "fork-left", "fork-right", "loose"]' |
| 514 | # Across the host, each repository is headed by its name, and handles |
| 515 | # are qualified where a change ID is recorded in more than one. In origin, |
| 516 | # a branch no record is on holds the one ready change, so the ready |
| 517 | # section says where it is. |
| 518 | (cd "$w/origin" && branch atop-dup o-dup atop-dup) |
| 519 | ok valley pending --all |
| 520 | after '^guarded$' '^(─)+$' '^ready$' |
| 521 | after '^nxvpwlkz v1 ' '^ g-ready$' '^ 1 commit · 1 file \+1 −0$' |
| 522 | after '^guarded:mmmm v1 ' '^ g-dup$' |
| 523 | after '^pqpq v1 ' '^ reversed$' '^ no commits · ' '^ approving it lands the one below too$' '^ └ oooo v1 ' \ |
| 524 | '^ dropped$' '^ no commits · no file changes$' |
| 525 | line '^xxxx v1 on g-draft ' |
| 526 | line '^open$' |
| 527 | after '^pppp v1 ' '^ stack-c$' '^ 1 commit · ' '^ approving it lands the 2 below too$' '^ ├ open:mmmm v1 ' \ |
| 528 | '^ │ stack-b$' '^ │ 1 commit · ' '^ └ nxvpwlkm v1 ' '^ stack-a$' |
| 529 | after '^origin$' '^(─)+$' '^nothing is ready on its own; 1 ready change is in a stack under branches$' '^$' \ |
| 530 | '^branches$' '^atop-dup ' '^ atop-dup$' '^ 1 commit · ' '^ approving it lands the one below too$' \ |
| 531 | '^ └ origin:mmmm v1 \(ready\) ' '^ o-dup$' |
| 532 | line '^released: could not read ' |
| 533 | after '^sealed$' '^(─)+$' '^nothing is ready$' |
| 534 | |
| 535 | # --checks adds a line to each change with the checks it requires, by |
| 536 | # cost, as valley checks derives them, here and in a repository read |
| 537 | # through its clone. The instance gets a floor for that, written to its |
| 538 | # main on disk as the integrator would. |
| 539 | git init --quiet "$w/floor" |
| 540 | mkdir -p "$w/floor/policy/instance" |
| 541 | cp "$floor"/*.cue "$w/floor/policy/instance/" |
| 542 | git -C "$w/floor" add policy |
| 543 | git -C "$w/floor" commit --quiet -m floor |
| 544 | git -C "$w/floor" push --quiet "$instance" HEAD:refs/heads/floor |
| 545 | git -C "$instance" update-ref refs/heads/main "$(git -C "$w/floor" rev-parse HEAD)" |
| 546 | ok valley pending --checks --all |
| 547 | after '^pppp v1 ' '^ stack-c$' '^ 1 commit · ' '^ requires 1 quick check, 0 slow$' '^ approving it lands the 2 below too$' \ |
| 548 | '^ ├ open:mmmm v1 ' '^ │ stack-b$' '^ │ 1 commit · ' '^ │ requires 1 quick check, 0 slow$' '^ └ nxvpwlkm v1 ' \ |
| 549 | '^ stack-a$' '^ 1 commit · ' '^ requires 1 quick check, 0 slow$' |
| 550 | after '^nxvpwlkz v1 ' '^ g-ready$' '^ 1 commit · ' '^ requires 1 quick check, 0 slow$' |
| 551 | |
| 552 | # ---------------------------------------------------------------------- |
| 553 | # A branch name is used again once its change has landed: ff now names no |
| 554 | # change, and reparent none either, once its transfer statement verifies. |
| 555 | ok valley-go resolve ff |
| 556 | line "^branch"$'\t'"ff$" |
| 557 | ok valley-go resolve reparent |
| 558 | line "^branch"$'\t'"reparent$" |
| 559 | env -u VALLEY_KNOWN_SIGNERS valley-go resolve reparent > "$w/out" 2> "$w/err" || fail "resolve failed" |
| 560 | line "^change"$'\t'"$G"$'\t' |
| 561 | ok valley-go resolve stack-a |
| 562 | line "^change"$'\t'"$A"$'\t' |
| 563 | |
| 564 | # H' has not landed, so its branch still names I, which is a draft, and |
| 565 | # approving the branch is refused for I's state rather than taken as a |
| 566 | # plain branch. |
| 567 | ok valley-go resolve again |
| 568 | line "^change"$'\t'"$I"$'\t'"zzzz"$'\t'"2"$'\t'"$hprime"$'\t'"again"$'\t'"draft$" |
| 569 | if valley approve again > "$w/out" 2> "$w/err"; then fail "approve took the branch of a draft"; fi |
| 570 | grep -q "change zzzz v2 is draft, not ready" "$w/err" || fail "approve did not refuse the draft for its state" |
| 571 | |
| 572 | # J' is not J's landing replayed, so its branch names J, a draft, too. |
| 573 | ok valley-go resolve ffrec |
| 574 | line "^change"$'\t'"$J"$'\t'"lmlm"$'\t'"2"$'\t'"$jprime"$'\t'"ffrec"$'\t'"draft$" |
| 575 | if valley approve ffrec > "$w/out" 2> "$w/err"; then fail "approve took the branch of a replayed landing"; fi |
| 576 | grep -q "change lmlm v2 is draft, not ready" "$w/err" || fail "approve did not refuse J' for its state" |
| 577 | |
| 578 | # A landed change names its branch no more once the branch moves on to new |
| 579 | # work: ff is a branch, free for that work. |
| 580 | git checkout --quiet -b ff-again ff |
| 581 | echo more > more.txt |
| 582 | git add more.txt |
| 583 | git commit --quiet -m more |
| 584 | git push --quiet origin ff-again:ff |
| 585 | ok valley-go resolve ff |
| 586 | line "^branch"$'\t'"ff$" |
| 587 | |
| 588 | # valley help names the verbs klaus looks for. |
| 589 | valley help > "$w/out" |
| 590 | line '^ ready ' |
| 591 | line '^ changes ' |
| 592 | |
| 593 | touch "$out" |