gunk-dev/the-valley

hooks.nix

sourcea4cb909466damain's published tip history
4.8 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 refspec is easy to get subtly
15 # wrong — --prune ignores the non-glob heads refspec, so pruning
16 # heads is the sweep's job — and only running git can tell.
17 # Relative mirror URLs (mirrorHost) resolve against the pushing
18 # repo, so the shipped scripts run with no substitution: this is
19 # exactly what a host executes.
20 #
21 # It also stalls a push in the window where git has read the local
22 # refs and not yet the mirror's. Two pushers at once rewind the
23 # mirror there; the drain, the only publisher, leaves the newer
24 # move queued and publishes it next.
25 mirror-e2e = pkgs.runCommand "valley-mirror-e2e" {
26 nativeBuildInputs = [ pkgs.git ];
27 initScript = hosts.mirrorHost.config.systemd.services.valley-init.script;
28 publishUnit = hosts.mirrorHost.config.systemd.units."valley-publish@.service".text;
29 passAsFile = [
30 "initScript"
31 "publishUnit"
32 ];
33 } (builtins.readFile ./mirror-e2e.sh);
34
35 # The pre-receive hook's policy, rule by rule where a rule is
36 # subtle: the glob matching of a declared pattern, and the order in
37 # which the rules are tried. What the hook does to a real push is
38 # protect-e2e's.
39 valleyhook-unit = packages.valleyhook;
40
41 # The note envelope every reader of an attestation shares (note/).
42 note-unit = packages.note;
43
44 # The one structural invariant, driven for real: bare repos wired
45 # with the rendered pre-receive hook, pushed to as each principal.
46 # What sshd would set from a key's authorized_keys entry, these
47 # pushes set in the environment directly — that rendering is pinned
48 # by module-eval, and everything the hook decides after it is what
49 # this check exercises: protected refs, attestations and the names
50 # they may take, integration requests and the request grant, named
51 # grants, symbolic refs, a composed hook, and the namespaces every push
52 # is refused. Projects with and without protection are both served.
53 protect-e2e = pkgs.runCommand "valley-protect-e2e" {
54 nativeBuildInputs = [
55 pkgs.git
56 pkgs.openssh
57 # Real attestations, made the way a contributor makes them, for the
58 # namespace the hook checks the contents of.
59 packages.attest
60 ];
61 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
62 passAsFile = [ "initScript" ];
63 } (builtins.readFile ./protect-e2e.sh);
64
65 # valley-init itself, over repositories that already exist. The other
66 # hook checks wire a bare repo by hand; this one runs the rendered init
67 # script and holds it to converging on what the declaration says — the
68 # managed hook installed where a project had none, re-pointed where it
69 # had drifted to another store path, removed where the declaration no
70 # longer protects the project, and a hand-written hook of the same name
71 # left alone. The hook it converges on is then pushed to for real, so
72 # the check ends where protect-e2e begins. Relocating the data
73 # directory is the only edit to the script — the sandbox cannot write
74 # /srv.
75 init-e2e = pkgs.runCommand "valley-init-e2e" {
76 nativeBuildInputs = [ pkgs.git ];
77 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
78 integratorInitScript = hosts.integratorHost.config.systemd.services.valley-init.script;
79 passAsFile = [
80 "initScript"
81 "integratorInitScript"
82 ];
83 } (builtins.readFile ./init-e2e.sh);
84
85 # Phase 1's exit criteria, end to end and unmocked: a push to a
86 # bare repo wired with the real rendered hooks produces a
87 # ref-updated event on a real JetStream server within seconds,
88 # visible in `valley tail`; replaying the repo's refs is
89 # deterministic; and a dead bus never fails a push. The hook and
90 # stream-init scripts are followed from the rendered unit scripts,
91 # so the check exercises exactly what a host would run — only the
92 # server invocation differs (the sandbox cannot write /srv), same
93 # binary and flags, relocated storage.
94 bus-e2e = pkgs.runCommand "valley-bus-e2e" {
95 nativeBuildInputs = [
96 pkgs.git
97 pkgs.natscli
98 pkgs.nats-server
99 pkgs.jq
100 pkgs.cue
101 packages.valley-script
102 ];
103 initScript = hosts.busHost.config.systemd.services.valley-init.script;
104 busInitScript = hosts.busHost.config.systemd.services.valley-bus-init.script;
105 eventSchema = ../../schema/events.cue;
106 passAsFile = [
107 "initScript"
108 "busInitScript"
109 ];
110 } (builtins.readFile ./bus-e2e.sh);
111}