Public: anyone can read this; the crew can change it.
A boot keeps its previews' checkouts, so they come back asleep instead of all deploying (#17629) #17726
Merged 19h 8m ago, live in production
boot-previews-asleep → main 0 commits
2 files
changed +34
−1
src/apps/runtime.ts +3 −1
| @@ -357,7 +357,9 @@ export class AppsRuntime { | ||
| 357 | 357 | await this.teardown(record, name); |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | if (reason === "boot") await this.dropStrayCheckouts(record); | |
| 360 | // Not in the production pass: no preview is in state yet, so every one's checkout would read as a | |
| 361 | // stray, and the preview pass would find nothing to settle asleep and deploy them all. | |
| 362 | if (reason === "boot" && only !== "production") await this.dropStrayCheckouts(record); | |
| 361 | 363 | } |
| 362 | 364 | dropStrayCheckouts(...a: Tail<typeof runtime_events.dropStrayCheckouts>) { |
| 363 | 365 | return runtime_events.dropStrayCheckouts(this, ...a); |
test/stray-checkouts.test.ts +31
| @@ -108,4 +108,35 @@ describe("dropStrayCheckouts", () => { | ||
| 108 | 108 | expect(existsSync(stray)).toBe(false); |
| 109 | 109 | await runtime.stop(); |
| 110 | 110 | }, 60_000); |
| 111 | ||
| 112 | test("booting in two passes, as start() does, keeps an old preview's checkout and settles it asleep", async () => { | |
| 113 | const runtime = new AppsRuntime(forge.app, { domain: "apps.test", scheme: "http", publicPort: 1, forgeUrl: forge.servers.url }); | |
| 114 | const branch = await commitToBranch(forge.app, forge.alice, repo, { | |
| 115 | branch: "feature/y", | |
| 116 | base: "main", | |
| 117 | message: "y", | |
| 118 | files: [{ path: "y.md", content: "y\n" }], | |
| 119 | }); | |
| 120 | if (!branch.ok) throw new Error(JSON.stringify(branch.error)); | |
| 121 | const opened = await openPull(forge.app, forge.alice, repo, { title: "y", baseBranch: "main", headBranch: "feature/y" }); | |
| 122 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 123 | const env = `pull-${opened.value.number}` as const; | |
| 124 | const head = (await runtime.pullHead(repo, opened.value))!; | |
| 125 | const headDir = make(env, head.slice(0, 7)); | |
| 126 | writeFileSync(join(headDir, "package.json"), JSON.stringify({ name: "y", scripts: { start: "true" } })); | |
| 127 | // Writing the file touched the directory: it is as old as a checkout from an earlier life. | |
| 128 | utimesSync(headDir, OLD, OLD); | |
| 129 | const stray = make(env, "ddddddd"); | |
| 130 | try { | |
| 131 | await runtime.reconcileApp(record, repo, "boot", "production"); | |
| 132 | expect(existsSync(headDir)).toBe(true); | |
| 133 | await runtime.reconcileApp(record, repo, "boot", "preview"); | |
| 134 | expect(existsSync(headDir)).toBe(true); | |
| 135 | expect(existsSync(stray)).toBe(false); | |
| 136 | // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| 137 | expect((runtime as any).envFor(record, env).asleep?.commitOid).toBe(head); | |
| 138 | } finally { | |
| 139 | await runtime.stop(); | |
| 140 | } | |
| 141 | }, 60_000); | |
| 111 | 142 | }); |
new above
offline