| 1 | # shellcheck shell=bash |
| 2 | # valley-restacker once --report-only, end to end over a real bare |
| 3 | # repository wired with the fixture host's rendered pre-receive hook. |
| 4 | # Every change is readied with the repository's own valley as its owner. |
| 5 | # The hook grants request and restack to the principal requester, which |
| 6 | # files the requests, and restack alone to the principal restacker, which |
| 7 | # is the principal the restacker counts. |
| 8 | # |
| 9 | # In the planner's scenarios, outcome records are injected on the server |
| 10 | # side with update-ref, because no push may write one: only the |
| 11 | # integrator writes them. Each injection is marked where it is made. The |
| 12 | # fixtures after them run the real integrator. |
| 13 | # Paths and fixtures come from the derivation environment. |
| 14 | # shellcheck disable=SC2154 |
| 15 | set -euo pipefail |
| 16 | |
| 17 | w="$TMPDIR/restack-e2e" |
| 18 | mkdir -p "$w" |
| 19 | export HOME="$w" |
| 20 | export GIT_CONFIG_NOSYSTEM=1 |
| 21 | git config --global user.name restack-e2e |
| 22 | git config --global user.email restack-e2e@localhost |
| 23 | git config --global init.defaultBranch main |
| 24 | git config --global advice.detachedHead false |
| 25 | |
| 26 | fail() { |
| 27 | printf 'restack-e2e: %s\n' "$*" >&2 |
| 28 | for f in "$w"/out "$w"/err; do |
| 29 | if [ -s "$f" ]; then cat "$f" >&2; fi |
| 30 | done |
| 31 | exit 1 |
| 32 | } |
| 33 | |
| 34 | origin="$w/project.git" |
| 35 | hook="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$initScriptPath" | head -n1)" |
| 36 | test -x "$hook" |
| 37 | git init --quiet --bare "$origin" |
| 38 | cp "$hook" "$origin/hooks/pre-receive" |
| 39 | chmod +x "$origin/hooks/pre-receive" |
| 40 | |
| 41 | repo="$w/project" |
| 42 | git init --quiet "$repo" |
| 43 | cd "$repo" |
| 44 | git remote add origin "$origin" |
| 45 | # The project layer caps the restacker at two automatic versions a change. |
| 46 | mkdir -p policy/project |
| 47 | printf 'package verification\n\nproject: restack: maxAutomaticVersions: 2\n' > policy/project/policy.cue |
| 48 | echo base > readme |
| 49 | git add readme policy |
| 50 | git commit --quiet -m base |
| 51 | env -u VALLEY_PRINCIPAL git push --quiet origin main |
| 52 | |
| 53 | as() { |
| 54 | local who="$1" |
| 55 | shift |
| 56 | git config valley.principal "$who" |
| 57 | VALLEY_PRINCIPAL="$who" "$@" |
| 58 | } |
| 59 | ok() { "$@" > "$w/out" 2> "$w/err" || fail "$* failed"; } |
| 60 | |
| 61 | # change <owner> <branch> <base>: a commit on base, pushed and readied by |
| 62 | # its owner; prints the change ID. |
| 63 | change() { |
| 64 | local who="$1" branch="$2" base="$3" |
| 65 | git checkout --quiet -B "$branch" "$base" |
| 66 | echo "$branch" > "$branch" |
| 67 | git add "$branch" |
| 68 | git commit --quiet -m "$branch" |
| 69 | as "$who" git push --quiet --force origin "$branch" |
| 70 | ok as "$who" valley ready |
| 71 | sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$w/out" |
| 72 | } |
| 73 | # branch <name> <base>: a plain branch, which no record is on. |
| 74 | branch() { |
| 75 | git checkout --quiet -B "$1" "$2" |
| 76 | echo "$1" > "$1" |
| 77 | git add "$1" |
| 78 | git commit --quiet -m "$1" |
| 79 | as alice git push --quiet origin "$1" |
| 80 | } |
| 81 | |
| 82 | base="$(git rev-parse main)" |
| 83 | a="$(change alice a "$base")" |
| 84 | b1="$(change bob b1 "$base")" |
| 85 | b2="$(change bob b2 b1)" |
| 86 | c1="$(change alice c1 "$base")" |
| 87 | c2="$(change alice c2 c1)" |
| 88 | c3="$(change bob c3 c1)" |
| 89 | d="$(change alice d "$base")" |
| 90 | ok as alice valley unready "$d" |
| 91 | wd="$(change bob wd "$base")" |
| 92 | ok as bob valley withdraw "$wd" |
| 93 | branch plain "$base" |
| 94 | e="$(change alice e "$base")" |
| 95 | branch e-plain e |
| 96 | g1="$(change alice g1 "$base")" |
| 97 | g2="$(change alice g2 g1)" |
| 98 | ok as alice valley unready "$g1" |
| 99 | u="$(change bob u "$base")" |
| 100 | # k gains two versions from the restacker principal. A version the restack |
| 101 | # grant adds keeps the active version's title, so each commit's subject is |
| 102 | # k's title; one under any other title is refused, and its branch is put |
| 103 | # back. |
| 104 | k="$(change alice k "$base")" |
| 105 | git checkout --quiet k |
| 106 | for n in 2 3; do |
| 107 | echo "$n" >> k |
| 108 | git commit --quiet -am k |
| 109 | as restacker git push --quiet origin k |
| 110 | ok as restacker valley ready --change "$k" k |
| 111 | done |
| 112 | echo forged >> k |
| 113 | git commit --quiet -am 'a title of its own' |
| 114 | as restacker git push --quiet origin k |
| 115 | if as restacker valley ready --change "$k" k > "$w/out" 2> "$w/err"; then |
| 116 | fail 'the restacker readied a version under a title of its own' |
| 117 | fi |
| 118 | grep -q 'under the title of the active one' "$w/err" || fail 'the refusal does not name the title' |
| 119 | git reset --quiet --hard HEAD~1 |
| 120 | as restacker git push --quiet --force origin k |
| 121 | # s lands by fast-forward before main moves, so it is submitted. |
| 122 | s="$(change alice s "$base")" |
| 123 | env -u VALLEY_PRINCIPAL git push --quiet origin s:main |
| 124 | git checkout --quiet main |
| 125 | git reset --quiet --hard origin/main |
| 126 | echo moved > moved |
| 127 | git add moved |
| 128 | git commit --quiet -m moved |
| 129 | env -u VALLEY_PRINCIPAL git push --quiet origin main |
| 130 | tip="$(git rev-parse main)" |
| 131 | |
| 132 | # Server-side injection of an outcome record under a request name. |
| 133 | evidence() { |
| 134 | git -C "$origin" for-each-ref --format='%(refname) %(objectname)' refs/the-valley/attestations/ \ |
| 135 | | LC_ALL=C sort | sha256sum | cut -c1-16 |
| 136 | } |
| 137 | inject() { |
| 138 | local name="$1" line="$2" blob |
| 139 | blob="$(printf '%s\n' "$line" | git -C "$origin" hash-object -w --stdin)" |
| 140 | git -C "$origin" update-ref "refs/the-valley/integration-outcomes/main/$name" "$blob" |
| 141 | } |
| 142 | # u's request was judged failed, and no request is left: its landing is |
| 143 | # uncertain. |
| 144 | inject "c-$u" "$(git rev-parse u) $base $(evidence) failed 2026-10-18T00:00:00Z" |
| 145 | |
| 146 | # request <name> <head>: requester files an integration request. |
| 147 | request() { as requester git push --quiet origin "$2:refs/the-valley/integration-requests/main/$1"; } |
| 148 | |
| 149 | refs() { git -C "$origin" for-each-ref --format='%(refname) %(objectname)' | LC_ALL=C sort; } |
| 150 | plan() { |
| 151 | local before |
| 152 | before="$(refs)" |
| 153 | valley-restacker once --report-only --json --repo "$origin" --state "$w/state" \ |
| 154 | --principal restacker --instance "$smokePolicy/instance" "$@" > "$w/plan.json" 2> "$w/err" \ |
| 155 | || fail "the planner failed" |
| 156 | [ "$(refs)" = "$before" ] || fail 'a --report-only pass changed a ref on origin' |
| 157 | } |
| 158 | # family <id>: the family plan a change is a layer of. |
| 159 | family() { jq -c --arg id "$1" '.families[] | select(any(.layers[]; .id == $id))' "$w/plan.json"; } |
| 160 | action() { |
| 161 | local got |
| 162 | got="$(family "$1" | jq -r .action)" |
| 163 | [ "$got" = "$2" ] || fail "the family of $1 is $got, not $2: $(family "$1")" |
| 164 | } |
| 165 | says() { family "$1" | jq -e --arg s "$2" 'any(.reasons[], .notes[]; contains($s))' > /dev/null \ |
| 166 | || fail "the family of $1 does not say: $2: $(family "$1")"; } |
| 167 | |
| 168 | # ---------------------------------------------------------------------- |
| 169 | # Selection and families. |
| 170 | plan |
| 171 | jq -e --arg t "$tip" '.tip == $t and .maxAutomaticVersions == 2' "$w/plan.json" > /dev/null \ |
| 172 | || fail "the plan does not read main's tip or the project's cap" |
| 173 | action "$a" restack |
| 174 | action "$b1" restack |
| 175 | [ "$(family "$b1" | jq -c '[.layers[].id]')" = "[\"$b1\",\"$b2\"]" ] || fail 'b1 and b2 are not one family' |
| 176 | [ "$(family "$c1" | jq '.layers | length')" = 3 ] || fail 'c1, c2 and c3 are not one family' |
| 177 | [ "$(family "$c2" | jq -r '.layers[0].id')" = "$c1" ] || fail 'the shared lower layer is not the bottom' |
| 178 | action "$c3" restack |
| 179 | action "$d" leave |
| 180 | action "$wd" leave |
| 181 | action "$u" leave |
| 182 | action "$e" hold |
| 183 | says "$e" 'e-plain is a plain branch' |
| 184 | action "$g2" hold |
| 185 | says "$g2" 'is a draft' |
| 186 | [ -z "$(family "$s")" ] || fail 'a submitted change was planned' |
| 187 | jq -e '[.families[].layers[] | select(.name == "plain")] | length == 0' "$w/plan.json" > /dev/null \ |
| 188 | || fail 'a lone plain branch was planned' |
| 189 | |
| 190 | # Capacity: k has two versions uploaded by the restacker principal, and a |
| 191 | # third is over the project's cap of 2. |
| 192 | action "$k" hold |
| 193 | says "$k" 'over the cap of 2' |
| 194 | family "$k" | jq -e '.layers[0].capacity.uploads == 3' > /dev/null || fail 'k does not count three uploads' |
| 195 | |
| 196 | # ---------------------------------------------------------------------- |
| 197 | # Request holds. A request by name with no outcome holds. |
| 198 | request a a |
| 199 | plan |
| 200 | action "$a" hold |
| 201 | says "$a" 'no outcome yet' |
| 202 | family "$a" | jq -e '.requests[0].by == ["name", "head"]' > /dev/null || fail 'request a was not related by name' |
| 203 | # A current stale releases. |
| 204 | inject a "$(git rev-parse a) $tip $(evidence) stale" |
| 205 | plan |
| 206 | action "$a" restack |
| 207 | # A mismatched head, tip or fingerprint holds. |
| 208 | inject a "$base $tip $(evidence) stale" |
| 209 | plan |
| 210 | action "$a" hold |
| 211 | says "$a" 'is about head' |
| 212 | inject a "$(git rev-parse a) $base $(evidence) stale" |
| 213 | plan |
| 214 | says "$a" 'judged on main at' |
| 215 | inject a "$(git rev-parse a) $tip 0000000000000000 stale" |
| 216 | plan |
| 217 | says "$a" 'judged on evidence' |
| 218 | # A malformed outcome holds. |
| 219 | inject a "not an outcome" |
| 220 | plan |
| 221 | says "$a" 'does not read' |
| 222 | # A current reject releases, with a note. |
| 223 | inject a "$(git rev-parse a) $tip $(evidence) reject" |
| 224 | plan |
| 225 | action "$a" restack |
| 226 | says "$a" 'was rejected' |
| 227 | |
| 228 | # By an exact head, under a name nothing else relates. |
| 229 | request zz-head "$(git rev-parse b2)" |
| 230 | # By range: a commit on c2 no branch holds, so only the request names it |
| 231 | # and the planner has to fetch it before reading its ancestry. |
| 232 | git checkout --quiet -B scratch c2 |
| 233 | echo over > over |
| 234 | git add over |
| 235 | git commit --quiet -m over |
| 236 | request zz-range "$(git rev-parse HEAD)" |
| 237 | git checkout --quiet main |
| 238 | git branch --quiet -D scratch |
| 239 | plan |
| 240 | action "$b1" hold |
| 241 | family "$b1" | jq -e '.requests[] | select(.name == "zz-head") | .by == ["head"]' > /dev/null \ |
| 242 | || fail 'zz-head was not related by head' |
| 243 | action "$c1" hold |
| 244 | family "$c1" | jq -e '.requests[] | select(.name == "zz-range") | .by == ["range"]' > /dev/null \ |
| 245 | || fail 'zz-range was not related by range' |
| 246 | action "$c3" hold |
| 247 | |
| 248 | # A request whose head is no commit cannot be related or not, so every |
| 249 | # family it might be about holds. Injected on the server side, since the |
| 250 | # hook takes no such request. |
| 251 | git -C "$origin" update-ref refs/the-valley/integration-requests/main/zz-blob \ |
| 252 | "$(echo blob | git -C "$origin" hash-object -w --stdin)" |
| 253 | plan |
| 254 | action "$a" hold |
| 255 | says "$a" 'cannot be determined' |
| 256 | |
| 257 | # The human summary reads the same plan. |
| 258 | valley-restacker once --report-only --repo "$origin" --state "$w/state" --principal restacker \ |
| 259 | --instance "$smokePolicy/instance" > "$w/out" 2> "$w/err" || fail 'the summary failed' |
| 260 | grep -qE '^[k-z]+: hold$' "$w/out" || fail 'the summary holds no family' |
| 261 | # And without --report-only, nothing runs. |
| 262 | if valley-restacker once --repo "$origin" --state "$w/state" --principal restacker \ |
| 263 | --instance "$smokePolicy/instance" > "$w/out" 2> "$w/err"; then |
| 264 | fail 'once ran without --report-only' |
| 265 | fi |
| 266 | |
| 267 | # ---------------------------------------------------------------------- |
| 268 | # A cap larger than any int. The schema admits it, so it composes, and the |
| 269 | # planner counts it as the largest int: no practical cap. k, held above by |
| 270 | # the cap of 2, is not held by this one. The request whose head is no |
| 271 | # commit would hold k too, so it is removed first, on the server side |
| 272 | # where it was injected. |
| 273 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/zz-blob |
| 274 | git checkout --quiet main |
| 275 | printf 'package verification\n\nproject: restack: maxAutomaticVersions: 9223372036854775808\n' \ |
| 276 | > policy/project/policy.cue |
| 277 | git commit --quiet -am 'a cap larger than any int' |
| 278 | env -u VALLEY_PRINCIPAL git push --quiet origin main |
| 279 | plan |
| 280 | grep -q '"maxAutomaticVersions": 9223372036854775807,' "$w/plan.json" \ |
| 281 | || fail "the plan does not count the cap as the largest int: $(cat "$w/plan.json")" |
| 282 | action "$k" restack |
| 283 | |
| 284 | |
| 285 | # ====================================================================== |
| 286 | # The fixtures the publishing slice's tests stand on, each proved here. |
| 287 | |
| 288 | # One verifier file, which the rendered hook checks pushed evidence |
| 289 | # against, and the integrator and the restacker read too. |
| 290 | signers="$keys/known_signers" |
| 291 | grep -qF -- "--known-signers $signers" "$hook" || fail 'the rendered hook does not read the shared verifier keys' |
| 292 | # ssh-keygen signs only with a key nobody else can read. |
| 293 | mkdir -p "$w/keys" |
| 294 | for who in contributor integrator; do install -m 600 "$keys/$who" "$w/keys/$who"; done |
| 295 | contributor=contributor.valley.invalid/attestations |
| 296 | integrator_name=integrator.valley.invalid/attestations |
| 297 | |
| 298 | # The transport (restack/e2e/transport): git reaches origin through it as |
| 299 | # ssh, as the principal the URL names, and the real receive-pack runs the |
| 300 | # rendered hook. A barrier is armed by writing it to $VALLEY_BARRIER/hold. |
| 301 | export GIT_SSH_COMMAND=valley-restack-transport GIT_SSH_VARIANT=simple |
| 302 | export VALLEY_BARRIER="$w/barrier" |
| 303 | mkdir -p "$VALLEY_BARRIER" |
| 304 | url() { printf 'ssh://%s@valley%s' "$1" "$2"; } |
| 305 | disarm() { rm -f "${VALLEY_BARRIER:?}"/*; } |
| 306 | arm() { |
| 307 | disarm |
| 308 | echo "$*" > "$VALLEY_BARRIER/hold" |
| 309 | } |
| 310 | arrived() { |
| 311 | local i=0 |
| 312 | until [ -e "$VALLEY_BARRIER/arrived" ]; do |
| 313 | i=$((i + 1)) |
| 314 | [ "$i" -lt 1200 ] || fail 'nothing reached the barrier' |
| 315 | sleep 0.05 |
| 316 | done |
| 317 | } |
| 318 | release() { touch "$VALLEY_BARRIER/release"; } |
| 319 | at() { git -C "$1" rev-parse --verify --quiet "$2" || true; } |
| 320 | |
| 321 | # ---------------------------------------------------------------------- |
| 322 | # The restacker principal holds restack and not request, so it cannot file |
| 323 | # a request, which requester can. |
| 324 | cd "$repo" |
| 325 | git checkout --quiet -B fixture main |
| 326 | if git push --quiet "$(url restacker "$origin")" fixture:refs/the-valley/integration-requests/main/zz-by-restacker \ |
| 327 | 2> "$w/err"; then |
| 328 | fail 'the restacker principal filed a request' |
| 329 | fi |
| 330 | git push --quiet "$(url requester "$origin")" fixture:refs/the-valley/integration-requests/main/zz-by-requester \ |
| 331 | 2> "$w/err" || fail 'requester could not file a request through the transport' |
| 332 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/zz-by-requester |
| 333 | |
| 334 | # A barrier holds a push before origin sees it, and releases it. |
| 335 | echo held > held |
| 336 | git add held |
| 337 | git commit --quiet -m held |
| 338 | arm receive connect |
| 339 | git push --quiet "$(url alice "$origin")" fixture:refs/heads/held 2> "$w/err" & |
| 340 | pid=$! |
| 341 | arrived |
| 342 | [ -z "$(at "$origin" refs/heads/held)" ] || fail 'a push the barrier held reached origin' |
| 343 | kill -0 "$pid" 2> /dev/null || fail 'a push the barrier held ended' |
| 344 | release |
| 345 | wait "$pid" || fail 'a released push failed' |
| 346 | [ "$(at "$origin" refs/heads/held)" = "$(git rev-parse fixture)" ] || fail 'a released push did not reach origin' |
| 347 | |
| 348 | # A push held there loses its lease to one made while it waits. |
| 349 | was="$(git rev-parse fixture)" |
| 350 | git commit --quiet --allow-empty -m mine |
| 351 | arm receive connect |
| 352 | git push --quiet --force-with-lease="refs/heads/held:$was" "$(url restacker "$origin")" fixture:refs/heads/held \ |
| 353 | 2> "$w/err" & |
| 354 | pid=$! |
| 355 | arrived |
| 356 | git checkout --quiet -B author "$was" |
| 357 | git commit --quiet --allow-empty -m "the author's" |
| 358 | as alice git push --quiet origin author:held |
| 359 | release |
| 360 | if wait "$pid"; then fail 'a push held across another kept its lease'; fi |
| 361 | grep -q 'stale info' "$w/err" || fail "the held push was not refused for its lease: $(cat "$w/err")" |
| 362 | [ "$(at "$origin" refs/heads/held)" = "$(git rev-parse author)" ] || fail "the author's push did not stand" |
| 363 | |
| 364 | # A barrier holds a push that origin has taken, before its client hears. |
| 365 | git checkout --quiet fixture |
| 366 | arm receive taken refs/heads/taken |
| 367 | git push --quiet "$(url alice "$origin")" fixture:refs/heads/taken 2> "$w/err" & |
| 368 | pid=$! |
| 369 | arrived |
| 370 | [ "$(at "$origin" refs/heads/taken)" = "$(git rev-parse fixture)" ] || fail 'origin had not taken the held push' |
| 371 | kill -0 "$pid" 2> /dev/null || fail 'the client heard before the release' |
| 372 | release |
| 373 | wait "$pid" || fail 'a push held after origin took it failed' |
| 374 | |
| 375 | # A dropped answer: origin takes the push, and its client reports that |
| 376 | # origin never said so. |
| 377 | arm receive drop refs/heads/dropped |
| 378 | if git push --porcelain "$(url alice "$origin")" fixture:refs/heads/dropped > "$w/out" 2> "$w/err"; then |
| 379 | fail 'a push whose answer was lost succeeded' |
| 380 | fi |
| 381 | cat "$w/out" "$w/err" | grep -q 'remote failed to report status' || fail 'the client did not lose the answer' |
| 382 | [ "$(at "$origin" refs/heads/dropped)" = "$(git rev-parse fixture)" ] || fail 'origin did not take the push whose answer was lost' |
| 383 | disarm |
| 384 | |
| 385 | # ---------------------------------------------------------------------- |
| 386 | # A repository served with the integrator's evidence fixtures: the nix |
| 387 | # stand-in (integrator/e2e), and a policy whose checks are pure, under a |
| 388 | # floor that requires nothing. |
| 389 | cp -r "$integratorE2e" "$w/stand-ins" |
| 390 | chmod -R +w "$w/stand-ins" |
| 391 | patchShebangs "$w/stand-ins" > /dev/null |
| 392 | export PATH="$w/stand-ins:$PATH" VALLEY_FAKE_STORE="$w/store" |
| 393 | mkdir -p "$w/floor" |
| 394 | printf 'package verification\n\nfloor: {\n\tchecks: {}\n\tclasses: {}\n\tunclassified: {}\n}\n' > "$w/floor/floor.cue" |
| 395 | |
| 396 | served="$w/served.git" |
| 397 | git init --quiet --bare "$served" |
| 398 | cp "$hook" "$served/hooks/pre-receive" |
| 399 | chmod +x "$served/hooks/pre-receive" |
| 400 | git init --quiet "$w/fixture" |
| 401 | cd "$w/fixture" |
| 402 | git remote add origin "$served" |
| 403 | mkdir -p docs src checks policy/project |
| 404 | echo "the readme" > docs/readme.md |
| 405 | echo "the source" > src/main.txt |
| 406 | echo docs > checks/prose-format.inputs |
| 407 | echo src > checks/code-build.inputs |
| 408 | cat > policy/project/policy.cue << 'CUE' |
| 409 | package verification |
| 410 | |
| 411 | project: { |
| 412 | checks: { |
| 413 | "prose-format": {runner: "nix", attribute: "prose-format"} |
| 414 | "code-build": {runner: "nix", attribute: "code-build"} |
| 415 | } |
| 416 | classes: { |
| 417 | prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 418 | code: {paths: "src/**": true, requires: "code-build": true} |
| 419 | } |
| 420 | unclassified: {} |
| 421 | } |
| 422 | CUE |
| 423 | git add -A |
| 424 | git commit --quiet -m 'seed the project' |
| 425 | env -u VALLEY_PRINCIPAL git push --quiet origin main |
| 426 | |
| 427 | # attested <branch> <attest run flags…>: alice's change, its evidence signed |
| 428 | # by the contributor's key and pushed with it through the hook, readied; |
| 429 | # prints the change ID. |
| 430 | attested() { |
| 431 | local branch="$1" |
| 432 | shift |
| 433 | as alice attest run --repo . --key "$w/keys/contributor" --name "$contributor" \ |
| 434 | --push origin --branch "$branch" "$@" > "$w/out" 2> "$w/err" || fail "attest run on $branch failed" |
| 435 | ok as alice valley ready |
| 436 | sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$w/out" |
| 437 | } |
| 438 | git checkout --quiet -b lands main |
| 439 | echo "a second source line" >> src/main.txt |
| 440 | git commit --quiet -am 'a change the integrator lands' |
| 441 | lands="$(attested lands --check code-build)" |
| 442 | # Its evidence claims an effectful check where the policy runs a pure one. |
| 443 | git checkout --quiet -b lies main |
| 444 | echo "a readme whose evidence lies" > docs/readme.md |
| 445 | git commit --quiet -am 'a change whose evidence lies about its kind' |
| 446 | lies="$(attested lies --command prose-format=true)" |
| 447 | git checkout --quiet main |
| 448 | echo moved > moved.txt |
| 449 | git add moved.txt |
| 450 | git commit --quiet -m 'main moves on' |
| 451 | env -u VALLEY_PRINCIPAL git push --quiet origin main |
| 452 | |
| 453 | integrate() { |
| 454 | integrator reconcile --repo "$served" --key "$w/keys/integrator" --name "$integrator_name" \ |
| 455 | --known-signers "$signers" --instance "$w/floor" --schema "$SCHEMA_VERIFICATION" \ |
| 456 | --attest-schema "$SCHEMA_ATTESTATION" --event-schema "$SCHEMA_EVENTS" > "$w/integrator.out" 2>&1 \ |
| 457 | || fail "the integrator failed: $(cat "$w/integrator.out")" |
| 458 | } |
| 459 | judged() { |
| 460 | grep -q "^c-$1 -> refs/heads/main .*: $2\$" "$w/integrator.out" \ |
| 461 | || fail "the integrator did not $2 c-$1: $(cat "$w/integrator.out")" |
| 462 | } |
| 463 | # requester files each request through the transport, one pass each, so |
| 464 | # the reject is judged on the tip the landing left. |
| 465 | git push --quiet "$(url requester "$served")" "lands:refs/the-valley/integration-requests/main/c-$lands" |
| 466 | integrate |
| 467 | judged "$lands" land |
| 468 | git push --quiet "$(url requester "$served")" "lies:refs/the-valley/integration-requests/main/c-$lies" |
| 469 | integrate |
| 470 | judged "$lies" reject |
| 471 | grep -q 'requires a pure check and the attestation claims an effectful check' "$w/integrator.out" \ |
| 472 | || fail "the reject is not for the evidence's kind: $(cat "$w/integrator.out")" |
| 473 | |
| 474 | # The planner, reading the shared verifier keys, sees the landed change |
| 475 | # submitted: it is no layer. Without the keys, the same landing is only |
| 476 | # uncertain. The rejected change's family is released by the real |
| 477 | # outcome, current at its head, tip and evidence, and the reject is noted. |
| 478 | served_plan() { |
| 479 | valley-restacker once --report-only --json --repo "$(url restacker "$served")" --state "$w/served-state" \ |
| 480 | --principal restacker --instance "$w/floor" "$@" > "$w/plan.json" 2> "$w/err" || fail 'the planner failed' |
| 481 | } |
| 482 | served_plan --known-signers "$signers" --integrator-name "$integrator_name" |
| 483 | [ -z "$(family "$lands")" ] || fail "the change the integrator landed was planned: $(family "$lands")" |
| 484 | action "$lies" restack |
| 485 | says "$lies" 'was rejected' |
| 486 | family "$lies" | jq -e --arg n "c-$lies" '.requests[] | select(.name == $n) | .decision == "reject" and .current' \ |
| 487 | > /dev/null || fail "the reject was not read as current: $(family "$lies")" |
| 488 | served_plan |
| 489 | action "$lands" leave |
| 490 | family "$lands" | jq -e '.layers[0].state == "uncertain"' > /dev/null \ |
| 491 | || fail "without the keys, the landing is not uncertain: $(family "$lands")" |
| 492 | |
| 493 | # ---------------------------------------------------------------------- |
| 494 | # A pass locks its state directory: a second pass fails while a barrier |
| 495 | # holds the first one's read of origin, and the first goes on once |
| 496 | # released. The directory belongs to the restacker principal, so a pass |
| 497 | # for another is refused it. |
| 498 | pass() { |
| 499 | valley-restacker once --report-only --repo "$(url restacker "$served")" --state "$w/served-state" \ |
| 500 | --principal restacker --instance "$w/floor" "$@" |
| 501 | } |
| 502 | arm upload connect |
| 503 | pass > "$w/first.out" 2> "$w/first.err" & |
| 504 | pid=$! |
| 505 | arrived |
| 506 | if pass > "$w/out" 2> "$w/err"; then fail 'a second pass ran while the first held the state'; fi |
| 507 | grep -q 'another pass is using the state directory' "$w/err" || fail "the second pass did not say why: $(cat "$w/err")" |
| 508 | release |
| 509 | wait "$pid" || fail "the first pass failed once released: $(cat "$w/first.err")" |
| 510 | if valley-restacker once --report-only --repo "$(url restacker "$served")" --state "$w/served-state" \ |
| 511 | --principal requester --instance "$w/floor" > "$w/out" 2> "$w/err"; then |
| 512 | fail 'a pass for another principal used the state directory' |
| 513 | fi |
| 514 | grep -q 'give each its own --state' "$w/err" || fail "the refusal does not say why: $(cat "$w/err")" |
| 515 | |
| 516 | # A pass whose read of origin never returns ends at its --timeout. |
| 517 | arm upload connect |
| 518 | if pass --timeout 2s > "$w/out" 2> "$w/err"; then fail 'a pass held at the barrier finished'; fi |
| 519 | grep -q 'ran past its --timeout of 2s' "$w/err" || fail "the pass did not end at its timeout: $(cat "$w/err")" |
| 520 | disarm |
| 521 | |
| 522 | touch "$out" |