@caelo-cms/provisioning 0.11.19 → 0.11.21

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 (174) hide show
  1. package/dist/admin-internal-google.d.ts +13 -1
  2. package/dist/admin-internal-google.d.ts.map +1 -1
  3. package/dist/admin-internal-google.js +47 -0
  4. package/dist/admin-internal-google.js.map +1 -1
  5. package/dist/agent/command.d.ts +1 -1
  6. package/dist/agent-db.js +32 -0
  7. package/dist/aws-task-roles.d.ts +11 -0
  8. package/dist/aws-task-roles.d.ts.map +1 -1
  9. package/dist/aws-task-roles.js +19 -0
  10. package/dist/aws-task-roles.js.map +1 -1
  11. package/dist/azure-secrets.d.ts +22 -0
  12. package/dist/azure-secrets.d.ts.map +1 -0
  13. package/dist/azure-secrets.js +14 -0
  14. package/dist/azure-secrets.js.map +1 -0
  15. package/dist/caddy.d.ts +7 -0
  16. package/dist/caddy.d.ts.map +1 -1
  17. package/dist/caddy.js +22 -1
  18. package/dist/caddy.js.map +1 -1
  19. package/dist/cli-routing.d.ts.map +1 -1
  20. package/dist/cli-routing.js +2 -2
  21. package/dist/cli-routing.js.map +1 -1
  22. package/dist/cli.js +8 -0
  23. package/dist/cli.js.map +1 -1
  24. package/dist/converge-checkpoint.d.ts +6 -0
  25. package/dist/converge-checkpoint.d.ts.map +1 -1
  26. package/dist/dns/manual.d.ts +5 -1
  27. package/dist/dns/manual.d.ts.map +1 -1
  28. package/dist/dns/manual.js +2 -1
  29. package/dist/dns/manual.js.map +1 -1
  30. package/dist/gateway-armor.d.ts +24 -0
  31. package/dist/gateway-armor.d.ts.map +1 -0
  32. package/dist/gateway-armor.js +118 -0
  33. package/dist/gateway-armor.js.map +1 -0
  34. package/dist/gateway-edge.d.ts +128 -0
  35. package/dist/gateway-edge.d.ts.map +1 -0
  36. package/dist/gateway-edge.js +211 -0
  37. package/dist/gateway-edge.js.map +1 -0
  38. package/dist/infra-contract.d.ts +1 -1
  39. package/dist/infra-contract.d.ts.map +1 -1
  40. package/dist/infra-contract.js +21 -1
  41. package/dist/infra-contract.js.map +1 -1
  42. package/dist/install-job-runner.d.ts.map +1 -1
  43. package/dist/install-job-runner.js +4 -3
  44. package/dist/install-job-runner.js.map +1 -1
  45. package/dist/install-job.d.ts +25 -1
  46. package/dist/install-job.d.ts.map +1 -1
  47. package/dist/install-job.js +72 -3
  48. package/dist/install-job.js.map +1 -1
  49. package/dist/lifecycle.d.ts.map +1 -1
  50. package/dist/lifecycle.js +8 -1
  51. package/dist/lifecycle.js.map +1 -1
  52. package/dist/operator-access.d.ts +7 -2
  53. package/dist/operator-access.d.ts.map +1 -1
  54. package/dist/operator-access.js +37 -6
  55. package/dist/operator-access.js.map +1 -1
  56. package/dist/pool-budget-stack.d.ts +22 -0
  57. package/dist/pool-budget-stack.d.ts.map +1 -1
  58. package/dist/pool-budget-stack.js +22 -1
  59. package/dist/pool-budget-stack.js.map +1 -1
  60. package/dist/project-status.d.ts +95 -0
  61. package/dist/project-status.d.ts.map +1 -0
  62. package/dist/project-status.js +213 -0
  63. package/dist/project-status.js.map +1 -0
  64. package/dist/public-service-shape.d.ts +45 -0
  65. package/dist/public-service-shape.d.ts.map +1 -0
  66. package/dist/public-service-shape.js +90 -0
  67. package/dist/public-service-shape.js.map +1 -0
  68. package/dist/remote-mcp-edge.d.ts +1 -1
  69. package/dist/remote-mcp-edge.js +1 -1
  70. package/dist/remote-mcp.d.ts.map +1 -1
  71. package/dist/remote-mcp.js +12 -2
  72. package/dist/remote-mcp.js.map +1 -1
  73. package/dist/serverless-backend.d.ts +27 -0
  74. package/dist/serverless-backend.d.ts.map +1 -0
  75. package/dist/serverless-backend.js +30 -0
  76. package/dist/serverless-backend.js.map +1 -0
  77. package/dist/stack-contract.d.ts +6 -0
  78. package/dist/stack-contract.d.ts.map +1 -1
  79. package/dist/stack-contract.js +24 -0
  80. package/dist/stack-contract.js.map +1 -1
  81. package/dist/stack-converge.d.ts +13 -0
  82. package/dist/stack-converge.d.ts.map +1 -1
  83. package/dist/stack-converge.js +27 -0
  84. package/dist/stack-converge.js.map +1 -1
  85. package/dist/staging-gateway-setup.d.ts +5 -0
  86. package/dist/staging-gateway-setup.d.ts.map +1 -1
  87. package/dist/staging-gateway-setup.js +60 -19
  88. package/dist/staging-gateway-setup.js.map +1 -1
  89. package/dist/state-attach.d.ts +17 -0
  90. package/dist/state-attach.d.ts.map +1 -1
  91. package/dist/state-attach.js +27 -9
  92. package/dist/state-attach.js.map +1 -1
  93. package/dist/upgrade/app-roll.d.ts +5 -1
  94. package/dist/upgrade/app-roll.d.ts.map +1 -1
  95. package/dist/upgrade/app-roll.js +20 -3
  96. package/dist/upgrade/app-roll.js.map +1 -1
  97. package/dist/upgrade/converge.d.ts.map +1 -1
  98. package/dist/upgrade/converge.js +27 -4
  99. package/dist/upgrade/converge.js.map +1 -1
  100. package/dist/upgrade/health.d.ts +13 -3
  101. package/dist/upgrade/health.d.ts.map +1 -1
  102. package/dist/upgrade/health.js +24 -7
  103. package/dist/upgrade/health.js.map +1 -1
  104. package/dist/upgrade/load-balancer-get.d.ts +17 -0
  105. package/dist/upgrade/load-balancer-get.d.ts.map +1 -0
  106. package/dist/upgrade/load-balancer-get.js +38 -0
  107. package/dist/upgrade/load-balancer-get.js.map +1 -0
  108. package/dist/upgrader-gcp.d.ts.map +1 -1
  109. package/dist/upgrader-gcp.js +8 -1
  110. package/dist/upgrader-gcp.js.map +1 -1
  111. package/dist/wizards/gcp-cost.d.ts +9 -0
  112. package/dist/wizards/gcp-cost.d.ts.map +1 -1
  113. package/dist/wizards/gcp-cost.js +69 -34
  114. package/dist/wizards/gcp-cost.js.map +1 -1
  115. package/dist/wizards/gcp-install-job.d.ts +27 -4
  116. package/dist/wizards/gcp-install-job.d.ts.map +1 -1
  117. package/dist/wizards/gcp-install-job.js +62 -32
  118. package/dist/wizards/gcp-install-job.js.map +1 -1
  119. package/dist/wizards/gcp.d.ts +3 -0
  120. package/dist/wizards/gcp.d.ts.map +1 -1
  121. package/dist/wizards/gcp.js +10 -4
  122. package/dist/wizards/gcp.js.map +1 -1
  123. package/package.json +2 -2
  124. package/src/admin-internal-google.ts +48 -0
  125. package/src/aws-task-roles.ts +22 -0
  126. package/src/azure-secrets.ts +38 -0
  127. package/src/caddy.test.ts +19 -2
  128. package/src/caddy.ts +23 -0
  129. package/src/cli-routing.ts +3 -2
  130. package/src/cli.ts +10 -0
  131. package/src/dns/manual.ts +4 -1
  132. package/src/gateway-armor.ts +135 -0
  133. package/src/gateway-bootstrap.test.ts +1 -0
  134. package/src/gateway-edge.test.ts +262 -0
  135. package/src/gateway-edge.ts +256 -0
  136. package/src/gateway-env-isolation.test.ts +45 -6
  137. package/src/infra-contract.test.ts +5 -3
  138. package/src/infra-contract.ts +21 -1
  139. package/src/install-job-runner.ts +4 -2
  140. package/src/install-job.ts +86 -4
  141. package/src/lifecycle.ts +8 -1
  142. package/src/operator-access.test.ts +43 -0
  143. package/src/operator-access.ts +38 -6
  144. package/src/pool-budget-stack.ts +25 -0
  145. package/src/pool-budget-stacks.test.ts +31 -0
  146. package/src/project-status.test.ts +462 -0
  147. package/src/project-status.ts +306 -0
  148. package/src/public-service-shape.test.ts +166 -0
  149. package/src/public-service-shape.ts +131 -0
  150. package/src/remote-mcp-edge.ts +1 -1
  151. package/src/remote-mcp.test.ts +38 -1
  152. package/src/remote-mcp.ts +25 -3
  153. package/src/serverless-backend.ts +47 -0
  154. package/src/stack-contract.test.ts +13 -0
  155. package/src/stack-contract.ts +25 -0
  156. package/src/stack-converge.test.ts +28 -1
  157. package/src/stack-converge.ts +30 -0
  158. package/src/staging-gateway-setup.test.ts +55 -3
  159. package/src/staging-gateway-setup.ts +79 -27
  160. package/src/state-attach.ts +46 -16
  161. package/src/upgrade/app-roll.ts +27 -3
  162. package/src/upgrade/converge.ts +33 -4
  163. package/src/upgrade/health.test.ts +88 -13
  164. package/src/upgrade/health.ts +32 -7
  165. package/src/upgrade/load-balancer-get.ts +64 -0
  166. package/src/upgrade/upgrade.test.ts +96 -3
  167. package/src/upgrader-gcp.ts +8 -1
  168. package/src/wizards/gcp-cost.ts +78 -35
  169. package/src/wizards/gcp-install-job.ts +91 -46
  170. package/src/wizards/gcp.ts +14 -7
  171. package/stacks/aws/index.ts +24 -22
  172. package/stacks/azure/index.ts +152 -64
  173. package/stacks/gcp/index.ts +35 -47
  174. package/stacks/gcp-firebase/index.ts +25 -13
