Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off - builds real worktree layouts on disk.
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as NodeFS from "node:fs";
4import * as NodeOS from "node:os";
5import * as NodePath from "node:path";
6import * as NetService from "@t3tools/shared/Net";
7import {
8 HostProcessEnvironment,
9 HostProcessPlatform,
10 HostProcessWorkingDirectory,
11} from "@t3tools/shared/hostProcess";
12import { assert, describe, it } from "@effect/vitest";
13import * as ConfigProvider from "effect/ConfigProvider";
14import * as Effect from "effect/Effect";
15import * as Layer from "effect/Layer";
16import * as Path from "effect/Path";
17import * as PlatformError from "effect/PlatformError";
18import * as Sink from "effect/Sink";
19import * as Stream from "effect/Stream";
20import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
21
22import {
23 checkPortAvailabilityOnHosts,
24 createDevRunnerEnv,
25 devPortProbeHosts,
26 findFirstAvailableOffset,
27 getDevRunnerModeArgs,
28 isBrowserAllowedPort,
29 resolveModePortOffsets,
30 resolveOffset,
31 runDevRunnerWithInput,
32} from "./dev-runner.ts";
33
34const emptyConfigLayer = ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} }));
35const netServiceLayer = Layer.succeed(NetService.NetService, {
36 canListenOnHost: () => Effect.succeed(true),
37 isPortAvailableOnLoopback: () => Effect.succeed(true),
38 hasListenerOnHost: () => Effect.succeed(false),
39 reserveLoopbackPort: () => Effect.succeed(49_152),
40 findAvailablePort: (port) => Effect.succeed(port),
41});
42
43function mockProcess(exit: number | PlatformError.PlatformError) {
44 return ChildProcessSpawner.makeHandle({
45 pid: ChildProcessSpawner.ProcessId(1),
46 exitCode:
47 typeof exit === "number"
48 ? Effect.succeed(ChildProcessSpawner.ExitCode(exit))
49 : Effect.fail(exit),
50 isRunning: Effect.succeed(false),
51 kill: () => Effect.void,
52 unref: Effect.succeed(Effect.void),
53 stdin: Sink.drain,
54 stdout: Stream.empty,
55 stderr: Stream.empty,
56 all: Stream.empty,
57 getInputFd: () => Sink.drain,
58 getOutputFd: () => Stream.empty,
59 });
60}
61
62const devServerInput = {
63 mode: "dev:server",
64 t3Home: "/tmp/t3code-dev-runner",
65 browser: undefined,
66 autoBootstrapProjectFromCwd: undefined,
67 logWebSocketEvents: undefined,
68 host: undefined,
69 port: 13_773,
70 devUrl: undefined,
71 dryRun: false,
72 share: false,
73 runArgs: ["--inspect", "secret-token-value"],
74} as const;
75
76it.layer(NodeServices.layer)("dev-runner", (it) => {
77 it.effect("accepts a dry run without the optional browser flag", () =>
78 Effect.gen(function* () {
79 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
80 const path = yield* Path.Path;
81 const output = yield* spawner.string(
82 ChildProcess.make(process.execPath, ["scripts/dev-runner.ts", "dev", "--dry-run"], {
83 cwd: path.resolve(import.meta.dirname, ".."),
84 }),
85 );
86
87 assert.include(output, "[dev-runner] mode=dev");
88 }),
89 );
90
91 describe("getDevRunnerModeArgs", () => {
92 it.effect("lets Vite+ honor the desktop dev task graph", () =>
93 Effect.sync(() => {
94 assert.deepStrictEqual(getDevRunnerModeArgs("dev:desktop"), [
95 "run",
96 "--filter=@t3tools/desktop",
97 "--filter=@t3tools/web",
98 "dev",
99 ]);
100 }),
101 );
102
103 it.effect("places Vite+ run flags before the task name", () =>
104 Effect.sync(() => {
105 assert.deepStrictEqual(getDevRunnerModeArgs("dev"), [
106 "run",
107 "--filter=@t3tools/contracts",
108 "--filter=@t3tools/web",
109 "--filter=t3",
110 "--parallel",
111 "dev",
112 ]);
113 }),
114 );
115 });
116
117 describe("resolveOffset", () => {
118 it.effect("uses explicit T3CODE_PORT_OFFSET when provided", () =>
119 Effect.gen(function* () {
120 const result = yield* resolveOffset({ portOffset: 12, devInstance: undefined });
121 assert.deepStrictEqual(result, {
122 offset: 12,
123 source: "T3CODE_PORT_OFFSET=12",
124 });
125 }),
126 );
127
128 it.effect("hashes non-numeric instance values", () =>
129 Effect.gen(function* () {
130 const result = yield* resolveOffset({
131 portOffset: undefined,
132 devInstance: "feature-branch",
133 });
134 assert.ok(result.offset >= 1);
135 assert.ok(result.offset <= 3000);
136 }),
137 );
138
139 it.effect("returns structured context for a negative port offset", () =>
140 Effect.gen(function* () {
141 const error = yield* resolveOffset({ portOffset: -1, devInstance: undefined }).pipe(
142 Effect.flip,
143 );
144
145 assert.equal(error._tag, "DevRunnerInvalidPortOffsetError");
146 assert.equal(error.configKey, "T3CODE_PORT_OFFSET");
147 assert.equal(error.portOffset, -1);
148 assert.equal(error.minimum, 0);
149 assert.ok(!("cause" in error));
150 }),
151 );
152 });
153
154 describe("createDevRunnerEnv", () => {
155 it.effect("forwards the reusable auth token to web dev and removes it for desktop", () =>
156 Effect.gen(function* () {
157 const input = {
158 baseEnv: { T3CODE_DEV_AUTH_TOKEN: "reusable-dev-auth-token-that-is-long-enough" },
159 serverOffset: 0,
160 webOffset: 0,
161 t3Home: undefined,
162 browser: undefined,
163 autoBootstrapProjectFromCwd: undefined,
164 logWebSocketEvents: undefined,
165 host: undefined,
166 port: undefined,
167 devUrl: undefined,
168 } as const;
169 const web = yield* createDevRunnerEnv({ ...input, mode: "dev" });
170 const desktop = yield* createDevRunnerEnv({ ...input, mode: "dev:desktop" });
171
172 assert.equal(web.T3CODE_DEV_AUTH_TOKEN, input.baseEnv.T3CODE_DEV_AUTH_TOKEN);
173 assert.equal(desktop.T3CODE_DEV_AUTH_TOKEN, undefined);
174 }),
175 );
176 it.effect("leaves the shared home implicit and disables browser auto-open", () =>
177 Effect.gen(function* () {
178 const env = yield* createDevRunnerEnv({
179 mode: "dev",
180 baseEnv: {},
181 serverOffset: 0,
182 webOffset: 0,
183 t3Home: undefined,
184 browser: undefined,
185 autoBootstrapProjectFromCwd: undefined,
186 logWebSocketEvents: undefined,
187 host: undefined,
188 port: undefined,
189 devUrl: undefined,
190 });
191
192 assert.equal(env.T3CODE_HOME, undefined);
193 assert.equal(env.T3CODE_NO_BROWSER, "1");
194 }),
195 );
196
197 it.effect("allows browser auto-open to be explicitly enabled", () =>
198 Effect.gen(function* () {
199 const env = yield* createDevRunnerEnv({
200 mode: "dev",
201 baseEnv: {},
202 serverOffset: 0,
203 webOffset: 0,
204 t3Home: undefined,
205 browser: true,
206 autoBootstrapProjectFromCwd: undefined,
207 logWebSocketEvents: undefined,
208 host: undefined,
209 port: undefined,
210 devUrl: undefined,
211 });
212
213 assert.equal(env.T3CODE_NO_BROWSER, "0");
214 }),
215 );
216
217 it.effect("requires the browser flag even when the environment enables auto-open", () =>
218 Effect.gen(function* () {
219 const env = yield* createDevRunnerEnv({
220 mode: "dev",
221 baseEnv: { T3CODE_NO_BROWSER: "0" },
222 serverOffset: 0,
223 webOffset: 0,
224 t3Home: undefined,
225 browser: false,
226 autoBootstrapProjectFromCwd: undefined,
227 logWebSocketEvents: undefined,
228 host: undefined,
229 port: undefined,
230 devUrl: undefined,
231 });
232
233 assert.equal(env.T3CODE_NO_BROWSER, "1");
234 }),
235 );
236
237 it.effect("supports explicit typed overrides", () =>
238 Effect.gen(function* () {
239 const path = yield* Path.Path;
240 const env = yield* createDevRunnerEnv({
241 mode: "dev:server",
242 baseEnv: {},
243 serverOffset: 0,
244 webOffset: 0,
245 t3Home: "/tmp/custom-t3",
246 browser: false,
247 autoBootstrapProjectFromCwd: false,
248 logWebSocketEvents: true,
249 host: "0.0.0.0",
250 port: 4222,
251 devUrl: new URL("http://localhost:7331"),
252 });
253
254 assert.equal(env.T3CODE_HOME, path.resolve("/tmp/custom-t3"));
255 assert.equal(env.T3CODE_PORT, "4222");
256 assert.equal(env.VITE_HTTP_URL, "http://localhost:4222");
257 assert.equal(env.VITE_WS_URL, "ws://localhost:4222");
258 assert.equal(env.T3CODE_NO_BROWSER, "1");
259 assert.equal(env.T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD, "0");
260 assert.equal(env.T3CODE_LOG_WS_EVENTS, "1");
261 assert.equal(env.T3CODE_HOST, "0.0.0.0");
262 assert.equal(env.VITE_DEV_SERVER_URL, "http://localhost:7331/");
263 }),
264 );
265
266 it.effect("strips inherited service-launcher context", () =>
267 Effect.gen(function* () {
268 const env = yield* createDevRunnerEnv({
269 mode: "dev",
270 baseEnv: {
271 T3_SERVICE_LAUNCHER_CONTEXT: '{"childVersion":"9.9.9"}',
272 T3_BOOT_SERVICE_UNIT: "t3code.service",
273 },
274 serverOffset: 0,
275 webOffset: 0,
276 t3Home: undefined,
277 browser: undefined,
278 autoBootstrapProjectFromCwd: undefined,
279 logWebSocketEvents: undefined,
280 host: undefined,
281 port: undefined,
282 devUrl: undefined,
283 });
284
285 assert.equal(env.T3_SERVICE_LAUNCHER_CONTEXT, undefined);
286 assert.equal(env.T3_BOOT_SERVICE_UNIT, undefined);
287 }),
288 );
289
290 it.effect("does not force websocket logging on in dev mode when unset", () =>
291 Effect.gen(function* () {
292 const env = yield* createDevRunnerEnv({
293 mode: "dev",
294 baseEnv: {
295 T3CODE_LOG_WS_EVENTS: "keep-me-out",
296 },
297 serverOffset: 0,
298 webOffset: 0,
299 t3Home: undefined,
300 browser: undefined,
301 autoBootstrapProjectFromCwd: undefined,
302 logWebSocketEvents: undefined,
303 host: undefined,
304 port: undefined,
305 devUrl: undefined,
306 });
307
308 assert.equal(env.T3CODE_MODE, "web");
309 assert.equal(env.T3CODE_LOG_WS_EVENTS, undefined);
310 }),
311 );
312
313 it.effect("forwards explicit websocket logging false without coercing it away", () =>
314 Effect.gen(function* () {
315 const env = yield* createDevRunnerEnv({
316 mode: "dev",
317 baseEnv: {
318 T3CODE_LOG_WS_EVENTS: "1",
319 },
320 serverOffset: 0,
321 webOffset: 0,
322 t3Home: undefined,
323 browser: undefined,
324 autoBootstrapProjectFromCwd: undefined,
325 logWebSocketEvents: false,
326 host: undefined,
327 port: undefined,
328 devUrl: undefined,
329 });
330
331 assert.equal(env.T3CODE_LOG_WS_EVENTS, "0");
332 }),
333 );
334
335 it.effect("uses custom t3Home when provided", () =>
336 Effect.gen(function* () {
337 const path = yield* Path.Path;
338 const env = yield* createDevRunnerEnv({
339 mode: "dev",
340 baseEnv: {},
341 serverOffset: 0,
342 webOffset: 0,
343 t3Home: "/tmp/my-t3",
344 browser: undefined,
345 autoBootstrapProjectFromCwd: undefined,
346 logWebSocketEvents: undefined,
347 host: undefined,
348 port: undefined,
349 devUrl: undefined,
350 });
351
352 assert.equal(env.T3CODE_HOME, path.resolve("/tmp/my-t3"));
353 }),
354 );
355
356 it.effect("pins desktop dev to a stable backend port and websocket url", () =>
357 Effect.gen(function* () {
358 const path = yield* Path.Path;
359 const env = yield* createDevRunnerEnv({
360 mode: "dev:desktop",
361 baseEnv: {
362 T3CODE_PORT: "13773",
363 T3CODE_MODE: "web",
364 T3CODE_NO_BROWSER: "0",
365 T3CODE_HOST: "0.0.0.0",
366 VITE_DEV_SERVER_URL: "http://127.0.0.1:8526",
367 VITE_WS_URL: "ws://localhost:13773",
368 },
369 serverOffset: 0,
370 webOffset: 0,
371 t3Home: "/tmp/my-t3",
372 browser: true,
373 autoBootstrapProjectFromCwd: undefined,
374 logWebSocketEvents: undefined,
375 host: "127.0.0.1",
376 port: 4222,
377 devUrl: undefined,
378 });
379
380 assert.equal(env.T3CODE_HOME, path.resolve("/tmp/my-t3"));
381 assert.equal(env.PORT, "5733");
382 assert.equal(env.VITE_DEV_SERVER_URL, "http://127.0.0.1:5733");
383 assert.equal(env.HOST, "127.0.0.1");
384 assert.equal(env.T3CODE_PORT, "4222");
385 assert.equal(env.VITE_HTTP_URL, "http://127.0.0.1:4222");
386 assert.equal(env.T3CODE_MODE, undefined);
387 assert.equal(env.T3CODE_NO_BROWSER, undefined);
388 assert.equal(env.T3CODE_HOST, undefined);
389 assert.equal(env.VITE_WS_URL, "ws://127.0.0.1:4222");
390 }),
391 );
392
393 it.effect("defaults dev server mode to the higher backend port range", () =>
394 Effect.gen(function* () {
395 const env = yield* createDevRunnerEnv({
396 mode: "dev",
397 baseEnv: {},
398 serverOffset: 0,
399 webOffset: 0,
400 t3Home: undefined,
401 browser: undefined,
402 autoBootstrapProjectFromCwd: undefined,
403 logWebSocketEvents: undefined,
404 host: undefined,
405 port: undefined,
406 devUrl: undefined,
407 });
408
409 assert.equal(env.T3CODE_PORT, "13773");
410 assert.equal(env.PORT, "5733");
411 }),
412 );
413
414 // Browser dev is single-origin: Vite proxies the backend, and the client
415 // resolves it from window.location.origin. Baking a localhost URL here is
416 // what breaks sharing a dev server to another device.
417 it.effect.each(["dev", "dev:web"] as const)(
418 "leaves the client backend URLs unset in %s mode",
419 (mode) =>
420 Effect.gen(function* () {
421 const env = yield* createDevRunnerEnv({
422 mode,
423 baseEnv: {
424 VITE_HTTP_URL: "http://localhost:1234",
425 VITE_WS_URL: "ws://localhost:1234",
426 },
427 serverOffset: 0,
428 webOffset: 0,
429 t3Home: undefined,
430 browser: undefined,
431 autoBootstrapProjectFromCwd: undefined,
432 logWebSocketEvents: undefined,
433 host: undefined,
434 port: undefined,
435 devUrl: undefined,
436 });
437
438 assert.equal(env.VITE_HTTP_URL, undefined);
439 assert.equal(env.VITE_WS_URL, undefined);
440 assert.equal(env.T3CODE_PORT, "13773");
441 // Deleting the keys is not sufficient — vite.config.ts merges
442 // `.env`/`.env.local` underneath this env and would revive them, so
443 // the intent has to be stated positively.
444 assert.equal(env.T3CODE_SINGLE_ORIGIN_DEV, "1");
445 }),
446 );
447
448 // Desktop pins the renderer at loopback deliberately; an ambient marker
449 // must not make Vite discard those URLs.
450 it.effect("clears the single-origin marker in dev:desktop mode", () =>
451 Effect.gen(function* () {
452 const env = yield* createDevRunnerEnv({
453 mode: "dev:desktop",
454 baseEnv: { T3CODE_SINGLE_ORIGIN_DEV: "1" },
455 serverOffset: 0,
456 webOffset: 0,
457 t3Home: undefined,
458 browser: undefined,
459 autoBootstrapProjectFromCwd: undefined,
460 logWebSocketEvents: undefined,
461 host: undefined,
462 port: undefined,
463 devUrl: undefined,
464 });
465
466 assert.equal(env.T3CODE_SINGLE_ORIGIN_DEV, undefined);
467 assert.equal(env.VITE_HTTP_URL, "http://127.0.0.1:13773");
468 }),
469 );
470
471 it.effect("clears the single-origin marker in dev:server mode", () =>
472 Effect.gen(function* () {
473 const env = yield* createDevRunnerEnv({
474 mode: "dev:server",
475 baseEnv: { T3CODE_SINGLE_ORIGIN_DEV: "1" },
476 serverOffset: 0,
477 webOffset: 0,
478 t3Home: undefined,
479 browser: undefined,
480 autoBootstrapProjectFromCwd: undefined,
481 logWebSocketEvents: undefined,
482 host: undefined,
483 port: undefined,
484 devUrl: undefined,
485 });
486
487 assert.equal(env.T3CODE_SINGLE_ORIGIN_DEV, undefined);
488 assert.equal(env.VITE_HTTP_URL, "http://localhost:13773");
489 }),
490 );
491
492 // HOST is Vite's bind address and gates the HMR pin in vite.config.ts. An
493 // inherited one would survive into browser dev and point HMR at the wrong
494 // interface — invisible over a shared origin, since the page still loads.
495 it.effect.each(["dev", "dev:web"] as const)("drops an inherited HOST in %s mode", (mode) =>
496 Effect.gen(function* () {
497 const env = yield* createDevRunnerEnv({
498 mode,
499 baseEnv: { HOST: "0.0.0.0" },
500 serverOffset: 0,
501 webOffset: 0,
502 t3Home: undefined,
503 browser: undefined,
504 autoBootstrapProjectFromCwd: undefined,
505 logWebSocketEvents: undefined,
506 host: undefined,
507 port: undefined,
508 devUrl: undefined,
509 });
510
511 assert.equal(env.HOST, undefined);
512 }),
513 );
514
515 // --host configures the *backend* (T3CODE_HOST). It must not become Vite's
516 // bind address by way of an inherited HOST that happens to agree with it.
517 it.effect("drops an inherited HOST even when --host is given", () =>
518 Effect.gen(function* () {
519 const env = yield* createDevRunnerEnv({
520 mode: "dev",
521 baseEnv: { HOST: "0.0.0.0" },
522 serverOffset: 0,
523 webOffset: 0,
524 t3Home: undefined,
525 browser: undefined,
526 autoBootstrapProjectFromCwd: undefined,
527 logWebSocketEvents: undefined,
528 host: "0.0.0.0",
529 port: undefined,
530 devUrl: undefined,
531 });
532
533 assert.equal(env.HOST, undefined);
534 assert.equal(env.T3CODE_HOST, "0.0.0.0");
535 }),
536 );
537
538 // Desktop sets HOST itself, so the clearing must not reach it.
539 it.effect("still pins HOST for dev:desktop", () =>
540 Effect.gen(function* () {
541 const env = yield* createDevRunnerEnv({
542 mode: "dev:desktop",
543 baseEnv: { HOST: "0.0.0.0" },
544 serverOffset: 0,
545 webOffset: 0,
546 t3Home: undefined,
547 browser: undefined,
548 autoBootstrapProjectFromCwd: undefined,
549 logWebSocketEvents: undefined,
550 host: undefined,
551 port: undefined,
552 devUrl: undefined,
553 });
554
555 assert.equal(env.HOST, "127.0.0.1");
556 }),
557 );
558
559 it.effect("keeps explicit backend URLs for the desktop renderer", () =>
560 Effect.gen(function* () {
561 const env = yield* createDevRunnerEnv({
562 mode: "dev:desktop",
563 baseEnv: {},
564 serverOffset: 0,
565 webOffset: 0,
566 t3Home: undefined,
567 browser: undefined,
568 autoBootstrapProjectFromCwd: undefined,
569 logWebSocketEvents: undefined,
570 host: undefined,
571 port: undefined,
572 devUrl: undefined,
573 });
574
575 assert.equal(env.VITE_HTTP_URL, "http://127.0.0.1:13773");
576 assert.equal(env.VITE_WS_URL, "ws://127.0.0.1:13773");
577 }),
578 );
579 });
580
581 describe("findFirstAvailableOffset", () => {
582 it.effect("returns the starting offset when required ports are available", () =>
583 Effect.gen(function* () {
584 const offset = yield* findFirstAvailableOffset({
585 startOffset: 0,
586 requireServerPort: true,
587 requireWebPort: true,
588 checkPortAvailability: () => Effect.succeed(true),
589 });
590
591 assert.equal(offset, 0);
592 }),
593 );
594
595 it.effect("advances until all required ports are available", () =>
596 Effect.gen(function* () {
597 const taken = new Set([13773, 5733, 13774, 5734]);
598 const offset = yield* findFirstAvailableOffset({
599 startOffset: 0,
600 requireServerPort: true,
601 requireWebPort: true,
602 checkPortAvailability: (port) => Effect.succeed(!taken.has(port)),
603 });
604
605 assert.equal(offset, 2);
606 }),
607 );
608
609 it.effect("skips browser-blocked web ports before probing availability", () =>
610 Effect.gen(function* () {
611 const probed: Array<{ port: number; role: string | undefined }> = [];
612 const offset = yield* findFirstAvailableOffset({
613 // 5733 + 833 = 6566, which browsers block as sane-port.
614 startOffset: 833,
615 requireServerPort: true,
616 requireWebPort: true,
617 checkPortAvailability: (port, role) => {
618 probed.push({ port, role });
619 return Effect.succeed(true);
620 },
621 });
622
623 assert.equal(offset, 834);
624 assert.deepStrictEqual(probed, [
625 { port: 14_607, role: "server" },
626 { port: 6567, role: "web" },
627 ]);
628 }),
629 );
630
631 it.effect("does not reject a server-only offset because its unused web port is blocked", () =>
632 Effect.gen(function* () {
633 const offset = yield* findFirstAvailableOffset({
634 startOffset: 833,
635 requireServerPort: true,
636 requireWebPort: false,
637 checkPortAvailability: () => Effect.succeed(true),
638 });
639
640 assert.equal(offset, 833);
641 }),
642 );
643
644 it.effect("allows offsets where the non-required server port exceeds max", () =>
645 Effect.gen(function* () {
646 const offset = yield* findFirstAvailableOffset({
647 startOffset: 59_802,
648 requireServerPort: false,
649 requireWebPort: true,
650 checkPortAvailability: () => Effect.succeed(true),
651 });
652
653 assert.equal(offset, 59_802);
654 }),
655 );
656
657 it.effect("reports the exhausted range and required port set", () =>
658 Effect.gen(function* () {
659 const error = yield* findFirstAvailableOffset({
660 startOffset: 51_763,
661 requireServerPort: true,
662 requireWebPort: false,
663 checkPortAvailability: () => Effect.succeed(true),
664 }).pipe(Effect.flip);
665
666 if (error._tag !== "DevRunnerPortExhaustedError") {
667 assert.fail(`Unexpected error: ${error._tag}`);
668 }
669 assert.equal(error.startOffset, 51_763);
670 assert.equal(error.requireServerPort, true);
671 assert.equal(error.requireWebPort, false);
672 assert.equal(error.baseServerPort, 13_773);
673 assert.equal(error.baseWebPort, 5_733);
674 assert.equal(error.maximumPort, 65_535);
675 assert.ok(!("cause" in error));
676 }),
677 );
678 });
679
680 describe("isBrowserAllowedPort", () => {
681 it.each([6000, 6566, 6665, 6666, 6667, 6668, 6669, 6679, 6697])(
682 "rejects Fetch-blocked web port %s from the worktree offset range",
683 (port) => {
684 assert.equal(isBrowserAllowedPort(port), false);
685 },
686 );
687
688 it.each([5733, 5900, 6567, 6670, 8733])("allows browser-safe web port %s", (port) => {
689 assert.equal(isBrowserAllowedPort(port), true);
690 });
691 });
692
693 describe("checkPortAvailabilityOnHosts", () => {
694 it.effect("checks overlapping hosts sequentially to avoid self-interference", () =>
695 Effect.gen(function* () {
696 let inFlightCount = 0;
697 const calls: Array<[number, string]> = [];
698
699 const available = yield* checkPortAvailabilityOnHosts(
700 13_773,
701 ["127.0.0.1", "0.0.0.0", "::"],
702 (port, host) =>
703 Effect.promise(async () => {
704 calls.push([port, host]);
705 inFlightCount += 1;
706 const overlapped = inFlightCount > 1;
707 await Promise.resolve();
708 inFlightCount -= 1;
709 return !overlapped;
710 }),
711 );
712
713 assert.equal(available, true);
714 assert.deepStrictEqual(calls, [
715 [13_773, "127.0.0.1"],
716 [13_773, "0.0.0.0"],
717 [13_773, "::"],
718 ]);
719 }),
720 );
721 });
722
723 describe("devPortProbeHosts", () => {
724 it.effect("probes loopback only when no bind host is configured", () =>
725 Effect.sync(() => {
726 assert.deepStrictEqual(devPortProbeHosts(undefined), ["127.0.0.1", "::1"]);
727 assert.deepStrictEqual(devPortProbeHosts(" "), ["127.0.0.1", "::1"]);
728 }),
729 );
730
731 // A port free on loopback can be taken on the interface the server will
732 // actually bind, so --host/T3CODE_HOST has to be probed as well.
733 it.effect("adds a non-loopback bind host to the probe list", () =>
734 Effect.sync(() => {
735 assert.deepStrictEqual(devPortProbeHosts("0.0.0.0"), ["127.0.0.1", "::1", "0.0.0.0"]);
736 assert.deepStrictEqual(devPortProbeHosts("192.168.1.10"), [
737 "127.0.0.1",
738 "::1",
739 "192.168.1.10",
740 ]);
741 }),
742 );
743
744 it.effect("does not probe loopback twice when it is the configured host", () =>
745 Effect.sync(() => {
746 assert.deepStrictEqual(devPortProbeHosts("127.0.0.1"), ["127.0.0.1", "::1"]);
747 }),
748 );
749
750 // Only the backend honours --host/T3CODE_HOST. Vite reads HOST (set for
751 // desktop only), so judging the web port against the backend's interface
752 // would reject ports for a server that never binds there.
753 it.effect("passes the port role so only the server port sees the bind host", () =>
754 Effect.gen(function* () {
755 const probed: Array<{ port: number; role: string | undefined }> = [];
756
757 yield* resolveModePortOffsets({
758 mode: "dev",
759 startOffset: 0,
760 hasExplicitServerPort: false,
761 hasExplicitDevUrl: false,
762 checkPortAvailability: (port, role) => {
763 probed.push({ port, role });
764 return Effect.succeed(true);
765 },
766 });
767
768 assert.deepStrictEqual(probed, [
769 { port: 13_773, role: "server" },
770 { port: 5733, role: "web" },
771 ]);
772 }),
773 );
774 });
775
776 describe("resolveModePortOffsets", () => {
777 it.effect("uses a shared fallback offset for dev mode", () =>
778 Effect.gen(function* () {
779 const taken = new Set([13773, 5733]);
780 const offsets = yield* resolveModePortOffsets({
781 mode: "dev",
782 startOffset: 0,
783 hasExplicitServerPort: false,
784 hasExplicitDevUrl: false,
785 checkPortAvailability: (port) => Effect.succeed(!taken.has(port)),
786 });
787
788 assert.deepStrictEqual(offsets, { serverOffset: 1, webOffset: 1 });
789 }),
790 );
791
792 it.effect("keeps server offset stable for dev:web and only shifts web offset", () =>
793 Effect.gen(function* () {
794 const taken = new Set([5733]);
795 const offsets = yield* resolveModePortOffsets({
796 mode: "dev:web",
797 startOffset: 0,
798 hasExplicitServerPort: false,
799 hasExplicitDevUrl: false,
800 checkPortAvailability: (port) => Effect.succeed(!taken.has(port)),
801 });
802
803 assert.deepStrictEqual(offsets, { serverOffset: 0, webOffset: 1 });
804 }),
805 );
806
807 it.effect("shifts only server offset for dev:server", () =>
808 Effect.gen(function* () {
809 const taken = new Set([13773]);
810 const offsets = yield* resolveModePortOffsets({
811 mode: "dev:server",
812 startOffset: 0,
813 hasExplicitServerPort: false,
814 hasExplicitDevUrl: false,
815 checkPortAvailability: (port) => Effect.succeed(!taken.has(port)),
816 });
817
818 assert.deepStrictEqual(offsets, { serverOffset: 1, webOffset: 1 });
819 }),
820 );
821
822 it.effect("respects explicit dev-url override for dev:web", () =>
823 Effect.gen(function* () {
824 const offsets = yield* resolveModePortOffsets({
825 mode: "dev:web",
826 startOffset: 0,
827 hasExplicitServerPort: false,
828 hasExplicitDevUrl: true,
829 checkPortAvailability: () => Effect.succeed(false),
830 });
831
832 assert.deepStrictEqual(offsets, { serverOffset: 0, webOffset: 0 });
833 }),
834 );
835
836 it.effect("respects explicit server port override for dev:server", () =>
837 Effect.gen(function* () {
838 const offsets = yield* resolveModePortOffsets({
839 mode: "dev:server",
840 startOffset: 0,
841 hasExplicitServerPort: true,
842 hasExplicitDevUrl: false,
843 checkPortAvailability: () => Effect.succeed(false),
844 });
845
846 assert.deepStrictEqual(offsets, { serverOffset: 0, webOffset: 0 });
847 }),
848 );
849 });
850
851 describe("runDevRunnerWithInput", () => {
852 it.effect("preserves invalid configuration as the exact cause", () =>
853 Effect.gen(function* () {
854 const error = yield* runDevRunnerWithInput({ ...devServerInput, dryRun: true }).pipe(
855 Effect.provide(
856 Layer.merge(
857 netServiceLayer,
858 ConfigProvider.layer(
859 ConfigProvider.fromEnv({ env: { T3CODE_PORT_OFFSET: "not-an-integer" } }),
860 ),
861 ),
862 ),
863 Effect.flip,
864 );
865
866 if (error._tag !== "DevRunnerConfigurationError") {
867 assert.fail(`Unexpected error: ${error._tag}`);
868 }
869 assert.deepStrictEqual(error.configKeys, ["T3CODE_PORT_OFFSET", "T3CODE_DEV_INSTANCE"]);
870 assert.ok(error.cause !== undefined);
871 assert.ok(!error.message.includes(String((error.cause as Error).message)));
872 }),
873 );
874
875 it.effect("preserves process spawn context and the exact platform cause", () => {
876 const cause = PlatformError.systemError({
877 _tag: "NotFound",
878 module: "ChildProcess",
879 method: "spawn",
880 description: "vp was not found",
881 });
882 const spawnerLayer = Layer.succeed(
883 ChildProcessSpawner.ChildProcessSpawner,
884 ChildProcessSpawner.make(() => Effect.fail(cause)),
885 );
886
887 return Effect.gen(function* () {
888 const error = yield* runDevRunnerWithInput(devServerInput).pipe(
889 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
890 Effect.provideService(HostProcessPlatform, "linux"),
891 Effect.flip,
892 );
893
894 if (error._tag !== "DevRunnerProcessError") {
895 assert.fail(`Unexpected error: ${error._tag}`);
896 }
897 assert.equal(error.operation, "spawn");
898 assert.equal(error.mode, "dev:server");
899 assert.equal(error.executable, "vp");
900 assert.equal(error.argumentCount, 5);
901 assert.equal(error.shell, false);
902 assert.equal(error.cause, cause);
903 assert.ok(!error.message.includes(cause.message));
904 assert.notProperty(error, "args");
905 assert.notInclude(error.message, "secret-token-value");
906 });
907 });
908
909 // `tailscale serve` config outlives the process, so a dry run that shared
910 // would replace and then tear down whatever mapping the port already had.
911 // Base-dir precedence (--home-dir > worktree .t3 > ambient T3CODE_HOME)
912 // lives in runDevRunnerWithInput; the env builder must not consult the
913 // ambient variable on its own, or it would silently outrank the worktree
914 // default and land dev state on the user's real database.
915 it.effect("ignores an ambient T3CODE_HOME when no home is resolved", () =>
916 Effect.gen(function* () {
917 const env = yield* createDevRunnerEnv({
918 mode: "dev",
919 baseEnv: { T3CODE_HOME: "/home/user/.t3" },
920 serverOffset: 0,
921 webOffset: 0,
922 t3Home: undefined,
923 browser: undefined,
924 autoBootstrapProjectFromCwd: undefined,
925 logWebSocketEvents: undefined,
926 host: undefined,
927 port: undefined,
928 devUrl: undefined,
929 });
930
931 assert.equal(env.T3CODE_HOME, undefined);
932 }),
933 );
934
935 // Sharing dev:desktop would publish a URL whose renderer dials the
936 // visitor's own loopback, and would clobber the VITE_DEV_SERVER_URL that
937 // Electron loads from. It must decline, not half-work.
938 it.effect("declines to share for dev:desktop and still starts the stack", () => {
939 let spawnCount = 0;
940 const spawnerLayer = Layer.succeed(
941 ChildProcessSpawner.ChildProcessSpawner,
942 ChildProcessSpawner.make(() => {
943 spawnCount += 1;
944 return Effect.succeed(mockProcess(0));
945 }),
946 );
947
948 return Effect.gen(function* () {
949 yield* runDevRunnerWithInput({
950 ...devServerInput,
951 mode: "dev:desktop",
952 port: undefined,
953 share: true,
954 }).pipe(
955 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
956 Effect.provideService(HostProcessPlatform, "linux"),
957 );
958
959 assert.equal(spawnCount, 1);
960 });
961 });
962
963 // Single-origin browser dev proxies the backend at localhost, so a backend
964 // bound only to a specific interface breaks every proxied request in a way
965 // that looks like a broken server. Reject the combination up front.
966 it.effect("rejects a specific non-loopback --host for browser dev modes", () => {
967 const spawnerLayer = Layer.succeed(
968 ChildProcessSpawner.ChildProcessSpawner,
969 ChildProcessSpawner.make(() => Effect.succeed(mockProcess(0))),
970 );
971
972 return Effect.gen(function* () {
973 const error = yield* runDevRunnerWithInput({
974 ...devServerInput,
975 mode: "dev",
976 port: undefined,
977 host: "192.168.1.10",
978 }).pipe(
979 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
980 Effect.provideService(HostProcessPlatform, "linux"),
981 Effect.flip,
982 );
983
984 if (error._tag !== "DevRunnerHostNotProxiableError") {
985 assert.fail(`Unexpected error: ${error._tag}`);
986 }
987 assert.equal(error.mode, "dev");
988 assert.equal(error.host, "192.168.1.10");
989 assert.include(error.message, "0.0.0.0");
990 assert.include(error.message, "--share");
991 });
992 });
993
994 // Wildcards keep loopback answering, so the proxy target stays valid and
995 // the combination must keep working — it is the documented way to serve a
996 // LAN interface and the browser proxy at once.
997 it.effect("still spawns the stack for a wildcard --host in dev mode", () => {
998 let spawnCount = 0;
999 const spawnerLayer = Layer.succeed(
1000 ChildProcessSpawner.ChildProcessSpawner,
1001 ChildProcessSpawner.make(() => {
1002 spawnCount += 1;
1003 return Effect.succeed(mockProcess(0));
1004 }),
1005 );
1006
1007 return Effect.gen(function* () {
1008 yield* runDevRunnerWithInput({
1009 ...devServerInput,
1010 mode: "dev",
1011 port: undefined,
1012 host: "0.0.0.0",
1013 }).pipe(
1014 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1015 Effect.provideService(HostProcessPlatform, "linux"),
1016 );
1017
1018 assert.equal(spawnCount, 1);
1019 });
1020 });
1021
1022 // dev:server does not proxy — the client talks to the backend directly —
1023 // so a specific interface bind stays legitimate there.
1024 it.effect("keeps a specific --host working for dev:server", () => {
1025 let spawnCount = 0;
1026 const spawnerLayer = Layer.succeed(
1027 ChildProcessSpawner.ChildProcessSpawner,
1028 ChildProcessSpawner.make(() => {
1029 spawnCount += 1;
1030 return Effect.succeed(mockProcess(0));
1031 }),
1032 );
1033
1034 return Effect.gen(function* () {
1035 yield* runDevRunnerWithInput({
1036 ...devServerInput,
1037 host: "192.168.1.10",
1038 }).pipe(
1039 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1040 Effect.provideService(HostProcessPlatform, "linux"),
1041 );
1042
1043 assert.equal(spawnCount, 1);
1044 });
1045 });
1046
1047 // A shared origin means a remote browser, where unbundled dev's
1048 // per-module waterfall pays a tailnet round trip per import level. The
1049 // runner defaults bundled dev on for the spawned stack, but only
1050 // defaults: an explicit T3CODE_BUNDLED_DEV (even "0") must pass through.
1051 describe("--share bundled dev default", () => {
1052 const shareSpawnedEnv = (input: { readonly ambientBundledDev: string | undefined }) =>
1053 Effect.gen(function* () {
1054 let captured: Record<string, string | undefined> | undefined;
1055 const spawnerLayer = Layer.succeed(
1056 ChildProcessSpawner.ChildProcessSpawner,
1057 ChildProcessSpawner.make((command) => {
1058 const spawned = command as unknown as {
1059 readonly command: string;
1060 readonly args: ReadonlyArray<string>;
1061 readonly options?: { readonly env?: Record<string, string | undefined> };
1062 };
1063 if (spawned.command === "vp") {
1064 captured = spawned.options?.env;
1065 return Effect.succeed(mockProcess(0));
1066 }
1067 // tailscale: answer `status --json` with a valid tailnet name,
1068 // succeed the `serve`/`off` calls.
1069 return Effect.succeed(
1070 ChildProcessSpawner.makeHandle({
1071 pid: ChildProcessSpawner.ProcessId(2),
1072 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
1073 isRunning: Effect.succeed(false),
1074 kill: () => Effect.void,
1075 unref: Effect.succeed(Effect.void),
1076 stdin: Sink.drain,
1077 stdout: spawned.args.includes("status")
1078 ? Stream.make(
1079 new TextEncoder().encode(
1080 JSON.stringify({ Self: { DNSName: "host.example.ts.net." } }),
1081 ),
1082 )
1083 : Stream.empty,
1084 stderr: Stream.empty,
1085 all: Stream.empty,
1086 getInputFd: () => Sink.drain,
1087 getOutputFd: () => Stream.empty,
1088 }),
1089 );
1090 }),
1091 );
1092
1093 yield* runDevRunnerWithInput({
1094 ...devServerInput,
1095 mode: "dev",
1096 port: undefined,
1097 share: true,
1098 }).pipe(
1099 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1100 Effect.provideService(HostProcessPlatform, "linux"),
1101 Effect.provideService(
1102 HostProcessEnvironment,
1103 input.ambientBundledDev === undefined
1104 ? {}
1105 : { T3CODE_BUNDLED_DEV: input.ambientBundledDev },
1106 ),
1107 );
1108
1109 return captured;
1110 });
1111
1112 it.effect("defaults T3CODE_BUNDLED_DEV=1 for a shared run", () =>
1113 Effect.gen(function* () {
1114 const env = yield* shareSpawnedEnv({ ambientBundledDev: undefined });
1115 assert.equal(env?.T3CODE_BUNDLED_DEV, "1");
1116 }),
1117 );
1118
1119 it.effect("keeps an explicit T3CODE_BUNDLED_DEV=0 opt-out", () =>
1120 Effect.gen(function* () {
1121 const env = yield* shareSpawnedEnv({ ambientBundledDev: "0" });
1122 assert.equal(env?.T3CODE_BUNDLED_DEV, "0");
1123 }),
1124 );
1125
1126 it.effect("leaves T3CODE_BUNDLED_DEV unset without --share", () =>
1127 Effect.gen(function* () {
1128 let captured: Record<string, string | undefined> | undefined;
1129 const spawnerLayer = Layer.succeed(
1130 ChildProcessSpawner.ChildProcessSpawner,
1131 ChildProcessSpawner.make((command) => {
1132 captured = (
1133 command as {
1134 readonly options?: { readonly env?: Record<string, string | undefined> };
1135 }
1136 ).options?.env;
1137 return Effect.succeed(mockProcess(0));
1138 }),
1139 );
1140
1141 yield* runDevRunnerWithInput({
1142 ...devServerInput,
1143 mode: "dev",
1144 port: undefined,
1145 }).pipe(
1146 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1147 Effect.provideService(HostProcessPlatform, "linux"),
1148 Effect.provideService(HostProcessEnvironment, {}),
1149 );
1150
1151 assert.equal(captured?.T3CODE_BUNDLED_DEV, undefined);
1152 }),
1153 );
1154 });
1155
1156 it.effect("spawns nothing when --dry-run is combined with --share", () => {
1157 let spawnCount = 0;
1158 const spawnerLayer = Layer.succeed(
1159 ChildProcessSpawner.ChildProcessSpawner,
1160 ChildProcessSpawner.make(() => {
1161 spawnCount += 1;
1162 return Effect.succeed(mockProcess(0));
1163 }),
1164 );
1165
1166 return Effect.gen(function* () {
1167 yield* runDevRunnerWithInput({
1168 ...devServerInput,
1169 mode: "dev",
1170 port: undefined,
1171 dryRun: true,
1172 share: true,
1173 }).pipe(
1174 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1175 Effect.provideService(HostProcessPlatform, "linux"),
1176 );
1177
1178 assert.equal(spawnCount, 0);
1179 });
1180 });
1181
1182 it.effect("reports non-zero exits without manufacturing a cause", () => {
1183 const spawnerLayer = Layer.succeed(
1184 ChildProcessSpawner.ChildProcessSpawner,
1185 ChildProcessSpawner.make(() => Effect.succeed(mockProcess(17))),
1186 );
1187
1188 return Effect.gen(function* () {
1189 const error = yield* runDevRunnerWithInput(devServerInput).pipe(
1190 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1191 Effect.provideService(HostProcessPlatform, "linux"),
1192 Effect.flip,
1193 );
1194
1195 if (error._tag !== "DevRunnerProcessExitError") {
1196 assert.fail(`Unexpected error: ${error._tag}`);
1197 }
1198 assert.equal(error.mode, "dev:server");
1199 assert.equal(error.executable, "vp");
1200 assert.equal(error.argumentCount, 5);
1201 assert.equal(error.shell, false);
1202 assert.equal(error.exitCode, 17);
1203 assert.ok(!("cause" in error));
1204 assert.notProperty(error, "args");
1205 assert.notInclude(error.message, "secret-token-value");
1206 });
1207 });
1208
1209 it.effect("preserves wait-for-exit failures as the exact cause", () => {
1210 const cause = PlatformError.systemError({
1211 _tag: "Unknown",
1212 module: "ChildProcess",
1213 method: "exitCode",
1214 description: "process status became unavailable",
1215 });
1216 const spawnerLayer = Layer.succeed(
1217 ChildProcessSpawner.ChildProcessSpawner,
1218 ChildProcessSpawner.make(() => Effect.succeed(mockProcess(cause))),
1219 );
1220
1221 return Effect.gen(function* () {
1222 const error = yield* runDevRunnerWithInput(devServerInput).pipe(
1223 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1224 Effect.provideService(HostProcessPlatform, "linux"),
1225 Effect.flip,
1226 );
1227
1228 if (error._tag !== "DevRunnerProcessError") {
1229 assert.fail(`Unexpected error: ${error._tag}`);
1230 }
1231 assert.equal(error.operation, "wait-for-exit");
1232 assert.equal(error.mode, "dev:server");
1233 assert.equal(error.executable, "vp");
1234 assert.equal(error.argumentCount, 5);
1235 assert.equal(error.shell, false);
1236 assert.equal(error.cause, cause);
1237 assert.ok(!error.message.includes(cause.message));
1238 assert.notProperty(error, "args");
1239 assert.notInclude(error.message, "secret-token-value");
1240 });
1241 });
1242
1243 describe("t3 home precedence", () => {
1244 const makeWorktree = Effect.acquireRelease(
1245 Effect.sync(() => {
1246 const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-devrunner-"));
1247 NodeFS.writeFileSync(
1248 NodePath.join(root, ".git"),
1249 "gitdir: /elsewhere/.git/worktrees/x\n",
1250 );
1251 return root;
1252 }),
1253 (root) => Effect.sync(() => NodeFS.rmSync(root, { recursive: true, force: true })),
1254 );
1255
1256 const spawnedHome = (input: {
1257 readonly t3Home: string | undefined;
1258 readonly cwd: string;
1259 readonly ambientHome: string | undefined;
1260 }) =>
1261 Effect.gen(function* () {
1262 let captured: Record<string, string | undefined> | undefined;
1263 const spawnerLayer = Layer.succeed(
1264 ChildProcessSpawner.ChildProcessSpawner,
1265 ChildProcessSpawner.make((command) => {
1266 captured = (
1267 command as {
1268 readonly options?: { readonly env?: Record<string, string | undefined> };
1269 }
1270 ).options?.env;
1271 return Effect.succeed(mockProcess(0));
1272 }),
1273 );
1274
1275 yield* runDevRunnerWithInput({ ...devServerInput, t3Home: input.t3Home }).pipe(
1276 Effect.provide(Layer.mergeAll(emptyConfigLayer, netServiceLayer, spawnerLayer)),
1277 Effect.provideService(HostProcessPlatform, "linux"),
1278 Effect.provideService(HostProcessWorkingDirectory, input.cwd),
1279 Effect.provideService(
1280 HostProcessEnvironment,
1281 input.ambientHome === undefined ? {} : { T3CODE_HOME: input.ambientHome },
1282 ),
1283 );
1284
1285 return captured?.T3CODE_HOME;
1286 });
1287
1288 it.effect("prefers an explicit --home-dir over the worktree default", () =>
1289 Effect.gen(function* () {
1290 const path = yield* Path.Path;
1291 const root = yield* makeWorktree;
1292 const home = yield* spawnedHome({
1293 t3Home: "/tmp/explicit-home",
1294 cwd: root,
1295 ambientHome: "/home/user/.t3",
1296 });
1297 assert.equal(home, path.resolve("/tmp/explicit-home"));
1298 }).pipe(Effect.scoped),
1299 );
1300
1301 it.effect("treats a blank --home-dir as unset rather than as a selection", () =>
1302 Effect.gen(function* () {
1303 const path = yield* Path.Path;
1304 const root = yield* makeWorktree;
1305 const home = yield* spawnedHome({
1306 t3Home: " ",
1307 cwd: root,
1308 ambientHome: "/home/user/.t3",
1309 });
1310 assert.equal(home, path.join(path.resolve(root), ".t3"));
1311 }).pipe(Effect.scoped),
1312 );
1313
1314 it.effect("prefers the worktree .t3 over an ambient T3CODE_HOME", () =>
1315 Effect.gen(function* () {
1316 const path = yield* Path.Path;
1317 const root = yield* makeWorktree;
1318 const home = yield* spawnedHome({
1319 t3Home: undefined,
1320 cwd: root,
1321 ambientHome: "/home/user/.t3",
1322 });
1323 assert.equal(home, path.join(path.resolve(root), ".t3"));
1324 }).pipe(Effect.scoped),
1325 );
1326
1327 it.effect("falls back to an ambient T3CODE_HOME outside a worktree", () =>
1328 Effect.gen(function* () {
1329 const path = yield* Path.Path;
1330 const home = yield* spawnedHome({
1331 t3Home: undefined,
1332 cwd: NodeOS.tmpdir(),
1333 ambientHome: "/home/user/.t3",
1334 });
1335 assert.equal(home, path.resolve("/home/user/.t3"));
1336 }),
1337 );
1338
1339 it.effect("leaves the home implicit with no worktree and no ambient value", () =>
1340 Effect.gen(function* () {
1341 const home = yield* spawnedHome({
1342 t3Home: undefined,
1343 cwd: NodeOS.tmpdir(),
1344 ambientHome: undefined,
1345 });
1346 assert.equal(home, undefined);
1347 }),
1348 );
1349 });
1350 });
1351});