- 新增 jsp-extractor/report/method-extractor/fix-prompt/registry/provider-chat/import-service/yaml-parser 测试 - .vscode-test.mjs 加 srcDir+coverage,package.json 加 test:coverage,产出 tests/coverage/(html) - 修复 method-extractor java fallback 取错捕获组、mockDocument.getText 忽略 range - 更新 tests/test-cases.md(24 文件 179 条)与 test-execution-log.md(覆盖率记录)
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import * as assert from 'assert';
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
import { loadActiveRules, listRuleFiles } from '../src/rules/yaml-parser';
|
|
|
|
suite('YamlParser Tests', () => {
|
|
let root: string;
|
|
setup(() => { root = fs.mkdtempSync(path.join(os.tmpdir(), 'yaml-test-')); });
|
|
teardown(() => { fs.rmSync(root, { recursive: true, force: true }); });
|
|
|
|
test('returns empty when rules dir missing', () => {
|
|
assert.deepStrictEqual(loadActiveRules(root), []);
|
|
assert.deepStrictEqual(listRuleFiles(root), []);
|
|
});
|
|
|
|
test('loads rules from yaml files with severity normalization', () => {
|
|
const dir = path.join(root, '.code-review', 'rules');
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
fs.writeFileSync(path.join(dir, 'a.yaml'), [
|
|
'- id: no-eval',
|
|
' severity: error',
|
|
' description: forbid eval',
|
|
' message: no eval',
|
|
' languages: [javascript]',
|
|
].join('\n'), 'utf8');
|
|
fs.writeFileSync(path.join(dir, 'b.yml'), [
|
|
'- id: bad-severity',
|
|
' severity: fatal',
|
|
' description: d',
|
|
' message: m',
|
|
].join('\n'), 'utf8');
|
|
|
|
const rules = loadActiveRules(root);
|
|
assert.strictEqual(rules.length, 2);
|
|
const evalRule = rules.find(r => r.id === 'no-eval');
|
|
assert.ok(evalRule);
|
|
assert.strictEqual(evalRule!.severity, 'error');
|
|
assert.deepStrictEqual(evalRule!.languages, ['javascript']);
|
|
assert.strictEqual(rules.find(r => r.id === 'bad-severity')!.severity, 'warning');
|
|
});
|
|
|
|
test('skips incomplete rules and non-yaml files', () => {
|
|
const dir = path.join(root, '.code-review', 'rules');
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
fs.writeFileSync(path.join(dir, 'partial.yaml'), '- id: no-msg\n severity: error\n description: d\n', 'utf8');
|
|
fs.writeFileSync(path.join(dir, 'note.txt'), 'not yaml', 'utf8');
|
|
|
|
const rules = loadActiveRules(root);
|
|
assert.strictEqual(rules.length, 0);
|
|
assert.deepStrictEqual(listRuleFiles(root), ['partial.yaml']);
|
|
});
|
|
});
|