| 1 | // The event vocabulary of a valley host: what its bus carries. Phase 1 |
| 2 | // (design/roadmap.md) defined exactly one event; later phases add an event |
| 3 | // or a field at a time, never more. Phase 3 adds the integrator's two |
| 4 | // outcomes, #IntegrationSucceeded and #RequestStale. |
| 5 | // |
| 6 | // Events are a projection of git, never a second source of truth. Every |
| 7 | // field here is derivable from the repository alone, so replaying a repo's |
| 8 | // refs reproduces the same events — the phase's determinism criterion. |
| 9 | // Wall-clock time, hostnames, and other machine facts are deliberately |
| 10 | // absent: any of them would make replay produce different events. |
| 11 | // |
| 12 | // Like the host schema, this file is not Nix. The NixOS module's hook is |
| 13 | // one publisher; any other publisher or consumer reads the same file. |
| 14 | // |
| 15 | // Validate a payload: cue vet -d '#RefUpdated' schema/events.cue <payload>.json |
| 16 | package valley |
| 17 | |
| 18 | // #Integration is what every integrator outcome carries: which project, |
| 19 | // which change, and which stream the change was judged against. The |
| 20 | // integrator is a single writer per target stream, so these three name the |
| 21 | // commit point exactly. |
| 22 | // |
| 23 | // The change is named by the last segment of its integration-request ref, |
| 24 | // `refs/the-valley/integration-requests/<target>/<change>`, which is where |
| 25 | // the request is durable. The bus is a projection of that ref, never a |
| 26 | // second place a request lives. |
| 27 | #Integration: { |
| 28 | // The project name on the publishing host — the same name |
| 29 | // #Host.projects keys on, and the <repo> token of the subject. |
| 30 | repo: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$" |
| 31 | |
| 32 | // The change, as its request ref names it. |
| 33 | change: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$" |
| 34 | |
| 35 | // The protected ref the change targets. |
| 36 | target: =~"^refs/" |
| 37 | } |
| 38 | |
| 39 | // #IntegrationSucceeded is published when a change lands: the target ref |
| 40 | // moved from `old` to `new`, and every check the policy required carried |
| 41 | // evidence that stood. It is published once per landing, on the subject |
| 42 | // valley.git.<repo>.integration-succeeded. |
| 43 | // |
| 44 | // Both object ids are read from the ref write itself, so the event is a |
| 45 | // projection of what git already records: replaying the target's history |
| 46 | // reproduces the same pair. |
| 47 | #IntegrationSucceeded: { |
| 48 | #Integration |
| 49 | |
| 50 | // The event's type, and its subject's last token. |
| 51 | event: "integration-succeeded" |
| 52 | |
| 53 | // The target ref before and after the fast-forward. |
| 54 | old: #ObjectId |
| 55 | new: #ObjectId |
| 56 | |
| 57 | // The checks whose evidence transferred, in the order the integrator |
| 58 | // judged them. Every check the policy required is here, because a |
| 59 | // change with an invalidated check does not land. |
| 60 | transferred: [...#CheckName] |
| 61 | } |
| 62 | |
| 63 | // #RequestStale is published when a change cannot land against the current |
| 64 | // tip: either its delta no longer applies, or evidence for at least one |
| 65 | // required check no longer transfers (dcr-439b771). It is published once |
| 66 | // per judgement, on the subject valley.git.<repo>.request-stale, and the |
| 67 | // request ref stays where it is so the change can be resubmitted. |
| 68 | // |
| 69 | // Staleness is the unified failure mode: there is no rejection event here, |
| 70 | // because a change whose evidence has moved is not wrong, it is behind. |
| 71 | #RequestStale: { |
| 72 | #Integration |
| 73 | |
| 74 | // The event's type, and its subject's last token. |
| 75 | event: "request-stale" |
| 76 | |
| 77 | // The target tip the request was judged against. A reader comparing |
| 78 | // this with the target's current value can tell whether the judgement |
| 79 | // is still the current one. |
| 80 | tip: #ObjectId |
| 81 | |
| 82 | // Why the evidence did not stand. |
| 83 | // |
| 84 | // "conflict" — the delta does not apply cleanly to the tip. |
| 85 | // Resolving it produces a tree nobody has authored, and new |
| 86 | // authorship needs new evidence, so every required check is named. |
| 87 | // "evidence" — the delta applies, and the named checks are the ones |
| 88 | // whose evidence did not transfer. |
| 89 | reason: "conflict" | "evidence" |
| 90 | |
| 91 | // Exactly the checks that need new evidence. Retry is partial: a |
| 92 | // check not named here does not need re-running. |
| 93 | checks: [...#CheckName] |
| 94 | } |
| 95 | |
| 96 | // A check's name, the same shape #Name carries in |
| 97 | // schema/verification.cue — the policy names the checks, and an event |
| 98 | // naming one has to agree with it. |
| 99 | #CheckName: =~"^[a-z0-9][a-z0-9-]*$" |
| 100 | |
| 101 | // #RefUpdated is published once per ref a push updates, and once per |
| 102 | // landing for the target the integrator moved, on the subject |
| 103 | // valley.git.<repo>.ref-updated: the ref's name and its object id before |
| 104 | // and after. Creation and deletion carry the all-zero id on the |
| 105 | // corresponding side — git's own convention. A replay of a repo's current |
| 106 | // refs emits one event per existing ref with the all-zero id as `old`, |
| 107 | // because a ref's prior value is not derivable from the repository. |
| 108 | #RefUpdated: { |
| 109 | // The event's type, and its subject's last token. |
| 110 | event: "ref-updated" |
| 111 | |
| 112 | // The project name on the publishing host — the same name |
| 113 | // #Host.projects keys on, and the <repo> token of the subject. |
| 114 | repo: =~"^[a-zA-Z0-9][a-zA-Z0-9._-]*$" |
| 115 | |
| 116 | // The full ref name, e.g. "refs/heads/main". |
| 117 | ref: =~"^refs/" |
| 118 | |
| 119 | // Object ids: lowercase hex, 40 (sha1) or 64 (sha256) digits, |
| 120 | // all-zero for "no value on this side". |
| 121 | old: #ObjectId |
| 122 | new: #ObjectId |
| 123 | } |
| 124 | |
| 125 | #ObjectId: =~"^([0-9a-f]{40}|[0-9a-f]{64})$" |