Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
import { describe, expect, it } from 'vitest';
import { buildChatMessages, historyAnswer, type BrowserChatTurn } from './chat-model';
const turn = (answer: string, extra: Partial<BrowserChatTurn> = {}): BrowserChatTurn => ({ id: 't', prompt: 'was macht dieser code?', modelId: 'm', request: [], answer, status: 'complete', ...extra });
const GROUNDED = '- Markierte Zeilen 50 bis 54 von `general.py` (Python-Quelltext).\n\nIm Quelltext:\n\n```python\nclass JSONBAgg(OrderableAggMixin, Aggregate):\n function = "JSONB_AGG"\n```\n\n'
+ '+2 weitere Attribute und Methoden\n\nJSONBAgg setzt `function` auf "JSONB_AGG".\n\n_Fakten aus der Datei gelesen; der Text danach ist vom Modell erzeugt._';
/** After four grounded answers "Explain the marked code line by line" got the first fact line
* back from the model; the chat's own notes and code lines are not the model's to repeat (B3). */
describe('answers the chat gave itself in the history of a later request (B3)', () => {
it('sends a grounded answer as its model sentence, or its facts when the sentence was left out', () => {
expect(historyAnswer(turn(GROUNDED, { answeredFrom: 'grounded' }))).toBe('JSONBAgg setzt `function` auf "JSONB_AGG".');
const dropped = GROUNDED.replace('JSONBAgg setzt `function` auf "JSONB_AGG".\n\n', '');
expect(historyAnswer(turn(dropped, { answeredFrom: 'grounded' }))).toBe('- Markierte Zeilen 50 bis 54 von `general.py` (Python-Quelltext).');
});
it('sends a listed answer with its list and a file outline with its heading and purpose, never the note', () => {
expect(historyAnswer(turn('Callers of JSONBAgg in the loaded graph.\n\n- CALLS (11): a, b\n\n_Listed from the indexed graph; not generated by the model._', { answeredFrom: 'graph' })))
.toBe('Callers of JSONBAgg in the loaded graph.\n\n- CALLS (11): a, b');
expect(historyAnswer(turn('`tox.ini`: INI configuration, 89 lines.\n\ntox configuration: the test environments.\n\n- `[tox]`: minversion `4.0`\n- `[testenv]`: deps `x`\n\n_Read from the file; not generated by the model._',
{ answeredFrom: 'file' }))).toBe('`tox.ini`: INI configuration, 89 lines.\n\ntox configuration: the test environments.');
});
it('sends a model answer as it was written, code included', () => {
const written = 'It sets:\n\n```python\nfunction = "JSONB_AGG"\n```\n\n_emphasis the model wrote_';
expect(historyAnswer(turn(written))).toBe(written);
const request = buildChatMessages([turn(GROUNDED, { answeredFrom: 'grounded' }), turn(written)], 'und?');
expect(request.filter(message => message.role === 'assistant').map(message => message.content)).toEqual(['JSONBAgg setzt `function` auf "JSONB_AGG".', written]);
});
});