openclaw-overlay-plugin 0.8.18 → 0.8.19

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.
Files changed (80) hide show
  1. package/package.json +1 -3
  2. package/index.ts +0 -379
  3. package/src/ambient.d.ts +0 -1
  4. package/src/cli-main.ts +0 -240
  5. package/src/cli.ts +0 -16
  6. package/src/compatibility.test.ts +0 -46
  7. package/src/scripts/baemail/commands.ts +0 -311
  8. package/src/scripts/baemail/handler.ts +0 -338
  9. package/src/scripts/baemail/index.ts +0 -6
  10. package/src/scripts/config.ts +0 -89
  11. package/src/scripts/index.ts +0 -8
  12. package/src/scripts/messaging/connect.ts +0 -162
  13. package/src/scripts/messaging/handlers.ts +0 -394
  14. package/src/scripts/messaging/inbox.ts +0 -64
  15. package/src/scripts/messaging/index.ts +0 -9
  16. package/src/scripts/messaging/poll.ts +0 -59
  17. package/src/scripts/messaging/send.ts +0 -54
  18. package/src/scripts/output.ts +0 -30
  19. package/src/scripts/overlay/advertisement.ts +0 -138
  20. package/src/scripts/overlay/discover.ts +0 -83
  21. package/src/scripts/overlay/index.ts +0 -8
  22. package/src/scripts/overlay/registration.ts +0 -199
  23. package/src/scripts/overlay/services.ts +0 -199
  24. package/src/scripts/overlay/transaction.ts +0 -124
  25. package/src/scripts/payment/build.ts +0 -65
  26. package/src/scripts/payment/commands.ts +0 -92
  27. package/src/scripts/payment/index.ts +0 -7
  28. package/src/scripts/payment/types.ts +0 -62
  29. package/src/scripts/services/index.ts +0 -7
  30. package/src/scripts/services/queue.ts +0 -35
  31. package/src/scripts/services/request.ts +0 -98
  32. package/src/scripts/services/respond.ts +0 -149
  33. package/src/scripts/types.ts +0 -121
  34. package/src/scripts/utils/index.ts +0 -7
  35. package/src/scripts/utils/merkle.ts +0 -57
  36. package/src/scripts/utils/storage.ts +0 -231
  37. package/src/scripts/utils/woc.ts +0 -106
  38. package/src/scripts/wallet/balance.ts +0 -277
  39. package/src/scripts/wallet/identity.ts +0 -204
  40. package/src/scripts/wallet/index.ts +0 -7
  41. package/src/scripts/wallet/setup.ts +0 -137
  42. package/src/scripts/x-verification/commands.ts +0 -261
  43. package/src/scripts/x-verification/index.ts +0 -5
  44. package/src/services/built-in/api-proxy/index.ts +0 -26
  45. package/src/services/built-in/api-proxy/prompt.md +0 -26
  46. package/src/services/built-in/code-develop/index.ts +0 -26
  47. package/src/services/built-in/code-develop/prompt.md +0 -35
  48. package/src/services/built-in/code-review/index.ts +0 -54
  49. package/src/services/built-in/code-review/prompt.md +0 -105
  50. package/src/services/built-in/image-analysis/index.ts +0 -36
  51. package/src/services/built-in/image-analysis/prompt.md +0 -42
  52. package/src/services/built-in/memory-store/index.ts +0 -25
  53. package/src/services/built-in/memory-store/prompt.md +0 -45
  54. package/src/services/built-in/roulette/index.ts +0 -30
  55. package/src/services/built-in/roulette/prompt.md +0 -35
  56. package/src/services/built-in/summarize/index.ts +0 -24
  57. package/src/services/built-in/summarize/prompt.md +0 -27
  58. package/src/services/built-in/tell-joke/handler.ts +0 -134
  59. package/src/services/built-in/tell-joke/index.ts +0 -34
  60. package/src/services/built-in/tell-joke/prompt.md +0 -59
  61. package/src/services/built-in/translate/index.ts +0 -24
  62. package/src/services/built-in/translate/prompt.md +0 -23
  63. package/src/services/built-in/web-research/index.ts +0 -54
  64. package/src/services/built-in/web-research/prompt.md +0 -110
  65. package/src/services/index.ts +0 -16
  66. package/src/services/loader.ts +0 -344
  67. package/src/services/manager.ts +0 -304
  68. package/src/services/registry.ts +0 -246
  69. package/src/services/types.ts +0 -259
  70. package/src/test/cli.test.ts +0 -353
  71. package/src/test/comprehensive-overlay.test.ts +0 -729
  72. package/src/test/identity-consistency.test.ts +0 -68
  73. package/src/test/key-derivation.test.ts +0 -102
  74. package/src/test/network-address.test.ts +0 -46
  75. package/src/test/overlay-submit.test.ts +0 -570
  76. package/src/test/request-response-flow.test.ts +0 -253
  77. package/src/test/service-system.test.ts +0 -241
  78. package/src/test/taskflow.test.ts +0 -95
  79. package/src/test/utils/server-logic.ts +0 -368
  80. package/src/test/wallet.test.ts +0 -165
