agentdb 2.0.0-alpha.1 → 2.0.0-alpha.2

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 (208) hide show
  1. package/dist/agentdb.min.js +4 -4
  2. package/dist/simulation/cli.js +0 -0
  3. package/dist/src/cli/lib/config-manager.d.ts.map +1 -1
  4. package/dist/src/cli/lib/config-manager.js.map +1 -1
  5. package/dist/src/cli/lib/history-tracker.d.ts.map +1 -1
  6. package/dist/src/cli/lib/history-tracker.js +7 -1
  7. package/dist/src/cli/lib/history-tracker.js.map +1 -1
  8. package/examples/README.md +105 -0
  9. package/examples/quickstart.js +43 -0
  10. package/package.json +6 -2
  11. package/simulation/.claude-flow/metrics/agent-metrics.json +1 -0
  12. package/simulation/.claude-flow/metrics/performance.json +87 -0
  13. package/simulation/.claude-flow/metrics/task-metrics.json +10 -0
  14. package/simulation/COMPLETION-STATUS.md +139 -0
  15. package/simulation/FINAL-RESULTS.md +414 -0
  16. package/simulation/FINAL-STATUS.md +281 -0
  17. package/simulation/INTEGRATION-COMPLETE.md +452 -0
  18. package/simulation/MIGRATION-STATUS.md +231 -0
  19. package/simulation/OPTIMIZATION-RESULTS.md +397 -0
  20. package/simulation/PHASE1-COMPLETE.md +163 -0
  21. package/simulation/README.md +848 -0
  22. package/simulation/SIMULATION-RESULTS.md +239 -0
  23. package/simulation/cli.ts +78 -0
  24. package/simulation/configs/default.json +37 -0
  25. package/simulation/data/advanced/aidefence.graph +0 -0
  26. package/simulation/data/advanced/bmssp.graph +0 -0
  27. package/simulation/data/advanced/consciousness.graph +0 -0
  28. package/simulation/data/advanced/goalie.graph +0 -0
  29. package/simulation/data/advanced/psycho-symbolic.graph +0 -0
  30. package/simulation/data/advanced/research-swarm.graph +0 -0
  31. package/simulation/data/advanced/sublinear.graph +0 -0
  32. package/simulation/data/advanced/temporal.graph +0 -0
  33. package/simulation/data/causal.graph +0 -0
  34. package/simulation/data/graph-traversal.graph +0 -0
  35. package/simulation/data/lean-agentic.graph +0 -0
  36. package/simulation/data/reflexion.graph +0 -0
  37. package/simulation/data/skills.graph +0 -0
  38. package/simulation/data/stock-market.graph +0 -0
  39. package/simulation/data/strange-loops.graph +0 -0
  40. package/simulation/data/swarm.graph +0 -0
  41. package/simulation/data/voting-consensus.graph +0 -0
  42. package/simulation/docs/CLI-INTEGRATION-PLAN.md +1038 -0
  43. package/simulation/docs/COMPREHENSIVE-LATENT-SPACE-COMPLETION.md +354 -0
  44. package/simulation/docs/DOCUMENTATION-INDEX.md +226 -0
  45. package/simulation/docs/IMPLEMENTATION-COMPLETE.md +521 -0
  46. package/simulation/docs/OPTIMIZATION-SUMMARY.md +279 -0
  47. package/simulation/docs/README.md +229 -0
  48. package/simulation/docs/SWARM-5-INTEGRATION-SUMMARY.md +528 -0
  49. package/simulation/docs/TESTING-SUMMARY.md +304 -0
  50. package/simulation/docs/architecture/EXTENSION-API.md +868 -0
  51. package/simulation/docs/architecture/INTEGRATION-ARCHITECTURE.md +1138 -0
  52. package/simulation/docs/architecture/OPTIMIZATION-STRATEGY.md +778 -0
  53. package/simulation/docs/architecture/SIMULATION-ARCHITECTURE.md +892 -0
  54. package/simulation/docs/guides/CLI-REFERENCE.md +896 -0
  55. package/simulation/docs/guides/CUSTOM-SIMULATIONS.md +931 -0
  56. package/simulation/docs/guides/DEPLOYMENT.md +832 -0
  57. package/simulation/docs/guides/IMPLEMENTATION-SUMMARY.md +544 -0
  58. package/simulation/docs/guides/MIGRATION-GUIDE.md +591 -0
  59. package/simulation/docs/guides/QUICK-START.md +361 -0
  60. package/simulation/docs/guides/README.md +736 -0
  61. package/simulation/docs/guides/TROUBLESHOOTING.md +817 -0
  62. package/simulation/docs/guides/WIZARD-GUIDE.md +869 -0
  63. package/simulation/docs/reports/latent-space/MASTER-SYNTHESIS.md +345 -0
  64. package/simulation/docs/reports/latent-space/README.md +132 -0
  65. package/simulation/docs/reports/latent-space/attention-analysis-RESULTS.md +238 -0
  66. package/simulation/docs/reports/latent-space/clustering-analysis-RESULTS.md +210 -0
  67. package/simulation/docs/reports/latent-space/hnsw-exploration-RESULTS.md +332 -0
  68. package/simulation/docs/reports/latent-space/hypergraph-exploration-RESULTS.md +37 -0
  69. package/simulation/docs/reports/latent-space/neural-augmentation-RESULTS.md +69 -0
  70. package/simulation/docs/reports/latent-space/quantum-hybrid-RESULTS.md +91 -0
  71. package/simulation/docs/reports/latent-space/self-organizing-hnsw-RESULTS.md +51 -0
  72. package/simulation/docs/reports/latent-space/traversal-optimization-RESULTS.md +238 -0
  73. package/simulation/reports/README.md +397 -0
  74. package/simulation/reports/advanced-simulations-performance.md +1241 -0
  75. package/simulation/reports/aidefence-integration-2025-11-30T01-36-53-486Z.json +30 -0
  76. package/simulation/reports/architecture-analysis.md +1396 -0
  77. package/simulation/reports/basic-scenarios-performance.md +1840 -0
  78. package/simulation/reports/bmssp-integration-2025-11-30T01-36-27-193Z.json +30 -0
  79. package/simulation/reports/bmssp-integration-2025-11-30T03-38-12-887Z.json +30 -0
  80. package/simulation/reports/causal-reasoning-2025-11-29T23-35-21-795Z.json +36 -0
  81. package/simulation/reports/causal-reasoning-2025-11-30T00-58-42-862Z.json +30 -0
  82. package/simulation/reports/causal-reasoning-2025-11-30T00-59-12-546Z.json +40 -0
  83. package/simulation/reports/consciousness-explorer-2025-11-30T01-36-51-269Z.json +31 -0
  84. package/simulation/reports/core-benchmarks.md +727 -0
  85. package/simulation/reports/goalie-integration-2025-11-30T01-36-52-377Z.json +30 -0
  86. package/simulation/reports/graph-traversal-2025-11-29T23-35-35-279Z.json +78 -0
  87. package/simulation/reports/graph-traversal-2025-11-29T23-37-36-697Z.json +30 -0
  88. package/simulation/reports/graph-traversal-2025-11-30T01-03-59-716Z.json +30 -0
  89. package/simulation/reports/graph-traversal-2025-11-30T01-05-10-984Z.json +30 -0
  90. package/simulation/reports/graph-traversal-2025-11-30T01-06-16-334Z.json +30 -0
  91. package/simulation/reports/graph-traversal-2025-11-30T01-06-53-312Z.json +30 -0
  92. package/simulation/reports/graph-traversal-2025-11-30T01-07-51-075Z.json +24 -0
  93. package/simulation/reports/graph-traversal-2025-11-30T01-08-22-179Z.json +42 -0
  94. package/simulation/reports/lean-agentic-swarm-2025-11-29T23-37-23-804Z.json +148 -0
  95. package/simulation/reports/lean-agentic-swarm-2025-11-30T01-31-24-401Z.json +31 -0
  96. package/simulation/reports/lean-agentic-swarm-2025-11-30T03-38-01-470Z.json +31 -0
  97. package/simulation/reports/multi-agent-swarm-2025-11-29T23-35-28-093Z.json +78 -0
  98. package/simulation/reports/multi-agent-swarm-2025-11-30T01-03-54-062Z.json +42 -0
  99. package/simulation/reports/multi-agent-swarm-2025-11-30T01-05-06-092Z.json +42 -0
  100. package/simulation/reports/psycho-symbolic-reasoner-2025-11-30T01-36-50-180Z.json +30 -0
  101. package/simulation/reports/quality-metrics.md +727 -0
  102. package/simulation/reports/reflexion-learning-2025-11-29T23-35-09-774Z.json +48 -0
  103. package/simulation/reports/reflexion-learning-2025-11-29T23-37-16-934Z.json +36 -0
  104. package/simulation/reports/reflexion-learning-2025-11-30T00-07-49-259Z.json +30 -0
  105. package/simulation/reports/reflexion-learning-2025-11-30T00-09-29-319Z.json +51 -0
  106. package/simulation/reports/reflexion-learning-2025-11-30T00-28-37-659Z.json +51 -0
  107. package/simulation/reports/reflexion-learning-2025-11-30T01-31-30-690Z.json +29 -0
  108. package/simulation/reports/reflexion-learning-2025-11-30T03-38-06-937Z.json +29 -0
  109. package/simulation/reports/research-foundations.md +2004 -0
  110. package/simulation/reports/research-swarm-2025-11-30T01-36-54-647Z.json +30 -0
  111. package/simulation/reports/scalability-deployment.md +2404 -0
  112. package/simulation/reports/skill-evolution-2025-11-29T23-35-15-945Z.json +36 -0
  113. package/simulation/reports/skill-evolution-2025-11-30T01-03-17-995Z.json +30 -0
  114. package/simulation/reports/skill-evolution-2025-11-30T01-03-48-441Z.json +30 -0
  115. package/simulation/reports/skill-evolution-2025-11-30T01-05-00-554Z.json +30 -0
  116. package/simulation/reports/skill-evolution-2025-11-30T01-06-11-436Z.json +30 -0
  117. package/simulation/reports/skill-evolution-2025-11-30T01-06-51-979Z.json +30 -0
  118. package/simulation/reports/skill-evolution-2025-11-30T01-07-32-695Z.json +40 -0
  119. package/simulation/reports/stock-market-emergence-2025-11-30T00-11-43-865Z.json +56 -0
  120. package/simulation/reports/stock-market-emergence-2025-11-30T00-28-57-495Z.json +56 -0
  121. package/simulation/reports/strange-loops-2025-11-29T23-37-30-621Z.json +78 -0
  122. package/simulation/reports/strange-loops-2025-11-30T00-07-55-415Z.json +30 -0
  123. package/simulation/reports/strange-loops-2025-11-30T00-09-35-133Z.json +30 -0
  124. package/simulation/reports/strange-loops-2025-11-30T00-48-50-744Z.json +24 -0
  125. package/simulation/reports/strange-loops-2025-11-30T00-54-48-044Z.json +24 -0
  126. package/simulation/reports/strange-loops-2025-11-30T00-57-27-633Z.json +24 -0
  127. package/simulation/reports/strange-loops-2025-11-30T00-57-59-135Z.json +42 -0
  128. package/simulation/reports/sublinear-solver-2025-11-30T01-36-33-134Z.json +30 -0
  129. package/simulation/reports/temporal-lead-solver-2025-11-30T01-36-38-628Z.json +30 -0
  130. package/simulation/reports/use-cases-applications.md +2212 -0
  131. package/simulation/reports/voting-system-consensus-2025-11-30T00-11-37-199Z.json +58 -0
  132. package/simulation/reports/voting-system-consensus-2025-11-30T00-28-47-735Z.json +58 -0
  133. package/simulation/runner.ts +300 -0
  134. package/simulation/scenarios/README-advanced/aidefence-integration.md +63 -0
  135. package/simulation/scenarios/README-advanced/bmssp-integration.md +58 -0
  136. package/simulation/scenarios/README-advanced/consciousness-explorer.md +53 -0
  137. package/simulation/scenarios/README-advanced/goalie-integration.md +61 -0
  138. package/simulation/scenarios/README-advanced/psycho-symbolic-reasoner.md +55 -0
  139. package/simulation/scenarios/README-advanced/research-swarm.md +63 -0
  140. package/simulation/scenarios/README-advanced/sublinear-solver.md +58 -0
  141. package/simulation/scenarios/README-advanced/temporal-lead-solver.md +55 -0
  142. package/simulation/scenarios/README-basic/causal-reasoning.md +39 -0
  143. package/simulation/scenarios/README-basic/graph-traversal.md +41 -0
  144. package/simulation/scenarios/README-basic/lean-agentic-swarm.md +122 -0
  145. package/simulation/scenarios/README-basic/multi-agent-swarm.md +34 -0
  146. package/simulation/scenarios/README-basic/reflexion-learning.md +41 -0
  147. package/simulation/scenarios/README-basic/skill-evolution.md +38 -0
  148. package/simulation/scenarios/README-basic/stock-market-emergence.md +28 -0
  149. package/simulation/scenarios/README-basic/strange-loops.md +36 -0
  150. package/simulation/scenarios/README-basic/voting-system-consensus.md +28 -0
  151. package/simulation/scenarios/README.md +438 -0
  152. package/simulation/scenarios/aidefence-integration.ts +165 -0
  153. package/simulation/scenarios/bmssp-integration.ts +137 -0
  154. package/simulation/scenarios/causal-reasoning.ts +143 -0
  155. package/simulation/scenarios/consciousness-explorer.ts +139 -0
  156. package/simulation/scenarios/domain-examples/.claude-flow/metrics/agent-metrics.json +1 -0
  157. package/simulation/scenarios/domain-examples/.claude-flow/metrics/performance.json +87 -0
  158. package/simulation/scenarios/domain-examples/.claude-flow/metrics/task-metrics.json +10 -0
  159. package/simulation/scenarios/domain-examples/README.md +525 -0
  160. package/simulation/scenarios/domain-examples/e-commerce-recommendations.ts +220 -0
  161. package/simulation/scenarios/domain-examples/index.ts +81 -0
  162. package/simulation/scenarios/domain-examples/iot-sensor-networks.ts +290 -0
  163. package/simulation/scenarios/domain-examples/medical-imaging.ts +181 -0
  164. package/simulation/scenarios/domain-examples/robotics-navigation.ts +214 -0
  165. package/simulation/scenarios/domain-examples/scientific-research.ts +250 -0
  166. package/simulation/scenarios/domain-examples/trading-systems.ts +138 -0
  167. package/simulation/scenarios/goalie-integration.ts +161 -0
  168. package/simulation/scenarios/graph-traversal.ts +129 -0
  169. package/simulation/scenarios/latent-space/OPTIMIZATION-COMPLETE.md +287 -0
  170. package/simulation/scenarios/latent-space/README-attention-analysis.md +170 -0
  171. package/simulation/scenarios/latent-space/README-clustering-analysis.md +239 -0
  172. package/simulation/scenarios/latent-space/README-hnsw-exploration.md +199 -0
  173. package/simulation/scenarios/latent-space/README-hypergraph-exploration.md +279 -0
  174. package/simulation/scenarios/latent-space/README-neural-augmentation.md +267 -0
  175. package/simulation/scenarios/latent-space/README-quantum-hybrid.md +276 -0
  176. package/simulation/scenarios/latent-space/README-self-organizing-hnsw.md +244 -0
  177. package/simulation/scenarios/latent-space/README-traversal-optimization.md +212 -0
  178. package/simulation/scenarios/latent-space/attention-analysis.ts +598 -0
  179. package/simulation/scenarios/latent-space/clustering-analysis.ts +796 -0
  180. package/simulation/scenarios/latent-space/hnsw-exploration.ts +526 -0
  181. package/simulation/scenarios/latent-space/hypergraph-exploration.ts +706 -0
  182. package/simulation/scenarios/latent-space/index.ts +47 -0
  183. package/simulation/scenarios/latent-space/neural-augmentation.ts +604 -0
  184. package/simulation/scenarios/latent-space/quantum-hybrid.ts +508 -0
  185. package/simulation/scenarios/latent-space/self-organizing-hnsw.ts +680 -0
  186. package/simulation/scenarios/latent-space/traversal-optimization.ts +782 -0
  187. package/simulation/scenarios/lean-agentic-swarm.ts +182 -0
  188. package/simulation/scenarios/multi-agent-swarm.ts +146 -0
  189. package/simulation/scenarios/psycho-symbolic-reasoner.ts +136 -0
  190. package/simulation/scenarios/reflexion-learning.ts +132 -0
  191. package/simulation/scenarios/research-swarm.ts +187 -0
  192. package/simulation/scenarios/skill-evolution.ts +135 -0
  193. package/simulation/scenarios/stock-market-emergence.ts +323 -0
  194. package/simulation/scenarios/strange-loops.ts +175 -0
  195. package/simulation/scenarios/sublinear-solver.ts +108 -0
  196. package/simulation/scenarios/temporal-lead-solver.ts +121 -0
  197. package/simulation/scenarios/voting-system-consensus.ts +251 -0
  198. package/simulation/tests/latent-space/attention-analysis.test.ts +204 -0
  199. package/simulation/tests/latent-space/clustering-analysis.test.ts +281 -0
  200. package/simulation/tests/latent-space/hnsw-exploration.test.ts +253 -0
  201. package/simulation/tests/latent-space/hypergraph-exploration.test.ts +295 -0
  202. package/simulation/tests/latent-space/neural-augmentation.test.ts +326 -0
  203. package/simulation/tests/latent-space/quantum-hybrid.test.ts +307 -0
  204. package/simulation/tests/latent-space/self-organizing-hnsw.test.ts +291 -0
  205. package/simulation/tests/latent-space/traversal-optimization.test.ts +261 -0
  206. package/simulation/types.ts +177 -0
  207. package/simulation/utils/PerformanceOptimizer.ts +269 -0
  208. package/src/cli/lib/history-tracker.ts +7 -1
