| 1 | #!/usr/bin/env bash |
| 2 | # The integrator, driven end to end over scratch repositories and throwaway |
| 3 | # keys. It runs the real binaries: `attest` produces the evidence, the |
| 4 | # `valley` deriver composes the policy, and the `integrator` judges and |
| 5 | # lands. Only the nix evaluator is stood in for (integrator/e2e/nix), and |
| 6 | # only because a nix build has no daemon to call. |
| 7 | # |
| 8 | # Each scenario below is one of the phase's exit criteria, observed rather |
| 9 | # than asserted about. Nothing here touches a repository outside its own |
| 10 | # scratch directory, and no ref is ever created anywhere but there. |
| 11 | set -euo pipefail |
| 12 | |
| 13 | work="$(mktemp -d)" |
| 14 | trap 'rm -rf "$work"' EXIT |
| 15 | here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 16 | |
| 17 | export HOME="$work" |
| 18 | export GIT_CONFIG_NOSYSTEM=1 |
| 19 | # Scratch goes where the run puts it, as it does under the unit, so what |
| 20 | # a pass leaves behind is observable rather than scattered through /tmp. |
| 21 | export TMPDIR="$work/tmp" |
| 22 | mkdir -p "$TMPDIR" |
| 23 | export VALLEY_FAKE_STORE="$work/store" |
| 24 | export PATH="$here:$PATH" # the nix stand-ins, ahead of anything real |
| 25 | |
| 26 | git config --global user.name valley-check |
| 27 | git config --global user.email valley-check@localhost |
| 28 | git config --global init.defaultBranch main |
| 29 | git config --global advice.detachedHead false |
| 30 | |
| 31 | say() { printf '\n=== %s\n' "$*"; } |
| 32 | die() { |
| 33 | printf '\nintegrator-e2e: %s\n' "$*" >&2 |
| 34 | exit 1 |
| 35 | } |
| 36 | holds() { printf ' ok: %s\n' "$*"; } |
| 37 | |
| 38 | # ---------------------------------------------------------------------- |
| 39 | say "keys: a contributor, an integrator, and a stranger" |
| 40 | |
| 41 | for who in contributor integrator stranger; do |
| 42 | ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$work/$who" |
| 43 | done |
| 44 | contributor=contributor.valley.invalid/attestations |
| 45 | integrator_name=integrator.valley.invalid/attestations |
| 46 | stranger=stranger.elsewhere.invalid/attestations |
| 47 | |
| 48 | # The known-signers file is the registry's interim compilation |
| 49 | # (dcr-b87f6e8): the integrator accepts the contributor and nobody else. |
| 50 | attest key --key "$work/contributor" --name "$contributor" > "$work/known_signers" |
| 51 | # What a reader of a landed note holds: both parties to it. |
| 52 | cat "$work/known_signers" > "$work/reader_keys" |
| 53 | attest key --key "$work/integrator" --name "$integrator_name" >> "$work/reader_keys" |
| 54 | attest key --key "$work/stranger" --name "$stranger" > "$work/stranger_key" |
| 55 | # The key hash the integrator's own attestation refs are keyed by. |
| 56 | ihash="$(attest key --key "$work/integrator" --name "$integrator_name" | cut -d+ -f2)" |
| 57 | holds "the integrator holds one signer: $(cut -d+ -f1 < "$work/known_signers")" |
| 58 | |
| 59 | # ---------------------------------------------------------------------- |
| 60 | say "the served repository, and the instance policy layer" |
| 61 | |
| 62 | origin="$work/project.git" |
| 63 | git init --quiet --bare "$origin" |
| 64 | repo="$work/project" |
| 65 | git init --quiet "$repo" |
| 66 | cd "$repo" |
| 67 | git remote add origin "$origin" |
| 68 | |
| 69 | mkdir -p docs src deploy checks policy/project |
| 70 | echo "the readme" > docs/readme.md |
| 71 | echo "the source" > src/main.txt |
| 72 | echo "the deployment" > deploy/target.txt |
| 73 | # What each check reads, which the nix stand-in turns into its closure. |
| 74 | echo docs > checks/prose-format.inputs |
| 75 | echo src > checks/code-build.inputs |
| 76 | |
| 77 | # The project layer: it declares its own classes and checks above the |
| 78 | # floor, and declines nothing. It sits at policy/project, which is where the |
| 79 | # integrator looks without being told (dcr-f41f718). |
| 80 | cat > policy/project/policy.cue <<'EOF' |
| 81 | package verification |
| 82 | |
| 83 | project: { |
| 84 | checks: { |
| 85 | "prose-format": {runner: "nix", attribute: "prose-format"} |
| 86 | "code-build": {runner: "nix", attribute: "code-build"} |
| 87 | // An effectful check, with the validity window dcr-439b771 calls |
| 88 | // Δ. Its observation transfers while nothing in the class that |
| 89 | // requires it has landed under it and it is younger than this. |
| 90 | reachable: {runner: "command", command: "true", validity: "1h"} |
| 91 | } |
| 92 | classes: { |
| 93 | prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 94 | code: {paths: "src/**": true, requires: "code-build": true} |
| 95 | deploy: {paths: "deploy/**": true, requires: reachable: true} |
| 96 | } |
| 97 | unclassified: {} |
| 98 | } |
| 99 | EOF |
| 100 | |
| 101 | git add -A |
| 102 | git commit --quiet -m "seed the project" |
| 103 | git push --quiet origin main |
| 104 | |
| 105 | # The instance layer lives outside the project's tree, and the integrator |
| 106 | # reads it from there: a change never supplies the policy that gates it. The |
| 107 | # floor is the group's own repository's, read at the tip that has been |
| 108 | # integrated (dcr-f41f718), and it sits at policy/instance in that tip. |
| 109 | instance_repo="$work/instance.git" |
| 110 | git init --quiet --bare "$instance_repo" |
| 111 | floor="$work/instance-project" |
| 112 | git init --quiet "$floor" |
| 113 | mkdir -p "$floor/policy/instance" |
| 114 | cat > "$floor/policy/instance/floor.cue" <<'EOF' |
| 115 | package verification |
| 116 | |
| 117 | floor: { |
| 118 | checks: {} |
| 119 | classes: {} |
| 120 | unclassified: {} |
| 121 | } |
| 122 | EOF |
| 123 | git -C "$floor" add -A |
| 124 | git -C "$floor" commit --quiet -m "seed the floor" |
| 125 | git -C "$floor" push --quiet "$instance_repo" main |
| 126 | |
| 127 | # The fallback source, for a host that serves no instance repository: the |
| 128 | # same documents, materialized as a directory. One scenario below reads the |
| 129 | # floor that way, and every other reads it from the repository. |
| 130 | instance="$work/instance" |
| 131 | mkdir -p "$instance" |
| 132 | cp "$floor/policy/instance/floor.cue" "$instance/floor.cue" |
| 133 | |
| 134 | holds "the floor is policy/instance at $instance_repo's tip, and the project's layer is policy/project at its own" |
| 135 | |
| 136 | # ---------------------------------------------------------------------- |
| 137 | # Helpers. |
| 138 | |
| 139 | # attest_change <branch> <check spec…> — run the checks over the branch's |
| 140 | # tip and publish the branch with its attestation ref, atomically. |
| 141 | attest_change() { |
| 142 | local branch="$1" key="${2:-$work/contributor}" name="${3:-$contributor}" |
| 143 | shift 3 |
| 144 | attest run --repo "$repo" --key "$key" --name "$name" \ |
| 145 | --push origin --branch "$branch" "$@" |
| 146 | } |
| 147 | |
| 148 | # request <change> <target> <commit> — the contributor files an integration |
| 149 | # request by pushing one ref. That ref is the whole of the request. |
| 150 | request() { |
| 151 | git push --quiet origin "$3:refs/the-valley/integration-requests/$2/$1" |
| 152 | } |
| 153 | |
| 154 | # reconcile [flag…] — one pass. A flag given here overrides the one set |
| 155 | # before it. |
| 156 | reconcile() { |
| 157 | # Neither policy path is stated: both layers come from where the |
| 158 | # integrator defaults to looking, which is the whole of what a deployment |
| 159 | # following the convention says about policy. |
| 160 | integrator reconcile \ |
| 161 | --repo "$origin" \ |
| 162 | --key "$work/integrator" --name "$integrator_name" \ |
| 163 | --known-signers "$work/known_signers" \ |
| 164 | --instance-repo "$instance_repo" \ |
| 165 | --schema "$SCHEMA_VERIFICATION" \ |
| 166 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 167 | --event-schema "$SCHEMA_EVENTS" \ |
| 168 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 169 | "$@" |
| 170 | } |
| 171 | |
| 172 | # integrate [flag…] — one pass, its output kept in last.out. pre is main's |
| 173 | # tip on origin before the pass. |
| 174 | integrate() { |
| 175 | pre="$(tip)" |
| 176 | reconcile "$@" 2>&1 | tee "$work/last.out" |
| 177 | grep -q . "$work/last.out" || die "the integrator said nothing" |
| 178 | } |
| 179 | |
| 180 | tip() { git -C "$origin" rev-parse refs/heads/main; } |
| 181 | # landed_as HEAD BEFORE [REPO [NAME]] — main in REPO, origin by default, |
| 182 | # is the one commit the integrator signing as NAME made for the change |
| 183 | # whose head is HEAD, on BEFORE, the tip main was at before the pass: |
| 184 | # HEAD's tree, the integrator as committer, BEFORE as its one parent, and |
| 185 | # main one commit ahead of BEFORE. So none of HEAD's own commits reached |
| 186 | # main in the pass. |
| 187 | landed_as() { |
| 188 | local in="${3:-$origin}" name="${4:-$integrator_name}" main |
| 189 | main="$(git -C "$in" rev-parse refs/heads/main)" |
| 190 | [ "$main" != "$1" ] || die "main is at $1 itself, not a commit the integrator made" |
| 191 | [ "$(git -C "$in" rev-parse "$main^{tree}")" = "$(git -C "$in" rev-parse "$1^{tree}")" ] \ |
| 192 | || die "main does not hold the tree of $1" |
| 193 | [ "$(git -C "$in" rev-list --no-walk --parents "$main")" = "$main $2" ] \ |
| 194 | || die "main's tip is not one commit whose one parent is $2, the tip before the pass" |
| 195 | [ "$(git -C "$in" rev-list --count "$2..$main")" = 1 ] \ |
| 196 | || die "main gained more than one commit in the pass" |
| 197 | [ "$(git -C "$in" log -1 --format=%cn "$main")" = "$name" ] \ |
| 198 | || die "main's tip was not committed by the integrator" |
| 199 | } |
| 200 | # transfer_path COMMIT — where an attestation ref holds the transfer |
| 201 | # statement for a landing as COMMIT (change.TransferPath). |
| 202 | transfer_path() { printf 'transfer.d/%s/%s/%s.note' "${1:0:2}" "${1:2:2}" "${1:4}"; } |
| 203 | forget() { git -C "$origin" update-ref -d "refs/the-valley/integration-requests/main/$1"; } |
| 204 | |
| 205 | # ---------------------------------------------------------------------- |
| 206 | say "1. a change with valid transferring evidence lands" |
| 207 | |
| 208 | before="$(tip)" |
| 209 | git checkout --quiet -b c1 |
| 210 | echo "a better readme" > docs/readme.md |
| 211 | echo "a new target" > deploy/second.txt |
| 212 | git add -A |
| 213 | git commit --quiet -m "improve the readme and add a target" |
| 214 | attest_change c1 "" "" --check prose-format --command reachable=true |
| 215 | request c1 main "$(git rev-parse c1)" |
| 216 | integrate |
| 217 | |
| 218 | grep -q "^c1 -> refs/heads/main .*: land$" "$work/last.out" || die "c1 did not land" |
| 219 | grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer" |
| 220 | grep -q "check reachable .*transferred (untouched)" "$work/last.out" || die "the effectful check did not transfer" |
| 221 | grep -q '"event":"integration-succeeded"' "$work/last.out" || die "no integration-succeeded event" |
| 222 | # The landing's own ref-updated event, vetted against #RefUpdated like the rest. |
| 223 | grep -qF "event ref-updated {\"event\":\"ref-updated\",\"repo\":" "$work/last.out" \ |
| 224 | || die "no ref-updated event" |
| 225 | [ "$(tip)" != "$before" ] || die "the protected ref did not move" |
| 226 | landed_as "$(git rev-parse c1)" "$pre" |
| 227 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c1 > /dev/null \ |
| 228 | && die "the request ref outlived the landing" |
| 229 | holds "main moved $(git rev-parse --short "$before") -> $(git -C "$origin" rev-parse --short refs/heads/main)" |
| 230 | |
| 231 | # The landing is recorded per head: a commit with no parent, holding one |
| 232 | # file that names the landed commit, the request and the head. The outcome |
| 233 | # record, written in the same transaction, says land. |
| 234 | record="refs/the-valley/integration-landings/main/$(git rev-parse c1)" |
| 235 | [ "$(git -C "$origin" cat-file blob "$record:landing")" = "$(printf 'landed %s\nrequest c1\nhead %s' "$(tip)" "$(git rev-parse c1)")" ] \ |
| 236 | || die "the landing record does not name the landing: $(git -C "$origin" cat-file blob "$record:landing" 2>&1)" |
| 237 | [ "$(git -C "$origin" rev-list --no-walk --parents "$record" | wc -w)" = 1 ] || die "the landing record's commit has a parent" |
| 238 | [ "$(git -C "$origin" cat-file blob refs/the-valley/integration-outcomes/main/c1 | cut -d' ' -f1,2,4)" = "$(git rev-parse c1) $before land" ] \ |
| 239 | || die "the outcome record does not say land at c1 on the tip it was judged against" |
| 240 | grep -qx " record $record" "$work/last.out" || die "the landing record was not reported" |
| 241 | holds "the landing record and the outcome record name the landing" |
| 242 | |
| 243 | # The decision is followed by one timing line: JSON after a fixed label, |
| 244 | # naming the request and what was decided, with the time each stage took. |
| 245 | # Every stage a landing reaches is there, as a whole number of |
| 246 | # milliseconds, and the stages add up to no more than the whole. |
| 247 | [ "$(grep -c '^ timing ' "$work/last.out")" = 1 ] || die "one decision did not print exactly one timing line" |
| 248 | timing="$(sed -n 's/^ timing //p' "$work/last.out")" |
| 249 | jq -e --arg head "$(git rev-parse c1)" --arg tip "$before" ' |
| 250 | keys == ["change", "duration_ms", "head", "outcome", "project", "request", "stages_ms", "target", "time", "tip"] |
| 251 | and .request == "refs/the-valley/integration-requests/main/c1" and .change == "c1" |
| 252 | and .head == $head and .target == "refs/heads/main" and .tip == $tip and .outcome == "land" |
| 253 | and (.project | type == "string" and length > 0) |
| 254 | and (.time | type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{3}Z$")) |
| 255 | and (.duration_ms | type == "number" and . >= 0 and . == floor) |
| 256 | and (.stages_ms | type == "object" |
| 257 | and (keys - ["refusal", "checkout", "evidence", "policy", "apply", "closures", "sign", "land", "record", "publish"] == []) |
| 258 | and all(.refusal, .checkout, .evidence, .policy, .sign, .land, .record, .publish; type == "number") |
| 259 | and all(.[]; type == "number" and . >= 0 and . == floor)) |
| 260 | and ([.stages_ms[]] | add) <= .duration_ms' <<< "$timing" > /dev/null \ |
| 261 | || die "c1's timing line does not say what a landing's should: $timing" |
| 262 | holds "the landing is timed: $timing" |
| 263 | |
| 264 | # The landed note carries both signatures, under one text, and verifies. |
| 265 | # The integrator writes under its own key hash, so its ref never races the |
| 266 | # contributor's over the same subject. |
| 267 | landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c1 | cut -d: -f2)/$ihash" |
| 268 | git -C "$origin" rev-parse --verify --quiet "$landed" > /dev/null \ |
| 269 | || die "no attestation ref by the integrator for the landed tree" |
| 270 | git -C "$origin" cat-file blob "$landed:prose-format/statement.note" > "$work/landed.note" |
| 271 | siblings="$(grep -c '^— ' "$work/landed.note")" |
| 272 | [ "$siblings" -eq 2 ] || die "the landed note carries $siblings signatures, not two" |
| 273 | attest verify --note "$work/landed.note" --known-keys "$work/reader_keys" \ |
| 274 | --schema "$SCHEMA_ATTESTATION" --repo "$repo" --rev c1 \ |
| 275 | --signer "$contributor" --signer "$integrator_name" > "$work/landed.verify" |
| 276 | grep -q 'matches the recorded subject digest' "$work/landed.verify" || die "the landed note does not bind to the tree" |
| 277 | holds "the landed note carries contributor and integrator sibling signatures and verifies" |
| 278 | |
| 279 | # And the integrator's own transfer statement sits beside it. |
| 280 | git -C "$origin" cat-file blob "$landed:$(transfer_path "$(tip)")" > "$work/transfer.note" |
| 281 | head -n1 "$work/transfer.note" | grep -qx 'the-valley/attestation/v1' || die "the transfer note is not a statement" |
| 282 | grep -qx 'predicateType the-valley/integration/transfer/v1' "$work/transfer.note" || die "wrong predicate type" |
| 283 | grep -qx 'predicate.change c1' "$work/transfer.note" || die "the transfer statement names no change" |
| 284 | grep -q '^predicate.policy.sha256 ' "$work/transfer.note" || die "the transfer statement names no policy" |
| 285 | attest verify --note "$work/transfer.note" --known-keys "$work/reader_keys" \ |
| 286 | --schema "$SCHEMA_ATTESTATION" --signer "$integrator_name" > /dev/null |
| 287 | holds "the transfer statement records the verdict and the policy it was derived under" |
| 288 | |
| 289 | # ---------------------------------------------------------------------- |
| 290 | say "2. an intervening landing invalidates one check's closure" |
| 291 | |
| 292 | git checkout --quiet main |
| 293 | git pull --quiet --ff-only origin main |
| 294 | |
| 295 | # c2 is authored against the current tip and reads both classes. |
| 296 | git checkout --quiet -b c2 |
| 297 | echo "a readme with more in it" > docs/readme.md |
| 298 | echo "the source, revised" > src/main.txt |
| 299 | git add -A |
| 300 | git commit --quiet -m "revise the readme and the source" |
| 301 | attest_change c2 "" "" --check prose-format --check code-build |
| 302 | c2="$(git rev-parse c2)" |
| 303 | |
| 304 | # Meanwhile another change lands, touching only what code-build reads. |
| 305 | git checkout --quiet main |
| 306 | git checkout --quiet -b intervening |
| 307 | echo "a second source file" > src/other.txt |
| 308 | git add -A |
| 309 | git commit --quiet -m "add a second source file" |
| 310 | attest_change intervening "" "" --check code-build |
| 311 | request intervening main "$(git rev-parse intervening)" |
| 312 | integrate |
| 313 | grep -q "^intervening -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 314 | holds "the intervening change landed first; c2's base has moved" |
| 315 | |
| 316 | request c2 main "$c2" |
| 317 | integrate |
| 318 | grep -q "^c2 -> refs/heads/main .*: stale$" "$work/last.out" || die "c2 was not stale" |
| 319 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 320 | || die "prose-format should have transferred by closure equality" |
| 321 | grep -q "check code-build .*input closure changed" "$work/last.out" \ |
| 322 | || die "code-build's closure should have moved" |
| 323 | grep -q '"event":"request-stale"' "$work/last.out" || die "no request-stale event" |
| 324 | grep -q '"checks":\["code-build"\]' "$work/last.out" || die "the event does not name exactly code-build" |
| 325 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c2 > /dev/null \ |
| 326 | || die "the request ref was dropped; there is nothing to approve again" |
| 327 | holds "one request-stale naming exactly code-build; prose-format reported transferred" |
| 328 | forget c2 |
| 329 | |
| 330 | # ---------------------------------------------------------------------- |
| 331 | say "2b. evidence that survives the rebase lands on the moved tip" |
| 332 | |
| 333 | # The same shape as 2, with the intervening landing outside what the |
| 334 | # change's checks read. The tree that lands is not the tree that was |
| 335 | # attested, and the evidence stands anyway — which is the whole of what |
| 336 | # content-addressed evidence buys. |
| 337 | git checkout --quiet main |
| 338 | git pull --quiet --ff-only origin main |
| 339 | git checkout --quiet -b c2b |
| 340 | echo "a readme revised again" > docs/readme.md |
| 341 | git add -A |
| 342 | git commit --quiet -m "revise the readme once more" |
| 343 | attest_change c2b "" "" --check prose-format |
| 344 | c2b="$(git rev-parse c2b)" |
| 345 | attested="$(attest digest --repo "$repo" --rev c2b | cut -d: -f2)" |
| 346 | |
| 347 | git checkout --quiet main |
| 348 | git checkout --quiet -b elsewhere |
| 349 | echo "a third source file" > src/third.txt |
| 350 | git add -A |
| 351 | git commit --quiet -m "add a third source file" |
| 352 | attest_change elsewhere "" "" --check code-build |
| 353 | request elsewhere main "$(git rev-parse elsewhere)" |
| 354 | integrate |
| 355 | grep -q "^elsewhere -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 356 | intervened="$(tip)" |
| 357 | |
| 358 | request c2b main "$c2b" |
| 359 | integrate |
| 360 | grep -q "^c2b -> refs/heads/main .*: land$" "$work/last.out" || die "c2b did not land" |
| 361 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 362 | || die "the evidence did not transfer by closure equality" |
| 363 | landedtree="$(git -C "$origin" rev-parse refs/heads/main^{tree})" |
| 364 | [ "$(git -C "$origin" rev-parse "refs/heads/main^")" = "$intervened" ] \ |
| 365 | || die "the landing is not a fast-forward from the tip it was judged against" |
| 366 | [ "$(git -C "$origin" rev-parse refs/heads/main^{tree})" != "$(git rev-parse "$c2b^{tree}")" ] \ |
| 367 | || die "the tree did not actually move; the scenario proves nothing" |
| 368 | holds "the delta landed on a tree it was never attested over, and no check re-ran" |
| 369 | |
| 370 | # Two attestation refs now, because the two statements are about two |
| 371 | # different trees: the contributor's is keyed by the tree it was made over, |
| 372 | # and the integrator's transfer statement by the tree that landed. |
| 373 | git fetch --quiet origin main |
| 374 | landed_digest="$(attest digest --repo "$repo" --rev "$(git -C "$origin" rev-parse refs/heads/main)" | cut -d: -f2)" |
| 375 | [ "$landed_digest" != "$attested" ] || die "the landed tree is the attested tree; the scenario proves nothing" |
| 376 | git -C "$origin" cat-file blob \ |
| 377 | "refs/the-valley/attestations/$attested/$ihash:prose-format/statement.note" > "$work/rebased.note" |
| 378 | [ "$(grep -c '^— ' "$work/rebased.note")" -eq 2 ] \ |
| 379 | || die "the countersigned note lost a sibling signature" |
| 380 | grep -qx "subject.digest.valley-tree-v1 $attested" "$work/rebased.note" \ |
| 381 | || die "the countersigned statement is not about the tree it was made over" |
| 382 | git -C "$origin" cat-file blob \ |
| 383 | "refs/the-valley/attestations/$landed_digest/$ihash:$(transfer_path "$(tip)")" > "$work/rebased.transfer" |
| 384 | grep -qx "subject.digest.valley-tree-v1 $landed_digest" "$work/rebased.transfer" \ |
| 385 | || die "the transfer statement is not about the landed tree" |
| 386 | grep -qx "predicate.base.valley-tree-v1 $attested" "$work/rebased.transfer" \ |
| 387 | || die "the transfer statement does not cite the base the evidence was produced over" |
| 388 | grep -qx "predicate.checks.0.rule closure" "$work/rebased.transfer" \ |
| 389 | || die "the transfer statement does not record the rule that carried the evidence" |
| 390 | holds "the contributor's statement stays about its own tree; the transfer statement names the landed one" |
| 391 | |
| 392 | # ---------------------------------------------------------------------- |
| 393 | say "2c. a re-parenting landing states its own committer, and needs none from the environment" |
| 394 | |
| 395 | # Re-parenting is the one landing that makes a commit of the integrator's |
| 396 | # own, so it is the one that needs a committer. Under the unit there is |
| 397 | # nothing to take one from: no git config the service can read, no GIT_* in |
| 398 | # its environment, and a hostname git will not guess an address from. So the |
| 399 | # integrator states both identities itself — the asker authored the change, |
| 400 | # the integrator committed the commit that carries it onto the tip — and the |
| 401 | # pass below runs with everything git could have fallen back to taken away. |
| 402 | |
| 403 | # A scrubbed environment: no global or system config, no GIT_* identity, and |
| 404 | # auto-detection refused outright, so that a host whose own hostname does |
| 405 | # resolve cannot hide a dependency on it. |
| 406 | scrubbed() { |
| 407 | env -u GIT_AUTHOR_NAME -u GIT_AUTHOR_EMAIL -u GIT_AUTHOR_DATE \ |
| 408 | -u GIT_COMMITTER_NAME -u GIT_COMMITTER_EMAIL -u GIT_COMMITTER_DATE -u EMAIL \ |
| 409 | GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 \ |
| 410 | GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.useConfigOnly GIT_CONFIG_VALUE_0=true \ |
| 411 | "$@" |
| 412 | } |
| 413 | scrubbed git -C "$origin" var GIT_COMMITTER_IDENT > /dev/null 2>&1 \ |
| 414 | && die "the scrub left an identity for git to find; the scenario proves nothing" |
| 415 | |
| 416 | git checkout --quiet main |
| 417 | git pull --quiet --ff-only origin main |
| 418 | git checkout --quiet -b c2c |
| 419 | echo "a readme revised by a stated author" > docs/readme.md |
| 420 | git add -A |
| 421 | # A distinct author, so that what the landed commit carries over from the |
| 422 | # head and what it states of its own are told apart by reading it. |
| 423 | GIT_AUTHOR_NAME="a contributor" GIT_AUTHOR_EMAIL="contributor@valley.invalid" \ |
| 424 | git commit --quiet -m "revise the readme under an author of its own" |
| 425 | attest_change c2c "" "" --check prose-format |
| 426 | c2c="$(git rev-parse c2c)" |
| 427 | |
| 428 | # The intervening landing, outside what prose-format reads, is what moves |
| 429 | # c2c's base and makes the landing below a re-parent rather than a |
| 430 | # fast-forward. |
| 431 | git checkout --quiet main |
| 432 | git checkout --quiet -b under-c2c |
| 433 | echo "a fifth source file" > src/fifth.txt |
| 434 | git add -A |
| 435 | git commit --quiet -m "add a fifth source file" |
| 436 | attest_change under-c2c "" "" --check code-build |
| 437 | request under-c2c main "$(git rev-parse under-c2c)" |
| 438 | integrate |
| 439 | grep -q "^under-c2c -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 440 | |
| 441 | request c2c main "$c2c" |
| 442 | pre="$(tip)" |
| 443 | scrubbed integrator reconcile \ |
| 444 | --repo "$origin" \ |
| 445 | --key "$work/integrator" --name "$integrator_name" \ |
| 446 | --known-signers "$work/known_signers" \ |
| 447 | --instance-repo "$instance_repo" \ |
| 448 | --schema "$SCHEMA_VERIFICATION" \ |
| 449 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 450 | --event-schema "$SCHEMA_EVENTS" \ |
| 451 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 452 | 2>&1 | tee "$work/last.out" |
| 453 | grep -q "^c2c -> refs/heads/main .*: land$" "$work/last.out" \ |
| 454 | || die "a landing with no git identity in the environment did not land: $(cat "$work/last.out")" |
| 455 | |
| 456 | landed_commit="$(git -C "$origin" rev-parse refs/heads/main)" |
| 457 | [ "$(git -C "$origin" merge-base "$c2c" "$pre")" != "$pre" ] \ |
| 458 | || die "c2c's base is the tip it landed on, so main did not move under it; the scenario proves nothing" |
| 459 | [ "$(git -C "$origin" rev-list --no-walk --parents "$landed_commit")" = "$landed_commit $pre" ] \ |
| 460 | || die "c2c did not land as one commit on the tip before the pass" |
| 461 | [ "$(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")" = "a contributor <contributor@valley.invalid>" ] \ |
| 462 | || die "the landed commit is not authored by the asker: $(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")" |
| 463 | [ "$(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")" = "$integrator_name <integrator@the-valley.invalid>" ] \ |
| 464 | || die "the landed commit is not committed by the integrator: $(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")" |
| 465 | # The commit id is a function of what the pass decided from and nothing |
| 466 | # else, so a pass that dies before the ref write recomputes this same |
| 467 | # commit rather than leaving another behind. |
| 468 | [ "$(git -C "$origin" log -1 --format=%aI "$landed_commit")" = "$(git -C "$origin" log -1 --format=%cI "$landed_commit")" ] \ |
| 469 | || die "the committer date is not the author's, so the landed commit id is not reproducible" |
| 470 | holds "the integrator committed under its own name with nothing in the environment to take one from" |
| 471 | |
| 472 | # ---------------------------------------------------------------------- |
| 473 | say "3. a conflicting delta is stale, and demands full re-attestation" |
| 474 | |
| 475 | git checkout --quiet main |
| 476 | git pull --quiet --ff-only origin main |
| 477 | git checkout --quiet -b c3 |
| 478 | echo "the readme, as c3 would have it" > docs/readme.md |
| 479 | git add -A |
| 480 | git commit --quiet -m "rewrite the readme one way" |
| 481 | attest_change c3 "" "" --check prose-format |
| 482 | c3="$(git rev-parse c3)" |
| 483 | |
| 484 | git checkout --quiet main |
| 485 | git checkout --quiet -b conflicting |
| 486 | echo "the readme, as the other change would have it" > docs/readme.md |
| 487 | git add -A |
| 488 | git commit --quiet -m "rewrite the readme another way" |
| 489 | attest_change conflicting "" "" --check prose-format |
| 490 | request conflicting main "$(git rev-parse conflicting)" |
| 491 | integrate |
| 492 | grep -q "^conflicting -> refs/heads/main .*: land$" "$work/last.out" || die "the conflicting change did not land" |
| 493 | |
| 494 | request c3 main "$c3" |
| 495 | integrate |
| 496 | grep -q "^c3 -> refs/heads/main .*: stale$" "$work/last.out" || die "c3 was not stale" |
| 497 | grep -q 'resolving it is new authorship' "$work/last.out" || die "the conflict was not reported as new authorship" |
| 498 | grep -q 'CONFLICT (content): Merge conflict in docs/readme.md' "$work/last.out" \ |
| 499 | || die "the conflict does not name what could not be merged" |
| 500 | grep -q '"reason":"conflict"' "$work/last.out" || die "the event does not say conflict" |
| 501 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "a conflict must re-demand every required check" |
| 502 | holds "a conflict is stale, and every required check is re-demanded" |
| 503 | forget c3 |
| 504 | |
| 505 | # ---------------------------------------------------------------------- |
| 506 | say "4. an unknown signer's attestation does not transfer" |
| 507 | |
| 508 | git checkout --quiet main |
| 509 | git pull --quiet --ff-only origin main |
| 510 | git checkout --quiet -b c4 |
| 511 | echo "a readme signed by a stranger" > docs/readme.md |
| 512 | git add -A |
| 513 | git commit --quiet -m "a change a stranger attested" |
| 514 | attest_change c4 "$work/stranger" "$stranger" --check prose-format |
| 515 | request c4 main "$(git rev-parse c4)" |
| 516 | integrate |
| 517 | grep -q "^c4 -> refs/heads/main .*: stale$" "$work/last.out" || die "c4 was not stale" |
| 518 | grep -q 'no signer the integrator holds' "$work/last.out" || die "the unknown signer was not reported" |
| 519 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "the event does not name prose-format" |
| 520 | [ "$(tip)" = "$(git -C "$origin" rev-parse refs/heads/main)" ] || die "main moved" |
| 521 | holds "evidence from a signer the integrator does not hold does not transfer" |
| 522 | forget c4 |
| 523 | |
| 524 | # ---------------------------------------------------------------------- |
| 525 | say "5. a tampered statement is rejected, not called stale" |
| 526 | |
| 527 | git checkout --quiet main |
| 528 | git checkout --quiet -b c5 |
| 529 | echo "an honest readme" > docs/readme.md |
| 530 | git add -A |
| 531 | git commit --quiet -m "an honest change" |
| 532 | attest_change c5 "" "" --check prose-format |
| 533 | c5="$(git rev-parse c5)" |
| 534 | c5digest="$(attest digest --repo "$repo" --rev c5 | cut -d: -f2)" |
| 535 | |
| 536 | # Edit one value in the signed text and store the result where the real |
| 537 | # note was. Everything else about the note is untouched. |
| 538 | c5ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 539 | "refs/the-valley/attestations/$c5digest" | head -n1)" |
| 540 | git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note" \ |
| 541 | | sed 's/^predicate.result passed$/predicate.result failed/' > "$work/tampered.note" |
| 542 | cmp -s "$work/tampered.note" <(git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note") \ |
| 543 | && die "the tamper changed nothing; the test proves nothing" |
| 544 | blob="$(git -C "$origin" hash-object -w --stdin < "$work/tampered.note")" |
| 545 | sub="$(printf '100644 blob %s\tstatement.note\n' "$blob" | git -C "$origin" mktree)" |
| 546 | top="$(printf '040000 tree %s\tprose-format\n' "$sub" | git -C "$origin" mktree)" |
| 547 | git -C "$origin" update-ref "$c5ref" "$top" |
| 548 | |
| 549 | request c5 main "$c5" |
| 550 | integrate |
| 551 | grep -q "^c5 -> refs/heads/main .*: reject$" "$work/last.out" || die "a tampered statement was not rejected" |
| 552 | grep -q 'does not verify as the statement it claims to be' "$work/last.out" || die "the refusal was not reported" |
| 553 | grep -q 'request-stale' "$work/last.out" && die "a forgery was announced as staleness" |
| 554 | holds "a tampered statement is a rejection, and no outcome event claims otherwise" |
| 555 | forget c5 |
| 556 | |
| 557 | # ---------------------------------------------------------------------- |
| 558 | say "6. an attestation about a different tree is rejected" |
| 559 | |
| 560 | git checkout --quiet main |
| 561 | git checkout --quiet -b c6 |
| 562 | echo "the tree that was actually attested" > docs/readme.md |
| 563 | git add -A |
| 564 | git commit --quiet -m "the attested change" |
| 565 | attest_change c6 "" "" --check prose-format |
| 566 | c6ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 567 | "refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c6 | cut -d: -f2)" | head -n1)" |
| 568 | |
| 569 | # A second, different tree — with no attestation of its own — and the |
| 570 | # first tree's valid, correctly signed note filed under its digest. |
| 571 | git checkout --quiet -b c6-lifted |
| 572 | echo "the tree that was not" > docs/readme.md |
| 573 | git add -A |
| 574 | git commit --quiet -m "the change the evidence was lifted onto" |
| 575 | git push --quiet origin c6-lifted |
| 576 | lifted="$(attest digest --repo "$repo" --rev c6-lifted | cut -d: -f2)" |
| 577 | git -C "$origin" update-ref \ |
| 578 | "refs/the-valley/attestations/$lifted/${c6ref##*/}" \ |
| 579 | "$(git -C "$origin" rev-parse "$c6ref^{tree}")" |
| 580 | |
| 581 | request c6 main "$(git rev-parse c6-lifted)" |
| 582 | integrate |
| 583 | grep -q "^c6 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lifted attestation was not rejected" |
| 584 | grep -q 'tree digest mismatch' "$work/last.out" || die "the refusal does not name the tree digest" |
| 585 | holds "a signature cannot be lifted onto a tree it was not made about" |
| 586 | forget c6 |
| 587 | |
| 588 | # ---------------------------------------------------------------------- |
| 589 | say "7. an attestation lying about its kind is rejected" |
| 590 | |
| 591 | # The policy runs prose-format with nix, so its evidence is content- |
| 592 | # addressed. This attestation claims a notarization instead, and its class |
| 593 | # was untouched by the intervening landing — so under the rule it nominated |
| 594 | # for itself it would sail onto a base it was never produced over. |
| 595 | git checkout --quiet main |
| 596 | git pull --quiet --ff-only origin main |
| 597 | git checkout --quiet -b c7 |
| 598 | echo "a readme attested as a notarization" > docs/readme.md |
| 599 | git add -A |
| 600 | git commit --quiet -m "a change whose attestation lies about its kind" |
| 601 | attest_change c7 "" "" --command prose-format=true |
| 602 | c7="$(git rev-parse c7)" |
| 603 | |
| 604 | git checkout --quiet main |
| 605 | git checkout --quiet -b under-c7 |
| 606 | echo "a fourth source file" > src/fourth.txt |
| 607 | git add -A |
| 608 | git commit --quiet -m "add a fourth source file" |
| 609 | attest_change under-c7 "" "" --check code-build |
| 610 | request under-c7 main "$(git rev-parse under-c7)" |
| 611 | integrate |
| 612 | grep -q "^under-c7 -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 613 | |
| 614 | request c7 main "$c7" |
| 615 | integrate |
| 616 | grep -q "^c7 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lie about the kind was not rejected" |
| 617 | grep -q 'requires a pure check and the attestation claims an effectful check' "$work/last.out" \ |
| 618 | || die "the refusal does not say the policy decides the rule" |
| 619 | holds "the transfer rule follows the policy's runner, never the attestation's own claim" |
| 620 | forget c7 |
| 621 | |
| 622 | # ---------------------------------------------------------------------- |
| 623 | say "8. evidence pushed after a no-evidence verdict re-judges and lands" |
| 624 | |
| 625 | git checkout --quiet main |
| 626 | git pull --quiet --ff-only origin main |
| 627 | git checkout --quiet -b c8 |
| 628 | echo "a readme with no evidence yet" > docs/readme.md |
| 629 | git add -A |
| 630 | git commit --quiet -m "a change submitted before its checks ran" |
| 631 | git push --quiet origin c8 |
| 632 | request c8 main "$(git rev-parse c8)" |
| 633 | integrate |
| 634 | grep -q "^c8 -> refs/heads/main .*: stale$" "$work/last.out" || die "a change with no evidence was not stale" |
| 635 | grep -q 'no attestation for this check accompanies the change' "$work/last.out" \ |
| 636 | || die "the absent attestation was not reported" |
| 637 | |
| 638 | # Nothing about the request or the tip moves; only the evidence arrives. |
| 639 | attest_change c8 "" "" --check prose-format |
| 640 | integrate |
| 641 | grep -q "^c8 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 642 | || die "the request was not re-judged after its evidence arrived" |
| 643 | landed_as "$(git rev-parse c8)" "$pre" |
| 644 | holds "a pass re-judges when evidence arrives, with the request and the tip unmoved" |
| 645 | |
| 646 | # ---------------------------------------------------------------------- |
| 647 | say "9. a ref that is not a request does not hold up one that is" |
| 648 | |
| 649 | git checkout --quiet main |
| 650 | git pull --quiet --ff-only origin main |
| 651 | git checkout --quiet -b c9 |
| 652 | echo "a readme beside a garbage ref" > docs/readme.md |
| 653 | git add -A |
| 654 | git commit --quiet -m "a change beside a malformed request" |
| 655 | attest_change c9 "" "" --check prose-format |
| 656 | # A name with no target segment at all, and one with a segment too many. |
| 657 | # This repository is served with no pre-receive hook, so the namespace takes |
| 658 | # whatever is pushed; on a host only a holder of the request grant writes |
| 659 | # it, and a holder can still write a name that is not a request. |
| 660 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/garbage" |
| 661 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/main/too/deep" |
| 662 | request c9 main "$(git rev-parse c9)" |
| 663 | integrate |
| 664 | grep -q 'refs/the-valley/integration-requests/garbage: not a request ref' "$work/last.out" \ |
| 665 | || die "the malformed ref was not reported" |
| 666 | grep -q 'refs/the-valley/integration-requests/main/too/deep: not a request ref' "$work/last.out" \ |
| 667 | || die "the over-deep ref was not reported" |
| 668 | grep -q "^c9 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 669 | || die "a malformed ref stopped the pass reaching a valid request" |
| 670 | holds "malformed refs are reported and skipped; the valid request beside them landed" |
| 671 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/garbage |
| 672 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/too/deep |
| 673 | |
| 674 | # ---------------------------------------------------------------------- |
| 675 | say "10. a pass leaves no scratch behind, and a leaked worktree is swept" |
| 676 | |
| 677 | # Nine scenarios of real passes, landings and rejections alike, and the |
| 678 | # scratch root is empty: every worktree a pass takes is given back on the |
| 679 | # way out, on the failure path as much as the success one. |
| 680 | leftover="$(find "$TMPDIR" -maxdepth 1 -name 'valley-integrator-wt*')" |
| 681 | [ -z "$leftover" ] || die "nine passes left scratch behind: $leftover" |
| 682 | [ "$(git -C "$origin" worktree list --porcelain | grep -c '^worktree ')" -eq 1 ] \ |
| 683 | || die "nine passes left a worktree attached to the repository" |
| 684 | holds "no pass left a worktree or a scratch directory behind" |
| 685 | |
| 686 | # What a crash leaves: the checkout and its administrative entry, both |
| 687 | # still valid, so nothing prunes them. Beside it, a worktree of the kind |
| 688 | # an operator might attach by hand, which is not the integrator's to |
| 689 | # remove. |
| 690 | leak="$TMPDIR/valley-integrator-wt-crashed" |
| 691 | mine="$work/an-operators-own-worktree" |
| 692 | git -C "$origin" worktree add --quiet --detach "$leak" refs/heads/main |
| 693 | git -C "$origin" worktree add --quiet --detach "$mine" refs/heads/main |
| 694 | timeout 5 integrator watch --interval 1s \ |
| 695 | --repo "$origin" \ |
| 696 | --key "$work/integrator" --name "$integrator_name" \ |
| 697 | --known-signers "$work/known_signers" \ |
| 698 | --instance "$instance" \ |
| 699 | --schema "$SCHEMA_VERIFICATION" \ |
| 700 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 701 | --event-schema "$SCHEMA_EVENTS" \ |
| 702 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 703 | > "$work/watch.out" 2>&1 || true |
| 704 | [ ! -e "$leak" ] || die "a leaked scratch worktree survived the sweep" |
| 705 | if git -C "$origin" worktree list --porcelain | grep -q "^worktree $leak$"; then |
| 706 | die "the leaked worktree is gone from disk and still registered" |
| 707 | fi |
| 708 | [ -e "$mine" ] || die "the sweep removed a worktree the integrator did not make" |
| 709 | git -C "$origin" worktree remove --force "$mine" |
| 710 | holds "a crash-leaked scratch worktree is swept at watch start; another hand's is not" |
| 711 | |
| 712 | # ---------------------------------------------------------------------- |
| 713 | say "11. a scratch root it may not write is reported as that, and nothing else" |
| 714 | |
| 715 | # The deployment failure this guards is a sandbox failure: the root TMPDIR |
| 716 | # names is not writable. That is a statement about the unit, not about the |
| 717 | # change being judged, and it has to arrive as one — with the path and where |
| 718 | # the path came from — rather than as git complaining about the leading |
| 719 | # directories of a .git file. |
| 720 | refused="$work/refused" |
| 721 | mkdir -p "$refused" |
| 722 | chmod a-w "$refused" |
| 723 | git checkout --quiet main |
| 724 | git pull --quiet --ff-only origin main |
| 725 | git checkout --quiet -b c10 |
| 726 | echo "a change that never gets a worktree" > docs/readme.md |
| 727 | git add -A |
| 728 | git commit --quiet -m "a change the integrator cannot make scratch for" |
| 729 | attest_change c10 "" "" --check prose-format |
| 730 | request c10 main "$(git rev-parse c10)" |
| 731 | export TMPDIR="$refused" |
| 732 | integrate || true |
| 733 | export TMPDIR="$work/tmp" |
| 734 | chmod u+w "$refused" |
| 735 | grep -q "scratch directory under $refused, which TMPDIR names" "$work/last.out" \ |
| 736 | || die "an unwritable scratch root was not reported as one: $(cat "$work/last.out")" |
| 737 | forget c10 |
| 738 | holds "an unwritable scratch root names the path and where it came from" |
| 739 | |
| 740 | # ---------------------------------------------------------------------- |
| 741 | say "12. a floor the instance repository does not carry names the directory looked in" |
| 742 | |
| 743 | # The deployment failure this guards is a controller pointed at the wrong |
| 744 | # directory: the floor is somewhere, and not where this controller looked. |
| 745 | # The report has to name the repository, the directory and the ref, because |
| 746 | # those three are what the operator compares against the repository in front |
| 747 | # of them. A floor is either not there at all, or there under a name that |
| 748 | # holds no documents, and both arrive that way. |
| 749 | # |
| 750 | # A missing floor is refused rather than read as requiring nothing, which is |
| 751 | # the direction the other layer's absence defaults in (dcr-f41f718). The |
| 752 | # refusal says why in its own sentence, because the operator reading it is |
| 753 | # being told that the deployment is not one that can land anything. |
| 754 | git checkout --quiet main |
| 755 | git pull --quiet --ff-only origin main |
| 756 | git checkout --quiet -b c11 |
| 757 | echo "a change judged under no floor" > docs/readme.md |
| 758 | git add -A |
| 759 | git commit --quiet -m "a change whose floor the controller cannot find" |
| 760 | attest_change c11 "" "" --check prose-format |
| 761 | request c11 main "$(git rev-parse c11)" |
| 762 | |
| 763 | # The sentence every refusal to find a floor ends with. |
| 764 | unwritten="a valley without a written floor is not a valley whose changes land" |
| 765 | |
| 766 | floorless() { |
| 767 | integrator reconcile \ |
| 768 | --repo "$origin" \ |
| 769 | --key "$work/integrator" --name "$integrator_name" \ |
| 770 | --known-signers "$work/known_signers" "$@" \ |
| 771 | --schema "$SCHEMA_VERIFICATION" \ |
| 772 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 773 | --event-schema "$SCHEMA_EVENTS" \ |
| 774 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 775 | 2>&1 | tee "$work/last.out" |
| 776 | } |
| 777 | |
| 778 | # The project's own repository carries policy/project and no policy/instance, |
| 779 | # so the default directory is not there. |
| 780 | floorless --instance-repo "$origin" || true |
| 781 | grep -qF "no instance policy layer: $origin has no policy/instance/ at refs/heads/main: $unwritten" "$work/last.out" \ |
| 782 | || die "a missing floor did not name the directory looked in, and why that is refused: $(cat "$work/last.out")" |
| 783 | |
| 784 | # And the flat layout, which is a directory that exists and holds no |
| 785 | # documents of its own: policy/ has the two layers under it and no *.cue in |
| 786 | # it. Said as that, rather than as an empty composition further on. |
| 787 | # |
| 788 | # Under a second request name, because the refusal above is now this |
| 789 | # controller's recorded answer to c11 and it stands until the request, the |
| 790 | # tip or the evidence moves — which is scenario 14's whole subject. A |
| 791 | # request is what an answer is remembered against, so a second one asks the |
| 792 | # question again. |
| 793 | request c11-flat main "$(git rev-parse c11)" |
| 794 | floorless --instance-repo "$origin" --instance-policy policy || true |
| 795 | grep -qF "no instance policy layer: $origin holds no *.cue in policy/ at refs/heads/main: $unwritten" "$work/last.out" \ |
| 796 | || die "a floor directory holding no documents did not say so: $(cat "$work/last.out")" |
| 797 | |
| 798 | # And the materialized layer, which is how a host that serves no instance |
| 799 | # repository is given the floor. A directory with nothing in it is the same |
| 800 | # absence and is refused the same way. |
| 801 | request c11-bare main "$(git rev-parse c11)" |
| 802 | nofloor="$work/no-floor-here" |
| 803 | mkdir -p "$nofloor" |
| 804 | floorless --instance "$nofloor" || true |
| 805 | grep -qF "no instance policy layer: $nofloor holds no *.cue: $unwritten" "$work/last.out" \ |
| 806 | || die "an empty materialized floor was not refused: $(cat "$work/last.out")" |
| 807 | forget c11 |
| 808 | forget c11-flat |
| 809 | forget c11-bare |
| 810 | holds "a floor that is not where the controller looked names the repository, the directory and the ref" |
| 811 | |
| 812 | # ---------------------------------------------------------------------- |
| 813 | say "13. a change the policy requires no check of lands, and says so" |
| 814 | |
| 815 | # Requiring nothing is an ordinary outcome, not an edge: this project's |
| 816 | # classes cover docs/, src/ and deploy/, and its `unclassified` set is |
| 817 | # empty, so a path outside all three is answered with nothing required. The |
| 818 | # landing still writes a transfer statement — a commit point that records |
| 819 | # nothing is a landing nothing attests to — and that statement says the |
| 820 | # required set was empty rather than carrying a list with nothing in it, |
| 821 | # which has no written form at all. |
| 822 | git checkout --quiet main |
| 823 | git pull --quiet --ff-only origin main |
| 824 | git checkout --quiet -b c12 |
| 825 | echo "outside every class this policy covers" > notes.txt |
| 826 | git add -A |
| 827 | git commit --quiet -m "a change no class covers" |
| 828 | request c12 main "$(git rev-parse c12)" |
| 829 | integrate |
| 830 | grep -q '^c12 -> refs/heads/main .*: land$' "$work/last.out" \ |
| 831 | || die "a change with nothing required did not land: $(cat "$work/last.out")" |
| 832 | grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \ |
| 833 | || die "the verdict did not say the policy required nothing" |
| 834 | landed_as "$(git rev-parse c12)" "$pre" |
| 835 | git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c12" > /dev/null \ |
| 836 | && die "the request ref survived the landing" |
| 837 | |
| 838 | nothing="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c12 | cut -d: -f2)/$ihash" |
| 839 | git -C "$origin" cat-file blob "$nothing:$(transfer_path "$(tip)")" > "$work/nothing.note" |
| 840 | grep -qx 'predicate.required none' "$work/nothing.note" \ |
| 841 | || die "the transfer statement does not say the required set was empty: $(cat "$work/nothing.note")" |
| 842 | grep -q '^predicate.checks' "$work/nothing.note" \ |
| 843 | && die "the transfer statement carries a check list beside the empty-set line" |
| 844 | attest verify --note "$work/nothing.note" --known-keys "$work/reader_keys" \ |
| 845 | --repo "$repo" --rev c12 --signer "$integrator_name" > /dev/null \ |
| 846 | || die "the transfer statement for a landing with nothing required does not verify" |
| 847 | holds "a landing with no required checks is signed, stored, and consumed its request" |
| 848 | |
| 849 | # ---------------------------------------------------------------------- |
| 850 | say "14. a request the controller cannot judge is reported once, not every tick" |
| 851 | |
| 852 | # The failure this guards is the one that turns a broken deployment into a |
| 853 | # broken deployment nobody can read: a pass that cannot act on its verdict, |
| 854 | # retried at tick rate, filling the journal with one refusal per interval |
| 855 | # forever. The same request, tip and evidence produce the same failure, so |
| 856 | # repeating it says nothing new. It is reported once and then the answer |
| 857 | # stands, exactly as an outcome stands. |
| 858 | git checkout --quiet main |
| 859 | git pull --quiet --ff-only origin main |
| 860 | git checkout --quiet -b c13 |
| 861 | echo "a change judged under no floor, repeatedly" > docs/readme.md |
| 862 | git add -A |
| 863 | git commit --quiet -m "a change whose floor the controller cannot find, under watch" |
| 864 | attest_change c13 "" "" --check prose-format |
| 865 | request c13 main "$(git rev-parse c13)" |
| 866 | |
| 867 | # Five seconds at a one-second tick: five passes over one request the |
| 868 | # controller cannot judge. |
| 869 | timeout 5 integrator watch --interval 1s \ |
| 870 | --repo "$origin" \ |
| 871 | --key "$work/integrator" --name "$integrator_name" \ |
| 872 | --known-signers "$work/known_signers" \ |
| 873 | --instance-repo "$origin" --instance-policy policy \ |
| 874 | --schema "$SCHEMA_VERIFICATION" \ |
| 875 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 876 | --event-schema "$SCHEMA_EVENTS" \ |
| 877 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 878 | > "$work/repeat.out" 2>&1 || true |
| 879 | reports="$(grep -c 'no instance policy layer' "$work/repeat.out" || true)" |
| 880 | [ "$reports" -eq 1 ] \ |
| 881 | || die "the same refusal was reported $reports times over five ticks: $(cat "$work/repeat.out")" |
| 882 | forget c13 |
| 883 | holds "a failure a pass cannot get past is reported once and then backs off" |
| 884 | |
| 885 | # ---------------------------------------------------------------------- |
| 886 | say "14b. a failure is recorded before its timing line, which nobody has to read" |
| 887 | |
| 888 | # The timing line is printed after the outcome is recorded, and is dropped |
| 889 | # when it cannot be written. A pass that cannot act on its verdict prints |
| 890 | # nothing before its timing line, so with standard output a pipe whose |
| 891 | # reader has gone, the timing line is the first write to fail. The failure |
| 892 | # is recorded all the same. The line the integrator prints after it, naming |
| 893 | # the failure, is its own output rather than timing, and may still end the |
| 894 | # pass there. |
| 895 | git checkout --quiet main |
| 896 | git pull --quiet --ff-only origin main |
| 897 | git checkout --quiet -b c14b |
| 898 | echo "a change judged with nobody reading" > docs/readme.md |
| 899 | git add -A |
| 900 | git commit --quiet -m "a change judged with nobody reading the integrator" |
| 901 | attest_change c14b "" "" --check prose-format |
| 902 | request c14b main "$(git rev-parse c14b)" |
| 903 | |
| 904 | # A pipe with no reader. The FIFO is opened to read and write, so opening it |
| 905 | # to write does not wait; closing the first leaves the writer alone. |
| 906 | mkfifo "$work/unread" |
| 907 | exec 3<> "$work/unread" |
| 908 | exec 4> "$work/unread" |
| 909 | exec 3<&- |
| 910 | status=0 |
| 911 | timeout 120 integrator reconcile \ |
| 912 | --repo "$origin" \ |
| 913 | --key "$work/integrator" --name "$integrator_name" \ |
| 914 | --known-signers "$work/known_signers" \ |
| 915 | --instance-repo "$origin" --instance-policy policy \ |
| 916 | --schema "$SCHEMA_VERIFICATION" \ |
| 917 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 918 | --event-schema "$SCHEMA_EVENTS" \ |
| 919 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 920 | >&4 2> "$work/unread.err" || status=$? |
| 921 | exec 4>&- |
| 922 | [ "$status" != 124 ] || die "the pass did not finish with nobody reading its output" |
| 923 | recorded="$(git -C "$origin" cat-file blob refs/the-valley/integration-outcomes/main/c14b 2> /dev/null || true)" |
| 924 | [ "$(echo "$recorded" | cut -d' ' -f4)" = failed ] \ |
| 925 | || die "with nobody reading its output, the pass did not record its failure (exit $status): ${recorded:-no record} $(cat "$work/unread.err")" |
| 926 | forget c14b |
| 927 | holds "with nobody reading its output, the pass recorded its failure before its timing line (exit $status)" |
| 928 | |
| 929 | # ---------------------------------------------------------------------- |
| 930 | say "15. a target that carries no project layer of its own is judged under the floor alone" |
| 931 | |
| 932 | # The bootstrap this guards is the first policy commit: a project that has |
| 933 | # not written a layer yet cannot land the commit that writes one, because a |
| 934 | # change never supplies the policy that gates it. The project layer only |
| 935 | # ever adds (dcr-f41f718), so its absence adds nothing, and what is left is |
| 936 | # the floor — which still governs, and is observed governing here. |
| 937 | |
| 938 | # The floor grows a requirement of its own first, so that what remains after |
| 939 | # the project layer goes away is something rather than nothing. |
| 940 | cat > "$floor/policy/instance/floor.cue" <<'EOF' |
| 941 | package verification |
| 942 | |
| 943 | floor: { |
| 944 | checks: "prose-format": {runner: "nix", attribute: "prose-format"} |
| 945 | classes: prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 946 | unclassified: {} |
| 947 | } |
| 948 | EOF |
| 949 | git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/" |
| 950 | git -C "$floor" push --quiet "$instance_repo" main |
| 951 | |
| 952 | # The project stops carrying a layer. Nothing classifies policy/project |
| 953 | # itself, so this lands with nothing required — which is how a project could |
| 954 | # have arrived without one in the first place. |
| 955 | git checkout --quiet main |
| 956 | git pull --quiet --ff-only origin main |
| 957 | git checkout --quiet -b c14 |
| 958 | git rm --quiet -r policy/project |
| 959 | git commit --quiet -m "stop carrying a project policy layer" |
| 960 | request c14 main "$(git rev-parse c14)" |
| 961 | integrate |
| 962 | grep -q "^c14 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 963 | || die "dropping the project layer did not land: $(cat "$work/last.out")" |
| 964 | |
| 965 | git checkout --quiet main |
| 966 | git pull --quiet --ff-only origin main |
| 967 | [ ! -e policy/project ] || die "the project layer is still at the tip; the scenario proves nothing" |
| 968 | git checkout --quiet -b c15 |
| 969 | echo "a readme judged under the floor alone" > docs/readme.md |
| 970 | git add -A |
| 971 | git commit --quiet -m "a change to a project that declares no policy of its own" |
| 972 | attest_change c15 "" "" --check prose-format |
| 973 | request c15 main "$(git rev-parse c15)" |
| 974 | integrate |
| 975 | grep -q "^c15 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 976 | || die "a change to a project with no layer of its own did not land: $(cat "$work/last.out")" |
| 977 | grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \ |
| 978 | || die "the pass did not say it composed the floor alone" |
| 979 | grep -q "check prose-format .*transferred" "$work/last.out" \ |
| 980 | || die "the floor's own requirement did not govern a project with no layer" |
| 981 | landed_as "$(git rev-parse c15)" "$pre" |
| 982 | holds "no project layer is no addition; the floor alone required prose-format and the change landed" |
| 983 | |
| 984 | # ---------------------------------------------------------------------- |
| 985 | say "16. a floor that requires nothing, written down, composes and judges" |
| 986 | |
| 987 | # Emptiness a floor states is not the same thing as a floor nobody wrote. |
| 988 | # The document is there, somebody landed it, and what it composes to is a |
| 989 | # policy that requires nothing — so a change under it lands requiring nothing, |
| 990 | # rather than being refused the way scenario 12's missing floor is. |
| 991 | cat > "$floor/policy/instance/floor.cue" <<'EOF' |
| 992 | package verification |
| 993 | |
| 994 | floor: { |
| 995 | checks: {} |
| 996 | classes: {} |
| 997 | unclassified: {} |
| 998 | } |
| 999 | EOF |
| 1000 | git -C "$floor" commit --quiet -am "the floor requires nothing, and says so" |
| 1001 | git -C "$floor" push --quiet "$instance_repo" main |
| 1002 | |
| 1003 | git checkout --quiet main |
| 1004 | git pull --quiet --ff-only origin main |
| 1005 | git checkout --quiet -b c16 |
| 1006 | echo "a readme under a floor that requires nothing" > docs/readme.md |
| 1007 | git add -A |
| 1008 | git commit --quiet -m "a change under an empty floor and no project layer" |
| 1009 | request c16 main "$(git rev-parse c16)" |
| 1010 | integrate |
| 1011 | grep -q "^c16 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 1012 | || die "a change under an explicitly empty floor did not land: $(cat "$work/last.out")" |
| 1013 | grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \ |
| 1014 | || die "the verdict did not say the policy required nothing" |
| 1015 | grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \ |
| 1016 | || die "the pass did not say it composed the floor alone" |
| 1017 | landed_as "$(git rev-parse c16)" "$pre" |
| 1018 | holds "a floor that states it requires nothing composes, judges, and lands the change requiring nothing" |
| 1019 | |
| 1020 | # ---------------------------------------------------------------------- |
| 1021 | say "17. a planted replacement ref changes nothing the controller reads" |
| 1022 | |
| 1023 | # refs/replace/<id> makes git read another object wherever it looks <id> up. |
| 1024 | # Two are planted here, and each alone would land a change that requires |
| 1025 | # evidence and carries none. One swaps the floor's blob in the instance |
| 1026 | # repository for a floor that requires nothing. The other swaps the change's |
| 1027 | # head in the served repository for a commit that touches no class. Neither |
| 1028 | # moves a ref the controller watches. A controller that left replacement |
| 1029 | # refs on would read both and land the change; this one reads the objects |
| 1030 | # the refs actually name, and holds the change stale. |
| 1031 | cat > "$floor/policy/instance/floor.cue" <<'EOF' |
| 1032 | package verification |
| 1033 | |
| 1034 | floor: { |
| 1035 | checks: "prose-format": {runner: "nix", attribute: "prose-format"} |
| 1036 | classes: prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 1037 | unclassified: {} |
| 1038 | } |
| 1039 | EOF |
| 1040 | git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/ again" |
| 1041 | git -C "$floor" push --quiet "$instance_repo" main |
| 1042 | landed_floor="$(git -C "$instance_repo" rev-parse main:policy/instance/floor.cue)" |
| 1043 | empty_floor="$(git -C "$instance_repo" rev-parse main~1:policy/instance/floor.cue)" |
| 1044 | git -C "$instance_repo" update-ref "refs/replace/$landed_floor" "$empty_floor" |
| 1045 | git -C "$instance_repo" show main:policy/instance/floor.cue | grep 'checks: {}' > /dev/null \ |
| 1046 | || die "the floor's replacement did not take, so this scenario proves nothing" |
| 1047 | |
| 1048 | git checkout --quiet main |
| 1049 | git pull --quiet --ff-only origin main |
| 1050 | git checkout --quiet -b c17-decoy |
| 1051 | echo "a note no class covers" > notes.txt |
| 1052 | git commit --quiet -am "a decoy that touches no class" |
| 1053 | git checkout --quiet main |
| 1054 | git checkout --quiet -b c17 |
| 1055 | echo "a readme no evidence covers" > docs/readme.md |
| 1056 | git commit --quiet -am "a change that requires prose-format and carries no evidence" |
| 1057 | git push --quiet origin c17 c17-decoy |
| 1058 | git -C "$origin" update-ref "refs/replace/$(git rev-parse c17)" "$(git rev-parse c17-decoy)" |
| 1059 | git -C "$origin" diff --name-only main c17 | grep -x notes.txt > /dev/null \ |
| 1060 | || die "the head's replacement did not take, so this scenario proves nothing" |
| 1061 | request c17 main "$(git rev-parse c17)" |
| 1062 | |
| 1063 | # The environment asks for replacement refs too, and is not listened to. |
| 1064 | before="$(tip)" |
| 1065 | GIT_CONFIG_PARAMETERS="'core.usereplacerefs'='true'" integrate |
| 1066 | grep -q "^c17 -> refs/heads/main .*: stale$" "$work/last.out" \ |
| 1067 | || die "a planted replacement ref decided the verdict: $(cat "$work/last.out")" |
| 1068 | grep -q "check prose-format" "$work/last.out" \ |
| 1069 | || die "the landed floor's requirement was not what the controller read" |
| 1070 | grep -q 'no attestation for this check accompanies the change' "$work/last.out" \ |
| 1071 | || die "the missing evidence was not reported" |
| 1072 | [ "$(tip)" = "$before" ] || die "main moved under a change that requires evidence" |
| 1073 | git -C "$instance_repo" update-ref -d "refs/replace/$landed_floor" |
| 1074 | git -C "$origin" update-ref -d "refs/replace/$(git rev-parse c17)" |
| 1075 | forget c17 |
| 1076 | holds "the floor and the change were read as landed and as pushed, past both replacements" |
| 1077 | |
| 1078 | # ---------------------------------------------------------------------- |
| 1079 | say "18. a request approved again while its previous head lands stands for the next pass" |
| 1080 | |
| 1081 | # A second approval is leased against the request it read, and |
| 1082 | # nothing stops it reading the head this pass is about to land. So the |
| 1083 | # request can move between the pass reading it and the pass consuming it. |
| 1084 | # The landing is still the old head's, and the request that moved is a new |
| 1085 | # request: consuming it would drop a change nobody judged. |
| 1086 | git checkout --quiet main |
| 1087 | git pull --quiet --ff-only origin main |
| 1088 | git checkout --quiet -b c18 |
| 1089 | echo "a readme requested once" > docs/readme.md |
| 1090 | git commit --quiet -am "the first request" |
| 1091 | attest_change c18 "" "" --check prose-format |
| 1092 | request c18 main "$(git rev-parse c18)" |
| 1093 | # main moves under the request, outside anything the check reads. The pass |
| 1094 | # then recomputes the check's closure over the landed tree, and that |
| 1095 | # evaluation is where the second approval happens. |
| 1096 | git checkout --quiet main |
| 1097 | echo "a note landed in between" > notes.txt |
| 1098 | git commit --quiet -am "a note landed in between" |
| 1099 | git push --quiet origin main |
| 1100 | git checkout --quiet c18 |
| 1101 | git checkout --quiet -b c18-again |
| 1102 | echo "a readme requested again" > docs/readme.md |
| 1103 | git commit --quiet -am "the second request" |
| 1104 | git push --quiet origin c18-again |
| 1105 | again="$(git rev-parse c18-again)" |
| 1106 | moving="refs/the-valley/integration-requests/main/c18" |
| 1107 | before="$(tip)" |
| 1108 | VALLEY_E2E_DURING_PASS="git -C '$origin' update-ref '$moving' '$again'" integrate |
| 1109 | grep -q "^c18 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 1110 | || die "the first request did not land: $(cat "$work/last.out")" |
| 1111 | [ "$(tip)" != "$before" ] || die "main did not move for the first request" |
| 1112 | [ "$(git -C "$origin" rev-parse --verify --quiet "$moving")" = "$again" ] \ |
| 1113 | || die "the request approved again was consumed with the landing of the one before it: $(git -C "$origin" for-each-ref refs/the-valley/integration-requests) $(cat "$work/last.out")" |
| 1114 | grep -q "request $moving moved to .* while .* landed; it stands for the next pass" "$work/last.out" \ |
| 1115 | || die "the moved request was not reported: $(cat "$work/last.out")" |
| 1116 | forget c18 |
| 1117 | holds "a request that moved while its previous head landed was left standing, and said so" |
| 1118 | |
| 1119 | # ---------------------------------------------------------------------- |
| 1120 | say "19. a bus that never answers does not hold up a landing" |
| 1121 | |
| 1122 | # The landing's own record comes first: main moves, the move is queued for |
| 1123 | # the mirrors, the evidence is stored and the request consumed. Only then |
| 1124 | # does the integrator publish, and each publish is cut off at its deadline. |
| 1125 | # The shipped wrapper puts the real nats first on the path, so the bare |
| 1126 | # binary runs here, behind a nats that never exits. |
| 1127 | mkdir "$work/hung-bus" "$work/queue" |
| 1128 | cat > "$work/hung-bus/nats" <<EOF |
| 1129 | #!$(command -v bash) |
| 1130 | exec sleep 1000 |
| 1131 | EOF |
| 1132 | chmod +x "$work/hung-bus/nats" |
| 1133 | git checkout --quiet main |
| 1134 | git pull --quiet --ff-only origin main |
| 1135 | git checkout --quiet -b c19 |
| 1136 | echo "landed past a bus that never answers" > docs/bus.md |
| 1137 | git add -A |
| 1138 | git commit --quiet -m "past a hung bus" |
| 1139 | attest_change c19 "" "" --check prose-format |
| 1140 | request c19 main "$(git rev-parse c19)" |
| 1141 | before="$(tip)" |
| 1142 | started=$SECONDS |
| 1143 | PATH="$work/hung-bus:$PATH" timeout 120 "$INTEGRATOR_UNWRAPPED" reconcile \ |
| 1144 | --repo "$origin" \ |
| 1145 | --key "$work/integrator" --name "$integrator_name" \ |
| 1146 | --known-signers "$work/known_signers" \ |
| 1147 | --instance-repo "$instance_repo" \ |
| 1148 | --schema "$SCHEMA_VERIFICATION" \ |
| 1149 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 1150 | --event-schema "$SCHEMA_EVENTS" \ |
| 1151 | --bus nats://127.0.0.1:1 \ |
| 1152 | --publish-queue "$work/queue" \ |
| 1153 | 2>&1 | tee "$work/last.out" \ |
| 1154 | || die "the pass did not finish with a bus that never answers: $(cat "$work/last.out")" |
| 1155 | elapsed=$((SECONDS - started)) |
| 1156 | grep -q "^c19 -> refs/heads/main .*: land$" "$work/last.out" || die "c19 did not land: $(cat "$work/last.out")" |
| 1157 | landed_as "$(git rev-parse c19)" "$before" |
| 1158 | [ "$(cat "$work"/queue/*)" = "$before $(tip) refs/heads/main" ] \ |
| 1159 | || die "the move was not queued for the mirrors: $(ls -A "$work/queue")" |
| 1160 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c19 > /dev/null \ |
| 1161 | && die "the request outlived the landing" |
| 1162 | grep -q "^ evidence " "$work/last.out" || die "the evidence was not stored" |
| 1163 | first_evidence="$(grep -n "^ evidence " "$work/last.out" | head -n1 | cut -d: -f1)" |
| 1164 | first_bus="$(grep -n "^ bus " "$work/last.out" | head -n1 | cut -d: -f1)" |
| 1165 | [ "$first_evidence" -lt "$first_bus" ] || die "the integrator asked the bus before it stored the evidence" |
| 1166 | grep -q "bus publish of valley.git.project.ref-updated FAILED: no answer within 10s" "$work/last.out" \ |
| 1167 | || die "the hung ref-updated publish was not cut off: $(cat "$work/last.out")" |
| 1168 | grep -q "bus publish of valley.git.project.integration-succeeded FAILED: no answer within 10s" "$work/last.out" \ |
| 1169 | || die "the hung integration-succeeded publish was not cut off" |
| 1170 | [ "$elapsed" -lt 60 ] || die "the pass took ${elapsed}s behind a bus that never answers" |
| 1171 | holds "c19 landed, queued and consumed its request before a hung bus was asked, and each publish gave up after 10s (${elapsed}s in all)" |
| 1172 | |
| 1173 | # ---------------------------------------------------------------------- |
| 1174 | say "20. a cue that never answers a payload's vet does not hold up a landing" |
| 1175 | |
| 1176 | # The payload is vetted before it is published, and the vet is bounded the |
| 1177 | # same way. This cue hangs only when asked to vet against the event schema; |
| 1178 | # every other use, judging included, goes to the real one. |
| 1179 | real_cue="$(command -v cue)" |
| 1180 | mkdir "$work/hung-cue" "$work/queue20" |
| 1181 | cat > "$work/hung-cue/cue" <<EOF |
| 1182 | #!$(command -v bash) |
| 1183 | for arg; do [ "\$arg" = "$SCHEMA_EVENTS" ] && exec sleep 1000; done |
| 1184 | exec "$real_cue" "\$@" |
| 1185 | EOF |
| 1186 | chmod +x "$work/hung-cue/cue" |
| 1187 | git checkout --quiet main |
| 1188 | git pull --quiet --ff-only origin main |
| 1189 | git checkout --quiet -b c20 |
| 1190 | echo "landed past a cue that never answers" > docs/cue.md |
| 1191 | git add -A |
| 1192 | git commit --quiet -m "past a hung cue" |
| 1193 | attest_change c20 "" "" --check prose-format |
| 1194 | request c20 main "$(git rev-parse c20)" |
| 1195 | before="$(tip)" |
| 1196 | started=$SECONDS |
| 1197 | PATH="$work/hung-cue:$PATH" timeout 120 "$INTEGRATOR_UNWRAPPED" reconcile \ |
| 1198 | --repo "$origin" \ |
| 1199 | --key "$work/integrator" --name "$integrator_name" \ |
| 1200 | --known-signers "$work/known_signers" \ |
| 1201 | --instance-repo "$instance_repo" \ |
| 1202 | --schema "$SCHEMA_VERIFICATION" \ |
| 1203 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 1204 | --event-schema "$SCHEMA_EVENTS" \ |
| 1205 | --publish-queue "$work/queue20" \ |
| 1206 | 2>&1 | tee "$work/last.out" \ |
| 1207 | || die "the pass did not finish with a cue that never answers: $(cat "$work/last.out")" |
| 1208 | elapsed=$((SECONDS - started)) |
| 1209 | grep -q "^c20 -> refs/heads/main .*: land$" "$work/last.out" || die "c20 did not land: $(cat "$work/last.out")" |
| 1210 | landed_as "$(git rev-parse c20)" "$before" |
| 1211 | [ "$(cat "$work"/queue20/*)" = "$before $(tip) refs/heads/main" ] \ |
| 1212 | || die "the move was not queued for the mirrors: $(ls -A "$work/queue20")" |
| 1213 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c20 > /dev/null \ |
| 1214 | && die "the request outlived the landing" |
| 1215 | grep -q "^ evidence " "$work/last.out" || die "the evidence was not stored" |
| 1216 | grep -q "bus ref-updated not published: cue vet against #RefUpdated gave no answer within 10s" "$work/last.out" \ |
| 1217 | || die "the hung vet of ref-updated was not cut off: $(cat "$work/last.out")" |
| 1218 | grep -q "bus integration-succeeded not published: cue vet against #IntegrationSucceeded gave no answer within 10s" "$work/last.out" \ |
| 1219 | || die "the hung vet of integration-succeeded was not cut off" |
| 1220 | [ "$elapsed" -lt 60 ] || die "the pass took ${elapsed}s behind a cue that never answers" |
| 1221 | holds "c20 landed, queued and consumed its request, and each hung vet gave up after 10s and skipped its publish (${elapsed}s in all)" |
| 1222 | |
| 1223 | # ---------------------------------------------------------------------- |
| 1224 | say "21. a request named for a change that is ready lands" |
| 1225 | |
| 1226 | # A change with a record is requested as c-<change ID>. The records are |
| 1227 | # written by the valley command itself, as its owner would write them; this |
| 1228 | # repository is served without the hook that guards them on a host. The |
| 1229 | # integrator reads them only to refuse. |
| 1230 | git config valley.principal contributor |
| 1231 | # ready_change <branch>: the branch's head on origin readied as a new |
| 1232 | # change, whose ID is left in $readied. |
| 1233 | ready_change() { |
| 1234 | valley ready "$1" > "$work/ready.out" || die "valley ready $1 failed" |
| 1235 | readied="$(sed -n 's/^The change ID \([k-z]*\) is new\..*/\1/p' "$work/ready.out")" |
| 1236 | [ "${#readied}" = 32 ] || die "valley ready $1 made no change ID: $(cat "$work/ready.out")" |
| 1237 | } |
| 1238 | outcome_of() { git -C "$origin" cat-file blob "refs/the-valley/integration-outcomes/main/$1" | cut -d' ' -f4; } |
| 1239 | |
| 1240 | git checkout --quiet main |
| 1241 | git pull --quiet --ff-only origin main |
| 1242 | git checkout --quiet -b c21 |
| 1243 | echo "a change with a record" > docs/c21.md |
| 1244 | git add -A |
| 1245 | git commit --quiet -m "a change with a record" |
| 1246 | attest_change c21 "" "" --check prose-format |
| 1247 | ready_change c21 |
| 1248 | id21="$readied" |
| 1249 | request "c-$id21" main "$(git rev-parse c21)" |
| 1250 | integrate |
| 1251 | grep -q "^c-$id21 -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id21 did not land" |
| 1252 | landed_as "$(git rev-parse c21)" "$pre" |
| 1253 | landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c21 | cut -d: -f2)/$ihash" |
| 1254 | git -C "$origin" cat-file blob "$landed:$(transfer_path "$(tip)")" | grep -qx "predicate.change c-$id21" \ |
| 1255 | || die "the transfer statement does not name the request c-$id21" |
| 1256 | holds "a ready change's request, named for its ID, landed, and its transfer statement names it so" |
| 1257 | |
| 1258 | # ---------------------------------------------------------------------- |
| 1259 | say "22. a change unreadied after its request was filed is refused, and lands once it is ready again" |
| 1260 | |
| 1261 | git checkout --quiet main |
| 1262 | git pull --quiet --ff-only origin main |
| 1263 | git checkout --quiet -b c22 |
| 1264 | echo "a change paused after it was approved" > docs/c22.md |
| 1265 | git add -A |
| 1266 | git commit --quiet -m "a change paused after it was approved" |
| 1267 | attest_change c22 "" "" --check prose-format |
| 1268 | ready_change c22 |
| 1269 | id22="$readied" |
| 1270 | request "c-$id22" main "$(git rev-parse c22)" |
| 1271 | valley unready "$id22" > /dev/null 2>&1 || die "valley unready failed" |
| 1272 | before="$(tip)" |
| 1273 | integrate |
| 1274 | grep -q "^c-$id22 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \ |
| 1275 | || die "a draft's request was not refused: $(cat "$work/last.out")" |
| 1276 | grep -q "change $id22 is draft, not ready" "$work/last.out" || die "the refusal did not say the change is a draft" |
| 1277 | [ "$(tip)" = "$before" ] || die "a draft's request moved main" |
| 1278 | git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id22" > /dev/null \ |
| 1279 | || die "the refused request was dropped" |
| 1280 | [ "$(outcome_of "c-$id22")" = refused-not-ready ] || die "the outcome record does not say refused-not-ready" |
| 1281 | |
| 1282 | # The refusal is decided again on every pass, and said once. |
| 1283 | timeout 4 integrator watch --interval 1s \ |
| 1284 | --repo "$origin" \ |
| 1285 | --key "$work/integrator" --name "$integrator_name" \ |
| 1286 | --known-signers "$work/known_signers" \ |
| 1287 | --instance-repo "$instance_repo" \ |
| 1288 | --schema "$SCHEMA_VERIFICATION" \ |
| 1289 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 1290 | --event-schema "$SCHEMA_EVENTS" \ |
| 1291 | > "$work/repeat.out" 2>&1 || true |
| 1292 | [ "$(grep -c "c-$id22 .*refused-not-ready" "$work/repeat.out" || true)" -eq 0 ] \ |
| 1293 | || die "a standing refusal was reported again: $(cat "$work/repeat.out")" |
| 1294 | [ "$(tip)" = "$before" ] || die "a draft's request moved main under watch" |
| 1295 | |
| 1296 | # Readied again at the same head, the same request lands on the next pass. |
| 1297 | valley ready --change "$id22" c22 > /dev/null 2>&1 || die "valley ready --change $id22 failed" |
| 1298 | integrate |
| 1299 | grep -q "^c-$id22 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 1300 | || die "the change readied again did not land: $(cat "$work/last.out")" |
| 1301 | landed_as "$(git rev-parse c22)" "$pre" |
| 1302 | holds "unready stopped a filed request, the refusal was said once, and ready let the same request land" |
| 1303 | |
| 1304 | # ---------------------------------------------------------------------- |
| 1305 | say "23. a request named for a branch, at a draft's head, is refused" |
| 1306 | |
| 1307 | # Whatever a request is named, a head that is a version of a change that |
| 1308 | # is not ready does not land. |
| 1309 | git checkout --quiet main |
| 1310 | git pull --quiet --ff-only origin main |
| 1311 | git checkout --quiet -b c23 |
| 1312 | echo "a draft requested under its branch's name" > docs/c23.md |
| 1313 | git add -A |
| 1314 | git commit --quiet -m "a draft requested under its branch's name" |
| 1315 | attest_change c23 "" "" --check prose-format |
| 1316 | ready_change c23 |
| 1317 | id23="$readied" |
| 1318 | valley unready "$id23" > /dev/null 2>&1 || die "valley unready failed" |
| 1319 | request c23 main "$(git rev-parse c23)" |
| 1320 | before="$(tip)" |
| 1321 | integrate |
| 1322 | grep -q "^c23 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \ |
| 1323 | || die "a branch-named request at a draft's head was not refused: $(cat "$work/last.out")" |
| 1324 | grep -q "is v1 of change $id23, which is draft, not ready" "$work/last.out" \ |
| 1325 | || die "the refusal did not name the draft" |
| 1326 | [ "$(tip)" = "$before" ] || die "a draft's head landed under its branch's name" |
| 1327 | [ "$(outcome_of c23)" = refused-not-ready ] || die "the outcome record does not say refused-not-ready" |
| 1328 | forget c23 |
| 1329 | holds "a draft's head was refused under a branch's name too" |
| 1330 | |
| 1331 | # ---------------------------------------------------------------------- |
| 1332 | say "24. a request whose commits hold a merge is refused" |
| 1333 | |
| 1334 | # A merge can make other work look landed by ancestry, so the integrator |
| 1335 | # lands a line of commits and nothing else. |
| 1336 | git checkout --quiet main |
| 1337 | git pull --quiet --ff-only origin main |
| 1338 | git checkout --quiet -b c24-side |
| 1339 | echo "a side line" > docs/c24-side.md |
| 1340 | git add -A |
| 1341 | git commit --quiet -m "a side line" |
| 1342 | git checkout --quiet main |
| 1343 | git checkout --quiet -b c24 |
| 1344 | echo "a line with a merge in it" > docs/c24.md |
| 1345 | git add -A |
| 1346 | git commit --quiet -m "a line with a merge in it" |
| 1347 | git merge --quiet --no-ff --no-edit c24-side |
| 1348 | git push --quiet origin c24 |
| 1349 | request c24 main "$(git rev-parse c24)" |
| 1350 | before="$(tip)" |
| 1351 | integrate |
| 1352 | grep -q "^c24 -> refs/heads/main .*: refused-merge$" "$work/last.out" \ |
| 1353 | || die "a request holding a merge was not refused: $(cat "$work/last.out")" |
| 1354 | grep -q "include the merge $(git rev-parse c24 | cut -c1-12)" "$work/last.out" || die "the refusal did not name the merge" |
| 1355 | [ "$(tip)" = "$before" ] || die "a request holding a merge moved main" |
| 1356 | [ "$(outcome_of c24)" = refused-merge ] || die "the outcome record does not say refused-merge" |
| 1357 | forget c24 |
| 1358 | holds "a request holding a merge was refused, and main did not move" |
| 1359 | |
| 1360 | # ---------------------------------------------------------------------- |
| 1361 | say "25. a line of commits above a draft's head is refused, naming the draft" |
| 1362 | |
| 1363 | # A request brings every commit from its merge base to its head. So a child |
| 1364 | # of a draft's head, approved under another name, would land the draft too. |
| 1365 | git checkout --quiet main |
| 1366 | git pull --quiet --ff-only origin main |
| 1367 | git checkout --quiet -b c25-draft |
| 1368 | echo "a draft below another change" > docs/c25-draft.md |
| 1369 | git add -A |
| 1370 | git commit --quiet -m "a draft below another change" |
| 1371 | git push --quiet origin c25-draft |
| 1372 | ready_change c25-draft |
| 1373 | id25="$readied" |
| 1374 | valley unready "$id25" > /dev/null 2>&1 || die "valley unready failed" |
| 1375 | git checkout --quiet -b c25 |
| 1376 | echo "a change above a draft" > docs/c25.md |
| 1377 | git add -A |
| 1378 | git commit --quiet -m "a change above a draft" |
| 1379 | git push --quiet origin c25 |
| 1380 | request c25 main "$(git rev-parse c25)" |
| 1381 | before="$(tip)" |
| 1382 | integrate |
| 1383 | grep -q "^c25 -> refs/heads/main .*: refused-not-ready$" "$work/last.out" \ |
| 1384 | || die "a child of a draft's head was not refused: $(cat "$work/last.out")" |
| 1385 | grep -q "the commit $(git rev-parse c25-draft | cut -c1-12) it brings is v1 of change $id25, which is draft, not ready" \ |
| 1386 | "$work/last.out" || die "the refusal did not name the draft" |
| 1387 | [ "$(tip)" = "$before" ] || die "a child of a draft's head moved main" |
| 1388 | forget c25 |
| 1389 | holds "a line above a draft's head was refused, and the refusal named the draft" |
| 1390 | |
| 1391 | # ---------------------------------------------------------------------- |
| 1392 | say "26. withdrawing a change voids its request, and readying it again needs a fresh approval" |
| 1393 | |
| 1394 | # integrate_quiet: a pass that may have nothing to say. |
| 1395 | integrate_quiet() { |
| 1396 | integrator reconcile \ |
| 1397 | --repo "$origin" \ |
| 1398 | --key "$work/integrator" --name "$integrator_name" \ |
| 1399 | --known-signers "$work/known_signers" \ |
| 1400 | --instance-repo "$instance_repo" \ |
| 1401 | --schema "$SCHEMA_VERIFICATION" \ |
| 1402 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 1403 | --event-schema "$SCHEMA_EVENTS" \ |
| 1404 | 2>&1 | tee "$work/last.out" |
| 1405 | } |
| 1406 | git checkout --quiet main |
| 1407 | git pull --quiet --ff-only origin main |
| 1408 | git checkout --quiet -b c26 |
| 1409 | echo "a change withdrawn after it was approved" > docs/c26.md |
| 1410 | git add -A |
| 1411 | git commit --quiet -m "a change withdrawn after it was approved" |
| 1412 | attest_change c26 "" "" --check prose-format |
| 1413 | ready_change c26 |
| 1414 | id26="$readied" |
| 1415 | request "c-$id26" main "$(git rev-parse c26)" |
| 1416 | valley withdraw "$id26" > /dev/null 2>&1 || die "valley withdraw failed" |
| 1417 | before="$(tip)" |
| 1418 | integrate |
| 1419 | grep -q "^c-$id26 -> refs/heads/main .*: voided-withdrawn$" "$work/last.out" \ |
| 1420 | || die "a withdrawn change's request was not voided: $(cat "$work/last.out")" |
| 1421 | git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id26" > /dev/null \ |
| 1422 | && die "the voided request is still there" |
| 1423 | [ "$(outcome_of "c-$id26")" = voided-withdrawn ] || die "the outcome record does not say voided-withdrawn" |
| 1424 | [ "$(tip)" = "$before" ] || die "a withdrawn change moved main" |
| 1425 | |
| 1426 | # Readied again at the same head, the change has no request: the old |
| 1427 | # approval is gone, and nothing lands. |
| 1428 | valley ready --change "$id26" c26 > /dev/null 2>&1 || die "valley ready --change $id26 failed" |
| 1429 | integrate_quiet |
| 1430 | git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c-$id26" > /dev/null \ |
| 1431 | && die "the old request came back" |
| 1432 | [ "$(tip)" = "$before" ] || die "a change readied again landed with no fresh approval" |
| 1433 | |
| 1434 | # A fresh approval at the same head lands. |
| 1435 | request "c-$id26" main "$(git rev-parse c26)" |
| 1436 | integrate |
| 1437 | grep -q "^c-$id26 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 1438 | || die "the fresh approval did not land: $(cat "$work/last.out")" |
| 1439 | landed_as "$(git rev-parse c26)" "$pre" |
| 1440 | holds "withdraw voided the request on the next pass; readied again, the change landed only on a fresh approval" |
| 1441 | |
| 1442 | # ---------------------------------------------------------------------- |
| 1443 | say "27. a stack is rebased whole, a landed change under it drops out, and approving its top lands it as one commit" |
| 1444 | |
| 1445 | # approve reads the floor where the integrator does: the owning valley, |
| 1446 | # which policy/valley names at main's tip. |
| 1447 | git checkout --quiet main |
| 1448 | git pull --quiet --ff-only origin main |
| 1449 | mkdir -p policy |
| 1450 | echo "$instance_repo" > policy/valley |
| 1451 | git add policy/valley |
| 1452 | git commit --quiet -m "name the owning valley" |
| 1453 | git push --quiet origin main |
| 1454 | |
| 1455 | # A change of two commits, a plain branch on it, and two changes on that. |
| 1456 | git checkout --quiet -b c27-a |
| 1457 | echo "the first half of a" > docs/c27-a1.md |
| 1458 | git add -A |
| 1459 | git commit --quiet -m "c27: the first half of a" |
| 1460 | echo "the second half of a" > docs/c27-a2.md |
| 1461 | git add -A |
| 1462 | git commit --quiet -m "c27: the second half of a" |
| 1463 | attest_change c27-a "" "" --check prose-format |
| 1464 | ready_change c27-a |
| 1465 | id27a="$readied" |
| 1466 | for layer in p b c; do |
| 1467 | git checkout --quiet -b "c27-$layer" |
| 1468 | echo "layer $layer" > "docs/c27-$layer.md" |
| 1469 | git add -A |
| 1470 | git commit --quiet -m "c27: layer $layer" |
| 1471 | git push --quiet origin "c27-$layer" |
| 1472 | done |
| 1473 | ready_change c27-b |
| 1474 | id27b="$readied" |
| 1475 | ready_change c27-c |
| 1476 | id27c="$readied" |
| 1477 | a="$(git rev-parse c27-a)" p="$(git rev-parse c27-p)" b="$(git rev-parse c27-b)" c="$(git rev-parse c27-c)" |
| 1478 | |
| 1479 | # main moves under the stack, outside what prose-format reads, and then a |
| 1480 | # lands through an integrator merge: one new commit, not its own two. |
| 1481 | git checkout --quiet main |
| 1482 | git checkout --quiet -b c27-x |
| 1483 | mkdir -p notes |
| 1484 | echo "main moves on" > notes/c27-x.txt |
| 1485 | git add -A |
| 1486 | git commit --quiet -m "c27: main moves on" |
| 1487 | git push --quiet origin c27-x |
| 1488 | request c27-x main "$(git rev-parse c27-x)" |
| 1489 | integrate |
| 1490 | grep -q "^c27-x -> refs/heads/main .*: land$" "$work/last.out" || die "c27-x did not land" |
| 1491 | request "c-$id27a" main "$a" |
| 1492 | integrate |
| 1493 | grep -q "^c-$id27a -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id27a did not land" |
| 1494 | [ "$(git -C "$origin" merge-base "$a" "$pre")" != "$pre" ] \ |
| 1495 | || die "a's base is the tip it landed on, so main did not move under it; the scenario proves nothing" |
| 1496 | main27="$(tip)" |
| 1497 | [ "$(git -C "$origin" rev-list --no-walk --parents "$main27")" = "$main27 $pre" ] \ |
| 1498 | || die "a did not land as one commit on the tip before the pass" |
| 1499 | |
| 1500 | # The rebase reads a's landing from its transfer statement, so a is no |
| 1501 | # layer, and its two commits under the plain branch drop out. Each layer |
| 1502 | # keeps its own diff, on the rebased layer below. |
| 1503 | export VALLEY_KNOWN_SIGNERS="$work/reader_keys" VALLEY_INTEGRATOR_SIGNER="$integrator_name" |
| 1504 | valley status --json "$id27a" | grep -q '"landing": *"landed-recorded"' || die "a's landing was not read as recorded" |
| 1505 | valley rebase "$id27c" > "$work/rebase.out" 2>&1 || die "the rebase failed: $(cat "$work/rebase.out")" |
| 1506 | git fetch --quiet origin |
| 1507 | np="$(git rev-parse origin/c27-p)" nb="$(git rev-parse origin/c27-b)" nc="$(git rev-parse origin/c27-c)" |
| 1508 | git merge-base --is-ancestor "$main27" "$np" || die "the bottom is not on main" |
| 1509 | git merge-base --is-ancestor "$np" "$nb" || die "b is not on the rebased plain branch" |
| 1510 | git merge-base --is-ancestor "$nb" "$nc" || die "c is not on b" |
| 1511 | [ "$(git rev-list --count "$main27..$np")" = 1 ] || die "a's commits did not drop out from under the plain branch" |
| 1512 | [ "$(git diff "$a" "$p")" = "$(git diff "$main27" "$np")" ] || die "the plain branch's diff changed" |
| 1513 | [ "$(git diff "$p" "$b")" = "$(git diff "$np" "$nb")" ] || die "b's diff changed" |
| 1514 | [ "$(git diff "$b" "$c")" = "$(git diff "$nb" "$nc")" ] || die "c's diff changed" |
| 1515 | grep -q "^ c27-p .* origin/c27-p pushed$" "$work/rebase.out" || die "the manifest did not list the plain branch: $(cat "$work/rebase.out")" |
| 1516 | holds "the stack moved whole onto main, and the landed change's commits dropped out from under it" |
| 1517 | |
| 1518 | # Approving the rebased top, and landing it, lands the whole stack as one |
| 1519 | # commit the integrator makes, with landing evidence for the top alone. A |
| 1520 | # lower layer's landing evidence comes with per-layer landing, which lands |
| 1521 | # a stack as one commit per layer. |
| 1522 | VALLEY_ATTEST_KEY="$work/contributor" VALLEY_ATTEST_NAME="$contributor" \ |
| 1523 | valley approve --head "$nc" "$id27c" > "$work/approve.out" 2>&1 \ |
| 1524 | || die "approving the rebased top failed: $(cat "$work/approve.out")" |
| 1525 | integrate |
| 1526 | grep -q "^c-$id27c -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id27c did not land" |
| 1527 | landed_as "$nc" "$pre" |
| 1528 | [ "$(git -C "$origin" rev-parse "$(tip)^")" = "$main27" ] || die "the stack did not land as one commit on the tip" |
| 1529 | for commit in "$np" "$nb" "$nc"; do |
| 1530 | git -C "$origin" merge-base --is-ancestor "$commit" "$(tip)" && die "the stack's own commit $commit is on main" |
| 1531 | done |
| 1532 | valley status --json "$id27c" | grep -q '"landing": *"landed-recorded"' || die "the top's landing was not read as recorded" |
| 1533 | unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER |
| 1534 | holds "the rebased stack landed as one commit, none of its own commits is on main, and the top reads landed-recorded" |
| 1535 | |
| 1536 | # ---------------------------------------------------------------------- |
| 1537 | say "28. a signer restricted to some projects counts in those, and is unknown in every other" |
| 1538 | |
| 1539 | # A check worker's key is in the known-signers file, as it is for every |
| 1540 | # controller that shares the file, and so is the integrator's, as a host's |
| 1541 | # registry holds it. The signer projects file lets the worker count in this |
| 1542 | # project alone. A controller takes the project from the repository it |
| 1543 | # serves, so this one's is "project". |
| 1544 | ssh-keygen -q -t ed25519 -N "" -C worker -f "$work/worker" |
| 1545 | worker=worker.valley.invalid/attestations |
| 1546 | cat "$work/known_signers" > "$work/worker_signers" |
| 1547 | attest key --key "$work/worker" --name "$worker" >> "$work/worker_signers" |
| 1548 | attest key --key "$work/integrator" --name "$integrator_name" >> "$work/worker_signers" |
| 1549 | printf '# the check worker builds for this project alone\n%s project\n' "$worker" > "$work/signer_projects" |
| 1550 | restricted=(--known-signers "$work/worker_signers" --signer-projects "$work/signer_projects") |
| 1551 | # The second project's controller signs under a name and key of its own, |
| 1552 | # as a controller on another host sharing the registry does, and holds the |
| 1553 | # same known-signers file, the first controller's key included. Nothing in |
| 1554 | # a note marks the first controller's signature as a countersignature, so |
| 1555 | # this host declares it: its signer projects file names the first |
| 1556 | # controller with no project, and the worker with this project alone. |
| 1557 | ssh-keygen -q -t ed25519 -N "" -C second-integrator -f "$work/second_integrator" |
| 1558 | second_integrator=second-integrator.valley.invalid/attestations |
| 1559 | printf '%s project\n%s\n' "$worker" "$integrator_name" > "$work/second_signer_projects" |
| 1560 | second=(--repo "$work/elsewhere.git" --key "$work/second_integrator" --name "$second_integrator" |
| 1561 | --known-signers "$work/worker_signers" --signer-projects "$work/second_signer_projects") |
| 1562 | |
| 1563 | git checkout --quiet main |
| 1564 | git pull --quiet --ff-only origin main |
| 1565 | git checkout --quiet -b c28 |
| 1566 | echo "a readme a check worker built" > docs/c28.md |
| 1567 | git add -A |
| 1568 | git commit --quiet -m "a change a check worker attested" |
| 1569 | attest_change c28 "$work/worker" "$worker" --check prose-format |
| 1570 | c28="$(git rev-parse c28)" |
| 1571 | c28digest="$(attest digest --repo "$repo" --rev c28 | cut -d: -f2)" |
| 1572 | c28ref="refs/the-valley/attestations/$c28digest/$(attest key --key "$work/worker" --name "$worker" | cut -d+ -f2)" |
| 1573 | request c28 main "$c28" |
| 1574 | |
| 1575 | # A second project, served the same way, holds the same commits, the same |
| 1576 | # note and the same request. Its controller's project is "elsewhere". |
| 1577 | elsewhere="$work/elsewhere.git" |
| 1578 | git init --quiet --bare "$elsewhere" |
| 1579 | git -C "$origin" push --quiet "$elsewhere" main c28 "$c28ref" refs/the-valley/integration-requests/main/c28 |
| 1580 | [ "$(git -C "$elsewhere" rev-parse "$c28ref")" = "$(git -C "$origin" rev-parse "$c28ref")" ] \ |
| 1581 | || die "the second project does not hold the same note" |
| 1582 | before28="$(git -C "$elsewhere" rev-parse main)" before="$(tip)" |
| 1583 | integrate "${second[@]}" |
| 1584 | grep -q "^c28 -> refs/heads/main .*: stale$" "$work/last.out" \ |
| 1585 | || die "the worker's evidence counted in a project not listed for it" |
| 1586 | grep -q "check prose-format .*signed by no signer the integrator holds" "$work/last.out" \ |
| 1587 | || die "the worker's note was not reported as an unknown signer's" |
| 1588 | [ "$(git -C "$elsewhere" rev-parse main)" = "$before28" ] || die "main moved in the second project" |
| 1589 | holds "in a project not listed for it, the worker's note is classified as a stranger's" |
| 1590 | |
| 1591 | # A signer projects file the controller cannot read stops it before it |
| 1592 | # judges anything: one that names a signer twice, one that names a |
| 1593 | # verifier key line rather than a signer, one whose projects are joined by |
| 1594 | # a no-break space rather than a space, and one that is not there. So does |
| 1595 | # one that restricts the integrator's own name, under which a worker would |
| 1596 | # also sign transfer statements. |
| 1597 | printf '%s project\n%s elsewhere\n' "$worker" "$worker" > "$work/named_twice" |
| 1598 | attest key --key "$work/worker" --name "$worker" > "$work/key_line" |
| 1599 | printf '%s project\302\240elsewhere\n' "$worker" > "$work/no_break_space" |
| 1600 | printf '%s project\n' "$integrator_name" > "$work/names_the_integrator" |
| 1601 | for list in named_twice key_line no_break_space missing names_the_integrator; do |
| 1602 | if reconcile "${restricted[@]}" --signer-projects "$work/$list" > "$work/$list.out" 2>&1; then |
| 1603 | die "a controller given the $list signer projects file ran: $(cat "$work/$list.out")" |
| 1604 | fi |
| 1605 | grep -q "signer projects file" "$work/$list.out" \ |
| 1606 | || die "the $list signer projects file was not named as the reason: $(cat "$work/$list.out")" |
| 1607 | grep -q "^c28 " "$work/$list.out" && die "a controller given the $list signer projects file judged c28" |
| 1608 | [ "$(tip)" = "$before" ] || die "main moved under the $list signer projects file" |
| 1609 | done |
| 1610 | grep -qF "names $integrator_name, the name the integrator signs under" "$work/names_the_integrator.out" \ |
| 1611 | || die "the integrator's own name was not the reason: $(cat "$work/names_the_integrator.out")" |
| 1612 | holds "a signer projects file that does not read, or restricts the integrator's name, stops the controller, and nothing lands" |
| 1613 | |
| 1614 | # In the project listed for it, the same note lands the change. |
| 1615 | integrate "${restricted[@]}" |
| 1616 | grep -q "^c28 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 1617 | || die "the worker's evidence did not count in the project listed for it" |
| 1618 | grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer" |
| 1619 | landed_as "$c28" "$pre" |
| 1620 | holds "in the project listed for it, the same note lands c28" |
| 1621 | |
| 1622 | # Landing countersigned the worker's note: the first controller stored it, |
| 1623 | # with its own signature added, under its own key hash. Copied into the |
| 1624 | # second project, the countersigned note still counts only through the |
| 1625 | # worker, who does not count there: the second controller holds the first |
| 1626 | # one's key, and its signer projects file lets that signature count |
| 1627 | # nowhere. |
| 1628 | countersigned="refs/the-valley/attestations/$c28digest/$ihash" |
| 1629 | git -C "$origin" cat-file blob "$countersigned:prose-format/statement.note" | grep -qF " $integrator_name " \ |
| 1630 | || die "the landing did not countersign the worker's note" |
| 1631 | git -C "$origin" push --quiet "$elsewhere" "$countersigned" |
| 1632 | integrate "${second[@]}" |
| 1633 | grep -q "^c28 -> refs/heads/main .*: stale$" "$work/last.out" \ |
| 1634 | || die "another controller's countersignature made the worker's note count in a project not listed for it" |
| 1635 | [ "$(git -C "$elsewhere" rev-parse main)" = "$before28" ] || die "main moved in the second project" |
| 1636 | holds "another controller's countersignature does not stand in for the worker" |
| 1637 | |
| 1638 | # A signer the file does not name still counts in the second project. The |
| 1639 | # contributor's note for the same tree arrives there, and replaces the |
| 1640 | # worker's as the evidence. |
| 1641 | attest run --repo "$repo" --key "$work/contributor" --name "$contributor" --check prose-format > /dev/null |
| 1642 | git push --quiet "$elsewhere" "refs/the-valley/attestations/$c28digest/$(cut -d+ -f2 < "$work/known_signers")" |
| 1643 | integrate "${second[@]}" |
| 1644 | grep -q "^c28 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 1645 | || die "an unrestricted signer's evidence did not count in the second project" |
| 1646 | landed_as "$c28" "$before28" "$elsewhere" "$second_integrator" |
| 1647 | holds "a signer the file does not name counts in every project, as before" |
| 1648 | |
| 1649 | # ---------------------------------------------------------------------- |
| 1650 | say "29. a change lands as one commit on the tip, and a tree that lands twice keeps both proofs" |
| 1651 | |
| 1652 | # A change of three commits on the tip. The middle one adds a build output |
| 1653 | # and the last removes it, so no diff review shows holds it. The change |
| 1654 | # lands as one commit the integrator makes, and the build output is in no |
| 1655 | # commit on main. |
| 1656 | export VALLEY_KNOWN_SIGNERS="$work/reader_keys" VALLEY_INTEGRATOR_SIGNER="$integrator_name" |
| 1657 | git fetch --quiet origin |
| 1658 | git checkout --quiet -B c29-a origin/main |
| 1659 | echo "the first text" > docs/c29.md |
| 1660 | git add -A |
| 1661 | git commit --quiet -m "c29: a document" |
| 1662 | mkdir -p build |
| 1663 | echo "a build output" > build/output.bin |
| 1664 | git add -A |
| 1665 | git commit --quiet -m "c29: a build output" |
| 1666 | git rm --quiet -r build |
| 1667 | git commit --quiet -m "c29: no build output" |
| 1668 | attest_change c29-a "" "" --check prose-format |
| 1669 | ready_change c29-a |
| 1670 | id29a="$readied" |
| 1671 | request "c-$id29a" main "$(git rev-parse c29-a)" |
| 1672 | integrate |
| 1673 | grep -q "^c-$id29a -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id29a did not land" |
| 1674 | landed_as "$(git rev-parse c29-a)" "$pre" |
| 1675 | land29a="$(tip)" |
| 1676 | [ -z "$(git -C "$origin" log --format=%H refs/heads/main -- build)" ] || die "the build output is on main" |
| 1677 | valley status --json "$id29a" | grep -q '"landing": *"landed-recorded"' || die "c-$id29a's landing was not read as recorded" |
| 1678 | holds "three commits on the tip landed as one commit, and the build output one of them held is nowhere on main" |
| 1679 | |
| 1680 | # Two single-commit changes: one changes the document, and the next puts |
| 1681 | # back the first text, so the tree c29-a landed lands again. Each landing |
| 1682 | # keeps its own transfer statement under that tree's ref, and both read |
| 1683 | # landed-recorded. |
| 1684 | git fetch --quiet origin |
| 1685 | git checkout --quiet -B c29-b origin/main |
| 1686 | echo "the second text" > docs/c29.md |
| 1687 | git commit --quiet -am "c29: the second text" |
| 1688 | attest_change c29-b "" "" --check prose-format |
| 1689 | ready_change c29-b |
| 1690 | request "c-$readied" main "$(git rev-parse c29-b)" |
| 1691 | integrate |
| 1692 | grep -q "^c-$readied -> refs/heads/main .*: land$" "$work/last.out" || die "c-$readied did not land" |
| 1693 | landed_as "$(git rev-parse c29-b)" "$pre" |
| 1694 | git fetch --quiet origin |
| 1695 | git checkout --quiet -B c29-c origin/main |
| 1696 | echo "the first text" > docs/c29.md |
| 1697 | git commit --quiet -am "c29: the first text again" |
| 1698 | [ "$(git rev-parse "c29-c^{tree}")" = "$(git -C "$origin" rev-parse "$land29a^{tree}")" ] \ |
| 1699 | || die "c29-c does not hold the tree c29-a landed; the scenario proves nothing" |
| 1700 | git push --quiet origin c29-c |
| 1701 | ready_change c29-c |
| 1702 | id29c="$readied" |
| 1703 | request "c-$id29c" main "$(git rev-parse c29-c)" |
| 1704 | integrate |
| 1705 | grep -q "^c-$id29c -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id29c did not land" |
| 1706 | landed_as "$(git rev-parse c29-c)" "$pre" |
| 1707 | land29c="$(tip)" |
| 1708 | landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c29-c | cut -d: -f2)/$ihash" |
| 1709 | for commit in "$land29a" "$land29c"; do |
| 1710 | git -C "$origin" cat-file blob "$landed:$(transfer_path "$commit")" > "$work/twice.note" \ |
| 1711 | || die "no transfer statement for the landing as $commit" |
| 1712 | grep -qx "subject.digest.git-sha1 $commit" "$work/twice.note" || die "the statement in $commit's slot is about another commit" |
| 1713 | done |
| 1714 | for id in "$id29a" "$id29c"; do |
| 1715 | valley status --json "$id" | grep -q '"landing": *"landed-recorded"' || die "change $id does not read landed-recorded" |
| 1716 | done |
| 1717 | unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER |
| 1718 | holds "one tree landed twice, each landing kept its own statement, and both read landed-recorded" |
| 1719 | |
| 1720 | # ---------------------------------------------------------------------- |
| 1721 | say "30. a change's next version lands under the same name, and the version before stays landed-recorded" |
| 1722 | |
| 1723 | # Version 1 lands under c-<ID>. Version 2, rebased onto the landing, lands |
| 1724 | # under the same name, and its outcome record replaces version 1's. Each |
| 1725 | # version's landing record still binds its own head to its own landing. |
| 1726 | export VALLEY_KNOWN_SIGNERS="$work/reader_keys" VALLEY_INTEGRATOR_SIGNER="$integrator_name" |
| 1727 | git fetch --quiet origin |
| 1728 | git checkout --quiet -B c30 origin/main |
| 1729 | echo "the first version" > docs/c30.md |
| 1730 | git add -A |
| 1731 | git commit --quiet -m "c30: the first version" |
| 1732 | attest_change c30 "" "" --check prose-format |
| 1733 | ready_change c30 |
| 1734 | id30="$readied" v1="$(git rev-parse c30)" |
| 1735 | request "c-$id30" main "$v1" |
| 1736 | integrate |
| 1737 | grep -q "^c-$id30 -> refs/heads/main .*: land$" "$work/last.out" || die "version 1 of c-$id30 did not land" |
| 1738 | landed_as "$v1" "$pre" |
| 1739 | land30v1="$(tip)" |
| 1740 | git fetch --quiet origin |
| 1741 | git checkout --quiet -B c30-again origin/main |
| 1742 | echo "the second version" > docs/c30-again.md |
| 1743 | git add -A |
| 1744 | git commit --quiet -m "c30: the second version" |
| 1745 | attest_change c30-again "" "" --check prose-format |
| 1746 | valley ready --change "$id30" c30-again > /dev/null 2>&1 || die "valley ready --change $id30 c30-again failed" |
| 1747 | v2="$(git rev-parse c30-again)" |
| 1748 | request "c-$id30" main "$v2" |
| 1749 | integrate |
| 1750 | grep -q "^c-$id30 -> refs/heads/main .*: land$" "$work/last.out" || die "version 2 of c-$id30 did not land" |
| 1751 | landed_as "$v2" "$pre" |
| 1752 | land30v2="$(tip)" |
| 1753 | [ "$(git -C "$origin" cat-file blob "refs/the-valley/integration-outcomes/main/c-$id30" | cut -d' ' -f1)" = "$v2" ] \ |
| 1754 | || die "the outcome record under c-$id30 does not name version 2; the scenario proves nothing" |
| 1755 | valley changes --json > "$work/changes30.json" |
| 1756 | jq -e --arg id "$id30" --arg l1 "$land30v1" --arg l2 "$land30v2" ' |
| 1757 | [.repos[].changes[] | select(.change_id == $id) | .versions[] | [.landing, .landed_commit]] |
| 1758 | == [["landed-recorded", $l1], ["landed-recorded", $l2]]' "$work/changes30.json" > /dev/null \ |
| 1759 | || die "both versions do not read landed-recorded as their own landings: $(jq -c --arg id "$id30" '.repos[].changes[] | select(.change_id == $id) | .versions' "$work/changes30.json")" |
| 1760 | holds "version 2 replaced the outcome record, and version 1's landing record kept it landed-recorded" |
| 1761 | |
| 1762 | # ---------------------------------------------------------------------- |
| 1763 | say "31. a branch below a landed change is no layer, and the change above it is measured from the landing" |
| 1764 | |
| 1765 | # main -> p -> a -> b, with p a plain branch, and a and b changes. a lands |
| 1766 | # as one new commit, so main reaches neither a's commits nor p, though |
| 1767 | # both are on main in content. p is listed nowhere and is no layer of b's |
| 1768 | # stack, and b counts its own commit alone. |
| 1769 | git fetch --quiet origin |
| 1770 | git checkout --quiet -B c31-p origin/main |
| 1771 | echo "the plain branch" > docs/c31-p.md |
| 1772 | git add -A |
| 1773 | git commit --quiet -m "c31: a plain branch" |
| 1774 | git push --quiet origin c31-p |
| 1775 | git checkout --quiet -B c31-a |
| 1776 | echo "change a" > docs/c31-a.md |
| 1777 | git add -A |
| 1778 | git commit --quiet -m "c31: change a" |
| 1779 | attest_change c31-a "" "" --check prose-format |
| 1780 | ready_change c31-a |
| 1781 | id31a="$readied" |
| 1782 | git checkout --quiet -B c31-b |
| 1783 | echo "change b" > docs/c31-b.md |
| 1784 | git add -A |
| 1785 | git commit --quiet -m "c31: change b" |
| 1786 | git push --quiet origin c31-b |
| 1787 | ready_change c31-b |
| 1788 | id31b="$readied" |
| 1789 | p31="$(git rev-parse c31-p)" a31="$(git rev-parse c31-a)" b31="$(git rev-parse c31-b)" |
| 1790 | request "c-$id31a" main "$a31" |
| 1791 | integrate |
| 1792 | grep -q "^c-$id31a -> refs/heads/main .*: land$" "$work/last.out" || die "c-$id31a did not land" |
| 1793 | landed_as "$a31" "$pre" |
| 1794 | main31="$(tip)" |
| 1795 | git -C "$origin" merge-base --is-ancestor "$p31" "$main31" && die "main reaches the plain branch; the scenario proves nothing" |
| 1796 | |
| 1797 | valley changes --json > "$work/changes31.json" |
| 1798 | jq -e --arg p "$p31" '[.repos[].branches[] | select(.head == $p)] == []' "$work/changes31.json" > /dev/null \ |
| 1799 | || die "valley changes lists the plain branch below the landed change" |
| 1800 | valley pending --json > "$work/pending31.json" |
| 1801 | jq -e --arg p "$p31" '[.repos[].branches[] | select(.head == $p)] == []' "$work/pending31.json" > /dev/null \ |
| 1802 | || die "valley pending --json lists the plain branch below the landed change" |
| 1803 | h31b="$(jq -r --arg id "$id31b" '.repos[].changes[] | select(.change_id == $id) | .handle' "$work/pending31.json")" |
| 1804 | [ -n "$h31b" ] || die "valley pending does not list c-$id31b" |
| 1805 | valley pending > "$work/pending31.out" |
| 1806 | grep -q "c31-p" "$work/pending31.out" && die "valley pending lists the plain branch below the landed change: $(cat "$work/pending31.out")" |
| 1807 | grep -A2 "^$h31b v1\( \|$\)" "$work/pending31.out" | tail -n1 | grep -qx ' 1 commit · 1 file +1 −0' \ |
| 1808 | || die "valley pending does not measure b from a's landing: $(grep -A3 "^$h31b v1" "$work/pending31.out")" |
| 1809 | holds "valley changes and valley pending leave out the plain branch, and pending counts b's own commit alone" |
| 1810 | |
| 1811 | valley rebase "$id31b" > "$work/rebase31.out" 2>&1 || die "the rebase of b failed: $(cat "$work/rebase31.out")" |
| 1812 | git fetch --quiet origin |
| 1813 | nb31="$(git rev-parse origin/c31-b)" |
| 1814 | [ "$(git rev-parse "$nb31^")" = "$main31" ] || die "b was not rebased as one commit onto main" |
| 1815 | [ "$(git diff "$a31" "$b31")" = "$(git diff "$main31" "$nb31")" ] || die "b's diff changed in the rebase" |
| 1816 | [ "$(git rev-parse origin/c31-p)" = "$p31" ] || die "the rebase moved the plain branch below the landed change" |
| 1817 | holds "b rebased alone onto main: the plain branch and a's commits dropped out from under it" |
| 1818 | unset VALLEY_KNOWN_SIGNERS VALLEY_INTEGRATOR_SIGNER |
| 1819 | |
| 1820 | printf '\nintegrator-e2e: every scenario held\n' |