gunk-dev/the-valley

hooks.nix

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