import path from 'path';
process.env.RUNBOOK_ROOT = path.resolve('tests/fixtures');
// Ensure no LLM key is set
delete process.env.LLM_API_KEY;
delete process.env.OPENAI_API_KEY;
import { loadConfig } from '../../src/adapters/config.mjs';
import { createFsAdapter } from '../../src/adapters/fsio.mjs';
import { createIndexer } from '../../src/services/indexer.mjs';
import { describe, test, expect, runTests } from '../unit/core/_harness.mjs';
// Mock answerService for now until implementation
function mockAnswerService({ searchService, llmAdapter }) {
return {
answer: async (question, options = {}) => {
const searchResult = searchService.search(question, { topK: options.topK || 3 });
// Without LLM, return structured answer with citations but no summary
const citations = searchResult.results.map((r, idx) => ({
id: idx + 1,
doc_id: r.docId,
title: r.title,
snippet: r.text.slice(0, 150) + '...',
stale: r.stale
}));
return {
question,
summary: null, // No LLM available
citations,
risks: searchResult.results.flatMap(r => r.risks || []),
safe_ops: searchResult.results.flatMap(r => r.safeOps || []),
mode: 'offline'
};
}
};
}
const config = loadConfig(process.env);
const fsAdapter = createFsAdapter(config.root);
const indexer = createIndexer({ fsAdapter, config, logger:{ log:()=>{} } });
describe('us2:answer-llm-off', () => {
test('returns structured answer without LLM summary when no API key', async () => {
const index = await indexer.buildIndex();
const searchService = {
search: (q, opts) => ({
results: index.documents.slice(0, opts?.topK || 3).map(d => ({
docId: d.id,
title: d.title,
text: `Content for ${d.title}`,
risks: d.risks || [],
safeOps: d.safeOps || [],
stale: d.freshness?.stale || false
}))
})
};
const llmAdapter = null; // No LLM
const answerService = mockAnswerService({ searchService, llmAdapter });
const result = await answerService.answer('How to restart service?');
expect(result.summary).toBe(null);
expect(Array.isArray(result.citations)).toBe(true);
expect(result.mode).toBe('offline');
expect(result.question).toBe('How to restart service?');
});
});
await runTests();