import { test } from "node:test";
import assert from "node:assert/strict";
import { buildContainerEnv, NUCLEICD_CONTROL_PORT } from "../src/container.ts";

test("buildContainerEnv carries the full instance contract", () => {
  const env = buildContainerEnv({
    poolId: "p1",
    instanceId: "sb-2",
    epoch: "7",
    instanceToken: "tok",
    controlPlaneURL: "https://runner.example",
    relayURL: "https://relay.example",
  });
  assert.deepEqual(env, {
    NUCLEIC_RUNNER_POOL_ID: "p1",
    NUCLEIC_RUNNER_INSTANCE_ID: "sb-2",
    NUCLEIC_RUNNER_EPOCH: "7",
    NUCLEIC_RUNNER_INSTANCE_TOKEN: "tok",
    NUCLEIC_RUNNER_CONTROL_URL: "https://runner.example",
    NUCLEIC_RELAY_URL: "https://relay.example",
  });
});

test("relay URL is optional (production default lives in nucleicd)", () => {
  const env = buildContainerEnv({
    poolId: "p1",
    instanceId: "host",
    epoch: "1",
    instanceToken: "tok",
    controlPlaneURL: "https://runner.example",
  });
  assert.equal("NUCLEIC_RELAY_URL" in env, false);
});

test("nucleicd control port is pinned (pairing proxy contract)", () => {
  assert.equal(NUCLEICD_CONTROL_PORT, 9200);
});
