gunk-dev/the-valley

hooks.nix

source8c4ff6fd0e3bmain's published tip history
6.5 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 request grant, the
58 # changes of a change record's state, named grants, symbolic refs, a
59 # composed hook, and the namespaces every push is refused. Projects with and without protection are both served.
60 protect-e2e = pkgs.runCommand "valley-protect-e2e" {
61 nativeBuildInputs = [
62 pkgs.git
63 pkgs.openssh
64 # Real attestations, made the way a contributor makes them, for the
65 # namespace the hook checks the contents of.
66 packages.attest
67 ];
68 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
69 passAsFile = [ "initScript" ];
70 } (builtins.readFile ./protect-e2e.sh);
71
72 # The plan graph, refs/the-valley/knots, through the hook the protected
73 # host renders. The real valley knot writes it as two principals, and
74 # every write lands; then crafted pushes break each rule the hook holds a
75 # push to the graph to, and each is refused with the ref left where it
76 # was: an untagged key, a non-fast-forward update, a merge, two commits,
77 # a parent that is not the old tip, a tag, another committer, a missing
78 # trailer, a deleted or changed comment, a deleted knot, a changed id,
79 # type or created_by, a forged author or creator, a symlink, an
80 # executable, a file or directory outside the layout, a non-canonical
81 # knot, an oversized one, a shared-subtree bomb, a dangling edge, a
82 # cycle, a deletion of the ref, and refs that only begin with its name.
83 # A create with a parent is refused and one without is admitted, and a
84 # valid graph update carries no invalid change record, attestation or
85 # integration request through with it.
86 knots-e2e = pkgs.runCommand "valley-knots-e2e" {
87 nativeBuildInputs = [
88 pkgs.git
89 packages.valley-go
90 ];
91 cliScript = ../../bin/valley;
92 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
93 passAsFile = [ "initScript" ];
94 } (builtins.readFile ./knots-e2e.sh);
95
96 # valley-init itself, over repositories that already exist. The other
97 # hook checks wire a bare repo by hand; this one runs the rendered init
98 # script and holds it to converging on what the declaration says — the
99 # managed hook installed where a project had none, re-pointed where it
100 # had drifted to another store path, removed where the declaration no
101 # longer protects the project, and a hand-written hook of the same name
102 # left alone. The hook it converges on is then pushed to for real, so
103 # the check ends where protect-e2e begins. Relocating the data
104 # directory is the only edit to the script — the sandbox cannot write
105 # /srv.
106 init-e2e = pkgs.runCommand "valley-init-e2e" {
107 nativeBuildInputs = [ pkgs.git ];
108 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
109 integratorInitScript = hosts.integratorHost.config.systemd.services.valley-init.script;
110 passAsFile = [
111 "initScript"
112 "integratorInitScript"
113 ];
114 } (builtins.readFile ./init-e2e.sh);
115
116 # Phase 1's exit criteria, end to end and unmocked: a push to a
117 # bare repo wired with the real rendered hooks produces a
118 # ref-updated event on a real JetStream server within seconds,
119 # visible in `valley tail`; replaying the repo's refs is
120 # deterministic; and a dead bus never fails a push. The hook and
121 # stream-init scripts are followed from the rendered unit scripts,
122 # so the check exercises exactly what a host would run — only the
123 # server invocation differs (the sandbox cannot write /srv), same
124 # binary and flags, relocated storage.
125 bus-e2e = pkgs.runCommand "valley-bus-e2e" {
126 nativeBuildInputs = [
127 pkgs.git
128 pkgs.natscli
129 pkgs.nats-server
130 pkgs.jq
131 pkgs.cue
132 packages.valley-script
133 ];
134 initScript = hosts.busHost.config.systemd.services.valley-init.script;
135 busInitScript = hosts.busHost.config.systemd.services.valley-bus-init.script;
136 eventSchema = ../../schema/events.cue;
137 passAsFile = [
138 "initScript"
139 "busInitScript"
140 ];
141 } (builtins.readFile ./bus-e2e.sh);
142}