import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";

const ipcSource = readFileSync(new URL("../src/main/ipc.ts", import.meta.url), "utf8");

test("workspace summary refreshes bundled gateway client before computing startup state", () => {
  assert.match(ipcSource, /const useBundledRuntime = typeof runtimeGatewayConnection\.url === "string"[\s\S]*runtimeStatus\.activeMode === "bundled-runtime"[\s\S]*runtimeStatus\.selectedMode === "bundled-runtime" && runtimeStatus\.processState === "running"/);
  assert.match(ipcSource, /let gatewayStatus = config\.apiKeyConfigured/);
  assert.match(ipcSource, /runtimeStatus\.processState === "running"/);
  assert.match(ipcSource, /await shouldRefreshGatewayClient\(config\)/);
  assert.match(ipcSource, /await reconfigureGatewayClient\(config\)/);
  assert.match(ipcSource, /await connectGatewayClientWithRetry\("bundled"\)/);
  assert.match(ipcSource, /gatewayStatus = await gatewayClient\.status\(\)\.catch\(\(\) => null\)/);
});
