gunk-dev/the-valley

web.nix

source3af64cbb9cebmain's published tip history
10.7 KiB
1# The web UI (web/): the shared export contract, the publisher, the
2# receiver, and the web server. Each check but web-image runs the unit
3# test derivation defined in nix/packages.nix. web-image is a
4# runCommand that unpacks the container image.
5{
6 pkgs,
7 packages,
8 ...
9}:
10{
11 # The projection over the shared fixture, which holds every disclosure
12 # rule: what reaches export.json, hidden projects' edges, a knot that
13 # waits on a hidden knot marked with waiting_on_hidden alone, the field
14 # gone once its one hidden blocker is done, the display mapping, each
15 # public project's group and short aliases with only public projects'
16 # groups, and group names and aliases that collide refused. The
17 # content digest; strict reading of export.json, with
18 # nothing after its document; each of VerifyManifest's steps, in order;
19 # the manifest's grammar and its agreement with export.json; the
20 # streaming body check; bundle acceptance against real git, refusing
21 # wrong tips, prerequisites, extra refs, corrupt objects and a header
22 # past its bound, writing a commit-graph git verifies, and serving no
23 # commit main does not reach, nor one named in the other object
24 # format's length, alone or among several; git's
25 # output read within its limit, with git stopped past it or when its
26 # reader stops early; and the receiver's state directory. For the state
27 # directory: staging/ stays private to the receiver and exports/ stays
28 # group- and world-readable under any umask; readers hold
29 # a generation through activations, every file of a generation is synced
30 # before high-water names it, a repository interrupted by a crash is
31 # rebuilt, recovery verifies a generation before activating it and keeps
32 # one whose git check was interrupted, and injected sweep and swap
33 # failures are reported separately from the commit; Stage and Activate
34 # wait for a held store lock only until their context expires, leaving
35 # staging and the active generation unchanged on cancellation; a
36 # manifest's capacity sweep stops once its context is done, leaving the
37 # rest of the trash and releasing the lock; and an activation that
38 # exceeds MaxStorage is refused, with the repository whose build passed
39 # the cap removed, while repositories built before it remain. An
40 # end-to-end pass uploads to a real valley-web-receive with
41 # its bearer token, a real valley-web serves the activated export, a pass
42 # with a wrong token fails as unauthenticated while the edge keeps serving,
43 # and a pass after withdrawing anyone's grant removes the project from the
44 # edge. go vet runs after the tests.
45 web-unit = packages.web.unit;
46
47 # Read access, which the publisher reads its consents through: both
48 # consents read out of real commits under the real schemas, an explicit
49 # empty reader set and an empty scope letting no one read, anyone's
50 # restrictions, no principal name special, a policy for another project
51 # and a grant for another identity covering nothing, other destinations'
52 # grants and expired principals' left out, policy/web never read, tree
53 # entries with a directory part or named twice refused before anything
54 # is copied out, a directory named twice on the way to a document
55 # refused, redeclared definitions widening nothing, a field spelled in
56 # another case than the schema's refused, and the coverage report over a
57 # real valley, with the registry read at its ref. go vet runs after them.
58 readaccess-unit = packages.readaccess.unit;
59
60 # The server and valley-web over the shared fixture, uploaded to a real
61 # store, and real git. The plan page's reading order, its free to start
62 # legend, its one card of ready changes, and the export's age, marked
63 # stale after five minutes; a knot's body and comments, with the edited
64 # one marked; a hidden project answering every route under its group,
65 # under no group and under its short alias exactly as a missing one,
66 # though its repository is in the generation; a blocked knot's chip
67 # naming its published blockers and, once, unpublished work; groups and
68 # projects named source, knots and web-export served on every route
69 # under /<group>/<project>, and their roots redirected to their trees,
70 # while the server's own paths under /-/ are never a group's; a group's
71 # alias and a project's short alias answering with a permanent redirect
72 # that keeps the path and query as sent; every 404 the one page made at
73 # start, the box of text with no site name; a commit
74 # main's tip does not reach, and every other object ID or name, refused
75 # with the one 404; hostile README, file, file name, commit subject and
76 # knot text rendered inert, and large and binary files not shown; a
77 # reference into the hidden project naming nothing of it; a directory
78 # past MaxRead listed in part, and a 5 MiB commit message ending its
79 # page of history early; the directories along a path sharing one
80 # MaxRead; the older links of history showing every commit once through
81 # a merge whose lines run across pages, and every link of a page past
82 # MaxFrontier lines, or one ended before a merge past MaxLeftToShow,
83 # reaching every commit; a merge whose parents pass a record of git log
84 # shown, first on a page and further down, with its first MaxParents
85 # followed; a source request's git slot held for a bound of its own from
86 # admission, through a slow export read and its git, answering 503 and
87 # giving back its slot, and given back before it renders; a SHA-256
88 # project served by full commit IDs alone; a file of MaxFile newlines shown to MaxLines;
89 # a chain of knots near the graph's limit shown to MaxPlanDepth, with
90 # the plan's structure built once; the policy on every response,
91 # admitting the page's inline stylesheet and script by their hashes; a
92 # request keeping its generation while another activates; an export
93 # read once per generation, however many requests wait for it, across
94 # activations; a load started only by a request taking a loader slot,
95 # with requests that wait for one ending at their deadline or when
96 # their reader goes away, leaving no load behind and holding no
97 # generation; a load reading export.json from a slow pipe stopped part
98 # way once its one request's deadline passes, caching nothing and
99 # giving back its generation; a flood during a load keeping
100 # MaxLoadWaiting requests waiting and answering the rest 503, with the
101 # server's goroutines and open files bounded; source requests past
102 # MaxGit and MaxWaiting answering 503, with an activation while they
103 # wait and a deadline that covers the wait; a request held past its
104 # deadline before it renders answering 503; a page past MaxResponse on
105 # a knot, and past a smaller bound on a file, a directory, a page of
106 # history and the plan, answering the one short page that says it is
107 # too large; readers that never read holding no git slot and no
108 # generation, and, asking for more than MaxBuffered in large pages of
109 # three sizes, holding no more of the heap than it and no more than
110 # MaxLarge, their pages' starts counted, with a large page it has no
111 # room for answering 503 while the plan, a knot and a directory still
112 # render; and valley-web run as a process of its own, serving and
113 # stopping on SIGTERM, and serving every page from a read-only state
114 # directory that the receiver wrote under umask 0077, with the test
115 # simulating another owner, since it cannot change users. go vet runs
116 # after the tests.
117 web-server-unit = packages.valley-web.unit;
118
119 # The receiver binary, valley-web-receive, run as a subprocess over the
120 # shared fixture's signed export and real git. A three-step upload
121 # activates an export that a separate valley-web process serves from the
122 # same state directory, and re-posting the manifest or commit is refused
123 # as replayed. Manifests with no token, a wrong token, a non-Bearer
124 # scheme, or two Authorization headers, and a body, a commit and an
125 # unused path with no token, are refused as unauthenticated without
126 # staging anything. Stale, future-dated, foreign-key, and
127 # foreign-destination manifests are refused; a manifest older than the
128 # staged one is refused as superseded while newer manifests replace staged
129 # bodies; and committing an unstaged sequence fails as no-manifest. Bodies
130 # with a hash mismatch, a size mismatch (with or without Content-Length),
131 # a Content-Encoding header, or an undeclared hash are refused; a
132 # concurrent upload of the same body receives 503; and an interrupted body
133 # upload leaves no partial file in staging, fails commit as incomplete
134 # while keeping the active export intact, and activates once re-sent in
135 # full. Manifests and bodies past --max-body or --max-upload fail as
136 # too-large before staging, while uploads at both caps succeed; a manifest
137 # reusing one bundle across eight projects fails when it exceeds
138 # --max-storage, and uploads within the cap succeed. When stalled
139 # manifests fill all 4 request slots, the next authenticated request gets
140 # 503 and an unauthenticated request still gets 401 while valley-web keeps
141 # serving, and uploads resume once the stalled clients disconnect. When 32
142 # connections stall in headers, valley-web keeps serving and a subsequent
143 # upload succeeds once the header timeout closes them. OPTIONS * with a
144 # withheld body on all 32 connections returns immediately so a following
145 # upload succeeds. A manifest request canceled while waiting for the store
146 # lock stages nothing. A commit whose client disconnects, and a SIGTERM
147 # during a commit, kill the process group of the commit's git: a shell
148 # that stalls in commit-graph and its forked child holding git's output
149 # open both die, the bundle stays staged, and the receiver exits only once
150 # the commit has ended. On SIGTERM the receiver drains and exits within its
151 # timeout even with all connections held, and CLI usage, token-file, and
152 # verifier-file errors exit without printing the token. Every test request,
153 # dial, and wait for a subprocess is bounded. go vet runs after the tests.
154 web-receiver-unit = packages.valley-web-receive.unit;
155
156 # The edge container image, unpacked layer by layer: /bin/valley-web and
157 # /bin/valley-web-receive resolve to store paths inside the image, and
158 # the image holds the git each program runs at its pinned store path; /etc/passwd and /etc/group define
159 # valley-web-receive, valley-web, and their shared valley-web group;
160 # /var/lib/valley-web is the sole declared volume and is owned by
161 # valley-web-receive:valley-web with mode 0750; and the image defaults to
162 # user valley-web with no default entrypoint or command.
163 web-image = pkgs.runCommand "valley-web-image" {
164 nativeBuildInputs = [ pkgs.jq ];
165 image = packages.valley-web-image;
166 } (builtins.readFile ./web-image.sh);
167}