gunk-dev/the-valley

cli.nix

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