flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/scripts/deploy/deploy.test.mjs

554 lines25,570 bytesCodeBlame
1// node --test "scripts/deploy/*.test.mjs" (npm run test:deploy)
2import assert from "node:assert/strict";
3import { execFileSync } from "node:child_process";
4import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5import { tmpdir } from "node:os";
6import { join } from "node:path";
7import { test } from "node:test";
8
9import { isStaticElf } from "../build-runner.mjs";
10import {
11 DEPLOY_CONFIG,
12 baseInputs,
13 baseState,
14 baseTag,
15 contentHash,
16 lockFor,
17 readBaseLock,
18 registryHas,
19 removeDeployConfig,
20 runnerRef,
21 runnerTag,
22 writeDeployConfig,
23} from "./image.mjs";
24
25import { annotation, commitFrom, liveCommit, pendingFrom, versionFrom } from "./cloudflare.mjs";
26import { changedNames, parseCargoLock, parseNpmLock, reaches } from "./lockfiles.mjs";
27import { decide, planJson, pool } from "./plan.mjs";
28import {
29 ROOT,
30 buildGroups,
31 cargoWorkspace,
32 findWranglerConfigs,
33 loadStack,
34 npmCiArgs,
35 npmWorkspace,
36 outsideImports,
37 pick,
38 problems,
39 resolveStack,
40 resolvedStack,
41 touches,
42 touchesBase,
43 touchesImage,
44} from "./stack.mjs";
45
46const stack = resolvedStack();
47const unit = (id) => stack.units.find((u) => u.id === id);
48
49// ── The manifest ──────────────────────────────────────────────────────────
50
51test("the manifest matches every wrangler config in the repository", () => {
52 assert.deepEqual(problems(stack, findWranglerConfigs()), []);
53});
54
55test("every wrangler.jsonc is found, and only checked-in ones", () => {
56 const configs = findWranglerConfigs();
57 assert.ok(configs.includes("services/events/wrangler.jsonc"));
58 assert.ok(configs.includes("apps/web/wrangler.jsonc"));
59 assert.ok(!configs.some((c) => c.includes("/build/")), "build output is not a unit");
60 assert.equal(configs.length, stack.units.length);
61});
62
63test("problems are found: an unlisted config, a later-stage binding, a wrong database, an unnamed KV", () => {
64 const broken = loadStack();
65 const events = broken.units.find((u) => u.id === "events");
66 events.stage = "front";
67 const identity = broken.units.find((u) => u.id === "identity");
68 identity.d1 = { database: "g1t-identity", migrations: "migrations" };
69 broken.resources = { kv: {} };
70 const found = problems(broken, [...findWranglerConfigs(), "services/new/wrangler.jsonc"]);
71 assert.ok(found.some((p) => p.includes("services/new/wrangler.jsonc is not in")));
72 assert.ok(found.some((p) => p.includes("binds to events (front), which ships after it")));
73 assert.ok(found.some((p) => p.startsWith("Unit identity: d1 is")));
74 assert.ok(found.some((p) => p.includes("has no name under resources.kv")));
75});
76
77test("stages follow bindings: nothing binds to a unit that ships after it", () => {
78 const order = stack.stages;
79 for (const u of stack.units) {
80 for (const target of u.bindsTo) {
81 const other = stack.units.find((o) => o.worker === target);
82 assert.ok(order.indexOf(other.stage) <= order.indexOf(u.stage), `${u.id} -> ${other.id}`);
83 }
84 }
85});
86
87test("Rust workers build with the shared script and the same wasm-opt level", () => {
88 for (const u of stack.units.filter((u) => u.kind === "rust-worker")) {
89 assert.equal(u.config.build.command, "node ../../scripts/build-rust-worker.mjs", u.id);
90 const toml = readFileSync(join(ROOT, u.path, "Cargo.toml"), "utf8");
91 assert.match(toml, /\[package\.metadata\.wasm-pack\.profile\.release\]\s*\nwasm-opt = \["-O1"\]/, u.id);
92 }
93});
94
95// ── What each unit is built from ──────────────────────────────────────────
96
97test("shared crates and packages are read from workspace metadata", () => {
98 assert.deepEqual(unit("events").dependsOn, ["crates/contracts", "crates/kit"]);
99 assert.deepEqual(unit("repos").dependsOn, ["crates/contracts", "crates/kit", "crates/scan", "crates/secrets"]);
100 assert.ok(unit("actions").dependsOn.includes("crates/actions"));
101 assert.ok(!unit("events").dependsOn.includes("crates/scan"));
102 assert.deepEqual(unit("web").dependsOn, ["packages/contracts", "packages/theme"]);
103 assert.deepEqual(unit("projects").dependsOn, ["packages/contracts"]);
104 assert.deepEqual(unit("pages").dependsOn, []);
105 assert.equal(unit("events").crate, "g1t-events");
106 assert.equal(unit("web").pkg, "@g1t/web");
107});
108
109test("the runner's image is built from the runner crate and what it uses, on the base its lock names", () => {
110 const runner = unit("runner");
111 assert.deepEqual(runner.image.dirs, ["crates/actions", "crates/runner"]);
112 assert.deepEqual(runner.image.baseDirs, ["services/runner/base"]);
113 assert.ok(runner.dependsOn.includes("crates/runner"));
114 assert.ok(touchesImage(runner, ["crates/actions/src/expr.rs"]));
115 assert.ok(touchesImage(runner, ["services/runner/Dockerfile"]));
116 assert.ok(touchesImage(runner, ["services/runner/base.json"]));
117 assert.ok(touchesImage(runner, ["scripts/build-runner.mjs"]));
118 assert.ok(!touchesImage(runner, ["services/runner/src/index.ts"]));
119 // The base's Dockerfile reaches the image only through a new lock.
120 assert.ok(!touchesImage(runner, ["services/runner/base/Dockerfile"]));
121 assert.ok(touchesBase(runner, ["services/runner/base/Dockerfile"]));
122 assert.ok(!touchesBase(unit("events"), ["services/runner/base/Dockerfile"]));
123});
124
125// ── The runner's images ───────────────────────────────────────────────────
126
127test("services/runner/base.json records the base its folder builds", () => {
128 const runner = unit("runner");
129 const lock = readBaseLock(runner);
130 assert.ok(lock, "services/runner/base.json is missing: node scripts/deploy.mjs build-base");
131 assert.equal(
132 lock.inputs,
133 baseInputs(runner),
134 "services/runner/base changed since base.json was written: node scripts/deploy.mjs build-base, and commit base.json",
135 );
136 assert.match(lock.image, /^registry\.cloudflare\.com\/[0-9a-f]{32}\/g1t-runner:base-\d{8}-[0-9a-f]{12}$/);
137 assert.ok(lock.image.endsWith(lock.inputs.slice(0, 12)));
138 assert.equal(baseState(runner).current, true);
139});
140
141test("an image's hash ignores line endings, and its tags say what they are", () => {
142 const files = { "a.txt": "one\r\ntwo\r\n", "b.txt": "x" };
143 const lf = { "a.txt": "one\ntwo\n", "b.txt": "x" };
144 const hash = (set) => contentHash(Object.keys(set), "/", (file) => Buffer.from(set[file]));
145 assert.equal(hash(files), hash(lf));
146 assert.notEqual(hash(lf), hash({ ...lf, "b.txt": "y" }));
147 assert.equal(baseTag("0123456789abcdef".repeat(4), new Date("2026-10-06T12:00:00Z")), "base-20261006-0123456789ab");
148 const runner = unit("runner");
149 assert.match(runnerTag(runner), /^[0-9a-f]{16}$/);
150 assert.equal(runnerTag(runner), runnerTag(runner));
151 assert.equal(runnerRef(runner, ROOT, "a".repeat(32)), `registry.cloudflare.com/${"a".repeat(32)}/g1t-runner:${runnerTag(runner)}`);
152});
153
154test("only the lockfile entries the runner is built from name its image", () => {
155 const lock = (wasm) => `[[package]]
156name = "g1t-runner"
157version = "0.1.0"
158dependencies = [
159 "ureq",
160]
161
162[[package]]
163name = "ureq"
164version = "2.12.1"
165
166[[package]]
167name = "wasm-bindgen"
168version = "${wasm}"
169`;
170 assert.equal(lockFor(lock("0.2.100"), "g1t-runner"), lockFor(lock("0.2.101"), "g1t-runner"));
171 assert.ok(lockFor(lock("0.2.100"), "g1t-runner").includes("ureq"));
172 assert.notEqual(lockFor(lock("0.2.100"), "g1t-runner"), lockFor(lock("0.2.100").replace("2.12.1", "2.12.2"), "g1t-runner"));
173});
174
175test("the runner's deploy config names its image by reference, beside its wrangler.jsonc", () => {
176 const runner = unit("runner");
177 const ref = "registry.cloudflare.com/acct/g1t-runner:0123456789abcdef";
178 const name = writeDeployConfig(runner, ref);
179 try {
180 assert.equal(name, DEPLOY_CONFIG);
181 const config = JSON.parse(readFileSync(join(ROOT, runner.path, DEPLOY_CONFIG), "utf8"));
182 assert.equal(config.name, "g1t-runner");
183 assert.equal(config.main, "./src/index.ts");
184 assert.ok(config.containers.length >= 1);
185 for (const container of config.containers) {
186 assert.equal(container.image, ref);
187 assert.equal(container.image_build_context, undefined);
188 }
189 // Every sandbox class shares the image; each has a Durable Object binding.
190 const classes = config.containers.map((c) => c.class_name).sort();
191 assert.deepEqual(classes, config.durable_objects.bindings.map((b) => b.class_name).sort());
192 // Generated, never committed, and not taken for a unit of its own.
193 assert.ok(readFileSync(join(ROOT, ".gitignore"), "utf8").includes("wrangler.deploy.json"));
194 assert.ok(!findWranglerConfigs().some((c) => c.endsWith(DEPLOY_CONFIG)));
195 } finally {
196 removeDeployConfig(runner);
197 }
198 assert.ok(!existsSync(join(ROOT, runner.path, DEPLOY_CONFIG)));
199});
200
201test("the registry is asked for an image's manifest, without Docker", async () => {
202 const asked = [];
203 const fetchImpl = async (url, init) => {
204 asked.push([url, init.method, init.headers.authorization]);
205 return { status: url.endsWith(":nope") || url.endsWith("/nope") ? 404 : 200, ok: !url.endsWith("/nope") };
206 };
207 const credentials = async () => ({ username: "v1", password: "secret" });
208 assert.equal(await registryHas("registry.cloudflare.com/acct/g1t-runner:abc", { fetchImpl, credentials }), true);
209 assert.equal(await registryHas("registry.cloudflare.com/acct/g1t-runner:nope", { fetchImpl, credentials }), false);
210 assert.deepEqual(asked[0], [
211 "https://registry.cloudflare.com/v2/acct/g1t-runner/manifests/abc",
212 "HEAD",
213 `Basic ${Buffer.from("v1:secret").toString("base64")}`,
214 ]);
215 await assert.rejects(registryHas("not-a-reference", { fetchImpl, credentials }));
216});
217
218test("a static Linux binary is told from a dynamic one", () => {
219 const dir = mkdtempSync(join(tmpdir(), "g1t-elf-"));
220 try {
221 const elf = (interp) => {
222 // 64-bit little-endian x86-64 ELF with one program header.
223 const bytes = Buffer.alloc(64 + 56);
224 bytes.writeUInt32BE(0x7f454c46, 0);
225 bytes[4] = 2;
226 bytes[5] = 1;
227 bytes.writeUInt16LE(0x3e, 18);
228 bytes.writeBigUInt64LE(64n, 32);
229 bytes.writeUInt16LE(56, 54);
230 bytes.writeUInt16LE(1, 56);
231 bytes.writeUInt32LE(interp ? 3 : 1, 64);
232 return bytes;
233 };
234 writeFileSync(join(dir, "static"), elf(false));
235 writeFileSync(join(dir, "dynamic"), elf(true));
236 writeFileSync(join(dir, "text"), "#!/bin/sh\n");
237 assert.equal(isStaticElf(join(dir, "static")), true);
238 assert.equal(isStaticElf(join(dir, "dynamic")), false);
239 assert.equal(isStaticElf(join(dir, "text")), false);
240 } finally {
241 rmSync(dir, { recursive: true, force: true });
242 }
243});
244
245test("path dependencies agree with Cargo's own resolved graph", (t) => {
246 let full;
247 try {
248 full = JSON.parse(execFileSync("cargo", ["metadata", "--format-version", "1", "--offline"], { cwd: ROOT, encoding: "utf8", maxBuffer: 256 << 20 }));
249 } catch {
250 t.skip("cargo metadata could not resolve offline");
251 return;
252 }
253 const cargo = cargoWorkspace(ROOT);
254 const dirOf = new Map(full.packages.filter((p) => p.source === null).map((p) => [p.id, p.manifest_path]));
255 const nodes = new Map(full.resolve.nodes.map((n) => [n.id, n]));
256 for (const u of stack.units.filter((u) => u.crate)) {
257 const root = full.packages.find((p) => p.name === u.crate).id;
258 const seen = new Set();
259 const stackIds = [root];
260 while (stackIds.length) {
261 const id = stackIds.pop();
262 for (const dep of nodes.get(id).deps) {
263 if (!dep.dep_kinds.some((k) => k.kind !== "dev")) continue;
264 if (dirOf.has(dep.pkg) && !seen.has(dep.pkg)) {
265 seen.add(dep.pkg);
266 stackIds.push(dep.pkg);
267 }
268 }
269 }
270 const names = [...seen].map((id) => full.packages.find((p) => p.id === id).name);
271 const dirs = names.map((name) => cargo.get(name).dir).sort();
272 assert.deepEqual(dirs, u.dependsOn.filter((d) => d.startsWith("crates/")).sort(), u.id);
273 }
274});
275
276test("every import that leaves a unit's folder is covered by its dependencies or inputs", () => {
277 for (const u of stack.units) {
278 for (const { file, target } of outsideImports(ROOT, u)) {
279 const covered = u.dependsOn.some((dir) => target.startsWith(`${dir}/`)) || u.inputs.some((input) => target === input || target.startsWith(input.replace(/\.ts$/, "")));
280 assert.ok(covered, `${file} imports ${target}, which ${u.id}'s manifest entry does not name`);
281 }
282 }
283});
284
285// ── What a change touches ─────────────────────────────────────────────────
286
287const ids = (units, files) => units.filter((u) => touches(u, files)).map((u) => u.id);
288
289test("a shared crate's change reaches every unit built from it, and no other", () => {
290 assert.deepEqual(ids(stack.units, ["crates/scan/src/lib.rs"]), ["repos", "security"]);
291 assert.deepEqual(ids(stack.units, ["crates/secrets/src/lib.rs"]), ["identity", "repos", "integrations", "webhooks", "actions"]);
292 const kit = ids(stack.units, ["crates/kit/src/lib.rs"]);
293 assert.deepEqual(kit, stack.units.filter((u) => u.kind === "rust-worker").map((u) => u.id));
294 assert.deepEqual(ids(stack.units, ["crates/runner/src/main.rs"]), ["runner"]);
295});
296
297test("a shared package's change reaches what imports it", () => {
298 assert.deepEqual(ids(stack.units, ["packages/theme/tokens.css"]), ["status", "web", "sudo", "docs"]);
299 assert.ok(ids(stack.units, ["packages/contracts/src/index.ts"]).includes("og"));
300 assert.ok(!ids(stack.units, ["packages/contracts/src/index.ts"]).includes("events"));
301});
302
303test("own folders, declared inputs and root files", () => {
304 assert.deepEqual(ids(stack.units, ["services/pages/src/index.ts"]), ["pages"]);
305 assert.deepEqual(ids(stack.units, ["apps/web/app/lib/roadmap.ts"]), ["og", "web"]);
306 assert.deepEqual(ids(stack.units, ["docs/PLAN.md", "README.md", "deploy/stack.jsonc"]), []);
307 assert.deepEqual(ids(stack.units, ["scripts/build-rust-worker.mjs"]), stack.units.filter((u) => u.kind === "rust-worker").map((u) => u.id));
308 // services/events is not a prefix of services/eventsx.
309 assert.equal(touches(unit("events"), ["services/eventsx/a.rs"]), null);
310});
311
312// ── Lockfiles ─────────────────────────────────────────────────────────────
313
314const lock = (sha2) => `version = 4
315
316[[package]]
317name = "g1t-events"
318version = "0.1.0"
319dependencies = [
320 "g1t-kit",
321]
322
323[[package]]
324name = "g1t-kit"
325version = "0.1.0"
326dependencies = [
327 "serde",
328]
329
330[[package]]
331name = "g1t-webhooks"
332version = "0.1.0"
333dependencies = [
334 "g1t-kit",
335 "g1t-secrets",
336]
337
338[[package]]
339name = "g1t-secrets"
340version = "0.1.0"
341dependencies = [
342 "sha2 ${sha2}",
343]
344
345[[package]]
346name = "serde"
347version = "1.0.0"
348source = "registry+https://github.com/rust-lang/crates.io-index"
349
350[[package]]
351name = "sha2"
352version = "${sha2}"
353source = "registry+https://github.com/rust-lang/crates.io-index"
354`;
355
356test("a Cargo.lock change reaches only crates that use what changed", () => {
357 const before = parseCargoLock(lock("0.10.8"));
358 const after = parseCargoLock(lock("0.10.9"));
359 const names = changedNames(before, after);
360 assert.deepEqual([...names], ["sha2"]);
361 assert.ok(reaches(after, ["g1t-webhooks"], names));
362 assert.ok(!reaches(after, ["g1t-events"], names));
363});
364
365test("a package-lock change reaches through workspace links", () => {
366 const make = (version) =>
367 JSON.stringify({
368 lockfileVersion: 3,
369 packages: {
370 "": { devDependencies: { wrangler: "^4" } },
371 "apps/web": { dependencies: { "@g1t/theme": "*", react: "^19" } },
372 "services/pages": { dependencies: {} },
373 "packages/theme": { dependencies: { fontkit: "^1" } },
374 "node_modules/@g1t/theme": { resolved: "packages/theme", link: true },
375 "node_modules/react": { version: "19.0.0" },
376 "node_modules/fontkit": { version },
377 "node_modules/wrangler": { version: "4.1.0" },
378 },
379 });
380 const before = parseNpmLock(make("1.0.0"));
381 const after = parseNpmLock(make("1.0.1"));
382 const names = changedNames(before, after);
383 assert.deepEqual([...names], ["fontkit"]);
384 assert.ok(reaches(after, ["apps/web", ""], names));
385 assert.ok(!reaches(after, ["services/pages", ""], names));
386});
387
388// ── Deciding ──────────────────────────────────────────────────────────────
389
390const HEAD = "a".repeat(40);
391const OLD = "b".repeat(40);
392const fakeGit = (files, { has = true, locks = {} } = {}) => ({
393 has: () => has,
394 changed: () => files,
395 show: (sha, path) => locks[`${sha}:${path}`] ?? "",
396});
397
398test("decide: changed units deploy, others wait, unknown ones deploy", () => {
399 const units = ["events", "repos", "pages", "web"].map(unit);
400 const live = { events: { sha: OLD }, repos: { sha: OLD }, pages: { sha: HEAD }, web: { sha: null, why: "never deployed" } };
401 const decisions = decide(units, { live, head: HEAD, gitApi: fakeGit(["crates/scan/src/lib.rs"]) });
402 const by = Object.fromEntries(decisions.map((d) => [d.unit.id, d]));
403 assert.equal(by.events.deploy, false);
404 assert.equal(by.events.reason, "nothing it is built from changed");
405 assert.equal(by.repos.deploy, true);
406 assert.match(by.repos.reason, /crates\/scan\/src\/lib.rs via crates\/scan/);
407 assert.equal(by.pages.deploy, false);
408 assert.equal(by.pages.reason, "up to date");
409 assert.equal(by.web.deploy, true);
410 assert.match(by.web.reason, /never deployed/);
411});
412
413test("decide: --force deploys unchanged units; a commit missing from history deploys", () => {
414 const forced = decide([unit("events")], { live: { events: { sha: HEAD } }, head: HEAD, force: true, gitApi: fakeGit([]) });
415 assert.equal(forced[0].deploy, true);
416 const shallow = decide([unit("events")], { live: { events: { sha: OLD } }, head: HEAD, gitApi: fakeGit([], { has: false }) });
417 assert.equal(shallow[0].deploy, true);
418 assert.match(shallow[0].reason, /does not have/);
419});
420
421test("decide: Cargo.lock counts only where it reaches", () => {
422 const locks = { [`${OLD}:Cargo.lock`]: lock("0.10.8"), [`${HEAD}:Cargo.lock`]: lock("0.10.9") };
423 const units = [unit("events"), unit("webhooks")];
424 const live = { events: { sha: OLD }, webhooks: { sha: OLD } };
425 const decisions = decide(units, { live, head: HEAD, gitApi: fakeGit(["Cargo.lock"], { locks }) });
426 assert.deepEqual(decisions.map((d) => [d.unit.id, d.deploy]), [["events", false], ["webhooks", true]]);
427});
428
429test("decide: the runner's image rebuilds only when what it is built from changed", () => {
430 const live = { runner: { sha: OLD } };
431 const code = decide([unit("runner")], { live, head: HEAD, gitApi: fakeGit(["services/runner/src/index.ts"]) });
432 assert.deepEqual([code[0].deploy, code[0].image], [true, false]);
433 const image = decide([unit("runner")], { live, head: HEAD, gitApi: fakeGit(["crates/runner/src/main.rs"]) });
434 assert.deepEqual([image[0].deploy, image[0].image], [true, true]);
435});
436
437test("the plan as data: migrations, and each stage's units in jobs that share a build", () => {
438 const units = ["events", "repos", "projects", "api", "web", "docs"].map(unit);
439 const decisions = units.map((u) => ({ unit: u, deploy: true, reason: "x", since: null, image: false }));
440 const data = planJson(stack, decisions, { events: { pending: ["0003_x.sql"] }, repos: { pending: [] } }, HEAD);
441 assert.deepEqual(data.migrations, [{ unit: "events", database: "g1t-events", pending: ["0003_x.sql"] }]);
442 assert.deepEqual(data.stages.core.jobs, [
443 { group: "rust", units: "events,repos", rust: true },
444 { group: "ts", units: "projects", rust: false },
445 ]);
446 assert.deepEqual(data.stages.edge.jobs, [{ group: "rust", units: "api", rust: true }]);
447 assert.deepEqual(data.stages.front.jobs, [
448 { group: "web", units: "web", rust: false },
449 { group: "docs", units: "docs", rust: false },
450 ]);
451 assert.deepEqual(data.stage_order, ["core", "edge", "front"]);
452 assert.deepEqual(buildGroups([]), []);
453 // Ten Rust workers go to three jobs; a unit whose image rebuilds gets its own.
454 const core = stack.units.filter((u) => u.stage === "core");
455 const jobs = buildGroups(core, ["runner"]);
456 assert.deepEqual(jobs.filter((j) => j.rust).map((j) => j.units.split(",").length), [4, 3, 3]);
457 assert.ok(jobs.some((j) => j.group === "runner-image" && j.units === "runner"));
458 assert.ok(!jobs.find((j) => j.group === "ts").units.includes("runner"));
459});
460
461test("units are picked by short name, folder or Worker name", () => {
462 assert.deepEqual(pick(stack, ["billing,services/web".replace("services/web", "apps/web"), "g1t-api"]).map((u) => u.id), ["billing", "web", "api"]);
463 assert.throws(() => pick(stack, ["nope"]), /No unit called nope/);
464});
465
466test("a CI job installs only what its units need", () => {
467 const npm = npmWorkspace();
468 assert.deepEqual(npmCiArgs([unit("events"), unit("repos")], npm), ["ci", "--no-audit", "--no-fund", "--workspaces=false"]);
469 assert.deepEqual(npmCiArgs([unit("events"), unit("status")], npm), [
470 "ci", "--no-audit", "--no-fund", "--include-workspace-root",
471 "-w", "@g1t/contracts", "-w", "@g1t/status", "-w", "@g1t/theme",
472 ]);
473});
474
475// ── Cloudflare's answers ──────────────────────────────────────────────────
476
477const version = (id, number, message, triggered = "deployment") => ({
478 id,
479 number,
480 metadata: { created_on: "2026-10-05T00:00:00Z", author_email: "a@b" },
481 annotations: { "workers/triggered_by": triggered, ...(message ? { "workers/message": message } : {}) },
482});
483
484test("a deploy is annotated with its commit, and read back", () => {
485 const { message, tag } = annotation(HEAD, "A subject ".repeat(20));
486 assert.ok(message.length <= 100);
487 assert.equal(commitFrom(message), HEAD);
488 assert.equal(tag, `g1t-${HEAD.slice(0, 12)}`);
489 assert.equal(commitFrom(message.replace("g1t-deploy", "g1t-deploy-dirty")), null);
490 assert.equal(commitFrom("deployed by hand"), null);
491});
492
493test("the live commit: the live version's, looking through secret changes", () => {
494 const versions = [version("v1", 1, annotation(OLD).message), version("v2", 2, null, "secret"), version("v3", 3, null, "version_upload")];
495 const status = (id) => ({ versions: [{ version_id: id, percentage: 100 }] });
496 assert.equal(liveCommit(status("v1"), versions).sha, OLD);
497 assert.equal(liveCommit(status("v2"), versions).sha, OLD);
498 assert.equal(liveCommit(status("v3"), versions).sha, null);
499 assert.match(liveCommit(status("v9"), versions).why, /not among/);
500 const split = liveCommit({ versions: [{ version_id: "v1", percentage: 10 }, { version_id: "v2", percentage: 90 }] }, versions);
501 assert.equal(split.sha, OLD);
502 assert.equal(split.split, true);
503});
504
505test("Wrangler's output: pending migrations and the version a deploy made", () => {
506 const pending = `
507 ⛅️ wrangler 4.146.0
508Resource location: remote
509Migrations to be applied:
510┌──────────────────────┐
511│ Name │
512├──────────────────────┤
513│ 0021_confidence.sql │
514├──────────────────────┤
515│ 0022_more.sql │
516└──────────────────────┘`;
517 assert.deepEqual(pendingFrom(pending), ["0021_confidence.sql", "0022_more.sql"]);
518 assert.deepEqual(pendingFrom("Resource location: remote\n\n✅ No migrations to apply!"), []);
519 assert.equal(versionFrom("Deployed g1t-events triggers\nCurrent Version ID: 2c7fc93a-82d9-4850-8a77-ba887d157a4f\n"), "2c7fc93a-82d9-4850-8a77-ba887d157a4f");
520});
521
522test("the pool runs everything, no more than its limit at once", async () => {
523 let running = 0;
524 let most = 0;
525 const out = await pool([1, 2, 3, 4, 5, 6, 7], 3, async (n) => {
526 running++;
527 most = Math.max(most, running);
528 await new Promise((resolve) => setTimeout(resolve, 5));
529 running--;
530 return n * 2;
531 });
532 assert.deepEqual(out, [2, 4, 6, 8, 10, 12, 14]);
533 assert.equal(most, 3);
534});
535
536// ── Everything else that reads the list ───────────────────────────────────
537
538test("self-hosting builds every Rust service the manifest says it runs", () => {
539 const dockerfile = readFileSync(join(ROOT, "deploy/self-host/Dockerfile"), "utf8");
540 const loops = [...dockerfile.matchAll(/for service in ([a-z ]+); do/g)].map((m) => m[1].trim().split(/\s+/).sort());
541 const wanted = stack.units.filter((u) => u.self_host === "run" && u.kind === "rust-worker").map((u) => u.path.split("/").pop()).sort();
542 assert.ok(loops.length >= 2);
543 for (const loop of loops) assert.deepEqual(loop, wanted);
544});
545
546test("docs/SELF_HOSTING.md's table names every unit", () => {
547 const doc = readFileSync(join(ROOT, "docs/SELF_HOSTING.md"), "utf8");
548 for (const u of stack.units) assert.ok(doc.includes(`| \`${u.path}\` |`), `${u.path} is missing from docs/SELF_HOSTING.md`);
549});
550
551test("resolveStack works on a manifest with no workspace crates or packages", () => {
552 const bare = resolveStack(loadStack(), { cargo: new Map(), npm: new Map() });
553 assert.deepEqual(bare.units.find((u) => u.id === "events").dependsOn, []);
554});