gunk-dev/the-valley

web.nix

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