yuangs 1.3.21 → 1.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -2
- package/test/index.test.js +68 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuangs",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.22",
|
|
4
4
|
"description": "苑广山的个人应用集合 CLI(彩色版)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"yuangs": "cli.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "
|
|
10
|
+
"test": "jest"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"yuangs",
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"axios": "^1.13.2",
|
|
30
30
|
"chalk": "^4.1.2"
|
|
31
31
|
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"jest": "^29.7.0"
|
|
34
|
+
},
|
|
32
35
|
"publishConfig": {
|
|
33
36
|
"access": "public"
|
|
34
37
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const { exec } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const yuangs = require('../index.js');
|
|
4
|
+
|
|
5
|
+
describe('Module: index.js', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
yuangs.clearConversationHistory();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('should export correct app URLs', () => {
|
|
11
|
+
expect(yuangs.urls).toHaveProperty('shici');
|
|
12
|
+
expect(yuangs.urls).toHaveProperty('dict');
|
|
13
|
+
expect(yuangs.urls).toHaveProperty('pong');
|
|
14
|
+
expect(yuangs.urls.shici).toContain('shici/index.html');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('should manage conversation history correctly', () => {
|
|
18
|
+
yuangs.addToConversationHistory('user', 'hello');
|
|
19
|
+
let history = yuangs.getConversationHistory();
|
|
20
|
+
expect(history).toHaveLength(1);
|
|
21
|
+
expect(history[0]).toEqual({ role: 'user', content: 'hello' });
|
|
22
|
+
|
|
23
|
+
yuangs.addToConversationHistory('assistant', 'hi');
|
|
24
|
+
history = yuangs.getConversationHistory();
|
|
25
|
+
expect(history).toHaveLength(2);
|
|
26
|
+
expect(history[1]).toEqual({ role: 'assistant', content: 'hi' });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should limit conversation history to 20 items', () => {
|
|
30
|
+
for (let i = 0; i < 25; i++) {
|
|
31
|
+
yuangs.addToConversationHistory('user', `msg ${i}`);
|
|
32
|
+
}
|
|
33
|
+
const history = yuangs.getConversationHistory();
|
|
34
|
+
expect(history).toHaveLength(20);
|
|
35
|
+
expect(history[history.length - 1].content).toBe('msg 24');
|
|
36
|
+
// The first 5 should be dropped, so the first one in history should be 'msg 5'
|
|
37
|
+
expect(history[0].content).toBe('msg 5');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should clear conversation history', () => {
|
|
41
|
+
yuangs.addToConversationHistory('user', 'test');
|
|
42
|
+
yuangs.clearConversationHistory();
|
|
43
|
+
expect(yuangs.getConversationHistory()).toHaveLength(0);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('CLI Integration', () => {
|
|
48
|
+
const cliPath = path.join(__dirname, '../cli.js');
|
|
49
|
+
|
|
50
|
+
test('should print help message', (done) => {
|
|
51
|
+
exec(`node ${cliPath} --help`, (error, stdout, stderr) => {
|
|
52
|
+
expect(error).toBeNull();
|
|
53
|
+
expect(stdout).toContain('苑广山的个人应用启动器');
|
|
54
|
+
expect(stdout).toContain('使用方法:');
|
|
55
|
+
done();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should list apps', (done) => {
|
|
60
|
+
exec(`node ${cliPath} list`, (error, stdout, stderr) => {
|
|
61
|
+
expect(error).toBeNull();
|
|
62
|
+
expect(stdout).toContain('苑广山的应用列表');
|
|
63
|
+
expect(stdout).toContain('shici');
|
|
64
|
+
expect(stdout).toContain('dict');
|
|
65
|
+
done();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|