"use strict";
var import_vitest = require("vitest");
var import_index = require("./index.js");
(0, import_vitest.describe)("TUI auth runtime services", () => {
  (0, import_vitest.afterEach)(() => {
    (0, import_index.setTuiRuntimeServices)({});
  });
  (0, import_vitest.it)("uses host-provided API-key device login and persistence services", async () => {
    const prompt = import_vitest.vi.fn();
    const perform = import_vitest.vi.fn().mockResolvedValue({
      dextoApiKey: "dxt_full_key",
      dextoKeyDisplay: "dxt_abc...",
      dextoKeyId: "key-id"
    });
    const persist = import_vitest.vi.fn().mockResolvedValue({
      keyId: "key-id",
      hasDextoApiKey: true
    });
    (0, import_index.setTuiRuntimeServices)({
      performDeviceCodeLogin: perform,
      persistDeviceApiKeyLoginResult: persist
    });
    const loginResult = await (0, import_index.performDeviceCodeLogin)({
      onPrompt: prompt
    });
    const persisted = await (0, import_index.persistDeviceApiKeyLoginResult)(loginResult);
    (0, import_vitest.expect)(perform).toHaveBeenCalledWith({ onPrompt: prompt });
    (0, import_vitest.expect)(persist).toHaveBeenCalledWith({
      dextoApiKey: "dxt_full_key",
      dextoKeyDisplay: "dxt_abc...",
      dextoKeyId: "key-id"
    });
    (0, import_vitest.expect)(persisted).toEqual({
      keyId: "key-id",
      hasDextoApiKey: true
    });
  });
  (0, import_vitest.it)("fails fast when API-key device login persistence is not provided by the host", async () => {
    await (0, import_vitest.expect)(
      (0, import_index.persistDeviceApiKeyLoginResult)({
        dextoApiKey: "dxt_full_key",
        dextoKeyDisplay: "dxt_abc...",
        dextoKeyId: "key-id"
      })
    ).rejects.toThrow("TUI runtime services missing required method");
  });
});
