feat(assistant): #94-#97 historique permanent, sidebar IA, panneau + et bouton rond
This commit is contained in:
@@ -916,16 +916,25 @@ async function main() {
|
||||
b._panel.remove();
|
||||
});
|
||||
|
||||
// ── 13. Session management ──
|
||||
await test("sessions persist and can be reopened and deleted", () => {
|
||||
// ── 13. Session management (#95/#96 — persistent backend history) ──
|
||||
await test("sessions persist and can be reopened and deleted", async () => {
|
||||
localStorage.clear();
|
||||
// Mock server to avoid network calls in tests
|
||||
globalThis.fetch = async (url) => {
|
||||
const u = String(url);
|
||||
if (u.includes("/api/ai/bookslm/history")) {
|
||||
if (u.includes("PUT")) return { ok: true, status: 200, json: async () => ({}) };
|
||||
return { ok: true, status: 200, json: async () => ({ sessions: [] }) };
|
||||
}
|
||||
return { ok: true, status: 200, json: async () => ({}) };
|
||||
};
|
||||
const b = new BooksLM();
|
||||
b._panel = document.createElement("div");
|
||||
b._mode = MODE.DIRECTORY;
|
||||
b._vault = "VaultSessions";
|
||||
b._directory = "notes";
|
||||
b._loadHistory();
|
||||
assert.equal(b._sessions.length, 1, "one session created on first load");
|
||||
await b._loadHistory();
|
||||
assert.ok(b._sessions.length >= 1, "at least one session on first load (local or server)");
|
||||
|
||||
b._messages.push({ role: "user", content: "Première question" });
|
||||
b._messages.push({ role: "assistant", content: "Réponse" });
|
||||
@@ -938,7 +947,7 @@ async function main() {
|
||||
b._messages.push({ role: "user", content: "Deuxième" });
|
||||
b._saveHistory();
|
||||
|
||||
b._loadSession(firstId);
|
||||
await b._loadSession(firstId);
|
||||
assert.equal(b._messages.length, 2, "previous session messages restored");
|
||||
assert.equal(b._messages[0].content, "Première question");
|
||||
const first = b._sessions.find((s) => s.id === firstId);
|
||||
@@ -979,16 +988,26 @@ async function main() {
|
||||
b.close();
|
||||
});
|
||||
|
||||
await test("legacy single-conversation history is migrated", () => {
|
||||
await test("legacy single-conversation history is migrated", async () => {
|
||||
localStorage.clear();
|
||||
// Mock server to avoid network calls in tests
|
||||
globalThis.fetch = async (url) => {
|
||||
const u = String(url);
|
||||
if (u.includes("/api/ai/bookslm/history")) {
|
||||
if (u.includes("PUT")) return { ok: true, status: 200, json: async () => ({}) };
|
||||
return { ok: true, status: 200, json: async () => ({ sessions: [] }) };
|
||||
}
|
||||
return { ok: true, status: 200, json: async () => ({}) };
|
||||
};
|
||||
const b = new BooksLM();
|
||||
b._mode = MODE.GENERAL;
|
||||
localStorage.setItem(
|
||||
b._legacyHistoryKey(),
|
||||
JSON.stringify([{ role: "user", content: "Ancienne conversation" }])
|
||||
);
|
||||
b._loadHistory();
|
||||
await b._loadHistory();
|
||||
assert.equal(b._sessions.length, 1, "legacy history imported as a session");
|
||||
assert.ok(b._messages.length >= 1, "messages from legacy session available");
|
||||
assert.equal(b._messages[0].content, "Ancienne conversation");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user