Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(llama.cpp): build WinGet Links paths with the native separator

[._.]/ Adam Eivy9edf3cc0f958
diff --git a/server/lib/llamaCppInstall.js b/server/lib/llamaCppInstall.js
index 6e7adfb095..84e5cd0856 100644
--- a/server/lib/llamaCppInstall.js
+++ b/server/lib/llamaCppInstall.js
@@ -15,10 +15,13 @@
* branches are coverable from either OS.
*/
-// The WinGet helpers below always reason about WINDOWS paths, whatever host is
-// running them — that is what keeps them coverable from a macOS/Linux checkout,
-// where `path.isAbsolute('C:\\…')` is false and would quietly answer "no".
-import { win32 as winPath } from 'path';
+// Two path flavours, deliberately: `isWingetManagedPath` CLASSIFIES a path
+// string that came off a Windows PATH, so it must reason in win32 whatever host
+// is running it (on POSIX, `path.isAbsolute('C:\\…')` is false and would quietly
+// answer "no", making the rule uncoverable from a macOS/Linux checkout).
+// `wingetLinkDirs` builds paths the LOCAL FILESYSTEM is then asked about, so it
+// must use the native flavour — see the note on that function.
+import nativePath, { win32 as winPath } from 'path';
export const LLAMA_CPP_DOWNLOAD_URL = 'https://github.com/ggml-org/llama.cpp/releases';
export const LLAMA_CPP_BREW_FORMULA = 'llama.cpp';
@@ -108,16 +111,26 @@ export function parseWingetPackageFields(stdout, packageId) {
* The directories winget links a portable package's executables into. Both
* scopes are returned because PortOS cannot know which one the user's install
* chose, and neither is guaranteed to exist.
+ *
+ * Joined with the NATIVE separator, not win32: the caller stats these paths and
+ * splices them into `process.env.PATH`, so they have to be shaped for the
+ * filesystem actually running the code. On Windows — the only host that reaches
+ * this in production — native IS win32, so nothing changes there; joining with
+ * win32 unconditionally would instead emit backslash paths a POSIX test host can
+ * neither create nor stat.
*/
export function wingetLinkDirs(env = process.env) {
- return wingetRoots(env).map((root) => winPath.join(root, 'Links'));
+ return wingetRoots(env, nativePath).map((root) => nativePath.join(root, 'Links'));
}
-/** The per-user and machine-wide directories winget installs packages under. */
-function wingetRoots(env) {
+/**
+ * The per-user and machine-wide directories winget installs packages under, in
+ * the caller's chosen path flavour (see the import note at the top).
+ */
+function wingetRoots(env, pathFlavour) {
return [
- env.LOCALAPPDATA ? winPath.join(env.LOCALAPPDATA, 'Microsoft', 'WinGet') : null,
- env.ProgramFiles ? winPath.join(env.ProgramFiles, 'WinGet') : null,
+ env.LOCALAPPDATA ? pathFlavour.join(env.LOCALAPPDATA, 'Microsoft', 'WinGet') : null,
+ env.ProgramFiles ? pathFlavour.join(env.ProgramFiles, 'WinGet') : null,
].filter(Boolean);
}
@@ -132,7 +145,7 @@ function wingetRoots(env) {
export function isWingetManagedPath(binaryPath, env = process.env) {
if (!binaryPath || !winPath.isAbsolute(binaryPath)) return false;
const candidate = winPath.normalize(binaryPath).toLowerCase();
- return wingetRoots(env).some((root) => (
+ return wingetRoots(env, winPath).some((root) => (
candidate.startsWith(winPath.normalize(root).toLowerCase() + winPath.sep)
));
}
diff --git a/server/lib/llamaCppInstall.test.js b/server/lib/llamaCppInstall.test.js
index c7cde6bb45..f7afe2cc8d 100644
--- a/server/lib/llamaCppInstall.test.js
+++ b/server/lib/llamaCppInstall.test.js
@@ -1,4 +1,5 @@
import { describe, it, expect } from 'vitest';
+import { join } from 'path';
import {
LLAMA_CPP_WINGET_ID,
isWingetManagedPath,
@@ -93,6 +94,18 @@ describe('isWingetManagedPath', () => {
expect(isWingetManagedPath(null, WIN_ENV)).toBe(false);
});
+ it('builds Links directories the LOCAL filesystem can stat', () => {
+ // Regression: these paths are handed to existsSync and spliced into
+ // process.env.PATH, so they are joined with the NATIVE separator. Joining
+ // with win32 unconditionally emitted backslash paths that no POSIX host
+ // could create or find, which broke the install path's PATH adoption test
+ // on Linux CI while passing on Windows.
+ const base = join('base', 'AppData', 'Local');
+ expect(wingetLinkDirs({ LOCALAPPDATA: base })).toEqual([
+ join(base, 'Microsoft', 'WinGet', 'Links'),
+ ]);
+ });
+
it('claims nothing when the environment names no WinGet root', () => {
expect(isWingetManagedPath('C:\\Users\\example\\AppData\\Local\\Microsoft\\WinGet\\Links\\llama-server.exe', {}))
.toBe(false);