gunk-dev/the-valley

hooks.nix

source018dae8b6a64main's published tip history
2.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 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 one structural invariant, driven for real: bare repos wired
26 # with the rendered pre-receive hook, pushed to as each principal.
27 # What sshd would set from a key's authorized_keys entry, these
28 # pushes set in the environment directly — that rendering is pinned
29 # by module-eval, and everything the hook decides after it is what
30 # this check exercises.
31 protect-e2e = pkgs.runCommand "valley-protect-e2e" {
32 nativeBuildInputs = [ pkgs.git ];
33 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
34 passAsFile = [ "initScript" ];
35 } (builtins.readFile ./protect-e2e.sh);
36
37 # Phase 1's exit criteria, end to end and unmocked: a push to a
38 # bare repo wired with the real rendered hooks produces a
39 # ref-updated event on a real JetStream server within seconds,
40 # visible in `valley tail`; replaying the repo's refs is
41 # deterministic; and a dead bus never fails a push. The hook and
42 # stream-init scripts are followed from the rendered unit scripts,
43 # so the check exercises exactly what a host would run — only the
44 # server invocation differs (the sandbox cannot write /srv), same
45 # binary and flags, relocated storage.
46 bus-e2e = pkgs.runCommand "valley-bus-e2e" {
47 nativeBuildInputs = [
48 pkgs.git
49 pkgs.natscli
50 pkgs.nats-server
51 pkgs.jq
52 pkgs.cue
53 packages.valley-script
54 ];
55 initScript = hosts.busHost.config.systemd.services.valley-init.script;
56 busInitScript = hosts.busHost.config.systemd.services.valley-bus-init.script;
57 eventSchema = ../../schema/events.cue;
58 passAsFile = [
59 "initScript"
60 "busInitScript"
61 ];
62 } (builtins.readFile ./bus-e2e.sh);
63}