"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var import_vitest = require("vitest");
var jobModule = __toESM(require("../../job.cjs"), 1);
var logModule = __toESM(require("../../log.cjs"), 1);
var import_avatar_session = require("./avatar_session.cjs");
(0, import_vitest.describe)("AvatarSession base", () => {
  (0, import_vitest.afterEach)(() => {
    import_vitest.vi.restoreAllMocks();
  });
  const mockAgentSession = (overrides = {}) => ({
    _started: false,
    output: { audio: null },
    on: import_vitest.vi.fn(),
    off: import_vitest.vi.fn(),
    emit: import_vitest.vi.fn(),
    ...overrides
  });
  const mockRoom = () => ({
    isConnected: false,
    on: import_vitest.vi.fn(),
    off: import_vitest.vi.fn()
  });
  (0, import_vitest.it)("registers aclose with job shutdown callback", async () => {
    let shutdownCallback;
    const addShutdownCallback = import_vitest.vi.fn((cb) => {
      shutdownCallback = cb;
    });
    import_vitest.vi.spyOn(jobModule, "getJobContext").mockReturnValue({
      addShutdownCallback
    });
    const session = new import_avatar_session.AvatarSession();
    const acloseSpy = import_vitest.vi.spyOn(session, "aclose").mockResolvedValue();
    await session.start(mockAgentSession(), mockRoom());
    (0, import_vitest.expect)(addShutdownCallback).toHaveBeenCalledTimes(1);
    (0, import_vitest.expect)(shutdownCallback).toBeTypeOf("function");
    await (shutdownCallback == null ? void 0 : shutdownCallback());
    (0, import_vitest.expect)(acloseSpy).toHaveBeenCalledTimes(1);
  });
  (0, import_vitest.it)("warns when avatar is started after AgentSession.start()", async () => {
    const warn = import_vitest.vi.fn();
    import_vitest.vi.spyOn(logModule, "log").mockReturnValue({
      warn,
      debug: import_vitest.vi.fn()
    });
    import_vitest.vi.spyOn(jobModule, "getJobContext").mockReturnValue(void 0);
    const session = new import_avatar_session.AvatarSession();
    await session.start(
      {
        ...mockAgentSession({
          _started: true,
          output: { audio: { constructor: { name: "MockAudioOutput" } } }
        })
      },
      mockRoom()
    );
    (0, import_vitest.expect)(warn).toHaveBeenCalledWith(
      { audioOutput: "MockAudioOutput" },
      import_vitest.expect.stringContaining("AvatarSession.start() was called after AgentSession.start()")
    );
  });
});
//# sourceMappingURL=avatar_session.test.cjs.map