flock-core 0.5.0b71__py3-none-any.whl → 0.5.1__py3-none-any.whl

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 flock-core might be problematic. Click here for more details.

Files changed (65) hide show
  1. flock/agent.py +39 -1
  2. flock/artifacts.py +17 -10
  3. flock/cli.py +1 -1
  4. flock/dashboard/__init__.py +2 -0
  5. flock/dashboard/collector.py +282 -6
  6. flock/dashboard/events.py +6 -0
  7. flock/dashboard/graph_builder.py +563 -0
  8. flock/dashboard/launcher.py +11 -6
  9. flock/dashboard/models/__init__.py +1 -0
  10. flock/dashboard/models/graph.py +156 -0
  11. flock/dashboard/service.py +175 -14
  12. flock/dashboard/static_v2/assets/index-DFRnI_mt.js +111 -0
  13. flock/dashboard/static_v2/assets/index-fPLNdmp1.css +1 -0
  14. flock/dashboard/static_v2/index.html +13 -0
  15. flock/dashboard/websocket.py +2 -2
  16. flock/engines/dspy_engine.py +294 -20
  17. flock/frontend/README.md +6 -6
  18. flock/frontend/src/App.tsx +23 -31
  19. flock/frontend/src/__tests__/integration/graph-snapshot.test.tsx +647 -0
  20. flock/frontend/src/components/details/DetailWindowContainer.tsx +13 -17
  21. flock/frontend/src/components/details/MessageDetailWindow.tsx +439 -0
  22. flock/frontend/src/components/details/MessageHistoryTab.tsx +128 -53
  23. flock/frontend/src/components/details/RunStatusTab.tsx +79 -38
  24. flock/frontend/src/components/graph/AgentNode.test.tsx +3 -1
  25. flock/frontend/src/components/graph/AgentNode.tsx +8 -6
  26. flock/frontend/src/components/graph/GraphCanvas.tsx +13 -8
  27. flock/frontend/src/components/graph/MessageNode.test.tsx +3 -1
  28. flock/frontend/src/components/graph/MessageNode.tsx +16 -3
  29. flock/frontend/src/components/layout/DashboardLayout.tsx +12 -9
  30. flock/frontend/src/components/modules/HistoricalArtifactsModule.tsx +4 -14
  31. flock/frontend/src/components/modules/ModuleRegistry.ts +5 -3
  32. flock/frontend/src/hooks/useModules.ts +12 -4
  33. flock/frontend/src/hooks/usePersistence.ts +5 -3
  34. flock/frontend/src/services/api.ts +3 -19
  35. flock/frontend/src/services/graphService.test.ts +330 -0
  36. flock/frontend/src/services/graphService.ts +75 -0
  37. flock/frontend/src/services/websocket.ts +104 -268
  38. flock/frontend/src/store/filterStore.test.ts +89 -1
  39. flock/frontend/src/store/filterStore.ts +38 -16
  40. flock/frontend/src/store/graphStore.test.ts +538 -173
  41. flock/frontend/src/store/graphStore.ts +374 -465
  42. flock/frontend/src/store/moduleStore.ts +51 -33
  43. flock/frontend/src/store/uiStore.ts +23 -11
  44. flock/frontend/src/types/graph.ts +77 -44
  45. flock/frontend/src/utils/mockData.ts +16 -3
  46. flock/frontend/vite.config.ts +2 -2
  47. flock/orchestrator.py +27 -7
  48. flock/patches/__init__.py +5 -0
  49. flock/patches/dspy_streaming_patch.py +82 -0
  50. flock/service.py +2 -2
  51. flock/store.py +169 -4
  52. flock/themes/darkmatrix.toml +2 -2
  53. flock/themes/deep.toml +2 -2
  54. flock/themes/neopolitan.toml +4 -4
  55. {flock_core-0.5.0b71.dist-info → flock_core-0.5.1.dist-info}/METADATA +20 -13
  56. {flock_core-0.5.0b71.dist-info → flock_core-0.5.1.dist-info}/RECORD +59 -53
  57. flock/frontend/src/__tests__/e2e/critical-scenarios.test.tsx +0 -586
  58. flock/frontend/src/__tests__/integration/filtering-e2e.test.tsx +0 -391
  59. flock/frontend/src/__tests__/integration/graph-rendering.test.tsx +0 -640
  60. flock/frontend/src/services/websocket.test.ts +0 -595
  61. flock/frontend/src/utils/transforms.test.ts +0 -860
  62. flock/frontend/src/utils/transforms.ts +0 -323
  63. {flock_core-0.5.0b71.dist-info → flock_core-0.5.1.dist-info}/WHEEL +0 -0
  64. {flock_core-0.5.0b71.dist-info → flock_core-0.5.1.dist-info}/entry_points.txt +0 -0
  65. {flock_core-0.5.0b71.dist-info → flock_core-0.5.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,640 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { render, screen, waitFor } from '@testing-library/react';
3
- import { ReactFlowProvider } from '@xyflow/react';
4
- import { useGraphStore } from '../../store/graphStore';
5
- import { useUIStore } from '../../store/uiStore';
6
- import { Agent, Message } from '../../types/graph';
7
-
8
- /**
9
- * Phase 4: Graph Visualization & Dual Views - Integration Tests
10
- *
11
- * Tests full graph rendering for both Agent View and Blackboard View modes.
12
- * Validates mode toggling performance and WebSocket event integration.
13
- *
14
- * SPECIFICATION: docs/specs/003-real-time-dashboard/PLAN.md Phase 4
15
- * REQUIREMENTS:
16
- * - Agent View renders correctly (agents as nodes, message flow edges)
17
- * - Blackboard View renders correctly (artifacts as nodes, transformation edges)
18
- * - Mode toggle switches between views within 100ms
19
- * - Graph updates on new WebSocket events
20
- */
21
-
22
- // Mock GraphCanvas component (to be implemented)
23
- const MockGraphCanvas = () => {
24
- const nodes = useGraphStore((state) => state.nodes);
25
- const edges = useGraphStore((state) => state.edges);
26
- const mode = useUIStore((state) => state.mode);
27
-
28
- return (
29
- <div data-testid="graph-canvas">
30
- <div data-testid="mode-indicator">{mode}</div>
31
- <div data-testid="node-count">{nodes.length}</div>
32
- <div data-testid="edge-count">{edges.length}</div>
33
- {nodes.map((node) => (
34
- <div key={node.id} data-testid={`node-${node.id}`} data-type={node.type}>
35
- {node.type === 'agent' && <span>{(node.data as any).name}</span>}
36
- {node.type === 'message' && <span>{(node.data as any).artifactType}</span>}
37
- </div>
38
- ))}
39
- {edges.map((edge) => (
40
- <div key={edge.id} data-testid={`edge-${edge.id}`}>
41
- {edge.source} → {edge.target}
42
- </div>
43
- ))}
44
- </div>
45
- );
46
- };
47
-
48
- describe('Graph Rendering Integration', () => {
49
- beforeEach(() => {
50
- // Reset stores before each test
51
- useGraphStore.setState({
52
- agents: new Map(),
53
- messages: new Map(),
54
- events: [],
55
- nodes: [],
56
- edges: [],
57
- runs: new Map(), // Phase 11: Reset runs map
58
- consumptions: new Map(), // Phase 11: Reset consumptions map
59
- });
60
-
61
- useUIStore.setState({
62
- mode: 'agent',
63
- });
64
- });
65
-
66
- describe('Agent View Rendering', () => {
67
- it('should render agents as nodes in Agent View', async () => {
68
- const agents: Agent[] = [
69
- {
70
- id: 'movie-agent',
71
- name: 'movie-agent',
72
- status: 'idle',
73
- subscriptions: [],
74
- lastActive: Date.now(),
75
- sentCount: 2,
76
- recvCount: 0,
77
- position: { x: 100, y: 100 },
78
- },
79
- {
80
- id: 'tagline-agent',
81
- name: 'tagline-agent',
82
- status: 'running',
83
- subscriptions: ['Movie'],
84
- lastActive: Date.now(),
85
- sentCount: 1,
86
- recvCount: 2,
87
- position: { x: 300, y: 100 },
88
- },
89
- {
90
- id: 'summary-agent',
91
- name: 'summary-agent',
92
- status: 'idle',
93
- subscriptions: ['Movie'],
94
- lastActive: Date.now(),
95
- sentCount: 0,
96
- recvCount: 2,
97
- position: { x: 500, y: 100 },
98
- },
99
- ];
100
-
101
- useGraphStore.getState().batchUpdate({ agents });
102
- useGraphStore.getState().generateAgentViewGraph();
103
-
104
- render(
105
- <ReactFlowProvider>
106
- <MockGraphCanvas />
107
- </ReactFlowProvider>
108
- );
109
-
110
- await waitFor(() => {
111
- expect(screen.getByTestId('mode-indicator')).toHaveTextContent('agent');
112
- expect(screen.getByTestId('node-count')).toHaveTextContent('3');
113
-
114
- // Verify all agent nodes are rendered
115
- expect(screen.getByTestId('node-movie-agent')).toBeInTheDocument();
116
- expect(screen.getByTestId('node-tagline-agent')).toBeInTheDocument();
117
- expect(screen.getByTestId('node-summary-agent')).toBeInTheDocument();
118
-
119
- // Verify node types
120
- expect(screen.getByTestId('node-movie-agent')).toHaveAttribute('data-type', 'agent');
121
- expect(screen.getByTestId('node-tagline-agent')).toHaveAttribute('data-type', 'agent');
122
- });
123
- });
124
-
125
- it('should render message flow edges in Agent View', async () => {
126
- const agents: Agent[] = [
127
- {
128
- id: 'movie-agent',
129
- name: 'movie-agent',
130
- status: 'idle',
131
- subscriptions: [],
132
- lastActive: Date.now(),
133
- sentCount: 2,
134
- recvCount: 0,
135
- },
136
- {
137
- id: 'tagline-agent',
138
- name: 'tagline-agent',
139
- status: 'idle',
140
- subscriptions: ['Movie'],
141
- lastActive: Date.now(),
142
- sentCount: 0,
143
- recvCount: 2,
144
- },
145
- ];
146
-
147
- const messages: Message[] = [
148
- {
149
- id: 'msg-1',
150
- type: 'Movie',
151
- payload: { title: 'Inception' },
152
- timestamp: Date.now(),
153
- correlationId: 'corr-1',
154
- producedBy: 'movie-agent',
155
- },
156
- {
157
- id: 'msg-2',
158
- type: 'Movie',
159
- payload: { title: 'Interstellar' },
160
- timestamp: Date.now(),
161
- correlationId: 'corr-2',
162
- producedBy: 'movie-agent',
163
- },
164
- ];
165
-
166
- useGraphStore.getState().batchUpdate({ agents, messages });
167
- // Phase 11 fix: Record consumption to populate consumed_by field
168
- useGraphStore.getState().recordConsumption(['msg-1', 'msg-2'], 'tagline-agent');
169
- useGraphStore.getState().generateAgentViewGraph();
170
-
171
- render(
172
- <ReactFlowProvider>
173
- <MockGraphCanvas />
174
- </ReactFlowProvider>
175
- );
176
-
177
- await waitFor(() => {
178
- expect(screen.getByTestId('node-count')).toHaveTextContent('2');
179
- expect(screen.getByTestId('edge-count')).not.toHaveTextContent('0');
180
-
181
- // Verify edge exists between movie-agent and tagline-agent
182
- const edges = useGraphStore.getState().edges;
183
- const edge = edges.find(
184
- (e) => e.source === 'movie-agent' && e.target === 'tagline-agent'
185
- );
186
- expect(edge).toBeDefined();
187
- expect(edge?.label).toContain('Movie');
188
- expect(edge?.label).toContain('2'); // Count of messages
189
- });
190
- });
191
-
192
- it('should display correct message counts on edges', async () => {
193
- const agents: Agent[] = [
194
- {
195
- id: 'producer',
196
- name: 'producer',
197
- status: 'idle',
198
- subscriptions: [],
199
- lastActive: Date.now(),
200
- sentCount: 5,
201
- recvCount: 0,
202
- },
203
- {
204
- id: 'consumer',
205
- name: 'consumer',
206
- status: 'idle',
207
- subscriptions: ['DataType'],
208
- lastActive: Date.now(),
209
- sentCount: 0,
210
- recvCount: 5,
211
- },
212
- ];
213
-
214
- const messages: Message[] = Array.from({ length: 5 }, (_, i) => ({
215
- id: `msg-${i}`,
216
- type: 'DataType',
217
- payload: { index: i },
218
- timestamp: Date.now() + i,
219
- correlationId: `corr-${i}`,
220
- producedBy: 'producer',
221
- }));
222
-
223
- useGraphStore.getState().batchUpdate({ agents, messages });
224
- // Phase 11 fix: Record consumption to populate consumed_by field
225
- useGraphStore.getState().recordConsumption(['msg-0', 'msg-1', 'msg-2', 'msg-3', 'msg-4'], 'consumer');
226
- useGraphStore.getState().generateAgentViewGraph();
227
-
228
- render(
229
- <ReactFlowProvider>
230
- <MockGraphCanvas />
231
- </ReactFlowProvider>
232
- );
233
-
234
- await waitFor(() => {
235
- const edges = useGraphStore.getState().edges;
236
- expect(edges).toHaveLength(1);
237
-
238
- const edge = edges[0];
239
- expect(edge).toBeDefined();
240
- expect(edge?.label).toBe('DataType (5)');
241
- expect(edge?.data?.messageCount).toBe(5);
242
- expect(edge?.data?.artifactIds).toHaveLength(5);
243
- });
244
- });
245
- });
246
-
247
- describe('Blackboard View Rendering', () => {
248
- it('should render artifacts as nodes in Blackboard View', async () => {
249
- const messages: Message[] = [
250
- {
251
- id: 'msg-1',
252
- type: 'Movie',
253
- payload: { title: 'Inception' },
254
- timestamp: Date.now(),
255
- correlationId: 'corr-1',
256
- producedBy: 'movie-agent',
257
- },
258
- {
259
- id: 'msg-2',
260
- type: 'Tagline',
261
- payload: { text: 'Dream within a dream' },
262
- timestamp: Date.now(),
263
- correlationId: 'corr-1',
264
- producedBy: 'tagline-agent',
265
- },
266
- {
267
- id: 'msg-3',
268
- type: 'Summary',
269
- payload: { text: 'A sci-fi thriller' },
270
- timestamp: Date.now(),
271
- correlationId: 'corr-1',
272
- producedBy: 'summary-agent',
273
- },
274
- ];
275
-
276
- useGraphStore.getState().batchUpdate({ messages });
277
- useGraphStore.getState().generateBlackboardViewGraph();
278
- useUIStore.setState({ mode: 'blackboard' });
279
-
280
- render(
281
- <ReactFlowProvider>
282
- <MockGraphCanvas />
283
- </ReactFlowProvider>
284
- );
285
-
286
- await waitFor(() => {
287
- expect(screen.getByTestId('mode-indicator')).toHaveTextContent('blackboard');
288
- expect(screen.getByTestId('node-count')).toHaveTextContent('3');
289
-
290
- // Verify all message nodes are rendered
291
- expect(screen.getByTestId('node-msg-1')).toBeInTheDocument();
292
- expect(screen.getByTestId('node-msg-2')).toBeInTheDocument();
293
- expect(screen.getByTestId('node-msg-3')).toBeInTheDocument();
294
-
295
- // Verify node types
296
- expect(screen.getByTestId('node-msg-1')).toHaveAttribute('data-type', 'message');
297
- });
298
- });
299
-
300
- it('should render transformation edges in Blackboard View', async () => {
301
- // Note: This test will need actual transformation edge logic
302
- // For now, we test the basic structure
303
-
304
- const messages: Message[] = [
305
- {
306
- id: 'msg-1',
307
- type: 'Movie',
308
- payload: { title: 'Inception' },
309
- timestamp: Date.now(),
310
- correlationId: 'corr-1',
311
- producedBy: 'movie-agent',
312
- },
313
- {
314
- id: 'msg-2',
315
- type: 'Tagline',
316
- payload: { text: 'Dream within a dream' },
317
- timestamp: Date.now(),
318
- correlationId: 'corr-1',
319
- producedBy: 'tagline-agent',
320
- },
321
- ];
322
-
323
- useGraphStore.getState().batchUpdate({ messages });
324
- useGraphStore.getState().generateBlackboardViewGraph();
325
- useUIStore.setState({ mode: 'blackboard' });
326
-
327
- render(
328
- <ReactFlowProvider>
329
- <MockGraphCanvas />
330
- </ReactFlowProvider>
331
- );
332
-
333
- await waitFor(() => {
334
- expect(screen.getByTestId('mode-indicator')).toHaveTextContent('blackboard');
335
- expect(screen.getByTestId('node-count')).toHaveTextContent('2');
336
-
337
- // Currently generateBlackboardViewGraph doesn't create edges
338
- // This will be implemented with transforms.ts
339
- const edges = useGraphStore.getState().edges;
340
- expect(edges).toHaveLength(0); // Will change after implementation
341
- });
342
- });
343
-
344
- it('should display artifact types correctly', async () => {
345
- const messages: Message[] = [
346
- {
347
- id: 'msg-1',
348
- type: 'Movie',
349
- payload: { title: 'Inception', year: 2010 },
350
- timestamp: Date.now(),
351
- correlationId: 'corr-1',
352
- producedBy: 'movie-agent',
353
- },
354
- ];
355
-
356
- useGraphStore.getState().batchUpdate({ messages });
357
- useGraphStore.getState().generateBlackboardViewGraph();
358
- useUIStore.setState({ mode: 'blackboard' });
359
-
360
- render(
361
- <ReactFlowProvider>
362
- <MockGraphCanvas />
363
- </ReactFlowProvider>
364
- );
365
-
366
- await waitFor(() => {
367
- const nodes = useGraphStore.getState().nodes;
368
- expect(nodes).toHaveLength(1);
369
- expect(nodes[0]).toBeDefined();
370
- expect((nodes[0]?.data as any).artifactType).toBe('Movie');
371
- expect(screen.getByText('Movie')).toBeInTheDocument();
372
- });
373
- });
374
- });
375
-
376
- describe('Mode Toggle Performance', () => {
377
- it('should switch between views within 100ms (REQUIREMENT)', async () => {
378
- // Setup both agent and message data
379
- const agents: Agent[] = [
380
- {
381
- id: 'agent-1',
382
- name: 'agent-1',
383
- status: 'idle',
384
- subscriptions: [],
385
- lastActive: Date.now(),
386
- sentCount: 1,
387
- recvCount: 0,
388
- },
389
- ];
390
-
391
- const messages: Message[] = [
392
- {
393
- id: 'msg-1',
394
- type: 'TestType',
395
- payload: {},
396
- timestamp: Date.now(),
397
- correlationId: 'corr-1',
398
- producedBy: 'agent-1',
399
- },
400
- ];
401
-
402
- useGraphStore.getState().batchUpdate({ agents, messages });
403
-
404
- // Measure Agent View generation
405
- const agentStartTime = performance.now();
406
- useGraphStore.getState().generateAgentViewGraph();
407
- const agentEndTime = performance.now();
408
- const agentDuration = agentEndTime - agentStartTime;
409
-
410
- expect(agentDuration).toBeLessThan(100); // REQUIREMENT
411
-
412
- // Measure Blackboard View generation
413
- const blackboardStartTime = performance.now();
414
- useGraphStore.getState().generateBlackboardViewGraph();
415
- const blackboardEndTime = performance.now();
416
- const blackboardDuration = blackboardEndTime - blackboardStartTime;
417
-
418
- expect(blackboardDuration).toBeLessThan(100); // REQUIREMENT
419
-
420
- // Verify both views generated correctly
421
- const agentNodes = useGraphStore.getState().nodes;
422
- expect(agentNodes.length).toBeGreaterThan(0);
423
- });
424
-
425
- it('should toggle mode quickly with UI store update', async () => {
426
- const startMode = useUIStore.getState().mode;
427
- expect(startMode).toBe('agent');
428
-
429
- const startTime = performance.now();
430
- useUIStore.getState().setMode('blackboard');
431
- const endTime = performance.now();
432
- const duration = endTime - startTime;
433
-
434
- expect(duration).toBeLessThan(10); // Mode toggle should be instant
435
- expect(useUIStore.getState().mode).toBe('blackboard');
436
-
437
- // Toggle back
438
- useUIStore.getState().setMode('agent');
439
- expect(useUIStore.getState().mode).toBe('agent');
440
- });
441
-
442
- it('should handle rapid mode toggling', async () => {
443
- const agents: Agent[] = [
444
- {
445
- id: 'agent-1',
446
- name: 'agent-1',
447
- status: 'idle',
448
- subscriptions: [],
449
- lastActive: Date.now(),
450
- sentCount: 0,
451
- recvCount: 0,
452
- },
453
- ];
454
-
455
- useGraphStore.getState().batchUpdate({ agents });
456
-
457
- // Rapidly toggle modes
458
- const iterations = 10;
459
- const startTime = performance.now();
460
-
461
- for (let i = 0; i < iterations; i++) {
462
- const newMode = i % 2 === 0 ? 'blackboard' : 'agent';
463
- useUIStore.getState().setMode(newMode);
464
-
465
- if (useUIStore.getState().mode === 'agent') {
466
- useGraphStore.getState().generateAgentViewGraph();
467
- } else {
468
- useGraphStore.getState().generateBlackboardViewGraph();
469
- }
470
- }
471
-
472
- const endTime = performance.now();
473
- const totalDuration = endTime - startTime;
474
- const avgDuration = totalDuration / iterations;
475
-
476
- expect(avgDuration).toBeLessThan(100); // Average should be under 100ms
477
- });
478
- });
479
-
480
- describe('Graph Updates on WebSocket Events', () => {
481
- it('should update graph when new agent is added', async () => {
482
- useGraphStore.getState().generateAgentViewGraph();
483
-
484
- render(
485
- <ReactFlowProvider>
486
- <MockGraphCanvas />
487
- </ReactFlowProvider>
488
- );
489
-
490
- expect(screen.getByTestId('node-count')).toHaveTextContent('0');
491
-
492
- // Simulate WebSocket event adding an agent
493
- const newAgent: Agent = {
494
- id: 'new-agent',
495
- name: 'new-agent',
496
- status: 'running',
497
- subscriptions: ['TestType'],
498
- lastActive: Date.now(),
499
- sentCount: 0,
500
- recvCount: 0,
501
- };
502
-
503
- useGraphStore.getState().addAgent(newAgent);
504
- useGraphStore.getState().generateAgentViewGraph();
505
-
506
- await waitFor(() => {
507
- expect(screen.getByTestId('node-count')).toHaveTextContent('1');
508
- expect(screen.getByTestId('node-new-agent')).toBeInTheDocument();
509
- });
510
- });
511
-
512
- it('should update graph when new message is published', async () => {
513
- const agents: Agent[] = [
514
- {
515
- id: 'producer',
516
- name: 'producer',
517
- status: 'idle',
518
- subscriptions: [],
519
- lastActive: Date.now(),
520
- sentCount: 0,
521
- recvCount: 0,
522
- },
523
- {
524
- id: 'consumer',
525
- name: 'consumer',
526
- status: 'idle',
527
- subscriptions: ['TestType'],
528
- lastActive: Date.now(),
529
- sentCount: 0,
530
- recvCount: 0,
531
- },
532
- ];
533
-
534
- useGraphStore.getState().batchUpdate({ agents });
535
- useGraphStore.getState().generateAgentViewGraph();
536
-
537
- render(
538
- <ReactFlowProvider>
539
- <MockGraphCanvas />
540
- </ReactFlowProvider>
541
- );
542
-
543
- const initialEdgeCount = useGraphStore.getState().edges.length;
544
-
545
- // Simulate WebSocket event publishing a message
546
- const newMessage: Message = {
547
- id: 'new-msg',
548
- type: 'TestType',
549
- payload: { data: 'test' },
550
- timestamp: Date.now(),
551
- correlationId: 'corr-1',
552
- producedBy: 'producer',
553
- };
554
-
555
- useGraphStore.getState().addMessage(newMessage);
556
- // Phase 11 fix: Record consumption to create edge
557
- useGraphStore.getState().recordConsumption(['new-msg'], 'consumer');
558
- useGraphStore.getState().generateAgentViewGraph();
559
-
560
- await waitFor(() => {
561
- const newEdgeCount = useGraphStore.getState().edges.length;
562
- expect(newEdgeCount).toBeGreaterThan(initialEdgeCount);
563
- });
564
- });
565
-
566
- it('should handle incremental updates efficiently', async () => {
567
- const initialAgents: Agent[] = Array.from({ length: 5 }, (_, i) => ({
568
- id: `agent-${i}`,
569
- name: `agent-${i}`,
570
- status: 'idle' as const,
571
- subscriptions: [],
572
- lastActive: Date.now(),
573
- sentCount: 0,
574
- recvCount: 0,
575
- }));
576
-
577
- useGraphStore.getState().batchUpdate({ agents: initialAgents });
578
- useGraphStore.getState().generateAgentViewGraph();
579
-
580
- // Measure incremental update performance
581
- const startTime = performance.now();
582
-
583
- const newAgent: Agent = {
584
- id: 'agent-new',
585
- name: 'agent-new',
586
- status: 'running',
587
- subscriptions: [],
588
- lastActive: Date.now(),
589
- sentCount: 0,
590
- recvCount: 0,
591
- };
592
-
593
- useGraphStore.getState().addAgent(newAgent);
594
- useGraphStore.getState().generateAgentViewGraph();
595
-
596
- const endTime = performance.now();
597
- const duration = endTime - startTime;
598
-
599
- // Incremental update should be very fast (<50ms)
600
- expect(duration).toBeLessThan(50);
601
-
602
- const nodes = useGraphStore.getState().nodes;
603
- expect(nodes).toHaveLength(6);
604
- });
605
- });
606
-
607
- describe('Empty States', () => {
608
- it('should render empty Agent View gracefully', async () => {
609
- useGraphStore.getState().generateAgentViewGraph();
610
-
611
- render(
612
- <ReactFlowProvider>
613
- <MockGraphCanvas />
614
- </ReactFlowProvider>
615
- );
616
-
617
- await waitFor(() => {
618
- expect(screen.getByTestId('node-count')).toHaveTextContent('0');
619
- expect(screen.getByTestId('edge-count')).toHaveTextContent('0');
620
- });
621
- });
622
-
623
- it('should render empty Blackboard View gracefully', async () => {
624
- useGraphStore.getState().generateBlackboardViewGraph();
625
- useUIStore.setState({ mode: 'blackboard' });
626
-
627
- render(
628
- <ReactFlowProvider>
629
- <MockGraphCanvas />
630
- </ReactFlowProvider>
631
- );
632
-
633
- await waitFor(() => {
634
- expect(screen.getByTestId('mode-indicator')).toHaveTextContent('blackboard');
635
- expect(screen.getByTestId('node-count')).toHaveTextContent('0');
636
- expect(screen.getByTestId('edge-count')).toHaveTextContent('0');
637
- });
638
- });
639
- });
640
- });