seo-generator-server/tests/llm/llmmanager.cost.test.js
StillHammer 4f60de68d6 Fix BatchProcessor initialization and add comprehensive test suite
- Fix BatchProcessor constructor to avoid server blocking during startup
- Add comprehensive integration tests for all modular combinations
- Enhance CLAUDE.md documentation with new test commands
- Update SelectiveLayers configuration for better LLM allocation
- Add AutoReporter system for test automation
- Include production workflow validation tests

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-19 14:17:49 +08:00

35 lines
1.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert';
import { safeImport } from '../_helpers/path.js';
import { FakeLLMClient } from '../_helpers/fakeLLMClient.js';
import { AutoReporter } from '../reporters/AutoReporter.js';
function skip(msg){ console.warn('[SKIP]', msg); }
// Auto-Reporter Configuration
const autoReporter = new AutoReporter();
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}`);
});