gunk-dev/the-valley

verification.cue

source342d77d65a25main's published tip history
7.1 KiB
1// The verification policy of a valley project: which checks a change must
2// carry, derived from the paths its diff touches. Policy is data, so it is
3// a CUE document like the host config and the event vocabulary
4// (ida-1ec03b1).
5//
6// This file is a draft. The decision it gives concrete form to
7// (dcr-f41f718) is `proposed`, not decided: nothing reads this file, no
8// enforcement point exists until Phase 3's integrator (design/roadmap.md),
9// and the flake's cue-vet check deliberately does not cover it yet.
10//
11// The policy lives in the project's own repository — the recommended fork
12// of dcr-f41f718 — because a fresh clone must be able to say what its own
13// changes must pass without asking a host, and because a project served by
14// two hosts must mean the same thing on both. The host's half of that
15// split is one field, sketched at the bottom of this file as
16// #ProjectVerification and deliberately not applied to schema/valley.cue.
17//
18// Like the host and event schemas, this file is deliberately not Nix. A
19// policy names checks; it never names derivations, systems, or store
20// paths, so it travels between machines unchanged.
21//
22// Validate a policy:
23// cue vet -c schema/verification.cue examples/verification-policy.cue
24package verification
25
26// #Policy is a complete verification policy: the checks a project can
27// require, the path classes that require them, and what a path the policy
28// does not cover costs.
29#Policy: {
30 // checks maps a check's name to how that check is run. Classes
31 // require checks by name; a name that is not a key here fails vet
32 // (see the cross-check below), because a required check nobody can
33 // run is the one failure this document must never have.
34 checks: [#Name]: #Check
35
36 // The path classes. Matching is a set operation, never first-match:
37 // a change's required checks are the union of `requires` over every
38 // class that at least one changed path matches. Classes may overlap
39 // on purpose — a knowledge node is both knowledge and prose — and
40 // overlapping classes compose to the maximum of what they ask for.
41 // That union is the whole of the "mixed commits take the max" rule
42 // (ida-1ec03b1): there is no separate mixed case to get wrong.
43 classes: [...#Class]
44
45 // The checks required when a changed path matches no class at all.
46 // A path outside every class means the policy is behind the tree, so
47 // the safe answer is the strictest set the project has rather than
48 // the empty one. An empty list is allowed, and is a deliberate
49 // statement that uncovered paths are unconstrained.
50 unclassified: [...#Name]
51}
52
53// #Class is one path class and what touching it requires.
54#Class: {
55 // The class's name. It exists to be quoted back — the integrator
56 // says which class made a check required — and nothing references
57 // it, so it need not be unique.
58 name: #Name
59
60 // The paths this class covers. Patterns are matched against each
61 // changed path of the diff, relative to the repository root: `*`
62 // matches within one path segment, `**` matches any number of
63 // segments including none. Every side of the diff counts — an added,
64 // modified, or deleted path, and both the old and the new path of a
65 // rename — because a check's scope is what the tree looked like as
66 // much as what it looks like now.
67 paths: [...#Pattern]
68
69 // The checks a change touching this class must carry. Every name
70 // must be a key of the policy's `checks`.
71 requires: [...#Name]
72}
73
74// #Check is how one named check is run. In the reference implementation a
75// check is a flake check: `nix build .#checks.<system>.<attribute>`, where
76// the system is the runner's own and never the policy's — a policy that
77// named a system would stop travelling.
78#Check: {
79 // The runner kind. "nix" is the only runner today; another kind
80 // would widen this to a disjunction, deliberately not before an
81 // implementation exists.
82 runner: "nix"
83
84 // The flake check attribute this check names.
85 attribute: #Name
86}
87
88// Names are lowercase, dash-separated, and short. They are quoted in
89// integrator output and carried in attestation payloads, so they are held
90// to the same shape as project names in schema/valley.cue.
91#Name: =~"^[a-z0-9][a-z0-9-]*$"
92
93// A path glob, relative to the repository root. A leading slash and a `..`
94// segment are both rejected: a pattern that reaches outside the tree is
95// describing something a diff cannot contain, and silently matching
96// nothing is the expensive way to find that out.
97#Pattern: =~"^[^/]" & !~"(^|/)\\.\\.(/|$)"
98
99// The top level of this package is itself a policy: a policy file
100// evaluated together with this schema is validated against #Policy —
101// unknown fields, malformed names, and unsafe patterns are rejected.
102checks: #Policy.checks
103classes: #Policy.classes
104unclassified: #Policy.unclassified
105
106// Every check a class requires, and every check `unclassified` names, must
107// exist in the catalogue. A name that does not lands in `checks` as an
108// incomplete #Check, so `cue vet -c` fails with an error naming the
109// missing check. Without this, a typo is not a vet error — it is a check
110// that silently stops being required.
111for c in classes for n in c.requires {
112 checks: (n): _
113}
114for n in unclassified {
115 checks: (n): _
116}
117
118// A file's top level cannot be closed (embedding #Policy would open it
119// instead — embedding lifts closedness), so reject stray top-level fields
120// explicitly: anything but the #Policy fields — a `class:` typo, a
121// host-side concern like `enable:` — conflicts with this sentinel and
122// fails vet with an error naming the field.
123[!="checks" & !="classes" & !="unclassified"]: "INVALID: unknown top-level field; only \"checks\", \"classes\" and \"unclassified\" are allowed"
124
125// ----------------------------------------------------------------------
126// Sketched, deliberately not applied.
127//
128// The host's half of the split dcr-f41f718 recommends. It belongs on
129// #Project in schema/valley.cue, as `verification?: #ProjectVerification`,
130// and it is not added there because no enforcement point reads it yet;
131// adding a field the host cannot act on would misrepresent the boundary.
132// It is written out here so the proposal can be read rather than imagined.
133//
134// The host declares *that* a project is verified, never *what* it must
135// pass. A host that restated the checks would be back to owning policy the
136// project should own — but a host that declares nothing cannot refuse to
137// serve a project whose in-repo policy has gone empty, which is exactly
138// the gate cosmo loses by migrating.
139#ProjectVerification: {
140 // Whether the host requires this project's changes to be verified.
141 // The block is optional on #Project, so a declaration written before
142 // this field existed evaluates exactly as it did before; a
143 // declaration that names the block and disables it is saying so on
144 // purpose, in the host's history.
145 enable: bool | *true
146
147 // Where the required-check policy is read from. "in-repo" — the
148 // project's own policy document, this schema — is the only source
149 // today; a host-declared policy would widen this to a disjunction,
150 // deliberately not before there is a reason to want one.
151 source: "in-repo"
152}