-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-agent.js
More file actions
209 lines (187 loc) · 7.27 KB
/
test-agent.js
File metadata and controls
209 lines (187 loc) · 7.27 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* LlamaApp Agent System Test Script
* DevToolsコンソールで実行してください
*/
async function runAgentTests() {
console.log('🧪 LlamaApp Agent Test Suite\n');
console.log('=' .repeat(60));
const results = {
passed: 0,
failed: 0,
tests: []
};
// ヘルパー関数
const test = async (name, fn) => {
try {
console.log(`\n🔍 Testing: ${name}`);
const result = await fn();
console.log(`✅ PASS: ${name}`);
results.passed++;
results.tests.push({ name, status: 'PASS', result });
return result;
} catch (error) {
console.error(`❌ FAIL: ${name}`);
console.error(` Error: ${error.message}`);
results.failed++;
results.tests.push({ name, status: 'FAIL', error: error.message });
return null;
}
};
// Test 1: Agent Status
await test('Get Agent Status', async () => {
const status = await window.llamaAPI.getAgentStatus();
console.log(' Status:', status);
if (!status.available) throw new Error('Agent not available');
return status;
});
// Test 2: Enable Agent
await test('Enable Agent', async () => {
const result = await window.llamaAPI.toggleAgent(true);
console.log(' Result:', result);
if (!result.enabled) throw new Error('Failed to enable agent');
return result;
});
// Test 3: Get Tools
await test('Get Tool Definitions', async () => {
const tools = await window.llamaAPI.getTools();
console.log(` Found ${tools.length} tools:`);
tools.forEach(tool => console.log(` - ${tool.name}: ${tool.description}`));
if (tools.length === 0) throw new Error('No tools found');
return tools;
});
// Test 4: Read File
await test('read_file Tool', async () => {
const result = await window.llamaAPI.executeTool('read_file', {
path: '~/Documents/LlamaAppTest/test.txt'
});
console.log(' File size:', result.result.size, 'bytes');
console.log(' Lines:', result.result.lines);
console.log(' Content preview:', result.result.content.substring(0, 100) + '...');
if (!result.success) throw new Error(result.error);
return result;
});
// Test 5: List Directory
await test('list_directory Tool', async () => {
const result = await window.llamaAPI.executeTool('list_directory', {
path: '~/Documents/LlamaAppTest'
});
console.log(' Files:', result.result.files.length);
console.log(' Directories:', result.result.directories.length);
result.result.files.forEach(f => console.log(` - ${f.name} (${f.sizeFormatted})`));
if (!result.success) throw new Error(result.error);
return result;
});
// Test 6: Get File Info
await test('get_file_info Tool', async () => {
const result = await window.llamaAPI.executeTool('get_file_info', {
path: '~/Documents/LlamaAppTest/test.txt'
});
console.log(' Name:', result.result.name);
console.log(' Size:', result.result.sizeFormatted);
console.log(' Modified:', result.result.modified);
if (!result.success) throw new Error(result.error);
return result;
});
// Test 7: Analyze JSON
await test('analyze_json Tool', async () => {
const result = await window.llamaAPI.executeTool('analyze_json', {
path: '~/Documents/LlamaAppTest/data.json'
});
console.log(' Type:', result.result.type);
console.log(' Size:', result.result.size, 'bytes');
console.log(' Keys:', result.result.keys);
if (!result.success) throw new Error(result.error);
return result;
});
// Test 8: Analyze CSV
await test('analyze_csv Tool', async () => {
const result = await window.llamaAPI.executeTool('analyze_csv', {
path: '~/Documents/LlamaAppTest/data.csv'
});
console.log(' Total rows:', result.result.totalRows);
console.log(' Columns:', result.result.columns.join(', '));
console.log(' Sample rows:', result.result.sample.length);
if (!result.success) throw new Error(result.error);
return result;
});
// Test 9: Search Files
await test('search_files Tool', async () => {
const result = await window.llamaAPI.executeTool('search_files', {
pattern: '*.txt',
directory: '~/Documents/LlamaAppTest'
});
console.log(' Found:', result.result.count, 'files');
result.result.files.forEach(f => console.log(` - ${f.name}`));
if (!result.success) throw new Error(result.error);
return result;
});
// Test 10: Get Disk Usage
await test('get_disk_usage Tool', async () => {
const result = await window.llamaAPI.executeTool('get_disk_usage', {
path: '~/Documents'
});
console.log(' Analyzed:', result.result.directory);
console.log(' Top items:', result.result.items.slice(0, 5).length);
result.result.items.slice(0, 5).forEach(item => {
console.log(` - ${item.path}: ${item.size}`);
});
if (!result.success) throw new Error(result.error);
return result;
});
// Test 11: List Processes
await test('list_processes Tool', async () => {
const result = await window.llamaAPI.executeTool('list_processes', {});
console.log(' Total processes:', result.result.count);
console.log(' Top 5 by CPU:');
result.result.processes.slice(0, 5).forEach(p => {
console.log(` - ${p.command.substring(0, 40)}: ${p.cpu} CPU, ${p.mem} MEM`);
});
if (!result.success) throw new Error(result.error);
return result;
});
// Test 12: Security - Blocked Directory
await test('Security: Blocked Directory (/System)', async () => {
const result = await window.llamaAPI.executeTool('read_file', {
path: '/System/Library/CoreServices/SystemVersion.plist'
});
// Should fail with permission denied
if (result.success) throw new Error('Security check failed: /System should be blocked');
console.log(' ✓ Correctly blocked:', result.error);
return result;
});
// Test 13: Security - Sensitive File
await test('Security: Sensitive File (.env)', async () => {
// Create a dummy .env file for testing
await window.llamaAPI.executeTool('read_file', {
path: '~/.env'
}).catch(() => {});
const result = await window.llamaAPI.executeTool('get_file_info', {
path: '~/.env'
});
// Should be blocked or fail gracefully
console.log(' Result:', result.success ? 'File detected (check security)' : 'Blocked correctly');
return result;
});
// Test 14: Get Execution History
await test('Get Execution History', async () => {
const history = await window.llamaAPI.getHistory(10);
console.log(' Total executions:', history.length);
console.log(' Recent tools:');
history.slice(0, 5).forEach(entry => {
console.log(` - ${entry.tool}: ${entry.success ? '✅' : '❌'}`);
});
if (history.length === 0) throw new Error('No execution history');
return history;
});
// Summary
console.log('\n' + '='.repeat(60));
console.log('📊 Test Results Summary\n');
console.log(`✅ Passed: ${results.passed}`);
console.log(`❌ Failed: ${results.failed}`);
console.log(`📈 Success Rate: ${((results.passed / (results.passed + results.failed)) * 100).toFixed(1)}%`);
console.log('\n' + '='.repeat(60));
return results;
}
// Run tests
console.log('Copy and paste this into DevTools Console:\n');
console.log('runAgentTests().then(r => console.log("Tests complete!", r));');