import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";

const read = (relative) => readFile(new URL(relative, import.meta.url), "utf8");

test("changing models in an existing chat adds an inline warning", async () => {
  const [panel, modelMenu, icons, css] = await Promise.all([
    read("./ConversationPanel.jsx"),
    read("./ComposerModelMenu.jsx"),
    read("../../shared/ActionIcons.jsx"),
    read("./conversation.css")
  ]);

  assert.match(modelMenu, /onModelChange/);
  assert.match(modelMenu, /selectedModel\?\.model !== nextModel\?\.model/);
  assert.match(panel, /conversation\.at\(-1\)\?\.id/);
  assert.match(panel, /<ModelChangeNotice/);
  assert.match(panel, /<ModelIcon className="model-change-icon" \/>/);
  assert.match(icons, /\bBox\b/);
  assert.match(icons, /export function ModelIcon/);
  assert.match(css, /\.model-change-notice\{[^}]*grid-template-columns:minmax\(24px,1fr\) minmax\(0,720px\) minmax\(24px,1fr\)/);
  assert.match(css, /\.model-change-title\{[^}]*font-size:15px/);
  assert.match(css, /\.model-change-warning\{[^}]*font-size:12px/);
  assert.match(css, /html\[data-theme="light"\] \.app-shell \.model-change-notice/);
});

test("model change copy describes possible performance loss and context compaction", async () => {
  const i18n = await read("../../shared/i18n.js");

  for (const key of [
    "conversation.modelChangedTitle",
    "conversation.modelChangedFromTo",
    "conversation.modelChangedPerformance",
    "conversation.modelChangedCompaction"
  ]) assert.match(i18n, new RegExp(key.replace(".", "\\.")));

  assert.match(i18n, /Changing models during a chat may reduce performance\./);
  assert.match(i18n, /Context may be compacted automatically\./);
  assert.match(i18n, /\\uC131\\uB2A5\\uC774 \\uC800\\uD558\\uB420 \\uC218 \\uC788\\uC2B5\\uB2C8\\uB2E4/);
  assert.match(i18n, /\\uCEE8\\uD14D\\uC2A4\\uD2B8\\uAC00 \\uC790\\uB3D9\\uC73C\\uB85C \\uC555\\uCD95\\uB420 \\uC218 \\uC788\\uC2B5\\uB2C8\\uB2E4/);
});
