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

config.test.ts

722 lines24.4 KB

1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeFS from "node:fs";
3import * as NodeOS from "node:os";
4​
5import { assert, expect, it } from "@effect/vitest";
6import * as ConfigProvider from "effect/ConfigProvider";
7import * as Effect from "effect/Effect";
8import * as FileSystem from "effect/FileSystem";
9import * as Layer from "effect/Layer";
10import * as Option from "effect/Option";
11import * as Path from "effect/Path";
12import * as Redacted from "effect/Redacted";
13import * as Schema from "effect/Schema";
14​
15import {
16 DesktopBackendBootstrap,
17 type DesktopBackendBootstrap as DesktopBackendBootstrapValue,
18} from "@t3tools/contracts";
19import * as NetService from "@t3tools/shared/Net";
20import * as NodeServices from "@effect/platform-node/NodeServices";
21import { deriveServerPaths } from "../config.ts";
22import { resolveServerConfig } from "./config.ts";
23​
24const deriveExplicitServerPaths = (baseDir: string, devUrl: URL | undefined) =>
25 deriveServerPaths(baseDir, devUrl, { baseDirIsExplicit: true });
26​
27const encodeDesktopBootstrap = Schema.encodeEffect(Schema.fromJsonString(DesktopBackendBootstrap));
28const encodeUnknownJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
29​
30const makeDesktopBootstrap = (
31 overrides: Partial<DesktopBackendBootstrapValue> = {},
32): DesktopBackendBootstrapValue => ({
33 mode: "desktop",
34 noBrowser: true,
35 port: 4888,
36 t3Home: "/tmp/t3-bootstrap-home",
37 host: "127.0.0.1",
38 desktopBootstrapToken: "desktop-bootstrap-token",
39 tailscaleServeEnabled: false,
40 tailscaleServePort: 443,
41 ...overrides,
42});
43​
44it.layer(NodeServices.layer)("cli config resolution", (it) => {
45 const defaultObservabilityConfig = {
46 traceMinLevel: "Info",
47 traceTimingEnabled: true,
48 traceBatchWindowMs: 1_000,
49 traceMaxBytes: 10 * 1024 * 1024,
50 traceMaxFiles: 10,
51 otlpTracesUrl: undefined,
52 otlpMetricsUrl: undefined,
53 otlpExportIntervalMs: 10_000,
54 otlpServiceName: "t3-server",
55 devAllowedOrigins: [],
56 } as const;
57​
58 const openBootstrapFd = Effect.fn(function* (payload: DesktopBackendBootstrapValue) {
59 const fs = yield* FileSystem.FileSystem;
60 const filePath = yield* fs.makeTempFileScoped({ prefix: "t3-bootstrap-", suffix: ".ndjson" });
61 const encoded = yield* encodeDesktopBootstrap(payload);
62 yield* fs.writeFileString(filePath, `${encoded}\n`);
63 return yield* Effect.acquireRelease(
64 Effect.sync(() => NodeFS.openSync(filePath, "r")),
65 // Without a /proc or /dev/fd path to reopen, the reader consumes the fd
66 // itself (autoClose), so on Windows it is already closed here.
67 (fd) =>
68 Effect.sync(() => {
69 try {
70 NodeFS.closeSync(fd);
71 } catch (error) {
72 if ((error as NodeJS.ErrnoException).code !== "EBADF") throw error;
73 }
74 }),
75 );
76 });
77​
78 it.effect("enables a trimmed reusable auth token only for web dev mode", () =>
79 Effect.gen(function* () {
80 const baseDir = yield* FileSystem.FileSystem.pipe(
81 Effect.flatMap((fs) => fs.makeTempDirectoryScoped({ prefix: "t3-cli-dev-auth-" })),
82 );
83 const flags = {
84 mode: Option.some("web" as const),
85 port: Option.some(8788),
86 host: Option.none<string>(),
87 baseDir: Option.some(baseDir),
88 cwd: Option.none<string>(),
89 devUrl: Option.some(new URL("http://127.0.0.1:5173")),
90 noBrowser: Option.none<boolean>(),
91 bootstrapFd: Option.none<number>(),
92 autoBootstrapProjectFromCwd: Option.none<boolean>(),
93 logWebSocketEvents: Option.none<boolean>(),
94 tailscaleServeEnabled: Option.none<boolean>(),
95 tailscaleServePort: Option.none<number>(),
96 };
97 const configLayer = ConfigProvider.layer(
98 ConfigProvider.fromEnv({
99 env: {
100 T3CODE_DEV_AUTH_TOKEN: " reusable-dev-auth-token-that-is-long-enough ",
101 },
102 }),
103 );
104 const web = yield* resolveServerConfig(flags, Option.none()).pipe(
105 Effect.provide(Layer.mergeAll(configLayer, NetService.layer)),
106 );
107 const desktop = yield* resolveServerConfig(
108 { ...flags, mode: Option.some("desktop" as const) },
109 Option.none(),
110 ).pipe(Effect.provide(Layer.mergeAll(configLayer, NetService.layer)));
111​
112 expect(web.devAuthToken).toBeDefined();
113 if (web.devAuthToken === undefined) {
114 return yield* Effect.die("Expected reusable dev auth token.");
115 }
116 expect(Redacted.value(web.devAuthToken)).toBe("reusable-dev-auth-token-that-is-long-enough");
117 expect(desktop.devAuthToken).toBeUndefined();
118 }),
119 );
120​
121 it.effect("does not expose an invalid reusable auth token", () =>
122 Effect.gen(function* () {
123 const secret = "short-secret";
124 const baseDir = yield* FileSystem.FileSystem.pipe(
125 Effect.flatMap((fs) => fs.makeTempDirectoryScoped({ prefix: "t3-cli-dev-auth-invalid-" })),
126 );
127 const flags = {
128 mode: Option.some("web" as const),
129 port: Option.some(8788),
130 host: Option.none<string>(),
131 baseDir: Option.some(baseDir),
132 cwd: Option.none<string>(),
133 devUrl: Option.some(new URL("http://127.0.0.1:5173")),
134 noBrowser: Option.none<boolean>(),
135 bootstrapFd: Option.none<number>(),
136 autoBootstrapProjectFromCwd: Option.none<boolean>(),
137 logWebSocketEvents: Option.none<boolean>(),
138 tailscaleServeEnabled: Option.none<boolean>(),
139 tailscaleServePort: Option.none<number>(),
140 };
141 const configLayer = ConfigProvider.layer(
142 ConfigProvider.fromEnv({ env: { T3CODE_DEV_AUTH_TOKEN: secret } }),
143 );
144 const error = yield* resolveServerConfig(flags, Option.none()).pipe(
145 Effect.provide(Layer.mergeAll(configLayer, NetService.layer)),
146 Effect.flip,
147 );
148 const desktop = yield* resolveServerConfig(
149 { ...flags, mode: Option.some("desktop" as const) },
150 Option.none(),
151 ).pipe(Effect.provide(Layer.mergeAll(configLayer, NetService.layer)));
152 const staticWeb = yield* resolveServerConfig(
153 { ...flags, devUrl: Option.none() },
154 Option.none(),
155 ).pipe(Effect.provide(Layer.mergeAll(configLayer, NetService.layer)));
156​
157 expect(String(error)).not.toContain(secret);
158 const serialized = yield* encodeUnknownJson(error);
159 expect(serialized).not.toContain(secret);
160 expect(desktop.devAuthToken).toBeUndefined();
161 expect(staticWeb.devAuthToken).toBeUndefined();
162 }),
163 );
164​
165 it.effect("falls back to effect/config values when flags are omitted", () =>
166 Effect.gen(function* () {
167 const { join } = yield* Path.Path;
168 const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-env-base");
169 const derivedPaths = yield* deriveExplicitServerPaths(
170 baseDir,
171 new URL("http://127.0.0.1:5173"),
172 );
173 const resolved = yield* resolveServerConfig(
174 {
175 mode: Option.none(),
176 port: Option.none(),
177 host: Option.none(),
178 baseDir: Option.none(),
179 cwd: Option.none(),
180 devUrl: Option.none(),
181 noBrowser: Option.none(),
182 bootstrapFd: Option.none(),
183 autoBootstrapProjectFromCwd: Option.none(),
184 logWebSocketEvents: Option.none(),
185 tailscaleServeEnabled: Option.none(),
186 tailscaleServePort: Option.none(),
187 },
188 Option.none(),
189 ).pipe(
190 Effect.provide(
191 Layer.mergeAll(
192 ConfigProvider.layer(
193 ConfigProvider.fromEnv({
194 env: {
195 T3CODE_LOG_LEVEL: "Warn",
196 T3CODE_MODE: "desktop",
197 T3CODE_PORT: "4001",
198 T3CODE_HOST: "0.0.0.0",
199 T3CODE_HOME: baseDir,
200 VITE_DEV_SERVER_URL: "http://127.0.0.1:5173",
201 T3CODE_DEV_ALLOWED_ORIGINS:
202 "https://host.example.ts.net, https://phone.example.ts.net ",
203 T3CODE_NO_BROWSER: "true",
204 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "false",
205 T3CODE_LOG_WS_EVENTS: "true",
206 },
207 }),
208 ),
209 NetService.layer,
210 ),
211 ),
212 );
213​
214 expect(resolved).toEqual({
215 logLevel: "Warn",
216 ...defaultObservabilityConfig,
217 mode: "desktop",
218 port: 4001,
219 cwd: process.cwd(),
220 baseDir,
221 ...derivedPaths,
222 host: "0.0.0.0",
223 staticDir: undefined,
224 devUrl: new URL("http://127.0.0.1:5173"),
225 devAllowedOrigins: ["https://host.example.ts.net", "https://phone.example.ts.net"],
226 noBrowser: true,
227 startupPresentation: "browser",
228 desktopBootstrapToken: undefined,
229 autoBootstrapProjectFromCwd: false,
230 logWebSocketEvents: true,
231 tailscaleServeEnabled: false,
232 tailscaleServePort: 443,
233 });
234 assert.equal(resolved.stateDir, join(baseDir, "userdata"));
235 }),
236 );
237​
238 it.effect("uses CLI flags when provided", () =>
239 Effect.gen(function* () {
240 const { join } = yield* Path.Path;
241 const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-flags-base");
242 const derivedPaths = yield* deriveExplicitServerPaths(
243 baseDir,
244 new URL("http://127.0.0.1:4173"),
245 );
246 const resolved = yield* resolveServerConfig(
247 {
248 mode: Option.some("web"),
249 port: Option.some(8788),
250 host: Option.some("127.0.0.1"),
251 baseDir: Option.some(baseDir),
252 cwd: Option.none(),
253 devUrl: Option.some(new URL("http://127.0.0.1:4173")),
254 noBrowser: Option.some(true),
255 bootstrapFd: Option.none(),
256 autoBootstrapProjectFromCwd: Option.some(true),
257 logWebSocketEvents: Option.some(true),
258 tailscaleServeEnabled: Option.some(true),
259 tailscaleServePort: Option.some(8443),
260 },
261 Option.some("Debug"),
262 ).pipe(
263 Effect.provide(
264 Layer.mergeAll(
265 ConfigProvider.layer(
266 ConfigProvider.fromEnv({
267 env: {
268 T3CODE_LOG_LEVEL: "Warn",
269 T3CODE_MODE: "desktop",
270 T3CODE_PORT: "4001",
271 T3CODE_HOST: "0.0.0.0",
272 T3CODE_HOME: join(NodeOS.tmpdir(), "ignored-base"),
273 VITE_DEV_SERVER_URL: "http://127.0.0.1:5173",
274 T3CODE_NO_BROWSER: "false",
275 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "false",
276 T3CODE_LOG_WS_EVENTS: "false",
277 },
278 }),
279 ),
280 NetService.layer,
281 ),
282 ),
283 );
284​
285 expect(resolved).toEqual({
286 logLevel: "Debug",
287 ...defaultObservabilityConfig,
288 mode: "web",
289 port: 8788,
290 cwd: process.cwd(),
291 baseDir,
292 ...derivedPaths,
293 host: "127.0.0.1",
294 staticDir: undefined,
295 devUrl: new URL("http://127.0.0.1:4173"),
296 noBrowser: true,
297 startupPresentation: "browser",
298 desktopBootstrapToken: undefined,
299 autoBootstrapProjectFromCwd: true,
300 logWebSocketEvents: true,
301 tailscaleServeEnabled: true,
302 tailscaleServePort: 8443,
303 });
304 assert.equal(resolved.dbPath, join(baseDir, "userdata", "state.sqlite"));
305 }),
306 );
307​
308 it.effect("preserves explicit false CLI boolean flags over env and bootstrap values", () =>
309 Effect.gen(function* () {
310 const { join } = yield* Path.Path;
311 const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-false-flags");
312 const fd = yield* openBootstrapFd(
313 makeDesktopBootstrap({
314 noBrowser: true,
315 tailscaleServeEnabled: false,
316 tailscaleServePort: 443,
317 }),
318 );
319 const derivedPaths = yield* deriveExplicitServerPaths(
320 baseDir,
321 new URL("http://127.0.0.1:4173"),
322 );
323​
324 const resolved = yield* resolveServerConfig(
325 {
326 mode: Option.some("web"),
327 port: Option.some(8788),
328 host: Option.some("127.0.0.1"),
329 baseDir: Option.some(baseDir),
330 cwd: Option.none(),
331 devUrl: Option.some(new URL("http://127.0.0.1:4173")),
332 noBrowser: Option.some(false),
333 bootstrapFd: Option.none(),
334 autoBootstrapProjectFromCwd: Option.some(false),
335 logWebSocketEvents: Option.some(false),
336 tailscaleServeEnabled: Option.none(),
337 tailscaleServePort: Option.none(),
338 },
339 Option.none(),
340 ).pipe(
341 Effect.provide(
342 Layer.mergeAll(
343 ConfigProvider.layer(
344 ConfigProvider.fromEnv({
345 env: {
346 T3CODE_BOOTSTRAP_FD: String(fd),
347 T3CODE_NO_BROWSER: "true",
348 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "true",
349 T3CODE_LOG_WS_EVENTS: "true",
350 },
351 }),
352 ),
353 NetService.layer,
354 ),
355 ),
356 );
357​
358 expect(resolved).toEqual({
359 logLevel: "Info",
360 ...defaultObservabilityConfig,
361 mode: "web",
362 port: 8788,
363 cwd: process.cwd(),
364 baseDir,
365 ...derivedPaths,
366 host: "127.0.0.1",
367 staticDir: undefined,
368 devUrl: new URL("http://127.0.0.1:4173"),
369 noBrowser: false,
370 startupPresentation: "browser",
371 desktopBootstrapToken: "desktop-bootstrap-token",
372 autoBootstrapProjectFromCwd: false,
373 logWebSocketEvents: false,
374 tailscaleServeEnabled: false,
375 tailscaleServePort: 443,
376 });
377 }),
378 );
379​
380 it.effect("uses bootstrap envelope values as fallbacks when flags and env are absent", () =>
381 Effect.gen(function* () {
382 const { join, resolve } = yield* Path.Path;
383 // The resolver absolutises the configured home, so the expectation must
384 // carry the host's drive on Windows.
385 const baseDir = resolve("/tmp/t3-bootstrap-home");
386 const fd = yield* openBootstrapFd(
387 makeDesktopBootstrap({
388 port: 4888,
389 host: "127.0.0.2",
390 t3Home: "/tmp/t3-bootstrap-home",
391 noBrowser: true,
392 desktopBootstrapToken: "desktop-token",
393 desktopTelemetryFd: 4,
394 desktopTelemetryControlFd: 5,
395 tailscaleServeEnabled: false,
396 tailscaleServePort: 443,
397 otlpTracesUrl: "http://localhost:4318/v1/traces",
398 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
399 }),
400 );
401 const derivedPaths = yield* deriveServerPaths(baseDir, undefined);
402​
403 const resolved = yield* resolveServerConfig(
404 {
405 mode: Option.none(),
406 port: Option.none(),
407 host: Option.none(),
408 baseDir: Option.none(),
409 cwd: Option.none(),
410 devUrl: Option.none(),
411 noBrowser: Option.none(),
412 bootstrapFd: Option.none(),
413 autoBootstrapProjectFromCwd: Option.none(),
414 logWebSocketEvents: Option.none(),
415 tailscaleServeEnabled: Option.none(),
416 tailscaleServePort: Option.none(),
417 },
418 Option.none(),
419 ).pipe(
420 Effect.provide(
421 Layer.mergeAll(
422 ConfigProvider.layer(
423 ConfigProvider.fromEnv({
424 env: {
425 T3CODE_BOOTSTRAP_FD: String(fd),
426 },
427 }),
428 ),
429 NetService.layer,
430 ),
431 ),
432 );
433​
434 expect(resolved).toEqual({
435 logLevel: "Info",
436 ...defaultObservabilityConfig,
437 otlpTracesUrl: "http://localhost:4318/v1/traces",
438 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
439 mode: "desktop",
440 port: 4888,
441 cwd: process.cwd(),
442 baseDir,
443 ...derivedPaths,
444 host: "127.0.0.2",
445 staticDir: resolved.staticDir,
446 devUrl: undefined,
447 noBrowser: true,
448 startupPresentation: "browser",
449 desktopBootstrapToken: "desktop-token",
450 desktopTelemetryFd: 4,
451 desktopTelemetryControlFd: 5,
452 resourceMonitorPath: undefined,
453 autoBootstrapProjectFromCwd: false,
454 logWebSocketEvents: false,
455 tailscaleServeEnabled: false,
456 tailscaleServePort: 443,
457 });
458 assert.equal(join(baseDir, "userdata"), resolved.stateDir);
459 assert.equal(resolved.desktopTelemetryFd, 4);
460 assert.equal(resolved.desktopTelemetryControlFd, 5);
461 }),
462 );
463​
464 it.effect("creates derived runtime directories during config resolution", () =>
465 Effect.gen(function* () {
466 const fs = yield* FileSystem.FileSystem;
467 const path = yield* Path.Path;
468 const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-config-dirs-" });
469 const customCwd = path.join(baseDir, "nested", "project");
470​
471 const resolved = yield* resolveServerConfig(
472 {
473 mode: Option.some("desktop"),
474 port: Option.some(4888),
475 host: Option.none(),
476 baseDir: Option.some(baseDir),
477 cwd: Option.some(customCwd),
478 devUrl: Option.some(new URL("http://127.0.0.1:5173")),
479 noBrowser: Option.none(),
480 bootstrapFd: Option.none(),
481 autoBootstrapProjectFromCwd: Option.none(),
482 logWebSocketEvents: Option.none(),
483 tailscaleServeEnabled: Option.none(),
484 tailscaleServePort: Option.none(),
485 },
486 Option.none(),
487 ).pipe(
488 Effect.provide(
489 Layer.mergeAll(
490 ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
491 NetService.layer,
492 ),
493 ),
494 );
495​
496 for (const directory of [
497 customCwd,
498 resolved.stateDir,
499 resolved.logsDir,
500 resolved.providerLogsDir,
501 resolved.terminalLogsDir,
502 resolved.attachmentsDir,
503 resolved.worktreesDir,
504 path.dirname(resolved.serverLogPath),
505 path.dirname(resolved.serverTracePath),
506 ]) {
507 expect(yield* fs.exists(directory)).toBe(true);
508 }
509 expect(resolved.cwd).toBe(path.resolve(customCwd));
510 }),
511 );
512​
513 it.effect("applies flag then env precedence over bootstrap envelope values", () =>
514 Effect.gen(function* () {
515 const { join } = yield* Path.Path;
516 const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-env-wins");
517 const fd = yield* openBootstrapFd(
518 makeDesktopBootstrap({
519 port: 4888,
520 host: "127.0.0.2",
521 t3Home: "/tmp/t3-bootstrap-home",
522 noBrowser: false,
523 desktopBootstrapToken: "desktop-token",
524 tailscaleServeEnabled: false,
525 tailscaleServePort: 443,
526 }),
527 );
528 const derivedPaths = yield* deriveExplicitServerPaths(
529 baseDir,
530 new URL("http://127.0.0.1:4173"),
531 );
532​
533 const resolved = yield* resolveServerConfig(
534 {
535 mode: Option.none(),
536 port: Option.some(8788),
537 host: Option.some("127.0.0.1"),
538 baseDir: Option.none(),
539 cwd: Option.none(),
540 devUrl: Option.some(new URL("http://127.0.0.1:4173")),
541 noBrowser: Option.none(),
542 bootstrapFd: Option.none(),
543 autoBootstrapProjectFromCwd: Option.none(),
544 logWebSocketEvents: Option.none(),
545 tailscaleServeEnabled: Option.none(),
546 tailscaleServePort: Option.none(),
547 },
548 Option.some("Debug"),
549 ).pipe(
550 Effect.provide(
551 Layer.mergeAll(
552 ConfigProvider.layer(
553 ConfigProvider.fromEnv({
554 env: {
555 T3CODE_MODE: "web",
556 T3CODE_BOOTSTRAP_FD: String(fd),
557 T3CODE_HOME: baseDir,
558 T3CODE_NO_BROWSER: "true",
559 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "true",
560 T3CODE_LOG_WS_EVENTS: "true",
561 },
562 }),
563 ),
564 NetService.layer,
565 ),
566 ),
567 );
568​
569 expect(resolved).toEqual({
570 logLevel: "Debug",
571 ...defaultObservabilityConfig,
572 mode: "web",
573 port: 8788,
574 cwd: process.cwd(),
575 baseDir,
576 ...derivedPaths,
577 host: "127.0.0.1",
578 staticDir: undefined,
579 devUrl: new URL("http://127.0.0.1:4173"),
580 noBrowser: true,
581 startupPresentation: "browser",
582 desktopBootstrapToken: "desktop-token",
583 autoBootstrapProjectFromCwd: true,
584 logWebSocketEvents: true,
585 tailscaleServeEnabled: false,
586 tailscaleServePort: 443,
587 });
588 }),
589 );
590​
591 it.effect("falls back to persisted observability settings when env vars are absent", () =>
592 Effect.gen(function* () {
593 const fs = yield* FileSystem.FileSystem;
594 const path = yield* Path.Path;
595 const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-config-settings-" });
596 const derivedPaths = yield* deriveExplicitServerPaths(baseDir, undefined);
597 yield* fs.makeDirectory(path.dirname(derivedPaths.settingsPath), { recursive: true });
598 yield* fs.writeFileString(
599 derivedPaths.settingsPath,
600 // @effect-diagnostics-next-line preferSchemaOverJson:off
601 `${JSON.stringify({
602 observability: {
603 otlpTracesUrl: "http://localhost:4318/v1/traces",
604 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
605 },
606 })}\n`,
607 );
608​
609 const resolved = yield* resolveServerConfig(
610 {
611 mode: Option.some("desktop"),
612 port: Option.some(4888),
613 host: Option.none(),
614 baseDir: Option.some(baseDir),
615 cwd: Option.none(),
616 devUrl: Option.none(),
617 noBrowser: Option.none(),
618 bootstrapFd: Option.none(),
619 autoBootstrapProjectFromCwd: Option.none(),
620 logWebSocketEvents: Option.none(),
621 tailscaleServeEnabled: Option.none(),
622 tailscaleServePort: Option.none(),
623 },
624 Option.none(),
625 ).pipe(
626 Effect.provide(
627 Layer.mergeAll(
628 ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
629 NetService.layer,
630 ),
631 ),
632 );
633​
634 expect(resolved.otlpTracesUrl).toBe("http://localhost:4318/v1/traces");
635 expect(resolved.otlpMetricsUrl).toBe("http://localhost:4318/v1/metrics");
636 expect(resolved).toEqual({
637 logLevel: "Info",
638 ...defaultObservabilityConfig,
639 otlpTracesUrl: "http://localhost:4318/v1/traces",
640 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
641 mode: "desktop",
642 port: 4888,
643 cwd: process.cwd(),
644 baseDir,
645 ...derivedPaths,
646 host: "127.0.0.1",
647 staticDir: resolved.staticDir,
648 devUrl: undefined,
649 noBrowser: true,
650 startupPresentation: "browser",
651 desktopBootstrapToken: undefined,
652 autoBootstrapProjectFromCwd: false,
653 logWebSocketEvents: false,
654 tailscaleServeEnabled: false,
655 tailscaleServePort: 443,
656 });
657 }),
658 );
659​
660 it.effect("forces noBrowser and disables auto-bootstrap for headless startup presentation", () =>
661 Effect.gen(function* () {
662 const { join } = yield* Path.Path;
663 const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-headless-base");
664 const derivedPaths = yield* deriveExplicitServerPaths(baseDir, undefined);
665​
666 const resolved = yield* resolveServerConfig(
667 {
668 mode: Option.some("web"),
669 port: Option.some(3773),
670 host: Option.none(),
671 baseDir: Option.some(baseDir),
672 cwd: Option.none(),
673 devUrl: Option.none(),
674 noBrowser: Option.none(),
675 bootstrapFd: Option.none(),
676 autoBootstrapProjectFromCwd: Option.none(),
677 logWebSocketEvents: Option.none(),
678 tailscaleServeEnabled: Option.none(),
679 tailscaleServePort: Option.none(),
680 },
681 Option.none(),
682 {
683 startupPresentation: "headless",
684 },
685 ).pipe(
686 Effect.provide(
687 Layer.mergeAll(
688 ConfigProvider.layer(
689 ConfigProvider.fromEnv({
690 env: {
691 T3CODE_NO_BROWSER: "false",
692 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "true",
693 },
694 }),
695 ),
696 NetService.layer,
697 ),
698 ),
699 );
700​
701 expect(resolved).toEqual({
702 logLevel: "Info",
703 ...defaultObservabilityConfig,
704 mode: "web",
705 port: 3773,
706 cwd: process.cwd(),
707 baseDir,
708 ...derivedPaths,
709 host: undefined,
710 staticDir: resolved.staticDir,
711 devUrl: undefined,
712 noBrowser: true,
713 startupPresentation: "headless",
714 desktopBootstrapToken: undefined,
715 autoBootstrapProjectFromCwd: false,
716 logWebSocketEvents: false,
717 tailscaleServeEnabled: false,
718 tailscaleServePort: 443,
719 });
720 }),
721 );
722});