@@ -0,0 +1,462 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * `status --project` (#822): everything comes from the project, the setup
5
+ * link goes to a terminal only and never once it is used, and a failed read
6
+ * says what to do.
7
+ */
8
+
9
+ import { afterEach, describe, expect, it } from "bun:test";
10
+ import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { readOwnerSetupState } from "./admin-internal-google.js";
14
+ import type { GcloudResult } from "./gcloud.js";
15
+ import type { GcloudRunner } from "./gcloud-retry.js";
16
+ import {
17
+ INSTALL_SETUP_LINK_SECRET,
18
+ type InstallJobStatus,
19
+ readInstallJobStatus,
20
+ writeInstallJobStatus,
21
+ } from "./install-job.js";
22
+ import {
23
+ adminUrlFromOutputs,
24
+ dnsRecordsToSet,
25
+ type ProjectStatusDeps,
26
+ projectStatusFailure,
27
+ projectStatusLines,
28
+ readProjectStatus,
29
+ } from "./project-status.js";
30
+ import { selfCommand } from "./self-command.js";
31
+ import type { SyncGcloud } from "./state-store.js";
32
+ import { handoffLines } from "./wizards/gcp-install-job.js";
33
+
34
+ const PROJECT = "acme-site";
35
+ const BUCKET = "gs://acme-site-caelo-ops/install";
36
+ const LINK = "https://admin.acme.test/setup?token=abc123";
37
+ const INSTALL = {
38
+ installId: "gcp-acme-site",
39
+ provider: "gcp",
40
+ projectId: PROJECT,
41
+ domain: "acme.test",
42
+ ownerEmail: "owner@acme.test",
43
+ region: "europe-west1",
44
+ stateBackend: {
45
+ kind: "gcs",
46
+ bucket: "acme-site-caelo-ops",
47
+ kmsKey: "projects/acme-site/locations/europe-west1/keyRings/caelo/cryptoKeys/pulumi-state",
48
+ },
49
+ };
50
+ const RECORDS = [
51
+ { hostname: "admin.acme.test", type: "A", value: "203.0.113.7" },
52
+ { hostname: "acme.test", type: "A", value: "203.0.113.7" },
53
+ ];
54
+ const PROGRESS = {
55
+ steps: {
56
+ [`pulumi-up-${PROJECT}`]: {
57
+ outputs: {
58
+ adminDomainOut: "admin.acme.test",
59
+ adminCloudRunUrlOut: "https://x.run.app",
60
+ dnsRecordsRequiredOut: RECORDS,
61
+ },
62
+ },
63
+ },
64
+ };
65
+
66
+ function job(patch: Partial<InstallJobStatus>): InstallJobStatus {
67
+ return {
68
+ statusVersion: 1,
69
+ installId: INSTALL.installId,
70
+ execution: "caelo-install-abc",
71
+ state: "succeeded",
72
+ phase: "Done",
73
+ caeloVersion: "0.12.0",
74
+ startedAt: "2026-11-05T10:00:00.000Z",
75
+ updatedAt: "2026-11-05T10:30:00.000Z",
76
+ ...patch,
77
+ };
78
+ }
79
+
80
+ const ok = (stdout: string): GcloudResult => ({ ok: true, stdout, stderr: "", exitCode: 0 });
81
+ const fail = (stderr: string): GcloudResult => ({ ok: false, stdout: "", stderr, exitCode: 1 });
82
+
83
+ interface World {
84
+ objects?: Record<string, unknown>;
85
+ /** Stderr of a refused `storage cat`. */
86
+ denied?: string;
87
+ setupLink?: string | null;
88
+ linkDenied?: string;
89
+ execution?: "running" | "gone";
90
+ ownerSetup?: "open" | "done" | "unknown";
91
+ isTerminal?: boolean;
92
+ resolving?: readonly string[];
93
+ }
94
+
95
+ /** {@link ProjectStatusDeps} over a fake project; records every gcloud call. */
96
+ function project(world: World): { deps: ProjectStatusDeps; calls: string[][]; probes: string[] } {
97
+ const calls: string[][] = [];
98
+ const probes: string[] = [];
99
+ const objects = world.objects ?? {
100
+ [`${BUCKET}/install.json`]: INSTALL,
101
+ [`${BUCKET}/progress.json`]: PROGRESS,
102
+ };
103
+ const syncRun: SyncGcloud = (args) => {
104
+ calls.push(args);
105
+ if (world.denied) return fail(world.denied);
106
+ const url = args[2] ?? "";
107
+ if (args[1] !== "cat") throw new Error(`a read-only command ran: ${args.join(" ")}`);
108
+ const value = objects[url];
109
+ return value === undefined
110
+ ? fail("ERROR: The following URLs matched no objects or files")
111
+ : ok(typeof value === "string" ? value : JSON.stringify(value));
112
+ };
113
+ const run: GcloudRunner = async (args) => {
114
+ calls.push(args);
115
+ if (args[0] === "secrets") {
116
+ expect(args).toContain(`--secret=${INSTALL_SETUP_LINK_SECRET}`);
117
+ if (world.linkDenied) return fail(world.linkDenied);
118
+ return world.setupLink ? ok(world.setupLink) : fail("NOT_FOUND: Secret not found");
119
+ }
120
+ if (args[0] === "run") {
121
+ return world.execution === "gone"
122
+ ? ok(JSON.stringify({ status: { completionTime: "t", failedCount: 1 } }))
123
+ : ok(JSON.stringify({ status: {} }));
124
+ }
125
+ throw new Error(`unexpected gcloud call: ${args.join(" ")}`);
126
+ };
127
+ return {
128
+ calls,
129
+ probes,
130
+ deps: {
131
+ run,
132
+ syncRun,
133
+ resolves: async (r) => (world.resolving ?? []).includes(r.hostname),
134
+ ownerSetupState: async (target) => {
135
+ probes.push(target.provider);
136
+ if (world.ownerSetup === "unknown") return { ok: false, error: "the admin is asleep" };
137
+ return { ok: true, value: world.ownerSetup ?? "open" };
138
+ },
139
+ isTerminal: world.isTerminal ?? true,
140
+ },
141
+ };
142
+ }
143
+
144
+ const text = async (w: World) =>
145
+ projectStatusLines(await readProjectStatus(PROJECT, project(w).deps)).join("\n");
146
+
147
+ describe("status --project: phase", () => {
148
+ it("shows a running job with the command that follows it", async () => {
149
+ const out = await text({
150
+ objects: {
151
+ [`${BUCKET}/install.json`]: INSTALL,
152
+ [`${BUCKET}/progress.json`]: PROGRESS,
153
+ [`${BUCKET}/install-job.json`]: job({
154
+ state: "running",
155
+ phase: "Waiting for DNS",
156
+ detail: "Set at your registrar: A admin.acme.test → 203.0.113.7",
157
+ }),
158
+ },
159
+ execution: "running",
160
+ });
161
+ expect(out).toContain("Waiting for DNS");
162
+ expect(out).toContain("Set at your registrar");
163
+ expect(out).toContain(
164
+ selfCommand("--provider", "gcp", "--install-job", "--project-id", PROJECT),
165
+ );
166
+ expect(out).toContain("the link appears here when the install has finished");
167
+ });
168
+
169
+ it("says when the job's execution died while the bucket still says running", async () => {
170
+ const out = await text({
171
+ objects: {
172
+ [`${BUCKET}/install.json`]: INSTALL,
173
+ [`${BUCKET}/progress.json`]: PROGRESS,
174
+ [`${BUCKET}/install-job.json`]: job({ state: "running", phase: "Provisioning" }),
175
+ },
176
+ execution: "gone",
177
+ });
178
+ expect(out).toContain("Not finished");
179
+ expect(out).toContain("Resume it where this run stopped");
180
+ expect(out).not.toContain("Follow it live");
181
+ });
182
+
183
+ it("before the job's first write says how to start it, and knows no admin or records", async () => {
184
+ const out = await text({ objects: { [`${BUCKET}/install.json`]: INSTALL } });
185
+ expect(out).toContain("Install job: not started");
186
+ expect(out).toContain("Admin: not known yet");
187
+ expect(out).toContain("DNS: not known yet");
188
+ });
189
+
190
+ it("names a terminal install for what it is", async () => {
191
+ const out = await text({});
192
+ expect(out).toContain("ran from a terminal");
193
+ });
194
+ });
195
+
196
+ describe("status --project: DNS", () => {
197
+ it("lists what public DNS does not answer yet, in the install's two groups", async () => {
198
+ const s = await dnsRecordsToSet(RECORDS, "acme.test", async () => false);
199
+ expect(s.setNow.map((r) => r.hostname)).toEqual(["admin.acme.test"]);
200
+ expect(s.atGoLive.map((r) => r.hostname)).toEqual(["acme.test"]);
201
+ expect(s.total).toBe(2);
202
+ });
203
+
204
+ it("drops a record that already resolves", async () => {
205
+ const out = await text({ resolving: ["admin.acme.test"] });
206
+ expect(out).toContain("DNS records still to set");
207
+ expect(out).toContain("Only at go-live");
208
+ expect(out).not.toContain("admin.acme.test ");
209
+ expect(out).not.toContain("Set now");
210
+ });
211
+
212
+ it("says so when every record is set", async () => {
213
+ const out = await text({ resolving: ["admin.acme.test", "acme.test"] });
214
+ expect(out).toContain("all set (2 of 2)");
215
+ });
216
+
217
+ it("includes the staging records the job stored, once", async () => {
218
+ const staging = { hostname: "staging.acme.test", type: "A", value: "203.0.113.7" };
219
+ const out = await text({
220
+ objects: {
221
+ [`${BUCKET}/install.json`]: INSTALL,
222
+ [`${BUCKET}/progress.json`]: PROGRESS,
223
+ [`${BUCKET}/install-job.json`]: job({ dnsRecords: [staging, staging] }),
224
+ },
225
+ });
226
+ expect(out.match(/staging\.acme\.test/g)).toHaveLength(1);
227
+ expect(out).not.toContain("Settings → Updates");
228
+ });
229
+ });
230
+
231
+ describe("status --project: admin URL", () => {
232
+ it("is admin.<domain> on gcp and the Cloud Run URL on gcp-firebase, as the setup link", () => {
233
+ const outputs = PROGRESS.steps[`pulumi-up-${PROJECT}`]?.outputs ?? {};
234
+ expect(adminUrlFromOutputs("gcp", outputs)).toBe("https://admin.acme.test");
235
+ expect(adminUrlFromOutputs("gcp-firebase", outputs)).toBe("https://x.run.app");
236
+ expect(adminUrlFromOutputs("gcp", {})).toBeNull();
237
+ });
238
+ });
239
+
240
+ describe("status --project: Owner setup link", () => {
241
+ const finished = {
242
+ objects: {
243
+ [`${BUCKET}/install.json`]: INSTALL,
244
+ [`${BUCKET}/progress.json`]: PROGRESS,
245
+ [`${BUCKET}/install-job.json`]: job({}),
246
+ },
247
+ setupLink: LINK,
248
+ };
249
+
250
+ it("prints the link while setup is open", async () => {
251
+ const out = await text(finished);
252
+ expect(out).toContain(LINK);
253
+ expect(out).toContain("owner@acme.test");
254
+ });
255
+
256
+ it("says setup is done instead of printing a used link", async () => {
257
+ const out = await text({ ...finished, ownerSetup: "done" });
258
+ expect(out).not.toContain(LINK);
259
+ expect(out).not.toContain("token=");
260
+ expect(out).toContain("done.");
261
+ expect(out).toContain("https://admin.acme.test");
262
+ });
263
+
264
+ it("never prints the link when stdout is not a terminal", async () => {
265
+ const out = await text({ ...finished, isTerminal: false });
266
+ expect(out).not.toContain(LINK);
267
+ expect(out).not.toContain("token=");
268
+ expect(out).toContain("only goes to a terminal");
269
+ });
270
+
271
+ it("still prints it when the check fails, saying so", async () => {
272
+ const out = await text({ ...finished, ownerSetup: "unknown" });
273
+ expect(out).toContain(LINK);
274
+ expect(out).toContain("the admin is asleep");
275
+ });
276
+
277
+ it("does not read the secret before the install finished", async () => {
278
+ const p = project({
279
+ ...finished,
280
+ objects: {
281
+ ...finished.objects,
282
+ [`${BUCKET}/install-job.json`]: job({ state: "running", phase: "Provisioning" }),
283
+ },
284
+ execution: "running",
285
+ });
286
+ const s = await readProjectStatus(PROJECT, p.deps);
287
+ expect(s.owner.kind).toBe("not-yet");
288
+ expect(p.calls.some((c) => c[0] === "secrets")).toBe(false);
289
+ expect(p.probes).toEqual([]);
290
+ });
291
+
292
+ it("with no stored link names the admin and the way to get one", async () => {
293
+ const out = await text({ ...finished, setupLink: null });
294
+ expect(out).toContain("no link is stored");
295
+ expect(out).toContain("https://admin.acme.test");
296
+ expect(out).toContain("--project-id acme-site");
297
+ });
298
+
299
+ it("reports a refused secret read with what the account needs", async () => {
300
+ const out = await text({ ...finished, linkDenied: "PERMISSION_DENIED: nope" });
301
+ expect(out).toContain("secretmanager.versions.access");
302
+ });
303
+ });
304
+
305
+ describe("status --project: failed reads and this machine", () => {
306
+ it("a project without an install says to check the id", async () => {
307
+ await expect(readProjectStatus(PROJECT, project({ objects: {} }).deps)).rejects.toThrow(
308
+ /holds no install\.json\. Check the project id/,
309
+ );
310
+ });
311
+
312
+ it("a refused bucket read says which sign-in it needs", async () => {
313
+ await expect(
314
+ readProjectStatus(PROJECT, project({ denied: "AccessDeniedException: 403" }).deps),
315
+ ).rejects.toThrow(/gcloud auth login/);
316
+ });
317
+
318
+ it("a refused status read says which sign-in it needs", () => {
319
+ const run: SyncGcloud = () => fail("AccessDeniedException: 403");
320
+ expect(() => readInstallJobStatus("b", run)).toThrow(/gcloud auth login/);
321
+ });
322
+
323
+ it("a malformed pulumi-up step is an error, not an unprovisioned install", async () => {
324
+ const objects = {
325
+ [`${BUCKET}/install.json`]: INSTALL,
326
+ [`${BUCKET}/progress.json`]: { steps: { [`pulumi-up-${PROJECT}`]: "broken" } },
327
+ };
328
+ await expect(readProjectStatus(PROJECT, project({ objects }).deps)).rejects.toThrow(
329
+ /pulumi-up step/,
330
+ );
331
+ });
332
+
333
+ it("a missing gcloud says to install it", () => {
334
+ const e = Object.assign(new Error("spawn gcloud ENOENT"), { code: "ENOENT" });
335
+ expect(projectStatusFailure(e)).toContain("Install the Google Cloud CLI");
336
+ });
337
+
338
+ describe("with an empty HOME", () => {
339
+ let home: string | undefined;
340
+ const realHome = process.env.HOME;
341
+ afterEach(() => {
342
+ process.env.HOME = realHome;
343
+ if (home) rmSync(home, { recursive: true, force: true });
344
+ });
345
+
346
+ it("needs no install directory and creates none", async () => {
347
+ home = mkdtempSync(join(tmpdir(), "caelo-status-"));
348
+ process.env.HOME = home;
349
+ const out = await text({});
350
+ expect(out).toContain("gcp-acme-site");
351
+ expect(existsSync(home)).toBe(true);
352
+ expect(readdirSync(home)).toEqual([]);
353
+ });
354
+ });
355
+ });
356
+
357
+ describe("the job's status document", () => {
358
+ it("takes DNS records past the secrets guard, a verification TXT included", () => {
359
+ const written: string[] = [];
360
+ const run: SyncGcloud = (_args, input) => {
361
+ if (input) written.push(input);
362
+ return ok("");
363
+ };
364
+ const dnsRecords = [
365
+ { hostname: "acme.test", type: "TXT", value: "hosting-site=caelo-production-site-19114e" },
366
+ ];
367
+ writeInstallJobStatus("b", job({ dnsRecords }), run);
368
+ expect(JSON.parse(written[0] ?? "{}").dnsRecords).toEqual(dnsRecords);
369
+ });
370
+ });
371
+
372
+ describe("the handoff message", () => {
373
+ it("says the tab may close and gives the exact command", () => {
374
+ const out = handoffLines(PROJECT).join("\n");
375
+ expect(out).toContain("You may close this tab now.");
376
+ expect(out).toContain(selfCommand("status", "--project", PROJECT));
377
+ });
378
+ });
379
+
380
+ describe("readOwnerSetupState", () => {
381
+ const target = { provider: "gcp", projectId: PROJECT, domain: "acme.test" } as const;
382
+ const gcloudToken = async () => ok("access-token");
383
+ const answering = (setup: () => Response) => {
384
+ const urls: string[] = [];
385
+ const doFetch = (async (input: string | URL | Request, init?: RequestInit) => {
386
+ const url = String(input);
387
+ urls.push(url);
388
+ if (url.includes("iamcredentials")) return Response.json({ signedJwt: "jwt" });
389
+ expect(init?.redirect).toBe("manual");
390
+ expect(new Headers(init?.headers).get("authorization")).toBe("Bearer jwt");
391
+ return setup();
392
+ }) as typeof fetch;
393
+ return { urls, doFetch };
394
+ };
395
+ const read = (setup: () => Response) =>
396
+ readOwnerSetupState(target, { run: gcloudToken, fetch: answering(setup).doFetch });
397
+
398
+ it("reads a rendered form as open", async () => {
399
+ expect(await read(() => new Response("<form>"))).toEqual({ ok: true, value: "open" });
400
+ });
401
+
402
+ it("reads the redirect to /login as done", async () => {
403
+ const r = await read(
404
+ () => new Response(null, { status: 303, headers: { location: "/login" } }),
405
+ );
406
+ expect(r).toEqual({ ok: true, value: "done" });
407
+ });
408
+
409
+ it("does not take any other answer for an answer", async () => {
410
+ const r = await read(() => new Response("boom", { status: 500 }));
411
+ expect(r).toEqual({ ok: false, error: "the admin answered /setup with HTTP 500" });
412
+ const elsewhere = await read(
413
+ () => new Response(null, { status: 303, headers: { location: "/maintenance" } }),
414
+ );
415
+ expect(elsewhere.ok).toBe(false);
416
+ });
417
+
418
+ it("sends its token only to the admin the install's domain names", async () => {
419
+ const { urls, doFetch } = answering(() => new Response("<form>"));
420
+ await readOwnerSetupState(target, { run: gcloudToken, fetch: doFetch });
421
+ expect(urls.filter((u) => !u.includes("iamcredentials"))).toEqual([
422
+ "https://admin.acme.test/setup",
423
+ ]);
424
+ });
425
+
426
+ it("takes the gcp-firebase address from Cloud Run, not from a checkpoint", async () => {
427
+ const { urls, doFetch } = answering(() => new Response("<form>"));
428
+ const run = async (args: string[]) => {
429
+ if (args[1] === "services" && args[2] === "describe") return ok("https://real.run.app\n");
430
+ if (args[1] === "services" && args[2] === "list") {
431
+ return ok("caelo-production-admin-abc\n");
432
+ }
433
+ return ok("access-token");
434
+ };
435
+ await readOwnerSetupState(
436
+ { provider: "gcp-firebase", projectId: PROJECT, region: "europe-west1" },
437
+ { run, fetch: doFetch },
438
+ );
439
+ expect(urls.at(-1)).toBe("https://real.run.app/setup");
440
+ });
441
+
442
+ it("turns a failed signing call into an answer, so the status still prints", async () => {
443
+ const doFetch = (async () => {
444
+ throw new Error("network down");
445
+ }) as unknown as typeof fetch;
446
+ const r = await readOwnerSetupState(target, { run: gcloudToken, fetch: doFetch });
447
+ expect(r.ok).toBe(false);
448
+ expect(r.ok ? "" : r.error).toContain("network down");
449
+ });
450
+
451
+ it("reports IAP's own refusal", async () => {
452
+ const r = await read(
453
+ () =>
454
+ new Response("denied", {
455
+ status: 403,
456
+ headers: { "x-goog-iap-generated-response": "true" },
457
+ }),
458
+ );
459
+ expect(r.ok).toBe(false);
460
+ expect(r.ok ? "" : r.error).toContain("Google IAP refused");
461
+ });
462
+ });