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

address review (claude): finish the expandHome consolidation, add direct unit tests

[._.]/ Adam Eivydef036b64691
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.js
index b5e26afade..c24641465a 100644
--- a/server/lib/fileUtils.js
+++ b/server/lib/fileUtils.js
@@ -183,11 +183,13 @@ export function dataPath(...segments) {
}
// `path.join(homedir(), '/.foo')` discards the homedir prefix because of
-// the leading slash, so strip the `~/` (or bare `~`) before joining.
+// the leading slash, so strip the leading `~/` (or `~\` on Windows) before
+// joining. Only expands a leading `~` — embedded `~` chars in path segments
+// (e.g. `iCloud~md~obsidian`) are preserved.
export function expandHome(p) {
if (typeof p !== 'string' || !p) return p;
if (p === '~') return homedir();
- if (p.startsWith('~/')) return join(homedir(), p.slice(2));
+ if (p.startsWith('~/') || p.startsWith('~\\')) return join(homedir(), p.slice(2));
return p;
}
diff --git a/server/lib/fileUtils.test.js b/server/lib/fileUtils.test.js
index d8d75e6062..e1f0981c18 100644
--- a/server/lib/fileUtils.test.js
+++ b/server/lib/fileUtils.test.js
@@ -2,10 +2,11 @@ import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vites
import { readFile, writeFile, rm, mkdir } from 'fs/promises';
import { mkdtempSync, rmSync, writeFileSync } from 'fs';
import { join } from 'path';
-import { tmpdir } from 'os';
+import { tmpdir, homedir } from 'os';
import { createHash } from 'crypto';
import {
assertSafeFilename,
+ expandHome,
isValidJSON,
listDirectoryByExtension,
safeJSONParse,
@@ -697,4 +698,39 @@ describe('fileUtils', () => {
expect(await sha256File(a)).not.toBe(await sha256File(b));
});
});
+
+ describe('expandHome', () => {
+ it('expands a bare `~` to the homedir', () => {
+ expect(expandHome('~')).toBe(homedir());
+ });
+
+ it('expands `~/foo` to homedir + foo', () => {
+ const out = expandHome('~/foo');
+ expect(out.startsWith(homedir())).toBe(true);
+ expect(out.endsWith('foo')).toBe(true);
+ });
+
+ it('expands the Windows form `~\\foo` so `lib/fileUtils.js` stays cross-platform', () => {
+ const out = expandHome('~\\foo');
+ expect(out.startsWith(homedir())).toBe(true);
+ expect(out.endsWith('foo')).toBe(true);
+ });
+
+ it('preserves absolute, relative, and empty inputs', () => {
+ expect(expandHome('/abs/path')).toBe('/abs/path');
+ expect(expandHome('relative/path')).toBe('relative/path');
+ expect(expandHome('')).toBe('');
+ });
+
+ it('preserves non-string inputs (null / undefined / number) without throwing', () => {
+ expect(expandHome(null)).toBe(null);
+ expect(expandHome(undefined)).toBe(undefined);
+ expect(expandHome(42)).toBe(42);
+ });
+
+ it('only expands a leading `~` — embedded `~` chars are preserved (iCloud~md~obsidian)', () => {
+ expect(expandHome('iCloud~md~obsidian')).toBe('iCloud~md~obsidian');
+ expect(expandHome('foo/~bar')).toBe('foo/~bar');
+ });
+ });
});
diff --git a/server/lib/runners.test.js b/server/lib/runners.test.js
index 2b5c9f60b0..e24dfd3da9 100644
--- a/server/lib/runners.test.js
+++ b/server/lib/runners.test.js
@@ -3,7 +3,7 @@ import { readFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
-import { RUNNER_FAMILIES, isMflux, isFlux2, isZImage, isErnie, isHiDream } from './runners.js';
+import { RUNNER_FAMILIES, isMflux, isFlux2, isZImage, isErnie, isHiDream, isQwen } from './runners.js';
const __dirname_self = dirname(fileURLToPath(import.meta.url));
const CLIENT_MIRROR_PATH = join(__dirname_self, '..', '..', 'client', 'src', 'lib', 'runnerFamilies.js');
@@ -42,6 +42,7 @@ describe('RUNNER_FAMILIES', () => {
expect(isZImage({ runner: 'z-image' })).toBe(true);
expect(isErnie({ runner: 'ernie' })).toBe(true);
expect(isHiDream({ runner: 'hidream' })).toBe(true);
+ expect(isQwen({ runner: 'qwen' })).toBe(true);
expect(isFlux2({ runner: 'mflux' })).toBe(false);
expect(isFlux2(null)).toBe(false);
expect(isFlux2(undefined)).toBe(false);
diff --git a/server/routes/scaffold.js b/server/routes/scaffold.js
index b2a84b9e87..473e243a0f 100644
--- a/server/routes/scaffold.js
+++ b/server/routes/scaffold.js
@@ -5,10 +5,10 @@ import { join, dirname, resolve, sep } from 'path';
import { fileURLToPath } from 'url';
import { exec, spawn } from 'child_process';
import { promisify } from 'util';
-import { homedir, platform } from 'os';
+import { platform } from 'os';
import { createApp, getReservedPorts } from '../services/apps.js';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
-import { ensureDir } from '../lib/fileUtils.js';
+import { ensureDir, expandHome } from '../lib/fileUtils.js';
import { scaffoldVite } from './scaffoldVite.js';
import { scaffoldExpress } from './scaffoldExpress.js';
import { scaffoldIOS } from './scaffoldIOS.js';
@@ -31,11 +31,10 @@ router.get('/directories', asyncHandler(async (req, res) => {
let targetPath;
if (!dirPath) {
targetPath = defaultPath;
- } else if (dirPath === '~') {
- targetPath = homedir();
- } else if (dirPath.startsWith('~/') || dirPath.startsWith('~\\')) {
- // Expand leading ~ only; preserve embedded ~ chars (e.g. iCloud~md~obsidian)
- targetPath = resolve(join(homedir(), dirPath.slice(2)));
+ } else if (dirPath === '~' || dirPath.startsWith('~/') || dirPath.startsWith('~\\')) {
+ // expandHome covers `~`, `~/foo`, and `~\foo` (Windows); embedded `~`
+ // chars (e.g. `iCloud~md~obsidian`) fall through to the else branch.
+ targetPath = resolve(expandHome(dirPath));
} else {
targetPath = resolve(dirPath);
}
diff --git a/server/services/voice/config.js b/server/services/voice/config.js
index cd6411eb24..0a315e994d 100644
--- a/server/services/voice/config.js
+++ b/server/services/voice/config.js
@@ -6,6 +6,7 @@ import { homedir } from 'os';
import { join } from 'path';
import { getSettings, updateSettings } from '../settings.js';
import { deepMerge } from '../../lib/objects.js';
+import { expandHome } from '../../lib/fileUtils.js';
const VOICE_HOME = join(homedir(), '.portos', 'voice');
@@ -110,12 +111,9 @@ export const VOICE_DEFAULTS = Object.freeze({
vad: { endOfSpeechMs: 700, minUtteranceMs: 250 },
});
-export const expandPath = (p) => {
- if (typeof p !== 'string') return p;
- if (p.startsWith('~/')) return join(homedir(), p.slice(2));
- if (p === '~') return homedir();
- return p;
-};
+// Alias kept for backward-compat with the 5 callers under server/services/voice/.
+// The canonical implementation now lives in `server/lib/fileUtils.js#expandHome`.
+export const expandPath = expandHome;
// Tiny in-memory cache so hot paths (per-turn enabled check in voice sockets)
// don't hit disk on every dispatch. Invalidated on updateVoiceConfig and