const assert = require('assert'); const fs = require('fs'); const os = require('os'); const path = require('path'); const { getDefaultConfigPath } = require('../runtime-paths'); describe('runtime-paths', () => { function createTempDir() { return fs.mkdtempSync(path.join(os.tmpdir(), 'jhm-runtime-paths-')); } it('prefers cwd config.json in source mode', () => { const cwd = createTempDir(); const appDir = createTempDir(); const cwdConfigPath = path.join(cwd, 'config.json'); const appConfigPath = path.join(appDir, 'config.json'); fs.writeFileSync(cwdConfigPath, '{}'); fs.writeFileSync(appConfigPath, '{}'); const resolved = getDefaultConfigPath({ packaged: false, cwd, appDir, }); assert.strictEqual(resolved, cwdConfigPath); fs.rmSync(cwd, { recursive: true, force: true }); fs.rmSync(appDir, { recursive: true, force: true }); }); it('prefers runtime/config.json next to executable in packaged mode', () => { const cwd = createTempDir(); const execRoot = createTempDir(); const runtimeDir = path.join(execRoot, 'runtime'); const execPath = path.join(execRoot, 'jhm-service.exe'); const runtimeConfigPath = path.join(runtimeDir, 'config.json'); fs.mkdirSync(runtimeDir, { recursive: true }); fs.writeFileSync(runtimeConfigPath, '{}'); const resolved = getDefaultConfigPath({ packaged: true, cwd, execPath, }); assert.strictEqual(resolved, runtimeConfigPath); fs.rmSync(cwd, { recursive: true, force: true }); fs.rmSync(execRoot, { recursive: true, force: true }); }); it('falls back to cwd config.json when packaged runtime config is missing', () => { const cwd = createTempDir(); const execRoot = createTempDir(); const execPath = path.join(execRoot, 'jhm-service'); const cwdConfigPath = path.join(cwd, 'config.json'); fs.writeFileSync(cwdConfigPath, '{}'); const resolved = getDefaultConfigPath({ packaged: true, cwd, execPath, }); assert.strictEqual(resolved, cwdConfigPath); fs.rmSync(cwd, { recursive: true, force: true }); fs.rmSync(execRoot, { recursive: true, force: true }); }); });