Files
DeepTutor/web/tests/reading-inline-markdown.test.ts
Bingxi Zhao (Frank) ce7c2dc2dc release: v1.6.1 — one key, one navigator, one sidebar you arrange
Model configuration was one layer replicated seven times: every service
stored its own profile with its own credentials, so a single OpenRouter
key had to be pasted into five separate pages. This release splits that
in two — a **connection** holds one vendor credential and links it down
to every service that vendor can serve, and a **task model** takes the
calls nobody asks for (naming a conversation, writing the composer's
starting points) off the model picked for actual reasoning. Both are
opt-in; existing per-service profiles resolve exactly as before.

Around that: Settings drops the card grid for a persistent searchable
navigator whose landing page answers "what state am I in" instead of
repeating the directory; Mastery Path files study conversations under
their topic and opens them in the tutor rather than dropping them on
/home; the sidebar folds features into More and reorders by drag; the
reading companion is rebuilt from /home's own chat components; and the
LightRAG engine talks to the SDK directly, so its extra no longer drags
MinerU in transitively.

Also back-merges PR #1041 (Anthropic SDK 1.x temperature via extra_body)
and PR #741 (owner-only auth secret/token files), which had been merged
straight into main and never flowed back to dev.

Release notes: assets/releases/ver1-6-1.md
Gates: pre-commit 15/15, ruff clean, pytest 5802 passed, web 450 node
tests, eslint 0 errors, docs build clean.
2026-08-30 13:19:42 +08:00

98 lines
3.0 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { InlineMarkdown, MarkdownLine } from "../lib/reading-inline-markdown";
/**
* Strips tags to approximate `Element.textContent` for markup this module
* produces — no nested tags swallow text and no fixture uses `<`, `>`, `&`,
* so this is exact for the cases under test.
*/
function flatten(html: string): string {
// React HTML-escapes text nodes on serialization (e.g. `>` becomes `&gt;`);
// decoding here mirrors what a real `Element.textContent` read would give
// back, since the escaping is a serialization detail, not a content change.
return html
.replace(/<[^>]+>/g, "")
.replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&#x27;|&#39;/g, "'");
}
function renderLine(text: string): string {
return renderToStaticMarkup(React.createElement(MarkdownLine, { text }));
}
function renderInline(text: string): string {
return renderToStaticMarkup(React.createElement(InlineMarkdown, { text }));
}
test("bold and italic render as elements but stay exact-match selectable", () => {
const source = "This is **bold** and *italic* text.";
const html = renderInline(source);
assert.match(html, /<strong>bold<\/strong>/);
assert.match(html, /<em>italic<\/em>/);
assert.equal(
flatten(html),
source,
"hidden markers must reproduce every stripped Markdown character",
);
});
test("links render as anchors while remaining exact-match selectable", () => {
const source = "See [the docs](https://example.com/x) for details.";
const html = renderInline(source);
assert.match(html, /href="https:\/\/example\.com\/x"/);
assert.match(html, />the docs</);
assert.equal(flatten(html), source);
});
test("inline code renders as a code element", () => {
const source = "Run `pytest -q` first.";
const html = renderInline(source);
assert.match(html, /<code[^>]*>pytest -q<\/code>/);
assert.equal(flatten(html), source);
});
test("plain prose with no Markdown syntax passes through untouched", () => {
const source = "Nothing special about this sentence at all.";
const html = renderInline(source);
assert.equal(html, source);
});
test("a bullet line keeps its marker selectable and adds no stray characters", () => {
const source = "- first item";
const html = renderLine(source);
assert.equal(flatten(html), source);
});
test("a blockquote line keeps its marker selectable", () => {
const source = "> a quoted remark";
const html = renderLine(source);
assert.equal(flatten(html), source);
});
test("a horizontal rule renders an <hr> while the source text survives hidden", () => {
const source = "---";
const html = renderLine(source);
assert.match(html, /<hr\b/);
assert.equal(flatten(html), source);
});
test("does not misparse an arithmetic expression as italics", () => {
const source = "3 * 4 = 12, not italic.";
const html = renderInline(source);
assert.equal(html, source);
});