gunk-dev/the-valley

hooks.nix

sourceb990a1416c2fmain's published tip history
7.1 KiB
1# The hooks the module renders, run against real git. Each check follows the
2# store paths out of a rendered valley-init script, so what it drives is what
3# a host would execute — never a copy of it written for the test.
4{
5 pkgs,
6 packages,
7 hosts,
8 ...
9}:
10{
11 # What a mirror ends up holding, end to end and unmocked: a bare
12 # repo wired with the real rendered hooks, pushed to for real, the
13 # real drain run as its unit would run it, and a second bare repo
14 # standing in for the mirror. The push is easy to get subtly
15 # wrong — it must publish main and the tags, delete the tags the
16 # primary deleted, and leave every other ref on the mirror as it
17 # is — and only running git can tell.
18 # Relative mirror URLs (mirrorHost) resolve against the pushing
19 # repo, so the shipped scripts run with no substitution: this is
20 # exactly what a host executes.
21 #
22 # It also stalls a push in the window where git has read the local
23 # refs and not yet the mirror's. Two pushers at once rewind the
24 # mirror there; the drain, the only publisher, leaves the newer
25 # move queued and publishes it next.
26 mirror-e2e = pkgs.runCommand "valley-mirror-e2e" {
27 nativeBuildInputs = [ pkgs.git ];
28 initScript = hosts.mirrorHost.config.systemd.services.valley-init.script;
29 publishUnit = hosts.mirrorHost.config.systemd.units."valley-publish@.service".text;
30 passAsFile = [
31 "initScript"
32 "publishUnit"
33 ];
34 } (builtins.readFile ./mirror-e2e.sh);
35
36 # The pre-receive hook's policy, rule by rule where a rule is
37 # subtle: the glob matching of a declared pattern, the order in which
38 # the rules are tried, and every transition of a change record, each
39 # refusal against real git objects. What the hook does to a real push
40 # is protect-e2e's, valley-ready's for the records the CLI writes, and
41 # knots-e2e's for the plan graph.
42 valleyhook-unit = packages.valleyhook;
43
44 # The note envelope every reader of an attestation shares (note/).
45 note-unit = packages.note;
46
47 # The change record the hook guards and the CLI writes (change/): its
48 # strict reading, and the fuzz target's seed corpus.
49 change-unit = packages.change;
50
51 # The one structural invariant, driven for real: bare repos wired
52 # with the rendered pre-receive hook, pushed to as each principal.
53 # What sshd would set from a key's authorized_keys entry, these
54 # pushes set in the environment directly — that rendering is pinned
55 # by module-eval, and everything the hook decides after it is what
56 # this check exercises: protected refs, attestations and the names
57 # they may take, integration requests and the approve grant under both
58 # its names, the changes of a change record's state, the restack
59 # grant's one version and each write it does not authorise, restack
60 # reports and their history, named grants, symbolic refs, a composed
61 # hook, and the namespaces every push is refused. An
62 # attestation's tree written by hand, with the genuine note at a name
63 # holding a slash, is refused. Projects with and without protection are
64 # both served.
65 protect-e2e = pkgs.runCommand "valley-protect-e2e" {
66 nativeBuildInputs = [
67 pkgs.git
68 pkgs.openssh
69 # Real attestations, made the way a contributor makes them, for the
70 # namespace the hook checks the contents of.
71 packages.attest
72 ];
73 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
74 passAsFile = [ "initScript" ];
75 } (builtins.readFile ./protect-e2e.sh);
76
77 # The plan graph, refs/the-valley/knots, through the hook the protected
78 # host renders. The real valley knot writes it as two principals, and
79 # every write lands; then crafted pushes break each rule the hook holds a
80 # push to the graph to, and each is refused with the ref left where it
81 # was: an untagged key, a non-fast-forward update, a merge, two commits,
82 # a parent that is not the old tip, a tag, another committer, a missing
83 # trailer, a deleted or changed comment, a deleted knot, a changed id,
84 # type or created_by, a forged author or creator, a symlink, an
85 # executable, a file or directory outside the layout, a non-canonical
86 # knot, an oversized one, a shared-subtree bomb, a dangling edge, a
87 # cycle, a deletion of the ref, and refs that only begin with its name.
88 # Trees written by hand are refused too: a root file named
89 # ideas/<id>-<slug>.md, every file flattened into names with slashes, a
90 # directory in the mode 040000, and entries named ".", ".." and "", the
91 # last sent to receive-pack directly, since git push will not send it.
92 # A refused write from the CLI runs the hook once. A create with a
93 # parent is refused and one without is admitted, and a valid graph
94 # update carries no invalid change record, attestation or integration
95 # request through with it.
96 knots-e2e = pkgs.runCommand "valley-knots-e2e" {
97 nativeBuildInputs = [
98 pkgs.git
99 packages.valley-go
100 ];
101 cliScript = ../../bin/valley;
102 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
103 passAsFile = [ "initScript" ];
104 } (builtins.readFile ./knots-e2e.sh);
105
106 # valley-init itself, over repositories that already exist. The other
107 # hook checks wire a bare repo by hand; this one runs the rendered init
108 # script and holds it to converging on what the declaration says — the
109 # managed hook installed where a project had none, re-pointed where it
110 # had drifted to another store path, removed where the declaration no
111 # longer protects the project, and a hand-written hook of the same name
112 # left alone. The hook it converges on is then pushed to for real, so
113 # the check ends where protect-e2e begins. Relocating the data
114 # directory is the only edit to the script — the sandbox cannot write
115 # /srv.
116 init-e2e = pkgs.runCommand "valley-init-e2e" {
117 nativeBuildInputs = [ pkgs.git ];
118 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
119 integratorInitScript = hosts.integratorHost.config.systemd.services.valley-init.script;
120 passAsFile = [
121 "initScript"
122 "integratorInitScript"
123 ];
124 } (builtins.readFile ./init-e2e.sh);
125
126 # Phase 1's exit criteria, end to end and unmocked: a push to a
127 # bare repo wired with the real rendered hooks produces a
128 # ref-updated event on a real JetStream server within seconds,
129 # visible in `valley tail`; replaying the repo's refs is
130 # deterministic; and a dead bus never fails a push. The hook and
131 # stream-init scripts are followed from the rendered unit scripts,
132 # so the check exercises exactly what a host would run — only the
133 # server invocation differs (the sandbox cannot write /srv), same
134 # binary and flags, relocated storage.
135 bus-e2e = pkgs.runCommand "valley-bus-e2e" {
136 nativeBuildInputs = [
137 pkgs.git
138 pkgs.natscli
139 pkgs.nats-server
140 pkgs.jq
141 pkgs.cue
142 packages.valley-script
143 ];
144 initScript = hosts.busHost.config.systemd.services.valley-init.script;
145 busInitScript = hosts.busHost.config.systemd.services.valley-bus-init.script;
146 eventSchema = ../../schema/events.cue;
147 passAsFile = [
148 "initScript"
149 "busInitScript"
150 ];
151 } (builtins.readFile ./bus-e2e.sh);
152}