| 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 asks for integration |
| 149 | # 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 | integrate() { |
| 155 | # Neither policy path is stated: both layers come from where the |
| 156 | # integrator defaults to looking, which is the whole of what a deployment |
| 157 | # following the convention says about policy. |
| 158 | integrator reconcile \ |
| 159 | --repo "$origin" \ |
| 160 | --key "$work/integrator" --name "$integrator_name" \ |
| 161 | --known-signers "$work/known_signers" \ |
| 162 | --instance-repo "$instance_repo" \ |
| 163 | --schema "$SCHEMA_VERIFICATION" \ |
| 164 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 165 | --event-schema "$SCHEMA_EVENTS" \ |
| 166 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 167 | 2>&1 | tee "$work/last.out" |
| 168 | grep -q . "$work/last.out" || die "the integrator said nothing" |
| 169 | } |
| 170 | |
| 171 | tip() { git -C "$origin" rev-parse refs/heads/main; } |
| 172 | forget() { git -C "$origin" update-ref -d "refs/the-valley/integration-requests/main/$1"; } |
| 173 | |
| 174 | # ---------------------------------------------------------------------- |
| 175 | say "1. a change with valid transferring evidence lands" |
| 176 | |
| 177 | before="$(tip)" |
| 178 | git checkout --quiet -b c1 |
| 179 | echo "a better readme" > docs/readme.md |
| 180 | echo "a new target" > deploy/second.txt |
| 181 | git add -A |
| 182 | git commit --quiet -m "improve the readme and add a target" |
| 183 | attest_change c1 "" "" --check prose-format --command reachable=true |
| 184 | request c1 main "$(git rev-parse c1)" |
| 185 | integrate |
| 186 | |
| 187 | grep -q "^c1 -> refs/heads/main .*: land$" "$work/last.out" || die "c1 did not land" |
| 188 | grep -q "check prose-format .*transferred" "$work/last.out" || die "prose-format did not transfer" |
| 189 | grep -q "check reachable .*transferred (untouched)" "$work/last.out" || die "the effectful check did not transfer" |
| 190 | grep -q '"event":"integration-succeeded"' "$work/last.out" || die "no integration-succeeded event" |
| 191 | [ "$(tip)" != "$before" ] || die "the protected ref did not move" |
| 192 | [ "$(tip)" = "$(git rev-parse c1)" ] || die "main is not at the change's head" |
| 193 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c1 > /dev/null \ |
| 194 | && die "the request ref outlived the landing" |
| 195 | holds "main moved $(git rev-parse --short "$before") -> $(git -C "$origin" rev-parse --short refs/heads/main)" |
| 196 | |
| 197 | # The landed note carries both signatures, under one text, and verifies. |
| 198 | # The integrator writes under its own key hash, so its ref never races the |
| 199 | # contributor's over the same subject. |
| 200 | landed="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c1 | cut -d: -f2)/$ihash" |
| 201 | git -C "$origin" rev-parse --verify --quiet "$landed" > /dev/null \ |
| 202 | || die "no attestation ref by the integrator for the landed tree" |
| 203 | git -C "$origin" cat-file blob "$landed:prose-format/statement.note" > "$work/landed.note" |
| 204 | siblings="$(grep -c '^— ' "$work/landed.note")" |
| 205 | [ "$siblings" -eq 2 ] || die "the landed note carries $siblings signatures, not two" |
| 206 | attest verify --note "$work/landed.note" --known-keys "$work/reader_keys" \ |
| 207 | --schema "$SCHEMA_ATTESTATION" --repo "$repo" --rev c1 \ |
| 208 | --signer "$contributor" --signer "$integrator_name" > "$work/landed.verify" |
| 209 | grep -q 'matches the recorded subject digest' "$work/landed.verify" || die "the landed note does not bind to the tree" |
| 210 | holds "the landed note carries contributor and integrator sibling signatures and verifies" |
| 211 | |
| 212 | # And the integrator's own transfer statement sits beside it. |
| 213 | git -C "$origin" cat-file blob "$landed:transfer.note" > "$work/transfer.note" |
| 214 | head -n1 "$work/transfer.note" | grep -qx 'the-valley/attestation/v1' || die "the transfer note is not a statement" |
| 215 | grep -qx 'predicateType the-valley/integration/transfer/v1' "$work/transfer.note" || die "wrong predicate type" |
| 216 | grep -qx 'predicate.change c1' "$work/transfer.note" || die "the transfer statement names no change" |
| 217 | grep -q '^predicate.policy.sha256 ' "$work/transfer.note" || die "the transfer statement names no policy" |
| 218 | attest verify --note "$work/transfer.note" --known-keys "$work/reader_keys" \ |
| 219 | --schema "$SCHEMA_ATTESTATION" --signer "$integrator_name" > /dev/null |
| 220 | holds "the transfer statement records the verdict and the policy it was derived under" |
| 221 | |
| 222 | # ---------------------------------------------------------------------- |
| 223 | say "2. an intervening landing invalidates one check's closure" |
| 224 | |
| 225 | git checkout --quiet main |
| 226 | git pull --quiet --ff-only origin main |
| 227 | |
| 228 | # c2 is authored against the current tip and reads both classes. |
| 229 | git checkout --quiet -b c2 |
| 230 | echo "a readme with more in it" > docs/readme.md |
| 231 | echo "the source, revised" > src/main.txt |
| 232 | git add -A |
| 233 | git commit --quiet -m "revise the readme and the source" |
| 234 | attest_change c2 "" "" --check prose-format --check code-build |
| 235 | c2="$(git rev-parse c2)" |
| 236 | |
| 237 | # Meanwhile another change lands, touching only what code-build reads. |
| 238 | git checkout --quiet main |
| 239 | git checkout --quiet -b intervening |
| 240 | echo "a second source file" > src/other.txt |
| 241 | git add -A |
| 242 | git commit --quiet -m "add a second source file" |
| 243 | attest_change intervening "" "" --check code-build |
| 244 | request intervening main "$(git rev-parse intervening)" |
| 245 | integrate |
| 246 | grep -q "^intervening -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 247 | holds "the intervening change landed first; c2's base has moved" |
| 248 | |
| 249 | request c2 main "$c2" |
| 250 | integrate |
| 251 | grep -q "^c2 -> refs/heads/main .*: stale$" "$work/last.out" || die "c2 was not stale" |
| 252 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 253 | || die "prose-format should have transferred by closure equality" |
| 254 | grep -q "check code-build .*input closure changed" "$work/last.out" \ |
| 255 | || die "code-build's closure should have moved" |
| 256 | grep -q '"event":"request-stale"' "$work/last.out" || die "no request-stale event" |
| 257 | grep -q '"checks":\["code-build"\]' "$work/last.out" || die "the event does not name exactly code-build" |
| 258 | git -C "$origin" rev-parse --verify --quiet refs/the-valley/integration-requests/main/c2 > /dev/null \ |
| 259 | || die "the request ref was dropped; there is nothing to resubmit" |
| 260 | holds "one request-stale naming exactly code-build; prose-format reported transferred" |
| 261 | forget c2 |
| 262 | |
| 263 | # ---------------------------------------------------------------------- |
| 264 | say "2b. evidence that survives the rebase lands on the moved tip" |
| 265 | |
| 266 | # The same shape as 2, with the intervening landing outside what the |
| 267 | # change's checks read. The tree that lands is not the tree that was |
| 268 | # attested, and the evidence stands anyway — which is the whole of what |
| 269 | # content-addressed evidence buys. |
| 270 | git checkout --quiet main |
| 271 | git pull --quiet --ff-only origin main |
| 272 | git checkout --quiet -b c2b |
| 273 | echo "a readme revised again" > docs/readme.md |
| 274 | git add -A |
| 275 | git commit --quiet -m "revise the readme once more" |
| 276 | attest_change c2b "" "" --check prose-format |
| 277 | c2b="$(git rev-parse c2b)" |
| 278 | attested="$(attest digest --repo "$repo" --rev c2b | cut -d: -f2)" |
| 279 | |
| 280 | git checkout --quiet main |
| 281 | git checkout --quiet -b elsewhere |
| 282 | echo "a third source file" > src/third.txt |
| 283 | git add -A |
| 284 | git commit --quiet -m "add a third source file" |
| 285 | attest_change elsewhere "" "" --check code-build |
| 286 | request elsewhere main "$(git rev-parse elsewhere)" |
| 287 | integrate |
| 288 | grep -q "^elsewhere -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 289 | |
| 290 | request c2b main "$c2b" |
| 291 | integrate |
| 292 | grep -q "^c2b -> refs/heads/main .*: land$" "$work/last.out" || die "c2b did not land" |
| 293 | grep -q "check prose-format .*transferred (closure)" "$work/last.out" \ |
| 294 | || die "the evidence did not transfer by closure equality" |
| 295 | landedtree="$(git -C "$origin" rev-parse refs/heads/main^{tree})" |
| 296 | [ "$(git -C "$origin" rev-parse "refs/heads/main^")" = "$(git rev-parse elsewhere)" ] \ |
| 297 | || die "the landing is not a fast-forward from the tip it was judged against" |
| 298 | [ "$(git -C "$origin" rev-parse refs/heads/main^{tree})" != "$(git rev-parse "$c2b^{tree}")" ] \ |
| 299 | || die "the tree did not actually move; the scenario proves nothing" |
| 300 | holds "the delta landed on a tree it was never attested over, and no check re-ran" |
| 301 | |
| 302 | # Two attestation refs now, because the two statements are about two |
| 303 | # different trees: the contributor's is keyed by the tree it was made over, |
| 304 | # and the integrator's transfer statement by the tree that landed. |
| 305 | git fetch --quiet origin main |
| 306 | landed_digest="$(attest digest --repo "$repo" --rev "$(git -C "$origin" rev-parse refs/heads/main)" | cut -d: -f2)" |
| 307 | [ "$landed_digest" != "$attested" ] || die "the landed tree is the attested tree; the scenario proves nothing" |
| 308 | git -C "$origin" cat-file blob \ |
| 309 | "refs/the-valley/attestations/$attested/$ihash:prose-format/statement.note" > "$work/rebased.note" |
| 310 | [ "$(grep -c '^— ' "$work/rebased.note")" -eq 2 ] \ |
| 311 | || die "the countersigned note lost a sibling signature" |
| 312 | grep -qx "subject.digest.valley-tree-v1 $attested" "$work/rebased.note" \ |
| 313 | || die "the countersigned statement is not about the tree it was made over" |
| 314 | git -C "$origin" cat-file blob \ |
| 315 | "refs/the-valley/attestations/$landed_digest/$ihash:transfer.note" > "$work/rebased.transfer" |
| 316 | grep -qx "subject.digest.valley-tree-v1 $landed_digest" "$work/rebased.transfer" \ |
| 317 | || die "the transfer statement is not about the landed tree" |
| 318 | grep -qx "predicate.base.valley-tree-v1 $attested" "$work/rebased.transfer" \ |
| 319 | || die "the transfer statement does not cite the base the evidence was produced over" |
| 320 | grep -qx "predicate.checks.0.rule closure" "$work/rebased.transfer" \ |
| 321 | || die "the transfer statement does not record the rule that carried the evidence" |
| 322 | holds "the contributor's statement stays about its own tree; the transfer statement names the landed one" |
| 323 | |
| 324 | # ---------------------------------------------------------------------- |
| 325 | say "2c. a re-parenting landing states its own committer, and needs none from the environment" |
| 326 | |
| 327 | # Re-parenting is the one landing that makes a commit of the integrator's |
| 328 | # own, so it is the one that needs a committer. Under the unit there is |
| 329 | # nothing to take one from: no git config the service can read, no GIT_* in |
| 330 | # its environment, and a hostname git will not guess an address from. So the |
| 331 | # integrator states both identities itself — the asker authored the change, |
| 332 | # the integrator committed the commit that carries it onto the tip — and the |
| 333 | # pass below runs with everything git could have fallen back to taken away. |
| 334 | |
| 335 | # A scrubbed environment: no global or system config, no GIT_* identity, and |
| 336 | # auto-detection refused outright, so that a host whose own hostname does |
| 337 | # resolve cannot hide a dependency on it. |
| 338 | scrubbed() { |
| 339 | env -u GIT_AUTHOR_NAME -u GIT_AUTHOR_EMAIL -u GIT_AUTHOR_DATE \ |
| 340 | -u GIT_COMMITTER_NAME -u GIT_COMMITTER_EMAIL -u GIT_COMMITTER_DATE -u EMAIL \ |
| 341 | GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 \ |
| 342 | GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.useConfigOnly GIT_CONFIG_VALUE_0=true \ |
| 343 | "$@" |
| 344 | } |
| 345 | scrubbed git -C "$origin" var GIT_COMMITTER_IDENT > /dev/null 2>&1 \ |
| 346 | && die "the scrub left an identity for git to find; the scenario proves nothing" |
| 347 | |
| 348 | git checkout --quiet main |
| 349 | git pull --quiet --ff-only origin main |
| 350 | git checkout --quiet -b c2c |
| 351 | echo "a readme revised by a stated author" > docs/readme.md |
| 352 | git add -A |
| 353 | # A distinct author, so that what the landed commit carries over from the |
| 354 | # head and what it states of its own are told apart by reading it. |
| 355 | GIT_AUTHOR_NAME="a contributor" GIT_AUTHOR_EMAIL="contributor@valley.invalid" \ |
| 356 | git commit --quiet -m "revise the readme under an author of its own" |
| 357 | attest_change c2c "" "" --check prose-format |
| 358 | c2c="$(git rev-parse c2c)" |
| 359 | |
| 360 | # The intervening landing, outside what prose-format reads, is what moves |
| 361 | # c2c's base and makes the landing below a re-parent rather than a |
| 362 | # fast-forward. |
| 363 | git checkout --quiet main |
| 364 | git checkout --quiet -b under-c2c |
| 365 | echo "a fifth source file" > src/fifth.txt |
| 366 | git add -A |
| 367 | git commit --quiet -m "add a fifth source file" |
| 368 | attest_change under-c2c "" "" --check code-build |
| 369 | request under-c2c main "$(git rev-parse under-c2c)" |
| 370 | integrate |
| 371 | grep -q "^under-c2c -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 372 | |
| 373 | request c2c main "$c2c" |
| 374 | scrubbed integrator reconcile \ |
| 375 | --repo "$origin" \ |
| 376 | --key "$work/integrator" --name "$integrator_name" \ |
| 377 | --known-signers "$work/known_signers" \ |
| 378 | --instance-repo "$instance_repo" \ |
| 379 | --schema "$SCHEMA_VERIFICATION" \ |
| 380 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 381 | --event-schema "$SCHEMA_EVENTS" \ |
| 382 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 383 | 2>&1 | tee "$work/last.out" |
| 384 | grep -q "^c2c -> refs/heads/main .*: land$" "$work/last.out" \ |
| 385 | || die "a landing with no git identity in the environment did not land: $(cat "$work/last.out")" |
| 386 | |
| 387 | landed_commit="$(git -C "$origin" rev-parse refs/heads/main)" |
| 388 | [ "$landed_commit" != "$c2c" ] || die "the landing was a fast-forward; the scenario proves nothing" |
| 389 | [ "$(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")" = "a contributor <contributor@valley.invalid>" ] \ |
| 390 | || die "the landed commit is not authored by the asker: $(git -C "$origin" log -1 --format='%an <%ae>' "$landed_commit")" |
| 391 | [ "$(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")" = "$integrator_name <integrator@the-valley.invalid>" ] \ |
| 392 | || die "the landed commit is not committed by the integrator: $(git -C "$origin" log -1 --format='%cn <%ce>' "$landed_commit")" |
| 393 | # The commit id is a function of what the pass decided from and nothing |
| 394 | # else, so a pass that dies before the ref write recomputes this same |
| 395 | # commit rather than leaving another behind. |
| 396 | [ "$(git -C "$origin" log -1 --format=%aI "$landed_commit")" = "$(git -C "$origin" log -1 --format=%cI "$landed_commit")" ] \ |
| 397 | || die "the committer date is not the author's, so the landed commit id is not reproducible" |
| 398 | holds "the integrator committed under its own name with nothing in the environment to take one from" |
| 399 | |
| 400 | # ---------------------------------------------------------------------- |
| 401 | say "3. a conflicting delta is stale, and demands full re-attestation" |
| 402 | |
| 403 | git checkout --quiet main |
| 404 | git pull --quiet --ff-only origin main |
| 405 | git checkout --quiet -b c3 |
| 406 | echo "the readme, as c3 would have it" > docs/readme.md |
| 407 | git add -A |
| 408 | git commit --quiet -m "rewrite the readme one way" |
| 409 | attest_change c3 "" "" --check prose-format |
| 410 | c3="$(git rev-parse c3)" |
| 411 | |
| 412 | git checkout --quiet main |
| 413 | git checkout --quiet -b conflicting |
| 414 | echo "the readme, as the other change would have it" > docs/readme.md |
| 415 | git add -A |
| 416 | git commit --quiet -m "rewrite the readme another way" |
| 417 | attest_change conflicting "" "" --check prose-format |
| 418 | request conflicting main "$(git rev-parse conflicting)" |
| 419 | integrate |
| 420 | grep -q "^conflicting -> refs/heads/main .*: land$" "$work/last.out" || die "the conflicting change did not land" |
| 421 | |
| 422 | request c3 main "$c3" |
| 423 | integrate |
| 424 | grep -q "^c3 -> refs/heads/main .*: stale$" "$work/last.out" || die "c3 was not stale" |
| 425 | grep -q 'resolving it is new authorship' "$work/last.out" || die "the conflict was not reported as new authorship" |
| 426 | grep -q 'CONFLICT (content): Merge conflict in docs/readme.md' "$work/last.out" \ |
| 427 | || die "the conflict does not name what could not be merged" |
| 428 | grep -q '"reason":"conflict"' "$work/last.out" || die "the event does not say conflict" |
| 429 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "a conflict must re-demand every required check" |
| 430 | holds "a conflict is stale, and every required check is re-demanded" |
| 431 | forget c3 |
| 432 | |
| 433 | # ---------------------------------------------------------------------- |
| 434 | say "4. an unknown signer's attestation does not transfer" |
| 435 | |
| 436 | git checkout --quiet main |
| 437 | git pull --quiet --ff-only origin main |
| 438 | git checkout --quiet -b c4 |
| 439 | echo "a readme signed by a stranger" > docs/readme.md |
| 440 | git add -A |
| 441 | git commit --quiet -m "a change a stranger attested" |
| 442 | attest_change c4 "$work/stranger" "$stranger" --check prose-format |
| 443 | request c4 main "$(git rev-parse c4)" |
| 444 | integrate |
| 445 | grep -q "^c4 -> refs/heads/main .*: stale$" "$work/last.out" || die "c4 was not stale" |
| 446 | grep -q 'no signer the integrator holds' "$work/last.out" || die "the unknown signer was not reported" |
| 447 | grep -q '"checks":\["prose-format"\]' "$work/last.out" || die "the event does not name prose-format" |
| 448 | [ "$(tip)" = "$(git -C "$origin" rev-parse refs/heads/main)" ] || die "main moved" |
| 449 | holds "evidence from a signer the integrator does not hold does not transfer" |
| 450 | forget c4 |
| 451 | |
| 452 | # ---------------------------------------------------------------------- |
| 453 | say "5. a tampered statement is rejected, not called stale" |
| 454 | |
| 455 | git checkout --quiet main |
| 456 | git checkout --quiet -b c5 |
| 457 | echo "an honest readme" > docs/readme.md |
| 458 | git add -A |
| 459 | git commit --quiet -m "an honest change" |
| 460 | attest_change c5 "" "" --check prose-format |
| 461 | c5="$(git rev-parse c5)" |
| 462 | c5digest="$(attest digest --repo "$repo" --rev c5 | cut -d: -f2)" |
| 463 | |
| 464 | # Edit one value in the signed text and store the result where the real |
| 465 | # note was. Everything else about the note is untouched. |
| 466 | c5ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 467 | "refs/the-valley/attestations/$c5digest" | head -n1)" |
| 468 | git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note" \ |
| 469 | | sed 's/^predicate.result passed$/predicate.result failed/' > "$work/tampered.note" |
| 470 | cmp -s "$work/tampered.note" <(git -C "$origin" cat-file blob "$c5ref:prose-format/statement.note") \ |
| 471 | && die "the tamper changed nothing; the test proves nothing" |
| 472 | blob="$(git -C "$origin" hash-object -w --stdin < "$work/tampered.note")" |
| 473 | sub="$(printf '100644 blob %s\tstatement.note\n' "$blob" | git -C "$origin" mktree)" |
| 474 | top="$(printf '040000 tree %s\tprose-format\n' "$sub" | git -C "$origin" mktree)" |
| 475 | git -C "$origin" update-ref "$c5ref" "$top" |
| 476 | |
| 477 | request c5 main "$c5" |
| 478 | integrate |
| 479 | grep -q "^c5 -> refs/heads/main .*: reject$" "$work/last.out" || die "a tampered statement was not rejected" |
| 480 | grep -q 'does not verify as the statement it claims to be' "$work/last.out" || die "the refusal was not reported" |
| 481 | grep -q 'request-stale' "$work/last.out" && die "a forgery was announced as staleness" |
| 482 | holds "a tampered statement is a rejection, and no outcome event claims otherwise" |
| 483 | forget c5 |
| 484 | |
| 485 | # ---------------------------------------------------------------------- |
| 486 | say "6. an attestation about a different tree is rejected" |
| 487 | |
| 488 | git checkout --quiet main |
| 489 | git checkout --quiet -b c6 |
| 490 | echo "the tree that was actually attested" > docs/readme.md |
| 491 | git add -A |
| 492 | git commit --quiet -m "the attested change" |
| 493 | attest_change c6 "" "" --check prose-format |
| 494 | c6ref="$(git -C "$origin" for-each-ref --format='%(refname)' \ |
| 495 | "refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c6 | cut -d: -f2)" | head -n1)" |
| 496 | |
| 497 | # A second, different tree — with no attestation of its own — and the |
| 498 | # first tree's valid, correctly signed note filed under its digest. |
| 499 | git checkout --quiet -b c6-lifted |
| 500 | echo "the tree that was not" > docs/readme.md |
| 501 | git add -A |
| 502 | git commit --quiet -m "the change the evidence was lifted onto" |
| 503 | git push --quiet origin c6-lifted |
| 504 | lifted="$(attest digest --repo "$repo" --rev c6-lifted | cut -d: -f2)" |
| 505 | git -C "$origin" update-ref \ |
| 506 | "refs/the-valley/attestations/$lifted/${c6ref##*/}" \ |
| 507 | "$(git -C "$origin" rev-parse "$c6ref^{tree}")" |
| 508 | |
| 509 | request c6 main "$(git rev-parse c6-lifted)" |
| 510 | integrate |
| 511 | grep -q "^c6 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lifted attestation was not rejected" |
| 512 | grep -q 'tree digest mismatch' "$work/last.out" || die "the refusal does not name the tree digest" |
| 513 | holds "a signature cannot be lifted onto a tree it was not made about" |
| 514 | forget c6 |
| 515 | |
| 516 | # ---------------------------------------------------------------------- |
| 517 | say "7. an attestation lying about its kind is rejected" |
| 518 | |
| 519 | # The policy runs prose-format with nix, so its evidence is content- |
| 520 | # addressed. This attestation claims a notarization instead, and its class |
| 521 | # was untouched by the intervening landing — so under the rule it nominated |
| 522 | # for itself it would sail onto a base it was never produced over. |
| 523 | git checkout --quiet main |
| 524 | git pull --quiet --ff-only origin main |
| 525 | git checkout --quiet -b c7 |
| 526 | echo "a readme attested as a notarization" > docs/readme.md |
| 527 | git add -A |
| 528 | git commit --quiet -m "a change whose attestation lies about its kind" |
| 529 | attest_change c7 "" "" --command prose-format=true |
| 530 | c7="$(git rev-parse c7)" |
| 531 | |
| 532 | git checkout --quiet main |
| 533 | git checkout --quiet -b under-c7 |
| 534 | echo "a fourth source file" > src/fourth.txt |
| 535 | git add -A |
| 536 | git commit --quiet -m "add a fourth source file" |
| 537 | attest_change under-c7 "" "" --check code-build |
| 538 | request under-c7 main "$(git rev-parse under-c7)" |
| 539 | integrate |
| 540 | grep -q "^under-c7 -> refs/heads/main .*: land$" "$work/last.out" || die "the intervening change did not land" |
| 541 | |
| 542 | request c7 main "$c7" |
| 543 | integrate |
| 544 | grep -q "^c7 -> refs/heads/main .*: reject$" "$work/last.out" || die "a lie about the kind was not rejected" |
| 545 | grep -q 'requires a pure check and the attestation claims an effectful check' "$work/last.out" \ |
| 546 | || die "the refusal does not say the policy decides the rule" |
| 547 | holds "the transfer rule follows the policy's runner, never the attestation's own claim" |
| 548 | forget c7 |
| 549 | |
| 550 | # ---------------------------------------------------------------------- |
| 551 | say "8. evidence pushed after a no-evidence verdict re-judges and lands" |
| 552 | |
| 553 | git checkout --quiet main |
| 554 | git pull --quiet --ff-only origin main |
| 555 | git checkout --quiet -b c8 |
| 556 | echo "a readme with no evidence yet" > docs/readme.md |
| 557 | git add -A |
| 558 | git commit --quiet -m "a change submitted before its checks ran" |
| 559 | git push --quiet origin c8 |
| 560 | request c8 main "$(git rev-parse c8)" |
| 561 | integrate |
| 562 | grep -q "^c8 -> refs/heads/main .*: stale$" "$work/last.out" || die "a change with no evidence was not stale" |
| 563 | grep -q 'no attestation for this check accompanies the change' "$work/last.out" \ |
| 564 | || die "the absent attestation was not reported" |
| 565 | |
| 566 | # Nothing about the request or the tip moves; only the evidence arrives. |
| 567 | attest_change c8 "" "" --check prose-format |
| 568 | integrate |
| 569 | grep -q "^c8 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 570 | || die "the request was not re-judged after its evidence arrived" |
| 571 | [ "$(tip)" = "$(git rev-parse c8)" ] || die "main is not at the change's head" |
| 572 | holds "a pass re-judges when evidence arrives, with the request and the tip unmoved" |
| 573 | |
| 574 | # ---------------------------------------------------------------------- |
| 575 | say "9. a ref that is not a request does not hold up one that is" |
| 576 | |
| 577 | git checkout --quiet main |
| 578 | git pull --quiet --ff-only origin main |
| 579 | git checkout --quiet -b c9 |
| 580 | echo "a readme beside a garbage ref" > docs/readme.md |
| 581 | git add -A |
| 582 | git commit --quiet -m "a change beside a malformed request" |
| 583 | attest_change c9 "" "" --check prose-format |
| 584 | # A name with no target segment at all, and one with a segment too many. |
| 585 | # This repository is served with no pre-receive hook, so the namespace takes |
| 586 | # whatever is pushed; on a host only a holder of the request grant writes |
| 587 | # it, and a holder can still write a name that is not a request. |
| 588 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/garbage" |
| 589 | git push --quiet origin "$(git rev-parse c9):refs/the-valley/integration-requests/main/too/deep" |
| 590 | request c9 main "$(git rev-parse c9)" |
| 591 | integrate |
| 592 | grep -q 'refs/the-valley/integration-requests/garbage: not a request ref' "$work/last.out" \ |
| 593 | || die "the malformed ref was not reported" |
| 594 | grep -q 'refs/the-valley/integration-requests/main/too/deep: not a request ref' "$work/last.out" \ |
| 595 | || die "the over-deep ref was not reported" |
| 596 | grep -q "^c9 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 597 | || die "a malformed ref stopped the pass reaching a valid request" |
| 598 | holds "malformed refs are reported and skipped; the valid request beside them landed" |
| 599 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/garbage |
| 600 | git -C "$origin" update-ref -d refs/the-valley/integration-requests/main/too/deep |
| 601 | |
| 602 | # ---------------------------------------------------------------------- |
| 603 | say "10. a pass leaves no scratch behind, and a leaked worktree is swept" |
| 604 | |
| 605 | # Nine scenarios of real passes, landings and rejections alike, and the |
| 606 | # scratch root is empty: every worktree a pass takes is given back on the |
| 607 | # way out, on the failure path as much as the success one. |
| 608 | leftover="$(find "$TMPDIR" -maxdepth 1 -name 'valley-integrator-wt*')" |
| 609 | [ -z "$leftover" ] || die "nine passes left scratch behind: $leftover" |
| 610 | [ "$(git -C "$origin" worktree list --porcelain | grep -c '^worktree ')" -eq 1 ] \ |
| 611 | || die "nine passes left a worktree attached to the repository" |
| 612 | holds "no pass left a worktree or a scratch directory behind" |
| 613 | |
| 614 | # What a crash leaves: the checkout and its administrative entry, both |
| 615 | # still valid, so nothing prunes them. Beside it, a worktree of the kind |
| 616 | # an operator might attach by hand, which is not the integrator's to |
| 617 | # remove. |
| 618 | leak="$TMPDIR/valley-integrator-wt-crashed" |
| 619 | mine="$work/an-operators-own-worktree" |
| 620 | git -C "$origin" worktree add --quiet --detach "$leak" refs/heads/main |
| 621 | git -C "$origin" worktree add --quiet --detach "$mine" refs/heads/main |
| 622 | timeout 5 integrator watch --interval 1s \ |
| 623 | --repo "$origin" \ |
| 624 | --key "$work/integrator" --name "$integrator_name" \ |
| 625 | --known-signers "$work/known_signers" \ |
| 626 | --instance "$instance" \ |
| 627 | --schema "$SCHEMA_VERIFICATION" \ |
| 628 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 629 | --event-schema "$SCHEMA_EVENTS" \ |
| 630 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 631 | > "$work/watch.out" 2>&1 || true |
| 632 | [ ! -e "$leak" ] || die "a leaked scratch worktree survived the sweep" |
| 633 | if git -C "$origin" worktree list --porcelain | grep -q "^worktree $leak$"; then |
| 634 | die "the leaked worktree is gone from disk and still registered" |
| 635 | fi |
| 636 | [ -e "$mine" ] || die "the sweep removed a worktree the integrator did not make" |
| 637 | git -C "$origin" worktree remove --force "$mine" |
| 638 | holds "a crash-leaked scratch worktree is swept at watch start; another hand's is not" |
| 639 | |
| 640 | # ---------------------------------------------------------------------- |
| 641 | say "11. a scratch root it may not write is reported as that, and nothing else" |
| 642 | |
| 643 | # The deployment failure this guards is a sandbox failure: the root TMPDIR |
| 644 | # names is not writable. That is a statement about the unit, not about the |
| 645 | # change being judged, and it has to arrive as one — with the path and where |
| 646 | # the path came from — rather than as git complaining about the leading |
| 647 | # directories of a .git file. |
| 648 | refused="$work/refused" |
| 649 | mkdir -p "$refused" |
| 650 | chmod a-w "$refused" |
| 651 | git checkout --quiet main |
| 652 | git pull --quiet --ff-only origin main |
| 653 | git checkout --quiet -b c10 |
| 654 | echo "a change that never gets a worktree" > docs/readme.md |
| 655 | git add -A |
| 656 | git commit --quiet -m "a change the integrator cannot make scratch for" |
| 657 | attest_change c10 "" "" --check prose-format |
| 658 | request c10 main "$(git rev-parse c10)" |
| 659 | export TMPDIR="$refused" |
| 660 | integrate || true |
| 661 | export TMPDIR="$work/tmp" |
| 662 | chmod u+w "$refused" |
| 663 | grep -q "scratch directory under $refused, which TMPDIR names" "$work/last.out" \ |
| 664 | || die "an unwritable scratch root was not reported as one: $(cat "$work/last.out")" |
| 665 | forget c10 |
| 666 | holds "an unwritable scratch root names the path and where it came from" |
| 667 | |
| 668 | # ---------------------------------------------------------------------- |
| 669 | say "12. a floor the instance repository does not carry names the directory looked in" |
| 670 | |
| 671 | # The deployment failure this guards is a controller pointed at the wrong |
| 672 | # directory: the floor is somewhere, and not where this controller looked. |
| 673 | # The report has to name the repository, the directory and the ref, because |
| 674 | # those three are what the operator compares against the repository in front |
| 675 | # of them. A floor is either not there at all, or there under a name that |
| 676 | # holds no documents, and both arrive that way. |
| 677 | # |
| 678 | # A missing floor is refused rather than read as requiring nothing, which is |
| 679 | # the direction the other layer's absence defaults in (dcr-f41f718). The |
| 680 | # refusal says why in its own sentence, because the operator reading it is |
| 681 | # being told that the deployment is not one that can land anything. |
| 682 | git checkout --quiet main |
| 683 | git pull --quiet --ff-only origin main |
| 684 | git checkout --quiet -b c11 |
| 685 | echo "a change judged under no floor" > docs/readme.md |
| 686 | git add -A |
| 687 | git commit --quiet -m "a change whose floor the controller cannot find" |
| 688 | attest_change c11 "" "" --check prose-format |
| 689 | request c11 main "$(git rev-parse c11)" |
| 690 | |
| 691 | # The sentence every refusal to find a floor ends with. |
| 692 | unwritten="a valley without a written floor is not a valley whose changes land" |
| 693 | |
| 694 | floorless() { |
| 695 | integrator reconcile \ |
| 696 | --repo "$origin" \ |
| 697 | --key "$work/integrator" --name "$integrator_name" \ |
| 698 | --known-signers "$work/known_signers" "$@" \ |
| 699 | --schema "$SCHEMA_VERIFICATION" \ |
| 700 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 701 | --event-schema "$SCHEMA_EVENTS" \ |
| 702 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 703 | 2>&1 | tee "$work/last.out" |
| 704 | } |
| 705 | |
| 706 | # The project's own repository carries policy/project and no policy/instance, |
| 707 | # so the default directory is not there. |
| 708 | floorless --instance-repo "$origin" || true |
| 709 | grep -qF "no instance policy layer: $origin has no policy/instance/ at refs/heads/main: $unwritten" "$work/last.out" \ |
| 710 | || die "a missing floor did not name the directory looked in, and why that is refused: $(cat "$work/last.out")" |
| 711 | |
| 712 | # And the flat layout, which is a directory that exists and holds no |
| 713 | # documents of its own: policy/ has the two layers under it and no *.cue in |
| 714 | # it. Said as that, rather than as an empty composition further on. |
| 715 | # |
| 716 | # Under a second request name, because the refusal above is now this |
| 717 | # controller's recorded answer to c11 and it stands until the request, the |
| 718 | # tip or the evidence moves — which is scenario 14's whole subject. A |
| 719 | # request is what an answer is remembered against, so a second one asks the |
| 720 | # question again. |
| 721 | request c11-flat main "$(git rev-parse c11)" |
| 722 | floorless --instance-repo "$origin" --instance-policy policy || true |
| 723 | grep -qF "no instance policy layer: $origin holds no *.cue in policy/ at refs/heads/main: $unwritten" "$work/last.out" \ |
| 724 | || die "a floor directory holding no documents did not say so: $(cat "$work/last.out")" |
| 725 | |
| 726 | # And the materialized layer, which is how a host that serves no instance |
| 727 | # repository is given the floor. A directory with nothing in it is the same |
| 728 | # absence and is refused the same way. |
| 729 | request c11-bare main "$(git rev-parse c11)" |
| 730 | nofloor="$work/no-floor-here" |
| 731 | mkdir -p "$nofloor" |
| 732 | floorless --instance "$nofloor" || true |
| 733 | grep -qF "no instance policy layer: $nofloor holds no *.cue: $unwritten" "$work/last.out" \ |
| 734 | || die "an empty materialized floor was not refused: $(cat "$work/last.out")" |
| 735 | forget c11 |
| 736 | forget c11-flat |
| 737 | forget c11-bare |
| 738 | holds "a floor that is not where the controller looked names the repository, the directory and the ref" |
| 739 | |
| 740 | # ---------------------------------------------------------------------- |
| 741 | say "13. a change the policy requires no check of lands, and says so" |
| 742 | |
| 743 | # Requiring nothing is an ordinary outcome, not an edge: this project's |
| 744 | # classes cover docs/, src/ and deploy/, and its `unclassified` set is |
| 745 | # empty, so a path outside all three is answered with nothing owed. The |
| 746 | # landing still writes a transfer statement — a commit point that records |
| 747 | # nothing is a landing nothing attests to — and that statement says the |
| 748 | # required set was empty rather than carrying a list with nothing in it, |
| 749 | # which has no written form at all. |
| 750 | git checkout --quiet main |
| 751 | git pull --quiet --ff-only origin main |
| 752 | git checkout --quiet -b c12 |
| 753 | echo "outside every class this policy covers" > notes.txt |
| 754 | git add -A |
| 755 | git commit --quiet -m "a change no class covers" |
| 756 | request c12 main "$(git rev-parse c12)" |
| 757 | integrate |
| 758 | grep -q '^c12 -> refs/heads/main .*: land$' "$work/last.out" \ |
| 759 | || die "a change with nothing required did not land: $(cat "$work/last.out")" |
| 760 | grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \ |
| 761 | || die "the verdict did not say the policy required nothing" |
| 762 | [ "$(tip)" = "$(git rev-parse c12)" ] || die "c12 did not land" |
| 763 | git -C "$origin" rev-parse --verify --quiet "refs/the-valley/integration-requests/main/c12" > /dev/null \ |
| 764 | && die "the request ref survived the landing" |
| 765 | |
| 766 | nothing="refs/the-valley/attestations/$(attest digest --repo "$repo" --rev c12 | cut -d: -f2)/$ihash" |
| 767 | git -C "$origin" cat-file blob "$nothing:transfer.note" > "$work/nothing.note" |
| 768 | grep -qx 'predicate.required none' "$work/nothing.note" \ |
| 769 | || die "the transfer statement does not say the required set was empty: $(cat "$work/nothing.note")" |
| 770 | grep -q '^predicate.checks' "$work/nothing.note" \ |
| 771 | && die "the transfer statement carries a check list beside the empty-set line" |
| 772 | attest verify --note "$work/nothing.note" --known-keys "$work/reader_keys" \ |
| 773 | --repo "$repo" --rev c12 --signer "$integrator_name" > /dev/null \ |
| 774 | || die "the transfer statement for a landing with nothing required does not verify" |
| 775 | holds "a landing with no required checks is signed, stored, and consumed its request" |
| 776 | |
| 777 | # ---------------------------------------------------------------------- |
| 778 | say "14. a request the controller cannot judge is reported once, not every tick" |
| 779 | |
| 780 | # The failure this guards is the one that turns a broken deployment into a |
| 781 | # broken deployment nobody can read: a pass that cannot act on its verdict, |
| 782 | # retried at tick rate, filling the journal with one refusal per interval |
| 783 | # forever. The same request, tip and evidence produce the same failure, so |
| 784 | # repeating it says nothing new. It is reported once and then the answer |
| 785 | # stands, exactly as an outcome stands. |
| 786 | git checkout --quiet main |
| 787 | git pull --quiet --ff-only origin main |
| 788 | git checkout --quiet -b c13 |
| 789 | echo "a change judged under no floor, repeatedly" > docs/readme.md |
| 790 | git add -A |
| 791 | git commit --quiet -m "a change whose floor the controller cannot find, under watch" |
| 792 | attest_change c13 "" "" --check prose-format |
| 793 | request c13 main "$(git rev-parse c13)" |
| 794 | |
| 795 | # Five seconds at a one-second tick: five passes over one request the |
| 796 | # controller cannot judge. |
| 797 | timeout 5 integrator watch --interval 1s \ |
| 798 | --repo "$origin" \ |
| 799 | --key "$work/integrator" --name "$integrator_name" \ |
| 800 | --known-signers "$work/known_signers" \ |
| 801 | --instance-repo "$origin" --instance-policy policy \ |
| 802 | --schema "$SCHEMA_VERIFICATION" \ |
| 803 | --attest-schema "$SCHEMA_ATTESTATION" \ |
| 804 | --event-schema "$SCHEMA_EVENTS" \ |
| 805 | ${VALLEY_E2E_NOW:+--now "$VALLEY_E2E_NOW"} \ |
| 806 | > "$work/repeat.out" 2>&1 || true |
| 807 | reports="$(grep -c 'no instance policy layer' "$work/repeat.out" || true)" |
| 808 | [ "$reports" -eq 1 ] \ |
| 809 | || die "the same refusal was reported $reports times over five ticks: $(cat "$work/repeat.out")" |
| 810 | forget c13 |
| 811 | holds "a failure a pass cannot get past is reported once and then backs off" |
| 812 | |
| 813 | # ---------------------------------------------------------------------- |
| 814 | say "15. a target that carries no project layer of its own is judged under the floor alone" |
| 815 | |
| 816 | # The bootstrap this guards is the first policy commit: a project that has |
| 817 | # not written a layer yet cannot land the commit that writes one, because a |
| 818 | # change never supplies the policy that gates it. The project layer only |
| 819 | # ever adds (dcr-f41f718), so its absence adds nothing, and what is left is |
| 820 | # the floor — which still governs, and is observed governing here. |
| 821 | |
| 822 | # The floor grows a requirement of its own first, so that what remains after |
| 823 | # the project layer goes away is something rather than nothing. |
| 824 | cat > "$floor/policy/instance/floor.cue" <<'EOF' |
| 825 | package verification |
| 826 | |
| 827 | floor: { |
| 828 | checks: "prose-format": {runner: "nix", attribute: "prose-format"} |
| 829 | classes: prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 830 | unclassified: {} |
| 831 | } |
| 832 | EOF |
| 833 | git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/" |
| 834 | git -C "$floor" push --quiet "$instance_repo" main |
| 835 | |
| 836 | # The project stops carrying a layer. Nothing classifies policy/project |
| 837 | # itself, so this lands with nothing owed — which is how a project could |
| 838 | # have arrived without one in the first place. |
| 839 | git checkout --quiet main |
| 840 | git pull --quiet --ff-only origin main |
| 841 | git checkout --quiet -b c14 |
| 842 | git rm --quiet -r policy/project |
| 843 | git commit --quiet -m "stop carrying a project policy layer" |
| 844 | request c14 main "$(git rev-parse c14)" |
| 845 | integrate |
| 846 | grep -q "^c14 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 847 | || die "dropping the project layer did not land: $(cat "$work/last.out")" |
| 848 | |
| 849 | git checkout --quiet main |
| 850 | git pull --quiet --ff-only origin main |
| 851 | [ ! -e policy/project ] || die "the project layer is still at the tip; the scenario proves nothing" |
| 852 | git checkout --quiet -b c15 |
| 853 | echo "a readme judged under the floor alone" > docs/readme.md |
| 854 | git add -A |
| 855 | git commit --quiet -m "a change to a project that declares no policy of its own" |
| 856 | attest_change c15 "" "" --check prose-format |
| 857 | request c15 main "$(git rev-parse c15)" |
| 858 | integrate |
| 859 | grep -q "^c15 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 860 | || die "a change to a project with no layer of its own did not land: $(cat "$work/last.out")" |
| 861 | grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \ |
| 862 | || die "the pass did not say it composed the floor alone" |
| 863 | grep -q "check prose-format .*transferred" "$work/last.out" \ |
| 864 | || die "the floor's own requirement did not govern a project with no layer" |
| 865 | [ "$(tip)" = "$(git rev-parse c15)" ] || die "main is not at the change's head" |
| 866 | holds "no project layer is no addition; the floor alone required prose-format and the change landed" |
| 867 | |
| 868 | # ---------------------------------------------------------------------- |
| 869 | say "16. a floor that requires nothing, written down, composes and judges" |
| 870 | |
| 871 | # Emptiness a floor states is not the same thing as a floor nobody wrote. |
| 872 | # The document is there, somebody landed it, and what it composes to is a |
| 873 | # policy that requires nothing — so a change under it lands owing nothing, |
| 874 | # rather than being refused the way scenario 12's missing floor is. |
| 875 | cat > "$floor/policy/instance/floor.cue" <<'EOF' |
| 876 | package verification |
| 877 | |
| 878 | floor: { |
| 879 | checks: {} |
| 880 | classes: {} |
| 881 | unclassified: {} |
| 882 | } |
| 883 | EOF |
| 884 | git -C "$floor" commit --quiet -am "the floor requires nothing, and says so" |
| 885 | git -C "$floor" push --quiet "$instance_repo" main |
| 886 | |
| 887 | git checkout --quiet main |
| 888 | git pull --quiet --ff-only origin main |
| 889 | git checkout --quiet -b c16 |
| 890 | echo "a readme under a floor that requires nothing" > docs/readme.md |
| 891 | git add -A |
| 892 | git commit --quiet -m "a change under an empty floor and no project layer" |
| 893 | request c16 main "$(git rev-parse c16)" |
| 894 | integrate |
| 895 | grep -q "^c16 -> refs/heads/main .*: land$" "$work/last.out" \ |
| 896 | || die "a change under an explicitly empty floor did not land: $(cat "$work/last.out")" |
| 897 | grep -q 'the policy requires no check of the paths this change touches' "$work/last.out" \ |
| 898 | || die "the verdict did not say the policy required nothing" |
| 899 | grep -qF "policy no project layer at policy/project; the floor alone" "$work/last.out" \ |
| 900 | || die "the pass did not say it composed the floor alone" |
| 901 | [ "$(tip)" = "$(git rev-parse c16)" ] || die "main is not at the change's head" |
| 902 | holds "a floor that states it requires nothing composes, judges, and lands the change owing nothing" |
| 903 | |
| 904 | # ---------------------------------------------------------------------- |
| 905 | say "17. a planted replacement ref changes nothing the controller reads" |
| 906 | |
| 907 | # refs/replace/<id> makes git read another object wherever it looks <id> up. |
| 908 | # Two are planted here, and each alone would land a change that owes |
| 909 | # evidence and carries none. One swaps the floor's blob in the instance |
| 910 | # repository for a floor that requires nothing. The other swaps the change's |
| 911 | # head in the served repository for a commit that touches no class. Neither |
| 912 | # moves a ref the controller watches. A controller that left replacement |
| 913 | # refs on would read both and land the change; this one reads the objects |
| 914 | # the refs actually name, and holds the change stale. |
| 915 | cat > "$floor/policy/instance/floor.cue" <<'EOF' |
| 916 | package verification |
| 917 | |
| 918 | floor: { |
| 919 | checks: "prose-format": {runner: "nix", attribute: "prose-format"} |
| 920 | classes: prose: {paths: "docs/**": true, requires: "prose-format": true} |
| 921 | unclassified: {} |
| 922 | } |
| 923 | EOF |
| 924 | git -C "$floor" commit --quiet -am "the floor requires prose-format of docs/ again" |
| 925 | git -C "$floor" push --quiet "$instance_repo" main |
| 926 | landed_floor="$(git -C "$instance_repo" rev-parse main:policy/instance/floor.cue)" |
| 927 | empty_floor="$(git -C "$instance_repo" rev-parse main~1:policy/instance/floor.cue)" |
| 928 | git -C "$instance_repo" update-ref "refs/replace/$landed_floor" "$empty_floor" |
| 929 | git -C "$instance_repo" show main:policy/instance/floor.cue | grep 'checks: {}' > /dev/null \ |
| 930 | || die "the floor's replacement did not take, so this scenario proves nothing" |
| 931 | |
| 932 | git checkout --quiet main |
| 933 | git pull --quiet --ff-only origin main |
| 934 | git checkout --quiet -b c17-decoy |
| 935 | echo "a note no class covers" > notes.txt |
| 936 | git commit --quiet -am "a decoy that touches no class" |
| 937 | git checkout --quiet main |
| 938 | git checkout --quiet -b c17 |
| 939 | echo "a readme no evidence covers" > docs/readme.md |
| 940 | git commit --quiet -am "a change that owes prose-format and carries no evidence" |
| 941 | git push --quiet origin c17 c17-decoy |
| 942 | git -C "$origin" update-ref "refs/replace/$(git rev-parse c17)" "$(git rev-parse c17-decoy)" |
| 943 | git -C "$origin" diff --name-only main c17 | grep -x notes.txt > /dev/null \ |
| 944 | || die "the head's replacement did not take, so this scenario proves nothing" |
| 945 | request c17 main "$(git rev-parse c17)" |
| 946 | |
| 947 | # The environment asks for replacement refs too, and is not listened to. |
| 948 | before="$(tip)" |
| 949 | GIT_CONFIG_PARAMETERS="'core.usereplacerefs'='true'" integrate |
| 950 | grep -q "^c17 -> refs/heads/main .*: stale$" "$work/last.out" \ |
| 951 | || die "a planted replacement ref decided the verdict: $(cat "$work/last.out")" |
| 952 | grep -q "check prose-format" "$work/last.out" \ |
| 953 | || die "the landed floor's requirement was not what the controller read" |
| 954 | grep -q 'no attestation for this check accompanies the change' "$work/last.out" \ |
| 955 | || die "the missing evidence was not reported" |
| 956 | [ "$(tip)" = "$before" ] || die "main moved under a change that owes evidence" |
| 957 | git -C "$instance_repo" update-ref -d "refs/replace/$landed_floor" |
| 958 | git -C "$origin" update-ref -d "refs/replace/$(git rev-parse c17)" |
| 959 | forget c17 |
| 960 | holds "the floor and the change were read as landed and as pushed, past both replacements" |
| 961 | |
| 962 | printf '\nintegrator-e2e: every scenario held\n' |