mirror of
https://github.com/VibedByKaKi/t3-code-android-nightly.git
synced 2026-10-17 15:57:43 +02:00
128 lines
3.6 KiB
TypeScript
128 lines
3.6 KiB
TypeScript
import * as Hetzner from "@/Hetzner";
|
|
import * as Test from "@/Test/Alchemy";
|
|
import * as servers from "@distilled.cloud/hetzner/servers";
|
|
import { expect } from "alchemy-test";
|
|
import * as Effect from "effect/Effect";
|
|
import { MinimumLogLevel } from "effect/References";
|
|
import * as Schedule from "effect/Schedule";
|
|
import * as HttpClient from "effect/http/HttpClient";
|
|
import * as pathe from "pathe";
|
|
import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
|
|
import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
|
|
|
|
const { test } = Test.make({ providers: Hetzner.providers() });
|
|
|
|
const logLevel = Effect.provideService(
|
|
MinimumLogLevel,
|
|
process.env.DEBUG ? "Debug" : "Info",
|
|
);
|
|
|
|
const hasHetznerCreds = !!process.env.HCLOUD_TOKEN;
|
|
|
|
const fixtureDir = pathe.resolve(
|
|
import.meta.dirname,
|
|
"../../AWS/Website/fixtures/astro-app",
|
|
);
|
|
const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
|
|
const fixtureEntries = [
|
|
".gitignore",
|
|
"package.json",
|
|
"astro.config.mjs",
|
|
"src",
|
|
"public",
|
|
];
|
|
|
|
const waitUntilGone = (id: number) =>
|
|
servers.getServer({ id }).pipe(
|
|
Effect.as("found" as const),
|
|
Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
|
|
Effect.repeat({
|
|
schedule: Schedule.spaced("1 second"),
|
|
until: (status) => status === "gone",
|
|
times: 10,
|
|
}),
|
|
);
|
|
|
|
test.provider.skipIf(!hasHetznerCreds)(
|
|
"Astro SSR: GET / and a dynamic API route",
|
|
(stack) =>
|
|
Effect.gen(function* () {
|
|
yield* stack.destroy();
|
|
|
|
const rootDir = yield* cloneFixture(fixtureDir, {
|
|
prefix: "alchemy-astro-hetzner-",
|
|
tempRoot,
|
|
entries: fixtureEntries,
|
|
});
|
|
|
|
const deployed = yield* stack.deploy(
|
|
Effect.gen(function* () {
|
|
const site = yield* Hetzner.Website.Astro("Web", {
|
|
rootDir,
|
|
memo: {
|
|
include: [
|
|
"src/**",
|
|
"public/**",
|
|
"package.json",
|
|
"astro.config.mjs",
|
|
],
|
|
},
|
|
});
|
|
return { site };
|
|
}),
|
|
);
|
|
|
|
const url = deployed.site.url;
|
|
expect(url).toBeDefined();
|
|
expect(url).toMatch(/^http:\/\//);
|
|
expect(deployed.site.service).toBeDefined();
|
|
expect(deployed.site.server).toBeDefined();
|
|
|
|
yield* expectUrlContains(`${url!}/`, "ASTRO_AWS_PAGE_MARKER", {
|
|
timeout: "90 seconds",
|
|
label: "astro ssr home",
|
|
});
|
|
yield* expectUrlContains(
|
|
`${url!}/api/hello?echo=roundtrip`,
|
|
"ASTRO_AWS_API_MARKER",
|
|
{
|
|
timeout: "30 seconds",
|
|
label: "astro api route",
|
|
},
|
|
);
|
|
|
|
const client = yield* HttpClient.HttpClient;
|
|
const health = yield* client.get(`${url!}/health`).pipe(
|
|
Effect.flatMap((res) =>
|
|
res.status === 200
|
|
? res.text
|
|
: Effect.fail(new Error(`health returned ${res.status}`)),
|
|
),
|
|
Effect.retry({
|
|
schedule: Schedule.exponential("500 millis"),
|
|
times: 10,
|
|
}),
|
|
);
|
|
expect(health).toContain("ok");
|
|
|
|
const serverId = deployed.site.server!.serverId;
|
|
yield* stack.destroy();
|
|
const gone = yield* waitUntilGone(serverId);
|
|
expect(gone).toEqual("gone");
|
|
}).pipe(
|
|
logLevel,
|
|
Effect.ensuring(stack.destroy().pipe(Effect.orDie)),
|
|
Effect.catchTag(["PreconditionFailed", "Forbidden"], (error) =>
|
|
Effect.logWarning(`skipping: Hetzner quota (${error._tag})`),
|
|
),
|
|
),
|
|
{
|
|
tags: [
|
|
"provider:hetzner",
|
|
"provider:hetzner:service",
|
|
"provider:hetzner:website",
|
|
"live",
|
|
],
|
|
timeout: 180_000,
|
|
},
|
|
);
|