@@ -0,0 +1,291 @@
1
+ /**
2
+ * Self-Organizing HNSW Simulation Tests
3
+ *
4
+ * Tests autonomous graph restructuring, adaptive parameter tuning,
5
+ * dynamic topology evolution, and self-healing mechanisms.
6
+ *
7
+ * Target Metrics:
8
+ * - MPC adaptation implementation
9
+ * - Degradation prevention >95% (target: 97.9%)
10
+ * - Self-healing latency <100ms
11
+ * - 30-day simulation capability
12
+ * - Real-time monitoring
13
+ */
14
+
15
+ import { describe, it, expect, beforeAll } from 'vitest';
16
+ import { selfOrganizingHNSWScenario } from '../../scenarios/latent-space/self-organizing-hnsw';
17
+ import type { SimulationReport } from '../../types';
18
+
19
+ describe('SelfOrganizingHNSW', () => {
20
+ let report: SimulationReport;
21
+
22
+ beforeAll(async () => {
23
+ report = await selfOrganizingHNSWScenario.run(selfOrganizingHNSWScenario.config);
24
+ }, 120000); // 120s timeout for long simulation
25
+
26
+ describe('Optimal Adaptation Strategy', () => {
27
+ it('should select MPC as best strategy', () => {
28
+ const best = report.summary.bestStrategy;
29
+ expect(['mpc', 'hybrid']).toContain(best.strategy);
30
+ });
31
+
32
+ it('should test static baseline', () => {
33
+ const strategies = selfOrganizingHNSWScenario.config.strategies;
34
+ const static_strategy = strategies.find(s => s.name === 'static');
35
+ expect(static_strategy).toBeDefined();
36
+ });
37
+
38
+ it('should test MPC adaptation', () => {
39
+ const strategies = selfOrganizingHNSWScenario.config.strategies;
40
+ const mpc = strategies.find(s => s.name === 'mpc');
41
+ expect(mpc).toBeDefined();
42
+ });
43
+
44
+ it('should test online learning', () => {
45
+ const strategies = selfOrganizingHNSWScenario.config.strategies;
46
+ const online = strategies.find(s => s.name === 'online-learning');
47
+ expect(online).toBeDefined();
48
+ });
49
+ });
50
+
51
+ describe('Degradation Prevention', () => {
52
+ it('should prevent >95% degradation', () => {
53
+ const avgDegradation = report.summary.avgDegradationPrevented;
54
+ expect(avgDegradation).toBeGreaterThan(95);
55
+ });
56
+
57
+ it('should target 97.9% degradation prevention', () => {
58
+ const avgDegradation = report.summary.avgDegradationPrevented;
59
+ expect(avgDegradation).toBeCloseTo(97.9, 5);
60
+ });
61
+
62
+ it('should detect performance degradation', () => {
63
+ const results = report.detailedResults as any[];
64
+ const hasAdaptation = results.some(r => {
65
+ return r.evolution?.timeline?.some((t: any) => t.degradation);
66
+ });
67
+ expect(hasAdaptation).toBe(true);
68
+ });
69
+ });
70
+
71
+ describe('Self-Healing Mechanisms', () => {
72
+ it('should heal fragmentation', () => {
73
+ const avgHealing = report.summary.avgHealingTime;
74
+ expect(avgHealing).toBeLessThan(100);
75
+ });
76
+
77
+ it('should target <100ms healing latency', () => {
78
+ const results = report.detailedResults as any[];
79
+ results.forEach(r => {
80
+ if (r.healing?.healingTimeMs) {
81
+ expect(r.healing.healingTimeMs).toBeLessThan(150);
82
+ }
83
+ });
84
+ });
85
+
86
+ it('should maintain recall after healing', () => {
87
+ const results = report.detailedResults as any[];
88
+ results.forEach(r => {
89
+ if (r.healing?.postHealingRecall) {
90
+ expect(r.healing.postHealingRecall).toBeGreaterThan(0.90);
91
+ }
92
+ });
93
+ });
94
+
95
+ it('should reconnect fragmented nodes', () => {
96
+ const results = report.detailedResults as any[];
97
+ results.forEach(r => {
98
+ if (r.healing) {
99
+ expect(r.healing.fragmentationRate).toBeLessThan(0.1);
100
+ }
101
+ });
102
+ });
103
+ });
104
+
105
+ describe('30-Day Simulation', () => {
106
+ it('should simulate 30 days', () => {
107
+ const days = selfOrganizingHNSWScenario.config.simulationDays;
108
+ expect(days).toBe(30);
109
+ });
110
+
111
+ it('should handle workload shifts', () => {
112
+ const shifts = selfOrganizingHNSWScenario.config.workloadShifts;
113
+ expect(shifts.length).toBeGreaterThanOrEqual(3);
114
+ });
115
+
116
+ it('should track performance over time', () => {
117
+ const results = report.detailedResults as any[];
118
+ const withEvolution = results.filter(r => r.evolution?.timeline?.length > 0);
119
+ expect(withEvolution.length).toBeGreaterThan(0);
120
+ });
121
+ });
122
+
123
+ describe('MPC Adaptation', () => {
124
+ it('should optimize parameters', () => {
125
+ const mpcResults = (report.detailedResults as any[]).filter(
126
+ r => r.strategy === 'mpc' || r.strategy === 'hybrid'
127
+ );
128
+
129
+ mpcResults.forEach(r => {
130
+ if (r.parameters?.optimalMFound) {
131
+ expect(r.parameters.optimalMFound).toBeGreaterThan(0);
132
+ }
133
+ });
134
+ });
135
+
136
+ it('should use predictive horizon', () => {
137
+ const strategies = selfOrganizingHNSWScenario.config.strategies;
138
+ const mpc = strategies.find(s => s.name === 'mpc');
139
+
140
+ if (mpc) {
141
+ expect(mpc.parameters.horizon).toBe(10);
142
+ }
143
+ });
144
+
145
+ it('should improve latency over time', () => {
146
+ const results = report.detailedResults as any[];
147
+ const adaptive = results.filter(r => r.strategy !== 'static');
148
+
149
+ adaptive.forEach(r => {
150
+ if (r.improvement?.latencyImprovement) {
151
+ expect(r.improvement.latencyImprovement).toBeGreaterThan(-10);
152
+ }
153
+ });
154
+ });
155
+ });
156
+
157
+ describe('Parameter Evolution', () => {
158
+ it('should discover optimal M', () => {
159
+ const paramMetrics = report.metrics.parameterEvolution;
160
+ expect(paramMetrics.avgOptimalM).toBeGreaterThan(0);
161
+ expect(paramMetrics.avgOptimalM).toBeLessThan(100);
162
+ });
163
+
164
+ it('should maintain parameter stability', () => {
165
+ const paramMetrics = report.metrics.parameterEvolution;
166
+ expect(paramMetrics.avgStability).toBeGreaterThan(0.7);
167
+ });
168
+
169
+ it('should track parameter trajectory', () => {
170
+ const results = report.detailedResults as any[];
171
+ const withTrajectory = results.filter(
172
+ r => r.parameters?.mTrajectory?.length > 0
173
+ );
174
+ expect(withTrajectory.length).toBeGreaterThan(0);
175
+ });
176
+ });
177
+
178
+ describe('Deletion Handling', () => {
179
+ it('should test multiple deletion rates', () => {
180
+ const rates = selfOrganizingHNSWScenario.config.deletionRates;
181
+ expect(rates.length).toBeGreaterThanOrEqual(3);
182
+ expect(rates).toContain(0.05);
183
+ });
184
+
185
+ it('should handle 10% daily deletions', () => {
186
+ const highDeletion = (report.detailedResults as any[]).filter(
187
+ r => r.deletionRate === 0.10
188
+ );
189
+
190
+ highDeletion.forEach(r => {
191
+ if (r.healing) {
192
+ expect(r.healing.postHealingRecall).toBeGreaterThan(0.85);
193
+ }
194
+ });
195
+ });
196
+ });
197
+
198
+ describe('Online Learning', () => {
199
+ it('should use gradient-based optimization', () => {
200
+ const strategies = selfOrganizingHNSWScenario.config.strategies;
201
+ const online = strategies.find(s => s.name === 'online-learning');
202
+
203
+ if (online) {
204
+ expect(online.parameters.learningRate).toBeDefined();
205
+ expect(online.parameters.learningRate).toBeLessThan(0.01);
206
+ }
207
+ });
208
+
209
+ it('should converge to good parameters', () => {
210
+ const onlineResults = (report.detailedResults as any[]).filter(
211
+ r => r.strategy === 'online-learning'
212
+ );
213
+
214
+ onlineResults.forEach(r => {
215
+ if (r.parameters?.optimalMFound) {
216
+ expect(r.parameters.optimalMFound).toBeGreaterThan(8);
217
+ expect(r.parameters.optimalMFound).toBeLessThan(64);
218
+ }
219
+ });
220
+ });
221
+ });
222
+
223
+ describe('Hybrid Strategy', () => {
224
+ it('should combine MPC and online learning', () => {
225
+ const hybrid = (report.detailedResults as any[]).find(r => r.strategy === 'hybrid');
226
+
227
+ if (hybrid) {
228
+ expect(hybrid.parameters).toBeDefined();
229
+ }
230
+ });
231
+
232
+ it('should achieve best overall performance', () => {
233
+ const best = report.summary.bestStrategy;
234
+ const improvement = (best as any).improvement?.latencyImprovement || 0;
235
+ expect(improvement).toBeGreaterThan(-20);
236
+ });
237
+ });
238
+
239
+ describe('Long-Term Stability', () => {
240
+ it('should converge within simulation period', () => {
241
+ const stability = report.metrics.longTermStability;
242
+ expect(stability.convergenceTime).toBeLessThan(30);
243
+ });
244
+
245
+ it('should maintain stability score >85%', () => {
246
+ const stability = report.metrics.longTermStability;
247
+ expect(stability.stabilityScore).toBeGreaterThan(0.85);
248
+ });
249
+ });
250
+
251
+ describe('Real-Time Monitoring', () => {
252
+ it('should track metrics over time', () => {
253
+ const results = report.detailedResults as any[];
254
+ const withTimeline = results.filter(r => r.evolution?.timeline);
255
+ expect(withTimeline.length).toBeGreaterThan(0);
256
+ });
257
+
258
+ it('should detect anomalies', () => {
259
+ const results = report.detailedResults as any[];
260
+ results.forEach(r => {
261
+ if (r.evolution?.timeline) {
262
+ r.evolution.timeline.forEach((t: any) => {
263
+ expect(t.metrics).toBeDefined();
264
+ });
265
+ }
266
+ });
267
+ });
268
+ });
269
+
270
+ describe('Report Generation', () => {
271
+ it('should generate analysis', () => {
272
+ expect(report.analysis).toBeDefined();
273
+ expect(report.analysis).toContain('Self-Organizing');
274
+ });
275
+
276
+ it('should provide recommendations', () => {
277
+ expect(report.recommendations).toBeDefined();
278
+ expect(report.recommendations.some(r => r.includes('MPC'))).toBe(true);
279
+ });
280
+
281
+ it('should generate evolution visualizations', () => {
282
+ expect(report.artifacts.evolutionTimelines).toBeDefined();
283
+ expect(report.artifacts.parameterTrajectories).toBeDefined();
284
+ expect(report.artifacts.healingVisualizations).toBeDefined();
285
+ });
286
+
287
+ it('should complete within timeout', () => {
288
+ expect(report.executionTimeMs).toBeLessThan(120000);
289
+ });
290
+ });
291
+ });
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Traversal Optimization Simulation Tests
3
+ *
4
+ * Tests search strategies for efficient latent space navigation including
5
+ * greedy, beam, dynamic-k, and attention-guided traversal.
6
+ *
7
+ * Target Metrics:
8
+ * - Beam-5 configuration (optimal)
9
+ * - Dynamic-k adaptation (5-20 range)
10
+ * - Recall@10 >95% (target: 96.8%)
11
+ * - Latency reduction -18.4% with dynamic-k
12
+ * - Greedy, beam, A*, best-first strategies
13
+ */
14
+
15
+ import { describe, it, expect, beforeAll } from 'vitest';
16
+ import { traversalOptimizationScenario } from '../../scenarios/latent-space/traversal-optimization';
17
+ import type { SimulationReport } from '../../types';
18
+
19
+ describe('TraversalOptimization', () => {
20
+ let report: SimulationReport;
21
+
22
+ beforeAll(async () => {
23
+ report = await traversalOptimizationScenario.run(traversalOptimizationScenario.config);
24
+ }, 90000); // 90s timeout
25
+
26
+ describe('Optimal Strategy Selection', () => {
27
+ it('should identify beam-5 as optimal', () => {
28
+ const best = report.summary.bestStrategy;
29
+ expect(best.strategy).toBe('beam');
30
+ expect(best.parameters.beamWidth).toBe(5);
31
+ });
32
+
33
+ it('should test greedy baseline', () => {
34
+ const strategies = traversalOptimizationScenario.config.strategies;
35
+ const greedy = strategies.find(s => s.name === 'greedy');
36
+ expect(greedy).toBeDefined();
37
+ });
38
+
39
+ it('should test multiple beam widths', () => {
40
+ const strategies = traversalOptimizationScenario.config.strategies;
41
+ const beamStrategies = strategies.filter(s => s.name === 'beam');
42
+ expect(beamStrategies.length).toBeGreaterThanOrEqual(3);
43
+ });
44
+ });
45
+
46
+ describe('Dynamic-K Adaptation', () => {
47
+ it('should adapt k in range 5-20', () => {
48
+ const dynamicK = (report.detailedResults as any[]).find(
49
+ r => r.strategy === 'dynamic-k'
50
+ );
51
+
52
+ if (dynamicK) {
53
+ const range = dynamicK.metrics.dynamicKRange;
54
+ expect(range[0]).toBe(5);
55
+ expect(range[1]).toBe(20);
56
+ }
57
+ });
58
+
59
+ it('should reduce latency by >15%', () => {
60
+ const analysis = report.metrics.dynamicKEfficiency;
61
+ if (analysis && analysis.latencyReduction) {
62
+ expect(Math.abs(analysis.latencyReduction)).toBeGreaterThan(15);
63
+ }
64
+ });
65
+
66
+ it('should target -18.4% latency reduction', () => {
67
+ const analysis = report.metrics.dynamicKEfficiency;
68
+ if (analysis && analysis.latencyReduction) {
69
+ expect(analysis.latencyReduction).toBeCloseTo(-18.4, 5);
70
+ }
71
+ });
72
+ });
73
+
74
+ describe('Recall Performance', () => {
75
+ it('should achieve >95% recall@10', () => {
76
+ const results = report.detailedResults as any[];
77
+ results.forEach(r => {
78
+ if (r.metrics.recallAt10) {
79
+ expect(r.metrics.recallAt10).toBeGreaterThan(0.95);
80
+ }
81
+ });
82
+ });
83
+
84
+ it('should target 96.8% recall@10', () => {
85
+ const best = report.summary.bestStrategy;
86
+ if (best.metrics.recallAt10) {
87
+ expect(best.metrics.recallAt10).toBeCloseTo(0.968, 0.02);
88
+ }
89
+ });
90
+
91
+ it('should maintain high precision', () => {
92
+ const results = report.detailedResults as any[];
93
+ results.forEach(r => {
94
+ expect(r.metrics.precision).toBeGreaterThan(0.85);
95
+ });
96
+ });
97
+
98
+ it('should optimize F1 score', () => {
99
+ const results = report.detailedResults as any[];
100
+ results.forEach(r => {
101
+ const f1 = r.metrics.f1Score;
102
+ expect(f1).toBeGreaterThan(0.85);
103
+ expect(f1).toBeLessThanOrEqual(1.0);
104
+ });
105
+ });
106
+ });
107
+
108
+ describe('Search Efficiency', () => {
109
+ it('should minimize average hops', () => {
110
+ const avgHops = report.summary.avgHops || 0;
111
+ expect(avgHops).toBeLessThan(25);
112
+ });
113
+
114
+ it('should reduce distance computations', () => {
115
+ const results = report.detailedResults as any[];
116
+ results.forEach(r => {
117
+ const avgDist = r.metrics.avgDistanceComputations;
118
+ expect(avgDist).toBeLessThan(r.graphSize / 10);
119
+ });
120
+ });
121
+
122
+ it('should track latency percentiles', () => {
123
+ const results = report.detailedResults as any[];
124
+ results.forEach(r => {
125
+ expect(r.metrics.latencyP50).toBeDefined();
126
+ expect(r.metrics.latencyP95).toBeDefined();
127
+ expect(r.metrics.latencyP99).toBeDefined();
128
+ });
129
+ });
130
+ });
131
+
132
+ describe('Strategy Comparison', () => {
133
+ it('should compare all strategies', () => {
134
+ const comparison = report.metrics.strategyComparison;
135
+ expect(Array.isArray(comparison)).toBe(true);
136
+ expect(comparison.length).toBeGreaterThanOrEqual(5);
137
+ });
138
+
139
+ it('should show beam > greedy recall', () => {
140
+ const comparison = report.metrics.strategyComparison;
141
+ const greedy = comparison.find((s: any) => s.strategy === 'greedy');
142
+ const beam = comparison.find((s: any) => s.strategy === 'beam');
143
+
144
+ if (greedy && beam) {
145
+ expect(beam.avgRecall).toBeGreaterThan(greedy.avgRecall);
146
+ }
147
+ });
148
+
149
+ it('should analyze latency trade-offs', () => {
150
+ const comparison = report.metrics.strategyComparison;
151
+ const greedy = comparison.find((s: any) => s.strategy === 'greedy');
152
+ const beam10 = (report.detailedResults as any[]).find(
153
+ r => r.strategy === 'beam' && r.parameters.beamWidth === 10
154
+ );
155
+
156
+ if (greedy && beam10) {
157
+ expect(beam10.metrics.latencyMs).toBeGreaterThan(greedy.metrics.latencyMs);
158
+ }
159
+ });
160
+ });
161
+
162
+ describe('Recall-Latency Frontier', () => {
163
+ it('should compute Pareto frontier', () => {
164
+ const frontier = report.metrics.recallLatencyFrontier;
165
+ expect(Array.isArray(frontier)).toBe(true);
166
+ expect(frontier.length).toBeGreaterThan(0);
167
+ });
168
+
169
+ it('should identify optimal trade-off points', () => {
170
+ const frontier = report.metrics.recallLatencyFrontier;
171
+ frontier.forEach((point: any) => {
172
+ expect(point.recall).toBeGreaterThan(0);
173
+ expect(point.latency).toBeGreaterThan(0);
174
+ });
175
+ });
176
+ });
177
+
178
+ describe('Attention-Guided Navigation', () => {
179
+ it('should test attention-guided strategy', () => {
180
+ const attentionStrategy = (report.detailedResults as any[]).find(
181
+ r => r.strategy === 'attention-guided'
182
+ );
183
+ expect(attentionStrategy).toBeDefined();
184
+ });
185
+
186
+ it('should improve efficiency', () => {
187
+ const analysis = report.metrics.attentionGuidance;
188
+ if (analysis && analysis.efficiency) {
189
+ expect(analysis.efficiency).toBeGreaterThan(0.85);
190
+ }
191
+ });
192
+
193
+ it('should prune search paths', () => {
194
+ const analysis = report.metrics.attentionGuidance;
195
+ if (analysis && analysis.pathPruning) {
196
+ expect(analysis.pathPruning).toBeGreaterThan(0.1);
197
+ }
198
+ });
199
+ });
200
+
201
+ describe('Query Distribution Robustness', () => {
202
+ it('should test uniform queries', () => {
203
+ const distributions = traversalOptimizationScenario.config.queryDistributions;
204
+ expect(distributions).toContain('uniform');
205
+ });
206
+
207
+ it('should test clustered queries', () => {
208
+ const distributions = traversalOptimizationScenario.config.queryDistributions;
209
+ expect(distributions).toContain('clustered');
210
+ });
211
+
212
+ it('should test outlier queries', () => {
213
+ const distributions = traversalOptimizationScenario.config.queryDistributions;
214
+ expect(distributions).toContain('outliers');
215
+ });
216
+
217
+ it('should handle mixed workloads', () => {
218
+ const distributions = traversalOptimizationScenario.config.queryDistributions;
219
+ expect(distributions).toContain('mixed');
220
+ });
221
+ });
222
+
223
+ describe('Scalability', () => {
224
+ it('should scale to 1M nodes', () => {
225
+ const sizes = traversalOptimizationScenario.config.graphSizes;
226
+ expect(sizes).toContain(1000000);
227
+ });
228
+
229
+ it('should maintain performance at scale', () => {
230
+ const large = (report.detailedResults as any[]).filter(
231
+ r => r.graphSize === 1000000
232
+ );
233
+
234
+ large.forEach(r => {
235
+ expect(r.metrics.recall).toBeGreaterThan(0.90);
236
+ });
237
+ });
238
+ });
239
+
240
+ describe('Report Generation', () => {
241
+ it('should generate comprehensive analysis', () => {
242
+ expect(report.analysis).toBeDefined();
243
+ expect(report.analysis).toContain('Traversal');
244
+ });
245
+
246
+ it('should provide strategy recommendations', () => {
247
+ expect(report.recommendations).toBeDefined();
248
+ expect(report.recommendations.length).toBeGreaterThanOrEqual(3);
249
+ });
250
+
251
+ it('should generate visualization artifacts', () => {
252
+ expect(report.artifacts.recallLatencyPlots).toBeDefined();
253
+ expect(report.artifacts.strategyComparisons).toBeDefined();
254
+ expect(report.artifacts.efficiencyCurves).toBeDefined();
255
+ });
256
+
257
+ it('should complete efficiently', () => {
258
+ expect(report.executionTimeMs).toBeLessThan(90000);
259
+ });
260
+ });
261
+ });