import { afterEach, describe, expect, it, vi } from "vitest";
import * as jobModule from "../../job.js";
import * as logModule from "../../log.js";
import { AvatarSession } from "./avatar_session.js";
describe("AvatarSession base", () => {
  afterEach(() => {
    vi.restoreAllMocks();
  });
  const mockAgentSession = (overrides = {}) => ({
    _started: false,
    output: { audio: null },
    on: vi.fn(),
    off: vi.fn(),
    emit: vi.fn(),
    ...overrides
  });
  const mockRoom = () => ({
    isConnected: false,
    on: vi.fn(),
    off: vi.fn()
  });
  it("registers aclose with job shutdown callback", async () => {
    let shutdownCallback;
    const addShutdownCallback = vi.fn((cb) => {
      shutdownCallback = cb;
    });
    vi.spyOn(jobModule, "getJobContext").mockReturnValue({
      addShutdownCallback
    });
    const session = new AvatarSession();
    const acloseSpy = vi.spyOn(session, "aclose").mockResolvedValue();
    await session.start(mockAgentSession(), mockRoom());
    expect(addShutdownCallback).toHaveBeenCalledTimes(1);
    expect(shutdownCallback).toBeTypeOf("function");
    await (shutdownCallback == null ? void 0 : shutdownCallback());
    expect(acloseSpy).toHaveBeenCalledTimes(1);
  });
  it("warns when avatar is started after AgentSession.start()", async () => {
    const warn = vi.fn();
    vi.spyOn(logModule, "log").mockReturnValue({
      warn,
      debug: vi.fn()
    });
    vi.spyOn(jobModule, "getJobContext").mockReturnValue(void 0);
    const session = new AvatarSession();
    await session.start(
      {
        ...mockAgentSession({
          _started: true,
          output: { audio: { constructor: { name: "MockAudioOutput" } } }
        })
      },
      mockRoom()
    );
    expect(warn).toHaveBeenCalledWith(
      { audioOutput: "MockAudioOutput" },
      expect.stringContaining("AvatarSession.start() was called after AgentSession.start()")
    );
  });
});
//# sourceMappingURL=avatar_session.test.js.map