| 1 | # bin/valley: that it stays a lint-clean script, what its review verb |
| 2 | # anchors a note to, what its deriver makes of a policy and a diff, that |
| 3 | # the-valley's own policy composes and names only checks that exist, what |
| 4 | # its review verb publishes when it files an integration request, what its |
| 5 | # Go verbs' unit tests hold, what its ready and withdraw verbs write to a |
| 6 | # change's record through the real push hook, and that its package |
| 7 | # evaluates for aarch64-darwin. |
| 8 | { |
| 9 | pkgs, |
| 10 | self, |
| 11 | system, |
| 12 | packages, |
| 13 | hosts, |
| 14 | ... |
| 15 | }: |
| 16 | let |
| 17 | # A stand-in for git, sort or cue that fails one chosen call; see |
| 18 | # fail-nth.sh. |
| 19 | failNth = pkgs.writeShellScript "fail-nth" (builtins.readFile ./fail-nth.sh); |
| 20 | in |
| 21 | { |
| 22 | # The CLI must stay a lint-clean script whose help verb answers |
| 23 | # without a repo or a remote — the cheap end of its eviction clause |
| 24 | # (dcr-74c3158); anything needing more graduates instead. The |
| 25 | # completions are held to the same bar, and the installed package |
| 26 | # must carry them at the auto-linked paths. |
| 27 | valley-cli = pkgs.runCommand "valley-cli" { |
| 28 | nativeBuildInputs = [ |
| 29 | pkgs.shellcheck |
| 30 | pkgs.zsh |
| 31 | packages.valley |
| 32 | ]; |
| 33 | cliScript = ../../bin/valley; |
| 34 | bashCompletion = ../../completions/valley.bash; |
| 35 | zshCompletion = ../../completions/_valley; |
| 36 | valley = packages.valley; |
| 37 | } (builtins.readFile ./valley-cli.sh); |
| 38 | |
| 39 | # review's notes: the anchors are the whole claim, so they are |
| 40 | # pinned here rather than left to the reader of bin/valley. The |
| 41 | # session is real — a pty, real less, a pager filter that |
| 42 | # restructures the diff, and an $EDITOR that inserts lines while |
| 43 | # the pager is open — because every property under test is a |
| 44 | # property of that arrangement: that v is handed the raw buffer |
| 45 | # and not the rendering, that an inserted line becomes a note, |
| 46 | # and that the file and line it names are the ones it sat on. |
| 47 | review-notes = pkgs.runCommand "valley-review-notes" { |
| 48 | nativeBuildInputs = [ |
| 49 | pkgs.git |
| 50 | pkgs.less |
| 51 | pkgs.util-linux # script(1), for the pty less insists on |
| 52 | packages.valley-script |
| 53 | ]; |
| 54 | # The reviewer, as a script: four insertions and one edit of a |
| 55 | # line that was already there. The edit is deliberately far |
| 56 | # from every insertion, since -U0 would otherwise merge them |
| 57 | # into one hunk and the note would be dropped with it. |
| 58 | reviewer = pkgs.writeShellScript "valley-review-notes-editor" ( |
| 59 | builtins.readFile ./review-notes-editor.sh |
| 60 | ); |
| 61 | } (builtins.readFile ./review-notes.sh); |
| 62 | |
| 63 | # The verification-policy deriver (dcr-f41f718). Composing the two |
| 64 | # layers is CUE's job and is pinned by cue-vet; matching paths is |
| 65 | # the script's own, and a path matcher is wrong exactly at the glob |
| 66 | # boundaries — `*` inside one segment against `**` across segments, |
| 67 | # `**` matching no segment at all — and at the sides of a diff a |
| 68 | # naive reader drops: a rename's old path and a deletion. Each is |
| 69 | # pinned by driving the real script over a scratch repository and |
| 70 | # the scratch policy in examples/policy/deriver/, whose floor is |
| 71 | # one glob boundary per class. A check's cost is pinned the same way: |
| 72 | # marking a check slow moves it between the summary lines and the |
| 73 | # --cost lists, and changes nothing owed. |
| 74 | # |
| 75 | # And the deriver fails closed: failNth stands in for git, sort and |
| 76 | # cue, and fails each call the deriver makes in turn. Every failure |
| 77 | # must end the derivation with nothing on stdout, because a failure |
| 78 | # read as an empty list is a change that owes nothing. cliScript is |
| 79 | # bin/valley itself, because the package's wrapper puts its own git |
| 80 | # ahead of anything on PATH. |
| 81 | policy-deriver = pkgs.runCommand "valley-policy-deriver" { |
| 82 | nativeBuildInputs = [ |
| 83 | pkgs.git |
| 84 | pkgs.cue |
| 85 | packages.valley-script |
| 86 | ]; |
| 87 | fixtures = ../../examples/policy/deriver; |
| 88 | schema = ../../schema/verification.cue; |
| 89 | cliScript = ../../bin/valley; |
| 90 | inherit failNth; |
| 91 | } (builtins.readFile ./policy-deriver.sh); |
| 92 | |
| 93 | # the-valley's own project layer (policy/project), which is what gates |
| 94 | # every change to this repository. A layer that stopped composing would |
| 95 | # stop every derivation once it landed, the derivation of its own fix |
| 96 | # included, so it is held here before it lands. The floor it is composed |
| 97 | # with is the example one: the owning valley's is not in this tree. The |
| 98 | # check also holds every check the layer names to being an attribute of |
| 99 | # this flake's checks, and holds a docs-only change to owing |
| 100 | # prose-format alone. And it holds a check's own files to owing that |
| 101 | # check: every file in this directory named after a check, and every |
| 102 | # other script here, read from the directory itself so a new one is |
| 103 | # held as soon as it is added. |
| 104 | own-policy = pkgs.runCommand "valley-own-policy" { |
| 105 | nativeBuildInputs = [ |
| 106 | pkgs.git |
| 107 | pkgs.cue |
| 108 | packages.valley-script |
| 109 | ]; |
| 110 | schema = ../../schema/verification.cue; |
| 111 | project = ../../policy/project; |
| 112 | floor = ../../examples/policy/instance/floor-format.cue; |
| 113 | template = ../../examples/policy/instance/template-docs.cue; |
| 114 | checkNames = builtins.attrNames self.checks.${system}; |
| 115 | checkFiles = builtins.attrNames (builtins.readDir ./.); |
| 116 | } (builtins.readFile ./own-policy.sh); |
| 117 | |
| 118 | # review's [a]pprove and the approve and rebase verbs, driven end to end |
| 119 | # over scratch repositories: a branch reviewed, the request filed, and |
| 120 | # what the receiving side then holds. The claim is about sequencing, so |
| 121 | # it is only observable from there — the bare repo logs every push it |
| 122 | # receives, and the check reads that log to see that ONE of them carried |
| 123 | # the evidence and the request together. A change whose version names no |
| 124 | # branch is approved at its recorded head the same way. Every check the scratch policy |
| 125 | # declares uses the command runner, for the reason attest-e2e gives: a |
| 126 | # nix build has no daemon. The packaged CLI carries its own schema, so |
| 127 | # the scratch projects that stand for projects other than the-valley |
| 128 | # carry no schema/. cliScript is bin/valley itself, for its other |
| 129 | # shipping mode: run straight from a the-valley checkout, it reads the |
| 130 | # schema there. |
| 131 | valley-request = pkgs.runCommand "valley-request" { |
| 132 | nativeBuildInputs = [ |
| 133 | pkgs.git |
| 134 | pkgs.cue |
| 135 | pkgs.openssh |
| 136 | packages.attest |
| 137 | packages.valley-script |
| 138 | ]; |
| 139 | schemaFile = ../../schema/verification.cue; |
| 140 | cliScript = ../../bin/valley; |
| 141 | inherit failNth; |
| 142 | } (builtins.readFile ./valley-request.sh); |
| 143 | |
| 144 | # The Go verbs' tests (status/), run in valley-go's checkPhase: the |
| 145 | # outcome records status accepts, the names its JSON refuses, and its |
| 146 | # shell quoting held to the bash it replaced. valley-status and |
| 147 | # valley-ready drive the verbs through the CLI over real repositories. |
| 148 | valley-go-unit = packages.valley-go; |
| 149 | |
| 150 | # Read origin's request/outcome refs and distinguish a pending request, |
| 151 | # a recorded decision and a landing, without moving the user's checkout. |
| 152 | # Each state is read again through --json, and jq holds the object to |
| 153 | # the valley-status/v1 contract. |
| 154 | valley-status = pkgs.runCommand "valley-status" { |
| 155 | nativeBuildInputs = [ |
| 156 | pkgs.git |
| 157 | pkgs.jq |
| 158 | packages.valley-script |
| 159 | ]; |
| 160 | } (builtins.readFile ./valley-status.sh); |
| 161 | |
| 162 | # ready, unready and withdraw, through real pushes to a bare repo wired |
| 163 | # with the rendered pre-receive hook, as each principal: a change created |
| 164 | # at v1, a second version, the same head refused, a withdrawal, revived |
| 165 | # at the same version and then at a new one, a principal that neither |
| 166 | # owns the change nor holds the request grant refused by the hook, and |
| 167 | # the operator, who holds it, let through. Then each source of a change's ID — the jj |
| 168 | # header, the Change-Id trailer, a generated ID, --stamp — a header and a |
| 169 | # trailer that disagree, and a change whose commits hold a merge. Last, a |
| 170 | # change named by its handle is approved, reviewed and rebased at the head |
| 171 | # its record names: a record pushed with its branch moved elsewhere in the |
| 172 | # same push is refused, the branch at the recorded head is filed at that |
| 173 | # head, and a later version whose branch is elsewhere is refused. A |
| 174 | # version that names no branch is approved at its head, and refused by |
| 175 | # review and rebase, which act on a branch. A name no record is on that |
| 176 | # is no branch name is refused. Then a |
| 177 | # draft: unready, ready again at the same head and at a new one, listed |
| 178 | # apart by pending, refused by approve, rebase and review's [a]pprove |
| 179 | # whether it is named by its handle or its branch, and a request pending |
| 180 | # under either name warned of by unready and withdraw, a request for an |
| 181 | # earlier version's branch too. A review left open while another |
| 182 | # principal unreadies the change, or readies a new version, refuses to |
| 183 | # act on it. A branch no record is on is acted on as a branch, and one |
| 184 | # two records are on is refused. The hook is followed from the protected |
| 185 | # host's rendered init script, so the rules the record meets are the |
| 186 | # ones a host applies. |
| 187 | valley-ready = pkgs.runCommand "valley-ready" { |
| 188 | nativeBuildInputs = [ |
| 189 | pkgs.git |
| 190 | pkgs.jq |
| 191 | pkgs.util-linux # script(1), for approve's confirmation on a terminal |
| 192 | packages.valley-script |
| 193 | ]; |
| 194 | initScript = hosts.protectedHost.config.systemd.services.valley-init.script; |
| 195 | passAsFile = [ "initScript" ]; |
| 196 | } (builtins.readFile ./valley-ready.sh); |
| 197 | |
| 198 | # valley changes and valley pending over the projects of one test host, |
| 199 | # made by the integrator host's rendered valley-init, so discovery reads |
| 200 | # the project list a host publishes and every record goes through the |
| 201 | # hook it installs. Two repositories with ready, draft and withdrawn |
| 202 | # records; handles unique across them; one listed repository that cannot |
| 203 | # be read; a change ID recorded in several, with qualified handles; --repo; |
| 204 | # a version landed by fast-forward, one landed as a new commit with a |
| 205 | # transfer statement the integrator signed, one consumed with no |
| 206 | # evidence, one whose statement another key signed, one with a landed |
| 207 | # version's tree on another parent, a landing's tree replayed on a later |
| 208 | # main, and heads below a merge that dropped them, through either |
| 209 | # parent; a project named origin that shares a change ID; a |
| 210 | # policy/valley git would read as an option or |
| 211 | # as ext::; includes as the nearest ancestor only; pending's human shape, |
| 212 | # its drafts array and --owes; and a branch name read as a branch again |
| 213 | # once its change has landed, before the branch moves and after. |
| 214 | valley-changes = pkgs.runCommand "valley-changes" { |
| 215 | nativeBuildInputs = [ |
| 216 | pkgs.git |
| 217 | pkgs.jq |
| 218 | pkgs.openssh |
| 219 | packages.valley-script |
| 220 | packages.valley-go |
| 221 | packages.attest |
| 222 | ]; |
| 223 | initScript = hosts.integratorHost.config.systemd.services.valley-init.script; |
| 224 | passAsFile = [ "initScript" ]; |
| 225 | # The floor --owes derives under. |
| 226 | floor = ../../examples/policy/instance; |
| 227 | } (builtins.readFile ./valley-changes.sh); |
| 228 | |
| 229 | # The CLI is offered for aarch64-darwin, which nothing here builds or |
| 230 | # tests (flake.nix). This check holds that offer to evaluating: an input |
| 231 | # with no Darwin build fails here rather than on a Mac. The package's |
| 232 | # drvPath is forced while this check is evaluated, and its string context |
| 233 | # is discarded, so the Darwin derivations are written to the store but |
| 234 | # are not inputs of this one. Building this check builds and substitutes |
| 235 | # nothing for Darwin. |
| 236 | valley-darwin-eval = pkgs.runCommand "valley-darwin-eval" { |
| 237 | darwinDrv = builtins.unsafeDiscardStringContext self.packages.aarch64-darwin.valley.drvPath; |
| 238 | darwinSystem = self.packages.aarch64-darwin.valley.system; |
| 239 | } (builtins.readFile ./valley-darwin-eval.sh); |
| 240 | } |