| 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 | export VALLEY_FAKE_STORE="$work/store" |
| 20 | export PATH="$here:$PATH" # the nix stand-ins, ahead of anything real |
| 21 | |
| 22 | git config --global user.name valley-check |
| 23 | git config --global user.email valley-check@localhost |
| 24 | git config --global init.defaultBranch main |
| 25 | git config --global advice.detachedHead false |
| 26 | |
| 27 | say() { printf '\n=== %s\n' "$*"; } |
| 28 | die() { |
| 29 | printf '\nintegrator-e2e: %s\n' "$*" >&2 |
| 30 | exit 1 |
| 31 | } |
| 32 | holds() { printf ' ok: %s\n' "$*"; } |
| 33 | |
| 34 | # ---------------------------------------------------------------------- |
| 35 | say "keys: a contributor, an integrator, and a stranger" |
| 36 | |
| 37 | for who in contributor integrator stranger; do |
| 38 | ssh-keygen -q -t ed25519 -N "" -C "$who" -f "$work/$who" |
| 39 | done |
| 40 | contributor=contributor.valley.invalid/attestations |
| 41 | integrator_name=integrator.valley.invalid/attestations |
| 42 | stranger=stranger.elsewhere.invalid/attestations |
| 43 | |
| 44 | # The known-signers file is the registry's interim compilation |
| 45 | # (dcr-b87f6e8): the integrator accepts the contributor and nobody else. |
| 46 | attest key --key "$work/contributor" --name "$contributor" > "$work/known_signers" |
| 47 | # What a reader of a landed note holds: both parties to it. |
| 48 | cat "$work/known_signers" > "$work/reader_keys" |
| 49 | attest key --key "$work/integrator" --name "$integrator_name" >> "$work/reader_keys" |
| 50 | attest key --key "$work/stranger" --name "$stranger" > "$work/stranger_key" |
| 51 | # The key hash the integrator's own attestation refs are keyed by. |
| 52 | ihash="$(attest key --key "$work/integrator" --name "$integrator_name" | cut -d+ -f2)" |
| 53 | holds "the integrator holds one signer: $(cut -d+ -f1 < "$work/known_signers")" |
| 54 | |
| 55 | # ---------------------------------------------------------------------- |
| 56 | say "the served repository, and the instance policy layer" |
| 57 | |
| 58 | origin="$work/project.git" |
| 59 | git init --quiet --bare "$origin" |
| 60 | repo="$work/project" |
| 61 | git init --quiet "$repo" |
| 62 | cd "$repo" |
| 63 | git remote add origin "$origin" |
| 64 | |
| 65 | mkdir -p docs src deploy checks policy |
| 66 | echo "the readme" > docs/readme.md |
| 67 | echo "the source" > src/main.txt |
| 68 | echo "the deployment" > deploy/target.txt |
| 69 | # What each check reads, which the nix stand-in turns into its closure. |
| 70 | echo docs > checks/prose-format.inputs |
| 71 | echo src > checks/code-build.inputs |
| 72 | |
| 73 | # The project layer: it declares its own classes and checks above the |
| 74 | # floor, and declines nothing. |
| 75 | cat > policy/project.cue <<'EOF' |
| 76 | package verification |
| 77 | |
| 78 | project: { |
| 79 | checks: { |
| 80 | "prose-format": {runner: "nix", attribute: "prose-format"} |
| 81 | "code-build": {runner: "nix", attribute: "code-build"} |
| 82 | // An effectful check, with the validity window dcr-439b771 calls |
| 83 | // Δ. Its observation transfers while nothing in the class that |
| 84 | // requires it has landed under it and it is younger than this. |
| 85 | reachable: {runner: "command", command: "true", validity: "1h"} |
| 86 | } |
| 87 | classes: { |
| 88 | prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 89 | code: {paths: "src/**": true, requires: "code-build": true} |
| 90 | deploy: {paths: "deploy/**": true, requires: reachable: true} |
| 91 | } |
| 92 | unclassified: {} |
| 93 | } |
| 94 | EOF |
| 95 | |
| 96 | git add -A |
| 97 | git commit --quiet -m "seed the project" |
| 98 | git push --quiet origin main |
| 99 | |
| 100 | # The instance layer lives outside the project's tree, and the integrator |
| 101 | # reads it from there: a change never supplies the policy that gates it. |
| 102 | instance="$work/instance" |
| 103 | mkdir -p "$instance" |
| 104 | cat > "$instance/floor.cue" <<'EOF' |
| 105 | package verification |
| 106 | |
| 107 | floor: { |
| 108 | checks: {} |
| 109 | classes: {} |
| 110 | unclassified: {} |
| 111 | } |
| 112 | EOF |
| 113 | holds "policy composes from $instance and the project's own policy/" |
| 114 | |
| 115 | # ---------------------------------------------------------------------- |
| 116 | # Helpers. |
| 117 | |
| 118 | # attest_change <branch> <check spec…> — run the checks over the branch's |
| 119 | # tip and publish the branch with its attestation ref, atomically. |
| 120 | attest_change() { |
| 121 | local branch="$1" key="${2:-$work/contributor}" name="${3:-$contributor}" |
| 122 | shift 3 |
| 123 | attest run --repo "$repo" --key "$key" --name "$name" \ |
| 124 | --push origin --branch "$branch" "$@" |
| 125 | } |
| 126 | |
| 127 | # request <change> <target> <commit> — the contributor asks for integration |
| 128 | # by pushing one ref. That ref is the whole of the request. |
| 129 | request() { |
| 130 | git push --quiet origin "$3:refs/the-valley/integration-requests/$2/$1" |
| 131 | } |
| 132 | |
| 133 | integrate() { |
| 134 | integrator reconcile \ |
| 135 | --repo "$origin" \ |
| 136 | --key "$work/integrator" --name "$integrator_name" \ |
| 137 | --known-signers "$work/known_signers" \ |
| 138 | --instance "$instance" --project-policy policy \ |
| 139 | --schema "$SCHEMA_VERIFICATION" \ |
| 140 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 141 | --event-schema "$SCHEMA_EVENTS" \ |
| 142 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 143 | 2>&1 | tee "$work/last.out" |
| 144 | grep -q . "$work/last.out" || die "the integrator said nothing" |
| 145 | } |
| 146 | |
| 147 | tip() { git -C "$origin" rev-parse refs/heads/main; } |
| 148 | forget() { git -C "$origin" update-ref -d "refs/the-valley/integration-requests/main/$1"; } |
| 149 | |
| 150 | # ---------------------------------------------------------------------- |
| 151 | say "1. a change with valid transferring evidence lands" |
| 152 | |
| 153 | before="$(tip)" |
| 154 | git checkout --quiet -b c1 |
| 155 | echo "a better readme" > docs/readme.md |
| 156 | echo "a new target" > deploy/second.txt |
| 157 | git add -A |
| 158 | git commit --quiet -m "improve the readme and add a target" |
| 159 | attest_change c1 "" "" --check prose-format --command reachable=true |
| 160 | request c1 main "$(git rev-parse c1)" |
| 161 | integrate |
| 162 | |
| 163 | grep -q "^c1 -> refs/heads/main .*: land$" "$work/last.out" || die "c1 did not land" |
| 164 | grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer" |
| 165 | grep -q "check reachable .*transferred (untouched)" "$work/last.out" || die "the effectful check did not transfer" |
| 166 | grep -q '"event":"integration-succeeded"' "$work/last.out" || die "no integration-succeeded event" |
| 167 | [ "$(tip)" != "$before" ] || die "the protected ref did not move" |
| 168 | [ "$(tip)" = "$(git rev-parse c1)" ] || die "main is not at the change's head" |
| 169 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c1 > /dev/null \ |
| 170 | && die "the request ref outlived the landing" |
| 171 | holds "main moved $(git rev-parse --short "$before") -> $(git -C "$origin" rev-parse --short refs/heads/main)" |
| 172 | |
| 173 | # The landed note carries both signatures, under one text, and verifies. |
| 174 | # The integrator writes under its own key hash, so its ref never races the |
| 175 | # contributor's over the same subject. |
| 176 | landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c1 | cut -d: -f2)/$ihash" |
| 177 | git -C "$origin" rev-parse --verify --quiet "$landed" > /dev/null \ |
| 178 | || die "no attestation ref by the integrator for the landed tree" |
| 179 | git -C "$origin" cat-file blob "$landed:prose-format/statement.note" > "$work/landed.note" |
| 180 | siblings="$(grep -c '^— ' "$work/landed.note")" |
| 181 | [ "$siblings" -eq 2 ] || die "the landed note carries $siblings signatures, not two" |
| 182 | attest verify --note "$work/landed.note" --known-keys "$work/reader_keys" \ |
| 183 | --schema "$SCHEMA_ATTESTATION" --repo "$repo" --rev c1 \ |
| 184 | --signer "$contributor" --signer "$integrator_name" > "$work/landed.verify" |
| 185 | grep -q 'matches the recorded subject digest' "$work/landed.verify" || die "the landed note does not bind to the tree" |
| 186 | holds "the landed note carries contributor and integrator sibling signatures and verifies" |
| 187 | |
| 188 | # And the integrator's own transfer statement sits beside it. |
| 189 | git -C "$origin" cat-file blob "$landed:transfer.note" > "$work/transfer.note" |
| 190 | head -n1 "$work/transfer.note" | grep -qx 'the-valley/attestation/v1' || die "the transfer note is not a statement" |
| 191 | grep -qx 'predicateType the-valley/integration/transfer/v1' "$work/transfer.note" || die "wrong predicate type" |
| 192 | grep -qx 'predicate.change c1' "$work/transfer.note" || die "the transfer statement names no change" |
| 193 | grep -q '^predicate.policy.sha256 ' "$work/transfer.note" || die "the transfer statement names no policy" |
| 194 | attest verify --note "$work/transfer.note" --known-keys "$work/reader_keys" \ |
| 195 | --schema "$SCHEMA_ATTESTATION" --signer "$integrator_name" > /dev/null |
| 196 | holds "the transfer statement records the verdict and the policy it was derived under" |
| 197 | |
| 198 | # ---------------------------------------------------------------------- |
| 199 | say "2. an intervening landing invalidates one check's closure" |
| 200 | |
| 201 | git checkout --quiet main |
| 202 | git pull --quiet --ff-only origin main |
| 203 | |
| 204 | # c2 is authored against the current tip and reads both classes. |
| 205 | git checkout --quiet -b c2 |
| 206 | echo "a readme with more in it" > docs/readme.md |
| 207 | echo "the source, revised" > src/main.txt |
| 208 | git add -A |
| 209 | git commit --quiet -m "revise the readme and the source" |
| 210 | attest_change c2 "" "" --check prose-format --check code-build |
| 211 | c2="$(git rev-parse c2)" |
| 212 | |
| 213 | # Meanwhile another change lands, touching only what code-build reads. |
| 214 | git checkout --quiet main |
| 215 | git checkout --quiet -b intervening |
| 216 | echo "a second source file" > src/other.txt |
| 217 | git add -A |
| 218 | git commit --quiet -m "add a second source file" |
| 219 | attest_change intervening "" "" --check code-build |
| 220 | request intervening main "$(git rev-parse intervening)" |
| 221 | integrate |
| 222 | grep -q "^intervening -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 223 | holds "the intervening change landed first; c2's base has moved" |
| 224 | |
| 225 | request c2 main "$c2" |
| 226 | integrate |
| 227 | grep -q "^c2 -> refs/heads/main .*: stale$" "$work/last.out" || die "c2 was not stale" |
| 228 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 229 | || die "prose-format should have transferred by closure equality" |
| 230 | grep -q "check code-build .*input closure changed" "$work/last.out" \ |
| 231 | || die "code-build's closure should have moved" |
| 232 | grep -q '"event":"request-stale"' "$work/last.out" || die "no request-stale event" |
| 233 | grep -q '"checks":\["code-build"\]' "$work/last.out" || die "the event does not name exactly code-build" |
| 234 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c2 > /dev/null \ |
| 235 | || die "the request ref was dropped; there is nothing to resubmit" |
| 236 | holds "one request-stale naming exactly code-build; prose-format reported transferred" |
| 237 | forget c2 |
| 238 | |
| 239 | # ---------------------------------------------------------------------- |
| 240 | say "2b. evidence that survives the rebase lands on the moved tip" |
| 241 | |
| 242 | # The same shape as 2, with the intervening landing outside what the |
| 243 | # change's checks read. The tree that lands is not the tree that was |
| 244 | # attested, and the evidence stands anyway — which is the whole of what |
| 245 | # content-addressed evidence buys. |
| 246 | git checkout --quiet main |
| 247 | git pull --quiet --ff-only origin main |
| 248 | git checkout --quiet -b c2b |
| 249 | echo "a readme revised again" > docs/readme.md |
| 250 | git add -A |
| 251 | git commit --quiet -m "revise the readme once more" |
| 252 | attest_change c2b "" "" --check prose-format |
| 253 | c2b="$(git rev-parse c2b)" |
| 254 | attested="$(attest digest --repo "$repo" --rev c2b | cut -d: -f2)" |
| 255 | |
| 256 | git checkout --quiet main |
| 257 | git checkout --quiet -b elsewhere |
| 258 | echo "a third source file" > src/third.txt |
| 259 | git add -A |
| 260 | git commit --quiet -m "add a third source file" |
| 261 | attest_change elsewhere "" "" --check code-build |
| 262 | request elsewhere main "$(git rev-parse elsewhere)" |
| 263 | integrate |
| 264 | grep -q "^elsewhere -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 265 | |
| 266 | request c2b main "$c2b" |
| 267 | integrate |
| 268 | grep -q "^c2b -> refs/heads/main .*: land$" "$work/last.out" || die "c2b did not land" |
| 269 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 270 | || die "the evidence did not transfer by closure equality" |
| 271 | landedtree="$(git -C "$origin" rev-parse refs/heads/main^{tree})" |
| 272 | [ "$(git -C "$origin" rev-parse "refs/heads/main^")" = "$(git rev-parse elsewhere)" ] \ |
| 273 | || die "the landing is not a fast-forward from the tip it was judged against" |
| 274 | [ "$(git -C "$origin" rev-parse refs/heads/main^{tree})" != "$(git rev-parse "$c2b^{tree}")" ] \ |
| 275 | || die "the tree did not actually move; the scenario proves nothing" |
| 276 | holds "the delta landed on a tree it was never attested over, and no check re-ran" |
| 277 | |
| 278 | # Two attestation refs now, because the two statements are about two |
| 279 | # different trees: the contributor's is keyed by the tree it was made over, |
| 280 | # and the integrator's transfer statement by the tree that landed. |
| 281 | git fetch --quiet origin main |
| 282 | landed_digest="$(attest digest --repo "$repo" --rev "$(git -C "$origin" rev-parse refs/heads/main)" | cut -d: -f2)" |
| 283 | [ "$landed_digest" != "$attested" ] || die "the landed tree is the attested tree; the scenario proves nothing" |
| 284 | git -C "$origin" cat-file blob \ |
| 285 | "refs/the-valley/attestations/$attested/$ihash:prose-format/statement.note" > "$work/rebased.note" |
| 286 | [ "$(grep -c '^— ' "$work/rebased.note")" -eq 2 ] \ |
| 287 | || die "the countersigned note lost a sibling signature" |
| 288 | grep -qx "subject.digest.valley-tree-v1 $attested" "$work/rebased.note" \ |
| 289 | || die "the countersigned statement is not about the tree it was made over" |
| 290 | git -C "$origin" cat-file blob \ |
| 291 | "refs/the-valley/attestations/$landed_digest/$ihash:transfer.note" > "$work/rebased.transfer" |
| 292 | grep -qx "subject.digest.valley-tree-v1 $landed_digest" "$work/rebased.transfer" \ |
| 293 | || die "the transfer statement is not about the landed tree" |
| 294 | grep -qx "predicate.base.valley-tree-v1 $attested" "$work/rebased.transfer" \ |
| 295 | || die "the transfer statement does not cite the base the evidence was produced over" |
| 296 | grep -qx "predicate.checks.0.rule closure" "$work/rebased.transfer" \ |
| 297 | || die "the transfer statement does not record the rule that carried the evidence" |
| 298 | holds "the contributor's statement stays about its own tree; the transfer statement names the landed one" |
| 299 | |
| 300 | # ---------------------------------------------------------------------- |
| 301 | say "3. a conflicting delta is stale, and demands full re-attestation" |
| 302 | |
| 303 | git checkout --quiet main |
| 304 | git pull --quiet --ff-only origin main |
| 305 | git checkout --quiet -b c3 |
| 306 | echo "the readme, as c3 would have it" > docs/readme.md |
| 307 | git add -A |
| 308 | git commit --quiet -m "rewrite the readme one way" |
| 309 | attest_change c3 "" "" --check prose-format |
| 310 | c3="$(git rev-parse c3)" |
| 311 | |
| 312 | git checkout --quiet main |
| 313 | git checkout --quiet -b conflicting |
| 314 | echo "the readme, as the other change would have it" > docs/readme.md |
| 315 | git add -A |
| 316 | git commit --quiet -m "rewrite the readme another way" |
| 317 | attest_change conflicting "" "" --check prose-format |
| 318 | request conflicting main "$(git rev-parse conflicting)" |
| 319 | integrate |
| 320 | grep -q "^conflicting -> refs/heads/main .*: land$" "$work/last.out" || die "the conflicting change did not land" |
| 321 | |
| 322 | request c3 main "$c3" |
| 323 | integrate |
| 324 | grep -q "^c3 -> refs/heads/main .*: stale$" "$work/last.out" || die "c3 was not stale" |
| 325 | grep -q 'resolving it is new authorship' "$work/last.out" || die "the conflict was not reported as new authorship" |
| 326 | grep -q 'CONFLICT (content): Merge conflict in docs/readme.md' "$work/last.out" \ |
| 327 | || die "the conflict does not name what could not be merged" |
| 328 | grep -q '"reason":"conflict"' "$work/last.out" || die "the event does not say conflict" |
| 329 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "a conflict must re-demand every required check" |
| 330 | holds "a conflict is stale, and every required check is re-demanded" |
| 331 | forget c3 |
| 332 | |
| 333 | # ---------------------------------------------------------------------- |
| 334 | say "4. an unknown signer's attestation does not transfer" |
| 335 | |
| 336 | git checkout --quiet main |
| 337 | git pull --quiet --ff-only origin main |
| 338 | git checkout --quiet -b c4 |
| 339 | echo "a readme signed by a stranger" > docs/readme.md |
| 340 | git add -A |
| 341 | git commit --quiet -m "a change a stranger attested" |
| 342 | attest_change c4 "$work/stranger" "$stranger" --check prose-format |
| 343 | request c4 main "$(git rev-parse c4)" |
| 344 | integrate |
| 345 | grep -q "^c4 -> refs/heads/main .*: stale$" "$work/last.out" || die "c4 was not stale" |
| 346 | grep -q 'no signer the integrator holds' "$work/last.out" || die "the unknown signer was not reported" |
| 347 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "the event does not name prose-format" |
| 348 | [ "$(tip)" = "$(git -C "$origin" rev-parse refs/heads/main)" ] || die "main moved" |
| 349 | holds "evidence from a signer the integrator does not hold does not transfer" |
| 350 | forget c4 |
| 351 | |
| 352 | # ---------------------------------------------------------------------- |
| 353 | say "5. a tampered statement is rejected, not called stale" |
| 354 | |
| 355 | git checkout --quiet main |
| 356 | git checkout --quiet -b c5 |
| 357 | echo "an honest readme" > docs/readme.md |
| 358 | git add -A |
| 359 | git commit --quiet -m "an honest change" |
| 360 | attest_change c5 "" "" --check prose-format |
| 361 | c5="$(git rev-parse c5)" |
| 362 | c5digest="$(attest digest --repo "$repo" --rev c5 | cut -d: -f2)" |
| 363 | |
| 364 | # Edit one value in the signed text and store the result where the real |
| 365 | # note was. Everything else about the note is untouched. |
| 366 | c5ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 367 | "refs/the-valley/attestations/$c5digest" | head -n1)" |
| 368 | git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note" \ |
| 369 | | sed 's/^predicate.result passed$/predicate.result failed/' > "$work/tampered.note" |
| 370 | cmp -s "$work/tampered.note" <(git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note") \ |
| 371 | && die "the tamper changed nothing; the test proves nothing" |
| 372 | blob="$(git -C "$origin" hash-object -w --stdin < "$work/tampered.note")" |
| 373 | sub="$(printf '100644 blob %s\tstatement.note\n' "$blob" | git -C "$origin" mktree)" |
| 374 | top="$(printf '040000 tree %s\tprose-format\n' "$sub" | git -C "$origin" mktree)" |
| 375 | git -C "$origin" update-ref "$c5ref" "$top" |
| 376 | |
| 377 | request c5 main "$c5" |
| 378 | integrate |
| 379 | grep -q "^c5 -> refs/heads/main .*: reject$" "$work/last.out" || die "a tampered statement was not rejected" |
| 380 | grep -q 'does not verify as the statement it claims to be' "$work/last.out" || die "the refusal was not reported" |
| 381 | grep -q 'request-stale' "$work/last.out" && die "a forgery was announced as staleness" |
| 382 | holds "a tampered statement is a rejection, and no outcome event claims otherwise" |
| 383 | forget c5 |
| 384 | |
| 385 | # ---------------------------------------------------------------------- |
| 386 | say "6. an attestation about a different tree is rejected" |
| 387 | |
| 388 | git checkout --quiet main |
| 389 | git checkout --quiet -b c6 |
| 390 | echo "the tree that was actually attested" > docs/readme.md |
| 391 | git add -A |
| 392 | git commit --quiet -m "the attested change" |
| 393 | attest_change c6 "" "" --check prose-format |
| 394 | c6ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 395 | "refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c6 | cut -d: -f2)" | head -n1)" |
| 396 | |
| 397 | # A second, different tree — with no attestation of its own — and the |
| 398 | # first tree's valid, correctly signed note filed under its digest. |
| 399 | git checkout --quiet -b c6-lifted |
| 400 | echo "the tree that was not" > docs/readme.md |
| 401 | git add -A |
| 402 | git commit --quiet -m "the change the evidence was lifted onto" |
| 403 | git push --quiet origin c6-lifted |
| 404 | lifted="$(attest digest --repo "$repo" --rev c6-lifted | cut -d: -f2)" |
| 405 | git -C "$origin" update-ref \ |
| 406 | "refs/the-valley/attestations/$lifted/${c6ref##*/}" \ |
| 407 | "$(git -C "$origin" rev-parse "$c6ref^{tree}")" |
| 408 | |
| 409 | request c6 main "$(git rev-parse c6-lifted)" |
| 410 | integrate |
| 411 | grep -q "^c6 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lifted attestation was not rejected" |
| 412 | grep -q 'tree digest mismatch' "$work/last.out" || die "the refusal does not name the tree digest" |
| 413 | holds "a signature cannot be lifted onto a tree it was not made about" |
| 414 | forget c6 |
| 415 | |
| 416 | # ---------------------------------------------------------------------- |
| 417 | say "7. an attestation lying about its kind is rejected" |
| 418 | |
| 419 | # The policy runs prose-format with nix, so its evidence is content- |
| 420 | # addressed. This attestation claims a notarization instead, and its class |
| 421 | # was untouched by the intervening landing — so under the rule it nominated |
| 422 | # for itself it would sail onto a base it was never produced over. |
| 423 | git checkout --quiet main |
| 424 | git pull --quiet --ff-only origin main |
| 425 | git checkout --quiet -b c7 |
| 426 | echo "a readme attested as a notarization" > docs/readme.md |
| 427 | git add -A |
| 428 | git commit --quiet -m "a change whose attestation lies about its kind" |
| 429 | attest_change c7 "" "" --command prose-format=true |
| 430 | c7="$(git rev-parse c7)" |
| 431 | |
| 432 | git checkout --quiet main |
| 433 | git checkout --quiet -b under-c7 |
| 434 | echo "a fourth source file" > src/fourth.txt |
| 435 | git add -A |
| 436 | git commit --quiet -m "add a fourth source file" |
| 437 | attest_change under-c7 "" "" --check code-build |
| 438 | request under-c7 main "$(git rev-parse under-c7)" |
| 439 | integrate |
| 440 | grep -q "^under-c7 -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 441 | |
| 442 | request c7 main "$c7" |
| 443 | integrate |
| 444 | grep -q "^c7 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lie about the kind was not rejected" |
| 445 | grep -q 'requires a pure check and the attestation claims an effectful check' "$work/last.out" \ |
| 446 | || die "the refusal does not say the policy decides the rule" |
| 447 | holds "the transfer rule follows the policy's runner, never the attestation's own claim" |
| 448 | forget c7 |
| 449 | |
| 450 | # ---------------------------------------------------------------------- |
| 451 | say "8. evidence pushed after a no-evidence verdict re-judges and lands" |
| 452 | |
| 453 | git checkout --quiet main |
| 454 | git pull --quiet --ff-only origin main |
| 455 | git checkout --quiet -b c8 |
| 456 | echo "a readme with no evidence yet" > docs/readme.md |
| 457 | git add -A |
| 458 | git commit --quiet -m "a change submitted before its checks ran" |
| 459 | git push --quiet origin c8 |
| 460 | request c8 main "$(git rev-parse c8)" |
| 461 | integrate |
| 462 | grep -q "^c8 -> refs/heads/main .*: stale$" "$work/last.out" || die "a change with no evidence was not stale" |
| 463 | grep -q 'no attestation for this check accompanies the change' "$work/last.out" \ |
| 464 | || die "the absent attestation was not reported" |
| 465 | |
| 466 | # Nothing about the request or the tip moves; only the evidence arrives. |
| 467 | attest_change c8 "" "" --check prose-format |
| 468 | integrate |
| 469 | grep -q "^c8 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 470 | || die "the request was not re-judged after its evidence arrived" |
| 471 | [ "$(tip)" = "$(git rev-parse c8)" ] || die "main is not at the change's head" |
| 472 | holds "a pass re-judges when evidence arrives, with the request and the tip unmoved" |
| 473 | |
| 474 | # ---------------------------------------------------------------------- |
| 475 | say "9. a ref that is not a request does not hold up one that is" |
| 476 | |
| 477 | git checkout --quiet main |
| 478 | git pull --quiet --ff-only origin main |
| 479 | git checkout --quiet -b c9 |
| 480 | echo "a readme beside a garbage ref" > docs/readme.md |
| 481 | git add -A |
| 482 | git commit --quiet -m "a change beside a malformed request" |
| 483 | attest_change c9 "" "" --check prose-format |
| 484 | # A name with no target segment at all, and one with a segment too many. |
| 485 | # Anyone with push access can write this namespace. |
| 486 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/garbage" |
| 487 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/main/too/deep" |
| 488 | request c9 main "$(git rev-parse c9)" |
| 489 | integrate |
| 490 | grep -q 'refs/the-valley/integration-requests/garbage: not a request ref' "$work/last.out" \ |
| 491 | || die "the malformed ref was not reported" |
| 492 | grep -q 'refs/the-valley/integration-requests/main/too/deep: not a request ref' "$work/last.out" \ |
| 493 | || die "the over-deep ref was not reported" |
| 494 | grep -q "^c9 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 495 | || die "a malformed ref stopped the pass reaching a valid request" |
| 496 | holds "malformed refs are reported and skipped; the valid request beside them landed" |
| 497 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/garbage |
| 498 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/too/deep |
| 499 | |
| 500 | printf '\nintegrator-e2e: every scenario held\n' |