Files
范智鹏 e9762bfbe1 test: 目录对齐赛道二成果物规范(tests/ 迁移+实验报告+提效测量脚本)
- src/test 迁移至根目录 tests/(16 测试 + fixtures/manual),导入改为 ../src/
- 新增 tsconfig.test.json 独立编译测试;.vscode-test.mjs / package.json / .gitignore 同步
- 新增 tests/test-execution-log.md、tests/test-cases.md(116 用例清单)
- 新增 tests/measure/measure-review-time.mjs + performance-comparison.md(提效测量)
- 重命名 3 个中文报告文件为 demo-*-coverage-report.md
- git rm --cached 解除 vsix 跟踪;README 标注演示视频进行中
2026-08-26 19:17:44 +08:00

44 lines
2.0 KiB
TypeScript

import * as assert from 'assert';
import { buildDedupOnlyPrompt } from '../src/rules/converters/dedup-prompt';
import { buildKnownRulesSection } from '../src/rules/converters/known-rules';
import type { CustomRule } from '../src/types';
const customRules: CustomRule[] = [
{ id: 'no-todo', severity: 'warning', description: '禁止提交 TODO 注释', message: '发现 TODO 注释' },
];
const singleYaml = [
'- id: no-todo',
' severity: warning',
' description: 禁止提交 TODO 注释',
' message: 发现 TODO 注释',
].join('\n');
suite('Dedup Prompt Tests', () => {
test('buildDedupOnlyPrompt 同时包含静态规则与自定义规则', () => {
const { system, user } = buildDedupOnlyPrompt(singleYaml, customRules);
assert.ok(system.includes('pmd/AvoidDeeplyNestedIfStmts'), '应包含 PMD 静态规则');
assert.ok(system.includes('eslint/no-unused-vars'), '应包含 ESLint 静态规则');
assert.ok(system.includes('sqlfluff/AL01'), '应包含 SQLFluff 静态规则');
assert.ok(system.includes('custom/no-todo'), '应包含自定义规则');
assert.ok(system.includes('duplicateLevel'), '应包含去重字段说明');
assert.ok(user.includes('no-todo'), 'user 侧应包含待去重规则');
});
test('无自定义规则时仍包含静态规则', () => {
const { system } = buildDedupOnlyPrompt(singleYaml, []);
assert.ok(system.includes('pmd/AvoidDeeplyNestedIfStmts'));
assert.ok(!system.includes('- custom/'), '无自定义规则时不应出现 custom/ 规则条目');
});
test('buildKnownRulesSection 三语文案齐全', () => {
const section = buildKnownRulesSection(customRules);
assert.ok(section.startsWith('## '), '应以清单标题开头');
assert.ok(section.includes('### pmd'), '应包含 linter 分组标题');
assert.ok(section.includes('### 已导入的自定义规则'), '应包含自定义规则分组标题');
assert.ok(section.includes('- custom/no-todo: 禁止提交 TODO 注释'), '应包含 custom/ 前缀规则行');
});
});