gunk-dev/the-valley

hooks.nix

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