gunk-dev/the-valley

hooks.nix

source9067b6d5ac52main's published tip history
5.2 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, and valley-ready's for the records the CLI writes.
41 valleyhook-unit = packages.valleyhook;
42
43 # The note envelope every reader of an attestation shares (note/).
44 note-unit = packages.note;
45
46 # The change record the hook guards and the CLI writes (change/): its
47 # strict reading, and the fuzz target's seed corpus.
48 change-unit = packages.change;
49
50 # The one structural invariant, driven for real: bare repos wired
51 # with the rendered pre-receive hook, pushed to as each principal.
52 # What sshd would set from a key's authorized_keys entry, these
53 # pushes set in the environment directly — that rendering is pinned
54 # by module-eval, and everything the hook decides after it is what
55 # this check exercises: protected refs, attestations and the names
56 # they may take, integration requests and the request grant, the
57 # changes of a change record's state, named grants, symbolic refs, a
58 # composed hook, and the namespaces every push is refused. Projects with and without protection are both served.
59 protect-e2e = pkgs.runCommand "valley-protect-e2e" {
60 nativeBuildInputs = [
61 pkgs.git
62 pkgs.openssh
63 # Real attestations, made the way a contributor makes them, for the
64 # namespace the hook checks the contents of.
65 packages.attest
66 ];
67 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
68 passAsFile = [ "initScript" ];
69 } (builtins.readFile ./protect-e2e.sh);
70
71 # valley-init itself, over repositories that already exist. The other
72 # hook checks wire a bare repo by hand; this one runs the rendered init
73 # script and holds it to converging on what the declaration says — the
74 # managed hook installed where a project had none, re-pointed where it
75 # had drifted to another store path, removed where the declaration no
76 # longer protects the project, and a hand-written hook of the same name
77 # left alone. The hook it converges on is then pushed to for real, so
78 # the check ends where protect-e2e begins. Relocating the data
79 # directory is the only edit to the script — the sandbox cannot write
80 # /srv.
81 init-e2e = pkgs.runCommand "valley-init-e2e" {
82 nativeBuildInputs = [ pkgs.git ];
83 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
84 integratorInitScript = hosts.integratorHost.config.systemd.services.valley-init.script;
85 passAsFile = [
86 "initScript"
87 "integratorInitScript"
88 ];
89 } (builtins.readFile ./init-e2e.sh);
90
91 # Phase 1's exit criteria, end to end and unmocked: a push to a
92 # bare repo wired with the real rendered hooks produces a
93 # ref-updated event on a real JetStream server within seconds,
94 # visible in `valley tail`; replaying the repo's refs is
95 # deterministic; and a dead bus never fails a push. The hook and
96 # stream-init scripts are followed from the rendered unit scripts,
97 # so the check exercises exactly what a host would run — only the
98 # server invocation differs (the sandbox cannot write /srv), same
99 # binary and flags, relocated storage.
100 bus-e2e = pkgs.runCommand "valley-bus-e2e" {
101 nativeBuildInputs = [
102 pkgs.git
103 pkgs.natscli
104 pkgs.nats-server
105 pkgs.jq
106 pkgs.cue
107 packages.valley-script
108 ];
109 initScript = hosts.busHost.config.systemd.services.valley-init.script;
110 busInitScript = hosts.busHost.config.systemd.services.valley-bus-init.script;
111 eventSchema = ../../schema/events.cue;
112 passAsFile = [
113 "initScript"
114 "busInitScript"
115 ];
116 } (builtins.readFile ./bus-e2e.sh);
117}