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