import assert from "node:assert/strict";
import test from "node:test";

import { preferredProviderProfile, providerProfileOptionsFromPayload } from "../src/stores/workbench-session.ts";

test("Workbench provider catalog marks missing selected profile as unavailable", () => {
  const options = providerProfileOptionsFromPayload({ profiles: [{ profile: "dsflash-go", label: "DeepSeek V4 Flash", configured: true }] }, "codex");

  const available = options.find((option) => option.value === "dsflash-go");
  const missingSelected = options.find((option) => option.value === "codex");

  assert.equal(available?.configured, true);
  assert.equal(missingSelected?.configured, false);
  assert.equal(preferredProviderProfile(options, "codex"), "dsflash-go");
});

test("Workbench provider selection stays non-blocking without a configured catalog option", () => {
  const options = providerProfileOptionsFromPayload({ profiles: [{ profile: "codex", configured: false }] }, "codex");
  assert.equal(preferredProviderProfile(options, "codex"), "codex");
  assert.equal(preferredProviderProfile(providerProfileOptionsFromPayload({}, "codex"), "codex"), "codex");
});
