@zhushanwen/subagent-core 0.2.0 → 0.5.1
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/README.md +45 -2
- package/agents/analyst.md +60 -0
- package/agents/coder.md +69 -0
- package/agents/debugger.md +66 -0
- package/agents/doc-reviewer.md +49 -0
- package/agents/explorer.md +63 -0
- package/agents/general-purpose.md +32 -0
- package/agents/orchestrator.md +61 -0
- package/agents/planner.md +53 -0
- package/agents/researcher.md +67 -0
- package/agents/reviewer.md +73 -0
- package/dist/chunk-43ONBFZX.js +240 -0
- package/dist/chunk-APZY4IME.js +27 -0
- package/dist/chunk-V3VHZ2VX.js +59 -0
- package/dist/execution/engine/engines/zcode/constants.cjs +62 -9
- package/dist/execution/engine/engines/zcode/constants.d.cts +116 -12
- package/dist/execution/engine/engines/zcode/constants.d.ts +116 -12
- package/dist/execution/engine/engines/zcode/constants.js +39 -7
- package/dist/execution/engine/engines/zcode/reader.d.cts +2 -1
- package/dist/execution/engine/engines/zcode/reader.d.ts +2 -1
- package/dist/execution/engine/engines/zcode/reader.js +4 -234
- package/dist/execution/engine/paths.js +7 -19
- package/dist/index.cjs +18234 -1277
- package/dist/index.d.cts +5646 -673
- package/dist/index.d.ts +5646 -673
- package/dist/index.js +17828 -1277
- package/dist/{types-BxyAidGf.d.cts → types-Dv4QhSJ_.d.cts} +678 -112
- package/dist/{types-BxyAidGf.d.ts → types-Dv4QhSJ_.d.ts} +678 -112
- package/package.json +7 -4
- package/src/__tests__/agent-opts-resolver-schema-prompt.test.ts +0 -1
- package/src/__tests__/append-system-prompt-assembly.test.ts +8 -7
- package/src/__tests__/fr4-get-state-handshake.test.ts +2 -2
- package/src/__tests__/m2-append-content-probe.test.ts +0 -1
- package/src/__tests__/manifest-store.test.ts +10 -9
- package/src/__tests__/record-store-cache.test.ts +0 -2
- package/src/__tests__/record-store-index.test.ts +1 -2
- package/src/__tests__/review-fix-loop-script.test.ts +93 -3
- package/src/__tests__/review-fix-loop-utils.test.ts +31 -10
- package/src/__tests__/robustness-low-batch1.test.ts +6 -5
- package/src/__tests__/robustness-medium-batch1.test.ts +2 -2
- package/src/__tests__/robustness-medium-batch2.test.ts +17 -6
- package/src/__tests__/robustness-medium-batch4.test.ts +2 -2
- package/src/__tests__/session-runner.test.ts +1 -1
- package/src/__tests__/smoke.test.ts +9 -2
- package/src/core/__tests__/host-services.test.ts +2 -2
- package/src/core/__tests__/logger.test.ts +1 -1
- package/src/core/error-message.ts +9 -0
- package/src/core/host-services.ts +21 -5
- package/src/core/notify-ports.ts +18 -5
- package/src/execution/__tests__/agent-profile.test.ts +232 -0
- package/src/execution/__tests__/agent-registry.test.ts +370 -0
- package/src/execution/__tests__/agent-result-mapper.test.ts +18 -2
- package/src/execution/__tests__/agents-assembly.test.ts +219 -0
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +6 -6
- package/src/execution/__tests__/chat-engine-routing.test.ts +136 -30
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +5 -4
- package/src/execution/__tests__/cold-resurrect.test.ts +283 -0
- package/src/execution/__tests__/create-concurrency-pool.test.ts +194 -0
- package/src/execution/__tests__/delivery-methods.test.ts +77 -62
- package/src/execution/__tests__/descendant-sweep-guards.test.ts +220 -0
- package/src/execution/__tests__/descendant-sweep.test.ts +269 -0
- package/src/execution/__tests__/dialog-queue.test.ts +199 -1
- package/src/execution/__tests__/engine-model-validation.test.ts +741 -0
- package/src/execution/__tests__/epipe-fallback.test.ts +31 -24
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +21 -91
- package/src/execution/__tests__/execute-nesting.test.ts +34 -188
- package/src/execution/__tests__/execution-record.test.ts +217 -60
- package/src/execution/__tests__/execution-runtime-face.test.ts +272 -0
- package/src/execution/__tests__/explicit-agent-ref-guard.test.ts +3 -3
- package/src/execution/__tests__/finalize-record.test.ts +278 -16
- package/src/execution/__tests__/gc-timer.test.ts +57 -2
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +14 -12
- package/src/execution/__tests__/get-state-handshake.test.ts +127 -0
- package/src/execution/__tests__/helpers/mock-extension-api.ts +1 -1
- package/src/execution/__tests__/helpers/session-runner-mocks.ts +113 -0
- package/src/execution/__tests__/helpers/spawn-mock.ts +150 -3
- package/src/execution/__tests__/helpers/subagent-service-mocks.ts +137 -0
- package/src/execution/__tests__/keep-alive-no-progress.test.ts +280 -0
- package/src/execution/__tests__/kill-all-escalation.test.ts +196 -0
- package/src/execution/__tests__/lifecycle-manager-idle-timer-identity.test.ts +117 -0
- package/src/execution/__tests__/lifecycle-manager.test.ts +39 -0
- package/src/execution/__tests__/lifecycle-predicates.test.ts +1 -2
- package/src/execution/__tests__/manifest-parentid.test.ts +4 -4
- package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +99 -0
- package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +113 -0
- package/src/execution/__tests__/model-resolver.test.ts +2 -2
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +23 -121
- package/src/execution/__tests__/nested-visibility.test.ts +2 -0
- package/src/execution/__tests__/notify-ledger.test.ts +1249 -0
- package/src/execution/__tests__/output-collector.test.ts +117 -6
- package/src/execution/__tests__/pi-invocation.test.ts +1 -1
- package/src/execution/__tests__/record-store-orphan-revive.test.ts +159 -0
- package/src/execution/__tests__/record-store.test.ts +89 -5
- package/src/execution/__tests__/records-cwd-isolation.test.ts +2 -2
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +29 -132
- package/src/execution/__tests__/recursive-visibility-env.test.ts +55 -179
- package/src/execution/__tests__/rpc-mode.test.ts +2 -2
- package/src/execution/__tests__/run-and-finalize-anchoring.test.ts +387 -0
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +19 -9
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +5 -4
- package/src/execution/__tests__/run-spawn-edges.test.ts +418 -26
- package/src/execution/__tests__/run-spawn-integration.test.ts +3 -3
- package/src/execution/__tests__/run-spawn-resume.test.ts +2 -2
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +2 -2
- package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +16 -8
- package/src/execution/__tests__/service-kill-escalation.test.ts +91 -0
- package/src/execution/__tests__/session-context-resolver.test.ts +0 -2
- package/src/execution/__tests__/session-file-gc.test.ts +35 -0
- package/src/execution/__tests__/session-pending.test.ts +471 -0
- package/src/execution/__tests__/session-reconstructor.test.ts +366 -15
- package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +110 -0
- package/src/execution/__tests__/session-runner-close-prune.test.ts +181 -0
- package/src/execution/__tests__/session-runner-dispatch.test.ts +489 -0
- package/src/execution/__tests__/session-runner-epipe.test.ts +4 -3
- package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +227 -0
- package/src/execution/__tests__/session-runner-lifecycle-helpers.test.ts +290 -0
- package/src/execution/__tests__/session-runner-schema-env.test.ts +7 -5
- package/src/execution/__tests__/settled-watchdog.test.ts +524 -0
- package/src/execution/__tests__/spawn-args.test.ts +11 -10
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +26 -23
- package/src/execution/__tests__/spawn-event-adapter.test.ts +1 -1
- package/src/execution/__tests__/spawn-worktree-guidance.test.ts +5 -4
- package/src/execution/__tests__/spawned-children.test.ts +155 -11
- package/src/execution/__tests__/start-sync-model-guard.test.ts +4 -4
- package/src/execution/__tests__/stdin-writer.test.ts +6 -4
- package/src/execution/__tests__/stream-sink-retirement.test.ts +6 -6
- package/src/execution/__tests__/subagent-actions-core.test.ts +1017 -0
- package/src/execution/__tests__/subagent-service-message-close.test.ts +99 -35
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +174 -0
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +271 -0
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +33 -29
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +341 -0
- package/src/execution/__tests__/subagent-service.test.ts +37 -30
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +88 -12
- package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +75 -0
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +22 -20
- package/src/execution/__tests__/temp-prompt.test.ts +1 -1
- package/src/execution/__tests__/timeout-integration.test.ts +13 -12
- package/src/execution/__tests__/turn-limiter-semantics.test.ts +1 -1
- package/src/execution/__tests__/turn-limiter.test.ts +1 -1
- package/src/execution/__tests__/ui-request-handler-factory.test.ts +107 -7
- package/src/execution/__tests__/ui-request-handler.test.ts +4 -3
- package/src/execution/__tests__/ui-request-queue.test.ts +167 -2
- package/src/execution/__tests__/worktree-git-ops.test.ts +571 -0
- package/src/execution/__tests__/worktree-manager.test.ts +14 -5
- package/src/execution/__tests__/worktree-pid-registration.integration.test.ts +4 -3
- package/src/execution/__tests__/worktree-reconcile-aging.test.ts +204 -0
- package/src/execution/agent-registry.ts +298 -30
- package/src/execution/agent-result-mapper.ts +3 -0
- package/src/execution/agents-assembly.ts +88 -0
- package/src/execution/cold-resurrect.ts +199 -0
- package/src/execution/concurrency-pool.ts +71 -9
- package/src/execution/dialog-queue.ts +101 -3
- package/src/execution/engine/__tests__/common/capability-gate.test.ts +91 -0
- package/src/execution/engine/__tests__/common/data-dir.test.ts +1 -1
- package/src/execution/engine/__tests__/common/journal-wiring.test.ts +84 -0
- package/src/execution/engine/__tests__/common/kill-chain.test.ts +34 -7
- package/src/execution/engine/__tests__/common/persona-router.test.ts +4 -5
- package/src/execution/engine/__tests__/common/pool-manager.test.ts +211 -51
- package/src/execution/engine/__tests__/common/session-view-service-zcode-dbpath.test.ts +149 -0
- package/src/execution/engine/__tests__/common/session-view-service.test.ts +499 -0
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +56 -99
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +88 -15
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +33 -7
- package/src/execution/engine/__tests__/conformance/golden-replay.pi.test.ts +1 -1
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +75 -54
- package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +128 -0
- package/src/execution/engine/__tests__/engine-discovery.test.ts +15 -3
- package/src/execution/engine/__tests__/model-prompt.test.ts +15 -3
- package/src/execution/engine/__tests__/registry.test.ts +94 -3
- package/src/execution/engine/__tests__/routing.test.ts +115 -6
- package/src/execution/engine/common/capability-gate.ts +92 -0
- package/src/execution/engine/common/journal-wiring.ts +97 -0
- package/src/execution/engine/common/kill-chain.ts +42 -10
- package/src/execution/engine/common/nesting-guard.ts +66 -0
- package/src/execution/engine/common/persona-router.ts +18 -8
- package/src/execution/engine/common/pool-manager.ts +332 -78
- package/src/execution/engine/common/session-view-service.ts +506 -0
- package/src/execution/engine/common/session-view-types.ts +125 -0
- package/src/execution/engine/engine-discovery.ts +12 -16
- package/src/execution/engine/engines/pi/__tests__/pi-engine.test.ts +174 -28
- package/src/execution/engine/engines/pi/__tests__/spawn-opts-direct.test.ts +257 -0
- package/src/execution/{argv-mirror.ts → engine/engines/pi/argv-mirror.ts} +43 -21
- package/src/execution/{get-state-handshake.ts → engine/engines/pi/get-state-handshake.ts} +86 -11
- package/src/execution/{output-collector.ts → engine/engines/pi/output-collector.ts} +108 -19
- package/src/execution/engine/engines/pi/pi-engine.ts +434 -38
- package/src/execution/{pi-invocation.ts → engine/engines/pi/pi-invocation.ts} +2 -2
- package/src/execution/engine/engines/pi/reader.ts +11 -0
- package/src/execution/engine/engines/pi/registration.ts +4 -2
- package/src/execution/engine/engines/pi/session-runner.ts +2840 -0
- package/src/execution/{spawn-event-adapter.ts → engine/engines/pi/spawn-event-adapter.ts} +75 -34
- package/src/execution/{stdin-writer.ts → engine/engines/pi/stdin-writer.ts} +10 -9
- package/src/execution/{temp-prompt.ts → engine/engines/pi/temp-prompt.ts} +2 -2
- package/src/execution/{turn-limiter.ts → engine/engines/pi/turn-limiter.ts} +1 -1
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +301 -0
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json +36 -0
- package/src/execution/engine/engines/zcode/__tests__/appserver-launcher.test.ts +321 -0
- package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +473 -0
- package/src/execution/engine/engines/zcode/__tests__/parser.test.ts +7 -210
- package/src/execution/engine/engines/zcode/__tests__/preparer.test.ts +6 -110
- package/src/execution/engine/engines/zcode/__tests__/session-channel-dispose-harvest.test.ts +247 -0
- package/src/execution/engine/engines/zcode/__tests__/session-channel-turn-timers.test.ts +451 -0
- package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +792 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +782 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +168 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-dispose.test.ts +210 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-retry.test.ts +353 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-status.test.ts +282 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-timeout.test.ts +372 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +65 -47
- package/src/execution/engine/engines/zcode/appserver-launcher.ts +167 -0
- package/src/execution/engine/engines/zcode/connection.ts +598 -0
- package/src/execution/engine/engines/zcode/constants.ts +147 -14
- package/src/execution/engine/engines/zcode/golden-sample.ts +42 -34
- package/src/execution/engine/engines/zcode/parser.ts +12 -346
- package/src/execution/engine/engines/zcode/preparer.ts +22 -150
- package/src/execution/engine/engines/zcode/session-channel.ts +968 -0
- package/src/execution/engine/engines/zcode/zcode-engine.ts +1023 -250
- package/src/execution/engine/host-task-spec.ts +32 -36
- package/src/execution/engine/model-validation.ts +177 -0
- package/src/execution/engine/port.ts +65 -7
- package/src/execution/engine/registry.ts +53 -0
- package/src/execution/engine/routing.ts +75 -1
- package/src/execution/engine/types.ts +30 -103
- package/src/execution/execution-record.ts +222 -144
- package/src/execution/finalize-record.ts +181 -85
- package/src/execution/idle-gc.ts +28 -0
- package/src/execution/lifecycle-manager.ts +27 -3
- package/src/execution/lifecycle-predicates.ts +1 -1
- package/src/execution/manifest-store.ts +53 -62
- package/src/execution/notifier.ts +10 -10
- package/src/execution/notify-host.ts +212 -0
- package/src/execution/notify-ledger.ts +117 -16
- package/src/execution/record-entry.ts +8 -2
- package/src/execution/record-store.ts +148 -88
- package/src/execution/round-settlement.ts +93 -0
- package/src/execution/session-file-gc.ts +96 -62
- package/src/execution/session-pending.ts +213 -62
- package/src/execution/session-reconstructor.ts +256 -143
- package/src/execution/sessions-index.ts +127 -102
- package/src/execution/settled-watchdog.ts +311 -0
- package/src/execution/subagent-actions-core.ts +686 -0
- package/src/execution/subagent-service.ts +1106 -907
- package/src/execution/subprocess-agent-runner.ts +144 -97
- package/src/execution/types.ts +9 -0
- package/src/execution/ui-request-handler-factory.ts +126 -75
- package/src/execution/ui-request-queue.ts +50 -19
- package/src/execution/worktree-git-ops.ts +397 -0
- package/src/execution/worktree-manager.ts +72 -10
- package/src/execution/worktree-registry.ts +6 -12
- package/src/index.ts +542 -9
- package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +42 -3
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +3 -5
- package/src/orchestration/__tests__/agent-call-stream.test.ts +2 -2
- package/src/orchestration/__tests__/args-meta.test.ts +358 -0
- package/src/orchestration/__tests__/args-validator.test.ts +14 -0
- package/src/orchestration/__tests__/error-recovery-rebuild-failure.test.ts +312 -0
- package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +384 -0
- package/src/orchestration/__tests__/execute-agent-call.test.ts +151 -11
- package/src/orchestration/__tests__/file-run-store-prune.test.ts +168 -0
- package/src/orchestration/__tests__/file-run-store-throttle.test.ts +168 -0
- package/src/orchestration/__tests__/file-run-store.test.ts +390 -0
- package/src/orchestration/__tests__/helpers/flush-microtasks.ts +13 -0
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +34 -0
- package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +357 -0
- package/src/orchestration/__tests__/lifecycle-recover-crashed.test.ts +289 -0
- package/src/orchestration/__tests__/lifecycle-runid-injection.test.ts +3 -3
- package/src/orchestration/__tests__/lifecycle.test.ts +84 -5
- package/src/orchestration/__tests__/non-cloneable-return-e2e.test.ts +1 -1
- package/src/orchestration/__tests__/run-snapshot.test.ts +356 -0
- package/src/orchestration/__tests__/script-generate.test.ts +314 -0
- package/src/orchestration/__tests__/script-lint.test.ts +17 -0
- package/src/orchestration/__tests__/test-mocks.ts +2 -0
- package/src/orchestration/__tests__/worker-exit-without-result.test.ts +7 -6
- package/src/orchestration/__tests__/worker-message-pump-finalize-run.test.ts +229 -0
- package/src/orchestration/__tests__/{error-recovery-handlers.test.ts → worker-message-pump-handlers.test.ts} +28 -27
- package/src/orchestration/__tests__/{error-recovery-postmessage-defense.test.ts → worker-message-pump-postmessage-defense.test.ts} +8 -8
- package/src/orchestration/__tests__/{error-recovery-serialize-failed-result.test.ts → worker-message-pump-serialize-failed-result.test.ts} +2 -2
- package/src/orchestration/__tests__/{error-recovery-workflow-call.test.ts → worker-message-pump-workflow-call.test.ts} +1 -1
- package/src/orchestration/__tests__/worker-pending-timeout-abort.test.ts +275 -0
- package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +78 -1
- package/src/orchestration/__tests__/worker-script-builder.test.ts +1 -1
- package/src/orchestration/__tests__/workflow-files.test.ts +186 -0
- package/src/orchestration/__tests__/workflow-nesting-e2e.test.ts +1 -1
- package/src/orchestration/__tests__/workflow-run-summary.test.ts +119 -0
- package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +124 -0
- package/src/orchestration/agent-opts-resolver.ts +8 -8
- package/src/orchestration/args-meta.ts +198 -0
- package/src/orchestration/args-validator.ts +53 -31
- package/src/orchestration/execute-agent-call.ts +25 -79
- package/src/orchestration/file-run-store.ts +327 -0
- package/src/orchestration/launcher.ts +160 -104
- package/src/orchestration/lifecycle.ts +371 -97
- package/src/orchestration/models/agent-call.ts +7 -7
- package/src/orchestration/models/budget.ts +5 -5
- package/src/orchestration/models/ports.ts +4 -4
- package/src/orchestration/models/run-runtime.ts +15 -15
- package/src/orchestration/models/trace.ts +9 -9
- package/src/orchestration/models/types.ts +111 -22
- package/src/orchestration/models/workflow-run.ts +28 -28
- package/src/orchestration/models/workflow-script.ts +4 -4
- package/src/orchestration/run-snapshot.ts +266 -0
- package/src/orchestration/script-generate.ts +154 -0
- package/src/orchestration/script-lint.ts +123 -90
- package/src/orchestration/worker-handle.ts +10 -10
- package/src/orchestration/worker-host.ts +10 -10
- package/src/orchestration/{error-recovery.ts → worker-message-pump.ts} +498 -221
- package/src/orchestration/worker-script-builder.ts +401 -346
- package/src/orchestration/workflow-files.ts +37 -11
- package/src/orchestration/workflow-run-summary.ts +69 -0
- package/src/orchestration/workflow-script-registry-impl.ts +31 -9
- package/src/shared/__tests__/agent-ref.test.ts +209 -2
- package/src/shared/__tests__/atomic-write.test.ts +267 -0
- package/src/shared/__tests__/bounded-serialize.test.ts +236 -0
- package/src/shared/__tests__/injection-render.test.ts +518 -0
- package/src/shared/__tests__/meta-parser.test.ts +151 -0
- package/src/shared/__tests__/resource-discovery-host-roots.test.ts +474 -0
- package/src/shared/__tests__/resource-discovery.test.ts +261 -217
- package/src/shared/agent-ref.ts +143 -2
- package/src/shared/atomic-write.ts +323 -0
- package/src/shared/bounded-serialize.ts +154 -0
- package/src/shared/injection-render.ts +279 -0
- package/src/shared/meta-parser.ts +182 -68
- package/src/shared/model-ref.ts +15 -2
- package/src/shared/resource-discovery.ts +97 -204
- package/src/shared/resource-meta.ts +14 -0
- package/src/shared/schema-jsonify.ts +1 -1
- package/src/shared/xml-injection.ts +9 -9
- package/workflows/README.md +9 -9
- package/workflows/chain.js +4 -2
- package/workflows/map-reduce.js +5 -3
- package/workflows/parallel.js +5 -3
- package/workflows/review-fix-loop-utils.cjs +165 -92
- package/workflows/review-fix-loop-utils.d.cts +287 -0
- package/workflows/review-fix-loop.js +18 -7
- package/workflows/scatter-gather.js +4 -2
- package/dist/chunk-3VOERJPJ.js +0 -22
- package/src/execution/__tests__/execute-options-mapper.test.ts +0 -200
- package/src/execution/engine/engines/pi/__tests__/task-spec-mapper.test.ts +0 -164
- 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__/zcode-engine.test.ts +0 -580
- package/src/execution/engine/engines/zcode/launcher.ts +0 -161
- package/src/execution/execute-options-mapper.ts +0 -115
- package/src/execution/session-runner.ts +0 -1789
- package/src/shared/__tests__/resource-discovery-manifest-cache.test.ts +0 -288
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
// file-run-store.test.ts —— RunStore port 的宿主无关文件实现(D2 设计件)。
|
|
2
|
+
//
|
|
3
|
+
// 四视角:
|
|
4
|
+
// ①使用者——save/loadAll 往返一致(聚合根字段全量保真:spec/state/budget/calls/trace/meta);
|
|
5
|
+
// ②隔离者——多 run 各落各文件,互不串扰;
|
|
6
|
+
// ③幸存者——append-only + 损坏行容错(半行写入崩溃后取最后一条「有效」行;整文件损坏不炸 loadAll);
|
|
7
|
+
// ④接线者——stateFilePath 路径形状(<dataRoot>/workflow-state/<runId>.jsonl)与
|
|
8
|
+
// 未 configureCore 的 fail-loud(core_host_not_configured,§3.4 错误规格)。
|
|
9
|
+
//
|
|
10
|
+
// dataRoot 经 configureCore(tmp) 注入 + resetCoreForTests 复位(对齐
|
|
11
|
+
// core/__tests__/host-services.test.ts 的配置态隔离模式);warn 断言经宿主 log
|
|
12
|
+
// 端口 spy 捕获(logger facade 每次调用动态解析宿主实现,logger.ts 契约)。
|
|
13
|
+
|
|
14
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
19
|
+
|
|
20
|
+
import { configureCore, resetCoreForTests, type HostServices } from "../../core/host-services.ts";
|
|
21
|
+
import { Budget } from "../models/budget.ts";
|
|
22
|
+
import { Trace } from "../models/trace.ts";
|
|
23
|
+
import { WorkflowRun } from "../models/workflow-run.ts";
|
|
24
|
+
import { FileRunStore } from "../file-run-store.ts";
|
|
25
|
+
|
|
26
|
+
let dataRoot: string;
|
|
27
|
+
let logSpy: ReturnType<typeof vi.fn<(level: import("../../core/logger.ts").LogLevel, component: string, message: string, data?: unknown) => void>>;
|
|
28
|
+
let store: FileRunStore;
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
resetCoreForTests();
|
|
32
|
+
dataRoot = mkdtempSync(join(tmpdir(), "file-run-store-"));
|
|
33
|
+
logSpy = vi.fn((_level: import("../../core/logger.ts").LogLevel, _component: string, _message: string, _data?: unknown) => {});
|
|
34
|
+
const host: HostServices = {
|
|
35
|
+
dataRoot: () => dataRoot,
|
|
36
|
+
log: logSpy,
|
|
37
|
+
};
|
|
38
|
+
configureCore(host);
|
|
39
|
+
store = new FileRunStore();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
resetCoreForTests();
|
|
44
|
+
rmSync(dataRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/** 构造可持久化的 WorkflowRun(对齐 lifecycle.test.ts makeEvictableRun 模式)。 */
|
|
48
|
+
function makeRun(runId: string, opts: { status?: "running" | "done" } = {}): WorkflowRun {
|
|
49
|
+
const status = opts.status ?? "running";
|
|
50
|
+
return WorkflowRun.reconstruct(
|
|
51
|
+
runId,
|
|
52
|
+
{
|
|
53
|
+
scriptSource: "export function execute() { return 'ok'; }",
|
|
54
|
+
args: { topic: "demo", count: 2 },
|
|
55
|
+
scriptName: "test-script",
|
|
56
|
+
scriptPath: "/fake/test.js",
|
|
57
|
+
parameters: { type: "object" },
|
|
58
|
+
budgetTokens: 1000,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
status,
|
|
62
|
+
...(status === "done" ? { reason: "completed" as const } : {}),
|
|
63
|
+
budget: new Budget({ maxTokens: 1000, usedTokens: 42, usedCost: 0.5, totalCallCount: 3 }),
|
|
64
|
+
calls: new Map(),
|
|
65
|
+
trace: new Trace(),
|
|
66
|
+
errorLogs: [],
|
|
67
|
+
scriptResult: status === "done" ? { summary: "done-value" } : undefined,
|
|
68
|
+
},
|
|
69
|
+
{ startedAt: "2026-08-30T00:00:00.000Z" },
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** warn 级日志消息集合(log 端口 (level, component, message) 签名过滤)。 */
|
|
74
|
+
function warnMessages(): string[] {
|
|
75
|
+
return logSpy.mock.calls
|
|
76
|
+
.filter((c) => c[0] === "warn")
|
|
77
|
+
.map((c) => String(c[2]));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 直接往 workflow-state 目录写预置文件(损坏行场景——不经 save 路径建目录)。 */
|
|
81
|
+
function writeStateFile(name: string, content: string): void {
|
|
82
|
+
const dir = join(dataRoot, "workflow-state");
|
|
83
|
+
mkdirSync(dir, { recursive: true });
|
|
84
|
+
writeFileSync(join(dir, name), content);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe("FileRunStore — save/loadAll 往返一致", () => {
|
|
88
|
+
it("running 快照往返:runId/spec/budget/trace/meta 字段保真", async () => {
|
|
89
|
+
const run = makeRun("wf-rt-1");
|
|
90
|
+
await store.save(run);
|
|
91
|
+
|
|
92
|
+
const loaded = await store.loadAll();
|
|
93
|
+
expect(loaded).toHaveLength(1);
|
|
94
|
+
const back = loaded[0];
|
|
95
|
+
|
|
96
|
+
expect(back.runId).toBe("wf-rt-1");
|
|
97
|
+
expect(back.state.status).toBe("running");
|
|
98
|
+
expect(back.spec.scriptName).toBe("test-script");
|
|
99
|
+
expect(back.spec.args).toEqual({ topic: "demo", count: 2 });
|
|
100
|
+
expect(back.spec.parameters).toEqual({ type: "object" });
|
|
101
|
+
// Budget 重水合为实例且消耗累积保真(后续预算判定不归零)
|
|
102
|
+
expect(back.state.budget).toBeInstanceOf(Budget);
|
|
103
|
+
expect(back.state.budget.maxTokens).toBe(1000);
|
|
104
|
+
expect(back.state.budget.usedTokens).toBe(42);
|
|
105
|
+
expect(back.state.budget.usedCost).toBe(0.5);
|
|
106
|
+
expect(back.state.budget.totalCallCount).toBe(3);
|
|
107
|
+
// Trace 重水合为实例;runtime 不落盘(跨进程必死,reconstruct 语义)
|
|
108
|
+
expect(back.state.trace).toBeInstanceOf(Trace);
|
|
109
|
+
expect(back.runtime).toBeUndefined();
|
|
110
|
+
expect(back.meta.startedAt).toBe("2026-08-30T00:00:00.000Z");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("done 快照往返:reason/scriptResult/error 保真", async () => {
|
|
114
|
+
const run = makeRun("wf-rt-2", { status: "done" });
|
|
115
|
+
await store.save(run);
|
|
116
|
+
|
|
117
|
+
const back = (await store.loadAll())[0];
|
|
118
|
+
expect(back.state.status).toBe("done");
|
|
119
|
+
expect(back.state.reason).toBe("completed");
|
|
120
|
+
expect(back.state.scriptResult).toEqual({ summary: "done-value" });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("append-only:同 run 多次 save 追加多行,loadAll 取最后一条(状态演进不丢)", async () => {
|
|
124
|
+
const run = makeRun("wf-rt-3");
|
|
125
|
+
await store.save(run);
|
|
126
|
+
run.transition("done", "failed");
|
|
127
|
+
await store.save(run);
|
|
128
|
+
|
|
129
|
+
const raw = readFileSync(store.stateFilePath("wf-rt-3"), "utf8");
|
|
130
|
+
expect(raw.trim().split("\n")).toHaveLength(2);
|
|
131
|
+
|
|
132
|
+
const back = (await store.loadAll())[0];
|
|
133
|
+
expect(back.state.status).toBe("done");
|
|
134
|
+
expect(back.state.reason).toBe("failed");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("含 calls 的快照往返:calls Map 逐项保真 + traceNode 回链 Trace 副本", async () => {
|
|
138
|
+
const run = makeRun("wf-rt-4");
|
|
139
|
+
// 经公开 append 路径构造 trace 节点(Trace 值对象,禁止外部打洞 nodes 数组;
|
|
140
|
+
// append 返回 void,节点对象由调用方持有——正是 D-10「call 与 trace 共享引用」的入口)
|
|
141
|
+
const node = {
|
|
142
|
+
stepIndex: 0,
|
|
143
|
+
agent: "coder",
|
|
144
|
+
task: "do work",
|
|
145
|
+
model: "test-model",
|
|
146
|
+
status: "completed" as const,
|
|
147
|
+
};
|
|
148
|
+
run.state.trace.append(node);
|
|
149
|
+
const calls = run.state.calls as Map<number, import("../models/agent-call.ts").AgentCall>;
|
|
150
|
+
const AgentCallMod = await import("../models/agent-call.ts");
|
|
151
|
+
const call = new AgentCallMod.AgentCall(0, { prompt: "do work" }, node);
|
|
152
|
+
call.status = "done";
|
|
153
|
+
call.attempts = 1;
|
|
154
|
+
run.state.calls.set(0, call);
|
|
155
|
+
|
|
156
|
+
await store.save(run);
|
|
157
|
+
const back = (await store.loadAll())[0];
|
|
158
|
+
|
|
159
|
+
expect(back.state.calls.size).toBe(1);
|
|
160
|
+
const restored = back.state.calls.get(0)!;
|
|
161
|
+
expect(restored.id).toBe(0);
|
|
162
|
+
expect(restored.opts.prompt).toBe("do work");
|
|
163
|
+
expect(restored.status).toBe("done");
|
|
164
|
+
expect(restored.attempts).toBe(1);
|
|
165
|
+
// D-10 尽力恢复:重水合 call.traceNode 与 trace.nodes 副本共享引用
|
|
166
|
+
expect(back.state.trace.toArray()[0].stepIndex).toBe(0);
|
|
167
|
+
expect(restored.traceNode.stepIndex).toBe(0);
|
|
168
|
+
expect(restored.traceNode).toBe(back.state.trace.toArray()[0]);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("FileRunStore — 多 run 隔离", () => {
|
|
173
|
+
it("两个 run 各落各文件,loadAll 全量返回且互不覆盖", async () => {
|
|
174
|
+
const a = makeRun("wf-iso-a");
|
|
175
|
+
const b = makeRun("wf-iso-b", { status: "done" });
|
|
176
|
+
await store.save(a);
|
|
177
|
+
await store.save(b);
|
|
178
|
+
|
|
179
|
+
const loaded = await store.loadAll();
|
|
180
|
+
expect(loaded.map((r) => r.runId).sort()).toEqual(["wf-iso-a", "wf-iso-b"]);
|
|
181
|
+
const backA = loaded.find((r) => r.runId === "wf-iso-a")!;
|
|
182
|
+
const backB = loaded.find((r) => r.runId === "wf-iso-b")!;
|
|
183
|
+
expect(backA.state.status).toBe("running");
|
|
184
|
+
expect(backB.state.status).toBe("done");
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe("FileRunStore — 损坏行容错", () => {
|
|
189
|
+
it("文件尾损坏行(半行写入)→ 取更早的最后有效行 + warn", async () => {
|
|
190
|
+
const run = makeRun("wf-corrupt-1");
|
|
191
|
+
await store.save(run);
|
|
192
|
+
// 模拟崩溃半行:追加一段非法 JSON(无换行截断形态)
|
|
193
|
+
const path = store.stateFilePath("wf-corrupt-1");
|
|
194
|
+
const before = readFileSync(path, "utf8");
|
|
195
|
+
writeFileSync(path, before + '{"runId": "wf-corrupt-1", "state": {"sta');
|
|
196
|
+
|
|
197
|
+
const back = (await store.loadAll())[0];
|
|
198
|
+
expect(back?.runId).toBe("wf-corrupt-1");
|
|
199
|
+
expect(back?.state.status).toBe("running");
|
|
200
|
+
expect(warnMessages().some((m) => m.includes("wf-corrupt-1.jsonl"))).toBe(true);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("形状合法但字段残缺的快照(缺 runId/state)→ 判损坏跳过 + warn", async () => {
|
|
204
|
+
writeStateFile("wf-corrupt-2.jsonl", '{"foo": 1}\n{"also": "bad"}\n');
|
|
205
|
+
|
|
206
|
+
const loaded = await store.loadAll();
|
|
207
|
+
expect(loaded).toHaveLength(0);
|
|
208
|
+
expect(warnMessages().some((m) => m.includes("malformed snapshot"))).toBe(true);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("整文件全损坏 → run 跳过不炸 loadAll(其余 run 正常恢复)", async () => {
|
|
212
|
+
writeStateFile("wf-corrupt-3.jsonl", "not json at all\n{broken\n");
|
|
213
|
+
const good = makeRun("wf-corrupt-4");
|
|
214
|
+
await store.save(good);
|
|
215
|
+
|
|
216
|
+
const loaded = await store.loadAll();
|
|
217
|
+
expect(loaded.map((r) => r.runId)).toEqual(["wf-corrupt-4"]);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("非 .jsonl 文件与空文件不参与加载", async () => {
|
|
221
|
+
writeStateFile("README.txt", "hello");
|
|
222
|
+
writeStateFile("wf-corrupt-5.jsonl", "\n\n");
|
|
223
|
+
|
|
224
|
+
const loaded = await store.loadAll();
|
|
225
|
+
expect(loaded).toHaveLength(0);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("loadAll 目录不存在(干净环境首启)→ 空数组不抛错", async () => {
|
|
229
|
+
// beforeEach 只建了 dataRoot 本身,workflow-state 尚未创建(未 save 过)
|
|
230
|
+
const loaded = await store.loadAll();
|
|
231
|
+
expect(loaded).toEqual([]);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe("FileRunStore — 版本衔接与 live-strip(U8 / ⛔5,D4 裁决)", () => {
|
|
236
|
+
/** core 存量形态行(U8 前:无 v 字段、live 未 strip 直接落盘)。 */
|
|
237
|
+
const LEGACY_LINE = JSON.stringify({
|
|
238
|
+
runId: "wf-legacy-1",
|
|
239
|
+
spec: {
|
|
240
|
+
scriptSource: "export function execute() { return 'legacy'; }",
|
|
241
|
+
args: { topic: "legacy" },
|
|
242
|
+
scriptName: "test-script",
|
|
243
|
+
scriptPath: "/fake/test.js",
|
|
244
|
+
},
|
|
245
|
+
state: {
|
|
246
|
+
status: "running",
|
|
247
|
+
budget: { maxTokens: 1000, usedTokens: 7, usedCost: 0.1, totalCallCount: 1 },
|
|
248
|
+
calls: [
|
|
249
|
+
{
|
|
250
|
+
id: 0,
|
|
251
|
+
opts: { prompt: "legacy work" },
|
|
252
|
+
status: "running",
|
|
253
|
+
attempts: 1,
|
|
254
|
+
traceNode: {
|
|
255
|
+
stepIndex: 0,
|
|
256
|
+
agent: "coder",
|
|
257
|
+
task: "legacy work",
|
|
258
|
+
model: "test-model",
|
|
259
|
+
status: "running",
|
|
260
|
+
live: { turns: [] },
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
trace: [
|
|
265
|
+
{
|
|
266
|
+
stepIndex: 0,
|
|
267
|
+
agent: "coder",
|
|
268
|
+
task: "legacy work",
|
|
269
|
+
model: "test-model",
|
|
270
|
+
status: "running",
|
|
271
|
+
live: { turns: [] },
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
errorLogs: [],
|
|
275
|
+
},
|
|
276
|
+
meta: { startedAt: "2026-08-29T00:00:00.000Z" },
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("⛔5 无 v 存量行(core 旧格式,含未 strip 的 live)宽容读取不丢数据", async () => {
|
|
280
|
+
writeStateFile("wf-legacy-1.jsonl", LEGACY_LINE + "\n");
|
|
281
|
+
|
|
282
|
+
const loaded = await store.loadAll();
|
|
283
|
+
expect(loaded).toHaveLength(1);
|
|
284
|
+
const back = loaded[0];
|
|
285
|
+
expect(back.runId).toBe("wf-legacy-1");
|
|
286
|
+
expect(back.state.status).toBe("running");
|
|
287
|
+
expect(back.state.budget.usedTokens).toBe(7);
|
|
288
|
+
expect(back.spec.args).toEqual({ topic: "legacy" });
|
|
289
|
+
// 宽容读不是降级路径:不产生 warn(版本不匹配才 warn)
|
|
290
|
+
expect(warnMessages().some((m) => m.includes("wf-legacy-1"))).toBe(false);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("⛔5 写入补 v 字段(快照行携带 wf-run-v2)+ 宽容读行写回后自然迁移", async () => {
|
|
294
|
+
const run = makeRun("wf-vwrite-1");
|
|
295
|
+
await store.save(run);
|
|
296
|
+
|
|
297
|
+
const raw = readFileSync(store.stateFilePath("wf-vwrite-1"), "utf8").trim();
|
|
298
|
+
expect(JSON.parse(raw).v).toBe("wf-run-v2");
|
|
299
|
+
|
|
300
|
+
// 存量行宽容读 → 再 save:落盘行升级为带 v 当前版本(不做自动迁移的
|
|
301
|
+
// 渐进收敛——D4 裁决②「写入时补 v」)
|
|
302
|
+
writeStateFile("wf-legacy-2.jsonl", LEGACY_LINE + "\n");
|
|
303
|
+
const legacy = (await store.loadAll()).find((r) => r.runId === "wf-legacy-1")!;
|
|
304
|
+
await store.save(legacy);
|
|
305
|
+
const migrated = readFileSync(store.stateFilePath("wf-legacy-1"), "utf8").trim();
|
|
306
|
+
expect(JSON.parse(migrated).v).toBe("wf-run-v2");
|
|
307
|
+
expect(migrated.includes('"live"')).toBe(false);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("⛔5 未知更高版本行跳过 + warn(消息含实际版本值,可定位)", async () => {
|
|
311
|
+
const future = JSON.parse(LEGACY_LINE);
|
|
312
|
+
future.runId = "wf-future-1";
|
|
313
|
+
future.v = "wf-run-v3";
|
|
314
|
+
const current = JSON.parse(LEGACY_LINE);
|
|
315
|
+
current.runId = "wf-current-1";
|
|
316
|
+
current.v = "wf-run-v2";
|
|
317
|
+
// 从尾向头扫描序:尾损坏行(继续向前)→ 高版本行(warn 跳过,继续向前)
|
|
318
|
+
// → 当前版本行(恢复)——单行版本不匹配不拖垮同文件其余行,warn 可见
|
|
319
|
+
writeStateFile(
|
|
320
|
+
"wf-vermix.jsonl",
|
|
321
|
+
JSON.stringify(current) + "\n" + JSON.stringify(future) + "\n" + '{"trunc',
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const loaded = await store.loadAll();
|
|
325
|
+
expect(loaded.map((r) => r.runId)).toEqual(["wf-current-1"]);
|
|
326
|
+
expect(warnMessages().some((m) => m.includes("unsupported version") && m.includes("wf-run-v3"))).toBe(true);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("⛔5 live 字段 strip 后落盘(落盘行无 live 键,内存 run 不受影响)", async () => {
|
|
330
|
+
const run = makeRun("wf-livestrip-1");
|
|
331
|
+
const node: import("../models/types.ts").ExecutionTraceNode = {
|
|
332
|
+
stepIndex: 0,
|
|
333
|
+
agent: "coder",
|
|
334
|
+
task: "do work",
|
|
335
|
+
model: "test-model",
|
|
336
|
+
status: "running",
|
|
337
|
+
live: undefined,
|
|
338
|
+
};
|
|
339
|
+
run.state.trace.append(node);
|
|
340
|
+
const AgentCallMod = await import("../models/agent-call.ts");
|
|
341
|
+
const call = new AgentCallMod.AgentCall(0, { prompt: "do work" }, node);
|
|
342
|
+
run.state.calls.set(0, call);
|
|
343
|
+
node.live = { id: "run-0", turns: [] } as unknown as import("../../execution/types.ts").ExecutionRecord;
|
|
344
|
+
|
|
345
|
+
await store.save(run);
|
|
346
|
+
|
|
347
|
+
const raw = readFileSync(store.stateFilePath("wf-livestrip-1"), "utf8");
|
|
348
|
+
expect(raw.includes('"live"')).toBe(false);
|
|
349
|
+
// strip 产出快照副本:内存中 run 的 live 保留(save 后 run 可继续跑)
|
|
350
|
+
expect(node.live).toBeDefined();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("pi 现网形态行(带 v)经 store 端到端恢复", async () => {
|
|
354
|
+
const piForm = JSON.parse(LEGACY_LINE);
|
|
355
|
+
piForm.runId = "wf-pi-e2e-1";
|
|
356
|
+
piForm.v = "wf-run-v2";
|
|
357
|
+
delete piForm.state.calls[0].traceNode.live;
|
|
358
|
+
delete piForm.state.trace[0].live;
|
|
359
|
+
writeStateFile("wf-pi-e2e-1.jsonl", JSON.stringify(piForm) + "\n");
|
|
360
|
+
|
|
361
|
+
const back = (await store.loadAll())[0];
|
|
362
|
+
expect(back.runId).toBe("wf-pi-e2e-1");
|
|
363
|
+
expect(back.state.calls.size).toBe(1);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe("FileRunStore — stateFilePath / 端口语义", () => {
|
|
368
|
+
it("路径形状 = <dataRoot>/workflow-state/<runId>.jsonl(纯计算不建目录)", () => {
|
|
369
|
+
expect(store.stateFilePath("wf-x-1")).toBe(
|
|
370
|
+
join(dataRoot, "workflow-state", "wf-x-1.jsonl"),
|
|
371
|
+
);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("宿主覆盖 configureCore 后路径现取新 dataRoot(不缓存路径)", () => {
|
|
375
|
+
const altRoot = mkdtempSync(join(tmpdir(), "file-run-store-alt-"));
|
|
376
|
+
try {
|
|
377
|
+
configureCore({ dataRoot: () => altRoot, log: () => {} });
|
|
378
|
+
expect(store.stateFilePath("wf-x-2")).toBe(
|
|
379
|
+
join(altRoot, "workflow-state", "wf-x-2.jsonl"),
|
|
380
|
+
);
|
|
381
|
+
} finally {
|
|
382
|
+
rmSync(altRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("未 configureCore 即消费 dataRoot → core_host_not_configured(§3.4 fail-loud)", () => {
|
|
387
|
+
resetCoreForTests();
|
|
388
|
+
expect(() => store.stateFilePath("wf-x-3")).toThrowError("core_host_not_configured");
|
|
389
|
+
});
|
|
390
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 排空微任务队列:固定 ticks 次 `await Promise.resolve()`,把 fire-and-forget
|
|
3
|
+
* promise 链推进到稳定态。递归而非 for 循环——固定 tick 排空不是逐项串行等待,
|
|
4
|
+
* no-await-in-loop 豁免形态统一收敛到本函数(项目纪律禁行内 disable)。
|
|
5
|
+
*
|
|
6
|
+
* 不用 vi.waitFor 的场景:反向断言(「X 未发生」)下 waitFor 会一满足即返回,
|
|
7
|
+
* 必须先跑满固定 tick 再静态断言。
|
|
8
|
+
*/
|
|
9
|
+
export async function flushMicrotasks(ticks = 10): Promise<void> {
|
|
10
|
+
if (ticks <= 0) return;
|
|
11
|
+
await Promise.resolve();
|
|
12
|
+
await flushMicrotasks(ticks - 1);
|
|
13
|
+
}
|
|
@@ -598,3 +598,37 @@ describe("executeNestedWorkflow", () => {
|
|
|
598
598
|
});
|
|
599
599
|
});
|
|
600
600
|
});
|
|
601
|
+
|
|
602
|
+
// ── runAndWait model 透传(host-surface:zsw CLI --model 的同步面入口)──
|
|
603
|
+
// 契约:显式 model → spec.model(Option B:workerData → $MODEL → agent() fallback);
|
|
604
|
+
// 未传 → undefined(不覆盖脚本内 agent() 显式参数 / agent .md / 引擎默认的解析序)。
|
|
605
|
+
describe("runAndWait model 透传", () => {
|
|
606
|
+
it("显式 model → spec.model 透传", async () => {
|
|
607
|
+
const childRun = makeDoneChildRun({ reason: "completed", scriptResult: "ok" });
|
|
608
|
+
const deps = makeDeps({ script: makeScript(), childRun });
|
|
609
|
+
setupRunWorkflow(childRun);
|
|
610
|
+
|
|
611
|
+
const result = await runAndWait(
|
|
612
|
+
"child-wf",
|
|
613
|
+
{},
|
|
614
|
+
deps,
|
|
615
|
+
undefined,
|
|
616
|
+
undefined,
|
|
617
|
+
"zai-coding-cn/glm-5.3-flash",
|
|
618
|
+
);
|
|
619
|
+
expect(result.reason).toBe("completed");
|
|
620
|
+
expect(vi.mocked(runWorkflow)).toHaveBeenCalledTimes(1);
|
|
621
|
+
const spec = vi.mocked(runWorkflow).mock.calls[0]![0] as RunSpec;
|
|
622
|
+
expect(spec.model).toBe("zai-coding-cn/glm-5.3-flash");
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it("未传 model → spec.model 保持 undefined(不覆盖既有解析序)", async () => {
|
|
626
|
+
const childRun = makeDoneChildRun({ reason: "completed", scriptResult: "ok" });
|
|
627
|
+
const deps = makeDeps({ script: makeScript(), childRun });
|
|
628
|
+
setupRunWorkflow(childRun);
|
|
629
|
+
|
|
630
|
+
await runAndWait("child-wf", {}, deps);
|
|
631
|
+
const spec = vi.mocked(runWorkflow).mock.calls[0]![0] as RunSpec;
|
|
632
|
+
expect(spec.model).toBeUndefined();
|
|
633
|
+
});
|
|
634
|
+
});
|