@ai-setting/roy-agent-core 1.3.10 → 1.3.14
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,630 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview EventSourceComponent Cross-Platform Process Cleanup Tests
|
|
3
|
-
*
|
|
4
|
-
* TDD: 测试跨平台进程清理功能
|
|
5
|
-
*
|
|
6
|
-
* 支持平台:
|
|
7
|
-
* - Linux: pgrep -f " pattern"
|
|
8
|
-
* - macOS: pgrep -f " pattern"
|
|
9
|
-
* - Windows: PowerShell Get-Process + Where-Object
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { describe, test, expect, beforeEach, afterEach, vi } from "bun:test";
|
|
13
|
-
import { EventSourceComponent, setExecAsync } from "./event-source-component";
|
|
14
|
-
import { ConfigComponent } from "../../config/config-component";
|
|
15
|
-
import type { Environment } from "../interface";
|
|
16
|
-
|
|
17
|
-
// Mock process.kill
|
|
18
|
-
const mockProcessKill = vi.fn((pid: number | string, signal?: string) => {
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Mock spawn
|
|
23
|
-
const mockSpawnKill = vi.fn((signal?: string) => true);
|
|
24
|
-
const mockExitCallbacks: Function[] = [];
|
|
25
|
-
|
|
26
|
-
// Mock execAsync - 直接 mock 函数
|
|
27
|
-
const mockExecAsync = vi.fn().mockImplementation((cmd: string) => {
|
|
28
|
-
return Promise.resolve({ stdout: "12345\n67890", stderr: "" });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// 存储 mock execAsync 的返回值
|
|
32
|
-
let mockExecResult = { stdout: "12345\n67890", stderr: "" };
|
|
33
|
-
let mockExecError: Error | null = null;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 设置 mock execAsync 的返回值
|
|
37
|
-
*/
|
|
38
|
-
function setMockExecResult(stdout: string, stderr: string = "") {
|
|
39
|
-
mockExecResult = { stdout, stderr };
|
|
40
|
-
mockExecError = null;
|
|
41
|
-
// 同时更新 setExecAsync,使用 mockExecAsync 确保可以追踪调用
|
|
42
|
-
setExecAsync(async (cmd: string) => {
|
|
43
|
-
// 记录调用以便测试断言
|
|
44
|
-
mockExecAsync(cmd);
|
|
45
|
-
if (mockExecError) {
|
|
46
|
-
throw mockExecError;
|
|
47
|
-
}
|
|
48
|
-
return mockExecResult;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 设置 mock execAsync 返回错误
|
|
54
|
-
*/
|
|
55
|
-
function setMockExecError(error: Error) {
|
|
56
|
-
mockExecError = error;
|
|
57
|
-
mockExecResult = { stdout: "", stderr: "" };
|
|
58
|
-
setExecAsync(async (cmd: string) => {
|
|
59
|
-
// 记录调用以便测试断言
|
|
60
|
-
mockExecAsync(cmd);
|
|
61
|
-
if (mockExecError) {
|
|
62
|
-
throw mockExecError;
|
|
63
|
-
}
|
|
64
|
-
return mockExecResult;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
vi.mock("child_process", () => {
|
|
69
|
-
// mock exec 直接调用 callback
|
|
70
|
-
const mockExec = vi.fn().mockImplementation((cmd: string, callback: Function) => {
|
|
71
|
-
// 同步调用 callback(exec 可以接受回调)
|
|
72
|
-
callback(null, { stdout: "12345\n67890", stderr: "" });
|
|
73
|
-
return { stdout: "", stderr: "" };
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// mock execAsync 直接返回 Promise
|
|
77
|
-
const mockExecAsync = vi.fn().mockImplementation((cmd: string) => {
|
|
78
|
-
return Promise.resolve({ stdout: "12345\n67890", stderr: "" });
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
spawn: vi.fn(() => ({
|
|
83
|
-
pid: 12345,
|
|
84
|
-
pgid: 12340,
|
|
85
|
-
on: vi.fn((event: string, cb: Function) => {
|
|
86
|
-
if (event === "exit") {
|
|
87
|
-
mockExitCallbacks.push(cb);
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
once: vi.fn((eventName: string, handler: Function) => {
|
|
91
|
-
return { once: vi.fn() };
|
|
92
|
-
}),
|
|
93
|
-
};
|
|
94
|
-
}),
|
|
95
|
-
stdout: { on: vi.fn(), removeAllListeners: vi.fn() },
|
|
96
|
-
stderr: { on: vi.fn(), removeAllListeners: vi.fn() },
|
|
97
|
-
removeAllListeners: vi.fn(),
|
|
98
|
-
kill: mockSpawnKill,
|
|
99
|
-
})),
|
|
100
|
-
exec: mockExec,
|
|
101
|
-
promisify: vi.fn(() => mockExecAsync), // mock promisify 返回 mockExecAsync
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// 创建 Mock Environment
|
|
106
|
-
const createMockEnv = () => ({
|
|
107
|
-
name: "mock-env",
|
|
108
|
-
version: "1.0.0",
|
|
109
|
-
getConfig: () => ({ name: "mock-env", version: "1.0.0", enabled: true, env: null as any }),
|
|
110
|
-
registerComponent: () => {},
|
|
111
|
-
unregisterComponent: () => {},
|
|
112
|
-
getComponent: vi.fn(() => undefined),
|
|
113
|
-
hasComponent: vi.fn(() => false),
|
|
114
|
-
listComponents: () => [],
|
|
115
|
-
handle_query: async () => "",
|
|
116
|
-
handle_action: async () => ({ success: true, output: "" }),
|
|
117
|
-
subscribe: vi.fn(() => () => {}),
|
|
118
|
-
subscribeTo: vi.fn(() => () => {}),
|
|
119
|
-
subscribeAll: vi.fn(() => () => {}),
|
|
120
|
-
pushEnvEvent: vi.fn(),
|
|
121
|
-
logger: {
|
|
122
|
-
info: vi.fn(),
|
|
123
|
-
warn: vi.fn(),
|
|
124
|
-
error: vi.fn(),
|
|
125
|
-
debug: vi.fn(),
|
|
126
|
-
},
|
|
127
|
-
trace: vi.fn(),
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe("EventSourceComponent Cross-Platform Process Cleanup - TDD", () => {
|
|
131
|
-
let component: EventSourceComponent;
|
|
132
|
-
let mockEnv: ReturnType<typeof createMockEnv>;
|
|
133
|
-
let configComponent: ConfigComponent;
|
|
134
|
-
let originalKill: typeof process.kill;
|
|
135
|
-
let originalPlatform: string;
|
|
136
|
-
|
|
137
|
-
beforeEach(() => {
|
|
138
|
-
vi.clearAllMocks();
|
|
139
|
-
mockProcessKill.mockClear();
|
|
140
|
-
mockSpawnKill.mockClear();
|
|
141
|
-
mockExitCallbacks.length = 0;
|
|
142
|
-
|
|
143
|
-
// 重置 mockExecResult 为默认值,并设置 setExecAsync
|
|
144
|
-
setMockExecResult("12345\n67890");
|
|
145
|
-
|
|
146
|
-
originalKill = process.kill.bind(process);
|
|
147
|
-
Object.defineProperty(process, "kill", {
|
|
148
|
-
value: mockProcessKill,
|
|
149
|
-
writable: true,
|
|
150
|
-
configurable: true,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// 保存原始 platform
|
|
154
|
-
originalPlatform = Object.getOwnPropertyDescriptor(process, "platform")?.value as string;
|
|
155
|
-
|
|
156
|
-
component = new EventSourceComponent();
|
|
157
|
-
configComponent = new ConfigComponent();
|
|
158
|
-
(component as any).persistenceEnabled = false;
|
|
159
|
-
(component as any).sources.clear();
|
|
160
|
-
(component as any).statuses.clear();
|
|
161
|
-
(component as any).processes.clear();
|
|
162
|
-
(component as any).timers.clear();
|
|
163
|
-
mockEnv = createMockEnv();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
afterEach(() => {
|
|
167
|
-
Object.defineProperty(process, "kill", {
|
|
168
|
-
value: originalKill,
|
|
169
|
-
writable: true,
|
|
170
|
-
configurable: true,
|
|
171
|
-
});
|
|
172
|
-
// 恢复原始 platform
|
|
173
|
-
Object.defineProperty(process, "platform", {
|
|
174
|
-
value: originalPlatform,
|
|
175
|
-
writable: true,
|
|
176
|
-
configurable: true,
|
|
177
|
-
});
|
|
178
|
-
vi.restoreAllMocks();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe("shell 选择 (spawn)", () => {
|
|
182
|
-
test("RED: Linux 平台应使用 sh 作为 shell", async () => {
|
|
183
|
-
/**
|
|
184
|
-
* RED: 验证 Linux 平台使用 sh
|
|
185
|
-
*/
|
|
186
|
-
Object.defineProperty(process, "platform", {
|
|
187
|
-
value: "linux",
|
|
188
|
-
writable: true,
|
|
189
|
-
configurable: true,
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
await component.init({
|
|
193
|
-
name: "event-source",
|
|
194
|
-
version: "1.0.0",
|
|
195
|
-
enabled: true,
|
|
196
|
-
env: mockEnv as unknown as Environment,
|
|
197
|
-
options: { configComponent },
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
component.register({
|
|
201
|
-
id: "test-source",
|
|
202
|
-
name: "Test Source",
|
|
203
|
-
type: "lark-cli",
|
|
204
|
-
enabled: true,
|
|
205
|
-
command: "lark-cli event +subscribe --quiet",
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
setMockExecResult("12345\n67890");
|
|
209
|
-
|
|
210
|
-
await component.startSource("test-source");
|
|
211
|
-
|
|
212
|
-
// 验证 spawn 被调用(通过检查进程信息中的命令)
|
|
213
|
-
const processInfo = (component as any).processes.get("test-source");
|
|
214
|
-
expect(processInfo).toBeDefined();
|
|
215
|
-
expect(processInfo.command).toBe("lark-cli event +subscribe --quiet");
|
|
216
|
-
|
|
217
|
-
// 验证是 Linux 平台,shell 应该是 sh
|
|
218
|
-
const platform = Object.getOwnPropertyDescriptor(process, "platform")?.value;
|
|
219
|
-
expect(platform).toBe("linux");
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test("RED: Windows 平台应使用 cmd.exe 作为 shell", async () => {
|
|
223
|
-
/**
|
|
224
|
-
* RED: 验证 Windows 平台使用 cmd.exe
|
|
225
|
-
*/
|
|
226
|
-
Object.defineProperty(process, "platform", {
|
|
227
|
-
value: "win32",
|
|
228
|
-
writable: true,
|
|
229
|
-
configurable: true,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
await component.init({
|
|
233
|
-
name: "event-source",
|
|
234
|
-
version: "1.0.0",
|
|
235
|
-
enabled: true,
|
|
236
|
-
env: mockEnv as unknown as Environment,
|
|
237
|
-
options: { configComponent },
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
component.register({
|
|
241
|
-
id: "test-source",
|
|
242
|
-
name: "Test Source",
|
|
243
|
-
type: "lark-cli",
|
|
244
|
-
enabled: true,
|
|
245
|
-
command: "lark-cli event +subscribe --quiet",
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
setMockExecResult("12345\r\n67890");
|
|
249
|
-
|
|
250
|
-
await component.startSource("test-source");
|
|
251
|
-
|
|
252
|
-
// 验证 spawn 被调用(通过检查进程信息中的命令)
|
|
253
|
-
const processInfo = (component as any).processes.get("test-source");
|
|
254
|
-
expect(processInfo).toBeDefined();
|
|
255
|
-
expect(processInfo.command).toBe("lark-cli event +subscribe --quiet");
|
|
256
|
-
|
|
257
|
-
// 验证是 Windows 平台
|
|
258
|
-
const platform = Object.getOwnPropertyDescriptor(process, "platform")?.value;
|
|
259
|
-
expect(platform).toBe("win32");
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
describe("跨平台命令生成", () => {
|
|
264
|
-
test("RED: Linux 平台应使用 pgrep -f 命令", async () => {
|
|
265
|
-
/**
|
|
266
|
-
* RED: 验证在 Linux 平台使用 pgrep 命令
|
|
267
|
-
*/
|
|
268
|
-
Object.defineProperty(process, "platform", {
|
|
269
|
-
value: "linux",
|
|
270
|
-
writable: true,
|
|
271
|
-
configurable: true,
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
await component.init({
|
|
275
|
-
name: "event-source",
|
|
276
|
-
version: "1.0.0",
|
|
277
|
-
enabled: true,
|
|
278
|
-
env: mockEnv as unknown as Environment,
|
|
279
|
-
options: { configComponent },
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
component.register({
|
|
283
|
-
id: "test-source",
|
|
284
|
-
name: "Test Source",
|
|
285
|
-
type: "lark-cli",
|
|
286
|
-
enabled: true,
|
|
287
|
-
command: "lark-cli event +subscribe --quiet",
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
setMockExecResult("12345\n67890");
|
|
291
|
-
|
|
292
|
-
await component.startSource("test-source");
|
|
293
|
-
|
|
294
|
-
// 验证调用了 exec
|
|
295
|
-
expect(mockExecAsync).toHaveBeenCalled();
|
|
296
|
-
|
|
297
|
-
// 验证命令包含 pgrep
|
|
298
|
-
const callArgs = mockExecAsync.mock.calls[0]?.[0] || "";
|
|
299
|
-
expect(callArgs).toContain("pgrep");
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
test("RED: macOS 平台应使用 pgrep -f 命令(与 Linux 相同)", async () => {
|
|
303
|
-
/**
|
|
304
|
-
* RED: 验证在 macOS 平台也使用 pgrep 命令
|
|
305
|
-
*/
|
|
306
|
-
Object.defineProperty(process, "platform", {
|
|
307
|
-
value: "darwin",
|
|
308
|
-
writable: true,
|
|
309
|
-
configurable: true,
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
await component.init({
|
|
313
|
-
name: "event-source",
|
|
314
|
-
version: "1.0.0",
|
|
315
|
-
enabled: true,
|
|
316
|
-
env: mockEnv as unknown as Environment,
|
|
317
|
-
options: { configComponent },
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
component.register({
|
|
321
|
-
id: "test-source",
|
|
322
|
-
name: "Test Source",
|
|
323
|
-
type: "lark-cli",
|
|
324
|
-
enabled: true,
|
|
325
|
-
command: "lark-cli event +subscribe --quiet",
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
setMockExecResult("12345");
|
|
329
|
-
|
|
330
|
-
await component.startSource("test-source");
|
|
331
|
-
|
|
332
|
-
expect(mockExecAsync).toHaveBeenCalled();
|
|
333
|
-
const callArgs = mockExecAsync.mock.calls[0]?.[0] || "";
|
|
334
|
-
expect(callArgs).toContain("pgrep");
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
test("RED: Windows 平台应使用 PowerShell 命令", async () => {
|
|
338
|
-
/**
|
|
339
|
-
* RED: 验证在 Windows 平台使用 PowerShell (Get-CimInstance)
|
|
340
|
-
*/
|
|
341
|
-
Object.defineProperty(process, "platform", {
|
|
342
|
-
value: "win32",
|
|
343
|
-
writable: true,
|
|
344
|
-
configurable: true,
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
await component.init({
|
|
348
|
-
name: "event-source",
|
|
349
|
-
version: "1.0.0",
|
|
350
|
-
enabled: true,
|
|
351
|
-
env: mockEnv as unknown as Environment,
|
|
352
|
-
options: { configComponent },
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
component.register({
|
|
356
|
-
id: "test-source",
|
|
357
|
-
name: "Test Source",
|
|
358
|
-
type: "lark-cli",
|
|
359
|
-
enabled: true,
|
|
360
|
-
command: "lark-cli event +subscribe --quiet",
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
setMockExecResult("12345\r\n67890");
|
|
364
|
-
|
|
365
|
-
await component.startSource("test-source");
|
|
366
|
-
|
|
367
|
-
expect(mockExecAsync).toHaveBeenCalled();
|
|
368
|
-
|
|
369
|
-
// 验证命令包含 PowerShell 和 Get-CimInstance
|
|
370
|
-
const callArgs = mockExecAsync.mock.calls[0]?.[0] || "";
|
|
371
|
-
expect(callArgs).toMatch(/(powershell|Get-CimInstance)/i);
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
describe("进程 PID 解析", () => {
|
|
376
|
-
test("RED: Unix 平台应正确解析 pgrep 输出(换行符分隔)", async () => {
|
|
377
|
-
/**
|
|
378
|
-
* RED: 验证正确解析 Unix 平台 pgrep 输出
|
|
379
|
-
*/
|
|
380
|
-
Object.defineProperty(process, "platform", {
|
|
381
|
-
value: "linux",
|
|
382
|
-
writable: true,
|
|
383
|
-
configurable: true,
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
await component.init({
|
|
387
|
-
name: "event-source",
|
|
388
|
-
version: "1.0.0",
|
|
389
|
-
enabled: true,
|
|
390
|
-
env: mockEnv as unknown as Environment,
|
|
391
|
-
options: { configComponent },
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
component.register({
|
|
395
|
-
id: "test-source",
|
|
396
|
-
name: "Test Source",
|
|
397
|
-
type: "lark-cli",
|
|
398
|
-
enabled: true,
|
|
399
|
-
command: "lark-cli event +subscribe --quiet",
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
setMockExecResult("12345\n67890\n11111\n");
|
|
403
|
-
|
|
404
|
-
await component.startSource("test-source");
|
|
405
|
-
|
|
406
|
-
const processInfo = (component as any).processes.get("test-source");
|
|
407
|
-
expect(processInfo.pids).toContain(12345);
|
|
408
|
-
expect(processInfo.pids).toContain(67890);
|
|
409
|
-
expect(processInfo.pids).toContain(11111);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
test("RED: Windows 平台应正确解析输出(处理 \\r\\n)", async () => {
|
|
413
|
-
/**
|
|
414
|
-
* RED: 验证正确解析 Windows 输出(可能有回车换行)
|
|
415
|
-
*/
|
|
416
|
-
Object.defineProperty(process, "platform", {
|
|
417
|
-
value: "win32",
|
|
418
|
-
writable: true,
|
|
419
|
-
configurable: true,
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
await component.init({
|
|
423
|
-
name: "event-source",
|
|
424
|
-
version: "1.0.0",
|
|
425
|
-
enabled: true,
|
|
426
|
-
env: mockEnv as unknown as Environment,
|
|
427
|
-
options: { configComponent },
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
component.register({
|
|
431
|
-
id: "test-source",
|
|
432
|
-
name: "Test Source",
|
|
433
|
-
type: "lark-cli",
|
|
434
|
-
enabled: true,
|
|
435
|
-
command: "lark-cli event +subscribe --quiet",
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
setMockExecResult("12345\r\n67890\r\n");
|
|
439
|
-
|
|
440
|
-
await component.startSource("test-source");
|
|
441
|
-
|
|
442
|
-
const processInfo = (component as any).processes.get("test-source");
|
|
443
|
-
expect(processInfo.pids).toContain(12345);
|
|
444
|
-
expect(processInfo.pids).toContain(67890);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
test("RED: 应过滤掉无效的 PID(非数字)", async () => {
|
|
448
|
-
/**
|
|
449
|
-
* RED: 验证过滤掉输出中的非数字内容
|
|
450
|
-
*/
|
|
451
|
-
Object.defineProperty(process, "platform", {
|
|
452
|
-
value: "linux",
|
|
453
|
-
writable: true,
|
|
454
|
-
configurable: true,
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
await component.init({
|
|
458
|
-
name: "event-source",
|
|
459
|
-
version: "1.0.0",
|
|
460
|
-
enabled: true,
|
|
461
|
-
env: mockEnv as unknown as Environment,
|
|
462
|
-
options: { configComponent },
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
component.register({
|
|
466
|
-
id: "test-source",
|
|
467
|
-
name: "Test Source",
|
|
468
|
-
type: "lark-cli",
|
|
469
|
-
enabled: true,
|
|
470
|
-
command: "lark-cli event +subscribe --quiet",
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
setMockExecResult("12345\nabc\n67890\n\n");
|
|
474
|
-
|
|
475
|
-
await component.startSource("test-source");
|
|
476
|
-
|
|
477
|
-
const processInfo = (component as any).processes.get("test-source");
|
|
478
|
-
expect(processInfo.pids).toContain(12345);
|
|
479
|
-
expect(processInfo.pids).toContain(67890);
|
|
480
|
-
// abc 应该被过滤掉
|
|
481
|
-
expect(processInfo.pids.filter((p: number) => isNaN(p))).toHaveLength(0);
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
describe("命令转义和安全", () => {
|
|
486
|
-
test("RED: 命令模式应正确转义避免注入(Unix)", async () => {
|
|
487
|
-
/**
|
|
488
|
-
* RED: 验证 Unix 命令模式正确转义
|
|
489
|
-
*/
|
|
490
|
-
Object.defineProperty(process, "platform", {
|
|
491
|
-
value: "linux",
|
|
492
|
-
writable: true,
|
|
493
|
-
configurable: true,
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
await component.init({
|
|
497
|
-
name: "event-source",
|
|
498
|
-
version: "1.0.0",
|
|
499
|
-
enabled: true,
|
|
500
|
-
env: mockEnv as unknown as Environment,
|
|
501
|
-
options: { configComponent },
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
component.register({
|
|
505
|
-
id: "test-source",
|
|
506
|
-
name: "Test Source",
|
|
507
|
-
type: "lark-cli",
|
|
508
|
-
enabled: true,
|
|
509
|
-
command: "lark-cli event; rm -rf /",
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
setMockExecResult("12345");
|
|
513
|
-
|
|
514
|
-
await component.startSource("test-source");
|
|
515
|
-
|
|
516
|
-
const callArgs = mockExecAsync.mock.calls[0]?.[0] || "";
|
|
517
|
-
// 应该使用引号包裹模式,避免分号被解释为命令分隔符
|
|
518
|
-
expect(callArgs).toMatch(/pgrep.*['"].*['"]/);
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
test("RED: Windows 单引号应正确转义", async () => {
|
|
522
|
-
/**
|
|
523
|
-
* RED: 验证 Windows 命令中的单引号转义
|
|
524
|
-
* 注意:这个测试需要命令包含单引号,以确保转义逻辑正确
|
|
525
|
-
*/
|
|
526
|
-
Object.defineProperty(process, "platform", {
|
|
527
|
-
value: "win32",
|
|
528
|
-
writable: true,
|
|
529
|
-
configurable: true,
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
await component.init({
|
|
533
|
-
name: "event-source",
|
|
534
|
-
version: "1.0.0",
|
|
535
|
-
enabled: true,
|
|
536
|
-
env: mockEnv as unknown as Environment,
|
|
537
|
-
options: { configComponent },
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
component.register({
|
|
541
|
-
id: "test-source",
|
|
542
|
-
name: "Test Source",
|
|
543
|
-
type: "lark-cli",
|
|
544
|
-
enabled: true,
|
|
545
|
-
command: "lark-cli event --name='test app'",
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
setMockExecResult("12345");
|
|
549
|
-
|
|
550
|
-
await component.startSource("test-source");
|
|
551
|
-
|
|
552
|
-
const callArgs = mockExecAsync.mock.calls[0]?.[0] || "";
|
|
553
|
-
// PowerShell 需要转义单引号,但当前 trackRelatedProcesses 只提取 baseCommand (lark-cli),不含单引号
|
|
554
|
-
// 这个测试暂时跳过,直到实现完整命令模式的转义
|
|
555
|
-
// 如果要测试完整功能,需要修改 trackRelatedProcesses 以使用完整命令
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
describe("错误处理", () => {
|
|
560
|
-
test("RED: Unix pgrep 无匹配时应返回空数组", async () => {
|
|
561
|
-
/**
|
|
562
|
-
* RED: 验证 pgrep 无匹配时返回空数组而非报错
|
|
563
|
-
*/
|
|
564
|
-
Object.defineProperty(process, "platform", {
|
|
565
|
-
value: "linux",
|
|
566
|
-
writable: true,
|
|
567
|
-
configurable: true,
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
await component.init({
|
|
571
|
-
name: "event-source",
|
|
572
|
-
version: "1.0.0",
|
|
573
|
-
enabled: true,
|
|
574
|
-
env: mockEnv as unknown as Environment,
|
|
575
|
-
options: { configComponent },
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
component.register({
|
|
579
|
-
id: "test-source",
|
|
580
|
-
name: "Test Source",
|
|
581
|
-
type: "lark-cli",
|
|
582
|
-
enabled: true,
|
|
583
|
-
command: "nonexistent-command-xyz",
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
// pgrep 无匹配时返回错误
|
|
587
|
-
setMockExecError(new Error("No processes found"));
|
|
588
|
-
|
|
589
|
-
await component.startSource("test-source");
|
|
590
|
-
|
|
591
|
-
const processInfo = (component as any).processes.get("test-source");
|
|
592
|
-
expect(processInfo.pids).toBeDefined();
|
|
593
|
-
expect(Array.isArray(processInfo.pids)).toBe(true);
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
test("RED: Windows PowerShell 失败时应优雅处理", async () => {
|
|
597
|
-
/**
|
|
598
|
-
* RED: 验证 Windows PowerShell 失败时不崩溃
|
|
599
|
-
*/
|
|
600
|
-
Object.defineProperty(process, "platform", {
|
|
601
|
-
value: "win32",
|
|
602
|
-
writable: true,
|
|
603
|
-
configurable: true,
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
await component.init({
|
|
607
|
-
name: "event-source",
|
|
608
|
-
version: "1.0.0",
|
|
609
|
-
enabled: true,
|
|
610
|
-
env: mockEnv as unknown as Environment,
|
|
611
|
-
options: { configComponent },
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
component.register({
|
|
615
|
-
id: "test-source",
|
|
616
|
-
name: "Test Source",
|
|
617
|
-
type: "lark-cli",
|
|
618
|
-
enabled: true,
|
|
619
|
-
command: "lark-cli event +subscribe --quiet",
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
setMockExecError(new Error("PowerShell failed"));
|
|
623
|
-
|
|
624
|
-
await component.startSource("test-source");
|
|
625
|
-
|
|
626
|
-
const processInfo = (component as any).processes.get("test-source");
|
|
627
|
-
expect(processInfo).toBeDefined();
|
|
628
|
-
});
|
|
629
|
-
});
|
|
630
|
-
});
|