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

const source = readFileSync(new URL("../src/main/workspace-startup.ts", import.meta.url), "utf8");

test("bundled runtime transient gateway errors stay in starting state while runtime is not failed", () => {
  assert.match(source, /const bundledRuntimeSelected = runtimeStatus\.selectedMode === "bundled-runtime"/);
  assert.match(source, /const staleGatewayTarget = typeof runtimeStatus\.gatewayUrl === "string"[\s\S]*gatewayStatus\.url !== runtimeStatus\.gatewayUrl/);
  assert.match(source, /const bundledRuntimeWaitingForGateway = bundledRuntimeSelected[\s\S]*warmupInFlight[\s\S]*runtimeStatus\.processState === "starting"[\s\S]*runtimeStatus\.processState === "running" && staleGatewayTarget/);
  assert.match(source, /const bundledTransientGatewayError = bundledRuntimeWaitingForGateway[\s\S]*isTransientLocalGatewayError\(gatewayError\)/);
  assert.match(source, /if \(gatewayStatus\?\.state === "error" && bundledTransientGatewayError\) \{[\s\S]*return buildGatewayStartingSummary\(gatewayStatus\)/);
});
