Skip to content

Commit 23081ba

Browse files
fix(desktop): probe OneDrive-redirected PowerShell profiles in fnm check
1 parent 48a5597 commit 23081ba

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,45 @@ describe("DesktopShellEnvironment", () => {
410410
}),
411411
);
412412

413+
it.effect("runs PowerShell probes when fnm is referenced only in an OneDrive-redirected profile", () =>
414+
Effect.gen(function* () {
415+
const mockDir = "C:\\mock\\temp";
416+
const env: NodeJS.ProcessEnv = {
417+
PATH: mockDir,
418+
USERPROFILE: "C:\\Users\\test",
419+
OneDrive: "C:\\Users\\test\\OneDrive",
420+
};
421+
const commands: ChildProcess.Command[] = [];
422+
423+
const mockFs = {
424+
exists: (path: string) => Effect.succeed(path.includes("node.exe")),
425+
readFile: (path: string) =>
426+
path.includes("OneDrive")
427+
? Effect.succeed(textEncoder.encode('Invoke-Expression "fnm env"'))
428+
: Effect.fail(
429+
PlatformError.systemError({
430+
_tag: "NotFound",
431+
module: "FileSystem",
432+
method: "readFile",
433+
pathOrDescriptor: "",
434+
}),
435+
),
436+
} as unknown as FileSystem.FileSystem;
437+
438+
yield* runShellEnvironment({
439+
env,
440+
platform: "win32",
441+
fs: mockFs,
442+
handler: (command) => {
443+
commands.push(command);
444+
return envOutput({ PATH: mockDir });
445+
},
446+
});
447+
448+
assert.equal(commands.length, 2);
449+
}),
450+
);
451+
413452
it.effect("skips ALL PowerShell probes when node is available and profile exists without fnm", () =>
414453
Effect.gen(function* () {
415454
const mockDir = "C:\\mock\\temp";

‎apps/desktop/src/shell/DesktopShellEnvironment.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,17 @@ const installWindowsEnvironment = Effect.fn("desktop.shellEnvironment.installWin
406406
const checkProfileMentionsFnm = Effect.gen(function* () {
407407
const userProfile = config.env.USERPROFILE;
408408
if (!userProfile) return true; // unsafe to skip if we can't find the profile
409-
const profilePaths = [
410-
`${userProfile}\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1`,
411-
`${userProfile}\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1`,
412-
`${userProfile}\\Documents\\WindowsPowerShell\\profile.ps1`,
413-
`${userProfile}\\Documents\\PowerShell\\profile.ps1`,
414-
];
409+
const documentsDirs = [`${userProfile}\\Documents`];
410+
const oneDrive = trimNonEmpty(config.env.OneDrive);
411+
if (Option.isSome(oneDrive)) {
412+
documentsDirs.push(`${oneDrive.value}\\Documents`);
413+
}
414+
const profilePaths = documentsDirs.flatMap((documentsDir) => [
415+
`${documentsDir}\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1`,
416+
`${documentsDir}\\PowerShell\\Microsoft.PowerShell_profile.ps1`,
417+
`${documentsDir}\\WindowsPowerShell\\profile.ps1`,
418+
`${documentsDir}\\PowerShell\\profile.ps1`,
419+
]);
415420
for (const p of profilePaths) {
416421
const bytes = yield* fileSystem.readFile(p).pipe(
417422
Effect.catchIf(

0 commit comments

Comments
 (0)