Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions apps/server/src/os-jank.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { assert, it } from "@effect/vitest";

import { hydratePosixHome } from "./os-jank.ts";

it("hydrates HOME for minimal service environments", () => {
const env: NodeJS.ProcessEnv = {};

hydratePosixHome(env, "/home/service-user");

assert.equal(env.HOME, "/home/service-user");
});

it("hydrates a blank HOME value", () => {
const env: NodeJS.ProcessEnv = { HOME: " " };

hydratePosixHome(env, "/home/service-user");

assert.equal(env.HOME, "/home/service-user");
});

it("preserves an explicitly configured HOME", () => {
const env: NodeJS.ProcessEnv = { HOME: "/custom/home" };

hydratePosixHome(env, "/home/service-user");

assert.equal(env.HOME, "/custom/home");
});
13 changes: 11 additions & 2 deletions apps/server/src/os-jank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function hydratePosixPath(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): vo
}
}

export function hydratePosixHome(env: NodeJS.ProcessEnv, homeDir = NodeOS.homedir()): void {
if ((env.HOME?.trim() ?? "").length === 0 && homeDir.length > 0) {
env.HOME = homeDir;
}
}
Comment thread
cursor[bot] marked this conversation as resolved.

export const fixPath = Effect.fn("fixPath")(function* (): Effect.fn.Return<
void,
never,
Expand Down Expand Up @@ -63,10 +69,13 @@ export const fixPath = Effect.fn("fixPath")(function* (): Effect.fn.Return<

if (platform !== "darwin" && platform !== "linux") return;

yield* Effect.sync(() => hydratePosixPath(env, platform)).pipe(
yield* Effect.sync(() => {
hydratePosixHome(env);
hydratePosixPath(env, platform);
}).pipe(
Effect.catchDefect((defect) =>
Effect.sync(() => {
logPathHydrationWarning("Failed to hydrate PATH from the user environment.", defect);
logPathHydrationWarning("Failed to hydrate the user environment.", defect);
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
}),
),
);
Expand Down
Loading