// Proof for kb#170 component 2 — run with:
//   BGE_M3_URL=http://localhost:11436/v1/embeddings node src/classifier.test.mjs
// (default BGE_M3_URL assumes host.docker.internal, which only resolves
// inside a container; override to localhost when running on the Agap host
// directly, same pattern as the bge-m3 curl checks elsewhere in this repo).
//
// This is a LIVE test against the real bge-m3 embedder (no mock) — the
// point of an encoder-only classifier is that it's cheap enough to just
// call for real (~30 short strings embedded once, then one embedding per
// test case). It does not touch Todoist, Kanboard, or any other live
// service.

import assert from 'node:assert/strict';
import { classifyIdea } from './classifier.js';

const cases = [
  { text: 'позвонить маме поздравить с днём рождения', expectArea: 'семья' },
  { text: 'купить новый пылесос для дома', expectArea: 'дом' },
  { text: 'записаться на приём к стоматологу', expectArea: 'здоровье' },
  { text: 'починить квоту Kimi у Adolf, срочно сегодня', expectArea: 'adolf', expectUrgency: 'high' },
  { text: 'спроектировать и запустить proactive-секретаря на Agap', expectArea: 'welfare', expectDecompose: 'needs-decomposition' },
  { text: 'оплатить счёт за интернет', expectDecompose: 'simple-task' },
  { text: 'организовать переезд на новую квартиру, когда-нибудь', expectDecompose: 'needs-decomposition', expectUrgency: 'low' },
];

let passed = 0;
let failed = 0;

for (const c of cases) {
  const result = await classifyIdea(c.text);
  const row = `"${c.text}" -> area=${result.area.label}(${result.area.score}) urgency=${result.urgency.label}(${result.urgency.score}) decompose=${result.decompose.label}(${result.decompose.score})`;
  try {
    if (c.expectArea) assert.equal(result.area.label, c.expectArea, `area mismatch for "${c.text}"`);
    if (c.expectUrgency) assert.equal(result.urgency.label, c.expectUrgency, `urgency mismatch for "${c.text}"`);
    if (c.expectDecompose) assert.equal(result.decompose.label, c.expectDecompose, `decompose mismatch for "${c.text}"`);
    console.log(`ok   - ${row}`);
    passed++;
  } catch (e) {
    console.log(`FAIL - ${row}\n       ${e.message}`);
    failed++;
  }
}

console.log(`\n${passed} passed, ${failed} failed`);
if (failed > 0) process.exit(1);
