| 1 | # shellcheck shell=bash |
| 2 | # Paths and fixtures come from the derivation environment. |
| 3 | # shellcheck disable=SC2154 |
| 4 | export HOME="$TMPDIR" |
| 5 | export XDG_STATE_HOME="$TMPDIR/state" |
| 6 | export GIT_CONFIG_NOSYSTEM=1 |
| 7 | # What this check writes down, kept out of the repository under test: an |
| 8 | # answer file or a captured stream sitting in the working tree would be |
| 9 | # committed by the next `git add -A` and change the tree being attested. |
| 10 | w="$TMPDIR/scratch" |
| 11 | mkdir -p "$w" |
| 12 | git config --global user.name valley-check |
| 13 | git config --global user.email valley-check@localhost |
| 14 | git config --global init.defaultBranch main |
| 15 | git config --global advice.detachedHead false |
| 16 | |
| 17 | # The operator's signing key. Provisioning one is deployment, so the verb |
| 18 | # takes it as a parameter and this check supplies a throwaway. |
| 19 | ssh-keygen -q -t ed25519 -N "" -C valley-check -f "$TMPDIR/host" |
| 20 | export VALLEY_ATTEST_KEY="$TMPDIR/host" |
| 21 | export VALLEY_ATTEST_NAME=laddie.valley.invalid/attestations |
| 22 | keyhash="$(attest key --key "$TMPDIR/host" --name "$VALLEY_ATTEST_NAME" | cut -d+ -f2)" |
| 23 | |
| 24 | origin="$TMPDIR/project.git" |
| 25 | git init --quiet --bare "$origin" |
| 26 | |
| 27 | # Every push the bare repo receives, as its hook sees it. The claim [a]sk |
| 28 | # makes is that ONE push carries the evidence and the request together, and |
| 29 | # that claim is only observable from the receiving side. |
| 30 | pushlog="$TMPDIR/pushlog" |
| 31 | cat > "$origin/hooks/pre-receive" <<EOF |
| 32 | #!/bin/sh |
| 33 | echo '--- push' >> $pushlog |
| 34 | cat >> $pushlog |
| 35 | EOF |
| 36 | chmod +x "$origin/hooks/pre-receive" |
| 37 | |
| 38 | # Interpose on origin's receive-pack so that the request namespace moves |
| 39 | # between [a]sk's read of it and the push it then makes. That window is |
| 40 | # where every race below lives, and a hook cannot reach it: by the time |
| 41 | # pre-receive runs the client has already been told what the refs were. |
| 42 | # One shot, so only the push under test is raced. |
| 43 | arm_race() { |
| 44 | cat > "$TMPDIR/racing-receive-pack" <<EOF |
| 45 | #!/bin/sh |
| 46 | if [ -e "$TMPDIR/race-armed" ]; then |
| 47 | rm -f "$TMPDIR/race-armed" |
| 48 | $1 |
| 49 | fi |
| 50 | exec git-receive-pack "\$@" |
| 51 | EOF |
| 52 | chmod +x "$TMPDIR/racing-receive-pack" |
| 53 | git config remote.origin.receivepack "$TMPDIR/racing-receive-pack" |
| 54 | touch "$TMPDIR/race-armed" |
| 55 | } |
| 56 | |
| 57 | # Put it away, and fail if it never fired: a race nothing raced is a |
| 58 | # scenario that proved nothing. |
| 59 | disarm_race() { |
| 60 | git config --unset remote.origin.receivepack |
| 61 | if [ -e "$TMPDIR/race-armed" ]; then |
| 62 | echo "valley-request: the racing receive-pack never ran, so nothing was raced" >&2 |
| 63 | exit 1 |
| 64 | fi |
| 65 | } |
| 66 | |
| 67 | # ---------------------------------------------------------------------- |
| 68 | # The owning valley's repository, carrying the floor at policy/instance. |
| 69 | # The floor is read from here and never from the project, which is the |
| 70 | # tree under judgment: what governs a change has to come from outside it. |
| 71 | # Fetching is all the deriver does to this repository, which is what |
| 72 | # anyone the valley governs necessarily holds. |
| 73 | valley="$TMPDIR/valley.git" |
| 74 | git init --quiet --bare "$valley" |
| 75 | valleywork="$TMPDIR/valley-work" |
| 76 | git init --quiet "$valleywork" |
| 77 | mkdir -p "$valleywork/policy/instance" |
| 78 | cat > "$valleywork/policy/instance/floor.cue" <<'EOF' |
| 79 | package verification |
| 80 | |
| 81 | floor: { |
| 82 | checks: "tree-ok": { |
| 83 | runner: "command" |
| 84 | command: "test -f docs/readme.md" |
| 85 | } |
| 86 | classes: prose: { |
| 87 | paths: "docs/**": true |
| 88 | requires: "tree-ok": true |
| 89 | } |
| 90 | // A class that covers paths and asks nothing of them. Owing no check |
| 91 | // is an ordinary outcome, not a hole: the policy has read these paths |
| 92 | // and has nothing to require of them. |
| 93 | classes: quiet: { |
| 94 | paths: "quiet/**": true |
| 95 | requires: {} |
| 96 | } |
| 97 | unclassified: "tree-ok": true |
| 98 | } |
| 99 | EOF |
| 100 | git -C "$valleywork" add -A |
| 101 | git -C "$valleywork" commit --quiet -m floor |
| 102 | git -C "$valleywork" push --quiet "$valley" main |
| 103 | |
| 104 | # ---------------------------------------------------------------------- |
| 105 | # The project, laid out the way the deriver reads one without being told: |
| 106 | # its own layer at policy/project, and its owning valley named at |
| 107 | # policy/valley. Both checks use the command runner: the nix runner cannot |
| 108 | # be exercised from inside a nix build, since the sandbox has no daemon to |
| 109 | # call, and what is under test here is the sequencing rather than the |
| 110 | # runner. |
| 111 | # |
| 112 | # examples/policy/ holds a second, contradictory pair of layers, and every |
| 113 | # check they require is named `phantom`. Nothing may derive it: a gate that |
| 114 | # came from a worked example is a gate nobody wrote, and the name is here |
| 115 | # so that the failure would be visible rather than plausible. |
| 116 | repo="$TMPDIR/project" |
| 117 | git init --quiet "$repo" |
| 118 | cd "$repo" || exit 1 |
| 119 | git remote add origin "$origin" |
| 120 | |
| 121 | mkdir -p docs src schema policy/project examples/policy/instance examples/policy/project |
| 122 | cp "$schemaFile" schema/verification.cue |
| 123 | echo "the readme" > docs/readme.md |
| 124 | echo "$valley" > policy/valley |
| 125 | cat > policy/project/policy.cue <<'EOF' |
| 126 | package verification |
| 127 | |
| 128 | project: { |
| 129 | checks: "no-secrets": { |
| 130 | runner: "command" |
| 131 | command: "! grep -rqF SECRET src" |
| 132 | } |
| 133 | classes: source: { |
| 134 | paths: "src/**": true |
| 135 | requires: "no-secrets": true |
| 136 | } |
| 137 | } |
| 138 | EOF |
| 139 | cat > examples/policy/instance/floor.cue <<'EOF' |
| 140 | package verification |
| 141 | |
| 142 | floor: { |
| 143 | checks: phantom: { |
| 144 | runner: "command" |
| 145 | command: "false" |
| 146 | } |
| 147 | classes: everything: { |
| 148 | paths: "**": true |
| 149 | requires: phantom: true |
| 150 | } |
| 151 | unclassified: phantom: true |
| 152 | } |
| 153 | EOF |
| 154 | cat > examples/policy/project/policy.cue <<'EOF' |
| 155 | package verification |
| 156 | |
| 157 | project: {} |
| 158 | EOF |
| 159 | git add -A |
| 160 | git commit --quiet -m base |
| 161 | git push --quiet -u origin main |
| 162 | first="$(git rev-parse main)" |
| 163 | |
| 164 | # ---------------------------------------------------------------------- |
| 165 | # 1. A branch whose required check passes: the evidence and the request |
| 166 | # reach origin in one push, and main does not move. |
| 167 | git checkout --quiet -b topic/one |
| 168 | echo "a better readme" > docs/readme.md |
| 169 | git commit --quiet -am "improve the readme" |
| 170 | git push --quiet origin topic/one |
| 171 | digest="$(attest digest --rev topic/one | cut -d: -f2)" |
| 172 | |
| 173 | : > "$pushlog" |
| 174 | printf 'a\n' > "$w/answers" |
| 175 | valley review topic/one < "$w/answers" > "$w/ask.out" 2> "$w/ask.err" |
| 176 | |
| 177 | grep -q '^checking topic/one at .*: tree-ok$' "$w/ask.out" |
| 178 | grep -qE '^check tree-ok +command passed$' "$w/ask.out" |
| 179 | grep -qx "Submitted topic/one ($(git rev-parse --short topic/one)) for integration into origin/main." "$w/ask.out" |
| 180 | grep -qx " request refs/the-valley/integration-requests/main/topic-one -> $(git rev-parse --short topic/one)" "$w/ask.out" |
| 181 | grep -qx " evidence refs/the-valley/attestations/$digest/$keyhash" "$w/ask.out" |
| 182 | grep -qx ' checks tree-ok' "$w/ask.out" |
| 183 | grep -qx 'Your local checkout has not changed.' "$w/ask.out" |
| 184 | grep -qx 'Check the result: valley status topic/one' "$w/ask.out" |
| 185 | |
| 186 | # What origin holds now. The attestation is keyed by the digest of the |
| 187 | # BRANCH's tree, which is what says the checks ran over the right tree and |
| 188 | # not over the operator's working copy. |
| 189 | git -C "$origin" for-each-ref --format='%(refname)' refs/the-valley > "$w/published.txt" |
| 190 | grep -qx "refs/the-valley/integration-requests/main/topic-one" "$w/published.txt" |
| 191 | grep -qx "refs/the-valley/attestations/$digest/$keyhash" "$w/published.txt" |
| 192 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-one)" \ |
| 193 | != "$(git rev-parse topic/one)" ]; then |
| 194 | echo "valley-request: the request ref does not name the branch's head" >&2 |
| 195 | exit 1 |
| 196 | fi |
| 197 | if [ "$(git -C "$origin" rev-parse refs/heads/main)" != "$first" ]; then |
| 198 | echo "valley-request: [a]sk moved main" >&2 |
| 199 | exit 1 |
| 200 | fi |
| 201 | |
| 202 | # One push carried both. This is the friction the verb exists to remove: |
| 203 | # `attest run --push` publishes the branch and the evidence and knows |
| 204 | # nothing about a request ref, so doing this by hand is two beats. |
| 205 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 206 | if [ "$pushes" != 1 ]; then |
| 207 | echo "valley-request: the evidence and the request took $pushes pushes, not 1" >&2 |
| 208 | cat "$pushlog" >&2 |
| 209 | exit 1 |
| 210 | fi |
| 211 | grep -q "refs/the-valley/attestations/$digest/$keyhash" "$pushlog" |
| 212 | grep -q 'refs/the-valley/integration-requests/main/topic-one' "$pushlog" |
| 213 | |
| 214 | # The note origin holds is the one the operator signed, over that tree. |
| 215 | git cat-file -p "refs/the-valley/attestations/$digest/$keyhash:tree-ok/statement.note" \ |
| 216 | > "$w/statement.note" |
| 217 | attest key --key "$TMPDIR/host" --name "$VALLEY_ATTEST_NAME" > "$w/known_keys" |
| 218 | attest verify --note "$w/statement.note" --repo "$repo" --rev topic/one \ |
| 219 | --known-keys "$w/known_keys" --signer "$VALLEY_ATTEST_NAME" > "$w/verify.out" |
| 220 | grep -q 'matches the recorded subject digest' "$w/verify.out" |
| 221 | |
| 222 | # ---------------------------------------------------------------------- |
| 223 | # 2. The layers the derivation used are the ones that govern, and it says |
| 224 | # which they were: the floor fetched from the owning valley, and the |
| 225 | # project's own layer at policy/project in the TARGET's tip. |
| 226 | # examples/policy/ is in this tree and requires `phantom` of every path, |
| 227 | # and no default reaches it — it is derivable only by naming it, which |
| 228 | # is what the options are for. |
| 229 | valley checks "$first" topic/one > "$w/checks.out" 2> "$w/checks.err" |
| 230 | grep -qx "policy: $valley policy/instance@refs/heads/main + policy/project@origin/main $(git rev-parse --short origin/main)" "$w/checks.out" |
| 231 | grep -qx 'classes matched: prose' "$w/checks.out" |
| 232 | grep -qE '^ tree-ok +mandatory +prose$' "$w/checks.out" |
| 233 | if grep -q phantom "$w/checks.out" "$w/checks.err"; then |
| 234 | echo "valley-request: a default derived a check from examples/policy/" >&2 |
| 235 | cat "$w/checks.out" "$w/checks.err" >&2 |
| 236 | exit 1 |
| 237 | fi |
| 238 | |
| 239 | # Named, the example layers derive exactly what they declare. This is the |
| 240 | # other half of the claim above: examples/policy/ is readable, and reading |
| 241 | # it is something a person asks for. |
| 242 | valley checks --instance examples/policy/instance --project examples/policy/project \ |
| 243 | "$first" topic/one > "$w/example.out" |
| 244 | grep -qE '^ phantom +mandatory' "$w/example.out" |
| 245 | grep -qx 'policy: examples/policy/instance + examples/policy/project' "$w/example.out" |
| 246 | |
| 247 | # ---------------------------------------------------------------------- |
| 248 | # 3. main moves on, so the next branch is stale. [a]sk is offered there |
| 249 | # too — the integrator applies a delta to the tip rather than |
| 250 | # fast-forwarding — and a branch whose check fails publishes nothing |
| 251 | # and leaves the review loop usable. |
| 252 | git checkout --quiet main |
| 253 | echo "a note" > docs/notes.md |
| 254 | git add -A |
| 255 | git commit --quiet -m "a landing that moves main" |
| 256 | git push --quiet origin main |
| 257 | |
| 258 | git checkout --quiet -b topic/two "$first" |
| 259 | printf 'SECRET\n' > src/leak.txt |
| 260 | git add -A |
| 261 | git commit --quiet -m "a leak" |
| 262 | git push --quiet origin topic/two |
| 263 | |
| 264 | : > "$pushlog" |
| 265 | printf 'a\ns\n' > "$w/answers" |
| 266 | valley review topic/two < "$w/answers" > "$w/fail.out" 2> "$w/fail.err" |
| 267 | |
| 268 | # The prompt is the whole of what the operator is offered, so it is pinned |
| 269 | # character for character: a verb that stops being offered, or one that |
| 270 | # starts, is a change to the review loop and not an incidental one. |
| 271 | grep -qF 'topic/two does not fast-forward from main: [a]sk, [b]ase onto main, [r]eject, [s]kip? ' "$w/fail.out" |
| 272 | grep -q '^checking topic/two at .*: no-secrets$' "$w/fail.out" |
| 273 | grep -qE '^check no-secrets +command failed$' "$w/fail.out" |
| 274 | grep -q 'the checks did not pass; nothing published, main untouched' "$w/fail.err" |
| 275 | # The prompt is printed without a newline, so what follows a refusal shares |
| 276 | # its line — the answer to it is not anchored. |
| 277 | grep -q 'skipped topic/two; nothing done' "$w/fail.out" |
| 278 | if [ -s "$pushlog" ]; then |
| 279 | echo "valley-request: a failing check pushed something" >&2 |
| 280 | cat "$pushlog" >&2 |
| 281 | exit 1 |
| 282 | fi |
| 283 | git -C "$origin" for-each-ref --format='%(refname)' refs/the-valley > "$w/after.txt" |
| 284 | if grep -q 'topic-two' "$w/after.txt"; then |
| 285 | echo "valley-request: a failing check left a ref on origin" >&2 |
| 286 | cat "$w/after.txt" >&2 |
| 287 | exit 1 |
| 288 | fi |
| 289 | |
| 290 | # ---------------------------------------------------------------------- |
| 291 | # 4. No signing key, with a check owed: refused before any check is run, |
| 292 | # and the prompt still comes back. The host signs, and there is no |
| 293 | # unsigned mode. |
| 294 | : > "$pushlog" |
| 295 | printf 'a\ns\n' > "$w/answers" |
| 296 | env -u VALLEY_ATTEST_KEY valley review topic/two < "$w/answers" > "$w/nokey.out" 2> "$w/nokey.err" |
| 297 | grep -q 'no signing key: set VALLEY_ATTEST_KEY' "$w/nokey.err" |
| 298 | grep -q 'skipped topic/two; nothing done' "$w/nokey.out" |
| 299 | if [ -s "$pushlog" ]; then |
| 300 | echo "valley-request: a run with no signing key pushed something" >&2 |
| 301 | exit 1 |
| 302 | fi |
| 303 | |
| 304 | # ---------------------------------------------------------------------- |
| 305 | # 5. A branch the policy requires no check of is filed as a request with |
| 306 | # no evidence. The integrator lands one and records it as a landing |
| 307 | # that required nothing, so refusing to file it here would strand |
| 308 | # exactly the changes a policy leaves unrequired. Nothing is owed, so |
| 309 | # nothing is signed: this runs with no signing key at all. |
| 310 | git checkout --quiet main |
| 311 | git checkout --quiet -b topic/quiet |
| 312 | mkdir -p quiet |
| 313 | echo "a quiet note" > quiet/note.md |
| 314 | git add -A |
| 315 | git commit --quiet -m "a change under a class that asks nothing" |
| 316 | git push --quiet origin topic/quiet |
| 317 | quiethead="$(git rev-parse --short topic/quiet)" |
| 318 | |
| 319 | : > "$pushlog" |
| 320 | printf 'a\n' > "$w/answers" |
| 321 | env -u VALLEY_ATTEST_KEY valley review topic/quiet < "$w/answers" \ |
| 322 | > "$w/quiet.out" 2> "$w/quiet.err" |
| 323 | |
| 324 | grep -q 'owes no check under .* + policy/project@origin/main .*; filing the request with no evidence' "$w/quiet.out" |
| 325 | grep -qF "$valley policy/instance@refs/heads/main" "$w/quiet.out" |
| 326 | grep -q '^Submitted topic/quiet .* for integration into origin/main\.$' "$w/quiet.out" |
| 327 | grep -qx " request refs/the-valley/integration-requests/main/topic-quiet -> $quiethead" "$w/quiet.out" |
| 328 | grep -qx ' evidence none — nothing was owed, so nothing was signed' "$w/quiet.out" |
| 329 | grep -qx ' checks none — the policy requires no check of this change' "$w/quiet.out" |
| 330 | |
| 331 | # One push, carrying the request and nothing else. |
| 332 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 333 | if [ "$pushes" != 1 ]; then |
| 334 | echo "valley-request: the bare request took $pushes pushes, not 1" >&2 |
| 335 | cat "$pushlog" >&2 |
| 336 | exit 1 |
| 337 | fi |
| 338 | if grep -q 'refs/the-valley/attestations/' "$pushlog"; then |
| 339 | echo "valley-request: a request owing nothing published evidence" >&2 |
| 340 | cat "$pushlog" >&2 |
| 341 | exit 1 |
| 342 | fi |
| 343 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-quiet)" \ |
| 344 | != "$(git rev-parse topic/quiet)" ]; then |
| 345 | echo "valley-request: the bare request does not name the branch's head" >&2 |
| 346 | exit 1 |
| 347 | fi |
| 348 | |
| 349 | # ---------------------------------------------------------------------- |
| 350 | # 6. [b]ase, and the prompt it comes back to. A stale branch is rebased |
| 351 | # onto main in a throwaway worktree and re-reviewed, and the prompt the |
| 352 | # loop then prints is the fast-forward one — the path a reader of |
| 353 | # bin/valley has to trace two loops to reach, so it is exercised here |
| 354 | # rather than argued about. |
| 355 | git checkout --quiet main |
| 356 | git checkout --quiet -b topic/three "$first" |
| 357 | echo "another readme" > docs/readme.md |
| 358 | git commit --quiet -am "another readme" |
| 359 | git push --quiet origin topic/three |
| 360 | before_base="$(git -C "$origin" rev-parse refs/heads/main)" |
| 361 | |
| 362 | printf 'b\ns\n' > "$w/answers" |
| 363 | valley review topic/three < "$w/answers" > "$w/base.out" 2>&1 |
| 364 | grep -qF 'topic/three does not fast-forward from main: [a]sk, [b]ase onto main, [r]eject, [s]kip? ' "$w/base.out" |
| 365 | grep -qF 'rebased topic/three onto origin/main, pushed with --force-with-lease' "$w/base.out" |
| 366 | # The post-[b]ase prompt: the branch fast-forwards now, so the loop falls |
| 367 | # through to the prompt that has no [b]ase in it. |
| 368 | grep -qF 'topic/three: [a]sk, [r]eject, [s]kip? ' "$w/base.out" |
| 369 | grep -q 'skipped topic/three; nothing done' "$w/base.out" |
| 370 | git merge-base --is-ancestor refs/remotes/origin/main refs/remotes/origin/topic/three \ |
| 371 | || { echo "valley-request: [b]ase left the branch stale" >&2; exit 1; } |
| 372 | if [ "$(git -C "$origin" rev-parse refs/heads/main)" != "$before_base" ]; then |
| 373 | echo "valley-request: the review loop moved main" >&2 |
| 374 | exit 1 |
| 375 | fi |
| 376 | git checkout --quiet main |
| 377 | |
| 378 | # The request filed in 1 is still pending: nothing here consumes it, which |
| 379 | # is the integrator's own step. |
| 380 | git -C "$origin" rev-parse --verify --quiet \ |
| 381 | refs/the-valley/integration-requests/main/topic-one > /dev/null |
| 382 | |
| 383 | # ---------------------------------------------------------------------- |
| 384 | # 7. A change does not supply the policy that gates it. This branch |
| 385 | # deletes its own policy/project and repoints policy/valley at a |
| 386 | # repository that does not exist. Both layers come from the target's |
| 387 | # tip, so neither edit reaches the derivation: it composes the same two |
| 388 | # layers it would for any other branch, and the fetch that a branch-read |
| 389 | # pointer would have attempted never happens. |
| 390 | git checkout --quiet -b topic/nolayer |
| 391 | git rm --quiet -r policy/project |
| 392 | echo "$TMPDIR/there-is-no-such-valley.git" > policy/valley |
| 393 | git add -A |
| 394 | git commit --quiet -m "delete the project layer and repoint the valley" |
| 395 | git push --quiet origin topic/nolayer |
| 396 | |
| 397 | valley checks "$first" topic/nolayer > "$w/nolayer.out" 2> "$w/nolayer.err" |
| 398 | grep -qx "policy: $valley policy/instance@refs/heads/main + policy/project@origin/main $(git rev-parse --short origin/main)" "$w/nolayer.out" |
| 399 | if grep -q 'there-is-no-such-valley' "$w/nolayer.out" "$w/nolayer.err"; then |
| 400 | echo "valley-request: the deriver followed the branch's own valley pointer" >&2 |
| 401 | cat "$w/nolayer.out" "$w/nolayer.err" >&2 |
| 402 | exit 1 |
| 403 | fi |
| 404 | |
| 405 | : > "$pushlog" |
| 406 | printf 'a\n' > "$w/answers" |
| 407 | valley review topic/nolayer < "$w/answers" \ |
| 408 | > "$w/nolayer.review.out" 2> "$w/nolayer.review.err" |
| 409 | grep -q '^Submitted topic/nolayer .* for integration into origin/main\.$' "$w/nolayer.review.out" |
| 410 | |
| 411 | # ---------------------------------------------------------------------- |
| 412 | # 8. The reviewer's checkout contributes nothing. This is the case that |
| 413 | # failed in live use: the operator's checkout was an older branch |
| 414 | # without the landed policy layer, and the deriver read the working |
| 415 | # tree and refused. topic/nolayer is exactly such a checkout — no |
| 416 | # policy/project in it, and a policy/valley naming nowhere — so every |
| 417 | # derivation below runs from it. |
| 418 | # |
| 419 | # Byte-identical output is the claim, not merely a successful one: |
| 420 | # review works the same from any branch, however stale. |
| 421 | git checkout --quiet main |
| 422 | valley checks "$first" topic/one > "$w/from-main.out" |
| 423 | git checkout --quiet topic/nolayer |
| 424 | valley checks "$first" topic/one > "$w/from-stale.out" |
| 425 | if ! cmp -s "$w/from-main.out" "$w/from-stale.out"; then |
| 426 | echo "valley-request: the checkout changed what the derivation said" >&2 |
| 427 | diff -u "$w/from-main.out" "$w/from-stale.out" >&2 || true |
| 428 | exit 1 |
| 429 | fi |
| 430 | |
| 431 | # And [a]sk, which is where it failed: a request filed from that same |
| 432 | # checkout, over a branch the stale tree knows nothing about. |
| 433 | git checkout --quiet -b topic/four origin/main |
| 434 | echo "one more readme" > docs/readme.md |
| 435 | git commit --quiet -am "one more readme" |
| 436 | git push --quiet origin topic/four |
| 437 | git checkout --quiet topic/nolayer |
| 438 | |
| 439 | : > "$pushlog" |
| 440 | printf 'a\n' > "$w/answers" |
| 441 | valley review topic/four < "$w/answers" > "$w/stale.out" 2> "$w/stale.err" |
| 442 | grep -q '^checking topic/four at .*: tree-ok$' "$w/stale.out" |
| 443 | grep -q '^Submitted topic/four .* for integration into origin/main\.$' "$w/stale.out" |
| 444 | grep -qx ' checks tree-ok' "$w/stale.out" |
| 445 | |
| 446 | # ---------------------------------------------------------------------- |
| 447 | # 9. A target carrying no project layer at all is derived under the floor |
| 448 | # alone, and says so. The project layer only ever adds, so the identity |
| 449 | # of "adds" is "adds nothing"; refusing instead would make a repository |
| 450 | # underivable until its first policy commit, and that commit could not |
| 451 | # derive either. This is the integrator's own reading of an absent |
| 452 | # layer (integrator/policy.go), and the two have to agree. |
| 453 | bare2="$TMPDIR/floorless.git" |
| 454 | git init --quiet --bare "$bare2" |
| 455 | repo2="$TMPDIR/floorless" |
| 456 | git init --quiet "$repo2" |
| 457 | cd "$repo2" || exit 1 |
| 458 | git remote add origin "$bare2" |
| 459 | mkdir -p docs schema policy |
| 460 | cp "$schemaFile" schema/verification.cue |
| 461 | echo "the readme" > docs/readme.md |
| 462 | echo "$valley" > policy/valley |
| 463 | git add -A |
| 464 | git commit --quiet -m base |
| 465 | git push --quiet -u origin main |
| 466 | base2="$(git rev-parse main)" |
| 467 | echo "a second readme" > docs/readme.md |
| 468 | git commit --quiet -am "a second readme" |
| 469 | |
| 470 | valley checks "$base2" HEAD > "$w/floorless.out" 2> "$w/floorless.err" |
| 471 | grep -qx "policy: $valley policy/instance@refs/heads/main + no policy/project@origin/main $(git rev-parse --short origin/main) — the floor alone" "$w/floorless.out" |
| 472 | grep -qE '^ tree-ok +mandatory +prose$' "$w/floorless.out" |
| 473 | if grep -q no-secrets "$w/floorless.out"; then |
| 474 | echo "valley-request: the floor-alone derivation saw another project's layer" >&2 |
| 475 | exit 1 |
| 476 | fi |
| 477 | cd "$repo" || exit 1 |
| 478 | git checkout --quiet main |
| 479 | |
| 480 | # ---------------------------------------------------------------------- |
| 481 | # 10. Resubmission after main moved. This is the case that wedged in live |
| 482 | # use. A request goes stale with reason=evidence when main lands |
| 483 | # inside a required check's input closure: no attestation over the |
| 484 | # submitted tree can transfer again, so the cure is a new head rebased |
| 485 | # onto the moved main. That head is not a descendant of the one the |
| 486 | # request ref holds, which makes writing it a non-fast-forward |
| 487 | # replacement — and a push without a lease is refused by git's own |
| 488 | # rule before origin's hook is ever consulted. The verdict that sends |
| 489 | # a change down this path is the integrator's and is pinned by |
| 490 | # integrator-e2e; what is under test here is that [a]sk can act on it. |
| 491 | git checkout --quiet -b topic/five origin/main |
| 492 | echo "a readme worth asking about" > docs/readme.md |
| 493 | git commit --quiet -am "a readme worth asking about" |
| 494 | git push --quiet origin topic/five |
| 495 | stalehead="$(git rev-parse topic/five)" |
| 496 | staledigest="$(attest digest --rev topic/five | cut -d: -f2)" |
| 497 | |
| 498 | printf 'a\n' > "$w/answers" |
| 499 | valley review topic/five < "$w/answers" > "$w/five-first.out" 2> "$w/five-first.err" |
| 500 | grep -qx " request refs/the-valley/integration-requests/main/topic-five -> $(git rev-parse --short "$stalehead")" "$w/five-first.out" |
| 501 | |
| 502 | # main moves, and the change is rebased onto it — the operator's half of |
| 503 | # a resubmission, which [a]sk does not do and does not need to. |
| 504 | git checkout --quiet main |
| 505 | echo "a second note" > docs/second.md |
| 506 | git add -A |
| 507 | git commit --quiet -m "a landing under the same class" |
| 508 | git push --quiet origin main |
| 509 | git checkout --quiet topic/five |
| 510 | git rebase --quiet main |
| 511 | git push --quiet --force-with-lease origin topic/five |
| 512 | newhead="$(git rev-parse topic/five)" |
| 513 | newdigest="$(attest digest --rev topic/five | cut -d: -f2)" |
| 514 | |
| 515 | # The premise of the scenario, asserted rather than assumed: the rebase |
| 516 | # produced a head off the old one's line and a tree the old evidence is |
| 517 | # not about. Without both, the push below would be an ordinary one and |
| 518 | # would prove nothing. |
| 519 | if git merge-base --is-ancestor "$stalehead" "$newhead"; then |
| 520 | echo "valley-request: the rebased head still descends from the old one" >&2 |
| 521 | exit 1 |
| 522 | fi |
| 523 | if [ "$staledigest" = "$newdigest" ]; then |
| 524 | echo "valley-request: the rebase left the tree the old evidence is about" >&2 |
| 525 | exit 1 |
| 526 | fi |
| 527 | |
| 528 | : > "$pushlog" |
| 529 | printf 'a\n' > "$w/answers" |
| 530 | valley review topic/five < "$w/answers" > "$w/five-again.out" 2> "$w/five-again.err" |
| 531 | |
| 532 | grep -qx 'requested topic/five -> refs/heads/main' "$w/five-again.out" |
| 533 | grep -qx " request refs/the-valley/integration-requests/main/topic-five -> $(git rev-parse --short "$newhead")" "$w/five-again.out" |
| 534 | # Replacing a pending request is said out loud, and the sentence names the |
| 535 | # head that was replaced. |
| 536 | grep -qx " replaced the pending request, which stood at $(git rev-parse --short "$stalehead") (a readme worth asking about)" "$w/five-again.out" |
| 537 | |
| 538 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-five)" \ |
| 539 | != "$newhead" ]; then |
| 540 | echo "valley-request: the resubmitted request does not name the rebased head" >&2 |
| 541 | exit 1 |
| 542 | fi |
| 543 | |
| 544 | # Both attestations stand. The old one is about a tree that will never |
| 545 | # land, but the namespace is create-only and a record that can be dropped |
| 546 | # is not one; the resubmission publishes beside it, never over it. |
| 547 | for stands in "refs/the-valley/attestations/$staledigest/$keyhash" \ |
| 548 | "refs/the-valley/attestations/$newdigest/$keyhash"; do |
| 549 | git -C "$origin" rev-parse --verify --quiet "$stands" > /dev/null || { |
| 550 | echo "valley-request: $stands is not on origin after the resubmission" >&2 |
| 551 | exit 1 |
| 552 | } |
| 553 | done |
| 554 | |
| 555 | # One push again, and the request ref moved off the old head inside it. |
| 556 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 557 | if [ "$pushes" != 1 ]; then |
| 558 | echo "valley-request: the resubmission took $pushes pushes, not 1" >&2 |
| 559 | cat "$pushlog" >&2 |
| 560 | exit 1 |
| 561 | fi |
| 562 | grep -qx "$stalehead $newhead refs/the-valley/integration-requests/main/topic-five" "$pushlog" |
| 563 | # And every attestation ref in that push is a creation: an all-zero old id |
| 564 | # is what the create-only namespace admits, and a resubmission that |
| 565 | # updated one would be refused by the real hook. |
| 566 | if grep '^[0-9a-f]* [0-9a-f]* refs/the-valley/attestations/' "$pushlog" \ |
| 567 | | grep -qv '^0* '; then |
| 568 | echo "valley-request: the resubmission updated an attestation ref" >&2 |
| 569 | cat "$pushlog" >&2 |
| 570 | exit 1 |
| 571 | fi |
| 572 | if [ "$(git -C "$origin" rev-parse refs/heads/main)" != "$(git rev-parse main)" ]; then |
| 573 | echo "valley-request: the resubmission moved main" >&2 |
| 574 | exit 1 |
| 575 | fi |
| 576 | |
| 577 | # ---------------------------------------------------------------------- |
| 578 | # 11. Two resubmissions of one change race for one ref, and the loser |
| 579 | # loses visibly. The request ref's value is read before the push and |
| 580 | # the push is leased against exactly that value, so the second one to |
| 581 | # arrive is refused rather than allowed to overwrite the first. The |
| 582 | # race is made real: a receive-pack wrapper moves the ref on origin |
| 583 | # after [a]sk has read it and before the push it then makes, which is |
| 584 | # what another operator getting there first looks like from here. |
| 585 | git checkout --quiet main |
| 586 | git checkout --quiet -b topic/six origin/main |
| 587 | echo "a readme two resubmissions both rebased" > docs/readme.md |
| 588 | git commit --quiet -am "a readme two resubmissions both rebased" |
| 589 | git push --quiet origin topic/six |
| 590 | sixfiled="$(git rev-parse topic/six)" |
| 591 | |
| 592 | printf 'a\n' > "$w/answers" |
| 593 | valley review topic/six < "$w/answers" > "$w/six-first.out" 2> "$w/six-first.err" |
| 594 | grep -qx 'requested topic/six -> refs/heads/main' "$w/six-first.out" |
| 595 | |
| 596 | git checkout --quiet main |
| 597 | echo "a third note" > docs/third.md |
| 598 | git add -A |
| 599 | git commit --quiet -m "another landing under the same class" |
| 600 | git push --quiet origin main |
| 601 | git checkout --quiet topic/six |
| 602 | git rebase --quiet main |
| 603 | git push --quiet --force-with-lease origin topic/six |
| 604 | sixhead="$(git rev-parse topic/six)" |
| 605 | sixdigest="$(attest digest --rev topic/six | cut -d: -f2)" |
| 606 | |
| 607 | # The other resubmission's head, built where origin can already reach |
| 608 | # every object in it: the same tree, parented on the same tip, so it is |
| 609 | # the commit a second operator rebasing this change would have produced. |
| 610 | racer="$(git -C "$origin" commit-tree "$(git rev-parse 'topic/six^{tree}')" \ |
| 611 | -p "$(git rev-parse origin/main)" -m "the other resubmission")" |
| 612 | |
| 613 | arm_race "git -C '$origin' update-ref refs/the-valley/integration-requests/main/topic-six '$racer'" |
| 614 | |
| 615 | : > "$pushlog" |
| 616 | printf 'a\ns\n' > "$w/answers" |
| 617 | valley review topic/six < "$w/answers" > "$w/race.out" 2> "$w/race.err" |
| 618 | disarm_race |
| 619 | |
| 620 | # A refusal, named as one, and the review loop still usable after it. |
| 621 | grep -q "the pending request moved from $(git rev-parse --short "$sixfiled") to $(git rev-parse --short "$racer") while this one was being prepared" "$w/race.err" |
| 622 | grep -q 'the lease on refs/the-valley/integration-requests/main/topic-six refused' "$w/race.err" |
| 623 | grep -q 'skipped topic/six; nothing done' "$w/race.out" |
| 624 | |
| 625 | # Nothing published. The winner's request stands untouched, the loser's |
| 626 | # evidence never reached origin, and origin saw no push at all — the lease |
| 627 | # refuses before any command is sent, which is what --atomic is worth. |
| 628 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-six)" \ |
| 629 | != "$racer" ]; then |
| 630 | echo "valley-request: the lease did not hold; the other resubmission was clobbered" >&2 |
| 631 | exit 1 |
| 632 | fi |
| 633 | if git -C "$origin" rev-parse --verify --quiet \ |
| 634 | "refs/the-valley/attestations/$sixdigest/$keyhash" > /dev/null; then |
| 635 | echo "valley-request: a refused resubmission published its evidence" >&2 |
| 636 | exit 1 |
| 637 | fi |
| 638 | if [ -s "$pushlog" ]; then |
| 639 | echo "valley-request: a refused resubmission reached origin's hook" >&2 |
| 640 | cat "$pushlog" >&2 |
| 641 | exit 1 |
| 642 | fi |
| 643 | |
| 644 | # The checks that were run are not lost with the refusal: their notes are |
| 645 | # in the operator's own repository, and the refusal says where. |
| 646 | git rev-parse --verify --quiet "refs/the-valley/attestations/$sixdigest/$keyhash" \ |
| 647 | > /dev/null || { |
| 648 | echo "valley-request: the refused resubmission kept no evidence locally" >&2 |
| 649 | exit 1 |
| 650 | } |
| 651 | grep -qx 'valley: the evidence is stored locally at:' "$w/race.err" |
| 652 | grep -qx " refs/the-valley/attestations/$sixdigest/$keyhash" "$w/race.err" |
| 653 | git checkout --quiet main |
| 654 | |
| 655 | # ---------------------------------------------------------------------- |
| 656 | # 12. Asking again at the same head. Evidence with a validity window |
| 657 | # expires while the tree stays the right tree, and the answer to that |
| 658 | # is a fresh observation over the same head. The request ref already |
| 659 | # names that head, so it is left out of the refspec entirely rather |
| 660 | # than pushed at the value origin already holds. |
| 661 | # |
| 662 | # The request is filed by hand here. Origin holding a request at this |
| 663 | # head is the whole of the state under test, and re-running [a]sk to |
| 664 | # produce it would put a second-granular observation instant in the |
| 665 | # note: the same tree re-attested inside one second is the identical |
| 666 | # ref, and across a second boundary it is not. |
| 667 | git checkout --quiet -b topic/seven origin/main |
| 668 | echo "a readme asked about twice" > docs/readme.md |
| 669 | git commit --quiet -am "a readme asked about twice" |
| 670 | git push --quiet origin topic/seven |
| 671 | sevenhead="$(git rev-parse topic/seven)" |
| 672 | sevendigest="$(attest digest --rev topic/seven | cut -d: -f2)" |
| 673 | git push --quiet origin \ |
| 674 | "$sevenhead:refs/the-valley/integration-requests/main/topic-seven" |
| 675 | |
| 676 | : > "$pushlog" |
| 677 | printf 'a\n' > "$w/answers" |
| 678 | valley review topic/seven < "$w/answers" > "$w/seven.out" 2> "$w/seven.err" |
| 679 | |
| 680 | grep -qx 'requested topic/seven -> refs/heads/main' "$w/seven.out" |
| 681 | grep -qx ' the request already stood at this head; the evidence is what was published' "$w/seven.out" |
| 682 | # The evidence went; the request ref was not in the refspec at all. |
| 683 | grep -q "refs/the-valley/attestations/$sevendigest/$keyhash" "$pushlog" |
| 684 | if grep -q 'refs/the-valley/integration-requests/main/topic-seven' "$pushlog"; then |
| 685 | echo "valley-request: a same-head re-ask pushed the request ref again" >&2 |
| 686 | cat "$pushlog" >&2 |
| 687 | exit 1 |
| 688 | fi |
| 689 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-seven)" \ |
| 690 | != "$sevenhead" ]; then |
| 691 | echo "valley-request: a same-head re-ask disturbed the request ref" >&2 |
| 692 | exit 1 |
| 693 | fi |
| 694 | |
| 695 | # The same head with nothing owed: no evidence to publish and no ref to |
| 696 | # write, so no push is made at all. topic/quiet's request has stood on |
| 697 | # origin at this head since 5. A push assembled with an empty refspec |
| 698 | # would fall back to origin's default one, and pushing whatever that |
| 699 | # happens to name is not what asking about a change means. |
| 700 | git checkout --quiet main |
| 701 | : > "$pushlog" |
| 702 | printf 'a\n' > "$w/answers" |
| 703 | env -u VALLEY_ATTEST_KEY valley review topic/quiet < "$w/answers" \ |
| 704 | > "$w/quiet-again.out" 2> "$w/quiet-again.err" |
| 705 | grep -qx " request refs/the-valley/integration-requests/main/topic-quiet -> $quiethead" "$w/quiet-again.out" |
| 706 | grep -qx ' the request already stood at this head and nothing was owed, so nothing needed publishing' "$w/quiet-again.out" |
| 707 | if [ -s "$pushlog" ]; then |
| 708 | echo "valley-request: a re-ask with nothing to publish still pushed" >&2 |
| 709 | cat "$pushlog" >&2 |
| 710 | exit 1 |
| 711 | fi |
| 712 | |
| 713 | # ---------------------------------------------------------------------- |
| 714 | # 13. Two operators filing one change at once. Reading that the request |
| 715 | # ref is absent is a value like any other, and the lease covers it: |
| 716 | # git spells that expectation with an empty value and refuses if the |
| 717 | # ref exists at all. Unleased, this push would have fast-forwarded the |
| 718 | # other filing away without saying a word. |
| 719 | git checkout --quiet -b topic/eight origin/main |
| 720 | echo "a readme two operators both filed" > docs/readme.md |
| 721 | git commit --quiet -am "a readme two operators both filed" |
| 722 | git push --quiet origin topic/eight |
| 723 | eighthead="$(git rev-parse topic/eight)" |
| 724 | eightdigest="$(attest digest --rev topic/eight | cut -d: -f2)" |
| 725 | # The other operator's filing: this same tree on this same tip, which is |
| 726 | # what a second checkout of one branch produces. It is a descendant of |
| 727 | # nothing here, so an unleased push over it would be a plain fast-forward. |
| 728 | firstfiler="$(git -C "$origin" commit-tree "$(git rev-parse 'topic/eight^{tree}')" \ |
| 729 | -p "$(git rev-parse origin/main)" -m "the other operator's filing")" |
| 730 | |
| 731 | arm_race "git -C '$origin' update-ref refs/the-valley/integration-requests/main/topic-eight '$firstfiler'" |
| 732 | : > "$pushlog" |
| 733 | printf 'a\ns\n' > "$w/answers" |
| 734 | valley review topic/eight < "$w/answers" > "$w/create-race.out" 2> "$w/create-race.err" |
| 735 | disarm_race |
| 736 | |
| 737 | # The other operator's commit is on origin and not here, so the subject |
| 738 | # says so rather than inventing one. Scenario 10 pins the case where the |
| 739 | # replaced head IS local and its subject is printed. |
| 740 | grep -q "a request for this change appeared while this one was being prepared, at $(git rev-parse --short "$firstfiler") (subject not in this repository)" "$w/create-race.err" |
| 741 | grep -q 'skipped topic/eight; nothing done' "$w/create-race.out" |
| 742 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-eight)" \ |
| 743 | != "$firstfiler" ]; then |
| 744 | echo "valley-request: an unleased filing clobbered the request that got there first" >&2 |
| 745 | exit 1 |
| 746 | fi |
| 747 | if git -C "$origin" rev-parse --verify --quiet \ |
| 748 | "refs/the-valley/attestations/$eightdigest/$keyhash" > /dev/null; then |
| 749 | echo "valley-request: a refused filing published its evidence" >&2 |
| 750 | exit 1 |
| 751 | fi |
| 752 | if [ -s "$pushlog" ]; then |
| 753 | echo "valley-request: a refused filing reached origin's hook" >&2 |
| 754 | cat "$pushlog" >&2 |
| 755 | exit 1 |
| 756 | fi |
| 757 | |
| 758 | # ---------------------------------------------------------------------- |
| 759 | # 14. A lease that refuses because the ref is gone, not because it moved. |
| 760 | # The integrator consumes the request ref when the change lands, so a |
| 761 | # resubmission prepared just before that lands into a lease against a |
| 762 | # ref that no longer exists. Git reports it as stale info either way, |
| 763 | # and only reading the ref again tells the two apart — so the two are |
| 764 | # told apart, and the operator is pointed at the landing rather than |
| 765 | # at a race that did not happen. |
| 766 | git checkout --quiet main |
| 767 | git checkout --quiet -b topic/nine origin/main |
| 768 | echo "a readme that lands mid-resubmission" > docs/readme.md |
| 769 | git commit --quiet -am "a readme that lands mid-resubmission" |
| 770 | git push --quiet origin topic/nine |
| 771 | |
| 772 | printf 'a\n' > "$w/answers" |
| 773 | valley review topic/nine < "$w/answers" > "$w/nine-first.out" 2> "$w/nine-first.err" |
| 774 | grep -qx 'requested topic/nine -> refs/heads/main' "$w/nine-first.out" |
| 775 | |
| 776 | git checkout --quiet main |
| 777 | echo "a fourth note" > docs/fourth.md |
| 778 | git add -A |
| 779 | git commit --quiet -m "a landing that moves main again" |
| 780 | git push --quiet origin main |
| 781 | git checkout --quiet topic/nine |
| 782 | git rebase --quiet main |
| 783 | git push --quiet --force-with-lease origin topic/nine |
| 784 | ninedigest="$(attest digest --rev topic/nine | cut -d: -f2)" |
| 785 | |
| 786 | arm_race "git -C '$origin' update-ref -d refs/the-valley/integration-requests/main/topic-nine" |
| 787 | : > "$pushlog" |
| 788 | printf 'a\ns\n' > "$w/answers" |
| 789 | valley review topic/nine < "$w/answers" > "$w/consumed.out" 2> "$w/consumed.err" |
| 790 | disarm_race |
| 791 | |
| 792 | grep -q 'the pending request was consumed while this one was being prepared, which is what the integrator does when a change lands' "$w/consumed.err" |
| 793 | grep -q 'nothing was published; fetch and review the branch again before asking a second time' "$w/consumed.err" |
| 794 | # Not reported as a race, which is the distinction the re-read buys. |
| 795 | if grep -q 'the pending request moved from' "$w/consumed.err"; then |
| 796 | echo "valley-request: a consumed request was reported as a lost race" >&2 |
| 797 | cat "$w/consumed.err" >&2 |
| 798 | exit 1 |
| 799 | fi |
| 800 | grep -q 'skipped topic/nine; nothing done' "$w/consumed.out" |
| 801 | if git -C "$origin" rev-parse --verify --quiet \ |
| 802 | refs/the-valley/integration-requests/main/topic-nine > /dev/null; then |
| 803 | echo "valley-request: a refused resubmission re-created the consumed request" >&2 |
| 804 | exit 1 |
| 805 | fi |
| 806 | if git -C "$origin" rev-parse --verify --quiet \ |
| 807 | "refs/the-valley/attestations/$ninedigest/$keyhash" > /dev/null; then |
| 808 | echo "valley-request: a refused resubmission published its evidence" >&2 |
| 809 | exit 1 |
| 810 | fi |
| 811 | if [ -s "$pushlog" ]; then |
| 812 | echo "valley-request: a refused resubmission reached origin's hook" >&2 |
| 813 | cat "$pushlog" >&2 |
| 814 | exit 1 |
| 815 | fi |
| 816 | |
| 817 | # ---------------------------------------------------------------------- |
| 818 | # 15. The same-head push carries no request ref, so it carries no |
| 819 | # compare-and-swap on one either — git leaves an up-to-date ref out of |
| 820 | # what it sends. Where the ref stands after that push is therefore not |
| 821 | # something the run established, and it is read again rather than |
| 822 | # asserted from the read before it. |
| 823 | # |
| 824 | # Nothing re-files it. A request for a change already in the stream is |
| 825 | # judged against an empty delta on every pass, which is why the |
| 826 | # integrator consumes the ref in the first place; re-creating it here |
| 827 | # would be a guess about which of consumption and deletion happened, |
| 828 | # paid for with a second push behind the one this verb promises. So |
| 829 | # the run says what is true and stops, and asking again is the repair. |
| 830 | git checkout --quiet main |
| 831 | git checkout --quiet -b topic/ten origin/main |
| 832 | echo "a readme consumed under the evidence" > docs/readme.md |
| 833 | git commit --quiet -am "a readme consumed under the evidence" |
| 834 | git push --quiet origin topic/ten |
| 835 | tenhead="$(git rev-parse topic/ten)" |
| 836 | tendigest="$(attest digest --rev topic/ten | cut -d: -f2)" |
| 837 | git push --quiet origin \ |
| 838 | "$tenhead:refs/the-valley/integration-requests/main/topic-ten" |
| 839 | |
| 840 | arm_race "git -C '$origin' update-ref -d refs/the-valley/integration-requests/main/topic-ten" |
| 841 | : > "$pushlog" |
| 842 | printf 'a\ns\n' > "$w/answers" |
| 843 | valley review topic/ten < "$w/answers" > "$w/posthoc.out" 2> "$w/posthoc.err" |
| 844 | disarm_race |
| 845 | |
| 846 | grep -q 'the request was consumed while this run was working, which is what the integrator does when a change lands' "$w/posthoc.err" |
| 847 | grep -q 'Nothing here re-filed it' "$w/posthoc.err" |
| 848 | # The claim the old code would have made, from a read that had gone out of |
| 849 | # date under it. |
| 850 | if grep -q 'the request already stood at this head' "$w/posthoc.out"; then |
| 851 | echo "valley-request: a consumed request was reported as still standing" >&2 |
| 852 | cat "$w/posthoc.out" >&2 |
| 853 | exit 1 |
| 854 | fi |
| 855 | grep -q 'skipped topic/ten; nothing done' "$w/posthoc.out" |
| 856 | |
| 857 | # The evidence went, because that push succeeded; the request did not come |
| 858 | # back, because nothing here writes it. |
| 859 | git -C "$origin" rev-parse --verify --quiet \ |
| 860 | "refs/the-valley/attestations/$tendigest/$keyhash" > /dev/null || { |
| 861 | echo "valley-request: the evidence push was reported as done and is not on origin" >&2 |
| 862 | exit 1 |
| 863 | } |
| 864 | if git -C "$origin" rev-parse --verify --quiet \ |
| 865 | refs/the-valley/integration-requests/main/topic-ten > /dev/null; then |
| 866 | echo "valley-request: the consumed request was re-filed behind the operator" >&2 |
| 867 | exit 1 |
| 868 | fi |
| 869 | # And that evidence went in one push, which is still the whole claim. |
| 870 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 871 | if [ "$pushes" != 1 ]; then |
| 872 | echo "valley-request: the same-head re-ask took $pushes pushes, not 1" >&2 |
| 873 | cat "$pushlog" >&2 |
| 874 | exit 1 |
| 875 | fi |
| 876 | git checkout --quiet main |
| 877 | |
| 878 | # ---------------------------------------------------------------------- |
| 879 | # The verbs the loop offers are the whole of what an operator can do to a |
| 880 | # branch, so no path may offer one outside the set: [a]sk, [b]ase, |
| 881 | # [r]eject, [s]kip. Every stream this check captured is scanned at the end, |
| 882 | # which is what makes the claim about paths rather than about the two |
| 883 | # prompts pinned character for character above — the fast-forward prompt, |
| 884 | # the stale one, the one [b]ase comes back to, and the ones a refused [a]sk |
| 885 | # returns to are all in here. A verb that writes the protected ref from the |
| 886 | # operator's own checkout — the retired [i]ntegrate, or any successor to |
| 887 | # it — fails this wherever it is printed. |
| 888 | offered="$(cat "$w"/*.out | grep -o '\[[a-z]\][a-z]*' | sort -u || true)" |
| 889 | outside="$(printf '%s\n' "$offered" | grep -vxE '\[a\]sk|\[b\]ase|\[r\]eject|\[s\]kip' || true)" |
| 890 | if [ -n "$outside" ]; then |
| 891 | echo "valley-request: a review path offered a verb outside the set:" >&2 |
| 892 | printf '%s\n' "$outside" >&2 |
| 893 | exit 1 |
| 894 | fi |
| 895 | # The scan is only worth something if it saw the offers at all. |
| 896 | for verb in '[a]sk' '[b]ase' '[r]eject' '[s]kip'; do |
| 897 | printf '%s\n' "$offered" | grep -qxF "$verb" \ |
| 898 | || { echo "valley-request: no captured session offered $verb" >&2; exit 1; } |
| 899 | done |
| 900 | |
| 901 | # No throwaway worktree outlived any of it: only the checkout is left. |
| 902 | worktrees="$(git worktree list --porcelain | grep -c '^worktree ' || true)" |
| 903 | if [ "$worktrees" != 1 ]; then |
| 904 | echo "valley-request: a throwaway worktree was left behind" >&2 |
| 905 | git worktree list >&2 |
| 906 | exit 1 |
| 907 | fi |
| 908 | |
| 909 | echo "every scenario held" |
| 910 | { |
| 911 | cat "$w/ask.out" |
| 912 | printf '\n--- the scratch origin, after all of it ---\n' |
| 913 | git -C "$origin" for-each-ref --format='%(objectname) %(refname)' |
| 914 | } > "$out" |