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

bin.test.ts

627 lines23.6 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 { 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 runCliWithRuntime(["--log-level", "debug", "--version"]),
191 );
192​
193 it.effect("accepts canonical --no-<flag> boolean negation", () =>
194 runCliWithRuntime(["--no-log-websocket-events", "--version"]),
195 );
196​
197 it.effect("rejects invalid log-level casing before launching the server", () =>
198 Effect.gen(function* () {
199 const error = yield* runCliWithRuntime(["--log-level", "Debug"]).pipe(Effect.flip);
200​
201 if (!CliError.isCliError(error)) {
202 assert.fail(`Expected CliError, got ${String(error)}`);
203 }
204 if (error._tag !== "InvalidValue") {
205 assert.fail(`Expected InvalidValue, got ${error._tag}`);
206 }
207 assert.equal(error.option, "log-level");
208 assert.equal(error.value, "Debug");
209 }),
210 );
211​
212 it.effect("rejects connect commands when public configuration is missing", () =>
213 Effect.gen(function* () {
214 const error = yield* runCli(["connect", "status"], noConnectCli).pipe(Effect.flip);
215​
216 if (!CliError.isCliError(error)) {
217 assert.fail(`Expected CliError, got ${String(error)}`);
218 }
219 if (error._tag !== "ShowHelp") {
220 assert.fail(`Expected ShowHelp, got ${error._tag}`);
221 }
222 assert.deepEqual(error.commandPath, ["t3", "connect"]);
223 assert.include(error.errors[0]?.message ?? "", "missing T3 Connect public configuration");
224​
225 const output = (yield* TestConsole.errorLines).join("\n");
226 assert.include(output, "ERROR");
227 assert.include(output, "missing T3 Connect public configuration");
228 }).pipe(Effect.provide(Layer.mergeAll(CliRuntimeLayer, TestConsole.layer))),
229 );
230​
231 it.effect("exposes service lifecycle commands without T3 Connect configuration", () =>
232 Effect.gen(function* () {
233 const { output } = yield* captureStdout(runCli(["service", "--help"], noConnectCli));
234​
235 assert.include(output, "Manage the T3 Code background service.");
236 assert.include(output, "install");
237 assert.include(output, "uninstall");
238 assert.include(output, "update");
239 assert.include(output, "status");
240 }),
241 );
242​
243 it.effect("reports fresh headless connect state without requiring local configuration", () =>
244 Effect.gen(function* () {
245 const baseDir = NodeFS.mkdtempSync(
246 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-status-test-"),
247 );
248 const { output } = yield* captureStdout(
249 runConnectCli(["connect", "status", "--base-dir", baseDir, "--json"]),
250 );
251 // @effect-diagnostics-next-line preferSchemaOverJson:off - CLI JSON output is decoded as a presentation DTO.
252 const status = JSON.parse(output) as {
253 readonly desired: boolean;
254 readonly authenticated: boolean;
255 readonly linked: boolean;
256 readonly cloudUserId: string | null;
257 readonly relayUrl: string | null;
258 };
259​
260 assert.equal(status.desired, false);
261 assert.equal(status.authenticated, false);
262 assert.equal(status.linked, false);
263 assert.equal(status.cloudUserId, null);
264 assert.equal(status.relayUrl, null);
265 }).pipe(Effect.provide(DisconnectedLauncherChildLayer)),
266 );
267​
268 it.effect("reports actionable human-readable headless connect state", () =>
269 Effect.gen(function* () {
270 const baseDir = NodeFS.mkdtempSync(
271 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-status-human-test-"),
272 );
273 const { output } = yield* captureStdout(
274 runConnectCli(["connect", "status", "--base-dir", baseDir]),
275 );
276​
277 assert.include(output, "T3 Connect\n Exposure: disabled");
278 assert.include(output, " Authorization: missing");
279 assert.include(output, " Environment link: not provisioned");
280 assert.include(output, "Next: Run `t3 connect link` to authorize and enable T3 Connect.");
281 }),
282 );
283​
284 it.effect("accepts the --headless login override without enabling access", () =>
285 Effect.gen(function* () {
286 const baseDir = NodeFS.mkdtempSync(
287 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-login-test-"),
288 );
289 const { secretsDir } = yield* ServerConfig.deriveServerPaths(baseDir, undefined);
290 NodeFS.mkdirSync(secretsDir, { recursive: true });
291 NodeFS.writeFileSync(
292 NodePath.join(secretsDir, "cloud-cli-oauth-token.bin"),
293 // @effect-diagnostics-next-line preferSchemaOverJson:off - Test fixture matches the persisted CLI token representation.
294 JSON.stringify({
295 accessToken: "access-token",
296 refreshToken: "refresh-token",
297 expiresAtEpochMs: Number.MAX_SAFE_INTEGER,
298 }),
299 );
300​
301 const login = yield* captureStdout(
302 runConnectCli(["connect", "login", "--base-dir", baseDir, "--headless"]),
303 );
304 const status = yield* captureStdout(
305 runConnectCli(["connect", "status", "--base-dir", baseDir, "--json"]),
306 );
307 // @effect-diagnostics-next-line preferSchemaOverJson:off - CLI JSON output is decoded as a presentation DTO.
308 const decoded = JSON.parse(status.output) as {
309 readonly desired: boolean;
310 readonly authenticated: boolean;
311 };
312​
313 assert.equal(login.output, "✓ Signed in");
314 assert.isFalse(decoded.desired);
315 assert.isTrue(decoded.authenticated);
316 }),
317 );
318​
319 it.effect("disables headless connect without a running server", () =>
320 Effect.gen(function* () {
321 const baseDir = NodeFS.mkdtempSync(
322 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-unlink-test-"),
323 );
324 const { output } = yield* captureStdout(
325 runConnectCli(["connect", "unlink", "--base-dir", baseDir]),
326 );
327​
328 assert.equal(output, "T3 Connect is disabled locally.");
329 }),
330 );
331​
332 it.effect("logs out of headless connect and removes the stored CLI authorization", () =>
333 Effect.gen(function* () {
334 const baseDir = NodeFS.mkdtempSync(
335 NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-logout-test-"),
336 );
337 const { secretsDir } = yield* ServerConfig.deriveServerPaths(baseDir, undefined);
338 const tokenPath = NodePath.join(secretsDir, "cloud-cli-oauth-token.bin");
339 NodeFS.mkdirSync(secretsDir, { recursive: true });
340 NodeFS.writeFileSync(tokenPath, "invalid persisted token");
341​
342 const { output } = yield* captureStdout(
343 runConnectCli(["connect", "logout", "--base-dir", baseDir]),
344 );
345​
346 assert.equal(
347 output,
348 "Signed out of T3 Connect locally.\nThe background service is managed separately with `t3 service`.",
349 );
350 assert.isFalse(NodeFS.existsSync(tokenPath));
351 }),
352 );
353​
354 it.effect("executes auth pairing subcommands and redacts secrets from list output", () =>
355 Effect.gen(function* () {
356 const baseDir = NodeFS.mkdtempSync(
357 NodePath.join(NodeOS.tmpdir(), "t3-cli-auth-pairing-test-"),
358 );
359​
360 const createdOutput = yield* captureStdout(
361 runCli(["auth", "pairing", "create", "--base-dir", baseDir, "--json"]),
362 );
363 // @effect-diagnostics-next-line preferSchemaOverJson:off
364 const created = JSON.parse(createdOutput.output) as {
365 readonly id: string;
366 readonly credential: string;
367 };
368 const listedOutput = yield* captureStdout(
369 runCli(["auth", "pairing", "list", "--base-dir", baseDir, "--json"]),
370 );
371 // @effect-diagnostics-next-line preferSchemaOverJson:off
372 const listed = JSON.parse(listedOutput.output) as ReadonlyArray<{
373 readonly id: string;
374 readonly credential?: string;
375 }>;
376​
377 assert.equal(typeof created.id, "string");
378 assert.equal(typeof created.credential, "string");
379 assert.equal(created.credential.length > 0, true);
380 assert.equal(listed.length, 1);
381 assert.equal(listed[0]?.id, created.id);
382 assert.equal("credential" in (listed[0] ?? {}), false);
383 }),
384 );
385​
386 it.effect("executes auth session subcommands and redacts secrets from list output", () =>
387 Effect.gen(function* () {
388 const baseDir = NodeFS.mkdtempSync(
389 NodePath.join(NodeOS.tmpdir(), "t3-cli-auth-session-test-"),
390 );
391​
392 const issuedOutput = yield* captureStdout(
393 runCli(["auth", "session", "issue", "--base-dir", baseDir, "--json"]),
394 );
395 // @effect-diagnostics-next-line preferSchemaOverJson:off
396 const issued = JSON.parse(issuedOutput.output) as {
397 readonly sessionId: string;
398 readonly token: string;
399 readonly scopes: ReadonlyArray<string>;
400 };
401 const listedOutput = yield* captureStdout(
402 runCli(["auth", "session", "list", "--base-dir", baseDir, "--json"]),
403 );
404 // @effect-diagnostics-next-line preferSchemaOverJson:off
405 const listed = JSON.parse(listedOutput.output) as ReadonlyArray<{
406 readonly sessionId: string;
407 readonly token?: string;
408 readonly scopes: ReadonlyArray<string>;
409 }>;
410​
411 assert.equal(typeof issued.sessionId, "string");
412 assert.equal(typeof issued.token, "string");
413 assert.deepEqual(issued.scopes, [
414 "orchestration:read",
415 "orchestration:operate",
416 "terminal:operate",
417 "review:write",
418 "relay:read",
419 "access:read",
420 "access:write",
421 "relay:write",
422 ]);
423 assert.equal(listed.length, 1);
424 assert.equal(listed[0]?.sessionId, issued.sessionId);
425 assert.deepEqual(listed[0]?.scopes, [
426 "orchestration:read",
427 "orchestration:operate",
428 "terminal:operate",
429 "review:write",
430 "relay:read",
431 "access:read",
432 "access:write",
433 "relay:write",
434 ]);
435 assert.equal("token" in (listed[0] ?? {}), false);
436 }).pipe(Effect.provide(DisconnectedLauncherChildLayer)),
437 );
438​
439 it.effect("rejects invalid ttl values before running auth commands", () =>
440 Effect.gen(function* () {
441 const error = yield* runCliWithRuntime(["auth", "pairing", "create", "--ttl", "soon"]).pipe(
442 Effect.flip,
443 );
444​
445 if (!CliError.isCliError(error)) {
446 assert.fail(`Expected CliError, got ${String(error)}`);
447 }
448 if (error._tag !== "ShowHelp") {
449 assert.fail(`Expected ShowHelp, got ${error._tag}`);
450 }
451 assert.deepEqual(error.commandPath, ["t3", "auth", "pairing", "create"]);
452 const ttlError = error.errors[0] as CliError.CliError | undefined;
453 if (!ttlError || ttlError._tag !== "InvalidValue") {
454 assert.fail(`Expected InvalidValue, got ${String(ttlError?._tag)}`);
455 }
456 assert.equal(ttlError.option, "ttl");
457 assert.equal(ttlError.value, "soon");
458 assert.isTrue(ttlError.message.includes("Invalid duration"));
459 assert.isTrue(ttlError.message.includes("5m, 1h, 30d, or 15 minutes"));
460 }),
461 );
462​
463 it.effect("adds, renames, and removes projects offline through the orchestration engine", () =>
464 Effect.gen(function* () {
465 const baseDir = NodeFS.mkdtempSync(
466 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-offline-test-"),
467 );
468 const workspaceRoot = NodeFS.mkdtempSync(
469 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-workspace-"),
470 );
471​
472 yield* runCliWithRuntime([
473 "project",
474 "add",
475 workspaceRoot,
476 "--title",
477 "Alpha",
478 "--base-dir",
479 baseDir,
480 ]);
481 const afterAdd = yield* readPersistedSnapshot(baseDir);
482 const addedProject = afterAdd.projects.find(
483 (project) => project.workspaceRoot === workspaceRoot && project.deletedAt === null,
484 );
485 assert.isTrue(addedProject !== undefined);
486 assert.equal(addedProject?.title, "Alpha");
487​
488 yield* runCliWithRuntime(["project", "rename", workspaceRoot, "Beta", "--base-dir", baseDir]);
489 const afterRename = yield* readPersistedSnapshot(baseDir);
490 const renamedProject = afterRename.projects.find(
491 (project) => project.id === addedProject?.id,
492 );
493 assert.equal(renamedProject?.title, "Beta");
494 assert.equal(renamedProject?.deletedAt, null);
495​
496 yield* runCliWithRuntime([
497 "project",
498 "remove",
499 addedProject?.id ?? "",
500 "--base-dir",
501 baseDir,
502 ]);
503 const afterRemove = yield* readPersistedSnapshot(baseDir);
504 const removedProject = afterRemove.projects.find(
505 (project) => project.id === addedProject?.id,
506 );
507 assert.isTrue((removedProject?.deletedAt ?? null) !== null);
508 }),
509 );
510​
511 it.effect("force removes projects that still contain threads", () =>
512 Effect.gen(function* () {
513 const baseDir = NodeFS.mkdtempSync(
514 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-force-remove-test-"),
515 );
516 const workspaceRoot = NodeFS.mkdtempSync(
517 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-force-remove-workspace-"),
518 );
519​
520 yield* runCliWithRuntime(["project", "add", workspaceRoot, "--base-dir", baseDir]);
521 const afterAdd = yield* readPersistedSnapshot(baseDir);
522 const project = afterAdd.projects.find(
523 (candidate) => candidate.workspaceRoot === workspaceRoot && candidate.deletedAt === null,
524 );
525 assert.isTrue(project !== undefined);
526​
527 const config = yield* makeCliTestServerConfig(baseDir);
528 yield* Effect.gen(function* () {
529 const engine = yield* OrchestrationEngine.OrchestrationEngineService;
530 yield* engine.dispatch({
531 type: "thread.create",
532 commandId: CommandId.make("cmd-cli-force-remove-thread"),
533 threadId: ThreadId.make("thread-cli-force-remove"),
534 projectId: project!.id,
535 title: "Thread",
536 modelSelection: {
537 instanceId: ProviderInstanceId.make("codex"),
538 model: "gpt-5-codex",
539 },
540 interactionMode: "default",
541 runtimeMode: "approval-required",
542 branch: null,
543 worktreePath: null,
544 createdAt: DateTime.formatIso(yield* DateTime.now),
545 });
546 }).pipe(Effect.provide(makeProjectPersistenceLayer(config)));
547​
548 yield* runCliWithRuntime([
549 "project",
550 "remove",
551 project!.id,
552 "--force",
553 "--base-dir",
554 baseDir,
555 ]);
556 const afterRemove = yield* readPersistedSnapshot(baseDir);
557 assert.isTrue(
558 (afterRemove.projects.find((candidate) => candidate.id === project!.id)?.deletedAt ??
559 null) !== null,
560 );
561 assert.isTrue(
562 (afterRemove.threads.find((thread) => thread.id === "thread-cli-force-remove")?.deletedAt ??
563 null) !== null,
564 );
565 }),
566 );
567​
568 it.effect("routes project commands through a running server when runtime state is present", () =>
569 Effect.gen(function* () {
570 const baseDir = NodeFS.mkdtempSync(
571 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-live-test-"),
572 );
573 const workspaceRoot = NodeFS.mkdtempSync(
574 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-live-workspace-"),
575 );
576​
577 yield* withLiveProjectCliServer(baseDir, () =>
578 Effect.gen(function* () {
579 yield* runCliWithRuntime([
580 "project",
581 "add",
582 workspaceRoot,
583 "--title",
584 "Live Project",
585 "--base-dir",
586 baseDir,
587 ]);
588 const projectionSnapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
589 const readModel = yield* projectionSnapshotQuery.getSnapshot();
590 const addedProject = readModel.projects.find(
591 (project) => project.workspaceRoot === workspaceRoot && project.deletedAt === null,
592 );
593 assert.isTrue(addedProject !== undefined);
594 assert.equal(addedProject?.title, "Live Project");
595 }),
596 );
597 }),
598 );
599​
600 it.effect("rejects dev-url on project commands", () =>
601 Effect.gen(function* () {
602 const workspaceRoot = NodeFS.mkdtempSync(
603 NodePath.join(NodeOS.tmpdir(), "t3-cli-projects-unknown-option-workspace-"),
604 );
605 const error = yield* runCliWithRuntime([
606 "project",
607 "add",
608 workspaceRoot,
609 "--dev-url",
610 "http://127.0.0.1:5173",
611 ]).pipe(Effect.flip);
612​
613 if (!CliError.isCliError(error)) {
614 assert.fail(`Expected CliError, got ${String(error)}`);
615 }
616 if (error._tag !== "ShowHelp") {
617 assert.fail(`Expected ShowHelp, got ${error._tag}`);
618 }
619 assert.deepEqual(error.commandPath, ["t3", "project", "add"]);
620 const optionError = error.errors[0] as CliError.CliError | undefined;
621 if (!optionError || optionError._tag !== "UnrecognizedOption") {
622 assert.fail(`Expected UnrecognizedOption, got ${String(optionError?._tag)}`);
623 }
624 assert.equal(optionError.option, "--dev-url");
625 }),
626 );
627});