gunk-dev/the-valley

hooks.nix

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