"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 warmup = __toESM(require("../_warmup.cjs"), 1);
var import_runner = __toESM(require("./runner.cjs"), 1);
(0, import_vitest.describe)("EotRunner", () => {
  (0, import_vitest.afterEach)(() => {
    import_vitest.vi.restoreAllMocks();
  });
  (0, import_vitest.it)("initializes the native EOT model and predicts on decoded PCM", async () => {
    const received = [];
    const fakeMod = {
      initEot: import_vitest.vi.fn(),
      initVad: import_vitest.vi.fn(),
      createVad: import_vitest.vi.fn(),
      VAD_WINDOW_SAMPLES: 512,
      predict: import_vitest.vi.fn(async (pcm2) => {
        received.push(pcm2);
        return 0.83;
      })
    };
    import_vitest.vi.spyOn(warmup, "_getLocalInferenceModule").mockReturnValue(
      fakeMod
    );
    const runner = new import_runner.default();
    await runner.initialize();
    (0, import_vitest.expect)(fakeMod.initEot).toHaveBeenCalledOnce();
    const samples = Int16Array.from([1, -2, 3, -4]);
    const pcm = Buffer.from(samples.buffer, samples.byteOffset, samples.byteLength).toString(
      "base64"
    );
    const out = await runner.run({ pcm });
    (0, import_vitest.expect)(out.probability).toBe(0.83);
    (0, import_vitest.expect)(out.inferenceDurationMs).toBeGreaterThanOrEqual(0);
    (0, import_vitest.expect)(received).toHaveLength(1);
    (0, import_vitest.expect)(Array.from(received[0])).toEqual([1, -2, 3, -4]);
    await runner.close();
  });
  (0, import_vitest.it)("throws on initialize when the native binding is unavailable", async () => {
    import_vitest.vi.spyOn(warmup, "_getLocalInferenceModule").mockReturnValue(void 0);
    const runner = new import_runner.default();
    await (0, import_vitest.expect)(runner.initialize()).rejects.toThrow(/native binding unavailable/);
  });
});
//# sourceMappingURL=runner.test.cjs.map