Files
coucou/brain/tests/node-page.test.ts
T
Claude 8a32d25a4b Memory › Graph: a real page for each star, galaxy centres link to all their stars, steady names
- `brain page <id> --json`: what memory knows about a node: title, date, the Markdown file to open
  (record or project page), the claude.ai link, how many messages and the first request, the
  memory's full text and why, the record's summary and lists (decisions, facts, lessons…), the
  conversations it comes from. Records are indexed by their frontmatter (records.ts).
- The panel shows it like a page: kind tag, big title, "Updated …", "Open file ↗" (and Open in
  Claude), then one paragraph that ends with the linked stars as underlined links (click = that
  page, the camera flies there), Summary, then each list. In page mode the kind chips give way to
  a "Kind: title ⌄" row that goes back to the list.
- Hovering a galaxy centre (or its name) draws a line to every star of the galaxy (235 for portfo);
  a named centre (50 memories or more) no longer shows a label on top, its name is already below.
- The galaxy names always sit right under their centre: they used to switch rows when another
  label was in the way, so they jumped as the galaxy turned.
- graph: memories now hang off the conversation they come from (their sources are record ids,
  the record gives the conversation), and measures ("abonnés instagram louis") are no longer
  turned into people.

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

60 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 { nodePage } from "../src/node-page.js";
import { conversationOfSources } from "../src/records.js";
let dir: string;
let config: BrainConfig;
beforeEach(() => {
dir = fs.mkdtempSync(path.join(os.tmpdir(), "page"));
config = {
brainPath: dir, claudeProjectsPath: path.join(dir, "none"), repoPaths: [],
chunkModel: "sonnet", mergeModel: "opus", maxChunkTokens: 100000, language: "fr", repoAliases: {},
};
const p = rawDbPath(config);
fs.mkdirSync(path.dirname(p), { recursive: true });
const db = new Database(p);
db.exec(`CREATE VIRTUAL TABLE 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 VALUES (?, ?, ?, ?, ?, ?, 'desktop', '', ?)`);
ins.run("c1", "Préparer Botan", "2026-11-20", "https://claude.ai/chat/c1", 0, "human", "Aide-moi à préparer le lancement de Botan");
ins.run("c1", "Préparer Botan", "2026-11-20", "https://claude.ai/chat/c1", 1, "claude", "D'accord");
db.close();
fs.mkdirSync(path.join(dir, "records"));
fs.writeFileSync(path.join(dir, "records", "2026-11-20_botan_c1.md"),
"---\nid: rec_20261120_botan_c1\ntitle: Lancement Botan\nupdated: 2026-11-21\nsources:\n - session:c1\n---\n## Résumé\nOn a préparé le **lancement**.\n\n## Décisions\n- Prix de 49 € [[proj_botan]]\n- Lancement en décembre\n");
fs.mkdirSync(path.join(dir, ".state", "proj"), { recursive: true });
fs.writeFileSync(path.join(dir, ".state", "proj", "proj_botan.json"), JSON.stringify({ id: "proj_botan", elements: [
{ id: "dec_1", kind: "décision", texte: "Prix de 49 €", date: "2026-11-20", sources: ["rec_20261120_botan_c1"], projets: ["botan"], raison: "Marge suffisante" },
] }));
});
afterEach(() => fs.rmSync(dir, { recursive: true, force: true }));
describe("node page", () => {
it("joins a memory to its record and its conversation", () => {
expect(conversationOfSources(config, ["rec_20261120_botan_c1"])).toBe("c1");
const p = nodePage(config, "dec_1")!;
expect(p.text).toBe("Prix de 49 €");
expect(p.reason).toBe("Marge suffisante");
expect(p.sources).toEqual([{ id: "conv_c1", title: "Préparer Botan", date: "2026-11-20" }]);
expect(p.summary).toBe("On a préparé le lancement.");
expect(p.sections[0]).toEqual({ title: "Décisions", items: ["Prix de 49 € botan", "Lancement en décembre"] });
});
it("gives a conversation its first request, length, link and record", () => {
const p = nodePage(config, "conv_c1")!;
expect(p.messages).toBe(2);
expect(p.firstRequest).toContain("lancement de Botan");
expect(p.link).toBe("https://claude.ai/chat/c1");
expect(p.file).toMatch(/records/);
expect(p.date).toBe("2026-11-21");
});
});