Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

bin.test.ts

612 lines23.0 KB

1// @effect-diagnostics nodeBuiltinImport:off - CLI integration exercises Node HTTP and filesystem boundaries.
2import * as NodeHttp from "node:http";
3import * as NodeFS from "node:fs";
4import * as NodeOS from "node:os";
5import * as NodePath from "node:path";
6​
7import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
8import * as NodeServices from "@effect/platform-node/NodeServices";
9import {
10 CommandId,
11 EnvironmentOrchestrationHttpApi,
12 ProviderInstanceId,
13 ThreadId,
14} from "@t3tools/contracts";
15import * as NetService from "@t3tools/shared/Net";
16import { assert, it } from "@effect/vitest";
17import * as Effect from "effect/Effect";
18import * as DateTime from "effect/DateTime";
19import * as Layer from "effect/Layer";
20import * as HttpRouter from "effect/unstable/http/HttpRouter";
21import * as HttpServer from "effect/unstable/http/HttpServer";
22import * as HttpApi from "effect/unstable/httpapi/HttpApi";
23import * as HttpApiBuilder from "effect/unstable/httpapi/HttpApiBuilder";
24import * as CliError from "effect/unstable/cli/CliError";
25import * as TestConsole from "effect/testing/TestConsole";
26import { Command } from "effect/unstable/cli";
27​
28import { cli, makeCli } from "./bin.ts";
29import * as ServerConfig from "./config.ts";
30import * as ProjectionSnapshotQuery from "./orchestration/Services/ProjectionSnapshotQuery.ts";
31import * as OrchestrationEngine from "./orchestration/Services/OrchestrationEngine.ts";
32import { OrchestrationLayerLive } from "./orchestration/runtimeLayer.ts";
33import { orchestrationHttpApiLayer } from "./orchestration/http.ts";
34import { layerConfig as SqlitePersistenceLayerLive } from "./persistence/Layers/Sqlite.ts";
35import * as RepositoryIdentityResolver from "./project/RepositoryIdentityResolver.ts";
36import {
37 makePersistedServerRuntimeState,
38 persistServerRuntimeState,
39} from "./serverRuntimeState.ts";
40import * as WorkspacePaths from "./workspace/WorkspacePaths.ts";
41import * as ServerSecretStore from "./auth/ServerSecretStore.ts";
42import * as EnvironmentAuth from "./auth/EnvironmentAuth.ts";
43import { environmentAuthenticatedAuthLayer } from "./auth/http.ts";
44import * as ServerSelfUpdate from "./cloud/selfUpdate.ts";
45​
46const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
47const ServerSelfUpdatePassThroughLayer = Layer.succeed(
48 ServerSelfUpdate.ServerSelfUpdate,
49 ServerSelfUpdate.ServerSelfUpdate.of({
50 update: () => Effect.die(new Error("server update is unused in this test")),
51 withCommandAdmission: (effect) => effect,
52 }),
53);
54class ProjectCliHttpApi extends HttpApi.make("environment").add(EnvironmentOrchestrationHttpApi) {}
55​
56const connectCli = makeCli({ cloudEnabled: true });
57const noConnectCli = makeCli({ cloudEnabled: false });
58const runCli = (args: ReadonlyArray<string>, command = cli) =>
59 Command.runWith(command, { version: "0.0.0" })(args);
60const runConnectCli = (args: ReadonlyArray<string>) => runCli(args, connectCli);
61const runCliWithRuntime = (args: ReadonlyArray<string>) =>
62 runCli(args).pipe(Effect.provide(CliRuntimeLayer));
63​
64const captureStdout = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
65 Effect.gen(function* () {
66 const result = yield* effect;
67 const output =
68 (yield* TestConsole.logLines).findLast((line): line is string => typeof line === "string") ??
69 "";
70 return { result, output };
71 }).pipe(Effect.provide(Layer.mergeAll(CliRuntimeLayer, TestConsole.layer)));
72​
73const makeCliTestServerConfig = (baseDir: string) =>
74 Effect.gen(function* () {
75 const derivedPaths = yield* ServerConfig.deriveServerPaths(baseDir, undefined);
76 return {
77 logLevel: "Info",
78 traceMinLevel: "Info",
79 traceTimingEnabled: true,
80 traceBatchWindowMs: 200,
81 traceMaxBytes: 10 * 1024 * 1024,
82 traceMaxFiles: 10,
83 otlpTracesUrl: undefined,
84 otlpMetricsUrl: undefined,
85 otlpExportIntervalMs: 10_000,
86 otlpServiceName: "t3-server",
87 mode: "web",
88 port: 0,
89 host: "127.0.0.1",
90 cwd: process.cwd(),
91 baseDir,
92 ...derivedPaths,
93 staticDir: undefined,
94 devUrl: undefined,
95 devAllowedOrigins: [],
96 noBrowser: true,
97 startupPresentation: "browser",
98 desktopBootstrapToken: undefined,
99 autoBootstrapProjectFromCwd: false,
100 logWebSocketEvents: false,
101 tailscaleServeEnabled: false,
102 tailscaleServePort: 443,
103 } satisfies ServerConfig.ServerConfig["Service"];
104 });
105​
106const makeProjectPersistenceLayer = (config: ServerConfig.ServerConfig["Service"]) =>
107 Layer.mergeAll(
108 OrchestrationLayerLive.pipe(
109 Layer.provideMerge(RepositoryIdentityResolver.layer),
110 Layer.provideMerge(SqlitePersistenceLayerLive),
111 ),
112 WorkspacePaths.layer,
113 ).pipe(Layer.provideMerge(NodeServices.layer), Layer.provide(ServerConfig.layer(config)));
114​
115const readPersistedSnapshot = (baseDir: string) =>
116 Effect.gen(function* () {
117 const config = yield* makeCliTestServerConfig(baseDir);
118 return yield* Effect.gen(function* () {
119 const projectionSnapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
120 return yield* projectionSnapshotQuery.getSnapshot();
121 }).pipe(Effect.provide(makeProjectPersistenceLayer(config)));
122 });
123​
124const withLiveProjectCliServer = <A, E, R>(baseDir: string, run: () => Effect.Effect<A, E, R>) =>
125 Effect.gen(function* () {
126 const config = yield* makeCliTestServerConfig(baseDir);
127 const routesLayer = HttpApiBuilder.layer(ProjectCliHttpApi).pipe(
128 Layer.provide(
129 orchestrationHttpApiLayer.pipe(Layer.provide(ServerSelfUpdatePassThroughLayer)),
130 ),
131 Layer.provide(environmentAuthenticatedAuthLayer),
132 );
133 const appLayer = HttpRouter.serve(routesLayer, {
134 disableListenLog: true,
135 disableLogger: true,
136 }).pipe(
137 Layer.provideMerge(
138 EnvironmentAuth.layer.pipe(
139 Layer.provideMerge(SqlitePersistenceLayerLive),
140 Layer.provide(ServerSecretStore.layer),
141 ),
142 ),
143 Layer.provideMerge(makeProjectPersistenceLayer(config)),
144 Layer.provideMerge(
145 NodeHttpServer.layer(NodeHttp.createServer, {
146 host: "127.0.0.1",
147 port: 0,
148 }),
149 ),
150 Layer.provideMerge(NodeServices.layer),
151 Layer.provide(ServerConfig.layer(config)),
152 );
153​
154 return yield* Effect.scoped(
155 Effect.gen(function* () {
156 const server = yield* HttpServer.HttpServer;
157 const address = server.address;
158 if (typeof address === "string" || !("port" in address)) {
159 assert.fail(`Expected TCP address, got ${address}`);
160 }
161 yield* persistServerRuntimeState({
162 path: config.serverRuntimeStatePath,
163 state: yield* makePersistedServerRuntimeState({
164 config,
165 port: address.port,
166 }),
167 });
168 return yield* run();
169 }).pipe(Effect.provide(Layer.mergeAll(appLayer, NodeServices.layer))),
170 );
171 });
172​
173it.layer(NodeServices.layer)("bin cli parsing", (it) => {
174 it.effect("accepts the built-in lowercase log-level flag values", () =>
175 runCliWithRuntime(["--log-level", "debug", "--version"]),
176 );
177​
178 it.effect("accepts canonical --no-<flag> boolean negation", () =>
179 runCliWithRuntime(["--no-log-websocket-events", "--version"]),
180 );
181​
182 it.effect("rejects invalid log-level casing before launching the server", () =>
183 Effect.gen(function* () {
184 const error = yield* runCliWithRuntime(["--log-level", "Debug"]).pipe(Effect.flip);
185​
186 if (!CliError.isCliError(error)) {
187 assert.fail(`Expected CliError, got ${String(error)}`);
188 }
189 if (error._tag !== "InvalidValue") {
190 assert.fail(`Expected InvalidValue, got ${error._tag}`);
191 }
192 assert.equal(error.option, "log-level");
193 assert.equal(error.value, "Debug");
194 }),
195 );
196​
197 it.effect("rejects connect commands when public configuration is missing", () =>
198 Effect.gen(function* () {
199 const error = yield* runCli(["connect", "status"], noConnectCli).pipe(Effect.flip);
200​
201 if (!CliError.isCliError(error)) {
202 assert.fail(`Expected CliError, got ${String(error)}`);
203 }
204 if (error._tag !== "ShowHelp") {
205 assert.fail(`Expected ShowHelp, got ${error._tag}`);
206 }
207 assert.deepEqual(error.commandPath, ["t3", "connect"]);
208 assert.include(error.errors[0]?.message ?? "", "missing T3 Connect public configuration");
209​
210 const output = (yield* TestConsole.errorLines).join("\n");
211 assert.include(output, "ERROR");
212 assert.include(output, "missing T3 Connect public configuration");
213 }).pipe(Effect.provide(Layer.mergeAll(CliRuntimeLayer, TestConsole.layer))),
214 );
215​
216 it.effect("exposes service lifecycle commands without T3 Connect configuration", () =>
217 Effect.gen(function* () {
218 const { output } = yield* captureStdout(runCli(["service", "--help"], noConnectCli));
219​
220 assert.include(output, "Manage the T3 Code background service.");
221 assert.include(output, "install");
222 assert.include(output, "uninstall");
223 assert.include(output, "update");
224 assert.include(output, "status");
225 }),
226 );
227​
228 it.effect("reports fresh headless connect state without requiring local configuration", () =>
229 Effect.gen(function* () {
230 const baseDir = NodeFS.mkdtempSync(
231 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-status-test-"),
232 );
233 const { output } = yield* captureStdout(
234 runConnectCli(["connect", "status", "--base-dir", baseDir, "--json"]),
235 );
236 // @effect-diagnostics-next-line preferSchemaOverJson:off - CLI JSON output is decoded as a presentation DTO.
237 const status = JSON.parse(output) as {
238 readonly desired: boolean;
239 readonly authenticated: boolean;
240 readonly linked: boolean;
241 readonly cloudUserId: string | null;
242 readonly relayUrl: string | null;
243 };
244​
245 assert.equal(status.desired, false);
246 assert.equal(status.authenticated, false);
247 assert.equal(status.linked, false);
248 assert.equal(status.cloudUserId, null);
249 assert.equal(status.relayUrl, null);
250 }),
251 );
252​
253 it.effect("reports actionable human-readable headless connect state", () =>
254 Effect.gen(function* () {
255 const baseDir = NodeFS.mkdtempSync(
256 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-status-human-test-"),
257 );
258 const { output } = yield* captureStdout(
259 runConnectCli(["connect", "status", "--base-dir", baseDir]),
260 );
261​
262 assert.include(output, "T3 Connect\n Exposure: disabled");
263 assert.include(output, " Authorization: missing");
264 assert.include(output, " Environment link: not provisioned");
265 assert.include(output, "Next: Run `t3 connect link` to authorize and enable T3 Connect.");
266 }),
267 );
268​
269 it.effect("accepts the --headless login override without enabling access", () =>
270 Effect.gen(function* () {
271 const baseDir = NodeFS.mkdtempSync(
272 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-login-test-"),
273 );
274 const { secretsDir } = yield* ServerConfig.deriveServerPaths(baseDir, undefined);
275 NodeFS.mkdirSync(secretsDir, { recursive: true });
276 NodeFS.writeFileSync(
277 NodePath.join(secretsDir, "cloud-cli-oauth-token.bin"),
278 // @effect-diagnostics-next-line preferSchemaOverJson:off - Test fixture matches the persisted CLI token representation.
279 JSON.stringify({
280 accessToken: "access-token",
281 refreshToken: "refresh-token",
282 expiresAtEpochMs: Number.MAX_SAFE_INTEGER,
283 }),
284 );
285​
286 const login = yield* captureStdout(
287 runConnectCli(["connect", "login", "--base-dir", baseDir, "--headless"]),
288 );
289 const status = yield* captureStdout(
290 runConnectCli(["connect", "status", "--base-dir", baseDir, "--json"]),
291 );
292 // @effect-diagnostics-next-line preferSchemaOverJson:off - CLI JSON output is decoded as a presentation DTO.
293 const decoded = JSON.parse(status.output) as {
294 readonly desired: boolean;
295 readonly authenticated: boolean;
296 };
297​
298 assert.equal(login.output, "✓ Signed in");
299 assert.isFalse(decoded.desired);
300 assert.isTrue(decoded.authenticated);
301 }),
302 );
303​
304 it.effect("disables headless connect without a running server", () =>
305 Effect.gen(function* () {
306 const baseDir = NodeFS.mkdtempSync(
307 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-unlink-test-"),
308 );
309 const { output } = yield* captureStdout(
310 runConnectCli(["connect", "unlink", "--base-dir", baseDir]),
311 );
312​
313 assert.equal(output, "T3 Connect is disabled locally.");
314 }),
315 );
316​
317 it.effect("logs out of headless connect and removes the stored CLI authorization", () =>
318 Effect.gen(function* () {
319 const baseDir = NodeFS.mkdtempSync(
320 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-logout-test-"),
321 );
322 const { secretsDir } = yield* ServerConfig.deriveServerPaths(baseDir, undefined);
323 const tokenPath = NodePath.join(secretsDir, "cloud-cli-oauth-token.bin");
324 NodeFS.mkdirSync(secretsDir, { recursive: true });
325 NodeFS.writeFileSync(tokenPath, "invalid persisted token");
326​
327 const { output } = yield* captureStdout(
328 runConnectCli(["connect", "logout", "--base-dir", baseDir]),
329 );
330​
331 assert.equal(
332 output,
333 "Signed out of T3 Connect locally.\nThe background service is managed separately with `t3 service`.",
334 );
335 assert.isFalse(NodeFS.existsSync(tokenPath));
336 }),
337 );
338​
339 it.effect("executes auth pairing subcommands and redacts secrets from list output", () =>
340 Effect.gen(function* () {
341 const baseDir = NodeFS.mkdtempSync(
342 NodePath.join(NodeOS.tmpdir(), "t3-cli-auth-pairing-test-"),
343 );
344​
345 const createdOutput = yield* captureStdout(
346 runCli(["auth", "pairing", "create", "--base-dir", baseDir, "--json"]),
347 );
348 // @effect-diagnostics-next-line preferSchemaOverJson:off
349 const created = JSON.parse(createdOutput.output) as {
350 readonly id: string;
351 readonly credential: string;
352 };
353 const listedOutput = yield* captureStdout(
354 runCli(["auth", "pairing", "list", "--base-dir", baseDir, "--json"]),
355 );
356 // @effect-diagnostics-next-line preferSchemaOverJson:off
357 const listed = JSON.parse(listedOutput.output) as ReadonlyArray<{
358 readonly id: string;
359 readonly credential?: string;
360 }>;
361​
362 assert.equal(typeof created.id, "string");
363 assert.equal(typeof created.credential, "string");
364 assert.equal(created.credential.length > 0, true);
365 assert.equal(listed.length, 1);
366 assert.equal(listed[0]?.id, created.id);
367 assert.equal("credential" in (listed[0] ?? {}), false);
368 }),
369 );
370​
371 it.effect("executes auth session subcommands and redacts secrets from list output", () =>
372 Effect.gen(function* () {
373 const baseDir = NodeFS.mkdtempSync(
374 NodePath.join(NodeOS.tmpdir(), "t3-cli-auth-session-test-"),
375 );
376​
377 const issuedOutput = yield* captureStdout(
378 runCli(["auth", "session", "issue", "--base-dir", baseDir, "--json"]),
379 );
380 // @effect-diagnostics-next-line preferSchemaOverJson:off
381 const issued = JSON.parse(issuedOutput.output) as {
382 readonly sessionId: string;
383 readonly token: string;
384 readonly scopes: ReadonlyArray<string>;
385 };
386 const listedOutput = yield* captureStdout(
387 runCli(["auth", "session", "list", "--base-dir", baseDir, "--json"]),
388 );
389 // @effect-diagnostics-next-line preferSchemaOverJson:off
390 const listed = JSON.parse(listedOutput.output) as ReadonlyArray<{
391 readonly sessionId: string;
392 readonly token?: string;
393 readonly scopes: ReadonlyArray<string>;
394 }>;
395​
396 assert.equal(typeof issued.sessionId, "string");
397 assert.equal(typeof issued.token, "string");
398 assert.deepEqual(issued.scopes, [
399 "orchestration:read",
400 "orchestration:operate",
401 "terminal:operate",
402 "review:write",
403 "relay:read",
404 "access:read",
405 "access:write",
406 "relay:write",
407 ]);
408 assert.equal(listed.length, 1);
409 assert.equal(listed[0]?.sessionId, issued.sessionId);
410 assert.deepEqual(listed[0]?.scopes, [
411 "orchestration:read",
412 "orchestration:operate",
413 "terminal:operate",
414 "review:write",
415 "relay:read",
416 "access:read",
417 "access:write",
418 "relay:write",
419 ]);
420 assert.equal("token" in (listed[0] ?? {}), false);
421 }),
422 );
423​
424 it.effect("rejects invalid ttl values before running auth commands", () =>
425 Effect.gen(function* () {
426 const error = yield* runCliWithRuntime(["auth", "pairing", "create", "--ttl", "soon"]).pipe(
427 Effect.flip,
428 );
429​
430 if (!CliError.isCliError(error)) {
431 assert.fail(`Expected CliError, got ${String(error)}`);
432 }
433 if (error._tag !== "ShowHelp") {
434 assert.fail(`Expected ShowHelp, got ${error._tag}`);
435 }
436 assert.deepEqual(error.commandPath, ["t3", "auth", "pairing", "create"]);
437 const ttlError = error.errors[0] as CliError.CliError | undefined;
438 if (!ttlError || ttlError._tag !== "InvalidValue") {
439 assert.fail(`Expected InvalidValue, got ${String(ttlError?._tag)}`);
440 }
441 assert.equal(ttlError.option, "ttl");
442 assert.equal(ttlError.value, "soon");
443 assert.isTrue(ttlError.message.includes("Invalid duration"));
444 assert.isTrue(ttlError.message.includes("5m, 1h, 30d, or 15 minutes"));
445 }),
446 );
447​
448 it.effect("adds, renames, and removes projects offline through the orchestration engine", () =>
449 Effect.gen(function* () {
450 const baseDir = NodeFS.mkdtempSync(
451 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-offline-test-"),
452 );
453 const workspaceRoot = NodeFS.mkdtempSync(
454 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-workspace-"),
455 );
456​
457 yield* runCliWithRuntime([
458 "project",
459 "add",
460 workspaceRoot,
461 "--title",
462 "Alpha",
463 "--base-dir",
464 baseDir,
465 ]);
466 const afterAdd = yield* readPersistedSnapshot(baseDir);
467 const addedProject = afterAdd.projects.find(
468 (project) => project.workspaceRoot === workspaceRoot && project.deletedAt === null,
469 );
470 assert.isTrue(addedProject !== undefined);
471 assert.equal(addedProject?.title, "Alpha");
472​
473 yield* runCliWithRuntime(["project", "rename", workspaceRoot, "Beta", "--base-dir", baseDir]);
474 const afterRename = yield* readPersistedSnapshot(baseDir);
475 const renamedProject = afterRename.projects.find(
476 (project) => project.id === addedProject?.id,
477 );
478 assert.equal(renamedProject?.title, "Beta");
479 assert.equal(renamedProject?.deletedAt, null);
480​
481 yield* runCliWithRuntime([
482 "project",
483 "remove",
484 addedProject?.id ?? "",
485 "--base-dir",
486 baseDir,
487 ]);
488 const afterRemove = yield* readPersistedSnapshot(baseDir);
489 const removedProject = afterRemove.projects.find(
490 (project) => project.id === addedProject?.id,
491 );
492 assert.isTrue((removedProject?.deletedAt ?? null) !== null);
493 }),
494 );
495​
496 it.effect("force removes projects that still contain threads", () =>
497 Effect.gen(function* () {
498 const baseDir = NodeFS.mkdtempSync(
499 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-force-remove-test-"),
500 );
501 const workspaceRoot = NodeFS.mkdtempSync(
502 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-force-remove-workspace-"),
503 );
504​
505 yield* runCliWithRuntime(["project", "add", workspaceRoot, "--base-dir", baseDir]);
506 const afterAdd = yield* readPersistedSnapshot(baseDir);
507 const project = afterAdd.projects.find(
508 (candidate) => candidate.workspaceRoot === workspaceRoot && candidate.deletedAt === null,
509 );
510 assert.isTrue(project !== undefined);
511​
512 const config = yield* makeCliTestServerConfig(baseDir);
513 yield* Effect.gen(function* () {
514 const engine = yield* OrchestrationEngine.OrchestrationEngineService;
515 yield* engine.dispatch({
516 type: "thread.create",
517 commandId: CommandId.make("cmd-cli-force-remove-thread"),
518 threadId: ThreadId.make("thread-cli-force-remove"),
519 projectId: project!.id,
520 title: "Thread",
521 modelSelection: {
522 instanceId: ProviderInstanceId.make("codex"),
523 model: "gpt-5-codex",
524 },
525 interactionMode: "default",
526 runtimeMode: "approval-required",
527 branch: null,
528 worktreePath: null,
529 createdAt: DateTime.formatIso(yield* DateTime.now),
530 });
531 }).pipe(Effect.provide(makeProjectPersistenceLayer(config)));
532​
533 yield* runCliWithRuntime([
534 "project",
535 "remove",
536 project!.id,
537 "--force",
538 "--base-dir",
539 baseDir,
540 ]);
541 const afterRemove = yield* readPersistedSnapshot(baseDir);
542 assert.isTrue(
543 (afterRemove.projects.find((candidate) => candidate.id === project!.id)?.deletedAt ??
544 null) !== null,
545 );
546 assert.isTrue(
547 (afterRemove.threads.find((thread) => thread.id === "thread-cli-force-remove")?.deletedAt ??
548 null) !== null,
549 );
550 }),
551 );
552​
553 it.effect("routes project commands through a running server when runtime state is present", () =>
554 Effect.gen(function* () {
555 const baseDir = NodeFS.mkdtempSync(
556 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-live-test-"),
557 );
558 const workspaceRoot = NodeFS.mkdtempSync(
559 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-live-workspace-"),
560 );
561​
562 yield* withLiveProjectCliServer(baseDir, () =>
563 Effect.gen(function* () {
564 yield* runCliWithRuntime([
565 "project",
566 "add",
567 workspaceRoot,
568 "--title",
569 "Live Project",
570 "--base-dir",
571 baseDir,
572 ]);
573 const projectionSnapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
574 const readModel = yield* projectionSnapshotQuery.getSnapshot();
575 const addedProject = readModel.projects.find(
576 (project) => project.workspaceRoot === workspaceRoot && project.deletedAt === null,
577 );
578 assert.isTrue(addedProject !== undefined);
579 assert.equal(addedProject?.title, "Live Project");
580 }),
581 );
582 }),
583 );
584​
585 it.effect("rejects dev-url on project commands", () =>
586 Effect.gen(function* () {
587 const workspaceRoot = NodeFS.mkdtempSync(
588 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-unknown-option-workspace-"),
589 );
590 const error = yield* runCliWithRuntime([
591 "project",
592 "add",
593 workspaceRoot,
594 "--dev-url",
595 "http://127.0.0.1:5173",
596 ]).pipe(Effect.flip);
597​
598 if (!CliError.isCliError(error)) {
599 assert.fail(`Expected CliError, got ${String(error)}`);
600 }
601 if (error._tag !== "ShowHelp") {
602 assert.fail(`Expected ShowHelp, got ${error._tag}`);
603 }
604 assert.deepEqual(error.commandPath, ["t3", "project", "add"]);
605 const optionError = error.errors[0] as CliError.CliError | undefined;
606 if (!optionError || optionError._tag !== "UnrecognizedOption") {
607 assert.fail(`Expected UnrecognizedOption, got ${String(optionError?._tag)}`);
608 }
609 assert.equal(optionError.option, "--dev-url");
610 }),
611 );
612});