gunk-dev/the-valley

cli.nix

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