diff --git a/paperforge/plugin/src/services/memory-state.ts b/paperforge/plugin/src/services/memory-state.ts index e3dc0831..9d7197e9 100644 --- a/paperforge/plugin/src/services/memory-state.ts +++ b/paperforge/plugin/src/services/memory-state.ts @@ -76,7 +76,8 @@ let _cachedPython: PythonResult | null = null; // ── Functions ── -export function readPathConfig(vaultPath: string): PathConfig { +export function readPathConfig(vaultPath: string, _fs?: any): PathConfig { + const f = _fs || fs; const pfPath = path.join(vaultPath, 'paperforge.json'); const defaults = { system_dir: 'System', @@ -86,10 +87,10 @@ export function readPathConfig(vaultPath: string): PathConfig { }; try { - if (!fs.existsSync(pfPath)) { + if (!f.existsSync(pfPath)) { return { ...defaults, _warning: 'paperforge.json not found; using defaults' }; } - const raw = fs.readFileSync(pfPath, 'utf-8'); + const raw = f.readFileSync(pfPath, 'utf-8'); const data = JSON.parse(raw); const vc = data.vault_config || {}; return { @@ -105,8 +106,8 @@ export function readPathConfig(vaultPath: string): PathConfig { } } -export function resolveVaultPaths(vaultPath: string): ResolvedPaths { - const cfg = readPathConfig(vaultPath); +export function resolveVaultPaths(vaultPath: string, _fs?: any): ResolvedPaths { + const cfg = readPathConfig(vaultPath, _fs); const systemDir = path.join(vaultPath, cfg.system_dir, 'PaperForge'); return { vault: vaultPath, diff --git a/paperforge/plugin/tests/runtime.test.mjs b/paperforge/plugin/tests/runtime.test.ts similarity index 94% rename from paperforge/plugin/tests/runtime.test.mjs rename to paperforge/plugin/tests/runtime.test.ts index 16fd964b..00b50fc2 100644 --- a/paperforge/plugin/tests/runtime.test.mjs +++ b/paperforge/plugin/tests/runtime.test.ts @@ -1,18 +1,14 @@ /** - * Vitest tests for runtime.js — resolvePythonExecutable, getPluginVersion, checkRuntimeVersion. + * Vitest tests for runtime functions — readPathConfig, resolveVaultPaths, + * resolvePythonExecutable, getPluginVersion, checkRuntimeVersion. * * Uses dependency injection (last parameter) instead of vi.mock to avoid * CJS/ESM module mocking limitations in vitest v2.1.x. */ import { describe, it, expect, vi, beforeEach } from 'vitest'; -const { - readPathConfig, - resolveRuntimePaths, - resolvePythonExecutable, - getPluginVersion, - checkRuntimeVersion, -} = await import('../src/testable.js'); +import { readPathConfig, resolveVaultPaths as resolveRuntimePaths } from "../src/services/memory-state"; +import { resolvePythonExecutable, getPluginVersion, checkRuntimeVersion } from "../src/services/python-bridge"; describe('readPathConfig', () => { it('uses vault_config system_dir when present', () => {