| 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=valley-host.example.org/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 approve |
| 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 approve'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. Requiring no |
| 91 | // check 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 | # |
| 117 | # schema/ is here because the-valley's own tree carries it. The packaged |
| 118 | # CLI never reads it; only bin/valley run straight from the checkout does |
| 119 | # (16). |
| 120 | repo="$TMPDIR/project" |
| 121 | git init --quiet "$repo" |
| 122 | cd "$repo" || exit 1 |
| 123 | git remote add origin "$origin" |
| 124 | |
| 125 | mkdir -p docs src schema policy/project examples/policy/instance examples/policy/project |
| 126 | cp "$schemaFile" schema/verification.cue |
| 127 | echo "the readme" > docs/readme.md |
| 128 | echo "$valley" > policy/valley |
| 129 | cat > policy/project/policy.cue <<'EOF' |
| 130 | package verification |
| 131 | |
| 132 | project: { |
| 133 | checks: "no-secrets": { |
| 134 | runner: "command" |
| 135 | command: "! grep -rqF SECRET src" |
| 136 | } |
| 137 | classes: source: { |
| 138 | paths: "src/**": true |
| 139 | requires: "no-secrets": true |
| 140 | } |
| 141 | } |
| 142 | EOF |
| 143 | cat > examples/policy/instance/floor.cue <<'EOF' |
| 144 | package verification |
| 145 | |
| 146 | floor: { |
| 147 | checks: phantom: { |
| 148 | runner: "command" |
| 149 | command: "false" |
| 150 | } |
| 151 | classes: everything: { |
| 152 | paths: "**": true |
| 153 | requires: phantom: true |
| 154 | } |
| 155 | unclassified: phantom: true |
| 156 | } |
| 157 | EOF |
| 158 | cat > examples/policy/project/policy.cue <<'EOF' |
| 159 | package verification |
| 160 | |
| 161 | project: {} |
| 162 | EOF |
| 163 | git add -A |
| 164 | git commit --quiet -m base |
| 165 | git push --quiet -u origin main |
| 166 | first="$(git rev-parse main)" |
| 167 | |
| 168 | # ---------------------------------------------------------------------- |
| 169 | # 1. A branch whose required check passes: the evidence and the request |
| 170 | # reach origin in one push, and main does not move. |
| 171 | git checkout --quiet -b topic/one |
| 172 | echo "a better readme" > docs/readme.md |
| 173 | git commit --quiet -am "improve the readme" |
| 174 | git push --quiet origin topic/one |
| 175 | digest="$(attest digest --rev topic/one | cut -d: -f2)" |
| 176 | |
| 177 | : > "$pushlog" |
| 178 | printf 'a\n' > "$w/answers" |
| 179 | valley review -v topic/one < "$w/answers" > "$w/approve.out" 2> "$w/approve.err" |
| 180 | |
| 181 | grep -q '^◐ topic/one checking 1 check: tree-ok$' "$w/approve.out" |
| 182 | grep -qE '^check tree-ok +command passed$' "$w/approve.out" |
| 183 | grep -qx '✓ topic/one approved · 1 check passed in [0-9]*s · landing on main' "$w/approve.out" |
| 184 | grep -qx " request refs/the-valley/integration-requests/main/topic-one -> $(git rev-parse --short topic/one)" "$w/approve.out" |
| 185 | grep -qx " evidence refs/the-valley/attestations/$digest/$keyhash" "$w/approve.out" |
| 186 | grep -qx ' checks tree-ok' "$w/approve.out" |
| 187 | |
| 188 | # How long the check took is printed after it, and logged on this machine: |
| 189 | # one JSON line per required check, in the state directory, outside the |
| 190 | # repository and the evidence. A branch no record is on names no change. |
| 191 | grep -qE '^time tree-ok +passed +[0-9][0-9.hms]* \(ran\)$' "$w/approve.out" |
| 192 | timings="$XDG_STATE_HOME/valley/timings.jsonl" |
| 193 | if [ "$(wc -l < "$timings")" != 1 ] || ! jq -e \ |
| 194 | --arg head "$(git rev-parse topic/one)" --arg origin "$origin" ' |
| 195 | keys == ["check", "cost", "duration_ms", "head", "repository", "result", "runner", "satisfied", "time"] |
| 196 | and .check == "tree-ok" and .runner == "command" and .cost == "quick" |
| 197 | and .result == "passed" and .satisfied == "ran" |
| 198 | and .head == $head and .repository == $origin |
| 199 | and (.duration_ms | type == "number" and . >= 0) |
| 200 | and (.time | test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{3}Z$"))' \ |
| 201 | "$timings" > /dev/null; then |
| 202 | echo "valley-request: approve did not log one timing for its one required check:" >&2 |
| 203 | cat "$timings" >&2 |
| 204 | exit 1 |
| 205 | fi |
| 206 | if [ "$(stat -c %a "$timings")" != 600 ]; then |
| 207 | echo "valley-request: the timing log was created $(stat -c %a "$timings"), not 600" >&2 |
| 208 | exit 1 |
| 209 | fi |
| 210 | |
| 211 | # What origin holds now. The attestation is keyed by the digest of the |
| 212 | # BRANCH's tree, which is what says the checks ran over the right tree and |
| 213 | # not over the operator's working copy. |
| 214 | git -C "$origin" for-each-ref --format='%(refname)' refs/the-valley > "$w/published.txt" |
| 215 | grep -qx "refs/the-valley/integration-requests/main/topic-one" "$w/published.txt" |
| 216 | grep -qx "refs/the-valley/attestations/$digest/$keyhash" "$w/published.txt" |
| 217 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-one)" \ |
| 218 | != "$(git rev-parse topic/one)" ]; then |
| 219 | echo "valley-request: the request ref does not name the branch's head" >&2 |
| 220 | exit 1 |
| 221 | fi |
| 222 | if [ "$(git -C "$origin" rev-parse refs/heads/main)" != "$first" ]; then |
| 223 | echo "valley-request: [a]pprove moved main" >&2 |
| 224 | exit 1 |
| 225 | fi |
| 226 | |
| 227 | # One push carried both. This is the friction the verb exists to remove: |
| 228 | # `attest run --push` publishes the branch and the evidence and knows |
| 229 | # nothing about a request ref, so doing this by hand is two beats. |
| 230 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 231 | if [ "$pushes" != 1 ]; then |
| 232 | echo "valley-request: the evidence and the request took $pushes pushes, not 1" >&2 |
| 233 | cat "$pushlog" >&2 |
| 234 | exit 1 |
| 235 | fi |
| 236 | grep -q "refs/the-valley/attestations/$digest/$keyhash" "$pushlog" |
| 237 | grep -q 'refs/the-valley/integration-requests/main/topic-one' "$pushlog" |
| 238 | |
| 239 | # The note origin holds is the one the operator signed, over that tree. |
| 240 | git cat-file -p "refs/the-valley/attestations/$digest/$keyhash:tree-ok/statement.note" \ |
| 241 | > "$w/statement.note" |
| 242 | attest key --key "$TMPDIR/host" --name "$VALLEY_ATTEST_NAME" > "$w/known_keys" |
| 243 | attest verify --note "$w/statement.note" --repo "$repo" --rev topic/one \ |
| 244 | --known-keys "$w/known_keys" --signer "$VALLEY_ATTEST_NAME" > "$w/verify.out" |
| 245 | grep -q 'matches the recorded subject digest' "$w/verify.out" |
| 246 | |
| 247 | # ---------------------------------------------------------------------- |
| 248 | # 2. The layers the derivation used are the ones that govern, and it says |
| 249 | # which they were: the floor fetched from the owning valley, and the |
| 250 | # project's own layer at policy/project in the TARGET's tip. |
| 251 | # examples/policy/ is in this tree and requires `phantom` of every path, |
| 252 | # and no default reaches it — it is derivable only by naming it, which |
| 253 | # is what the options are for. |
| 254 | valley checks "$first" topic/one > "$w/checks.out" 2> "$w/checks.err" |
| 255 | grep -qx "policy: $valley policy/instance@refs/heads/main + policy/project@origin/main $(git rev-parse --short origin/main)" "$w/checks.out" |
| 256 | grep -qx 'classes matched: prose' "$w/checks.out" |
| 257 | grep -qE '^ tree-ok +mandatory +prose$' "$w/checks.out" |
| 258 | if grep -q phantom "$w/checks.out" "$w/checks.err"; then |
| 259 | echo "valley-request: a default derived a check from examples/policy/" >&2 |
| 260 | cat "$w/checks.out" "$w/checks.err" >&2 |
| 261 | exit 1 |
| 262 | fi |
| 263 | |
| 264 | # Named, the example layers derive exactly what they declare. This is the |
| 265 | # other half of the claim above: examples/policy/ is readable, and reading |
| 266 | # it is something a person asks for. |
| 267 | valley checks --instance examples/policy/instance --project examples/policy/project \ |
| 268 | "$first" topic/one > "$w/example.out" |
| 269 | grep -qE '^ phantom +mandatory' "$w/example.out" |
| 270 | grep -qx 'policy: examples/policy/instance + examples/policy/project' "$w/example.out" |
| 271 | |
| 272 | # ---------------------------------------------------------------------- |
| 273 | # 3. main moves on, so the next branch is behind main. It is offered the |
| 274 | # ordinary prompt under one line that says so — the integrator applies |
| 275 | # a delta to the tip rather than fast-forwarding, so nothing is asked of |
| 276 | # the operator — and a branch whose check fails publishes nothing and |
| 277 | # leaves the review loop usable. Approving the same head again would |
| 278 | # only fail again, so after the failure the prompt says approving needs |
| 279 | # a new head and offers [v]iew full diff, [r]eject and [s]kip alone, and |
| 280 | # an answer of a is not taken. Review never offers [b]ase. |
| 281 | git checkout --quiet main |
| 282 | echo "a note" > docs/notes.md |
| 283 | git add -A |
| 284 | git commit --quiet -m "a landing that moves main" |
| 285 | git push --quiet origin main |
| 286 | |
| 287 | git checkout --quiet -b topic/two "$first" |
| 288 | printf 'SECRET\n' > src/leak.txt |
| 289 | git add -A |
| 290 | git commit --quiet -m "a leak" |
| 291 | git push --quiet origin topic/two |
| 292 | |
| 293 | : > "$pushlog" |
| 294 | printf 'a\na\ns\n' > "$w/answers" |
| 295 | valley review topic/two < "$w/answers" > "$w/fail.out" 2> "$w/fail.err" |
| 296 | |
| 297 | # The prompt is the whole of what the operator is offered, so it is pinned |
| 298 | # character for character: a verb that stops being offered, or one that |
| 299 | # starts, is a change to the review loop and not an incidental one. |
| 300 | behind='topic/two · behind main (integrator merges)' |
| 301 | grep -qx "$behind" "$w/fail.out" |
| 302 | grep -qF '[a]pprove [v]iew diff [r]eject [s]kip: ' "$w/fail.out" |
| 303 | if grep -qF '[b]ase' "$w/fail.out"; then |
| 304 | echo "valley-request: review offered [b]ase for a branch behind main" >&2 |
| 305 | exit 1 |
| 306 | fi |
| 307 | grep -q '◐ topic/two checking 1 check: no-secrets' "$w/fail.out" |
| 308 | twohead="$(git rev-parse --short topic/two)" |
| 309 | grep -qxF "topic/two · checks failed at $twohead" "$w/fail.out" |
| 310 | grep -qF '[v]iew diff [r]eject [s]kip: ' "$w/fail.out" |
| 311 | grep -qF 'answer v, r, or s' "$w/fail.out" |
| 312 | offers="$(grep -oF '[a]pprove' "$w/fail.out" | wc -l)" |
| 313 | checked="$(grep -c '◐ topic/two checking ' "$w/fail.out" || true)" |
| 314 | if [ "$offers" != 1 ] || [ "$checked" != 1 ]; then |
| 315 | echo "valley-request: after its checks failed, the prompt offered [a]pprove again ($offers offers, $checked runs)" >&2 |
| 316 | cat "$w/fail.out" >&2 |
| 317 | exit 1 |
| 318 | fi |
| 319 | grep -qx '⊘ topic/two not approved · 1 of [0-9]* checks* failed' "$w/fail.err" |
| 320 | grep -qx ' ✗ no-secrets — see: valley status topic/two' "$w/fail.err" |
| 321 | # The prompt is printed without a newline, so what follows a refusal shares |
| 322 | # its line — the answer to it is not anchored. |
| 323 | grep -q 'skipped topic/two; nothing done' "$w/fail.out" |
| 324 | if [ -s "$pushlog" ]; then |
| 325 | echo "valley-request: a failing check pushed something" >&2 |
| 326 | cat "$pushlog" >&2 |
| 327 | exit 1 |
| 328 | fi |
| 329 | git -C "$origin" for-each-ref --format='%(refname)' refs/the-valley > "$w/after.txt" |
| 330 | if grep -q 'topic-two' "$w/after.txt"; then |
| 331 | echo "valley-request: a failing check left a ref on origin" >&2 |
| 332 | cat "$w/after.txt" >&2 |
| 333 | exit 1 |
| 334 | fi |
| 335 | |
| 336 | # The same for a branch that fast-forwards: after its checks fail, the |
| 337 | # prompt offers [r]eject and [s]kip alone. |
| 338 | git checkout --quiet -b topic/leak main |
| 339 | mkdir -p src |
| 340 | printf 'SECRET\n' > src/leak.txt |
| 341 | git add -A |
| 342 | git commit --quiet -m "another leak" |
| 343 | git push --quiet origin topic/leak |
| 344 | leakhead="$(git rev-parse --short topic/leak)" |
| 345 | : > "$pushlog" |
| 346 | printf 'a\na\ns\n' > "$w/answers" |
| 347 | valley review topic/leak < "$w/answers" > "$w/leak.out" 2> "$w/leak.err" |
| 348 | grep -qF '[a]pprove [v]iew diff [r]eject [s]kip: ' "$w/leak.out" |
| 349 | grep -qxF "topic/leak · checks failed at $leakhead" "$w/leak.out" |
| 350 | grep -qF '[v]iew diff [r]eject [s]kip: ' "$w/leak.out" |
| 351 | grep -qF 'answer v, r, or s' "$w/leak.out" |
| 352 | grep -q 'skipped topic/leak; nothing done' "$w/leak.out" |
| 353 | offers="$(grep -oF '[a]pprove' "$w/leak.out" | wc -l)" |
| 354 | checked="$(grep -c '◐ topic/leak checking ' "$w/leak.out" || true)" |
| 355 | if [ "$offers" != 1 ] || [ "$checked" != 1 ] || [ -s "$pushlog" ]; then |
| 356 | echo "valley-request: after its checks failed, a branch that fast-forwards was offered [a]pprove again ($offers offers, $checked runs)" >&2 |
| 357 | cat "$w/leak.out" "$pushlog" >&2 |
| 358 | exit 1 |
| 359 | fi |
| 360 | |
| 361 | # ---------------------------------------------------------------------- |
| 362 | # 4. No signing key, with a check required: refused before any check is run, |
| 363 | # and the prompt still comes back. The host signs, and there is no |
| 364 | # unsigned mode. |
| 365 | : > "$pushlog" |
| 366 | printf 'a\ns\n' > "$w/answers" |
| 367 | env -u VALLEY_ATTEST_KEY valley review topic/two < "$w/answers" > "$w/nokey.out" 2> "$w/nokey.err" |
| 368 | grep -qx '⊘ topic/two not approved · no signing key' "$w/nokey.err" |
| 369 | grep -q '^ set VALLEY_ATTEST_KEY' "$w/nokey.err" |
| 370 | grep -q 'skipped topic/two; nothing done' "$w/nokey.out" |
| 371 | # A refusal that is no check failure leaves the prompt as it was, [a]pprove |
| 372 | # and all: a new session starts with no check failed. |
| 373 | offers="$(grep -oF '[a]pprove [v]iew diff [r]eject [s]kip: ' "$w/nokey.out" | wc -l)" |
| 374 | if [ "$offers" != 2 ]; then |
| 375 | echo "valley-request: a refusal that was no check failure changed the prompt" >&2 |
| 376 | cat "$w/nokey.out" >&2 |
| 377 | exit 1 |
| 378 | fi |
| 379 | if [ -s "$pushlog" ]; then |
| 380 | echo "valley-request: a run with no signing key pushed something" >&2 |
| 381 | exit 1 |
| 382 | fi |
| 383 | |
| 384 | # ---------------------------------------------------------------------- |
| 385 | # 5. A branch the policy requires no check of is filed as a request with |
| 386 | # no evidence. The integrator lands one and records it as a landing |
| 387 | # that required nothing, so refusing to file it here would strand |
| 388 | # exactly the changes a policy leaves unrequired. Nothing is required, |
| 389 | # so nothing is signed: this runs with no signing key at all. |
| 390 | git checkout --quiet main |
| 391 | git checkout --quiet -b topic/quiet |
| 392 | mkdir -p quiet |
| 393 | echo "a quiet note" > quiet/note.md |
| 394 | git add -A |
| 395 | git commit --quiet -m "a change under a class that asks nothing" |
| 396 | git push --quiet origin topic/quiet |
| 397 | quiethead="$(git rev-parse --short topic/quiet)" |
| 398 | |
| 399 | : > "$pushlog" |
| 400 | printf 'a\n' > "$w/answers" |
| 401 | env -u VALLEY_ATTEST_KEY valley review -v topic/quiet < "$w/answers" \ |
| 402 | > "$w/quiet.out" 2> "$w/quiet.err" |
| 403 | |
| 404 | grep -q 'requires no check under .* + policy/project@origin/main .*; filing the request with no evidence' "$w/quiet.out" |
| 405 | grep -qF "$valley policy/instance@refs/heads/main" "$w/quiet.out" |
| 406 | grep -qx '✓ topic/quiet approved · no checks required · landing on main' "$w/quiet.out" |
| 407 | grep -qx " request refs/the-valley/integration-requests/main/topic-quiet -> $quiethead" "$w/quiet.out" |
| 408 | grep -qx ' evidence none — nothing was required, so nothing was signed' "$w/quiet.out" |
| 409 | grep -qx ' checks none — the policy requires no check of this change' "$w/quiet.out" |
| 410 | |
| 411 | # One push, carrying the request and nothing else. |
| 412 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 413 | if [ "$pushes" != 1 ]; then |
| 414 | echo "valley-request: the bare request took $pushes pushes, not 1" >&2 |
| 415 | cat "$pushlog" >&2 |
| 416 | exit 1 |
| 417 | fi |
| 418 | if grep -q 'refs/the-valley/attestations/' "$pushlog"; then |
| 419 | echo "valley-request: a request that requires nothing published evidence" >&2 |
| 420 | cat "$pushlog" >&2 |
| 421 | exit 1 |
| 422 | fi |
| 423 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-quiet)" \ |
| 424 | != "$(git rev-parse topic/quiet)" ]; then |
| 425 | echo "valley-request: the bare request does not name the branch's head" >&2 |
| 426 | exit 1 |
| 427 | fi |
| 428 | |
| 429 | # ---------------------------------------------------------------------- |
| 430 | # 6. A branch behind main is approved as it is. Review offers no [b]ase: |
| 431 | # an answer of b is not taken, and approving files the branch's own |
| 432 | # head, not a rebased one, while main and the branch stay where they |
| 433 | # were. |
| 434 | git checkout --quiet main |
| 435 | git checkout --quiet -b topic/three "$first" |
| 436 | echo "another readme" > docs/readme.md |
| 437 | git commit --quiet -am "another readme" |
| 438 | git push --quiet origin topic/three |
| 439 | before_base="$(git -C "$origin" rev-parse refs/heads/main)" |
| 440 | |
| 441 | printf 'b\na\n' > "$w/answers" |
| 442 | : > "$pushlog" |
| 443 | valley review topic/three < "$w/answers" > "$w/base.out" 2>&1 |
| 444 | grep -qx 'topic/three · behind main (integrator merges)' "$w/base.out" |
| 445 | grep -qF '[a]pprove [v]iew diff [r]eject [s]kip: answer a, v, r, or s' "$w/base.out" |
| 446 | if grep -qF -e '[b]ase' -e 'rebased topic/three' "$w/base.out"; then |
| 447 | echo "valley-request: review offered or ran a rebase of a branch behind main" >&2 |
| 448 | cat "$w/base.out" >&2 |
| 449 | exit 1 |
| 450 | fi |
| 451 | [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-three)" = "$(git rev-parse topic/three)" ] \ |
| 452 | || { echo "valley-request: approving a branch behind main did not file its own head" >&2; exit 1; } |
| 453 | git merge-base --is-ancestor refs/remotes/origin/main topic/three \ |
| 454 | && { echo "valley-request: the branch behind main was rebased" >&2; exit 1; } |
| 455 | if [ "$(git -C "$origin" rev-parse refs/heads/main)" != "$before_base" ]; then |
| 456 | echo "valley-request: the review loop moved main" >&2 |
| 457 | exit 1 |
| 458 | fi |
| 459 | git checkout --quiet main |
| 460 | |
| 461 | # The request filed in 1 is still pending: nothing here consumes it, which |
| 462 | # is the integrator's own step. |
| 463 | git -C "$origin" rev-parse --verify --quiet \ |
| 464 | refs/the-valley/integration-requests/main/topic-one > /dev/null |
| 465 | |
| 466 | # ---------------------------------------------------------------------- |
| 467 | # 7. A change does not supply the policy that gates it. This branch |
| 468 | # deletes its own policy/project and repoints policy/valley at a |
| 469 | # repository that does not exist. Both layers come from the target's |
| 470 | # tip, so neither edit reaches the derivation: it composes the same two |
| 471 | # layers it would for any other branch, and the fetch that a branch-read |
| 472 | # pointer would have attempted never happens. |
| 473 | git checkout --quiet -b topic/nolayer |
| 474 | git rm --quiet -r policy/project |
| 475 | echo "$TMPDIR/there-is-no-such-valley.git" > policy/valley |
| 476 | git add -A |
| 477 | git commit --quiet -m "delete the project layer and repoint the valley" |
| 478 | git push --quiet origin topic/nolayer |
| 479 | |
| 480 | valley checks "$first" topic/nolayer > "$w/nolayer.out" 2> "$w/nolayer.err" |
| 481 | grep -qx "policy: $valley policy/instance@refs/heads/main + policy/project@origin/main $(git rev-parse --short origin/main)" "$w/nolayer.out" |
| 482 | if grep -q 'there-is-no-such-valley' "$w/nolayer.out" "$w/nolayer.err"; then |
| 483 | echo "valley-request: the deriver followed the branch's own valley pointer" >&2 |
| 484 | cat "$w/nolayer.out" "$w/nolayer.err" >&2 |
| 485 | exit 1 |
| 486 | fi |
| 487 | |
| 488 | : > "$pushlog" |
| 489 | printf 'a\n' > "$w/answers" |
| 490 | valley review topic/nolayer < "$w/answers" \ |
| 491 | > "$w/nolayer.review.out" 2> "$w/nolayer.review.err" |
| 492 | grep -q '^✓ topic/nolayer approved · ' "$w/nolayer.review.out" |
| 493 | |
| 494 | # ---------------------------------------------------------------------- |
| 495 | # 8. The reviewer's checkout contributes nothing. This is the case that |
| 496 | # failed in live use: the operator's checkout was an older branch |
| 497 | # without the landed policy layer, and the deriver read the working |
| 498 | # tree and refused. topic/nolayer is exactly such a checkout — no |
| 499 | # policy/project in it, and a policy/valley naming nowhere — so every |
| 500 | # derivation below runs from it. |
| 501 | # |
| 502 | # Byte-identical output is the claim, not merely a successful one: |
| 503 | # review works the same from any branch, however stale. |
| 504 | git checkout --quiet main |
| 505 | valley checks "$first" topic/one > "$w/from-main.out" |
| 506 | git checkout --quiet topic/nolayer |
| 507 | valley checks "$first" topic/one > "$w/from-stale.out" |
| 508 | if ! cmp -s "$w/from-main.out" "$w/from-stale.out"; then |
| 509 | echo "valley-request: the checkout changed what the derivation said" >&2 |
| 510 | diff -u "$w/from-main.out" "$w/from-stale.out" >&2 || true |
| 511 | exit 1 |
| 512 | fi |
| 513 | |
| 514 | # And [a]pprove, which is where it failed: a request filed from that same |
| 515 | # checkout, over a branch the stale tree knows nothing about. |
| 516 | git checkout --quiet -b topic/four origin/main |
| 517 | echo "one more readme" > docs/readme.md |
| 518 | git commit --quiet -am "one more readme" |
| 519 | git push --quiet origin topic/four |
| 520 | git checkout --quiet topic/nolayer |
| 521 | |
| 522 | : > "$pushlog" |
| 523 | printf 'a\n' > "$w/answers" |
| 524 | valley review -v topic/four < "$w/answers" > "$w/stale.out" 2> "$w/stale.err" |
| 525 | grep -q '^◐ topic/four checking 1 check: tree-ok$' "$w/stale.out" |
| 526 | grep -q '^✓ topic/four approved · ' "$w/stale.out" |
| 527 | grep -qx ' checks tree-ok' "$w/stale.out" |
| 528 | |
| 529 | # ---------------------------------------------------------------------- |
| 530 | # 9. A target carrying no project layer at all is derived under the floor |
| 531 | # alone, and says so. The project layer only ever adds, so the identity |
| 532 | # of "adds" is "adds nothing"; refusing instead would make a repository |
| 533 | # underivable until its first policy commit, and that commit could not |
| 534 | # derive either. This is the integrator's own reading of an absent |
| 535 | # layer (integrator/policy.go), and the two have to agree. |
| 536 | bare2="$TMPDIR/floorless.git" |
| 537 | git init --quiet --bare "$bare2" |
| 538 | repo2="$TMPDIR/floorless" |
| 539 | git init --quiet "$repo2" |
| 540 | cd "$repo2" || exit 1 |
| 541 | git remote add origin "$bare2" |
| 542 | mkdir -p docs policy |
| 543 | echo "the readme" > docs/readme.md |
| 544 | echo "$valley" > policy/valley |
| 545 | git add -A |
| 546 | git commit --quiet -m base |
| 547 | git push --quiet -u origin main |
| 548 | base2="$(git rev-parse main)" |
| 549 | echo "a second readme" > docs/readme.md |
| 550 | git commit --quiet -am "a second readme" |
| 551 | |
| 552 | valley checks "$base2" HEAD > "$w/floorless.out" 2> "$w/floorless.err" |
| 553 | 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" |
| 554 | grep -qE '^ tree-ok +mandatory +prose$' "$w/floorless.out" |
| 555 | if grep -q no-secrets "$w/floorless.out"; then |
| 556 | echo "valley-request: the floor-alone derivation saw another project's layer" >&2 |
| 557 | exit 1 |
| 558 | fi |
| 559 | cd "$repo" || exit 1 |
| 560 | git checkout --quiet main |
| 561 | |
| 562 | # ---------------------------------------------------------------------- |
| 563 | # 10. Approving again after main moved. This is the case that wedged in live |
| 564 | # use. A request goes stale with reason=evidence when main lands |
| 565 | # inside a required check's input closure: no attestation over the |
| 566 | # requested tree can transfer again, so the cure is a new head rebased |
| 567 | # onto the moved main. That head is not a descendant of the one the |
| 568 | # request ref holds, which makes writing it a non-fast-forward |
| 569 | # replacement — and a push without a lease is refused by git's own |
| 570 | # rule before origin's hook is ever consulted. The verdict that sends |
| 571 | # a change down this path is the integrator's and is pinned by |
| 572 | # integrator-e2e; what is under test here is that [a]pprove can act on it. |
| 573 | git checkout --quiet -b topic/five origin/main |
| 574 | echo "a readme worth approving" > docs/readme.md |
| 575 | git commit --quiet -am "a readme worth approving" |
| 576 | git push --quiet origin topic/five |
| 577 | stalehead="$(git rev-parse topic/five)" |
| 578 | staledigest="$(attest digest --rev topic/five | cut -d: -f2)" |
| 579 | |
| 580 | printf 'a\n' > "$w/answers" |
| 581 | valley review -v topic/five < "$w/answers" > "$w/five-first.out" 2> "$w/five-first.err" |
| 582 | grep -qx " request refs/the-valley/integration-requests/main/topic-five -> $(git rev-parse --short "$stalehead")" "$w/five-first.out" |
| 583 | |
| 584 | # main moves, and the change is rebased onto it — the operator's half of |
| 585 | # approving again, which [a]pprove does not do and does not need to. |
| 586 | git checkout --quiet main |
| 587 | echo "a second note" > docs/second.md |
| 588 | git add -A |
| 589 | git commit --quiet -m "a landing under the same class" |
| 590 | git push --quiet origin main |
| 591 | git checkout --quiet topic/five |
| 592 | git rebase --quiet main |
| 593 | git push --quiet --force-with-lease origin topic/five |
| 594 | newhead="$(git rev-parse topic/five)" |
| 595 | newdigest="$(attest digest --rev topic/five | cut -d: -f2)" |
| 596 | |
| 597 | # The premise of the scenario, asserted rather than assumed: the rebase |
| 598 | # produced a head off the old one's line and a tree the old evidence is |
| 599 | # not about. Without both, the push below would be an ordinary one and |
| 600 | # would prove nothing. |
| 601 | if git merge-base --is-ancestor "$stalehead" "$newhead"; then |
| 602 | echo "valley-request: the rebased head still descends from the old one" >&2 |
| 603 | exit 1 |
| 604 | fi |
| 605 | if [ "$staledigest" = "$newdigest" ]; then |
| 606 | echo "valley-request: the rebase left the tree the old evidence is about" >&2 |
| 607 | exit 1 |
| 608 | fi |
| 609 | |
| 610 | : > "$pushlog" |
| 611 | printf 'a\n' > "$w/answers" |
| 612 | valley review -v topic/five < "$w/answers" > "$w/five-again.out" 2> "$w/five-again.err" |
| 613 | |
| 614 | grep -q '^✓ topic/five approved · ' "$w/five-again.out" |
| 615 | grep -qx " request refs/the-valley/integration-requests/main/topic-five -> $(git rev-parse --short "$newhead")" "$w/five-again.out" |
| 616 | # Replacing a pending request is said out loud, and the sentence names the |
| 617 | # head that was replaced. |
| 618 | grep -qx " replaced the pending request, which stood at $(git rev-parse --short "$stalehead") (a readme worth approving)" "$w/five-again.out" |
| 619 | |
| 620 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-five)" \ |
| 621 | != "$newhead" ]; then |
| 622 | echo "valley-request: the request filed again does not name the rebased head" >&2 |
| 623 | exit 1 |
| 624 | fi |
| 625 | |
| 626 | # Both attestations stand. The old one is about a tree that will never |
| 627 | # land, but published evidence is never removed, and a record that can be |
| 628 | # dropped is not one; the second approval publishes beside it, never over it. |
| 629 | for stands in "refs/the-valley/attestations/$staledigest/$keyhash" \ |
| 630 | "refs/the-valley/attestations/$newdigest/$keyhash"; do |
| 631 | git -C "$origin" rev-parse --verify --quiet "$stands" > /dev/null || { |
| 632 | echo "valley-request: $stands is not on origin after the second approval" >&2 |
| 633 | exit 1 |
| 634 | } |
| 635 | done |
| 636 | |
| 637 | # One push again, and the request ref moved off the old head inside it. |
| 638 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 639 | if [ "$pushes" != 1 ]; then |
| 640 | echo "valley-request: the second approval took $pushes pushes, not 1" >&2 |
| 641 | cat "$pushlog" >&2 |
| 642 | exit 1 |
| 643 | fi |
| 644 | grep -qx "$stalehead $newhead refs/the-valley/integration-requests/main/topic-five" "$pushlog" |
| 645 | # And every attestation ref in that push is a creation: an all-zero old id. |
| 646 | # approve pushes a ref of its own notes alone, so an approval that updated |
| 647 | # one would drop the notes it held, which the real hook refuses. |
| 648 | if grep '^[0-9a-f]* [0-9a-f]* refs/the-valley/attestations/' "$pushlog" \ |
| 649 | | grep -qv '^0* '; then |
| 650 | echo "valley-request: the second approval updated an attestation ref" >&2 |
| 651 | cat "$pushlog" >&2 |
| 652 | exit 1 |
| 653 | fi |
| 654 | if [ "$(git -C "$origin" rev-parse refs/heads/main)" != "$(git rev-parse main)" ]; then |
| 655 | echo "valley-request: the second approval moved main" >&2 |
| 656 | exit 1 |
| 657 | fi |
| 658 | |
| 659 | # ---------------------------------------------------------------------- |
| 660 | # 11. Two approvals of one change race for one ref, and the loser |
| 661 | # loses visibly. The request ref's value is read before the push and |
| 662 | # the push is leased against exactly that value, so the second one to |
| 663 | # arrive is refused rather than allowed to overwrite the first. The |
| 664 | # race is made real: a receive-pack wrapper moves the ref on origin |
| 665 | # after approve has read it and before the push it then makes, which is |
| 666 | # what another operator getting there first looks like from here. |
| 667 | git checkout --quiet main |
| 668 | git checkout --quiet -b topic/six origin/main |
| 669 | echo "a readme two approvals both rebased" > docs/readme.md |
| 670 | git commit --quiet -am "a readme two approvals both rebased" |
| 671 | git push --quiet origin topic/six |
| 672 | sixfiled="$(git rev-parse topic/six)" |
| 673 | |
| 674 | printf 'a\n' > "$w/answers" |
| 675 | valley review topic/six < "$w/answers" > "$w/six-first.out" 2> "$w/six-first.err" |
| 676 | grep -q '^✓ topic/six approved · ' "$w/six-first.out" |
| 677 | |
| 678 | git checkout --quiet main |
| 679 | echo "a third note" > docs/third.md |
| 680 | git add -A |
| 681 | git commit --quiet -m "another landing under the same class" |
| 682 | git push --quiet origin main |
| 683 | git checkout --quiet topic/six |
| 684 | git rebase --quiet main |
| 685 | git push --quiet --force-with-lease origin topic/six |
| 686 | sixhead="$(git rev-parse topic/six)" |
| 687 | sixdigest="$(attest digest --rev topic/six | cut -d: -f2)" |
| 688 | |
| 689 | # The other approval's head, built where origin can already reach |
| 690 | # every object in it: the same tree, parented on the same tip, so it is |
| 691 | # the commit a second operator rebasing this change would have produced. |
| 692 | racer="$(git -C "$origin" commit-tree "$(git rev-parse 'topic/six^{tree}')" \ |
| 693 | -p "$(git rev-parse origin/main)" -m "the other approval")" |
| 694 | |
| 695 | arm_race "git -C '$origin' update-ref refs/the-valley/integration-requests/main/topic-six '$racer'" |
| 696 | |
| 697 | : > "$pushlog" |
| 698 | printf 'a\ns\n' > "$w/answers" |
| 699 | valley review -v topic/six < "$w/answers" > "$w/race.out" 2> "$w/race.err" |
| 700 | disarm_race |
| 701 | |
| 702 | # A refusal, named as one, and the review loop still usable after it. |
| 703 | grep -q "^⊘ topic/six not approved · another approval filed $(git rev-parse --short "$racer") (.*) meanwhile$" "$w/race.err" |
| 704 | grep -qx ' run: valley approve topic/six' "$w/race.err" |
| 705 | grep -q 'skipped topic/six; nothing done' "$w/race.out" |
| 706 | |
| 707 | # Nothing published. The winner's request stands untouched, the loser's |
| 708 | # evidence never reached origin, and origin saw no push at all — the lease |
| 709 | # refuses before any command is sent, which is what --atomic is worth. |
| 710 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-six)" \ |
| 711 | != "$racer" ]; then |
| 712 | echo "valley-request: the lease did not hold; the other approval was clobbered" >&2 |
| 713 | exit 1 |
| 714 | fi |
| 715 | if git -C "$origin" rev-parse --verify --quiet \ |
| 716 | "refs/the-valley/attestations/$sixdigest/$keyhash" > /dev/null; then |
| 717 | echo "valley-request: an approval that was refused published its evidence" >&2 |
| 718 | exit 1 |
| 719 | fi |
| 720 | if [ -s "$pushlog" ]; then |
| 721 | echo "valley-request: an approval that was refused reached origin's hook" >&2 |
| 722 | cat "$pushlog" >&2 |
| 723 | exit 1 |
| 724 | fi |
| 725 | |
| 726 | # The checks that were run are not lost with the refusal: their notes are |
| 727 | # in the operator's own repository, and the refusal says where. |
| 728 | git rev-parse --verify --quiet "refs/the-valley/attestations/$sixdigest/$keyhash" \ |
| 729 | > /dev/null || { |
| 730 | echo "valley-request: the refused approval kept no evidence locally" >&2 |
| 731 | exit 1 |
| 732 | } |
| 733 | grep -qx 'valley: the evidence is stored locally at:' "$w/race.err" |
| 734 | grep -qx " refs/the-valley/attestations/$sixdigest/$keyhash" "$w/race.err" |
| 735 | git checkout --quiet main |
| 736 | |
| 737 | # ---------------------------------------------------------------------- |
| 738 | # 12. Approving again at the same head. Evidence with a validity window |
| 739 | # expires while the tree stays the right tree, and the answer to that |
| 740 | # is a fresh observation over the same head. The request ref already |
| 741 | # names that head, so it is left out of the refspec entirely rather |
| 742 | # than pushed at the value origin already holds. |
| 743 | # |
| 744 | # The request is filed by hand here. Origin holding a request at this |
| 745 | # head is the whole of the state under test, and re-running [a]pprove to |
| 746 | # produce it would put a second-granular observation instant in the |
| 747 | # note: the same tree re-attested inside one second is the identical |
| 748 | # ref, and across a second boundary it is not. |
| 749 | git checkout --quiet -b topic/seven origin/main |
| 750 | echo "a readme approved twice" > docs/readme.md |
| 751 | git commit --quiet -am "a readme approved twice" |
| 752 | git push --quiet origin topic/seven |
| 753 | sevenhead="$(git rev-parse topic/seven)" |
| 754 | sevendigest="$(attest digest --rev topic/seven | cut -d: -f2)" |
| 755 | git push --quiet origin \ |
| 756 | "$sevenhead:refs/the-valley/integration-requests/main/topic-seven" |
| 757 | |
| 758 | : > "$pushlog" |
| 759 | printf 'a\n' > "$w/answers" |
| 760 | valley review -v topic/seven < "$w/answers" > "$w/seven.out" 2> "$w/seven.err" |
| 761 | |
| 762 | grep -q '^✓ topic/seven approved · ' "$w/seven.out" |
| 763 | grep -qx ' the request already stood at this head; the evidence is what was published' "$w/seven.out" |
| 764 | # The evidence went; the request ref was not in the refspec at all. |
| 765 | grep -q "refs/the-valley/attestations/$sevendigest/$keyhash" "$pushlog" |
| 766 | if grep -q 'refs/the-valley/integration-requests/main/topic-seven' "$pushlog"; then |
| 767 | echo "valley-request: a same-head re-approval pushed the request ref again" >&2 |
| 768 | cat "$pushlog" >&2 |
| 769 | exit 1 |
| 770 | fi |
| 771 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-seven)" \ |
| 772 | != "$sevenhead" ]; then |
| 773 | echo "valley-request: a same-head re-approval disturbed the request ref" >&2 |
| 774 | exit 1 |
| 775 | fi |
| 776 | |
| 777 | # The same head with nothing required: no evidence to publish and no ref to |
| 778 | # write, so no push is made at all. topic/quiet's request has stood on |
| 779 | # origin at this head since 5. A push assembled with an empty refspec |
| 780 | # would fall back to origin's default one, and pushing whatever that |
| 781 | # happens to name is not what approving a change means. |
| 782 | git checkout --quiet main |
| 783 | : > "$pushlog" |
| 784 | printf 'a\n' > "$w/answers" |
| 785 | env -u VALLEY_ATTEST_KEY valley review -v topic/quiet < "$w/answers" \ |
| 786 | > "$w/quiet-again.out" 2> "$w/quiet-again.err" |
| 787 | grep -qx " request refs/the-valley/integration-requests/main/topic-quiet -> $quiethead" "$w/quiet-again.out" |
| 788 | grep -qx ' the request already stood at this head and nothing was required, so nothing needed publishing' "$w/quiet-again.out" |
| 789 | if [ -s "$pushlog" ]; then |
| 790 | echo "valley-request: a re-approval with nothing to publish still pushed" >&2 |
| 791 | cat "$pushlog" >&2 |
| 792 | exit 1 |
| 793 | fi |
| 794 | |
| 795 | # ---------------------------------------------------------------------- |
| 796 | # 13. Two operators filing one change at once. Reading that the request |
| 797 | # ref is absent is a value like any other, and the lease covers it: |
| 798 | # git spells that expectation with an empty value and refuses if the |
| 799 | # ref exists at all. Unleased, this push would have fast-forwarded the |
| 800 | # other filing away without saying a word. |
| 801 | git checkout --quiet -b topic/eight origin/main |
| 802 | echo "a readme two operators both filed" > docs/readme.md |
| 803 | git commit --quiet -am "a readme two operators both filed" |
| 804 | git push --quiet origin topic/eight |
| 805 | eighthead="$(git rev-parse topic/eight)" |
| 806 | eightdigest="$(attest digest --rev topic/eight | cut -d: -f2)" |
| 807 | # The other operator's filing: this same tree on this same tip, which is |
| 808 | # what a second checkout of one branch produces. It is a descendant of |
| 809 | # nothing here, so an unleased push over it would be a plain fast-forward. |
| 810 | firstfiler="$(git -C "$origin" commit-tree "$(git rev-parse 'topic/eight^{tree}')" \ |
| 811 | -p "$(git rev-parse origin/main)" -m "the other operator's filing")" |
| 812 | |
| 813 | arm_race "git -C '$origin' update-ref refs/the-valley/integration-requests/main/topic-eight '$firstfiler'" |
| 814 | : > "$pushlog" |
| 815 | printf 'a\ns\n' > "$w/answers" |
| 816 | valley review topic/eight < "$w/answers" > "$w/create-race.out" 2> "$w/create-race.err" |
| 817 | disarm_race |
| 818 | |
| 819 | # The other operator's commit is on origin and not here, so the subject |
| 820 | # says so rather than inventing one. Scenario 10 pins the case where the |
| 821 | # replaced head IS local and its subject is printed. |
| 822 | grep -q "not approved · another approval filed $(git rev-parse --short "$firstfiler") (subject not in this repository) meanwhile" "$w/create-race.err" |
| 823 | grep -q 'skipped topic/eight; nothing done' "$w/create-race.out" |
| 824 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-eight)" \ |
| 825 | != "$firstfiler" ]; then |
| 826 | echo "valley-request: an unleased filing clobbered the request that got there first" >&2 |
| 827 | exit 1 |
| 828 | fi |
| 829 | if git -C "$origin" rev-parse --verify --quiet \ |
| 830 | "refs/the-valley/attestations/$eightdigest/$keyhash" > /dev/null; then |
| 831 | echo "valley-request: a refused filing published its evidence" >&2 |
| 832 | exit 1 |
| 833 | fi |
| 834 | if [ -s "$pushlog" ]; then |
| 835 | echo "valley-request: a refused filing reached origin's hook" >&2 |
| 836 | cat "$pushlog" >&2 |
| 837 | exit 1 |
| 838 | fi |
| 839 | |
| 840 | # ---------------------------------------------------------------------- |
| 841 | # 14. A lease that refuses because the ref is gone, not because it moved. |
| 842 | # The integrator consumes the request ref when the change lands, so an |
| 843 | # approval prepared just before that lands into a lease against a |
| 844 | # ref that no longer exists. Git reports it as stale info either way, |
| 845 | # and only reading the ref again tells the two apart — so the two are |
| 846 | # told apart, and the operator is pointed at the landing rather than |
| 847 | # at a race that did not happen. |
| 848 | git checkout --quiet main |
| 849 | git checkout --quiet -b topic/nine origin/main |
| 850 | echo "a readme that lands mid-approval" > docs/readme.md |
| 851 | git commit --quiet -am "a readme that lands mid-approval" |
| 852 | git push --quiet origin topic/nine |
| 853 | |
| 854 | printf 'a\n' > "$w/answers" |
| 855 | valley review topic/nine < "$w/answers" > "$w/nine-first.out" 2> "$w/nine-first.err" |
| 856 | grep -q '^✓ topic/nine approved · ' "$w/nine-first.out" |
| 857 | |
| 858 | git checkout --quiet main |
| 859 | echo "a fourth note" > docs/fourth.md |
| 860 | git add -A |
| 861 | git commit --quiet -m "a landing that moves main again" |
| 862 | git push --quiet origin main |
| 863 | git checkout --quiet topic/nine |
| 864 | git rebase --quiet main |
| 865 | git push --quiet --force-with-lease origin topic/nine |
| 866 | ninedigest="$(attest digest --rev topic/nine | cut -d: -f2)" |
| 867 | |
| 868 | arm_race "git -C '$origin' update-ref -d refs/the-valley/integration-requests/main/topic-nine" |
| 869 | : > "$pushlog" |
| 870 | printf 'a\ns\n' > "$w/answers" |
| 871 | valley review topic/nine < "$w/answers" > "$w/consumed.out" 2> "$w/consumed.err" |
| 872 | disarm_race |
| 873 | |
| 874 | grep -qx '⊘ topic/nine not approved · the pending request was consumed meanwhile' "$w/consumed.err" |
| 875 | grep -qx ' see: valley status topic/nine' "$w/consumed.err" |
| 876 | # Not reported as a race, which is the distinction the re-read buys. |
| 877 | if grep -q 'another approval filed' "$w/consumed.err"; then |
| 878 | echo "valley-request: a consumed request was reported as a lost race" >&2 |
| 879 | cat "$w/consumed.err" >&2 |
| 880 | exit 1 |
| 881 | fi |
| 882 | grep -q 'skipped topic/nine; nothing done' "$w/consumed.out" |
| 883 | if git -C "$origin" rev-parse --verify --quiet \ |
| 884 | refs/the-valley/integration-requests/main/topic-nine > /dev/null; then |
| 885 | echo "valley-request: an approval that was refused re-created the consumed request" >&2 |
| 886 | exit 1 |
| 887 | fi |
| 888 | if git -C "$origin" rev-parse --verify --quiet \ |
| 889 | "refs/the-valley/attestations/$ninedigest/$keyhash" > /dev/null; then |
| 890 | echo "valley-request: an approval that was refused published its evidence" >&2 |
| 891 | exit 1 |
| 892 | fi |
| 893 | if [ -s "$pushlog" ]; then |
| 894 | echo "valley-request: an approval that was refused reached origin's hook" >&2 |
| 895 | cat "$pushlog" >&2 |
| 896 | exit 1 |
| 897 | fi |
| 898 | |
| 899 | # ---------------------------------------------------------------------- |
| 900 | # 15. The same-head push carries no request ref, so it carries no |
| 901 | # compare-and-swap on one either — git leaves an up-to-date ref out of |
| 902 | # what it sends. Where the ref stands after that push is therefore not |
| 903 | # something the run established, and it is read again rather than |
| 904 | # asserted from the read before it. |
| 905 | # |
| 906 | # Nothing re-files it. A request for a change already in the stream is |
| 907 | # judged against an empty delta on every pass, which is why the |
| 908 | # integrator consumes the ref in the first place; re-creating it here |
| 909 | # would be a guess about which of consumption and deletion happened, |
| 910 | # paid for with a second push behind the one this verb promises. So |
| 911 | # the run says what is true and stops, and approving again is the repair. |
| 912 | git checkout --quiet main |
| 913 | git checkout --quiet -b topic/ten origin/main |
| 914 | echo "a readme consumed under the evidence" > docs/readme.md |
| 915 | git commit --quiet -am "a readme consumed under the evidence" |
| 916 | git push --quiet origin topic/ten |
| 917 | tenhead="$(git rev-parse topic/ten)" |
| 918 | tendigest="$(attest digest --rev topic/ten | cut -d: -f2)" |
| 919 | git push --quiet origin \ |
| 920 | "$tenhead:refs/the-valley/integration-requests/main/topic-ten" |
| 921 | |
| 922 | arm_race "git -C '$origin' update-ref -d refs/the-valley/integration-requests/main/topic-ten" |
| 923 | : > "$pushlog" |
| 924 | printf 'a\ns\n' > "$w/answers" |
| 925 | valley review -v topic/ten < "$w/answers" > "$w/posthoc.out" 2> "$w/posthoc.err" |
| 926 | disarm_race |
| 927 | |
| 928 | grep -qx '? topic/ten approved · request consumed meanwhile · see: valley status topic/ten' "$w/posthoc.out" |
| 929 | # The claim the old code would have made, from a read that had gone out of |
| 930 | # date under it. |
| 931 | if grep -q 'the request already stood at this head' "$w/posthoc.out"; then |
| 932 | echo "valley-request: a consumed request was reported as still standing" >&2 |
| 933 | cat "$w/posthoc.out" >&2 |
| 934 | exit 1 |
| 935 | fi |
| 936 | grep -q 'skipped topic/ten; nothing done' "$w/posthoc.out" |
| 937 | |
| 938 | # The evidence went, because that push succeeded; the request did not come |
| 939 | # back, because nothing here writes it. |
| 940 | git -C "$origin" rev-parse --verify --quiet \ |
| 941 | "refs/the-valley/attestations/$tendigest/$keyhash" > /dev/null || { |
| 942 | echo "valley-request: the evidence push was reported as done and is not on origin" >&2 |
| 943 | exit 1 |
| 944 | } |
| 945 | if git -C "$origin" rev-parse --verify --quiet \ |
| 946 | refs/the-valley/integration-requests/main/topic-ten > /dev/null; then |
| 947 | echo "valley-request: the consumed request was re-filed behind the operator" >&2 |
| 948 | exit 1 |
| 949 | fi |
| 950 | # And that evidence went in one push, which is still the whole claim. |
| 951 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 952 | if [ "$pushes" != 1 ]; then |
| 953 | echo "valley-request: the same-head re-approval took $pushes pushes, not 1" >&2 |
| 954 | cat "$pushlog" >&2 |
| 955 | exit 1 |
| 956 | fi |
| 957 | git checkout --quiet main |
| 958 | |
| 959 | # ---------------------------------------------------------------------- |
| 960 | # 16. A project other than the-valley carries no schema/. The schema ships |
| 961 | # with the tool, so the packaged CLI derives what a change requires |
| 962 | # and files the request from a checkout that has none. This is the case |
| 963 | # that failed in live use: [a]pprove in a valley's config repository, which |
| 964 | # carries its own floor at policy/instance, refused with "no policy |
| 965 | # schema" and published nothing. |
| 966 | cfgorigin="$TMPDIR/config.git" |
| 967 | git init --quiet --bare "$cfgorigin" |
| 968 | cfg="$TMPDIR/config" |
| 969 | git init --quiet "$cfg" |
| 970 | cd "$cfg" || exit 1 |
| 971 | git remote add origin "$cfgorigin" |
| 972 | mkdir -p docs policy/instance |
| 973 | cp "$valleywork/policy/instance/floor.cue" policy/instance/floor.cue |
| 974 | echo "the readme" > docs/readme.md |
| 975 | git add -A |
| 976 | git commit --quiet -m base |
| 977 | git push --quiet -u origin main |
| 978 | git checkout --quiet -b topic/config |
| 979 | echo "a config readme" > docs/readme.md |
| 980 | git commit --quiet -am "a config readme" |
| 981 | git push --quiet origin topic/config |
| 982 | cfgdigest="$(attest digest --rev topic/config | cut -d: -f2)" |
| 983 | |
| 984 | printf 'a\n' > "$w/answers" |
| 985 | valley review -v topic/config < "$w/answers" > "$w/config.out" 2> "$w/config.err" |
| 986 | if grep -q 'no policy schema' "$w/config.err"; then |
| 987 | echo "valley-request: [a]pprove looked for the schema in a project's checkout" >&2 |
| 988 | cat "$w/config.err" >&2 |
| 989 | exit 1 |
| 990 | fi |
| 991 | grep -q '^◐ topic/config checking 1 check: tree-ok$' "$w/config.out" |
| 992 | grep -q '^✓ topic/config approved · ' "$w/config.out" |
| 993 | git -C "$cfgorigin" rev-parse --verify --quiet \ |
| 994 | "refs/the-valley/attestations/$cfgdigest/$keyhash" > /dev/null || { |
| 995 | echo "valley-request: [a]pprove in a project without schema/ published no evidence" >&2 |
| 996 | exit 1 |
| 997 | } |
| 998 | if [ "$(git -C "$cfgorigin" rev-parse refs/the-valley/integration-requests/main/topic-config)" \ |
| 999 | != "$(git rev-parse topic/config)" ]; then |
| 1000 | echo "valley-request: [a]pprove in a project without schema/ filed no request for its head" >&2 |
| 1001 | exit 1 |
| 1002 | fi |
| 1003 | |
| 1004 | # checks without --schema reads the packaged schema too, and derives what |
| 1005 | # [a]pprove ran from this repository's own floor. |
| 1006 | valley checks > "$w/config-checks.out" 2> "$w/config-checks.err" |
| 1007 | grep -qF '(this repository is its own valley)' "$w/config-checks.out" |
| 1008 | grep -qE '^ tree-ok +mandatory +prose$' "$w/config-checks.out" |
| 1009 | |
| 1010 | # The packaged schema is a default and not a pin. A schema named in the |
| 1011 | # environment is the one read, and --schema overrides both. |
| 1012 | if VALLEY_VERIFICATION_SCHEMA="$TMPDIR/no-such-schema.cue" valley checks \ |
| 1013 | > "$w/envschema.out" 2> "$w/envschema.err"; then |
| 1014 | echo "valley-request: VALLEY_VERIFICATION_SCHEMA did not replace the packaged schema" >&2 |
| 1015 | exit 1 |
| 1016 | fi |
| 1017 | grep -qF "no policy schema at $TMPDIR/no-such-schema.cue" "$w/envschema.err" |
| 1018 | VALLEY_VERIFICATION_SCHEMA="$TMPDIR/no-such-schema.cue" valley checks --schema "$schemaFile" \ |
| 1019 | > "$w/flagschema.out" 2> "$w/flagschema.err" |
| 1020 | grep -qE '^ tree-ok +mandatory +prose$' "$w/flagschema.out" |
| 1021 | |
| 1022 | # bin/valley run straight from a checkout, with nothing setting the |
| 1023 | # variable, reads schema/verification.cue in that checkout. the-valley's own |
| 1024 | # tree carries one, as the first scratch project does, and every other |
| 1025 | # project's tree does not. |
| 1026 | if env -u VALLEY_VERIFICATION_SCHEMA bash "$cliScript" checks \ |
| 1027 | > "$w/bare-config.out" 2> "$w/bare-config.err"; then |
| 1028 | echo "valley-request: bin/valley run bare found a schema in a checkout without one" >&2 |
| 1029 | exit 1 |
| 1030 | fi |
| 1031 | grep -qF "no policy schema at $(git rev-parse --show-toplevel)/schema/verification.cue" \ |
| 1032 | "$w/bare-config.err" |
| 1033 | cd "$repo" || exit 1 |
| 1034 | env -u VALLEY_VERIFICATION_SCHEMA bash "$cliScript" checks "$first" topic/one \ |
| 1035 | > "$w/bare.out" 2> "$w/bare.err" |
| 1036 | grep -qE '^ tree-ok +mandatory +prose$' "$w/bare.out" |
| 1037 | |
| 1038 | # Every git call the default derivation makes fails closed: finding the |
| 1039 | # target, reading both layers out of its tip, reading the pointer, |
| 1040 | # fetching the owning valley, and the diff. fail-nth fails them one at a |
| 1041 | # time, and each run must end non-zero, say so, and print nothing on |
| 1042 | # stdout. The layer reads matter most here: a listing of policy/project |
| 1043 | # that failed, read as an empty directory, would derive under the floor |
| 1044 | # alone, and a read of origin/main that failed, read as no such ref, |
| 1045 | # would derive from the local main. |
| 1046 | shims="$TMPDIR/shims" |
| 1047 | mkdir -p "$shims" |
| 1048 | ln -s "$failNth" "$shims/git" |
| 1049 | shimmed_checks() { |
| 1050 | echo 0 > "$TMPDIR/shim-count" |
| 1051 | env -u VALLEY_VERIFICATION_SCHEMA SHIM_REAL_PATH="$PATH" SHIM_TOOL=git \ |
| 1052 | SHIM_FAIL_AT="$1" SHIM_STATUS=128 SHIM_COUNT="$TMPDIR/shim-count" \ |
| 1053 | PATH="$shims:$PATH" bash "$cliScript" checks "$first" topic/one |
| 1054 | } |
| 1055 | shimmed_checks 0 > "$w/shim-want.out" |
| 1056 | grep -qE '^ tree-ok +mandatory +prose$' "$w/shim-want.out" |
| 1057 | calls="$(cat "$TMPDIR/shim-count")" |
| 1058 | [ "$calls" -gt 0 ] || { |
| 1059 | echo "valley-request: the derivation never called git, so failing it proves nothing" >&2 |
| 1060 | exit 1 |
| 1061 | } |
| 1062 | for ((at = 1; at <= calls; at++)); do |
| 1063 | if shimmed_checks "$at" > "$w/shim.out" 2> "$w/shim.err" || [ -s "$w/shim.out" ] \ |
| 1064 | || ! grep -q '^valley: ' "$w/shim.err"; then |
| 1065 | echo "valley-request: git call $at of $calls failed, and the deriver did not refuse cleanly" >&2 |
| 1066 | cat "$w/shim.out" "$w/shim.err" >&2 |
| 1067 | exit 1 |
| 1068 | fi |
| 1069 | done |
| 1070 | |
| 1071 | # The same, for the derivation that resolves its own base: `merge-base` is |
| 1072 | # a call the explicit-base runs above never make, and --names is a second |
| 1073 | # way of printing what the derivation found. A run is shimmed for each |
| 1074 | # call, with the arguments the caller gives. |
| 1075 | defaulted_checks() { |
| 1076 | echo 0 > "$TMPDIR/shim-count" |
| 1077 | env -u VALLEY_VERIFICATION_SCHEMA SHIM_REAL_PATH="$PATH" SHIM_TOOL=git \ |
| 1078 | SHIM_FAIL_AT="$1" SHIM_STATUS=128 SHIM_COUNT="$TMPDIR/shim-count" \ |
| 1079 | PATH="$shims:$PATH" bash "$cliScript" checks "${@:2}" |
| 1080 | } |
| 1081 | git checkout --quiet topic/one |
| 1082 | for mode in report names; do |
| 1083 | margs=() |
| 1084 | [ "$mode" != names ] || margs=(--names) |
| 1085 | defaulted_checks 0 "${margs[@]}" > "$w/dshim-want.out" |
| 1086 | [ -s "$w/dshim-want.out" ] || { |
| 1087 | echo "valley-request: default resolution ($mode) printed nothing" >&2 |
| 1088 | exit 1 |
| 1089 | } |
| 1090 | calls="$(cat "$TMPDIR/shim-count")" |
| 1091 | sawmb=0 |
| 1092 | for ((at = 1; at <= calls; at++)); do |
| 1093 | if defaulted_checks "$at" "${margs[@]}" > "$w/dshim.out" 2> "$w/dshim.err" \ |
| 1094 | || [ -s "$w/dshim.out" ] || ! grep -q '^valley: ' "$w/dshim.err"; then |
| 1095 | echo "valley-request: default resolution ($mode): git call $at of $calls failed, and the deriver did not refuse cleanly" >&2 |
| 1096 | cat "$w/dshim.out" "$w/dshim.err" >&2 |
| 1097 | exit 1 |
| 1098 | fi |
| 1099 | done |
| 1100 | done |
| 1101 | git checkout --quiet - |
| 1102 | |
| 1103 | # A write that fails is a failure of the derivation, not a shorter list. |
| 1104 | # diff_paths runs with errexit off, so its printf is the case: the function |
| 1105 | # is cut out of the script and given a full disk to write to. |
| 1106 | fn="$(sed -n '/^diff_paths() {/,/^}/p' "$cliScript")" |
| 1107 | [ -n "$fn" ] || { echo "valley-request: diff_paths not found in the script" >&2; exit 1; } |
| 1108 | if ( |
| 1109 | eval "$fn" |
| 1110 | printf 'M\0docs/a.md\0R100\0old\0new\0' | diff_paths > /dev/full |
| 1111 | ) 2> "$w/full.err"; then |
| 1112 | echo "valley-request: diff_paths returned 0 after its write failed" >&2 |
| 1113 | exit 1 |
| 1114 | fi |
| 1115 | # And end to end: with no file allowed to grow, every intermediate file the |
| 1116 | # derivation writes fails, and nothing may print. The pipe keeps the |
| 1117 | # refusal readable, since a file stream would be cut off too. |
| 1118 | for mode in report names; do |
| 1119 | margs=() |
| 1120 | [ "$mode" != names ] || margs=(--names) |
| 1121 | if wrote="$( |
| 1122 | ulimit -f 0 |
| 1123 | trap '' XFSZ |
| 1124 | env -u VALLEY_VERIFICATION_SCHEMA bash "$cliScript" checks "${margs[@]}" "$first" topic/one 2> /dev/null |
| 1125 | )" || [ -n "$wrote" ]; then |
| 1126 | echo "valley-request: a derivation with unwritable scratch files ($mode) did not fail cleanly" >&2 |
| 1127 | printf '%s\n' "$wrote" >&2 |
| 1128 | exit 1 |
| 1129 | fi |
| 1130 | done |
| 1131 | |
| 1132 | # ---------------------------------------------------------------------- |
| 1133 | # 17. The approve verb: [a]pprove without the pager, for a front end that |
| 1134 | # has shown the change its own way. It runs the function the key |
| 1135 | # runs, so it publishes what the key's session in 1 published, the |
| 1136 | # evidence and the request in one push, and prints what that session |
| 1137 | # printed. stdin is closed, because no answer is read, and the change |
| 1138 | # is named the way status accepts it, with origin/ in front. |
| 1139 | git checkout --quiet -b topic/verb origin/main |
| 1140 | echo "a readme approved without the pager" > docs/readme.md |
| 1141 | git commit --quiet -am "a readme approved without the pager" |
| 1142 | git push --quiet origin topic/verb |
| 1143 | verbhead="$(git rev-parse topic/verb)" |
| 1144 | verbdigest="$(attest digest --rev topic/verb | cut -d: -f2)" |
| 1145 | git checkout --quiet main |
| 1146 | |
| 1147 | : > "$pushlog" |
| 1148 | valley approve -v origin/topic/verb < /dev/null > "$w/verb.out" 2> "$w/verb.err" |
| 1149 | grep -q '◐ topic/verb checking 1 check: tree-ok' "$w/verb.out" |
| 1150 | grep -qx '✓ topic/verb approved · 1 check passed in [0-9]*s · landing on main' "$w/verb.out" |
| 1151 | grep -qx " request refs/the-valley/integration-requests/main/topic-verb -> $(git rev-parse --short "$verbhead")" "$w/verb.out" |
| 1152 | grep -qx " evidence refs/the-valley/attestations/$verbdigest/$keyhash" "$w/verb.out" |
| 1153 | grep -qx ' checks tree-ok' "$w/verb.out" |
| 1154 | if grep -q '\[[a-z]\]' "$w/verb.out"; then |
| 1155 | echo "valley-request: the approve verb offered a prompt" >&2 |
| 1156 | cat "$w/verb.out" >&2 |
| 1157 | exit 1 |
| 1158 | fi |
| 1159 | if [ "$(git -C "$origin" rev-parse refs/the-valley/integration-requests/main/topic-verb)" \ |
| 1160 | != "$verbhead" ]; then |
| 1161 | echo "valley-request: the approve verb's request does not name the branch's head" >&2 |
| 1162 | exit 1 |
| 1163 | fi |
| 1164 | git -C "$origin" rev-parse --verify --quiet \ |
| 1165 | "refs/the-valley/attestations/$verbdigest/$keyhash" > /dev/null || { |
| 1166 | echo "valley-request: the approve verb published no evidence" >&2 |
| 1167 | exit 1 |
| 1168 | } |
| 1169 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 1170 | if [ "$pushes" != 1 ]; then |
| 1171 | echo "valley-request: the approve verb took $pushes pushes, not 1" >&2 |
| 1172 | cat "$pushlog" >&2 |
| 1173 | exit 1 |
| 1174 | fi |
| 1175 | |
| 1176 | # A refusal is the verb's exit status, after the same words the key's |
| 1177 | # refusal prints, and it publishes nothing. |
| 1178 | : > "$pushlog" |
| 1179 | if valley approve -v topic/two < /dev/null > "$w/verb-refused.out" 2> "$w/verb-refused.err"; then |
| 1180 | echo "valley-request: the approve verb exited 0 for a change whose check failed" >&2 |
| 1181 | exit 1 |
| 1182 | fi |
| 1183 | grep -q '^⊘ topic/two not approved · 1 of [0-9]* checks* failed$' "$w/verb-refused.err" |
| 1184 | if [ -s "$pushlog" ]; then |
| 1185 | echo "valley-request: a refused approve verb pushed something" >&2 |
| 1186 | cat "$pushlog" >&2 |
| 1187 | exit 1 |
| 1188 | fi |
| 1189 | if valley approve -v topic/no-such-change < /dev/null > "$w/verb-missing.out" 2> "$w/verb-missing.err"; then |
| 1190 | echo "valley-request: the approve verb exited 0 for a change origin does not have" >&2 |
| 1191 | exit 1 |
| 1192 | fi |
| 1193 | grep -q 'no such branch on origin: topic/no-such-change' "$w/verb-missing.err" |
| 1194 | |
| 1195 | # ---------------------------------------------------------------------- |
| 1196 | # 17b. Timing never stands in the way of approval. A FIFO nobody reads, |
| 1197 | # sitting at the timing log's path, would hold an open for writing |
| 1198 | # forever: the log is refused with a warning, and approval goes on. |
| 1199 | # With standard error a pipe nobody reads as well, the warning is |
| 1200 | # dropped rather than ending the run. Both runs keep a state |
| 1201 | # directory of their own, so the log the other cases read is not |
| 1202 | # touched. |
| 1203 | fifostate="$w/fifo-state" |
| 1204 | mkdir -p "$fifostate/valley" |
| 1205 | mkfifo "$fifostate/valley/timings.jsonl" |
| 1206 | approved_past_fifo() { |
| 1207 | if [ "$(git -C "$origin" rev-parse "refs/the-valley/integration-requests/main/topic-$1")" \ |
| 1208 | != "$(git rev-parse "topic/$1")" ]; then |
| 1209 | echo "valley-request: approving past a FIFO at the timing log filed no request ($2)" >&2 |
| 1210 | exit 1 |
| 1211 | fi |
| 1212 | git -C "$origin" rev-parse --verify --quiet \ |
| 1213 | "refs/the-valley/attestations/$(attest digest --rev "topic/$1" | cut -d: -f2)/$keyhash" > /dev/null || { |
| 1214 | echo "valley-request: approving past a FIFO at the timing log published no evidence ($2)" >&2 |
| 1215 | exit 1 |
| 1216 | } |
| 1217 | } |
| 1218 | for branch in fifo unread; do |
| 1219 | git checkout --quiet -b "topic/$branch" origin/main |
| 1220 | echo "a readme approved past a FIFO, $branch" > docs/readme.md |
| 1221 | git commit --quiet -am "a readme approved past a FIFO, $branch" |
| 1222 | git push --quiet origin "topic/$branch" |
| 1223 | git checkout --quiet main |
| 1224 | done |
| 1225 | |
| 1226 | XDG_STATE_HOME="$fifostate" timeout 120 valley approve -v origin/topic/fifo \ |
| 1227 | < /dev/null > "$w/fifo.out" 2> "$w/fifo.err" || { |
| 1228 | echo "valley-request: approve did not finish past a FIFO at the timing log (exit $?):" >&2 |
| 1229 | cat "$w/fifo.out" "$w/fifo.err" >&2 |
| 1230 | exit 1 |
| 1231 | } |
| 1232 | grep -qE '^time tree-ok +passed +[0-9][0-9.hms]* \(ran\)$' "$w/fifo.out" |
| 1233 | grep -qx "attest: warning: timings not logged: $fifostate/valley/timings.jsonl is not a regular file" "$w/fifo.err" |
| 1234 | approved_past_fifo fifo "standard error read" |
| 1235 | |
| 1236 | # A pipe with no reader. The FIFO is opened to read and write, so opening it |
| 1237 | # to write does not wait; closing the first leaves the writer alone. |
| 1238 | mkfifo "$w/unread" |
| 1239 | exec 3<> "$w/unread" |
| 1240 | exec 4> "$w/unread" |
| 1241 | exec 3<&- |
| 1242 | status=0 |
| 1243 | XDG_STATE_HOME="$fifostate" timeout 120 valley approve -v origin/topic/unread \ |
| 1244 | < /dev/null > "$w/unread.out" 2>&4 || status=$? |
| 1245 | exec 4>&- |
| 1246 | if [ "$status" != 0 ]; then |
| 1247 | echo "valley-request: approve with nobody reading standard error exited $status:" >&2 |
| 1248 | cat "$w/unread.out" >&2 |
| 1249 | exit 1 |
| 1250 | fi |
| 1251 | approved_past_fifo unread "standard error unread" |
| 1252 | |
| 1253 | # ---------------------------------------------------------------------- |
| 1254 | # 18. The rebase verb: [b]ase without the pager. A stale branch is |
| 1255 | # rebased onto main in a throwaway worktree and pushed under a lease, |
| 1256 | # and the new head is printed. Nothing is approved and nothing is |
| 1257 | # re-reviewed: rebasing is mechanics, and the judgment on what it |
| 1258 | # produced stays with whoever reads it next. |
| 1259 | git checkout --quiet -b topic/behind "$first" |
| 1260 | echo "a readme left behind" > docs/behind.md |
| 1261 | git add -A |
| 1262 | git commit --quiet -m "a readme left behind" |
| 1263 | git push --quiet origin topic/behind |
| 1264 | behindhead="$(git rev-parse topic/behind)" |
| 1265 | git checkout --quiet main |
| 1266 | if git -C "$origin" merge-base --is-ancestor refs/heads/main refs/heads/topic/behind; then |
| 1267 | echo "valley-request: the branch to rebase fast-forwarded from main already" >&2 |
| 1268 | exit 1 |
| 1269 | fi |
| 1270 | before_rebase="$(git -C "$origin" rev-parse refs/heads/main)" |
| 1271 | |
| 1272 | : > "$pushlog" |
| 1273 | valley rebase topic/behind < /dev/null > "$w/rebase.out" 2> "$w/rebase.err" |
| 1274 | rebased="$(git -C "$origin" rev-parse refs/heads/topic/behind)" |
| 1275 | grep -qx 'rebased topic/behind onto origin/main, pushed with --force-with-lease' "$w/rebase.out" |
| 1276 | grep -qx " head $rebased" "$w/rebase.out" |
| 1277 | if [ "$rebased" = "$behindhead" ]; then |
| 1278 | echo "valley-request: the rebase verb left the branch where it was" >&2 |
| 1279 | exit 1 |
| 1280 | fi |
| 1281 | git -C "$origin" merge-base --is-ancestor refs/heads/main "$rebased" || { |
| 1282 | echo "valley-request: the rebased head does not fast-forward from main" >&2 |
| 1283 | exit 1 |
| 1284 | } |
| 1285 | if [ "$(git -C "$origin" rev-parse refs/heads/main)" != "$before_rebase" ]; then |
| 1286 | echo "valley-request: the rebase verb moved main" >&2 |
| 1287 | exit 1 |
| 1288 | fi |
| 1289 | if git -C "$origin" rev-parse --verify --quiet \ |
| 1290 | refs/the-valley/integration-requests/main/topic-behind > /dev/null; then |
| 1291 | echo "valley-request: the rebase verb filed a request" >&2 |
| 1292 | exit 1 |
| 1293 | fi |
| 1294 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 1295 | if [ "$pushes" != 1 ] || grep -v '^--- push' "$pushlog" | grep -qv ' refs/heads/topic/behind$'; then |
| 1296 | echo "valley-request: the rebase verb pushed something besides the branch" >&2 |
| 1297 | cat "$pushlog" >&2 |
| 1298 | exit 1 |
| 1299 | fi |
| 1300 | |
| 1301 | # A branch that fast-forwards from main already is left as it is. |
| 1302 | : > "$pushlog" |
| 1303 | valley rebase topic/behind < /dev/null > "$w/rebase-again.out" 2> "$w/rebase-again.err" |
| 1304 | grep -qx 'topic/behind already fast-forwards from origin/main; nothing rebased' "$w/rebase-again.out" |
| 1305 | grep -qx " head $rebased" "$w/rebase-again.out" |
| 1306 | if [ -s "$pushlog" ]; then |
| 1307 | echo "valley-request: rebasing a branch that fast-forwards pushed something" >&2 |
| 1308 | cat "$pushlog" >&2 |
| 1309 | exit 1 |
| 1310 | fi |
| 1311 | |
| 1312 | # A rebase that conflicts changes nothing, says so, and exits non-zero. |
| 1313 | git checkout --quiet -b topic/clash "$first" |
| 1314 | echo "a note that clashes" > docs/notes.md |
| 1315 | git add -A |
| 1316 | git commit --quiet -m "a note that clashes" |
| 1317 | git push --quiet origin topic/clash |
| 1318 | clashhead="$(git rev-parse topic/clash)" |
| 1319 | git checkout --quiet main |
| 1320 | if valley rebase topic/clash < /dev/null > "$w/clash.out" 2> "$w/clash.err"; then |
| 1321 | echo "valley-request: a rebase that conflicts exited 0" >&2 |
| 1322 | exit 1 |
| 1323 | fi |
| 1324 | grep -q 'topic/clash conflicts with main — resolve by hand; nothing changed' "$w/clash.err" |
| 1325 | if [ "$(git -C "$origin" rev-parse refs/heads/topic/clash)" != "$clashhead" ]; then |
| 1326 | echo "valley-request: a rebase that conflicted moved the branch" >&2 |
| 1327 | exit 1 |
| 1328 | fi |
| 1329 | |
| 1330 | # ---------------------------------------------------------------------- |
| 1331 | # 19. A change whose version names no branch is approved at its head like |
| 1332 | # any other. The record allows a version with no branch, though valley |
| 1333 | # ready always names one, so the record here is written by hand. The |
| 1334 | # check it requires runs over the recorded head, and the evidence and the |
| 1335 | # c-<change ID> request reach origin in one push. |
| 1336 | git checkout --quiet -b branchless main |
| 1337 | echo "a readme no branch carries" > docs/readme.md |
| 1338 | git commit --quiet -am "a readme no branch carries" |
| 1339 | barehead="$(git rev-parse HEAD)" |
| 1340 | baredigest="$(attest digest --rev "$barehead" | cut -d: -f2)" |
| 1341 | git checkout --quiet main |
| 1342 | bareid=rrrrssssttttuuuuvvvvwwwwxxxxyyyy |
| 1343 | blob="$(printf '{"schema": "valley-change-record/v1", "change_id": "%s", "target": "main", "owner": "contributor", "state": "ready", "seq": 1, "versions": [{"n": 1, "head": "git-sha1:%s", "title": "no branch", "branch": "", "uploader": "contributor"}], "active": 1}\n' \ |
| 1344 | "$bareid" "$barehead" | git hash-object -w --stdin)" |
| 1345 | record="$(git commit-tree "$(printf '100644 blob %s\trecord.json\n' "$blob" | git mktree)" \ |
| 1346 | -p "$barehead" -m 'a change record')" |
| 1347 | git push --quiet origin "$record:refs/the-valley/changes/main/$bareid" |
| 1348 | |
| 1349 | : > "$pushlog" |
| 1350 | valley approve -v --head "$barehead" rrrr < /dev/null > "$w/branchless.out" 2> "$w/branchless.err" |
| 1351 | grep -qx '◐ rrrr v1 checking 1 check: tree-ok' "$w/branchless.out" |
| 1352 | grep -qx " request refs/the-valley/integration-requests/main/c-$bareid -> $(git rev-parse --short "$barehead")" "$w/branchless.out" |
| 1353 | grep -qx " evidence refs/the-valley/attestations/$baredigest/$keyhash" "$w/branchless.out" |
| 1354 | if [ "$(git -C "$origin" rev-parse "refs/the-valley/integration-requests/main/c-$bareid")" != "$barehead" ]; then |
| 1355 | echo "valley-request: approve of a change with no branch did not file its head" >&2 |
| 1356 | exit 1 |
| 1357 | fi |
| 1358 | pushes="$(grep -c '^--- push' "$pushlog" || true)" |
| 1359 | if [ "$pushes" != 1 ] \ |
| 1360 | || ! grep -q "refs/the-valley/attestations/$baredigest/$keyhash" "$pushlog" \ |
| 1361 | || ! grep -q "refs/the-valley/integration-requests/main/c-$bareid" "$pushlog"; then |
| 1362 | echo "valley-request: the evidence and request for a change with no branch did not go in one push" >&2 |
| 1363 | cat "$pushlog" >&2 |
| 1364 | exit 1 |
| 1365 | fi |
| 1366 | # A change with a record is timed under its ID and the version approved. |
| 1367 | if ! tail -n 1 "$timings" | jq -e --arg id "$bareid" --arg head "$barehead" \ |
| 1368 | '.change == $id and .version == 1 and .head == $head and .check == "tree-ok"' > /dev/null; then |
| 1369 | echo "valley-request: the timing of a change with a record does not name the change and version:" >&2 |
| 1370 | tail -n 1 "$timings" >&2 |
| 1371 | exit 1 |
| 1372 | fi |
| 1373 | |
| 1374 | # ---------------------------------------------------------------------- |
| 1375 | # 20. Evidence origin already holds is reused, and only what is missing |
| 1376 | # runs here. A check worker publishes evidence as this section's |
| 1377 | # worker does: attest run under its own key, then a push of the |
| 1378 | # attestation ref alone. This origin runs the protected host's real |
| 1379 | # pre-receive hook, which admits a note only when a key it knows signed |
| 1380 | # it, behind a wrapper that logs every push it receives. The project's |
| 1381 | # owning valley publishes the signers a client verifies with, at |
| 1382 | # refs/the-valley/signers, written on disk as the host's publisher |
| 1383 | # writes it (signers-e2e drives the publisher itself). Both of the |
| 1384 | # project's checks use the nix runner, through integrator-e2e's |
| 1385 | # stand-in for nix, wrapped so that every call is logged: a check that |
| 1386 | # ran is a check the log shows a build of. |
| 1387 | r="$w/reuse" |
| 1388 | mkdir -p "$r/bin" "$r/keys" |
| 1389 | cp -r "$integratorE2e" "$r/stand-ins" |
| 1390 | chmod -R +w "$r/stand-ins" |
| 1391 | patchShebangs "$r/stand-ins" > /dev/null |
| 1392 | nixlog="$r/nix.log" |
| 1393 | for tool in nix nix-store; do |
| 1394 | cat > "$r/bin/$tool" <<EOF |
| 1395 | #!$(command -v bash) |
| 1396 | printf '%s %s\n' "$tool" "\$*" >> "$nixlog" |
| 1397 | exec "$r/stand-ins/$tool" "\$@" |
| 1398 | EOF |
| 1399 | chmod +x "$r/bin/$tool" |
| 1400 | done |
| 1401 | export PATH="$r/bin:$PATH" VALLEY_FAKE_STORE="$r/store" |
| 1402 | |
| 1403 | for who in worker operator integrator; do install -m 600 "$reuseKeys/$who" "$r/keys/$who"; done |
| 1404 | workername=worker.valley.invalid/attestations |
| 1405 | operatorname=operator.valley.invalid/attestations |
| 1406 | integratorname=integrator.valley.invalid/attestations |
| 1407 | workerhash="$(attest key --key "$r/keys/worker" --name "$workername" | cut -d+ -f2)" |
| 1408 | operatorhash="$(attest key --key "$r/keys/operator" --name "$operatorname" | cut -d+ -f2)" |
| 1409 | { |
| 1410 | attest key --key "$r/keys/worker" --name "$workername" |
| 1411 | attest key --key "$r/keys/operator" --name "$operatorname" |
| 1412 | attest key --key "$r/keys/integrator" --name "$integratorname" |
| 1413 | } > "$r/known-signers" |
| 1414 | |
| 1415 | # The owning valley: the floor, which requires nothing, and the signers it |
| 1416 | # publishes. |
| 1417 | instance="$r/instance.git" |
| 1418 | git init --quiet --bare "$instance" |
| 1419 | git init --quiet "$r/seed" |
| 1420 | mkdir -p "$r/seed/policy/instance" "$r/floor" |
| 1421 | printf 'package verification\n\nfloor: {\n\tchecks: {}\n\tclasses: {}\n\tunclassified: {}\n}\n' > "$r/floor/floor.cue" |
| 1422 | cp "$r/floor/floor.cue" "$r/seed/policy/instance/" |
| 1423 | git -C "$r/seed" add -A |
| 1424 | git -C "$r/seed" commit --quiet -m 'the floor' |
| 1425 | git -C "$r/seed" push --quiet "$instance" main |
| 1426 | # published <file> [<mode> <type> <object>]: the instance publishes the |
| 1427 | # known-signers file, and, given an entry, that entry as signer-projects. |
| 1428 | published() { |
| 1429 | local keysblob nameblob entries |
| 1430 | keysblob="$(git -C "$instance" hash-object -w "$1")" |
| 1431 | nameblob="$(printf '%s\n' "$integratorname" | git -C "$instance" hash-object -w --stdin)" |
| 1432 | entries="$(printf '100644 blob %s\tintegrator-name\n100644 blob %s\tknown-signers' "$nameblob" "$keysblob")" |
| 1433 | [ $# -lt 4 ] || entries+="$(printf '\n%s %s %s\tsigner-projects' "$2" "$3" "$4")" |
| 1434 | git -C "$instance" update-ref refs/the-valley/signers "$(printf '%s\n' "$entries" | git -C "$instance" mktree)" |
| 1435 | } |
| 1436 | published "$r/known-signers" |
| 1437 | |
| 1438 | served="$r/project.git" |
| 1439 | hook="$(grep -o '/nix/store/[^ ]*-valley-protect-open' "$reuseInitScriptPath" | head -n1)" |
| 1440 | test -x "$hook" |
| 1441 | git init --quiet --bare "$served" |
| 1442 | reusepushes="$r/pushlog" |
| 1443 | cat > "$served/hooks/pre-receive" <<EOF |
| 1444 | #!/bin/sh |
| 1445 | echo '--- push' >> "$reusepushes" |
| 1446 | tee -a "$reusepushes" | "$hook" |
| 1447 | EOF |
| 1448 | chmod +x "$served/hooks/pre-receive" |
| 1449 | |
| 1450 | proj="$r/project" |
| 1451 | git init --quiet "$proj" |
| 1452 | cd "$proj" || exit 1 |
| 1453 | git remote add origin "$served" |
| 1454 | mkdir -p docs src live checks policy/project |
| 1455 | echo "$instance" > policy/valley |
| 1456 | echo "the readme" > docs/readme.md |
| 1457 | echo "the source" > src/main.txt |
| 1458 | echo "the state" > live/state.txt |
| 1459 | echo docs > checks/prose-format.inputs |
| 1460 | echo src > checks/code-build.inputs |
| 1461 | cat > policy/project/policy.cue <<'EOF' |
| 1462 | package verification |
| 1463 | |
| 1464 | project: { |
| 1465 | checks: { |
| 1466 | "prose-format": {runner: "nix", attribute: "prose-format"} |
| 1467 | "code-build": {runner: "nix", attribute: "code-build"} |
| 1468 | "live-ok": {runner: "command", command: "true", validity: "1h"} |
| 1469 | } |
| 1470 | classes: { |
| 1471 | prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 1472 | code: {paths: "src/**": true, requires: "code-build": true} |
| 1473 | live: {paths: "live/**": true, requires: "live-ok": true} |
| 1474 | } |
| 1475 | unclassified: {} |
| 1476 | } |
| 1477 | EOF |
| 1478 | git add -A |
| 1479 | git commit --quiet -m 'seed the project' |
| 1480 | git push --quiet origin main |
| 1481 | git clone --quiet "$served" "$r/worker" |
| 1482 | |
| 1483 | # edited <branch> <file…>: a branch off origin's main that adds a line to |
| 1484 | # each file, pushed. |
| 1485 | edited() { |
| 1486 | local name="$1" f |
| 1487 | shift |
| 1488 | git fetch --quiet origin |
| 1489 | git checkout --quiet -B "$name" origin/main |
| 1490 | for f in "$@"; do echo "$name" >> "$f"; done |
| 1491 | git add -A |
| 1492 | git commit --quiet -m "$name" |
| 1493 | git push --quiet origin "$name" |
| 1494 | } |
| 1495 | # worker <head> <attest run flag…>: the worker attests the head under its |
| 1496 | # own key and pushes the attestation ref alone. |
| 1497 | worker() { |
| 1498 | local head="$1" digest ref |
| 1499 | shift |
| 1500 | git -C "$r/worker" fetch --quiet origin |
| 1501 | digest="$(attest digest --repo "$r/worker" --rev "$head" | cut -d: -f2)" |
| 1502 | ref="refs/the-valley/attestations/$digest/$workerhash" |
| 1503 | attest run --repo "$r/worker" --rev "$head" --key "$r/keys/worker" --name "$workername" "$@" \ |
| 1504 | > "$r/worker.out" 2>&1 || { |
| 1505 | echo "valley-request: the worker's attest run failed" >&2 |
| 1506 | cat "$r/worker.out" >&2 |
| 1507 | exit 1 |
| 1508 | } |
| 1509 | git -C "$r/worker" push --quiet origin "$ref:$ref" |
| 1510 | } |
| 1511 | # approving <name> <command…>: run the command as the principal that holds |
| 1512 | # the approve grant, signing as the operator, into <name>.out and .err in |
| 1513 | # the scratch directory. Origin's pushes and the nix log start empty. |
| 1514 | approving() { |
| 1515 | local name="$1" |
| 1516 | shift |
| 1517 | : > "$nixlog" |
| 1518 | : > "$reusepushes" |
| 1519 | VALLEY_PRINCIPAL=requester VALLEY_ATTEST_KEY="$r/keys/operator" VALLEY_ATTEST_NAME="$operatorname" \ |
| 1520 | "$@" < /dev/null > "$w/$name.out" 2> "$w/$name.err" |
| 1521 | } |
| 1522 | # requested <branch>: where origin's request for the branch stands, or |
| 1523 | # nothing. |
| 1524 | requested() { |
| 1525 | git -C "$served" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/$1" || true |
| 1526 | } |
| 1527 | # integrated <request> [<signer projects file>]: one pass of the real |
| 1528 | # integrator, given the file when there is one, lands the request. |
| 1529 | integrated() { |
| 1530 | integrator reconcile --repo "$served" --key "$r/keys/integrator" --name "$integratorname" \ |
| 1531 | --known-signers "$r/known-signers" ${2:+--signer-projects "$2"} --instance "$r/floor" --schema "$schemaFile" \ |
| 1532 | --attest-schema "$attestSchema" --event-schema "$eventSchema" > "$r/integrator.out" 2>&1 || { |
| 1533 | echo "valley-request: the integrator failed" >&2 |
| 1534 | cat "$r/integrator.out" >&2 |
| 1535 | exit 1 |
| 1536 | } |
| 1537 | grep -q "^$1 -> refs/heads/main .*: land\$" "$r/integrator.out" || { |
| 1538 | echo "valley-request: the integrator did not land $1" >&2 |
| 1539 | cat "$r/integrator.out" >&2 |
| 1540 | exit 1 |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | # 20a. The worker covered every required check. approve reuses both, runs |
| 1545 | # nothing, needs no signing key, and pushes the request alone. |
| 1546 | edited cover docs/readme.md src/main.txt |
| 1547 | coverhead="$(git rev-parse cover)" |
| 1548 | coverdigest="$(attest digest --rev cover | cut -d: -f2)" |
| 1549 | worker "$coverhead" --check prose-format --check code-build |
| 1550 | approving cover env -u VALLEY_ATTEST_KEY valley approve -v origin/cover |
| 1551 | grep -q "^reusing the evidence origin holds for cover at $(git rev-parse --short cover), tree " "$w/cover.out" |
| 1552 | grep -qE "^ prose-format +signed by $workername\+$workerhash\$" "$w/cover.out" |
| 1553 | grep -qE "^ code-build +signed by $workername\+$workerhash\$" "$w/cover.out" |
| 1554 | grep -qx " reused refs/the-valley/attestations/$coverdigest/$workerhash" "$w/cover.out" |
| 1555 | grep -qx ' checks code-build, prose-format' "$w/cover.out" |
| 1556 | if grep -qE '^(checking| evidence) ' "$w/cover.out" || [ -s "$nixlog" ]; then |
| 1557 | echo "valley-request: approve ran checks that origin's evidence covered" >&2 |
| 1558 | cat "$w/cover.out" "$nixlog" >&2 |
| 1559 | exit 1 |
| 1560 | fi |
| 1561 | [ "$(requested cover)" = "$coverhead" ] || { |
| 1562 | echo "valley-request: a fully covered approval filed no request" >&2 |
| 1563 | exit 1 |
| 1564 | } |
| 1565 | if [ "$(grep -c '^--- push' "$reusepushes")" != 1 ] \ |
| 1566 | || ! grep -q ' refs/the-valley/integration-requests/main/cover$' "$reusepushes" \ |
| 1567 | || grep -q ' refs/the-valley/attestations/' "$reusepushes"; then |
| 1568 | echo "valley-request: a fully covered approval did not push the request alone" >&2 |
| 1569 | cat "$reusepushes" >&2 |
| 1570 | exit 1 |
| 1571 | fi |
| 1572 | |
| 1573 | # 20b. The same head again: the evidence is on origin and the request |
| 1574 | # stands, so there is nothing to push and no push is made. |
| 1575 | approving cover-again env -u VALLEY_ATTEST_KEY valley approve -v origin/cover |
| 1576 | grep -qx ' the request already stood at this head and origin already held the evidence, so nothing needed publishing' "$w/cover-again.out" |
| 1577 | if [ -s "$reusepushes" ] || [ -s "$nixlog" ]; then |
| 1578 | echo "valley-request: approving a covered head again pushed or ran something" >&2 |
| 1579 | cat "$reusepushes" "$nixlog" >&2 |
| 1580 | exit 1 |
| 1581 | fi |
| 1582 | # The integrator verifies the worker's evidence itself, and lands it. |
| 1583 | integrated cover |
| 1584 | |
| 1585 | # 20c. The request write stays leased when nothing runs: a request filed |
| 1586 | # while this approval is prepared wins, and nothing is published. |
| 1587 | edited raced docs/readme.md |
| 1588 | racedhead="$(git rev-parse raced)" |
| 1589 | worker "$racedhead" --check prose-format |
| 1590 | arm_race "git -C '$served' update-ref refs/the-valley/integration-requests/main/raced '$coverhead'" |
| 1591 | if approving raced env -u VALLEY_ATTEST_KEY valley approve -v origin/raced; then |
| 1592 | echo "valley-request: a covered approval clobbered a request filed during it" >&2 |
| 1593 | exit 1 |
| 1594 | fi |
| 1595 | disarm_race |
| 1596 | grep -q "^⊘ raced not approved · another approval filed $(git rev-parse --short "$coverhead") (.*) meanwhile$" "$w/raced.err" |
| 1597 | if [ "$(requested raced)" != "$coverhead" ] || [ -s "$reusepushes" ]; then |
| 1598 | echo "valley-request: a covered approval that lost the lease published something" >&2 |
| 1599 | exit 1 |
| 1600 | fi |
| 1601 | git -C "$served" update-ref -d refs/the-valley/integration-requests/main/raced |
| 1602 | |
| 1603 | # 20d. The worker covered one check and has no note for the other. A worker |
| 1604 | # note for the other check that names another flake attribute is not |
| 1605 | # reused either (the attribute case below), and the integrator |
| 1606 | # refuses it too. Without --build-here, approve |
| 1607 | # files the request at once with the evidence origin holds: it builds |
| 1608 | # nothing, pushes the request alone, names the missing check, and |
| 1609 | # exits 0. review's [a]pprove files the same way. Each request is |
| 1610 | # taken away again before the integrator reads it. With --build-here, |
| 1611 | # that check runs here: exactly that one, signed by the operator, in |
| 1612 | # one push with the request. The integrator lands it on the two |
| 1613 | # signers' evidence. 21f has the integrator hold a request filed |
| 1614 | # without evidence, and land it once the evidence arrives. |
| 1615 | edited partial docs/readme.md src/main.txt |
| 1616 | partialhead="$(git rev-parse partial)" |
| 1617 | partialdigest="$(attest digest --rev partial | cut -d: -f2)" |
| 1618 | worker "$partialhead" --check prose-format |
| 1619 | for filed in partial-filed partial-review; do |
| 1620 | if [ "$filed" = partial-filed ]; then |
| 1621 | approving "$filed" valley approve -v origin/partial |
| 1622 | else |
| 1623 | approving "$filed" bash -c 'printf "a\n" | valley review -v origin/partial' |
| 1624 | fi |
| 1625 | if ! grep -qx '◇ partial approved · waiting for 1 check (no worker building)' "$w/$filed.out" \ |
| 1626 | || ! grep -qx ' run: valley approve --build-here partial' "$w/$filed.out" \ |
| 1627 | || ! grep -qx ' missing code-build' "$w/$filed.out" \ |
| 1628 | || ! grep -qE "^ prose-format +signed by $workername\+$workerhash\$" "$w/$filed.out" \ |
| 1629 | || grep -qE '^(checking| evidence) ' "$w/$filed.out" || [ -s "$nixlog" ] \ |
| 1630 | || [ "$(grep -c '^--- push' "$reusepushes")" != 1 ] \ |
| 1631 | || ! grep -q ' refs/the-valley/integration-requests/main/partial$' "$reusepushes" \ |
| 1632 | || grep -q ' refs/the-valley/attestations/' "$reusepushes" \ |
| 1633 | || [ "$(requested partial)" != "$partialhead" ]; then |
| 1634 | echo "valley-request: $filed did not file the request alone while naming the missing nix check" >&2 |
| 1635 | cat "$w/$filed.out" "$w/$filed.err" "$nixlog" "$reusepushes" >&2 |
| 1636 | exit 1 |
| 1637 | fi |
| 1638 | git -C "$served" update-ref -d refs/the-valley/integration-requests/main/partial |
| 1639 | done |
| 1640 | approving partial valley approve -v --build-here origin/partial |
| 1641 | grep -qE "^ prose-format +signed by $workername\+$workerhash\$" "$w/partial.out" |
| 1642 | grep -qx "◐ partial checking 1 check: code-build" "$w/partial.out" |
| 1643 | grep -qE '^check code-build +nix +passed$' "$w/partial.out" |
| 1644 | if ! grep -qE '^nix build .*/code-build-[A-Za-z0-9]{6}\.drv\^\*$' "$nixlog" || grep -q 'prose-format' "$nixlog"; then |
| 1645 | echo "valley-request: a partly covered approval did not run exactly the missing check" >&2 |
| 1646 | cat "$nixlog" >&2 |
| 1647 | exit 1 |
| 1648 | fi |
| 1649 | grep -qx " evidence refs/the-valley/attestations/$partialdigest/$operatorhash" "$w/partial.out" |
| 1650 | grep -qx " reused refs/the-valley/attestations/$partialdigest/$workerhash" "$w/partial.out" |
| 1651 | if [ "$(grep -c '^--- push' "$reusepushes")" != 1 ] \ |
| 1652 | || ! grep -q " refs/the-valley/attestations/$partialdigest/$operatorhash\$" "$reusepushes" \ |
| 1653 | || ! grep -q ' refs/the-valley/integration-requests/main/partial$' "$reusepushes"; then |
| 1654 | echo "valley-request: the remainder's evidence and the request did not go in one push" >&2 |
| 1655 | cat "$reusepushes" >&2 |
| 1656 | exit 1 |
| 1657 | fi |
| 1658 | git cat-file -p "refs/the-valley/attestations/$partialdigest/$operatorhash:code-build/statement.note" > /dev/null |
| 1659 | if git cat-file -e "refs/the-valley/attestations/$partialdigest/$operatorhash:prose-format" 2> /dev/null; then |
| 1660 | echo "valley-request: the operator signed a check the worker's evidence covered" >&2 |
| 1661 | exit 1 |
| 1662 | fi |
| 1663 | integrated partial |
| 1664 | |
| 1665 | # 20e. Origin already holds the operator's own evidence for this tree, for |
| 1666 | # one check alone. It is reused, and the other check has nowhere to |
| 1667 | # go, since approve publishes a signer's evidence for a tree once: |
| 1668 | # refused before anything runs (bd-7b7d58f). |
| 1669 | edited occupied docs/readme.md src/main.txt |
| 1670 | occupiedhead="$(git rev-parse occupied)" |
| 1671 | occupieddigest="$(attest digest --rev occupied | cut -d: -f2)" |
| 1672 | attest run --rev "$occupiedhead" --key "$r/keys/operator" --name "$operatorname" --check code-build \ |
| 1673 | > "$r/operator.out" 2>&1 |
| 1674 | git push --quiet origin "refs/the-valley/attestations/$occupieddigest/$operatorhash:refs/the-valley/attestations/$occupieddigest/$operatorhash" |
| 1675 | if approving occupied valley approve -v --build-here origin/occupied; then |
| 1676 | echo "valley-request: approve built evidence that origin could not take" >&2 |
| 1677 | exit 1 |
| 1678 | fi |
| 1679 | grep -qE "^ code-build +signed by $operatorname\+$operatorhash\$" "$w/occupied.out" |
| 1680 | grep -qx "⊘ occupied not approved · this key's evidence for the tree, on origin, lacks prose-format" "$w/occupied.err" |
| 1681 | grep -qx ' attest with another key: set VALLEY_ATTEST_KEY' "$w/occupied.err" |
| 1682 | if [ -s "$nixlog" ] || [ -s "$reusepushes" ] || [ -n "$(requested occupied)" ]; then |
| 1683 | echo "valley-request: an approval refused for an occupied ref ran or published something" >&2 |
| 1684 | exit 1 |
| 1685 | fi |
| 1686 | |
| 1687 | # 20f. A listing of origin's evidence that fails, and a fetch of it that |
| 1688 | # fails, are refusals, never an empty answer: nothing runs and nothing |
| 1689 | # is published. A stand-in for git, first on PATH, fails the one call |
| 1690 | # named. It needs bin/valley run straight, since the package's wrapper |
| 1691 | # puts its own git ahead of anything on PATH. |
| 1692 | edited unread docs/readme.md |
| 1693 | unreadhead="$(git rev-parse unread)" |
| 1694 | unreaddigest="$(attest digest --rev unread | cut -d: -f2)" |
| 1695 | worker "$unreadhead" --check prose-format |
| 1696 | unreadoid="$(git -C "$served" rev-parse "refs/the-valley/attestations/$unreaddigest/$workerhash")" |
| 1697 | realgit="$(command -v git)" |
| 1698 | mkdir -p "$r/shim" |
| 1699 | cat > "$r/shim/git" <<EOF |
| 1700 | #!$(command -v bash) |
| 1701 | # git, failing the one call REUSE_FAIL names: the listing of origin's |
| 1702 | # evidence for one tree, or a fetch of the object one of its refs names. |
| 1703 | case "\${REUSE_FAIL:-}:\$*" in |
| 1704 | inventory:ls-remote*"refs/the-valley/attestations/$unreaddigest/"*) |
| 1705 | echo "git: injected failure" >&2 |
| 1706 | exit 128 |
| 1707 | ;; |
| 1708 | fetch:fetch*--stdin*) |
| 1709 | wanted="\$(cat)" |
| 1710 | if grep -qF "$unreadoid" <<< "\$wanted"; then |
| 1711 | echo "git: injected failure" >&2 |
| 1712 | exit 128 |
| 1713 | fi |
| 1714 | printf '%s\n' "\$wanted" | exec "$realgit" "\$@" |
| 1715 | ;; |
| 1716 | esac |
| 1717 | exec "$realgit" "\$@" |
| 1718 | EOF |
| 1719 | chmod +x "$r/shim/git" |
| 1720 | for failing in inventory fetch; do |
| 1721 | if REUSE_FAIL="$failing" PATH="$r/shim:$PATH" VALLEY_VERIFICATION_SCHEMA="$schemaFile" \ |
| 1722 | approving "unread-$failing" bash "$cliScript" approve -v origin/unread; then |
| 1723 | echo "valley-request: approve went on past a failed $failing of origin's evidence" >&2 |
| 1724 | exit 1 |
| 1725 | fi |
| 1726 | case "$failing" in |
| 1727 | inventory) says='valley: could not list the evidence origin holds for this tree' ;; |
| 1728 | fetch) says='valley: could not fetch the evidence origin holds for this tree' ;; |
| 1729 | esac |
| 1730 | grep -qxF "$says" "$w/unread-$failing.err" |
| 1731 | grep -qx '⊘ unread not approved · could not read the evidence origin holds' "$w/unread-$failing.err" |
| 1732 | if [ -s "$nixlog" ] || [ -s "$reusepushes" ] || [ -n "$(requested unread)" ]; then |
| 1733 | echo "valley-request: approve ran or published something after a failed $failing" >&2 |
| 1734 | exit 1 |
| 1735 | fi |
| 1736 | done |
| 1737 | # And with origin answering, the same approval reuses the worker's |
| 1738 | # evidence: the stand-in failed only what it was told to. |
| 1739 | VALLEY_VERIFICATION_SCHEMA="$schemaFile" approving unread bash "$cliScript" approve -v origin/unread |
| 1740 | grep -qE "^ prose-format +signed by $workername\+$workerhash\$" "$w/unread.out" |
| 1741 | [ "$(requested unread)" = "$unreadhead" ] |
| 1742 | integrated unread |
| 1743 | |
| 1744 | # 20g. approve skips a check only where the integrator accepts the same |
| 1745 | # evidence. Each case below stores one set of evidence on origin. |
| 1746 | # Approve, with no signing key, reuses nothing for it, naming the note |
| 1747 | # the integrator judges the check by and why it is not reused. It files |
| 1748 | # the request at once all the same, naming the check as missing and |
| 1749 | # building nothing. Then one pass of the real integrator decides that |
| 1750 | # request from the same refs. A note the hook would |
| 1751 | # refuse is planted past it, straight into origin's storage. Two cases |
| 1752 | # land: there approve is stricter than the integrator, on purpose. |
| 1753 | # |
| 1754 | # noted <file> <key> <name> <rev> <check> <attest run flag…>: attest the |
| 1755 | # revision in the worker's clone under the key, and copy the note it stored |
| 1756 | # for the check to the file, byte for byte. Nothing pushes the ref it |
| 1757 | # stored. |
| 1758 | noted() { |
| 1759 | local file="$1" key="$2" name="$3" rev="$4" check="$5" digest hash |
| 1760 | shift 5 |
| 1761 | git -C "$r/worker" fetch --quiet origin |
| 1762 | digest="$(attest digest --repo "$r/worker" --rev "$rev" | cut -d: -f2)" |
| 1763 | hash="$(attest key --key "$key" --name "$name" | cut -d+ -f2)" |
| 1764 | attest run --repo "$r/worker" --rev "$rev" --key "$key" --name "$name" "$@" > "$r/noted.out" 2>&1 || { |
| 1765 | echo "valley-request: attesting $rev for a planted note failed" >&2 |
| 1766 | cat "$r/noted.out" >&2 |
| 1767 | exit 1 |
| 1768 | } |
| 1769 | git -C "$r/worker" cat-file blob "refs/the-valley/attestations/$digest/$hash:$check/statement.note" > "$file" |
| 1770 | } |
| 1771 | # resigned <file> <sed expression>: the note's text, edited by the |
| 1772 | # expression, signed again by the worker. |
| 1773 | resigned() { |
| 1774 | sed -n '/^$/q;p' "$1" | sed "$2" > "$r/text" |
| 1775 | attest sign --key "$r/keys/worker" --name "$workername" "$r/text" > "$1" |
| 1776 | } |
| 1777 | # planted <ref> <check> <file>: the note stored at the ref on origin, in a |
| 1778 | # tree shaped as attest shapes one, straight into storage. |
| 1779 | planted() { |
| 1780 | local blob sub |
| 1781 | blob="$(git -C "$served" hash-object -w "$3")" |
| 1782 | sub="$(printf '100644 blob %s\tstatement.note\n' "$blob" | git -C "$served" mktree)" |
| 1783 | git -C "$served" update-ref "$1" "$(printf '040000 tree %s\t%s\n' "$sub" "$2" | git -C "$served" mktree)" |
| 1784 | } |
| 1785 | # unreused <branch> <reason>: approve, with no signing key, reuses nothing |
| 1786 | # for prose-format, says why, and files the request with prose-format |
| 1787 | # missing, building nothing. |
| 1788 | unreused() { |
| 1789 | approving "$1" env -u VALLEY_ATTEST_KEY valley approve -v "origin/$1" |
| 1790 | if ! grep -qF "valley: not reusing prose-format: the integrator judges it by " "$w/$1.err" \ |
| 1791 | || ! grep -qF -- "$2" "$w/$1.err" || grep -q 'reusing' "$w/$1.out" \ |
| 1792 | || ! grep -qx ' missing prose-format' "$w/$1.out" \ |
| 1793 | || [ "$(requested "$1")" != "$(git rev-parse "$1")" ] || [ -s "$nixlog" ]; then |
| 1794 | echo "valley-request: approve did not refuse $1 for the reason: $2" >&2 |
| 1795 | cat "$w/$1.err" >&2 |
| 1796 | exit 1 |
| 1797 | fi |
| 1798 | } |
| 1799 | # unpassed <branch> <reason>: the note the integrator judges prose-format |
| 1800 | # by verifies and is no pass of it, so building the check again changes |
| 1801 | # nothing for that tree. approve says why, refuses the head, and files |
| 1802 | # and builds nothing. |
| 1803 | unpassed() { |
| 1804 | if approving "$1" env -u VALLEY_ATTEST_KEY valley approve -v "origin/$1"; then |
| 1805 | echo "valley-request: approve filed $1, whose judged note is no pass" >&2 |
| 1806 | exit 1 |
| 1807 | fi |
| 1808 | if ! grep -qF -- "$2" "$w/$1.err" \ |
| 1809 | || ! grep -q "^⊘ $1 not approved · 1 of [0-9]* checks* failed\$" "$w/$1.err" \ |
| 1810 | || ! grep -qx " ✗ prose-format — see: valley status $1" "$w/$1.err" \ |
| 1811 | || [ -n "$(requested "$1")" ] || [ -s "$nixlog" ]; then |
| 1812 | echo "valley-request: approve did not refuse $1 for the reason: $2" >&2 |
| 1813 | cat "$w/$1.err" >&2 |
| 1814 | exit 1 |
| 1815 | fi |
| 1816 | } |
| 1817 | # judged <branch> <outcome> <reason> [<known-signers> [<signer projects>]]: |
| 1818 | # the branch's head is filed, by hand when approve has not, and one pass of the real integrator, |
| 1819 | # verifying with the known-signers file and given the signer projects file |
| 1820 | # when there is one, decides it as the outcome, giving the reason. A |
| 1821 | # request it does not land is taken away again. |
| 1822 | judged() { |
| 1823 | git -C "$served" update-ref "refs/the-valley/integration-requests/main/$1" "$(git rev-parse "$1")" |
| 1824 | integrator reconcile --repo "$served" --key "$r/keys/integrator" --name "$integratorname" \ |
| 1825 | --known-signers "${4:-$r/known-signers}" ${5:+--signer-projects "$5"} --instance "$r/floor" --schema "$schemaFile" \ |
| 1826 | --attest-schema "$attestSchema" --event-schema "$eventSchema" > "$r/integrator.out" 2>&1 || { |
| 1827 | echo "valley-request: the integrator failed" >&2 |
| 1828 | cat "$r/integrator.out" >&2 |
| 1829 | exit 1 |
| 1830 | } |
| 1831 | if ! grep -q "^$1 -> refs/heads/main @ [0-9a-f]*: $2\$" "$r/integrator.out" \ |
| 1832 | || ! grep -qF -- "$3" "$r/integrator.out"; then |
| 1833 | echo "valley-request: the integrator did not decide $1 as $2, saying: $3" >&2 |
| 1834 | cat "$r/integrator.out" >&2 |
| 1835 | exit 1 |
| 1836 | fi |
| 1837 | [ "$2" = land ] || git -C "$served" update-ref -d "refs/the-valley/integration-requests/main/$1" |
| 1838 | } |
| 1839 | under() { printf 'refs/the-valley/attestations/%s/%s' "$(attest digest --rev "$1" | cut -d: -f2)" "$2"; } |
| 1840 | |
| 1841 | # Stale trust: the host revokes the worker, and this operator's own |
| 1842 | # known-signers file still trusts it. The override does not widen what the |
| 1843 | # host publishes. |
| 1844 | { |
| 1845 | attest key --key "$r/keys/operator" --name "$operatorname" |
| 1846 | attest key --key "$r/keys/integrator" --name "$integratorname" |
| 1847 | } > "$r/revoked-signers" |
| 1848 | edited revoked docs/readme.md |
| 1849 | worker "$(git rev-parse revoked)" --check prose-format |
| 1850 | published "$r/revoked-signers" |
| 1851 | VALLEY_KNOWN_SIGNERS="$r/known-signers" unreused revoked \ |
| 1852 | "attest verify refuses it under the host's signers: no signature on this note is by a key the verifier holds" |
| 1853 | judged revoked stale 'signed by no signer the integrator holds' "$r/revoked-signers" |
| 1854 | published "$r/known-signers" |
| 1855 | |
| 1856 | # Narrowed trust: an override that does not trust the worker keeps approve |
| 1857 | # from reusing what the host would accept. |
| 1858 | edited narrowed docs/readme.md |
| 1859 | worker "$(git rev-parse narrowed)" --check prose-format |
| 1860 | VALLEY_KNOWN_SIGNERS="$r/revoked-signers" unreused narrowed \ |
| 1861 | 'attest verify refuses it under VALLEY_KNOWN_SIGNERS: no signature on this note is by a key the verifier holds' |
| 1862 | judged narrowed land 'transferred (unmoved)' |
| 1863 | |
| 1864 | # Conflicting notes: the integrator judges a check by the first note that |
| 1865 | # verifies, in ref order. A failure the worker signed sits first, so the |
| 1866 | # pass the worker published after it does not count. |
| 1867 | edited failed docs/readme.md |
| 1868 | noted "$r/failed.note" "$r/keys/worker" "$workername" "$(git rev-parse failed)" prose-format --check prose-format |
| 1869 | resigned "$r/failed.note" 's/^predicate.result passed$/predicate.result failed/' |
| 1870 | attest verify --note "$r/failed.note" --known-keys "$r/known-signers" --repo . --rev failed > /dev/null |
| 1871 | planted "$(under failed 00000000)" prose-format "$r/failed.note" |
| 1872 | worker "$(git rev-parse failed)" --check prose-format |
| 1873 | unpassed failed 'its predicate.result is "failed", not "passed"' |
| 1874 | judged failed stale 'the attestation records the check as failed' |
| 1875 | |
| 1876 | # The same, with an observation first: a note of the wrong kind is no |
| 1877 | # evidence, so the request is stale. |
| 1878 | edited kind docs/readme.md |
| 1879 | noted "$r/kind.note" "$r/keys/worker" "$workername" "$(git rev-parse kind)" prose-format --command prose-format=true |
| 1880 | planted "$(under kind 00000000)" prose-format "$r/kind.note" |
| 1881 | worker "$(git rev-parse kind)" --check prose-format |
| 1882 | unpassed kind 'its predicateType is "the-valley/check/effectful/v1", not "the-valley/check/pure/v1"' |
| 1883 | judged kind stale 'the policy requires a pure check and the attestation is for an effectful check' |
| 1884 | |
| 1885 | # A malformed envelope: a note the worker signed, without its last newline. |
| 1886 | # approve reads it byte for byte, as the integrator does. |
| 1887 | edited envelope docs/readme.md |
| 1888 | noted "$r/envelope.note" "$r/keys/worker" "$workername" "$(git rev-parse envelope)" prose-format --check prose-format |
| 1889 | head -c -1 "$r/envelope.note" > "$r/envelope.cut" |
| 1890 | planted "$(under envelope "$workerhash")" prose-format "$r/envelope.cut" |
| 1891 | unreused envelope 'the signature block is empty or does not end with a newline' |
| 1892 | judged envelope reject 'the attestation does not verify as the statement it claims to be' |
| 1893 | |
| 1894 | # An unknown signature: a key neither the host nor the hook knows. |
| 1895 | ssh-keygen -q -t ed25519 -N "" -C stranger -f "$r/keys/stranger" |
| 1896 | strangername=stranger.valley.invalid/attestations |
| 1897 | edited stranger docs/readme.md |
| 1898 | noted "$r/stranger.note" "$r/keys/stranger" "$strangername" "$(git rev-parse stranger)" prose-format --check prose-format |
| 1899 | planted "$(under stranger "$(attest key --key "$r/keys/stranger" --name "$strangername" | cut -d+ -f2)")" \ |
| 1900 | prose-format "$r/stranger.note" |
| 1901 | unreused stranger 'no signature on this note is by a key the verifier holds' |
| 1902 | judged stranger stale 'signed by no signer the integrator holds' |
| 1903 | |
| 1904 | # A wrong tree: the worker's note about main, stored under this head's tree. |
| 1905 | edited tree docs/readme.md |
| 1906 | noted "$r/tree.note" "$r/keys/worker" "$workername" origin/main prose-format --check prose-format |
| 1907 | planted "$(under tree "$workerhash")" prose-format "$r/tree.note" |
| 1908 | unreused tree 'tree digest mismatch' |
| 1909 | judged tree reject 'tree digest mismatch' |
| 1910 | |
| 1911 | # An expired observation of a command check. approve never reuses one, so |
| 1912 | # with no key it refuses; the integrator refuses the observation as too old. |
| 1913 | edited expired live/state.txt |
| 1914 | noted "$r/expired.note" "$r/keys/worker" "$workername" "$(git rev-parse expired)" live-ok --command live-ok=true |
| 1915 | resigned "$r/expired.note" 's/^predicate.observedAt .*/predicate.observedAt 2020-01-01T00:00:00Z/' |
| 1916 | planted "$(under expired "$workerhash")" live-ok "$r/expired.note" |
| 1917 | if approving expired env -u VALLEY_ATTEST_KEY valley approve -v origin/expired \ |
| 1918 | || ! grep -q 'no signing key' "$w/expired.err" || grep -q 'reusing' "$w/expired.out"; then |
| 1919 | echo "valley-request: approve reused an observation of a command check" >&2 |
| 1920 | cat "$w/expired.out" "$w/expired.err" >&2 |
| 1921 | exit 1 |
| 1922 | fi |
| 1923 | judged expired stale 'the observation is ' |
| 1924 | |
| 1925 | # The attribute: the worker's note for prose-format names another flake |
| 1926 | # attribute. Approve compares it and refuses the head; the integrator |
| 1927 | # compares it too, on an unmoved tree, and the note is no evidence for |
| 1928 | # prose-format. |
| 1929 | edited attribute docs/readme.md |
| 1930 | worker "$(git rev-parse attribute)" --check prose-format=code-build |
| 1931 | unpassed attribute 'its predicate.check.attribute is "code-build", not "prose-format"' |
| 1932 | judged attribute stale 'the attestation is for runner "nix", attribute "code-build", and the policy requires runner "nix", attribute "prose-format"' |
| 1933 | |
| 1934 | # 20h. A signer can be restricted to projects. The host publishes its |
| 1935 | # signer projects file beside the known-signers file, and approve |
| 1936 | # reuses a note only when one of its signers counts in this project. |
| 1937 | # The project is named project, after origin, as the integrator names |
| 1938 | # it after its repository. Each integrator pass is given the file the |
| 1939 | # host publishes. |
| 1940 | # |
| 1941 | # restricting <file>: the instance publishes the known-signers file with |
| 1942 | # this signer projects file. |
| 1943 | restricting() { |
| 1944 | published "$r/known-signers" 100644 blob "$(git -C "$instance" hash-object -w "$1")" |
| 1945 | } |
| 1946 | # unpublished <branch> <reason>: the publication is not used, so approve, |
| 1947 | # with no signing key, reuses none of origin's evidence, says why, and |
| 1948 | # files the request with prose-format missing, building nothing. |
| 1949 | unpublished() { |
| 1950 | approving "$1" env -u VALLEY_ATTEST_KEY valley approve -v "origin/$1" |
| 1951 | if ! grep -qxF "valley: $2, so none of the evidence on origin is reused" "$w/$1.err" \ |
| 1952 | || grep -q 'reusing' "$w/$1.out" \ |
| 1953 | || ! grep -qx ' missing prose-format' "$w/$1.out" \ |
| 1954 | || [ "$(requested "$1")" != "$(git rev-parse "$1")" ] || [ -s "$nixlog" ]; then |
| 1955 | echo "valley-request: approve did not refuse $1 for the reason: $2" >&2 |
| 1956 | cat "$w/$1.err" >&2 |
| 1957 | exit 1 |
| 1958 | fi |
| 1959 | } |
| 1960 | |
| 1961 | # The worker restricted to another project: its note is a stranger's here. |
| 1962 | # approve does not reuse it, the integrator does not accept it, and an |
| 1963 | # approval from review --build-here, with a signing key, builds the check |
| 1964 | # under the operator's key. |
| 1965 | printf '%s elsewhere\n' "$workername" > "$r/elsewhere.projects" |
| 1966 | restricting "$r/elsewhere.projects" |
| 1967 | edited elsewhere docs/readme.md |
| 1968 | elsewherehead="$(git rev-parse elsewhere)" |
| 1969 | worker "$elsewherehead" --check prose-format |
| 1970 | unreused elsewhere \ |
| 1971 | "none of its signers counts in project project: the published signer-projects lets $workername count only in elsewhere" |
| 1972 | judged elsewhere stale 'signed by no signer the integrator holds' "$r/known-signers" "$r/elsewhere.projects" |
| 1973 | approving elsewhere-built bash -c 'printf "a\n" | valley review -v --build-here origin/elsewhere' |
| 1974 | grep -qF "valley: not reusing prose-format: the integrator judges it by $(under elsewhere "$workerhash"):prose-format/statement.note, and none of its signers counts in project project" "$w/elsewhere-built.err" |
| 1975 | grep -qx "◐ elsewhere checking 1 check: prose-format" "$w/elsewhere-built.out" |
| 1976 | grep -qx " evidence $(under elsewhere "$operatorhash")" "$w/elsewhere-built.out" |
| 1977 | if ! grep -qE '^nix build .*/prose-format-[A-Za-z0-9]{6}\.drv\^\*$' "$nixlog" \ |
| 1978 | || grep -q '^ reused ' "$w/elsewhere-built.out"; then |
| 1979 | echo "valley-request: approve did not build the check whose only signer counts elsewhere" >&2 |
| 1980 | cat "$w/elsewhere-built.out" "$nixlog" >&2 |
| 1981 | exit 1 |
| 1982 | fi |
| 1983 | [ "$(requested elsewhere)" = "$elsewherehead" ] |
| 1984 | integrated elsewhere "$r/elsewhere.projects" |
| 1985 | |
| 1986 | # The same worker note, countersigned by the integrator. The integrator's |
| 1987 | # own signature never counts for a check, so the note still has no signer |
| 1988 | # who counts here. |
| 1989 | edited countersigned docs/readme.md |
| 1990 | noted "$r/countersigned.note" "$r/keys/worker" "$workername" "$(git rev-parse countersigned)" prose-format --check prose-format |
| 1991 | attest sign --key "$r/keys/integrator" --name "$integratorname" "$r/countersigned.note" > "$r/countersigned.both" |
| 1992 | planted "$(under countersigned "$workerhash")" prose-format "$r/countersigned.both" |
| 1993 | unreused countersigned \ |
| 1994 | "the published signer-projects lets $workername count only in elsewhere; $integratorname is the host's integrator, whose signature is a countersignature" |
| 1995 | judged countersigned stale 'signed by no signer the integrator holds' "$r/known-signers" "$r/elsewhere.projects" |
| 1996 | |
| 1997 | # A published list that does not read, and one that is no file: the |
| 1998 | # publication is not used, and nothing on origin is reused. |
| 1999 | edited listed docs/readme.md |
| 2000 | listedhead="$(git rev-parse listed)" |
| 2001 | worker "$listedhead" --check prose-format |
| 2002 | printf '%s project\n%s elsewhere\n' "$workername" "$workername" > "$r/twice.projects" |
| 2003 | restricting "$r/twice.projects" |
| 2004 | unpublished listed \ |
| 2005 | "signer-projects in refs/the-valley/signers in $instance does not read: line 2: $workername is named on an earlier line too" |
| 2006 | printf '%s project\n' "$workername" > "$r/here.projects" |
| 2007 | listblob="$(git -C "$instance" hash-object -w "$r/here.projects")" |
| 2008 | for entry in "040000 tree $(printf '100644 blob %s\tlist\n' "$listblob" | git -C "$instance" mktree)" "100755 blob $listblob"; do |
| 2009 | # shellcheck disable=SC2086 # the entry is a mode, a type and an object |
| 2010 | published "$r/known-signers" $entry |
| 2011 | unpublished listed "signer-projects in refs/the-valley/signers in $instance is not a file" |
| 2012 | done |
| 2013 | |
| 2014 | # The worker restricted to this project and one more: the same note is |
| 2015 | # reused, nothing runs, and the integrator lands it. |
| 2016 | printf '# the projects the worker builds for\n%s elsewhere project\n' "$workername" > "$r/here.projects" |
| 2017 | restricting "$r/here.projects" |
| 2018 | approving listed env -u VALLEY_ATTEST_KEY valley approve -v origin/listed |
| 2019 | grep -qE "^ prose-format +signed by $workername\+$workerhash\$" "$w/listed.out" |
| 2020 | grep -qx " reused $(under listed "$workerhash")" "$w/listed.out" |
| 2021 | if [ -s "$nixlog" ] || [ "$(requested listed)" != "$listedhead" ]; then |
| 2022 | echo "valley-request: approve did not reuse the note of a worker restricted to this project" >&2 |
| 2023 | cat "$w/listed.out" "$w/listed.err" "$nixlog" >&2 |
| 2024 | exit 1 |
| 2025 | fi |
| 2026 | integrated listed "$r/here.projects" |
| 2027 | published "$r/known-signers" |
| 2028 | |
| 2029 | # 20i. The worker covered the one nix check, and the change requires a |
| 2030 | # command check too. No worker runs a command check, so approve runs |
| 2031 | # it here without --build-here, builds no nix check, and files. |
| 2032 | edited commanded docs/readme.md live/state.txt |
| 2033 | commandedhead="$(git rev-parse commanded)" |
| 2034 | worker "$commandedhead" --check prose-format |
| 2035 | approving commanded valley approve -v origin/commanded |
| 2036 | grep -qE "^ prose-format +signed by $workername\+$workerhash\$" "$w/commanded.out" |
| 2037 | grep -qx "◐ commanded checking 1 check: live-ok" "$w/commanded.out" |
| 2038 | if grep -q '^nix build' "$nixlog" || [ "$(requested commanded)" != "$commandedhead" ]; then |
| 2039 | echo "valley-request: an approval whose only uncovered check is a command check built nix or filed nothing" >&2 |
| 2040 | cat "$w/commanded.out" "$w/commanded.err" "$nixlog" >&2 |
| 2041 | exit 1 |
| 2042 | fi |
| 2043 | integrated commanded |
| 2044 | |
| 2045 | # 20j. No worker has built the change, and it requires a command check and |
| 2046 | # a nix check. approve without --build-here runs the command check |
| 2047 | # here, builds no nix check, and publishes the command check's |
| 2048 | # evidence with the request in one push, naming the nix check as |
| 2049 | # missing. It does not offer --build-here, which that evidence now |
| 2050 | # blocks (bd-7b7d58f). |
| 2051 | edited mixed docs/readme.md live/state.txt |
| 2052 | mixedhead="$(git rev-parse mixed)" |
| 2053 | mixeddigest="$(attest digest --rev mixed | cut -d: -f2)" |
| 2054 | approving mixed valley approve -v origin/mixed |
| 2055 | grep -qx "◐ mixed checking 1 check: live-ok" "$w/mixed.out" |
| 2056 | grep -qx ' missing prose-format' "$w/mixed.out" |
| 2057 | grep -qx '◇ mixed approved · waiting for 1 check (no worker building)' "$w/mixed.out" |
| 2058 | grep -qx ' run: valley ready mixed' "$w/mixed.out" |
| 2059 | grep -qx " evidence refs/the-valley/attestations/$mixeddigest/$operatorhash" "$w/mixed.out" |
| 2060 | if grep -q '^nix build' "$nixlog" || [ "$(requested mixed)" != "$mixedhead" ] \ |
| 2061 | || [ "$(grep -c '^--- push' "$reusepushes")" != 1 ] \ |
| 2062 | || ! grep -q " refs/the-valley/attestations/$mixeddigest/$operatorhash\$" "$reusepushes" \ |
| 2063 | || ! grep -q ' refs/the-valley/integration-requests/main/mixed$' "$reusepushes"; then |
| 2064 | echo "valley-request: an approval missing a nix check did not run the command check alone and file with its evidence" >&2 |
| 2065 | cat "$w/mixed.out" "$w/mixed.err" "$nixlog" "$reusepushes" >&2 |
| 2066 | exit 1 |
| 2067 | fi |
| 2068 | git -C "$served" update-ref -d refs/the-valley/integration-requests/main/mixed |
| 2069 | |
| 2070 | # ---------------------------------------------------------------------- |
| 2071 | # 21. The check worker builds what ready changes require before anyone |
| 2072 | # approves them, and publishes it where approve reuses it. It runs as |
| 2073 | # packaged, valley-worker, from a clone of the owning valley, which now |
| 2074 | # publishes its project list, so the worker reads the project through |
| 2075 | # its own cache clone, as valley pending --repo does. It signs with the |
| 2076 | # worker's key and pushes as a principal that holds no grant, through |
| 2077 | # the same protected hook. The host restricts the worker's key to this |
| 2078 | # project, and each integrator pass is given that list. The worker's |
| 2079 | # state directory holds its lock and its record of failed batches. |
| 2080 | printf '%s project\n' "$workername" > "$r/worker.projects" |
| 2081 | restricting "$r/worker.projects" |
| 2082 | git -C "$instance" update-ref refs/the-valley/projects \ |
| 2083 | "$(printf 'project\n' | git -C "$instance" hash-object -w --stdin)" |
| 2084 | git clone --quiet "$instance" "$r/worker-home" |
| 2085 | wstate="$r/worker-state" |
| 2086 | git config valley.principal requester |
| 2087 | # fresh: origin's pushes and the nix log start empty. |
| 2088 | fresh() { |
| 2089 | : > "$nixlog" |
| 2090 | : > "$reusepushes" |
| 2091 | } |
| 2092 | # working <name> [<env assignment>…]: one pass of the worker, with the |
| 2093 | # environment given, into $r/<name>.log. Its status is the pass's. |
| 2094 | working() { |
| 2095 | local name="$1" |
| 2096 | shift |
| 2097 | (cd "$r/worker-home" && env VALLEY_PRINCIPAL=worker "$@" valley-worker --repo project \ |
| 2098 | --key "$r/keys/worker" --name "$workername" --state "$wstate") > "$r/$name.log" 2>&1 |
| 2099 | } |
| 2100 | # readied <branch> <file…>: edited, then readied as a change by the |
| 2101 | # requester. It sets id, handle and head, and line, the start of each line |
| 2102 | # the worker prints about the change's active version. |
| 2103 | readied() { |
| 2104 | local name="$1" |
| 2105 | edited "$@" |
| 2106 | VALLEY_PRINCIPAL=requester valley ready "$name" > "$r/$name.ready" 2>&1 |
| 2107 | id="$(sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$r/$name.ready")" |
| 2108 | handle="$(sed -n 's/^project \([^ ]*\) v1 ready$/\1/p' "$r/$name.ready")" |
| 2109 | head="$(git rev-parse "$name")" |
| 2110 | line="project: $handle v1 at ${head:0:7}" |
| 2111 | [ -n "$id" ] && [ -n "$handle" ] || { |
| 2112 | echo "valley-request: could not ready $name" >&2 |
| 2113 | cat "$r/$name.ready" >&2 |
| 2114 | exit 1 |
| 2115 | } |
| 2116 | } |
| 2117 | # pushed <ref>: origin received one push since fresh, carrying that ref |
| 2118 | # alone. pushed none: origin received no push. |
| 2119 | pushed() { |
| 2120 | if [ "$1" = none ]; then |
| 2121 | [ ! -s "$reusepushes" ] && return |
| 2122 | elif [ "$(grep -c '^--- push' "$reusepushes")" = 1 ] \ |
| 2123 | && [ "$(grep -vc '^--- push' "$reusepushes")" = 1 ] \ |
| 2124 | && grep -q " $1\$" "$reusepushes"; then |
| 2125 | return |
| 2126 | fi |
| 2127 | echo "valley-request: the worker's pushes were not what was expected ($1)" >&2 |
| 2128 | cat "$reusepushes" >&2 |
| 2129 | exit 1 |
| 2130 | } |
| 2131 | # built <check…>: nix built a derivation of exactly these checks, each |
| 2132 | # once. attest evaluates the checks of a batch together, then builds each |
| 2133 | # check's derivation with nix build <store>/<check>-XXXXXX.drv^*, which the |
| 2134 | # stand-in names after the check, so every derivation a nix build line |
| 2135 | # names is read as one build of that check. built nothing: nix did not run. |
| 2136 | built() { |
| 2137 | local got |
| 2138 | if [ "$1" = nothing ]; then |
| 2139 | [ ! -s "$nixlog" ] && return |
| 2140 | echo "valley-request: the worker ran nix when it had nothing to build" >&2 |
| 2141 | cat "$nixlog" >&2 |
| 2142 | exit 1 |
| 2143 | fi |
| 2144 | got="$(grep '^nix build ' "$nixlog" | tr ' ' '\n' \ |
| 2145 | | sed -n 's|^.*/\([a-z0-9][a-z0-9-]*\)-[A-Za-z0-9]\{6\}\.drv^\*$|\1|p' | sort | paste -sd' ')" |
| 2146 | [ "$got" = "$(printf '%s\n' "$@" | sort | paste -sd' ')" ] && return |
| 2147 | echo "valley-request: the worker built '$got', not '$*'" >&2 |
| 2148 | cat "$nixlog" >&2 |
| 2149 | exit 1 |
| 2150 | } |
| 2151 | # said <name> <line>: the pass's log holds the line. |
| 2152 | said() { |
| 2153 | grep -qxF "$2" "$r/$1.log" && return |
| 2154 | echo "valley-request: the pass $1 did not say: $2" >&2 |
| 2155 | cat "$r/$1.log" >&2 |
| 2156 | exit 1 |
| 2157 | } |
| 2158 | |
| 2159 | # 21a. Evidence precedes approval. The worker builds the nix checks a ready |
| 2160 | # change requires, together, and pushes the one attestation ref |
| 2161 | # attest stored, before any request exists. A change whose only check |
| 2162 | # is a command check is left to approve. The next pass finds the |
| 2163 | # evidence on origin and does nothing. approve, with no signing key, |
| 2164 | # reuses all of it and runs nothing, and the real integrator lands it. |
| 2165 | readied lively live/state.txt |
| 2166 | livelyline="$line" |
| 2167 | readied early docs/readme.md src/main.txt |
| 2168 | earlydigest="$(attest digest --rev early | cut -d: -f2)" |
| 2169 | earlyref="refs/the-valley/attestations/$earlydigest/$workerhash" |
| 2170 | fresh |
| 2171 | working early |
| 2172 | said early "$line: building code-build, prose-format" |
| 2173 | said early "$line: published $earlyref" |
| 2174 | said early "$livelyline: requires no nix check" |
| 2175 | built code-build prose-format |
| 2176 | pushed "$earlyref" |
| 2177 | git -C "$served" cat-file -e "$earlyref:code-build/statement.note" |
| 2178 | git -C "$served" cat-file -e "$earlyref:prose-format/statement.note" |
| 2179 | [ -z "$(requested "c-$id")" ] || { |
| 2180 | echo "valley-request: a request existed before the worker's evidence" >&2 |
| 2181 | exit 1 |
| 2182 | } |
| 2183 | fresh |
| 2184 | working early-again |
| 2185 | said early-again "$line: origin holds evidence for every nix check it requires" |
| 2186 | built nothing |
| 2187 | pushed none |
| 2188 | approving early env -u VALLEY_ATTEST_KEY valley approve -v --head "$head" "$handle" |
| 2189 | grep -qE "^ prose-format +signed by $workername\+$workerhash\$" "$w/early.out" |
| 2190 | grep -qE "^ code-build +signed by $workername\+$workerhash\$" "$w/early.out" |
| 2191 | built nothing |
| 2192 | [ "$(requested "c-$id")" = "$head" ] |
| 2193 | integrated "c-$id" "$r/worker.projects" |
| 2194 | |
| 2195 | # 21b. Concurrent passes take turns. The first holds the lock while it |
| 2196 | # builds, and a stand-in hook keeps it building until the second says |
| 2197 | # it is waiting. The second then reads origin after the first has |
| 2198 | # published, and builds nothing. |
| 2199 | readied together src/main.txt |
| 2200 | togetherref="refs/the-valley/attestations/$(attest digest --rev together | cut -d: -f2)/$workerhash" |
| 2201 | cat > "$r/hold" <<EOF |
| 2202 | #!$(command -v bash) |
| 2203 | [ -e "$r/hold-armed" ] || exit 0 |
| 2204 | rm -f "$r/hold-armed" |
| 2205 | for _ in \$(seq 600); do |
| 2206 | grep -q 'waiting for it to end' "$r/together-second.log" 2> /dev/null && exit 0 |
| 2207 | sleep 0.1 |
| 2208 | done |
| 2209 | echo "the second pass never waited for the first" >&2 |
| 2210 | exit 1 |
| 2211 | EOF |
| 2212 | chmod +x "$r/hold" |
| 2213 | touch "$r/hold-armed" |
| 2214 | fresh |
| 2215 | working together-first VALLEY_E2E_DURING_PASS="$r/hold" & |
| 2216 | first=$! |
| 2217 | for _ in $(seq 600); do |
| 2218 | grep -q ': building ' "$r/together-first.log" 2> /dev/null && break |
| 2219 | sleep 0.1 |
| 2220 | done |
| 2221 | working together-second |
| 2222 | wait "$first" |
| 2223 | said together-second "valley: another pass holds $wstate/lock; waiting for it to end" |
| 2224 | said together-first "$line: published $togetherref" |
| 2225 | said together-second "$line: origin holds evidence for every nix check it requires" |
| 2226 | built code-build |
| 2227 | pushed "$togetherref" |
| 2228 | |
| 2229 | # 21c. A failed batch backs off. Every nix call fails while the stand-in |
| 2230 | # is told to fail. The pass reports the failure, publishes nothing, |
| 2231 | # and exits 1. The batch is not built again until its wait, 15 |
| 2232 | # minutes, is over, then it fails again and waits twice as long. Once |
| 2233 | # it passes it is published, and the record of it is gone. |
| 2234 | readied flaky docs/readme.md |
| 2235 | flakyref="refs/the-valley/attestations/$(attest digest --rev flaky | cut -d: -f2)/$workerhash" |
| 2236 | fresh |
| 2237 | if working flaky-1 VALLEY_NOW=2026-10-22T10:00:00Z VALLEY_E2E_DURING_PASS='exit 1'; then |
| 2238 | echo "valley-request: a pass whose batch failed exited 0" >&2 |
| 2239 | exit 1 |
| 2240 | fi |
| 2241 | said flaky-1 "$line: the batch did not pass (exit status 1); it is not built again before 2026-10-22T10:15:00Z" |
| 2242 | pushed none |
| 2243 | jq -e '.projects.project | length == 1 and (.[] | .failures == 1)' "$wstate/failures.json" > /dev/null |
| 2244 | fresh |
| 2245 | working flaky-2 VALLEY_NOW=2026-10-22T10:14:59Z |
| 2246 | said flaky-2 "$line: its batch prose-format failed 1 time in a row, so it is not built again before 2026-10-22T10:15:00Z" |
| 2247 | built nothing |
| 2248 | pushed none |
| 2249 | if working flaky-3 VALLEY_NOW=2026-10-22T10:15:00Z VALLEY_E2E_DURING_PASS='exit 1'; then |
| 2250 | echo "valley-request: a pass whose batch failed again exited 0" >&2 |
| 2251 | exit 1 |
| 2252 | fi |
| 2253 | said flaky-3 "$line: the batch did not pass (exit status 1); it is not built again before 2026-10-22T10:45:00Z" |
| 2254 | fresh |
| 2255 | working flaky-4 VALLEY_NOW=2026-10-22T10:45:00Z |
| 2256 | said flaky-4 "$line: building prose-format" |
| 2257 | said flaky-4 "$line: published $flakyref" |
| 2258 | built prose-format |
| 2259 | pushed "$flakyref" |
| 2260 | [ ! -e "$wstate/failures.json" ] || { |
| 2261 | echo "valley-request: the record of a batch that passed was kept" >&2 |
| 2262 | cat "$wstate/failures.json" >&2 |
| 2263 | exit 1 |
| 2264 | } |
| 2265 | |
| 2266 | # 21d. A lost reply. The worker's push is taken by a receive-pack that |
| 2267 | # exits 1 when it is done, so origin lands the ref and the worker hears |
| 2268 | # a failure: the pass says so, and exits 1. The next pass finds the |
| 2269 | # evidence on origin, and builds and pushes nothing. Then a push that |
| 2270 | # never reaches origin: once its one-minute wait is over, the next |
| 2271 | # pass pushes the ref the first one stored, the same object, and |
| 2272 | # builds nothing. |
| 2273 | cat > "$r/lossy" <<EOF |
| 2274 | #!$(command -v bash) |
| 2275 | git-receive-pack "\$@" |
| 2276 | echo "the connection dropped" >&2 |
| 2277 | exit 1 |
| 2278 | EOF |
| 2279 | cat > "$r/unreached" <<EOF |
| 2280 | #!$(command -v bash) |
| 2281 | echo "the connection dropped" >&2 |
| 2282 | exit 1 |
| 2283 | EOF |
| 2284 | chmod +x "$r/lossy" "$r/unreached" |
| 2285 | readied landed docs/readme.md |
| 2286 | landedref="refs/the-valley/attestations/$(attest digest --rev landed | cut -d: -f2)/$workerhash" |
| 2287 | if working landed-1 VALLEY_NOW=2026-10-23T09:00:00Z GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=remote.origin.receivepack GIT_CONFIG_VALUE_0="$r/lossy"; then |
| 2288 | echo "valley-request: a pass that heard its push fail exited 0" >&2 |
| 2289 | exit 1 |
| 2290 | fi |
| 2291 | said landed-1 "$line: could not publish $landedref; it is not pushed again before 2026-10-23T09:01:00Z" |
| 2292 | git -C "$served" cat-file -e "$landedref:prose-format/statement.note" |
| 2293 | fresh |
| 2294 | working landed-2 VALLEY_NOW=2026-10-23T09:00:00Z |
| 2295 | said landed-2 "$line: origin holds evidence for every nix check it requires" |
| 2296 | built nothing |
| 2297 | pushed none |
| 2298 | readied unreached docs/readme.md |
| 2299 | unreachedref="refs/the-valley/attestations/$(attest digest --rev unreached | cut -d: -f2)/$workerhash" |
| 2300 | if working unreached-1 VALLEY_NOW=2026-10-23T09:00:00Z GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=remote.origin.receivepack GIT_CONFIG_VALUE_0="$r/unreached"; then |
| 2301 | echo "valley-request: a pass whose push never arrived exited 0" >&2 |
| 2302 | exit 1 |
| 2303 | fi |
| 2304 | if git -C "$served" rev-parse --verify --quiet "$unreachedref" > /dev/null; then |
| 2305 | echo "valley-request: a push that never arrived landed" >&2 |
| 2306 | exit 1 |
| 2307 | fi |
| 2308 | # The clone the worker reads the project through: keyed by its URL, which |
| 2309 | # is the owning valley's with its last segment replaced (status/list.go). |
| 2310 | cache="$HOME/.cache/valley/repos/$(printf '%s' "$served" | sha256sum | cut -c1-16)-project" |
| 2311 | storedobject="$(git -C "$cache" rev-parse "$unreachedref")" |
| 2312 | fresh |
| 2313 | working unreached-2 VALLEY_NOW=2026-10-23T09:01:00Z |
| 2314 | said unreached-2 "$line: an earlier pass stored $unreachedref, and origin does not hold it" |
| 2315 | said unreached-2 "$line: published $unreachedref" |
| 2316 | built nothing |
| 2317 | pushed "$unreachedref" |
| 2318 | [ "$(git -C "$served" rev-parse "$unreachedref")" = "$storedobject" ] |
| 2319 | # A tag in the cache clone named like the ref the worker stores a |
| 2320 | # change's evidence at, while that ref is missing. The worker reads its |
| 2321 | # own ref by that exact name, so it does not take the tag for evidence an |
| 2322 | # earlier pass stored: it builds the change and publishes what attest |
| 2323 | # stored. |
| 2324 | readied tagged docs/readme.md |
| 2325 | taggedref="refs/the-valley/attestations/$(attest digest --rev tagged | cut -d: -f2)/$workerhash" |
| 2326 | git -C "$cache" update-ref "refs/tags/$taggedref" "$storedobject" |
| 2327 | fresh |
| 2328 | working tagged VALLEY_NOW=2026-10-23T09:02:00Z && taggedpass=0 || taggedpass=$? |
| 2329 | if grep -qF "an earlier pass stored $taggedref" "$r/tagged.log"; then |
| 2330 | echo "valley-request: the worker took a tag named like its own ref for evidence an earlier pass stored" >&2 |
| 2331 | cat "$r/tagged.log" >&2 |
| 2332 | exit 1 |
| 2333 | fi |
| 2334 | if [ "$taggedpass" != 0 ]; then |
| 2335 | echo "valley-request: the pass with a tag named like the worker's own ref exited $taggedpass" >&2 |
| 2336 | cat "$r/tagged.log" >&2 |
| 2337 | exit 1 |
| 2338 | fi |
| 2339 | said tagged "$line: published $taggedref" |
| 2340 | pushed "$taggedref" |
| 2341 | |
| 2342 | # 21e. A head superseded while it is built. A stand-in hook readies a new |
| 2343 | # version of the change in the middle of the batch. The batch runs to |
| 2344 | # its end, and the pass publishes the evidence for the head it pinned, |
| 2345 | # which the hook admits, since it is true of that tree. The pass then |
| 2346 | # reads the change again and builds the new version, which approve |
| 2347 | # reuses, and the real integrator lands. The next pass builds nothing. |
| 2348 | readied superseded docs/readme.md |
| 2349 | oldline="$line" |
| 2350 | oldref="refs/the-valley/attestations/$(attest digest --rev superseded | cut -d: -f2)/$workerhash" |
| 2351 | cat > "$r/supersede" <<EOF |
| 2352 | #!$(command -v bash) |
| 2353 | [ -e "$r/supersede-armed" ] || exit 0 |
| 2354 | rm -f "$r/supersede-armed" |
| 2355 | cd "$proj" |
| 2356 | echo again >> docs/readme.md |
| 2357 | git commit --quiet -am 'superseded, again' |
| 2358 | VALLEY_PRINCIPAL=requester git push --quiet origin superseded |
| 2359 | VALLEY_PRINCIPAL=requester valley ready --change "$id" superseded > "$r/superseded-v2.ready" 2>&1 |
| 2360 | # Its own pushes are not the worker's. |
| 2361 | : > "$reusepushes" |
| 2362 | EOF |
| 2363 | chmod +x "$r/supersede" |
| 2364 | touch "$r/supersede-armed" |
| 2365 | fresh |
| 2366 | working superseded-1 VALLEY_E2E_DURING_PASS="$r/supersede" |
| 2367 | grep -qx "project $handle v2 ready" "$r/superseded-v2.ready" |
| 2368 | said superseded-1 "$oldline: published $oldref" |
| 2369 | newhead="$(git rev-parse superseded)" |
| 2370 | newref="refs/the-valley/attestations/$(attest digest --rev superseded | cut -d: -f2)/$workerhash" |
| 2371 | said superseded-1 "project: $handle v2 at ${newhead:0:7}: published $newref" |
| 2372 | if [ "$(grep -c '^--- push' "$reusepushes")" != 2 ] || ! grep -q " $oldref\$" "$reusepushes" \ |
| 2373 | || ! grep -q " $newref\$" "$reusepushes"; then |
| 2374 | echo "valley-request: the pass did not publish the superseded version and then the new one" >&2 |
| 2375 | cat "$reusepushes" "$r/superseded-1.log" >&2 |
| 2376 | exit 1 |
| 2377 | fi |
| 2378 | fresh |
| 2379 | working superseded-2 |
| 2380 | said superseded-2 "project: $handle v2 at ${newhead:0:7}: origin holds evidence for every nix check it requires" |
| 2381 | built nothing |
| 2382 | pushed none |
| 2383 | approving superseded env -u VALLEY_ATTEST_KEY valley approve -v --head "$newhead" "$handle" |
| 2384 | built nothing |
| 2385 | [ "$(requested "c-$id")" = "$newhead" ] |
| 2386 | integrated "c-$id" "$r/worker.projects" |
| 2387 | |
| 2388 | # 21f. Origin already holds the worker's own ref for a tree, without one of |
| 2389 | # the checks the change requires. A worker publishes a tree's |
| 2390 | # evidence once, so the pass says so and builds nothing. approve without |
| 2391 | # --build-here files the request at once, naming the missing check, |
| 2392 | # and builds nothing. The real integrator holds that request as stale |
| 2393 | # for want of evidence, and keeps it. approve --build-here then builds |
| 2394 | # the rest under the operator's key and publishes the evidence alone, |
| 2395 | # since the request already stands at that head. The integrator, |
| 2396 | # judging again because evidence arrived, lands it on the two signers' |
| 2397 | # evidence. |
| 2398 | readied worker-occupied docs/readme.md src/main.txt |
| 2399 | occupiedref="refs/the-valley/attestations/$(attest digest --rev worker-occupied | cut -d: -f2)/$workerhash" |
| 2400 | attest run --rev worker-occupied --key "$r/keys/worker" --name "$workername" --check prose-format > "$r/worker-occupied-attest.out" 2>&1 |
| 2401 | git push --quiet origin "$occupiedref:$occupiedref" |
| 2402 | fresh |
| 2403 | working worker-occupied |
| 2404 | said worker-occupied "$line: origin already holds $occupiedref, this worker's evidence for its tree, and it does not cover code-build. A worker publishes a tree's evidence once, so approve --build-here builds the rest (bd-7b7d58f)" |
| 2405 | built nothing |
| 2406 | pushed none |
| 2407 | approving worker-occupied-filed valley approve -v --head "$head" "$handle" |
| 2408 | grep -q "^◐ $handle v1 approved · lands when 1 check passes ([0-9]*/[0-9]* passed)$" "$w/worker-occupied-filed.out" |
| 2409 | grep -qx ' missing code-build' "$w/worker-occupied-filed.out" |
| 2410 | built nothing |
| 2411 | if [ "$(requested "c-$id")" != "$head" ] || grep -q ' refs/the-valley/attestations/' "$reusepushes"; then |
| 2412 | echo "valley-request: approve without --build-here did not file the request alone" >&2 |
| 2413 | cat "$w/worker-occupied-filed.out" "$w/worker-occupied-filed.err" "$reusepushes" >&2 |
| 2414 | exit 1 |
| 2415 | fi |
| 2416 | integrator reconcile --repo "$served" --key "$r/keys/integrator" --name "$integratorname" \ |
| 2417 | --known-signers "$r/known-signers" --signer-projects "$r/worker.projects" --instance "$r/floor" --schema "$schemaFile" \ |
| 2418 | --attest-schema "$attestSchema" --event-schema "$eventSchema" > "$r/integrator.out" 2>&1 || { |
| 2419 | echo "valley-request: the integrator failed" >&2 |
| 2420 | cat "$r/integrator.out" >&2 |
| 2421 | exit 1 |
| 2422 | } |
| 2423 | if ! grep -q "^c-$id -> refs/heads/main @ [0-9a-f]*: stale\$" "$r/integrator.out" \ |
| 2424 | || ! grep -qE '^ check +code-build +no attestation for this check accompanies the change$' "$r/integrator.out" \ |
| 2425 | || [ "$(requested "c-$id")" != "$head" ]; then |
| 2426 | echo "valley-request: the integrator did not keep a request missing evidence as stale" >&2 |
| 2427 | cat "$r/integrator.out" >&2 |
| 2428 | exit 1 |
| 2429 | fi |
| 2430 | approving worker-occupied valley approve -v --build-here --head "$head" "$handle" |
| 2431 | built code-build |
| 2432 | grep -qx ' the request already stood at this head; the evidence is what was published' "$w/worker-occupied.out" |
| 2433 | if [ "$(grep -c '^--- push' "$reusepushes")" != 1 ] \ |
| 2434 | || ! grep -q " refs/the-valley/attestations/[0-9a-f]*/$operatorhash\$" "$reusepushes" \ |
| 2435 | || grep -q ' refs/the-valley/integration-requests/' "$reusepushes"; then |
| 2436 | echo "valley-request: approve --build-here over a standing request did not publish the evidence alone" >&2 |
| 2437 | cat "$reusepushes" >&2 |
| 2438 | exit 1 |
| 2439 | fi |
| 2440 | integrated "c-$id" "$r/worker.projects" |
| 2441 | |
| 2442 | # 21g. A read of origin that fails stops the pass, before anything is |
| 2443 | # built: with the project's origin away, the pass exits 1 and says |
| 2444 | # so, and the ready change is left for a pass that can read it. |
| 2445 | readied unread-origin docs/readme.md |
| 2446 | mv "$served" "$served.away" |
| 2447 | fresh |
| 2448 | if working unread-origin; then |
| 2449 | echo "valley-request: a pass went on past an origin it could not read" >&2 |
| 2450 | exit 1 |
| 2451 | fi |
| 2452 | mv "$served.away" "$served" |
| 2453 | grep -q '^valley: project: .*; the pass stops here$' "$r/unread-origin.log" |
| 2454 | built nothing |
| 2455 | fresh |
| 2456 | working unread-origin-again |
| 2457 | said unread-origin-again "$line: building prose-format" |
| 2458 | |
| 2459 | # await <file> <text>: wait up to a minute for the file to hold the text. |
| 2460 | await() { |
| 2461 | for _ in $(seq 600); do |
| 2462 | grep -qF -- "$2" "$1" 2> /dev/null && return |
| 2463 | sleep 0.1 |
| 2464 | done |
| 2465 | echo "valley-request: $1 never said: $2" >&2 |
| 2466 | exit 1 |
| 2467 | } |
| 2468 | |
| 2469 | # 21h. The wait after a failed batch runs from when the batch ended. The |
| 2470 | # clock is not fixed here. The stand-in takes 3 seconds and then |
| 2471 | # fails, so the batch's wait ends at least 15 minutes after it ended, |
| 2472 | # which is more than 15 minutes after the pass began. Past the wait, |
| 2473 | # the batch is built and published. |
| 2474 | readied slow docs/readme.md |
| 2475 | slowdigest="$(attest digest --rev slow | cut -d: -f2)" |
| 2476 | began="$(date -u +%s)" |
| 2477 | fresh |
| 2478 | if working slow-1 VALLEY_E2E_DURING_PASS='sleep 3; exit 1'; then |
| 2479 | echo "valley-request: a pass whose batch failed exited 0" >&2 |
| 2480 | exit 1 |
| 2481 | fi |
| 2482 | retry="$(jq -r --arg key "build $slowdigest prose-format" '.projects.project[$key].retry' "$wstate/failures.json")" |
| 2483 | if [ "$(($(date -u -d "$retry" +%s) - began))" -lt 903 ]; then |
| 2484 | echo "valley-request: the wait after a 3-second batch ends at $retry, less than 15 minutes after it ended; the pass began at $(date -u -d "@$began" +%FT%TZ)" >&2 |
| 2485 | exit 1 |
| 2486 | fi |
| 2487 | fresh |
| 2488 | working slow-2 VALLEY_NOW=2099-01-01T00:00:00Z |
| 2489 | said slow-2 "$line: published refs/the-valley/attestations/$slowdigest/$workerhash" |
| 2490 | |
| 2491 | # 21i. A failed push waits too, by the object it would publish. Two changes |
| 2492 | # whose heads hold the same tree share one attestation ref, and origin |
| 2493 | # takes no push. The first pass builds once and tries one push. It |
| 2494 | # then reads both changes again, and each one's push waits behind that |
| 2495 | # failure. A pass within the minute tries no push. The next failure doubles the wait. Past it, the |
| 2496 | # ref is published once, and the record of it is gone. |
| 2497 | cat > "$r/counted" <<EOF |
| 2498 | #!$(command -v bash) |
| 2499 | echo push >> "$r/push-attempts" |
| 2500 | echo "the connection dropped" >&2 |
| 2501 | exit 1 |
| 2502 | EOF |
| 2503 | chmod +x "$r/counted" |
| 2504 | refusing=(GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=remote.origin.receivepack GIT_CONFIG_VALUE_0="$r/counted") |
| 2505 | readied twin-a docs/readme.md |
| 2506 | git checkout --quiet -B twin-b origin/main |
| 2507 | git checkout --quiet twin-a -- docs/readme.md |
| 2508 | git commit --quiet -m twin-b |
| 2509 | VALLEY_PRINCIPAL=requester git push --quiet origin twin-b |
| 2510 | VALLEY_PRINCIPAL=requester valley ready twin-b > "$r/twin-b.ready" 2>&1 |
| 2511 | [ "$(git rev-parse 'twin-a^{tree}')" = "$(git rev-parse 'twin-b^{tree}')" ] |
| 2512 | twinref="refs/the-valley/attestations/$(attest digest --rev twin-a | cut -d: -f2)/$workerhash" |
| 2513 | # attempts <n> <name> <failed> <waiting>: origin was offered n pushes in |
| 2514 | # all, and the pass's log says failed and waiting for the twins' ref that |
| 2515 | # many times each, with the wait ending at the time given last. |
| 2516 | attempts() { |
| 2517 | local until="$5" |
| 2518 | if [ "$(wc -l < "$r/push-attempts")" != "$1" ] \ |
| 2519 | || [ "$(grep -c ": could not publish $twinref; it is not pushed again before $until\$" "$r/$2.log")" != "$3" ] \ |
| 2520 | || [ "$(grep -c ": publishing $twinref failed [0-9]* times\? in a row, so it is not pushed again before $until\$" "$r/$2.log")" != "$4" ]; then |
| 2521 | echo "valley-request: the pass $2 did not offer origin the twins' ref as often as expected" >&2 |
| 2522 | cat "$r/push-attempts" "$r/$2.log" >&2 |
| 2523 | exit 1 |
| 2524 | fi |
| 2525 | } |
| 2526 | : > "$r/push-attempts" |
| 2527 | fresh |
| 2528 | if working twins-1 VALLEY_NOW=2026-10-24T09:00:00Z "${refusing[@]}"; then |
| 2529 | echo "valley-request: a pass whose push failed exited 0" >&2 |
| 2530 | exit 1 |
| 2531 | fi |
| 2532 | built prose-format |
| 2533 | attempts 1 twins-1 1 2 2026-10-24T09:01:00Z |
| 2534 | working twins-2 VALLEY_NOW=2026-10-24T09:00:59Z "${refusing[@]}" |
| 2535 | attempts 1 twins-2 0 2 2026-10-24T09:01:00Z |
| 2536 | if working twins-3 VALLEY_NOW=2026-10-24T09:01:00Z "${refusing[@]}"; then |
| 2537 | echo "valley-request: a pass whose push failed again exited 0" >&2 |
| 2538 | exit 1 |
| 2539 | fi |
| 2540 | attempts 2 twins-3 1 1 2026-10-24T09:03:00Z |
| 2541 | fresh |
| 2542 | working twins-4 VALLEY_NOW=2026-10-24T09:03:00Z |
| 2543 | built nothing |
| 2544 | pushed "$twinref" |
| 2545 | [ ! -e "$wstate/failures.json" ] || { |
| 2546 | echo "valley-request: the record of a push that went through was kept" >&2 |
| 2547 | cat "$wstate/failures.json" >&2 |
| 2548 | exit 1 |
| 2549 | } |
| 2550 | |
| 2551 | # 21j. A pass forgets only the failures of the projects it read whole. The |
| 2552 | # host serves a second project, other, with no ready change. A batch of |
| 2553 | # this project fails. A pass over other alone leaves that wait as it |
| 2554 | # is, so the next pass over this project does not build the batch. |
| 2555 | git init --quiet --bare "$r/other.git" |
| 2556 | git -C "$instance" update-ref refs/the-valley/projects \ |
| 2557 | "$(printf 'other\nproject\n' | git -C "$instance" hash-object -w --stdin)" |
| 2558 | readied flapping docs/readme.md |
| 2559 | flappingref="refs/the-valley/attestations/$(attest digest --rev flapping | cut -d: -f2)/$workerhash" |
| 2560 | if working flapping-1 VALLEY_NOW=2026-10-25T09:00:00Z VALLEY_E2E_DURING_PASS='exit 1'; then |
| 2561 | echo "valley-request: a pass whose batch failed exited 0" >&2 |
| 2562 | exit 1 |
| 2563 | fi |
| 2564 | (cd "$r/worker-home" && VALLEY_PRINCIPAL=worker VALLEY_NOW=2026-10-25T09:01:00Z valley-worker --repo other \ |
| 2565 | --key "$r/keys/worker" --name "$workername" --state "$wstate") > "$r/other.log" 2>&1 || { |
| 2566 | echo "valley-request: a pass over other failed" >&2 |
| 2567 | cat "$r/other.log" >&2 |
| 2568 | exit 1 |
| 2569 | } |
| 2570 | fresh |
| 2571 | working flapping-2 VALLEY_NOW=2026-10-25T09:02:00Z |
| 2572 | said flapping-2 "$line: its batch prose-format failed 1 time in a row, so it is not built again before 2026-10-25T09:15:00Z" |
| 2573 | built nothing |
| 2574 | fresh |
| 2575 | working flapping-3 VALLEY_NOW=2026-10-25T09:15:00Z |
| 2576 | said flapping-3 "$line: published $flappingref" |
| 2577 | |
| 2578 | # 21k. A pass killed while attest runs. attest holds the lock it was |
| 2579 | # handed, so a second pass waits for attest to end rather than build |
| 2580 | # the same batch beside it. Then the second pass finds the ref the |
| 2581 | # orphaned attest stored, publishes it, and builds nothing. |
| 2582 | readied killed docs/readme.md |
| 2583 | killedref="refs/the-valley/attestations/$(attest digest --rev killed | cut -d: -f2)/$workerhash" |
| 2584 | cat > "$r/hold-kill" <<EOF |
| 2585 | #!$(command -v bash) |
| 2586 | [ -e "$r/kill-armed" ] || exit 0 |
| 2587 | rm -f "$r/kill-armed" |
| 2588 | # The worker is the nearest process above this one named valley-go. |
| 2589 | p=\$\$ |
| 2590 | while [ "\$p" -gt 1 ]; do |
| 2591 | if [ "\$(cat "/proc/\$p/comm")" = valley-go ]; then |
| 2592 | echo "\$p" > "$r/killed.pid" |
| 2593 | break |
| 2594 | fi |
| 2595 | read -r _ _ _ p _ < "/proc/\$p/stat" |
| 2596 | done |
| 2597 | for _ in \$(seq 600); do |
| 2598 | [ -e "$r/release" ] && exit 0 |
| 2599 | sleep 0.1 |
| 2600 | done |
| 2601 | exit 1 |
| 2602 | EOF |
| 2603 | chmod +x "$r/hold-kill" |
| 2604 | touch "$r/kill-armed" |
| 2605 | fresh |
| 2606 | working killed-1 VALLEY_E2E_DURING_PASS="$r/hold-kill" & |
| 2607 | killedpass=$! |
| 2608 | await "$r/killed.pid" "" |
| 2609 | kill -9 "$(cat "$r/killed.pid")" |
| 2610 | status=0 |
| 2611 | wait "$killedpass" || status=$? |
| 2612 | [ "$status" = 137 ] || { |
| 2613 | echo "valley-request: the killed pass ended with $status" >&2 |
| 2614 | exit 1 |
| 2615 | } |
| 2616 | working killed-2 & |
| 2617 | secondpass=$! |
| 2618 | await "$r/killed-2.log" "valley: another pass holds $wstate/lock; waiting for it to end" |
| 2619 | touch "$r/release" |
| 2620 | wait "$secondpass" |
| 2621 | said killed-2 "$line: an earlier pass stored $killedref, and origin does not hold it" |
| 2622 | said killed-2 "$line: published $killedref" |
| 2623 | built prose-format |
| 2624 | pushed "$killedref" |
| 2625 | |
| 2626 | # 21l. A cache clone whose making was interrupted. A stand-in for git takes |
| 2627 | # the clone's config.lock as it sets the origin, kills the worker, and |
| 2628 | # dies holding the lock, as git killed mid-write does. The next pass |
| 2629 | # makes the clone again and reads the project through it. The worker |
| 2630 | # runs as valley-go here, since the package's wrapper puts its own git |
| 2631 | # ahead of the stand-in. |
| 2632 | cachehome="$r/interrupted-cache" |
| 2633 | interrupted="$cachehome/valley/repos/$(printf '%s' "$served" | sha256sum | cut -c1-16)-project" |
| 2634 | mkdir -p "$r/killing-git" |
| 2635 | cat > "$r/killing-git/git" <<EOF |
| 2636 | #!$(command -v bash) |
| 2637 | if [ "\${1:-} \${2:-}" = "remote add" ]; then |
| 2638 | : > .git/config.lock |
| 2639 | kill -9 "\$PPID" |
| 2640 | kill -9 "\$\$" |
| 2641 | fi |
| 2642 | exec "$(command -v git)" "\$@" |
| 2643 | EOF |
| 2644 | chmod +x "$r/killing-git/git" |
| 2645 | status=0 |
| 2646 | (cd "$r/worker-home" && VALLEY_PRINCIPAL=worker XDG_CACHE_HOME="$cachehome" PATH="$r/killing-git:$PATH" \ |
| 2647 | VALLEY_VERIFICATION_SCHEMA="$schemaFile" valley-go work --repo project \ |
| 2648 | --key "$r/keys/worker" --name "$workername" --state "$wstate") > "$r/interrupted-1.log" 2>&1 || status=$? |
| 2649 | if [ "$status" != 137 ] || [ -z "$(find "$cachehome" -name config.lock)" ]; then |
| 2650 | echo "valley-request: the stand-in did not interrupt the clone's making while holding its config.lock ($status)" >&2 |
| 2651 | cat "$r/interrupted-1.log" >&2 |
| 2652 | exit 1 |
| 2653 | fi |
| 2654 | # recovered <name>: a pass over the cache at $cachehome succeeds, and the |
| 2655 | # clone it reads the project through names origin. |
| 2656 | recovered() { |
| 2657 | fresh |
| 2658 | working "$1" XDG_CACHE_HOME="$cachehome" || { |
| 2659 | echo "valley-request: the pass after an interrupted clone failed" >&2 |
| 2660 | cat "$r/$1.log" >&2 |
| 2661 | exit 1 |
| 2662 | } |
| 2663 | [ "$(git -C "$interrupted" config --get remote.origin.url)" = "$served" ] |
| 2664 | said "$1" "$livelyline: requires no nix check" |
| 2665 | built nothing |
| 2666 | } |
| 2667 | recovered interrupted-2 |
| 2668 | |
| 2669 | # 21m. A clone left half made in its place, as an older version left one: |
| 2670 | # a repository with no origin, and a stale config.lock beside its |
| 2671 | # configuration. The next pass sets it aside, makes the clone again, |
| 2672 | # and reads the project through it. |
| 2673 | cachehome="$r/half-made-cache" |
| 2674 | interrupted="$cachehome/valley/repos/$(printf '%s' "$served" | sha256sum | cut -c1-16)-project" |
| 2675 | git init --quiet "$interrupted" |
| 2676 | : > "$interrupted/.git/config.lock" |
| 2677 | recovered half-made |
| 2678 | [ ! -e "$interrupted/.git/config.lock" ] |
| 2679 | |
| 2680 | worktrees="$(git worktree list --porcelain | grep -c '^worktree ' || true)" |
| 2681 | if [ "$worktrees" != 1 ]; then |
| 2682 | echo "valley-request: a throwaway worktree was left behind in the reuse project" >&2 |
| 2683 | git worktree list >&2 |
| 2684 | exit 1 |
| 2685 | fi |
| 2686 | |
| 2687 | # ---------------------------------------------------------------------- |
| 2688 | # 22. approve reads each ref by its exact name. Given a ref name that is |
| 2689 | # missing, git goes on to try other names for it, refs/tags/<name> |
| 2690 | # and refs/heads/<name> among them. ls-remote and fetch take a ref |
| 2691 | # whose name ends in the one asked for. Any pusher can make such a |
| 2692 | # ref, and a fetch brings a tag along with the commits it names. Each |
| 2693 | # case leaves a ref missing, makes the ref git would take for it, and |
| 2694 | # shows that approve treats the ref as missing. Every branch here |
| 2695 | # touches quiet/ alone, so nothing is required and no key is needed. |
| 2696 | # The refs are read here with show-ref, which reads that exact name. |
| 2697 | lookorigin="$TMPDIR/lookalike.git" |
| 2698 | git init --quiet --bare "$lookorigin" |
| 2699 | look="$TMPDIR/lookalike" |
| 2700 | git init --quiet "$look" |
| 2701 | cd "$look" || exit 1 |
| 2702 | git remote add origin "$lookorigin" |
| 2703 | mkdir -p docs policy |
| 2704 | echo "the readme" > docs/readme.md |
| 2705 | echo "$valley" > policy/valley |
| 2706 | git add -A |
| 2707 | git commit --quiet -m base |
| 2708 | git push --quiet origin main |
| 2709 | lookbase="$(git rev-parse main)" |
| 2710 | quiet_branch() { |
| 2711 | git checkout --quiet -b "topic/$1" "$2" |
| 2712 | mkdir -p quiet |
| 2713 | echo "a quiet note for $1" > quiet/note.md |
| 2714 | git add -A |
| 2715 | git commit --quiet -m "a quiet note for $1" |
| 2716 | git push --quiet origin "topic/$1" |
| 2717 | git checkout --quiet main |
| 2718 | } |
| 2719 | # The request ref approve filed on lookorigin, or nothing. |
| 2720 | filed() { |
| 2721 | git -C "$lookorigin" show-ref --verify --hash \ |
| 2722 | "refs/the-valley/integration-requests/main/topic-$1" 2> /dev/null || true |
| 2723 | } |
| 2724 | |
| 2725 | # A request ref that is missing, with a branch on origin named like it at |
| 2726 | # the head approved. Read through that branch, the request would already |
| 2727 | # stand at this head, and approve would report success and file nothing. |
| 2728 | # git push matches its destination the same way, so a push to the |
| 2729 | # request ref would write that branch, and approve refuses to push at |
| 2730 | # all while it stands. Once it is deleted, approve files the request. |
| 2731 | quiet_branch lookalike main |
| 2732 | lookhead="$(git rev-parse topic/lookalike)" |
| 2733 | lookref=refs/heads/refs/the-valley/integration-requests/main/topic-lookalike |
| 2734 | git -C "$lookorigin" update-ref "$lookref" "$lookhead" |
| 2735 | if env -u VALLEY_ATTEST_KEY valley approve -v origin/topic/lookalike < /dev/null \ |
| 2736 | > "$w/lookalike.out" 2> "$w/lookalike.err"; then |
| 2737 | echo "valley-request: approve reported success with a branch named like the request it files" >&2 |
| 2738 | cat "$w/lookalike.out" >&2 |
| 2739 | exit 1 |
| 2740 | fi |
| 2741 | grep -qF "⊘ topic/lookalike not approved · origin holds $lookref, " "$w/lookalike.err" |
| 2742 | grep -qxF " delete $lookref on origin" "$w/lookalike.err" |
| 2743 | [ -z "$(filed lookalike)" ] || { |
| 2744 | echo "valley-request: approve filed a request past a branch named like it" >&2 |
| 2745 | exit 1 |
| 2746 | } |
| 2747 | git -C "$lookorigin" update-ref -d "$lookref" |
| 2748 | env -u VALLEY_ATTEST_KEY valley approve -v origin/topic/lookalike < /dev/null \ |
| 2749 | > "$w/lookalike-again.out" 2> "$w/lookalike-again.err" |
| 2750 | if [ "$(filed lookalike)" != "$lookhead" ]; then |
| 2751 | echo "valley-request: with the branch named like it gone, approve filed no request" >&2 |
| 2752 | cat "$w/lookalike-again.out" "$w/lookalike-again.err" >&2 |
| 2753 | exit 1 |
| 2754 | fi |
| 2755 | |
| 2756 | # A branch that is not on origin, with a tag origin carries named like its |
| 2757 | # remote-tracking ref. The fetch brings the tag, and read through it the |
| 2758 | # branch would be approved at the tag's commit. |
| 2759 | git -C "$lookorigin" update-ref refs/tags/refs/remotes/origin/topic/gone "$lookhead" |
| 2760 | if env -u VALLEY_ATTEST_KEY valley approve -v origin/topic/gone < /dev/null \ |
| 2761 | > "$w/gone.out" 2> "$w/gone.err"; then |
| 2762 | echo "valley-request: approve filed a branch origin does not have, at a tag named like it" >&2 |
| 2763 | exit 1 |
| 2764 | fi |
| 2765 | # The verb refuses it itself, before approve reads the branch again. |
| 2766 | grep -qx 'valley: no such branch on origin: topic/gone' "$w/gone.err" |
| 2767 | git show-ref --verify --quiet refs/tags/refs/remotes/origin/topic/gone || { |
| 2768 | echo "valley-request: the fetch did not bring the tag, so nothing was tested" >&2 |
| 2769 | exit 1 |
| 2770 | } |
| 2771 | [ -z "$(filed gone)" ] || { |
| 2772 | echo "valley-request: approve filed a request for a branch origin does not have" >&2 |
| 2773 | exit 1 |
| 2774 | } |
| 2775 | if valley review topic/gone < /dev/null > "$w/gone-review.out" 2> "$w/gone-review.err"; then |
| 2776 | echo "valley-request: review went on with a branch origin does not have" >&2 |
| 2777 | exit 1 |
| 2778 | fi |
| 2779 | # review refuses it before it reads the stack, and says nothing else. |
| 2780 | if [ "$(cat "$w/gone-review.err")" != 'valley: no such branch on origin: topic/gone' ]; then |
| 2781 | echo "valley-request: review read a branch origin does not have before refusing it:" >&2 |
| 2782 | cat "$w/gone-review.err" >&2 |
| 2783 | exit 1 |
| 2784 | fi |
| 2785 | |
| 2786 | # An owning valley with no main, and a branch on it named |
| 2787 | # refs/heads/main, which git stores as refs/heads/refs/heads/main. Fetched |
| 2788 | # through that branch, the floor would come from it. |
| 2789 | lookvalley="$TMPDIR/lookalike-valley.git" |
| 2790 | git init --quiet --bare "$lookvalley" |
| 2791 | git -C "$valleywork" push --quiet "$lookvalley" main:refs/heads/refs/heads/main |
| 2792 | echo "$lookvalley" > policy/valley |
| 2793 | git commit --quiet -am "a valley with no main" |
| 2794 | git push --quiet origin main |
| 2795 | quiet_branch floorless main |
| 2796 | if env -u VALLEY_ATTEST_KEY valley approve -v origin/topic/floorless < /dev/null \ |
| 2797 | > "$w/floorless.out" 2> "$w/floorless.err"; then |
| 2798 | echo "valley-request: approve read a floor from a valley with no main" >&2 |
| 2799 | exit 1 |
| 2800 | fi |
| 2801 | grep -qF "the owning valley $lookvalley has no refs/heads/main" "$w/floorless.err" |
| 2802 | [ -z "$(filed floorless)" ] || { |
| 2803 | echo "valley-request: approve filed a request under a valley with no main" >&2 |
| 2804 | exit 1 |
| 2805 | } |
| 2806 | |
| 2807 | # origin with no main, and a tag origin carries named like main's |
| 2808 | # remote-tracking ref, at a commit whose floor requires nothing of this |
| 2809 | # branch. Read through the tag, approve would derive the policy from it |
| 2810 | # and file the request. |
| 2811 | quiet_branch mainless "$lookbase" |
| 2812 | git -C "$lookorigin" update-ref refs/tags/refs/remotes/origin/main "$lookbase" |
| 2813 | git -C "$lookorigin" update-ref -d refs/heads/main |
| 2814 | if env -u VALLEY_ATTEST_KEY valley approve -v origin/topic/mainless < /dev/null \ |
| 2815 | > "$w/mainless.out" 2> "$w/mainless.err"; then |
| 2816 | echo "valley-request: approve filed a request while origin has no main" >&2 |
| 2817 | exit 1 |
| 2818 | fi |
| 2819 | grep -qx '⊘ topic/mainless not approved · origin has no main to approve onto' "$w/mainless.err" |
| 2820 | git show-ref --verify --quiet refs/tags/refs/remotes/origin/main || { |
| 2821 | echo "valley-request: the fetch did not bring the tag, so nothing was tested" >&2 |
| 2822 | exit 1 |
| 2823 | } |
| 2824 | [ -z "$(filed mainless)" ] || { |
| 2825 | echo "valley-request: approve filed a request while origin has no main" >&2 |
| 2826 | exit 1 |
| 2827 | } |
| 2828 | cd "$repo" || exit 1 |
| 2829 | |
| 2830 | # ---------------------------------------------------------------------- |
| 2831 | # The verbs the loop offers are the whole of what an operator can do to a |
| 2832 | # branch, so no path may offer one outside the set: [a]pprove, [r]eject, |
| 2833 | # [s]kip, and [v]iew full diff, which only shows. A change alone is never |
| 2834 | # offered [b]ase. Every stream this check captured is scanned at the end, |
| 2835 | # which is what makes the claim about paths rather than about the |
| 2836 | # prompts pinned character for character above — the fast-forward prompt, |
| 2837 | # the one under the behind-main line, and the ones a refused [a]pprove |
| 2838 | # returns to are all in here. A verb that writes the protected ref from the |
| 2839 | # operator's own checkout — the retired [i]ntegrate, or any successor to |
| 2840 | # it — fails this wherever it is printed. |
| 2841 | offered="$(cat "$w"/*.out | grep -o '\[[a-z]\][a-z]*' | sort -u || true)" |
| 2842 | outside="$(printf '%s\n' "$offered" | grep -vxE '\[a\]pprove|\[r\]eject|\[s\]kip|\[v\]iew' || true)" |
| 2843 | if [ -n "$outside" ]; then |
| 2844 | echo "valley-request: a review path offered a verb outside the set:" >&2 |
| 2845 | printf '%s\n' "$outside" >&2 |
| 2846 | exit 1 |
| 2847 | fi |
| 2848 | # The scan is only worth something if it saw the offers at all. |
| 2849 | for verb in '[a]pprove' '[r]eject' '[s]kip' '[v]iew'; do |
| 2850 | printf '%s\n' "$offered" | grep -qxF "$verb" \ |
| 2851 | || { echo "valley-request: no captured session offered $verb" >&2; exit 1; } |
| 2852 | done |
| 2853 | |
| 2854 | # No throwaway worktree outlived any of it: only the checkout is left. |
| 2855 | worktrees="$(git worktree list --porcelain | grep -c '^worktree ' || true)" |
| 2856 | if [ "$worktrees" != 1 ]; then |
| 2857 | echo "valley-request: a throwaway worktree was left behind" >&2 |
| 2858 | git worktree list >&2 |
| 2859 | exit 1 |
| 2860 | fi |
| 2861 | |
| 2862 | echo "every scenario held" |
| 2863 | { |
| 2864 | cat "$w/approve.out" |
| 2865 | printf '\n--- the scratch origin, after all of it ---\n' |
| 2866 | git -C "$origin" for-each-ref --format='%(objectname) %(refname)' |
| 2867 | } > "$out" |