feat(backend): recite the project context to verify what the model receives

Storing a context is not enough: the user needs to know it actually reaches
Ollama, and that the messages replayed are the ones they expect. The read-only
probe answers that by asking the model to recite its context and reporting how
many messages were replayed, while persisting nothing.
This commit is contained in:
BlackAngelTV committed 2026-10-05 21:39:28 +02:00
1 parent 38f088c8fe
commit c1d6593c35
2 files changed
+94 -5

No files matched your search

+40 -1
View File
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { api, registerUser, startServer } from './helpers.js';
import { api, readSse, registerUser, startServer } from './helpers.js';
describe('projects and context', () => {
let srv;
@@ -177,4 +177,43 @@ describe('projects and context', () => {
0,
);
});
it('recites the stored context without persisting anything', async () => {
const p = await newProject('Recall');
for (const content of ['Le frontend est écrit en Rust', 'Le backend répond en SSE']) {
await api(srv.base, 'POST', `/api/projects/${p.id}/messages`, {
token: alice.token,
body: { content },
});
}
const res = await fetch(`${srv.base}/api/projects/${p.id}/context/recall`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${alice.token}` },
body: JSON.stringify({}),
});
assert.equal(res.status, 200);
const events = await readSse(res);
const done = events.find((e) => e.event === 'done');
assert.ok(events.some((e) => e.event === 'delta'), 'expected the model to answer');
// The model really received the two stored messages.
assert.equal(done.data.contextMessages, 2);
assert.equal(done.data.reply, 'Bonjour Tony, je suis Jarvis.');
// A probe must leave the context untouched.
const msgs = await api(srv.base, 'GET', `/api/projects/${p.id}/messages`, { token: alice.token });
assert.equal(msgs.json.messages.length, 2);
});
it('recital needs a token', async () => {
const p = await newProject('Recall auth');
const res = await fetch(`${srv.base}/api/projects/${p.id}/context/recall`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({}),
});
assert.equal(res.status, 401);
});
});