mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 16:10:09 +08:00
A focused cut on top of v1.4.3:
- Skill hub: install community skills from ClawHub (and any compatible
registry via settings/skill_hubs.json) — provider abstraction in
services/skill/hub.py, new `deeptutor skill search/install/list/remove`
CLI, admin-only install endpoint for multi-user (install ≠ assign).
Every import runs a security gate: hub verdict check, zip-slip/zip-bomb
guards, text/script suffix whitelist, `always:` frontmatter stripped,
provenance recorded in .hub-lock.json.
- KB previews: new /knowledge/{kb}/file-preview-text/{filename} endpoint
serving extracted plain text; KB Files tab renders real in-browser
DOCX/XLSX previews; DOCX previewer scales pages to fit narrow panels.
- Markdown previews allow safe raster data:image URLs on <img src>
(react-markdown strips all data: URLs by default); script-capable
schemes stay blocked.
- All ten localized READMEs re-synced with the English README.
- Docs (deeptutor.info): `deeptutor skill` reference, hub-install notes on
Space and multi-user pages, KB file routes in the server API table
(en + zh).
- CLI docs contract test updated for partner/skill subcommands.
Release notes: assets/releases/ver1-4-4.md
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
188 lines
6.4 KiB
TypeScript
188 lines
6.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
escapeUnknownHtmlTagsForDisplay,
|
|
hasVisibleMarkdownContent,
|
|
markdownUrlTransform,
|
|
normalizeMarkdownForDisplay,
|
|
} from "../lib/markdown-display";
|
|
|
|
test("normalizeMarkdownForDisplay removes empty details blocks", () => {
|
|
const input = "Before\n\n<details><summary></summary></details>\n\nAfter";
|
|
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay removes raw html control placeholders", () => {
|
|
const input =
|
|
'Before\n\n<progress></progress>\n<input type="text" />\n<textarea> </textarea>\n\nAfter';
|
|
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay removes empty markdown tables", () => {
|
|
const input = "Before\n\n| |\n|---|\n\nAfter";
|
|
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay removes empty html tables", () => {
|
|
const input = "Before\n\n<table><tr><td> </td></tr></table>\n\nAfter";
|
|
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay keeps meaningful tables", () => {
|
|
const input = "Before\n\n| Topic |\n|---|\n| Math |\n\nAfter";
|
|
assert.equal(normalizeMarkdownForDisplay(input), input);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay linkifies bare citations in prose", () => {
|
|
assert.equal(
|
|
normalizeMarkdownForDisplay("Reference [1]."),
|
|
'Reference [1](#references "citation").',
|
|
);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay links research citations to exact references", () => {
|
|
assert.equal(
|
|
normalizeMarkdownForDisplay(
|
|
"Agentic loops [CIT-1-01] and plans [PLAN-01].",
|
|
),
|
|
'Agentic loops [1](#ref-cit-1-01 "citation") and plans [2](#ref-plan-01 "citation").',
|
|
);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay numbers research citations from reference list order", () => {
|
|
const refs =
|
|
'<details id="references" open><summary>参考资料</summary><ol>' +
|
|
'<li id="ref-cit-1-01" data-citation-id="CIT-1-01">' +
|
|
"<strong>[1]</strong> <code>CIT-1-01</code> A</li>" +
|
|
'<li id="ref-cit-2-01" data-citation-id="CIT-2-01">' +
|
|
"<strong>[2]</strong> <code>CIT-2-01</code> B</li>" +
|
|
"</ol></details>";
|
|
const input = `First [CIT-2-01], then [CIT-1-01].\n\n${refs}`;
|
|
assert.equal(
|
|
normalizeMarkdownForDisplay(input),
|
|
`First [2](#ref-cit-2-01 "citation"), then [1](#ref-cit-1-01 "citation").\n\n${refs}`,
|
|
);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay keeps array indexes inside fenced code", () => {
|
|
const input = "```js\nconst item = values[0];\n```";
|
|
assert.equal(normalizeMarkdownForDisplay(input), input);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay keeps array indexes inside inline code", () => {
|
|
const input = "Use `values[0]` for the first item.";
|
|
assert.equal(normalizeMarkdownForDisplay(input), input);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay unwraps explicit citation code spans outside code", () => {
|
|
assert.equal(
|
|
normalizeMarkdownForDisplay("See `[web-1]` for details."),
|
|
'See [web-1](#references "citation") for details.',
|
|
);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay unwraps research citation code spans", () => {
|
|
assert.equal(
|
|
normalizeMarkdownForDisplay("See `[CIT-1-01]` for details."),
|
|
'See [1](#ref-cit-1-01 "citation") for details.',
|
|
);
|
|
});
|
|
|
|
test("normalizeMarkdownForDisplay does not linkify research reference list ids", () => {
|
|
const input =
|
|
'<details id="references" open><summary>参考资料</summary><ol>' +
|
|
'<li id="ref-cit-1-01" data-citation-id="CIT-1-01">' +
|
|
"<strong>[1]</strong> <code>CIT-1-01</code> Web Search: q</li>" +
|
|
"</ol></details>";
|
|
assert.equal(normalizeMarkdownForDisplay(input), input);
|
|
});
|
|
|
|
test("escapeUnknownHtmlTagsForDisplay escapes LLM pseudo tags", () => {
|
|
const input = "Before\n<think>internal scratchpad</think>\nAfter";
|
|
assert.equal(
|
|
escapeUnknownHtmlTagsForDisplay(input),
|
|
"Before\n`<think>`internal scratchpad`</think>`\nAfter",
|
|
);
|
|
});
|
|
|
|
test("escapeUnknownHtmlTagsForDisplay preserves line count for previews", () => {
|
|
const input = "A\n\n<thinking>hidden</thinking>\nB";
|
|
const output = escapeUnknownHtmlTagsForDisplay(input);
|
|
assert.equal(output.split("\n").length, input.split("\n").length);
|
|
});
|
|
|
|
test("escapeUnknownHtmlTagsForDisplay keeps allowed html tags", () => {
|
|
const input = "<details><summary>More</summary>Body</details>";
|
|
assert.equal(escapeUnknownHtmlTagsForDisplay(input), input);
|
|
});
|
|
|
|
test("escapeUnknownHtmlTagsForDisplay escapes active html containers", () => {
|
|
const input = '<iframe src="https://example.com"></iframe>';
|
|
assert.equal(
|
|
escapeUnknownHtmlTagsForDisplay(input),
|
|
'`<iframe src="https://example.com">``</iframe>`',
|
|
);
|
|
});
|
|
|
|
test("escapeUnknownHtmlTagsForDisplay strips unsafe html attributes", () => {
|
|
const input =
|
|
'<a href="javascript:alert(1)" onclick="alert(2)" style="color:red">link</a>';
|
|
assert.equal(escapeUnknownHtmlTagsForDisplay(input), "<a>link</a>");
|
|
});
|
|
|
|
test("markdownUrlTransform keeps raster data images on img src", () => {
|
|
const png = "data:image/png;base64,iVBORw0KGgo=";
|
|
assert.equal(markdownUrlTransform(png, "src", { tagName: "img" }), png);
|
|
});
|
|
|
|
test("markdownUrlTransform rejects active data URLs", () => {
|
|
assert.equal(
|
|
markdownUrlTransform("data:text/html;base64,PHNjcmlwdD4=", "src", {
|
|
tagName: "img",
|
|
}),
|
|
"",
|
|
);
|
|
assert.equal(
|
|
markdownUrlTransform(
|
|
"data:image/svg+xml;base64,PHN2ZyBvbmxvYWQ9YWxlcnQoMSk+",
|
|
"src",
|
|
{ tagName: "img" },
|
|
),
|
|
"",
|
|
);
|
|
});
|
|
|
|
test("markdownUrlTransform only allows data images on img src", () => {
|
|
assert.equal(
|
|
markdownUrlTransform("data:image/png;base64,iVBORw0KGgo=", "href", {
|
|
tagName: "a",
|
|
}),
|
|
"",
|
|
);
|
|
});
|
|
|
|
test("hasVisibleMarkdownContent rejects empty raw-html placeholders", () => {
|
|
assert.equal(
|
|
hasVisibleMarkdownContent("<details><summary></summary></details>"),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("hasVisibleMarkdownContent rejects raw html control placeholders", () => {
|
|
assert.equal(
|
|
hasVisibleMarkdownContent('<progress></progress>\n<input type="text" />'),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("hasVisibleMarkdownContent rejects empty markdown tables", () => {
|
|
assert.equal(hasVisibleMarkdownContent("| |\n|---|"), false);
|
|
});
|
|
|
|
test("hasVisibleMarkdownContent keeps meaningful markdown", () => {
|
|
assert.equal(
|
|
hasVisibleMarkdownContent("这是一个正常回复。\n\n- 第一条"),
|
|
true,
|
|
);
|
|
});
|