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