gunk-dev/the-valley

cli.nix

sourceb04ee164d2afmain's published tip history
5.2 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, and
3# what its review verb publishes when it files an integration request.
4{ pkgs, packages, ... }:
5let
6 # A stand-in for git, sort or cue that fails one chosen call; see
7 # fail-nth.sh.
8 failNth = pkgs.writeShellScript "fail-nth" (builtins.readFile ./fail-nth.sh);
9in
10{
11 # The CLI must stay a lint-clean script whose help verb answers
12 # without a repo or a remote — the cheap end of its eviction clause
13 # (dcr-74c3158); anything needing more graduates instead. The
14 # completions are held to the same bar, and the installed package
15 # must carry them at the auto-linked paths.
16 valley-cli = pkgs.runCommand "valley-cli" {
17 nativeBuildInputs = [
18 pkgs.shellcheck
19 pkgs.zsh
20 packages.valley
21 ];
22 cliScript = ../../bin/valley;
23 bashCompletion = ../../completions/valley.bash;
24 zshCompletion = ../../completions/_valley;
25 valley = packages.valley;
26 } (builtins.readFile ./valley-cli.sh);
27
28 # review's notes: the anchors are the whole claim, so they are
29 # pinned here rather than left to the reader of bin/valley. The
30 # session is real — a pty, real less, a pager filter that
31 # restructures the diff, and an $EDITOR that inserts lines while
32 # the pager is open — because every property under test is a
33 # property of that arrangement: that v is handed the raw buffer
34 # and not the rendering, that an inserted line becomes a note,
35 # and that the file and line it names are the ones it sat on.
36 review-notes = pkgs.runCommand "valley-review-notes" {
37 nativeBuildInputs = [
38 pkgs.git
39 pkgs.less
40 pkgs.util-linux # script(1), for the pty less insists on
41 packages.valley-script
42 ];
43 # The reviewer, as a script: four insertions and one edit of a
44 # line that was already there. The edit is deliberately far
45 # from every insertion, since -U0 would otherwise merge them
46 # into one hunk and the note would be dropped with it.
47 reviewer = pkgs.writeShellScript "valley-review-notes-editor" (
48 builtins.readFile ./review-notes-editor.sh
49 );
50 } (builtins.readFile ./review-notes.sh);
51
52 # The verification-policy deriver (dcr-f41f718). Composing the two
53 # layers is CUE's job and is pinned by cue-vet; matching paths is
54 # the script's own, and a path matcher is wrong exactly at the glob
55 # boundaries — `*` inside one segment against `**` across segments,
56 # `**` matching no segment at all — and at the sides of a diff a
57 # naive reader drops: a rename's old path and a deletion. Each is
58 # pinned by driving the real script over a scratch repository and
59 # the scratch policy in examples/policy/deriver/, whose floor is
60 # one glob boundary per class. A check's cost is pinned the same way:
61 # marking a check slow moves it between the summary lines and the
62 # --cost lists, and changes nothing owed.
63 #
64 # And the deriver fails closed: failNth stands in for git, sort and
65 # cue, and fails each call the deriver makes in turn. Every failure
66 # must end the derivation with nothing on stdout, because a failure
67 # read as an empty list is a change that owes nothing. cliScript is
68 # bin/valley itself, because the package's wrapper puts its own git
69 # ahead of anything on PATH.
70 policy-deriver = pkgs.runCommand "valley-policy-deriver" {
71 nativeBuildInputs = [
72 pkgs.git
73 pkgs.cue
74 packages.valley-script
75 ];
76 fixtures = ../../examples/policy/deriver;
77 schema = ../../schema/verification.cue;
78 cliScript = ../../bin/valley;
79 inherit failNth;
80 } (builtins.readFile ./policy-deriver.sh);
81
82 # review's [a]pprove and the approve and rebase verbs, driven end to end
83 # over scratch repositories: a branch reviewed, the request filed, and
84 # what the receiving side then holds. The claim is about sequencing, so
85 # it is only observable from there — the bare repo logs every push it
86 # receives, and the check reads that log to see that ONE of them carried
87 # the evidence and the request together. Every check the scratch policy
88 # declares uses the command runner, for the reason attest-e2e gives: a
89 # nix build has no daemon. The packaged CLI carries its own schema, so
90 # the scratch projects that stand for projects other than the-valley
91 # carry no schema/. cliScript is bin/valley itself, for its other
92 # shipping mode: run straight from a the-valley checkout, it reads the
93 # schema there.
94 valley-request = pkgs.runCommand "valley-request" {
95 nativeBuildInputs = [
96 pkgs.git
97 pkgs.cue
98 pkgs.openssh
99 packages.attest
100 packages.valley-script
101 ];
102 schemaFile = ../../schema/verification.cue;
103 cliScript = ../../bin/valley;
104 inherit failNth;
105 } (builtins.readFile ./valley-request.sh);
106
107 # Read origin's request/outcome refs and distinguish a pending request,
108 # a recorded decision and a landing, without moving the user's checkout.
109 # Each state is read again through --json, and jq holds the object to
110 # the valley-status/v1 contract.
111 valley-status = pkgs.runCommand "valley-status" {
112 nativeBuildInputs = [
113 pkgs.git
114 pkgs.jq
115 packages.valley-script
116 ];
117 } (builtins.readFile ./valley-status.sh);
118}