onbuzz 4.9.13 → 4.10.0
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.
- package/node_modules/glob/README.md +31 -5
- package/node_modules/glob/dist/commonjs/glob.d.ts +8 -0
- package/node_modules/glob/dist/commonjs/glob.d.ts.map +1 -1
- package/node_modules/glob/dist/commonjs/glob.js +2 -1
- package/node_modules/glob/dist/commonjs/glob.js.map +1 -1
- package/node_modules/glob/dist/commonjs/index.min.js +3 -3
- package/node_modules/glob/dist/commonjs/index.min.js.map +4 -4
- package/node_modules/glob/dist/commonjs/pattern.d.ts +3 -0
- package/node_modules/glob/dist/commonjs/pattern.d.ts.map +1 -1
- package/node_modules/glob/dist/commonjs/pattern.js +4 -0
- package/node_modules/glob/dist/commonjs/pattern.js.map +1 -1
- package/node_modules/glob/dist/esm/glob.d.ts +8 -0
- package/node_modules/glob/dist/esm/glob.d.ts.map +1 -1
- package/node_modules/glob/dist/esm/glob.js +2 -1
- package/node_modules/glob/dist/esm/glob.js.map +1 -1
- package/node_modules/glob/dist/esm/index.min.js +3 -3
- package/node_modules/glob/dist/esm/index.min.js.map +4 -4
- package/node_modules/glob/dist/esm/pattern.d.ts +3 -0
- package/node_modules/glob/dist/esm/pattern.d.ts.map +1 -1
- package/node_modules/glob/dist/esm/pattern.js +4 -0
- package/node_modules/glob/dist/esm/pattern.js.map +1 -1
- package/node_modules/{@isaacs → glob/node_modules}/balanced-match/README.md +7 -10
- package/node_modules/{@isaacs → glob/node_modules}/balanced-match/package.json +7 -18
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/README.md +3 -6
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.js +6 -4
- package/node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -0
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.js +6 -4
- package/node_modules/glob/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
- package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/package.json +11 -7
- package/node_modules/glob/node_modules/minimatch/README.md +76 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.d.ts +4 -2
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.js +309 -55
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.js +2 -4
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.js +4 -4
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.d.ts +81 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js +232 -134
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.js +8 -8
- package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.d.ts +4 -2
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.js +309 -55
- package/node_modules/glob/node_modules/minimatch/dist/esm/ast.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.js +2 -4
- package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.js +4 -4
- package/node_modules/glob/node_modules/minimatch/dist/esm/escape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.d.ts +81 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.js +232 -134
- package/node_modules/glob/node_modules/minimatch/dist/esm/index.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.d.ts +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.d.ts.map +1 -1
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.js +8 -8
- package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.js.map +1 -1
- package/node_modules/glob/node_modules/minimatch/package.json +17 -11
- package/node_modules/glob/package.json +10 -13
- package/node_modules/minipass/LICENSE.md +55 -0
- package/node_modules/minipass/dist/commonjs/index.d.ts +12 -16
- package/node_modules/minipass/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/minipass/dist/commonjs/index.js +13 -3
- package/node_modules/minipass/dist/commonjs/index.js.map +1 -1
- package/node_modules/minipass/dist/esm/index.d.ts +12 -16
- package/node_modules/minipass/dist/esm/index.d.ts.map +1 -1
- package/node_modules/minipass/dist/esm/index.js +3 -1
- package/node_modules/minipass/dist/esm/index.js.map +1 -1
- package/node_modules/minipass/package.json +9 -14
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +96 -10
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.cjs.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts +109 -32
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +334 -197
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js.map +4 -4
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel-browser.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel-browser.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.mjs.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts +109 -32
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +333 -196
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js.map +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +1 -1
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js.map +4 -4
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel-node.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel-node.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.d.ts +5 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.d.ts +1400 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js.map +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.d.ts +12 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.d.ts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +71 -18
- package/node_modules/path-scurry/package.json +8 -24
- package/package.json +1 -1
- package/scripts/debug-balance-probe.mjs +35 -35
- package/scripts/push-image.sh +43 -43
- package/scripts/setup-acr.sh +65 -65
- package/scripts/verify-optional-deps.js +96 -1
- package/src/__tests__/composioCliFlags.test.js +239 -239
- package/src/analyzers/CSSAnalyzer.js +298 -297
- package/src/analyzers/ConfigValidator.js +691 -690
- package/src/analyzers/ESLintAnalyzer.js +320 -320
- package/src/analyzers/JavaScriptAnalyzer.js +260 -261
- package/src/analyzers/PrettierFormatter.js +246 -247
- package/src/analyzers/PythonAnalyzer.js +283 -283
- package/src/analyzers/SecurityAnalyzer.js +729 -729
- package/src/analyzers/SparrowAnalyzer.js +341 -341
- package/src/analyzers/TypeScriptAnalyzer.js +247 -247
- package/src/analyzers/__tests__/CSSAnalyzer.test.js +41 -41
- package/src/analyzers/__tests__/ConfigValidator.test.js +362 -362
- package/src/analyzers/__tests__/JavaScriptAnalyzer.test.js +40 -40
- package/src/analyzers/__tests__/PythonAnalyzer.test.js +205 -208
- package/src/analyzers/__tests__/SecurityAnalyzer.test.js +303 -303
- package/src/analyzers/__tests__/TypeScriptAnalyzer.test.js +187 -187
- package/src/analyzers/codeCloneDetector/analyzer.js +344 -344
- package/src/analyzers/codeCloneDetector/detector.js +250 -250
- package/src/analyzers/codeCloneDetector/index.js +194 -192
- package/src/analyzers/codeCloneDetector/parser.js +199 -199
- package/src/core/__tests__/agentPool.test.js +866 -866
- package/src/core/__tests__/agentPoolAutoResume.test.js +209 -209
- package/src/core/__tests__/agentPoolWakeOnMessage.test.js +315 -315
- package/src/core/__tests__/agentScheduler.emptyResponseChatStall.test.js +213 -213
- package/src/core/__tests__/agentScheduler.errorCategorisation.test.js +246 -246
- package/src/core/__tests__/agentScheduler.firstChunkTimeout.test.js +138 -138
- package/src/core/__tests__/agentScheduler.modeTransitions.test.js +233 -233
- package/src/core/__tests__/agentScheduler.nativePromptPick.test.js +319 -319
- package/src/core/__tests__/agentScheduler.taskLifecycleInstruction.test.js +78 -78
- package/src/core/__tests__/agentScheduler.visualizer.test.js +258 -258
- package/src/core/__tests__/flowCheckpointStore.test.js +140 -140
- package/src/core/__tests__/flowEndToEnd.test.js +565 -565
- package/src/core/__tests__/flowFieldMapping.test.js +188 -189
- package/src/core/__tests__/flowLintClientMirror.test.js +96 -98
- package/src/core/__tests__/flowSavePayload.test.js +170 -169
- package/src/core/__tests__/flowTemplates.test.js +311 -311
- package/src/core/__tests__/flowVersionStore.test.js +123 -123
- package/src/core/__tests__/messageProcessor.test.js +669 -669
- package/src/core/__tests__/stateManager.test.js +0 -1
- package/src/core/agentPool.js +2474 -2475
- package/src/core/agentScheduler.js +1 -4
- package/src/core/contextManager.js +708 -708
- package/src/core/flowExecutor.js +1510 -1510
- package/src/core/flowFieldMapping.js +136 -138
- package/src/core/messageProcessor.js +953 -954
- package/src/core/orchestrator.js +593 -595
- package/src/core/stateManager.js +1765 -1752
- package/src/index.js +1221 -1221
- package/src/interfaces/__tests__/archivedAgentDelete.test.js +207 -207
- package/src/interfaces/__tests__/bulkAgentRoute.test.js +361 -361
- package/src/interfaces/__tests__/imageServing.test.js +228 -228
- package/src/interfaces/__tests__/remoteSessionAuth.test.js +308 -308
- package/src/interfaces/__tests__/videoJobsRoutes.test.js +178 -179
- package/src/interfaces/__tests__/webServer.marketplace.test.js +629 -629
- package/src/interfaces/schedulerRoutes.js +50 -50
- package/src/interfaces/terminal/__tests__/smoke/connection.test.js +341 -350
- package/src/interfaces/terminal/__tests__/smoke/enhancements.test.js +156 -156
- package/src/interfaces/terminal/__tests__/smoke/imports.test.js +325 -330
- package/src/interfaces/terminal/__tests__/smoke/tools.test.js +385 -388
- package/src/interfaces/terminal/api/session.js +265 -266
- package/src/interfaces/terminal/api/websocket.js +496 -497
- package/src/interfaces/terminal/components/AgentCreator.js +691 -705
- package/src/interfaces/terminal/components/AgentEditor.js +676 -678
- package/src/interfaces/terminal/components/AgentSwitcher.js +331 -330
- package/src/interfaces/terminal/components/ErrorPanel.js +263 -264
- package/src/interfaces/terminal/components/Header.js +28 -28
- package/src/interfaces/terminal/components/Layout.js +598 -603
- package/src/interfaces/terminal/components/MessageList.js +280 -281
- package/src/interfaces/terminal/components/SettingsPanel.js +410 -415
- package/src/interfaces/terminal/components/StatusBar.js +2 -0
- package/src/interfaces/terminal/index.js +168 -168
- package/src/interfaces/terminal/state/useAgentControl.js +496 -496
- package/src/interfaces/terminal/state/useAgents.js +537 -537
- package/src/interfaces/terminal/state/useMessages.js +629 -630
- package/src/interfaces/terminal/state/useTools.js +554 -554
- package/src/interfaces/terminal/utils/debugLogger.js +44 -44
- package/src/interfaces/terminal/utils/settingsStorage.js +232 -232
- package/src/interfaces/webServer.js +7578 -7579
- package/src/interfaces/webServer.js.bak +7046 -7046
- package/src/modules/fileExplorer/__tests__/zipDownload.test.js +237 -237
- package/src/modules/fileExplorer/controller.js +470 -469
- package/src/modules/fileExplorer/routes.js +285 -286
- package/src/modules/widget/__tests__/isDisabled.test.js +41 -41
- package/src/modules/widget/__tests__/routes.test.js +677 -678
- package/src/modules/widget/__tests__/runtime.test.js +401 -401
- package/src/modules/widget/__tests__/versioning.test.js +309 -309
- package/src/modules/widget/__tests__/webComponentRuntime.test.js +565 -565
- package/src/modules/widget/__tests__/widgetTool.test.js +316 -316
- package/src/modules/widget/routes.js +435 -435
- package/src/modules/widget/runtime/bundle.js +640 -640
- package/src/modules/widget/runtime/webComponentBundle.js +470 -470
- package/src/modules/widget/schema.js +182 -181
- package/src/modules/widget/widgetTool.js +1389 -1389
- package/src/services/__tests__/agentActivityService.test.js +401 -402
- package/src/services/__tests__/benchmarkService.test.js +184 -184
- package/src/services/__tests__/contextInjectionService.test.js +246 -246
- package/src/services/__tests__/conversationQuery.test.js +721 -723
- package/src/services/__tests__/credentialVault.test.js +469 -469
- package/src/services/__tests__/discordService.integration.test.js +638 -639
- package/src/services/__tests__/flowContextService.test.js +590 -590
- package/src/services/__tests__/memoryService.test.js +1 -1
- package/src/services/__tests__/messageSource.test.js +380 -380
- package/src/services/__tests__/modelRouterNaming.test.js +111 -111
- package/src/services/__tests__/projectDetector.test.js +34 -34
- package/src/services/__tests__/promptService.test.js +242 -242
- package/src/services/__tests__/telegramService.test.js +941 -941
- package/src/services/__tests__/tokenCountingService.test.js +48 -48
- package/src/services/agentActivityService.js +419 -420
- package/src/services/aiService.js +2997 -3001
- package/src/services/apiKeyManager.js +359 -359
- package/src/services/benchmarkService.js +196 -196
- package/src/services/codebaseKnowledgeService.js +2 -2
- package/src/services/composioService.js +738 -738
- package/src/services/conversationCompactionService.js +1258 -1257
- package/src/services/credentialVault.js +685 -685
- package/src/services/discordService.js +792 -793
- package/src/services/embeddings/__tests__/azureCustomProvider.test.js +232 -232
- package/src/services/embeddings/__tests__/embeddingService.test.js +417 -417
- package/src/services/embeddings/__tests__/localProvider.test.js +263 -263
- package/src/services/embeddings/autoRecall.js +218 -219
- package/src/services/embeddings/indexers/__tests__/agentIndexer.test.js +232 -232
- package/src/services/embeddings/indexers/__tests__/memoryIndexer.test.js +418 -418
- package/src/services/embeddings/indexers/__tests__/reminisceIndexer.test.js +356 -357
- package/src/services/embeddings/indexers/__tests__/skillsIndexer.test.js +145 -145
- package/src/services/embeddings/indexers/__tests__/taskIndexer.test.js +146 -146
- package/src/services/embeddings/indexers/composioIndexer.js +279 -279
- package/src/services/embeddings/providerInterface.js +206 -206
- package/src/services/embeddings/providers/localProvider.js +11 -7
- package/src/services/embeddings/providers/openaiProvider.js +101 -101
- package/src/services/embeddings/vectorStore/inMemoryJsonStore.js +356 -356
- package/src/services/errorHandler.js +809 -809
- package/src/services/flowContextService.js +586 -586
- package/src/services/grounding/MockAdapter.js +125 -125
- package/src/services/modelRouterService.js +26 -31
- package/src/services/modelsService.js +322 -322
- package/src/services/ollamaService.js +452 -452
- package/src/services/projectDetector.js +403 -404
- package/src/services/promptService.js +418 -418
- package/src/services/qualityInspector.js +795 -795
- package/src/services/scheduleService.js +726 -726
- package/src/services/serviceRegistry.js +386 -386
- package/src/services/telegrafBot.js +174 -174
- package/src/services/telegramService.js +1972 -1972
- package/src/services/visualEditorBridge.js +1033 -1033
- package/src/services/visualEditorServer.js +1769 -1774
- package/src/services/whatsappService.js +667 -668
- package/src/tools/__tests__/agentCommunicationTool.findAgent.test.js +226 -226
- package/src/tools/__tests__/agentCommunicationTool.test.js +3 -3
- package/src/tools/__tests__/agentDelayTool.test.js +342 -342
- package/src/tools/__tests__/baseTool.test.js +3 -3
- package/src/tools/__tests__/codeMapTool.test.js +915 -915
- package/src/tools/__tests__/fileContentReplaceTool.test.js +309 -309
- package/src/tools/__tests__/fileTreeTool.test.js +274 -274
- package/src/tools/__tests__/filesystemTool.test.js +815 -815
- package/src/tools/__tests__/foundryWebSearchTool.test.js +252 -252
- package/src/tools/__tests__/imageTool.validator.test.js +194 -194
- package/src/tools/__tests__/jobDoneTool.test.js +580 -581
- package/src/tools/__tests__/memoryTool.forgetStale.test.js +272 -272
- package/src/tools/__tests__/memoryTool.reminisce.test.js +2 -2
- package/src/tools/__tests__/memoryTool.reminisceSemanticSearch.test.js +301 -301
- package/src/tools/__tests__/memoryTool.semanticSearch.test.js +405 -405
- package/src/tools/__tests__/memoryTool.teamPool.test.js +293 -293
- package/src/tools/__tests__/memoryTool.test.js +1 -1
- package/src/tools/__tests__/seekTool.test.js +282 -282
- package/src/tools/__tests__/skillsTool.search.test.js +164 -164
- package/src/tools/__tests__/skillsTool.test.js +226 -226
- package/src/tools/__tests__/staticAnalysisTool.test.js +509 -509
- package/src/tools/__tests__/taskManagerTool.discipline.test.js +137 -137
- package/src/tools/__tests__/taskManagerTool.search.test.js +143 -143
- package/src/tools/__tests__/taskManagerTool.test.js +866 -866
- package/src/tools/__tests__/terminalTool.test.js +448 -448
- package/src/tools/__tests__/toolShapeForgiveness.test.js +259 -260
- package/src/tools/__tests__/userPromptTool.test.js +297 -297
- package/src/tools/__tests__/videoTool.jobs.test.js +147 -147
- package/src/tools/__tests__/webTool.e2e.test.js +609 -603
- package/src/tools/__tests__/webTool.unit.test.js +195 -195
- package/src/tools/__tests__/webTool.visionModel.test.js +75 -75
- package/src/tools/agentCommunicationTool.js +8 -10
- package/src/tools/agentDelayTool.js +496 -497
- package/src/tools/asyncToolManager.js +602 -603
- package/src/tools/baseTool.js +12 -11
- package/src/tools/cloneDetectionTool.js +576 -581
- package/src/tools/codeMapTool.js +0 -6
- package/src/tools/composioTool.js +617 -617
- package/src/tools/dependencyResolverTool.js +1211 -1212
- package/src/tools/desktop/DesktopTool.js +629 -638
- package/src/tools/desktop/__tests__/DesktopTool.e2e.test.js +306 -306
- package/src/tools/desktop/__tests__/DesktopTool.test.js +507 -507
- package/src/tools/desktop/__tests__/osController.test.js +364 -364
- package/src/tools/desktop/osController.js +491 -491
- package/src/tools/docxTool.js +623 -623
- package/src/tools/excelTool.js +636 -636
- package/src/tools/fileContentReplaceTool.js +5 -7
- package/src/tools/fileSystemTool.js +12 -19
- package/src/tools/fileTreeTool.js +840 -840
- package/src/tools/foundryWebSearchTool.js +273 -273
- package/src/tools/helpTool.js +198 -198
- package/src/tools/imageTool.js +1397 -1397
- package/src/tools/importAnalyzerTool.js +1056 -1056
- package/src/tools/jobDoneTool.js +495 -495
- package/src/tools/memoryTool.js +1 -1
- package/src/tools/office/pres/__tests__/presSystem.test.js +365 -365
- package/src/tools/office/pres/archetypes/agenda.js +61 -61
- package/src/tools/office/pres/archetypes/bentoGrid.js +218 -219
- package/src/tools/office/pres/archetypes/bigStat.js +140 -142
- package/src/tools/office/pres/archetypes/closing.js +70 -70
- package/src/tools/office/pres/archetypes/hero.js +70 -70
- package/src/tools/office/pres/archetypes/productHero.js +93 -94
- package/src/tools/office/pres/archetypes/table.js +73 -74
- package/src/tools/office/pres/backgrounds/orb.js +66 -66
- package/src/tools/office/pres/components.js +422 -423
- package/src/tools/officeTool.js +441 -441
- package/src/tools/pdfTool.js +625 -627
- package/src/tools/platformControlTool.js +1081 -1081
- package/src/tools/seekTool.js +917 -918
- package/src/tools/skillsTool.js +1 -1
- package/src/tools/staticAnalysisTool.js +2143 -2146
- package/src/tools/taskManagerTool.js +3324 -3324
- package/src/tools/terminalTool.js +2615 -2618
- package/src/tools/videoTool.js +1303 -1303
- package/src/tools/visionTool.js +508 -508
- package/src/tools/visualEditorTool.js +1289 -1290
- package/src/tools/webTool.js +3368 -3368
- package/src/tools/whatsappTool.js +464 -464
- package/src/types/__tests__/agent.test.js +499 -499
- package/src/types/__tests__/contextReference.test.js +606 -606
- package/src/types/__tests__/conversation.test.js +555 -555
- package/src/types/__tests__/toolCommand.test.js +584 -584
- package/src/types/contextReference.js +974 -971
- package/src/types/conversation.js +729 -729
- package/src/types/toolCommand.js +746 -746
- package/src/utilities/__tests__/attachmentValidator.test.js +80 -80
- package/src/utilities/__tests__/auditReport.test.js +328 -328
- package/src/utilities/__tests__/directoryAccessManager.test.js +388 -388
- package/src/utilities/__tests__/jsonRepair.test.js +103 -104
- package/src/utilities/__tests__/modeTransitionReasons.test.js +105 -105
- package/src/utilities/__tests__/platformUtils.test.js +80 -87
- package/src/utilities/__tests__/structuredFileValidator.test.js +261 -263
- package/src/utilities/__tests__/toolConstants.test.js +92 -94
- package/src/utilities/__tests__/useIsTouchDevice.detect.test.js +114 -114
- package/src/utilities/__tests__/webUiUtilSync.test.js +117 -117
- package/src/utilities/attachmentValidator.js +284 -288
- package/src/utilities/authCache.js.backup-1779570472481 +121 -121
- package/src/utilities/browserStealth.js +631 -630
- package/src/utilities/configManager.js +616 -617
- package/src/utilities/directoryAccessManager.js +564 -565
- package/src/utilities/fileProcessor.js +308 -307
- package/src/utilities/humanBehavior.js +454 -453
- package/src/utilities/logger.js +479 -479
- package/src/utilities/structuredFileValidator.js +696 -699
- package/src/utilities/tagParser.js +5 -10
- package/src/utilities/userDataDir.js +308 -308
- package/node_modules/@isaacs/brace-expansion/dist/commonjs/index.js.map +0 -1
- package/node_modules/@isaacs/brace-expansion/dist/esm/index.js.map +0 -1
- package/node_modules/minipass/LICENSE +0 -15
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/LICENSE.md +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.js +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.js.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/package.json +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.js +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.js.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/package.json +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/LICENSE +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/package.json +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.d.ts +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.d.ts.map +0 -0
- /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/package.json +0 -0
|
@@ -1,866 +1,866 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentPool - Comprehensive unit tests (target: 80%+ line coverage)
|
|
3
|
-
* Tests agent lifecycle, state transitions, message queuing, pause/resume,
|
|
4
|
-
* conversation management, directory access, and edge cases.
|
|
5
|
-
*/
|
|
6
|
-
import { jest, describe, test, expect, beforeEach } from '@jest/globals';
|
|
7
|
-
import { createMockLogger, createMockConfig, createMockStateManager } from '../../__test-utils__/mockFactories.js';
|
|
8
|
-
|
|
9
|
-
// ── Mocks ────────────────────────────────────────────────────────────────────
|
|
10
|
-
const mockValidateAccessConfiguration = jest.fn().mockReturnValue({ valid: true });
|
|
11
|
-
const mockCreateProjectDefaults = jest.fn().mockReturnValue({
|
|
12
|
-
workingDirectory: '/tmp/project',
|
|
13
|
-
readOnlyDirectories: [],
|
|
14
|
-
writeEnabledDirectories: ['/tmp/project']
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
jest.unstable_mockModule('../../utilities/directoryAccessManager.js', () => {
|
|
18
|
-
const MockDAM = jest.fn().mockImplementation(() => ({
|
|
19
|
-
validateAccessConfiguration: mockValidateAccessConfiguration
|
|
20
|
-
}));
|
|
21
|
-
MockDAM.createProjectDefaults = mockCreateProjectDefaults;
|
|
22
|
-
return { default: MockDAM };
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
jest.unstable_mockModule('../../services/visualEditorBridge.js', () => ({
|
|
26
|
-
getVisualEditorBridge: jest.fn().mockReturnValue({
|
|
27
|
-
hasInstance: jest.fn().mockReturnValue(false),
|
|
28
|
-
stopInstance: jest.fn().mockResolvedValue(undefined)
|
|
29
|
-
})
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
const { default: AgentPool } = await import('../agentPool.js');
|
|
33
|
-
|
|
34
|
-
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
35
|
-
function makePool(overrides = {}) {
|
|
36
|
-
const config = createMockConfig(overrides.config);
|
|
37
|
-
const logger = createMockLogger();
|
|
38
|
-
const stateManager = createMockStateManager();
|
|
39
|
-
const contextManager = { getContext: jest.fn() };
|
|
40
|
-
const toolsRegistry = overrides.toolsRegistry || null;
|
|
41
|
-
const pool = new AgentPool(config, logger, stateManager, contextManager, toolsRegistry);
|
|
42
|
-
return { pool, config, logger, stateManager, contextManager };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function agentCfg(overrides = {}) {
|
|
46
|
-
return {
|
|
47
|
-
name: 'TestAgent',
|
|
48
|
-
systemPrompt: 'You are a test agent.',
|
|
49
|
-
preferredModel: 'test-model',
|
|
50
|
-
capabilities: [],
|
|
51
|
-
projectDir: '/tmp/project',
|
|
52
|
-
...overrides
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ── Tests ────────────────────────────────────────────────────────────────────
|
|
57
|
-
describe('AgentPool', () => {
|
|
58
|
-
let pool,
|
|
59
|
-
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
jest.clearAllMocks();
|
|
62
|
-
({ pool,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// ─── createAgent ───────────────────────────────────────────────────────
|
|
66
|
-
describe('createAgent', () => {
|
|
67
|
-
test('creates agent with correct default fields', async () => {
|
|
68
|
-
const agent = await pool.createAgent(agentCfg());
|
|
69
|
-
expect(agent.id).toMatch(/^agent-testagent-/);
|
|
70
|
-
expect(agent.name).toBe('TestAgent');
|
|
71
|
-
expect(agent.status).toBe('active');
|
|
72
|
-
expect(agent.mode).toBe('chat');
|
|
73
|
-
expect(agent.preferredModel).toBe('test-model');
|
|
74
|
-
expect(agent.conversations.full.messages).toEqual([]);
|
|
75
|
-
expect(agent.messageQueues.userMessages).toEqual([]);
|
|
76
|
-
expect(agent.messageQueues.interAgentMessages).toEqual([]);
|
|
77
|
-
expect(agent.messageQueues.toolResults).toEqual([]);
|
|
78
|
-
expect(agent.iterationCount).toBe(0);
|
|
79
|
-
expect(agent.maxIterations).toBe(10);
|
|
80
|
-
expect(agent.stopRequested).toBe(false);
|
|
81
|
-
expect(agent.taskList.tasks).toEqual([]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('generates unique IDs for different agents', async () => {
|
|
85
|
-
const a1 = await pool.createAgent(agentCfg({ name: 'Alpha' }));
|
|
86
|
-
const a2 = await pool.createAgent(agentCfg({ name: 'Beta' }));
|
|
87
|
-
expect(a1.id).not.toBe(a2.id);
|
|
88
|
-
expect(a1.id).toMatch(/^agent-alpha-/);
|
|
89
|
-
expect(a2.id).toMatch(/^agent-beta-/);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('applies mode from config', async () => {
|
|
93
|
-
const agent = await pool.createAgent(agentCfg({ mode: 'agent' }));
|
|
94
|
-
expect(agent.mode).toBe('agent');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('initializes model-specific conversation for preferredModel', async () => {
|
|
98
|
-
const agent = await pool.createAgent(agentCfg({ preferredModel: 'gpt-4' }));
|
|
99
|
-
expect(agent.conversations['gpt-4']).toBeDefined();
|
|
100
|
-
expect(agent.conversations['gpt-4'].messages).toEqual([]);
|
|
101
|
-
expect(agent.conversations['gpt-4'].compactizedMessages).toBeNull();
|
|
102
|
-
expect(agent.conversations['gpt-4'].compactizationCount).toBe(0);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('persists agent state after creation', async () => {
|
|
106
|
-
await pool.createAgent(agentCfg());
|
|
107
|
-
expect(stateManager.persistAgentState).toHaveBeenCalled();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('enhances system prompt via toolsRegistry when capabilities present', async () => {
|
|
111
|
-
const toolsRegistry = {
|
|
112
|
-
enhanceSystemPrompt: jest.fn().mockReturnValue('enhanced prompt')
|
|
113
|
-
};
|
|
114
|
-
const { pool: p2 } = makePool({ toolsRegistry });
|
|
115
|
-
const agent = await p2.createAgent(agentCfg({ capabilities: ['terminal'] }));
|
|
116
|
-
expect(toolsRegistry.enhanceSystemPrompt).toHaveBeenCalledWith(
|
|
117
|
-
'You are a test agent.',
|
|
118
|
-
['terminal'],
|
|
119
|
-
expect.objectContaining({ compact: false })
|
|
120
|
-
);
|
|
121
|
-
expect(agent.systemPrompt).toBe('enhanced prompt');
|
|
122
|
-
expect(agent.originalSystemPrompt).toBe('You are a test agent.');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('falls back to original prompt when enhancement throws', async () => {
|
|
126
|
-
const toolsRegistry = {
|
|
127
|
-
enhanceSystemPrompt: jest.fn().mockImplementation(() => { throw new Error('boom'); })
|
|
128
|
-
};
|
|
129
|
-
const { pool: p2 } = makePool({ toolsRegistry });
|
|
130
|
-
const agent = await p2.createAgent(agentCfg({ capabilities: ['terminal'] }));
|
|
131
|
-
expect(agent.systemPrompt).toBe('You are a test agent.');
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('skips enhancement when capabilities is empty', async () => {
|
|
135
|
-
const toolsRegistry = { enhanceSystemPrompt: jest.fn() };
|
|
136
|
-
const { pool: p2 } = makePool({ toolsRegistry });
|
|
137
|
-
await p2.createAgent(agentCfg({ capabilities: [] }));
|
|
138
|
-
expect(toolsRegistry.enhanceSystemPrompt).not.toHaveBeenCalled();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('validates directory access configuration when provided', async () => {
|
|
142
|
-
const dirAccess = { workingDirectory: '/custom', readOnlyDirectories: [], writeEnabledDirectories: ['/custom'] };
|
|
143
|
-
const agent = await pool.createAgent(agentCfg({ directoryAccess: dirAccess }));
|
|
144
|
-
expect(mockValidateAccessConfiguration).toHaveBeenCalledWith(dirAccess);
|
|
145
|
-
expect(agent.directoryAccess).toBe(dirAccess);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('throws on invalid directory access configuration', async () => {
|
|
149
|
-
mockValidateAccessConfiguration.mockReturnValueOnce({ valid: false, errors: ['bad path'] });
|
|
150
|
-
await expect(pool.createAgent(agentCfg({
|
|
151
|
-
directoryAccess: { workingDirectory: '/bad' }
|
|
152
|
-
}))).rejects.toThrow('Invalid directory access configuration');
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test('creates default directory access when none provided', async () => {
|
|
156
|
-
await pool.createAgent(agentCfg());
|
|
157
|
-
expect(mockCreateProjectDefaults).toHaveBeenCalledWith('/tmp/project');
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test('enforces MAX_AGENTS limit', async () => {
|
|
161
|
-
const { pool: p2 } = makePool({ config: { system: { maxAgentsPerProject: 2 } } });
|
|
162
|
-
await p2.createAgent(agentCfg({ name: 'A1' }));
|
|
163
|
-
await p2.createAgent(agentCfg({ name: 'A2' }));
|
|
164
|
-
await expect(p2.createAgent(agentCfg({ name: 'A3' }))).rejects.toThrow('Maximum agents per project exceeded');
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('stores sessionId, metadata, and platformProvided', async () => {
|
|
168
|
-
const agent = await pool.createAgent(agentCfg({
|
|
169
|
-
sessionId: 'sess-123',
|
|
170
|
-
metadata: { foo: 'bar' },
|
|
171
|
-
platformProvided: false
|
|
172
|
-
}));
|
|
173
|
-
expect(agent.sessionId).toBe('sess-123');
|
|
174
|
-
expect(agent.metadata).toEqual({ foo: 'bar' });
|
|
175
|
-
expect(agent.platformProvided).toBe(false);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test('uses process.cwd when no projectDir specified and no directoryAccess', async () => {
|
|
179
|
-
mockCreateProjectDefaults.mockClear();
|
|
180
|
-
await pool.createAgent(agentCfg({ projectDir: undefined }));
|
|
181
|
-
// Should call with process.cwd() as fallback
|
|
182
|
-
expect(mockCreateProjectDefaults).toHaveBeenCalled();
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// ─── getAgent ──────────────────────────────────────────────────────────
|
|
187
|
-
describe('getAgent', () => {
|
|
188
|
-
test('returns agent by ID after creation', async () => {
|
|
189
|
-
const created = await pool.createAgent(agentCfg());
|
|
190
|
-
const found = await pool.getAgent(created.id);
|
|
191
|
-
expect(found).toBe(created);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('returns null for non-existent agent', async () => {
|
|
195
|
-
expect(await pool.getAgent('nonexistent')).toBeNull();
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// ─── updateAgent ──────────────────────────────────────────────────────
|
|
200
|
-
describe('updateAgent', () => {
|
|
201
|
-
test('updates fields and preserves ID', async () => {
|
|
202
|
-
const agent = await pool.createAgent(agentCfg());
|
|
203
|
-
const updated = await pool.updateAgent(agent.id, { name: 'Updated', id: 'should-be-ignored' });
|
|
204
|
-
expect(updated.name).toBe('Updated');
|
|
205
|
-
expect(updated.id).toBe(agent.id);
|
|
206
|
-
expect(updated.lastModified).toBeDefined();
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test('throws for non-existent agent', async () => {
|
|
210
|
-
await expect(pool.updateAgent('nonexistent', { name: 'X' })).rejects.toThrow('Agent not found');
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
test('persists state after update', async () => {
|
|
214
|
-
const agent = await pool.createAgent(agentCfg());
|
|
215
|
-
stateManager.persistAgentState.mockClear();
|
|
216
|
-
await pool.updateAgent(agent.id, { name: 'Updated' });
|
|
217
|
-
expect(stateManager.persistAgentState).toHaveBeenCalled();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
test('validates directory access in updates', async () => {
|
|
221
|
-
const agent = await pool.createAgent(agentCfg());
|
|
222
|
-
mockValidateAccessConfiguration.mockReturnValueOnce({ valid: false, errors: ['invalid'] });
|
|
223
|
-
await expect(pool.updateAgent(agent.id, {
|
|
224
|
-
directoryAccess: { workingDirectory: '/bad' }
|
|
225
|
-
})).rejects.toThrow('Invalid directory access configuration');
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test('updates currentModel when preferredModel changes and copies conversation', async () => {
|
|
229
|
-
const agent = await pool.createAgent(agentCfg({ preferredModel: 'model-a' }));
|
|
230
|
-
// Add a message to old model conversation
|
|
231
|
-
agent.conversations['model-a'].messages.push({ role: 'user', content: 'old msg' });
|
|
232
|
-
const updated = await pool.updateAgent(agent.id, { preferredModel: 'model-b' });
|
|
233
|
-
expect(updated.currentModel).toBe('model-b');
|
|
234
|
-
expect(updated.conversations['model-b']).toBeDefined();
|
|
235
|
-
// Conversation should have been copied
|
|
236
|
-
expect(updated.conversations['model-b'].messages).toHaveLength(1);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
test('regenerates system prompt when capabilities change', async () => {
|
|
240
|
-
const toolsRegistry = { enhanceSystemPrompt: jest.fn().mockReturnValue('new enhanced') };
|
|
241
|
-
const { pool: p2 } = makePool({ toolsRegistry });
|
|
242
|
-
const agent = await p2.createAgent(agentCfg());
|
|
243
|
-
toolsRegistry.enhanceSystemPrompt.mockClear();
|
|
244
|
-
await p2.updateAgent(agent.id, { capabilities: ['terminal'] });
|
|
245
|
-
expect(toolsRegistry.enhanceSystemPrompt).toHaveBeenCalled();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test('regenerates system prompt when originalSystemPrompt is updated', async () => {
|
|
249
|
-
const toolsRegistry = { enhanceSystemPrompt: jest.fn().mockReturnValue('re-enhanced') };
|
|
250
|
-
const { pool: p2 } = makePool({ toolsRegistry });
|
|
251
|
-
const agent = await p2.createAgent(agentCfg());
|
|
252
|
-
toolsRegistry.enhanceSystemPrompt.mockClear();
|
|
253
|
-
const updated = await p2.updateAgent(agent.id, { originalSystemPrompt: 'Brand new prompt' });
|
|
254
|
-
expect(toolsRegistry.enhanceSystemPrompt).toHaveBeenCalled();
|
|
255
|
-
expect(updated.originalSystemPrompt).toBe('Brand new prompt');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// ─── deleteAgent ──────────────────────────────────────────────────────
|
|
260
|
-
describe('deleteAgent', () => {
|
|
261
|
-
test('removes agent from pool and returns success', async () => {
|
|
262
|
-
const agent = await pool.createAgent(agentCfg());
|
|
263
|
-
const result = await pool.deleteAgent(agent.id);
|
|
264
|
-
expect(result.success).toBe(true);
|
|
265
|
-
expect(result.remainingAgents).toBe(0);
|
|
266
|
-
expect(await pool.getAgent(agent.id)).toBeNull();
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// Was: 'throws for non-existent agent'. The contract changed —
|
|
270
|
-
// deleteAgent is now idempotent so the bulk-delete UX can wipe
|
|
271
|
-
// unloaded agents (the My Squadron group-delete used to fail with
|
|
272
|
-
// "Failed to delete N agents" whenever any target wasn't in memory).
|
|
273
|
-
// deleteAgentState is itself ENOENT-tolerant, so "not in pool, not
|
|
274
|
-
// on disk" still resolves to success — same end state.
|
|
275
|
-
test('is idempotent for an agent not in the pool (succeeds, clears persistent state)', async () => {
|
|
276
|
-
stateManager.deleteAgentState.mockClear();
|
|
277
|
-
const result = await pool.deleteAgent('nonexistent-agent-id');
|
|
278
|
-
expect(result.success).toBe(true);
|
|
279
|
-
// Still asked the state manager to clear it — best-effort cleanup.
|
|
280
|
-
expect(stateManager.deleteAgentState).toHaveBeenCalledWith('nonexistent-agent-id');
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
test('removes persistent state even when the agent was never loaded', async () => {
|
|
284
|
-
// Simulate an agent that exists on disk but isn't in memory
|
|
285
|
-
// (e.g. process restarted, or it was unloaded earlier).
|
|
286
|
-
stateManager.deleteAgentState.mockClear();
|
|
287
|
-
// No createAgent — pool.agents stays empty.
|
|
288
|
-
const result = await pool.deleteAgent('unloaded-but-on-disk');
|
|
289
|
-
expect(result.success).toBe(true);
|
|
290
|
-
expect(stateManager.deleteAgentState).toHaveBeenCalledWith('unloaded-but-on-disk');
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
test('cleans up maps (directory, paused, notification)', async () => {
|
|
294
|
-
const agent = await pool.createAgent(agentCfg());
|
|
295
|
-
pool.pausedAgents.set(agent.id, {});
|
|
296
|
-
pool.notificationQueue.set(agent.id, []);
|
|
297
|
-
await pool.deleteAgent(agent.id);
|
|
298
|
-
expect(pool.pausedAgents.has(agent.id)).toBe(false);
|
|
299
|
-
expect(pool.notificationQueue.has(agent.id)).toBe(false);
|
|
300
|
-
expect(pool.agentDirectory.has(agent.id)).toBe(false);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
test('agent is no longer retrievable after delete', async () => {
|
|
304
|
-
const agent = await pool.createAgent(agentCfg());
|
|
305
|
-
await pool.deleteAgent(agent.id);
|
|
306
|
-
const retrieved = await pool.getAgent(agent.id);
|
|
307
|
-
expect(retrieved).toBeFalsy();
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
// ─── unloadAgent ──────────────────────────────────────────────────────
|
|
312
|
-
describe('unloadAgent', () => {
|
|
313
|
-
test('removes from memory but persists state first', async () => {
|
|
314
|
-
const agent = await pool.createAgent(agentCfg());
|
|
315
|
-
stateManager.persistAgentState.mockClear();
|
|
316
|
-
const result = await pool.unloadAgent(agent.id);
|
|
317
|
-
expect(result.success).toBe(true);
|
|
318
|
-
expect(result.agentName).toBe('TestAgent');
|
|
319
|
-
expect(result.message).toContain('unloaded');
|
|
320
|
-
expect(await pool.getAgent(agent.id)).toBeNull();
|
|
321
|
-
expect(stateManager.persistAgentState).toHaveBeenCalled();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
test('throws for non-existent agent', async () => {
|
|
325
|
-
await expect(pool.unloadAgent('nonexistent')).rejects.toThrow('Agent not found');
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
test('calls scheduler.removeAgent if scheduler is set', async () => {
|
|
329
|
-
const mockScheduler = { removeAgent: jest.fn() };
|
|
330
|
-
pool.setScheduler(mockScheduler);
|
|
331
|
-
const agent = await pool.createAgent(agentCfg());
|
|
332
|
-
await pool.unloadAgent(agent.id);
|
|
333
|
-
expect(mockScheduler.removeAgent).toHaveBeenCalledWith(agent.id, 'unloaded');
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// ─── pauseAgent / resumeAgent ─────────────────────────────────────────
|
|
338
|
-
describe('pauseAgent', () => {
|
|
339
|
-
test('sets paused status and pausedUntil with seconds duration', async () => {
|
|
340
|
-
const agent = await pool.createAgent(agentCfg());
|
|
341
|
-
const result = await pool.pauseAgent(agent.id, 60, 'test pause');
|
|
342
|
-
expect(result.success).toBe(true);
|
|
343
|
-
expect(agent.status).toBe('paused');
|
|
344
|
-
expect(agent.pausedUntil).toBeDefined();
|
|
345
|
-
expect(pool.pausedAgents.has(agent.id)).toBe(true);
|
|
346
|
-
const pauseInfo = pool.pausedAgents.get(agent.id);
|
|
347
|
-
expect(pauseInfo.reason).toBe('test pause');
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
test('accepts Date as duration', async () => {
|
|
351
|
-
const agent = await pool.createAgent(agentCfg());
|
|
352
|
-
const future = new Date(Date.now() + 60000);
|
|
353
|
-
const result = await pool.pauseAgent(agent.id, future);
|
|
354
|
-
expect(result.success).toBe(true);
|
|
355
|
-
expect(new Date(agent.pausedUntil).getTime()).toBe(future.getTime());
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
test('caps duration to maxPauseDuration config', async () => {
|
|
359
|
-
const { pool: p2 } = makePool({ config: { system: { maxPauseDuration: 10 } } });
|
|
360
|
-
const agent = await p2.createAgent(agentCfg());
|
|
361
|
-
await p2.pauseAgent(agent.id, 9999, 'long pause');
|
|
362
|
-
const pauseEnd = new Date(agent.pausedUntil).getTime();
|
|
363
|
-
expect(pauseEnd).toBeLessThan(Date.now() + 15000);
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
test('throws for non-existent agent', async () => {
|
|
367
|
-
await expect(pool.pauseAgent('nonexistent', 60)).rejects.toThrow('Agent not found');
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
describe('resumeAgent (unpause)', () => {
|
|
372
|
-
test('resumes paused agent to active', async () => {
|
|
373
|
-
const agent = await pool.createAgent(agentCfg());
|
|
374
|
-
await pool.pauseAgent(agent.id, 300, 'test');
|
|
375
|
-
const result = await pool.resumeAgent(agent.id);
|
|
376
|
-
expect(result.success).toBe(true);
|
|
377
|
-
expect(agent.status).toBe('active');
|
|
378
|
-
expect(agent.pausedUntil).toBeNull();
|
|
379
|
-
expect(pool.pausedAgents.has(agent.id)).toBe(false);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
test('no-op for non-paused agent', async () => {
|
|
383
|
-
const agent = await pool.createAgent(agentCfg());
|
|
384
|
-
const result = await pool.resumeAgent(agent.id);
|
|
385
|
-
expect(result.success).toBe(true);
|
|
386
|
-
expect(result.message).toContain('not paused');
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
test('throws for non-existent agent', async () => {
|
|
390
|
-
await expect(pool.resumeAgent('nonexistent')).rejects.toThrow('Agent not found');
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
// ─── Message queue methods ────────────────────────────────────────────
|
|
395
|
-
describe('addUserMessage', () => {
|
|
396
|
-
test('pushes message with generated ID and timestamps', async () => {
|
|
397
|
-
const agent = await pool.createAgent(agentCfg());
|
|
398
|
-
await pool.addUserMessage(agent.id, { content: 'hello', role: 'user' });
|
|
399
|
-
expect(agent.messageQueues.userMessages).toHaveLength(1);
|
|
400
|
-
const msg = agent.messageQueues.userMessages[0];
|
|
401
|
-
expect(msg.content).toBe('hello');
|
|
402
|
-
expect(msg.id).toBeDefined();
|
|
403
|
-
expect(msg.queuedAt).toBeDefined();
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
test('auto-creates task for AGENT mode agents', async () => {
|
|
407
|
-
const agent = await pool.createAgent(agentCfg({ mode: 'agent' }));
|
|
408
|
-
await pool.addUserMessage(agent.id, { content: 'do something' });
|
|
409
|
-
expect(agent.taskList.tasks).toHaveLength(1);
|
|
410
|
-
expect(agent.taskList.tasks[0].source).toBe('auto-created');
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
test('throws for non-existent agent', async () => {
|
|
414
|
-
await expect(pool.addUserMessage('nonexistent', { content: 'hi' })).rejects.toThrow('Agent not found');
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
test('clears a future scheduler-applied delayEndTime on user message', async () => {
|
|
418
|
-
// A user message is an explicit signal to act now — any back-off
|
|
419
|
-
// delay set by the scheduler (rate-limit, network error, builtin
|
|
420
|
-
// tool delay) should evaporate rather than making the user wait
|
|
421
|
-
// out the remainder.
|
|
422
|
-
const agent = await pool.createAgent(agentCfg());
|
|
423
|
-
agent.delayEndTime = new Date(Date.now() + 60_000).toISOString();
|
|
424
|
-
|
|
425
|
-
await pool.addUserMessage(agent.id, { content: 'please act now' });
|
|
426
|
-
|
|
427
|
-
expect(agent.delayEndTime).toBeNull();
|
|
428
|
-
expect(agent.messageQueues.userMessages).toHaveLength(1);
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
test('leaves a past/expired delayEndTime alone', async () => {
|
|
432
|
-
// Already-expired delays don't need clearing — the scheduler ignores
|
|
433
|
-
// them on the next tick anyway. We only act on actively-blocking delays.
|
|
434
|
-
const agent = await pool.createAgent(agentCfg());
|
|
435
|
-
const pastIso = new Date(Date.now() - 1_000).toISOString();
|
|
436
|
-
agent.delayEndTime = pastIso;
|
|
437
|
-
|
|
438
|
-
await pool.addUserMessage(agent.id, { content: 'go' });
|
|
439
|
-
|
|
440
|
-
expect(agent.delayEndTime).toBe(pastIso);
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
// ── Auto-save user messages as plan/* memories ────────────────────
|
|
444
|
-
// Talisman case study: agents never voluntarily wrote memories
|
|
445
|
-
// and the user's literal asks vanished in compaction. The pool
|
|
446
|
-
// now auto-saves substantive user messages to the plan/* store
|
|
447
|
-
// as a system-level safety net (the agent itself can still write
|
|
448
|
-
// better-titled plans on top; these auto-saves are cleanup-safe).
|
|
449
|
-
|
|
450
|
-
describe('REGRESSION: auto-save substantive user messages as plan/*', () => {
|
|
451
|
-
test('calls _autoSaveUserMessageAsPlan for each user message (best-effort)', async () => {
|
|
452
|
-
const agent = await pool.createAgent(agentCfg());
|
|
453
|
-
const spy = jest.spyOn(pool, '_autoSaveUserMessageAsPlan').mockResolvedValue(undefined);
|
|
454
|
-
await pool.addUserMessage(agent.id, { content: 'please do a thing that is long enough to count as substantive content here, more than 120 chars total for the heuristic', role: 'user' });
|
|
455
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
456
|
-
expect(spy.mock.calls[0][0]).toBe(agent.id);
|
|
457
|
-
expect(spy.mock.calls[0][1].content).toMatch(/please do a thing/);
|
|
458
|
-
spy.mockRestore();
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
test('a memory-service failure does NOT block the message-enqueue path', async () => {
|
|
462
|
-
// Auto-save is best-effort. If memoryService blows up, the
|
|
463
|
-
// user's message must still land on the queue.
|
|
464
|
-
const agent = await pool.createAgent(agentCfg());
|
|
465
|
-
jest.spyOn(pool, '_autoSaveUserMessageAsPlan').mockRejectedValue(new Error('memory store offline'));
|
|
466
|
-
await pool.addUserMessage(agent.id, { content: 'hello', role: 'user' });
|
|
467
|
-
expect(agent.messageQueues.userMessages).toHaveLength(1);
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
describe('_looksSubstantive heuristic — pollution audit', () => {
|
|
472
|
-
// ── TRUE POSITIVES — these SHOULD be saved ─────────────────────
|
|
473
|
-
test('TRUE POSITIVE: numbered request (Talisman literal case)', () => {
|
|
474
|
-
const msg = `Amazing! a few more things
|
|
475
|
-
1. "choose your hero" page - lets put a nice fantasy image at the background.
|
|
476
|
-
2. play screen - why is the board still round? plus, not all nodes have their own art.
|
|
477
|
-
3. when we roll for combat - there is no dice animation visible`;
|
|
478
|
-
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
test('TRUE POSITIVE: multi-paragraph feature request', () => {
|
|
482
|
-
const msg = 'Implement OAuth login. Replace the existing session-cookie flow with Google and Microsoft sign-in. Migrate existing users by linking their email to the new auth records on first sign-in. Update the docs.';
|
|
483
|
-
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
test('TRUE POSITIVE: numbered bug list (descriptions, not paths)', () => {
|
|
487
|
-
const msg = `Fix these bugs:\n1. login button does nothing on Safari\n2. cart total wrong when discount applied\n3. 500 error on /api/orders/export`;
|
|
488
|
-
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
test('TRUE POSITIVE: bulleted plan with imperative verbs', () => {
|
|
492
|
-
const msg = `fixes needed:\n- fix bug in login flow that breaks on slow networks\n- add retry logic to the cache layer\n- write a test for the missing error case`;
|
|
493
|
-
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
// ── POLLUTION RISKS — these should NOT be saved ────────────────
|
|
497
|
-
test('POLLUTION: short ack is rejected', () => {
|
|
498
|
-
expect(pool._looksSubstantive('ok thanks')).toBe(false);
|
|
499
|
-
expect(pool._looksSubstantive('thanks!')).toBe(false);
|
|
500
|
-
expect(pool._looksSubstantive('yes please')).toBe(false);
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
test('POLLUTION: question with no imperative is rejected (user wants an answer, not a plan)', () => {
|
|
504
|
-
const msg = 'what does this function do? I see it referenced in three places but the docs do not explain its purpose at all.';
|
|
505
|
-
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
test('POLLUTION: numbered list of QUESTIONS is rejected (not a plan)', () => {
|
|
509
|
-
const msg = `quick questions:\n1. why is the cache key the user id?\n2. is the rate limit per-user or per-ip?`;
|
|
510
|
-
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
test('POLLUTION: list of file paths is rejected (just references)', () => {
|
|
514
|
-
const msg = `look at these:\n- src/auth/login.js\n- src/auth/session.js\n- src/middleware/auth.js\n- tests/auth.test.js`;
|
|
515
|
-
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
test('POLLUTION: long pleasantry with no imperative is rejected', () => {
|
|
519
|
-
const msg = 'hey, hope you are well today, that was a good run earlier and I am happy with the progress so far!';
|
|
520
|
-
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
test('POLLUTION: trivial numbered nonsense is rejected (too short under list rule)', () => {
|
|
524
|
-
expect(pool._looksSubstantive('1. yes 2. no 3. maybe')).toBe(false);
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
test('POLLUTION: reading-comprehension feedback is rejected', () => {
|
|
528
|
-
expect(pool._looksSubstantive('I do not understand what you wrote in your last message. Can you explain it differently?')).toBe(false);
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
test('POLLUTION: agreement / confirmation is rejected', () => {
|
|
532
|
-
expect(pool._looksSubstantive('yes, please proceed with that plan. it looks correct to me.')).toBe(false);
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
test('POLLUTION: simple one-shot instruction is rejected (too short)', () => {
|
|
536
|
-
expect(pool._looksSubstantive('run the tests again')).toBe(false);
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
// ── Defensive corner cases ─────────────────────────────────────
|
|
540
|
-
test('tool-result wrappers are rejected', () => {
|
|
541
|
-
expect(pool._looksSubstantive('[Tool Results — 1 result from 1 tool batch: filesystem] {...lots of content...}')).toBe(false);
|
|
542
|
-
expect(pool._looksSubstantive('[Previous Task — Final Tool Results] [jobdone] {...}')).toBe(false);
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
test('non-string content is rejected defensively', () => {
|
|
546
|
-
expect(pool._looksSubstantive(null)).toBe(false);
|
|
547
|
-
expect(pool._looksSubstantive(undefined)).toBe(false);
|
|
548
|
-
expect(pool._looksSubstantive({ obj: true })).toBe(false);
|
|
549
|
-
});
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
describe('helpers: question / reference / imperative detection', () => {
|
|
553
|
-
test('_dominatedByQuestions detects majority-question content', () => {
|
|
554
|
-
expect(pool._dominatedByQuestions('what does X do?')).toBe(true);
|
|
555
|
-
expect(pool._dominatedByQuestions('1. what?\n2. why?\n3. how?')).toBe(true);
|
|
556
|
-
expect(pool._dominatedByQuestions('fix the bug')).toBe(false);
|
|
557
|
-
// Mixed: 1 question + 2 commands → not dominated.
|
|
558
|
-
expect(pool._dominatedByQuestions('why is this slow?\nfix the cache\nadd metrics')).toBe(false);
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
test('_listItemsAreJustReferences detects path-only lists', () => {
|
|
562
|
-
const refList = `look:\n- src/a.js\n- src/b.js\n- src/c.js`;
|
|
563
|
-
expect(pool._listItemsAreJustReferences(refList)).toBe(true);
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
test('_listItemsAreJustReferences does NOT flag bug descriptions', () => {
|
|
567
|
-
const bugList = `bugs:\n- login breaks on Safari\n- cart total wrong with discount`;
|
|
568
|
-
expect(pool._listItemsAreJustReferences(bugList)).toBe(false);
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
test('_hasImperativeSignal matches common command verbs', () => {
|
|
572
|
-
expect(pool._hasImperativeSignal('fix the login bug')).toBe(true);
|
|
573
|
-
expect(pool._hasImperativeSignal('add a retry')).toBe(true);
|
|
574
|
-
expect(pool._hasImperativeSignal('refactor this module')).toBe(true);
|
|
575
|
-
expect(pool._hasImperativeSignal('what does this do')).toBe(false);
|
|
576
|
-
expect(pool._hasImperativeSignal('looks good')).toBe(false);
|
|
577
|
-
});
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
describe('dedup + cap (Jaccard similarity, AUTO_PLAN_CAP)', () => {
|
|
581
|
-
test('_tokenize lowercases + drops short words + strips punctuation', () => {
|
|
582
|
-
const tokens = pool._tokenize('Fix THE login button on iOS!');
|
|
583
|
-
// 'the', 'on' are <3 chars dropped; 'fix', 'login', 'button', 'ios' remain.
|
|
584
|
-
expect(tokens.has('fix')).toBe(true);
|
|
585
|
-
expect(tokens.has('login')).toBe(true);
|
|
586
|
-
expect(tokens.has('button')).toBe(true);
|
|
587
|
-
expect(tokens.has('ios')).toBe(true);
|
|
588
|
-
expect(tokens.has('the')).toBe(false);
|
|
589
|
-
expect(tokens.has('on')).toBe(false);
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
test('_jaccard returns 1 for identical text, 0 for disjoint, 1 for both empty', () => {
|
|
593
|
-
const a = pool._tokenize('fix the login button');
|
|
594
|
-
const b = pool._tokenize('fix the login button');
|
|
595
|
-
const c = pool._tokenize('build the cache layer');
|
|
596
|
-
expect(pool._jaccard(a, b)).toBe(1);
|
|
597
|
-
expect(pool._jaccard(a, c)).toBe(0);
|
|
598
|
-
expect(pool._jaccard(new Set(), new Set())).toBe(1);
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
test('_overlapCoefficient catches "I repeat my old message" near-duplicate (containment ≥0.85)', () => {
|
|
602
|
-
// Real Talisman case: user repeated themselves verbatim with
|
|
603
|
-
// an "I repeat my old message" preamble. Jaccard alone marks
|
|
604
|
-
// these as merely "similar" because the preamble adds new
|
|
605
|
-
// words; the overlap coefficient (intersection / smaller-set)
|
|
606
|
-
// correctly reports that the original is fully contained in
|
|
607
|
-
// the repeated version.
|
|
608
|
-
const original = pool._tokenize(
|
|
609
|
-
`1. "choose your hero" page - lets put a nice fantasy image at the background. also, lets create a character card art (general)`,
|
|
610
|
-
);
|
|
611
|
-
const repeated = pool._tokenize(
|
|
612
|
-
`Amazing! I repeat my old message - a few more things\n\n"choose your hero" page - lets put a nice fantasy image at the background. also, lets create a character card art (general)`,
|
|
613
|
-
);
|
|
614
|
-
expect(pool._overlapCoefficient(original, repeated)).toBeGreaterThanOrEqual(0.85);
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
test('_overlapCoefficient is 0 for disjoint sets, 1 for one fully contained in the other', () => {
|
|
618
|
-
const a = pool._tokenize('fix login button');
|
|
619
|
-
const b = pool._tokenize('fix login button additional extra words');
|
|
620
|
-
const c = pool._tokenize('build cache layer');
|
|
621
|
-
// 'a' fully contained in 'b' → 1.0
|
|
622
|
-
expect(pool._overlapCoefficient(a, b)).toBe(1);
|
|
623
|
-
// disjoint
|
|
624
|
-
expect(pool._overlapCoefficient(a, c)).toBe(0);
|
|
625
|
-
});
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
test('no-ops when delayEndTime is null', async () => {
|
|
629
|
-
const agent = await pool.createAgent(agentCfg());
|
|
630
|
-
agent.delayEndTime = null;
|
|
631
|
-
|
|
632
|
-
await pool.addUserMessage(agent.id, { content: 'go' });
|
|
633
|
-
|
|
634
|
-
expect(agent.delayEndTime).toBeNull();
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
test('broadcasts agent state update when a delay was cleared', async () => {
|
|
638
|
-
// The UI's delay chip listens for `agent_state_updated` — when we
|
|
639
|
-
// clear a delay we should surface it immediately so the chip
|
|
640
|
-
// disappears without a reload.
|
|
641
|
-
const agent = await pool.createAgent(agentCfg());
|
|
642
|
-
agent.delayEndTime = new Date(Date.now() + 30_000).toISOString();
|
|
643
|
-
|
|
644
|
-
const broadcast = jest.fn().mockResolvedValue(undefined);
|
|
645
|
-
pool.scheduler = { broadcastAgentStateUpdate: broadcast };
|
|
646
|
-
|
|
647
|
-
await pool.addUserMessage(agent.id, { content: 'now' });
|
|
648
|
-
|
|
649
|
-
expect(broadcast).toHaveBeenCalledWith(agent.id, 'user-message-clears-delay');
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
test('does not broadcast when no delay was set', async () => {
|
|
653
|
-
const agent = await pool.createAgent(agentCfg());
|
|
654
|
-
const broadcast = jest.fn().mockResolvedValue(undefined);
|
|
655
|
-
pool.scheduler = { broadcastAgentStateUpdate: broadcast };
|
|
656
|
-
|
|
657
|
-
await pool.addUserMessage(agent.id, { content: 'hi' });
|
|
658
|
-
|
|
659
|
-
expect(broadcast).not.toHaveBeenCalled();
|
|
660
|
-
});
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
describe('addInterAgentMessage', () => {
|
|
664
|
-
test('pushes message with sender info', async () => {
|
|
665
|
-
const agent = await pool.createAgent(agentCfg());
|
|
666
|
-
await pool.addInterAgentMessage(agent.id, { content: 'inter-msg', sender: 'agent-x', senderName: 'AgentX' });
|
|
667
|
-
expect(agent.messageQueues.interAgentMessages).toHaveLength(1);
|
|
668
|
-
expect(agent.messageQueues.interAgentMessages[0].content).toBe('inter-msg');
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
test('auto-creates task for AGENT mode agents with sender label', async () => {
|
|
672
|
-
const agent = await pool.createAgent(agentCfg({ mode: 'agent' }));
|
|
673
|
-
await pool.addInterAgentMessage(agent.id, { content: 'help', sender: 'other', senderName: 'OtherAgent' });
|
|
674
|
-
expect(agent.taskList.tasks).toHaveLength(1);
|
|
675
|
-
expect(agent.taskList.tasks[0].title).toContain('inter-agent');
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
test('throws for non-existent agent', async () => {
|
|
679
|
-
await expect(pool.addInterAgentMessage('nonexistent', { content: 'hi' })).rejects.toThrow('Agent not found');
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
describe('addToolResult', () => {
|
|
684
|
-
test('pushes result with generated ID and timestamps', async () => {
|
|
685
|
-
const agent = await pool.createAgent(agentCfg());
|
|
686
|
-
await pool.addToolResult(agent.id, { toolId: 'terminal', status: 'completed', result: 'ok' });
|
|
687
|
-
expect(agent.messageQueues.toolResults).toHaveLength(1);
|
|
688
|
-
const r = agent.messageQueues.toolResults[0];
|
|
689
|
-
expect(r.toolId).toBe('terminal');
|
|
690
|
-
expect(r.id).toBeDefined();
|
|
691
|
-
expect(r.queuedAt).toBeDefined();
|
|
692
|
-
});
|
|
693
|
-
|
|
694
|
-
test('throws for non-existent agent', async () => {
|
|
695
|
-
await expect(pool.addToolResult('nonexistent', {})).rejects.toThrow('Agent not found');
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
// ─── clearConversation ────────────────────────────────────────────────
|
|
700
|
-
describe('clearConversation', () => {
|
|
701
|
-
test('empties all conversation history, queues, and task list', async () => {
|
|
702
|
-
const agent = await pool.createAgent(agentCfg());
|
|
703
|
-
agent.conversations.full.messages.push({ role: 'user', content: 'old' });
|
|
704
|
-
agent.messageQueues.userMessages.push({ content: 'queued' });
|
|
705
|
-
agent.messageQueues.toolResults.push({ toolId: 'x' });
|
|
706
|
-
agent.messageQueues.interAgentMessages.push({ content: 'inter' });
|
|
707
|
-
agent.taskList.tasks.push({ id: 'task1', title: 'do thing' });
|
|
708
|
-
|
|
709
|
-
const result = await pool.clearConversation(agent.id);
|
|
710
|
-
expect(result.success).toBe(true);
|
|
711
|
-
expect(result.previousMessageCount).toBe(1);
|
|
712
|
-
expect(agent.conversations.full.messages).toEqual([]);
|
|
713
|
-
expect(agent.messageQueues.userMessages).toEqual([]);
|
|
714
|
-
expect(agent.messageQueues.toolResults).toEqual([]);
|
|
715
|
-
expect(agent.messageQueues.interAgentMessages).toEqual([]);
|
|
716
|
-
expect(agent.taskList.tasks).toEqual([]);
|
|
717
|
-
expect(agent.currentTask).toBeNull();
|
|
718
|
-
expect(agent.iterationCount).toBe(0);
|
|
719
|
-
});
|
|
720
|
-
|
|
721
|
-
test('resets model-specific conversations', async () => {
|
|
722
|
-
const agent = await pool.createAgent(agentCfg({ preferredModel: 'model-a' }));
|
|
723
|
-
agent.conversations['model-a'].messages.push({ role: 'user', content: 'msg' });
|
|
724
|
-
await pool.clearConversation(agent.id);
|
|
725
|
-
expect(agent.conversations['model-a'].messages).toEqual([]);
|
|
726
|
-
expect(agent.conversations['model-a'].compactizedMessages).toBeNull();
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
test('throws for non-existent agent', async () => {
|
|
730
|
-
await expect(pool.clearConversation('nonexistent')).rejects.toThrow('Agent not found');
|
|
731
|
-
});
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
// ─── listActiveAgents / getAllAgents ───────────────────────────────────
|
|
735
|
-
describe('listActiveAgents', () => {
|
|
736
|
-
test('returns shaped array of all agents', async () => {
|
|
737
|
-
await pool.createAgent(agentCfg({ name: 'A1' }));
|
|
738
|
-
await pool.createAgent(agentCfg({ name: 'A2' }));
|
|
739
|
-
const list = await pool.listActiveAgents();
|
|
740
|
-
expect(list).toHaveLength(2);
|
|
741
|
-
expect(list[0]).toHaveProperty('id');
|
|
742
|
-
expect(list[0]).toHaveProperty('name');
|
|
743
|
-
expect(list[0]).toHaveProperty('mode');
|
|
744
|
-
expect(list[0]).toHaveProperty('capabilities');
|
|
745
|
-
expect(list[0]).toHaveProperty('isPaused');
|
|
746
|
-
expect(list[0]).toHaveProperty('messageCount');
|
|
747
|
-
});
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
describe('getAllAgents', () => {
|
|
751
|
-
test('returns all agents and auto-resumes expired pauses', async () => {
|
|
752
|
-
const agent = await pool.createAgent(agentCfg());
|
|
753
|
-
agent.status = 'paused';
|
|
754
|
-
agent.pausedUntil = new Date(Date.now() - 1000).toISOString();
|
|
755
|
-
const all = await pool.getAllAgents();
|
|
756
|
-
const found = all.find(a => a.id === agent.id);
|
|
757
|
-
expect(found.status).toBe('active');
|
|
758
|
-
expect(found.pausedUntil).toBeNull();
|
|
759
|
-
});
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
// ─── persistAgentState ────────────────────────────────────────────────
|
|
763
|
-
describe('persistAgentState', () => {
|
|
764
|
-
test('delegates to stateManager with agent object', async () => {
|
|
765
|
-
const agent = await pool.createAgent(agentCfg());
|
|
766
|
-
stateManager.persistAgentState.mockClear();
|
|
767
|
-
await pool.persistAgentState(agent.id);
|
|
768
|
-
expect(stateManager.persistAgentState).toHaveBeenCalledWith(agent);
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
test('throws for non-existent agent', async () => {
|
|
772
|
-
await expect(pool.persistAgentState('nonexistent')).rejects.toThrow('Agent not found');
|
|
773
|
-
});
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
// ─── Private helpers ──────────────────────────────────────────────────
|
|
777
|
-
describe('private helpers', () => {
|
|
778
|
-
test('_generateAgentId sanitizes name', () => {
|
|
779
|
-
const id = pool._generateAgentId('Hello World!');
|
|
780
|
-
expect(id).toMatch(/^agent-hello-world--\d+$/);
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
test('_isAgentPaused returns false for active agent', () => {
|
|
784
|
-
expect(pool._isAgentPaused({ status: 'active', pausedUntil: null })).toBe(false);
|
|
785
|
-
});
|
|
786
|
-
|
|
787
|
-
test('_isAgentPaused returns true for future pause', () => {
|
|
788
|
-
const future = new Date(Date.now() + 60000).toISOString();
|
|
789
|
-
expect(pool._isAgentPaused({ status: 'paused', pausedUntil: future })).toBe(true);
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
test('_isAgentPaused returns false for expired pause', () => {
|
|
793
|
-
const past = new Date(Date.now() - 60000).toISOString();
|
|
794
|
-
expect(pool._isAgentPaused({ status: 'paused', pausedUntil: past })).toBe(false);
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
test('_isPauseExpired returns true when no pausedUntil', () => {
|
|
798
|
-
expect(pool._isPauseExpired({})).toBe(true);
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
test('_isPauseExpired returns false when future pause', () => {
|
|
802
|
-
const future = new Date(Date.now() + 60000).toISOString();
|
|
803
|
-
expect(pool._isPauseExpired({ pausedUntil: future })).toBe(false);
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
test('_getFirstUserMessageSnippet returns null for empty conversations', () => {
|
|
807
|
-
const agent = { conversations: { full: { messages: [] } } };
|
|
808
|
-
expect(pool._getFirstUserMessageSnippet(agent)).toBeNull();
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
test('_getFirstUserMessageSnippet returns snippet for first user message', () => {
|
|
812
|
-
const agent = {
|
|
813
|
-
conversations: { full: { messages: [
|
|
814
|
-
{ role: 'assistant', content: 'hi' },
|
|
815
|
-
{ role: 'user', content: 'Build me a web app', type: 'consolidated-input' }
|
|
816
|
-
] } }
|
|
817
|
-
};
|
|
818
|
-
expect(pool._getFirstUserMessageSnippet(agent)).toBe('Build me a web app');
|
|
819
|
-
});
|
|
820
|
-
|
|
821
|
-
test('_getFirstUserMessageSnippet truncates long snippets', () => {
|
|
822
|
-
const longMsg = 'A'.repeat(200);
|
|
823
|
-
const agent = {
|
|
824
|
-
conversations: { full: { messages: [
|
|
825
|
-
{ role: 'user', content: longMsg }
|
|
826
|
-
] } }
|
|
827
|
-
};
|
|
828
|
-
const snippet = pool._getFirstUserMessageSnippet(agent);
|
|
829
|
-
expect(snippet.length).toBeLessThanOrEqual(120);
|
|
830
|
-
expect(snippet).toContain('...');
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
test('_queueNotification stores notification for agent', () => {
|
|
834
|
-
pool._queueNotification('agent-1', { content: 'test' });
|
|
835
|
-
expect(pool.notificationQueue.has('agent-1')).toBe(true);
|
|
836
|
-
expect(pool.notificationQueue.get('agent-1')).toHaveLength(1);
|
|
837
|
-
});
|
|
838
|
-
|
|
839
|
-
test('_generateAgentDescription includes capabilities', () => {
|
|
840
|
-
const desc = pool._generateAgentDescription({ name: 'Bot', type: 'user-created', capabilities: ['terminal', 'filesystem'] });
|
|
841
|
-
expect(desc).toContain('Bot');
|
|
842
|
-
expect(desc).toContain('terminal');
|
|
843
|
-
});
|
|
844
|
-
});
|
|
845
|
-
|
|
846
|
-
// ─── setters ──────────────────────────────────────────────────────────
|
|
847
|
-
describe('setter methods', () => {
|
|
848
|
-
test('setToolsRegistry stores the registry', () => {
|
|
849
|
-
const registry = { getTool: jest.fn() };
|
|
850
|
-
pool.setToolsRegistry(registry);
|
|
851
|
-
expect(pool.toolsRegistry).toBe(registry);
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
test('setMessageProcessor stores the reference', () => {
|
|
855
|
-
const mp = { processMessage: jest.fn() };
|
|
856
|
-
pool.setMessageProcessor(mp);
|
|
857
|
-
expect(pool.messageProcessor).toBe(mp);
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
test('setScheduler stores the scheduler reference', () => {
|
|
861
|
-
const sched = { addAgent: jest.fn() };
|
|
862
|
-
pool.setScheduler(sched);
|
|
863
|
-
expect(pool.scheduler).toBe(sched);
|
|
864
|
-
});
|
|
865
|
-
});
|
|
866
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* AgentPool - Comprehensive unit tests (target: 80%+ line coverage)
|
|
3
|
+
* Tests agent lifecycle, state transitions, message queuing, pause/resume,
|
|
4
|
+
* conversation management, directory access, and edge cases.
|
|
5
|
+
*/
|
|
6
|
+
import { jest, describe, test, expect, beforeEach } from '@jest/globals';
|
|
7
|
+
import { createMockLogger, createMockConfig, createMockStateManager } from '../../__test-utils__/mockFactories.js';
|
|
8
|
+
|
|
9
|
+
// ── Mocks ────────────────────────────────────────────────────────────────────
|
|
10
|
+
const mockValidateAccessConfiguration = jest.fn().mockReturnValue({ valid: true });
|
|
11
|
+
const mockCreateProjectDefaults = jest.fn().mockReturnValue({
|
|
12
|
+
workingDirectory: '/tmp/project',
|
|
13
|
+
readOnlyDirectories: [],
|
|
14
|
+
writeEnabledDirectories: ['/tmp/project']
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
jest.unstable_mockModule('../../utilities/directoryAccessManager.js', () => {
|
|
18
|
+
const MockDAM = jest.fn().mockImplementation(() => ({
|
|
19
|
+
validateAccessConfiguration: mockValidateAccessConfiguration
|
|
20
|
+
}));
|
|
21
|
+
MockDAM.createProjectDefaults = mockCreateProjectDefaults;
|
|
22
|
+
return { default: MockDAM };
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
jest.unstable_mockModule('../../services/visualEditorBridge.js', () => ({
|
|
26
|
+
getVisualEditorBridge: jest.fn().mockReturnValue({
|
|
27
|
+
hasInstance: jest.fn().mockReturnValue(false),
|
|
28
|
+
stopInstance: jest.fn().mockResolvedValue(undefined)
|
|
29
|
+
})
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const { default: AgentPool } = await import('../agentPool.js');
|
|
33
|
+
|
|
34
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
35
|
+
function makePool(overrides = {}) {
|
|
36
|
+
const config = createMockConfig(overrides.config);
|
|
37
|
+
const logger = createMockLogger();
|
|
38
|
+
const stateManager = createMockStateManager();
|
|
39
|
+
const contextManager = { getContext: jest.fn() };
|
|
40
|
+
const toolsRegistry = overrides.toolsRegistry || null;
|
|
41
|
+
const pool = new AgentPool(config, logger, stateManager, contextManager, toolsRegistry);
|
|
42
|
+
return { pool, config, logger, stateManager, contextManager };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function agentCfg(overrides = {}) {
|
|
46
|
+
return {
|
|
47
|
+
name: 'TestAgent',
|
|
48
|
+
systemPrompt: 'You are a test agent.',
|
|
49
|
+
preferredModel: 'test-model',
|
|
50
|
+
capabilities: [],
|
|
51
|
+
projectDir: '/tmp/project',
|
|
52
|
+
...overrides
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── Tests ────────────────────────────────────────────────────────────────────
|
|
57
|
+
describe('AgentPool', () => {
|
|
58
|
+
let pool, stateManager;
|
|
59
|
+
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
jest.clearAllMocks();
|
|
62
|
+
({ pool, stateManager } = makePool());
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// ─── createAgent ───────────────────────────────────────────────────────
|
|
66
|
+
describe('createAgent', () => {
|
|
67
|
+
test('creates agent with correct default fields', async () => {
|
|
68
|
+
const agent = await pool.createAgent(agentCfg());
|
|
69
|
+
expect(agent.id).toMatch(/^agent-testagent-/);
|
|
70
|
+
expect(agent.name).toBe('TestAgent');
|
|
71
|
+
expect(agent.status).toBe('active');
|
|
72
|
+
expect(agent.mode).toBe('chat');
|
|
73
|
+
expect(agent.preferredModel).toBe('test-model');
|
|
74
|
+
expect(agent.conversations.full.messages).toEqual([]);
|
|
75
|
+
expect(agent.messageQueues.userMessages).toEqual([]);
|
|
76
|
+
expect(agent.messageQueues.interAgentMessages).toEqual([]);
|
|
77
|
+
expect(agent.messageQueues.toolResults).toEqual([]);
|
|
78
|
+
expect(agent.iterationCount).toBe(0);
|
|
79
|
+
expect(agent.maxIterations).toBe(10);
|
|
80
|
+
expect(agent.stopRequested).toBe(false);
|
|
81
|
+
expect(agent.taskList.tasks).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('generates unique IDs for different agents', async () => {
|
|
85
|
+
const a1 = await pool.createAgent(agentCfg({ name: 'Alpha' }));
|
|
86
|
+
const a2 = await pool.createAgent(agentCfg({ name: 'Beta' }));
|
|
87
|
+
expect(a1.id).not.toBe(a2.id);
|
|
88
|
+
expect(a1.id).toMatch(/^agent-alpha-/);
|
|
89
|
+
expect(a2.id).toMatch(/^agent-beta-/);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('applies mode from config', async () => {
|
|
93
|
+
const agent = await pool.createAgent(agentCfg({ mode: 'agent' }));
|
|
94
|
+
expect(agent.mode).toBe('agent');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('initializes model-specific conversation for preferredModel', async () => {
|
|
98
|
+
const agent = await pool.createAgent(agentCfg({ preferredModel: 'gpt-4' }));
|
|
99
|
+
expect(agent.conversations['gpt-4']).toBeDefined();
|
|
100
|
+
expect(agent.conversations['gpt-4'].messages).toEqual([]);
|
|
101
|
+
expect(agent.conversations['gpt-4'].compactizedMessages).toBeNull();
|
|
102
|
+
expect(agent.conversations['gpt-4'].compactizationCount).toBe(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('persists agent state after creation', async () => {
|
|
106
|
+
await pool.createAgent(agentCfg());
|
|
107
|
+
expect(stateManager.persistAgentState).toHaveBeenCalled();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('enhances system prompt via toolsRegistry when capabilities present', async () => {
|
|
111
|
+
const toolsRegistry = {
|
|
112
|
+
enhanceSystemPrompt: jest.fn().mockReturnValue('enhanced prompt')
|
|
113
|
+
};
|
|
114
|
+
const { pool: p2 } = makePool({ toolsRegistry });
|
|
115
|
+
const agent = await p2.createAgent(agentCfg({ capabilities: ['terminal'] }));
|
|
116
|
+
expect(toolsRegistry.enhanceSystemPrompt).toHaveBeenCalledWith(
|
|
117
|
+
'You are a test agent.',
|
|
118
|
+
['terminal'],
|
|
119
|
+
expect.objectContaining({ compact: false })
|
|
120
|
+
);
|
|
121
|
+
expect(agent.systemPrompt).toBe('enhanced prompt');
|
|
122
|
+
expect(agent.originalSystemPrompt).toBe('You are a test agent.');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('falls back to original prompt when enhancement throws', async () => {
|
|
126
|
+
const toolsRegistry = {
|
|
127
|
+
enhanceSystemPrompt: jest.fn().mockImplementation(() => { throw new Error('boom'); })
|
|
128
|
+
};
|
|
129
|
+
const { pool: p2 } = makePool({ toolsRegistry });
|
|
130
|
+
const agent = await p2.createAgent(agentCfg({ capabilities: ['terminal'] }));
|
|
131
|
+
expect(agent.systemPrompt).toBe('You are a test agent.');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('skips enhancement when capabilities is empty', async () => {
|
|
135
|
+
const toolsRegistry = { enhanceSystemPrompt: jest.fn() };
|
|
136
|
+
const { pool: p2 } = makePool({ toolsRegistry });
|
|
137
|
+
await p2.createAgent(agentCfg({ capabilities: [] }));
|
|
138
|
+
expect(toolsRegistry.enhanceSystemPrompt).not.toHaveBeenCalled();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('validates directory access configuration when provided', async () => {
|
|
142
|
+
const dirAccess = { workingDirectory: '/custom', readOnlyDirectories: [], writeEnabledDirectories: ['/custom'] };
|
|
143
|
+
const agent = await pool.createAgent(agentCfg({ directoryAccess: dirAccess }));
|
|
144
|
+
expect(mockValidateAccessConfiguration).toHaveBeenCalledWith(dirAccess);
|
|
145
|
+
expect(agent.directoryAccess).toBe(dirAccess);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('throws on invalid directory access configuration', async () => {
|
|
149
|
+
mockValidateAccessConfiguration.mockReturnValueOnce({ valid: false, errors: ['bad path'] });
|
|
150
|
+
await expect(pool.createAgent(agentCfg({
|
|
151
|
+
directoryAccess: { workingDirectory: '/bad' }
|
|
152
|
+
}))).rejects.toThrow('Invalid directory access configuration');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('creates default directory access when none provided', async () => {
|
|
156
|
+
await pool.createAgent(agentCfg());
|
|
157
|
+
expect(mockCreateProjectDefaults).toHaveBeenCalledWith('/tmp/project');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('enforces MAX_AGENTS limit', async () => {
|
|
161
|
+
const { pool: p2 } = makePool({ config: { system: { maxAgentsPerProject: 2 } } });
|
|
162
|
+
await p2.createAgent(agentCfg({ name: 'A1' }));
|
|
163
|
+
await p2.createAgent(agentCfg({ name: 'A2' }));
|
|
164
|
+
await expect(p2.createAgent(agentCfg({ name: 'A3' }))).rejects.toThrow('Maximum agents per project exceeded');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('stores sessionId, metadata, and platformProvided', async () => {
|
|
168
|
+
const agent = await pool.createAgent(agentCfg({
|
|
169
|
+
sessionId: 'sess-123',
|
|
170
|
+
metadata: { foo: 'bar' },
|
|
171
|
+
platformProvided: false
|
|
172
|
+
}));
|
|
173
|
+
expect(agent.sessionId).toBe('sess-123');
|
|
174
|
+
expect(agent.metadata).toEqual({ foo: 'bar' });
|
|
175
|
+
expect(agent.platformProvided).toBe(false);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('uses process.cwd when no projectDir specified and no directoryAccess', async () => {
|
|
179
|
+
mockCreateProjectDefaults.mockClear();
|
|
180
|
+
await pool.createAgent(agentCfg({ projectDir: undefined }));
|
|
181
|
+
// Should call with process.cwd() as fallback
|
|
182
|
+
expect(mockCreateProjectDefaults).toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// ─── getAgent ──────────────────────────────────────────────────────────
|
|
187
|
+
describe('getAgent', () => {
|
|
188
|
+
test('returns agent by ID after creation', async () => {
|
|
189
|
+
const created = await pool.createAgent(agentCfg());
|
|
190
|
+
const found = await pool.getAgent(created.id);
|
|
191
|
+
expect(found).toBe(created);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('returns null for non-existent agent', async () => {
|
|
195
|
+
expect(await pool.getAgent('nonexistent')).toBeNull();
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// ─── updateAgent ──────────────────────────────────────────────────────
|
|
200
|
+
describe('updateAgent', () => {
|
|
201
|
+
test('updates fields and preserves ID', async () => {
|
|
202
|
+
const agent = await pool.createAgent(agentCfg());
|
|
203
|
+
const updated = await pool.updateAgent(agent.id, { name: 'Updated', id: 'should-be-ignored' });
|
|
204
|
+
expect(updated.name).toBe('Updated');
|
|
205
|
+
expect(updated.id).toBe(agent.id);
|
|
206
|
+
expect(updated.lastModified).toBeDefined();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('throws for non-existent agent', async () => {
|
|
210
|
+
await expect(pool.updateAgent('nonexistent', { name: 'X' })).rejects.toThrow('Agent not found');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('persists state after update', async () => {
|
|
214
|
+
const agent = await pool.createAgent(agentCfg());
|
|
215
|
+
stateManager.persistAgentState.mockClear();
|
|
216
|
+
await pool.updateAgent(agent.id, { name: 'Updated' });
|
|
217
|
+
expect(stateManager.persistAgentState).toHaveBeenCalled();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('validates directory access in updates', async () => {
|
|
221
|
+
const agent = await pool.createAgent(agentCfg());
|
|
222
|
+
mockValidateAccessConfiguration.mockReturnValueOnce({ valid: false, errors: ['invalid'] });
|
|
223
|
+
await expect(pool.updateAgent(agent.id, {
|
|
224
|
+
directoryAccess: { workingDirectory: '/bad' }
|
|
225
|
+
})).rejects.toThrow('Invalid directory access configuration');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('updates currentModel when preferredModel changes and copies conversation', async () => {
|
|
229
|
+
const agent = await pool.createAgent(agentCfg({ preferredModel: 'model-a' }));
|
|
230
|
+
// Add a message to old model conversation
|
|
231
|
+
agent.conversations['model-a'].messages.push({ role: 'user', content: 'old msg' });
|
|
232
|
+
const updated = await pool.updateAgent(agent.id, { preferredModel: 'model-b' });
|
|
233
|
+
expect(updated.currentModel).toBe('model-b');
|
|
234
|
+
expect(updated.conversations['model-b']).toBeDefined();
|
|
235
|
+
// Conversation should have been copied
|
|
236
|
+
expect(updated.conversations['model-b'].messages).toHaveLength(1);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('regenerates system prompt when capabilities change', async () => {
|
|
240
|
+
const toolsRegistry = { enhanceSystemPrompt: jest.fn().mockReturnValue('new enhanced') };
|
|
241
|
+
const { pool: p2 } = makePool({ toolsRegistry });
|
|
242
|
+
const agent = await p2.createAgent(agentCfg());
|
|
243
|
+
toolsRegistry.enhanceSystemPrompt.mockClear();
|
|
244
|
+
await p2.updateAgent(agent.id, { capabilities: ['terminal'] });
|
|
245
|
+
expect(toolsRegistry.enhanceSystemPrompt).toHaveBeenCalled();
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('regenerates system prompt when originalSystemPrompt is updated', async () => {
|
|
249
|
+
const toolsRegistry = { enhanceSystemPrompt: jest.fn().mockReturnValue('re-enhanced') };
|
|
250
|
+
const { pool: p2 } = makePool({ toolsRegistry });
|
|
251
|
+
const agent = await p2.createAgent(agentCfg());
|
|
252
|
+
toolsRegistry.enhanceSystemPrompt.mockClear();
|
|
253
|
+
const updated = await p2.updateAgent(agent.id, { originalSystemPrompt: 'Brand new prompt' });
|
|
254
|
+
expect(toolsRegistry.enhanceSystemPrompt).toHaveBeenCalled();
|
|
255
|
+
expect(updated.originalSystemPrompt).toBe('Brand new prompt');
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// ─── deleteAgent ──────────────────────────────────────────────────────
|
|
260
|
+
describe('deleteAgent', () => {
|
|
261
|
+
test('removes agent from pool and returns success', async () => {
|
|
262
|
+
const agent = await pool.createAgent(agentCfg());
|
|
263
|
+
const result = await pool.deleteAgent(agent.id);
|
|
264
|
+
expect(result.success).toBe(true);
|
|
265
|
+
expect(result.remainingAgents).toBe(0);
|
|
266
|
+
expect(await pool.getAgent(agent.id)).toBeNull();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Was: 'throws for non-existent agent'. The contract changed —
|
|
270
|
+
// deleteAgent is now idempotent so the bulk-delete UX can wipe
|
|
271
|
+
// unloaded agents (the My Squadron group-delete used to fail with
|
|
272
|
+
// "Failed to delete N agents" whenever any target wasn't in memory).
|
|
273
|
+
// deleteAgentState is itself ENOENT-tolerant, so "not in pool, not
|
|
274
|
+
// on disk" still resolves to success — same end state.
|
|
275
|
+
test('is idempotent for an agent not in the pool (succeeds, clears persistent state)', async () => {
|
|
276
|
+
stateManager.deleteAgentState.mockClear();
|
|
277
|
+
const result = await pool.deleteAgent('nonexistent-agent-id');
|
|
278
|
+
expect(result.success).toBe(true);
|
|
279
|
+
// Still asked the state manager to clear it — best-effort cleanup.
|
|
280
|
+
expect(stateManager.deleteAgentState).toHaveBeenCalledWith('nonexistent-agent-id');
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test('removes persistent state even when the agent was never loaded', async () => {
|
|
284
|
+
// Simulate an agent that exists on disk but isn't in memory
|
|
285
|
+
// (e.g. process restarted, or it was unloaded earlier).
|
|
286
|
+
stateManager.deleteAgentState.mockClear();
|
|
287
|
+
// No createAgent — pool.agents stays empty.
|
|
288
|
+
const result = await pool.deleteAgent('unloaded-but-on-disk');
|
|
289
|
+
expect(result.success).toBe(true);
|
|
290
|
+
expect(stateManager.deleteAgentState).toHaveBeenCalledWith('unloaded-but-on-disk');
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('cleans up maps (directory, paused, notification)', async () => {
|
|
294
|
+
const agent = await pool.createAgent(agentCfg());
|
|
295
|
+
pool.pausedAgents.set(agent.id, {});
|
|
296
|
+
pool.notificationQueue.set(agent.id, []);
|
|
297
|
+
await pool.deleteAgent(agent.id);
|
|
298
|
+
expect(pool.pausedAgents.has(agent.id)).toBe(false);
|
|
299
|
+
expect(pool.notificationQueue.has(agent.id)).toBe(false);
|
|
300
|
+
expect(pool.agentDirectory.has(agent.id)).toBe(false);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('agent is no longer retrievable after delete', async () => {
|
|
304
|
+
const agent = await pool.createAgent(agentCfg());
|
|
305
|
+
await pool.deleteAgent(agent.id);
|
|
306
|
+
const retrieved = await pool.getAgent(agent.id);
|
|
307
|
+
expect(retrieved).toBeFalsy();
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// ─── unloadAgent ──────────────────────────────────────────────────────
|
|
312
|
+
describe('unloadAgent', () => {
|
|
313
|
+
test('removes from memory but persists state first', async () => {
|
|
314
|
+
const agent = await pool.createAgent(agentCfg());
|
|
315
|
+
stateManager.persistAgentState.mockClear();
|
|
316
|
+
const result = await pool.unloadAgent(agent.id);
|
|
317
|
+
expect(result.success).toBe(true);
|
|
318
|
+
expect(result.agentName).toBe('TestAgent');
|
|
319
|
+
expect(result.message).toContain('unloaded');
|
|
320
|
+
expect(await pool.getAgent(agent.id)).toBeNull();
|
|
321
|
+
expect(stateManager.persistAgentState).toHaveBeenCalled();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test('throws for non-existent agent', async () => {
|
|
325
|
+
await expect(pool.unloadAgent('nonexistent')).rejects.toThrow('Agent not found');
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('calls scheduler.removeAgent if scheduler is set', async () => {
|
|
329
|
+
const mockScheduler = { removeAgent: jest.fn() };
|
|
330
|
+
pool.setScheduler(mockScheduler);
|
|
331
|
+
const agent = await pool.createAgent(agentCfg());
|
|
332
|
+
await pool.unloadAgent(agent.id);
|
|
333
|
+
expect(mockScheduler.removeAgent).toHaveBeenCalledWith(agent.id, 'unloaded');
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// ─── pauseAgent / resumeAgent ─────────────────────────────────────────
|
|
338
|
+
describe('pauseAgent', () => {
|
|
339
|
+
test('sets paused status and pausedUntil with seconds duration', async () => {
|
|
340
|
+
const agent = await pool.createAgent(agentCfg());
|
|
341
|
+
const result = await pool.pauseAgent(agent.id, 60, 'test pause');
|
|
342
|
+
expect(result.success).toBe(true);
|
|
343
|
+
expect(agent.status).toBe('paused');
|
|
344
|
+
expect(agent.pausedUntil).toBeDefined();
|
|
345
|
+
expect(pool.pausedAgents.has(agent.id)).toBe(true);
|
|
346
|
+
const pauseInfo = pool.pausedAgents.get(agent.id);
|
|
347
|
+
expect(pauseInfo.reason).toBe('test pause');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test('accepts Date as duration', async () => {
|
|
351
|
+
const agent = await pool.createAgent(agentCfg());
|
|
352
|
+
const future = new Date(Date.now() + 60000);
|
|
353
|
+
const result = await pool.pauseAgent(agent.id, future);
|
|
354
|
+
expect(result.success).toBe(true);
|
|
355
|
+
expect(new Date(agent.pausedUntil).getTime()).toBe(future.getTime());
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test('caps duration to maxPauseDuration config', async () => {
|
|
359
|
+
const { pool: p2 } = makePool({ config: { system: { maxPauseDuration: 10 } } });
|
|
360
|
+
const agent = await p2.createAgent(agentCfg());
|
|
361
|
+
await p2.pauseAgent(agent.id, 9999, 'long pause');
|
|
362
|
+
const pauseEnd = new Date(agent.pausedUntil).getTime();
|
|
363
|
+
expect(pauseEnd).toBeLessThan(Date.now() + 15000);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test('throws for non-existent agent', async () => {
|
|
367
|
+
await expect(pool.pauseAgent('nonexistent', 60)).rejects.toThrow('Agent not found');
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
describe('resumeAgent (unpause)', () => {
|
|
372
|
+
test('resumes paused agent to active', async () => {
|
|
373
|
+
const agent = await pool.createAgent(agentCfg());
|
|
374
|
+
await pool.pauseAgent(agent.id, 300, 'test');
|
|
375
|
+
const result = await pool.resumeAgent(agent.id);
|
|
376
|
+
expect(result.success).toBe(true);
|
|
377
|
+
expect(agent.status).toBe('active');
|
|
378
|
+
expect(agent.pausedUntil).toBeNull();
|
|
379
|
+
expect(pool.pausedAgents.has(agent.id)).toBe(false);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
test('no-op for non-paused agent', async () => {
|
|
383
|
+
const agent = await pool.createAgent(agentCfg());
|
|
384
|
+
const result = await pool.resumeAgent(agent.id);
|
|
385
|
+
expect(result.success).toBe(true);
|
|
386
|
+
expect(result.message).toContain('not paused');
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test('throws for non-existent agent', async () => {
|
|
390
|
+
await expect(pool.resumeAgent('nonexistent')).rejects.toThrow('Agent not found');
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
// ─── Message queue methods ────────────────────────────────────────────
|
|
395
|
+
describe('addUserMessage', () => {
|
|
396
|
+
test('pushes message with generated ID and timestamps', async () => {
|
|
397
|
+
const agent = await pool.createAgent(agentCfg());
|
|
398
|
+
await pool.addUserMessage(agent.id, { content: 'hello', role: 'user' });
|
|
399
|
+
expect(agent.messageQueues.userMessages).toHaveLength(1);
|
|
400
|
+
const msg = agent.messageQueues.userMessages[0];
|
|
401
|
+
expect(msg.content).toBe('hello');
|
|
402
|
+
expect(msg.id).toBeDefined();
|
|
403
|
+
expect(msg.queuedAt).toBeDefined();
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('auto-creates task for AGENT mode agents', async () => {
|
|
407
|
+
const agent = await pool.createAgent(agentCfg({ mode: 'agent' }));
|
|
408
|
+
await pool.addUserMessage(agent.id, { content: 'do something' });
|
|
409
|
+
expect(agent.taskList.tasks).toHaveLength(1);
|
|
410
|
+
expect(agent.taskList.tasks[0].source).toBe('auto-created');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test('throws for non-existent agent', async () => {
|
|
414
|
+
await expect(pool.addUserMessage('nonexistent', { content: 'hi' })).rejects.toThrow('Agent not found');
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test('clears a future scheduler-applied delayEndTime on user message', async () => {
|
|
418
|
+
// A user message is an explicit signal to act now — any back-off
|
|
419
|
+
// delay set by the scheduler (rate-limit, network error, builtin
|
|
420
|
+
// tool delay) should evaporate rather than making the user wait
|
|
421
|
+
// out the remainder.
|
|
422
|
+
const agent = await pool.createAgent(agentCfg());
|
|
423
|
+
agent.delayEndTime = new Date(Date.now() + 60_000).toISOString();
|
|
424
|
+
|
|
425
|
+
await pool.addUserMessage(agent.id, { content: 'please act now' });
|
|
426
|
+
|
|
427
|
+
expect(agent.delayEndTime).toBeNull();
|
|
428
|
+
expect(agent.messageQueues.userMessages).toHaveLength(1);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
test('leaves a past/expired delayEndTime alone', async () => {
|
|
432
|
+
// Already-expired delays don't need clearing — the scheduler ignores
|
|
433
|
+
// them on the next tick anyway. We only act on actively-blocking delays.
|
|
434
|
+
const agent = await pool.createAgent(agentCfg());
|
|
435
|
+
const pastIso = new Date(Date.now() - 1_000).toISOString();
|
|
436
|
+
agent.delayEndTime = pastIso;
|
|
437
|
+
|
|
438
|
+
await pool.addUserMessage(agent.id, { content: 'go' });
|
|
439
|
+
|
|
440
|
+
expect(agent.delayEndTime).toBe(pastIso);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// ── Auto-save user messages as plan/* memories ────────────────────
|
|
444
|
+
// Talisman case study: agents never voluntarily wrote memories
|
|
445
|
+
// and the user's literal asks vanished in compaction. The pool
|
|
446
|
+
// now auto-saves substantive user messages to the plan/* store
|
|
447
|
+
// as a system-level safety net (the agent itself can still write
|
|
448
|
+
// better-titled plans on top; these auto-saves are cleanup-safe).
|
|
449
|
+
|
|
450
|
+
describe('REGRESSION: auto-save substantive user messages as plan/*', () => {
|
|
451
|
+
test('calls _autoSaveUserMessageAsPlan for each user message (best-effort)', async () => {
|
|
452
|
+
const agent = await pool.createAgent(agentCfg());
|
|
453
|
+
const spy = jest.spyOn(pool, '_autoSaveUserMessageAsPlan').mockResolvedValue(undefined);
|
|
454
|
+
await pool.addUserMessage(agent.id, { content: 'please do a thing that is long enough to count as substantive content here, more than 120 chars total for the heuristic', role: 'user' });
|
|
455
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
456
|
+
expect(spy.mock.calls[0][0]).toBe(agent.id);
|
|
457
|
+
expect(spy.mock.calls[0][1].content).toMatch(/please do a thing/);
|
|
458
|
+
spy.mockRestore();
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test('a memory-service failure does NOT block the message-enqueue path', async () => {
|
|
462
|
+
// Auto-save is best-effort. If memoryService blows up, the
|
|
463
|
+
// user's message must still land on the queue.
|
|
464
|
+
const agent = await pool.createAgent(agentCfg());
|
|
465
|
+
jest.spyOn(pool, '_autoSaveUserMessageAsPlan').mockRejectedValue(new Error('memory store offline'));
|
|
466
|
+
await pool.addUserMessage(agent.id, { content: 'hello', role: 'user' });
|
|
467
|
+
expect(agent.messageQueues.userMessages).toHaveLength(1);
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
describe('_looksSubstantive heuristic — pollution audit', () => {
|
|
472
|
+
// ── TRUE POSITIVES — these SHOULD be saved ─────────────────────
|
|
473
|
+
test('TRUE POSITIVE: numbered request (Talisman literal case)', () => {
|
|
474
|
+
const msg = `Amazing! a few more things
|
|
475
|
+
1. "choose your hero" page - lets put a nice fantasy image at the background.
|
|
476
|
+
2. play screen - why is the board still round? plus, not all nodes have their own art.
|
|
477
|
+
3. when we roll for combat - there is no dice animation visible`;
|
|
478
|
+
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test('TRUE POSITIVE: multi-paragraph feature request', () => {
|
|
482
|
+
const msg = 'Implement OAuth login. Replace the existing session-cookie flow with Google and Microsoft sign-in. Migrate existing users by linking their email to the new auth records on first sign-in. Update the docs.';
|
|
483
|
+
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test('TRUE POSITIVE: numbered bug list (descriptions, not paths)', () => {
|
|
487
|
+
const msg = `Fix these bugs:\n1. login button does nothing on Safari\n2. cart total wrong when discount applied\n3. 500 error on /api/orders/export`;
|
|
488
|
+
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
test('TRUE POSITIVE: bulleted plan with imperative verbs', () => {
|
|
492
|
+
const msg = `fixes needed:\n- fix bug in login flow that breaks on slow networks\n- add retry logic to the cache layer\n- write a test for the missing error case`;
|
|
493
|
+
expect(pool._looksSubstantive(msg)).toBe(true);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
// ── POLLUTION RISKS — these should NOT be saved ────────────────
|
|
497
|
+
test('POLLUTION: short ack is rejected', () => {
|
|
498
|
+
expect(pool._looksSubstantive('ok thanks')).toBe(false);
|
|
499
|
+
expect(pool._looksSubstantive('thanks!')).toBe(false);
|
|
500
|
+
expect(pool._looksSubstantive('yes please')).toBe(false);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
test('POLLUTION: question with no imperative is rejected (user wants an answer, not a plan)', () => {
|
|
504
|
+
const msg = 'what does this function do? I see it referenced in three places but the docs do not explain its purpose at all.';
|
|
505
|
+
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
test('POLLUTION: numbered list of QUESTIONS is rejected (not a plan)', () => {
|
|
509
|
+
const msg = `quick questions:\n1. why is the cache key the user id?\n2. is the rate limit per-user or per-ip?`;
|
|
510
|
+
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
test('POLLUTION: list of file paths is rejected (just references)', () => {
|
|
514
|
+
const msg = `look at these:\n- src/auth/login.js\n- src/auth/session.js\n- src/middleware/auth.js\n- tests/auth.test.js`;
|
|
515
|
+
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
test('POLLUTION: long pleasantry with no imperative is rejected', () => {
|
|
519
|
+
const msg = 'hey, hope you are well today, that was a good run earlier and I am happy with the progress so far!';
|
|
520
|
+
expect(pool._looksSubstantive(msg)).toBe(false);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
test('POLLUTION: trivial numbered nonsense is rejected (too short under list rule)', () => {
|
|
524
|
+
expect(pool._looksSubstantive('1. yes 2. no 3. maybe')).toBe(false);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test('POLLUTION: reading-comprehension feedback is rejected', () => {
|
|
528
|
+
expect(pool._looksSubstantive('I do not understand what you wrote in your last message. Can you explain it differently?')).toBe(false);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
test('POLLUTION: agreement / confirmation is rejected', () => {
|
|
532
|
+
expect(pool._looksSubstantive('yes, please proceed with that plan. it looks correct to me.')).toBe(false);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
test('POLLUTION: simple one-shot instruction is rejected (too short)', () => {
|
|
536
|
+
expect(pool._looksSubstantive('run the tests again')).toBe(false);
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// ── Defensive corner cases ─────────────────────────────────────
|
|
540
|
+
test('tool-result wrappers are rejected', () => {
|
|
541
|
+
expect(pool._looksSubstantive('[Tool Results — 1 result from 1 tool batch: filesystem] {...lots of content...}')).toBe(false);
|
|
542
|
+
expect(pool._looksSubstantive('[Previous Task — Final Tool Results] [jobdone] {...}')).toBe(false);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
test('non-string content is rejected defensively', () => {
|
|
546
|
+
expect(pool._looksSubstantive(null)).toBe(false);
|
|
547
|
+
expect(pool._looksSubstantive(undefined)).toBe(false);
|
|
548
|
+
expect(pool._looksSubstantive({ obj: true })).toBe(false);
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
describe('helpers: question / reference / imperative detection', () => {
|
|
553
|
+
test('_dominatedByQuestions detects majority-question content', () => {
|
|
554
|
+
expect(pool._dominatedByQuestions('what does X do?')).toBe(true);
|
|
555
|
+
expect(pool._dominatedByQuestions('1. what?\n2. why?\n3. how?')).toBe(true);
|
|
556
|
+
expect(pool._dominatedByQuestions('fix the bug')).toBe(false);
|
|
557
|
+
// Mixed: 1 question + 2 commands → not dominated.
|
|
558
|
+
expect(pool._dominatedByQuestions('why is this slow?\nfix the cache\nadd metrics')).toBe(false);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test('_listItemsAreJustReferences detects path-only lists', () => {
|
|
562
|
+
const refList = `look:\n- src/a.js\n- src/b.js\n- src/c.js`;
|
|
563
|
+
expect(pool._listItemsAreJustReferences(refList)).toBe(true);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
test('_listItemsAreJustReferences does NOT flag bug descriptions', () => {
|
|
567
|
+
const bugList = `bugs:\n- login breaks on Safari\n- cart total wrong with discount`;
|
|
568
|
+
expect(pool._listItemsAreJustReferences(bugList)).toBe(false);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
test('_hasImperativeSignal matches common command verbs', () => {
|
|
572
|
+
expect(pool._hasImperativeSignal('fix the login bug')).toBe(true);
|
|
573
|
+
expect(pool._hasImperativeSignal('add a retry')).toBe(true);
|
|
574
|
+
expect(pool._hasImperativeSignal('refactor this module')).toBe(true);
|
|
575
|
+
expect(pool._hasImperativeSignal('what does this do')).toBe(false);
|
|
576
|
+
expect(pool._hasImperativeSignal('looks good')).toBe(false);
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
describe('dedup + cap (Jaccard similarity, AUTO_PLAN_CAP)', () => {
|
|
581
|
+
test('_tokenize lowercases + drops short words + strips punctuation', () => {
|
|
582
|
+
const tokens = pool._tokenize('Fix THE login button on iOS!');
|
|
583
|
+
// 'the', 'on' are <3 chars dropped; 'fix', 'login', 'button', 'ios' remain.
|
|
584
|
+
expect(tokens.has('fix')).toBe(true);
|
|
585
|
+
expect(tokens.has('login')).toBe(true);
|
|
586
|
+
expect(tokens.has('button')).toBe(true);
|
|
587
|
+
expect(tokens.has('ios')).toBe(true);
|
|
588
|
+
expect(tokens.has('the')).toBe(false);
|
|
589
|
+
expect(tokens.has('on')).toBe(false);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
test('_jaccard returns 1 for identical text, 0 for disjoint, 1 for both empty', () => {
|
|
593
|
+
const a = pool._tokenize('fix the login button');
|
|
594
|
+
const b = pool._tokenize('fix the login button');
|
|
595
|
+
const c = pool._tokenize('build the cache layer');
|
|
596
|
+
expect(pool._jaccard(a, b)).toBe(1);
|
|
597
|
+
expect(pool._jaccard(a, c)).toBe(0);
|
|
598
|
+
expect(pool._jaccard(new Set(), new Set())).toBe(1);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
test('_overlapCoefficient catches "I repeat my old message" near-duplicate (containment ≥0.85)', () => {
|
|
602
|
+
// Real Talisman case: user repeated themselves verbatim with
|
|
603
|
+
// an "I repeat my old message" preamble. Jaccard alone marks
|
|
604
|
+
// these as merely "similar" because the preamble adds new
|
|
605
|
+
// words; the overlap coefficient (intersection / smaller-set)
|
|
606
|
+
// correctly reports that the original is fully contained in
|
|
607
|
+
// the repeated version.
|
|
608
|
+
const original = pool._tokenize(
|
|
609
|
+
`1. "choose your hero" page - lets put a nice fantasy image at the background. also, lets create a character card art (general)`,
|
|
610
|
+
);
|
|
611
|
+
const repeated = pool._tokenize(
|
|
612
|
+
`Amazing! I repeat my old message - a few more things\n\n"choose your hero" page - lets put a nice fantasy image at the background. also, lets create a character card art (general)`,
|
|
613
|
+
);
|
|
614
|
+
expect(pool._overlapCoefficient(original, repeated)).toBeGreaterThanOrEqual(0.85);
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
test('_overlapCoefficient is 0 for disjoint sets, 1 for one fully contained in the other', () => {
|
|
618
|
+
const a = pool._tokenize('fix login button');
|
|
619
|
+
const b = pool._tokenize('fix login button additional extra words');
|
|
620
|
+
const c = pool._tokenize('build cache layer');
|
|
621
|
+
// 'a' fully contained in 'b' → 1.0
|
|
622
|
+
expect(pool._overlapCoefficient(a, b)).toBe(1);
|
|
623
|
+
// disjoint
|
|
624
|
+
expect(pool._overlapCoefficient(a, c)).toBe(0);
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
test('no-ops when delayEndTime is null', async () => {
|
|
629
|
+
const agent = await pool.createAgent(agentCfg());
|
|
630
|
+
agent.delayEndTime = null;
|
|
631
|
+
|
|
632
|
+
await pool.addUserMessage(agent.id, { content: 'go' });
|
|
633
|
+
|
|
634
|
+
expect(agent.delayEndTime).toBeNull();
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
test('broadcasts agent state update when a delay was cleared', async () => {
|
|
638
|
+
// The UI's delay chip listens for `agent_state_updated` — when we
|
|
639
|
+
// clear a delay we should surface it immediately so the chip
|
|
640
|
+
// disappears without a reload.
|
|
641
|
+
const agent = await pool.createAgent(agentCfg());
|
|
642
|
+
agent.delayEndTime = new Date(Date.now() + 30_000).toISOString();
|
|
643
|
+
|
|
644
|
+
const broadcast = jest.fn().mockResolvedValue(undefined);
|
|
645
|
+
pool.scheduler = { broadcastAgentStateUpdate: broadcast };
|
|
646
|
+
|
|
647
|
+
await pool.addUserMessage(agent.id, { content: 'now' });
|
|
648
|
+
|
|
649
|
+
expect(broadcast).toHaveBeenCalledWith(agent.id, 'user-message-clears-delay');
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
test('does not broadcast when no delay was set', async () => {
|
|
653
|
+
const agent = await pool.createAgent(agentCfg());
|
|
654
|
+
const broadcast = jest.fn().mockResolvedValue(undefined);
|
|
655
|
+
pool.scheduler = { broadcastAgentStateUpdate: broadcast };
|
|
656
|
+
|
|
657
|
+
await pool.addUserMessage(agent.id, { content: 'hi' });
|
|
658
|
+
|
|
659
|
+
expect(broadcast).not.toHaveBeenCalled();
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
describe('addInterAgentMessage', () => {
|
|
664
|
+
test('pushes message with sender info', async () => {
|
|
665
|
+
const agent = await pool.createAgent(agentCfg());
|
|
666
|
+
await pool.addInterAgentMessage(agent.id, { content: 'inter-msg', sender: 'agent-x', senderName: 'AgentX' });
|
|
667
|
+
expect(agent.messageQueues.interAgentMessages).toHaveLength(1);
|
|
668
|
+
expect(agent.messageQueues.interAgentMessages[0].content).toBe('inter-msg');
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
test('auto-creates task for AGENT mode agents with sender label', async () => {
|
|
672
|
+
const agent = await pool.createAgent(agentCfg({ mode: 'agent' }));
|
|
673
|
+
await pool.addInterAgentMessage(agent.id, { content: 'help', sender: 'other', senderName: 'OtherAgent' });
|
|
674
|
+
expect(agent.taskList.tasks).toHaveLength(1);
|
|
675
|
+
expect(agent.taskList.tasks[0].title).toContain('inter-agent');
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
test('throws for non-existent agent', async () => {
|
|
679
|
+
await expect(pool.addInterAgentMessage('nonexistent', { content: 'hi' })).rejects.toThrow('Agent not found');
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
describe('addToolResult', () => {
|
|
684
|
+
test('pushes result with generated ID and timestamps', async () => {
|
|
685
|
+
const agent = await pool.createAgent(agentCfg());
|
|
686
|
+
await pool.addToolResult(agent.id, { toolId: 'terminal', status: 'completed', result: 'ok' });
|
|
687
|
+
expect(agent.messageQueues.toolResults).toHaveLength(1);
|
|
688
|
+
const r = agent.messageQueues.toolResults[0];
|
|
689
|
+
expect(r.toolId).toBe('terminal');
|
|
690
|
+
expect(r.id).toBeDefined();
|
|
691
|
+
expect(r.queuedAt).toBeDefined();
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
test('throws for non-existent agent', async () => {
|
|
695
|
+
await expect(pool.addToolResult('nonexistent', {})).rejects.toThrow('Agent not found');
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
// ─── clearConversation ────────────────────────────────────────────────
|
|
700
|
+
describe('clearConversation', () => {
|
|
701
|
+
test('empties all conversation history, queues, and task list', async () => {
|
|
702
|
+
const agent = await pool.createAgent(agentCfg());
|
|
703
|
+
agent.conversations.full.messages.push({ role: 'user', content: 'old' });
|
|
704
|
+
agent.messageQueues.userMessages.push({ content: 'queued' });
|
|
705
|
+
agent.messageQueues.toolResults.push({ toolId: 'x' });
|
|
706
|
+
agent.messageQueues.interAgentMessages.push({ content: 'inter' });
|
|
707
|
+
agent.taskList.tasks.push({ id: 'task1', title: 'do thing' });
|
|
708
|
+
|
|
709
|
+
const result = await pool.clearConversation(agent.id);
|
|
710
|
+
expect(result.success).toBe(true);
|
|
711
|
+
expect(result.previousMessageCount).toBe(1);
|
|
712
|
+
expect(agent.conversations.full.messages).toEqual([]);
|
|
713
|
+
expect(agent.messageQueues.userMessages).toEqual([]);
|
|
714
|
+
expect(agent.messageQueues.toolResults).toEqual([]);
|
|
715
|
+
expect(agent.messageQueues.interAgentMessages).toEqual([]);
|
|
716
|
+
expect(agent.taskList.tasks).toEqual([]);
|
|
717
|
+
expect(agent.currentTask).toBeNull();
|
|
718
|
+
expect(agent.iterationCount).toBe(0);
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
test('resets model-specific conversations', async () => {
|
|
722
|
+
const agent = await pool.createAgent(agentCfg({ preferredModel: 'model-a' }));
|
|
723
|
+
agent.conversations['model-a'].messages.push({ role: 'user', content: 'msg' });
|
|
724
|
+
await pool.clearConversation(agent.id);
|
|
725
|
+
expect(agent.conversations['model-a'].messages).toEqual([]);
|
|
726
|
+
expect(agent.conversations['model-a'].compactizedMessages).toBeNull();
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
test('throws for non-existent agent', async () => {
|
|
730
|
+
await expect(pool.clearConversation('nonexistent')).rejects.toThrow('Agent not found');
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
// ─── listActiveAgents / getAllAgents ───────────────────────────────────
|
|
735
|
+
describe('listActiveAgents', () => {
|
|
736
|
+
test('returns shaped array of all agents', async () => {
|
|
737
|
+
await pool.createAgent(agentCfg({ name: 'A1' }));
|
|
738
|
+
await pool.createAgent(agentCfg({ name: 'A2' }));
|
|
739
|
+
const list = await pool.listActiveAgents();
|
|
740
|
+
expect(list).toHaveLength(2);
|
|
741
|
+
expect(list[0]).toHaveProperty('id');
|
|
742
|
+
expect(list[0]).toHaveProperty('name');
|
|
743
|
+
expect(list[0]).toHaveProperty('mode');
|
|
744
|
+
expect(list[0]).toHaveProperty('capabilities');
|
|
745
|
+
expect(list[0]).toHaveProperty('isPaused');
|
|
746
|
+
expect(list[0]).toHaveProperty('messageCount');
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
describe('getAllAgents', () => {
|
|
751
|
+
test('returns all agents and auto-resumes expired pauses', async () => {
|
|
752
|
+
const agent = await pool.createAgent(agentCfg());
|
|
753
|
+
agent.status = 'paused';
|
|
754
|
+
agent.pausedUntil = new Date(Date.now() - 1000).toISOString();
|
|
755
|
+
const all = await pool.getAllAgents();
|
|
756
|
+
const found = all.find(a => a.id === agent.id);
|
|
757
|
+
expect(found.status).toBe('active');
|
|
758
|
+
expect(found.pausedUntil).toBeNull();
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
// ─── persistAgentState ────────────────────────────────────────────────
|
|
763
|
+
describe('persistAgentState', () => {
|
|
764
|
+
test('delegates to stateManager with agent object', async () => {
|
|
765
|
+
const agent = await pool.createAgent(agentCfg());
|
|
766
|
+
stateManager.persistAgentState.mockClear();
|
|
767
|
+
await pool.persistAgentState(agent.id);
|
|
768
|
+
expect(stateManager.persistAgentState).toHaveBeenCalledWith(agent);
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
test('throws for non-existent agent', async () => {
|
|
772
|
+
await expect(pool.persistAgentState('nonexistent')).rejects.toThrow('Agent not found');
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
// ─── Private helpers ──────────────────────────────────────────────────
|
|
777
|
+
describe('private helpers', () => {
|
|
778
|
+
test('_generateAgentId sanitizes name', () => {
|
|
779
|
+
const id = pool._generateAgentId('Hello World!');
|
|
780
|
+
expect(id).toMatch(/^agent-hello-world--\d+$/);
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
test('_isAgentPaused returns false for active agent', () => {
|
|
784
|
+
expect(pool._isAgentPaused({ status: 'active', pausedUntil: null })).toBe(false);
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
test('_isAgentPaused returns true for future pause', () => {
|
|
788
|
+
const future = new Date(Date.now() + 60000).toISOString();
|
|
789
|
+
expect(pool._isAgentPaused({ status: 'paused', pausedUntil: future })).toBe(true);
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
test('_isAgentPaused returns false for expired pause', () => {
|
|
793
|
+
const past = new Date(Date.now() - 60000).toISOString();
|
|
794
|
+
expect(pool._isAgentPaused({ status: 'paused', pausedUntil: past })).toBe(false);
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
test('_isPauseExpired returns true when no pausedUntil', () => {
|
|
798
|
+
expect(pool._isPauseExpired({})).toBe(true);
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
test('_isPauseExpired returns false when future pause', () => {
|
|
802
|
+
const future = new Date(Date.now() + 60000).toISOString();
|
|
803
|
+
expect(pool._isPauseExpired({ pausedUntil: future })).toBe(false);
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
test('_getFirstUserMessageSnippet returns null for empty conversations', () => {
|
|
807
|
+
const agent = { conversations: { full: { messages: [] } } };
|
|
808
|
+
expect(pool._getFirstUserMessageSnippet(agent)).toBeNull();
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
test('_getFirstUserMessageSnippet returns snippet for first user message', () => {
|
|
812
|
+
const agent = {
|
|
813
|
+
conversations: { full: { messages: [
|
|
814
|
+
{ role: 'assistant', content: 'hi' },
|
|
815
|
+
{ role: 'user', content: 'Build me a web app', type: 'consolidated-input' }
|
|
816
|
+
] } }
|
|
817
|
+
};
|
|
818
|
+
expect(pool._getFirstUserMessageSnippet(agent)).toBe('Build me a web app');
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
test('_getFirstUserMessageSnippet truncates long snippets', () => {
|
|
822
|
+
const longMsg = 'A'.repeat(200);
|
|
823
|
+
const agent = {
|
|
824
|
+
conversations: { full: { messages: [
|
|
825
|
+
{ role: 'user', content: longMsg }
|
|
826
|
+
] } }
|
|
827
|
+
};
|
|
828
|
+
const snippet = pool._getFirstUserMessageSnippet(agent);
|
|
829
|
+
expect(snippet.length).toBeLessThanOrEqual(120);
|
|
830
|
+
expect(snippet).toContain('...');
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
test('_queueNotification stores notification for agent', () => {
|
|
834
|
+
pool._queueNotification('agent-1', { content: 'test' });
|
|
835
|
+
expect(pool.notificationQueue.has('agent-1')).toBe(true);
|
|
836
|
+
expect(pool.notificationQueue.get('agent-1')).toHaveLength(1);
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
test('_generateAgentDescription includes capabilities', () => {
|
|
840
|
+
const desc = pool._generateAgentDescription({ name: 'Bot', type: 'user-created', capabilities: ['terminal', 'filesystem'] });
|
|
841
|
+
expect(desc).toContain('Bot');
|
|
842
|
+
expect(desc).toContain('terminal');
|
|
843
|
+
});
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
// ─── setters ──────────────────────────────────────────────────────────
|
|
847
|
+
describe('setter methods', () => {
|
|
848
|
+
test('setToolsRegistry stores the registry', () => {
|
|
849
|
+
const registry = { getTool: jest.fn() };
|
|
850
|
+
pool.setToolsRegistry(registry);
|
|
851
|
+
expect(pool.toolsRegistry).toBe(registry);
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
test('setMessageProcessor stores the reference', () => {
|
|
855
|
+
const mp = { processMessage: jest.fn() };
|
|
856
|
+
pool.setMessageProcessor(mp);
|
|
857
|
+
expect(pool.messageProcessor).toBe(mp);
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
test('setScheduler stores the scheduler reference', () => {
|
|
861
|
+
const sched = { addAgent: jest.fn() };
|
|
862
|
+
pool.setScheduler(sched);
|
|
863
|
+
expect(pool.scheduler).toBe(sched);
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
});
|