.claude 仓库: - git mv skills/ssw-h5dev-flow → skills/ssw-loop (保留 history) - 改 SKILL.md frontmatter (name + description 触发词) - 改 5 个 references + 3 个子代理 prompt 模板 + learnings.md.tmpl - 改 templates/html/style.css + script.js 注释 - 改 scripts/scaffold.sh + 4 个 check 脚本路径 - 改其他 skill 引用: dacli-ts/SKILL.md + anti-patterns.md, no-spa-page/SKILL.md, jnpf-browser-automation/SKILL.md - 改 CLAUDE.md §技能索引 + §开发流程 + §问题处理 - 改 .claude/templates/flow-jxcj-rerun-process.md + .claude/settings.local.json (allow list) dacli 仓库: - 改 src/commands/doc/_parser.ts + list.ts 注释 (提及 ssw-loop plan/debug/research 走 MD) - 改 tests/unit/doc-md-slice.test.ts 注释 - 改 docs/尚数网基本开发规范v3.0.md (7 处引用) - git mv docs/skill-audit/ssw-h5dev-flow.md → ssw-loop.md (保留 history) - 改 docs/cmd-review/doc.md 历史保留 (未改, 反映 v0.11 时代状态): - dacli/docs/v0.11-*.md (4 个 plan 文件) - docs/dacli/ssw-dacli/ (Java 版归档, 已废弃) - docs/aibridge/.claude/ (Python 时代) 验证: 14/14 doc-md-slice 测试 PASS
122 lines
4.5 KiB
TypeScript
122 lines
4.5 KiB
TypeScript
/**
|
|
* tests/unit/doc-md-slice.test.ts — .md section 切片 (v0.12+)
|
|
*
|
|
* 背景: ssw-loop 改 plan/debug/research 走 MD 后, dacli doc get 必须能按 ## 切分,
|
|
* 否则子代理回退到 Read 整个 .md (踩 R1 反模式, 25K+ tokens).
|
|
*/
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
|
import { mkdtempSync, copyFileSync, rmSync, existsSync, writeFileSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import { tmpdir } from 'node:os'
|
|
import {
|
|
parseFile, getSection, getRawLines, listSections, isMarkdown,
|
|
} from '../../src/commands/doc/_parser.ts'
|
|
|
|
let tmpDir: string
|
|
let mdPath: string
|
|
let htmlPath: string
|
|
|
|
const FIXTURE_MD = join(__dirname, '..', 'fixtures', 'plan.md')
|
|
const FIXTURE_HTML = join(__dirname, '..', 'fixtures', 'design-sample.html')
|
|
|
|
beforeAll(() => {
|
|
tmpDir = mkdtempSync(join(tmpdir(), 'dacli-md-'))
|
|
mdPath = join(tmpDir, 'plan.md')
|
|
if (existsSync(FIXTURE_MD)) copyFileSync(FIXTURE_MD, mdPath)
|
|
else writeFileSync(mdPath, '# placeholder\n')
|
|
|
|
htmlPath = join(tmpDir, 'design.html')
|
|
if (existsSync(FIXTURE_HTML)) copyFileSync(FIXTURE_HTML, htmlPath)
|
|
else {
|
|
writeFileSync(htmlPath, `<!DOCTYPE html><html><head><title>t</title></head><body>
|
|
<div id="h2_overview"><h2>概述</h2>概述内容</div>
|
|
<div id="h2_models"><h2>数据模型</h2>表 10 张</div>
|
|
</body></html>`)
|
|
}
|
|
})
|
|
|
|
afterAll(() => { rmSync(tmpDir, { recursive: true, force: true }) })
|
|
|
|
describe('isMarkdown', () => {
|
|
it('.md → true', () => expect(isMarkdown('plan.md')).toBe(true))
|
|
it('.markdown → true', () => expect(isMarkdown('plan.markdown')).toBe(true))
|
|
it('.html → false', () => expect(isMarkdown('design.html')).toBe(false))
|
|
it('大写 .MD → true', () => expect(isMarkdown('PLAN.MD')).toBe(true))
|
|
})
|
|
|
|
describe('parseFile (.md)', () => {
|
|
it('按 ## 切分出 4 个 section', () => {
|
|
const { sections } = parseFile(mdPath, false)
|
|
const ids = Array.from(sections.keys())
|
|
expect(ids).toEqual([
|
|
'元信息',
|
|
'1. 当前任务 (上下文恢复指针)',
|
|
'2. 已决事项 (子代理回写)',
|
|
'3. 阶段进度',
|
|
])
|
|
})
|
|
it('section 行数合理 (>=1)', () => {
|
|
const { sections } = parseFile(mdPath, false)
|
|
for (const sec of sections.values()) expect(sec.lines).toBeGreaterThanOrEqual(1)
|
|
})
|
|
})
|
|
|
|
describe('getSection (.md)', () => {
|
|
it('按中文标题 id 命中 (核心用例: 上下文恢复读 plan.md 当前任务)', () => {
|
|
const sec = getSection(mdPath, '1. 当前任务 (上下文恢复指针)', false)
|
|
expect(sec).not.toBeNull()
|
|
expect(sec!.title).toBe('1. 当前任务 (上下文恢复指针)')
|
|
expect(sec!.text).toContain('**派子代理创建 4 模块 10 form**')
|
|
// 6 个动态指针字段 (阶段/具体任务/负责人/预计完成/前置依赖/回滚点)
|
|
expect(sec!.text).toContain('回滚点: 无 (新建应用)')
|
|
// H1 应用名作为前言
|
|
expect(sec!.text).toContain('数据要素人工智能创新大赛管理平台')
|
|
})
|
|
it('不存在的 id → null', () => {
|
|
expect(getSection(mdPath, '不存在的标题', false)).toBeNull()
|
|
})
|
|
it('--section=元信息 也命中', () => {
|
|
const sec = getSection(mdPath, '元信息', false)
|
|
expect(sec).not.toBeNull()
|
|
expect(sec!.text).toContain('jxcj')
|
|
})
|
|
})
|
|
|
|
describe('getRawLines (.md)', () => {
|
|
it('按行号切片', () => {
|
|
const r = getRawLines(mdPath, 1, 5, false)
|
|
expect(r).not.toBeNull()
|
|
expect(r!.content).toContain('数据要素人工智能创新大赛管理平台')
|
|
})
|
|
})
|
|
|
|
describe('listSections (.md)', () => {
|
|
it('返回所有 section 元数据', () => {
|
|
const list = listSections(mdPath)
|
|
expect(list.length).toBe(4)
|
|
expect(list[0].id).toBe('元信息')
|
|
expect(list[0].title).toBe('元信息')
|
|
})
|
|
})
|
|
|
|
describe('stripMermaid (.md)', () => {
|
|
it('--strip-mermaid=true 去除 mermaid 围栏', () => {
|
|
const sec = getSection(mdPath, '2. 已决事项 (子代理回写)', true)
|
|
expect(sec!.text).not.toContain('graph LR')
|
|
expect(sec!.text).not.toContain('mermaid')
|
|
expect(sec!.text).toContain('competitionInfo')
|
|
})
|
|
it('默认保留 mermaid (对理解设计有用)', () => {
|
|
const sec = getSection(mdPath, '2. 已决事项 (子代理回写)', false)
|
|
expect(sec!.text).toContain('graph LR')
|
|
})
|
|
})
|
|
|
|
describe('HTML 文件仍按原 HTML 解析 (回归)', () => {
|
|
it('HTML 文件解析出 h2_overview/h2_models', () => {
|
|
const { sections } = parseFile(htmlPath, false)
|
|
expect(sections.has('h2_overview')).toBe(true)
|
|
expect(sections.has('h2_models')).toBe(true)
|
|
})
|
|
})
|