test: 补充单元测试提升代码覆盖率
新增测试文件: - agent/executor-extended.test.ts, presets/ - context/manager-extended.test.ts - core/agent.test.ts, providers.test.ts - lsp/cli.test.ts, client-extended.test.ts, index.test.ts - permission/file-prompt.test.ts, prompt.test.ts - skills/builtin/ - tools/filesystem/write_file-extended.test.ts - tools/git/git_commit-extended.test.ts - tools/load_description.test.ts - tools/todo/todo-manager.test.ts - tools/tool-search.test.ts - types/ - utils/config-extended.test.ts, diff-extended.test.ts 修改现有测试: - agent/manager.test.ts - tools/skill/skill.test.ts - utils/config.test.ts, diff.test.ts, image.test.ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { computeDiff, countChanges, formatEditDiff } from '../../../src/utils/diff.js';
|
||||
import { computeDiff, countChanges, formatEditDiff, formatDiff } from '../../../src/utils/diff.js';
|
||||
|
||||
describe('computeDiff - 计算文件差异', () => {
|
||||
describe('新文件', () => {
|
||||
@@ -248,6 +248,56 @@ describe('LCS 算法测试', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatDiff - 格式化 diff 输出', () => {
|
||||
it('新文件显示新增标记', () => {
|
||||
const diff = computeDiff(null, 'line1\nline2');
|
||||
const result = formatDiff(diff, '/test/file.ts');
|
||||
|
||||
expect(result).toContain('新文件');
|
||||
expect(result).toContain('/test/file.ts');
|
||||
});
|
||||
|
||||
it('修改文件显示原文件和修改后标记', () => {
|
||||
const diff = computeDiff('old', 'new');
|
||||
const result = formatDiff(diff, '/test/file.ts');
|
||||
|
||||
expect(result).toContain('原文件');
|
||||
expect(result).toContain('修改后');
|
||||
expect(result).toContain('/test/file.ts');
|
||||
});
|
||||
|
||||
it('hunk 头部显示正确的行号范围', () => {
|
||||
const diff = computeDiff('line1\nline2', 'line1\nnew\nline2');
|
||||
const result = formatDiff(diff, '/test/file.ts');
|
||||
|
||||
expect(result).toContain('@@');
|
||||
});
|
||||
|
||||
it('新增行显示 + 前缀', () => {
|
||||
const diff = computeDiff(null, 'added line');
|
||||
const result = formatDiff(diff, '/test/file.ts');
|
||||
|
||||
expect(result).toContain('+');
|
||||
expect(result).toContain('added line');
|
||||
});
|
||||
|
||||
it('删除行显示 - 前缀', () => {
|
||||
const diff = computeDiff('removed line', 'new line');
|
||||
const result = formatDiff(diff, '/test/file.ts');
|
||||
|
||||
expect(result).toContain('-');
|
||||
expect(result).toContain('removed line');
|
||||
});
|
||||
|
||||
it('空 diff 返回基本格式', () => {
|
||||
const diff = computeDiff('same', 'same');
|
||||
const result = formatDiff(diff, '/test/file.ts');
|
||||
|
||||
// 没有 hunks 时只有头部
|
||||
expect(result).toContain('/test/file.ts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('实际代码场景', () => {
|
||||
it('函数修改', () => {
|
||||
const oldContent = `function hello() {
|
||||
|
||||
Reference in New Issue
Block a user