@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, 04:45 UTC

main
ts 151 lines 5.64 KB
Raw
1 import * as NodeServices from "@effect/platform-node/NodeServices";
2 import * as Effect from "effect/Effect";
3 import * as FileSystem from "effect/FileSystem";
4 import * as Path from "effect/Path";
5 import type * as Scope from "effect/Scope";
6 import { describe, expect, it } from "vitest";
7 import { makeAwsTarget } from "../aws.ts";
8 import { fromHarnessOptions } from "../index.ts";
9 import {
10 DEFAULT_TARGET_SPECIFIER,
11 make,
12 readNitroOutput,
13 SERVER_ENTRY_NAME,
14 type SolidStartTarget,
15 } from "../SolidStart.ts";
16
17 const runWithNode = <A, E>(
18 effect: Effect.Effect<A, E, FileSystem.FileSystem | Path.Path | Scope.Scope>,
19 ): Promise<A> =>
20 Effect.runPromise(
21 Effect.scoped(effect).pipe(Effect.provide(NodeServices.layer)) as Effect.Effect<A, E>,
22 );
23
24 describe("readNitroOutput", () => {
25 it("maps a nitro .output tree onto the BuildOutput contract, entry first", async () => {
26 const output = await runWithNode(
27 Effect.gen(function* () {
28 const fs = yield* FileSystem.FileSystem;
29 const path = yield* Path.Path;
30 const dir = yield* fs.makeTempDirectoryScoped({
31 prefix: "solidstart-output-",
32 });
33 const serverDir = path.join(dir, "server");
34 const publicDir = path.join(dir, "public");
35 yield* fs.makeDirectory(path.join(serverDir, "chunks"), {
36 recursive: true,
37 });
38 yield* fs.makeDirectory(publicDir, { recursive: true });
39 // alphabetically before index.mjs, to prove entry-first sorting
40 yield* fs.writeFileString(path.join(serverDir, "chunks", "a.mjs"), "export const a = 1;");
41 yield* fs.writeFileString(
42 path.join(serverDir, "index.mjs"),
43 "export const handler = () => {};",
44 );
45 yield* fs.writeFileString(path.join(publicDir, "robots.txt"), "User-agent: *\n");
46 return yield* readNitroOutput({ dir, serverDir, publicDir });
47 }),
48 );
49 expect(output.serverModules?.map((module) => module.name)).toEqual([
50 SERVER_ENTRY_NAME,
51 "server/chunks/a.mjs",
52 ]);
53 expect(output.serverModules?.[0]?.hash).toMatch(/^[0-9a-f]{64}$/);
54 expect(output.clientDirectory?.endsWith("public")).toBe(true);
55 expect(output.distDirectory).toBeDefined();
56 expect(output.externalWorkspaces.size).toBe(0);
57 });
58
59 it("fails when the server directory has no index.mjs entry", async () => {
60 const result = await runWithNode(
61 Effect.gen(function* () {
62 const fs = yield* FileSystem.FileSystem;
63 const path = yield* Path.Path;
64 const dir = yield* fs.makeTempDirectoryScoped({
65 prefix: "solidstart-output-",
66 });
67 const serverDir = path.join(dir, "server");
68 yield* fs.makeDirectory(serverDir, { recursive: true });
69 yield* fs.writeFileString(path.join(serverDir, "other.mjs"), "export const x = 1;");
70 return yield* Effect.result(
71 readNitroOutput({
72 dir,
73 serverDir,
74 publicDir: path.join(dir, "public"),
75 }),
76 );
77 }),
78 );
79 expect(result._tag).toBe("Failure");
80 if (result._tag === "Failure") {
81 expect(String(result.failure)).toContain("server/index.mjs");
82 }
83 });
84 });
85
86 describe("make", () => {
87 it("defaults to this package's AWS deploy target", () => {
88 expect(DEFAULT_TARGET_SPECIFIER).toBe("@alchemy.run/frontend-frameworks/solidstart/aws");
89 });
90
91 it("rejects a caller-supplied nitro preset that fights the deploy target", async () => {
92 const result = await runWithNode(
93 Effect.gen(function* () {
94 const framework = yield* make({
95 root: "/tmp/does-not-matter",
96 // The adapter-only target: no wholesale `build`, so the preset
97 // conflict check runs before anything touches the project.
98 target: adapterOnly(makeAwsTarget()),
99 nitro: { preset: "netlify" },
100 });
101 return yield* Effect.result(framework.build({ root: "/tmp/does-not-matter" }));
102 }),
103 );
104 expect(result._tag).toBe("Failure");
105 if (result._tag === "Failure") {
106 expect(result.failure._tag).toBe("FrameworkError");
107 expect(result.failure.message).toContain('"netlify"');
108 expect(result.failure.message).toContain('"aws-lambda"');
109 }
110 });
111
112 it("build fails with a descriptive FrameworkError outside a SolidStart project", async () => {
113 // /tmp has no vite install: loading the project's Vite is the first
114 // step after the target resolves and must surface a FrameworkError.
115 const result = await runWithNode(
116 Effect.gen(function* () {
117 const framework = yield* make({
118 root: "/tmp/does-not-matter",
119 target: adapterOnly(makeAwsTarget()),
120 });
121 return yield* Effect.result(framework.build({ root: "/tmp/does-not-matter" }));
122 }),
123 );
124 expect(result._tag).toBe("Failure");
125 if (result._tag === "Failure") {
126 expect(result.failure._tag).toBe("FrameworkError");
127 expect(result.failure.framework).toBe("solidstart");
128 }
129 });
130
131 it("exposes the framework contract (build + dev)", async () => {
132 const framework = await runWithNode(make({ root: "/tmp/does-not-matter" }));
133 expect(typeof framework.build).toBe("function");
134 expect(typeof framework.dev).toBe("function");
135 });
136 });
137
138 describe("fromHarnessOptions", () => {
139 it("forwards the harness's nitro overrides", () => {
140 expect(fromHarnessOptions({ solidstart: { nitro: { prerender: {} } } }).nitro).toEqual({
141 prerender: {},
142 });
143 expect(fromHarnessOptions({}).nitro).toBeUndefined();
144 });
145 });
146
147 /** Drop the wholesale `build` hook so the in-process pipeline runs. */
148 const adapterOnly = (target: SolidStartTarget): SolidStartTarget => {
149 const { build: _build, ...rest } = target;
150 return rest;
151 };