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
// @vitest-environment jsdom
import { describe, expect, it } from 'vitest';
import { JSONB_AGG_CALLERS, jsonbAggEvidence } from './galaxy-evidence.fixture';
import { dockHarness, readerOf } from './chat-dock.fixture';
const dock = dockHarness();
const PRE_COMMIT = 'repos:\n - repo: https://github.com/PyCQA/isort\n rev: 5.13.2\n hooks:\n - id: isort\n';
/** "Ask the model" under an answer the chat gave itself put the model's text in its place: the
* 11 listed callers became one sentence naming one of them, and nothing said who wrote it (B1). */
describe('the model answer to a listed, grounded or file answer is a turn of its own (B1)', () => {
it('keeps the listed callers and adds the model answer below them, marked as generated', async () => {
const { props, runtime } = dock.setup();
runtime.chat.mockResolvedValueOnce('The call to JSONBAgg is made by the test_jsonb_agg method.');
await dock.render({ ...props, proactiveSelection: jsonbAggEvidence() }); await dock.load();
await dock.ask('Who calls JSONBAgg?');
await dock.click('Ask the model', dock.last());
expect(runtime.chat).toHaveBeenCalledOnce();
const [listed, asked] = dock.turns();
expect(dock.turns()).toHaveLength(2);
for (const name of JSONB_AGG_CALLERS) expect(dock.answerOf(listed)).toContain(name);
expect(dock.answerOf(listed)).toContain('not generated by the model');
expect(asked.querySelector('.cbm-chat-question')?.textContent).toContain('Who calls JSONBAgg?');
expect(asked.querySelector('.cbm-chat-asked-model')?.textContent).toBe('Asked the local model');
expect(dock.answerOf(asked)).toBe('The call to JSONBAgg is made by the test_jsonb_agg method.');
expect(dock.notesOf(asked)).toContain('Generated by the local model; it can be wrong.');
// Only the last turn offers a button: asking again repeats the model's answer in place.
expect(dock.buttonsOf(listed)).toEqual([]);
expect(dock.buttonsOf(asked)).toEqual(['Ask again']);
await dock.click('Ask again', asked);
expect(runtime.chat).toHaveBeenCalledTimes(2);
expect(runtime.chat.mock.calls[1][0]).toEqual(runtime.chat.mock.calls[0][0]);
expect(dock.turns()).toHaveLength(2);
});
it('keeps German facts and adds the model answer with a German note', async () => {
const { props, runtime } = dock.setup();
runtime.chat.mockResolvedValueOnce('`JSONBAgg` setzt `function` auf "JSONB_AGG".').mockResolvedValueOnce('Diese Klasse ist eine Aggregation.');
await dock.render({ ...props, proactiveSelection: jsonbAggEvidence() }); await dock.load();
await dock.ask('was macht diese klasse? sehr kurze antwort');
const facts = dock.answerOf(dock.last());
expect(facts).toContain('Ausgewählt: JSONBAgg (Klasse)');
await dock.click('Modell fragen', dock.last());
const [grounded, asked] = dock.turns();
expect(dock.turns()).toHaveLength(2);
expect(dock.answerOf(grounded)).toBe(facts);
expect(asked.querySelector('.cbm-chat-asked-model')?.textContent).toBe('An das lokale Modell gestellt');
expect(dock.answerOf(asked)).toBe('Diese Klasse ist eine Aggregation.');
expect(dock.notesOf(asked)).toContain('Vom lokalen Modell erzeugt; kann falsch sein.');
expect(dock.buttonsOf(asked)).toEqual(['Erneut fragen']);
});
it('keeps a file outline and adds the model answer below it', async () => {
const { props, runtime } = dock.setup();
runtime.chat.mockResolvedValueOnce('This file configures pre-commit hooks.');
await dock.render({ ...props, selectionScope: 'django-demo:explore', readerContext: readerOf(PRE_COMMIT, '.pre-commit-config.yaml') }); await dock.load();
await dock.ask('What does this file do?');
const outline = dock.answerOf(dock.last());
expect(outline).toContain('repos (list of 1):');
await dock.click('Ask the model', dock.last());
expect(dock.turns()).toHaveLength(2);
expect(dock.answerOf(dock.turns()[0])).toBe(outline);
expect(dock.answerOf(dock.last())).toBe('This file configures pre-commit hooks.');
// The model is asked about the file, and the outline is not handed to it as an earlier answer.
const request = runtime.chat.mock.calls[0][0];
expect(request[0].content).toContain('--- BEGIN EXACT SOURCE TEXT ---\nrepos:');
expect(request.filter(message => message.role === 'assistant')).toHaveLength(0);
// A follow-up carries both: the outline and the model's answer.
await dock.ask('Which hook runs isort?');
expect(dock.questionsIn(runtime.chat.mock.calls[1][0])).toEqual(['What does this file do?', 'What does this file do?', 'Which hook runs isort?']);
});
it('marks every free model answer as generated, in the language of the question', async () => {
const { props, runtime } = dock.setup();
runtime.chat.mockResolvedValueOnce('It adds two values.').mockResolvedValueOnce('Es addiert zwei Werte.');
await dock.render({ ...props, readerContext: readerOf('export const sum = (a: number, b: number) => a + b;', 'src/sum.ts') }); await dock.load();
await dock.ask('Which values does it add, and where is it used?');
expect(dock.notesOf(dock.last())).toContain('Generated by the local model; it can be wrong.');
expect(dock.buttonsOf(dock.last())).toEqual(['Ask again']);
expect(dock.last().querySelector('.cbm-chat-asked-model')).toBeNull();
await dock.ask('Welche Werte addiert es, und wo wird es benutzt?');
expect(dock.notesOf(dock.last())).toContain('Vom lokalen Modell erzeugt; kann falsch sein.');
expect(dock.buttonsOf(dock.last())).toEqual(['Erneut fragen']);
});
});