@ai-setting/roy-agent-core 1.3.9 → 1.3.11
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/dist/config/index.js +1647 -0
- package/dist/index.js +12579 -89691
- package/package.json +19 -56
- package/src/config/config-component.test.ts +0 -627
- package/src/config/config-component.ts +0 -906
- package/src/config/config-parser.test.ts +0 -319
- package/src/config/config-parser.ts +0 -203
- package/src/config/decentralized-config.test.ts +0 -740
- package/src/config/env-key.ts +0 -210
- package/src/config/env-source.test.ts +0 -252
- package/src/config/env-source.ts +0 -301
- package/src/config/file-source.test.ts +0 -357
- package/src/config/file-source.ts +0 -421
- package/src/config/index.ts +0 -24
- package/src/config/protocol-resolver.test.ts +0 -217
- package/src/config/protocol-resolver.ts +0 -228
- package/src/env/agent/agent-component.abort.test.ts +0 -511
- package/src/env/agent/agent-component.record-session.test.ts +0 -349
- package/src/env/agent/agent-component.test.ts +0 -1389
- package/src/env/agent/agent-component.tool-error.test.ts +0 -327
- package/src/env/agent/agent-component.ts +0 -1711
- package/src/env/agent/agent-config-registration.test.ts +0 -226
- package/src/env/agent/agent-config-registration.ts +0 -46
- package/src/env/agent/agent-reminder-plugin.integration.test.ts +0 -243
- package/src/env/agent/index.ts +0 -10
- package/src/env/agent/summary-agent.parse-hint.test.ts +0 -360
- package/src/env/agent/summary-agent.ts +0 -508
- package/src/env/agent/types.ts +0 -536
- package/src/env/commands/commands-component.test.ts +0 -364
- package/src/env/commands/commands-component.ts +0 -604
- package/src/env/commands/commands-config-registration.test.ts +0 -198
- package/src/env/commands/commands-config-registration.ts +0 -38
- package/src/env/commands/index.ts +0 -21
- package/src/env/commands/parser.test.ts +0 -203
- package/src/env/commands/parser.ts +0 -115
- package/src/env/commands/types.ts +0 -184
- package/src/env/commands-prompt-integration.test.ts +0 -243
- package/src/env/component-env.test.ts +0 -119
- package/src/env/component.ts +0 -335
- package/src/env/constants.test.ts +0 -72
- package/src/env/constants.ts +0 -123
- package/src/env/debug/debug-component.test.ts +0 -114
- package/src/env/debug/debug-component.ts +0 -547
- package/src/env/debug/formatters/index.ts +0 -9
- package/src/env/debug/formatters/repl-formatter.test.ts +0 -139
- package/src/env/debug/formatters/repl-formatter.ts +0 -358
- package/src/env/debug/formatters/trace-formatter.test.ts +0 -119
- package/src/env/debug/formatters/trace-formatter.ts +0 -191
- package/src/env/debug/formatters/tree-formatter.test.ts +0 -107
- package/src/env/debug/formatters/tree-formatter.ts +0 -325
- package/src/env/debug/index.ts +0 -38
- package/src/env/debug/parser/regex-parser.test.ts +0 -201
- package/src/env/debug/parser/regex-parser.ts +0 -196
- package/src/env/debug/parser/span-builder.test.ts +0 -241
- package/src/env/debug/parser/span-builder.ts +0 -386
- package/src/env/debug/reader/log-reader.test.ts +0 -170
- package/src/env/debug/reader/log-reader.ts +0 -186
- package/src/env/debug/reader/span-db-reader.test.ts +0 -118
- package/src/env/debug/reader/span-db-reader.ts +0 -201
- package/src/env/debug/types.test.ts +0 -187
- package/src/env/debug/types.ts +0 -171
- package/src/env/environment-init.test.ts +0 -183
- package/src/env/environment-lifecycle.test.ts +0 -516
- package/src/env/environment-service.test.ts +0 -332
- package/src/env/environment.handle-query.test.ts +0 -96
- package/src/env/environment.test.ts +0 -232
- package/src/env/environment.ts +0 -708
- package/src/env/errors.test.ts +0 -165
- package/src/env/errors.ts +0 -157
- package/src/env/event-source/event-source-agent-handler.test.ts +0 -193
- package/src/env/event-source/event-source-agent-handler.ts +0 -111
- package/src/env/event-source/event-source-component.process-cleanup.test.ts +0 -236
- package/src/env/event-source/event-source-component.stop.test.ts +0 -346
- package/src/env/event-source/event-source-component.test.ts +0 -1207
- package/src/env/event-source/event-source-component.ts +0 -1379
- package/src/env/event-source/event-source-config-registration.test.ts +0 -242
- package/src/env/event-source/event-source-config-registration.ts +0 -37
- package/src/env/event-source/event-source-integration.test.ts +0 -320
- package/src/env/event-source/event-source-platform.test.ts +0 -630
- package/src/env/event-source/types.ts +0 -298
- package/src/env/hook/global-hook-manager.ts +0 -162
- package/src/env/hook/hook-manager.test.ts +0 -374
- package/src/env/hook/hook-manager.ts +0 -309
- package/src/env/hook/index.ts +0 -38
- package/src/env/hook/types.ts +0 -138
- package/src/env/index.ts +0 -144
- package/src/env/interface.ts +0 -203
- package/src/env/llm/hooks.test.ts +0 -293
- package/src/env/llm/hooks.ts +0 -316
- package/src/env/llm/index.ts +0 -61
- package/src/env/llm/invoke-threshold-check.test.ts +0 -88
- package/src/env/llm/invoke-timeout.test.ts +0 -54
- package/src/env/llm/invoke.test.ts +0 -71
- package/src/env/llm/invoke.ts +0 -1039
- package/src/env/llm/llm-config.test.ts +0 -523
- package/src/env/llm/llm.test.ts +0 -233
- package/src/env/llm/llm.ts +0 -568
- package/src/env/llm/provider.test.ts +0 -182
- package/src/env/llm/provider.ts +0 -108
- package/src/env/llm/transform.test.ts +0 -251
- package/src/env/llm/transform.ts +0 -286
- package/src/env/llm/types.test.ts +0 -580
- package/src/env/llm/types.ts +0 -424
- package/src/env/log-trace/decorator-otel.test.ts +0 -182
- package/src/env/log-trace/decorator.ts +0 -230
- package/src/env/log-trace/index.ts +0 -79
- package/src/env/log-trace/log-trace-component.test.ts +0 -242
- package/src/env/log-trace/log-trace-component.ts +0 -497
- package/src/env/log-trace/log-trace-config-registration.test.ts +0 -348
- package/src/env/log-trace/log-trace-config-registration.ts +0 -45
- package/src/env/log-trace/logger.test.ts +0 -149
- package/src/env/log-trace/logger.ts +0 -522
- package/src/env/log-trace/opentelemetry/cli-propagation.test.ts +0 -147
- package/src/env/log-trace/opentelemetry/cli-propagation.ts +0 -194
- package/src/env/log-trace/opentelemetry/integration.test.ts +0 -668
- package/src/env/log-trace/opentelemetry/mod.ts +0 -25
- package/src/env/log-trace/opentelemetry/propagation-env.test.ts +0 -181
- package/src/env/log-trace/opentelemetry/propagation-env.ts +0 -136
- package/src/env/log-trace/opentelemetry/propagation.test.ts +0 -259
- package/src/env/log-trace/opentelemetry/propagation.ts +0 -215
- package/src/env/log-trace/opentelemetry/tracer-provider-context.test.ts +0 -166
- package/src/env/log-trace/opentelemetry/tracer-provider.test.ts +0 -379
- package/src/env/log-trace/opentelemetry/tracer-provider.ts +0 -612
- package/src/env/log-trace/span-storage.test.ts +0 -145
- package/src/env/log-trace/span-storage.ts +0 -230
- package/src/env/log-trace/trace-context.test.ts +0 -187
- package/src/env/log-trace/trace-context.ts +0 -162
- package/src/env/log-trace/types.test.ts +0 -63
- package/src/env/log-trace/types.ts +0 -172
- package/src/env/mcp/README.md +0 -244
- package/src/env/mcp/__integration__/mcp-component.integration.test.ts +0 -373
- package/src/env/mcp/config.test.ts +0 -74
- package/src/env/mcp/config.ts +0 -116
- package/src/env/mcp/index.ts +0 -41
- package/src/env/mcp/loader.test.ts +0 -161
- package/src/env/mcp/loader.ts +0 -209
- package/src/env/mcp/mcp-component.test.ts +0 -111
- package/src/env/mcp/mcp-component.ts +0 -358
- package/src/env/mcp/mcp-config-registration.test.ts +0 -304
- package/src/env/mcp/mcp-config-registration.ts +0 -50
- package/src/env/mcp/scanner.test.ts +0 -170
- package/src/env/mcp/scanner.ts +0 -246
- package/src/env/mcp/tool/adapter.test.ts +0 -520
- package/src/env/mcp/tool/adapter.ts +0 -521
- package/src/env/mcp/tool/index.ts +0 -5
- package/src/env/mcp/types.test.ts +0 -171
- package/src/env/mcp/types.ts +0 -79
- package/src/env/memory/README.md +0 -177
- package/src/env/memory/built-in/index.ts +0 -59
- package/src/env/memory/built-in/recall-memory.ts +0 -103
- package/src/env/memory/built-in/record-memory.ts +0 -148
- package/src/env/memory/index.ts +0 -20
- package/src/env/memory/memory-component.test.ts +0 -239
- package/src/env/memory/memory-component.ts +0 -503
- package/src/env/memory/memory-config-registration.test.ts +0 -67
- package/src/env/memory/memory-config-registration.ts +0 -48
- package/src/env/memory/memory-config.ts +0 -45
- package/src/env/memory/memory-file.test.ts +0 -268
- package/src/env/memory/plugin/index.ts +0 -48
- package/src/env/memory/plugin/memory-agent.test.ts +0 -249
- package/src/env/memory/plugin/memory-agent.ts +0 -365
- package/src/env/memory/plugin/memory-manager.ts +0 -198
- package/src/env/memory/plugin/memory-plugin-agent.test.ts +0 -145
- package/src/env/memory/plugin/memory-plugin.ts +0 -210
- package/src/env/memory/plugin/plugin-simplified.test.ts +0 -51
- package/src/env/memory/plugin/recall-memory.test.ts +0 -106
- package/src/env/memory/plugin/recall-memory.ts +0 -53
- package/src/env/memory/plugin/types.ts +0 -101
- package/src/env/memory/tools/memory-agent-tools.ts +0 -228
- package/src/env/memory/types.ts +0 -85
- package/src/env/paths.ts +0 -118
- package/src/env/prompt/index.ts +0 -18
- package/src/env/prompt/memory-prompts.test.ts +0 -91
- package/src/env/prompt/prompt-component.test.ts +0 -491
- package/src/env/prompt/prompt-component.ts +0 -619
- package/src/env/prompt/prompt-config-registration.test.ts +0 -213
- package/src/env/prompt/prompt-config-registration.ts +0 -39
- package/src/env/prompt/prompts-index.ts +0 -504
- package/src/env/prompt/renderer.ts +0 -67
- package/src/env/prompt/types.ts +0 -136
- package/src/env/session/hooks.ts +0 -18
- package/src/env/session/index.ts +0 -37
- package/src/env/session/search-query-parser.test.ts +0 -425
- package/src/env/session/search-query-parser.ts +0 -171
- package/src/env/session/session-checkpoint.test.ts +0 -523
- package/src/env/session/session-component.extract-recent-messages.test.ts +0 -209
- package/src/env/session/session-component.test.ts +0 -132
- package/src/env/session/session-component.ts +0 -1249
- package/src/env/session/session-config-registration.test.ts +0 -138
- package/src/env/session/session-config-registration.ts +0 -52
- package/src/env/session/session-message-converter.test.ts +0 -763
- package/src/env/session/session-message-converter.ts +0 -415
- package/src/env/session/session-message-e2e.test.ts +0 -448
- package/src/env/session/session-search.test.ts +0 -391
- package/src/env/session/session-store.test.ts +0 -362
- package/src/env/session/session-store.ts +0 -141
- package/src/env/session/storage/index.ts +0 -6
- package/src/env/session/storage/memory.ts +0 -502
- package/src/env/session/storage/sqlite.ts +0 -794
- package/src/env/session/types.ts +0 -742
- package/src/env/skill/config.ts +0 -39
- package/src/env/skill/index.ts +0 -6
- package/src/env/skill/parser.test.ts +0 -116
- package/src/env/skill/parser.ts +0 -77
- package/src/env/skill/scanner.test.ts +0 -211
- package/src/env/skill/scanner.ts +0 -119
- package/src/env/skill/skill-component.test.ts +0 -234
- package/src/env/skill/skill-component.ts +0 -352
- package/src/env/skill/skill-config-registration.test.ts +0 -60
- package/src/env/skill/skill-config-registration.ts +0 -43
- package/src/env/skill/tool/index.ts +0 -1
- package/src/env/skill/tool/skill-tool.test.ts +0 -100
- package/src/env/skill/tool/skill-tool.ts +0 -72
- package/src/env/skill/types.ts +0 -64
- package/src/env/task/delegate/delegate-tool.test.ts +0 -498
- package/src/env/task/delegate/delegate-tool.ts +0 -1014
- package/src/env/task/delegate/index.ts +0 -18
- package/src/env/task/delegate/stop-tool.test.ts +0 -140
- package/src/env/task/delegate/stop-tool.ts +0 -119
- package/src/env/task/delegate/task-events.test.ts +0 -178
- package/src/env/task/delegate/task-events.ts +0 -143
- package/src/env/task/hooks/contexts.test.ts +0 -92
- package/src/env/task/hooks/contexts.ts +0 -192
- package/src/env/task/hooks/index.ts +0 -23
- package/src/env/task/hooks/task-hook-points.test.ts +0 -32
- package/src/env/task/hooks/task-hook-points.ts +0 -54
- package/src/env/task/index.ts +0 -7
- package/src/env/task/plugins/index.ts +0 -13
- package/src/env/task/plugins/task-plugin.test.ts +0 -74
- package/src/env/task/plugins/task-plugin.ts +0 -89
- package/src/env/task/plugins/task-tag-plugin.test.ts +0 -377
- package/src/env/task/plugins/task-tag-plugin.ts +0 -319
- package/src/env/task/plugins/task-workflow-extractor.integration.test.ts +0 -226
- package/src/env/task/plugins/workflow-extractor-agent.test.ts +0 -107
- package/src/env/task/plugins/workflow-extractor-agent.ts +0 -225
- package/src/env/task/storage/index.ts +0 -6
- package/src/env/task/storage/sqlite-task-store.test.ts +0 -283
- package/src/env/task/storage/sqlite-task-store.ts +0 -903
- package/src/env/task/storage/task-search.test.ts +0 -291
- package/src/env/task/tag-service.test.ts +0 -198
- package/src/env/task/tag-service.ts +0 -264
- package/src/env/task/task-component.test.ts +0 -193
- package/src/env/task/task-component.ts +0 -658
- package/src/env/task/task-config-registration.test.ts +0 -57
- package/src/env/task/task-config-registration.ts +0 -37
- package/src/env/task/task-types.test.ts +0 -137
- package/src/env/task/tools/complete-tool.ts +0 -44
- package/src/env/task/tools/create-tool.ts +0 -49
- package/src/env/task/tools/delete-tool.ts +0 -43
- package/src/env/task/tools/get-tool.ts +0 -59
- package/src/env/task/tools/index.ts +0 -10
- package/src/env/task/tools/list-tool.ts +0 -40
- package/src/env/task/tools/operation/create-tool.ts +0 -48
- package/src/env/task/tools/operation/delete-tool.ts +0 -43
- package/src/env/task/tools/operation/get-tool.ts +0 -43
- package/src/env/task/tools/operation/index.ts +0 -9
- package/src/env/task/tools/operation/list-tool.ts +0 -40
- package/src/env/task/tools/operation/operation-tools.test.ts +0 -274
- package/src/env/task/tools/operation/operation-types.ts +0 -75
- package/src/env/task/tools/operation/update-tool.ts +0 -47
- package/src/env/task/tools/task-tools.test.ts +0 -203
- package/src/env/task/tools/task-types.test.ts +0 -75
- package/src/env/task/tools/task-types.ts +0 -68
- package/src/env/task/tools/update-tool.ts +0 -70
- package/src/env/task/types.ts +0 -160
- package/src/env/tool/built-in/bash.ts +0 -201
- package/src/env/tool/built-in/echo.ts +0 -29
- package/src/env/tool/built-in/edit-file.test.ts +0 -136
- package/src/env/tool/built-in/edit-file.ts +0 -92
- package/src/env/tool/built-in/glob.test.ts +0 -94
- package/src/env/tool/built-in/glob.ts +0 -65
- package/src/env/tool/built-in/grep.test.ts +0 -122
- package/src/env/tool/built-in/grep.ts +0 -108
- package/src/env/tool/built-in/index.ts +0 -44
- package/src/env/tool/built-in/read-file.test.ts +0 -84
- package/src/env/tool/built-in/read-file.ts +0 -75
- package/src/env/tool/built-in/write-file.test.ts +0 -119
- package/src/env/tool/built-in/write-file.ts +0 -68
- package/src/env/tool/index.ts +0 -24
- package/src/env/tool/registry.test.ts +0 -257
- package/src/env/tool/registry.ts +0 -167
- package/src/env/tool/tool-component.test.ts +0 -559
- package/src/env/tool/tool-component.ts +0 -563
- package/src/env/tool/tool-config-registration.test.ts +0 -249
- package/src/env/tool/tool-config-registration.ts +0 -46
- package/src/env/tool/types.ts +0 -267
- package/src/env/tool/validator.test.ts +0 -143
- package/src/env/tool/validator.ts +0 -44
- package/src/env/types.ts +0 -180
- package/src/env/workflow/ask-user-tool-registration.test.ts +0 -216
- package/src/env/workflow/complex-workflow.integration.test.ts +0 -1900
- package/src/env/workflow/decorators/decorator-node.ts +0 -229
- package/src/env/workflow/decorators/decorator.test.ts +0 -196
- package/src/env/workflow/decorators/edge.ts +0 -82
- package/src/env/workflow/decorators/index.ts +0 -31
- package/src/env/workflow/decorators/node-as.ts +0 -98
- package/src/env/workflow/decorators/workflow.ts +0 -54
- package/src/env/workflow/engine/dag-manager.test.ts +0 -570
- package/src/env/workflow/engine/dag-manager.ts +0 -594
- package/src/env/workflow/engine/engine.ts +0 -1422
- package/src/env/workflow/engine/event-bus.test.ts +0 -359
- package/src/env/workflow/engine/event-bus.ts +0 -156
- package/src/env/workflow/engine/executor-agent-session.test.ts +0 -84
- package/src/env/workflow/engine/executor.test.ts +0 -619
- package/src/env/workflow/engine/executor.ts +0 -593
- package/src/env/workflow/engine/index.ts +0 -24
- package/src/env/workflow/engine/node-registry.test.ts +0 -560
- package/src/env/workflow/engine/node-registry.ts +0 -289
- package/src/env/workflow/engine/resume-removed.test.ts +0 -22
- package/src/env/workflow/engine/scheduler.test.ts +0 -715
- package/src/env/workflow/engine/scheduler.ts +0 -318
- package/src/env/workflow/engine/workflow-engine.test.ts +0 -815
- package/src/env/workflow/extractor/workflow-converter.ts +0 -306
- package/src/env/workflow/fixtures.ts +0 -380
- package/src/env/workflow/index.ts +0 -38
- package/src/env/workflow/integration/run-resume-unified.test.ts +0 -186
- package/src/env/workflow/integration/service-integration.test.ts +0 -267
- package/src/env/workflow/metadata/keys.ts +0 -12
- package/src/env/workflow/nodes/agent-component-adapter.test.ts +0 -318
- package/src/env/workflow/nodes/agent-component-adapter.ts +0 -448
- package/src/env/workflow/nodes/agent-node.test.ts +0 -371
- package/src/env/workflow/nodes/agent-node.ts +0 -598
- package/src/env/workflow/nodes/ask-user-node.ts +0 -113
- package/src/env/workflow/nodes/condition-node.ts +0 -200
- package/src/env/workflow/nodes/index.ts +0 -9
- package/src/env/workflow/nodes/merge-node.ts +0 -141
- package/src/env/workflow/nodes/skill-node.test.ts +0 -253
- package/src/env/workflow/nodes/skill-node.ts +0 -393
- package/src/env/workflow/nodes/tool-node.test.ts +0 -251
- package/src/env/workflow/nodes/tool-node.ts +0 -493
- package/src/env/workflow/nodes/workflow-llm-history.test.ts +0 -455
- package/src/env/workflow/nodes/workflow-node.test.ts +0 -315
- package/src/env/workflow/nodes/workflow-node.ts +0 -311
- package/src/env/workflow/service/index.ts +0 -27
- package/src/env/workflow/service/registry.test.ts +0 -133
- package/src/env/workflow/service/registry.ts +0 -71
- package/src/env/workflow/service/workflow-service.test.ts +0 -310
- package/src/env/workflow/service/workflow-service.ts +0 -393
- package/src/env/workflow/storage/index.ts +0 -28
- package/src/env/workflow/storage/mock-repositories.ts +0 -385
- package/src/env/workflow/storage/sqlite.test.ts +0 -179
- package/src/env/workflow/storage/sqlite.ts +0 -163
- package/src/env/workflow/storage/workflow-repo.test.ts +0 -780
- package/src/env/workflow/storage/workflow-repo.ts +0 -342
- package/src/env/workflow/tools/ask-user-tool.ts +0 -82
- package/src/env/workflow/tools/index.ts +0 -26
- package/src/env/workflow/tools/run-workflow.test.ts +0 -352
- package/src/env/workflow/tools/run-workflow.ts +0 -214
- package/src/env/workflow/types/context.ts +0 -18
- package/src/env/workflow/types/decorators-types.ts +0 -198
- package/src/env/workflow/types/event.test.ts +0 -515
- package/src/env/workflow/types/event.ts +0 -193
- package/src/env/workflow/types/index.ts +0 -49
- package/src/env/workflow/types/run.test.ts +0 -437
- package/src/env/workflow/types/run.ts +0 -173
- package/src/env/workflow/types/workflow-hil.ts +0 -114
- package/src/env/workflow/types/workflow-message.test.ts +0 -138
- package/src/env/workflow/types/workflow-message.ts +0 -196
- package/src/env/workflow/types/workflow-session.test.ts +0 -95
- package/src/env/workflow/types/workflow-session.ts +0 -59
- package/src/env/workflow/types/workflow.test.ts +0 -495
- package/src/env/workflow/types/workflow.ts +0 -195
- package/src/env/workflow/types_compat.ts +0 -51
- package/src/env/workflow/utils/create-workflow.ts +0 -47
- package/src/env/workflow/utils/execution-state.ts +0 -245
- package/src/env/workflow/utils/index.ts +0 -18
- package/src/env/workflow/utils/node-registry-helper.ts +0 -58
- package/src/env/workflow/utils/recovery-validator.test.ts +0 -460
- package/src/env/workflow/utils/recovery-validator.ts +0 -377
- package/src/env/workflow/utils/session-parser.test.ts +0 -111
- package/src/env/workflow/utils/session-parser.ts +0 -94
- package/src/env/workflow/utils/session-recovery.test.ts +0 -334
- package/src/env/workflow/utils/session-recovery.ts +0 -188
- package/src/env/workflow/utils/template-resolver.test.ts +0 -258
- package/src/env/workflow/utils/template-resolver.ts +0 -436
- package/src/env/workflow/utils/validation-rules.ts +0 -149
- package/src/env/workflow/workflow-component.ts +0 -544
- package/src/index.ts +0 -422
- package/src/utils/id.ts +0 -21
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Environment Service 集成测试
|
|
3
|
-
*
|
|
4
|
-
* TDD: 测试 Environment 从配置文件加载组件配置并初始化组件的能力
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, test, expect, beforeEach, afterEach, vi } from "bun:test";
|
|
8
|
-
import { BaseEnvironment } from "./environment";
|
|
9
|
-
import { ConfigComponent } from "../config/config-component";
|
|
10
|
-
import { BaseComponent } from "./component";
|
|
11
|
-
import * as fsSync from "fs";
|
|
12
|
-
import * as path from "path";
|
|
13
|
-
import * as os from "os";
|
|
14
|
-
|
|
15
|
-
// ============================================================================
|
|
16
|
-
// 测试用的 Mock Component
|
|
17
|
-
// ============================================================================
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Mock LLMComponent - 模拟 LLMComponent 的配置加载
|
|
21
|
-
*/
|
|
22
|
-
class MockLLMComponent extends BaseComponent {
|
|
23
|
-
readonly name = "llm";
|
|
24
|
-
readonly version = "1.0.0";
|
|
25
|
-
|
|
26
|
-
// 存储初始化时的配置
|
|
27
|
-
initOptions: any = null;
|
|
28
|
-
loadedConfig: any = null;
|
|
29
|
-
|
|
30
|
-
async init(config: import("./component").ComponentConfig): Promise<void> {
|
|
31
|
-
await super.init(config);
|
|
32
|
-
|
|
33
|
-
// 从 options 获取配置
|
|
34
|
-
const options = config.options as any;
|
|
35
|
-
this.initOptions = options;
|
|
36
|
-
this.loadedConfig = options?.config;
|
|
37
|
-
|
|
38
|
-
this.setStatus("running");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getLoadedConfig() {
|
|
42
|
-
return this.loadedConfig;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Mock ToolComponent - 模拟 ToolComponent 的配置加载
|
|
48
|
-
*/
|
|
49
|
-
class MockToolComponent extends BaseComponent {
|
|
50
|
-
readonly name = "tool";
|
|
51
|
-
readonly version = "1.0.0";
|
|
52
|
-
|
|
53
|
-
initOptions: any = null;
|
|
54
|
-
loadedConfig: any = null;
|
|
55
|
-
|
|
56
|
-
async init(config: import("./component").ComponentConfig): Promise<void> {
|
|
57
|
-
await super.init(config);
|
|
58
|
-
|
|
59
|
-
const options = config.options as any;
|
|
60
|
-
this.initOptions = options;
|
|
61
|
-
this.loadedConfig = options?.config;
|
|
62
|
-
|
|
63
|
-
this.setStatus("running");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
getLoadedConfig() {
|
|
67
|
-
return this.loadedConfig;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ============================================================================
|
|
72
|
-
// 测试
|
|
73
|
-
// ============================================================================
|
|
74
|
-
|
|
75
|
-
describe("Environment Service Configuration", () => {
|
|
76
|
-
let env: BaseEnvironment;
|
|
77
|
-
let configComponent: ConfigComponent;
|
|
78
|
-
let tempDir: string;
|
|
79
|
-
|
|
80
|
-
beforeEach(() => {
|
|
81
|
-
env = new BaseEnvironment({ name: "test-service-env" });
|
|
82
|
-
configComponent = new ConfigComponent();
|
|
83
|
-
|
|
84
|
-
// Create temp directory for config files
|
|
85
|
-
tempDir = fsSync.mkdtempSync(path.join(os.tmpdir(), "env-service-test-"));
|
|
86
|
-
configComponent.setXdgDataHome(tempDir);
|
|
87
|
-
|
|
88
|
-
// 注册 ConfigComponent
|
|
89
|
-
env.registerComponent(configComponent);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
afterEach(() => {
|
|
93
|
-
vi.restoreAllMocks();
|
|
94
|
-
// Clean up environment variables
|
|
95
|
-
Object.keys(process.env)
|
|
96
|
-
.filter(k => k.startsWith("TEST_"))
|
|
97
|
-
.forEach(k => delete process.env[k]);
|
|
98
|
-
// Clean up temp directory
|
|
99
|
-
try {
|
|
100
|
-
fsSync.rmSync(tempDir, { recursive: true });
|
|
101
|
-
} catch {}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("loadServiceConfig", () => {
|
|
105
|
-
test("should load service config from file", async () => {
|
|
106
|
-
// 创建服务配置文件
|
|
107
|
-
const serviceConfig = {
|
|
108
|
-
environment: {
|
|
109
|
-
name: "my-service",
|
|
110
|
-
version: "1.0.0",
|
|
111
|
-
},
|
|
112
|
-
components: {
|
|
113
|
-
llm: {
|
|
114
|
-
config: {
|
|
115
|
-
defaultModel: "gpt-4",
|
|
116
|
-
temperature: 0.5,
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
fsSync.writeFileSync(
|
|
123
|
-
path.join(tempDir, "service-config.jsonc"),
|
|
124
|
-
JSON.stringify(serviceConfig),
|
|
125
|
-
"utf-8"
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// 调用 loadServiceConfig 方法
|
|
129
|
-
const loadedConfig = await env.loadServiceConfig("service-config.jsonc");
|
|
130
|
-
|
|
131
|
-
// 验证配置被正确加载
|
|
132
|
-
expect(loadedConfig).toBeDefined();
|
|
133
|
-
expect(loadedConfig.environment.name).toBe("my-service");
|
|
134
|
-
expect(loadedConfig.components.llm.config.defaultModel).toBe("gpt-4");
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test("should throw error if service config not found", async () => {
|
|
138
|
-
// 尝试加载不存在的配置文件应该抛出错误
|
|
139
|
-
await expect(
|
|
140
|
-
env.loadServiceConfig("non-existent-config.jsonc")
|
|
141
|
-
).rejects.toThrow();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe("generateComponentOptions", () => {
|
|
146
|
-
test("should generate component options from service config", async () => {
|
|
147
|
-
// 创建服务配置
|
|
148
|
-
const serviceConfig = {
|
|
149
|
-
environment: {
|
|
150
|
-
name: "test-env",
|
|
151
|
-
},
|
|
152
|
-
components: {
|
|
153
|
-
llm: {
|
|
154
|
-
configPath: "llm.jsonc",
|
|
155
|
-
envPrefix: "LLM",
|
|
156
|
-
config: {
|
|
157
|
-
defaultModel: "gpt-4",
|
|
158
|
-
temperature: 0.7,
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// 生成 LLM 组件的 Options
|
|
165
|
-
const options = env.generateComponentOptions("llm", serviceConfig.components.llm);
|
|
166
|
-
|
|
167
|
-
// 验证生成的 Options 包含正确的配置
|
|
168
|
-
expect(options.configComponent).toBe(configComponent);
|
|
169
|
-
expect(options.config.defaultModel).toBe("gpt-4");
|
|
170
|
-
expect(options.config.temperature).toBe(0.7);
|
|
171
|
-
expect(options.envPrefix).toBe("LLM");
|
|
172
|
-
expect(options.configPath).toBe("llm.jsonc");
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test("should include configComponent in generated options", async () => {
|
|
176
|
-
const serviceConfig = {
|
|
177
|
-
components: {
|
|
178
|
-
tool: {
|
|
179
|
-
config: {
|
|
180
|
-
toolsDir: "./tools",
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const options = env.generateComponentOptions("tool", serviceConfig.components.tool);
|
|
187
|
-
|
|
188
|
-
// 必须包含 ConfigComponent
|
|
189
|
-
expect(options.configComponent).toBeDefined();
|
|
190
|
-
expect(options.configComponent).toBe(configComponent);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe("registerComponentWithConfig", () => {
|
|
195
|
-
test("should register component and initialize with config", async () => {
|
|
196
|
-
const llmComponent = new MockLLMComponent();
|
|
197
|
-
const componentConfig = {
|
|
198
|
-
config: {
|
|
199
|
-
defaultModel: "gpt-4",
|
|
200
|
-
temperature: 0.8,
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
// 使用新 API 注册并初始化组件
|
|
205
|
-
await env.registerComponentWithConfig(llmComponent, componentConfig);
|
|
206
|
-
|
|
207
|
-
// 验证组件被正确初始化
|
|
208
|
-
expect(llmComponent.getStatus()).toBe("running");
|
|
209
|
-
expect(llmComponent.getLoadedConfig()).toEqual(componentConfig.config);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test("should support envPrefix in component registration", async () => {
|
|
213
|
-
const toolComponent = new MockToolComponent();
|
|
214
|
-
const componentConfig = {
|
|
215
|
-
envPrefix: "TOOL",
|
|
216
|
-
config: {
|
|
217
|
-
toolsDir: "./custom-tools",
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
await env.registerComponentWithConfig(toolComponent, componentConfig);
|
|
222
|
-
|
|
223
|
-
expect(toolComponent.getStatus()).toBe("running");
|
|
224
|
-
expect(toolComponent.initOptions.envPrefix).toBe("TOOL");
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe("initFromConfig", () => {
|
|
229
|
-
test("should initialize environment from service config file", async () => {
|
|
230
|
-
// 创建完整的服务配置文件
|
|
231
|
-
const serviceConfig = {
|
|
232
|
-
environment: {
|
|
233
|
-
name: "auto-init-env",
|
|
234
|
-
version: "1.0.0",
|
|
235
|
-
},
|
|
236
|
-
components: {
|
|
237
|
-
llm: {
|
|
238
|
-
config: {
|
|
239
|
-
defaultModel: "gpt-4",
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
tool: {
|
|
243
|
-
config: {
|
|
244
|
-
toolsDir: "./tools",
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
fsSync.writeFileSync(
|
|
251
|
-
path.join(tempDir, "auto-service.jsonc"),
|
|
252
|
-
JSON.stringify(serviceConfig),
|
|
253
|
-
"utf-8"
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
// 创建新的 Environment
|
|
257
|
-
const autoEnv = new BaseEnvironment();
|
|
258
|
-
autoEnv.registerComponent(configComponent);
|
|
259
|
-
|
|
260
|
-
// 注册 mock components
|
|
261
|
-
const llmComponent = new MockLLMComponent();
|
|
262
|
-
const toolComponent = new MockToolComponent();
|
|
263
|
-
autoEnv.registerComponent(llmComponent);
|
|
264
|
-
autoEnv.registerComponent(toolComponent);
|
|
265
|
-
|
|
266
|
-
// 从配置文件初始化
|
|
267
|
-
await autoEnv.initFromConfig("auto-service.jsonc");
|
|
268
|
-
|
|
269
|
-
// 验证环境初始化成功
|
|
270
|
-
expect(autoEnv.getStatus()).toBe("running");
|
|
271
|
-
|
|
272
|
-
// 验证组件被正确初始化
|
|
273
|
-
expect(llmComponent.getStatus()).toBe("running");
|
|
274
|
-
expect(llmComponent.getLoadedConfig().defaultModel).toBe("gpt-4");
|
|
275
|
-
|
|
276
|
-
expect(toolComponent.getStatus()).toBe("running");
|
|
277
|
-
expect(toolComponent.getLoadedConfig().toolsDir).toBe("./tools");
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test("should set environment name from config", async () => {
|
|
281
|
-
const serviceConfig = {
|
|
282
|
-
environment: {
|
|
283
|
-
name: "custom-named-env",
|
|
284
|
-
version: "2.0.0",
|
|
285
|
-
},
|
|
286
|
-
components: {}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
fsSync.writeFileSync(
|
|
290
|
-
path.join(tempDir, "named-service.jsonc"),
|
|
291
|
-
JSON.stringify(serviceConfig),
|
|
292
|
-
"utf-8"
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const namedEnv = new BaseEnvironment();
|
|
296
|
-
namedEnv.registerComponent(configComponent);
|
|
297
|
-
|
|
298
|
-
await namedEnv.initFromConfig("named-service.jsonc");
|
|
299
|
-
|
|
300
|
-
// 验证环境名称被正确设置
|
|
301
|
-
expect(namedEnv.name).toBe("custom-named-env");
|
|
302
|
-
expect(namedEnv.version).toBe("2.0.0");
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
describe("environment variable resolution", () => {
|
|
307
|
-
test("should resolve environment variables in config", async () => {
|
|
308
|
-
// 设置环境变量
|
|
309
|
-
process.env.TEST_LLM_MODEL = "gpt-5";
|
|
310
|
-
|
|
311
|
-
const serviceConfig = {
|
|
312
|
-
environment: { name: "env-test" },
|
|
313
|
-
components: {
|
|
314
|
-
llm: {
|
|
315
|
-
envPrefix: "TEST",
|
|
316
|
-
config: {
|
|
317
|
-
// 配置值应该能引用环境变量
|
|
318
|
-
defaultModel: "gpt-4", // 静态值测试
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
const options = env.generateComponentOptions("llm", serviceConfig.components.llm);
|
|
325
|
-
|
|
326
|
-
// 验证配置被正确传递
|
|
327
|
-
expect(options.config.defaultModel).toBe("gpt-4");
|
|
328
|
-
|
|
329
|
-
delete process.env.TEST_LLM_MODEL;
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
});
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview handle_query 集成测试
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, vi, beforeEach } from "bun:test";
|
|
6
|
-
import { BaseEnvironment } from "./environment";
|
|
7
|
-
import { AgentComponent } from "./agent/agent-component";
|
|
8
|
-
import { ConfigComponent } from "../config/config-component";
|
|
9
|
-
import type { EnvEvent } from "./types";
|
|
10
|
-
|
|
11
|
-
describe("BaseEnvironment.handle_query", () => {
|
|
12
|
-
let env: BaseEnvironment;
|
|
13
|
-
let agentComponent: AgentComponent;
|
|
14
|
-
let configComponent: ConfigComponent;
|
|
15
|
-
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
env = new BaseEnvironment({ name: "test-env" });
|
|
18
|
-
configComponent = new ConfigComponent();
|
|
19
|
-
agentComponent = new AgentComponent();
|
|
20
|
-
|
|
21
|
-
// 注册到 Environment
|
|
22
|
-
env.registerComponent(configComponent);
|
|
23
|
-
env.registerComponent(agentComponent);
|
|
24
|
-
|
|
25
|
-
// 通过 init 方法设置 env(BaseComponent 需要 env)
|
|
26
|
-
// AgentComponent 需要 ConfigComponent
|
|
27
|
-
await agentComponent.init({
|
|
28
|
-
name: "agent",
|
|
29
|
-
version: "1.0.0",
|
|
30
|
-
enabled: true,
|
|
31
|
-
env: env as any,
|
|
32
|
-
options: { configComponent },
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("should delegate to AgentComponent.run", async () => {
|
|
37
|
-
const result = await env.handle_query("Hello");
|
|
38
|
-
|
|
39
|
-
// AgentComponent 没有 LLMComponent 时会返回 Mock 响应
|
|
40
|
-
expect(result).toBe("Mock response: Hello!");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should pass context to AgentComponent.run", async () => {
|
|
44
|
-
const context = {
|
|
45
|
-
sessionId: "test-session-123",
|
|
46
|
-
metadata: { key: "value" },
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// 由于没有 LLMComponent,使用 mock
|
|
50
|
-
// 这个测试主要验证 context 被正确传递
|
|
51
|
-
const result = await env.handle_query("Test query", context);
|
|
52
|
-
expect(result).toBe("Mock response: Hello!");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should emit events via subscribe", async () => {
|
|
56
|
-
const events: EnvEvent[] = [];
|
|
57
|
-
|
|
58
|
-
// 订阅 EnvEvent
|
|
59
|
-
const unsubscribe = env.subscribe((event) => {
|
|
60
|
-
events.push(event);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const result = await env.handle_query("Hello");
|
|
64
|
-
|
|
65
|
-
expect(result).toBe("Mock response: Hello!");
|
|
66
|
-
|
|
67
|
-
// 验证事件被触发
|
|
68
|
-
expect(events.length).toBeGreaterThan(0);
|
|
69
|
-
|
|
70
|
-
// 应该包含 agent.start 和 agent.completed 事件
|
|
71
|
-
// 注意:llm.content 事件只有在有真实 LLMComponent 时才会发送
|
|
72
|
-
const eventTypes = events.map(e => e.type);
|
|
73
|
-
expect(eventTypes).toContain("agent.start");
|
|
74
|
-
expect(eventTypes).toContain("agent.completed");
|
|
75
|
-
|
|
76
|
-
unsubscribe();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should throw error if AgentComponent is not registered", async () => {
|
|
80
|
-
const emptyEnv = new BaseEnvironment({ name: "empty-env" });
|
|
81
|
-
|
|
82
|
-
await expect(
|
|
83
|
-
emptyEnv.handle_query("Hello")
|
|
84
|
-
).rejects.toThrow("AgentComponent not found");
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("should work without event subscription", async () => {
|
|
88
|
-
const result = await env.handle_query("Hello");
|
|
89
|
-
expect(result).toBe("Mock response: Hello!");
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("should work without context", async () => {
|
|
93
|
-
const result = await env.handle_query("Hello");
|
|
94
|
-
expect(result).toBe("Mock response: Hello!");
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview BaseEnvironment Unit Tests
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
6
|
-
import { BaseEnvironment, type BaseEnvironmentConfig } from "./environment";
|
|
7
|
-
import type { EnvEvent, EnvEventHandler, Action, ToolResult, Context } from "./types";
|
|
8
|
-
|
|
9
|
-
describe("BaseEnvironment", () => {
|
|
10
|
-
let env: BaseEnvironment;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
env = new BaseEnvironment({ name: "test-env", version: "1.0.0" });
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(async () => {
|
|
17
|
-
await env.stop();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("构造函数", () => {
|
|
21
|
-
it("应该使用默认配置", () => {
|
|
22
|
-
const defaultEnv = new BaseEnvironment();
|
|
23
|
-
expect(defaultEnv.name).toBe("base-environment");
|
|
24
|
-
expect(defaultEnv.version).toBe("1.0.0");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("应该使用提供的配置", () => {
|
|
28
|
-
expect(env.name).toBe("test-env");
|
|
29
|
-
expect(env.version).toBe("1.0.0");
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe("getConfig()", () => {
|
|
34
|
-
it("应该返回正确的配置", () => {
|
|
35
|
-
const config = env.getConfig();
|
|
36
|
-
expect(config.name).toBe("test-env");
|
|
37
|
-
expect(config.version).toBe("1.0.0");
|
|
38
|
-
expect(config.enabled).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("组件管理", () => {
|
|
43
|
-
it("应该注册和获取组件", () => {
|
|
44
|
-
const mockComponent = {
|
|
45
|
-
name: "test-component",
|
|
46
|
-
version: "1.0.0",
|
|
47
|
-
hooks: {},
|
|
48
|
-
getStatus: () => "created" as const,
|
|
49
|
-
getConfig: () => ({ name: "test-component", version: "1.0.0", enabled: true }),
|
|
50
|
-
init: vi.fn(),
|
|
51
|
-
start: vi.fn(),
|
|
52
|
-
stop: vi.fn(),
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
env.registerComponent(mockComponent as any);
|
|
56
|
-
expect(env.getComponent("test-component")).toBe(mockComponent);
|
|
57
|
-
expect(env.listComponents()).toHaveLength(1);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("应该注销组件", () => {
|
|
61
|
-
const mockComponent = {
|
|
62
|
-
name: "test-component",
|
|
63
|
-
version: "1.0.0",
|
|
64
|
-
hooks: {},
|
|
65
|
-
getStatus: () => "created" as const,
|
|
66
|
-
getConfig: () => ({ name: "test-component", version: "1.0.0", enabled: true }),
|
|
67
|
-
init: vi.fn(),
|
|
68
|
-
start: vi.fn(),
|
|
69
|
-
stop: vi.fn(),
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
env.registerComponent(mockComponent as any);
|
|
73
|
-
env.unregisterComponent("test-component");
|
|
74
|
-
expect(env.getComponent("test-component")).toBeUndefined();
|
|
75
|
-
expect(env.listComponents()).toHaveLength(0);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("获取不存在的组件应返回 undefined", () => {
|
|
79
|
-
expect(env.getComponent("non-existent")).toBeUndefined();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("handle_query", () => {
|
|
84
|
-
it("应该抛出错误(AgentComponent 未注册)", async () => {
|
|
85
|
-
await env.init();
|
|
86
|
-
await expect(env.handle_query("hello")).rejects.toThrow("AgentComponent not found");
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe("handle_action", () => {
|
|
91
|
-
it("应该抛出错误(未实现)", async () => {
|
|
92
|
-
await env.init();
|
|
93
|
-
const action: Action = { type: "test", params: {} };
|
|
94
|
-
const context: Context = {};
|
|
95
|
-
await expect(env.handle_action(action, context)).rejects.toThrow("handle_action not implemented");
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("EnvEvent 机制", () => {
|
|
100
|
-
it("应该订阅和取消订阅", () => {
|
|
101
|
-
const handler = vi.fn();
|
|
102
|
-
const unsubscribe = env.subscribe(handler);
|
|
103
|
-
|
|
104
|
-
// 推送事件
|
|
105
|
-
env.pushEnvEvent({
|
|
106
|
-
id: "test-id",
|
|
107
|
-
type: "test.event",
|
|
108
|
-
timestamp: Date.now(),
|
|
109
|
-
metadata: { env_name: "test" },
|
|
110
|
-
payload: {},
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
expect(handler).toHaveBeenCalledTimes(1);
|
|
114
|
-
|
|
115
|
-
// 取消订阅
|
|
116
|
-
unsubscribe();
|
|
117
|
-
|
|
118
|
-
// 再次推送事件
|
|
119
|
-
env.pushEnvEvent({
|
|
120
|
-
id: "test-id-2",
|
|
121
|
-
type: "test.event",
|
|
122
|
-
timestamp: Date.now(),
|
|
123
|
-
metadata: { env_name: "test" },
|
|
124
|
-
payload: {},
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
expect(handler).toHaveBeenCalledTimes(1); // 不应再调用
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("subscribeAll 应该等同于 subscribe", () => {
|
|
131
|
-
const handler = vi.fn();
|
|
132
|
-
const unsubscribe = env.subscribeAll(handler);
|
|
133
|
-
|
|
134
|
-
env.pushEnvEvent({ id: "1", type: "any.event", timestamp: Date.now(), metadata: {}, payload: {} });
|
|
135
|
-
env.pushEnvEvent({ id: "2", type: "another.event", timestamp: Date.now(), metadata: {}, payload: {} });
|
|
136
|
-
|
|
137
|
-
expect(handler).toHaveBeenCalledTimes(2);
|
|
138
|
-
|
|
139
|
-
unsubscribe();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("应该订阅指定类型事件", () => {
|
|
143
|
-
const handler = vi.fn();
|
|
144
|
-
const unsubscribe = env.subscribeTo("specific.event", handler);
|
|
145
|
-
|
|
146
|
-
// 推送指定类型事件
|
|
147
|
-
env.pushEnvEvent({
|
|
148
|
-
id: "test-id",
|
|
149
|
-
type: "specific.event",
|
|
150
|
-
timestamp: Date.now(),
|
|
151
|
-
metadata: { env_name: "test" },
|
|
152
|
-
payload: {},
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// 推送其他类型事件
|
|
156
|
-
env.pushEnvEvent({
|
|
157
|
-
id: "test-id-2",
|
|
158
|
-
type: "other.event",
|
|
159
|
-
timestamp: Date.now(),
|
|
160
|
-
metadata: { env_name: "test" },
|
|
161
|
-
payload: {},
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
expect(handler).toHaveBeenCalledTimes(1);
|
|
165
|
-
|
|
166
|
-
unsubscribe();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("应该订阅多个类型事件", () => {
|
|
170
|
-
const handler = vi.fn();
|
|
171
|
-
const unsubscribe = env.subscribeTo(["event1", "event2"], handler);
|
|
172
|
-
|
|
173
|
-
env.pushEnvEvent({ id: "1", type: "event1", timestamp: Date.now(), metadata: {}, payload: {} });
|
|
174
|
-
env.pushEnvEvent({ id: "2", type: "event2", timestamp: Date.now(), metadata: {}, payload: {} });
|
|
175
|
-
env.pushEnvEvent({ id: "3", type: "event3", timestamp: Date.now(), metadata: {}, payload: {} });
|
|
176
|
-
|
|
177
|
-
expect(handler).toHaveBeenCalledTimes(2);
|
|
178
|
-
|
|
179
|
-
unsubscribe();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("pushEnvEvent 应该自动填充元信息", () => {
|
|
183
|
-
const handler = vi.fn();
|
|
184
|
-
env.subscribe(handler);
|
|
185
|
-
|
|
186
|
-
env.pushEnvEvent({
|
|
187
|
-
type: "test.event",
|
|
188
|
-
payload: { data: "test" },
|
|
189
|
-
} as any);
|
|
190
|
-
|
|
191
|
-
const event = handler.mock.calls[0][0] as EnvEvent;
|
|
192
|
-
expect(event.id).toBeDefined();
|
|
193
|
-
expect(event.timestamp).toBeDefined();
|
|
194
|
-
expect(event.metadata.env_name).toBe("test-env");
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe("生命周期", () => {
|
|
199
|
-
it("应该正确初始化", async () => {
|
|
200
|
-
await env.init();
|
|
201
|
-
expect(env.getStatus()).toBe("running");
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("应该正确启动", async () => {
|
|
205
|
-
await env.start();
|
|
206
|
-
expect(env.getStatus()).toBe("running");
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("重复启动不应报错", async () => {
|
|
210
|
-
await env.start();
|
|
211
|
-
await env.start();
|
|
212
|
-
expect(env.getStatus()).toBe("running");
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("应该正确停止", async () => {
|
|
216
|
-
await env.stop();
|
|
217
|
-
expect(env.getStatus()).toBe("stopped");
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("停止后应清理事件处理器", async () => {
|
|
221
|
-
const handler = vi.fn();
|
|
222
|
-
env.subscribe(handler);
|
|
223
|
-
|
|
224
|
-
await env.stop();
|
|
225
|
-
|
|
226
|
-
// 停止后推送事件应该不触发
|
|
227
|
-
env.pushEnvEvent({ id: "test", type: "test", timestamp: Date.now(), metadata: {}, payload: {} });
|
|
228
|
-
|
|
229
|
-
expect(handler).not.toHaveBeenCalled();
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|