| 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 |
| 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. |
| 79 | cat > policy/project.cue <<'EOF' |
| 80 | package verification |
| 81 | |
| 82 | project: { |
| 83 | checks: { |
| 84 | "prose-format": {runner: "nix", attribute: "prose-format"} |
| 85 | "code-build": {runner: "nix", attribute: "code-build"} |
| 86 | // An effectful check, with the validity window dcr-439b771 calls |
| 87 | // Δ. Its observation transfers while nothing in the class that |
| 88 | // requires it has landed under it and it is younger than this. |
| 89 | reachable: {runner: "command", command: "true", validity: "1h"} |
| 90 | } |
| 91 | classes: { |
| 92 | prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 93 | code: {paths: "src/**": true, requires: "code-build": true} |
| 94 | deploy: {paths: "deploy/**": true, requires: reachable: true} |
| 95 | } |
| 96 | unclassified: {} |
| 97 | } |
| 98 | EOF |
| 99 | |
| 100 | git add -A |
| 101 | git commit --quiet -m "seed the project" |
| 102 | git push --quiet origin main |
| 103 | |
| 104 | # The instance layer lives outside the project's tree, and the integrator |
| 105 | # reads it from there: a change never supplies the policy that gates it. |
| 106 | instance="$work/instance" |
| 107 | mkdir -p "$instance" |
| 108 | cat > "$instance/floor.cue" <<'EOF' |
| 109 | package verification |
| 110 | |
| 111 | floor: { |
| 112 | checks: {} |
| 113 | classes: {} |
| 114 | unclassified: {} |
| 115 | } |
| 116 | EOF |
| 117 | holds "policy composes from $instance and the project's own policy/" |
| 118 | |
| 119 | # ---------------------------------------------------------------------- |
| 120 | # Helpers. |
| 121 | |
| 122 | # attest_change <branch> <check spec…> — run the checks over the branch's |
| 123 | # tip and publish the branch with its attestation ref, atomically. |
| 124 | attest_change() { |
| 125 | local branch="$1" key="${2:-$work/contributor}" name="${3:-$contributor}" |
| 126 | shift 3 |
| 127 | attest run --repo "$repo" --key "$key" --name "$name" \ |
| 128 | --push origin --branch "$branch" "$@" |
| 129 | } |
| 130 | |
| 131 | # request <change> <target> <commit> — the contributor asks for integration |
| 132 | # by pushing one ref. That ref is the whole of the request. |
| 133 | request() { |
| 134 | git push --quiet origin "$3:refs/the-valley/integration-requests/$2/$1" |
| 135 | } |
| 136 | |
| 137 | integrate() { |
| 138 | integrator reconcile \ |
| 139 | --repo "$origin" \ |
| 140 | --key "$work/integrator" --name "$integrator_name" \ |
| 141 | --known-signers "$work/known_signers" \ |
| 142 | --instance "$instance" --project-policy policy \ |
| 143 | --schema "$SCHEMA_VERIFICATION" \ |
| 144 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 145 | --event-schema "$SCHEMA_EVENTS" \ |
| 146 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 147 | 2>&1 | tee "$work/last.out" |
| 148 | grep -q . "$work/last.out" || die "the integrator said nothing" |
| 149 | } |
| 150 | |
| 151 | tip() { git -C "$origin" rev-parse refs/heads/main; } |
| 152 | forget() { git -C "$origin" update-ref -d "refs/the-valley/integration-requests/main/$1"; } |
| 153 | |
| 154 | # ---------------------------------------------------------------------- |
| 155 | say "1. a change with valid transferring evidence lands" |
| 156 | |
| 157 | before="$(tip)" |
| 158 | git checkout --quiet -b c1 |
| 159 | echo "a better readme" > docs/readme.md |
| 160 | echo "a new target" > deploy/second.txt |
| 161 | git add -A |
| 162 | git commit --quiet -m "improve the readme and add a target" |
| 163 | attest_change c1 "" "" --check prose-format --command reachable=true |
| 164 | request c1 main "$(git rev-parse c1)" |
| 165 | integrate |
| 166 | |
| 167 | grep -q "^c1 -> refs/heads/main .*: land$" "$work/last.out" || die "c1 did not land" |
| 168 | grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer" |
| 169 | grep -q "check reachable .*transferred (untouched)" "$work/last.out" || die "the effectful check did not transfer" |
| 170 | grep -q '"event":"integration-succeeded"' "$work/last.out" || die "no integration-succeeded event" |
| 171 | [ "$(tip)" != "$before" ] || die "the protected ref did not move" |
| 172 | [ "$(tip)" = "$(git rev-parse c1)" ] || die "main is not at the change's head" |
| 173 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c1 > /dev/null \ |
| 174 | && die "the request ref outlived the landing" |
| 175 | holds "main moved $(git rev-parse --short "$before") -> $(git -C "$origin" rev-parse --short refs/heads/main)" |
| 176 | |
| 177 | # The landed note carries both signatures, under one text, and verifies. |
| 178 | # The integrator writes under its own key hash, so its ref never races the |
| 179 | # contributor's over the same subject. |
| 180 | landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c1 | cut -d: -f2)/$ihash" |
| 181 | git -C "$origin" rev-parse --verify --quiet "$landed" > /dev/null \ |
| 182 | || die "no attestation ref by the integrator for the landed tree" |
| 183 | git -C "$origin" cat-file blob "$landed:prose-format/statement.note" > "$work/landed.note" |
| 184 | siblings="$(grep -c '^— ' "$work/landed.note")" |
| 185 | [ "$siblings" -eq 2 ] || die "the landed note carries $siblings signatures, not two" |
| 186 | attest verify --note "$work/landed.note" --known-keys "$work/reader_keys" \ |
| 187 | --schema "$SCHEMA_ATTESTATION" --repo "$repo" --rev c1 \ |
| 188 | --signer "$contributor" --signer "$integrator_name" > "$work/landed.verify" |
| 189 | grep -q 'matches the recorded subject digest' "$work/landed.verify" || die "the landed note does not bind to the tree" |
| 190 | holds "the landed note carries contributor and integrator sibling signatures and verifies" |
| 191 | |
| 192 | # And the integrator's own transfer statement sits beside it. |
| 193 | git -C "$origin" cat-file blob "$landed:transfer.note" > "$work/transfer.note" |
| 194 | head -n1 "$work/transfer.note" | grep -qx 'the-valley/attestation/v1' || die "the transfer note is not a statement" |
| 195 | grep -qx 'predicateType the-valley/integration/transfer/v1' "$work/transfer.note" || die "wrong predicate type" |
| 196 | grep -qx 'predicate.change c1' "$work/transfer.note" || die "the transfer statement names no change" |
| 197 | grep -q '^predicate.policy.sha256 ' "$work/transfer.note" || die "the transfer statement names no policy" |
| 198 | attest verify --note "$work/transfer.note" --known-keys "$work/reader_keys" \ |
| 199 | --schema "$SCHEMA_ATTESTATION" --signer "$integrator_name" > /dev/null |
| 200 | holds "the transfer statement records the verdict and the policy it was derived under" |
| 201 | |
| 202 | # ---------------------------------------------------------------------- |
| 203 | say "2. an intervening landing invalidates one check's closure" |
| 204 | |
| 205 | git checkout --quiet main |
| 206 | git pull --quiet --ff-only origin main |
| 207 | |
| 208 | # c2 is authored against the current tip and reads both classes. |
| 209 | git checkout --quiet -b c2 |
| 210 | echo "a readme with more in it" > docs/readme.md |
| 211 | echo "the source, revised" > src/main.txt |
| 212 | git add -A |
| 213 | git commit --quiet -m "revise the readme and the source" |
| 214 | attest_change c2 "" "" --check prose-format --check code-build |
| 215 | c2="$(git rev-parse c2)" |
| 216 | |
| 217 | # Meanwhile another change lands, touching only what code-build reads. |
| 218 | git checkout --quiet main |
| 219 | git checkout --quiet -b intervening |
| 220 | echo "a second source file" > src/other.txt |
| 221 | git add -A |
| 222 | git commit --quiet -m "add a second source file" |
| 223 | attest_change intervening "" "" --check code-build |
| 224 | request intervening main "$(git rev-parse intervening)" |
| 225 | integrate |
| 226 | grep -q "^intervening -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 227 | holds "the intervening change landed first; c2's base has moved" |
| 228 | |
| 229 | request c2 main "$c2" |
| 230 | integrate |
| 231 | grep -q "^c2 -> refs/heads/main .*: stale$" "$work/last.out" || die "c2 was not stale" |
| 232 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 233 | || die "prose-format should have transferred by closure equality" |
| 234 | grep -q "check code-build .*input closure changed" "$work/last.out" \ |
| 235 | || die "code-build's closure should have moved" |
| 236 | grep -q '"event":"request-stale"' "$work/last.out" || die "no request-stale event" |
| 237 | grep -q '"checks":\["code-build"\]' "$work/last.out" || die "the event does not name exactly code-build" |
| 238 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c2 > /dev/null \ |
| 239 | || die "the request ref was dropped; there is nothing to resubmit" |
| 240 | holds "one request-stale naming exactly code-build; prose-format reported transferred" |
| 241 | forget c2 |
| 242 | |
| 243 | # ---------------------------------------------------------------------- |
| 244 | say "2b. evidence that survives the rebase lands on the moved tip" |
| 245 | |
| 246 | # The same shape as 2, with the intervening landing outside what the |
| 247 | # change's checks read. The tree that lands is not the tree that was |
| 248 | # attested, and the evidence stands anyway — which is the whole of what |
| 249 | # content-addressed evidence buys. |
| 250 | git checkout --quiet main |
| 251 | git pull --quiet --ff-only origin main |
| 252 | git checkout --quiet -b c2b |
| 253 | echo "a readme revised again" > docs/readme.md |
| 254 | git add -A |
| 255 | git commit --quiet -m "revise the readme once more" |
| 256 | attest_change c2b "" "" --check prose-format |
| 257 | c2b="$(git rev-parse c2b)" |
| 258 | attested="$(attest digest --repo "$repo" --rev c2b | cut -d: -f2)" |
| 259 | |
| 260 | git checkout --quiet main |
| 261 | git checkout --quiet -b elsewhere |
| 262 | echo "a third source file" > src/third.txt |
| 263 | git add -A |
| 264 | git commit --quiet -m "add a third source file" |
| 265 | attest_change elsewhere "" "" --check code-build |
| 266 | request elsewhere main "$(git rev-parse elsewhere)" |
| 267 | integrate |
| 268 | grep -q "^elsewhere -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 269 | |
| 270 | request c2b main "$c2b" |
| 271 | integrate |
| 272 | grep -q "^c2b -> refs/heads/main .*: land$" "$work/last.out" || die "c2b did not land" |
| 273 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 274 | || die "the evidence did not transfer by closure equality" |
| 275 | landedtree="$(git -C "$origin" rev-parse refs/heads/main^{tree})" |
| 276 | [ "$(git -C "$origin" rev-parse "refs/heads/main^")" = "$(git rev-parse elsewhere)" ] \ |
| 277 | || die "the landing is not a fast-forward from the tip it was judged against" |
| 278 | [ "$(git -C "$origin" rev-parse refs/heads/main^{tree})" != "$(git rev-parse "$c2b^{tree}")" ] \ |
| 279 | || die "the tree did not actually move; the scenario proves nothing" |
| 280 | holds "the delta landed on a tree it was never attested over, and no check re-ran" |
| 281 | |
| 282 | # Two attestation refs now, because the two statements are about two |
| 283 | # different trees: the contributor's is keyed by the tree it was made over, |
| 284 | # and the integrator's transfer statement by the tree that landed. |
| 285 | git fetch --quiet origin main |
| 286 | landed_digest="$(attest digest --repo "$repo" --rev "$(git -C "$origin" rev-parse refs/heads/main)" | cut -d: -f2)" |
| 287 | [ "$landed_digest" != "$attested" ] || die "the landed tree is the attested tree; the scenario proves nothing" |
| 288 | git -C "$origin" cat-file blob \ |
| 289 | "refs/the-valley/attestations/$attested/$ihash:prose-format/statement.note" > "$work/rebased.note" |
| 290 | [ "$(grep -c '^— ' "$work/rebased.note")" -eq 2 ] \ |
| 291 | || die "the countersigned note lost a sibling signature" |
| 292 | grep -qx "subject.digest.valley-tree-v1 $attested" "$work/rebased.note" \ |
| 293 | || die "the countersigned statement is not about the tree it was made over" |
| 294 | git -C "$origin" cat-file blob \ |
| 295 | "refs/the-valley/attestations/$landed_digest/$ihash:transfer.note" > "$work/rebased.transfer" |
| 296 | grep -qx "subject.digest.valley-tree-v1 $landed_digest" "$work/rebased.transfer" \ |
| 297 | || die "the transfer statement is not about the landed tree" |
| 298 | grep -qx "predicate.base.valley-tree-v1 $attested" "$work/rebased.transfer" \ |
| 299 | || die "the transfer statement does not cite the base the evidence was produced over" |
| 300 | grep -qx "predicate.checks.0.rule closure" "$work/rebased.transfer" \ |
| 301 | || die "the transfer statement does not record the rule that carried the evidence" |
| 302 | holds "the contributor's statement stays about its own tree; the transfer statement names the landed one" |
| 303 | |
| 304 | # ---------------------------------------------------------------------- |
| 305 | say "3. a conflicting delta is stale, and demands full re-attestation" |
| 306 | |
| 307 | git checkout --quiet main |
| 308 | git pull --quiet --ff-only origin main |
| 309 | git checkout --quiet -b c3 |
| 310 | echo "the readme, as c3 would have it" > docs/readme.md |
| 311 | git add -A |
| 312 | git commit --quiet -m "rewrite the readme one way" |
| 313 | attest_change c3 "" "" --check prose-format |
| 314 | c3="$(git rev-parse c3)" |
| 315 | |
| 316 | git checkout --quiet main |
| 317 | git checkout --quiet -b conflicting |
| 318 | echo "the readme, as the other change would have it" > docs/readme.md |
| 319 | git add -A |
| 320 | git commit --quiet -m "rewrite the readme another way" |
| 321 | attest_change conflicting "" "" --check prose-format |
| 322 | request conflicting main "$(git rev-parse conflicting)" |
| 323 | integrate |
| 324 | grep -q "^conflicting -> refs/heads/main .*: land$" "$work/last.out" || die "the conflicting change did not land" |
| 325 | |
| 326 | request c3 main "$c3" |
| 327 | integrate |
| 328 | grep -q "^c3 -> refs/heads/main .*: stale$" "$work/last.out" || die "c3 was not stale" |
| 329 | grep -q 'resolving it is new authorship' "$work/last.out" || die "the conflict was not reported as new authorship" |
| 330 | grep -q 'CONFLICT (content): Merge conflict in docs/readme.md' "$work/last.out" \ |
| 331 | || die "the conflict does not name what could not be merged" |
| 332 | grep -q '"reason":"conflict"' "$work/last.out" || die "the event does not say conflict" |
| 333 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "a conflict must re-demand every required check" |
| 334 | holds "a conflict is stale, and every required check is re-demanded" |
| 335 | forget c3 |
| 336 | |
| 337 | # ---------------------------------------------------------------------- |
| 338 | say "4. an unknown signer's attestation does not transfer" |
| 339 | |
| 340 | git checkout --quiet main |
| 341 | git pull --quiet --ff-only origin main |
| 342 | git checkout --quiet -b c4 |
| 343 | echo "a readme signed by a stranger" > docs/readme.md |
| 344 | git add -A |
| 345 | git commit --quiet -m "a change a stranger attested" |
| 346 | attest_change c4 "$work/stranger" "$stranger" --check prose-format |
| 347 | request c4 main "$(git rev-parse c4)" |
| 348 | integrate |
| 349 | grep -q "^c4 -> refs/heads/main .*: stale$" "$work/last.out" || die "c4 was not stale" |
| 350 | grep -q 'no signer the integrator holds' "$work/last.out" || die "the unknown signer was not reported" |
| 351 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "the event does not name prose-format" |
| 352 | [ "$(tip)" = "$(git -C "$origin" rev-parse refs/heads/main)" ] || die "main moved" |
| 353 | holds "evidence from a signer the integrator does not hold does not transfer" |
| 354 | forget c4 |
| 355 | |
| 356 | # ---------------------------------------------------------------------- |
| 357 | say "5. a tampered statement is rejected, not called stale" |
| 358 | |
| 359 | git checkout --quiet main |
| 360 | git checkout --quiet -b c5 |
| 361 | echo "an honest readme" > docs/readme.md |
| 362 | git add -A |
| 363 | git commit --quiet -m "an honest change" |
| 364 | attest_change c5 "" "" --check prose-format |
| 365 | c5="$(git rev-parse c5)" |
| 366 | c5digest="$(attest digest --repo "$repo" --rev c5 | cut -d: -f2)" |
| 367 | |
| 368 | # Edit one value in the signed text and store the result where the real |
| 369 | # note was. Everything else about the note is untouched. |
| 370 | c5ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 371 | "refs/the-valley/attestations/$c5digest" | head -n1)" |
| 372 | git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note" \ |
| 373 | | sed 's/^predicate.result passed$/predicate.result failed/' > "$work/tampered.note" |
| 374 | cmp -s "$work/tampered.note" <(git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note") \ |
| 375 | && die "the tamper changed nothing; the test proves nothing" |
| 376 | blob="$(git -C "$origin" hash-object -w --stdin < "$work/tampered.note")" |
| 377 | sub="$(printf '100644 blob %s\tstatement.note\n' "$blob" | git -C "$origin" mktree)" |
| 378 | top="$(printf '040000 tree %s\tprose-format\n' "$sub" | git -C "$origin" mktree)" |
| 379 | git -C "$origin" update-ref "$c5ref" "$top" |
| 380 | |
| 381 | request c5 main "$c5" |
| 382 | integrate |
| 383 | grep -q "^c5 -> refs/heads/main .*: reject$" "$work/last.out" || die "a tampered statement was not rejected" |
| 384 | grep -q 'does not verify as the statement it claims to be' "$work/last.out" || die "the refusal was not reported" |
| 385 | grep -q 'request-stale' "$work/last.out" && die "a forgery was announced as staleness" |
| 386 | holds "a tampered statement is a rejection, and no outcome event claims otherwise" |
| 387 | forget c5 |
| 388 | |
| 389 | # ---------------------------------------------------------------------- |
| 390 | say "6. an attestation about a different tree is rejected" |
| 391 | |
| 392 | git checkout --quiet main |
| 393 | git checkout --quiet -b c6 |
| 394 | echo "the tree that was actually attested" > docs/readme.md |
| 395 | git add -A |
| 396 | git commit --quiet -m "the attested change" |
| 397 | attest_change c6 "" "" --check prose-format |
| 398 | c6ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 399 | "refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c6 | cut -d: -f2)" | head -n1)" |
| 400 | |
| 401 | # A second, different tree — with no attestation of its own — and the |
| 402 | # first tree's valid, correctly signed note filed under its digest. |
| 403 | git checkout --quiet -b c6-lifted |
| 404 | echo "the tree that was not" > docs/readme.md |
| 405 | git add -A |
| 406 | git commit --quiet -m "the change the evidence was lifted onto" |
| 407 | git push --quiet origin c6-lifted |
| 408 | lifted="$(attest digest --repo "$repo" --rev c6-lifted | cut -d: -f2)" |
| 409 | git -C "$origin" update-ref \ |
| 410 | "refs/the-valley/attestations/$lifted/${c6ref##*/}" \ |
| 411 | "$(git -C "$origin" rev-parse "$c6ref^{tree}")" |
| 412 | |
| 413 | request c6 main "$(git rev-parse c6-lifted)" |
| 414 | integrate |
| 415 | grep -q "^c6 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lifted attestation was not rejected" |
| 416 | grep -q 'tree digest mismatch' "$work/last.out" || die "the refusal does not name the tree digest" |
| 417 | holds "a signature cannot be lifted onto a tree it was not made about" |
| 418 | forget c6 |
| 419 | |
| 420 | # ---------------------------------------------------------------------- |
| 421 | say "7. an attestation lying about its kind is rejected" |
| 422 | |
| 423 | # The policy runs prose-format with nix, so its evidence is content- |
| 424 | # addressed. This attestation claims a notarization instead, and its class |
| 425 | # was untouched by the intervening landing — so under the rule it nominated |
| 426 | # for itself it would sail onto a base it was never produced over. |
| 427 | git checkout --quiet main |
| 428 | git pull --quiet --ff-only origin main |
| 429 | git checkout --quiet -b c7 |
| 430 | echo "a readme attested as a notarization" > docs/readme.md |
| 431 | git add -A |
| 432 | git commit --quiet -m "a change whose attestation lies about its kind" |
| 433 | attest_change c7 "" "" --command prose-format=true |
| 434 | c7="$(git rev-parse c7)" |
| 435 | |
| 436 | git checkout --quiet main |
| 437 | git checkout --quiet -b under-c7 |
| 438 | echo "a fourth source file" > src/fourth.txt |
| 439 | git add -A |
| 440 | git commit --quiet -m "add a fourth source file" |
| 441 | attest_change under-c7 "" "" --check code-build |
| 442 | request under-c7 main "$(git rev-parse under-c7)" |
| 443 | integrate |
| 444 | grep -q "^under-c7 -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 445 | |
| 446 | request c7 main "$c7" |
| 447 | integrate |
| 448 | grep -q "^c7 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lie about the kind was not rejected" |
| 449 | grep -q 'requires a pure check and the attestation claims an effectful check' "$work/last.out" \ |
| 450 | || die "the refusal does not say the policy decides the rule" |
| 451 | holds "the transfer rule follows the policy's runner, never the attestation's own claim" |
| 452 | forget c7 |
| 453 | |
| 454 | # ---------------------------------------------------------------------- |
| 455 | say "8. evidence pushed after a no-evidence verdict re-judges and lands" |
| 456 | |
| 457 | git checkout --quiet main |
| 458 | git pull --quiet --ff-only origin main |
| 459 | git checkout --quiet -b c8 |
| 460 | echo "a readme with no evidence yet" > docs/readme.md |
| 461 | git add -A |
| 462 | git commit --quiet -m "a change submitted before its checks ran" |
| 463 | git push --quiet origin c8 |
| 464 | request c8 main "$(git rev-parse c8)" |
| 465 | integrate |
| 466 | grep -q "^c8 -> refs/heads/main .*: stale$" "$work/last.out" || die "a change with no evidence was not stale" |
| 467 | grep -q 'no attestation for this check accompanies the change' "$work/last.out" \ |
| 468 | || die "the absent attestation was not reported" |
| 469 | |
| 470 | # Nothing about the request or the tip moves; only the evidence arrives. |
| 471 | attest_change c8 "" "" --check prose-format |
| 472 | integrate |
| 473 | grep -q "^c8 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 474 | || die "the request was not re-judged after its evidence arrived" |
| 475 | [ "$(tip)" = "$(git rev-parse c8)" ] || die "main is not at the change's head" |
| 476 | holds "a pass re-judges when evidence arrives, with the request and the tip unmoved" |
| 477 | |
| 478 | # ---------------------------------------------------------------------- |
| 479 | say "9. a ref that is not a request does not hold up one that is" |
| 480 | |
| 481 | git checkout --quiet main |
| 482 | git pull --quiet --ff-only origin main |
| 483 | git checkout --quiet -b c9 |
| 484 | echo "a readme beside a garbage ref" > docs/readme.md |
| 485 | git add -A |
| 486 | git commit --quiet -m "a change beside a malformed request" |
| 487 | attest_change c9 "" "" --check prose-format |
| 488 | # A name with no target segment at all, and one with a segment too many. |
| 489 | # Anyone with push access can write this namespace. |
| 490 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/garbage" |
| 491 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/main/too/deep" |
| 492 | request c9 main "$(git rev-parse c9)" |
| 493 | integrate |
| 494 | grep -q 'refs/the-valley/integration-requests/garbage: not a request ref' "$work/last.out" \ |
| 495 | || die "the malformed ref was not reported" |
| 496 | grep -q 'refs/the-valley/integration-requests/main/too/deep: not a request ref' "$work/last.out" \ |
| 497 | || die "the over-deep ref was not reported" |
| 498 | grep -q "^c9 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 499 | || die "a malformed ref stopped the pass reaching a valid request" |
| 500 | holds "malformed refs are reported and skipped; the valid request beside them landed" |
| 501 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/garbage |
| 502 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/too/deep |
| 503 | |
| 504 | # ---------------------------------------------------------------------- |
| 505 | say "10. a pass leaves no scratch behind, and a leaked worktree is swept" |
| 506 | |
| 507 | # Nine scenarios of real passes, landings and rejections alike, and the |
| 508 | # scratch root is empty: every worktree a pass takes is given back on the |
| 509 | # way out, on the failure path as much as the success one. |
| 510 | leftover="$(find "$TMPDIR" -maxdepth 1 -name 'valley-integrator-wt*')" |
| 511 | [ -z "$leftover" ] || die "nine passes left scratch behind: $leftover" |
| 512 | [ "$(git -C "$origin" worktree list --porcelain | grep -c '^worktree ')" -eq 1 ] \ |
| 513 | || die "nine passes left a worktree attached to the repository" |
| 514 | holds "no pass left a worktree or a scratch directory behind" |
| 515 | |
| 516 | # What a crash leaves: the checkout and its administrative entry, both |
| 517 | # still valid, so nothing prunes them. Beside it, a worktree of the kind |
| 518 | # an operator might attach by hand, which is not the integrator's to |
| 519 | # remove. |
| 520 | leak="$TMPDIR/valley-integrator-wt-crashed" |
| 521 | mine="$work/an-operators-own-worktree" |
| 522 | git -C "$origin" worktree add --quiet --detach "$leak" refs/heads/main |
| 523 | git -C "$origin" worktree add --quiet --detach "$mine" refs/heads/main |
| 524 | timeout 5 integrator watch --interval 1s \ |
| 525 | --repo "$origin" \ |
| 526 | --key "$work/integrator" --name "$integrator_name" \ |
| 527 | --known-signers "$work/known_signers" \ |
| 528 | --instance "$instance" --project-policy policy \ |
| 529 | --schema "$SCHEMA_VERIFICATION" \ |
| 530 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 531 | --event-schema "$SCHEMA_EVENTS" \ |
| 532 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 533 | > "$work/watch.out" 2>&1 || true |
| 534 | [ ! -e "$leak" ] || die "a leaked scratch worktree survived the sweep" |
| 535 | if git -C "$origin" worktree list --porcelain | grep -q "^worktree $leak$"; then |
| 536 | die "the leaked worktree is gone from disk and still registered" |
| 537 | fi |
| 538 | [ -e "$mine" ] || die "the sweep removed a worktree the integrator did not make" |
| 539 | git -C "$origin" worktree remove --force "$mine" |
| 540 | holds "a crash-leaked scratch worktree is swept at watch start; another hand's is not" |
| 541 | |
| 542 | # ---------------------------------------------------------------------- |
| 543 | say "11. a scratch root it may not write is reported as that, and nothing else" |
| 544 | |
| 545 | # The deployment failure this guards is a sandbox failure: the root TMPDIR |
| 546 | # names is not writable. That is a statement about the unit, not about the |
| 547 | # change being judged, and it has to arrive as one — with the path and where |
| 548 | # the path came from — rather than as git complaining about the leading |
| 549 | # directories of a .git file. |
| 550 | refused="$work/refused" |
| 551 | mkdir -p "$refused" |
| 552 | chmod a-w "$refused" |
| 553 | git checkout --quiet main |
| 554 | git pull --quiet --ff-only origin main |
| 555 | git checkout --quiet -b c10 |
| 556 | echo "a change that never gets a worktree" > docs/readme.md |
| 557 | git add -A |
| 558 | git commit --quiet -m "a change the integrator cannot make scratch for" |
| 559 | attest_change c10 "" "" --check prose-format |
| 560 | request c10 main "$(git rev-parse c10)" |
| 561 | export TMPDIR="$refused" |
| 562 | integrate || true |
| 563 | export TMPDIR="$work/tmp" |
| 564 | chmod u+w "$refused" |
| 565 | grep -q "scratch directory under $refused, which TMPDIR names" "$work/last.out" \ |
| 566 | || die "an unwritable scratch root was not reported as one: $(cat "$work/last.out")" |
| 567 | forget c10 |
| 568 | holds "an unwritable scratch root names the path and where it came from" |
| 569 | |
| 570 | printf '\nintegrator-e2e: every scenario held\n' |