test(plugin): migrate runtime test to TypeScript

This commit is contained in:
Research Assistant 2026-05-24 17:32:01 +08:00
parent 2ef0db1b05
commit 3ccf5c424e
2 changed files with 10 additions and 13 deletions

View file

@ -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,

View file

@ -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', () => {