@@ -4,9 +4,11 @@ import {
44 HostProcessEnvironment,
55 HostProcessPlatform,
66 HostProcessIsExecutable,
7+ HostProcessUserId,
78} from "@t3tools/shared/hostProcess";
89import * as Effect from "effect/Effect";
910import * as Layer from "effect/Layer";
11+ import * as Option from "effect/Option";
1012import * as Path from "effect/Path";
1113import * as FileSystem from "effect/FileSystem";
1214
@@ -134,6 +136,54 @@ it.effect("puts detected Android tools on the helper PATH without losing existin
134136 }).pipe(Effect.provide(NodePath.layer)),
135137);
136138
139+ it.effect(
140+ "recovers an owned Linux runtime directory without overriding explicit environments",
141+ () =>
142+ Effect.gen(function* () {
143+ const fs = yield* FileSystem.FileSystem;
144+ const directory = yield* fs.makeTempDirectoryScoped();
145+ const stat = yield* fs.stat(directory);
146+ for (const [platform, uid, runtimeDir, type, owner, expected] of [
147+ ["linux", 1000, undefined, "Directory", 1000, "/run/user/1000"],
148+ ["linux", 1000, "/custom/runtime", "Directory", 1000, "/custom/runtime"],
149+ ["linux", 1000, "", "Directory", 1000, ""],
150+ ["linux", 1000, undefined, "Directory", 1001, undefined],
151+ ["linux", 1000, undefined, "File", 1000, undefined],
152+ ["linux", undefined, undefined, "Directory", 1000, undefined],
153+ ["darwin", 1000, undefined, "Directory", 1000, undefined],
154+ ["win32", 1000, undefined, "Directory", 1000, undefined],
155+ ] as const) {
156+ const environment = { PATH: "/usr/bin", XDG_RUNTIME_DIR: runtimeDir };
157+ const result = yield* LocalDeviceHost.__testing.hubEnvironment(environment).pipe(
158+ Effect.provideService(HostProcessPlatform, platform),
159+ Effect.provideService(HostProcessUserId, uid),
160+ Effect.provideService(
161+ FileSystem.FileSystem,
162+ FileSystem.makeNoop({
163+ stat: (path) => {
164+ expect(path).toBe("/run/user/1000");
165+ return Effect.succeed({ ...stat, type, uid: Option.some(owner) });
166+ },
167+ }),
168+ ),
169+ );
170+ expect(result.XDG_RUNTIME_DIR).toBe(expected);
171+ expect(result.PATH).toBe("/usr/bin");
172+ expect(result.FORCE_COLOR).toBe("0");
173+ expect(result.NO_COLOR).toBe("1");
174+ expect(environment.XDG_RUNTIME_DIR).toBe(runtimeDir);
175+ }
176+ const missing = yield* LocalDeviceHost.__testing
177+ .hubEnvironment({})
178+ .pipe(
179+ Effect.provideService(HostProcessPlatform, "linux"),
180+ Effect.provideService(HostProcessUserId, 1000),
181+ Effect.provideService(FileSystem.FileSystem, FileSystem.makeNoop({})),
182+ );
183+ expect(missing.XDG_RUNTIME_DIR).toBeUndefined();
184+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
185+ );
186+
137187it.effect(
138188 "constructs and inspects an unconfigured host without installing or starting helpers",
139189 () =>
0 commit comments