deploy: every run leaves each zone of the mind with HTTP/3 on and 0-RTT off (#25)
jonas, 2026-11-27 14:24 UTC · 3c8c37756896c7ab7d3b5a3959df06868c7e906e · parent 671f2cf
5 files changed
- M core/lib/src/cli/README.md
- M core/lib/src/cli/cloudflare-access.ts
- M core/lib/src/cli/deploy.ts
- A core/lib/src/cli/zone-protocols.test.ts
- A core/lib/src/cli/zone-protocols.ts
M core/lib/src/cli/README.md
@@ -143,6 +143,11 @@ another Worker, or with an A, AAAA, CNAME or MX record, is in use: the command says what is there and asks before it goes on. With your yes (or `--erase-records`) it erases every DNS record and Workers route of that domain, right before the deploy and after every other check. + Every run, a new mind's and a later one's, leaves each domain of the mind with HTTP/3 on and + 0-RTT Connection Resumption off: it reads both settings and writes one that differs, before + the deploy and before it erases anything ([zone-protocols.ts](zone-protocols.ts) says why). + The settings are the whole domain's. `--plan` says what a deploy would turn, and writes + nothing. 4. **Telemetry: no token.** The deploy makes no telemetry tables (`events`, `logs`, `spans`), and no bucket or Pipelines stream for them. The mind reads Cloudflare's own datasets and `metrics` through `itx.telemetry.query`, with no token (`onboarding/telemetry.md` of `/repos/onboarding`). A mind @@ -182,6 +187,7 @@ plan there. Cloudflare may ask for a payment method and charges nothing for the Free plan. With nobody at the terminal it stops with that page's address. Whether Cloudflare allows the set-up through the API on an account that never had Zero Trust is not yet seen. + 6. **The config**, which is the script's one input, written to `${XDG_CACHE_HOME:-~/.cache}/iterate/deploys/<stage>/config.json` and printed (with any sensitive keys redacted) to stdout after the deploy: @@ -239,6 +245,7 @@ `/repos/onboarding`: the onboarding page, its agent's guides and the cards of the Tasks board. A new mind commits that folder as the repo's first commit at its birth, after its config. A mind that has the repo already keeps it as it is. + 8. **The deploy**: `pnpm run deploy --stage <stage> --yes` of core/alchemy. Its output goes to `deploy.log` beside the config. A new state store can refuse the run that made it ("State store request failed"): the command then deploys once more by itself. So it does, a minute
M core/lib/src/cli/cloudflare-access.ts
@@ -93,8 +93,9 @@ /** WHAT `iterate deploy` ASKS A SIGN-IN FOR: the stack's scopes, and those of the command's own * steps. Nothing here adds a zone: a domain from another registrar is added on Cloudflare's own * page. The command's other calls need no scope beyond the stack's: the zone's routes and - * records (read, and erased after a yes), the account's workers.dev name, whether Workers Paid - * and R2 are on, and a deployed mind's config, which is in its boundary Worker's settings. */ + * records (read, and erased after a yes), each zone's HTTP/3 and 0-RTT settings + * (zone-protocols.ts, by `zone-settings.write`), the account's workers.dev name, whether Workers + * Paid and R2 are on, and a deployed mind's config, which is in its boundary Worker's settings. */ export const DEPLOY_SCOPES = [ // the person: their address is the owner's, and their name makes the domain names offered "user-details.read",
M core/lib/src/cli/deploy.ts
@@ -92,6 +92,7 @@ } from "./mcp-clients.ts"; import { refreshOAuthSession } from "./oauth.ts"; import { openPageCommand } from "./open-page.ts"; +import { protocolChangeLine, setZoneProtocols, zoneProtocolChanges } from "./zone-protocols.ts"; const exec = promisify(execFile); const CACHE = join(process.env.XDG_CACHE_HOME || join(homedir(), ".cache"), "iterate"); @@ -3337,7 +3338,11 @@ const deployedConfig = { ...config, mindId }; writeFileSync(configFile, `${JSON.stringify(deployedConfig, null, 2)}\n`); access = await renewed(); + // HTTP/3 on and 0-RTT off on each zone of the mind (./zone-protocols.ts): read at every run, + // and written before the deploy, and before anything of the domain is erased + const protocolChanges = await zoneProtocolChanges(cf, account.id, config.cloudflare.zones); if (input.plan) { + for (const change of protocolChanges) p.log.info(protocolChangeLine(change, false)); const plan = join(work, "plan.log"); writeFileSync(plan, ""); const planning = wait(`Planning the deploy of the mind at ${c.domain(controlPlaneHostname)}`); @@ -3362,6 +3367,9 @@ p.outro(`Nothing was changed. Done in ${seconds(began)}.`); return; } + // before the erase: a write that Cloudflare refuses stops the run with the domain as it was + await setZoneProtocols(cf, protocolChanges); + for (const change of protocolChanges) p.log.success(protocolChangeLine(change, true)); if (holdings) { const erased = await eraseHoldings(cf, zone.id); p.log.success(
A core/lib/src/cli/zone-protocols.test.ts
@@ -0,0 +1,85 @@ +import { expect, test } from "vitest"; +import type { Answer, Cloudflare } from "./cloudflare-access.ts"; +import { protocolChangeLine, setZoneProtocols, zoneProtocolChanges } from "./zone-protocols.ts"; + +const answer = (status: number, result: unknown, error = ""): Answer => ({ + status, + result, + total: 0, + error, +}); + +/** A Cloudflare with two zones of account `a`, whose settings are `settings`, and every call. */ +function fake(settings: Record<string, Record<string, string>>) { + const calls: string[] = []; + const cf: Cloudflare = async (method, path, body) => { + calls.push(`${method} ${path}${body === undefined ? "" : ` ${JSON.stringify(body)}`}`); + const listed = /^\/zones\?name=([^&]+)&account\.id=a$/.exec(path); + if (listed) return answer(200, settings[listed[1]!] ? [{ id: `id-${listed[1]}` }] : []); + const [, zone, setting] = /^\/zones\/id-([^/]+)\/settings\/(\w+)$/.exec(path) || []; + const zoneSettings = zone ? settings[zone] : undefined; + if (!zoneSettings || !setting || !(setting in zoneSettings)) + return answer(403, null, "Unauthorized to access requested resource"); + if (method === "PATCH") zoneSettings[setting] = (body as { value: string }).value; + return answer(200, { id: setting, value: zoneSettings[setting], editable: true }); + }; + return { cf, calls }; +} + +test("a deploy leaves each zone with HTTP/3 on and 0-RTT off, and writes only what differs", async () => { + const settings = { + "one.example": { http3: "off", "0rtt": "on" }, + "two.example": { http3: "on", "0rtt": "off" }, + }; + const { cf, calls } = fake(settings); + const changes = await zoneProtocolChanges(cf, "a", ["one.example", "two.example"]); + expect(changes.map((change) => protocolChangeLine(change, false))).toEqual([ + "A deploy turns HTTP/3 on for one.example (it is off).", + "A deploy turns 0-RTT Connection Resumption off for one.example (it is on).", + ]); + // the read wrote nothing + expect(calls.every((call) => call.startsWith("GET "))).toBe(true); + + await setZoneProtocols(cf, changes); + expect(calls.filter((call) => !call.startsWith("GET "))).toEqual([ + 'PATCH /zones/id-one.example/settings/http3 {"value":"on"}', + 'PATCH /zones/id-one.example/settings/0rtt {"value":"off"}', + ]); + expect(settings["one.example"]).toEqual({ http3: "on", "0rtt": "off" }); + expect(protocolChangeLine(changes[1]!, true)).toBe( + "Turned 0-RTT Connection Resumption off for one.example (it was on).", + ); + // a second run finds nothing to change + expect(await zoneProtocolChanges(cf, "a", ["one.example", "two.example"])).toEqual([]); +}); + +test("an answer that names no zone or no value stops the run before any write", async () => { + const { cf, calls } = fake({ "one.example": { http3: "on" } }); + await expect(zoneProtocolChanges(cf, "a", ["gone.example"])).rejects.toThrow( + "Cloudflare did not answer with the zone gone.example of the account a (200). Nothing was changed.", + ); + await expect(zoneProtocolChanges(cf, "a", ["one.example"])).rejects.toThrow( + "Cloudflare did not say whether 0-RTT Connection Resumption is on for one.example (403: Unauthorized to access requested resource). Nothing was changed.", + ); + expect(calls.every((call) => call.startsWith("GET "))).toBe(true); +}); + +test("a write that Cloudflare refuses, or answers with the old value, stops the run", async () => { + const change = { + zone: "one.example", + path: "/zones/id/settings/0rtt", + name: "0-RTT Connection Resumption", + from: "on", + to: "off", + }; + await expect( + setZoneProtocols(async () => answer(403, null, "Authentication error"), [change]), + ).rejects.toThrow( + "Cloudflare did not turn 0-RTT Connection Resumption off for one.example (403: Authentication error). The deploy did not start.", + ); + await expect( + setZoneProtocols(async () => answer(200, { value: "on" }), [change]), + ).rejects.toThrow( + "Cloudflare did not turn 0-RTT Connection Resumption off for one.example (200).", + ); +});
A core/lib/src/cli/zone-protocols.ts
@@ -0,0 +1,74 @@ +// zone-protocols.ts — THE TWO PROTOCOL SETTINGS THAT `iterate deploy` LEAVES ON EACH ZONE OF A +// MIND: HTTP/3 on, and 0-RTT Connection Resumption off. With 0-RTT, a browser sends a request in +// the TLS handshake's early data, and whoever recorded that data can send the request again: a +// mind answers GET links that work once. Every run reads both settings and writes the ones that +// differ, so a setting that somebody changed on Cloudflare's page is put back at the next deploy. +// They are no resource of the stack (core/alchemy): Alchemy plans nothing for a resource whose +// input did not change, so it would not see such a change. +import { z } from "zod"; +import { resultOf, type Cloudflare } from "./cloudflare-access.ts"; + +/** Each setting by its id in Cloudflare's API (`/zones/<id>/settings/<setting>`), the name on + * Cloudflare's page (Speed, Settings, Protocol Optimization), and the value that a deploy + * leaves. */ +export const ZONE_PROTOCOLS = [ + { id: "http3", name: "HTTP/3", value: "on" }, + { id: "0rtt", name: "0-RTT Connection Resumption", value: "off" }, +] as const; + +/** A setting of a zone that is not what a deploy leaves. */ +export type ProtocolChange = { + zone: string; + path: string; + name: string; + from: string; + to: string; +}; + +/** WHAT A DEPLOY WOULD CHANGE: the settings of `zones` that differ from `ZONE_PROTOCOLS`. Reads + * only. An answer that does not say a setting's value is no fact about it, so it stops the run. */ +export async function zoneProtocolChanges( + cf: Cloudflare, + account: string, + zones: readonly string[], +): Promise<ProtocolChange[]> { + const changes: ProtocolChange[] = []; + for (const zone of zones) { + const listed = await cf("GET", `/zones?name=${zone}&account.id=${account}`); + const id = resultOf(z.array(z.object({ id: z.string() })), listed)?.[0]?.id; + if (!id) + throw new Error( + `Cloudflare did not answer with the zone ${zone} of the account ${account} (${listed.status}${listed.error && `: ${listed.error}`}). Nothing was changed. Run the command again.`, + ); + for (const setting of ZONE_PROTOCOLS) { + const path = `/zones/${id}/settings/${setting.id}`; + const answer = await cf("GET", path); + const read = resultOf(z.object({ value: z.string() }), answer); + if (answer.status !== 200 || !read) + throw new Error( + `Cloudflare did not say whether ${setting.name} is on for ${zone} (${answer.status}${answer.error && `: ${answer.error}`}). Nothing was changed. Run the command again.`, + ); + if (read.value !== setting.value) + changes.push({ zone, path, name: setting.name, from: read.value, to: setting.value }); + } + } + return changes; +} + +/** Writes them, and stops at the first that Cloudflare refuses or answers with another value. */ +export async function setZoneProtocols(cf: Cloudflare, changes: readonly ProtocolChange[]) { + for (const change of changes) { + const answer = await cf("PATCH", change.path, { value: change.to }); + const now = resultOf(z.object({ value: z.string() }), answer)?.value; + if (answer.status !== 200 || now !== change.to) + throw new Error( + `Cloudflare did not turn ${change.name} ${change.to} for ${change.zone} (${answer.status}${answer.error && `: ${answer.error}`}). The deploy did not start. Run the command again, or turn it ${change.to} on Cloudflare's page for ${change.zone}: Speed, Settings, Protocol Optimization.`, + ); + } +} + +/** One line for a person: what was changed, or what a deploy would change (`done` false). */ +export const protocolChangeLine = (change: ProtocolChange, done: boolean) => + done + ? `Turned ${change.name} ${change.to} for ${change.zone} (it was ${change.from}).` + : `A deploy turns ${change.name} ${change.to} for ${change.zone} (it is ${change.from}).`;