gunk-dev/the-valley

cli.nix

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