Files
metona-ai-desktop/electron/harness/tools/built-in/__tests__/html-to-markdown.test.ts
T
thzxx 3940716dc2
CI / 类型检查 + Lint + 单元测试 (push) Failing after 5m45s
CI / 全量测试 (Electron ABI) (push) Failing after 5m22s
CI / 产物编译验证 (push) Successful in 10m3s
feat: v0.7.0 四阶段全量迭代 — 修复面收口 · 安全纵深 · 架构还债 · 能力演进
P1 修复面收口: v0.6.3 截断自愈推全量(Anthropic/Ollama/非流式/引擎兜底); SSE 上游错误帧检测进重试通道;
clearMessages 摘要游标根治; truncateResult 内联图片白名单统一; 前端四 bug(确认弹窗锁死/MemoryViewer/
Virtuoso Footer/abort 尾部过滤) + reasoning 缓冲跨迭代污染; 托盘通知过滤与新建会话死链接线

P2 安全纵深: MCP 审批闭环(ConfirmationHook×PolicyEngine 联动+重名拒注册); SSRF 收敛 ssrf-guard 共享模块
(web_fetch 双通道校验+重定向终态复检); Electron 加固(preload CJS 化→sandbox:true/CSP/权限白名单/will-navigate);
run_command cmd.exe 白名单通道元字符守门; diff_viewer 10MB 预检; Anthropic thinking 预算下限; Agnes 思考显式关闭

P3 架构还债: OpenAICompatibleAdapter 中间基类收敛四家样板; 错误分类单轨化(删 mapError/getFetchSignal,
超时显式 ETIMEDOUT); PRAGMA user_version 迁移版本化; 死代码清理专项(cn.ts/SHORTCUTS/ContextMenu 分支/
getWindowState/modifiedArgs/sandbox 空壳); i18next 引入; a11y 第一轮; SearXNG 页批量草稿模型统一

P4 能力演进: Ollama pull 可取消/capabilities 探测/num_ctx 实测缓存; UpdateService feed 比对式自动更新
(app:updateCheck IPC + StatusBar 入口); MiMo providerOptions(web_search 服务端工具/strict JSON);
web_fetch extract_mode=markdown(turndown); network.proxyUrl 全局代理(Chromium sessions+undici dispatcher)

测试: 264 → 507 用例(Electron ABI 全绿零跳过), 覆盖引擎压缩管线/重试竞速/MEMORY.md 闸门/file_editor 五操作/
filesystem 七工具实体夹具/git 真实仓库/SSE 错误帧/全线截断自愈/Provider 请求形态矩阵/SSRF 表测/钩子分级矩阵/
OutputValidator 全量/SLO 指标/MCP 安全纯函数/task_manager 链路/渲染层纯域/i18n 桥契约
2026-08-27 17:06:58 +08:00

72 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* htmlToMarkdown 转换器测试(v0.6.4 P4-4
* 锁定 Agent 抓取高频结构的输出形态与降级行为。
*/
import { describe, it, expect } from 'vitest';
import { htmlToMarkdown } from '../network-utils';
describe('htmlToMarkdownv0.6.4 P4-4', () => {
it('标题/段落/加粗/链接/图片 基础结构', () => {
const md = htmlToMarkdown(`
<div>
<h2>安装指南</h2>
<p>先 <strong>下载</strong> 安装包,再看<a href="/docs">文档</a>。</p>
<img src="/logo.png" alt="Logo">
</div>
`);
expect(md).toContain('## 安装指南');
expect(md).toContain('**下载**');
expect(md).toContain('[文档](/docs)');
expect(md).toContain('![Logo](/logo.png)');
});
it('em/code 行内标记', () => {
const md = htmlToMarkdown('<p><em>注意</em><code>npm i</code></p>');
expect(md).toContain('*注意*');
expect(md).toContain('`npm i`');
});
it('pre 代码块保留原文(剥离内部 code 标签的行内包裹)', () => {
const md = htmlToMarkdown('<pre><code>const a = 1;\nconsole.log(a);</code></pre>');
expect(md).toContain('```\nconst a = 1;');
expect(md).toContain('console.log(a);\n```');
});
it('无序与有序列表(一层)', () => {
const md = htmlToMarkdown(`
<ul><li>甲</li><li>乙</li></ul>
<ol><li>第一步</li><li>第二步</li></ol>
`);
expect(md).toMatch(/- 甲\n- 乙/s);
expect(md).toMatch(/1\. 第一步\n2\. 第二步/s);
});
it('blockquote 与 hr', () => {
const md = htmlToMarkdown('<blockquote>引言内容</blockquote><hr>');
expect(md).toContain('> 引言内容');
expect(md).toContain('---');
});
it('script/style/svg 等噪声整块剔除', () => {
const md = htmlToMarkdown(
'<script>alert(1)</script><style>.x{}</style><svg>noise</svg><p>正文</p>',
);
expect(md).not.toContain('alert');
expect(md).not.toContain('.x');
expect(md).toContain('正文');
});
it('表格降级为可读文本(不抛错、不留标签痕迹)', () => {
const md = htmlToMarkdown('<table><tr><td>A</td><td>B</td></tr></table>');
expect(md).toContain('A');
expect(md).toContain('B');
expect(md).not.toMatch(/<t[dh]r?>/);
});
it('空输入返回空串', () => {
expect(htmlToMarkdown('')).toBe('');
expect(htmlToMarkdown('<script>x</script>')).toBe('');
});
});