@qlairoslabs/acp-client 0.13.0-alpha.1 → 0.13.2-alpha.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/CONSUMER_GUIDE.md +181 -8
- package/MIGRATION-0.12-to-0.13.md +20 -7
- package/package.json +13 -2
- package/src/agent/config.ts +2 -0
- package/src/agent/conversation-manager.ts +1 -0
- package/src/agent/native-operations.ts +40 -0
- package/src/agent-session-config.ts +2 -0
- package/src/agent-session.ts +12 -2
- package/src/agent.ts +100 -2
- package/src/client.ts +5 -3
- package/src/controller-connection.ts +1 -0
- package/src/controller.ts +2 -0
- package/src/index.ts +3 -0
- package/src/launcher.ts +2 -0
- package/src/native/approvals.ts +20 -3
- package/src/native/capabilities.ts +2 -2
- package/src/native/connection.ts +1 -1
- package/src/native/controller.ts +5 -3
- package/src/native/host-config.ts +2 -0
- package/src/native/host.ts +83 -4
- package/src/native/mcp.ts +47 -0
- package/src/native/recovery.ts +8 -7
- package/src/native/reminders/routine-guard.ts +4 -3
- package/src/native/reminders/routine-wire.ts +1 -1
- package/src/native-harness/README.md +58 -1
- package/src/native-harness/package.json +4 -0
- package/src/native-harness/scripts/build-routine-zones.py +47 -0
- package/src/native-harness/src/capabilities/attachments/admission.ts +42 -0
- package/src/native-harness/src/capabilities/attachments/image-validation.ts +98 -0
- package/src/native-harness/src/capabilities/attachments/input.ts +1 -0
- package/src/native-harness/src/capabilities/attachments/read.ts +76 -0
- package/src/native-harness/src/capabilities/attachments/recovery.ts +26 -0
- package/src/native-harness/src/capabilities/attachments/selection.ts +37 -0
- package/src/native-harness/src/capabilities/attachments/service.ts +75 -0
- package/src/native-harness/src/capabilities/attachments/upload.ts +164 -0
- package/src/native-harness/src/capabilities/attachments/vision.ts +45 -0
- package/src/native-harness/src/capabilities/context/build.ts +5 -0
- package/src/native-harness/src/capabilities/context/session.ts +2 -1
- package/src/native-harness/src/capabilities/model/openrouter-stream.ts +80 -17
- package/src/native-harness/src/capabilities/model/runner.ts +6 -3
- package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
- package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
- package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
- package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
- package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
- package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
- package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
- package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
- package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
- package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
- package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
- package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
- package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
- package/src/native-harness/src/capabilities/tools/mcp/client.ts +97 -0
- package/src/native-harness/src/capabilities/tools/mcp/http.ts +183 -0
- package/src/native-harness/src/capabilities/tools/mcp/registry.ts +62 -0
- package/src/native-harness/src/capabilities/tools/mcp/result.ts +33 -0
- package/src/native-harness/src/capabilities/tools/mcp/schema.ts +77 -0
- package/src/native-harness/src/capabilities/tools/mcp/secrets.ts +28 -0
- package/src/native-harness/src/capabilities/tools/mcp/stdio.ts +105 -0
- package/src/native-harness/src/capabilities/tools/reminders/index.ts +27 -5
- package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +4 -1
- package/src/native-harness/src/capabilities/tools/web/config.ts +1 -0
- package/src/native-harness/src/capabilities/tools/web/definitions.ts +18 -0
- package/src/native-harness/src/capabilities/tools/web/direct-address.ts +56 -0
- package/src/native-harness/src/capabilities/tools/web/direct-transport.ts +235 -0
- package/src/native-harness/src/capabilities/tools/web/direct.ts +149 -0
- package/src/native-harness/src/capabilities/tools/web/exa-transport.ts +41 -0
- package/src/native-harness/src/capabilities/tools/web/exa.ts +71 -0
- package/src/native-harness/src/capabilities/tools/web/preview.ts +44 -0
- package/src/native-harness/src/capabilities/tools/web/registry.ts +47 -0
- package/src/native-harness/src/capabilities/tools/web/usage.ts +1 -0
- package/src/native-harness/src/contracts/agent.ts +3 -1
- package/src/native-harness/src/contracts/attachments.ts +62 -0
- package/src/native-harness/src/contracts/config-permissions.ts +14 -3
- package/src/native-harness/src/contracts/context.ts +1 -1
- package/src/native-harness/src/contracts/events.ts +2 -2
- package/src/native-harness/src/contracts/loop.ts +3 -3
- package/src/native-harness/src/contracts/mcp.ts +22 -0
- package/src/native-harness/src/contracts/model-execution.ts +2 -1
- package/src/native-harness/src/contracts/operator-controls.ts +8 -1
- package/src/native-harness/src/contracts/protocol.ts +21 -5
- package/src/native-harness/src/contracts/reminders.ts +4 -2
- package/src/native-harness/src/contracts/routines.ts +20 -0
- package/src/native-harness/src/contracts/session-file.ts +2 -0
- package/src/native-harness/src/contracts/session.ts +8 -3
- package/src/native-harness/src/contracts/storage.ts +32 -13
- package/src/native-harness/src/contracts/tools.ts +2 -0
- package/src/native-harness/src/contracts/web.ts +16 -0
- package/src/native-harness/src/governance/permissions/gate.ts +9 -2
- package/src/native-harness/src/governance/policy/resolve.ts +6 -1
- package/src/native-harness/src/index.ts +48 -12
- package/src/native-harness/src/interfaces/cli/development.ts +108 -53
- package/src/native-harness/src/interfaces/cli/serve.ts +2 -2
- package/src/native-harness/src/interfaces/cli/start.ts +22 -13
- package/src/native-harness/src/interfaces/client.ts +8 -2
- package/src/native-harness/src/interfaces/inspector/index.html +7 -1
- package/src/native-harness/src/interfaces/inspector/state.ts +6 -2
- package/src/native-harness/src/interfaces/protocol/load.ts +3 -1
- package/src/native-harness/src/interfaces/protocol/local.ts +13 -4
- package/src/native-harness/src/interfaces/protocol/operator.ts +8 -2
- package/src/native-harness/src/interfaces/protocol/server.ts +102 -36
- package/src/native-harness/src/interfaces/protocol/stdio-client.ts +8 -0
- package/src/native-harness/src/interfaces/web-chat/index.html +65 -12
- package/src/native-harness/src/interfaces/web-chat/server.ts +30 -3
- package/src/native-harness/src/kernel/channels.ts +27 -15
- package/src/native-harness/src/kernel/loop.ts +1 -1
- package/src/native-harness/src/runtime/config/inference-key.ts +7 -0
- package/src/native-harness/src/runtime/config/managed.ts +1 -1
- package/src/native-harness/src/runtime/config/paths.ts +8 -1
- package/src/native-harness/src/runtime/execution/mcp-stdio.ts +31 -0
- package/src/native-harness/src/runtime/reminder-validation.ts +31 -10
- package/src/native-harness/src/runtime/reminders.ts +2 -2
- package/src/native-harness/src/state/storage/archive.ts +113 -12
- package/src/native-harness/src/state/storage/attachment-files.ts +58 -0
- package/src/native-harness/src/state/storage/attachment-import.ts +106 -0
- package/src/native-harness/src/state/storage/attachment-tables.ts +123 -0
- package/src/native-harness/src/state/storage/engine.ts +396 -45
- package/src/native-harness/src/state/storage/inference.ts +30 -2
- package/src/native-harness/src/state/storage/memory-attachments.ts +56 -0
- package/src/native-harness/src/state/storage/memory-reminders.ts +31 -6
- package/src/native-harness/src/state/storage/memory.ts +32 -4
- package/src/native-harness/src/state/storage/reminder-archive.ts +53 -12
- package/src/native-harness/src/state/storage/reminder-change.ts +60 -14
- package/src/native-harness/src/state/storage/reminder-tables.ts +11 -3
- package/src/native-harness/src/state/storage/routine-row.ts +25 -0
- package/src/native-harness/src/state/storage/session-file.ts +22 -9
- package/src/native-harness/src/state/storage/sqlite-reminders.ts +48 -8
- package/src/native-harness/src/state/storage/sqlite.ts +59 -11
- package/src/native-harness/src/state/storage/web-tables.ts +47 -0
- package/src/native-harness/src/testing.ts +151 -56
- package/src/native-harness/src/util/attachment-input.ts +42 -0
- package/src/native-harness/src/util/config.ts +64 -9
- package/src/native-harness/src/util/intake.ts +7 -0
- package/src/native-harness/src/util/mcp-config.ts +102 -0
- package/src/native-harness/src/util/web-config.ts +34 -0
- package/src/native-harness/src/util/web-usage.ts +33 -0
- package/src/orchestrator/permissions.ts +6 -3
- package/src/permissions/conversation.ts +13 -5
- package/src/permissions/matcher.ts +2 -0
- package/src/permissions/outcome.ts +12 -1
- package/src/permissions/policy.ts +13 -8
- package/src/steering/combine.ts +1 -0
- package/src/steering/contracts.ts +3 -0
- package/src/terminals.ts +9 -6
- package/src/native/reminders/reminders.test.ts +0 -553
- package/src/native/reminders/routine-config.typecheck.ts +0 -13
- package/src/native/reminders/wire.typecheck.ts +0 -13
- package/src/native-harness/.res/README.md +0 -1
- package/src/native-harness/.res/architecture/README.md +0 -21
- package/src/native-harness/.res/architecture/context-and-data.md +0 -31
- package/src/native-harness/.res/architecture/execution.md +0 -42
- package/src/native-harness/.res/architecture/overview.md +0 -44
- package/src/native-harness/.res/architecture/persistence.md +0 -56
- package/src/native-harness/.res/architecture/suspend-and-resume.md +0 -45
- package/src/native-harness/.res/architecture/technical-architecture.md +0 -50
- package/src/native-harness/.res/decisions/0001-basic-loop.md +0 -11
- package/src/native-harness/.res/decisions/0002-channel-input.md +0 -17
- package/src/native-harness/.res/decisions/0003-inference-inspection.md +0 -14
- package/src/native-harness/.res/decisions/0004-shared-context.md +0 -21
- package/src/native-harness/.res/decisions/0005-notice-inbox.md +0 -20
- package/src/native-harness/.res/decisions/0006-explicit-notices.md +0 -12
- package/src/native-harness/.res/decisions/0007-channel-output.md +0 -12
- package/src/native-harness/.res/decisions/0008-browser-client.md +0 -16
- package/src/native-harness/.res/decisions/0009-scripted-model.md +0 -18
- package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +0 -19
- package/src/native-harness/.res/decisions/0011-stdio-transport.md +0 -21
- package/src/native-harness/.res/decisions/0012-session-storage-contract.md +0 -37
- package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +0 -64
- package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +0 -73
- package/src/native-harness/.res/decisions/0015-session-file-contract.md +0 -72
- package/src/native-harness/.res/decisions/0016-configuration-permissions.md +0 -159
- package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +0 -69
- package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +0 -78
- package/src/native-harness/.res/decisions/0019-model-execution.md +0 -188
- package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +0 -71
- package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +0 -100
- package/src/native-harness/.res/decisions/0022-operator-controls.md +0 -115
- package/src/native-harness/.res/decisions/0023-long-running-mock.md +0 -82
- package/src/native-harness/.res/decisions/0024-callback-policy-names.md +0 -46
- package/src/native-harness/.res/decisions/0025-external-notices.md +0 -364
- package/src/native-harness/.res/decisions/0026-bounded-context.md +0 -81
- package/src/native-harness/.res/decisions/0027-development-instructions.md +0 -22
- package/src/native-harness/.res/decisions/0028-debug-tools.md +0 -16
- package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +0 -37
- package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +0 -145
- package/src/native-harness/.res/decisions/0031-one-off-reminders.md +0 -173
- package/src/native-harness/.res/docs/11-15.md +0 -148
- package/src/native-harness/.res/docs/BUSINESS_RULES.md +0 -111
- package/src/native-harness/.res/docs/WORK.md +0 -65
- package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +0 -312
- package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +0 -77
- package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +0 -313
- package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +0 -160
- package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +0 -89
- package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +0 -135
- package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +0 -143
- package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +0 -93
- package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +0 -181
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +0 -433
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +0 -60
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +0 -141
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +0 -168
- package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +0 -111
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +0 -129
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +0 -135
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +0 -437
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +0 -127
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +0 -203
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +0 -292
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +0 -91
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +0 -187
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +0 -148
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +0 -95
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +0 -200
- package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +0 -80
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +0 -206
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +0 -106
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +0 -297
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +0 -41
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +0 -36
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +0 -84
- package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +0 -147
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +0 -15
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +0 -107
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +0 -114
- package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +0 -24
- package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +0 -23
- package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +0 -103
- package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +0 -50
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +0 -337
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +0 -76
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +0 -204
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +0 -73
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +0 -64
- package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +0 -58
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +0 -45
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +0 -108
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +0 -169
- package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +0 -128
- package/src/native-harness/.res/marketing-draft.md +0 -22
- package/src/native-harness/.res/sandbox/1-simple-harness/README.md +0 -285
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +0 -19
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +0 -138
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +0 -148
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +0 -172
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +0 -194
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +0 -233
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +0 -249
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +0 -265
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +0 -279
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +0 -293
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +0 -307
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +0 -29
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +0 -317
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +0 -327
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +0 -40
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +0 -59
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +0 -69
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +0 -79
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +0 -89
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +0 -102
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +0 -116
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +0 -49
- package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +0 -87
- package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +0 -289
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +0 -221
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +0 -287
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +0 -165
- package/src/native-harness/.res/sandbox/1-simple-harness/state.json +0 -22
- package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +0 -2
- package/src/native-harness/AGENTS.md +0 -70
- package/src/native-harness/ARCHITECTURE.md +0 -249
- package/src/native-harness/bun.lock +0 -26
- package/src/native-harness/test/agent.test.ts +0 -130
- package/src/native-harness/test/approval-gate.test.ts +0 -255
- package/src/native-harness/test/approval-protocol.test.ts +0 -94
- package/src/native-harness/test/boundaries.test.ts +0 -18
- package/src/native-harness/test/channel-controls.test.ts +0 -322
- package/src/native-harness/test/client-abort.test.ts +0 -136
- package/src/native-harness/test/config-policy.test.ts +0 -301
- package/src/native-harness/test/conformance/storage.ts +0 -1141
- package/src/native-harness/test/context.test.ts +0 -177
- package/src/native-harness/test/crash.test.ts +0 -187
- package/src/native-harness/test/debug-tools.test.ts +0 -67
- package/src/native-harness/test/development-cli.test.ts +0 -67
- package/src/native-harness/test/development.test.ts +0 -171
- package/src/native-harness/test/dispatch-evidence.test.ts +0 -58
- package/src/native-harness/test/e2e.test.ts +0 -186
- package/src/native-harness/test/external-notices.test.ts +0 -101
- package/src/native-harness/test/fixtures/approval-e2e.jsonl +0 -4
- package/src/native-harness/test/fixtures/crash-scenario.jsonl +0 -5
- package/src/native-harness/test/fixtures/development-lifecycle.jsonl +0 -10
- package/src/native-harness/test/fixtures/echo-scenario.jsonl +0 -3
- package/src/native-harness/test/fixtures/format2-schema.ts +0 -27
- package/src/native-harness/test/fixtures/format3-schema.ts +0 -16
- package/src/native-harness/test/fixtures/hold-scenario.jsonl +0 -4
- package/src/native-harness/test/fixtures/model-e2e.jsonl +0 -3
- package/src/native-harness/test/fixtures/storage-owner.ts +0 -20
- package/src/native-harness/test/format-reply.test.ts +0 -10
- package/src/native-harness/test/helpers/operator-view.ts +0 -41
- package/src/native-harness/test/helpers/scenario.ts +0 -9
- package/src/native-harness/test/helpers/session.ts +0 -38
- package/src/native-harness/test/helpers/stdio.ts +0 -46
- package/src/native-harness/test/inspector.test.ts +0 -77
- package/src/native-harness/test/listeners.test.ts +0 -49
- package/src/native-harness/test/loop.test.ts +0 -88
- package/src/native-harness/test/model-channel-double.test.ts +0 -87
- package/src/native-harness/test/model-crash.test.ts +0 -62
- package/src/native-harness/test/model-delivery-regressions.test.ts +0 -55
- package/src/native-harness/test/model-e2e.test.ts +0 -71
- package/src/native-harness/test/model-final-filter.test.ts +0 -30
- package/src/native-harness/test/model-large-reply.test.ts +0 -28
- package/src/native-harness/test/model-live-queue.test.ts +0 -33
- package/src/native-harness/test/model-runner.test.ts +0 -117
- package/src/native-harness/test/model-storage.test.ts +0 -99
- package/src/native-harness/test/model-stream-adapter.test.ts +0 -26
- package/src/native-harness/test/model-stream-public.test.ts +0 -77
- package/src/native-harness/test/notices.test.ts +0 -64
- package/src/native-harness/test/openrouter-config.test.ts +0 -218
- package/src/native-harness/test/operator-controls.test.ts +0 -132
- package/src/native-harness/test/output.test.ts +0 -44
- package/src/native-harness/test/owner-config.test.ts +0 -64
- package/src/native-harness/test/permissions-e2e.test.ts +0 -68
- package/src/native-harness/test/persistence.test.ts +0 -236
- package/src/native-harness/test/portability.test.ts +0 -337
- package/src/native-harness/test/protocol.test.ts +0 -160
- package/src/native-harness/test/reminder-clock.test.ts +0 -61
- package/src/native-harness/test/reminder-stdio.test.ts +0 -140
- package/src/native-harness/test/reminder-storage.test.ts +0 -124
- package/src/native-harness/test/scenario-jsonl.test.ts +0 -112
- package/src/native-harness/test/scripted.test.ts +0 -92
- package/src/native-harness/test/session-file.test.ts +0 -51
- package/src/native-harness/test/startup-channel-changes.test.ts +0 -256
- package/src/native-harness/test/stdio.test.ts +0 -132
- package/src/native-harness/test/storage-memory.test.ts +0 -4
- package/src/native-harness/test/storage-sqlite.test.ts +0 -420
- package/src/native-harness/test/suspension.test.ts +0 -430
- package/src/native-harness/test/timeline-retrieval.test.ts +0 -211
- package/src/native-harness/test/tools-catalog.test.ts +0 -468
- package/src/native-harness/test/tools-protocol.test.ts +0 -418
- package/src/native-harness/test/transfers.test.ts +0 -94
- package/src/native-harness/test/web-chat.test.ts +0 -35
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
import { createSession } from "../src/index.ts";
|
|
3
|
-
import { createMemoryStorageAdapter } from "../src/state/storage/memory.ts";
|
|
4
|
-
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
5
|
-
import type { PersistentSession } from "../src/contracts/session.ts";
|
|
6
|
-
import { lastInput } from "./helpers/session.ts";
|
|
7
|
-
|
|
8
|
-
/** Deterministic two-channel rig (decision 0014). The scripted model asks for the
|
|
9
|
-
* `hold` tool whenever the newest input starts with "hold" and answers
|
|
10
|
-
* "ok <input>" otherwise; a held tool returns only when the test releases it, and
|
|
11
|
-
* deliberately ignores its abort signal, like a tool that returns late. */
|
|
12
|
-
function rig() {
|
|
13
|
-
const adapter = createMemoryStorageAdapter();
|
|
14
|
-
const holds = new Map<string, () => void>();
|
|
15
|
-
const effects: string[] = [], requests: string[] = [];
|
|
16
|
-
let created = false;
|
|
17
|
-
const open = (key = "k") => {
|
|
18
|
-
const opened = adapter.open({ mode: created ? "open" : "create", identity: { sessionId: "s", compatibilityKey: key } });
|
|
19
|
-
if (!opened.ok) throw new Error(opened.error.message);
|
|
20
|
-
created = true;
|
|
21
|
-
const storage = opened.value;
|
|
22
|
-
const session = createSession({ systemPrompt: "system", storage, configureTurn: turn => {
|
|
23
|
-
let n = 0;
|
|
24
|
-
return { tools: [], model: async messages => {
|
|
25
|
-
const last = messages.at(-1)!, text = lastInput(messages);
|
|
26
|
-
requests.push(`${turn.channelId}#${turn.turnId}:${last.role === "tool" ? "(tool result)" : text}`);
|
|
27
|
-
if (last.role === "tool") return { role: "assistant", content: `finished ${turn.channelId}`, calls: [] };
|
|
28
|
-
if (text.startsWith("hold")) return { role: "assistant", content: null, calls: [{ id: `h${turn.turnId}-${++n}`, name: "hold", arguments: "{}" }] };
|
|
29
|
-
return { role: "assistant", content: `ok ${text}`, calls: [] };
|
|
30
|
-
}, executeTool: async () => {
|
|
31
|
-
effects.push(`start:${turn.channelId}#${turn.turnId}`);
|
|
32
|
-
const key = `${turn.channelId}#${turn.turnId}`;
|
|
33
|
-
await new Promise<void>(resolve => holds.set(key, resolve));
|
|
34
|
-
holds.delete(key);
|
|
35
|
-
effects.push(`done:${turn.channelId}#${turn.turnId}`);
|
|
36
|
-
return "held";
|
|
37
|
-
} };
|
|
38
|
-
} });
|
|
39
|
-
const events: ChannelEvent[] = [];
|
|
40
|
-
session.subscribe(event => events.push(event));
|
|
41
|
-
return { session, events, close() { session.stop("test"); const closed = storage.close(); if (!closed.ok) throw new Error(closed.error.message); } };
|
|
42
|
-
};
|
|
43
|
-
const keys = (channel: string) => [...holds.keys()].filter(key => key.startsWith(`${channel}#`));
|
|
44
|
-
return { open, effects, requests, held: (channel: string) => keys(channel).length > 0,
|
|
45
|
-
/** Release one turn's tool, or every held tool of the channel. */
|
|
46
|
-
release: (channel: string, turnId?: number) => { for (const key of keys(channel)) if (turnId === undefined || key === `${channel}#${turnId}`) holds.get(key)!(); } };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function until(check: () => boolean, what: string) {
|
|
50
|
-
for (let i = 0; i < 400; i++) { if (check()) return; await new Promise(resolve => setTimeout(resolve, 5)); }
|
|
51
|
-
throw new Error(`Timed out waiting for ${what}`);
|
|
52
|
-
}
|
|
53
|
-
const types = (events: ChannelEvent[], channel: string) => events.filter(event => event.channel === channel).map(event => event.event.type);
|
|
54
|
-
const send = (session: PersistentSession, channel: string, text: string, itemId?: string) =>
|
|
55
|
-
session.agent.send({ channelId: channel, participantId: "ana", text, ...(itemId ? { itemId } : {}) });
|
|
56
|
-
const channel = (session: PersistentSession, id: string) => session.status().channels.find(c => c.channelId === id)!;
|
|
57
|
-
const ok = <T>(result: { ok: true; value: T } | { ok: false; error: { code: string; message: string } }): T => {
|
|
58
|
-
if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
59
|
-
return result.value;
|
|
60
|
-
};
|
|
61
|
-
const refused = (result: { ok: boolean; error?: { code: string } }, code: string) => expect(result.ok ? "ok" : result.error!.code).toBe(code);
|
|
62
|
-
const turnOf = (session: PersistentSession, turnId: number) => session.snapshot().turns.find(turn => turn.turnId === turnId)!;
|
|
63
|
-
|
|
64
|
-
test("Alice suspends while her tool runs; Bob continues; her backlog survives a reopen and is taken once on resume", async () => {
|
|
65
|
-
const r = rig();
|
|
66
|
-
const first = r.open(), { session } = first;
|
|
67
|
-
session.start();
|
|
68
|
-
send(session, "alice", "hold work", "a1");
|
|
69
|
-
await until(() => r.held("alice"), "alice's tool");
|
|
70
|
-
expect(send(session, "alice", "later", "a2")).toMatchObject({ accepted: true, milestone: "received" });
|
|
71
|
-
|
|
72
|
-
const suspending = session.channels.suspend("alice");
|
|
73
|
-
expect(channel(session, "alice")).toMatchObject({ lifecycle: "suspending", activeTurn: { turnId: 1, status: "running" }, waitingForResume: true });
|
|
74
|
-
// Closed to new input and notices; a retry of accepted input still answers.
|
|
75
|
-
expect(send(session, "alice", "too late")).toMatchObject({ accepted: false, code: "channel_suspended" });
|
|
76
|
-
expect(session.agent.notify({ channelId: "alice", fromChannelId: "bob", text: "psst" })).toMatchObject({ accepted: false, code: "channel_suspended" });
|
|
77
|
-
expect(send(session, "alice", "later", "a2")).toMatchObject({ accepted: true, duplicate: true, milestone: "received" });
|
|
78
|
-
// Bob is not affected.
|
|
79
|
-
send(session, "bob", "hello bob", "b1");
|
|
80
|
-
await until(() => first.events.some(e => e.channel === "bob" && e.event.type === "turn_ended"), "bob's turn");
|
|
81
|
-
expect(send(session, "bob", "again", "b2")).toMatchObject({ accepted: true });
|
|
82
|
-
await until(() => first.events.filter(e => e.channel === "bob" && e.event.type === "turn_ended").length === 2, "bob's second turn");
|
|
83
|
-
expect(channel(session, "alice").lifecycle).toBe("suspending"); // waits for the tool, does not cancel it
|
|
84
|
-
r.release("alice");
|
|
85
|
-
const done = ok(await suspending);
|
|
86
|
-
expect(done).toMatchObject({ lifecycle: "suspended", activeTurn: { turnId: 1, status: "suspended" }, pendingItemIds: ["a2"], waitingForResume: true });
|
|
87
|
-
expect(types(first.events, "alice")).toEqual(["turn_started", "items_receipt", "tool_call", "channel_state", "tool_call", "turn_suspended", "channel_state"]);
|
|
88
|
-
// Pending work on a suspended channel is visible but is not execution.
|
|
89
|
-
expect(session.status().execution).toBe("idle");
|
|
90
|
-
expect(session.agent.idle()).toBe(true);
|
|
91
|
-
|
|
92
|
-
first.close();
|
|
93
|
-
const second = r.open(), again = second.session;
|
|
94
|
-
again.start();
|
|
95
|
-
send(again, "bob", "still here", "b3");
|
|
96
|
-
await until(() => second.events.some(e => e.channel === "bob" && e.event.type === "turn_ended"), "bob after reopen");
|
|
97
|
-
expect(channel(again, "alice")).toMatchObject({ lifecycle: "suspended", activeTurn: { turnId: 1, status: "suspended" }, pendingItemIds: ["a2"] });
|
|
98
|
-
expect(types(second.events, "alice")).toEqual([]); // start() does not wake her
|
|
99
|
-
expect(send(again, "alice", "x")).toMatchObject({ accepted: false, code: "channel_suspended" });
|
|
100
|
-
|
|
101
|
-
ok(again.channels.resume("alice"));
|
|
102
|
-
await until(() => second.events.some(e => e.channel === "alice" && e.event.type === "turn_ended"), "alice's resumed turn");
|
|
103
|
-
expect(types(second.events, "alice").slice(0, 3)).toEqual(["channel_state", "turn_resumed", "turn_took"]);
|
|
104
|
-
expect(r.effects.filter(line => line.startsWith("start:alice"))).toEqual(["start:alice#1"]); // the recorded tool did not run again
|
|
105
|
-
expect(turnOf(again, 1)).toMatchObject({ state: { status: "completed" }, itemIds: ["a1", "a2"] });
|
|
106
|
-
expect(again.snapshot().items.find(item => item.itemId === "a2")).toMatchObject({ turnId: 1 });
|
|
107
|
-
expect(r.requests.filter(line => line.endsWith(":later"))).toEqual(["alice#1:later"]); // taken and shown to the model once
|
|
108
|
-
second.session.stop("done");
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("resuming a checkpoint before start does not start other channels or strand their backlog", async () => {
|
|
112
|
-
const r = rig(), first = r.open();
|
|
113
|
-
first.session.start();
|
|
114
|
-
send(first.session, "alice", "hold work", "a1");
|
|
115
|
-
await until(() => r.held("alice"), "alice's tool");
|
|
116
|
-
const suspension = first.session.channels.suspend("alice");
|
|
117
|
-
r.release("alice");
|
|
118
|
-
ok(await suspension);
|
|
119
|
-
first.close();
|
|
120
|
-
|
|
121
|
-
const preparing = r.open();
|
|
122
|
-
expect(send(preparing.session, "bob", "pending", "b1").accepted).toBe(true);
|
|
123
|
-
preparing.close();
|
|
124
|
-
const reopened = r.open(), session = reopened.session;
|
|
125
|
-
ok(session.channels.resume("alice"));
|
|
126
|
-
expect(send(session, "carol", "before start", "c1").accepted).toBe(true);
|
|
127
|
-
await until(() => turnOf(session, 1).state.status === "completed", "alice's resumed turn");
|
|
128
|
-
expect(session.snapshot().items.filter(item => ["b1", "c1"].includes(item.itemId)).map(item => item.milestone)).toEqual(["received", "received"]);
|
|
129
|
-
expect(session.snapshot().turns.filter(turn => turn.channelId === "bob" || turn.channelId === "carol")).toEqual([]);
|
|
130
|
-
|
|
131
|
-
session.start();
|
|
132
|
-
await until(() => session.snapshot().turns.filter(turn => ["bob", "carol"].includes(turn.channelId) && turn.state.status === "completed").length === 2, "pending turns");
|
|
133
|
-
expect(session.snapshot().turns.filter(turn => turn.channelId === "bob").map(turn => turn.itemIds)).toEqual([["b1"]]);
|
|
134
|
-
expect(r.requests.filter(line => line.endsWith(":pending"))).toHaveLength(1);
|
|
135
|
-
reopened.close();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test("interrupting one turn ends it at once; a late tool result and a stale interrupt cannot touch the next turn", async () => {
|
|
139
|
-
const r = rig();
|
|
140
|
-
const { session, events } = r.open();
|
|
141
|
-
session.start();
|
|
142
|
-
send(session, "alice", "hold first", "a1");
|
|
143
|
-
send(session, "bob", "hello bob", "b1");
|
|
144
|
-
await until(() => r.held("alice"), "alice's first tool");
|
|
145
|
-
await until(() => events.some(e => e.channel === "bob" && e.event.type === "turn_ended"), "bob");
|
|
146
|
-
send(session, "alice", "hold second", "a2"); // untaken: stays pending behind the running turn
|
|
147
|
-
refused(session.channels.interrupt("bob", 1, "wrong channel"), "not_found");
|
|
148
|
-
refused(session.channels.interrupt("alice", 99), "not_found");
|
|
149
|
-
|
|
150
|
-
const first = ok(session.channels.interrupt("alice", 1, "no longer needed"));
|
|
151
|
-
expect(first).toMatchObject({ interrupted: true, turn: { turnId: 1, state: { status: "interrupted", reason: "no longer needed", uncertainCallIds: ["h1-1"] } } });
|
|
152
|
-
// The pending input starts the next turn without waiting for the old tool.
|
|
153
|
-
await until(() => channel(session, "alice").activeTurn?.turnId === 3 && r.effects.includes("start:alice#3"), "the next turn's tool");
|
|
154
|
-
const interrupted = events.find(e => e.channel === "alice" && e.event.type === "turn_ended")!.event;
|
|
155
|
-
expect(interrupted).toMatchObject({ outcome: "interrupted", error: "no longer needed", uncertainCalls: ["h1-1"] });
|
|
156
|
-
// The old tool returns late: nothing is recorded for turn 1 and turn 3 is unaffected.
|
|
157
|
-
const before = session.snapshot().timeline.length;
|
|
158
|
-
r.release("alice", 1);
|
|
159
|
-
await until(() => r.effects.includes("done:alice#1"), "the old tool to return late");
|
|
160
|
-
await new Promise(resolve => setTimeout(resolve, 20));
|
|
161
|
-
expect(channel(session, "alice").activeTurn).toMatchObject({ turnId: 3, status: "running" }); // still waiting on its own tool
|
|
162
|
-
r.release("alice", 3);
|
|
163
|
-
await until(() => r.effects.includes("done:alice#3"), "the second tool to finish");
|
|
164
|
-
expect(session.snapshot().timeline.filter(entry => entry.turnId === 1 && entry.message.role === "tool")).toEqual([]);
|
|
165
|
-
expect(turnOf(session, 1).state).toMatchObject({ status: "interrupted", uncertainCallIds: ["h1-1"] });
|
|
166
|
-
expect(session.snapshot().timeline.length).toBeGreaterThanOrEqual(before);
|
|
167
|
-
await until(() => turnOf(session, 3).state.status === "completed", "turn 3 to complete");
|
|
168
|
-
// Retrying the old interrupt leaves later turns alone.
|
|
169
|
-
expect(ok(session.channels.interrupt("alice", 1, "retry"))).toMatchObject({ interrupted: false, turn: { turnId: 1, state: { status: "interrupted" } } });
|
|
170
|
-
expect(turnOf(session, 3).state.status).toBe("completed");
|
|
171
|
-
expect(turnOf(session, 3).itemIds).toEqual(["a2"]);
|
|
172
|
-
session.stop("done");
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test("a stale interrupt sent while the next turn is running leaves that turn running", async () => {
|
|
176
|
-
const r = rig();
|
|
177
|
-
const { session } = r.open();
|
|
178
|
-
session.start();
|
|
179
|
-
send(session, "alice", "hold one", "a1");
|
|
180
|
-
await until(() => r.held("alice"), "first tool");
|
|
181
|
-
send(session, "alice", "hold two", "a2");
|
|
182
|
-
ok(session.channels.interrupt("alice", 1));
|
|
183
|
-
await until(() => r.effects.includes("start:alice#2"), "the second turn's tool");
|
|
184
|
-
expect(ok(session.channels.interrupt("alice", 1))).toMatchObject({ interrupted: false });
|
|
185
|
-
expect(turnOf(session, 2).state.status).toBe("running");
|
|
186
|
-
expect(channel(session, "alice").activeTurn).toMatchObject({ turnId: 2, status: "running" });
|
|
187
|
-
r.release("alice");
|
|
188
|
-
await until(() => turnOf(session, 2).state.status === "completed", "turn 2");
|
|
189
|
-
expect(turnOf(session, 1).state).toMatchObject({ status: "interrupted", reason: "interrupted by request" });
|
|
190
|
-
session.stop("done");
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test("interrupt and checkpoint race during a channel suspension: the first commit wins", async () => {
|
|
194
|
-
// Interrupt first: suspended without a checkpoint, backlog kept, late result fenced.
|
|
195
|
-
const a = rig(), one = a.open();
|
|
196
|
-
one.session.start();
|
|
197
|
-
send(one.session, "alice", "hold it", "a1"); await until(() => a.held("alice"), "tool");
|
|
198
|
-
send(one.session, "alice", "after", "a2");
|
|
199
|
-
const suspending = one.session.channels.suspend("alice");
|
|
200
|
-
expect(ok(one.session.channels.interrupt("alice", 1, "cut"))).toMatchObject({ interrupted: true });
|
|
201
|
-
expect(ok(await suspending)).toMatchObject({ lifecycle: "suspended", pendingItemIds: ["a2"] });
|
|
202
|
-
expect(channel(one.session, "alice").activeTurn).toBeUndefined();
|
|
203
|
-
a.release("alice");
|
|
204
|
-
await new Promise(resolve => setTimeout(resolve, 20));
|
|
205
|
-
expect(turnOf(one.session, 1).state.status).toBe("interrupted");
|
|
206
|
-
expect(one.session.snapshot().timeline.some(entry => entry.turnId === 1 && entry.message.role === "tool")).toBe(false);
|
|
207
|
-
expect(types(one.events, "alice").filter(t => t === "turn_suspended")).toEqual([]);
|
|
208
|
-
ok(one.session.channels.resume("alice")); // the backlog starts a fresh turn
|
|
209
|
-
await until(() => turnOf(one.session, 2)?.state.status === "completed", "the backlog turn");
|
|
210
|
-
one.session.stop("done");
|
|
211
|
-
|
|
212
|
-
// Checkpoint first: the interrupt reports it did not interrupt a turn and the checkpoint stays.
|
|
213
|
-
const b = rig(), two = b.open();
|
|
214
|
-
two.session.start();
|
|
215
|
-
send(two.session, "alice", "hold it", "a1"); await until(() => b.held("alice"), "tool");
|
|
216
|
-
const second = two.session.channels.suspend("alice");
|
|
217
|
-
b.release("alice");
|
|
218
|
-
expect(ok(await second)).toMatchObject({ lifecycle: "suspended", activeTurn: { turnId: 1, status: "suspended" } });
|
|
219
|
-
expect(ok(two.session.channels.interrupt("alice", 1, "too late"))).toMatchObject({ interrupted: false, turn: { state: { status: "suspended" } } });
|
|
220
|
-
expect(channel(two.session, "alice").activeTurn).toEqual({ turnId: 1, status: "suspended" });
|
|
221
|
-
two.session.stop("done");
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("session suspend and resume keep Alice individually suspended; her resume during session suspension starts nothing", async () => {
|
|
225
|
-
const r = rig(), { session, events } = r.open();
|
|
226
|
-
session.start();
|
|
227
|
-
send(session, "alice", "hold work", "a1"); await until(() => r.held("alice"), "tool");
|
|
228
|
-
send(session, "alice", "queued", "a2");
|
|
229
|
-
const alice = session.channels.suspend("alice"); r.release("alice"); ok(await alice);
|
|
230
|
-
send(session, "bob", "hi", "b1"); await until(() => events.some(e => e.channel === "bob" && e.event.type === "turn_ended"), "bob");
|
|
231
|
-
|
|
232
|
-
expect((await session.suspend()).ok).toBe(true);
|
|
233
|
-
expect(session.status()).toMatchObject({ lifecycle: "suspended", execution: "suspended" });
|
|
234
|
-
expect(session.resume().ok).toBe(true);
|
|
235
|
-
expect(session.status().lifecycle).toBe("running");
|
|
236
|
-
expect(channel(session, "alice")).toMatchObject({ lifecycle: "suspended", activeTurn: { turnId: 1, status: "suspended" }, pendingItemIds: ["a2"] });
|
|
237
|
-
expect(types(events, "alice")).not.toContain("turn_resumed");
|
|
238
|
-
expect(session.status().execution).toBe("idle"); // her backlog is not execution
|
|
239
|
-
|
|
240
|
-
// Resume her channel while the session is suspended: checkpoint preserved, no work.
|
|
241
|
-
expect((await session.suspend()).ok).toBe(true);
|
|
242
|
-
const resumed = ok(session.channels.resume("alice"));
|
|
243
|
-
expect(resumed).toMatchObject({ lifecycle: "open", activeTurn: { turnId: 1, status: "suspended" }, pendingItemIds: ["a2"], waitingForResume: true });
|
|
244
|
-
await new Promise(resolve => setTimeout(resolve, 30));
|
|
245
|
-
expect(types(events, "alice")).not.toContain("turn_resumed");
|
|
246
|
-
expect(turnOf(session, 1).state.status).toBe("suspended");
|
|
247
|
-
expect(send(session, "alice", "x")).toMatchObject({ accepted: false, code: "not_running" });
|
|
248
|
-
// Session resume continues it, and the pending input is taken once.
|
|
249
|
-
expect(session.resume().ok).toBe(true);
|
|
250
|
-
await until(() => turnOf(session, 1).state.status === "completed", "the resumed turn");
|
|
251
|
-
expect(turnOf(session, 1).itemIds).toEqual(["a1", "a2"]);
|
|
252
|
-
expect(r.effects.filter(line => line.startsWith("start:alice"))).toEqual(["start:alice#1"]);
|
|
253
|
-
session.stop("done");
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("withdraw competes with take: a withdrawn input never reaches a model, a taken one names its turn", async () => {
|
|
257
|
-
const r = rig(), { session, events } = r.open();
|
|
258
|
-
session.start();
|
|
259
|
-
send(session, "alice", "hold work", "a1"); await until(() => r.held("alice"), "tool");
|
|
260
|
-
send(session, "alice", "withdraw me", "w"); send(session, "alice", "take me", "t");
|
|
261
|
-
expect(ok(session.channels.withdraw("alice", "w"))).toMatchObject({ outcome: "withdrawn", repeated: false });
|
|
262
|
-
expect(types(events, "alice")).toContain("item_withdrawn");
|
|
263
|
-
expect(ok(session.channels.withdraw("alice", "w"))).toMatchObject({ outcome: "withdrawn", repeated: true });
|
|
264
|
-
expect(send(session, "alice", "withdraw me", "w")).toMatchObject({ accepted: true, duplicate: true, milestone: "withdrawn" });
|
|
265
|
-
expect(channel(session, "alice").pendingItemIds).toEqual(["t"]);
|
|
266
|
-
r.release("alice");
|
|
267
|
-
await until(() => turnOf(session, 1).state.status === "completed", "turn");
|
|
268
|
-
expect(ok(session.channels.withdraw("alice", "t"))).toMatchObject({ outcome: "taken", turnId: 1 });
|
|
269
|
-
expect(r.requests.some(line => line.includes("withdraw me"))).toBe(false);
|
|
270
|
-
expect(session.snapshot().timeline.some(entry => entry.itemId === "w")).toBe(false);
|
|
271
|
-
expect(session.snapshot().turns).toHaveLength(1);
|
|
272
|
-
session.stop("done");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
test("create, edit, suspend and delete are channel-local; a retired ID stays retired across a reopen", async () => {
|
|
276
|
-
const r = rig(), first = r.open(), { session } = first;
|
|
277
|
-
session.start();
|
|
278
|
-
expect(ok(session.channels.create({ channelId: "carol", displayName: "Carol" }))).toMatchObject({ created: true, channel: { lifecycle: "open", displayName: "Carol" } });
|
|
279
|
-
await new Promise(resolve => setTimeout(resolve, 20));
|
|
280
|
-
expect(session.snapshot().turns).toEqual([]); // creating starts no work
|
|
281
|
-
expect(ok(session.channels.edit("carol", "Caroline"))).toMatchObject({ displayName: "Caroline", lifecycle: "open" });
|
|
282
|
-
expect(ok(await session.channels.suspend("carol"))).toMatchObject({ lifecycle: "suspended" }); // idle: at once
|
|
283
|
-
expect(ok(await session.channels.suspend("carol"))).toMatchObject({ lifecycle: "suspended" });
|
|
284
|
-
expect(send(session, "carol", "hi")).toMatchObject({ accepted: false, code: "channel_suspended" });
|
|
285
|
-
ok(session.channels.resume("carol"));
|
|
286
|
-
send(session, "carol", "hello", "c1");
|
|
287
|
-
await until(() => turnOf(session, 1)?.state.status === "completed", "carol's turn");
|
|
288
|
-
send(session, "dave", "hold", "d1"); await until(() => r.held("dave"), "dave's tool");
|
|
289
|
-
send(session, "dave", "queued", "d2");
|
|
290
|
-
refused(session.channels.delete("dave"), "channel_busy");
|
|
291
|
-
r.release("dave"); await until(() => turnOf(session, 2).state.status === "completed", "dave");
|
|
292
|
-
expect(ok(session.channels.delete("carol"))).toMatchObject({ lifecycle: "retired" });
|
|
293
|
-
expect(send(session, "carol", "again")).toMatchObject({ accepted: false, code: "channel_retired" });
|
|
294
|
-
expect(session.agent.notify({ channelId: "carol", fromChannelId: "dave", text: "n" })).toMatchObject({ accepted: false, code: "channel_retired" });
|
|
295
|
-
refused(session.channels.create({ channelId: "carol" }), "channel_retired");
|
|
296
|
-
expect(session.snapshot().timeline.some(entry => entry.channelId === "carol")).toBe(true);
|
|
297
|
-
first.close();
|
|
298
|
-
const second = r.open();
|
|
299
|
-
expect(channel(second.session, "carol").lifecycle).toBe("retired");
|
|
300
|
-
expect(send(second.session, "carol", "once more")).toMatchObject({ accepted: false, code: "channel_retired" });
|
|
301
|
-
second.session.stop("done");
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
test("stop during a channel suspension returns it to open and keeps another channel's committed checkpoint", async () => {
|
|
305
|
-
const r = rig(), first = r.open(), { session } = first;
|
|
306
|
-
session.start();
|
|
307
|
-
send(session, "alice", "hold a", "a1"); send(session, "bob", "hold b", "b1");
|
|
308
|
-
await until(() => r.held("alice") && r.held("bob"), "both tools");
|
|
309
|
-
const alice = session.channels.suspend("alice"); r.release("alice"); ok(await alice);
|
|
310
|
-
const bob = session.channels.suspend("bob");
|
|
311
|
-
expect(channel(session, "bob").lifecycle).toBe("suspending");
|
|
312
|
-
session.stop("stop");
|
|
313
|
-
expect(refusedStopped(await bob)).toBe("stopped");
|
|
314
|
-
expect(channel(session, "alice")).toMatchObject({ lifecycle: "suspended", activeTurn: { turnId: 1, status: "suspended" } });
|
|
315
|
-
expect(channel(session, "bob")).toMatchObject({ lifecycle: "open", unresolvedInterruption: { status: "interrupted" } });
|
|
316
|
-
r.release("bob");
|
|
317
|
-
first.close();
|
|
318
|
-
const second = r.open();
|
|
319
|
-
expect(channel(second.session, "alice")).toMatchObject({ lifecycle: "suspended", activeTurn: { turnId: 1, status: "suspended" } });
|
|
320
|
-
second.session.stop("done");
|
|
321
|
-
});
|
|
322
|
-
const refusedStopped = (result: { ok: boolean; error?: { code: string } }) => result.ok ? "ok" : result.error!.code;
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { afterEach, expect, spyOn, test } from "bun:test";
|
|
2
|
-
import { HarnessClient } from "../src/client.ts";
|
|
3
|
-
import type { ClientTransport, RpcRequest } from "../src/contracts/protocol.ts";
|
|
4
|
-
|
|
5
|
-
const clients: HarnessClient[] = [];
|
|
6
|
-
afterEach(() => { for (const client of clients.splice(0)) client.close(); });
|
|
7
|
-
|
|
8
|
-
function setup(timeoutMs = 5_000) {
|
|
9
|
-
const sent: RpcRequest[] = [];
|
|
10
|
-
let deliver: Parameters<ClientTransport["subscribe"]>[0] | undefined;
|
|
11
|
-
let disconnect: Parameters<ClientTransport["onClose"]>[0] | undefined;
|
|
12
|
-
const wire = {
|
|
13
|
-
sendError: undefined as Error | undefined,
|
|
14
|
-
send(request: RpcRequest) {
|
|
15
|
-
sent.push(request);
|
|
16
|
-
if (wire.sendError) throw wire.sendError;
|
|
17
|
-
},
|
|
18
|
-
subscribe(listener: Parameters<ClientTransport["subscribe"]>[0]) {
|
|
19
|
-
deliver = listener;
|
|
20
|
-
return () => { deliver = undefined; };
|
|
21
|
-
},
|
|
22
|
-
onClose(listener: Parameters<ClientTransport["onClose"]>[0]) {
|
|
23
|
-
disconnect = listener;
|
|
24
|
-
return () => { disconnect = undefined; };
|
|
25
|
-
},
|
|
26
|
-
close() {},
|
|
27
|
-
} satisfies ClientTransport & { sendError?: Error };
|
|
28
|
-
const client = new HarnessClient(wire, timeoutMs);
|
|
29
|
-
clients.push(client);
|
|
30
|
-
|
|
31
|
-
const control = new AbortController();
|
|
32
|
-
const add = spyOn(control.signal, "addEventListener");
|
|
33
|
-
const remove = spyOn(control.signal, "removeEventListener");
|
|
34
|
-
return {
|
|
35
|
-
client, control, sent, wire,
|
|
36
|
-
respond(request: RpcRequest, value = { calls: [] }) {
|
|
37
|
-
deliver?.({ jsonrpc: "2.0", id: request.id, result: value });
|
|
38
|
-
},
|
|
39
|
-
disconnect(error: Error) { disconnect?.(error); },
|
|
40
|
-
expectClean(requestCount: number) {
|
|
41
|
-
expect(add.mock.calls).toHaveLength(requestCount);
|
|
42
|
-
expect(remove.mock.calls).toHaveLength(requestCount);
|
|
43
|
-
const removed = new Set(remove.mock.calls.map(([kind, listener]) => {
|
|
44
|
-
expect(kind).toBe("abort");
|
|
45
|
-
return listener;
|
|
46
|
-
}));
|
|
47
|
-
expect(removed).toEqual(new Set(add.mock.calls.map(([, listener]) => listener)));
|
|
48
|
-
expect(removed.size).toBe(requestCount);
|
|
49
|
-
expect((Reflect.get(client, "waiting") as Map<number, unknown>).size).toBe(0);
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
test("client pre-abort sends nothing and registers no waiter", async () => {
|
|
55
|
-
const rig = setup();
|
|
56
|
-
rig.control.abort();
|
|
57
|
-
await expect(rig.client.modelCalls({}, rig.control.signal)).rejects.toMatchObject({ code: "cancelled" });
|
|
58
|
-
expect(rig.sent).toEqual([]);
|
|
59
|
-
rig.expectClean(0);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("client abort ignores a late response and sends no cancel frame", async () => {
|
|
63
|
-
const rig = setup();
|
|
64
|
-
const waiting = rig.client.request("session/model-calls", {}, rig.control.signal).catch(error => error);
|
|
65
|
-
const request = rig.sent[0]!;
|
|
66
|
-
rig.control.abort();
|
|
67
|
-
expect(await waiting).toMatchObject({ code: "cancelled" });
|
|
68
|
-
rig.respond(request);
|
|
69
|
-
expect(rig.sent.map(frame => frame.method)).toEqual(["session/model-calls"]);
|
|
70
|
-
rig.expectClean(1);
|
|
71
|
-
const next = rig.client.modelCalls();
|
|
72
|
-
rig.respond(rig.sent[1]!);
|
|
73
|
-
expect(await next).toEqual({ calls: [] });
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("client response before abort settles and removes the listener once", async () => {
|
|
77
|
-
const rig = setup();
|
|
78
|
-
const waiting = rig.client.modelCalls({}, rig.control.signal);
|
|
79
|
-
rig.respond(rig.sent[0]!);
|
|
80
|
-
rig.control.abort();
|
|
81
|
-
expect(await waiting).toEqual({ calls: [] });
|
|
82
|
-
expect(rig.sent).toHaveLength(1);
|
|
83
|
-
rig.expectClean(1);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("client timeout before abort keeps the timeout and removes the listener once", async () => {
|
|
87
|
-
const rig = setup(10);
|
|
88
|
-
const waiting = rig.client.modelCalls({}, rig.control.signal).catch(error => error);
|
|
89
|
-
expect(await waiting).toMatchObject({ code: "timeout" });
|
|
90
|
-
rig.control.abort();
|
|
91
|
-
rig.respond(rig.sent[0]!);
|
|
92
|
-
expect(rig.sent).toHaveLength(1);
|
|
93
|
-
rig.expectClean(1);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test("client transport close rejects every waiter and removes their listeners", async () => {
|
|
97
|
-
const rig = setup();
|
|
98
|
-
const waiting = [rig.client.modelCalls({}, rig.control.signal), rig.client.modelCalls({}, rig.control.signal)];
|
|
99
|
-
const settled = Promise.allSettled(waiting);
|
|
100
|
-
rig.disconnect(new Error("fixture transport closed"));
|
|
101
|
-
rig.control.abort();
|
|
102
|
-
const reason = expect.objectContaining({ code: "transport_closed", message: "fixture transport closed" });
|
|
103
|
-
expect(await settled).toEqual([
|
|
104
|
-
{ status: "rejected", reason }, { status: "rejected", reason },
|
|
105
|
-
]);
|
|
106
|
-
await expect(rig.client.modelCalls({}, rig.control.signal)).rejects.toMatchObject({ code: "transport_closed" });
|
|
107
|
-
expect(rig.sent).toHaveLength(2);
|
|
108
|
-
rig.expectClean(2);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("client send failure removes the waiter and ignores the late response and abort", async () => {
|
|
112
|
-
const rig = setup();
|
|
113
|
-
const failure = new Error("fixture send failed");
|
|
114
|
-
rig.wire.sendError = failure;
|
|
115
|
-
await expect(rig.client.modelCalls({}, rig.control.signal)).rejects.toBe(failure);
|
|
116
|
-
rig.respond(rig.sent[0]!);
|
|
117
|
-
rig.control.abort();
|
|
118
|
-
expect(rig.sent).toHaveLength(1);
|
|
119
|
-
rig.expectClean(1);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test("client releases all listeners shared by concurrent requests", async () => {
|
|
123
|
-
const rig = setup();
|
|
124
|
-
const count = 64;
|
|
125
|
-
const settled = Promise.allSettled(Array.from({ length: count }, () => rig.client.modelCalls({}, rig.control.signal)));
|
|
126
|
-
for (const request of rig.sent.slice(0, count / 2)) rig.respond(request);
|
|
127
|
-
rig.control.abort();
|
|
128
|
-
for (const request of rig.sent.slice(count / 2)) rig.respond(request);
|
|
129
|
-
const results = await settled;
|
|
130
|
-
expect(results.filter(result => result.status === "fulfilled")).toHaveLength(count / 2);
|
|
131
|
-
expect(results.filter(result => result.status === "rejected")).toEqual(
|
|
132
|
-
Array.from({ length: count / 2 }, () => ({ status: "rejected", reason: expect.objectContaining({ code: "cancelled" }) })),
|
|
133
|
-
);
|
|
134
|
-
expect(rig.sent.map(request => request.method)).toEqual(Array(count).fill("session/model-calls"));
|
|
135
|
-
rig.expectClean(count);
|
|
136
|
-
});
|