The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as FileSystem from "effect/FileSystem"; |
| 6 | import * as Path from "effect/Path"; |
| 7 | import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts"; |
| 8 | import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts"; |
| 9 | import { |
| 10 | assertSiteGone, |
| 11 | cloudflareFixture, |
| 12 | cloudRunUrl, |
| 13 | liveOptions, |
| 14 | logLevel, |
| 15 | serviceIdentity, |
| 16 | tempRoot, |
| 17 | } from "./site.ts"; |
| 18 | |
| 19 | const { test } = Test.make({ providers: GCP.providers() }); |
| 20 | |
| 21 | test.provider( |
| 22 | "StaticSite: build v1, rebuild to v2 in place, destroy, gone", |
| 23 | (stack) => |
| 24 | Effect.gen(function* () { |
| 25 | yield* stack.destroy(); |
| 26 | const fs = yield* FileSystem.FileSystem; |
| 27 | const path = yield* Path.Path; |
| 28 | const cwd = yield* cloneFixture(cloudflareFixture("staticsite-fixture"), { |
| 29 | prefix: "alchemy-staticsite-gcp-", |
| 30 | tempRoot, |
| 31 | entries: ["src", "build.sh"], |
| 32 | }); |
| 33 | const deploy = () => |
| 34 | stack.deploy( |
| 35 | Effect.gen(function* () { |
| 36 | const site = yield* GCP.Website.StaticSite("Blog", { |
| 37 | path: cwd, |
| 38 | build: { command: "bash build.sh", output: "dist" }, |
| 39 | memo: { include: ["src/**", "build.sh"] }, |
| 40 | }); |
| 41 | return { site }; |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | const first = yield* deploy(); |
| 46 | const url = first.site.url as string; |
| 47 | expect(url).toMatch(cloudRunUrl); |
| 48 | const service = serviceIdentity(first.site.service!); |
| 49 | yield* expectUrlContains(`${url}/`, "StaticSite fixture v1", { |
| 50 | timeout: "180 seconds", |
| 51 | label: "static v1", |
| 52 | }); |
| 53 | |
| 54 | const index = path.join(cwd, "src/index.html"); |
| 55 | yield* fs.writeFileString( |
| 56 | index, |
| 57 | (yield* fs.readFileString(index)).replaceAll("fixture v1", "fixture v2"), |
| 58 | ); |
| 59 | const second = yield* deploy(); |
| 60 | expect(second.site.url).toBe(url); |
| 61 | expect(second.site.service!.codeHash).not.toBe(first.site.service!.codeHash); |
| 62 | yield* expectUrlContains(`${url}/`, "StaticSite fixture v2", { |
| 63 | timeout: "60 seconds", |
| 64 | label: "static v2", |
| 65 | }); |
| 66 | |
| 67 | yield* stack.destroy(); |
| 68 | yield* assertSiteGone(service); |
| 69 | }).pipe(logLevel), |
| 70 | liveOptions(1_200_000), |
| 71 | ); |