Files
coucou/brain/tests/suggest.test.ts
Claude 5d3b87826d Hub: the page title stays on one line in a narrow window; Search skips the tools' echoes
The band's title broke letter by letter ("Se / arc / h") when the window got narrow.
Claude Code stores the tools' echoes ("[bash OK: …]", "[a lu /Users/…]") as human lines:
the first request of a conversation now skips them, so Search's recent rows show what
you asked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LJm3SRL9k3gBPaVtfPhwcT
2026-11-28 20:04:17 +00:00

63 lines
3.1 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from "vitest";
import Database from "better-sqlite3";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import type { BrainConfig } from "../src/config.js";
import { rawDbPath } from "../src/rawindex.js";
import { suggestions } from "../src/suggest.js";
let dir: string;
let config: BrainConfig;
function seed(rows: { conv: string; title: string; date: string; project: string; first: string }[]) {
const p = rawDbPath(config);
fs.mkdirSync(path.dirname(p), { recursive: true });
const db = new Database(p);
db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS raw_messages USING fts5(
conv_id UNINDEXED, conv_title UNINDEXED, conv_date UNINDEXED, conv_link UNINDEXED,
msg_index UNINDEXED, role UNINDEXED, source UNINDEXED, project UNINDEXED, text)`);
const ins = db.prepare(`INSERT INTO raw_messages (conv_id, conv_title, conv_date, conv_link, msg_index, role, source, project, text)
VALUES (?, ?, ?, '', 0, 'human', ?, ?, ?)`);
for (const r of rows) ins.run(r.conv, r.title, r.date, r.project ? "session" : "desktop", r.project, r.first);
db.close();
}
beforeEach(() => {
dir = fs.mkdtempSync(path.join(os.tmpdir(), "suggest"));
config = {
brainPath: dir, claudeProjectsPath: path.join(dir, "none"), repoPaths: [],
chunkModel: "sonnet", mergeModel: "opus", maxChunkTokens: 100000, language: "fr", repoAliases: {},
};
});
afterEach(() => fs.rmSync(dir, { recursive: true, force: true }));
describe("suggest", () => {
it("gives the last conversations and the words that come back in recent titles", () => {
seed([
{ conv: "a", title: "Reel Botan hook", date: "2026-11-27", project: "", first: "Refais ce Reel" },
{ conv: "b", title: "Nouveau Reels pour Botan", date: "2026-11-26", project: "reels", first: "Un autre" },
{ conv: "c", title: "Galaxie mémoire", date: "2026-11-25", project: "coucou", first: "La galaxie" },
{ conv: "d", title: "x", date: "2026-11-28", project: "", first: "<!-- coucou-brain-internal --> JSON" },
]);
const s = suggestions(config, { now: new Date("2026-11-28").getTime() });
expect(s.recent.map(r => r.id)).toEqual(["a", "b", "c"]); // brain's own run left out
expect(s.recent[0]!.source).toBe("claude");
expect(s.recent[1]!.source).toBe("code");
expect(s.searches).toEqual(expect.arrayContaining(["Reel", "Botan"]));
expect(s.searches).not.toContain("Nouveau"); // a stop word
expect(s.searches).not.toContain("Galaxie"); // seen once only
});
});
describe("first requests", () => {
it("skip the tools' echoes stored as human lines", async () => {
const { isToolEcho } = await import("../src/rawindex.js");
expect(isToolEcho("[bash OK: cat ~/CoucouBrain/projects/sbe-hub.md → --- id: proj_sbe")).toBe(true);
expect(isToolEcho("[a lu /Users/louis/Developer/coucou/README.md]")).toBe(true);
expect(isToolEcho("[grep \"foo\" in src]")).toBe(true);
expect(isToolEcho("[Image #1] la page search est trop vide")).toBe(false);
expect(isToolEcho("Refais ce Reel")).toBe(false);
});
});