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