@zhushanwen/pi-subagent-workflow 8.6.0 → 8.7.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/package.json +9 -13
- package/relay/relay.mjs +1 -1
- package/src/host/__tests__/pi-host.test.ts +214 -0
- package/src/host/pi-host.ts +109 -0
- package/src/index.ts +89 -32
- package/src/injectors/__tests__/engine-awareness.test.ts +292 -0
- package/src/injectors/__tests__/engine-section-stability.test.ts +341 -0
- package/src/injectors/__tests__/subagent-list-injector.test.ts +5 -5
- package/src/injectors/__tests__/workflow-list-injector.test.ts +5 -5
- package/src/injectors/engine-awareness.ts +123 -0
- package/src/injectors/model-list-injector.ts +1 -1
- package/src/injectors/subagent-list-injector.ts +8 -8
- package/src/injectors/workflow-list-injector.ts +8 -8
- package/src/interface/__tests__/detectors.test.ts +3 -3
- package/src/interface/__tests__/subagent-tool-path-guard.test.ts +2 -2
- package/src/interface/__tests__/tool-workflow-script-generate.test.ts +2 -2
- package/src/interface/__tests__/tool-workflow-throw-paths.test.ts +1 -1
- package/src/interface/bg-notify-render.ts +4 -4
- package/src/interface/commands.ts +3 -3
- package/src/interface/format.ts +2 -2
- package/src/interface/helpers.ts +1 -1
- package/src/interface/list-component.ts +4 -4
- package/src/interface/list-shared.ts +2 -2
- package/src/interface/list-view.ts +2 -2
- package/src/interface/subagent-actions.ts +263 -11
- package/src/interface/subagent-tool-schema.ts +20 -13
- package/src/interface/subagent-tool.ts +11 -6
- package/src/interface/subagents.ts +3 -3
- package/src/interface/tool-render.ts +34 -2
- package/src/interface/tool-workflow-script.ts +4 -4
- package/src/interface/tool-workflow.ts +6 -6
- package/src/interface/views/WorkflowsView.ts +5 -5
- package/src/interface/views/__tests__/WorkflowsView-signature.test.ts +3 -3
- package/src/interface/views/__tests__/detail-content-session-file.test.ts +2 -2
- package/src/interface/views/detail-content.ts +4 -4
- package/src/interface/views/format.ts +4 -4
- package/src/{orchestration/jsonl-run-store.ts → jsonl-run-store.ts} +11 -11
- package/src/execution/__tests__/__fixtures__/notifier-golden-snapshots.json +0 -53
- package/src/execution/__tests__/__fixtures__/truncline.snapshot.json +0 -1
- package/src/execution/__tests__/agent-registry.test.ts +0 -363
- package/src/execution/__tests__/agent-result-mapper.test.ts +0 -150
- package/src/execution/__tests__/alive-store.test.ts +0 -147
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +0 -490
- package/src/execution/__tests__/before-agent-start-injection.test.ts +0 -132
- package/src/execution/__tests__/bg-notify-render.test.ts +0 -329
- package/src/execution/__tests__/channel-registry-handshake.test.ts +0 -243
- package/src/execution/__tests__/chat-engine-routing.test.ts +0 -601
- package/src/execution/__tests__/chatmode-first-round-closure-service.test.ts +0 -365
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +0 -190
- package/src/execution/__tests__/chatmode-round-notify-real-chain.test.ts +0 -215
- package/src/execution/__tests__/concurrency-pool.test.ts +0 -250
- package/src/execution/__tests__/config.test.ts +0 -110
- package/src/execution/__tests__/conversation-wiring.test.ts +0 -198
- package/src/execution/__tests__/crash-recovery.test.ts +0 -320
- package/src/execution/__tests__/delivery-methods.test.ts +0 -422
- package/src/execution/__tests__/dialog-queue.test.ts +0 -299
- package/src/execution/__tests__/epipe-fallback.test.ts +0 -241
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +0 -243
- package/src/execution/__tests__/execute-nesting.test.ts +0 -323
- package/src/execution/__tests__/execute-options-mapper.test.ts +0 -200
- package/src/execution/__tests__/execution-record.test.ts +0 -1394
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +0 -171
- package/src/execution/__tests__/finalize-record.test.ts +0 -368
- package/src/execution/__tests__/finalized-marker.test.ts +0 -82
- package/src/execution/__tests__/format-schema-instruction.test.ts +0 -169
- package/src/execution/__tests__/format.test.ts +0 -458
- package/src/execution/__tests__/gc-timer.test.ts +0 -184
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +0 -254
- package/src/execution/__tests__/gui-mode-dispatch.test.ts +0 -59
- package/src/execution/__tests__/helpers/mock-extension-api.ts +0 -30
- package/src/execution/__tests__/helpers/spawn-mock.ts +0 -242
- package/src/execution/__tests__/host-mode.test.ts +0 -87
- package/src/execution/__tests__/index-session-start-identity.test.ts +0 -371
- package/src/execution/__tests__/index-session-start.test.ts +0 -672
- package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
- package/src/execution/__tests__/lifecycle-manager.test.ts +0 -383
- package/src/execution/__tests__/lifecycle-predicates.test.ts +0 -116
- package/src/execution/__tests__/list-component.test.ts +0 -401
- package/src/execution/__tests__/list-fields.test.ts +0 -140
- package/src/execution/__tests__/manifest-parentid.test.ts +0 -117
- package/src/execution/__tests__/model-resolver.test.ts +0 -465
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +0 -287
- package/src/execution/__tests__/nested-visibility.test.ts +0 -325
- package/src/execution/__tests__/notifier-flush.test.ts +0 -612
- package/src/execution/__tests__/notifier-golden-snapshot.test.ts +0 -261
- package/src/execution/__tests__/notify-ledger.test.ts +0 -826
- package/src/execution/__tests__/one-shot-upgrade.test.ts +0 -205
- package/src/execution/__tests__/output-collector.test.ts +0 -358
- package/src/execution/__tests__/parent-child-matrix.test.ts +0 -336
- package/src/execution/__tests__/path-encoding.test.ts +0 -104
- package/src/execution/__tests__/pi-invocation.test.ts +0 -134
- package/src/execution/__tests__/record-store.test.ts +0 -1057
- package/src/execution/__tests__/records-cwd-isolation.test.ts +0 -91
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +0 -339
- package/src/execution/__tests__/recursive-visibility-env.test.ts +0 -273
- package/src/execution/__tests__/relay-agent.test.ts +0 -448
- package/src/execution/__tests__/relay-env.test.ts +0 -42
- package/src/execution/__tests__/resource-policy.test.ts +0 -109
- package/src/execution/__tests__/rpc-mode.test.ts +0 -89
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +0 -267
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +0 -253
- package/src/execution/__tests__/run-spawn-edges.test.ts +0 -687
- package/src/execution/__tests__/run-spawn-integration.test.ts +0 -933
- package/src/execution/__tests__/run-spawn-resume.test.ts +0 -322
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +0 -196
- package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +0 -199
- package/src/execution/__tests__/sdk-contract.test.ts +0 -273
- package/src/execution/__tests__/session-context-resolver.test.ts +0 -167
- package/src/execution/__tests__/session-file-gc.test.ts +0 -293
- package/src/execution/__tests__/session-pending.test.ts +0 -197
- package/src/execution/__tests__/session-reconstructor.test.ts +0 -379
- package/src/execution/__tests__/session-runner-epipe.test.ts +0 -178
- package/src/execution/__tests__/session-runner-schema-env.test.ts +0 -350
- package/src/execution/__tests__/session-start-reaper.test.ts +0 -233
- package/src/execution/__tests__/spawn-args.test.ts +0 -445
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +0 -189
- package/src/execution/__tests__/spawn-event-adapter.test.ts +0 -167
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +0 -207
- package/src/execution/__tests__/spawned-children.test.ts +0 -92
- package/src/execution/__tests__/start-sync-model-guard.test.ts +0 -150
- package/src/execution/__tests__/startup-config-declaration.test.ts +0 -35
- package/src/execution/__tests__/status-refactor.test.ts +0 -345
- package/src/execution/__tests__/stdin-writer.test.ts +0 -463
- package/src/execution/__tests__/stream-sink-retirement.test.ts +0 -261
- package/src/execution/__tests__/subagent-service-abort.test.ts +0 -60
- package/src/execution/__tests__/subagent-service-message-close.test.ts +0 -629
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +0 -180
- package/src/execution/__tests__/subagent-service.test.ts +0 -788
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -310
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +0 -599
- package/src/execution/__tests__/temp-prompt.test.ts +0 -53
- package/src/execution/__tests__/timeout-integration.test.ts +0 -615
- package/src/execution/__tests__/tombstone-store.test.ts +0 -73
- package/src/execution/__tests__/tool-action.test.ts +0 -476
- package/src/execution/__tests__/truncline-snapshot.test.ts +0 -81
- package/src/execution/__tests__/turn-limiter-semantics.test.ts +0 -194
- package/src/execution/__tests__/turn-limiter.test.ts +0 -65
- package/src/execution/__tests__/ui-channels.test.ts +0 -187
- package/src/execution/__tests__/ui-interaction-model.test.ts +0 -67
- package/src/execution/__tests__/ui-request-handler-factory.test.ts +0 -370
- package/src/execution/__tests__/ui-request-handler.test.ts +0 -204
- package/src/execution/__tests__/ui-request-observability.test.ts +0 -114
- package/src/execution/__tests__/ui-request-queue.test.ts +0 -133
- package/src/execution/__tests__/worktree-manager.test.ts +0 -633
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +0 -229
- package/src/execution/__tests__/worktree-reconcile.integration.test.ts +0 -181
- package/src/execution/__tests__/worktree-registry.test.ts +0 -199
- package/src/execution/agent-registry.ts +0 -199
- package/src/execution/agent-result-mapper.ts +0 -90
- package/src/execution/alive-store.ts +0 -92
- package/src/execution/argv-mirror.ts +0 -113
- package/src/execution/best-effort.ts +0 -38
- package/src/execution/channel-registry-access.ts +0 -144
- package/src/execution/concurrency-pool.ts +0 -116
- package/src/execution/config.ts +0 -96
- package/src/execution/dialog-queue.ts +0 -330
- package/src/execution/engine/__tests__/common/data-dir.test.ts +0 -53
- package/src/execution/engine/__tests__/common/errors.test.ts +0 -132
- package/src/execution/engine/__tests__/common/event-journal.test.ts +0 -177
- package/src/execution/engine/__tests__/common/kill-chain.test.ts +0 -192
- package/src/execution/engine/__tests__/common/nesting-guard.test.ts +0 -81
- package/src/execution/engine/__tests__/common/persona-router.test.ts +0 -123
- package/src/execution/engine/__tests__/common/pool-manager.test.ts +0 -154
- package/src/execution/engine/__tests__/common/schema-emulation.test.ts +0 -128
- package/src/execution/engine/__tests__/conformance/__fixtures__/pi-golden-events.json +0 -28
- package/src/execution/engine/__tests__/conformance/agent-event-invariants.ts +0 -141
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +0 -109
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +0 -101
- package/src/execution/engine/__tests__/conformance/contract.probe.test.ts +0 -77
- package/src/execution/engine/__tests__/conformance/contract.read-degradation.test.ts +0 -104
- package/src/execution/engine/__tests__/conformance/contract.relay.test.ts +0 -342
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +0 -201
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +0 -76
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +0 -79
- package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -87
- package/src/execution/engine/__tests__/engines-declaration.test.ts +0 -36
- package/src/execution/engine/__tests__/model-prompt.test.ts +0 -85
- package/src/execution/engine/__tests__/paths.test.ts +0 -39
- package/src/execution/engine/__tests__/registry.test.ts +0 -120
- package/src/execution/engine/__tests__/routing.test.ts +0 -231
- package/src/execution/engine/common/data-dir.ts +0 -62
- package/src/execution/engine/common/errors.ts +0 -183
- package/src/execution/engine/common/event-journal.ts +0 -254
- package/src/execution/engine/common/journal-replay.ts +0 -62
- package/src/execution/engine/common/kill-chain.ts +0 -221
- package/src/execution/engine/common/nesting-guard.ts +0 -50
- package/src/execution/engine/common/persona-router.ts +0 -108
- package/src/execution/engine/common/pool-manager.ts +0 -226
- package/src/execution/engine/common/schema-emulation.ts +0 -189
- package/src/execution/engine/common/session-view-projection.ts +0 -51
- package/src/execution/engine/engine-discovery.ts +0 -65
- package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +0 -469
- package/src/execution/engine/engines/pi/__tests__/reader.test.ts +0 -155
- package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
- package/src/execution/engine/engines/pi/pi-engine.ts +0 -415
- package/src/execution/engine/engines/pi/reader.ts +0 -48
- package/src/execution/engine/engines/pi/registration.ts +0 -35
- package/src/execution/engine/engines/pi/task-spec-mapper.ts +0 -100
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-spawn.json +0 -39
- package/src/execution/engine/engines/zcode/__tests__/launcher.test.ts +0 -150
- package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +0 -246
- package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +0 -228
- package/src/execution/engine/engines/zcode/__tests__/reader.test.ts +0 -210
- package/src/execution/engine/engines/zcode/__tests__/registration.test.ts +0 -64
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +0 -127
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +0 -580
- package/src/execution/engine/engines/zcode/constants.ts +0 -43
- package/src/execution/engine/engines/zcode/golden-sample.ts +0 -39
- package/src/execution/engine/engines/zcode/launcher.ts +0 -161
- package/src/execution/engine/engines/zcode/parser.ts +0 -436
- package/src/execution/engine/engines/zcode/preparer.ts +0 -363
- package/src/execution/engine/engines/zcode/reader.ts +0 -381
- package/src/execution/engine/engines/zcode/registration.ts +0 -37
- package/src/execution/engine/engines/zcode/zcode-engine.ts +0 -658
- package/src/execution/engine/host-task-spec.ts +0 -47
- package/src/execution/engine/model-prompt.ts +0 -59
- package/src/execution/engine/paths.ts +0 -42
- package/src/execution/engine/port.ts +0 -153
- package/src/execution/engine/registry.ts +0 -123
- package/src/execution/engine/routing.ts +0 -218
- package/src/execution/engine/types.ts +0 -309
- package/src/execution/execute-options-mapper.ts +0 -112
- package/src/execution/execution-record.ts +0 -965
- package/src/execution/finalize-record.ts +0 -251
- package/src/execution/finalized-marker.ts +0 -51
- package/src/execution/get-state-handshake.ts +0 -104
- package/src/execution/host-mode.ts +0 -56
- package/src/execution/idle-gc.ts +0 -47
- package/src/execution/lifecycle-manager.ts +0 -513
- package/src/execution/lifecycle-predicates.ts +0 -65
- package/src/execution/manifest-store.ts +0 -256
- package/src/execution/model-config-service.ts +0 -219
- package/src/execution/model-resolver.ts +0 -248
- package/src/execution/notifier.ts +0 -330
- package/src/execution/notify-ledger.ts +0 -580
- package/src/execution/output-collector.ts +0 -228
- package/src/execution/path-encoding.ts +0 -60
- package/src/execution/pi-invocation.ts +0 -120
- package/src/execution/record-entry.ts +0 -132
- package/src/execution/record-store.ts +0 -1234
- package/src/execution/relay-env.ts +0 -37
- package/src/execution/session-context-resolver.ts +0 -64
- package/src/execution/session-file-gc.ts +0 -120
- package/src/execution/session-pending.ts +0 -164
- package/src/execution/session-reconstructor.ts +0 -678
- package/src/execution/session-runner.ts +0 -1781
- package/src/execution/sessions-index.ts +0 -304
- package/src/execution/spawn-event-adapter.ts +0 -363
- package/src/execution/stdin-writer.ts +0 -198
- package/src/execution/stream-sink.ts +0 -126
- package/src/execution/subagent-service.ts +0 -2141
- package/src/execution/subprocess-agent-runner.ts +0 -317
- package/src/execution/temp-prompt.ts +0 -62
- package/src/execution/tombstone-store.ts +0 -72
- package/src/execution/turn-limiter.ts +0 -102
- package/src/execution/types.ts +0 -973
- package/src/execution/ui-channels.ts +0 -216
- package/src/execution/ui-interaction-model.ts +0 -48
- package/src/execution/ui-request-handler-factory.ts +0 -212
- package/src/execution/ui-request-observability.ts +0 -81
- package/src/execution/ui-request-queue.ts +0 -184
- package/src/execution/worktree-manager.ts +0 -688
- package/src/execution/worktree-registry.ts +0 -222
- package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +0 -349
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +0 -202
- package/src/orchestration/__tests__/agent-call-stream.test.ts +0 -152
- package/src/orchestration/__tests__/args-validator.test.ts +0 -143
- package/src/orchestration/__tests__/config-loader.test.ts +0 -503
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +0 -809
- package/src/orchestration/__tests__/error-recovery-postmessage-defense.test.ts +0 -405
- package/src/orchestration/__tests__/error-recovery-serialize-failed-result.test.ts +0 -56
- package/src/orchestration/__tests__/error-recovery-workflow-call.test.ts +0 -166
- package/src/orchestration/__tests__/execute-agent-call.test.ts +0 -451
- package/src/orchestration/__tests__/jsonl-run-store-corrupt-entry.test.ts +0 -150
- package/src/orchestration/__tests__/jsonl-run-store-loadall-sources.test.ts +0 -171
- package/src/orchestration/__tests__/jsonl-run-store-retention.test.ts +0 -202
- package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +0 -1030
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +0 -600
- package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +0 -96
- package/src/orchestration/__tests__/lifecycle.test.ts +0 -659
- package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +0 -95
- package/src/orchestration/__tests__/review-fix-loop-e2e.test.ts +0 -2025
- package/src/orchestration/__tests__/script-lint.test.ts +0 -831
- package/src/orchestration/__tests__/skill-discovery.test.ts +0 -201
- package/src/orchestration/__tests__/test-mocks.ts +0 -197
- package/src/orchestration/__tests__/worker-exit-without-result.test.ts +0 -368
- package/src/orchestration/__tests__/worker-host.test.ts +0 -120
- package/src/orchestration/__tests__/worker-returnmeta-passthrough.test.ts +0 -164
- package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +0 -563
- package/src/orchestration/__tests__/worker-script-builder.test.ts +0 -309
- package/src/orchestration/__tests__/worker-script-template-snapshot.test.ts +0 -129
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +0 -317
- package/src/orchestration/__tests__/workflow-script-lint-memo.test.ts +0 -110
- package/src/orchestration/__tests__/workflows-e2e.test.ts +0 -537
- package/src/orchestration/agent-opts-resolver.ts +0 -174
- package/src/orchestration/args-validator.ts +0 -127
- package/src/orchestration/config-loader.ts +0 -315
- package/src/orchestration/error-recovery.ts +0 -1018
- package/src/orchestration/execute-agent-call.ts +0 -256
- package/src/orchestration/launcher.ts +0 -455
- package/src/orchestration/lifecycle.ts +0 -399
- package/src/orchestration/models/__tests__/budget.test.ts +0 -307
- package/src/orchestration/models/__tests__/trace.test.ts +0 -408
- package/src/orchestration/models/agent-call.ts +0 -83
- package/src/orchestration/models/budget.ts +0 -118
- package/src/orchestration/models/ports.ts +0 -164
- package/src/orchestration/models/run-runtime.ts +0 -104
- package/src/orchestration/models/run-spec.ts +0 -83
- package/src/orchestration/models/run-state.ts +0 -44
- package/src/orchestration/models/trace.ts +0 -183
- package/src/orchestration/models/types.ts +0 -301
- package/src/orchestration/models/workflow-run.ts +0 -254
- package/src/orchestration/models/workflow-script-registry.ts +0 -35
- package/src/orchestration/models/workflow-script.ts +0 -117
- package/src/orchestration/script-lint.ts +0 -766
- package/src/orchestration/skill-discovery.ts +0 -115
- package/src/orchestration/worker-handle.ts +0 -115
- package/src/orchestration/worker-host.ts +0 -98
- package/src/orchestration/worker-script-builder.ts +0 -421
- package/src/orchestration/workflow-files.ts +0 -85
- package/src/orchestration/workflow-script-registry-impl.ts +0 -133
- package/src/shared/__tests__/agent-ref.test.ts +0 -34
- package/src/shared/__tests__/meta-parser.test.ts +0 -304
- package/src/shared/__tests__/model-ref.test.ts +0 -306
- package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -280
- package/src/shared/__tests__/resource-discovery.test.ts +0 -736
- package/src/shared/__tests__/resource-meta.test.ts +0 -51
- package/src/shared/__tests__/schema-jsonify.test.ts +0 -81
- package/src/shared/__tests__/timer-delay.test.ts +0 -61
- package/src/shared/agent-event.ts +0 -13
- package/src/shared/agent-ref.ts +0 -57
- package/src/shared/meta-parser.ts +0 -261
- package/src/shared/model-ref.ts +0 -286
- package/src/shared/resource-discovery.ts +0 -811
- package/src/shared/resource-meta.ts +0 -65
- package/src/shared/schema-env.ts +0 -44
- package/src/shared/schema-jsonify.ts +0 -58
- package/src/shared/timer-delay.ts +0 -54
- package/src/shared/xml-injection.ts +0 -35
- package/workflows/README.md +0 -81
- package/workflows/_shared/agent-refs.cjs +0 -40
- package/workflows/chain.js +0 -131
- package/workflows/map-reduce.js +0 -174
- package/workflows/parallel.js +0 -148
- package/workflows/review-fix-loop-utils.cjs +0 -1309
- package/workflows/review-fix-loop.js +0 -1404
- package/workflows/scatter-gather.js +0 -178
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
// src/execution/__tests__/chatmode-round-notify-real-chain.test.ts
|
|
2
|
-
//
|
|
3
|
-
// [N2] chatMode 轮次通知正文——真实 session-runner 链路测试。
|
|
4
|
-
//
|
|
5
|
-
// round2 审查实证的断链:agent_settled → onRoundSettled 先 notifyComplete(此时
|
|
6
|
-
// record.result 从未被写——成功轮次的 MF-2 原写点 doFinalizeRoundToIdle 对
|
|
7
|
-
// runAndFinalize early return 不可达)→ 轮次通知正文恒 "(empty)",turns[].text 已累积
|
|
8
|
-
// 但 notify 读的是 record.result。修复:onRoundSettled 在 notify 前从本轮 turns 派生
|
|
9
|
-
// 回复文本(对齐 collectResult 的 getFullText)写入 record.result。
|
|
10
|
-
//
|
|
11
|
-
// 与 chatmode-first-round-closure-service.test.ts(mock session-runner)不同,本文件用
|
|
12
|
-
// 真实 session-runner(FakeChild 驱动 text_delta / agent_settled)+ 真实
|
|
13
|
-
// service.execute(conversation:true),禁止手工预置 record.result——那正是掩盖断链的方式。
|
|
14
|
-
// mock 结构与 run-spawn-chatmode-settled.test.ts 一致(FakeChild + session-pending count=0)。
|
|
15
|
-
|
|
16
|
-
import { spawn } from "node:child_process";
|
|
17
|
-
import * as fs from "node:fs";
|
|
18
|
-
import * as os from "node:os";
|
|
19
|
-
import * as path from "node:path";
|
|
20
|
-
|
|
21
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
22
|
-
|
|
23
|
-
const { loggerMock } = vi.hoisted(() => ({
|
|
24
|
-
loggerMock: { debug: vi.fn(), warn: vi.fn(), error: vi.fn(), info: vi.fn() },
|
|
25
|
-
}));
|
|
26
|
-
vi.mock("@zhushanwen/pi-extension-logger", () => ({ getLogger: () => loggerMock }));
|
|
27
|
-
|
|
28
|
-
vi.mock("node:child_process", async () => {
|
|
29
|
-
const { FakeChild } = await import("./helpers/spawn-mock.ts");
|
|
30
|
-
return {
|
|
31
|
-
spawn: vi.fn(() => new FakeChild()),
|
|
32
|
-
// buildEnvBlock 的 git branch 调用(execFile 异步):默认 err-first 兜底 → catch → branch=""
|
|
33
|
-
execFile: vi.fn(
|
|
34
|
-
(
|
|
35
|
-
_cmd: string,
|
|
36
|
-
_args: readonly string[],
|
|
37
|
-
_opts: unknown,
|
|
38
|
-
cb: (err: Error | null, stdout?: string, stderr?: string) => void,
|
|
39
|
-
) => cb(new Error("execFile not configured in this test")),
|
|
40
|
-
),
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
vi.mock("node:fs", async () => {
|
|
45
|
-
const actual = await import("node:fs");
|
|
46
|
-
return {
|
|
47
|
-
default: {
|
|
48
|
-
...actual,
|
|
49
|
-
mkdirSync: vi.fn(),
|
|
50
|
-
existsSync: vi.fn(() => false),
|
|
51
|
-
appendFileSync: vi.fn(),
|
|
52
|
-
writeFileSync: vi.fn(),
|
|
53
|
-
readdirSync: vi.fn(() => []),
|
|
54
|
-
},
|
|
55
|
-
mkdirSync: vi.fn(),
|
|
56
|
-
existsSync: vi.fn(() => false),
|
|
57
|
-
appendFileSync: vi.fn(),
|
|
58
|
-
writeFileSync: vi.fn(),
|
|
59
|
-
readdirSync: vi.fn(() => []),
|
|
60
|
-
// tmp 目录创建/清理走真实实现(本文件用例级隔离需要)
|
|
61
|
-
mkdtempSync: actual.mkdtempSync,
|
|
62
|
-
rmSync: actual.rmSync,
|
|
63
|
-
promises: actual.promises,
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// removeAliveMarker 一并 mock(finalize-record 消费;成功轮次 early return 不触达,防御性补全)
|
|
68
|
-
vi.mock("../alive-store.ts", () => ({
|
|
69
|
-
writeAliveMarker: vi.fn(),
|
|
70
|
-
removeAliveMarker: vi.fn(),
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
// chatMode agent_end 早返回不读后代判定;统一 count=0(对齐 harness)。
|
|
74
|
-
vi.mock("../session-pending.ts", () => ({
|
|
75
|
-
readActivePendingFromSessionFile: vi.fn(() => ({ count: 0 })),
|
|
76
|
-
}));
|
|
77
|
-
|
|
78
|
-
vi.mock("../temp-prompt.ts", () => ({
|
|
79
|
-
writePromptToTempFile: vi.fn(async (agent: string) => {
|
|
80
|
-
const safeName = agent.replace(/[^\w.-]+/g, "_");
|
|
81
|
-
return { dir: `/tmp/fake-${safeName}`, filePath: `/tmp/fake-${safeName}/prompt-${safeName}.md` };
|
|
82
|
-
}),
|
|
83
|
-
cleanupTempPrompt: vi.fn(async () => {}),
|
|
84
|
-
}));
|
|
85
|
-
|
|
86
|
-
import { _resetLifecycleState } from "../lifecycle-manager.ts";
|
|
87
|
-
import { ModelConfigService } from "../model-config-service.ts";
|
|
88
|
-
import type { ModelInfo, ModelRegistryLike } from "../model-resolver.ts";
|
|
89
|
-
import type { ExecutionRecord } from "../types.ts";
|
|
90
|
-
import { SubagentService } from "../subagent-service.ts";
|
|
91
|
-
import type { PiLike } from "../subagent-service.ts";
|
|
92
|
-
import {
|
|
93
|
-
emitStdoutLine,
|
|
94
|
-
lastSpawnedChild,
|
|
95
|
-
sessionHeader,
|
|
96
|
-
waitForSpawn,
|
|
97
|
-
} from "./helpers/spawn-mock.ts";
|
|
98
|
-
|
|
99
|
-
const mockSpawn = vi.mocked(spawn);
|
|
100
|
-
|
|
101
|
-
const STUB_MODEL: ModelInfo = { id: "test-model", name: "Test", provider: "test", reasoning: false };
|
|
102
|
-
|
|
103
|
-
/** 最小合法 registry(initModel fail-fast 需要;resolveModel 第三层直接透传 ctxModel)。 */
|
|
104
|
-
function makeEmptyRegistry(): ModelRegistryLike {
|
|
105
|
-
return { getAvailable: () => [], find: () => undefined, hasConfiguredAuth: () => true };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function makePi(): PiLike & {
|
|
109
|
-
appendEntry: ReturnType<typeof vi.fn>;
|
|
110
|
-
events: { emit: ReturnType<typeof vi.fn> };
|
|
111
|
-
sendMessage: ReturnType<typeof vi.fn>;
|
|
112
|
-
} {
|
|
113
|
-
return { appendEntry: vi.fn(), events: { emit: vi.fn() }, sendMessage: vi.fn() };
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** 暴露私有 store 的接口(测试专用 cast)。 */
|
|
117
|
-
interface ServiceInternals {
|
|
118
|
-
store: { getMutable(id: string): ExecutionRecord | undefined };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
describe("[N2] chatMode 轮次通知正文:真实 session-runner 链路", () => {
|
|
122
|
-
let agentDir: string;
|
|
123
|
-
let service: SubagentService;
|
|
124
|
-
let pi: ReturnType<typeof makePi>;
|
|
125
|
-
let internals: ServiceInternals;
|
|
126
|
-
|
|
127
|
-
beforeEach(() => {
|
|
128
|
-
vi.clearAllMocks();
|
|
129
|
-
// lifecycle-manager 模块级单例(idleTimers Map 跨用例共享),每用例前清空防泄漏。
|
|
130
|
-
_resetLifecycleState();
|
|
131
|
-
agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "round-notify-"));
|
|
132
|
-
const modelService = new ModelConfigService({ agentDir, cwd: agentDir });
|
|
133
|
-
modelService.initModel({
|
|
134
|
-
modelRegistry: makeEmptyRegistry(),
|
|
135
|
-
sessionId: "root-session",
|
|
136
|
-
ctxModel: STUB_MODEL,
|
|
137
|
-
});
|
|
138
|
-
service = new SubagentService({ cwd: agentDir, modelService });
|
|
139
|
-
pi = makePi();
|
|
140
|
-
service.initSession({ pi, sessionId: "root-session" });
|
|
141
|
-
internals = service as unknown as ServiceInternals;
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
afterEach(() => {
|
|
145
|
-
service.dispose();
|
|
146
|
-
_resetLifecycleState();
|
|
147
|
-
vi.restoreAllMocks();
|
|
148
|
-
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("真实 execute(conversation:true) + FakeChild 驱动 text_delta/agent_settled → 通知正文含本轮真实回复(非 (empty))", async () => {
|
|
152
|
-
const ROUND_REPLY = "THE ROUND REPLY";
|
|
153
|
-
|
|
154
|
-
// 真实链路:execute → kickOffBackground → runAndFinalize → 真实 runSpawn → FakeChild。
|
|
155
|
-
// ctx.onRoundSettled 由 buildSessionRunnerContext 注入(真实回调,非 mock)。
|
|
156
|
-
const handle = await service.execute({
|
|
157
|
-
task: "tell me something",
|
|
158
|
-
slug: "round-notify",
|
|
159
|
-
conversation: true,
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
await waitForSpawn(mockSpawn);
|
|
163
|
-
const child = lastSpawnedChild(mockSpawn);
|
|
164
|
-
|
|
165
|
-
// 真实事件链:header(握手加速)→ text_delta(本轮回复累积进 turns)→ turn_end →
|
|
166
|
-
// agent_end(chatMode 保活)→ agent_settled(真空闲:armIdleTimer → onRoundSettled)。
|
|
167
|
-
emitStdoutLine(child, sessionHeader("sess-round-1"));
|
|
168
|
-
emitStdoutLine(child, {
|
|
169
|
-
type: "message_update",
|
|
170
|
-
// type 对齐 pi-ai AssistantMessageEvent 真实协议(text 增量 = "text_delta",带 contentIndex)。
|
|
171
|
-
// 曾用 {type:"text"} 假类型——旧实现不查 type 只看 delta 碰巧兼容;现实现按 type 正向
|
|
172
|
-
// 分流(toolcall_delta 不混入 text 流),假类型事件被正确丢弃,fake 必须对齐真实协议。
|
|
173
|
-
assistantMessageEvent: { type: "text_delta", contentIndex: 0, delta: ROUND_REPLY },
|
|
174
|
-
});
|
|
175
|
-
emitStdoutLine(child, { type: "turn_end" });
|
|
176
|
-
emitStdoutLine(child, { type: "agent_end", willRetry: false });
|
|
177
|
-
emitStdoutLine(child, { type: "agent_settled" });
|
|
178
|
-
|
|
179
|
-
// agent_settled → onRoundSettled(round+1 + record.result 派生 + notifyComplete)→
|
|
180
|
-
// 无其他 busy background → 立即 flush → pi.sendMessage。
|
|
181
|
-
await vi.waitFor(() => {
|
|
182
|
-
expect(pi.sendMessage).toHaveBeenCalledTimes(1);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const sentMsg = pi.sendMessage.mock.calls[0]![0] as { customType: string; content: string };
|
|
186
|
-
expect(sentMsg.customType).toBe("subagent-bg-notify");
|
|
187
|
-
expect(sentMsg.content).toContain("finished a round");
|
|
188
|
-
// [N2] 核心:正文含本轮真实回复文本(修复前此处是 "(empty)")
|
|
189
|
-
expect(sentMsg.content).toContain(ROUND_REPLY);
|
|
190
|
-
expect(sentMsg.content).not.toContain("(empty)");
|
|
191
|
-
|
|
192
|
-
// record 侧:turns 已累积 + result 从 turns 真实派生(非手工预置)+ running-resumable
|
|
193
|
-
const record = internals.store.getMutable(handle.subagentId);
|
|
194
|
-
expect(record).toBeDefined();
|
|
195
|
-
expect(record!.turns[0]!.text).toBe(ROUND_REPLY);
|
|
196
|
-
expect(record!.result).toBe(ROUND_REPLY);
|
|
197
|
-
expect(record!.status).toBe("running");
|
|
198
|
-
expect(record!.round).toBe(1);
|
|
199
|
-
|
|
200
|
-
// 收尾:close 让 runSpawn resolve → runAndFinalize 续体 early return → .then 的
|
|
201
|
-
// notifyComplete 被同 id:round dedup 吞——总发送数仍恰为 1。
|
|
202
|
-
child.stdout.end();
|
|
203
|
-
child.stderr.end();
|
|
204
|
-
child.emit("close", 0);
|
|
205
|
-
await new Promise((r) => setTimeout(r, 30));
|
|
206
|
-
expect(pi.sendMessage).toHaveBeenCalledTimes(1);
|
|
207
|
-
|
|
208
|
-
// [C2] close 现状语义扩展:终态化不再发新通知(总数仍 1),末条轮次通知含
|
|
209
|
-
// Full transcript 指针行——真实链路 sessionHeader 已回填 record.sessionFile
|
|
210
|
-
//(session-runner.ts:1039),chatMode:true 经 toNotifyRecord 条件透传到通知正文。
|
|
211
|
-
const lastMsg = pi.sendMessage.mock.calls[0]![0] as { content: string; details?: { sessionFile?: string } };
|
|
212
|
-
expect(lastMsg.details?.sessionFile).toBe(record!.sessionFile);
|
|
213
|
-
expect(lastMsg.content).toContain(`\n\nFull transcript: ${record!.sessionFile}`);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
// src/__tests__/concurrency-pool.test.ts
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { DefaultConcurrencyPool } from "../concurrency-pool.ts";
|
|
5
|
-
|
|
6
|
-
describe("DefaultConcurrencyPool", () => {
|
|
7
|
-
it("allows up to maxConcurrent concurrent tasks", async () => {
|
|
8
|
-
const pool = new DefaultConcurrencyPool(2);
|
|
9
|
-
await pool.acquire(0);
|
|
10
|
-
await pool.acquire(0);
|
|
11
|
-
// 第三个 acquire 应阻塞
|
|
12
|
-
let thirdAcquired = false;
|
|
13
|
-
const third = pool.acquire(0).then(() => { thirdAcquired = true; });
|
|
14
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
15
|
-
expect(thirdAcquired).toBe(false);
|
|
16
|
-
expect(pool.active).toBe(2);
|
|
17
|
-
|
|
18
|
-
pool.release();
|
|
19
|
-
await third;
|
|
20
|
-
expect(thirdAcquired).toBe(true);
|
|
21
|
-
expect(pool.active).toBe(2);
|
|
22
|
-
|
|
23
|
-
pool.release();
|
|
24
|
-
pool.release();
|
|
25
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
26
|
-
expect(pool.active).toBe(0);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("higher priority acquires the pool first", async () => {
|
|
30
|
-
const pool = new DefaultConcurrencyPool(1);
|
|
31
|
-
await pool.acquire(0); // 占满
|
|
32
|
-
|
|
33
|
-
let lowAcquired = false;
|
|
34
|
-
let highAcquired = false;
|
|
35
|
-
const low = pool.acquire(10).then(() => { lowAcquired = true; });
|
|
36
|
-
const high = pool.acquire(0).then(() => { highAcquired = true; });
|
|
37
|
-
|
|
38
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
39
|
-
pool.release();
|
|
40
|
-
await Promise.race([low, high, new Promise((r) => setTimeout(r, 20))]);
|
|
41
|
-
|
|
42
|
-
expect(highAcquired).toBe(true);
|
|
43
|
-
expect(lowAcquired).toBe(false);
|
|
44
|
-
pool.release();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("same-priority tasks wake in FIFO (seq) order", async () => {
|
|
48
|
-
const pool = new DefaultConcurrencyPool(1);
|
|
49
|
-
await pool.acquire(0); // fill slot
|
|
50
|
-
|
|
51
|
-
const order: number[] = [];
|
|
52
|
-
// Enqueue 3 tasks with same priority — they should resolve in enqueue order
|
|
53
|
-
const p1 = pool.acquire(0).then(() => { order.push(1); pool.release(); });
|
|
54
|
-
const p2 = pool.acquire(0).then(() => { order.push(2); pool.release(); });
|
|
55
|
-
const p3 = pool.acquire(0).then(() => { order.push(3); pool.release(); });
|
|
56
|
-
|
|
57
|
-
pool.release(); // kick off the chain
|
|
58
|
-
await Promise.allSettled([p1, p2, p3]);
|
|
59
|
-
|
|
60
|
-
expect(order).toEqual([1, 2, 3]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("extra release() does not make active negative", () => {
|
|
64
|
-
const pool = new DefaultConcurrencyPool(2);
|
|
65
|
-
pool.release(); // no acquires yet
|
|
66
|
-
pool.release();
|
|
67
|
-
pool.release();
|
|
68
|
-
expect(pool.active).toBe(0);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("active never exceeds maxConcurrent", async () => {
|
|
72
|
-
const pool = new DefaultConcurrencyPool(2);
|
|
73
|
-
const acquires: Array<Promise<void>> = [];
|
|
74
|
-
let peak = 0;
|
|
75
|
-
for (let i = 0; i < 6; i++) {
|
|
76
|
-
acquires.push(pool.acquire(0).then(() => {
|
|
77
|
-
peak = Math.max(peak, pool.active);
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
// Drain: release one at a time so we can observe peak
|
|
81
|
-
for (let i = 0; i < 6; i++) {
|
|
82
|
-
pool.release();
|
|
83
|
-
await new Promise((r) => setTimeout(r, 2));
|
|
84
|
-
}
|
|
85
|
-
await Promise.allSettled(acquires);
|
|
86
|
-
expect(peak).toBeLessThanOrEqual(2);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("clamps maxConcurrent=0 to 1 (no deadlock, C3 fix)", async () => {
|
|
90
|
-
const pool = new DefaultConcurrencyPool(0);
|
|
91
|
-
// 不会死锁——clamp 到 1,acquire 立即返回
|
|
92
|
-
await pool.acquire(0);
|
|
93
|
-
expect(pool.active).toBe(1);
|
|
94
|
-
pool.release();
|
|
95
|
-
expect(pool.active).toBe(0);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("clamps negative maxConcurrent to 1", async () => {
|
|
99
|
-
const pool = new DefaultConcurrencyPool(-5);
|
|
100
|
-
await pool.acquire(0);
|
|
101
|
-
expect(pool.active).toBe(1);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("priority 0 (sync) preempts priority 1000 (background)", async () => {
|
|
105
|
-
const pool = new DefaultConcurrencyPool(1);
|
|
106
|
-
await pool.acquire(1000); // background 占满
|
|
107
|
-
|
|
108
|
-
let bgAcquired = false;
|
|
109
|
-
let syncAcquired = false;
|
|
110
|
-
const bg = pool.acquire(1000).then(() => { bgAcquired = true; });
|
|
111
|
-
const sync = pool.acquire(0).then(() => { syncAcquired = true; });
|
|
112
|
-
|
|
113
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
114
|
-
pool.release();
|
|
115
|
-
await Promise.race([bg, sync, new Promise((r) => setTimeout(r, 20))]);
|
|
116
|
-
|
|
117
|
-
expect(syncAcquired).toBe(true);
|
|
118
|
-
expect(bgAcquired).toBe(false);
|
|
119
|
-
pool.release();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// ============================================================
|
|
123
|
-
// 分层配额:effectiveMaxConcurrent 参数控制放行上限 (T-A1~T-A4)
|
|
124
|
-
// ============================================================
|
|
125
|
-
//
|
|
126
|
-
// [背景] T2 Wave 0 给 acquire 增加可选 effectiveMaxConcurrent 参数,让调用方
|
|
127
|
-
// 传 max(1, maxConcurrent - depth) 实现分层配额(嵌套越深有效并发越小)。
|
|
128
|
-
// 该参数覆盖实例级 maxConcurrent 的本次调用上限,不改实例状态。
|
|
129
|
-
// 这组测试锁定该参数的语义。
|
|
130
|
-
|
|
131
|
-
describe("分层配额 effectiveMaxConcurrent (T-A1~T-A4)", () => {
|
|
132
|
-
it("T-A1: effectiveMaxConcurrent 限制本次调用放行数(小于实例级 maxConcurrent)", async () => {
|
|
133
|
-
// 实例配额 5,但本次调用 effective=2 → 第 3 个应阻塞
|
|
134
|
-
const pool = new DefaultConcurrencyPool(5);
|
|
135
|
-
await pool.acquire(0, 2);
|
|
136
|
-
await pool.acquire(0, 2);
|
|
137
|
-
expect(pool.active).toBe(2);
|
|
138
|
-
|
|
139
|
-
let thirdAcquired = false;
|
|
140
|
-
const third = pool.acquire(0, 2).then(() => { thirdAcquired = true; });
|
|
141
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
142
|
-
|
|
143
|
-
expect(thirdAcquired).toBe(false);
|
|
144
|
-
expect(pool.active).toBe(2);
|
|
145
|
-
|
|
146
|
-
pool.release();
|
|
147
|
-
await third;
|
|
148
|
-
expect(thirdAcquired).toBe(true);
|
|
149
|
-
pool.release();
|
|
150
|
-
pool.release();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("T-A2: 同一 pool 实例不同 effectiveMaxConcurrent 控制不同调用放行数", async () => {
|
|
154
|
-
// 同一 pool(实例级 maxConcurrent=5)
|
|
155
|
-
const pool = new DefaultConcurrencyPool(5);
|
|
156
|
-
// 前 3 个用 effective=3,全放行(active 0→1→2→3,每次 < 3)
|
|
157
|
-
await pool.acquire(0, 3);
|
|
158
|
-
await pool.acquire(0, 3);
|
|
159
|
-
await pool.acquire(0, 3);
|
|
160
|
-
expect(pool.active).toBe(3);
|
|
161
|
-
|
|
162
|
-
// 第 4 个用 effective=3 → 阻塞(active 3 >= 3)
|
|
163
|
-
let blockedAcquired = false;
|
|
164
|
-
const blocked = pool.acquire(0, 3).then(() => { blockedAcquired = true; });
|
|
165
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
166
|
-
expect(blockedAcquired).toBe(false);
|
|
167
|
-
|
|
168
|
-
// 换 effective=5 放行(active 3 < 5)
|
|
169
|
-
let wideAcquired = false;
|
|
170
|
-
const wide = pool.acquire(0, 5).then(() => { wideAcquired = true; });
|
|
171
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
172
|
-
expect(wideAcquired).toBe(true);
|
|
173
|
-
expect(pool.active).toBe(4);
|
|
174
|
-
|
|
175
|
-
// wide release 后 blocked 仍等(active 3 >= 3 不变直到再 release)
|
|
176
|
-
pool.release(); // wide 释放
|
|
177
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
178
|
-
expect(blockedAcquired).toBe(true);
|
|
179
|
-
|
|
180
|
-
// 清理
|
|
181
|
-
pool.release();
|
|
182
|
-
pool.release();
|
|
183
|
-
pool.release();
|
|
184
|
-
pool.release();
|
|
185
|
-
await Promise.allSettled([blocked, wide]);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("T-A3: effectiveMaxConcurrent=1 只放行 1 个(保底)", async () => {
|
|
189
|
-
const pool = new DefaultConcurrencyPool(5);
|
|
190
|
-
await pool.acquire(0, 1);
|
|
191
|
-
expect(pool.active).toBe(1);
|
|
192
|
-
|
|
193
|
-
let secondAcquired = false;
|
|
194
|
-
const second = pool.acquire(0, 1).then(() => { secondAcquired = true; });
|
|
195
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
196
|
-
expect(secondAcquired).toBe(false);
|
|
197
|
-
expect(pool.active).toBe(1);
|
|
198
|
-
|
|
199
|
-
pool.release();
|
|
200
|
-
await second;
|
|
201
|
-
expect(secondAcquired).toBe(true);
|
|
202
|
-
pool.release();
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("T-A4: maxConcurrent readonly 属性可读且等于构造值", () => {
|
|
206
|
-
const pool = new DefaultConcurrencyPool(4);
|
|
207
|
-
expect(pool.maxConcurrent).toBe(4);
|
|
208
|
-
|
|
209
|
-
// clamp 路径也通过该属性暴露
|
|
210
|
-
const clamped = new DefaultConcurrencyPool(0);
|
|
211
|
-
expect(clamped.maxConcurrent).toBe(1);
|
|
212
|
-
|
|
213
|
-
const negative = new DefaultConcurrencyPool(-3);
|
|
214
|
-
expect(negative.maxConcurrent).toBe(1);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
// ============================================================
|
|
219
|
-
// H2: acquire 支持 AbortSignal — abort 时排队条目 reject
|
|
220
|
-
// ============================================================
|
|
221
|
-
describe("H2 abort support for acquire", () => {
|
|
222
|
-
it("abort signal rejects queued acquire with AbortError", async () => {
|
|
223
|
-
const pool = new DefaultConcurrencyPool(1);
|
|
224
|
-
await pool.acquire(0); // 占满
|
|
225
|
-
|
|
226
|
-
const controller = new AbortController();
|
|
227
|
-
const queued = pool.acquire(0, undefined, controller.signal);
|
|
228
|
-
|
|
229
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
230
|
-
expect(pool.active).toBe(1); // 仍在排队
|
|
231
|
-
|
|
232
|
-
controller.abort();
|
|
233
|
-
|
|
234
|
-
await expect(queued).rejects.toThrow("aborted");
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("non-aborted acquire still resolves normally after release", async () => {
|
|
238
|
-
const pool = new DefaultConcurrencyPool(1);
|
|
239
|
-
await pool.acquire(0); // 占满
|
|
240
|
-
|
|
241
|
-
const controller = new AbortController();
|
|
242
|
-
const queued = pool.acquire(0, undefined, controller.signal);
|
|
243
|
-
|
|
244
|
-
pool.release(); // 释放 → queued 应被 resolve
|
|
245
|
-
await queued; // 不应 reject
|
|
246
|
-
expect(pool.active).toBe(1);
|
|
247
|
-
pool.release();
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
});
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
// src/__tests__/config.test.ts
|
|
2
|
-
//
|
|
3
|
-
// loadGlobalConfig 测试。
|
|
4
|
-
// 配置已退化为仅 maxConcurrent(模型解析改为「主 agent model 优先」,
|
|
5
|
-
// 不再有 categories/fallback/yolo/session 级覆盖)。
|
|
6
|
-
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import * as os from "node:os";
|
|
9
|
-
import * as path from "node:path";
|
|
10
|
-
|
|
11
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
12
|
-
|
|
13
|
-
import { getGlobalConfigPath, loadGlobalConfig } from "../config.ts";
|
|
14
|
-
|
|
15
|
-
let tmpDir: string;
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "subagents-config-test-"));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
/** 写入 config.json(自动创建 subagents/ 子目录)。 */
|
|
26
|
-
function writeConfig(agentDir: string, content: string): void {
|
|
27
|
-
const configPath = getGlobalConfigPath(agentDir);
|
|
28
|
-
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
29
|
-
fs.writeFileSync(configPath, content, "utf-8");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ============================================================
|
|
33
|
-
// loadGlobalConfig
|
|
34
|
-
// ============================================================
|
|
35
|
-
|
|
36
|
-
describe("loadGlobalConfig", () => {
|
|
37
|
-
it("returns default config when file does not exist", () => {
|
|
38
|
-
const cfg = loadGlobalConfig(tmpDir);
|
|
39
|
-
expect(cfg.version).toBe(1);
|
|
40
|
-
expect(cfg.maxConcurrent).toBe(6);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("returns default config when JSON is corrupt", () => {
|
|
44
|
-
writeConfig(tmpDir, "{not valid json");
|
|
45
|
-
const cfg = loadGlobalConfig(tmpDir);
|
|
46
|
-
expect(cfg.version).toBe(1);
|
|
47
|
-
expect(cfg.maxConcurrent).toBe(6);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("deep-merges with defaults: missing fields fall back to defaults", () => {
|
|
51
|
-
writeConfig(tmpDir, JSON.stringify({ version: 1 }));
|
|
52
|
-
const cfg = loadGlobalConfig(tmpDir);
|
|
53
|
-
expect(cfg.version).toBe(1);
|
|
54
|
-
expect(cfg.maxConcurrent).toBe(6);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("loads valid config with maxConcurrent override", () => {
|
|
58
|
-
writeConfig(tmpDir, JSON.stringify({ version: 1, maxConcurrent: 8 }));
|
|
59
|
-
const cfg = loadGlobalConfig(tmpDir);
|
|
60
|
-
expect(cfg.maxConcurrent).toBe(8);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("ignores legacy categories/fallback/yoloByDefault fields (model resolution deprecated)", () => {
|
|
64
|
-
// 旧 config.json 仍可能含这些字段——读取时不报错,但 SubagentsGlobalConfig
|
|
65
|
-
// 类型上已不含它们,loadGlobalConfig 只取 version + maxConcurrent。
|
|
66
|
-
writeConfig(
|
|
67
|
-
tmpDir,
|
|
68
|
-
JSON.stringify({
|
|
69
|
-
version: 1,
|
|
70
|
-
maxConcurrent: 6,
|
|
71
|
-
yoloByDefault: true,
|
|
72
|
-
categories: { coding: { label: "C", model: "x/y" } },
|
|
73
|
-
fallback: { model: "anthropic/x" },
|
|
74
|
-
}),
|
|
75
|
-
);
|
|
76
|
-
const cfg = loadGlobalConfig(tmpDir);
|
|
77
|
-
expect(cfg.maxConcurrent).toBe(6);
|
|
78
|
-
expect(cfg.version).toBe(1);
|
|
79
|
-
// 仅两个字段(类型保证)
|
|
80
|
-
expect(Object.keys(cfg).sort()).toEqual(["maxConcurrent", "version"]);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// ============================================================
|
|
85
|
-
// sanitizeMaxConcurrent(经 loadGlobalConfig 间接覆盖)
|
|
86
|
-
// ============================================================
|
|
87
|
-
|
|
88
|
-
describe("sanitizeMaxConcurrent (via loadGlobalConfig)", () => {
|
|
89
|
-
it("rejects non-number maxConcurrent → default", () => {
|
|
90
|
-
writeConfig(tmpDir, JSON.stringify({ maxConcurrent: "eight" }));
|
|
91
|
-
expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("rejects non-integer maxConcurrent → default", () => {
|
|
95
|
-
writeConfig(tmpDir, JSON.stringify({ maxConcurrent: 4.5 }));
|
|
96
|
-
expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("rejects zero/negative maxConcurrent → default", () => {
|
|
100
|
-
writeConfig(tmpDir, JSON.stringify({ maxConcurrent: 0 }));
|
|
101
|
-
expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
|
|
102
|
-
writeConfig(tmpDir, JSON.stringify({ maxConcurrent: -1 }));
|
|
103
|
-
expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(6);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("accepts positive integer", () => {
|
|
107
|
-
writeConfig(tmpDir, JSON.stringify({ maxConcurrent: 16 }));
|
|
108
|
-
expect(loadGlobalConfig(tmpDir).maxConcurrent).toBe(16);
|
|
109
|
-
});
|
|
110
|
-
});
|