@volter/twin-cloudflare 0.1.0

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.
Files changed (58) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +223 -0
  3. package/dist/r2/src/endpoint.d.ts +14 -0
  4. package/dist/r2/src/endpoint.js +30 -0
  5. package/dist/r2/src/fetch.d.ts +7 -0
  6. package/dist/r2/src/fetch.js +230 -0
  7. package/dist/r2/src/generated/surface.gen.json +1 -0
  8. package/dist/r2/src/manifest.d.ts +22 -0
  9. package/dist/r2/src/manifest.js +69 -0
  10. package/dist/r2/src/semantics/buckets.d.ts +18 -0
  11. package/dist/r2/src/semantics/buckets.js +145 -0
  12. package/dist/r2/src/semantics/objects.d.ts +8 -0
  13. package/dist/r2/src/semantics/objects.js +252 -0
  14. package/dist/r2/src/wire.d.ts +54 -0
  15. package/dist/r2/src/wire.js +120 -0
  16. package/dist/src/cli.d.ts +2 -0
  17. package/dist/src/cli.js +26 -0
  18. package/dist/src/cloudflare-budget.d.ts +22 -0
  19. package/dist/src/cloudflare-budget.js +40 -0
  20. package/dist/src/cloudflare-capabilities.d.ts +6 -0
  21. package/dist/src/cloudflare-capabilities.js +1161 -0
  22. package/dist/src/cloudflare-common.d.ts +59 -0
  23. package/dist/src/cloudflare-common.js +142 -0
  24. package/dist/src/cloudflare-conformance.d.ts +6 -0
  25. package/dist/src/cloudflare-conformance.js +251 -0
  26. package/dist/src/cloudflare-connector.d.ts +53 -0
  27. package/dist/src/cloudflare-connector.js +418 -0
  28. package/dist/src/cloudflare-openapi-operations.d.ts +10 -0
  29. package/dist/src/cloudflare-openapi-operations.js +3336 -0
  30. package/dist/src/cloudflare-provisioning.d.ts +5 -0
  31. package/dist/src/cloudflare-provisioning.js +2097 -0
  32. package/dist/src/cloudflare-r2.d.ts +121 -0
  33. package/dist/src/cloudflare-r2.js +138 -0
  34. package/dist/src/cloudflare-server.d.ts +17 -0
  35. package/dist/src/cloudflare-server.js +101 -0
  36. package/dist/src/cloudflare-twin.d.ts +14 -0
  37. package/dist/src/cloudflare-twin.js +762 -0
  38. package/dist/src/cloudflare-worker-assets.d.ts +25 -0
  39. package/dist/src/cloudflare-worker-assets.js +192 -0
  40. package/dist/src/index.d.ts +9 -0
  41. package/dist/src/index.js +69 -0
  42. package/dist/src/screens/dashboard.d.ts +3 -0
  43. package/dist/src/screens/dashboard.js +265 -0
  44. package/package.json +56 -0
  45. package/src/cli.ts +25 -0
  46. package/src/cloudflare-budget.ts +61 -0
  47. package/src/cloudflare-capabilities.ts +1107 -0
  48. package/src/cloudflare-common.ts +183 -0
  49. package/src/cloudflare-conformance.ts +204 -0
  50. package/src/cloudflare-connector.ts +443 -0
  51. package/src/cloudflare-openapi-operations.ts +3344 -0
  52. package/src/cloudflare-provisioning.ts +1969 -0
  53. package/src/cloudflare-r2.ts +173 -0
  54. package/src/cloudflare-server.ts +109 -0
  55. package/src/cloudflare-twin.ts +714 -0
  56. package/src/cloudflare-worker-assets.ts +207 -0
  57. package/src/index.ts +112 -0
  58. package/src/screens/dashboard.tsx +297 -0
