"use strict";
var import_vitest = require("vitest");
var import_utils = require("./utils.cjs");
const ENV_KEYS = ["LIVEKIT_INFERENCE_URL", "LIVEKIT_URL"];
const saved = {};
(0, import_vitest.beforeEach)(() => {
  for (const k of ENV_KEYS) {
    saved[k] = process.env[k];
    delete process.env[k];
  }
});
(0, import_vitest.afterEach)(() => {
  for (const k of ENV_KEYS) {
    if (saved[k] === void 0) delete process.env[k];
    else process.env[k] = saved[k];
  }
});
(0, import_vitest.describe)("resolveEnvVar", () => {
  (0, import_vitest.it)("returns empty string when no env or default", () => {
    (0, import_vitest.expect)((0, import_utils.resolveEnvVar)(void 0, ["LIVEKIT_INFERENCE_URL"])).toBe("");
  });
  (0, import_vitest.it)("returns default when no matching env exists", () => {
    (0, import_vitest.expect)((0, import_utils.resolveEnvVar)(void 0, ["LIVEKIT_INFERENCE_URL"], "https://default.example.com")).toBe(
      "https://default.example.com"
    );
  });
  (0, import_vitest.it)("returns first matching env value", () => {
    process.env.LIVEKIT_INFERENCE_URL = "https://inference.example.com";
    process.env.LIVEKIT_URL = "https://livekit.example.com";
    (0, import_vitest.expect)(
      (0, import_utils.resolveEnvVar)(
        void 0,
        ["LIVEKIT_INFERENCE_URL", "LIVEKIT_URL"],
        "https://default.example.com"
      )
    ).toBe("https://inference.example.com");
  });
  (0, import_vitest.it)("falls back to later env when earlier env missing", () => {
    process.env.LIVEKIT_URL = "https://livekit.example.com";
    (0, import_vitest.expect)(
      (0, import_utils.resolveEnvVar)(
        void 0,
        ["LIVEKIT_INFERENCE_URL", "LIVEKIT_URL"],
        "https://default.example.com"
      )
    ).toBe("https://livekit.example.com");
  });
  (0, import_vitest.it)("prefers explicit value over environment", () => {
    process.env.LIVEKIT_INFERENCE_URL = "https://env.example.com";
    (0, import_vitest.expect)(
      (0, import_utils.resolveEnvVar)(
        "https://explicit.example.com",
        ["LIVEKIT_INFERENCE_URL"],
        "https://default.example.com"
      )
    ).toBe("https://explicit.example.com");
  });
  (0, import_vitest.it)("treats empty env value as missing", () => {
    process.env.LIVEKIT_INFERENCE_URL = "";
    (0, import_vitest.expect)((0, import_utils.resolveEnvVar)(void 0, ["LIVEKIT_INFERENCE_URL"], "https://default.example.com")).toBe(
      "https://default.example.com"
    );
  });
  (0, import_vitest.it)("treats whitespace env value as set", () => {
    process.env.LIVEKIT_INFERENCE_URL = " ";
    (0, import_vitest.expect)((0, import_utils.resolveEnvVar)(void 0, ["LIVEKIT_INFERENCE_URL"], "https://default.example.com")).toBe(
      " "
    );
  });
});
//# sourceMappingURL=utils_env.test.cjs.map