Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(windows): use native PowerShell modules for private paths

Codexf336231c11c4
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts
index 11f6aa1a..7b996c1d 100644
--- a/apps/desktop/src/main/local-server.test.ts
+++ b/apps/desktop/src/main/local-server.test.ts
@@ -6,6 +6,7 @@ import {
existsSync,
linkSync,
mkdirSync,
+ mkdtempSync,
readdirSync,
readFileSync,
realpathSync,
@@ -13,6 +14,7 @@ import {
symlinkSync,
writeFileSync,
} from "node:fs";
+import { homedir } from "node:os";
import path from "node:path";
import { setTimeout as delay } from "node:timers/promises";
import { zstdCompressSync } from "node:zlib";
@@ -381,8 +383,8 @@ const fixture = (
config: Partial<DesktopConfig> = {},
prepare: (home: string) => void = () => {},
api = installerApi(),
+ root = tempDirectory(),
) => {
- const root = tempDirectory();
const home = path.join(root, "home");
const installerDirectory = path.join(root, "installer");
mkdirSync(installerDirectory);
@@ -2478,29 +2480,52 @@ describe("LocalServerModule after a restart", () => {
});
it("moves the keys of the unpacked source's .env into the instance's user.env once", async () => {
- const f = fixture({}, enrolled, (home) => {
- const source = path.join(home, "desktop", "source", "previous");
- mkdirSync(source, { recursive: true });
- writeFileSync(
- path.join(source, ".env"),
- "SONIOX_API_KEY=soniox\nTEAMHUB_SECRET_ENCRYPTION_KEY=other\n",
- );
- writeFileSync(
- path.join(home, "desktop", "local-server.json"),
- JSON.stringify({ home, repo: source, origin: "http://localhost:3000" }),
- );
- });
- await f.host.start();
- await waitForInstaller(() => expect(f.module.status().phase).toBe("ready"));
- const source = path.join(f.home, "desktop", "source", "previous");
- expect(existsSync(path.join(source, ".env"))).toBe(false);
- const user = readFileSync(
- path.join(f.home, "instances", LOCAL_INSTANCE, "user.env"),
- "utf8",
+ // Windows refuses to store credentials under shared ancestors such as Temp.
+ const parent = realpathSync(homedir());
+ const root = isWindowsHost
+ ? mkdtempSync(path.join(parent, "desktop-acl-test-"))
+ : tempDirectory();
+ const f = fixture(
+ {},
+ enrolled,
+ (home) => {
+ const source = path.join(home, "desktop", "source", "previous");
+ mkdirSync(source, { recursive: true });
+ writeFileSync(
+ path.join(source, ".env"),
+ "SONIOX_API_KEY=soniox\nTEAMHUB_SECRET_ENCRYPTION_KEY=other\n",
+ );
+ writeFileSync(
+ path.join(home, "desktop", "local-server.json"),
+ JSON.stringify({
+ home,
+ repo: source,
+ origin: "http://localhost:3000",
+ }),
+ );
+ },
+ undefined,
+ root,
);
- expect(user).toContain("SONIOX_API_KEY='soniox'");
- expect(user).not.toContain("TEAMHUB_SECRET_ENCRYPTION_KEY");
- await f.host.stop("quit");
+ try {
+ await f.host.start();
+ await waitForInstaller(() => {
+ const status = f.module.status();
+ expect(status.phase, status.message).toBe("ready");
+ });
+ const source = path.join(f.home, "desktop", "source", "previous");
+ expect(existsSync(path.join(source, ".env"))).toBe(false);
+ const user = readFileSync(
+ path.join(f.home, "instances", LOCAL_INSTANCE, "user.env"),
+ "utf8",
+ );
+ expect(user).toContain("SONIOX_API_KEY='soniox'");
+ expect(user).not.toContain("TEAMHUB_SECRET_ENCRYPTION_KEY");
+ } finally {
+ await f.host.stop("quit");
+ if (isWindowsHost && path.dirname(realpathSync(root)) === parent)
+ rmSync(root, { recursive: true, force: true, maxRetries: 10 });
+ }
});
it("leaves a developer checkout's .env alone", async () => {
@@ -3446,19 +3471,28 @@ describe("LocalServerModule after a restart", () => {
await f.host.stop("quit");
});
- it("leaves no staged record behind when the record cannot be moved into place", async () => {
- const f = fixture(withCheckout, {}, checkout);
- // A folder where the record goes: the rename fails.
- mkdirSync(path.join(f.home, "desktop", "local-server.json", "x"), {
- recursive: true,
- });
- await f.host.start();
- await f.module.begin().catch(() => {});
- expect(readdirSync(path.join(f.home, "desktop"))).toEqual(
- expect.not.arrayContaining([expect.stringMatching(/\.tmp$/)]),
- );
- await f.host.stop("quit");
- });
+ it(
+ "leaves no staged record behind when the record cannot be moved into place",
+ // A target directory returns EPERM on Windows, consuming the 30 s retry budget.
+ { timeout: isWindowsHost ? 45_000 : 5_000 },
+ async () => {
+ const f = fixture(withCheckout, {}, checkout);
+ mkdirSync(path.join(f.home, "desktop", "local-server.json", "x"), {
+ recursive: true,
+ });
+ await f.host.start();
+ try {
+ await expect(f.module.begin()).rejects.toMatchObject({
+ syscall: "rename",
+ });
+ expect(readdirSync(path.join(f.home, "desktop"))).toEqual(
+ expect.not.arrayContaining([expect.stringMatching(/\.tmp$/)]),
+ );
+ } finally {
+ await f.host.stop("quit");
+ }
+ },
+ );
it("leaves the services alone when the window uses another server", async () => {
const f = fixture({}, { serverUrl: "https://linger.example" }, record);
diff --git a/packages/local-installation/src/computer-current-cli.test.ts b/packages/local-installation/src/computer-current-cli.test.ts
index 7d0d378d..9ae4c153 100644
--- a/packages/local-installation/src/computer-current-cli.test.ts
+++ b/packages/local-installation/src/computer-current-cli.test.ts
@@ -32,7 +32,14 @@ afterEach(async () => {
// Synthetic process contract from Computer 0.40's published login/daemon help.
// Login starts the daemon; connection/reconciliation can finish after it returns.
-it("enrolls and starts the current Computer CLI automatically", async () => {
+// On Windows this lifecycle runs dozens of real PowerShell ACL checks.
+it(
+ "enrolls and starts the current Computer CLI automatically",
+ enrollAndRestartCurrentComputer,
+ process.platform === "win32" ? 180_000 : undefined,
+);
+
+async function enrollAndRestartCurrentComputer() {
const root = await mkdtemp(path.join(tmpdir(), "computer-current-cli-"));
roots.push(root);
const executable = path.join(root, "computer"),
@@ -96,4 +103,4 @@ else {console.error('Unknown command: '+args.join(' '));process.exit(9);}
true,
);
expect(JSON.stringify(commands)).not.toContain("synthetic-private-token");
-});
+}
diff --git a/packages/local-installation/src/windows-private.native.test.ts b/packages/local-installation/src/windows-private.native.test.ts
index cf8bfe71..c17b7477 100644
--- a/packages/local-installation/src/windows-private.native.test.ts
+++ b/packages/local-installation/src/windows-private.native.test.ts
@@ -1,5 +1,5 @@
-import { afterEach, expect, it } from "vitest";
-import { mkdtemp, rm, writeFile, symlink } from "node:fs/promises";
+import { afterEach, expect, it, vi } from "vitest";
+import { mkdir, mkdtemp, rm, writeFile, symlink } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { windowsPrivatePath } from "./windows-private.js";
@@ -27,6 +27,34 @@ it.skipIf(process.platform !== "win32")(
).resolves.toBeUndefined();
},
);
+it.skipIf(process.platform !== "win32")(
+ "uses the native Get-Acl despite the caller's module path",
+ { timeout: 30_000 },
+ async () => {
+ const root = await fixture();
+ const modules = path.join(root, "modules");
+ const name = "Microsoft.PowerShell.Security";
+ await mkdir(path.join(modules, name), { recursive: true });
+ await writeFile(
+ path.join(modules, name, name + ".psm1"),
+ "function Get-Acl { throw 'UNEXPECTED_ACL_MODULE' }; Export-ModuleMember -Function Get-Acl",
+ );
+ const foreignModules = [modules, process.env.PSModulePath]
+ .filter(Boolean)
+ .join(path.delimiter);
+ vi.stubEnv("PSModulePath", foreignModules);
+ try {
+ const privateFile = path.join(root, "settings.json");
+ await writeFile(privateFile, "{}");
+ await expect(
+ windowsPrivatePath(privateFile, "file"),
+ ).resolves.toBeUndefined();
+ expect(process.env.PSModulePath).toBe(foreignModules);
+ } finally {
+ vi.unstubAllEnvs();
+ }
+ },
+);
it.skipIf(process.platform !== "win32")(
"rejects a junction as either the target or an ancestor",
async () => {
diff --git a/packages/local-installation/src/windows-private.ts b/packages/local-installation/src/windows-private.ts
index e1374ccf..ffe2029a 100644
--- a/packages/local-installation/src/windows-private.ts
+++ b/packages/local-installation/src/windows-private.ts
@@ -5,6 +5,9 @@ import { runProcess } from "./process.js";
// contents, user-controlled PowerShell, or credentials appear in argv/output.
export const WINDOWS_PRIVATE_SCRIPT = String.raw`
$ErrorActionPreference = 'Stop'
+# This fixed Windows PowerShell script uses only its own built-in modules.
+# A caller's PowerShell 7 modules can prevent Get-Acl from loading.
+$env:PSModulePath = [IO.Path]::Combine($PSHOME, 'Modules')
[Console]::InputEncoding = [Text.UTF8Encoding]::new($false)
try {
$request = [Console]::In.ReadToEnd() | ConvertFrom-Json