strray-ai 1.0.17 → 1.0.18

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.

Potentially problematic release.


This version of strray-ai might be problematic. Click here for more details.

Files changed (76) hide show
  1. package/opencode.json +1 -3
  2. package/package.json +2 -1
  3. package/scripts/postinstall.cjs +53 -0
  4. package/src/__tests__/agents/architect.test.ts +108 -0
  5. package/src/__tests__/agents/bug-triage-specialist.test.ts +246 -0
  6. package/src/__tests__/agents/code-reviewer.test.ts +242 -0
  7. package/src/__tests__/agents/enforcer.test.ts +179 -0
  8. package/src/__tests__/agents/index.test.ts +135 -0
  9. package/src/__tests__/agents/orchestrator.test.ts +228 -0
  10. package/src/__tests__/agents/refactorer.test.ts +248 -0
  11. package/src/__tests__/agents/security-auditor.test.ts +234 -0
  12. package/src/__tests__/agents/test-architect.test.ts +256 -0
  13. package/src/__tests__/agents/types.test.ts +210 -0
  14. package/src/__tests__/framework-enforcement-integration.test.ts +252 -0
  15. package/src/__tests__/framework-logger-persistence.test.ts +156 -0
  16. package/src/__tests__/integration/codex-enforcement-e2e.test.ts +195 -0
  17. package/src/__tests__/integration/codex-enforcement.test.ts +237 -0
  18. package/src/__tests__/integration/commit-batching-enforcement-integration.test.ts +343 -0
  19. package/src/__tests__/integration/context-providers-integration.test.ts +302 -0
  20. package/src/__tests__/integration/delegation-system.test.ts +263 -0
  21. package/src/__tests__/integration/e2e-framework-integration.test.ts +1524 -0
  22. package/src/__tests__/integration/framework-init.test.ts +327 -0
  23. package/src/__tests__/integration/json-codex-integration.test.ts +332 -0
  24. package/src/__tests__/integration/oh-my-opencode-integration.test.ts +240 -0
  25. package/src/__tests__/integration/orchestration-e2e.test.ts +176 -0
  26. package/src/__tests__/integration/orchestrator/basic-orchestrator.test.ts +53 -0
  27. package/src/__tests__/integration/orchestrator/concurrent-execution.test.ts +64 -0
  28. package/src/__tests__/integration/orchestrator/dependency-handling.test.ts +78 -0
  29. package/src/__tests__/integration/orchestrator-integration.test.ts.disabled +1279 -0
  30. package/src/__tests__/integration/postprocessor-integration.test.ts +64 -0
  31. package/src/__tests__/integration/security/security-integration.test.ts +160 -0
  32. package/src/__tests__/integration/server.test.ts +187 -0
  33. package/src/__tests__/integration/session-cleanup-validation.test.ts +612 -0
  34. package/src/__tests__/integration/session-lifecycle.test.ts +450 -0
  35. package/src/__tests__/integration/session-management.test.ts +168 -0
  36. package/src/__tests__/integration/session-monitoring-integration.test.ts +644 -0
  37. package/src/__tests__/integration/session-state-sharing.test.ts +601 -0
  38. package/src/__tests__/performance/enterprise-performance-tests.ts +1030 -0
  39. package/src/__tests__/performance/performance-system.test.ts +408 -0
  40. package/src/__tests__/plugins/marketplace-service.test.ts +1542 -0
  41. package/src/__tests__/plugins/marketplace-service.test.ts.disabled +1516 -0
  42. package/src/__tests__/postprocessor/escalation/EscalationEngine.test.ts +205 -0
  43. package/src/__tests__/postprocessor/success/SuccessHandler.test.ts +258 -0
  44. package/src/__tests__/setup.ts +220 -0
  45. package/src/__tests__/test-integration.ts +2 -0
  46. package/src/__tests__/test-processor.ts +1 -0
  47. package/src/__tests__/unit/agent-delegator.test.ts +949 -0
  48. package/src/__tests__/unit/analytics.test.ts +192 -0
  49. package/src/__tests__/unit/ast-code-parser.test.ts +342 -0
  50. package/src/__tests__/unit/benchmark.test.ts +201 -0
  51. package/src/__tests__/unit/blocked-test.test.ts +8 -0
  52. package/src/__tests__/unit/boot-orchestrator.test.ts +182 -0
  53. package/src/__tests__/unit/codebase-context-analyzer.test.ts +375 -0
  54. package/src/__tests__/unit/codex-injector.test.ts +282 -0
  55. package/src/__tests__/unit/codex-parser.test.ts +296 -0
  56. package/src/__tests__/unit/context-loader.test.ts +723 -0
  57. package/src/__tests__/unit/dependency-graph-builder.test.ts +531 -0
  58. package/src/__tests__/unit/monitoring.test.ts +115 -0
  59. package/src/__tests__/unit/orchestrator.test.ts +212 -0
  60. package/src/__tests__/unit/processor-activation.test.ts +878 -0
  61. package/src/__tests__/unit/rule-enforcer.test.ts +363 -0
  62. package/src/__tests__/unit/security/security-auditor.test.ts +226 -0
  63. package/src/__tests__/unit/security/security-hardener.test.ts +404 -0
  64. package/src/__tests__/unit/security/security-headers.test.ts +255 -0
  65. package/src/__tests__/unit/session-coordination-validator.test.ts +184 -0
  66. package/src/__tests__/unit/session-health-monitoring.test.ts +161 -0
  67. package/src/__tests__/unit/session-migration-logic.test.ts +153 -0
  68. package/src/__tests__/unit/session-migration-validator.test.ts +130 -0
  69. package/src/__tests__/unit/session-security-validator.test.ts +87 -0
  70. package/src/__tests__/unit/state-manager-persistence.test.ts +301 -0
  71. package/src/__tests__/unit/state-manager.test.ts +205 -0
  72. package/src/__tests__/utils/mock-framework.ts +392 -0
  73. package/src/__tests__/utils/mock-server.ts +72 -0
  74. package/src/__tests__/utils/test-data.ts +130 -0
  75. package/src/__tests__/utils/test-helpers.ts +640 -0
  76. package/src/__tests__/utils/test-utils.ts +241 -0