@@ -0,0 +1,1161 @@
1
+ // Honest top-down Cloudflare denominator: exactly one capability per HTTP operation
2
+ // in Cloudflare's first-party OpenAPI 4.0.0 document, plus an explicitly separate
3
+ // connector surface. The operation census is
4
+ // generated from cloudflare/api-schemas commit 2ac8369e9b63dccacee1a2284e95bb819f05b307.
5
+ import { mkdtempSync, rmSync } from 'node:fs';
6
+ import { tmpdir } from 'node:os';
7
+ import { join } from 'node:path';
8
+ import { checkCapabilities, verifyBoundary } from '@volter/world-tooling';
9
+ import { applyTwinWrite, deployableEntries, projectResources } from '@volter/world-core';
10
+ import { handleCloudflareTwinRequest } from "./cloudflare-twin.js";
11
+ import { pullCloudflareState, performCloudflareAction, syncCloudflareFromReal, } from "./cloudflare-connector.js";
12
+ import { CloudflareBudget, CloudflareBudgetError, CLOUDFLARE_BUDGET_CEILING, cloudflareCallWeight } from "./cloudflare-budget.js";
13
+ import { CLOUDFLARE_OPENAPI_OPERATIONS } from "./cloudflare-openapi-operations.js";
14
+ // Independent official SDK namespace census. It is not used as a denominator: the
15
+ // finer and complete OpenAPI method+path inventory below is the one manifest granularity.
16
+ export const CLOUDFLARE_OFFICIAL_AREAS = [
17
+ 'abuse-reports', 'accounts', 'acm', 'addressing', 'ai', 'ai-audit', 'ai-gateway', 'ai-security', 'aisearch',
18
+ 'alerting', 'analytics-query', 'api-gateway', 'argo', 'audit-logs', 'billing', 'bot-management', 'botnet-feed',
19
+ 'brand-protection', 'browser-rendering', 'cache', 'calls', 'certificate-authorities', 'client-certificates',
20
+ 'cloud-connector', 'cloudforce-one', 'connectivity', 'content-scanning', 'csam-scanner', 'custom-certificates',
21
+ 'custom-csrs', 'custom-hostnames', 'custom-nameservers', 'custom-pages', 'd1', 'dcv-delegation', 'ddos-protection',
22
+ 'diagnostics', 'dls', 'dns', 'dns-firewall', 'durable-objects', 'email-auth', 'email-routing', 'email-security',
23
+ 'email-sending', 'filters', 'firewall', 'flagship', 'fraud', 'google-tag-gateway', 'healthchecks', 'hostnames',
24
+ 'hyperdrive', 'iam', 'images', 'intel', 'ips', 'keyless-certificates', 'kv', 'leaked-credential-checks',
25
+ 'load-balancers', 'logpush', 'logs', 'magic-cloud-networking', 'magic-network-monitoring', 'magic-transit',
26
+ 'managed-transforms', 'memberships', 'moq', 'mtls-certificates', 'network-interconnects', 'organizations',
27
+ 'origin-ca-certificates', 'origin-post-quantum-encryption', 'origin-tls-client-auth', 'origin-tls-compliance-modes',
28
+ 'page-rules', 'page-shield', 'pages', 'pipelines', 'precursor', 'queues', 'r2', 'r2-data-catalog', 'radar',
29
+ 'rate-limits', 'realtime-kit', 'registrar', 'registrar-sandbox', 'request-tracers', 'resource-sharing',
30
+ 'resource-tagging', 'rules', 'rulesets', 'rum', 'schema-validation', 'secrets-store', 'security-center',
31
+ 'security-txt', 'snippets', 'spectrum', 'speed', 'ssl', 'stream', 'tenant-custom-nameservers', 'tenants',
32
+ 'token-validation', 'turnstile', 'url-normalization', 'url-scanner', 'user', 'vectorize', 'vulnerability-scanner',
33
+ 'waiting-rooms', 'web3', 'workers', 'workers-for-platforms', 'workflows', 'zaraz', 'zero-trust', 'zones',
34
+ ];
35
+ export const CLOUDFLARE_OPENAPI_AREAS = [...new Set(CLOUDFLARE_OPENAPI_OPERATIONS.map((operation) => operation.area))].sort();
36
+ export const CLOUDFLARE_AREAS = [...new Set([...CLOUDFLARE_OPENAPI_AREAS, 'connector'])].sort();
37
+ const AT = '2026-08-21T00:00:00.000Z';
38
+ const ACCOUNT = 'a'.repeat(32);
39
+ const ZONE = 'b'.repeat(32);
40
+ const VENDOR_TUNNEL = '11111111-2222-4333-a444-555555555555';
41
+ async function withRoot(fn) {
42
+ const root = mkdtempSync(join(tmpdir(), 'cloudflare-cap-'));
43
+ const call = (step) => handleCloudflareTwinRequest({
44
+ root,
45
+ method: step.m,
46
+ path: step.p,
47
+ occurredAt: AT,
48
+ headers: {
49
+ ...(step.auth === false ? {} : { authorization: `Bearer ${step.bearer ?? 'local-certification-token'}` }),
50
+ ...(step.ct ? { 'content-type': step.ct } : {}),
51
+ },
52
+ ...(step.raw !== undefined ? { body: step.raw } : step.b === undefined ? {} : { body: JSON.stringify(step.b) }),
53
+ });
54
+ try {
55
+ return await verifyBoundary('cloudflare.withRoot', () => fn(call, root));
56
+ }
57
+ finally {
58
+ rmSync(root, { recursive: true, force: true });
59
+ }
60
+ }
61
+ async function seed(call) {
62
+ await call({ m: 'POST', p: '/twin/bootstrap', b: {
63
+ accounts: [{ id: ACCOUNT, name: 'Acme' }],
64
+ zones: [{ id: ZONE, account_id: ACCOUNT, name: 'example.test' }],
65
+ } });
66
+ }
67
+ /** The head's loop, in miniature (protocol 2): perform each entry the twin appended through the connector,
68
+ * remembering the vendor's id for the ones it minted so a later entry names the vendor's id, not ours. */
69
+ async function performAll(root, execute, adopted = new Map(), done = new Set()) {
70
+ const ctx = { resolve: (type, id) => adopted.get(`${type}:${id}`) ?? id, service: 'cloudflare', root };
71
+ let performed = 0;
72
+ for (const entry of deployableEntries('cloudflare', root)) {
73
+ if (done.has(entry.id))
74
+ continue; // the head confirms what it performed; this harness remembers instead
75
+ try {
76
+ const outcome = await performCloudflareAction(execute, entry, ctx);
77
+ adopted.set(`${entry.subject.type}:${entry.subject.id}`, outcome.externalId);
78
+ done.add(entry.id);
79
+ performed += 1;
80
+ }
81
+ catch (error) {
82
+ return { performed, failed: error instanceof Error ? error.message : String(error), adopted, done };
83
+ }
84
+ }
85
+ return { performed, failed: null, adopted, done };
86
+ }
87
+ /** A vendor answering the API v4 envelope, as the kernel's executor hands it over: JSON in, JSON out. */
88
+ function vendor(reply) {
89
+ const seen = [];
90
+ const execute = async (request) => {
91
+ const body = request.body ? JSON.parse(typeof request.body === 'string' ? request.body : new TextDecoder().decode(request.body)) : undefined;
92
+ const path = request.path.replace(/^\/client\/v4/, '');
93
+ seen.push({ method: request.method, path, ...(body ? { body } : {}) });
94
+ const answer = reply(request.method, path, body);
95
+ return { status: answer.status, headers: {}, body: JSON.stringify(answer.body) };
96
+ };
97
+ return { execute, seen };
98
+ }
99
+ async function tunnel(call, name = 'local-cert') {
100
+ const response = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/cfd_tunnel`, b: { name, config_src: 'cloudflare' } });
101
+ return String(response.body.result?.id ?? '');
102
+ }
103
+ /** Build the exact multipart body an unmodified SDK/wrangler-shaped deploy emits: a JSON
104
+ * `metadata` part plus named module file parts. */
105
+ function moduleUpload(metadata, files = { 'worker.js': 'export default { fetch() { return new Response("ok"); } };' }) {
106
+ const boundary = 'twin-cap-boundary';
107
+ const parts = [
108
+ `--${boundary}\r\nContent-Disposition: form-data; name="metadata"\r\nContent-Type: application/json\r\n\r\n${JSON.stringify(metadata)}\r\n`,
109
+ ...Object.entries(files).map(([name, content]) => `--${boundary}\r\nContent-Disposition: form-data; name="files[]"; filename="${name}"\r\nContent-Type: application/javascript+module\r\n\r\n${content}\r\n`),
110
+ ];
111
+ return { m: 'PUT', p: '', raw: `${parts.join('')}--${boundary}--\r\n`, ct: `multipart/form-data; boundary=${boundary}` };
112
+ }
113
+ async function deployWorker(call, name = 'cert-worker', metadata = { main_module: 'worker.js' }) {
114
+ const upload = moduleUpload(metadata);
115
+ return call({ ...upload, p: `/accounts/${ACCOUNT}/workers/scripts/${name}` });
116
+ }
117
+ async function seedQueue(call, name = 'cert-queue') {
118
+ const response = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues`, b: { queue_name: name } });
119
+ return String(response.body.result?.queue_id ?? '');
120
+ }
121
+ const HD_ORIGIN = { scheme: 'postgres', database: 'app', user: 'launch', password: 'secret-launch-pass', host: 'db.internal.test', port: 5432 };
122
+ async function seedHyperdrive(call, name = 'cert-hd') {
123
+ const response = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/hyperdrive/configs`, b: { name, origin: HD_ORIGIN } });
124
+ return String(response.body.result?.id ?? '');
125
+ }
126
+ const operationVerifiers = new Map([
127
+ ['GET /accounts', () => withRoot(async (call) => {
128
+ await seed(call);
129
+ const denied = await call({ m: 'GET', p: '/accounts', auth: false });
130
+ const response = await call({ m: 'GET', p: '/accounts?name=Acme&per_page=1' });
131
+ return denied.status === 403 && denied.body.errors?.[0]?.code === 10000
132
+ && response.status === 200 && response.body.result?.[0]?.id === ACCOUNT
133
+ && response.body.result_info?.total_count === 1;
134
+ })],
135
+ ['GET /accounts/{account_id}', () => withRoot(async (call) => {
136
+ await seed(call);
137
+ const response = await call({ m: 'GET', p: `/accounts/${ACCOUNT}` });
138
+ return response.status === 200 && response.body.result?.name === 'Acme';
139
+ })],
140
+ ['GET /zones', () => withRoot(async (call) => {
141
+ await seed(call);
142
+ const response = await call({ m: 'GET', p: `/zones?name=example.test&account.id=${ACCOUNT}` });
143
+ return response.status === 200 && response.body.result?.[0]?.account?.id === ACCOUNT;
144
+ })],
145
+ ['GET /zones/{zone_id}', () => withRoot(async (call) => {
146
+ await seed(call);
147
+ const response = await call({ m: 'GET', p: `/zones/${ZONE}` });
148
+ return response.status === 200 && response.body.result?.name === 'example.test';
149
+ })],
150
+ ['POST /accounts/{account_id}/cfd_tunnel', () => withRoot(async (call) => {
151
+ await seed(call);
152
+ const invalid = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/cfd_tunnel`, b: { name: 'bad', tunnel_secret: 'not-base64' } });
153
+ const id = await tunnel(call);
154
+ return invalid.status === 400 && /^[0-9a-f-]{36}$/.test(id);
155
+ })],
156
+ ['GET /accounts/{account_id}/cfd_tunnel', () => withRoot(async (call) => {
157
+ await seed(call);
158
+ const first = await tunnel(call, 'first');
159
+ await tunnel(call, 'second');
160
+ await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/cfd_tunnel/${first}` });
161
+ const all = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel` });
162
+ const active = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel?is_deleted=false` });
163
+ const deleted = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel?is_deleted=true` });
164
+ return all.body.result?.length === 2 && active.body.result?.length === 1
165
+ && deleted.body.result?.[0]?.deleted_at !== null;
166
+ })],
167
+ ['GET /accounts/{account_id}/cfd_tunnel/{tunnel_id}', () => withRoot(async (call) => {
168
+ await seed(call);
169
+ const id = await tunnel(call);
170
+ const response = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}` });
171
+ return response.status === 200 && response.body.result?.id === id;
172
+ })],
173
+ ['PATCH /accounts/{account_id}/cfd_tunnel/{tunnel_id}', () => withRoot(async (call) => {
174
+ await seed(call);
175
+ const first = await tunnel(call, 'first');
176
+ await tunnel(call, 'second');
177
+ const conflict = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/cfd_tunnel/${first}`, b: { name: 'second' } });
178
+ const invalid = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/cfd_tunnel/${first}`, b: { tunnel_secret: 'not-base64' } });
179
+ const validSecret = Buffer.alloc(32, 7).toString('base64');
180
+ const edited = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/cfd_tunnel/${first}`, b: { name: 'renamed', tunnel_secret: validSecret } });
181
+ return conflict.status === 409 && invalid.status === 400 && edited.body.result?.name === 'renamed';
182
+ })],
183
+ ['DELETE /accounts/{account_id}/cfd_tunnel/{tunnel_id}', () => withRoot(async (call) => {
184
+ await seed(call);
185
+ const id = await tunnel(call);
186
+ const response = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}` });
187
+ return response.status === 200 && response.body.result?.id === id
188
+ && typeof response.body.result?.deleted_at === 'string'
189
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}` })).status === 404;
190
+ })],
191
+ ['PUT /accounts/{account_id}/cfd_tunnel/{tunnel_id}/configurations', () => withRoot(async (call) => {
192
+ await seed(call);
193
+ const id = await tunnel(call);
194
+ const response = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}/configurations`, b: { config: { ingress: [{ hostname: '*', service: 'http_status:404' }] } } });
195
+ return response.status === 200 && response.body.result?.tunnel_id === id && response.body.result?.version === 1;
196
+ })],
197
+ ['GET /accounts/{account_id}/cfd_tunnel/{tunnel_id}/configurations', () => withRoot(async (call) => {
198
+ await seed(call);
199
+ const id = await tunnel(call);
200
+ await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}/configurations`, b: { config: { ingress: [{ hostname: '*', service: 'http_status:404' }] } } });
201
+ const response = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}/configurations` });
202
+ return response.status === 200 && response.body.result?.config?.ingress?.[0]?.service === 'http_status:404';
203
+ })],
204
+ ['GET /accounts/{account_id}/cfd_tunnel/{tunnel_id}/token', () => withRoot(async (call) => {
205
+ await seed(call);
206
+ const id = await tunnel(call);
207
+ const first = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}/token` });
208
+ const second = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/cfd_tunnel/${id}/token` });
209
+ return typeof first.body.result === 'string' && first.body.result === second.body.result;
210
+ })],
211
+ ['POST /zones/{zone_id}/dns_records', () => withRoot(async (call) => {
212
+ await seed(call);
213
+ const caa = await call({ m: 'POST', p: `/zones/${ZONE}/dns_records`, b: {
214
+ type: 'CAA', name: 'example.test', ttl: 60, data: { flags: 0, tag: 'issue', value: 'letsencrypt.org' },
215
+ } });
216
+ return caa.status === 200 && caa.body.result?.type === 'CAA'
217
+ && caa.body.result?.data?.value === 'letsencrypt.org'
218
+ && !Object.hasOwn(caa.body.result, 'content');
219
+ })],
220
+ ['GET /zones/{zone_id}/dns_records', () => withRoot(async (call) => {
221
+ await seed(call);
222
+ await call({ m: 'POST', p: `/zones/${ZONE}/dns_records`, b: { type: 'CNAME', name: 'app.example.test', content: 'target.example.test', ttl: 1 } });
223
+ const response = await call({ m: 'GET', p: `/zones/${ZONE}/dns_records?type=CNAME&name=app.example.test` });
224
+ return response.status === 200 && response.body.result?.length === 1;
225
+ })],
226
+ ['GET /zones/{zone_id}/dns_records/{dns_record_id}', () => withRoot(async (call) => {
227
+ await seed(call);
228
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/dns_records`, b: { type: 'A', name: 'a.example.test', content: '192.0.2.1', ttl: 60 } });
229
+ return (await call({ m: 'GET', p: `/zones/${ZONE}/dns_records/${created.body.result.id}` })).status === 200;
230
+ })],
231
+ ['PUT /zones/{zone_id}/dns_records/{dns_record_id}', () => withRoot(async (call) => {
232
+ await seed(call);
233
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/dns_records`, b: { type: 'A', name: 'a.example.test', content: '192.0.2.1', ttl: 60, comment: 'old', tags: ['owner:test'], settings: { ipv4_only: true } } });
234
+ const id = created.body.result.id;
235
+ const partial = await call({ m: 'PUT', p: `/zones/${ZONE}/dns_records/${id}`, b: { content: '192.0.2.2' } });
236
+ const replaced = await call({ m: 'PUT', p: `/zones/${ZONE}/dns_records/${id}`, b: { type: 'CAA', name: 'example.test', ttl: 120, data: { flags: 0, tag: 'issue', value: 'pki.goog' } } });
237
+ const value = replaced.body.result;
238
+ return partial.status === 400 && replaced.status === 200 && value.type === 'CAA' && value.data?.value === 'pki.goog'
239
+ && !Object.hasOwn(value, 'content') && value.comment === null && value.tags?.length === 0
240
+ && Object.keys(value.settings ?? {}).length === 0;
241
+ })],
242
+ ['PATCH /zones/{zone_id}/dns_records/{dns_record_id}', () => withRoot(async (call) => {
243
+ await seed(call);
244
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/dns_records`, b: { type: 'TXT', name: 'txt.example.test', content: 'one', ttl: 60, comment: 'keep', tags: ['owner:test'] } });
245
+ const response = await call({ m: 'PATCH', p: `/zones/${ZONE}/dns_records/${created.body.result.id}`, b: { content: 'two' } });
246
+ const value = response.body.result;
247
+ return response.status === 200 && value.content === 'two' && value.name === 'txt.example.test' && value.comment === 'keep' && value.tags?.[0] === 'owner:test';
248
+ })],
249
+ ['DELETE /zones/{zone_id}/dns_records/{dns_record_id}', () => withRoot(async (call) => {
250
+ await seed(call);
251
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/dns_records`, b: { type: 'TXT', name: 'txt.example.test', content: 'one', ttl: 60 } });
252
+ const id = created.body.result.id;
253
+ return (await call({ m: 'DELETE', p: `/zones/${ZONE}/dns_records/${id}` })).status === 200
254
+ && (await call({ m: 'GET', p: `/zones/${ZONE}/dns_records/${id}` })).status === 404;
255
+ })],
256
+ ]);
257
+ // Workers / R2 / Hyperdrive / Queues provisioning verifiers. Every verify starts from a
258
+ // fresh root, seeds through the twin's own write path, asserts response VALUES, and drives
259
+ // the negative 4xx path its operation implies. Merged into operationVerifiers below.
260
+ const provisioningVerifiers = new Map([
261
+ ['GET /accounts/{account_id}/workers/scripts', () => withRoot(async (call) => {
262
+ await seed(call);
263
+ const uploaded = await deployWorker(call, 'list-me', { main_module: 'worker.js', compatibility_date: '2026-08-01', tags: ['launch'] });
264
+ // A service binding to a Worker that does not exist must be rejected, and the rejected
265
+ // upload must not appear in the list (round-two N4).
266
+ const svcGhost = await deployWorker(call, 'svc-ghost', { main_module: 'worker.js', bindings: [{ type: 'service', name: 'SVC', service: 'never-uploaded' }] });
267
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts` });
268
+ const item = listed.body.result?.[0];
269
+ return uploaded.status === 200 && svcGhost.status === 400 && listed.status === 200
270
+ && item?.id === 'list-me' && item?.etag === uploaded.body.result?.etag
271
+ && item?.compatibility_date === '2026-08-01' && item?.tags?.[0] === 'launch'
272
+ && listed.body.result_info?.total_count === 1;
273
+ })],
274
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}', () => withRoot(async (call) => {
275
+ await seed(call);
276
+ await deployWorker(call, 'download-me', { main_module: 'worker.js' });
277
+ const download = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/download-me` });
278
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/never-uploaded` });
279
+ // A single-module module-syntax Worker still downloads as multipart/form-data (not raw JS).
280
+ return download.status === 200 && download.raw === true
281
+ && (download.headers?.['content-type'] ?? '').includes('multipart/form-data')
282
+ && String(download.body).includes('return new Response("ok")')
283
+ && missing.status === 404 && missing.body.errors?.[0]?.code === 10007;
284
+ })],
285
+ ['DELETE /accounts/{account_id}/workers/scripts/{script_name}', () => withRoot(async (call) => {
286
+ await seed(call);
287
+ // Dirty-state cell: upload with a DO class AND distinctive metadata, prove no-force delete
288
+ // is BLOCKED by the namespace (the pinned OpenAPI force contract), force-delete, then
289
+ // recreate the same name with BARE metadata and assert none of the deleted script's fields
290
+ // resurrect through the kernel tombstone merge (finding-3).
291
+ await deployWorker(call, 'delete-me', {
292
+ main_module: 'worker.js', usage_model: 'unbound', logpush: true, tags: ['old-tag'],
293
+ compatibility_date: '2026-01-01', migrations: { new_tag: 'v9', new_classes: ['Session'] },
294
+ });
295
+ const blocked = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/workers/scripts/delete-me` });
296
+ const forced = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/workers/scripts/delete-me?force=true` });
297
+ const gone = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/delete-me` });
298
+ const namespaces = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/durable_objects/namespaces` });
299
+ const recreated = await deployWorker(call, 'delete-me', { main_module: 'worker.js' });
300
+ const fresh = recreated.body.result;
301
+ return blocked.status === 400 && forced.status === 200 && forced.body.result === null
302
+ && gone.status === 404
303
+ && namespaces.body.result?.length === 0
304
+ && recreated.status === 200 && fresh?.id === 'delete-me'
305
+ && fresh?.usage_model === 'standard' && fresh?.logpush === false
306
+ && !Object.hasOwn(fresh ?? {}, 'compatibility_date') && (fresh?.tags?.length ?? 0) === 0
307
+ && !Object.hasOwn(fresh ?? {}, 'migration_tag')
308
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/delete-me` })).status === 200;
309
+ })],
310
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/schedules', () => withRoot(async (call) => {
311
+ await seed(call);
312
+ await deployWorker(call);
313
+ await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/schedules`, b: [{ cron: '*/30 * * * *' }] });
314
+ const response = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/schedules` });
315
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/never-uploaded/schedules` });
316
+ return response.status === 200 && response.body.result?.schedules?.[0]?.cron === '*/30 * * * *'
317
+ && typeof response.body.result?.schedules?.[0]?.created_on === 'string'
318
+ && missing.status === 404;
319
+ })],
320
+ ['PUT /accounts/{account_id}/workers/scripts/{script_name}/schedules', () => withRoot(async (call) => {
321
+ await seed(call);
322
+ await deployWorker(call);
323
+ const invalid = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/schedules`, b: [{ cron: 'not a cron' }] });
324
+ // Garbage that happens to have 5 whitespace tokens must still be rejected field-by-field.
325
+ const garbageFields = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/schedules`, b: [{ cron: 'zz zz zz zz zz' }] });
326
+ const outOfRange = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/schedules`, b: [{ cron: '99 * * * *' }] });
327
+ const replaced = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/schedules`, b: [{ cron: '0 3 * * MON' }, { cron: '*/5 9-17 * jan-mar 1,3,5' }] });
328
+ const emptied = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/schedules`, b: [] });
329
+ return invalid.status === 400 && garbageFields.status === 400 && outOfRange.status === 400 && replaced.status === 200
330
+ && replaced.body.result?.schedules?.map((item) => item.cron).join(',') === '0 3 * * MON,*/5 9-17 * jan-mar 1,3,5'
331
+ && emptied.status === 200 && emptied.body.result?.schedules?.length === 0;
332
+ })],
333
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/subdomain', () => withRoot(async (call) => {
334
+ await seed(call);
335
+ await deployWorker(call);
336
+ const before = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain` });
337
+ await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain`, b: { enabled: true, previews_enabled: true } });
338
+ const after = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain` });
339
+ return before.body.result?.enabled === false && after.status === 200
340
+ && after.body.result?.enabled === true && after.body.result?.previews_enabled === true;
341
+ })],
342
+ ['POST /accounts/{account_id}/workers/scripts/{script_name}/subdomain', () => withRoot(async (call) => {
343
+ await seed(call);
344
+ await deployWorker(call);
345
+ const invalid = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain`, b: {} });
346
+ const enabled = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain`, b: { enabled: true } });
347
+ return invalid.status === 400 && enabled.status === 200 && enabled.body.result?.enabled === true;
348
+ })],
349
+ ['DELETE /accounts/{account_id}/workers/scripts/{script_name}/subdomain', () => withRoot(async (call) => {
350
+ await seed(call);
351
+ await deployWorker(call);
352
+ await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain`, b: { enabled: true, previews_enabled: true } });
353
+ const disabled = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain` });
354
+ const after = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/subdomain` });
355
+ return disabled.status === 200 && disabled.body.result?.enabled === false
356
+ && after.body.result?.previews_enabled === false;
357
+ })],
358
+ ['GET /accounts/{account_id}/workers/subdomain', () => withRoot(async (call) => {
359
+ await seed(call);
360
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/subdomain` });
361
+ await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/subdomain`, b: { subdomain: 'launch-team' } });
362
+ const after = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/subdomain` });
363
+ return missing.status === 404 && after.status === 200 && after.body.result?.subdomain === 'launch-team';
364
+ })],
365
+ ['PUT /accounts/{account_id}/workers/subdomain', () => withRoot(async (call) => {
366
+ await seed(call);
367
+ const invalid = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/subdomain`, b: {} });
368
+ const badLabel = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/subdomain`, b: { subdomain: 'not a label!' } });
369
+ const created = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/subdomain`, b: { subdomain: 'Launch-Team' } });
370
+ return invalid.status === 400 && badLabel.status === 400
371
+ && created.status === 200 && created.body.result?.subdomain === 'launch-team';
372
+ })],
373
+ ['DELETE /accounts/{account_id}/workers/subdomain', () => withRoot(async (call) => {
374
+ await seed(call);
375
+ await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/subdomain`, b: { subdomain: 'launch-team' } });
376
+ const deleted = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/workers/subdomain` });
377
+ const after = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/subdomain` });
378
+ // 204 with no body per the pinned OpenAPI; a later PUT can re-create over the tombstone.
379
+ const recreated = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/subdomain`, b: { subdomain: 'launch-team' } });
380
+ return deleted.status === 204 && after.status === 404
381
+ && recreated.status === 200 && recreated.body.result?.subdomain === 'launch-team';
382
+ })],
383
+ ['GET /accounts/{account_id}/workers/domains', () => withRoot(async (call) => {
384
+ await seed(call);
385
+ await deployWorker(call);
386
+ await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/domains`, b: { hostname: 'api.example.test', service: 'cert-worker' } });
387
+ const all = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains` });
388
+ const filtered = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains?hostname=api.example.test` });
389
+ const none = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains?hostname=other.example.test` });
390
+ // The documented `environment` filter is honored: production matches, anything else empties.
391
+ const prod = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains?environment=production` });
392
+ const staging = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains?environment=staging` });
393
+ return all.status === 200 && all.body.result?.[0]?.service === 'cert-worker'
394
+ && filtered.body.result?.length === 1 && none.body.result?.length === 0
395
+ && prod.body.result?.length === 1 && staging.body.result?.length === 0;
396
+ })],
397
+ ['PUT /accounts/{account_id}/workers/domains', () => withRoot(async (call) => {
398
+ await seed(call);
399
+ await deployWorker(call);
400
+ const outside = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/domains`, b: { hostname: 'api.unrelated.test', service: 'cert-worker' } });
401
+ const noWorker = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/domains`, b: { hostname: 'api.example.test', service: 'never-uploaded' } });
402
+ const badZoneName = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/domains`, b: { hostname: 'api.example.test', service: 'cert-worker', zone_name: 'wrong.test' } });
403
+ const attached = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/domains`, b: { hostname: 'API.example.test', service: 'cert-worker' } });
404
+ const value = attached.body.result;
405
+ return outside.status === 400 && noWorker.status === 400 && badZoneName.status === 400 && attached.status === 200
406
+ && value?.hostname === 'api.example.test' && value?.zone_id === ZONE && value?.zone_name === 'example.test'
407
+ && typeof value?.cert_id === 'string' && value.cert_id.length > 0;
408
+ })],
409
+ ['GET /accounts/{account_id}/workers/domains/{domain_id}', () => withRoot(async (call) => {
410
+ await seed(call);
411
+ await deployWorker(call);
412
+ const attached = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/domains`, b: { hostname: 'api.example.test', service: 'cert-worker' } });
413
+ const id = attached.body.result?.id;
414
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains/${id}` });
415
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains/${'f'.repeat(32)}` });
416
+ return fetched.status === 200 && fetched.body.result?.id === id && missing.status === 404;
417
+ })],
418
+ ['DELETE /accounts/{account_id}/workers/domains/{domain_id}', () => withRoot(async (call) => {
419
+ await seed(call);
420
+ await deployWorker(call);
421
+ const attached = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/workers/domains`, b: { hostname: 'api.example.test', service: 'cert-worker' } });
422
+ const id = attached.body.result?.id;
423
+ const detached = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/workers/domains/${id}` });
424
+ // Pinned workers_api-response-common envelope: no `result` member.
425
+ return detached.status === 200 && detached.body.success === true
426
+ && !Object.hasOwn(detached.body, 'result')
427
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/domains/${id}` })).status === 404;
428
+ })],
429
+ ['GET /accounts/{account_id}/workers/durable_objects/namespaces', () => withRoot(async (call) => {
430
+ await seed(call);
431
+ await deployWorker(call, 'do-worker', { main_module: 'worker.js', migrations: { new_tag: 'v1', new_sqlite_classes: ['Session'], new_classes: ['Legacy'] } });
432
+ // A REJECTED upload (a DO binding referencing a class the migration does not create) must
433
+ // leave NO orphan namespace and no script — migrations are planned, not applied, until all
434
+ // validation passes (round-two N5).
435
+ const rejected = await deployWorker(call, 'ghost-worker', {
436
+ main_module: 'worker.js',
437
+ bindings: [{ type: 'durable_object_namespace', name: 'DO', class_name: 'Missing' }],
438
+ migrations: { new_tag: 'v1', new_sqlite_classes: ['Present'] },
439
+ });
440
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/durable_objects/namespaces` });
441
+ const classes = (listed.body.result ?? []).map((item) => `${item.class}:${item.use_sqlite}:${item.script}`).sort();
442
+ return rejected.status === 400
443
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/ghost-worker` })).status === 404
444
+ && listed.status === 200 && classes.join(',') === 'Legacy:false:do-worker,Session:true:do-worker'
445
+ && listed.body.result_info?.total_count === 2;
446
+ })],
447
+ ['GET /zones/{zone_id}/workers/routes', () => withRoot(async (call) => {
448
+ await seed(call);
449
+ await deployWorker(call);
450
+ await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: { pattern: 'example.test/api/*', script: 'cert-worker' } });
451
+ const listed = await call({ m: 'GET', p: `/zones/${ZONE}/workers/routes` });
452
+ const badZone = await call({ m: 'GET', p: `/zones/${'9'.repeat(32)}/workers/routes` });
453
+ return listed.status === 200 && listed.body.result?.[0]?.pattern === 'example.test/api/*'
454
+ && listed.body.result?.[0]?.script === 'cert-worker' && badZone.status === 404;
455
+ })],
456
+ ['POST /zones/{zone_id}/workers/routes', () => withRoot(async (call) => {
457
+ await seed(call);
458
+ await deployWorker(call);
459
+ const invalid = await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: {} });
460
+ // A route naming a script that is not a Worker on the zone's account must 400 (finding-5).
461
+ const ghostScript = await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: { pattern: 'example.test/ghost/*', script: 'never-uploaded' } });
462
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: { pattern: 'example.test/api/*', script: 'cert-worker' } });
463
+ const duplicate = await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: { pattern: 'example.test/api/*' } });
464
+ return invalid.status === 400 && ghostScript.status === 400 && ghostScript.body.errors?.[0]?.code === 10007
465
+ && created.status === 200
466
+ && /^[0-9a-f]{32}$/.test(String(created.body.result?.id)) && duplicate.status === 409;
467
+ })],
468
+ ['GET /zones/{zone_id}/workers/routes/{route_id}', () => withRoot(async (call) => {
469
+ await seed(call);
470
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: { pattern: 'example.test/*' } });
471
+ const id = created.body.result?.id;
472
+ const fetched = await call({ m: 'GET', p: `/zones/${ZONE}/workers/routes/${id}` });
473
+ const missing = await call({ m: 'GET', p: `/zones/${ZONE}/workers/routes/${'f'.repeat(32)}` });
474
+ return fetched.status === 200 && fetched.body.result?.pattern === 'example.test/*'
475
+ && !Object.hasOwn(fetched.body.result ?? {}, 'script') && missing.status === 404;
476
+ })],
477
+ ['PUT /zones/{zone_id}/workers/routes/{route_id}', () => withRoot(async (call) => {
478
+ await seed(call);
479
+ await deployWorker(call);
480
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: { pattern: 'example.test/api/*', script: 'cert-worker' } });
481
+ const id = created.body.result?.id;
482
+ const invalid = await call({ m: 'PUT', p: `/zones/${ZONE}/workers/routes/${id}`, b: {} });
483
+ const ghostScript = await call({ m: 'PUT', p: `/zones/${ZONE}/workers/routes/${id}`, b: { pattern: 'example.test/v2/*', script: 'never-uploaded' } });
484
+ const updated = await call({ m: 'PUT', p: `/zones/${ZONE}/workers/routes/${id}`, b: { pattern: 'example.test/v2/*', script: 'cert-worker' } });
485
+ return invalid.status === 400 && ghostScript.status === 400 && ghostScript.body.errors?.[0]?.code === 10007
486
+ && updated.status === 200 && updated.body.result?.pattern === 'example.test/v2/*';
487
+ })],
488
+ ['DELETE /zones/{zone_id}/workers/routes/{route_id}', () => withRoot(async (call) => {
489
+ await seed(call);
490
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/workers/routes`, b: { pattern: 'example.test/*' } });
491
+ const id = created.body.result?.id;
492
+ const deleted = await call({ m: 'DELETE', p: `/zones/${ZONE}/workers/routes/${id}` });
493
+ return deleted.status === 200 && deleted.body.result?.id === id
494
+ && (await call({ m: 'GET', p: `/zones/${ZONE}/workers/routes/${id}` })).status === 404;
495
+ })],
496
+ ['GET /accounts/{account_id}/r2/buckets', () => withRoot(async (call) => {
497
+ await seed(call);
498
+ await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'launch-artifacts' } });
499
+ await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'launch-logs' } });
500
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/r2/buckets` });
501
+ const filtered = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/r2/buckets?name_contains=logs` });
502
+ const after = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/r2/buckets?start_after=launch-artifacts` });
503
+ return listed.status === 200
504
+ && listed.body.result?.buckets?.map((item) => item.name).join(',') === 'launch-artifacts,launch-logs'
505
+ && filtered.body.result?.buckets?.length === 1
506
+ && after.body.result?.buckets?.[0]?.name === 'launch-logs';
507
+ })],
508
+ ['POST /accounts/{account_id}/r2/buckets', () => withRoot(async (call) => {
509
+ await seed(call);
510
+ const invalid = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'UPPER_CASE' } });
511
+ const created = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'launch-artifacts', locationHint: 'wnam', storageClass: 'Standard' } });
512
+ const duplicate = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'launch-artifacts' } });
513
+ const value = created.body.result;
514
+ return invalid.status === 400 && created.status === 200
515
+ && value?.name === 'launch-artifacts' && value?.location === 'wnam' && value?.storage_class === 'Standard'
516
+ && typeof value?.creation_date === 'string'
517
+ && duplicate.status === 409 && duplicate.body.errors?.[0]?.code === 10004;
518
+ })],
519
+ ['GET /accounts/{account_id}/r2/buckets/{bucket_name}', () => withRoot(async (call) => {
520
+ await seed(call);
521
+ await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'launch-artifacts' } });
522
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/r2/buckets/launch-artifacts` });
523
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/r2/buckets/never-created` });
524
+ return fetched.status === 200 && fetched.body.result?.name === 'launch-artifacts'
525
+ && missing.status === 404 && missing.body.errors?.[0]?.code === 10006;
526
+ })],
527
+ ['DELETE /accounts/{account_id}/r2/buckets/{bucket_name}', () => withRoot(async (call) => {
528
+ await seed(call);
529
+ // Dirty-state cell: create → delete → recreate the same bucket name must yield a live bucket.
530
+ await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'launch-artifacts' } });
531
+ const deleted = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/r2/buckets/launch-artifacts` });
532
+ const gone = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/r2/buckets/launch-artifacts` });
533
+ const recreated = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/r2/buckets`, b: { name: 'launch-artifacts' } });
534
+ const alive = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/r2/buckets/launch-artifacts` });
535
+ // Pinned r2_v4_response REQUIRES a `result` member (unlike the queue delete envelope).
536
+ return deleted.status === 200 && Object.hasOwn(deleted.body, 'result')
537
+ && gone.status === 404 && recreated.status === 200
538
+ && alive.status === 200 && alive.body.result?.name === 'launch-artifacts';
539
+ })],
540
+ ['GET /accounts/{account_id}/hyperdrive/configs', () => withRoot(async (call) => {
541
+ await seed(call);
542
+ const id = await seedHyperdrive(call);
543
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/hyperdrive/configs` });
544
+ const value = listed.body.result?.[0];
545
+ return listed.status === 200 && value?.id === id && value?.origin?.host === 'db.internal.test'
546
+ && !Object.hasOwn(value?.origin ?? {}, 'password')
547
+ && listed.body.result_info?.total_count === 1;
548
+ })],
549
+ ['POST /accounts/{account_id}/hyperdrive/configs', () => withRoot(async (call) => {
550
+ await seed(call);
551
+ const invalid = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/hyperdrive/configs`, b: { name: 'bad', origin: { scheme: 'postgres', database: 'app', user: 'u', password: 'p', host: 'db.test' } } });
552
+ const created = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/hyperdrive/configs`, b: { name: 'cert-hd', origin: HD_ORIGIN, caching: { disabled: false }, origin_connection_limit: 25 } });
553
+ const value = created.body.result;
554
+ // The origin connection is recorded as configuration — the password is writeOnly in the
555
+ // vendor schema and must never be echoed; the origin is never dialed.
556
+ return invalid.status === 400 && created.status === 200
557
+ && /^[0-9a-f]{32}$/.test(String(value?.id)) && value?.origin?.port === 5432
558
+ && !Object.hasOwn(value?.origin ?? {}, 'password')
559
+ && value?.caching?.disabled === false && value?.origin_connection_limit === 25;
560
+ })],
561
+ ['GET /accounts/{account_id}/hyperdrive/configs/{hyperdrive_id}', () => withRoot(async (call) => {
562
+ await seed(call);
563
+ const id = await seedHyperdrive(call);
564
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}` });
565
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${'f'.repeat(32)}` });
566
+ return fetched.status === 200 && fetched.body.result?.name === 'cert-hd' && missing.status === 404;
567
+ })],
568
+ ['PUT /accounts/{account_id}/hyperdrive/configs/{hyperdrive_id}', () => withRoot(async (call) => {
569
+ await seed(call);
570
+ const id = await seedHyperdrive(call);
571
+ const invalid = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}`, b: { name: 'renamed' } });
572
+ const replaced = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}`, b: { name: 'renamed', origin: { ...HD_ORIGIN, host: 'db2.internal.test' } } });
573
+ const value = replaced.body.result;
574
+ return invalid.status === 400 && replaced.status === 200
575
+ && value?.name === 'renamed' && value?.origin?.host === 'db2.internal.test'
576
+ && !Object.hasOwn(value ?? {}, 'caching');
577
+ })],
578
+ ['PATCH /accounts/{account_id}/hyperdrive/configs/{hyperdrive_id}', () => withRoot(async (call) => {
579
+ await seed(call);
580
+ const id = await seedHyperdrive(call);
581
+ const patched = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}`, b: { caching: { disabled: true } } });
582
+ const value = patched.body.result;
583
+ // The vendor's edit-origin is a TYPED PARTIAL: a {host,port}-only PATCH must be accepted and
584
+ // MERGED over the existing origin (scheme/database/user preserved), not rejected (finding-4).
585
+ const partialOrigin = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}`, b: { origin: { host: 'db2.internal.test', port: 5433 } } });
586
+ const merged = partialOrigin.body.result?.origin;
587
+ // An unmodeled caching key must still be rejected, not recorded-and-echoed.
588
+ const badCaching = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}`, b: { caching: { bogus: 1 } } });
589
+ const badOrigin = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}`, b: { origin: { scheme: 'oracle' } } });
590
+ // A partial PATCH must not merge into an INCOHERENT origin the create path could never make:
591
+ // adding a `port` to an Access origin is rejected (round-two N1).
592
+ const access = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/hyperdrive/configs`, b: {
593
+ name: 'access-hd',
594
+ origin: { scheme: 'postgres', database: 'app', user: 'u', password: 'p', access_client_id: 'cid', access_client_secret: 'csec', host: 'access.test' },
595
+ } });
596
+ const accessID = access.body.result?.id;
597
+ const incoherent = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${accessID}`, b: { origin: { port: 5432 } } });
598
+ return patched.status === 200 && value?.name === 'cert-hd' && value?.caching?.disabled === true
599
+ && value?.origin?.host === 'db.internal.test'
600
+ && partialOrigin.status === 200 && merged?.host === 'db2.internal.test' && merged?.port === 5433
601
+ && merged?.scheme === 'postgres' && merged?.database === 'app'
602
+ && badCaching.status === 400 && badOrigin.status === 400
603
+ && access.status === 200 && incoherent.status === 400;
604
+ })],
605
+ ['DELETE /accounts/{account_id}/hyperdrive/configs/{hyperdrive_id}', () => withRoot(async (call) => {
606
+ await seed(call);
607
+ const id = await seedHyperdrive(call);
608
+ const deleted = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}` });
609
+ return deleted.status === 200 && deleted.body.result === null
610
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/hyperdrive/configs/${id}` })).status === 404;
611
+ })],
612
+ ['GET /accounts/{account_id}/queues', () => withRoot(async (call) => {
613
+ await seed(call);
614
+ const id = await seedQueue(call);
615
+ await deployWorker(call, 'producer-worker', { main_module: 'worker.js', bindings: [{ type: 'queue', name: 'Q', queue_name: 'cert-queue' }] });
616
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues` });
617
+ const value = listed.body.result?.[0];
618
+ // Producer bindings recorded on a Worker upload surface as the queue's producers.
619
+ return listed.status === 200 && value?.queue_id === id && value?.queue_name === 'cert-queue'
620
+ && value?.producers?.[0]?.script === 'producer-worker' && value?.producers_total_count === 1;
621
+ })],
622
+ ['POST /accounts/{account_id}/queues', () => withRoot(async (call) => {
623
+ await seed(call);
624
+ const invalid = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues`, b: {} });
625
+ const created = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues`, b: { queue_name: 'cert-queue' } });
626
+ const duplicate = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues`, b: { queue_name: 'cert-queue' } });
627
+ const value = created.body.result;
628
+ return invalid.status === 400 && created.status === 200
629
+ && /^[0-9a-f]{32}$/.test(String(value?.queue_id)) && value?.queue_name === 'cert-queue'
630
+ && value?.consumers_total_count === 0 && duplicate.status === 400;
631
+ })],
632
+ ['GET /accounts/{account_id}/queues/{queue_id}', () => withRoot(async (call) => {
633
+ await seed(call);
634
+ const id = await seedQueue(call);
635
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}` });
636
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${'f'.repeat(32)}` });
637
+ return fetched.status === 200 && fetched.body.result?.queue_name === 'cert-queue' && missing.status === 404;
638
+ })],
639
+ ['DELETE /accounts/{account_id}/queues/{queue_id}', () => withRoot(async (call) => {
640
+ await seed(call);
641
+ await deployWorker(call);
642
+ const id = await seedQueue(call);
643
+ const consumer = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'worker', script_name: 'cert-worker' } });
644
+ const deleted = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/queues/${id}` });
645
+ const gone = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}` });
646
+ const consumerGone = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumer.body.result?.consumer_id}` });
647
+ // Pinned QueueDeleteResponse envelope carries no `result` member (finding-8).
648
+ return deleted.status === 200 && deleted.body.success === true
649
+ && !Object.hasOwn(deleted.body, 'result')
650
+ && gone.status === 404 && consumerGone.status === 404;
651
+ })],
652
+ ['GET /accounts/{account_id}/queues/{queue_id}/consumers', () => withRoot(async (call) => {
653
+ await seed(call);
654
+ await deployWorker(call);
655
+ const id = await seedQueue(call);
656
+ await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'worker', script_name: 'cert-worker' } });
657
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}/consumers` });
658
+ const value = listed.body.result?.[0];
659
+ return listed.status === 200 && value?.type === 'worker' && value?.script_name === 'cert-worker'
660
+ && value?.queue_name === 'cert-queue';
661
+ })],
662
+ ['POST /accounts/{account_id}/queues/{queue_id}/consumers', () => withRoot(async (call) => {
663
+ await seed(call);
664
+ await deployWorker(call);
665
+ const id = await seedQueue(call);
666
+ const badType = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'lambda' } });
667
+ const noScript = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'worker', script_name: 'never-uploaded' } });
668
+ const worker = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'worker', script_name: 'cert-worker', settings: { batch_size: 10, max_retries: 3 } } });
669
+ // A queue has at most one consumer — a second POST must be rejected until the first is gone.
670
+ const second = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'http_pull' } });
671
+ await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${worker.body.result?.consumer_id}` });
672
+ // The vendor documents max_concurrency:null ("opt into the platform maximum") — must be accepted.
673
+ const pull = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'http_pull', settings: { visibility_timeout_ms: 6000 } } });
674
+ return badType.status === 400 && noScript.status === 400
675
+ && worker.status === 200 && worker.body.result?.settings?.batch_size === 10
676
+ && second.status === 400
677
+ && pull.status === 200 && pull.body.result?.type === 'http_pull'
678
+ && !Object.hasOwn(pull.body.result ?? {}, 'script_name');
679
+ })],
680
+ ['GET /accounts/{account_id}/queues/{queue_id}/consumers/{consumer_id}', () => withRoot(async (call) => {
681
+ await seed(call);
682
+ await deployWorker(call);
683
+ const id = await seedQueue(call);
684
+ const created = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'worker', script_name: 'cert-worker' } });
685
+ const consumerID = created.body.result?.consumer_id;
686
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumerID}` });
687
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${'f'.repeat(32)}` });
688
+ return fetched.status === 200 && fetched.body.result?.consumer_id === consumerID && missing.status === 404;
689
+ })],
690
+ ['PUT /accounts/{account_id}/queues/{queue_id}/consumers/{consumer_id}', () => withRoot(async (call) => {
691
+ await seed(call);
692
+ await deployWorker(call);
693
+ const id = await seedQueue(call);
694
+ await seedQueue(call, 'dlq'); // a dead_letter_queue must reference a real queue on the account
695
+ const created = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'worker', script_name: 'cert-worker' } });
696
+ const consumerID = created.body.result?.consumer_id;
697
+ const badSetting = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumerID}`, b: { type: 'http_pull', settings: { max_concurrency: 2 } } });
698
+ const ghostDlq = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumerID}`, b: { type: 'worker', script_name: 'cert-worker', dead_letter_queue: 'nope-queue' } });
699
+ const badNull = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumerID}`, b: { type: 'worker', script_name: 'cert-worker', settings: { batch_size: null } } });
700
+ // The vendor's recommended max_concurrency:null ("platform maximum") must be accepted;
701
+ // batch_size:null must NOT (only max_concurrency is nullable).
702
+ const updated = await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumerID}`, b: { type: 'worker', script_name: 'cert-worker', dead_letter_queue: 'dlq', settings: { batch_size: 25, max_concurrency: null } } });
703
+ const value = updated.body.result;
704
+ // max_concurrency is a worker-consumer setting; the http_pull union does not carry it.
705
+ return badSetting.status === 400 && ghostDlq.status === 400 && badNull.status === 400 && updated.status === 200
706
+ && value?.dead_letter_queue === 'dlq' && value?.settings?.batch_size === 25
707
+ && value?.settings?.max_concurrency === null;
708
+ })],
709
+ ['DELETE /accounts/{account_id}/queues/{queue_id}/consumers/{consumer_id}', () => withRoot(async (call) => {
710
+ await seed(call);
711
+ await deployWorker(call);
712
+ const id = await seedQueue(call);
713
+ const created = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/queues/${id}/consumers`, b: { type: 'worker', script_name: 'cert-worker' } });
714
+ const consumerID = created.body.result?.consumer_id;
715
+ const deleted = await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumerID}` });
716
+ // Pinned ConsumerDeleteResponse envelope carries no `result` member (finding-8).
717
+ return deleted.status === 200 && deleted.body.success === true
718
+ && !Object.hasOwn(deleted.body, 'result')
719
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}/consumers/${consumerID}` })).status === 404
720
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/queues/${id}` })).status === 200;
721
+ })],
722
+ ]);
723
+ // Account members: the built-in roles, a member added with role ids and removed, and a bootstrapped member's user
724
+ // two-factor state (Cloudflare's record of the person, which no account API sets).
725
+ const memberSeed = async (call) => {
726
+ await seed(call);
727
+ await call({ m: 'POST', p: '/twin/bootstrap', b: { members: [{ account_id: ACCOUNT, email: 'ana@example.test', roles: ['Super Administrator - All Privileges'], two_factor: true }] } });
728
+ return (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/roles` })).body.result;
729
+ };
730
+ const memberVerifiers = new Map([
731
+ ['GET /accounts/{account_id}/roles', () => withRoot(async (call) => { const roles = await memberSeed(call); return roles.some((r) => r.name === 'Administrator') && roles.every((r) => /^[a-f0-9]{32}$/.test(r.id)); })],
732
+ ['GET /accounts/{account_id}/members', () => withRoot(async (call) => {
733
+ await memberSeed(call);
734
+ const list = (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/members` })).body.result;
735
+ return list.length === 1 && list[0].user.email === 'ana@example.test' && list[0].user.two_factor_authentication_enabled === true && list[0].status === 'accepted' && list[0].roles[0].name === 'Super Administrator - All Privileges';
736
+ })],
737
+ ['POST /accounts/{account_id}/members', () => withRoot(async (call) => {
738
+ const roles = await memberSeed(call);
739
+ const admin = roles.find((r) => r.name === 'Administrator').id;
740
+ const added = (await call({ m: 'POST', p: `/accounts/${ACCOUNT}/members`, b: { email: 'ben@example.test', roles: [admin] } })).body;
741
+ const bad = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/members`, b: { email: 'carol@example.test', roles: ['nope'] } });
742
+ const dup = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/members`, b: { email: 'ben@example.test', roles: [admin] } });
743
+ return added.success === true && added.result.status === 'pending' && added.result.user.two_factor_authentication_enabled === false && bad.status === 400 && dup.status === 400;
744
+ })],
745
+ ['GET /accounts/{account_id}/members/{member_id}', () => withRoot(async (call) => {
746
+ await memberSeed(call);
747
+ const id = (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/members` })).body.result[0].id;
748
+ return (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/members/${id}` })).body.result.email === 'ana@example.test'
749
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/members/${'f'.repeat(32)}` })).status === 404;
750
+ })],
751
+ ['DELETE /accounts/{account_id}/members/{member_id}', () => withRoot(async (call) => {
752
+ await memberSeed(call);
753
+ const id = (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/members` })).body.result[0].id;
754
+ await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/members/${id}` });
755
+ return (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/members` })).body.result.length === 0;
756
+ })],
757
+ ]);
758
+ // The account audit log: a user's API token created, a zone setting changed with it and a member removed are logged
759
+ // newest first; the token and the setting are attributed to that user (the setting with its old and new value), the
760
+ // removal (a token no one owns) to no one.
761
+ operationVerifiers.set('GET /accounts/{account_id}/audit_logs', () => withRoot(async (call) => {
762
+ await memberSeed(call);
763
+ const token = (await call({ m: 'POST', p: '/twin/users/ana@example.test/tokens' })).body.result.token;
764
+ await call({ m: 'PATCH', p: `/zones/${ZONE}/settings/always_use_https`, b: { value: 'on' }, bearer: token });
765
+ const id = (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/members` })).body.result[0].id;
766
+ await call({ m: 'DELETE', p: `/accounts/${ACCOUNT}/members/${id}` });
767
+ const log = (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/audit_logs` })).body.result;
768
+ return log.length === 3 && log[2].action.type === 'create' && log[2].resource.type === 'token' && log[2].actor.email === 'ana@example.test'
769
+ && log[1].actor.email === 'ana@example.test' && log[1].resource.type === 'zone_setting' && log[1].oldValue === 'off' && log[1].newValue === 'on'
770
+ && log[0].action.type === 'delete' && log[0].actor.email === ''
771
+ && (await call({ m: 'GET', p: `/accounts/${ACCOUNT}/audit_logs?before=2000-01-01T00:00:00Z` })).body.result.length === 0;
772
+ }));
773
+ for (const [key, verify] of memberVerifiers)
774
+ operationVerifiers.set(key, verify);
775
+ for (const [key, verify] of provisioningVerifiers)
776
+ operationVerifiers.set(key, verify);
777
+ // The Workers deploy plane an unmodified `wrangler deploy` drives beyond the script upload:
778
+ // static-assets upload sessions and bucketed uploads, versions, deployments, script settings,
779
+ // and secrets listing. Same discipline: fresh root, response VALUES, and the negative path.
780
+ const ASSET_A = 'a1'.repeat(16);
781
+ const ASSET_B = 'b2'.repeat(16);
782
+ const ASSET_MANIFEST = { '/index.html': { hash: ASSET_A, size: 5 }, '/app.js': { hash: ASSET_B, size: 3 } };
783
+ function tokenPayload(jwt) {
784
+ try {
785
+ return JSON.parse(Buffer.from(String(jwt).split('.')[1] ?? '', 'base64url').toString('utf8'));
786
+ }
787
+ catch {
788
+ return {};
789
+ }
790
+ }
791
+ /** One bulk asset upload exactly as wrangler sends it: parts named by hash, base64 content. */
792
+ function assetUpload(jwt, files) {
793
+ const boundary = 'twin-asset-boundary';
794
+ const parts = Object.entries(files).map(([hash, file]) => `--${boundary}\r\nContent-Disposition: form-data; name="${hash}"; filename="${hash}"\r\nContent-Type: ${file.type}\r\n\r\n${Buffer.from(file.content).toString('base64')}\r\n`);
795
+ return { m: 'POST', p: `/accounts/${ACCOUNT}/workers/assets/upload?base64=true`, raw: `${parts.join('')}--${boundary}--\r\n`, ct: `multipart/form-data; boundary=${boundary}`, bearer: jwt };
796
+ }
797
+ /** Session → upload every bucket → the completion token (the whole wrangler asset sync). */
798
+ async function syncAssets(call, name = 'cert-worker') {
799
+ const session = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/${name}/assets-upload-session`, b: { manifest: ASSET_MANIFEST } });
800
+ const jwt = String(session.body.result?.jwt ?? '');
801
+ if ((session.body.result?.buckets ?? []).length === 0)
802
+ return jwt;
803
+ const done = await call(assetUpload(jwt, { [ASSET_A]: { type: 'text/html', content: 'hello' }, [ASSET_B]: { type: 'text/javascript', content: '1+1' } }));
804
+ return String(done.body.result?.jwt ?? '');
805
+ }
806
+ async function deployVersion(call, name = 'cert-worker', metadata = { main_module: 'worker.js' }, body = 'export default {};') {
807
+ const upload = moduleUpload(metadata, { 'worker.js': body });
808
+ return call({ ...upload, m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/${name}/versions` });
809
+ }
810
+ const deployPlaneVerifiers = new Map([
811
+ ['POST /accounts/{account_id}/workers/scripts/{script_name}/assets-upload-session', () => withRoot(async (call) => {
812
+ await seed(call);
813
+ const invalid = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/assets-upload-session`, b: { manifest: { 'no-slash': { hash: ASSET_A, size: 1 } } } });
814
+ const first = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/assets-upload-session`, b: { manifest: ASSET_MANIFEST } });
815
+ const buckets = (first.body.result?.buckets ?? []).flat().sort().join(',');
816
+ await syncAssets(call);
817
+ // Once the account holds both hashes, a new session names no buckets and its jwt already completes.
818
+ const again = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/assets-upload-session`, b: { manifest: ASSET_MANIFEST } });
819
+ return invalid.status === 400 && first.status === 200
820
+ && buckets === [ASSET_A, ASSET_B].sort().join(',') && tokenPayload(first.body.result?.jwt).purpose === 'upload'
821
+ && again.status === 200 && again.body.result?.buckets?.length === 0
822
+ && tokenPayload(again.body.result?.jwt).purpose === 'completion';
823
+ })],
824
+ ['POST /accounts/{account_id}/workers/assets/upload', () => withRoot(async (call) => {
825
+ await seed(call);
826
+ const session = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/assets-upload-session`, b: { manifest: ASSET_MANIFEST } });
827
+ const jwt = String(session.body.result?.jwt);
828
+ // The API token is not the session token; a size that disagrees with the manifest is refused.
829
+ const apiToken = await call({ ...assetUpload(jwt, { [ASSET_A]: { type: 'text/html', content: 'hello' } }), bearer: undefined });
830
+ const wrongSize = await call(assetUpload(jwt, { [ASSET_A]: { type: 'text/html', content: 'hello world' } }));
831
+ const partial = await call(assetUpload(jwt, { [ASSET_A]: { type: 'text/html', content: 'hello' } }));
832
+ const complete = await call(assetUpload(jwt, { [ASSET_B]: { type: 'text/javascript', content: '1+1' } }));
833
+ const completion = String(complete.body.result?.jwt ?? '');
834
+ // The completion token is redeemed by the script upload; an assets binding with no assets is refused.
835
+ const noAssets = await deployWorker(call, 'cert-worker', { main_module: 'worker.js', bindings: [{ type: 'assets', name: 'ASSETS' }] });
836
+ const withAssets = await deployWorker(call, 'cert-worker', { main_module: 'worker.js', bindings: [{ type: 'assets', name: 'ASSETS' }], assets: { jwt: completion, config: { run_worker_first: true } } });
837
+ return apiToken.status === 401 && wrongSize.status === 400
838
+ && partial.status === 200 && !Object.hasOwn(partial.body.result ?? {}, 'jwt')
839
+ && complete.status === 200 && tokenPayload(completion).purpose === 'completion'
840
+ && noAssets.status === 400 && withAssets.status === 200 && withAssets.body.result?.has_assets === true;
841
+ })],
842
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/versions', () => withRoot(async (call) => {
843
+ await seed(call);
844
+ await deployWorker(call);
845
+ const second = await deployWorker(call, 'cert-worker', { main_module: 'worker.js', compatibility_date: '2026-09-01' });
846
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/versions` });
847
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/never-uploaded/versions` });
848
+ const items = listed.body.result?.items ?? [];
849
+ return listed.status === 200 && items.length === 2 && items[0]?.number === 2 && items[1]?.number === 1
850
+ && items[0]?.id === second.body.result?.deployment_id
851
+ && items[0]?.resources?.script_runtime?.compatibility_date === '2026-09-01'
852
+ && missing.status === 404 && missing.body.errors?.[0]?.code === 10007;
853
+ })],
854
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/versions/{version_id}', () => withRoot(async (call) => {
855
+ await seed(call);
856
+ const uploaded = await deployWorker(call, 'cert-worker', { main_module: 'worker.js', bindings: [{ type: 'secret_text', name: 'API_KEY', text: 'shh' }] });
857
+ const id = uploaded.body.result?.deployment_id;
858
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/versions/${id}` });
859
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/versions/${'0'.repeat(8)}-0000-4000-a000-${'0'.repeat(12)}` });
860
+ const value = fetched.body.result;
861
+ return fetched.status === 200 && value?.id === id && value?.number === 1
862
+ && value?.resources?.script?.etag === uploaded.body.result?.etag
863
+ && value?.resources?.bindings?.[0]?.name === 'API_KEY' && !Object.hasOwn(value?.resources?.bindings?.[0] ?? {}, 'text')
864
+ && missing.status === 404;
865
+ })],
866
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/deployments', () => withRoot(async (call) => {
867
+ await seed(call);
868
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/deployments` });
869
+ const uploaded = await deployWorker(call);
870
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/deployments` });
871
+ const latest = listed.body.result?.deployments?.[0];
872
+ return missing.status === 404 && missing.body.errors?.[0]?.code === 10007
873
+ && listed.status === 200 && latest?.strategy === 'percentage'
874
+ && latest?.versions?.[0]?.version_id === uploaded.body.result?.deployment_id && latest?.versions?.[0]?.percentage === 100;
875
+ })],
876
+ ['POST /accounts/{account_id}/workers/scripts/{script_name}/deployments', () => withRoot(async (call) => {
877
+ await seed(call);
878
+ const first = await deployWorker(call);
879
+ // A version upload does not change the live Worker until a deployment routes traffic to it.
880
+ const version = await deployVersion(call, 'cert-worker', { main_module: 'worker.js' }, 'export default { v: 2 };');
881
+ const versionID = version.body.result?.id;
882
+ const before = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/settings` });
883
+ const badSum = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/deployments`, b: { strategy: 'percentage', versions: [{ version_id: versionID, percentage: 60 }, { version_id: first.body.result?.deployment_id, percentage: 50 }] } });
884
+ const unknown = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/deployments`, b: { strategy: 'percentage', versions: [{ version_id: 'not-a-version', percentage: 100 }] } });
885
+ const deployed = await call({ m: 'POST', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/deployments`, b: { strategy: 'percentage', versions: [{ version_id: versionID, percentage: 100 }], annotations: { 'workers/message': 'ship v2' } } });
886
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/deployments` });
887
+ const download = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker` });
888
+ return version.status === 200 && before.status === 200 && badSum.status === 400 && unknown.status === 400
889
+ && deployed.status === 200 && deployed.body.result?.annotations?.['workers/message'] === 'ship v2'
890
+ && listed.body.result?.deployments?.[0]?.id === deployed.body.result?.id
891
+ && String(download.body).includes('v: 2');
892
+ })],
893
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/script-settings', () => withRoot(async (call) => {
894
+ await seed(call);
895
+ await deployWorker(call, 'cert-worker', { main_module: 'worker.js', logpush: true, tags: ['launch'] });
896
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/script-settings` });
897
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/never-uploaded/script-settings` });
898
+ const value = fetched.body.result;
899
+ return fetched.status === 200 && value?.logpush === true && value?.tags?.[0] === 'launch' && missing.status === 404;
900
+ })],
901
+ ['PATCH /accounts/{account_id}/workers/scripts/{script_name}/script-settings', () => withRoot(async (call) => {
902
+ await seed(call);
903
+ await deployWorker(call);
904
+ const invalid = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/script-settings`, b: { logpush: 'yes' } });
905
+ const patched = await call({ m: 'PATCH', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/script-settings`, b: { observability: { enabled: true, head_sampling_rate: 0.5 }, tags: ['env:prod'] } });
906
+ const after = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/script-settings` });
907
+ const value = after.body.result;
908
+ return invalid.status === 400 && patched.status === 200
909
+ && value?.observability?.enabled === true && value?.observability?.head_sampling_rate === 0.5
910
+ && value?.tags?.[0] === 'env:prod' && value?.logpush === false;
911
+ })],
912
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/settings', () => withRoot(async (call) => {
913
+ await seed(call);
914
+ await deployWorker(call, 'cert-worker', { main_module: 'worker.js', compatibility_date: '2026-09-01', bindings: [
915
+ { type: 'plain_text', name: 'MODE', text: 'prod' }, { type: 'secret_text', name: 'API_KEY', text: 'shh' },
916
+ ] });
917
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/settings` });
918
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/never-uploaded/settings` });
919
+ const bindings = fetched.body.result?.bindings ?? [];
920
+ const secret = bindings.find((item) => item.name === 'API_KEY');
921
+ return fetched.status === 200 && fetched.body.result?.compatibility_date === '2026-09-01'
922
+ && bindings.find((item) => item.name === 'MODE')?.text === 'prod'
923
+ && secret?.type === 'secret_text' && !Object.hasOwn(secret ?? {}, 'text')
924
+ && missing.status === 404 && missing.body.errors?.[0]?.code === 10007;
925
+ })],
926
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/secrets', () => withRoot(async (call) => {
927
+ await seed(call);
928
+ await deployWorker(call, 'cert-worker', { main_module: 'worker.js', bindings: [
929
+ { type: 'plain_text', name: 'MODE', text: 'prod' }, { type: 'secret_text', name: 'API_KEY', text: 'shh' },
930
+ ] });
931
+ const listed = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/secrets` });
932
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/never-uploaded/secrets` });
933
+ const result = listed.body.result ?? [];
934
+ return listed.status === 200 && result.length === 1 && result[0]?.name === 'API_KEY' && result[0]?.type === 'secret_text'
935
+ && !Object.hasOwn(result[0] ?? {}, 'text')
936
+ && missing.status === 404 && missing.body.errors?.[0]?.code === 10007;
937
+ })],
938
+ ['GET /accounts/{account_id}/workers/scripts/{script_name}/secrets/{secret_name}', () => withRoot(async (call) => {
939
+ await seed(call);
940
+ await deployWorker(call, 'cert-worker', { main_module: 'worker.js', bindings: [{ type: 'secret_text', name: 'API_KEY', text: 'shh' }] });
941
+ const fetched = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/secrets/API_KEY` });
942
+ const missing = await call({ m: 'GET', p: `/accounts/${ACCOUNT}/workers/scripts/cert-worker/secrets/NOPE` });
943
+ return fetched.status === 200 && fetched.body.result?.name === 'API_KEY'
944
+ && !Object.hasOwn(fetched.body.result ?? {}, 'text') && missing.status === 404;
945
+ })],
946
+ ]);
947
+ for (const [key, verify] of deployPlaneVerifiers)
948
+ operationVerifiers.set(key, verify);
949
+ // These official operations contain broad unions/nested schemas. The twin deliberately
950
+ // supports the certification-needed slices (ingress; CNAME/A/CAA records; the multipart
951
+ // module upload with the deploy-critical binding kinds and Durable Object migrations), but
952
+ // each whole vendor operation stays todo until every official variant is schema-faithful.
953
+ const INCOMPLETE_OPERATION_UNIONS = new Set([
954
+ 'PUT /accounts/{account_id}/cfd_tunnel/{tunnel_id}/configurations',
955
+ 'POST /zones/{zone_id}/dns_records',
956
+ 'PUT /zones/{zone_id}/dns_records/{dns_record_id}',
957
+ 'PATCH /zones/{zone_id}/dns_records/{dns_record_id}',
958
+ // Served and exercised by every worker-seeding verify above, but the full multipart metadata
959
+ // union (38 binding kinds, assets, placement, limits, observability) is far broader than the
960
+ // implemented deploy slice — the whole vendor operation honestly stays todo.
961
+ 'PUT /accounts/{account_id}/workers/scripts/{script_name}',
962
+ // The versions upload carries the same multipart metadata union as the script PUT above.
963
+ 'POST /accounts/{account_id}/workers/scripts/{script_name}/versions',
964
+ ]);
965
+ const operationCapabilities = CLOUDFLARE_OPENAPI_OPERATIONS.map((operation) => {
966
+ const operationKey = `${operation.method} ${operation.path}`;
967
+ const verify = INCOMPLETE_OPERATION_UNIONS.has(operationKey) ? undefined : operationVerifiers.get(operationKey);
968
+ return {
969
+ id: operation.id,
970
+ area: operation.area,
971
+ title: `${operation.method} ${operation.path} — ${operation.summary}`,
972
+ dimension: 'api',
973
+ tier: operation.tier,
974
+ expected: verify ? 'done' : 'todo',
975
+ ...(verify ? { verify } : {}),
976
+ };
977
+ });
978
+ const doneConnector = (id, title, tier, verify) => ({
979
+ id, area: 'connector', title, dimension: 'connector', tier, expected: 'done', verify,
980
+ });
981
+ const connectorCapabilities = [
982
+ doneConnector('cloudflare.connector.pull_complete_pagination', 'Pull walks every result_info page across the account graph', 'core', async () => {
983
+ const calls = [];
984
+ const execute = async (_method, path) => {
985
+ calls.push(path);
986
+ const page = Number(new URL(path, 'https://x.invalid').searchParams.get('page') ?? 1);
987
+ if (path.startsWith('/accounts?'))
988
+ return { status: 200, body: { success: true, result: [{ id: page === 1 ? ACCOUNT : 'c'.repeat(32), name: `A${page}` }], result_info: { page, total_pages: 2 } } };
989
+ if (path.startsWith('/zones?'))
990
+ return { status: 200, body: { success: true, result: [{ id: ZONE, name: 'example.test', account: { id: ACCOUNT } }], result_info: { page, total_pages: 1 } } };
991
+ return { status: 200, body: { success: true, result: [], result_info: { page, total_pages: 1 } } };
992
+ };
993
+ const result = await pullCloudflareState(execute);
994
+ return result.length === 3 && calls.includes('/accounts?per_page=50&page=2');
995
+ }),
996
+ doneConnector('cloudflare.connector.pull_idempotent', 'Repeated identical pull is idempotent in the projection', 'core', () => withRoot(async (_call, root) => {
997
+ const execute = async (_method, path) => ({ status: 200, body: { success: true, result: path.startsWith('/accounts?') ? [{ id: ACCOUNT, name: 'Acme' }] : [] } });
998
+ const first = await syncCloudflareFromReal(execute, { root, occurredAt: AT });
999
+ const second = await syncCloudflareFromReal(execute, { root, occurredAt: AT });
1000
+ return first.deltasAppended === 1 && second.deltasAppended === 0;
1001
+ })),
1002
+ doneConnector('cloudflare.connector.pull_refuses_invalid_envelope', 'Pull requires a valid success:true envelope and refuses transport failures', 'core', async () => {
1003
+ for (const response of [{ status: 200, body: {} }, { status: 403, body: { success: false, errors: [{ message: 'denied' }] } }]) {
1004
+ try {
1005
+ await pullCloudflareState(async () => response);
1006
+ return false;
1007
+ }
1008
+ catch (error) {
1009
+ if (!String(error).includes('refused'))
1010
+ return false;
1011
+ }
1012
+ }
1013
+ return true;
1014
+ }),
1015
+ doneConnector('cloudflare.connector.pull_deletion_convergence', 'A complete later pull tombstones vendor-observed resources that disappeared', 'core', () => withRoot(async (_call, root) => {
1016
+ let present = true;
1017
+ const execute = async (_method, path) => ({ status: 200, body: {
1018
+ success: true,
1019
+ result: path.startsWith('/accounts?') && present ? [{ id: ACCOUNT, name: 'Acme' }] : [],
1020
+ result_info: { page: 1, total_pages: 1 },
1021
+ } });
1022
+ await syncCloudflareFromReal(execute, { root, occurredAt: AT });
1023
+ present = false;
1024
+ await syncCloudflareFromReal(execute, { root, occurredAt: '2026-08-21T00:00:01.000Z' });
1025
+ return projectResources('cloudflare', root).find((resource) => resource.id === ACCOUNT)?.deleted === true;
1026
+ })),
1027
+ doneConnector('cloudflare.connector.pull_incomplete_inventory_safe', 'A metadata-free partial inventory cannot tombstone unseen vendor resources', 'core', () => withRoot(async (_call, root) => {
1028
+ let includeSecond = true;
1029
+ const secondID = 'c'.repeat(32);
1030
+ const execute = async (_method, path) => ({ status: 200, body: {
1031
+ success: true,
1032
+ result: path.startsWith('/accounts?') ? [{ id: ACCOUNT, name: 'A' }, ...(includeSecond ? [{ id: secondID, name: 'B' }] : [])] : [],
1033
+ } });
1034
+ await syncCloudflareFromReal(execute, { root, occurredAt: AT });
1035
+ includeSecond = false;
1036
+ await syncCloudflareFromReal(execute, { root, occurredAt: '2026-08-21T00:00:01.000Z' });
1037
+ // the row is still there and still live: an inventory that never said it was complete cannot erase it
1038
+ const unseen = projectResources('cloudflare', root).find((resource) => resource.id === secondID);
1039
+ return unseen !== undefined && unseen.deleted !== true;
1040
+ })),
1041
+ doneConnector('cloudflare.connector.pull_tunnel_deletion_timestamp', 'Complete pull tunnel tombstones expose the observation timestamp', 'common', () => withRoot(async (_call, root) => {
1042
+ let present = true;
1043
+ const execute = async (_method, path) => {
1044
+ if (path.endsWith('/configurations'))
1045
+ return { status: 404, body: { success: false, result: null, errors: [] } };
1046
+ const result = path.startsWith('/accounts?') ? [{ id: ACCOUNT, name: 'A' }]
1047
+ : path.startsWith('/zones?') ? []
1048
+ : path.includes('/cfd_tunnel?') && present ? [{ id: VENDOR_TUNNEL, account_tag: ACCOUNT, name: 't', config_src: 'cloudflare' }] : [];
1049
+ return { status: 200, body: { success: true, result, result_info: { page: 1, total_pages: 1 } } };
1050
+ };
1051
+ await syncCloudflareFromReal(execute, { root, occurredAt: AT });
1052
+ present = false;
1053
+ const deletedAt = '2026-08-21T00:00:01.000Z';
1054
+ await syncCloudflareFromReal(execute, { root, occurredAt: deletedAt });
1055
+ const value = projectResources('cloudflare', root).find((resource) => resource.id === VENDOR_TUNNEL);
1056
+ return value?.deleted === true && value.deleted_at === deletedAt;
1057
+ })),
1058
+ doneConnector('cloudflare.connector.mapper_schema_validation', 'Pull rejects malformed vendor fixtures before folding impossible identities', 'common', async () => {
1059
+ try {
1060
+ await pullCloudflareState(async () => ({ status: 200, body: { success: true, result: [{}] } }));
1061
+ return false;
1062
+ }
1063
+ catch (error) {
1064
+ return String(error).includes('id must be a nonempty string');
1065
+ }
1066
+ }),
1067
+ doneConnector('cloudflare.connector.configuration_identity', 'Pulled and locally-updated configuration converge on one account+tunnel identity', 'core', () => withRoot(async (call, root) => {
1068
+ await seed(call);
1069
+ await applyTwinWrite('cloudflare', { operation: 'tunnel.observe', subjectType: 'cloudflare_tunnel', subjectId: VENDOR_TUNNEL, fields: { account_id: ACCOUNT, name: 't', config_src: 'cloudflare', status: 'inactive', _deleted: false }, occurredAt: AT, actor: { kind: 'system' } }, root);
1070
+ await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/cfd_tunnel/${VENDOR_TUNNEL}/configurations`, b: { config: { ingress: [{ hostname: '*', service: 'http_status:503' }] } } });
1071
+ const execute = async (_method, path) => ({ status: 200, body: { success: true, result: path.startsWith('/accounts?') ? [{ id: ACCOUNT, name: 'Acme' }] : path.startsWith('/zones?') ? [] : path.includes('/cfd_tunnel?') ? [{ id: VENDOR_TUNNEL, account_tag: ACCOUNT, name: 't', config_src: 'cloudflare' }] : { account_id: ACCOUNT, tunnel_id: VENDOR_TUNNEL, config: { ingress: [{ hostname: '*', service: 'http_status:404' }] } } } });
1072
+ await syncCloudflareFromReal(execute, { root, occurredAt: '2026-08-21T00:00:01.000Z' });
1073
+ return projectResources('cloudflare', root).filter((value) => value.type === 'tunnel_configuration').length === 1;
1074
+ })),
1075
+ doneConnector('cloudflare.connector.pull_call_conservation', 'Pull fetches configuration only for remotely-managed tunnels', 'common', async () => {
1076
+ const paths = [];
1077
+ const execute = async (_method, path) => { paths.push(path); return { status: 200, body: { success: true, result: path.startsWith('/accounts?') ? [{ id: ACCOUNT, name: 'Acme' }] : path.includes('/cfd_tunnel?') ? [{ id: VENDOR_TUNNEL, name: 'local', config_src: 'local', account_tag: ACCOUNT }] : [] } }; };
1078
+ await pullCloudflareState(execute);
1079
+ return paths.length === 3 && !paths.some((path) => path.endsWith('/configurations'));
1080
+ }),
1081
+ doneConnector('cloudflare.connector.push', 'performCloudflareAction carries each entry across through the kernel\'s executor: the tunnel create answers Cloudflare\'s own id, and the configuration that follows is addressed to THAT id, not the local one (protocol 2)', 'core', () => withRoot(async (call, root) => {
1082
+ await seed(call);
1083
+ const localTunnel = await tunnel(call, 'push-me');
1084
+ await call({ m: 'PUT', p: `/accounts/${ACCOUNT}/cfd_tunnel/${localTunnel}/configurations`, b: { config: { ingress: [{ hostname: '*', service: 'http_status:404' }] } } });
1085
+ let failConfiguration = true;
1086
+ const { execute, seen } = vendor((method, _path, body) => {
1087
+ if (method === 'POST')
1088
+ return { status: 200, body: { success: true, result: { id: VENDOR_TUNNEL, account_tag: ACCOUNT, name: 'push-me', config_src: 'cloudflare' } } };
1089
+ if (failConfiguration)
1090
+ return { status: 500, body: { success: false, errors: [{ message: 'retry' }], result: null } };
1091
+ return { status: 200, body: { success: true, result: { account_id: ACCOUNT, tunnel_id: VENDOR_TUNNEL, config: body?.config } } };
1092
+ });
1093
+ // the vendor refuses the configuration once: the create is already across, and the dependent entry stops the batch
1094
+ const first = await performAll(root, execute);
1095
+ if (first.failed === null || !first.failed.includes('retry'))
1096
+ return false;
1097
+ if (first.adopted.get(`cloudflare_tunnel:${localTunnel}`) !== VENDOR_TUNNEL)
1098
+ return false;
1099
+ failConfiguration = false;
1100
+ const again = await performAll(root, execute, first.adopted, first.done);
1101
+ const configurations = seen.filter((request) => request.path.includes('/configurations'));
1102
+ return again.failed === null && configurations.length > 0
1103
+ && configurations.every((request) => request.path.includes(VENDOR_TUNNEL) && !request.path.includes(localTunnel));
1104
+ })),
1105
+ doneConnector('cloudflare.connector.push_confirmation_shape', 'A perform refuses an HTTP 200 body without success:true and the result identity Cloudflare owes — the entry stays undeployed rather than being marked across on a shapeless answer', 'core', () => withRoot(async (call, root) => {
1106
+ await seed(call);
1107
+ await tunnel(call, 'do-not-confirm');
1108
+ const before = deployableEntries('cloudflare', root).filter((entry) => entry.operation === 'tunnel.create').length;
1109
+ const shapeless = vendor(() => ({ status: 200, body: {} }));
1110
+ const refused = await performAll(root, shapeless.execute);
1111
+ if (refused.failed === null || before === 0)
1112
+ return false;
1113
+ // the same seam confirms a well-shaped answer, so the refusal was the SHAPE and not the seam
1114
+ const proper = vendor(() => ({ status: 200, body: { success: true, result: { id: VENDOR_TUNNEL } } }));
1115
+ const accepted = await performAll(root, proper.execute);
1116
+ return accepted.failed === null && accepted.adopted.size > 0;
1117
+ })),
1118
+ doneConnector('cloudflare.connector.push_dns_replace', 'A local DNS PUT stays a vendor PUT, addressed to the adopted record id, and omits the fields the replacement cleared', 'common', () => withRoot(async (call, root) => {
1119
+ await seed(call);
1120
+ const created = await call({ m: 'POST', p: `/zones/${ZONE}/dns_records`, b: {
1121
+ type: 'A', name: 'replace.example.test', ttl: 60, content: '192.0.2.1', private_routing: true,
1122
+ } });
1123
+ const localID = String(created.body.result?.id);
1124
+ const vendorID = 'e'.repeat(32);
1125
+ const first = vendor(() => ({ status: 200, body: { success: true, result: { id: vendorID } } }));
1126
+ const after = await performAll(root, first.execute);
1127
+ if (after.failed !== null || after.adopted.get(`dns_record:${localID}`) !== vendorID)
1128
+ return false;
1129
+ await call({ m: 'PUT', p: `/zones/${ZONE}/dns_records/${localID}`, b: {
1130
+ type: 'CAA', name: 'replace.example.test', ttl: 120, data: { flags: 0, tag: 'issue', value: 'pki.goog' },
1131
+ } });
1132
+ const second = vendor(() => ({ status: 200, body: { success: true, result: { id: vendorID } } }));
1133
+ const replay = await performAll(root, second.execute, after.adopted, after.done);
1134
+ const observed = second.seen.at(-1);
1135
+ return replay.failed === null && observed?.method === 'PUT' && observed.path.endsWith(`/dns_records/${vendorID}`)
1136
+ && observed.body?.type === 'CAA' && !Object.hasOwn(observed.body ?? {}, 'content')
1137
+ && !Object.hasOwn(observed.body ?? {}, 'private_routing');
1138
+ })),
1139
+ doneConnector('cloudflare.connector.budget_weights', 'Budget weights reads at 2 and mutations at 3', 'core', () => cloudflareCallWeight('GET', '/zones') === 2 && cloudflareCallWeight('POST', '/zones/x/dns_records') === 3),
1140
+ doneConnector('cloudflare.connector.budget_ceiling', 'Budget rejects calls above the conservative 60-unit minute', 'core', () => {
1141
+ const root = mkdtempSync(join(tmpdir(), 'cloudflare-budget-cap-'));
1142
+ try {
1143
+ const budget = new CloudflareBudget({ root, token: 'cap' });
1144
+ budget.recordCall(CLOUDFLARE_BUDGET_CEILING);
1145
+ try {
1146
+ budget.checkBudget(1);
1147
+ return false;
1148
+ }
1149
+ catch (error) {
1150
+ return error instanceof CloudflareBudgetError;
1151
+ }
1152
+ }
1153
+ finally {
1154
+ rmSync(root, { recursive: true, force: true });
1155
+ }
1156
+ }),
1157
+ ];
1158
+ export const CLOUDFLARE_CAPABILITIES = [...operationCapabilities, ...connectorCapabilities];
1159
+ export async function cloudflareCapabilities() {
1160
+ return checkCapabilities('cloudflare', CLOUDFLARE_CAPABILITIES);
1161
+ }