import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { readRuntimeInfo, writeRuntimeInfo } from '../../src/comm/runtime-info';

describe('runtime-info', () => {
  it('writes and reads bootstrap metadata from data dir', () => {
    const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'neta-runtime-info-'));
    const runtimeInfoPath = path.join(tempDir, 'runtime-info.json');

    writeRuntimeInfo(runtimeInfoPath, {
      pid: 321,
      ready: true,
      startedAt: '2026-04-25T10:00:00.000Z',
      port: 8009,
      url: 'http://127.0.0.1:8009',
      controlBaseUrl: 'http://127.0.0.1:8009',
      controlSecret: 'secret-1',
      dataDir: tempDir,
      logDir: path.join(tempDir, 'logs'),
      configDir: 'C:/Program Files/Neta',
    });

    const loaded = readRuntimeInfo(runtimeInfoPath);
    expect(loaded?.controlSecret).toBe('secret-1');
    expect(loaded?.controlBaseUrl).toBe('http://127.0.0.1:8009');
  });
});