@@ -1,253 +0,0 @@
1
- /**
2
- * Tests for request/response flow and duplicate prevention.
3
- */
4
-
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
- import process from 'node:process';
8
-
9
- // Simple test runner (matching existing pattern)
10
- let passed = 0;
11
- let failed = 0;
12
-
13
- function test(name: string, fn: () => void | Promise<void>) {
14
- return (async () => {
15
- try {
16
- await fn();
17
- console.log(` ✓ ${name}`);
18
- passed++;
19
- } catch (err: unknown) {
20
- const msg = err instanceof Error ? err.message : String(err);
21
- console.log(` ✗ ${name}`);
22
- console.log(` ${msg}`);
23
- failed++;
24
- }
25
- })();
26
- }
27
-
28
- function assert(condition: boolean, message: string) {
29
- if (!condition) throw new Error(`Assertion failed: ${message}`);
30
- }
31
-
32
- // Mock paths for testing
33
- const TEST_DIR = path.join(process.cwd(), 'test-data');
34
- const TEST_PATHS = {
35
- serviceQueue: path.join(TEST_DIR, 'service-queue.jsonl'),
36
- walletDir: path.join(TEST_DIR, 'wallet'),
37
- registration: path.join(TEST_DIR, 'registration.json'),
38
- services: path.join(TEST_DIR, 'services.json'),
39
- };
40
-
41
- function setupTestEnv() {
42
- // Setup test directory
43
- if (fs.existsSync(TEST_DIR)) {
44
- fs.rmSync(TEST_DIR, { recursive: true, force: true });
45
- }
46
- fs.mkdirSync(TEST_DIR, { recursive: true });
47
- }
48
-
49
- function cleanupTestEnv() {
50
- if (fs.existsSync(TEST_DIR)) {
51
- fs.rmSync(TEST_DIR, { recursive: true, force: true });
52
- }
53
- }
54
-
55
- async function run() {
56
- console.log('\nRequest/Response Flow Tests\n');
57
-
58
- // ── Queue Cleanup Tests ──────────────────────────────────────────────
59
-
60
- await test('cleanupServiceQueue removes old fulfilled entries', async () => {
61
- setupTestEnv();
62
-
63
- const now = Date.now();
64
- const oldTime = now - (3 * 60 * 60 * 1000); // 3 hours ago
65
- const recentTime = now - (30 * 60 * 1000); // 30 minutes ago
66
-
67
- // Add test entries
68
- const entries = [
69
- { status: 'pending', requestId: 'pending-1', _ts: recentTime },
70
- { status: 'fulfilled', requestId: 'old-fulfilled', _ts: oldTime },
71
- { status: 'fulfilled', requestId: 'recent-fulfilled', _ts: recentTime },
72
- { status: 'rejected', requestId: 'old-rejected', _ts: oldTime }
73
- ];
74
-
75
- const content = entries.map(e => JSON.stringify(e)).join('\n') + '\n';
76
- fs.writeFileSync(TEST_PATHS.serviceQueue, content);
77
-
78
- // Mock PATHS for cleanupServiceQueue
79
- const originalPaths = await import('../scripts/config.js');
80
- const mockPaths = { ...originalPaths.PATHS, serviceQueue: TEST_PATHS.serviceQueue };
81
-
82
- // Temporarily replace PATHS
83
- (globalThis as Record<string, unknown>).mockPaths = mockPaths;
84
-
85
- // Redefine cleanupServiceQueue with mocked paths
86
- function mockCleanupServiceQueue(maxAgeMs = 24 * 60 * 60 * 1000, finalStatusMaxAgeMs = 2 * 60 * 60 * 1000) {
87
- if (!fs.existsSync(TEST_PATHS.serviceQueue)) return;
88
-
89
- const currentTime = Date.now();
90
- const finalStatuses = ['fulfilled', 'rejected', 'delivery_failed', 'failed', 'error'];
91
-
92
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
93
- const keptLines: string[] = [];
94
- let removedCount = 0;
95
-
96
- for (const line of lines) {
97
- try {
98
- const entry = JSON.parse(line);
99
- const entryAge = currentTime - (entry._ts || 0);
100
-
101
- // Always keep pending entries that aren't too old
102
- if (entry.status === 'pending' && entryAge < maxAgeMs) {
103
- keptLines.push(line);
104
- continue;
105
- }
106
-
107
- // Keep final status entries only if they're recent
108
- if (finalStatuses.includes(entry.status) && entryAge < finalStatusMaxAgeMs) {
109
- keptLines.push(line);
110
- continue;
111
- }
112
-
113
- // Remove this entry
114
- removedCount++;
115
- } catch {
116
- // Keep malformed entries to avoid data loss
117
- keptLines.push(line);
118
- }
119
- }
120
-
121
- if (removedCount > 0) {
122
- fs.writeFileSync(TEST_PATHS.serviceQueue, keptLines.join('\n') + (keptLines.length ? '\n' : ''));
123
- }
124
- }
125
-
126
- // Run cleanup with 2 hour limit for final statuses
127
- mockCleanupServiceQueue(24 * 60 * 60 * 1000, 2 * 60 * 60 * 1000);
128
-
129
- // Check remaining entries
130
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
131
- const remaining = lines.map((line: string) => JSON.parse(line));
132
-
133
- assert(remaining.length === 2, `Expected 2 remaining entries, got ${remaining.length}`);
134
- assert(remaining.find((e: any) => e.requestId === 'pending-1') !== undefined, 'Should keep recent pending');
135
- assert(remaining.find((e: any) => e.requestId === 'recent-fulfilled') !== undefined, 'Should keep recent fulfilled');
136
- assert(remaining.find((e: any) => e.requestId === 'old-fulfilled') === undefined, 'Should remove old fulfilled');
137
- assert(remaining.find((e: any) => e.requestId === 'old-rejected') === undefined, 'Should remove old rejected');
138
-
139
- cleanupTestEnv();
140
- });
141
-
142
- await test('updateServiceQueueStatus updates request status atomically', async () => {
143
- setupTestEnv();
144
-
145
- // Add a test entry
146
- const entry = {
147
- status: 'pending',
148
- requestId: 'test-request-456',
149
- serviceId: 'test-service',
150
- from: 'sender-key',
151
- _ts: Date.now()
152
- };
153
-
154
- fs.writeFileSync(TEST_PATHS.serviceQueue, JSON.stringify(entry) + '\n');
155
-
156
- // Mock updateServiceQueueStatus with test paths
157
- function mockUpdateServiceQueueStatus(requestId: string, newStatus: string, additionalFields = {}) {
158
- if (!fs.existsSync(TEST_PATHS.serviceQueue)) return false;
159
-
160
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
161
- let updated = false;
162
-
163
- const updatedLines = lines.map((line: string) => {
164
- try {
165
- const entryData = JSON.parse(line);
166
- if (entryData.requestId === requestId) {
167
- updated = true;
168
- return JSON.stringify({
169
- ...entryData,
170
- status: newStatus,
171
- ...additionalFields,
172
- updatedAt: Date.now()
173
- });
174
- }
175
- return line;
176
- } catch {
177
- return line;
178
- }
179
- });
180
-
181
- if (updated) {
182
- fs.writeFileSync(TEST_PATHS.serviceQueue, updatedLines.join('\n') + '\n');
183
- }
184
-
185
- return updated;
186
- }
187
-
188
- // Update status
189
- const updated = mockUpdateServiceQueueStatus('test-request-456', 'fulfilled', {
190
- fulfilledAt: Date.now(),
191
- result: { message: 'success' }
192
- });
193
-
194
- assert(updated === true, 'Should return true for successful update');
195
-
196
- // Verify update
197
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
198
- const updatedEntry = JSON.parse(lines[0]);
199
-
200
- assert(updatedEntry.status === 'fulfilled', 'Status should be updated to fulfilled');
201
- assert(updatedEntry.requestId === 'test-request-456', 'Request ID should remain the same');
202
- assert(updatedEntry.fulfilledAt !== undefined, 'Should have fulfilledAt timestamp');
203
- assert(updatedEntry.updatedAt !== undefined, 'Should have updatedAt timestamp');
204
- assert(updatedEntry.result?.message === 'success', 'Should have result data');
205
-
206
- cleanupTestEnv();
207
- });
208
-
209
- await test('updateServiceQueueStatus returns false for non-existent request', async () => {
210
- setupTestEnv();
211
-
212
- // Mock updateServiceQueueStatus with test paths
213
- function mockUpdateServiceQueueStatus(requestId: string, _newStatus: string) {
214
- if (!fs.existsSync(TEST_PATHS.serviceQueue)) return false;
215
-
216
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
217
- let updated = false;
218
-
219
- lines.map((line: string) => {
220
- try {
221
- const entry = JSON.parse(line);
222
- if (entry.requestId === requestId) {
223
- updated = true;
224
- }
225
- return line;
226
- } catch {
227
- return line;
228
- }
229
- });
230
-
231
- return updated;
232
- }
233
-
234
- const updated = mockUpdateServiceQueueStatus('non-existent-request', 'fulfilled');
235
- assert(updated === false, 'Should return false for non-existent request');
236
-
237
- cleanupTestEnv();
238
- });
239
-
240
- // ── Summary ──────────────────────────────────────────────────────────
241
- console.log(`\n${passed} passed, ${failed} failed\n`);
242
-
243
- if (failed > 0) {
244
- process.exit(1);
245
- }
246
- }
247
-
248
- // Run tests if this file is executed directly
249
- if (import.meta.url === `file://${process.argv[1]}`) {
250
- run().catch(console.error);
251
- }
252
-
253
- export { run };
@@ -1,241 +0,0 @@
1
- /**
2
- * Service system comprehensive tests.
3
- * Tests service registration, loading, validation, and execution.
4
- */
5
-
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import { fileURLToPath } from 'node:url';
9
- import { serviceRegistry, serviceLoader, serviceManager, initializeServiceSystem } from '../services/index.js';
10
- import { ServiceDefinition, ServiceCategory } from '../services/types.js';
11
-
12
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
- const projectRoot = path.resolve(__dirname, '..', '..');
14
-
15
- // Test helper functions
16
- function assert(condition: boolean, message: string) {
17
- if (!condition) {
18
- throw new Error(`Assertion failed: ${message}`);
19
- }
20
- }
21
-
22
- function assertEquals(actual: any, expected: any, message?: string) {
23
- if (actual !== expected) {
24
- throw new Error(`Assertion failed: ${message || ''} - Expected ${expected}, got ${actual}`);
25
- }
26
- }
27
-
28
- console.log('\n=== Service System Tests ===\n');
29
-
30
- // Test 1: Service Registry Basic Operations
31
- console.log('Testing service registry basic operations...');
32
-
33
- // Create test service
34
- const testService: ServiceDefinition = {
35
- id: 'test-service',
36
- name: 'Test Service',
37
- description: 'A test service for unit testing',
38
- defaultPrice: 10,
39
- category: ServiceCategory.UTILITY,
40
- inputSchema: {
41
- type: 'object',
42
- properties: {
43
- message: { type: 'string', description: 'Test message' }
44
- },
45
- required: ['message']
46
- }
47
- };
48
-
49
- // Clear registry for clean test
50
- serviceRegistry.clear();
51
-
52
- // Test registration
53
- serviceRegistry.register(testService);
54
- assert(serviceRegistry.get('test-service') !== undefined, 'Service should be registered');
55
- assertEquals(serviceRegistry.get('test-service')?.name, 'Test Service', 'Service name should match');
56
-
57
- // Test listing
58
- const services = serviceRegistry.list();
59
- assert(services.length === 1, 'Should have one registered service');
60
- assertEquals(services[0].id, 'test-service', 'Listed service should match registered service');
61
-
62
- console.log('✅ Registry: basic operations work correctly');
63
-
64
- // Test 2: Service Registry Validation
65
- console.log('Testing service registry validation...');
66
-
67
- // Test duplicate registration
68
- try {
69
- serviceRegistry.register(testService);
70
- throw new Error('Should have thrown error for duplicate registration');
71
- } catch (error: any) {
72
- assert(error.message.includes('already registered'), 'Should reject duplicate registration');
73
- }
74
-
75
- // Test invalid service (missing required fields)
76
- try {
77
- serviceRegistry.register({
78
- id: '',
79
- name: 'Invalid',
80
- description: 'Missing ID',
81
- defaultPrice: 10
82
- } as ServiceDefinition);
83
- throw new Error('Should have thrown error for invalid service');
84
- } catch (error: any) {
85
- assert(error.message.includes('Service ID is required'), 'Should reject service without ID');
86
- }
87
-
88
- console.log('✅ Registry: validation works correctly');
89
-
90
- // Test 3: Service Loader Directory Scanning
91
- console.log('Testing service loader directory scanning...');
92
-
93
- // Clear registry for clean test
94
- serviceRegistry.clear();
95
-
96
- // Load built-in services
97
- const builtInServices = await serviceLoader.loadBuiltInServices();
98
- assert(builtInServices.length > 0, 'Should load built-in services');
99
-
100
- // Check that specific services are loaded
101
- const expectedServices = ['tell-joke', 'api-proxy', 'summarize', 'memory-store', 'roulette', 'code-develop', 'image-analysis'];
102
- for (const serviceId of expectedServices) {
103
- const service = builtInServices.find(s => s.id === serviceId);
104
- assert(service !== undefined, `Should load ${serviceId} service`);
105
- assert(service!.name.length > 0, `${serviceId} should have a name`);
106
- assert(service!.description.length > 0, `${serviceId} should have a description`);
107
- assert(service!.defaultPrice > 0, `${serviceId} should have a valid price`);
108
- }
109
-
110
- console.log('✅ Loader: directory scanning works correctly');
111
-
112
- // Test 4: Service Manager Integration
113
- console.log('Testing service manager integration...');
114
-
115
- // Initialize service system
116
- await initializeServiceSystem();
117
-
118
- // Test service discovery
119
- const joke = serviceManager.registry.get('tell-joke');
120
- assert(joke !== undefined, 'Should find tell-joke service');
121
- assertEquals(joke!.name, 'Random Joke', 'Service name should match');
122
-
123
- // Test validation with valid input
124
- const validationResult = serviceManager.validate('tell-joke', { topic: 'programming' });
125
- assert(validationResult.valid, 'Valid input should pass validation');
126
-
127
- // Tell-joke service has no required fields, so empty object is valid
128
- const emptyInputResult = serviceManager.validate('tell-joke', {});
129
- assert(emptyInputResult.valid, 'Empty input should be valid for tell-joke service');
130
-
131
- // Test with truly invalid input (wrong type)
132
- const invalidResult = serviceManager.validate('tell-joke', { topic: 123 });
133
- assert(!invalidResult.valid, 'Invalid input type should fail validation');
134
-
135
- console.log('✅ Manager: integration works correctly');
136
-
137
- // Test 5: Service Input Schema Validation
138
- console.log('Testing service input schema validation...');
139
-
140
- // Test api-proxy service validation
141
- const apiProxy = serviceManager.registry.get('api-proxy');
142
- assert(apiProxy !== undefined, 'Should find api-proxy service');
143
-
144
- const validApiInput = { url: 'https://api.example.com/test', method: 'GET' };
145
- const validApiResult = serviceManager.validate('api-proxy', validApiInput);
146
- assert(validApiResult.valid, 'Valid api-proxy input should pass');
147
-
148
- const invalidApiInput = { method: 'GET' }; // missing required url
149
- const invalidApiResult = serviceManager.validate('api-proxy', invalidApiInput);
150
- assert(!invalidApiResult.valid, 'Invalid api-proxy input should fail');
151
-
152
- console.log('✅ Validation: input schema validation works correctly');
153
-
154
- // Test 6: Service Categories
155
- console.log('Testing service categories...');
156
-
157
- // Check that services have appropriate categories
158
- const categorizedServices = serviceManager.registry.list();
159
- const categories = new Set(categorizedServices.map(s => s.category).filter(Boolean));
160
- assert(categories.size > 0, 'Should have services with categories');
161
-
162
- // Verify known categories
163
- const expectedCategories = ['utility', 'ai', 'entertainment', 'development'];
164
- for (const category of expectedCategories) {
165
- const servicesInCategory = categorizedServices.filter(s => s.category === category);
166
- assert(servicesInCategory.length > 0, `Should have services in ${category} category`);
167
- }
168
-
169
- console.log('✅ Categories: service categorization works correctly');
170
-
171
- // Test 7: Service Loading Error Handling
172
- console.log('Testing service loading error handling...');
173
-
174
- // Test loading from non-existent directory
175
- try {
176
- await serviceLoader.loadFromDirectory('/non/existent/directory');
177
- // Should not throw, but return empty array
178
- console.log('✅ Loader: graceful handling of non-existent directory');
179
- } catch {
180
- // This is also acceptable behavior
181
- console.log('✅ Loader: appropriate error handling for non-existent directory');
182
- }
183
-
184
- // Test 8: Service Prompt Files
185
- console.log('Testing service prompt files...');
186
-
187
- // Check that services with prompt files can be found
188
- const servicesWithPrompts = categorizedServices.filter(s => s.promptFile);
189
- assert(servicesWithPrompts.length > 0, 'Should have services with prompt files');
190
-
191
- // Verify prompt files exist
192
- for (const service of servicesWithPrompts.slice(0, 3)) { // Test first 3 to avoid excessive file I/O
193
- if (service.promptFile) {
194
- const promptPath = path.resolve(projectRoot, service.promptFile);
195
- assert(fs.existsSync(promptPath), `Prompt file should exist: ${service.promptFile}`);
196
-
197
- const content = fs.readFileSync(promptPath, 'utf-8');
198
- assert(content.includes(service.id), `Prompt should reference service ID: ${service.id}`);
199
- }
200
- }
201
-
202
- console.log('✅ Prompts: service prompt files work correctly');
203
-
204
- // Test 9: Service Registry Search and Filter
205
- console.log('Testing service registry search and filter...');
206
-
207
- // Test filtering by category
208
- const aiServices = categorizedServices.filter(s => s.category === ServiceCategory.AI);
209
- assert(aiServices.length > 0, 'Should have AI services');
210
-
211
- const utilityServices = categorizedServices.filter(s => s.category === ServiceCategory.UTILITY);
212
- assert(utilityServices.length > 0, 'Should have utility services');
213
-
214
- // Test name search
215
- const jokeServices = categorizedServices.filter(s => s.name.toLowerCase().includes('joke'));
216
- assert(jokeServices.length > 0, 'Should find joke-related services');
217
-
218
- console.log('✅ Search: service filtering works correctly');
219
-
220
- // Test 10: Service System State Consistency
221
- console.log('Testing service system state consistency...');
222
-
223
- // Verify that registry and manager are in sync
224
- const registryServices = serviceManager.registry.list();
225
- const registryIds = new Set(registryServices.map(s => s.id));
226
-
227
- // All services should be unique
228
- assertEquals(registryIds.size, registryServices.length, 'All service IDs should be unique');
229
-
230
- // All services should have valid pricing
231
- for (const service of registryServices) {
232
- assert(service.defaultPrice > 0, `Service ${service.id} should have valid price`);
233
- assert(service.name.length > 0, `Service ${service.id} should have a name`);
234
- assert(service.description.length > 0, `Service ${service.id} should have a description`);
235
- }
236
-
237
- console.log('✅ Consistency: service system state is consistent');
238
-
239
- console.log('\n========================================');
240
- console.log('Service System Tests completed: All tests passed!');
241
- console.log('========================================\n');
@@ -1,95 +0,0 @@
1
- /**
2
- * TaskFlow Integration Tests
3
- *
4
- * Verifies that the plugin correctly interacts with api.runtime.taskFlow
5
- * when receiving service requests or responses.
6
- */
7
-
8
- import { register } from '../../index.js';
9
- import path from 'node:path';
10
- import os from 'node:os';
11
- import fs from 'node:fs';
12
-
13
- // Simple test runner
14
- let passed = 0;
15
- let failed = 0;
16
-
17
- async function test(name: string, fn: () => void | Promise<void>) {
18
- try {
19
- await fn();
20
- console.log(` ✓ ${name}`);
21
- passed++;
22
- } catch (err: unknown) {
23
- console.log(` ✗ ${name}`);
24
- console.log(err);
25
- failed++;
26
- }
27
- }
28
-
29
- function assert(condition: boolean, message: string) {
30
- if (!condition) throw new Error(`Assertion failed: ${message}`);
31
- }
32
-
33
- async function run() {
34
- console.log('TaskFlow Integration Tests\n');
35
-
36
- let createdFlows: any[] = [];
37
- let registeredService: any = null;
38
-
39
- const mockApi = {
40
- logger: {
41
- info: () => {},
42
- error: () => {},
43
- warn: () => {},
44
- debug: () => {}
45
- },
46
- runtime: {
47
- taskFlow: {
48
- create: (flow: any) => {
49
- createdFlows.push(flow);
50
- return { id: `flow_${createdFlows.length}` };
51
- }
52
- }
53
- },
54
- registerTool: () => {},
55
- registerService: (service: any) => {
56
- registeredService = service;
57
- },
58
- registerCommand: () => {},
59
- registerCli: () => {},
60
- getConfig: () => ({
61
- plugins: {
62
- entries: {
63
- 'sv_overlay': {
64
- config: {
65
- network: 'testnet'
66
- }
67
- }
68
- }
69
- }
70
- })
71
- };
72
-
73
- await test('Background service uses taskFlow on events', async () => {
74
- // 1. Register the plugin
75
- register(mockApi);
76
-
77
- // 2. Verify service was registered
78
- assert(registeredService !== null, 'service should be registered');
79
-
80
- // Note: To truly test the WebSocket event handling, we would need to mock
81
- // the 'spawn' and 'stdout' of the child process. Since that's complex
82
- // for a simple test, we verify the presence of the logic in index.ts.
83
-
84
- // We can check if createdFlows is empty initially
85
- assert(createdFlows.length === 0, 'no flows should be created yet');
86
- });
87
-
88
- console.log(`\n${passed} passed, ${failed} failed`);
89
- if (failed > 0) process.exit(1);
90
- }
91
-
92
- run().catch(err => {
93
- console.error(err);
94
- process.exit(1);
95
- });