@@ -0,0 +1,302 @@
1
+ /**
2
+ * Integration tests for Context Providers Chain
3
+ * Tests the complete integration between CodebaseContextAnalyzer, ASTCodeParser, and DependencyGraphBuilder
4
+ */
5
+
6
+ import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
7
+ import { AgentDelegator } from "../../delegation/agent-delegator.js";
8
+ import { StringRayStateManager } from "../../state/state-manager.js";
9
+ import { frameworkLogger } from "../../framework-logger.js";
10
+
11
+ // Mock external dependencies
12
+ vi.mock("../../framework-logger.js");
13
+
14
+ describe("Context Providers Integration", () => {
15
+ let agentDelegator: AgentDelegator;
16
+ let stateManager: StringRayStateManager;
17
+
18
+ beforeEach(() => {
19
+ vi.clearAllMocks();
20
+ stateManager = new StringRayStateManager();
21
+ agentDelegator = new AgentDelegator(stateManager);
22
+ });
23
+
24
+ afterEach(() => {
25
+ vi.restoreAllMocks();
26
+ });
27
+
28
+ describe("context provider initialization", () => {
29
+ it("should initialize all context providers successfully", () => {
30
+ expect(agentDelegator).toBeDefined();
31
+ // The constructor should have initialized context providers without throwing
32
+ });
33
+
34
+ it("should handle ast-grep unavailability gracefully", () => {
35
+ // Even if ast-grep is not available, the system should still initialize
36
+ expect(agentDelegator).toBeDefined();
37
+ });
38
+
39
+ it.skip("should log context provider initialization status", () => {
40
+ const mockLogger = vi.mocked(frameworkLogger);
41
+
42
+ // Constructor should have called logger
43
+ expect(mockLogger.log).toHaveBeenCalledWith(
44
+ "agent-delegator",
45
+ "context-providers-initialized",
46
+ "success",
47
+ expect.any(Object),
48
+ );
49
+ });
50
+ });
51
+
52
+ describe("complexity analysis with context awareness", () => {
53
+ it("should enhance complexity analysis with context data", async () => {
54
+ const request = {
55
+ operation: "analyze-component",
56
+ description: "Analyze a React component with dependencies",
57
+ context: {
58
+ files: ["src/components/Button.tsx", "src/utils/helpers.ts"],
59
+ filePath: "src/components/Button.tsx",
60
+ operation: "refactor",
61
+ },
62
+ };
63
+
64
+ const result = await agentDelegator.analyzeDelegation(request);
65
+
66
+ expect(result.strategy).toBeDefined();
67
+ expect(result.complexity.score).toBeGreaterThanOrEqual(0);
68
+ expect(result.complexity.level).toBeDefined();
69
+ expect(result.agents).toBeDefined();
70
+ expect(result.agents.length).toBeGreaterThan(0);
71
+ });
72
+
73
+ it.skip("should use context-enhanced metrics for large codebases", async () => {
74
+ const request = {
75
+ operation: "refactor-large-component",
76
+ description: "Refactor a large component with many dependencies",
77
+ context: {
78
+ files: Array.from({ length: 100 }, (_, i) => `src/component${i}.tsx`),
79
+ filePath: "src/components/LargeComponent.tsx",
80
+ operation: "refactor",
81
+ },
82
+ };
83
+
84
+ const result = await agentDelegator.analyzeDelegation(request);
85
+
86
+ expect(result.complexity.level).toBe("enterprise");
87
+ expect(result.strategy).toBe("orchestrator-led");
88
+ expect(result.agents.length).toBeGreaterThan(2);
89
+ });
90
+
91
+ it("should fall back to basic metrics when context analysis fails", async () => {
92
+ // This test verifies that even if context providers have issues,
93
+ // the system continues to work with basic complexity analysis
94
+
95
+ const request = {
96
+ operation: "simple-function",
97
+ description: "Simple function that should work with basic analysis",
98
+ context: {
99
+ files: ["simple.ts"],
100
+ operation: "create",
101
+ },
102
+ };
103
+
104
+ const result = await agentDelegator.analyzeDelegation(request);
105
+
106
+ expect(result.strategy).toBeDefined();
107
+ expect(result.complexity.score).toBeGreaterThanOrEqual(0);
108
+ // Should still work even if context enhancement fails
109
+ });
110
+ });
111
+
112
+ describe("memory optimization integration", () => {
113
+ it("should respect memory limits during analysis", async () => {
114
+ const request = {
115
+ operation: "analyze-large-codebase",
116
+ description: "Analyze large codebase with memory constraints",
117
+ context: {
118
+ files: Array.from({ length: 200 }, (_, i) => `src/file${i}.ts`),
119
+ filePath: "src/main.ts",
120
+ operation: "analyze",
121
+ },
122
+ };
123
+
124
+ const result = await agentDelegator.analyzeDelegation(request);
125
+
126
+ expect(result).toBeDefined();
127
+ // Should complete analysis even with memory constraints
128
+ });
129
+
130
+ it("should cache analysis results appropriately", async () => {
131
+ const request1 = {
132
+ operation: "analyze-component",
133
+ description: "First analysis of component",
134
+ context: {
135
+ files: ["src/Button.tsx"],
136
+ filePath: "src/Button.tsx",
137
+ },
138
+ };
139
+
140
+ const request2 = {
141
+ operation: "analyze-component",
142
+ description: "Second analysis of same component",
143
+ context: {
144
+ files: ["src/Button.tsx"],
145
+ filePath: "src/Button.tsx",
146
+ },
147
+ };
148
+
149
+ await agentDelegator.analyzeDelegation(request1);
150
+ await agentDelegator.analyzeDelegation(request2);
151
+
152
+ // Both should complete successfully, potentially using cached results
153
+ expect(true).toBe(true);
154
+ });
155
+ });
156
+
157
+ describe("error handling and resilience", () => {
158
+ it("should handle context provider initialization failures", () => {
159
+ // The system should be resilient to context provider issues
160
+ // This is already tested by the constructor tests above
161
+ expect(agentDelegator).toBeDefined();
162
+ });
163
+
164
+ it("should continue operating with partial context data", async () => {
165
+ const request = {
166
+ operation: "analyze-with-limited-context",
167
+ description: "Analysis with minimal context data",
168
+ context: {
169
+ // Minimal context that might cause some providers to fail
170
+ files: ["unknown-file.xyz"],
171
+ operation: "unknown",
172
+ },
173
+ };
174
+
175
+ const result = await agentDelegator.analyzeDelegation(request);
176
+
177
+ // Should still produce a valid result
178
+ expect(result.strategy).toBeDefined();
179
+ expect(result.complexity.score).toBeGreaterThanOrEqual(0);
180
+ });
181
+
182
+ it("should log errors without crashing the analysis", async () => {
183
+ const mockLogger = vi.mocked(frameworkLogger);
184
+
185
+ const request = {
186
+ operation: "problematic-analysis",
187
+ description: "Analysis that might cause issues",
188
+ context: {
189
+ files: ["nonexistent-file.ts"],
190
+ filePath: "nonexistent-file.ts",
191
+ },
192
+ };
193
+
194
+ await agentDelegator.analyzeDelegation(request);
195
+
196
+ // Should have logged any errors but not thrown
197
+ expect(mockLogger.log).toHaveBeenCalled();
198
+ });
199
+ });
200
+
201
+ describe("performance validation", () => {
202
+ it("should complete analysis within reasonable time limits", async () => {
203
+ const request = {
204
+ operation: "performance-test",
205
+ description: "Test analysis performance",
206
+ context: {
207
+ files: ["src/test.ts"],
208
+ filePath: "src/test.ts",
209
+ operation: "create",
210
+ },
211
+ };
212
+
213
+ const startTime = Date.now();
214
+ const result = await agentDelegator.analyzeDelegation(request);
215
+ const duration = Date.now() - startTime;
216
+
217
+ expect(duration).toBeLessThan(5000); // Should complete within 5 seconds
218
+ expect(result).toBeDefined();
219
+ });
220
+
221
+ it("should handle concurrent analysis requests", async () => {
222
+ const requests = Array.from({ length: 5 }, (_, i) => ({
223
+ operation: `concurrent-test-${i}`,
224
+ description: `Concurrent analysis request ${i}`,
225
+ context: {
226
+ files: [`src/test${i}.ts`],
227
+ filePath: `src/test${i}.ts`,
228
+ operation: "create",
229
+ },
230
+ }));
231
+
232
+ const startTime = Date.now();
233
+ const results = await Promise.all(
234
+ requests.map((request) => agentDelegator.analyzeDelegation(request)),
235
+ );
236
+ const duration = Date.now() - startTime;
237
+
238
+ expect(results).toHaveLength(5);
239
+ results.forEach((result) => {
240
+ expect(result.strategy).toBeDefined();
241
+ expect(result.complexity.score).toBeGreaterThanOrEqual(0);
242
+ });
243
+
244
+ expect(duration).toBeLessThan(10000); // Should complete within 10 seconds for 5 concurrent requests
245
+ });
246
+ });
247
+
248
+ describe("rule enforcement integration", () => {
249
+ it("should apply complexity-based agent selection rules", async () => {
250
+ const simpleRequest = {
251
+ operation: "create-simple-component",
252
+ description: "Simple component creation",
253
+ context: {
254
+ files: ["src/SimpleButton.tsx"],
255
+ operation: "create",
256
+ },
257
+ };
258
+
259
+ const complexRequest = {
260
+ operation: "refactor-large-system",
261
+ description: "Complex system refactoring",
262
+ context: {
263
+ files: Array.from({ length: 100 }, (_, i) => `src/component${i}.tsx`),
264
+ operation: "refactor",
265
+ riskLevel: "critical" as const,
266
+ },
267
+ };
268
+
269
+ const simpleResult =
270
+ await agentDelegator.analyzeDelegation(simpleRequest);
271
+ const complexResult =
272
+ await agentDelegator.analyzeDelegation(complexRequest);
273
+
274
+ // Simple request should use fewer agents
275
+ expect(simpleResult.agents.length).toBeLessThanOrEqual(
276
+ complexResult.agents.length,
277
+ );
278
+ expect(simpleResult.strategy).not.toBe("orchestrator-led");
279
+
280
+ // Complex request should use more sophisticated strategy
281
+ expect(complexResult.strategy).toBe("orchestrator-led");
282
+ });
283
+
284
+ it("should enforce memory limits during analysis", async () => {
285
+ const largeRequest = {
286
+ operation: "analyze-massive-codebase",
287
+ description: "Analysis of very large codebase",
288
+ context: {
289
+ files: Array.from({ length: 1000 }, (_, i) => `src/file${i}.ts`),
290
+ filePath: "src/main.ts",
291
+ operation: "analyze",
292
+ },
293
+ };
294
+
295
+ const result = await agentDelegator.analyzeDelegation(largeRequest);
296
+
297
+ // Should complete analysis despite large input
298
+ expect(result).toBeDefined();
299
+ expect(result.complexity.score).toBeGreaterThanOrEqual(0);
300
+ });
301
+ });
302
+ });
@@ -0,0 +1,263 @@
1
+ /**
2
+ * StringRay AI v1.0.9 - Delegation System Integration Tests
3
+ *
4
+ * Tests the complete automatic multi-agent delegation system.
5
+ *
6
+ * @version 1.0.0
7
+ * @since 2026-01-07
8
+ */
9
+
10
+ import { describe, it, expect, beforeEach, vi } from "vitest";
11
+ import { StringRayStateManager } from "../../state/state-manager.js";
12
+ import {
13
+ createAgentDelegator,
14
+ createSessionCoordinator,
15
+ } from "../../delegation/index.js";
16
+
17
+ describe("StringRay Delegation System Integration", () => {
18
+ let stateManager: StringRayStateManager;
19
+ let agentDelegator: any;
20
+ let sessionCoordinator: any;
21
+
22
+ beforeEach(() => {
23
+ vi.clearAllMocks();
24
+ stateManager = new StringRayStateManager();
25
+ agentDelegator = createAgentDelegator(stateManager);
26
+ sessionCoordinator = createSessionCoordinator(stateManager);
27
+
28
+ // Register mock agents for testing
29
+ const mockAgent = {
30
+ execute: vi.fn().mockImplementation(async () => {
31
+ await new Promise((resolve) => setTimeout(resolve, 1)); // Small delay to ensure duration > 0
32
+ return { result: "success" };
33
+ }),
34
+ getCapabilities: vi
35
+ .fn()
36
+ .mockReturnValue({ name: "test-architect", performance: 0.8 }),
37
+ };
38
+ stateManager.set("agent:test-architect", mockAgent);
39
+ stateManager.set("agent:enforcer", mockAgent);
40
+ stateManager.set("agent:architect", mockAgent);
41
+ stateManager.set("agent:security-auditor", mockAgent);
42
+ });
43
+
44
+ describe("Session Management", () => {
45
+ it("should initialize session with proper metadata", () => {
46
+ const session = sessionCoordinator.initializeSession("test_session");
47
+
48
+ expect(session).toBeDefined();
49
+ expect(session.sessionId).toBe("test_session");
50
+ expect(session.createdAt).toBeInstanceOf(Date);
51
+ expect(session.agentCount).toBeGreaterThan(0);
52
+ });
53
+
54
+ it("should track session status correctly", () => {
55
+ sessionCoordinator.initializeSession("status_test");
56
+
57
+ const status = sessionCoordinator.getSessionStatus("status_test");
58
+ expect(status).toBeDefined();
59
+ expect(status.active).toBe(true);
60
+ expect(status.agentCount).toBeGreaterThan(0);
61
+ });
62
+
63
+ it("should cleanup session properly", () => {
64
+ sessionCoordinator.initializeSession("cleanup_test");
65
+ sessionCoordinator.cleanupSession("cleanup_test");
66
+
67
+ const status = sessionCoordinator.getSessionStatus("cleanup_test");
68
+ expect(status).toBeNull(); // Session should be completely removed after cleanup
69
+ });
70
+ });
71
+
72
+ describe("Complexity Analysis", () => {
73
+ it("should analyze simple operations correctly", async () => {
74
+ const request = {
75
+ operation: "format",
76
+ description: "Format a single file",
77
+ context: {
78
+ files: ["utils.ts"],
79
+ changeVolume: 10,
80
+ dependencies: 0,
81
+ riskLevel: "low" as const,
82
+ },
83
+ };
84
+
85
+ const delegation = await agentDelegator.analyzeDelegation(request);
86
+
87
+ expect(delegation.complexity.level).toBe("simple");
88
+ expect(delegation.strategy).toBe("single-agent");
89
+ expect(delegation.agents).toHaveLength(1);
90
+ });
91
+
92
+ it("should analyze complex operations correctly", async () => {
93
+ const request = {
94
+ operation: "refactor",
95
+ description: "Refactor complex authentication module",
96
+ context: {
97
+ files: ["auth.ts", "user.ts", "permissions.ts", "database.ts"],
98
+ changeVolume: 500,
99
+ dependencies: 8,
100
+ riskLevel: "high" as const,
101
+ },
102
+ };
103
+
104
+ const delegation = await agentDelegator.analyzeDelegation(request);
105
+
106
+ expect(delegation.complexity.level).toBe("complex");
107
+ expect(delegation.strategy).toBe("multi-agent");
108
+ expect(delegation.agents.length).toBeGreaterThan(1);
109
+ });
110
+ });
111
+
112
+ describe("Agent Coordination", () => {
113
+ it("should send and receive messages between agents", async () => {
114
+ const session = sessionCoordinator.initializeSession("msg_test");
115
+
116
+ await sessionCoordinator.sendMessage(
117
+ session.sessionId,
118
+ "architect",
119
+ "enforcer",
120
+ {
121
+ type: "design_review",
122
+ data: "Please review the architectural changes",
123
+ },
124
+ );
125
+
126
+ const messages = sessionCoordinator.receiveMessages(
127
+ session.sessionId,
128
+ "enforcer",
129
+ );
130
+ expect(messages).toHaveLength(1);
131
+ expect(messages[0].message.type).toBe("design_review");
132
+ });
133
+
134
+ it("should share and retrieve context data", async () => {
135
+ const session = sessionCoordinator.initializeSession("context_test");
136
+
137
+ sessionCoordinator.shareContext(
138
+ session.sessionId,
139
+ "design_decisions",
140
+ {
141
+ pattern: "observer",
142
+ reasoning: "For loose coupling between auth components",
143
+ },
144
+ "architect",
145
+ );
146
+
147
+ const sharedData = sessionCoordinator.getSharedContext(
148
+ session.sessionId,
149
+ "design_decisions",
150
+ );
151
+ expect(sharedData).toBeDefined();
152
+ expect(sharedData!.pattern).toBe("observer");
153
+ expect(sharedData!.sharedBy).toBe("architect");
154
+ });
155
+ });
156
+
157
+ describe("Conflict Resolution", () => {
158
+ it("should resolve conflicts using majority vote", async () => {
159
+ const session = sessionCoordinator.initializeSession("conflict_test");
160
+
161
+ // Simulate conflicting recommendations
162
+ sessionCoordinator.shareContext(
163
+ session.sessionId,
164
+ "recommendation",
165
+ "Option A",
166
+ "architect",
167
+ );
168
+ sessionCoordinator.shareContext(
169
+ session.sessionId,
170
+ "recommendation",
171
+ "Option A",
172
+ "enforcer",
173
+ );
174
+ sessionCoordinator.shareContext(
175
+ session.sessionId,
176
+ "recommendation",
177
+ "Option B",
178
+ "refactorer",
179
+ );
180
+
181
+ const resolved = sessionCoordinator.resolveConflict(
182
+ session.sessionId,
183
+ "recommendation",
184
+ "majority_vote",
185
+ );
186
+ expect(resolved).toBe("Option A");
187
+ });
188
+
189
+ it("should resolve conflicts using expert priority", async () => {
190
+ const session = sessionCoordinator.initializeSession("expert_test");
191
+
192
+ sessionCoordinator.shareContext(
193
+ session.sessionId,
194
+ "security_review",
195
+ "Approved",
196
+ "security-auditor",
197
+ );
198
+ sessionCoordinator.shareContext(
199
+ session.sessionId,
200
+ "security_review",
201
+ "Rejected",
202
+ "architect",
203
+ );
204
+
205
+ const resolved = sessionCoordinator.resolveConflict(
206
+ session.sessionId,
207
+ "security_review",
208
+ "expert_priority",
209
+ );
210
+ expect(resolved).toBe("Approved"); // Security expert takes priority
211
+ });
212
+ });
213
+
214
+ describe("Performance and Monitoring", () => {
215
+ it("should track delegation performance metrics", async () => {
216
+ const request = {
217
+ operation: "test",
218
+ description: "Performance test",
219
+ context: {
220
+ files: ["test.ts"],
221
+ changeVolume: 50,
222
+ dependencies: 2,
223
+ riskLevel: "medium" as const,
224
+ },
225
+ };
226
+
227
+ const startTime = Date.now();
228
+
229
+ // Analyze and then execute the delegation to generate performance metrics
230
+ const delegation = await agentDelegator.analyzeDelegation(request);
231
+ await agentDelegator.executeDelegation(delegation, request);
232
+
233
+ const endTime = Date.now();
234
+
235
+ const metrics = agentDelegator.getPerformanceMetrics();
236
+ expect(metrics.totalDelegations).toBeGreaterThan(0);
237
+ expect(metrics.averageResponseTime).toBeGreaterThan(0);
238
+ expect(endTime - startTime).toBeLessThan(2000); // Should complete within reasonable time
239
+ });
240
+
241
+ it("should maintain session performance under load", () => {
242
+ // Create multiple sessions
243
+ for (let i = 0; i < 10; i++) {
244
+ sessionCoordinator.initializeSession(`perf_test_${i}`);
245
+ }
246
+
247
+ // All sessions should be active
248
+ for (let i = 0; i < 10; i++) {
249
+ const status = sessionCoordinator.getSessionStatus(`perf_test_${i}`);
250
+ expect(status.active).toBe(true);
251
+ }
252
+
253
+ // Cleanup should work efficiently
254
+ const cleanupStart = Date.now();
255
+ for (let i = 0; i < 10; i++) {
256
+ sessionCoordinator.cleanupSession(`perf_test_${i}`);
257
+ }
258
+ const cleanupTime = Date.now() - cleanupStart;
259
+
260
+ expect(cleanupTime).toBeLessThan(100); // Should cleanup quickly
261
+ });
262
+ });
263
+ });