fix(ai): les clics ne font plus sauter la conversation au bas (BUG-059); tableaux markdown corrects dans create_pdf (#92)

This commit is contained in:
2026-09-17 13:55:36 -04:00
parent 6a58a59a11
commit 22e9240e4f
14 changed files with 174 additions and 32 deletions
+19
View File
@@ -302,6 +302,25 @@ async function main() {
}
});
await test("isScrollbarPress: content clicks never unpin, scrollbar drags do (BUG-059)", () => {
const { isScrollbarPress } = bookslmMod;
const container = document.createElement("div");
container.getBoundingClientRect = () => ({
left: 0, right: 800, top: 0, bottom: 600, width: 800, height: 600,
});
const link = document.createElement("a");
// Click on a file link / steps toggle → must NOT unpin (the thread
// would otherwise jump to the bottom when the padding is cleared).
assert.equal(isScrollbarPress(link, 790, container), false);
// Click on blank content area → must NOT unpin either.
assert.equal(isScrollbarPress(container, 300, container), false);
// Dragging the vertical scrollbar: target is the container itself and
// the press lands in the right-edge gutter → unpin allowed.
assert.equal(isScrollbarPress(container, 792, container), true);
// Defensive: no container / no geometry → never unpin.
assert.equal(isScrollbarPress(link, 790, null), false);
});
await test("the placeholder render keeps the anchor (no scroll reset before first token)", async () => {
// Regression: the assistant placeholder used to be rendered while
// `_isLoading` was still false, so it took the "restore previous
+37
View File
@@ -150,6 +150,43 @@ class TestCreatePdf:
}, confirm=True)
assert (vault / "big.pdf").exists()
def test_markdown_tables_go_through_the_export_pipeline(self, vault, monkeypatch):
# The document-page pipeline (mistune tables + WeasyPrint) must be
# used when available: capture the HTML handed to the PDF generator.
import sys
import types
captured = {}
fake = types.ModuleType("backend.pdf_export")
def fake_build(html, title, **kw):
captured["html"] = html
captured["title"] = title
return "<html>" + html + "</html>"
fake.build_pdf_html = fake_build
fake.generate_pdf = lambda html, title=None, **kw: b"%PDF-fake"
monkeypatch.setitem(sys.modules, "backend.pdf_export", fake)
out = call_tool("create_pdf", _ctx(), {
"vault": "Vault", "path": "table.pdf", "title": "Rapport",
"content": "# T\n\n| a | b |\n|---|---|\n| 1 | 2 |",
}, confirm=True)
assert out.ok
assert "<table>" in captured["html"]
assert captured["title"] == "Rapport"
assert (vault / "table.pdf").read_bytes() == b"%PDF-fake"
def test_reportlab_fallback_when_weasyprint_missing(self, vault, monkeypatch):
# sys.modules[name] = None makes `from backend.pdf_export import …`
# raise ImportError → the simplified renderer must take over.
import sys
monkeypatch.setitem(sys.modules, "backend.pdf_export", None)
call_tool("create_pdf", _ctx(), {
"vault": "Vault", "path": "fb.pdf", "title": "T", "content": "# H\ntexte",
}, confirm=True)
assert (vault / "fb.pdf").read_bytes().startswith(b"%PDF")
class TestVaultSafety:
def test_path_outside_vault_rejected(self, vault):