@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 69 lines 2.89 KB
Raw
1 import * as Prisma from "@alchemy.run/prisma";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import { getProject, getService } from "@distilled.cloud/prisma/management";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as HttpClient from "effect/http/HttpClient";
8 import * as Path from "effect/Path";
9 import { bodyContaining, copyViteFixture } from "./Fixture.ts";
10
11 const { test } = Test.make({ providers: Prisma.providers() });
12
13 test.provider(
14 "Vite publishes real builds, memoizes unchanged content, updates in place, and cleans up",
15 (stack) =>
16 Effect.gen(function* () {
17 yield* stack.destroy();
18 const fs = yield* FileSystem.FileSystem;
19 const path = yield* Path.Path;
20 const rootDir = yield* copyViteFixture;
21 const deploy = (fallback: "single-page-application" | "none" = "single-page-application") =>
22 stack.deploy(
23 Prisma.Website.Vite("Web", {
24 rootDir,
25 assets: { notFoundHandling: fallback },
26 vite: { outDir: "build" },
27 memo: { include: ["index.html", "main.ts", "package.json"] },
28 }).pipe(Effect.map((site) => ({ site }))),
29 );
30 const initial = (yield* deploy()).site;
31 expect(initial.url).toMatch(/^https:\/\//);
32 const projectId = initial.compute!.projectId;
33 const appId = initial.compute!.appId;
34 yield* bodyContaining(`${initial.url}/client/route`, "Prisma Website fixture");
35 yield* bodyContaining(`${initial.url}/health`, "ok");
36 const unchanged = (yield* deploy()).site;
37 expect(unchanged.compute!.deploymentId).toBe(initial.compute!.deploymentId);
38 const indexPath = path.join(rootDir, "index.html");
39 const index = yield* fs.readFileString(indexPath);
40 yield* fs.writeFileString(
41 indexPath,
42 index.replaceAll("Prisma Website fixture", "Prisma Website updated"),
43 );
44 const updated = (yield* deploy("none")).site;
45 expect(updated.compute!.appId).toBe(appId);
46 expect(updated.compute!.projectId).toBe(projectId);
47 expect(updated.compute!.deploymentId).not.toBe(initial.compute!.deploymentId);
48 yield* bodyContaining(`${updated.url}/`, "Prisma Website updated");
49 const missing = yield* HttpClient.get(`${updated.url}/missing-client-route`);
50 expect(missing.status).toBe(404);
51 yield* stack.destroy();
52 expect(
53 yield* getService({ serviceId: appId }).pipe(
54 Effect.as(false),
55 Effect.catchTag("NotFound", () => Effect.succeed(true)),
56 ),
57 ).toBe(true);
58 expect(
59 yield* getProject({ id: projectId }).pipe(
60 Effect.as(false),
61 Effect.catchTag("NotFound", () => Effect.succeed(true)),
62 ),
63 ).toBe(true);
64 }).pipe(Effect.scoped),
65 {
66 tags: ["provider:prisma", "provider:prisma:website", "live"],
67 timeout: 120_000,
68 },
69 );