seogeneratorserver/tests/llm/llmmanager.cost.test.js
StillHammer dbf1a3de8c Add technical plan for multi-format export system
Added plan.md with complete architecture for format-agnostic content generation:
- Support for Markdown, HTML, Plain Text, JSON formats
- New FormatExporter module with neutral data structure
- Integration strategy with existing ContentAssembly and ArticleStorage
- Bonus features: SEO metadata generation, readability scoring, WordPress Gutenberg format
- Implementation roadmap with 4 phases (6h total estimated)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 16:14:29 +08:00

30 lines
1.2 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert';
import { safeImport } from '../_helpers/path.js';
import { FakeLLMClient } from '../_helpers/fakeLLMClient.js';
function skip(msg){ console.warn('[SKIP]', msg); }
test('LLMManager: returns usage and computes cost if table provided', async () => {
const res = await safeImport('LLMManager');
if (!res.ok) { skip(res.reason); return; }
const L = res.mod;
if (typeof L.__setClient !== 'function' || typeof L.__setCosts !== 'function') {
skip('Missing __setClient/__setCosts hooks');
return;
}
const fake = new FakeLLMClient();
L.__setClient('mock', fake);
L.__setCosts({ 'mock:fake-1': { in: 0.001, out: 0.003 } }); // $/1k tokens
const out = await L.callModel({ provider:'mock', model:'fake-1', input:'price me' });
const usage = out.usage || out.meta?.usage;
assert.ok(usage, 'usage expected');
const cost = out.__meta?.cost ?? out.cost;
assert.ok(typeof cost === 'number', 'cost numeric expected');
// 100 in, 150 out => 0.1k*0.001 + 0.15k*0.003 = 0.0001 + 0.00045 = 0.00055
assert.ok(cost > 0 && cost < 0.001, `cost looks off: ${cost}`);
});