"use strict";
var import_vitest = require("vitest");
var import_detector = require("../inference/eot/detector.cjs");
var import_otel_http_exporter = require("./otel_http_exporter.cjs");
(0, import_vitest.describe)("SimpleOTLPHttpLogExporter attribute conversion", () => {
  const originalEnv = { ...process.env };
  let fetchSpy;
  (0, import_vitest.beforeEach)(() => {
    process.env.LIVEKIT_API_KEY = "APIsecretkey123";
    process.env.LIVEKIT_API_SECRET = "topsecretvalue456";
    fetchSpy = import_vitest.vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response("{}", { status: 200 }));
  });
  (0, import_vitest.afterEach)(() => {
    fetchSpy.mockRestore();
    process.env = { ...originalEnv };
  });
  function sentPayload() {
    var _a;
    const init = (_a = fetchSpy.mock.calls.at(-1)) == null ? void 0 : _a[1];
    return String(init == null ? void 0 : init.body);
  }
  async function exportAttributes(attributes) {
    const exporter = new import_otel_http_exporter.SimpleOTLPHttpLogExporter({
      cloudHostname: "cloud.example.com",
      resourceAttributes: {},
      scopeName: "test"
    });
    await exporter.export([{ body: "rec", timestampMs: 0, attributes }]);
    return sentPayload();
  }
  (0, import_vitest.it)("honors toJSON() so objects can redact fields at the wire boundary", async () => {
    const value = {
      safe: "visible",
      toJSON: () => ({ safe: "visible" }),
      secret: "do-not-emit"
    };
    const payload = await exportAttributes({ value });
    (0, import_vitest.expect)(payload).toContain("visible");
    (0, import_vitest.expect)(payload).not.toContain("do-not-emit");
  });
  (0, import_vitest.it)("redacts live TurnDetector credentials embedded in session options", async () => {
    process.env.LIVEKIT_INFERENCE_URL = "ws://gateway";
    delete process.env.LIVEKIT_INFERENCE_API_KEY;
    delete process.env.LIVEKIT_INFERENCE_API_SECRET;
    const turnDetection = new import_detector.TurnDetector({ version: "v1" });
    const payload = await exportAttributes({
      "session.options": { turnHandling: { turnDetection } }
    });
    (0, import_vitest.expect)(payload).not.toContain("APIsecretkey123");
    (0, import_vitest.expect)(payload).not.toContain("topsecretvalue456");
    (0, import_vitest.expect)(payload).toContain("turn-detector-v1");
    (0, import_vitest.expect)(payload).toContain("ws://gateway");
  });
});
//# sourceMappingURL=otel_http_exporter.test.cjs.map