gunk-dev/the-valley

hooks.nix

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