chenyc
2026-04-21 8632fbd73fdb15f22fae9cd36b9ed3e0635360f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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 });
  });
});