| 1 | { |
| 2 | description = "the-valley: the CUE domain schema for a valley host, and the NixOS module that installs one"; |
| 3 | |
| 4 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; |
| 5 | |
| 6 | outputs = |
| 7 | { self, nixpkgs }: |
| 8 | let |
| 9 | lib = nixpkgs.lib; |
| 10 | # Checks use import-from-derivation (the module's cue export), so they |
| 11 | # are only defined for the system that can actually build them here. |
| 12 | systems = [ "x86_64-linux" ]; |
| 13 | |
| 14 | # The integrator's CLI (bin/valley) wrapped for `nix run`. The script |
| 15 | # itself must keep running bare from any checkout — the package is the |
| 16 | # second of its two shipping modes, never a dependency of the first. |
| 17 | valleyScriptFor = |
| 18 | pkgs: |
| 19 | pkgs.writeShellApplication { |
| 20 | name = "valley"; |
| 21 | runtimeInputs = [ |
| 22 | pkgs.git |
| 23 | pkgs.natscli # tail and replay only; every other verb needs just git |
| 24 | pkgs.cue # checks only — it composes the policy layers |
| 25 | pkgs.less # review only — its v key is what takes a note |
| 26 | ]; |
| 27 | text = builtins.readFile ./bin/valley; |
| 28 | }; |
| 29 | |
| 30 | # The installed package: the wrapped script plus the shell completions, |
| 31 | # at the standard paths home-manager/NixOS auto-link. |
| 32 | valleyCliFor = |
| 33 | pkgs: |
| 34 | pkgs.symlinkJoin { |
| 35 | name = "valley"; |
| 36 | paths = [ (valleyScriptFor pkgs) ]; |
| 37 | nativeBuildInputs = [ pkgs.installShellFiles ]; |
| 38 | postBuild = '' |
| 39 | installShellCompletion --bash --name valley ${./completions/valley.bash} |
| 40 | installShellCompletion --zsh --name _valley ${./completions/_valley} |
| 41 | ''; |
| 42 | }; |
| 43 | |
| 44 | # Markdown prose is filled paragraphs hard-wrapped at 100 columns |
| 45 | # (ida-1ec03b1). One prettier invocation backs both the formatter app |
| 46 | # and the prose-format check, so the two cannot drift. |
| 47 | # Embedded-language formatting is off so fenced code blocks pass |
| 48 | # through byte-for-byte. |
| 49 | proseFmtArgs = "--prose-wrap always --print-width 100 --embedded-language-formatting off"; |
| 50 | |
| 51 | # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns. |
| 52 | proseFmtFor = |
| 53 | pkgs: |
| 54 | pkgs.writeShellApplication { |
| 55 | name = "valley-fmt"; |
| 56 | runtimeInputs = [ |
| 57 | pkgs.git |
| 58 | pkgs.prettier |
| 59 | ]; |
| 60 | text = '' |
| 61 | cd "$(git rev-parse --show-toplevel)" |
| 62 | git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \ |
| 63 | prettier ${proseFmtArgs} --write |
| 64 | ''; |
| 65 | }; |
| 66 | |
| 67 | # The Phase 2 attestation helper (dcr-0de694f). Go, standard library |
| 68 | # only, note format included — hence vendorHash = null, and hence no |
| 69 | # module fetch at build time. Its unit tests run in the checkPhase and |
| 70 | # need git and ssh-keygen. |
| 71 | attestUnwrappedFor = |
| 72 | pkgs: |
| 73 | pkgs.buildGoModule { |
| 74 | pname = "valley-attest"; |
| 75 | version = "0"; |
| 76 | src = ./attest; |
| 77 | vendorHash = null; |
| 78 | nativeCheckInputs = [ |
| 79 | pkgs.git |
| 80 | pkgs.openssh |
| 81 | ]; |
| 82 | meta.mainProgram = "attest"; |
| 83 | }; |
| 84 | |
| 85 | # The shipping form. git and cue are pinned to this flake's nixpkgs, |
| 86 | # so every host composes and vets a statement with the same tools. |
| 87 | # Signing needs no tool at all: a note is signed on crypto/ed25519 |
| 88 | # inside the binary. `nix` is deliberately NOT pinned: the check being |
| 89 | # attested to must be built by the nix the machine actually runs, and |
| 90 | # a nix carried in here would be a second one. |
| 91 | attestFor = |
| 92 | pkgs: |
| 93 | pkgs.runCommand "valley-attest" |
| 94 | { |
| 95 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 96 | meta.mainProgram = "attest"; |
| 97 | } |
| 98 | '' |
| 99 | mkdir -p $out/bin |
| 100 | makeWrapper ${lib.getExe (attestUnwrappedFor pkgs)} $out/bin/attest \ |
| 101 | --prefix PATH : ${ |
| 102 | lib.makeBinPath [ |
| 103 | pkgs.git |
| 104 | pkgs.cue |
| 105 | ] |
| 106 | } \ |
| 107 | --set-default VALLEY_ATTEST_SCHEMA ${./schema/attestation.cue} |
| 108 | ''; |
| 109 | |
| 110 | # The Phase 3 integrator (dcr-439b771). Go, standard library only, |
| 111 | # same trade as attest — hence vendorHash = null and no module fetch. |
| 112 | integratorUnwrappedFor = |
| 113 | pkgs: |
| 114 | pkgs.buildGoModule { |
| 115 | pname = "valley-integrator"; |
| 116 | version = "0"; |
| 117 | src = ./integrator; |
| 118 | vendorHash = null; |
| 119 | meta.mainProgram = "integrator"; |
| 120 | }; |
| 121 | |
| 122 | # The shipping form. The integrator drives four programs rather than |
| 123 | # reimplementing what they do: attest judges every statement and |
| 124 | # every note, the valley deriver and cue compose the policy, and git |
| 125 | # holds the requests and the refs. All four are pinned to this |
| 126 | # flake's nixpkgs so an instance's integrators agree; `nix` is |
| 127 | # deliberately absent for the same reason it is absent from attest — |
| 128 | # a closure must be recomputed by the nix the machine actually runs. |
| 129 | integratorFor = |
| 130 | pkgs: |
| 131 | pkgs.runCommand "valley-integrator" |
| 132 | { |
| 133 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 134 | meta.mainProgram = "integrator"; |
| 135 | } |
| 136 | '' |
| 137 | mkdir -p $out/bin |
| 138 | makeWrapper ${lib.getExe (integratorUnwrappedFor pkgs)} $out/bin/integrator \ |
| 139 | --prefix PATH : ${ |
| 140 | lib.makeBinPath [ |
| 141 | pkgs.git |
| 142 | pkgs.cue |
| 143 | pkgs.natscli |
| 144 | (attestFor pkgs) |
| 145 | (valleyScriptFor pkgs) |
| 146 | ] |
| 147 | } \ |
| 148 | --set-default VALLEY_ATTEST_SCHEMA ${./schema/attestation.cue} \ |
| 149 | --set-default VALLEY_VERIFICATION_SCHEMA ${./schema/verification.cue} \ |
| 150 | --set-default VALLEY_EVENT_SCHEMA ${./schema/events.cue} |
| 151 | ''; |
| 152 | in |
| 153 | { |
| 154 | nixosModules.valley-host = ./nix/valley-host.nix; |
| 155 | nixosModules.default = self.nixosModules.valley-host; |
| 156 | |
| 157 | # The knowledge lint, for any project that keeps a `.the-valley/` graph. |
| 158 | # This is the check's primary form: a consuming project takes this flake |
| 159 | # as an input and instantiates the derivation over its own source, so the |
| 160 | # check a policy names is supplied by the instance rather than written |
| 161 | # again by every project the policy covers (dcr-f41f718). A whole |
| 162 | # consuming flake is: |
| 163 | # |
| 164 | # { |
| 165 | # inputs.the-valley.url = "github:gunk-dev/the-valley"; |
| 166 | # outputs = |
| 167 | # { self, the-valley }: |
| 168 | # { |
| 169 | # checks.x86_64-linux.knowledge-lint = the-valley.lib.knowledgeLint { |
| 170 | # system = "x86_64-linux"; |
| 171 | # src = self; |
| 172 | # }; |
| 173 | # }; |
| 174 | # } |
| 175 | # |
| 176 | # There is no nixpkgs input in that flake on purpose: cue and python come |
| 177 | # from this flake's pinned nixpkgs, so every project in a group runs the |
| 178 | # same lint against the same toolchain. `root` names the graph directory |
| 179 | # for a project that keeps its graph somewhere other than `.the-valley/`. |
| 180 | lib.knowledgeLint = |
| 181 | { |
| 182 | system, |
| 183 | src, |
| 184 | root ? ".the-valley", |
| 185 | }: |
| 186 | import ./nix/knowledge-lint.nix { |
| 187 | inherit src root; |
| 188 | pkgs = nixpkgs.legacyPackages.${system}; |
| 189 | }; |
| 190 | |
| 191 | apps = lib.genAttrs systems (system: { |
| 192 | fmt = { |
| 193 | type = "app"; |
| 194 | program = lib.getExe (proseFmtFor nixpkgs.legacyPackages.${system}); |
| 195 | }; |
| 196 | attest = { |
| 197 | type = "app"; |
| 198 | program = lib.getExe (attestFor nixpkgs.legacyPackages.${system}); |
| 199 | }; |
| 200 | integrator = { |
| 201 | type = "app"; |
| 202 | program = lib.getExe (integratorFor nixpkgs.legacyPackages.${system}); |
| 203 | }; |
| 204 | }); |
| 205 | |
| 206 | packages = lib.genAttrs systems ( |
| 207 | system: |
| 208 | let |
| 209 | valley = valleyCliFor nixpkgs.legacyPackages.${system}; |
| 210 | in |
| 211 | { |
| 212 | inherit valley; |
| 213 | default = valley; |
| 214 | attest = attestFor nixpkgs.legacyPackages.${system}; |
| 215 | integrator = integratorFor nixpkgs.legacyPackages.${system}; |
| 216 | } |
| 217 | ); |
| 218 | |
| 219 | checks = lib.genAttrs systems ( |
| 220 | system: |
| 221 | let |
| 222 | pkgs = nixpkgs.legacyPackages.${system}; |
| 223 | |
| 224 | # Eval-only instantiation of the module — catches option-surface |
| 225 | # and cue-export regressions without building or booting anything. |
| 226 | # Each check host shares the machine baseline and supplies its own |
| 227 | # declaration (and, where the declaration asks for backup, the |
| 228 | # secret paths). |
| 229 | mkHost = |
| 230 | module: |
| 231 | lib.nixosSystem { |
| 232 | inherit system; |
| 233 | modules = [ |
| 234 | self.nixosModules.default |
| 235 | { |
| 236 | fileSystems."/" = { |
| 237 | device = "/dev/disk/by-label/nixos"; |
| 238 | fsType = "ext4"; |
| 239 | }; |
| 240 | boot.loader.grub.enable = false; |
| 241 | system.stateVersion = "25.11"; |
| 242 | services.valley = { |
| 243 | enable = true; |
| 244 | authorizedKeys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck0 valley-check" ]; |
| 245 | }; |
| 246 | } |
| 247 | module |
| 248 | ]; |
| 249 | }; |
| 250 | |
| 251 | # The example declaration enables backup, so this host supplies |
| 252 | # the four secret paths (eval-only placeholders). |
| 253 | host = mkHost { |
| 254 | services.valley = { |
| 255 | config = ./examples/host.cue; |
| 256 | backup = { |
| 257 | repositoryFile = "/run/agenix/valley-restic-repo"; |
| 258 | passwordFile = "/run/agenix/valley-restic-password"; |
| 259 | sshKeyFile = "/run/agenix/valley-git-ssh-key"; |
| 260 | knownHostsFile = "/var/lib/valley-backup/known_hosts"; |
| 261 | }; |
| 262 | }; |
| 263 | }; |
| 264 | |
| 265 | # A declaration without a backup block predates the field and must |
| 266 | # keep evaluating exactly as before: zero restic machinery. |
| 267 | noBackupHost = mkHost { |
| 268 | services.valley.config = pkgs.writeText "no-backup-host.cue" '' |
| 269 | package valley |
| 270 | projects: "the-valley": {} |
| 271 | ''; |
| 272 | }; |
| 273 | |
| 274 | # The example declaration with the secret paths left unset: the |
| 275 | # module must refuse with assertions naming the missing options. |
| 276 | noSecretsHost = mkHost { |
| 277 | services.valley.config = ./examples/host.cue; |
| 278 | }; |
| 279 | |
| 280 | # Bus enabled, minimal declaration. The bus-e2e check drives this |
| 281 | # host's rendered hooks and stream-init against a real server. |
| 282 | busHost = mkHost { |
| 283 | services.valley = { |
| 284 | config = pkgs.writeText "bus-host.cue" '' |
| 285 | package valley |
| 286 | projects: "events-pilot": {} |
| 287 | ''; |
| 288 | bus.enable = true; |
| 289 | }; |
| 290 | }; |
| 291 | |
| 292 | # Two mirror URLs the sandbox can serve: git resolves a relative |
| 293 | # URL against the pushing repo's directory, so the mirror-e2e |
| 294 | # check drives the rendered script with no substitution at all — |
| 295 | # one reachable sibling repo, one that does not exist. |
| 296 | mirrorHost = mkHost { |
| 297 | services.valley.config = pkgs.writeText "mirror-host.cue" '' |
| 298 | package valley |
| 299 | projects: "mirror-pilot": mirrors: ["../mirror.git"] |
| 300 | projects: "dead-mirror": mirrors: ["../nope.git"] |
| 301 | ''; |
| 302 | }; |
| 303 | |
| 304 | # Write protection declared: one project taking the default |
| 305 | # protected set, one naming a glob beside it, and one left open. |
| 306 | # The baseline key above is anonymous and stays in the list, so |
| 307 | # this host also renders the two forms of key side by side. |
| 308 | protectedHost = mkHost { |
| 309 | services.valley = { |
| 310 | config = pkgs.writeText "protected-host.cue" '' |
| 311 | package valley |
| 312 | projects: "guarded": {} |
| 313 | projects: "released": {} |
| 314 | projects: "open": {} |
| 315 | ''; |
| 316 | authorizedKeys = [ |
| 317 | { |
| 318 | principal = "integrator"; |
| 319 | key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck1 integrator"; |
| 320 | } |
| 321 | { |
| 322 | principal = "contributor"; |
| 323 | key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor"; |
| 324 | } |
| 325 | ]; |
| 326 | protect = { |
| 327 | guarded.writers = [ "integrator" ]; |
| 328 | released = { |
| 329 | refs = [ |
| 330 | "refs/heads/main" |
| 331 | "refs/heads/release/*" |
| 332 | ]; |
| 333 | writers = [ "integrator" ]; |
| 334 | }; |
| 335 | }; |
| 336 | }; |
| 337 | }; |
| 338 | |
| 339 | failedAssertions = builtins.filter (a: !a.assertion) ( |
| 340 | host.config.assertions |
| 341 | ++ noBackupHost.config.assertions |
| 342 | ++ busHost.config.assertions |
| 343 | ++ mirrorHost.config.assertions |
| 344 | ++ protectedHost.config.assertions |
| 345 | ); |
| 346 | |
| 347 | # Protecting a project the declaration does not serve is a typo |
| 348 | # the module must refuse rather than silently ignore. |
| 349 | strayProtectionHost = mkHost { |
| 350 | services.valley = { |
| 351 | config = pkgs.writeText "stray-protection-host.cue" '' |
| 352 | package valley |
| 353 | projects: "guarded": {} |
| 354 | ''; |
| 355 | protect.gaurded.writers = [ "integrator" ]; |
| 356 | }; |
| 357 | }; |
| 358 | |
| 359 | strayProtectionAssertions = builtins.filter ( |
| 360 | a: !a.assertion |
| 361 | ) strayProtectionHost.config.assertions; |
| 362 | |
| 363 | protectedKeyLines = protectedHost.config.users.users.git.openssh.authorizedKeys.keys; |
| 364 | |
| 365 | # A declaration written before these options renders the host it |
| 366 | # always did: no hook wired, no tag on a key, no sshd change. It |
| 367 | # still carries the sweep that removes a hook it once had — the |
| 368 | # same discipline the mirror and bus hooks keep, and the only way |
| 369 | # protection can be turned off by editing a declaration. |
| 370 | protectionRenderedWithoutDeclaration = |
| 371 | noBackupHost.config.services.openssh.settings ? PermitUserEnvironment |
| 372 | || lib.any (lib.hasInfix "environment=") ( |
| 373 | noBackupHost.config.users.users.git.openssh.authorizedKeys.keys |
| 374 | ) |
| 375 | || lib.hasInfix "valley-protect-" noBackupHost.config.systemd.services.valley-init.script; |
| 376 | |
| 377 | missingSecretAssertions = builtins.filter (a: !a.assertion) noSecretsHost.config.assertions; |
| 378 | |
| 379 | resticRenderedWithoutDeclaration = |
| 380 | noBackupHost.config.systemd.services ? "restic-backups-valley" |
| 381 | || noBackupHost.config.systemd.timers ? "restic-backups-valley"; |
| 382 | |
| 383 | # The bus defaults off; a host that never asked for one must |
| 384 | # render zero bus machinery. |
| 385 | busRenderedWithoutEnable = |
| 386 | noBackupHost.config.systemd.services ? valley-bus |
| 387 | || noBackupHost.config.systemd.services ? valley-bus-init; |
| 388 | |
| 389 | # A tree in the store, written from a path -> contents map. The |
| 390 | # knowledge lint reads a whole graph rather than a file, so every |
| 391 | # fixture below is small but complete. |
| 392 | mkTree = |
| 393 | name: files: |
| 394 | pkgs.runCommand name { } ( |
| 395 | lib.concatStrings ( |
| 396 | lib.mapAttrsToList (path: text: '' |
| 397 | install -Dm444 ${pkgs.writeText "knowledge-lint-fixture" text} $out/${path} |
| 398 | '') files |
| 399 | ) |
| 400 | ); |
| 401 | |
| 402 | # A project that is nearly nothing: a README, a docs directory, and |
| 403 | # five nodes carrying one of each typed edge. This is the shape the |
| 404 | # first consuming project has, and the knowledge-lint-consumer check |
| 405 | # instantiates lib.knowledgeLint over it exactly as that project's |
| 406 | # own flake would. The nodes created on or before the id-rule |
| 407 | # cutoff carry ids their slugs do not derive, and must pass anyway; |
| 408 | # the graduated idea postdates the cutoff and carries the derived |
| 409 | # id its slug demands. |
| 410 | consumerProject = mkTree "knowledge-lint-consumer-project" { |
| 411 | "README.md" = '' |
| 412 | # A project |
| 413 | |
| 414 | It keeps its knowledge in [.the-valley](./.the-valley/). |
| 415 | ''; |
| 416 | "docs/design.md" = '' |
| 417 | # Design |
| 418 | |
| 419 | ## The shape |
| 420 | ''; |
| 421 | ".the-valley/ideas/ida-0a1b2c3-the-shape.md" = '' |
| 422 | --- |
| 423 | type: idea |
| 424 | id: ida-0a1b2c3 |
| 425 | status: raw |
| 426 | title: The shape the design should take |
| 427 | created: 2026-08-02 |
| 428 | --- |
| 429 | |
| 430 | # The shape the design should take |
| 431 | |
| 432 | As sketched in [design.md](../../docs/design.md#the-shape). |
| 433 | ''; |
| 434 | ".the-valley/outcomes/oc-4d5e6f7-the-design-lands.md" = '' |
| 435 | --- |
| 436 | type: outcome |
| 437 | id: oc-4d5e6f7 |
| 438 | status: open |
| 439 | title: The design lands |
| 440 | created: 2026-08-02 |
| 441 | blocked_by: [ida-0a1b2c3] |
| 442 | --- |
| 443 | |
| 444 | # The design lands |
| 445 | |
| 446 | Waits on [[ida-0a1b2c3]]. |
| 447 | ''; |
| 448 | ".the-valley/decisions/dcr-1122334-where-the-graph-lives.md" = '' |
| 449 | --- |
| 450 | type: decision |
| 451 | id: dcr-1122334 |
| 452 | status: superseded |
| 453 | title: Where the graph lives |
| 454 | created: 2026-08-02 |
| 455 | --- |
| 456 | |
| 457 | # Where the graph lives |
| 458 | |
| 459 | The graph is a directory of markdown files under the project root. |
| 460 | ''; |
| 461 | ".the-valley/decisions/dcr-5566778-where-the-graph-lives.md" = '' |
| 462 | --- |
| 463 | type: decision |
| 464 | id: dcr-5566778 |
| 465 | status: decided |
| 466 | title: Where the graph lives |
| 467 | created: 2026-08-02 |
| 468 | supersedes: [dcr-1122334] |
| 469 | --- |
| 470 | |
| 471 | # Where the graph lives |
| 472 | |
| 473 | The graph is a directory of markdown files at `.the-valley/`, alongside the code. |
| 474 | ''; |
| 475 | # sha256("the-shape-graduates") begins ba2b574. |
| 476 | ".the-valley/ideas/ida-ba2b574-the-shape-graduates.md" = '' |
| 477 | --- |
| 478 | type: idea |
| 479 | id: ida-ba2b574 |
| 480 | status: graduated |
| 481 | title: An idea whose thinking now lives in a decision |
| 482 | created: 2026-08-06 |
| 483 | graduated_into: dcr-5566778 |
| 484 | --- |
| 485 | |
| 486 | # An idea whose thinking now lives in a decision |
| 487 | |
| 488 | Graduated into [[dcr-5566778]]. |
| 489 | ''; |
| 490 | }; |
| 491 | |
| 492 | # A project with no graph at all. Adding the check must not require |
| 493 | # having written a node yet, or no project would ever adopt it |
| 494 | # before its first one. |
| 495 | graphlessProject = mkTree "knowledge-lint-graphless-project" { |
| 496 | "README.md" = '' |
| 497 | # A project with no knowledge graph yet |
| 498 | ''; |
| 499 | }; |
| 500 | |
| 501 | # What the lint must reject, and the words its failure must contain. |
| 502 | # A lint that fails without naming the file and the defect costs the |
| 503 | # reader the whole diagnosis, so both are pinned. |
| 504 | rejectedGraphs = { |
| 505 | unknown-status = { |
| 506 | names = ''ida-0000001-a-node.md".status''; |
| 507 | files.".the-valley/ideas/ida-0000001-a-node.md" = '' |
| 508 | --- |
| 509 | type: idea |
| 510 | id: ida-0000001 |
| 511 | status: nonsense |
| 512 | title: A node in a state ideas do not have |
| 513 | created: 2026-08-02 |
| 514 | --- |
| 515 | ''; |
| 516 | }; |
| 517 | |
| 518 | edge-on-the-wrong-type = { |
| 519 | names = "blocked_by: field not allowed"; |
| 520 | files.".the-valley/ideas/ida-0000002-a-node.md" = '' |
| 521 | --- |
| 522 | type: idea |
| 523 | id: ida-0000002 |
| 524 | status: raw |
| 525 | title: An idea carrying the one edge only outcomes carry |
| 526 | created: 2026-08-02 |
| 527 | blocked_by: [] |
| 528 | --- |
| 529 | ''; |
| 530 | }; |
| 531 | |
| 532 | node-in-the-wrong-directory = { |
| 533 | names = "a bug node belongs in .the-valley/bugs/"; |
| 534 | files.".the-valley/ideas/bd-0000003-a-bug.md" = '' |
| 535 | --- |
| 536 | type: bug |
| 537 | id: bd-0000003 |
| 538 | status: open |
| 539 | title: A bug filed among the ideas |
| 540 | created: 2026-08-02 |
| 541 | --- |
| 542 | ''; |
| 543 | }; |
| 544 | |
| 545 | filename-id-mismatch = { |
| 546 | names = "filename says id ida-0000004, frontmatter says ida-0000005"; |
| 547 | files.".the-valley/ideas/ida-0000004-a-node.md" = '' |
| 548 | --- |
| 549 | type: idea |
| 550 | id: ida-0000005 |
| 551 | status: raw |
| 552 | title: A node whose filename and frontmatter disagree |
| 553 | created: 2026-08-02 |
| 554 | --- |
| 555 | ''; |
| 556 | }; |
| 557 | |
| 558 | duplicate-id = { |
| 559 | names = "is already used by"; |
| 560 | files = { |
| 561 | ".the-valley/ideas/ida-0000006-one.md" = '' |
| 562 | --- |
| 563 | type: idea |
| 564 | id: ida-0000006 |
| 565 | status: raw |
| 566 | title: One node |
| 567 | created: 2026-08-02 |
| 568 | --- |
| 569 | ''; |
| 570 | ".the-valley/ideas/ida-0000006-two.md" = '' |
| 571 | --- |
| 572 | type: idea |
| 573 | id: ida-0000006 |
| 574 | status: raw |
| 575 | title: Another node wearing the same id |
| 576 | created: 2026-08-02 |
| 577 | --- |
| 578 | ''; |
| 579 | }; |
| 580 | }; |
| 581 | |
| 582 | missing-frontmatter = { |
| 583 | names = "no YAML frontmatter"; |
| 584 | files.".the-valley/ideas/ida-0000007-a-node.md" = '' |
| 585 | # A node that is only prose |
| 586 | ''; |
| 587 | }; |
| 588 | |
| 589 | dangling-wiki-link = { |
| 590 | names = "[[ida-9999999]] is not a node id"; |
| 591 | files.".the-valley/ideas/ida-0000008-a-node.md" = '' |
| 592 | --- |
| 593 | type: idea |
| 594 | id: ida-0000008 |
| 595 | status: raw |
| 596 | title: A node pointing at nothing |
| 597 | created: 2026-08-02 |
| 598 | --- |
| 599 | |
| 600 | It builds on [[ida-9999999]]. |
| 601 | ''; |
| 602 | }; |
| 603 | |
| 604 | dangling-blocked-by = { |
| 605 | names = "blocked_by names oc-9999999, which is not a node"; |
| 606 | files.".the-valley/outcomes/oc-0000009-an-outcome.md" = '' |
| 607 | --- |
| 608 | type: outcome |
| 609 | id: oc-0000009 |
| 610 | status: open |
| 611 | title: An outcome waiting on nothing that exists |
| 612 | created: 2026-08-02 |
| 613 | blocked_by: [oc-9999999] |
| 614 | --- |
| 615 | ''; |
| 616 | }; |
| 617 | |
| 618 | dangling-supersedes = { |
| 619 | names = "supersedes names dcr-9999999, which is not a node"; |
| 620 | files.".the-valley/decisions/dcr-000000c-a-decision.md" = '' |
| 621 | --- |
| 622 | type: decision |
| 623 | id: dcr-000000c |
| 624 | status: decided |
| 625 | title: A decision replacing nothing that exists |
| 626 | created: 2026-08-02 |
| 627 | supersedes: [dcr-9999999] |
| 628 | --- |
| 629 | ''; |
| 630 | }; |
| 631 | |
| 632 | # The edge alone is half a supersession. A node declared replaced |
| 633 | # while its own status still reads otherwise leaves the graph |
| 634 | # saying two things, which is the defect the edge exists to end. |
| 635 | supersedes-a-node-still-standing = { |
| 636 | names = "whose status is adopted, not superseded"; |
| 637 | files = { |
| 638 | ".the-valley/ideas/ida-000000d-the-replacement.md" = '' |
| 639 | --- |
| 640 | type: idea |
| 641 | id: ida-000000d |
| 642 | status: adopted |
| 643 | title: An idea replacing one that has not been told |
| 644 | created: 2026-08-02 |
| 645 | supersedes: [ida-000000e] |
| 646 | --- |
| 647 | ''; |
| 648 | ".the-valley/ideas/ida-000000e-the-replaced.md" = '' |
| 649 | --- |
| 650 | type: idea |
| 651 | id: ida-000000e |
| 652 | status: adopted |
| 653 | title: An idea replaced in fact but not in its status |
| 654 | created: 2026-08-02 |
| 655 | --- |
| 656 | ''; |
| 657 | }; |
| 658 | }; |
| 659 | |
| 660 | supersedes-on-the-wrong-type = { |
| 661 | names = "supersedes: field not allowed"; |
| 662 | files.".the-valley/outcomes/oc-000000f-an-outcome.md" = '' |
| 663 | --- |
| 664 | type: outcome |
| 665 | id: oc-000000f |
| 666 | status: open |
| 667 | title: An outcome carrying the edge only ideas and decisions carry |
| 668 | created: 2026-08-02 |
| 669 | blocked_by: [] |
| 670 | supersedes: [] |
| 671 | --- |
| 672 | ''; |
| 673 | }; |
| 674 | |
| 675 | # Only ideas and decisions have a `superseded` status, so an edge |
| 676 | # naming any other type is rejected on shape by the schema. |
| 677 | supersedes-a-type-that-cannot-be = { |
| 678 | names = ''supersedes.0: invalid value "bd-0000011"''; |
| 679 | files.".the-valley/ideas/ida-0000010-a-node.md" = '' |
| 680 | --- |
| 681 | type: idea |
| 682 | id: ida-0000010 |
| 683 | status: adopted |
| 684 | title: An idea claiming to replace a bug |
| 685 | created: 2026-08-02 |
| 686 | supersedes: [bd-0000011] |
| 687 | --- |
| 688 | ''; |
| 689 | }; |
| 690 | |
| 691 | # The id rule: a node created after the cutoff must carry the id |
| 692 | # its slug derives, and the failure names the id it should have. |
| 693 | non-derived-id = { |
| 694 | names = "sha256 of the slug gives ida-d1d9c0c"; |
| 695 | files.".the-valley/ideas/ida-1111111-a-node.md" = '' |
| 696 | --- |
| 697 | type: idea |
| 698 | id: ida-1111111 |
| 699 | status: raw |
| 700 | title: A node whose id its slug does not derive |
| 701 | created: 2026-08-06 |
| 702 | --- |
| 703 | ''; |
| 704 | }; |
| 705 | |
| 706 | # Graduation cannot be half-declared: the status without the |
| 707 | # destination is rejected by the schema. |
| 708 | graduated-without-destination = { |
| 709 | names = "graduated_into: incomplete value"; |
| 710 | files.".the-valley/ideas/ida-d1d9c0c-a-node.md" = '' |
| 711 | --- |
| 712 | type: idea |
| 713 | id: ida-d1d9c0c |
| 714 | status: graduated |
| 715 | title: A graduated idea that does not say where it went |
| 716 | created: 2026-08-06 |
| 717 | --- |
| 718 | ''; |
| 719 | }; |
| 720 | |
| 721 | dangling-graduated-into = { |
| 722 | names = "graduated_into names dcr-9999999, which is not a node"; |
| 723 | files.".the-valley/ideas/ida-d1d9c0c-a-node.md" = '' |
| 724 | --- |
| 725 | type: idea |
| 726 | id: ida-d1d9c0c |
| 727 | status: graduated |
| 728 | title: A graduated idea naming a decision that is not there |
| 729 | created: 2026-08-06 |
| 730 | graduated_into: dcr-9999999 |
| 731 | --- |
| 732 | ''; |
| 733 | }; |
| 734 | |
| 735 | broken-link = { |
| 736 | names = "./nowhere.md does not exist"; |
| 737 | files.".the-valley/ideas/ida-000000a-a-node.md" = '' |
| 738 | --- |
| 739 | type: idea |
| 740 | id: ida-000000a |
| 741 | status: raw |
| 742 | title: A node linking to a file that is not there |
| 743 | created: 2026-08-02 |
| 744 | --- |
| 745 | |
| 746 | See [nowhere](./nowhere.md). |
| 747 | ''; |
| 748 | }; |
| 749 | |
| 750 | broken-anchor = { |
| 751 | names = "names no heading"; |
| 752 | files.".the-valley/ideas/ida-000000b-a-node.md" = '' |
| 753 | --- |
| 754 | type: idea |
| 755 | id: ida-000000b |
| 756 | status: raw |
| 757 | title: A node linking to a heading that is not there |
| 758 | created: 2026-08-02 |
| 759 | --- |
| 760 | |
| 761 | # A heading |
| 762 | |
| 763 | See [above](./ida-000000b-a-node.md#not-this-heading). |
| 764 | ''; |
| 765 | }; |
| 766 | }; |
| 767 | in |
| 768 | { |
| 769 | # The CLI must stay a lint-clean script whose help verb answers |
| 770 | # without a repo or a remote — the cheap end of its eviction clause |
| 771 | # (dcr-74c3158); anything needing more graduates instead. The |
| 772 | # completions are held to the same bar, and the installed package |
| 773 | # must carry them at the auto-linked paths. |
| 774 | valley-cli = |
| 775 | let |
| 776 | valley = valleyCliFor pkgs; |
| 777 | in |
| 778 | pkgs.runCommand "valley-cli" |
| 779 | { |
| 780 | nativeBuildInputs = [ |
| 781 | pkgs.shellcheck |
| 782 | pkgs.zsh |
| 783 | valley |
| 784 | ]; |
| 785 | } |
| 786 | '' |
| 787 | shellcheck ${./bin/valley} |
| 788 | shellcheck ${./completions/valley.bash} |
| 789 | # shellcheck cannot lint zsh; a bare parse is the cheap check. |
| 790 | zsh -n ${./completions/_valley} |
| 791 | valley help > help.txt |
| 792 | grep -q '^usage: valley' help.txt |
| 793 | test -f ${valley}/share/bash-completion/completions/valley |
| 794 | test -f ${valley}/share/zsh/site-functions/_valley |
| 795 | touch $out |
| 796 | ''; |
| 797 | |
| 798 | # review's notes: the anchors are the whole claim, so they are |
| 799 | # pinned here rather than left to the reader of bin/valley. The |
| 800 | # session is real — a pty, real less, a pager filter that |
| 801 | # restructures the diff, and an $EDITOR that inserts lines while |
| 802 | # the pager is open — because every property under test is a |
| 803 | # property of that arrangement: that v is handed the raw buffer |
| 804 | # and not the rendering, that an inserted line becomes a note, |
| 805 | # and that the file and line it names are the ones it sat on. |
| 806 | review-notes = |
| 807 | let |
| 808 | # The reviewer, as a script: four insertions and one edit of a |
| 809 | # line that was already there. The edit is deliberately far |
| 810 | # from every insertion, since -U0 would otherwise merge them |
| 811 | # into one hunk and the note would be dropped with it. |
| 812 | reviewer = pkgs.writeShellScript "valley-review-notes-editor" '' |
| 813 | f="$1" |
| 814 | case "$1" in +*) f="$2" ;; esac |
| 815 | printf 'editor got: %s\n' "$*" >> "$XDG_STATE_HOME/editor.log" |
| 816 | sed -i \ |
| 817 | -e '/^branch scratch, log against/a a note above every file' \ |
| 818 | -e '/^diff --git a\/alpha.md/a alpha reads like two files' \ |
| 819 | -e '/^+alpha 3 changed$/a why is 3 changed at all?' \ |
| 820 | -e '/^ alpha 13$/a and this hunk is fine' \ |
| 821 | -e '/^+beta 5 changed$/a beta wants the same treatment' \ |
| 822 | -e 's/^ alpha 17$/ alpha SEVENTEEN/' \ |
| 823 | "$f" |
| 824 | ''; |
| 825 | in |
| 826 | pkgs.runCommand "valley-review-notes" |
| 827 | { |
| 828 | nativeBuildInputs = [ |
| 829 | pkgs.git |
| 830 | pkgs.less |
| 831 | pkgs.util-linux # script(1), for the pty less insists on |
| 832 | (valleyScriptFor pkgs) |
| 833 | ]; |
| 834 | } |
| 835 | '' |
| 836 | export HOME="$TMPDIR" XDG_STATE_HOME="$TMPDIR/state" TERM=xterm |
| 837 | export GIT_CONFIG_NOSYSTEM=1 |
| 838 | unset VISUAL || true |
| 839 | git config --global user.name valley-check |
| 840 | git config --global user.email valley-check@localhost |
| 841 | git config --global init.defaultBranch main |
| 842 | |
| 843 | # A project with an origin and one branch to review: two |
| 844 | # files, changed twice and once, far enough apart that the |
| 845 | # diff has two hunks in the first file and one in the second. |
| 846 | git init --quiet --bare "$TMPDIR/origin.git" |
| 847 | git init --quiet "$TMPDIR/work" |
| 848 | cd "$TMPDIR/work" |
| 849 | git remote add origin "$TMPDIR/origin.git" |
| 850 | seq 1 20 | sed 's/^/alpha /' > alpha.md |
| 851 | seq 1 10 | sed 's/^/beta /' > beta.md |
| 852 | git add -A |
| 853 | git commit --quiet -m seed |
| 854 | git push --quiet -u origin main |
| 855 | git checkout --quiet -b scratch |
| 856 | sed -i -e '3s/.*/alpha 3 changed/' -e '15s/.*/alpha 15 changed/' alpha.md |
| 857 | sed -i -e '5s/.*/beta 5 changed/' beta.md |
| 858 | git commit --quiet -am "touch both files" |
| 859 | git push --quiet origin scratch |
| 860 | git checkout --quiet main |
| 861 | git fetch --quiet origin |
| 862 | |
| 863 | # A pager filter that restructures the diff, as delta's |
| 864 | # rendering does: if v were handed what less displays, every |
| 865 | # anchor below would be wrong. |
| 866 | git config --global pager.diff "sed -e 's/^/| /'" |
| 867 | export EDITOR=${reviewer} |
| 868 | mkdir -p "$XDG_STATE_HOME" |
| 869 | |
| 870 | # v opens the editor, RETURN dismisses less's LESSOPEN |
| 871 | # warning, q leaves the pager, s is the verdict. |
| 872 | { printf 'v\nq'; sleep 2; printf 's\n'; sleep 1; } \ |
| 873 | | script -qec "valley review scratch" /dev/null > session.log 2>&1 |
| 874 | sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r//g' session.log > plain.log |
| 875 | |
| 876 | # The anchors, exactly: above every file, on a file header |
| 877 | # above the first hunk, mid-hunk, in a second hunk whose |
| 878 | # numbering starts elsewhere, and in a second file. |
| 879 | diff -u - "$XDG_STATE_HOME/valley/notes/scratch.md" <<EOF |
| 880 | ## scratch at $(git rev-parse --short origin/scratch) |
| 881 | |
| 882 | (unanchored): a note above every file |
| 883 | alpha.md: alpha reads like two files |
| 884 | alpha.md:3: why is 3 changed at all? |
| 885 | alpha.md:13: and this hunk is fine |
| 886 | beta.md:5: beta wants the same treatment |
| 887 | |
| 888 | EOF |
| 889 | |
| 890 | # The editor was given the buffer valley wrote, not the |
| 891 | # rendering less displayed, and given a line to open at. |
| 892 | grep -qE 'editor got: \+[0-9]+ .*/review\.diff$' \ |
| 893 | "$XDG_STATE_HOME/editor.log" |
| 894 | # The filter did run: what the pager showed was its output. |
| 895 | grep -q '^| @@ ' plain.log |
| 896 | # The line the reviewer edited instead of inserting is gone, |
| 897 | # and said so. |
| 898 | grep -q 'changed or deleted diff line(s) ignored' plain.log |
| 899 | ! grep -q 'alpha SEVENTEEN' "$XDG_STATE_HOME/valley/notes/scratch.md" |
| 900 | |
| 901 | # The verdict is unchanged, and the notes come after it. |
| 902 | grep -q 'skipped scratch; nothing done' plain.log |
| 903 | verdict="$(grep -n 'skipped scratch' plain.log | cut -d: -f1)" |
| 904 | notes="$(grep -n '5 note(s) on scratch' plain.log | cut -d: -f1)" |
| 905 | [ "$verdict" -lt "$notes" ] |
| 906 | |
| 907 | # Piped, review is what it always was: the diff on stdout, |
| 908 | # the verdict from stdin, and no notes to take. |
| 909 | printf 's\n' | valley review scratch > piped.log |
| 910 | grep -q '^diff --git a/alpha.md b/alpha.md$' piped.log |
| 911 | grep -q 'skipped scratch; nothing done' piped.log |
| 912 | ! grep -q 'note(s) on scratch' piped.log |
| 913 | |
| 914 | touch $out |
| 915 | ''; |
| 916 | |
| 917 | # Markdown prose format (ida-1ec03b1): the check is formatter |
| 918 | # idempotence — formatting the tree must change nothing. On failure, |
| 919 | # fix with `nix run .#fmt`. |
| 920 | prose-format = |
| 921 | pkgs.runCommand "valley-prose-format" |
| 922 | { |
| 923 | nativeBuildInputs = [ pkgs.prettier ]; |
| 924 | } |
| 925 | '' |
| 926 | cd ${self} |
| 927 | find . -name '*.md' -print0 | xargs -0 --no-run-if-empty \ |
| 928 | prettier ${proseFmtArgs} --check |
| 929 | touch $out |
| 930 | ''; |
| 931 | |
| 932 | # This repo's own graph, checked by the derivation the flake |
| 933 | # exposes rather than by a second implementation of it. Whatever a |
| 934 | # consuming project runs, this repo runs. |
| 935 | knowledge-lint = self.lib.knowledgeLint { |
| 936 | inherit system; |
| 937 | src = self; |
| 938 | }; |
| 939 | |
| 940 | # The reusable form, exercised over a foreign tree: a project that |
| 941 | # is a README, a docs directory and two nodes, and a project with no |
| 942 | # graph at all. Both must pass, and both are checked by depending on |
| 943 | # the instantiated derivations rather than by re-running the lint. |
| 944 | knowledge-lint-consumer = |
| 945 | pkgs.runCommand "valley-knowledge-lint-consumer" |
| 946 | { |
| 947 | consumer = self.lib.knowledgeLint { |
| 948 | inherit system; |
| 949 | src = consumerProject; |
| 950 | }; |
| 951 | graphless = self.lib.knowledgeLint { |
| 952 | inherit system; |
| 953 | src = graphlessProject; |
| 954 | }; |
| 955 | } |
| 956 | '' |
| 957 | test -e "$consumer" && test -e "$graphless" |
| 958 | touch $out |
| 959 | ''; |
| 960 | |
| 961 | # The lint must fail on a broken graph, and its failure must name |
| 962 | # the file and the defect — a check that only says "no" leaves the |
| 963 | # reader to find the breakage themselves. The script and the schema |
| 964 | # here are the same store paths lib.knowledgeLint uses, so the |
| 965 | # rejections cannot drift from what a consumer runs. |
| 966 | knowledge-lint-rejects = |
| 967 | pkgs.runCommand "valley-knowledge-lint-rejects" |
| 968 | { |
| 969 | nativeBuildInputs = [ |
| 970 | pkgs.cue |
| 971 | pkgs.python3 |
| 972 | ]; |
| 973 | } |
| 974 | '' |
| 975 | ${lib.concatStrings ( |
| 976 | lib.mapAttrsToList (case: spec: '' |
| 977 | mkdir -p work/${case} |
| 978 | if python3 ${./nix/knowledge-lint.py} \ |
| 979 | --tree ${mkTree "knowledge-lint-${case}" spec.files} \ |
| 980 | --schema ${./schema/node.cue} \ |
| 981 | --work work/${case} 2> ${case}.err |
| 982 | then |
| 983 | echo "knowledge-lint: expected graph '${case}' to be rejected" >&2 |
| 984 | exit 1 |
| 985 | fi |
| 986 | if ! grep -qF -- ${lib.escapeShellArg spec.names} ${case}.err; then |
| 987 | echo "knowledge-lint: '${case}' was rejected without naming" \ |
| 988 | ${lib.escapeShellArg spec.names} >&2 |
| 989 | cat ${case}.err >&2 |
| 990 | exit 1 |
| 991 | fi |
| 992 | '') rejectedGraphs |
| 993 | )} |
| 994 | touch $out |
| 995 | ''; |
| 996 | |
| 997 | # The example host declaration must vet against the schema, and the |
| 998 | # schema must reject what it claims to reject: unsafe project names, |
| 999 | # unknown project fields, stray top-level fields (typos, deployment |
| 1000 | # concerns), and malformed backup policy (machine concerns, targets |
| 1001 | # without an implementation, non-positive retention). CUE closedness |
| 1002 | # is easy to regress silently — e.g. embedding #Host instead of |
| 1003 | # referencing it opens the schema — so the rejections are pinned |
| 1004 | # here. |
| 1005 | cue-vet = |
| 1006 | let |
| 1007 | invalidConfigs = { |
| 1008 | unsafe-project-name = '' |
| 1009 | package valley |
| 1010 | projects: ".hidden": {} |
| 1011 | ''; |
| 1012 | unknown-project-field = '' |
| 1013 | package valley |
| 1014 | projects: ok: dataDir: "/srv/git" |
| 1015 | ''; |
| 1016 | top-level-typo = '' |
| 1017 | package valley |
| 1018 | project: oops: {} |
| 1019 | ''; |
| 1020 | deployment-concern-in-cue = '' |
| 1021 | package valley |
| 1022 | user: "git" |
| 1023 | projects: ok: {} |
| 1024 | ''; |
| 1025 | machine-concern-in-backup = '' |
| 1026 | package valley |
| 1027 | projects: ok: {} |
| 1028 | backup: repositoryFile: "/run/agenix/valley-restic-repo" |
| 1029 | ''; |
| 1030 | unimplemented-backup-target = '' |
| 1031 | package valley |
| 1032 | projects: ok: {} |
| 1033 | backup: target: "restic-s3" |
| 1034 | ''; |
| 1035 | negative-retention = '' |
| 1036 | package valley |
| 1037 | projects: ok: {} |
| 1038 | backup: retention: daily: -1 |
| 1039 | ''; |
| 1040 | }; |
| 1041 | in |
| 1042 | pkgs.runCommand "valley-cue-vet" |
| 1043 | { |
| 1044 | nativeBuildInputs = [ pkgs.cue ]; |
| 1045 | } |
| 1046 | '' |
| 1047 | cue vet -c ${./schema/valley.cue} ${./examples/host.cue} |
| 1048 | cue export ${./schema/valley.cue} ${./examples/host.cue} > example.json |
| 1049 | grep -q 'gunk-dev/the-valley' example.json |
| 1050 | grep -q 'restic-sftp' example.json |
| 1051 | |
| 1052 | # A declaration without a backup block must stay valid — |
| 1053 | # consumers written before the field existed keep vetting. |
| 1054 | cue vet -c ${./schema/valley.cue} ${pkgs.writeText "no-backup.cue" '' |
| 1055 | package valley |
| 1056 | projects: "the-valley": {} |
| 1057 | ''} |
| 1058 | |
| 1059 | # The event schema accepts what the publisher hook emits … |
| 1060 | cue vet -d '#RefUpdated' ${./schema/events.cue} ${pkgs.writeText "ref-updated.json" '' |
| 1061 | {"event":"ref-updated","repo":"the-valley","ref":"refs/heads/main","old":"0000000000000000000000000000000000000000","new":"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"} |
| 1062 | ''} |
| 1063 | # … and stays closed: a field outside the git-derivable |
| 1064 | # identity — wall-clock time, a hostname — must be rejected, |
| 1065 | # or replay determinism silently dies. |
| 1066 | if cue vet -d '#RefUpdated' ${./schema/events.cue} ${pkgs.writeText "ref-updated-timestamped.json" '' |
| 1067 | {"event":"ref-updated","repo":"the-valley","ref":"refs/heads/main","old":"0000000000000000000000000000000000000000","new":"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3","time":"2026-07-16T00:00:00Z"} |
| 1068 | ''}; then |
| 1069 | echo "cue-vet: expected the timestamped ref-updated payload to be rejected" >&2 |
| 1070 | exit 1 |
| 1071 | fi |
| 1072 | if cue vet -d '#RefUpdated' ${./schema/events.cue} ${pkgs.writeText "ref-updated-short-sha.json" '' |
| 1073 | {"event":"ref-updated","repo":"the-valley","ref":"refs/heads/main","old":"0000000000000000000000000000000000000000","new":"a94a8fe"} |
| 1074 | ''}; then |
| 1075 | echo "cue-vet: expected the abbreviated object id to be rejected" >&2 |
| 1076 | exit 1 |
| 1077 | fi |
| 1078 | |
| 1079 | ${lib.concatStrings ( |
| 1080 | lib.mapAttrsToList (name: cfg: '' |
| 1081 | if cue vet -c ${./schema/valley.cue} ${pkgs.writeText "${name}.cue" cfg}; then |
| 1082 | echo "cue-vet: expected invalid config '${name}' to be rejected" >&2 |
| 1083 | exit 1 |
| 1084 | fi |
| 1085 | '') invalidConfigs |
| 1086 | )} |
| 1087 | touch $out |
| 1088 | ''; |
| 1089 | |
| 1090 | # The attestation statement schema (dcr-0de694f). A statement the |
| 1091 | # helper composes must vet, and the schema must reject what it |
| 1092 | # claims to reject. Two rejections carry the decision's whole |
| 1093 | # weight and are pinned by name below: a subject with no |
| 1094 | # content-addressed digest has no identity at all, and a |
| 1095 | # predicate that crosses the pure/effectful line would let a |
| 1096 | # notarization pass itself off as re-derivable. |
| 1097 | attest-schema = |
| 1098 | let |
| 1099 | treeDigest = "73847e0b723a444df8c677e5e67d2e7858327259323c76b24f8f11b650b66d69"; |
| 1100 | subject = '' |
| 1101 | "subject": { |
| 1102 | "primary": "valley-tree-v1", |
| 1103 | "digest": { |
| 1104 | "valley-tree-v1": "${treeDigest}", |
| 1105 | "git-sha1": "99b5f2f7971e2c8e37a7a579cb761d80272a9a3d" |
| 1106 | } |
| 1107 | } |
| 1108 | ''; |
| 1109 | pureStatement = '' |
| 1110 | { |
| 1111 | "statementType": "the-valley/attestation/v1", |
| 1112 | ${subject}, |
| 1113 | "predicateType": "the-valley/check/pure/v1", |
| 1114 | "predicate": { |
| 1115 | "check": {"name": "prose-format", "runner": "nix", "attribute": "prose-format"}, |
| 1116 | "result": "passed", |
| 1117 | "inputs": {"valley-inputs-v1": "8df8c199decb43eb715790d6fc3a9dd96adaaf3a75073a50acfa51d73aaf3253"}, |
| 1118 | "derivation": {"sha256": "ef69ed0ccc0546a38a40eebbfcac610cedd7cf4f81036cd21ddff483f08d3ad7"}, |
| 1119 | "output": {"valley-tree-v1": "cf1f5a9c96bbdf1d69da451c94168fa3a760f91f94827ba88bdb72de8dfa8af9"} |
| 1120 | }, |
| 1121 | "provenance": { |
| 1122 | "harness": "a harness", |
| 1123 | "model": "a model", |
| 1124 | "prompt": {"sha256": "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03"}, |
| 1125 | "delegation": [{"principal": "human:integrator", "grant": "land changes"}] |
| 1126 | } |
| 1127 | } |
| 1128 | ''; |
| 1129 | effectfulStatement = '' |
| 1130 | { |
| 1131 | "statementType": "the-valley/attestation/v1", |
| 1132 | ${subject}, |
| 1133 | "predicateType": "the-valley/check/effectful/v1", |
| 1134 | "predicate": { |
| 1135 | "check": {"name": "live-api", "runner": "command", "command": "curl -sf https://example.invalid"}, |
| 1136 | "result": "passed", |
| 1137 | "environment": "a sealed environment", |
| 1138 | "observedAt": "2026-08-02T13:02:00Z" |
| 1139 | } |
| 1140 | } |
| 1141 | ''; |
| 1142 | # Each case is the pure statement with one thing wrong. |
| 1143 | invalidStatements = { |
| 1144 | # Carriage is not statement: a signature inside the signed |
| 1145 | # bytes is a category error, and the sentinel names it. |
| 1146 | signature-in-statement = builtins.replaceStrings [ "\"statementType\"" ] [ |
| 1147 | "\"signature\": \"-----BEGIN SSH SIGNATURE-----\", \"statementType\"" |
| 1148 | ] pureStatement; |
| 1149 | # A subject with only advisory members. |
| 1150 | no-content-addressed-subject = |
| 1151 | builtins.replaceStrings [ "\"valley-tree-v1\": \"${treeDigest}\"," ] [ "" ] |
| 1152 | pureStatement; |
| 1153 | # A notarization wearing a re-derivable predicate type. |
| 1154 | effectful-claiming-pure = builtins.replaceStrings [ "the-valley/check/effectful/v1" ] [ |
| 1155 | "the-valley/check/pure/v1" |
| 1156 | ] effectfulStatement; |
| 1157 | # A re-derivable claim that drops what it is re-derived |
| 1158 | # against. |
| 1159 | pure-without-output = builtins.replaceStrings [ "\"output\"" ] [ "\"outputs\"" ] pureStatement; |
| 1160 | # A predicate type nobody has published a shape for. |
| 1161 | unversioned-predicate-type = |
| 1162 | builtins.replaceStrings [ "the-valley/check/pure/v1" ] [ "the-valley/check/pure" ] |
| 1163 | pureStatement; |
| 1164 | # A digest under a scheme no verifier can check. |
| 1165 | unknown-digest-scheme = builtins.replaceStrings [ "\"git-sha1\"" ] [ "\"md5\"" ] pureStatement; |
| 1166 | # An abbreviated digest. |
| 1167 | short-digest = builtins.replaceStrings [ treeDigest ] [ "73847e0b" ] pureStatement; |
| 1168 | # A check name outside the shape schema/verification.cue |
| 1169 | # holds check names to. |
| 1170 | unsafe-check-name = builtins.replaceStrings [ "\"prose-format\", \"runner\"" ] [ |
| 1171 | "\"Prose Format\", \"runner\"" |
| 1172 | ] pureStatement; |
| 1173 | # A nix check carrying a command line. |
| 1174 | nix-check-with-a-command = builtins.replaceStrings [ "\"runner\": \"nix\"" ] [ |
| 1175 | "\"runner\": \"nix\", \"command\": \"make\"" |
| 1176 | ] pureStatement; |
| 1177 | # A value with no written form. The statement is written |
| 1178 | # out as lines and the form has no escapes, so a command |
| 1179 | # spanning two of them is stopped at the gate rather than |
| 1180 | # in a renderer after the check has already run. |
| 1181 | command-over-two-lines = builtins.replaceStrings [ "curl -sf https://example.invalid" ] [ |
| 1182 | "curl -sf https://example.invalid \\\\\\n --retry 3" |
| 1183 | ] effectfulStatement; |
| 1184 | # And the other value a line cannot carry. |
| 1185 | empty-environment = builtins.replaceStrings [ "\"a sealed environment\"" ] [ |
| 1186 | "\"\"" |
| 1187 | ] effectfulStatement; |
| 1188 | }; |
| 1189 | in |
| 1190 | pkgs.runCommand "valley-attest-schema" |
| 1191 | { |
| 1192 | nativeBuildInputs = [ pkgs.cue ]; |
| 1193 | } |
| 1194 | '' |
| 1195 | cue vet -c ${./schema/attestation.cue} ${pkgs.writeText "pure.json" pureStatement} |
| 1196 | cue vet -c ${./schema/attestation.cue} ${pkgs.writeText "effectful.json" effectfulStatement} |
| 1197 | |
| 1198 | ${lib.concatStrings ( |
| 1199 | lib.mapAttrsToList (name: text: '' |
| 1200 | if cue vet -c ${./schema/attestation.cue} ${pkgs.writeText "${name}.json" text} \ |
| 1201 | > ${name}.err 2>&1; then |
| 1202 | echo "attest-schema: expected invalid statement '${name}' to be rejected" >&2 |
| 1203 | exit 1 |
| 1204 | fi |
| 1205 | '') invalidStatements |
| 1206 | )} |
| 1207 | |
| 1208 | # A map whose keys come from a caller is written as |
| 1209 | # #SegmentKeyed. A field's name is written into the key that |
| 1210 | # names its line, so a name holding the dot that separates |
| 1211 | # segments, the space that separates key from value, or |
| 1212 | # anything a line cannot carry is a statement with no written |
| 1213 | # form. It fails vet rather than reaching a signer. |
| 1214 | cue vet -d '#SegmentKeyed' ${./schema/attestation.cue} ${ |
| 1215 | pkgs.writeText "segment-keys.json" '' |
| 1216 | {"harness": "a harness", "run-id": "1", "z9": "the last shape a segment takes"} |
| 1217 | '' |
| 1218 | } |
| 1219 | ${lib.concatStrings ( |
| 1220 | lib.mapAttrsToList (name: key: '' |
| 1221 | if cue vet -d '#SegmentKeyed' ${./schema/attestation.cue} ${ |
| 1222 | pkgs.writeText "${name}.json" '' |
| 1223 | {"harness": "a harness", ${builtins.toJSON key}: "a key with no written form"} |
| 1224 | '' |
| 1225 | } > ${name}.err 2>&1; then |
| 1226 | echo "attest-schema: expected the key '${key}' to be rejected" >&2 |
| 1227 | exit 1 |
| 1228 | fi |
| 1229 | grep -q 'field not allowed' ${name}.err |
| 1230 | '') { |
| 1231 | non-ascii-key = "café"; |
| 1232 | dotted-key = "a.b"; |
| 1233 | spaced-key = "a b"; |
| 1234 | index-shaped-key = "0"; |
| 1235 | } |
| 1236 | )} |
| 1237 | |
| 1238 | # A rejection that does not name the field leaves the reader |
| 1239 | # to find the breakage themselves. |
| 1240 | grep -q 'signature: conflicting values' signature-in-statement.err |
| 1241 | grep -q 'subject.digest."valley-tree-v1"' no-content-addressed-subject.err |
| 1242 | grep -q 'predicate.environment: field not allowed' effectful-claiming-pure.err |
| 1243 | grep -q 'predicate.check.command' command-over-two-lines.err |
| 1244 | touch $out |
| 1245 | ''; |
| 1246 | |
| 1247 | # The written form and the note envelope, held to fixed vectors. |
| 1248 | # These bytes are an interop contract rather than an |
| 1249 | # implementation detail: a regenerated or independently written |
| 1250 | # attest must produce them identically or every signature already |
| 1251 | # made stops verifying. So the vectors are checked-in files with a |
| 1252 | # README saying they are the contract (attest/conformance/), and |
| 1253 | # this check is what holds a second implementation to them. |
| 1254 | attest-conformance = |
| 1255 | pkgs.runCommand "valley-attest-conformance" |
| 1256 | { |
| 1257 | nativeBuildInputs = [ |
| 1258 | pkgs.cue |
| 1259 | (attestFor pkgs) |
| 1260 | ]; |
| 1261 | } |
| 1262 | '' |
| 1263 | vectors=${./attest/conformance} |
| 1264 | |
| 1265 | # One vector written out and compared, quietly, so the |
| 1266 | # perturbed run at the end can expect it to fail without |
| 1267 | # saying so. |
| 1268 | writes() { attest render "$1/input.json" | cmp -s - "$1/statement.txt"; } |
| 1269 | |
| 1270 | found=0 |
| 1271 | signed=0 |
| 1272 | for dir in "$vectors"/vectors/*/; do |
| 1273 | name="$(basename "$dir")" |
| 1274 | found=$((found + 1)) |
| 1275 | |
| 1276 | if ! writes "$dir"; then |
| 1277 | echo "attest-conformance: $name is not written as its recorded bytes" >&2 |
| 1278 | diff -u "$dir/statement.txt" <(attest render "$dir/input.json") >&2 || true |
| 1279 | exit 1 |
| 1280 | fi |
| 1281 | |
| 1282 | # The written form is a fixed point, or a statement written |
| 1283 | # out again anywhere downstream stops matching what was |
| 1284 | # signed. |
| 1285 | if ! attest render "$dir/statement.txt" | cmp -s - "$dir/statement.txt"; then |
| 1286 | echo "attest-conformance: $name is not a fixed point of the written form" >&2 |
| 1287 | exit 1 |
| 1288 | fi |
| 1289 | |
| 1290 | # Every vector is a whole statement — order is defined per |
| 1291 | # predicate type, so a fragment has no written form — and is |
| 1292 | # held to the schema too, so the set cannot drift into |
| 1293 | # documents no verifier would accept. |
| 1294 | cue vet -c ${./schema/attestation.cue} "$dir/input.json" |
| 1295 | |
| 1296 | # The signed vector pins the whole path from a statement to |
| 1297 | # a note something else can check, not just the written |
| 1298 | # form. No --repo: the subject tree is not what this check |
| 1299 | # is about. |
| 1300 | if [ -e "$dir/statement.note" ]; then |
| 1301 | signed=$((signed + 1)) |
| 1302 | attest verify --note "$dir/statement.note" \ |
| 1303 | --known-keys "$vectors/known_keys" > "$name.verify" |
| 1304 | grep -q '^signature ok' "$name.verify" |
| 1305 | grep -q '^text ok' "$name.verify" |
| 1306 | |
| 1307 | # The text a verifier reads back is the text on disk: a |
| 1308 | # note is its statement, and reading one gives the other. |
| 1309 | sed '/^$/q' "$dir/statement.note" | sed '$d' | cmp - "$dir/statement.txt" |
| 1310 | fi |
| 1311 | done |
| 1312 | |
| 1313 | # Two signers over one statement is the property the note |
| 1314 | # format is here for, so the set must actually hold one. |
| 1315 | siblings="$(grep -c '^— ' "$vectors"/vectors/04-two-signers/statement.note)" |
| 1316 | if [ "$siblings" -ne 2 ]; then |
| 1317 | echo "attest-conformance: the two-signer vector carries $siblings signatures" >&2 |
| 1318 | exit 1 |
| 1319 | fi |
| 1320 | attest verify --note "$vectors"/vectors/04-two-signers/statement.note \ |
| 1321 | --known-keys "$vectors/known_keys" \ |
| 1322 | --signer conformance.the-valley.invalid/attestations \ |
| 1323 | --signer witness.the-valley.invalid/attestations > siblings.verify |
| 1324 | if [ "$(grep -c '^signature ok' siblings.verify)" -ne 2 ]; then |
| 1325 | echo "attest-conformance: both sibling signatures must verify" >&2 |
| 1326 | cat siblings.verify >&2 |
| 1327 | exit 1 |
| 1328 | fi |
| 1329 | |
| 1330 | if [ "$found" -lt 4 ] || [ "$signed" -lt 2 ]; then |
| 1331 | echo "attest-conformance: $found vectors, $signed signed — the set has been emptied" >&2 |
| 1332 | exit 1 |
| 1333 | fi |
| 1334 | |
| 1335 | # The other half of the contract: what must not be written or |
| 1336 | # read at all. A document with no written form, and text that |
| 1337 | # is not the written form of anything. |
| 1338 | refused=0 |
| 1339 | for file in "$vectors"/refused/*; do |
| 1340 | refused=$((refused + 1)) |
| 1341 | if attest render "$file" > /dev/null 2> "$(basename "$file").err"; then |
| 1342 | echo "attest-conformance: $(basename "$file") was accepted" >&2 |
| 1343 | exit 1 |
| 1344 | fi |
| 1345 | done |
| 1346 | if [ "$refused" -lt 30 ]; then |
| 1347 | echo "attest-conformance: only $refused refusals — the set has been emptied" >&2 |
| 1348 | exit 1 |
| 1349 | fi |
| 1350 | |
| 1351 | # The comparison must be able to fail. One recorded byte |
| 1352 | # sequence with a single value changed is what a divergent |
| 1353 | # implementation looks like, and it must not pass. |
| 1354 | mkdir -p perturbed |
| 1355 | cp "$vectors/vectors/01-statement-minimal/input.json" perturbed/ |
| 1356 | sed 's/^predicate.result passed$/predicate.result failed/' \ |
| 1357 | "$vectors/vectors/01-statement-minimal/statement.txt" > perturbed/statement.txt |
| 1358 | cmp -s perturbed/statement.txt "$vectors/vectors/01-statement-minimal/statement.txt" \ |
| 1359 | && { echo "attest-conformance: the perturbation changed nothing" >&2; exit 1; } |
| 1360 | if writes perturbed; then |
| 1361 | echo "attest-conformance: a perturbed vector passed; the comparison proves nothing" >&2 |
| 1362 | exit 1 |
| 1363 | fi |
| 1364 | |
| 1365 | # And so must the signature check. One byte of the signed |
| 1366 | # text changed is a signature that no longer covers it. |
| 1367 | sed 's/a sealed environment/a sealed environmenT/' \ |
| 1368 | "$vectors"/vectors/04-two-signers/statement.note > perturbed/statement.note |
| 1369 | if attest verify --note perturbed/statement.note \ |
| 1370 | --known-keys "$vectors/known_keys" > perturbed.verify 2>&1; then |
| 1371 | echo "attest-conformance: a note whose text was edited still verified" >&2 |
| 1372 | exit 1 |
| 1373 | fi |
| 1374 | grep -q 'does not check out over this text' perturbed.verify |
| 1375 | |
| 1376 | echo "attest-conformance: $found vectors written byte for byte, $signed signed, $refused refused" |
| 1377 | touch $out |
| 1378 | ''; |
| 1379 | |
| 1380 | # The helper itself, driven end to end over scratch repositories |
| 1381 | # and a throwaway key: what it publishes, what it refuses to |
| 1382 | # publish, and what a verifier makes of both. |
| 1383 | # |
| 1384 | # Every check here uses the command runner. The nix runner cannot |
| 1385 | # be exercised from inside a nix build — there is no daemon in the |
| 1386 | # sandbox — so what a pure statement looks like is pinned by |
| 1387 | # attest-schema above and by the unit tests over the digest |
| 1388 | # scheme, and the runner itself is exercised by running the helper |
| 1389 | # outside the sandbox. |
| 1390 | attest-e2e = |
| 1391 | pkgs.runCommand "valley-attest-e2e" |
| 1392 | { |
| 1393 | nativeBuildInputs = [ |
| 1394 | pkgs.git |
| 1395 | pkgs.openssh |
| 1396 | (attestFor pkgs) |
| 1397 | ]; |
| 1398 | } |
| 1399 | '' |
| 1400 | export HOME="$TMPDIR" |
| 1401 | export GIT_CONFIG_NOSYSTEM=1 |
| 1402 | git config --global user.name valley-check |
| 1403 | git config --global user.email valley-check@localhost |
| 1404 | git config --global init.defaultBranch main |
| 1405 | |
| 1406 | # Throwaway keys in a scratch directory. The signer is a |
| 1407 | # parameter: provisioning a host identity is deployment, and |
| 1408 | # nothing here reads or writes anything under a real ~/.ssh. |
| 1409 | # A verifier is given key names and hashes, so what it holds |
| 1410 | # is what `attest key` prints and nothing more. |
| 1411 | ssh-keygen -q -t ed25519 -N "" -C valley-check -f "$TMPDIR/host" |
| 1412 | ssh-keygen -q -t ed25519 -N "" -C witness -f "$TMPDIR/witness" |
| 1413 | ssh-keygen -q -t ed25519 -N "" -C stranger -f "$TMPDIR/stranger" |
| 1414 | host=host.valley.invalid/attestations |
| 1415 | witness=witness.valley.invalid/attestations |
| 1416 | stranger=stranger.elsewhere.invalid/attestations |
| 1417 | attest key --key "$TMPDIR/host" --name "$host" > "$TMPDIR/known_keys" |
| 1418 | attest key --key "$TMPDIR/witness" --name "$witness" >> "$TMPDIR/known_keys" |
| 1419 | attest key --key "$TMPDIR/stranger" --name "$stranger" > "$TMPDIR/other_keys" |
| 1420 | grep -q "^$host+[0-9a-f]\{8\}+A" "$TMPDIR/known_keys" |
| 1421 | |
| 1422 | # A key behind a passphrase is refused rather than prompted |
| 1423 | # for: attest runs unattended. |
| 1424 | ssh-keygen -q -t ed25519 -N "a passphrase" -C locked -f "$TMPDIR/locked" |
| 1425 | if attest key --key "$TMPDIR/locked" --name "$host" 2> locked.err; then |
| 1426 | echo "attest-e2e: an encrypted key must be refused" >&2 |
| 1427 | exit 1 |
| 1428 | fi |
| 1429 | grep -q 'cannot ask for a passphrase' locked.err |
| 1430 | |
| 1431 | repo="$TMPDIR/tree" |
| 1432 | git init --quiet "$repo" |
| 1433 | cd "$repo" |
| 1434 | echo hello > hello.txt |
| 1435 | mkdir -p sub |
| 1436 | echo nested > sub/nested.txt |
| 1437 | ln -s hello.txt link |
| 1438 | printf '#!/bin/sh\ntrue\n' > run.sh |
| 1439 | chmod 755 run.sh |
| 1440 | git add -A |
| 1441 | git commit --quiet -m base |
| 1442 | |
| 1443 | digest="$(attest digest | sed 's/^valley-tree-v1://')" |
| 1444 | case "$digest" in |
| 1445 | [0-9a-f][0-9a-f]*) ;; |
| 1446 | *) echo "attest-e2e: no tree digest: $digest" >&2; exit 1 ;; |
| 1447 | esac |
| 1448 | |
| 1449 | refs() { git for-each-ref --format='%(refname)' refs/the-valley; } |
| 1450 | nothing_published() { |
| 1451 | if [ -n "$(refs)" ]; then |
| 1452 | echo "attest-e2e: $1" >&2 |
| 1453 | git for-each-ref refs/the-valley >&2 |
| 1454 | exit 1 |
| 1455 | fi |
| 1456 | } |
| 1457 | |
| 1458 | # Without a key, nothing is emitted — an unsigned statement |
| 1459 | # is not an attestation. |
| 1460 | if attest run --command 'ok=true' 2> nokey.err; then |
| 1461 | echo "attest-e2e: a run with no signing key must fail" >&2 |
| 1462 | exit 1 |
| 1463 | fi |
| 1464 | grep -q 'no signing key' nokey.err |
| 1465 | nothing_published "a run with no signing key stored a ref" |
| 1466 | |
| 1467 | # A failing check publishes nothing, and says which check. |
| 1468 | if attest run --key "$TMPDIR/host" --name "$host" \ |
| 1469 | --command 'ok=true' --command 'nope=false' > failing.out 2> failing.err; then |
| 1470 | echo "attest-e2e: a failing check must fail the run" >&2 |
| 1471 | exit 1 |
| 1472 | fi |
| 1473 | grep -qE '^check nope +command failed$' failing.out |
| 1474 | grep -q 'nothing published' failing.err |
| 1475 | nothing_published "a failing check left a ref behind" |
| 1476 | |
| 1477 | # A statement the schema rejects is stopped before it is |
| 1478 | # signed or stored. Provenance is the caller's, so a |
| 1479 | # malformed one is how a malformed statement gets composed |
| 1480 | # at all. |
| 1481 | echo '{"harness":"valley-check","authority":"root"}' > bad-provenance.json |
| 1482 | if attest run --key "$TMPDIR/host" --name "$host" --command 'ok=true' \ |
| 1483 | --provenance bad-provenance.json > malformed.out 2> malformed.err; then |
| 1484 | echo "attest-e2e: a malformed statement must fail the run" >&2 |
| 1485 | exit 1 |
| 1486 | fi |
| 1487 | grep -q 'provenance.authority: field not allowed' malformed.err |
| 1488 | grep -q 'nothing published' malformed.err |
| 1489 | nothing_published "a malformed statement left a ref behind" |
| 1490 | |
| 1491 | # A statement the schema admits but no line can carry is |
| 1492 | # stopped too, at the same point and for the same reason. |
| 1493 | printf '{"harness":"valley\\ncheck"}\n' > unwritable-provenance.json |
| 1494 | if attest run --key "$TMPDIR/host" --name "$host" --command 'ok=true' \ |
| 1495 | --provenance unwritable-provenance.json > unwritable.out 2> unwritable.err; then |
| 1496 | echo "attest-e2e: a statement with no written form must fail the run" >&2 |
| 1497 | exit 1 |
| 1498 | fi |
| 1499 | grep -q 'nothing published' unwritable.err |
| 1500 | nothing_published "a statement with no written form left a ref behind" |
| 1501 | |
| 1502 | # The successful run. |
| 1503 | echo '{"harness":"valley-check","model":"none","delegation":[{"principal":"human:integrator","grant":"land changes"}]}' > provenance.json |
| 1504 | attest run --key "$TMPDIR/host" --name "$host" --command 'ok=true' \ |
| 1505 | --provenance provenance.json > run.out |
| 1506 | grep -q "^subject valley-tree-v1:$digest\$" run.out |
| 1507 | grep -q '^check ok *command passed$' run.out |
| 1508 | grep -q "^signer $host+" run.out |
| 1509 | |
| 1510 | # Stored at a ref keyed by the subject digest, as one note |
| 1511 | # rather than a statement and a signature beside it. |
| 1512 | ref="$(refs)" |
| 1513 | case "$ref" in |
| 1514 | refs/the-valley/attestations/"$digest"/*) ;; |
| 1515 | *) echo "attest-e2e: ref $ref is not keyed by the subject digest" >&2; exit 1 ;; |
| 1516 | esac |
| 1517 | git cat-file -p "$ref:ok/statement.note" > statement.note |
| 1518 | head -n 1 statement.note | grep -qx 'the-valley/attestation/v1' |
| 1519 | grep -qx "subject.digest.valley-tree-v1 $digest" statement.note |
| 1520 | grep -qx 'provenance.harness valley-check' statement.note |
| 1521 | grep -q "^— $host " statement.note |
| 1522 | |
| 1523 | # No git object is signed: the signature is over the |
| 1524 | # statement's text and nothing else. |
| 1525 | if git cat-file commit HEAD | grep -q '^gpgsig'; then |
| 1526 | echo "attest-e2e: attest signed a git object" >&2 |
| 1527 | exit 1 |
| 1528 | fi |
| 1529 | |
| 1530 | verify() { |
| 1531 | attest verify --note "$1" --known-keys "$2" --repo "$repo" |
| 1532 | } |
| 1533 | |
| 1534 | verify statement.note "$TMPDIR/known_keys" > verify.out |
| 1535 | grep -q "^signature ok $host+" verify.out |
| 1536 | grep -q 'matches the recorded subject digest' verify.out |
| 1537 | |
| 1538 | # One atomic native-git push carries the branch and the |
| 1539 | # attestation ref together. |
| 1540 | git init --quiet --bare "$TMPDIR/host.git" |
| 1541 | git remote add valley "$TMPDIR/host.git" |
| 1542 | attest run --key "$TMPDIR/host" --name "$host" --command 'ok=true' \ |
| 1543 | --push valley > push.out |
| 1544 | grep -q -- '--atomic' push.out |
| 1545 | git -C "$TMPDIR/host.git" for-each-ref --format='%(refname)' > published.txt |
| 1546 | grep -qx 'refs/heads/main' published.txt |
| 1547 | grep -qx "$ref" published.txt |
| 1548 | |
| 1549 | # A second party attests to the same statement, and its |
| 1550 | # signature lands beside the first under the text both cover. |
| 1551 | # This is what the note format is here for. |
| 1552 | attest sign --key "$TMPDIR/witness" --name "$witness" statement.note \ |
| 1553 | > countersigned.note |
| 1554 | if [ "$(grep -c '^— ' countersigned.note)" -ne 2 ]; then |
| 1555 | echo "attest-e2e: countersigning did not add a sibling signature line" >&2 |
| 1556 | cat countersigned.note >&2 |
| 1557 | exit 1 |
| 1558 | fi |
| 1559 | sed '/^$/q' countersigned.note | sed '$d' | cmp - <(sed '/^$/q' statement.note | sed '$d') |
| 1560 | attest verify --note countersigned.note --known-keys "$TMPDIR/known_keys" \ |
| 1561 | --repo "$repo" --signer "$host" --signer "$witness" > countersigned.out |
| 1562 | if [ "$(grep -c '^signature ok' countersigned.out)" -ne 2 ]; then |
| 1563 | echo "attest-e2e: both signatures over one statement must verify" >&2 |
| 1564 | cat countersigned.out >&2 |
| 1565 | exit 1 |
| 1566 | fi |
| 1567 | |
| 1568 | # A verifier that does not hold the witness's key still |
| 1569 | # accepts the note, and says which signature it cannot speak |
| 1570 | # to. Requiring that signer is how it refuses instead. |
| 1571 | attest key --key "$TMPDIR/host" --name "$host" > "$TMPDIR/host_only" |
| 1572 | attest verify --note countersigned.note --known-keys "$TMPDIR/host_only" \ |
| 1573 | --repo "$repo" > partial.out |
| 1574 | grep -q "^signature ok $host+" partial.out |
| 1575 | grep -q "^signature unknown $witness+" partial.out |
| 1576 | if attest verify --note countersigned.note --known-keys "$TMPDIR/host_only" \ |
| 1577 | --repo "$repo" --signer "$witness" > required.out 2>&1; then |
| 1578 | echo "attest-e2e: a required signer with no verified signature must fail" >&2 |
| 1579 | exit 1 |
| 1580 | fi |
| 1581 | grep -q "no signature on this note is by $witness" required.out |
| 1582 | |
| 1583 | # A note signed by a key the verifier does not hold is not a |
| 1584 | # bad signature — it is not a signer. |
| 1585 | if verify statement.note "$TMPDIR/other_keys" > stranger.out 2>&1; then |
| 1586 | echo "attest-e2e: a note signed by nobody we hold a key for must not verify" >&2 |
| 1587 | exit 1 |
| 1588 | fi |
| 1589 | grep -q 'no signature on this note is by a key the verifier holds' stranger.out |
| 1590 | |
| 1591 | # Tampering with the signed bytes: one byte of the text the |
| 1592 | # signature covers. |
| 1593 | sed "s/$digest/00000000000000000000000000000000000000000000000000000000000000ff/" \ |
| 1594 | statement.note > tampered.note |
| 1595 | if verify tampered.note "$TMPDIR/known_keys" > tampered.out 2>&1; then |
| 1596 | echo "attest-e2e: a tampered statement must not verify" >&2 |
| 1597 | exit 1 |
| 1598 | fi |
| 1599 | grep -q 'does not check out over this text' tampered.out |
| 1600 | |
| 1601 | # A signature cannot be lifted onto a statement it was not |
| 1602 | # made about: it sits under the text it covers, so moving it |
| 1603 | # means moving that text with it. |
| 1604 | sed '/^$/q' statement.note | sed '$d' > lifted.txt |
| 1605 | sed 's/^provenance.harness .*/provenance.harness somebody-else/' lifted.txt > lifted.body |
| 1606 | sed -n '/^$/,$p' statement.note | tail -n +2 > lifted.sigs |
| 1607 | { cat lifted.body; echo; cat lifted.sigs; } > lifted.note |
| 1608 | if verify lifted.note "$TMPDIR/known_keys" > lifted.out 2>&1; then |
| 1609 | echo "attest-e2e: a signature was lifted onto another statement" >&2 |
| 1610 | exit 1 |
| 1611 | fi |
| 1612 | grep -q 'does not check out over this text' lifted.out |
| 1613 | |
| 1614 | # A statement written some other way than the one written |
| 1615 | # form, signed properly over those bytes. The signature is |
| 1616 | # good and the statement is still refused: it would verify |
| 1617 | # here and fail wherever it was written out again, so the |
| 1618 | # form is a rule rather than a convention. |
| 1619 | { head -n 1 lifted.txt; tail -n +2 lifted.txt | sort -r; } > loose.txt |
| 1620 | cmp -s loose.txt lifted.txt \ |
| 1621 | && { echo "attest-e2e: the reordering changed nothing" >&2; exit 1; } |
| 1622 | attest sign --key "$TMPDIR/host" --name "$host" loose.txt > loose.note |
| 1623 | if verify loose.note "$TMPDIR/known_keys" > loose.out 2>&1; then |
| 1624 | echo "attest-e2e: a statement not in the written form must not verify" >&2 |
| 1625 | exit 1 |
| 1626 | fi |
| 1627 | grep -q 'not the written form of what it says' loose.out |
| 1628 | |
| 1629 | # The subject is the tree. Change the tree and the same |
| 1630 | # signed statement stops being about it … |
| 1631 | echo goodbye > hello.txt |
| 1632 | git commit --quiet -am "change the tree" |
| 1633 | if verify statement.note "$TMPDIR/known_keys" > moved.out 2>&1; then |
| 1634 | echo "attest-e2e: a statement about another tree must not verify" >&2 |
| 1635 | exit 1 |
| 1636 | fi |
| 1637 | grep -q 'tree digest mismatch' moved.out |
| 1638 | |
| 1639 | # … while rewriting the commit over the same tree leaves the |
| 1640 | # attestation standing, which is what a subject that is a |
| 1641 | # tree digest buys. |
| 1642 | git commit --quiet --amend -m "same tree, new commit" |
| 1643 | rewritten="$(attest digest | sed 's/^valley-tree-v1://')" |
| 1644 | git revert --quiet --no-edit HEAD |
| 1645 | restored="$(attest digest | sed 's/^valley-tree-v1://')" |
| 1646 | if [ "$restored" != "$digest" ]; then |
| 1647 | echo "attest-e2e: restoring the tree did not restore its digest" >&2 |
| 1648 | echo " original $digest" >&2 |
| 1649 | echo " restored $restored" >&2 |
| 1650 | exit 1 |
| 1651 | fi |
| 1652 | if [ "$rewritten" = "$digest" ]; then |
| 1653 | echo "attest-e2e: a changed tree kept its digest" >&2 |
| 1654 | exit 1 |
| 1655 | fi |
| 1656 | verify statement.note "$TMPDIR/known_keys" > rebased.out |
| 1657 | grep -q 'matches the recorded subject digest' rebased.out |
| 1658 | touch $out |
| 1659 | ''; |
| 1660 | |
| 1661 | # The integrator's verdict, case by case, with no repository in |
| 1662 | # sight. Every rule of dcr-439b771 is a function of data, so the |
| 1663 | # unit tests state each one directly; what a repository does to |
| 1664 | # produce those inputs is integrator-e2e's. |
| 1665 | integrator-unit = integratorUnwrappedFor pkgs; |
| 1666 | |
| 1667 | # The integrator itself, driven end to end over scratch bare |
| 1668 | # repositories and throwaway keys, running the real binaries: the |
| 1669 | # helper produces the evidence, the deriver composes the policy, |
| 1670 | # the controller judges and lands. The scenarios are Phase 3's |
| 1671 | # exit criteria, observed rather than asserted about. |
| 1672 | # |
| 1673 | # Only the nix evaluator is stood in for — a nix build has no |
| 1674 | # daemon in the sandbox, the same wall attest-e2e meets — and the |
| 1675 | # stand-in models the one property the pure rule rests on: a |
| 1676 | # check's input closure is the content of the files it reads. |
| 1677 | # Everything downstream of it is real: attest builds the manifest |
| 1678 | # and the digest, and the integrator compares them. |
| 1679 | integrator-e2e = |
| 1680 | pkgs.runCommand "valley-integrator-e2e" |
| 1681 | { |
| 1682 | nativeBuildInputs = [ |
| 1683 | pkgs.bash |
| 1684 | pkgs.git |
| 1685 | pkgs.openssh |
| 1686 | pkgs.coreutils |
| 1687 | pkgs.findutils |
| 1688 | pkgs.gnused |
| 1689 | pkgs.gnugrep |
| 1690 | pkgs.cue |
| 1691 | (attestFor pkgs) |
| 1692 | (valleyScriptFor pkgs) |
| 1693 | (integratorFor pkgs) |
| 1694 | ]; |
| 1695 | SCHEMA_ATTESTATION = ./schema/attestation.cue; |
| 1696 | SCHEMA_VERIFICATION = ./schema/verification.cue; |
| 1697 | SCHEMA_EVENTS = ./schema/events.cue; |
| 1698 | # No bus in a sandbox: the payloads are still composed and |
| 1699 | # vetted against the vocabulary, and printed rather than |
| 1700 | # published. What publishing does is the post-receive hook's |
| 1701 | # one `nats pub`, which this shares. |
| 1702 | } |
| 1703 | '' |
| 1704 | cp -r ${./integrator/e2e} e2e |
| 1705 | chmod -R +w e2e |
| 1706 | # The stand-ins go on PATH and are executed by name, so |
| 1707 | # their /usr/bin/env shebangs have to resolve in a sandbox |
| 1708 | # that has no /usr/bin. |
| 1709 | patchShebangs e2e |
| 1710 | bash e2e/run.sh 2>&1 | tee log |
| 1711 | grep -q 'every scenario held' log |
| 1712 | cp log $out |
| 1713 | ''; |
| 1714 | |
| 1715 | # The verification-policy deriver (dcr-f41f718). Composing the two |
| 1716 | # layers is CUE's job and is pinned by cue-vet above; matching |
| 1717 | # paths is the script's own, and a path matcher is wrong exactly at |
| 1718 | # the glob boundaries — `*` inside one segment against `**` across |
| 1719 | # segments, `**` matching no segment at all — and at the sides of a |
| 1720 | # diff a naive reader drops: a rename's old path and a deletion. |
| 1721 | # Each is pinned by driving the real script over a scratch |
| 1722 | # repository and a scratch policy, never by reading the code. |
| 1723 | policy-deriver = |
| 1724 | let |
| 1725 | # A floor whose classes are one glob boundary each, and whose |
| 1726 | # check names say which class matched. |
| 1727 | deriverFloor = pkgs.writeText "deriver-floor.cue" '' |
| 1728 | package verification |
| 1729 | floor: { |
| 1730 | checks: { |
| 1731 | "c-docs": {runner: "nix", attribute: "c-docs"} |
| 1732 | "c-notes": {runner: "nix", attribute: "c-notes"} |
| 1733 | "c-flat": {runner: "nix", attribute: "c-flat"} |
| 1734 | "c-deep": {runner: "nix", attribute: "c-deep"} |
| 1735 | "c-nested": {runner: "nix", attribute: "c-nested"} |
| 1736 | "c-uncovered": {runner: "nix", attribute: "c-uncovered"} |
| 1737 | } |
| 1738 | classes: { |
| 1739 | docs: {paths: "docs/**": true, requires: "c-docs": true} |
| 1740 | notes: {paths: "notes/**": true, requires: "c-notes": true} |
| 1741 | flat: {paths: "src/*.rs": true, requires: "c-flat": true} |
| 1742 | deep: {paths: "src/**/*.rs": true, requires: "c-deep": true} |
| 1743 | nested: {paths: "a/**/b": true, requires: "c-nested": true} |
| 1744 | } |
| 1745 | unclassified: "c-uncovered": true |
| 1746 | } |
| 1747 | ''; |
| 1748 | # One requirement that is a template default rather than a |
| 1749 | # rule, so the two forms are told apart on real output. |
| 1750 | deriverTemplate = pkgs.writeText "deriver-template.cue" '' |
| 1751 | package verification |
| 1752 | #tmpl: #Policy & { |
| 1753 | checks: "c-tmpl": {runner: "nix", attribute: "c-tmpl"} |
| 1754 | classes: docs: requires: "c-tmpl": bool | *true |
| 1755 | } |
| 1756 | ''; |
| 1757 | deriverProject = pkgs.writeText "deriver-project.cue" '' |
| 1758 | package verification |
| 1759 | project: { |
| 1760 | #tmpl |
| 1761 | } |
| 1762 | ''; |
| 1763 | in |
| 1764 | pkgs.runCommand "valley-policy-deriver" |
| 1765 | { |
| 1766 | nativeBuildInputs = [ |
| 1767 | pkgs.git |
| 1768 | pkgs.cue |
| 1769 | (valleyScriptFor pkgs) |
| 1770 | ]; |
| 1771 | } |
| 1772 | '' |
| 1773 | export HOME="$TMPDIR" |
| 1774 | export GIT_CONFIG_NOSYSTEM=1 |
| 1775 | git config --global user.name valley-check |
| 1776 | git config --global user.email valley-check@localhost |
| 1777 | git config --global init.defaultBranch main |
| 1778 | |
| 1779 | policy="$TMPDIR/policy" |
| 1780 | mkdir -p "$policy/instance" "$policy/project" |
| 1781 | cp ${deriverFloor} "$policy/instance/floor.cue" |
| 1782 | cp ${deriverTemplate} "$policy/instance/template.cue" |
| 1783 | cp ${deriverProject} "$policy/project/policy.cue" |
| 1784 | |
| 1785 | repo="$TMPDIR/tree" |
| 1786 | git init --quiet "$repo" |
| 1787 | cd "$repo" |
| 1788 | mkdir -p docs notes src/deep a/x/y |
| 1789 | echo moved > docs/moved.md |
| 1790 | for f in docs/kept.md docs/gone.md src/one.rs src/deep/two.rs \ |
| 1791 | a/b a/x/y/b Makefile; do |
| 1792 | echo seed > "$f" |
| 1793 | done |
| 1794 | git add -A |
| 1795 | git commit --quiet -m base |
| 1796 | base="$(git rev-parse HEAD)" |
| 1797 | |
| 1798 | derive() { |
| 1799 | valley checks --schema ${./schema/verification.cue} \ |
| 1800 | --instance "$policy/instance" --project "$policy/project" \ |
| 1801 | "$base" HEAD |
| 1802 | } |
| 1803 | |
| 1804 | # The check names in the deriver's table, sorted, on one line. |
| 1805 | named() { |
| 1806 | awk '/^required checks:$/ {f = 1; next} |
| 1807 | /^$/ {f = 0} |
| 1808 | f && /^ / {print $1}' <<<"$report" | sort | paste -sd' ' - |
| 1809 | } |
| 1810 | |
| 1811 | # Start a case from the base tree; assert its check table. |
| 1812 | case_start() { git checkout --quiet -B "$1" "$base"; } |
| 1813 | expect() { |
| 1814 | local got |
| 1815 | got="$(named)" |
| 1816 | if [ "$got" != "$1" ]; then |
| 1817 | echo "policy-deriver: $2" >&2 |
| 1818 | echo " expected: $1" >&2 |
| 1819 | echo " got: $got" >&2 |
| 1820 | echo "$report" >&2 |
| 1821 | exit 1 |
| 1822 | fi |
| 1823 | } |
| 1824 | |
| 1825 | # `**` crosses segments, `*` does not. One file under src/ |
| 1826 | # matches both patterns; one a segment deeper matches only |
| 1827 | # the `**` one. |
| 1828 | case_start flat |
| 1829 | echo edit > src/one.rs |
| 1830 | git commit --quiet -am flat |
| 1831 | report="$(derive)" |
| 1832 | expect "c-deep c-flat" "src/*.rs must match a file directly under src/" |
| 1833 | |
| 1834 | case_start deep |
| 1835 | echo edit > src/deep/two.rs |
| 1836 | git commit --quiet -am deep |
| 1837 | report="$(derive)" |
| 1838 | expect "c-deep" "src/*.rs must not match across a path separator" |
| 1839 | |
| 1840 | # A `**` between two segments matches no segment at all … |
| 1841 | case_start nested-none |
| 1842 | echo edit > a/b |
| 1843 | git commit --quiet -am nested-none |
| 1844 | report="$(derive)" |
| 1845 | expect "c-nested" "a/**/b must match a/b" |
| 1846 | |
| 1847 | # … and any number of them. |
| 1848 | case_start nested-many |
| 1849 | echo edit > a/x/y/b |
| 1850 | git commit --quiet -am nested-many |
| 1851 | report="$(derive)" |
| 1852 | expect "c-nested" "a/**/b must match a/x/y/b" |
| 1853 | |
| 1854 | # A rename counts on both sides: the class covering the old |
| 1855 | # path is required as much as the one covering the new. |
| 1856 | case_start renamed |
| 1857 | git mv docs/moved.md notes/moved.md |
| 1858 | git commit --quiet -m renamed |
| 1859 | git diff --name-status -M "$base" HEAD | grep -q '^R' \ |
| 1860 | || { echo "policy-deriver: the rename case is not a rename" >&2; exit 1; } |
| 1861 | report="$(derive)" |
| 1862 | expect "c-docs c-notes c-tmpl" "a rename must count on both sides" |
| 1863 | |
| 1864 | # A deleted path is still a changed path. |
| 1865 | case_start deleted |
| 1866 | git rm --quiet docs/gone.md |
| 1867 | git commit --quiet -m deleted |
| 1868 | report="$(derive)" |
| 1869 | expect "c-docs c-tmpl" "a deletion must count" |
| 1870 | |
| 1871 | # The form of the value is the mandatory bit: the floor's |
| 1872 | # concrete `true` against the template's `bool | *true`. |
| 1873 | grep -qE '^ c-docs +mandatory +docs$' <<<"$report" |
| 1874 | grep -qE '^ c-tmpl +default +docs$' <<<"$report" |
| 1875 | |
| 1876 | # A path no class covers takes the unclassified set, and says |
| 1877 | # so by name. |
| 1878 | case_start uncovered |
| 1879 | echo edit > Makefile |
| 1880 | git commit --quiet -am uncovered |
| 1881 | report="$(derive)" |
| 1882 | expect "c-uncovered" "an uncovered path must take the unclassified set" |
| 1883 | grep -q '^classes matched: unclassified$' <<<"$report" |
| 1884 | grep -q '^unclassified: 1 path(s) matched no class$' <<<"$report" |
| 1885 | grep -q '^ Makefile$' <<<"$report" |
| 1886 | |
| 1887 | touch $out |
| 1888 | ''; |
| 1889 | |
| 1890 | module-eval = |
| 1891 | if failedAssertions != [ ] then |
| 1892 | throw "valley module-eval: failed assertions: ${lib.concatMapStringsSep "; " (a: a.message) failedAssertions}" |
| 1893 | else if resticRenderedWithoutDeclaration then |
| 1894 | throw "valley module-eval: restic machinery rendered for a declaration without a backup block" |
| 1895 | else if busRenderedWithoutEnable then |
| 1896 | throw "valley module-eval: bus machinery rendered without services.valley.bus.enable" |
| 1897 | else if |
| 1898 | !(lib.any (a: lib.hasInfix "services.valley.backup." a.message) missingSecretAssertions) |
| 1899 | then |
| 1900 | throw "valley module-eval: enabling backup without the secret-path options must fail an assertion naming them" |
| 1901 | else if protectionRenderedWithoutDeclaration then |
| 1902 | throw "valley module-eval: write-protection machinery rendered for a declaration without services.valley.protect" |
| 1903 | else if |
| 1904 | protectedHost.config.services.openssh.settings.PermitUserEnvironment or null |
| 1905 | != "VALLEY_PRINCIPAL" |
| 1906 | then |
| 1907 | throw "valley module-eval: a key naming a principal needs sshd to honour that one variable and no other" |
| 1908 | else if |
| 1909 | !(lib.any (a: lib.hasInfix "services.valley.protect.gaurded" a.message) strayProtectionAssertions) |
| 1910 | then |
| 1911 | throw "valley module-eval: protecting a project the declaration does not serve must fail an assertion naming it" |
| 1912 | else |
| 1913 | pkgs.runCommand "valley-module-eval" |
| 1914 | { |
| 1915 | initScript = host.config.systemd.services.valley-init.script; |
| 1916 | sshdConfig = host.config.services.openssh.extraConfig; |
| 1917 | resticService = host.config.systemd.units."restic-backups-valley.service".text; |
| 1918 | resticTimer = host.config.systemd.units."restic-backups-valley.timer".text; |
| 1919 | protectedInit = protectedHost.config.systemd.services.valley-init.script; |
| 1920 | protectedKeys = lib.concatStringsSep "\n" protectedKeyLines; |
| 1921 | passAsFile = [ |
| 1922 | "initScript" |
| 1923 | "sshdConfig" |
| 1924 | "resticService" |
| 1925 | "resticTimer" |
| 1926 | "protectedInit" |
| 1927 | "protectedKeys" |
| 1928 | ]; |
| 1929 | } |
| 1930 | '' |
| 1931 | # The repo init list and mirror hook must be generated from |
| 1932 | # the CUE export, and the git user's sshd Match block must |
| 1933 | # be terminated so it cannot scope later config. |
| 1934 | grep -q "the-valley" "$initScriptPath" |
| 1935 | grep -q "valley-mirrors" "$initScriptPath" |
| 1936 | grep -q "Match All" "$sshdConfigPath" |
| 1937 | |
| 1938 | # The mirror publishes main and tags only — a heads glob |
| 1939 | # would publish every topic branch awaiting review — with |
| 1940 | # --prune for tag deletions and a sweep that unpublishes |
| 1941 | # any other head (--prune cannot: it ignores non-glob |
| 1942 | # refspecs). Never --mirror: it also deletes remote-only |
| 1943 | # refs, and GitHub's read-only refs/pull/* fails every such |
| 1944 | # push. Follow the hook chain from the init script to the |
| 1945 | # rendered push script and pin the invocation there. |
| 1946 | mirrorHook="$(grep -o '/nix/store/[^ ]*-valley-mirrors-[^ ]*' "$initScriptPath" | head -n1)" |
| 1947 | mirrorPush="$(grep -o '/nix/store/[^ ]*-valley-mirror-push-[^ ]*' "$mirrorHook" | head -n1)" |
| 1948 | grep -q -- 'push --prune' "$mirrorPush" |
| 1949 | grep -qF -- '+refs/heads/main:refs/heads/main' "$mirrorPush" |
| 1950 | grep -qF -- '+refs/tags/*:refs/tags/*' "$mirrorPush" |
| 1951 | grep -qF -- 'ls-remote --heads' "$mirrorPush" |
| 1952 | grep -qF -- 'push "$url" --delete' "$mirrorPush" |
| 1953 | if grep -qF -- '+refs/heads/*:refs/heads/*' "$mirrorPush"; then |
| 1954 | echo "module-eval: mirror push regressed to publishing every head" >&2 |
| 1955 | exit 1 |
| 1956 | fi |
| 1957 | if grep -q -- '--mirror' "$mirrorPush"; then |
| 1958 | echo "module-eval: mirror push regressed to --mirror" >&2 |
| 1959 | exit 1 |
| 1960 | fi |
| 1961 | # Deletions must never reach a namespace the mirror owns. |
| 1962 | if grep -q 'refs/pull' "$mirrorPush"; then |
| 1963 | echo "module-eval: mirror push must not name refs/pull/*" >&2 |
| 1964 | exit 1 |
| 1965 | fi |
| 1966 | |
| 1967 | # The rendered restic units must back up the data directory |
| 1968 | # to the consumer-supplied repository with the declared |
| 1969 | # retention over a pinned host key, on the declared cadence. |
| 1970 | grep -q "RESTIC_REPOSITORY_FILE=/run/agenix/valley-restic-repo" "$resticServicePath" |
| 1971 | grep -q -- "--keep-daily 7 --keep-weekly 4 --keep-monthly 6" "$resticServicePath" |
| 1972 | grep -q "UserKnownHostsFile=/var/lib/valley-backup/known_hosts" "$resticServicePath" |
| 1973 | grep -q "BatchMode=yes" "$resticServicePath" |
| 1974 | grep -q "OnCalendar=03:30" "$resticTimerPath" |
| 1975 | |
| 1976 | # The backup paths render as a --files-from list: follow |
| 1977 | # ExecStartPre to that list and pin the data directory. |
| 1978 | preStart="$(sed -n 's/^ExecStartPre=//p' "$resticServicePath" | head -n1)" |
| 1979 | staticPaths="$(grep -o '/nix/store/[^ ]*-staticPaths' "$preStart" | head -n1)" |
| 1980 | grep -qx "/srv/git" "$staticPaths" |
| 1981 | |
| 1982 | # A key's principal rides on its own authorized_keys entry |
| 1983 | # — that is the only thing that tells one pusher from |
| 1984 | # another — and a key written as a plain string is passed |
| 1985 | # through untouched. |
| 1986 | grep -q '^environment="VALLEY_PRINCIPAL=integrator" ssh-ed25519 ' "$protectedKeysPath" |
| 1987 | grep -q '^ssh-ed25519 .* valley-check$' "$protectedKeysPath" |
| 1988 | |
| 1989 | # The hook goes on the projects declared protected, and |
| 1990 | # nowhere else. |
| 1991 | grep -q "valley-protect-guarded" "$protectedInitPath" |
| 1992 | grep -q "valley-protect-released" "$protectedInitPath" |
| 1993 | if grep -q "valley-protect-open" "$protectedInitPath"; then |
| 1994 | echo "module-eval: a project nobody protected was wired with the hook" >&2 |
| 1995 | exit 1 |
| 1996 | fi |
| 1997 | touch $out |
| 1998 | ''; |
| 1999 | |
| 2000 | # What a mirror ends up holding, end to end and unmocked: a bare |
| 2001 | # repo wired with the real rendered hooks, pushed to for real, and |
| 2002 | # a second bare repo standing in for the mirror. The refspec is |
| 2003 | # easy to get subtly wrong — --prune ignores the non-glob heads |
| 2004 | # refspec, so pruning heads is the sweep's job — and only running |
| 2005 | # git can tell. Relative mirror URLs (mirrorHost) resolve against |
| 2006 | # the pushing repo, so the shipped scripts run with no |
| 2007 | # substitution: this is exactly what a host executes. |
| 2008 | mirror-e2e = |
| 2009 | pkgs.runCommand "valley-mirror-e2e" |
| 2010 | { |
| 2011 | nativeBuildInputs = [ pkgs.git ]; |
| 2012 | initScript = mirrorHost.config.systemd.services.valley-init.script; |
| 2013 | passAsFile = [ "initScript" ]; |
| 2014 | } |
| 2015 | '' |
| 2016 | export HOME="$TMPDIR" |
| 2017 | export GIT_CONFIG_NOSYSTEM=1 |
| 2018 | git config --global user.name valley-check |
| 2019 | git config --global user.email valley-check@localhost |
| 2020 | git config --global init.defaultBranch main |
| 2021 | cd "$TMPDIR" |
| 2022 | |
| 2023 | wait_for() { |
| 2024 | for _ in $(seq 1 150); do |
| 2025 | "$@" >/dev/null 2>&1 && return 0 |
| 2026 | sleep 0.2 |
| 2027 | done |
| 2028 | echo "mirror-e2e: timed out waiting for: $*" >&2 |
| 2029 | return 1 |
| 2030 | } |
| 2031 | heads() { git -C mirror.git for-each-ref --format='%(refname)' refs/heads; } |
| 2032 | tags() { git -C mirror.git for-each-ref --format='%(refname)' refs/tags; } |
| 2033 | mirror_main_is() { [ "$(git -C mirror.git rev-parse main)" = "$tip" ]; } |
| 2034 | only_main() { [ "$(heads)" = refs/heads/main ]; } |
| 2035 | |
| 2036 | # A primary repo wired exactly as valley-init wires it, with |
| 2037 | # the real store paths followed from the rendered init script. |
| 2038 | dispatch="$(grep -o '/nix/store/[^ ]*-valley-post-receive' "$initScriptPath" | head -n1)" |
| 2039 | mhook="$(grep -o '/nix/store/[^ ]*-valley-mirrors-mirror-pilot' "$initScriptPath" | head -n1)" |
| 2040 | deadhook="$(grep -o '/nix/store/[^ ]*-valley-mirrors-dead-mirror' "$initScriptPath" | head -n1)" |
| 2041 | test -x "$dispatch" && test -x "$mhook" && test -x "$deadhook" |
| 2042 | wire() { |
| 2043 | mkdir -p "$1/hooks/post-receive.d" |
| 2044 | ln -s "$dispatch" "$1/hooks/post-receive" |
| 2045 | ln -s "$2" "$1/hooks/post-receive.d/valley-mirrors" |
| 2046 | } |
| 2047 | |
| 2048 | # The mirror as it stands today: every head and tag of the |
| 2049 | # primary, topic branches included. Seeded before the hook is |
| 2050 | # wired, so nothing sweeps it out from under the setup. |
| 2051 | git init --quiet --bare mirror-pilot.git |
| 2052 | git init --quiet --bare mirror.git |
| 2053 | git clone --quiet "$PWD/mirror-pilot.git" work |
| 2054 | git -C work commit --quiet --allow-empty -m one |
| 2055 | git -C work tag v1 |
| 2056 | git -C work tag doomed |
| 2057 | for b in idea/one idea/two; do git -C work branch "$b"; done |
| 2058 | git -C work push --quiet origin \ |
| 2059 | '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*' |
| 2060 | git -C mirror-pilot.git push --quiet ../mirror.git \ |
| 2061 | '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*' |
| 2062 | [ "$(heads | wc -l)" -eq 3 ] |
| 2063 | wire mirror-pilot.git "$mhook" |
| 2064 | |
| 2065 | # A real push to the primary — a topic branch alongside main, |
| 2066 | # and a tag deleted. The hook replicates asynchronously, so |
| 2067 | # wait on main's new tip before judging the rest. |
| 2068 | git -C work commit --quiet --allow-empty -m two |
| 2069 | git -C work tag -d doomed >/dev/null |
| 2070 | git -C work branch idea/three |
| 2071 | git -C work push --quiet --follow-tags origin main idea/three |
| 2072 | git -C work push --quiet --delete origin doomed |
| 2073 | tip="$(git -C work rev-parse HEAD)" |
| 2074 | wait_for mirror_main_is |
| 2075 | |
| 2076 | # main and the tags are published; nothing else is, and the |
| 2077 | # topic branches that were on the mirror are gone. The sweep |
| 2078 | # is a second push, so it converges just after main lands. |
| 2079 | wait_for only_main |
| 2080 | [ "$(tags)" = refs/tags/v1 ] |
| 2081 | |
| 2082 | # A branch that appears on the mirror by any other route is |
| 2083 | # unpublished on the next push. |
| 2084 | git -C mirror.git branch sneaky main |
| 2085 | git -C work commit --quiet --allow-empty -m three |
| 2086 | git -C work push --quiet origin main |
| 2087 | tip="$(git -C work rev-parse HEAD)" |
| 2088 | wait_for mirror_main_is |
| 2089 | wait_for only_main |
| 2090 | |
| 2091 | # An unreachable mirror costs a log line, never the push: the |
| 2092 | # hook must return promptly and the push must succeed. |
| 2093 | git init --quiet --bare dead-mirror.git |
| 2094 | wire dead-mirror.git "$deadhook" |
| 2095 | git clone --quiet "$PWD/dead-mirror.git" deadwork |
| 2096 | git -C deadwork commit --quiet --allow-empty -m one |
| 2097 | timeout 60 git -C deadwork push --quiet origin main |
| 2098 | [ "$(git -C dead-mirror.git rev-parse main)" = "$(git -C deadwork rev-parse HEAD)" ] |
| 2099 | |
| 2100 | touch $out |
| 2101 | ''; |
| 2102 | |
| 2103 | # The one structural invariant, driven for real: bare repos wired |
| 2104 | # with the rendered pre-receive hook, pushed to as each |
| 2105 | # principal. What sshd would set from a key's authorized_keys |
| 2106 | # entry, these pushes set in the environment directly — that |
| 2107 | # rendering is pinned by module-eval above, and everything the |
| 2108 | # hook decides after it is what this check exercises. |
| 2109 | protect-e2e = |
| 2110 | pkgs.runCommand "valley-protect-e2e" |
| 2111 | { |
| 2112 | nativeBuildInputs = [ pkgs.git ]; |
| 2113 | initScript = protectedHost.config.systemd.services.valley-init.script; |
| 2114 | passAsFile = [ "initScript" ]; |
| 2115 | } |
| 2116 | '' |
| 2117 | export HOME="$TMPDIR" |
| 2118 | export GIT_CONFIG_NOSYSTEM=1 |
| 2119 | git config --global user.name valley-check |
| 2120 | git config --global user.email valley-check@localhost |
| 2121 | git config --global init.defaultBranch main |
| 2122 | cd "$TMPDIR" |
| 2123 | |
| 2124 | # A bare repo wired exactly as valley-init wires it, with |
| 2125 | # the real store path followed from the rendered init script. |
| 2126 | serve() { |
| 2127 | local hook |
| 2128 | hook="$(grep -o "/nix/store/[^ ]*-valley-protect-$1" "$initScriptPath" | head -n1)" |
| 2129 | test -x "$hook" |
| 2130 | git init --quiet --bare "$1.git" |
| 2131 | ln -s "$hook" "$1.git/hooks/pre-receive" |
| 2132 | } |
| 2133 | serve guarded |
| 2134 | serve released |
| 2135 | |
| 2136 | # Pushing as a principal is pushing with the tag on; pushing |
| 2137 | # with an untagged key is pushing with it off. |
| 2138 | as() { |
| 2139 | local who="$1" |
| 2140 | shift |
| 2141 | if [ "$who" = anonymous ]; then |
| 2142 | env -u VALLEY_PRINCIPAL "$@" |
| 2143 | else |
| 2144 | VALLEY_PRINCIPAL="$who" "$@" |
| 2145 | fi |
| 2146 | } |
| 2147 | refs() { git -C "$TMPDIR/$1.git" for-each-ref --format='%(refname)'; } |
| 2148 | has_ref() { |
| 2149 | if ! refs "$1" | grep -qx "$2"; then |
| 2150 | echo "protect-e2e: $1 has no $2" >&2 |
| 2151 | refs "$1" >&2 |
| 2152 | exit 1 |
| 2153 | fi |
| 2154 | } |
| 2155 | lacks_ref() { |
| 2156 | if refs "$1" | grep -qx "$2"; then |
| 2157 | echo "protect-e2e: $1 kept $2 through a rejected push" >&2 |
| 2158 | exit 1 |
| 2159 | fi |
| 2160 | } |
| 2161 | |
| 2162 | git init --quiet work |
| 2163 | cd work |
| 2164 | git commit --quiet --allow-empty -m one |
| 2165 | git remote add guarded "$TMPDIR/guarded.git" |
| 2166 | git remote add released "$TMPDIR/released.git" |
| 2167 | |
| 2168 | # A non-writer cannot create a protected ref, and the |
| 2169 | # rejection says who was pushing, what they were writing, |
| 2170 | # and who may. |
| 2171 | if as contributor git push --quiet guarded main 2> denied.err; then |
| 2172 | echo "protect-e2e: a non-writer wrote a protected ref" >&2 |
| 2173 | exit 1 |
| 2174 | fi |
| 2175 | grep -q 'contributor' denied.err |
| 2176 | grep -q 'refs/heads/main' denied.err |
| 2177 | grep -q 'writers: integrator' denied.err |
| 2178 | lacks_ref guarded refs/heads/main |
| 2179 | |
| 2180 | # An untagged key is nobody, and nobody is not a writer. |
| 2181 | if as anonymous git push --quiet guarded main 2> untagged.err; then |
| 2182 | echo "protect-e2e: an untagged key wrote a protected ref" >&2 |
| 2183 | exit 1 |
| 2184 | fi |
| 2185 | grep -q '<untagged key>' untagged.err |
| 2186 | lacks_ref guarded refs/heads/main |
| 2187 | |
| 2188 | # Everything else is wide open to the same non-writer: topic |
| 2189 | # branches, tags, and refs no declaration protects. |
| 2190 | git branch idea/one |
| 2191 | git tag v1 |
| 2192 | git branch release/1.0 |
| 2193 | as contributor git push --quiet guarded idea/one v1 release/1.0 |
| 2194 | has_ref guarded refs/heads/idea/one |
| 2195 | has_ref guarded refs/tags/v1 |
| 2196 | has_ref guarded refs/heads/release/1.0 |
| 2197 | |
| 2198 | # The same ref is protected where a declaration says so: the |
| 2199 | # glob in released's set matches it. |
| 2200 | if as contributor git push --quiet released release/1.0 2> glob.err; then |
| 2201 | echo "protect-e2e: a glob in the protected set did not match" >&2 |
| 2202 | exit 1 |
| 2203 | fi |
| 2204 | grep -q 'refs/heads/release/1.0' glob.err |
| 2205 | lacks_ref released refs/heads/release/1.0 |
| 2206 | |
| 2207 | # The writer creates it, and updates it. |
| 2208 | as integrator git push --quiet guarded main |
| 2209 | has_ref guarded refs/heads/main |
| 2210 | git commit --quiet --allow-empty -m two |
| 2211 | as integrator git push --quiet guarded main |
| 2212 | second="$(git rev-parse HEAD)" |
| 2213 | [ "$(git -C "$TMPDIR/guarded.git" rev-parse main)" = "$second" ] |
| 2214 | |
| 2215 | # A delete is a write. |
| 2216 | if as contributor git push --quiet --delete guarded main 2> deleted.err; then |
| 2217 | echo "protect-e2e: a non-writer deleted a protected ref" >&2 |
| 2218 | exit 1 |
| 2219 | fi |
| 2220 | grep -q 'refs/heads/main' deleted.err |
| 2221 | has_ref guarded refs/heads/main |
| 2222 | |
| 2223 | # pre-receive answers for the whole push: an open ref |
| 2224 | # travelling with a protected one lands only if the |
| 2225 | # protected one does. |
| 2226 | git commit --quiet --allow-empty -m three |
| 2227 | git branch idea/two |
| 2228 | if as contributor git push --quiet --atomic guarded idea/two main 2> atomic.err; then |
| 2229 | echo "protect-e2e: a protected ref rode in on an atomic push" >&2 |
| 2230 | exit 1 |
| 2231 | fi |
| 2232 | grep -q 'refs/heads/main' atomic.err |
| 2233 | lacks_ref guarded refs/heads/idea/two |
| 2234 | [ "$(git -C "$TMPDIR/guarded.git" rev-parse main)" = "$second" ] |
| 2235 | |
| 2236 | # Attestation refs: anyone may create one … |
| 2237 | att="refs/the-valley/attestations/$(printf '%064d' 0)/key0" |
| 2238 | git update-ref "$att" HEAD~1 |
| 2239 | as contributor git push --quiet guarded "$att:$att" |
| 2240 | has_ref guarded "$att" |
| 2241 | landed="$(git -C "$TMPDIR/guarded.git" rev-parse "$att")" |
| 2242 | |
| 2243 | # … and nobody may rewrite or drop one, writer or not. |
| 2244 | git update-ref "$att" HEAD |
| 2245 | if as contributor git push --quiet --force guarded "$att:$att" 2> rewritten.err; then |
| 2246 | echo "protect-e2e: an attestation ref was rewritten" >&2 |
| 2247 | exit 1 |
| 2248 | fi |
| 2249 | grep -q 'create-only' rewritten.err |
| 2250 | grep -q "$att" rewritten.err |
| 2251 | if as integrator git push --quiet --force guarded "$att:$att" 2> rewritten-by-writer.err; then |
| 2252 | echo "protect-e2e: a writer rewrote an attestation ref" >&2 |
| 2253 | exit 1 |
| 2254 | fi |
| 2255 | grep -q 'create-only' rewritten-by-writer.err |
| 2256 | if as integrator git push --quiet --delete guarded "$att" 2> dropped.err; then |
| 2257 | echo "protect-e2e: an attestation ref was deleted" >&2 |
| 2258 | exit 1 |
| 2259 | fi |
| 2260 | grep -q 'create-only' dropped.err |
| 2261 | [ "$(git -C "$TMPDIR/guarded.git" rev-parse "$att")" = "$landed" ] |
| 2262 | |
| 2263 | # A second attestation beside it is still just a creation. |
| 2264 | att2="refs/the-valley/attestations/$(printf '%064d' 0)/key1" |
| 2265 | git update-ref "$att2" HEAD |
| 2266 | as contributor git push --quiet guarded "$att2:$att2" |
| 2267 | has_ref guarded "$att2" |
| 2268 | |
| 2269 | touch $out |
| 2270 | ''; |
| 2271 | |
| 2272 | # Phase 1's exit criteria, end to end and unmocked: a push to a |
| 2273 | # bare repo wired with the real rendered hooks produces a |
| 2274 | # ref-updated event on a real JetStream server within seconds, |
| 2275 | # visible in `valley tail`; replaying the repo's refs is |
| 2276 | # deterministic; and a dead bus never fails a push. The hook and |
| 2277 | # stream-init scripts are followed from the rendered unit scripts, |
| 2278 | # so the check exercises exactly what a host would run — only the |
| 2279 | # server invocation differs (the sandbox cannot write /srv), same |
| 2280 | # binary and flags, relocated storage. |
| 2281 | bus-e2e = |
| 2282 | pkgs.runCommand "valley-bus-e2e" |
| 2283 | { |
| 2284 | nativeBuildInputs = [ |
| 2285 | pkgs.git |
| 2286 | pkgs.natscli |
| 2287 | pkgs.nats-server |
| 2288 | pkgs.jq |
| 2289 | pkgs.cue |
| 2290 | (valleyScriptFor pkgs) |
| 2291 | ]; |
| 2292 | initScript = busHost.config.systemd.services.valley-init.script; |
| 2293 | busInitScript = busHost.config.systemd.services.valley-bus-init.script; |
| 2294 | passAsFile = [ |
| 2295 | "initScript" |
| 2296 | "busInitScript" |
| 2297 | ]; |
| 2298 | } |
| 2299 | '' |
| 2300 | export HOME="$TMPDIR" |
| 2301 | export NATS_URL=nats://127.0.0.1:4222 |
| 2302 | export GIT_CONFIG_NOSYSTEM=1 |
| 2303 | git config --global user.name valley-check |
| 2304 | git config --global user.email valley-check@localhost |
| 2305 | git config --global init.defaultBranch main |
| 2306 | |
| 2307 | wait_for() { |
| 2308 | for _ in $(seq 1 150); do |
| 2309 | "$@" >/dev/null 2>&1 && return 0 |
| 2310 | sleep 0.2 |
| 2311 | done |
| 2312 | echo "bus-e2e: timed out waiting for: $*" >&2 |
| 2313 | return 1 |
| 2314 | } |
| 2315 | |
| 2316 | nats-server --addr 127.0.0.1 --port 4222 --jetstream \ |
| 2317 | --store_dir "$TMPDIR/js" & |
| 2318 | server_pid=$! |
| 2319 | |
| 2320 | # The real stream-init script the module renders. |
| 2321 | bash -eu "$busInitScriptPath" |
| 2322 | nats stream info valley >/dev/null |
| 2323 | |
| 2324 | # A bare repo wired exactly as valley-init wires it, with the |
| 2325 | # real store paths followed from the rendered init script. |
| 2326 | dispatch="$(grep -o '/nix/store/[^ ]*-valley-post-receive' "$initScriptPath" | head -n1)" |
| 2327 | bushook="$(grep -o '/nix/store/[^ ]*-valley-bus-events' "$initScriptPath" | head -n1)" |
| 2328 | test -x "$dispatch" |
| 2329 | test -x "$bushook" |
| 2330 | repo="$TMPDIR/events-pilot.git" |
| 2331 | git init --quiet --bare "$repo" |
| 2332 | mkdir -p "$repo/hooks/post-receive.d" |
| 2333 | ln -s "$dispatch" "$repo/hooks/post-receive" |
| 2334 | ln -s "$bushook" "$repo/hooks/post-receive.d/valley-bus" |
| 2335 | |
| 2336 | git clone --quiet "$repo" "$TMPDIR/work" |
| 2337 | cd "$TMPDIR/work" |
| 2338 | echo one > file |
| 2339 | git add file |
| 2340 | git commit --quiet -m one |
| 2341 | git push --quiet origin main |
| 2342 | first="$(git rev-parse HEAD)" |
| 2343 | zeros="$(printf '%040d' 0)" |
| 2344 | |
| 2345 | # Exit criterion 1: the event arrives within seconds, with a |
| 2346 | # payload that is exactly the git facts of the push … |
| 2347 | msgs_is() { [ "$(nats stream info valley --json | jq .state.messages)" -eq "$1" ]; } |
| 2348 | wait_for msgs_is 1 |
| 2349 | got="$(nats stream get valley 1 --json)" |
| 2350 | [ "$(jq -r .subject <<<"$got")" = valley.git.events-pilot.ref-updated ] |
| 2351 | payload="$(jq -r .data <<<"$got" | base64 -d)" |
| 2352 | expected='{"event":"ref-updated","repo":"events-pilot","ref":"refs/heads/main","old":"'"$zeros"'","new":"'"$first"'"}' |
| 2353 | [ "$payload" = "$expected" ] |
| 2354 | |
| 2355 | # … valid against the shipped event schema. |
| 2356 | echo "$payload" > "$TMPDIR/payload.json" |
| 2357 | cue vet -d '#RefUpdated' ${./schema/events.cue} "$TMPDIR/payload.json" |
| 2358 | |
| 2359 | # … and visible in `valley tail`. Subscribe first, then push. |
| 2360 | valley tail > "$TMPDIR/tail.out" 2>&1 & |
| 2361 | tail_pid=$! |
| 2362 | subscribed() { grep -q 'valley.>' "$TMPDIR/tail.out"; } |
| 2363 | wait_for subscribed |
| 2364 | echo two > file |
| 2365 | git commit --quiet -am two |
| 2366 | git push --quiet origin main |
| 2367 | second="$(git rev-parse HEAD)" |
| 2368 | wait_for msgs_is 2 |
| 2369 | payload2="$(nats stream get valley 2 --json | jq -r .data | base64 -d)" |
| 2370 | expected2='{"event":"ref-updated","repo":"events-pilot","ref":"refs/heads/main","old":"'"$first"'","new":"'"$second"'"}' |
| 2371 | [ "$payload2" = "$expected2" ] |
| 2372 | tail_saw() { grep -qF "$expected2" "$TMPDIR/tail.out"; } |
| 2373 | wait_for tail_saw |
| 2374 | kill "$tail_pid" 2>/dev/null || true |
| 2375 | |
| 2376 | # Exit criterion 2: rebuilding the stream from the repo's |
| 2377 | # refs is deterministic — two replays from scratch produce |
| 2378 | # identical events, landing on the pushed tip with the |
| 2379 | # all-zero id as old. |
| 2380 | dump_stream() { |
| 2381 | local info first_seq last_seq i |
| 2382 | info="$(nats stream info valley --json)" |
| 2383 | first_seq="$(jq .state.first_seq <<<"$info")" |
| 2384 | last_seq="$(jq .state.last_seq <<<"$info")" |
| 2385 | for i in $(seq "$first_seq" "$last_seq"); do |
| 2386 | nats stream get valley "$i" --json | jq -c '{subject: .subject, data: .data}' |
| 2387 | done |
| 2388 | } |
| 2389 | nats stream purge valley --force >/dev/null |
| 2390 | valley replay "$repo" |
| 2391 | wait_for msgs_is 1 |
| 2392 | run1="$(dump_stream)" |
| 2393 | nats stream purge valley --force >/dev/null |
| 2394 | valley replay "$repo" |
| 2395 | wait_for msgs_is 1 |
| 2396 | run2="$(dump_stream)" |
| 2397 | [ "$run1" = "$run2" ] |
| 2398 | replayed="$(jq -r .data <<<"$run1" | base64 -d)" |
| 2399 | [ "$replayed" = '{"event":"ref-updated","repo":"events-pilot","ref":"refs/heads/main","old":"'"$zeros"'","new":"'"$second"'"}' ] |
| 2400 | |
| 2401 | # A dead bus never blocks a push: the event is simply lost |
| 2402 | # (and rebuildable by replay). |
| 2403 | kill "$server_pid" |
| 2404 | wait "$server_pid" || true |
| 2405 | echo three > file |
| 2406 | git commit --quiet -am three |
| 2407 | git push --quiet origin main |
| 2408 | |
| 2409 | touch $out |
| 2410 | ''; |
| 2411 | } |
| 2412 | ); |
| 2413 | }; |
| 2414 | } |