@zabaca/zbc 0.18.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/apps/walgit/CONTEXT.md +5 -1
- package/templates/apps/walgit/shared/container-env.ts +81 -0
- package/templates/apps/walgit/shared/landing.ts +575 -168
- package/templates/apps/walgit/shared/llms.ts +25 -3
- package/templates/apps/walgit/src/proposals.ts +47 -11
- package/templates/apps/walgit/src/signers.ts +44 -3
- package/templates/apps/walgit/worker/index.ts +43 -37
- package/templates/infra/modules/cloudflare/index.ts +106 -6
package/package.json
CHANGED
|
@@ -171,13 +171,17 @@ _Avoid_: login, token (there is none; the signature is the credential), auth
|
|
|
171
171
|
## Proposals (ADR-0018)
|
|
172
172
|
|
|
173
173
|
**Proposal**:
|
|
174
|
-
A ref under `refs/walgit/proposals/` that names a commit its pusher wants in a target ref. It is a ref and a Push Certificate and nothing else: the host keeps no record of it beyond the Index, requests nothing of anyone, and derives its state from git ancestry rather than storing one. The ref reads `refs/walgit/proposals/<target>/<id>`, where the **last segment is the id** and everything before it is the target
|
|
174
|
+
A ref under `refs/walgit/proposals/` that names a commit its pusher wants in a target ref. It is a ref and a Push Certificate and nothing else: the host keeps no record of it beyond the Index, requests nothing of anyone, and derives its state from git ancestry rather than storing one. The ref reads `refs/walgit/proposals/<target>/<id>`, where the **last segment is the id** and everything before it is the target — so a target may itself contain slashes (`feat/login`) and nothing has to be fetched to know what a Proposal is for. The target is a branch, or the one non-branch target `walgit/signers` (see **Signer List Proposal**). `pre-receive` refuses one whose target does not exist, whose target is neither a branch nor that one (any segment beginning `refs/`), or whose tip is not a commit: append-only means a ref written here is written for good, so junk is refused before it is stored or never. Deployment-wide and off by default (`WALGIT_PROPOSALS`); with the flag off the namespace is an ordinary one under the ordinary gate.
|
|
175
175
|
_Avoid_: pull request (GitHub's, and already means a GitHub PR elsewhere in the repository), merge request, change request (an approval-board ticket), PR
|
|
176
176
|
|
|
177
177
|
**Merged**:
|
|
178
178
|
A Proposal whose tip is an ancestor of its target ref's tip. Computed on read, never recorded, so it is only ever true because someone with the right to write the target pushed a fast-forward or a true merge of the Proposal's tip. A squash or a rebase of it does not merge the Proposal, and a Proposal is never Merged by anything but ancestry.
|
|
179
179
|
_Avoid_: closed, accepted (nothing records an acceptance), landed
|
|
180
180
|
|
|
181
|
+
**Signer List Proposal**:
|
|
182
|
+
A Proposal whose target is `walgit/signers` — `refs/walgit/proposals/walgit/signers/<id>` — carrying the Signer List's `signers` file with a line added. It is how a stranger **asks to be listed**, which is the one thing the refusal could otherwise only tell it to get somebody else to do. It moves nothing: `refs/walgit/signers` is still written only by a key the list already names, so the list changes when a Signer accepts and not before. The target's spelling is the ref with `refs/` dropped, and it is exact — `walgit/signers/deeper` is an ordinary branch name. `agentgit accept` lands one without a checkout (`merge-tree` + `commit-tree`, then a signed push of the list), because nobody has the list checked out and an agent's own work must not move to accept one.
|
|
183
|
+
_Avoid_: join request, membership request, invite
|
|
184
|
+
|
|
181
185
|
**Whoever may read may propose**:
|
|
182
186
|
The one rule for who can push a Proposal: on a world-readable name, anyone whose push is signed; on a Private name, its Signers and Readers. There is no third list. An Unclaimed name refuses nothing anyway, so a Proposal there is allowed and pointless.
|
|
183
187
|
|
|
@@ -24,6 +24,24 @@
|
|
|
24
24
|
* and an unset one simply means unenforced.
|
|
25
25
|
*/
|
|
26
26
|
export const CONTAINER_ENV = [
|
|
27
|
+
// Which deploy this is, and the one variable here that configures nothing.
|
|
28
|
+
//
|
|
29
|
+
// Everything else on this list changes what the container DOES; this changes
|
|
30
|
+
// only the fingerprint, which is the point. A deploy that ships a new image
|
|
31
|
+
// and no new configuration moves no value above, so the Durable Object sees
|
|
32
|
+
// an unchanged environment and leaves the old container serving — observed
|
|
33
|
+
// on the 0.16.1 production deploy, where `--containers-rollout immediate`
|
|
34
|
+
// reported a completed rollout and the instance answering git was the one
|
|
35
|
+
// started an hour before. The image is not something this side can inspect,
|
|
36
|
+
// so the deploy names itself instead: the cloudflare module's `deployIdVar`
|
|
37
|
+
// passes the deployed commit as a var, and this line is what carries it the
|
|
38
|
+
// last hop into the container.
|
|
39
|
+
//
|
|
40
|
+
// Nothing reads it. It is visible in the container's own environment and on
|
|
41
|
+
// the Worker's variables in the dashboard, which is the second thing it buys
|
|
42
|
+
// — Cloudflare numbers container versions itself (v50, v51) and nothing else
|
|
43
|
+
// in the deploy says which commit that is.
|
|
44
|
+
'WALGIT_BUILD_ID',
|
|
27
45
|
'WALGIT_HTTP_TOKENS',
|
|
28
46
|
'WALGIT_S3_ENDPOINT',
|
|
29
47
|
'WALGIT_S3_BUCKET',
|
|
@@ -129,3 +147,66 @@ export function fingerprintEnv(env: Record<string, string>): string {
|
|
|
129
147
|
}
|
|
130
148
|
return (hash >>> 0).toString(16).padStart(8, '0')
|
|
131
149
|
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The half of a Durable Object that `reconcileContainerEnv` needs: whether a
|
|
153
|
+
* container is running, how to kill it, and where the fingerprint it booted
|
|
154
|
+
* with is kept.
|
|
155
|
+
*
|
|
156
|
+
* A port rather than the `Container` class itself because this module imports
|
|
157
|
+
* no runtime (ADR-0010) — and because the rule below is about ORDER, which is
|
|
158
|
+
* only observable from outside the object performing it.
|
|
159
|
+
*/
|
|
160
|
+
export interface ContainerReconcileTarget {
|
|
161
|
+
/** Is a container process currently running for this Durable Object? */
|
|
162
|
+
readonly running: boolean
|
|
163
|
+
/** The fingerprint recorded by the last reconcile, if there has been one. */
|
|
164
|
+
read(): Promise<string | undefined>
|
|
165
|
+
/** Kill the running container. The next request starts a fresh one. */
|
|
166
|
+
destroy(): Promise<void>
|
|
167
|
+
/** Record the fingerprint the container is now running. */
|
|
168
|
+
write(fingerprint: string): Promise<void>
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** What a reconcile did, for the caller to log. */
|
|
172
|
+
export type ContainerReconcileOutcome = 'unchanged' | 'recorded' | 'replaced'
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Replace the container if it is running an environment this deploy changed.
|
|
176
|
+
*
|
|
177
|
+
* The caller re-reads its own environment on every Durable Object
|
|
178
|
+
* construction, and a `wrangler deploy` constructs a new one — so that side is
|
|
179
|
+
* never stale. The container is: it read `process.env` once at start and cannot
|
|
180
|
+
* be told anything afterwards. Without this, a new value takes effect whenever
|
|
181
|
+
* the container next happens to idle out, which under sustained traffic is
|
|
182
|
+
* never.
|
|
183
|
+
*
|
|
184
|
+
* The fingerprint is persisted rather than held in memory because that is the
|
|
185
|
+
* only state that survives the very event being detected — a redeploy discards
|
|
186
|
+
* every in-memory field, so an in-memory copy would compare the new environment
|
|
187
|
+
* against itself and always agree.
|
|
188
|
+
*
|
|
189
|
+
* Two rules the tests pin, both learned the hard way:
|
|
190
|
+
*
|
|
191
|
+
* - NO RECORD counts as a mismatch, not as a fresh start. A running container
|
|
192
|
+
* with no record predates this code, so what it booted with is unknowable,
|
|
193
|
+
* and on the deploy that ships this it is exactly the container already
|
|
194
|
+
* serving a superseded environment. A Durable Object that has never started
|
|
195
|
+
* one arrives here with `running` false and simply records.
|
|
196
|
+
* - The write happens LAST, and only after a successful destroy. Recording
|
|
197
|
+
* first would make a failed replacement look reconciled forever.
|
|
198
|
+
*/
|
|
199
|
+
export async function reconcileContainerEnv(
|
|
200
|
+
target: ContainerReconcileTarget,
|
|
201
|
+
current: string,
|
|
202
|
+
): Promise<ContainerReconcileOutcome> {
|
|
203
|
+
const booted = await target.read()
|
|
204
|
+
if (booted === current) return 'unchanged'
|
|
205
|
+
|
|
206
|
+
// Only a RUNNING container can be stale. A stopped one has nothing to
|
|
207
|
+
// replace: its next start reads the environment as it now is.
|
|
208
|
+
const replaced = target.running
|
|
209
|
+
if (replaced) await target.destroy()
|
|
210
|
+
await target.write(current)
|
|
211
|
+
return replaced ? 'replaced' : 'recorded'
|
|
212
|
+
}
|