| 1 | # The hooks the module renders, run against real git. Each check follows the |
| 2 | # store paths out of a rendered valley-init script, so what it drives is what |
| 3 | # a host would execute — never a copy of it written for the test. |
| 4 | # |
| 5 | # A check that pushes through the pre-receive hook runs the real valleyhook, |
| 6 | # and takes the hosts that run it. mirror-e2e, bus-e2e and init-e2e run none |
| 7 | # of this flake's programs: they drive what the module renders around them, |
| 8 | # so they take the hosts rendered over stand-ins (nix/checks/hosts.nix), and |
| 9 | # an edit to a program does not change them. |
| 10 | { |
| 11 | pkgs, |
| 12 | packages, |
| 13 | hosts, |
| 14 | stubbedHosts, |
| 15 | ... |
| 16 | }: |
| 17 | { |
| 18 | # What a mirror ends up holding, end to end and unmocked: a bare |
| 19 | # repo wired with the real rendered hooks, pushed to for real, the |
| 20 | # real drain run as its unit would run it, and a second bare repo |
| 21 | # standing in for the mirror. The push is easy to get subtly |
| 22 | # wrong — it must publish main and the tags, delete the tags the |
| 23 | # primary deleted, and leave every other ref on the mirror as it |
| 24 | # is — and only running git can tell. |
| 25 | # Relative mirror URLs (mirrorHost) resolve against the pushing |
| 26 | # repo, so the shipped scripts run with no substitution: this is |
| 27 | # exactly what a host executes. |
| 28 | # |
| 29 | # It also stalls a push in the window where git has read the local |
| 30 | # refs and not yet the mirror's. Two pushers at once rewind the |
| 31 | # mirror there; the drain, the only publisher, leaves the newer |
| 32 | # move queued and publishes it next. |
| 33 | mirror-e2e = pkgs.runCommand "valley-mirror-e2e" { |
| 34 | nativeBuildInputs = [ pkgs.git ]; |
| 35 | initScript = stubbedHosts.mirrorHost.config.systemd.services.valley-init.script; |
| 36 | publishUnit = stubbedHosts.mirrorHost.config.systemd.units."valley-publish@.service".text; |
| 37 | passAsFile = [ |
| 38 | "initScript" |
| 39 | "publishUnit" |
| 40 | ]; |
| 41 | } (builtins.readFile ./mirror-e2e.sh); |
| 42 | |
| 43 | # The pre-receive hook's policy, rule by rule where a rule is |
| 44 | # subtle: the glob matching of a declared pattern, the order in which |
| 45 | # the rules are tried, and every transition of a change record, each |
| 46 | # refusal against real git objects. What the hook does to a real push |
| 47 | # is protect-e2e's, valley-ready's for the records the CLI writes, and |
| 48 | # knots-e2e's for the plan graph. |
| 49 | valleyhook-unit = packages.valleyhook.unit; |
| 50 | |
| 51 | # The note envelope every reader of an attestation shares (note/). |
| 52 | note-unit = packages.note.unit; |
| 53 | |
| 54 | # The strict JSON reading the hook reads its push policy with, the |
| 55 | # identity compiler its registry, and read access a policy/read and the |
| 56 | # registry (exactjson/). |
| 57 | exactjson-unit = packages.exactjson.unit; |
| 58 | |
| 59 | # The change record the hook guards and the CLI writes (change/): its |
| 60 | # strict reading, and the fuzz target's seed corpus. |
| 61 | change-unit = packages.change.unit; |
| 62 | |
| 63 | # The one structural invariant, driven for real: bare repos wired |
| 64 | # with the rendered pre-receive hook, pushed to as each principal. |
| 65 | # What sshd would set from a key's authorized_keys entry, these |
| 66 | # pushes set in the environment directly — that rendering is pinned |
| 67 | # by module-eval, and everything the hook decides after it is what |
| 68 | # this check exercises: protected refs, attestations and the names |
| 69 | # they may take, integration requests and the approve grant under both |
| 70 | # its names, the changes of a change record's state, the restack |
| 71 | # grant's one version and each write it does not authorise, restack |
| 72 | # reports and their history, named grants, symbolic refs, refs named |
| 73 | # like other refs and the one-off report of them, a composed hook, and |
| 74 | # the namespaces every push is refused. An |
| 75 | # attestation's tree written by hand, with the genuine note at a name |
| 76 | # holding a slash, is refused. Projects with and without protection are |
| 77 | # both served. Last, the rendered init script wires a repository that |
| 78 | # already has history, and the hook it installs refuses an untagged key |
| 79 | # and takes a declared writer's push: the check begins where init-e2e |
| 80 | # ends. |
| 81 | protect-e2e = pkgs.runCommand "valley-protect-e2e" { |
| 82 | nativeBuildInputs = [ |
| 83 | pkgs.git |
| 84 | pkgs.openssh |
| 85 | # Real attestations, made the way a contributor makes them, for the |
| 86 | # namespace the hook checks the contents of. |
| 87 | packages.attest |
| 88 | ]; |
| 89 | initScript = hosts.protectedHost.config.systemd.services.valley-init.script; |
| 90 | passAsFile = [ "initScript" ]; |
| 91 | } (builtins.readFile ./protect-e2e.sh); |
| 92 | |
| 93 | # The plan graph, refs/the-valley/knots, through the hook the protected |
| 94 | # host renders. The real valley knot writes it as two principals, and |
| 95 | # every write lands; then crafted pushes break each rule the hook holds a |
| 96 | # push to the graph to, and each is refused with the ref left where it |
| 97 | # was: an untagged key, a non-fast-forward update, a merge, two commits, |
| 98 | # a parent that is not the old tip, a tag, another committer, a missing |
| 99 | # trailer, a deleted comment, an edit that records no edit, names |
| 100 | # another editor, half its record or no UTC time, changes the author, or |
| 101 | # comes from a principal without the approve grant, a new comment that |
| 102 | # records an edit, a deleted knot, a changed id, |
| 103 | # type or created_by, a forged author or creator, a symlink, an |
| 104 | # executable, a file or directory outside the layout, a non-canonical |
| 105 | # knot, an oversized one, a shared-subtree bomb, a dangling edge, a |
| 106 | # cycle, a deletion of the ref, and refs that only begin with its name. |
| 107 | # Trees written by hand are refused too: a root file named |
| 108 | # ideas/<id>-<slug>.md, every file flattened into names with slashes, a |
| 109 | # directory in the mode 040000, and entries named ".", ".." and "", the |
| 110 | # last sent to receive-pack directly, since git push will not send it. |
| 111 | # A refused write from the CLI runs the hook once. A create with a |
| 112 | # parent is refused and one without is admitted, and a valid graph |
| 113 | # update carries no invalid change record, attestation or integration |
| 114 | # request through with it. Comments are edited by the real CLI and by |
| 115 | # crafted pushes: by their author, and by holders of the approve grant |
| 116 | # under each of its names, while another principal is refused, and |
| 117 | # valley knot log and show --at give back every earlier text. |
| 118 | knots-e2e = pkgs.runCommand "valley-knots-e2e" { |
| 119 | nativeBuildInputs = [ |
| 120 | pkgs.git |
| 121 | pkgs.jq |
| 122 | packages.valley-unwrapped |
| 123 | ]; |
| 124 | initScript = hosts.protectedHost.config.systemd.services.valley-init.script; |
| 125 | passAsFile = [ "initScript" ]; |
| 126 | } (builtins.readFile ./knots-e2e.sh); |
| 127 | |
| 128 | # valley-init itself, over repositories that already exist. The other |
| 129 | # hook checks wire a bare repo by hand; this one runs the rendered init |
| 130 | # script and holds it to converging on what the declaration says — the |
| 131 | # managed hook installed where a project had none, re-pointed where it |
| 132 | # had drifted to another store path, removed where the declaration no |
| 133 | # longer protects the project, and a hand-written hook of the same name |
| 134 | # left alone. The hooks run a stand-in for valleyhook, so nothing is |
| 135 | # pushed through them here: protect-e2e pushes through the hook this |
| 136 | # script converges on, with the real valleyhook. Relocating the data |
| 137 | # directory is the only edit to the script — the sandbox cannot write |
| 138 | # /srv. |
| 139 | init-e2e = pkgs.runCommand "valley-init-e2e" { |
| 140 | nativeBuildInputs = [ pkgs.git ]; |
| 141 | initScript = stubbedHosts.protectedHost.config.systemd.services.valley-init.script; |
| 142 | integratorInitScript = stubbedHosts.integratorHost.config.systemd.services.valley-init.script; |
| 143 | passAsFile = [ |
| 144 | "initScript" |
| 145 | "integratorInitScript" |
| 146 | ]; |
| 147 | } (builtins.readFile ./init-e2e.sh); |
| 148 | |
| 149 | # Phase 1's exit criteria, end to end and unmocked: a push to a |
| 150 | # bare repo wired with the real rendered hooks produces a |
| 151 | # ref-updated event on a real JetStream server within seconds, |
| 152 | # visible in `valley tail`; replaying the repo's refs is |
| 153 | # deterministic; and a dead bus never fails a push. The hook and |
| 154 | # stream-init scripts are followed from the rendered unit scripts, |
| 155 | # so the check exercises exactly what a host would run — only the |
| 156 | # server invocation differs (the sandbox cannot write /srv), same |
| 157 | # binary and flags, relocated storage. |
| 158 | bus-e2e = pkgs.runCommand "valley-bus-e2e" { |
| 159 | nativeBuildInputs = [ |
| 160 | pkgs.git |
| 161 | pkgs.natscli |
| 162 | pkgs.nats-server |
| 163 | pkgs.jq |
| 164 | pkgs.cue |
| 165 | packages.valley-unstamped |
| 166 | ]; |
| 167 | initScript = stubbedHosts.busHost.config.systemd.services.valley-init.script; |
| 168 | busInitScript = stubbedHosts.busHost.config.systemd.services.valley-bus-init.script; |
| 169 | eventSchema = ../../schema/events.cue; |
| 170 | passAsFile = [ |
| 171 | "initScript" |
| 172 | "busInitScript" |
| 173 | ]; |
| 174 | } (builtins.readFile ./bus-e2e.sh); |
| 175 | } |