gunk-dev/the-valley

web.nix

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