gunk-dev/the-valley

cli.nix

sourcedfa994caaeb3main's published tip history
16.1 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 and the rebase engine's 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, what its plan verb shows of that graph, and that its
8# package evaluates for aarch64-darwin.
9{
10 pkgs,
11 self,
12 system,
13 packages,
14 hosts,
15 ...
16}:
17let
18 # A stand-in for git, sort or cue that fails one chosen call; see
19 # fail-nth.sh.
20 failNth = pkgs.writeShellScript "fail-nth" (builtins.readFile ./fail-nth.sh);
21in
22{
23 # The CLI must stay a lint-clean script whose help verb answers
24 # without a repo or a remote — the cheap end of its eviction clause
25 # (dcr-74c3158); anything needing more graduates instead. The
26 # completions are held to the same bar, and the installed package
27 # must carry them at the auto-linked paths.
28 valley-cli = pkgs.runCommand "valley-cli" {
29 nativeBuildInputs = [
30 pkgs.git
31 pkgs.shellcheck
32 pkgs.zsh
33 packages.valley
34 ];
35 cliScript = ../../bin/valley;
36 bashCompletion = ../../completions/valley.bash;
37 zshCompletion = ../../completions/_valley;
38 valley = packages.valley;
39 } (builtins.readFile ./valley-cli.sh);
40
41 # review's notes: the anchors are the whole claim, so they are
42 # pinned here rather than left to the reader of bin/valley. The
43 # session is real — a pty, real less, a pager filter that
44 # restructures the diff, and an $EDITOR that inserts lines while
45 # the pager is open — because every property under test is a
46 # property of that arrangement: that v is handed the raw buffer
47 # and not the rendering, that an inserted line becomes a note,
48 # and that the file and line it names are the ones it sat on. It goes
49 # on to review a stack layer by layer, and a stale stack: approving its
50 # top refused, its bottom approved, and review's [b]ase before the first
51 # page, after which the pages and the request are at the rebased heads,
52 # and the layer approved before the rebase is printed as a clean restack
53 # instead of paged. Last, a note written beside an edited line of a
54 # version paged as changed since its approval keeps its file and line.
55 review-notes = pkgs.runCommand "valley-review-notes" {
56 nativeBuildInputs = [
57 pkgs.git
58 pkgs.less
59 pkgs.util-linux # script(1), for the pty less insists on
60 packages.valley-script
61 ];
62 # The reviewer, as a script: four insertions and one edit of a
63 # line that was already there. The edit is deliberately far
64 # from every insertion, since -U0 would otherwise merge them
65 # into one hunk and the note would be dropped with it.
66 reviewer = pkgs.writeShellScript "valley-review-notes-editor" (
67 builtins.readFile ./review-notes-editor.sh
68 );
69 } (builtins.readFile ./review-notes.sh);
70
71 # The verification-policy deriver (dcr-f41f718). Composing the two
72 # layers is CUE's job and is pinned by cue-vet; matching paths is
73 # the script's own, and a path matcher is wrong exactly at the glob
74 # boundaries — `*` inside one segment against `**` across segments,
75 # `**` matching no segment at all — and at the sides of a diff a
76 # naive reader drops: a rename's old path and a deletion. Each is
77 # pinned by driving the real script over a scratch repository and
78 # the scratch policy in examples/policy/deriver/, whose floor is
79 # one glob boundary per class. A check's cost is pinned the same way:
80 # marking a check slow moves it between the summary lines and the
81 # --cost lists, and changes nothing required. So is the carry mode:
82 # overlapping classes, and paths in different classes, report the
83 # strictest of their modes, and an unclassified path is same-paths. A
84 # mode written by refining `policy` counts. A pattern holding a newline
85 # cannot forge a line of the render: the schema refuses it, the render
86 # refuses it under a schema that admits it, and the deriver refuses the
87 # second line under a render that admits it too.
88 #
89 # And the deriver fails closed: failNth stands in for git, sort and
90 # cue, and fails each call the deriver makes in turn. Every failure
91 # must end the derivation with nothing on stdout, because a failure
92 # read as an empty list is a change that requires nothing. cliScript is
93 # bin/valley itself, because the package's wrapper puts its own git
94 # ahead of anything on PATH.
95 policy-deriver = pkgs.runCommand "valley-policy-deriver" {
96 nativeBuildInputs = [
97 pkgs.git
98 pkgs.cue
99 packages.valley-script
100 ];
101 fixtures = ../../examples/policy/deriver;
102 schema = ../../schema/verification.cue;
103 cliScript = ../../bin/valley;
104 inherit failNth;
105 } (builtins.readFile ./policy-deriver.sh);
106
107 # the-valley's own project layer (policy/project), which is what gates
108 # every change to this repository. A layer that stopped composing would
109 # stop every derivation once it landed, the derivation of its own fix
110 # included, so it is held here before it lands. The floor it is composed
111 # with is the example one: the owning valley's is not in this tree. The
112 # check also holds every check the layer names to being an attribute of
113 # this flake's checks, and holds a docs-only change to requiring
114 # prose-format alone. And it holds a check's own files to requiring
115 # that check: every file in this directory named after a check, and every
116 # other script here, read from the directory itself so a new one is
117 # held as soon as it is added. It holds each scope to its carry mode,
118 # the scopes the carry classes classify to every check they required
119 # before, and the restacker's cap to the default.
120 own-policy = pkgs.runCommand "valley-own-policy" {
121 nativeBuildInputs = [
122 pkgs.git
123 pkgs.cue
124 packages.valley-script
125 ];
126 schema = ../../schema/verification.cue;
127 project = ../../policy/project;
128 floor = ../../examples/policy/instance/floor-format.cue;
129 template = ../../examples/policy/instance/template-docs.cue;
130 checkNames = builtins.attrNames self.checks.${system};
131 checkFiles = builtins.attrNames (builtins.readDir ./.);
132 } (builtins.readFile ./own-policy.sh);
133
134 # review's [a]pprove and the approve and rebase verbs, driven end to end
135 # over scratch repositories: a branch reviewed, the request filed, and
136 # what the receiving side then holds. The claim is about sequencing, so
137 # it is only observable from there — the bare repo logs every push it
138 # receives, and the check reads that log to see that ONE of them carried
139 # the evidence and the request together. A change whose version names no
140 # branch is approved at its recorded head the same way. Every check the scratch policy
141 # declares uses the command runner, for the reason attest-e2e gives: a
142 # nix build has no daemon. The packaged CLI carries its own schema, so
143 # the scratch projects that stand for projects other than the-valley
144 # carry no schema/. cliScript is bin/valley itself, for its other
145 # shipping mode: run straight from a the-valley checkout, it reads the
146 # schema there.
147 valley-request = pkgs.runCommand "valley-request" {
148 nativeBuildInputs = [
149 pkgs.git
150 pkgs.cue
151 pkgs.openssh
152 packages.attest
153 packages.valley-script
154 ];
155 schemaFile = ../../schema/verification.cue;
156 cliScript = ../../bin/valley;
157 inherit failNth;
158 } (builtins.readFile ./valley-request.sh);
159
160 # The rebase engine's tests (rebase/), run in its package's checkPhase
161 # with go vet: a chain, a shared lower layer, a conflict, an empty layer,
162 # a lease lost to a moved branch, a record append refused after the
163 # branches moved, a branch push and a record push that origin takes and
164 # never acknowledges, a cancellation before the push, and a cancellation
165 # while a hook or a filter blocks, each over real repositories and real
166 # pushes. valley-ready and integrator-e2e drive it through valley rebase.
167 rebase-unit = packages.rebase;
168
169 # The Go verbs' tests (status/), run in valley-go's checkPhase: the
170 # outcome records status accepts, the names its JSON refuses, its shell
171 # quoting held to the bash it replaced, and a rebase ended by a SIGTERM
172 # while a hook blocks it. valley-status and valley-ready drive the verbs
173 # through the CLI over real repositories.
174 valley-go-unit = packages.valley-go;
175
176 # Read origin's request/outcome refs and distinguish a pending request,
177 # a recorded decision and a landing, without moving the user's checkout.
178 # Each state is read again through --json, and jq holds the object to
179 # the valley-status/v1 contract. A change's restack report is shown as
180 # current, and as historical once a ref it observed has changed: its
181 # branch, main, its record, a branch it saw missing, or a request that
182 # held it back. Status, changes and pending all show it.
183 valley-status = pkgs.runCommand "valley-status" {
184 nativeBuildInputs = [
185 pkgs.git
186 pkgs.jq
187 packages.valley-script
188 ];
189 } (builtins.readFile ./valley-status.sh);
190
191 # ready, unready and withdraw, through real pushes to a bare repo wired
192 # with the rendered pre-receive hook, as each principal: a change created
193 # at v1, a second version, the same head refused, a withdrawal, revived
194 # at the same version and then at a new one, a principal that neither
195 # owns the change nor holds the request grant refused by the hook, and
196 # the operator, who holds it, let through. Then each source of a change's ID — the jj
197 # header, the Change-Id trailer, a generated ID, --stamp — a header and a
198 # trailer that disagree, and a change whose commits hold a merge. Last, a
199 # change named by its handle is approved, reviewed and rebased at the head
200 # its record names: a record pushed with its branch moved elsewhere in the
201 # same push is refused, the branch at the recorded head is filed at that
202 # head, and a later version whose branch is elsewhere is refused. A
203 # version that names no branch is approved at its head, and refused by
204 # review and rebase, which act on a branch. A name no record is on that
205 # is no branch name is refused. Then a
206 # draft: unready, ready again at the same head and at a new one, listed
207 # apart by pending, refused by approve, rebase and review's [a]pprove
208 # whether it is named by its handle or its branch, and a request pending
209 # under either name warned of by unready and withdraw, a request for an
210 # earlier version's branch too. A review left open while another
211 # principal unreadies the change, or readies a new version, refuses to
212 # act on it. A branch no record is on is acted on as a branch, and one
213 # two records are on is refused. Last, stacks rebased whole: every layer
214 # moved and each change given a version, by ancestry and by trees; a
215 # conflict in the middle layer; each refusal before the rebase; a branch
216 # moved, and a plain branch readied, after the rebase read the stack; a
217 # change unreadied between the branch push and its record write, and the
218 # command the manifest gives to finish it; and a second stack left on an
219 # old head. Then review set against a change's approved version: a clean
220 # restack after [b]ase, with the landing between the bases listed and no
221 # diff paged; a later version with an edited file, paged with the
222 # range-diff and its own diff of that file; a version whose message
223 # alone changed and one whose author alone did, each flagged; a change
224 # with no approved version, paged in full; and a stack whose lower layer
225 # is set against its own approval while its top, which has none, is
226 # paged. The hook is followed from the protected host's rendered init
227 # script, so the rules the record meets are the ones a host applies.
228 valley-ready = pkgs.runCommand "valley-ready" {
229 nativeBuildInputs = [
230 pkgs.git
231 pkgs.jq
232 pkgs.util-linux # script(1), for approve's confirmation on a terminal
233 packages.valley-script
234 ];
235 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
236 passAsFile = [ "initScript" ];
237 } (builtins.readFile ./valley-ready.sh);
238
239 # valley changes and valley pending over the projects of one test host,
240 # made by the integrator host's rendered valley-init, so discovery reads
241 # the project list a host publishes and every record goes through the
242 # hook it installs. Two repositories with ready, draft and withdrawn
243 # records; handles unique across them; one listed repository that cannot
244 # be read; a change ID recorded in several, with qualified handles; --repo;
245 # a version landed by fast-forward, one landed as a new commit with a
246 # transfer statement the integrator signed, one consumed with no
247 # evidence, one whose statement another key signed, one with a landed
248 # version's tree on another parent, a landing's tree replayed on a later
249 # main, and heads below a merge that dropped them, through either
250 # parent; a project named origin that shares a change ID; a
251 # policy/valley git would read as an option or
252 # as ext::; includes as the nearest ancestor only; pending's human shape,
253 # its drafts array and --checks; and a branch name read as a branch again
254 # once its change has landed, before the branch moves and after.
255 valley-changes = pkgs.runCommand "valley-changes" {
256 nativeBuildInputs = [
257 pkgs.git
258 pkgs.jq
259 pkgs.openssh
260 packages.valley-script
261 packages.valley-go
262 packages.attest
263 ];
264 initScript = hosts.integratorHost.config.systemd.services.valley-init.script;
265 passAsFile = [ "initScript" ];
266 # The floor --checks derives under.
267 floor = ../../examples/policy/instance;
268 } (builtins.readFile ./valley-changes.sh);
269
270 # valley knot against local bare repositories that run no hook, as any
271 # git remote would: every verb, the ref's shape after each write, another
272 # project named by --project and by a qualified id, and then each way a
273 # write may fail to land the first time. A stand-in for git, first on
274 # PATH, makes another writer land between a read and its push, drops the
275 # connection after a push lands and after one that did not, takes a
276 # claim or changes a field first, and releases and retakes a claim an
277 # unclaim read. Each write must then land exactly once, or be reported
278 # as a conflict. Two writers also run at once. cliScript
279 # is bin/valley itself, because the package's wrapper puts its own git
280 # ahead of the stand-in.
281 valley-knot = pkgs.runCommand "valley-knot" {
282 nativeBuildInputs = [
283 pkgs.git
284 pkgs.jq
285 packages.valley-go
286 ];
287 cliScript = ../../bin/valley;
288 } (builtins.readFile ./valley-knot.sh);
289
290 # valley plan against local bare repositories that run no hook: a graph
291 # built with the real knot verbs, each at a time VALLEY_NOW fixes, so
292 # every date and age it shows is the same on every run. The text, off a
293 # terminal, and the valley-plan/v1 document are compared with golden
294 # files kept beside the code that prints them (status/testdata/plan/).
295 # Then a project with no graph, --all over the projects the instance
296 # publishes with one that cannot be read, and the operator named by
297 # --owner and by no one. cliScript is bin/valley itself, as for
298 # valley-knot.
299 valley-plan = pkgs.runCommand "valley-plan" {
300 nativeBuildInputs = [
301 pkgs.git
302 pkgs.jq
303 pkgs.gawk
304 pkgs.diffutils
305 packages.valley-go
306 ];
307 cliScript = ../../bin/valley;
308 golden = ../../status/testdata/plan;
309 } (builtins.readFile ./valley-plan.sh);
310
311 # The CLI is offered for aarch64-darwin, which nothing here builds or
312 # tests (flake.nix). This check holds that offer to evaluating: an input
313 # with no Darwin build fails here rather than on a Mac. The package's
314 # drvPath is forced while this check is evaluated, and its string context
315 # is discarded, so the Darwin derivations are written to the store but
316 # are not inputs of this one. Building this check builds and substitutes
317 # nothing for Darwin.
318 valley-darwin-eval = pkgs.runCommand "valley-darwin-eval" {
319 darwinDrv = builtins.unsafeDiscardStringContext self.packages.aarch64-darwin.valley.drvPath;
320 darwinSystem = self.packages.aarch64-darwin.valley.system;
321 } (builtins.readFile ./valley-darwin-eval.sh);
322}