-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeepwiki.test.ts
More file actions
90 lines (75 loc) · 2.85 KB
/
Copy pathdeepwiki.test.ts
File metadata and controls
90 lines (75 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { describe, it, expect, afterAll } from 'vitest';
import {
queryDeepWiki,
adaptedQueryDeepWiki,
closeDeepWikiConnection,
getRepoName,
} from '../../src/utils/deepwiki';
afterAll(async () => {
await closeDeepWikiConnection();
});
describe('getRepoName', () => {
it('should map adc to ant-design/ant-design-charts', () => {
expect(getRepoName('adc')).toBe('ant-design/ant-design-charts');
});
it('should map normal library to antvis/<UPPER>', () => {
expect(getRepoName('g2')).toBe('antvis/G2');
expect(getRepoName('s2')).toBe('antvis/S2');
expect(getRepoName('l7')).toBe('antvis/L7');
});
});
describe('DeepWiki Integration Test', () => {
it('should get real response from DeepWiki for G2 question', async () => {
const result = await queryDeepWiki({
repoName: 'antvis/G2',
question: '如何调整折线图两端的间隔',
});
console.log('DeepWiki Answer (keep-alive):', result.slice(0, 200));
expect(result).toBeDefined();
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(10);
expect(result).not.toMatch(/^Error/);
// 确保尾部 wiki 推荐链接已被清理
expect(result).not.toMatch(/Wiki pages you might want to explore/i);
expect(result).not.toMatch(/View this search on DeepWiki/i);
}, 120000);
it('should work with close-after-query mode', async () => {
const result = await queryDeepWiki({
repoName: 'antvis/G2',
question: 'What is G2?',
connectionMode: 'close-after-query',
});
console.log('DeepWiki Answer (close-after-query):', result.slice(0, 200));
expect(result).toBeDefined();
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(10);
}, 120000);
it('should auto-resolve short repoName via getRepoName', async () => {
const result = await queryDeepWiki({
repoName: 'g2',
question: 'What charts does G2 support?',
});
expect(result).toBeDefined();
expect(result.length).toBeGreaterThan(10);
}, 120000);
});
describe('adaptedQueryDeepWiki', () => {
it('should return { documentation } on success', async () => {
const result = await adaptedQueryDeepWiki({
repoName: 'antvis/G2',
question: 'What is G2?',
});
expect(result.documentation).toBeDefined();
expect(typeof result.documentation).toBe('string');
expect(result).not.toHaveProperty('error');
}, 120000);
it('should return { documentation: null, error } on failure', async () => {
const result = await adaptedQueryDeepWiki({
repoName: 'nonexistent/repo-that-does-not-exist-12345',
question: 'anything',
});
// DeepWiki 对不存在的仓库可能返回空或报错
// adaptedQueryDeepWiki 应该把异常吞掉,返回 error 字段
expect(result.documentation === null || typeof result.error === 'string').toBe(true);
}, 120000);
});