import * as Prisma from "@alchemy.run/prisma";
import { expect } from "@alchemy.run/test";
import * as Test from "@alchemy.run/test/Alchemy";
import { getProject, getService } from "@distilled.cloud/prisma/management";
import * as Effect from "effect/Effect";
import * as HttpClient from "effect/http/HttpClient";
import { MinimumLogLevel } from "effect/References";
import * as Schedule from "effect/Schedule";
import { materializeIsolatedProject, removeIsolatedProject } from "../IsolatedProject.ts";
import IsolatedProjectCompute, { project } from "./fixtures/isolated-project-compute.ts";
const { test } = Test.make({ providers: Prisma.providers() });
const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
// Live proof that the Prisma Compute bun bootstrap boots when the app's
// `main` lives in an isolated project (see test/IsolatedProject.ts) — the
// bundle `cwd` resolves none of alchemy's dependencies, so the bootstrap's
// `@effect/platform-bun` / `alchemy/*` imports must be bundled by the
// virtual-entry plugin rather than found from the project root. With them
// left external bun dies at module load and the app never answers.
test.provider(
"app bundled from an isolated project serves HTTP",
(stack) =>
Effect.gen(function* () {
yield* materializeIsolatedProject(project);
yield* stack.destroy();
try {
const app = yield* stack.deploy(
Effect.gen(function* () {
return yield* IsolatedProjectCompute;
}),
);
expect(app.url).toBeTruthy();
const health = yield* HttpClient.get(new URL("/health", app.url)).pipe(
Effect.flatMap((res) =>
res.status === 200
? res.json
: Effect.fail(new Error(`/health returned ${res.status}`)),
),
Effect.retry({ schedule: Schedule.spaced("2 seconds"), times: 30 }),
);
expect(health).toEqual({ ok: true });
yield* stack.destroy();
const projectGone = yield* getProject({ id: app.projectId }).pipe(
Effect.as(false),
Effect.catchTag("NotFound", () => Effect.succeed(true)),
);
const appGone = yield* getService({ serviceId: app.appId }).pipe(
Effect.as(false),
Effect.catchTag("NotFound", () => Effect.succeed(true)),
);
expect(projectGone).toBe(true);
expect(appGone).toBe(true);
} finally {
yield* stack.destroy().pipe(Effect.ignore);
yield* removeIsolatedProject(project);
}
}).pipe(logLevel),
// One Prisma Compute deploy alone can take the full 600s.
{
tags: ["provider:prisma", "provider:prisma:compute", "provider:prisma:project", "live"],
timeout: 1_200_000,
},
);