@pi-in-go/pigpen-ahp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CREDITS.md +27 -0
- package/LICENSE +23 -0
- package/README.md +148 -0
- package/extensions/ahp/access_options_test.go +116 -0
- package/extensions/ahp/extension.go +54 -0
- package/extensions/ahp/go.mod +12 -0
- package/extensions/ahp/go.sum +2 -0
- package/extensions/ahp/go.work +8 -0
- package/extensions/ahp/internal/channels/chat.go +110 -0
- package/extensions/ahp/internal/channels/root.go +32 -0
- package/extensions/ahp/internal/channels/session.go +128 -0
- package/extensions/ahp/internal/channels/session_test.go +108 -0
- package/extensions/ahp/internal/compose/compose.go +153 -0
- package/extensions/ahp/internal/compose/compose_test.go +120 -0
- package/extensions/ahp/internal/gaps/gaps_test.go +88 -0
- package/extensions/ahp/internal/host/handshake_test.go +206 -0
- package/extensions/ahp/internal/host/host.go +1305 -0
- package/extensions/ahp/internal/host/reconnect_test.go +197 -0
- package/extensions/ahp/internal/host/replaywindow_test.go +31 -0
- package/extensions/ahp/internal/host/schema_test.go +79 -0
- package/extensions/ahp/internal/host/store.go +291 -0
- package/extensions/ahp/internal/host/store_update_test.go +85 -0
- package/extensions/ahp/internal/host/subscriptions_test.go +160 -0
- package/extensions/ahp/internal/host/surface_test.go +95 -0
- package/extensions/ahp/internal/host/workarounds.go +458 -0
- package/extensions/ahp/internal/host/workarounds_test.go +96 -0
- package/extensions/ahp/internal/live/live.go +328 -0
- package/extensions/ahp/internal/live/live_test.go +91 -0
- package/extensions/ahp/internal/live/store.go +113 -0
- package/extensions/ahp/internal/mapper/activity.go +199 -0
- package/extensions/ahp/internal/mapper/activity_test.go +188 -0
- package/extensions/ahp/internal/mapper/bench_test.go +38 -0
- package/extensions/ahp/internal/mapper/event_mapper_test.go +380 -0
- package/extensions/ahp/internal/mapper/fixtures_test.go +387 -0
- package/extensions/ahp/internal/mapper/helpers_test.go +251 -0
- package/extensions/ahp/internal/mapper/js.go +131 -0
- package/extensions/ahp/internal/mapper/mapper.go +600 -0
- package/extensions/ahp/internal/mapper/message_input_test.go +196 -0
- package/extensions/ahp/internal/mapper/messageinput.go +272 -0
- package/extensions/ahp/internal/mapper/schema_helpers_test.go +5 -0
- package/extensions/ahp/internal/mapper/testdata/LICENSE-pi-ahp +21 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/abort.json +711 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/bash-long-output.json +1312 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/compaction.json +6285 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/parallel-tools.json +2622 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/plain-text.json +1856 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/single-tool.json +1128 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/steering.json +3926 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-bash.json +2372 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-edit.json +3983 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-error.json +2850 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-find.json +1162 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-grep.json +2783 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-loop.json +1693 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-ls.json +2427 -0
- package/extensions/ahp/internal/mapper/testdata/fixtures/tool-write.json +1271 -0
- package/extensions/ahp/internal/mapper/title.go +34 -0
- package/extensions/ahp/internal/mapper/usermsg.go +87 -0
- package/extensions/ahp/internal/pi/activeturn_test.go +296 -0
- package/extensions/ahp/internal/pi/backend.go +64 -0
- package/extensions/ahp/internal/pi/catalogue.go +370 -0
- package/extensions/ahp/internal/pi/catalogue_test.go +271 -0
- package/extensions/ahp/internal/pi/chatdriver.go +533 -0
- package/extensions/ahp/internal/pi/chatdriver_test.go +416 -0
- package/extensions/ahp/internal/pi/clientactions.go +212 -0
- package/extensions/ahp/internal/pi/clientactions_test.go +273 -0
- package/extensions/ahp/internal/pi/completions.go +230 -0
- package/extensions/ahp/internal/pi/completions_test.go +272 -0
- package/extensions/ahp/internal/pi/config_test.go +269 -0
- package/extensions/ahp/internal/pi/deletesession.go +69 -0
- package/extensions/ahp/internal/pi/deletesession_test.go +153 -0
- package/extensions/ahp/internal/pi/disposal_test.go +362 -0
- package/extensions/ahp/internal/pi/fixture_test.go +308 -0
- package/extensions/ahp/internal/pi/foreign_test.go +122 -0
- package/extensions/ahp/internal/pi/harness_test.go +83 -0
- package/extensions/ahp/internal/pi/history.go +269 -0
- package/extensions/ahp/internal/pi/hydrated_test.go +171 -0
- package/extensions/ahp/internal/pi/hydratedlifecycle_test.go +196 -0
- package/extensions/ahp/internal/pi/hydration_test.go +209 -0
- package/extensions/ahp/internal/pi/hydrator.go +212 -0
- package/extensions/ahp/internal/pi/imageinput.go +224 -0
- package/extensions/ahp/internal/pi/imageinput_test.go +57 -0
- package/extensions/ahp/internal/pi/lifecycle_test.go +381 -0
- package/extensions/ahp/internal/pi/models.go +212 -0
- package/extensions/ahp/internal/pi/models_test.go +128 -0
- package/extensions/ahp/internal/pi/paging.go +95 -0
- package/extensions/ahp/internal/pi/pagingtruncate_test.go +323 -0
- package/extensions/ahp/internal/pi/projecttrust.go +222 -0
- package/extensions/ahp/internal/pi/registry.go +924 -0
- package/extensions/ahp/internal/pi/restart_test.go +185 -0
- package/extensions/ahp/internal/pi/services.go +70 -0
- package/extensions/ahp/internal/pi/sessionconfig.go +64 -0
- package/extensions/ahp/internal/pi/sessionfiles_test.go +74 -0
- package/extensions/ahp/internal/pi/sessionstore.go +83 -0
- package/extensions/ahp/internal/pi/summary_test.go +426 -0
- package/extensions/ahp/internal/pi/workarounds_wire_test.go +208 -0
- package/extensions/ahp/internal/pisession/fromentries_test.go +32 -0
- package/extensions/ahp/internal/pisession/json.go +31 -0
- package/extensions/ahp/internal/pisession/pisession.go +580 -0
- package/extensions/ahp/internal/settings/access.go +63 -0
- package/extensions/ahp/internal/settings/access_test.go +52 -0
- package/extensions/ahp/internal/settings/settings.go +117 -0
- package/extensions/ahp/internal/settings/settings_test.go +104 -0
- package/extensions/ahp/internal/svc/etag_other.go +15 -0
- package/extensions/ahp/internal/svc/etag_unix.go +34 -0
- package/extensions/ahp/internal/svc/glob.go +197 -0
- package/extensions/ahp/internal/svc/mime.go +37 -0
- package/extensions/ahp/internal/svc/paths.go +108 -0
- package/extensions/ahp/internal/svc/pty.go +64 -0
- package/extensions/ahp/internal/svc/pty_darwin.go +42 -0
- package/extensions/ahp/internal/svc/pty_linux.go +36 -0
- package/extensions/ahp/internal/svc/pty_other.go +9 -0
- package/extensions/ahp/internal/svc/pty_test.go +114 -0
- package/extensions/ahp/internal/svc/pty_unix.go +147 -0
- package/extensions/ahp/internal/svc/resource.go +495 -0
- package/extensions/ahp/internal/svc/resource_test.go +501 -0
- package/extensions/ahp/internal/svc/stat_bsd.go +9 -0
- package/extensions/ahp/internal/svc/stat_linux.go +9 -0
- package/extensions/ahp/internal/svc/terminal.go +454 -0
- package/extensions/ahp/internal/svc/terminal_test.go +512 -0
- package/extensions/ahp/internal/svc/watch.go +590 -0
- package/extensions/ahp/internal/svc/watch_test.go +627 -0
- package/extensions/ahp/internal/svc/watchevents_test.go +452 -0
- package/extensions/ahp/internal/svc/watchpolicy.go +81 -0
- package/extensions/ahp/internal/svc/watchpolicy_test.go +151 -0
- package/extensions/ahp/internal/svc/watchracy_test.go +61 -0
- package/extensions/ahp/internal/testkit/schema/LICENSE-agent-host-protocol +21 -0
- package/extensions/ahp/internal/testkit/schema/actions.schema.json +9208 -0
- package/extensions/ahp/internal/testkit/schema/commands.schema.json +10862 -0
- package/extensions/ahp/internal/testkit/schema/errors.schema.json +10928 -0
- package/extensions/ahp/internal/testkit/schema/notifications.schema.json +6667 -0
- package/extensions/ahp/internal/testkit/schema/state.schema.json +6392 -0
- package/extensions/ahp/internal/testkit/schema.go +360 -0
- package/extensions/ahp/internal/testkit/testkit.go +367 -0
- package/extensions/ahp/internal/twin/twin.go +27 -0
- package/extensions/ahp/internal/wire/dispatchable.go +106 -0
- package/extensions/ahp/internal/wire/dispatchable_list.go +15 -0
- package/extensions/ahp/internal/wire/helpers_test.go +5 -0
- package/extensions/ahp/internal/wire/wire.go +218 -0
- package/extensions/ahp/internal/wire/wire_test.go +123 -0
- package/extensions/ahp/internal/ws/helpers_test.go +7 -0
- package/extensions/ahp/internal/ws/vscode_test.go +198 -0
- package/extensions/ahp/internal/ws/ws.go +674 -0
- package/extensions/ahp/internal/ws/ws_test.go +324 -0
- package/extensions/ahp/realpig_test.go +589 -0
- package/extensions/ahp/runtime.go +311 -0
- package/extensions/ahp/runtime_test.go +110 -0
- package/extensions/ahp/testdata/upstream-tests.json +3833 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/LICENSE +21 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/NOTICE-PIGPEN.md +18 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahp/client.go +1011 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahp/error.go +111 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahp/multi_host_state_mirror.go +239 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahp/reducers.go +1939 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahp/transport.go +176 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/actions.generated.go +2447 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/commands.generated.go +1546 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/common.go +205 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/errors.generated.go +65 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/messages.generated.go +138 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/notifications.generated.go +264 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/state.generated.go +6171 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/ahptypes/version.generated.go +31 -0
- package/extensions/ahp/third_party/agent-host-protocol-go/go.mod +3 -0
- package/extensions/ahp/twins_test.go +91 -0
- package/package.json +40 -0
- package/proof/PORT.md +121 -0
- package/proof/mutations.json +152 -0
- package/proof/oracle/LICENSE +21 -0
- package/proof/oracle/README.md +120 -0
- package/proof/oracle/UPSTREAM.md +7 -0
- package/proof/oracle/package.json +68 -0
- package/proof/oracle/src/bin/cli.ts +66 -0
- package/proof/oracle/src/bin/tunnel.ts +128 -0
- package/proof/oracle/src/channels/chat.ts +134 -0
- package/proof/oracle/src/channels/root.ts +39 -0
- package/proof/oracle/src/channels/session.ts +118 -0
- package/proof/oracle/src/channels/terminal.ts +11 -0
- package/proof/oracle/src/core/channels.ts +108 -0
- package/proof/oracle/src/core/client-workarounds.ts +358 -0
- package/proof/oracle/src/core/connection.ts +41 -0
- package/proof/oracle/src/core/host.ts +882 -0
- package/proof/oracle/src/core/sequencer.ts +75 -0
- package/proof/oracle/src/core/state-store.ts +162 -0
- package/proof/oracle/src/core/uri.ts +25 -0
- package/proof/oracle/src/host/direct-settings.ts +110 -0
- package/proof/oracle/src/host/pi-host.ts +220 -0
- package/proof/oracle/src/host/serve.ts +71 -0
- package/proof/oracle/src/host/terminal-service.ts +346 -0
- package/proof/oracle/src/pi/activity.ts +171 -0
- package/proof/oracle/src/pi/changeset-service.ts +646 -0
- package/proof/oracle/src/pi/changeset-uri.ts +64 -0
- package/proof/oracle/src/pi/chat-driver.ts +529 -0
- package/proof/oracle/src/pi/completions.ts +160 -0
- package/proof/oracle/src/pi/delete-session.ts +53 -0
- package/proof/oracle/src/pi/event-mapper.ts +648 -0
- package/proof/oracle/src/pi/git-changes.ts +605 -0
- package/proof/oracle/src/pi/history.ts +305 -0
- package/proof/oracle/src/pi/image-input.ts +56 -0
- package/proof/oracle/src/pi/image-mime.ts +8 -0
- package/proof/oracle/src/pi/in-process-backend.ts +155 -0
- package/proof/oracle/src/pi/message-input.ts +212 -0
- package/proof/oracle/src/pi/models.ts +124 -0
- package/proof/oracle/src/pi/project-trust.ts +66 -0
- package/proof/oracle/src/pi/provider.ts +2 -0
- package/proof/oracle/src/pi/resource-paths.ts +80 -0
- package/proof/oracle/src/pi/resource-service.ts +356 -0
- package/proof/oracle/src/pi/resource-watch-policy.ts +35 -0
- package/proof/oracle/src/pi/resource-watch.ts +357 -0
- package/proof/oracle/src/pi/session-catalogue.ts +318 -0
- package/proof/oracle/src/pi/session-config.ts +84 -0
- package/proof/oracle/src/pi/session-history.ts +75 -0
- package/proof/oracle/src/pi/session-hydrator.ts +219 -0
- package/proof/oracle/src/pi/session-registry.ts +815 -0
- package/proof/oracle/src/pi/session-storage.ts +29 -0
- package/proof/oracle/src/pi/session-title.ts +18 -0
- package/proof/oracle/src/pi/turn-paging.ts +94 -0
- package/proof/oracle/src/pi/user-message.ts +66 -0
- package/proof/oracle/src/protocol/errors.ts +44 -0
- package/proof/oracle/src/protocol/jsonrpc.ts +89 -0
- package/proof/oracle/src/protocol/version.ts +39 -0
- package/proof/oracle/src/transport/websocket.ts +136 -0
- package/proof/oracle/src/tunnel/devtunnel.ts +293 -0
- package/proof/oracle/src/tunnel/discovery.ts +37 -0
- package/proof/oracle/test/active-turn-reconnect.test.ts +274 -0
- package/proof/oracle/test/activity.test.ts +171 -0
- package/proof/oracle/test/changeset-lifecycle.test.serial.ts +303 -0
- package/proof/oracle/test/changeset-uri.test.ts +37 -0
- package/proof/oracle/test/changeset.test.serial.ts +487 -0
- package/proof/oracle/test/chat-driver.test.ts +691 -0
- package/proof/oracle/test/client-actions.test.ts +409 -0
- package/proof/oracle/test/client-workarounds.test.ts +320 -0
- package/proof/oracle/test/completions.test.ts +323 -0
- package/proof/oracle/test/delete-session.test.ts +142 -0
- package/proof/oracle/test/direct-settings.test.ts +81 -0
- package/proof/oracle/test/event-mapper.test.ts +619 -0
- package/proof/oracle/test/fetch-turns.test.ts +207 -0
- package/proof/oracle/test/fixtures/abort.json +711 -0
- package/proof/oracle/test/fixtures/bash-long-output.json +1312 -0
- package/proof/oracle/test/fixtures/compaction.json +6285 -0
- package/proof/oracle/test/fixtures/parallel-tools.json +2622 -0
- package/proof/oracle/test/fixtures/plain-text.json +1856 -0
- package/proof/oracle/test/fixtures/single-tool.json +1128 -0
- package/proof/oracle/test/fixtures/steering.json +3926 -0
- package/proof/oracle/test/fixtures/tool-bash.json +2372 -0
- package/proof/oracle/test/fixtures/tool-edit.json +3983 -0
- package/proof/oracle/test/fixtures/tool-error.json +2850 -0
- package/proof/oracle/test/fixtures/tool-find.json +1162 -0
- package/proof/oracle/test/fixtures/tool-grep.json +2783 -0
- package/proof/oracle/test/fixtures/tool-loop.json +1693 -0
- package/proof/oracle/test/fixtures/tool-ls.json +2427 -0
- package/proof/oracle/test/fixtures/tool-write.json +1271 -0
- package/proof/oracle/test/handshake.test.ts +275 -0
- package/proof/oracle/test/harness.ts +153 -0
- package/proof/oracle/test/hydrated-session-lifecycle.test.ts +211 -0
- package/proof/oracle/test/image-input.test.ts +28 -0
- package/proof/oracle/test/image-session.test.ts +69 -0
- package/proof/oracle/test/live-turn.test.ts +304 -0
- package/proof/oracle/test/mapper-fixtures.test.ts +293 -0
- package/proof/oracle/test/message-input.test.ts +181 -0
- package/proof/oracle/test/model-discovery.test.ts +170 -0
- package/proof/oracle/test/models.test.ts +109 -0
- package/proof/oracle/test/pi-host.test.ts +91 -0
- package/proof/oracle/test/pi-replay.test.ts +141 -0
- package/proof/oracle/test/project-trust.test.ts +125 -0
- package/proof/oracle/test/protocol-surface.test.ts +121 -0
- package/proof/oracle/test/pty.test.ts +100 -0
- package/proof/oracle/test/reconnect.test.ts +389 -0
- package/proof/oracle/test/resource-watch-policy.test.ts +78 -0
- package/proof/oracle/test/resource-watch.test.serial.ts +536 -0
- package/proof/oracle/test/resource.test.ts +499 -0
- package/proof/oracle/test/schema.test.ts +88 -0
- package/proof/oracle/test/session-catalogue.test.ts +314 -0
- package/proof/oracle/test/session-config.test.ts +224 -0
- package/proof/oracle/test/session-disposal.test.ts +364 -0
- package/proof/oracle/test/session-hydration.test.ts +194 -0
- package/proof/oracle/test/session-lifecycle.test.ts +416 -0
- package/proof/oracle/test/session-storage.test.serial.ts +32 -0
- package/proof/oracle/test/session-summary.test.ts +418 -0
- package/proof/oracle/test/subscriptions.test.ts +198 -0
- package/proof/oracle/test/support/assertions.ts +32 -0
- package/proof/oracle/test/support/async.ts +26 -0
- package/proof/oracle/test/support/hydrated-session.ts +205 -0
- package/proof/oracle/test/support/images.ts +8 -0
- package/proof/oracle/test/support/recorded-fixtures.ts +60 -0
- package/proof/oracle/test/support/recorded-scenarios.ts +145 -0
- package/proof/oracle/test/support/replay.ts +194 -0
- package/proof/oracle/test/support/schema.ts +221 -0
- package/proof/oracle/test/support/session-files.ts +12 -0
- package/proof/oracle/test/support/session-storage.ts +22 -0
- package/proof/oracle/test/support/upstream.ts +25 -0
- package/proof/oracle/test/support/watch-events.ts +108 -0
- package/proof/oracle/test/terminal-service.test.ts +495 -0
- package/proof/oracle/test/truncate.test.ts +230 -0
- package/proof/oracle/test/tunnel.test.ts +258 -0
- package/proof/oracle/test/upstream-workarounds.test.ts +37 -0
- package/proof/oracle/test/uri.test.ts +24 -0
- package/proof/oracle/test/watch-events.test.ts +118 -0
- package/proof/oracle/tsconfig.json +32 -0
- package/proof/proof-piglet/piglet.yaml +18 -0
- package/proof/tools/fakellm/go.mod +3 -0
- package/proof/tools/fakellm/main.go +109 -0
- package/proof/tools/gen-dispatchable.py +30 -0
- package/provenance.json +28 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
package host_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
"time"
|
|
6
|
+
|
|
7
|
+
"github.com/microsoft/agent-host-protocol/clients/go/ahptypes"
|
|
8
|
+
|
|
9
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/host"
|
|
10
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/testkit"
|
|
11
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/twin"
|
|
12
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/wire"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
func initialized(t *testing.T, h *host.Host, subs ...string) *testkit.Client {
|
|
16
|
+
t.Helper()
|
|
17
|
+
c := testkit.Connect(t, h)
|
|
18
|
+
extra := map[string]any{}
|
|
19
|
+
if len(subs) > 0 {
|
|
20
|
+
extra["initialSubscriptions"] = subs
|
|
21
|
+
}
|
|
22
|
+
c.Initialize(nextClientID(), extra)
|
|
23
|
+
return c
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Twins of upstream test/subscriptions.test.ts, describe "subscriptions".
|
|
27
|
+
func TestSubscriptions(t *testing.T) {
|
|
28
|
+
h := testkit.NewHost(host.Options{})
|
|
29
|
+
|
|
30
|
+
twin.Run(t, "subscriptions", "returns the current state as a snapshot", func(t *testing.T) {
|
|
31
|
+
c := initialized(t, h)
|
|
32
|
+
res := c.Subscribe(wire.RootChannel)
|
|
33
|
+
if res.Snapshot == nil || res.Snapshot.Resource != wire.RootChannel {
|
|
34
|
+
t.Fatalf("snapshot = %+v", res.Snapshot)
|
|
35
|
+
}
|
|
36
|
+
if root := res.Snapshot.State.Root; root == nil || len(root.Agents) != 1 {
|
|
37
|
+
t.Fatalf("root state = %+v", root)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
twin.Run(t, "subscriptions", "rejects a channel scheme the host does not serve", func(t *testing.T) {
|
|
42
|
+
c := initialized(t, h)
|
|
43
|
+
c.ExpectError("subscribe", map[string]any{"channel": "ahp-unknown:/x"}, -32602)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
twin.Run(t, "subscriptions", "rejects a well-formed URI for a channel that does not exist", func(t *testing.T) {
|
|
47
|
+
c := initialized(t, h)
|
|
48
|
+
c.ExpectError("subscribe", map[string]any{"channel": "ahp-session:/nope"}, -32008)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Twins of upstream test/subscriptions.test.ts, describe "action dispatch".
|
|
53
|
+
func TestActionDispatch(t *testing.T) {
|
|
54
|
+
h := testkit.NewHost(host.Options{})
|
|
55
|
+
|
|
56
|
+
twin.Run(t, "subscriptions", "echoes a client-dispatchable action with its origin", func(t *testing.T) {
|
|
57
|
+
c := initialized(t, h)
|
|
58
|
+
c.Subscribe(wire.RootChannel)
|
|
59
|
+
seq := c.Dispatch(wire.RootChannel, map[string]any{"type": "root/configChanged", "config": map[string]any{"theme": "dark"}})
|
|
60
|
+
env := c.NextEnvelope(wire.RootChannel, 0)
|
|
61
|
+
if env.Channel != wire.RootChannel || actionType(t, env) != "root/configChanged" || env.RejectionReason != nil {
|
|
62
|
+
t.Fatalf("envelope = %+v", env)
|
|
63
|
+
}
|
|
64
|
+
// The origin lets the write-ahead client match the echo to its own dispatch.
|
|
65
|
+
if env.Origin == nil || env.Origin.ClientSeq != seq || env.ServerSeq <= 0 {
|
|
66
|
+
t.Fatalf("origin = %+v serverSeq = %d", env.Origin, env.ServerSeq)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
twin.Run(t, "subscriptions", "rejects an action that is not client-dispatchable", func(t *testing.T) {
|
|
71
|
+
c := initialized(t, h)
|
|
72
|
+
c.Subscribe(wire.RootChannel)
|
|
73
|
+
// root/agentsChanged is server-only: the host owns the agent list.
|
|
74
|
+
c.Dispatch(wire.RootChannel, map[string]any{"type": "root/agentsChanged", "agents": []any{}})
|
|
75
|
+
env := c.NextEnvelope(wire.RootChannel, 0)
|
|
76
|
+
if env.RejectionReason == nil || !contains(*env.RejectionReason, "not client-dispatchable") {
|
|
77
|
+
t.Fatalf("rejectionReason = %v", env.RejectionReason)
|
|
78
|
+
}
|
|
79
|
+
if root := h.Store().Root(wire.RootChannel); root == nil || len(root.Agents) != 1 {
|
|
80
|
+
t.Fatalf("a rejected action must leave state untouched, got %+v", root)
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
twin.Run(t, "subscriptions", "silently ignores an action for a channel that does not exist", func(t *testing.T) {
|
|
85
|
+
c := initialized(t, h)
|
|
86
|
+
c.Subscribe(wire.RootChannel)
|
|
87
|
+
c.Dispatch("ahp-session:/ghost", map[string]any{"type": "session/titleChanged", "title": "x"})
|
|
88
|
+
// No echo for the ghost channel, so the next envelope on root is the one dispatched afterwards.
|
|
89
|
+
c.Dispatch(wire.RootChannel, map[string]any{"type": "root/configChanged", "config": map[string]any{"probe": 1}})
|
|
90
|
+
if env := c.NextEnvelope("", 0); env.Channel != wire.RootChannel {
|
|
91
|
+
t.Fatalf("first envelope was on %s", env.Channel)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
twin.Run(t, "subscriptions", "broadcasts to every subscriber and allocates one seq per action", func(t *testing.T) {
|
|
96
|
+
alice, bob := initialized(t, h), initialized(t, h)
|
|
97
|
+
alice.Subscribe(wire.RootChannel)
|
|
98
|
+
bob.Subscribe(wire.RootChannel)
|
|
99
|
+
alice.Dispatch(wire.RootChannel, map[string]any{"type": "root/configChanged", "config": map[string]any{"shared": true}})
|
|
100
|
+
a, b := alice.NextEnvelope(wire.RootChannel, 0), bob.NextEnvelope(wire.RootChannel, 0)
|
|
101
|
+
if a.ServerSeq != b.ServerSeq || testkit.JSON(t, a.Action) != testkit.JSON(t, b.Action) {
|
|
102
|
+
t.Fatalf("alice %d %s, bob %d %s", a.ServerSeq, testkit.JSON(t, a.Action), b.ServerSeq, testkit.JSON(t, b.Action))
|
|
103
|
+
}
|
|
104
|
+
// Both clients reduce the same envelope, so they converge by construction.
|
|
105
|
+
if a.Origin == nil || b.Origin == nil || a.Origin.ClientId != b.Origin.ClientId {
|
|
106
|
+
t.Fatalf("origins differ: %+v %+v", a.Origin, b.Origin)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
twin.Run(t, "subscriptions", "treats root/configChanged as a no-op until the host declares a config schema", func(t *testing.T) {
|
|
111
|
+
// AHP only merges config values into a schema the host has already published. The action is
|
|
112
|
+
// still sequenced and echoed; it just does not change state.
|
|
113
|
+
c := initialized(t, h)
|
|
114
|
+
c.Subscribe(wire.RootChannel)
|
|
115
|
+
c.Dispatch(wire.RootChannel, map[string]any{"type": "root/configChanged", "config": map[string]any{"theme": "dark"}})
|
|
116
|
+
env := c.NextEnvelope(wire.RootChannel, 0)
|
|
117
|
+
if env.RejectionReason != nil {
|
|
118
|
+
t.Fatalf("unexpected rejection %q", *env.RejectionReason)
|
|
119
|
+
}
|
|
120
|
+
if root := h.Store().Root(wire.RootChannel); root == nil || root.Config != nil {
|
|
121
|
+
t.Fatalf("config = %+v", root)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
twin.Run(t, "subscriptions", "stops delivering after unsubscribe", func(t *testing.T) {
|
|
126
|
+
c := initialized(t, h)
|
|
127
|
+
c.Subscribe(wire.RootChannel)
|
|
128
|
+
c.Unsubscribe(wire.RootChannel)
|
|
129
|
+
c.Ping()
|
|
130
|
+
before := h.ServerSeq()
|
|
131
|
+
h.DispatchServerAction(wire.RootChannel, rootActiveSessions(7))
|
|
132
|
+
// The action was still sequenced and applied — the client just stops seeing it.
|
|
133
|
+
if h.ServerSeq() != before+1 {
|
|
134
|
+
t.Fatalf("serverSeq = %d, want %d", h.ServerSeq(), before+1)
|
|
135
|
+
}
|
|
136
|
+
if !c.Silent(func(n testkit.Notification) bool { _, ok := n.Envelope(); return ok }, 150*time.Millisecond) {
|
|
137
|
+
t.Fatal("an unsubscribed client received an action")
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
func rootActiveSessions(n int64) ahptypes.StateAction {
|
|
143
|
+
return ahptypes.StateAction{Value: &ahptypes.RootActiveSessionsChangedAction{Type: ahptypes.ActionTypeRootActiveSessionsChanged, ActiveSessions: n}}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
func actionType(t *testing.T, env ahptypes.ActionEnvelope) string {
|
|
147
|
+
t.Helper()
|
|
148
|
+
m := testkit.Normalize(t, env.Action).(map[string]any)
|
|
149
|
+
s, _ := m["type"].(string)
|
|
150
|
+
return s
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
func contains(s, sub string) bool {
|
|
154
|
+
for i := 0; i+len(sub) <= len(s); i++ {
|
|
155
|
+
if s[i:i+len(sub)] == sub {
|
|
156
|
+
return true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return false
|
|
160
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
package host_test
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"os"
|
|
6
|
+
"strings"
|
|
7
|
+
"testing"
|
|
8
|
+
|
|
9
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/host"
|
|
10
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/testkit"
|
|
11
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/twin"
|
|
12
|
+
"github.com/MichaelKinsy/pigpen/ahp/internal/wire"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// Twins of upstream test/protocol-surface.test.ts: the AHP 0.9 command surface this product
|
|
16
|
+
// exposes. Upstream makes the policy table exhaustive at compile time over the client library's
|
|
17
|
+
// CommandMap, so an AHP upgrade forces an explicit decision; here the same table is checked against
|
|
18
|
+
// the vendored spec's command list in TestCommandPolicyCoversTheSpec (an addition, not a twin).
|
|
19
|
+
|
|
20
|
+
// rootMethods are the connection-level commands routed on the root channel.
|
|
21
|
+
var rootMethods = []string{
|
|
22
|
+
"ping", "createResourceWatch", "listSessions", "resourceRead", "resourceWrite", "resourceList",
|
|
23
|
+
"resourceCopy", "resourceDelete", "resourceMove", "resourceResolve", "resourceMkdir", "resourceRequest",
|
|
24
|
+
"resolveSessionConfig", "sessionConfigCompletions",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// unsupportedRequests are commands this host deliberately does not implement.
|
|
28
|
+
var unsupportedRequests = map[string]map[string]any{
|
|
29
|
+
"createChat": {"channel": "ahp-session:/session", "chat": "ahp-chat:/chat"},
|
|
30
|
+
"disposeChat": {"channel": "ahp-chat:/chat"},
|
|
31
|
+
"authenticate": {"channel": wire.RootChannel, "resource": "https://example.com", "token": "opaque"},
|
|
32
|
+
"invokeChangesetOperation": {"channel": "ahp-changeset:/changes", "operationId": "apply"},
|
|
33
|
+
"listAutomationTriggerDefinitions": {"channel": wire.RootChannel},
|
|
34
|
+
"runAutomation": {"channel": "ahp-automations://", "automation": "ahp-automation:/job", "requestId": "request"},
|
|
35
|
+
"fetchAutomationRuns": {"channel": "ahp-automations://", "automation": "ahp-automation:/job"},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func TestAHPCommandSurface(t *testing.T) {
|
|
39
|
+
h := testkit.NewHost(host.Options{})
|
|
40
|
+
client := testkit.Connect(t, h)
|
|
41
|
+
t.Cleanup(client.Close)
|
|
42
|
+
client.Initialize("surface-client", nil)
|
|
43
|
+
|
|
44
|
+
twin.Run(t, "protocol-surface", "returns MethodNotFound for every deliberately unsupported command", func(t *testing.T) {
|
|
45
|
+
for method, params := range unsupportedRequests {
|
|
46
|
+
client.ExpectError(method, params, wire.CodeMethodNotFound)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
twin.Run(t, "protocol-surface", "requires the root routing channel on every connection-level command", func(t *testing.T) {
|
|
51
|
+
wrongChannel := "ahp-session:/wrong-channel"
|
|
52
|
+
for _, method := range rootMethods {
|
|
53
|
+
client.ExpectError(method, map[string]any{"channel": wrongChannel}, wire.CodeInvalidParams)
|
|
54
|
+
}
|
|
55
|
+
initializing := testkit.Connect(t, h)
|
|
56
|
+
t.Cleanup(initializing.Close)
|
|
57
|
+
initializing.ExpectError("initialize", map[string]any{"channel": wrongChannel, "clientId": "wrong-channel-client", "protocolVersions": testkit.SupportedVersions()}, wire.CodeInvalidParams)
|
|
58
|
+
reconnecting := testkit.Connect(t, h)
|
|
59
|
+
t.Cleanup(reconnecting.Close)
|
|
60
|
+
reconnecting.ExpectError("reconnect", map[string]any{"channel": wrongChannel, "clientId": "wrong-channel-reconnect", "lastSeenServerSeq": 0, "subscriptions": []string{}}, wire.CodeInvalidParams)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// TestCommandPolicyCoversTheSpec is the port's counterpart of upstream's compile-time exhaustiveness:
|
|
65
|
+
// every command of the vendored spec must be an explicit decision, implemented or refused.
|
|
66
|
+
func TestCommandPolicyCoversTheSpec(t *testing.T) {
|
|
67
|
+
raw, err := os.ReadFile("../testkit/schema/commands.schema.json")
|
|
68
|
+
if err != nil {
|
|
69
|
+
t.Fatal(err)
|
|
70
|
+
}
|
|
71
|
+
var schema struct {
|
|
72
|
+
Defs map[string]json.RawMessage `json:"$defs"`
|
|
73
|
+
}
|
|
74
|
+
if err := json.Unmarshal(raw, &schema); err != nil {
|
|
75
|
+
t.Fatal(err)
|
|
76
|
+
}
|
|
77
|
+
implemented := map[string]bool{
|
|
78
|
+
"initialize": true, "ping": true, "reconnect": true, "subscribe": true, "createSession": true, "disposeSession": true,
|
|
79
|
+
"createTerminal": true, "disposeTerminal": true, "createResourceWatch": true, "listSessions": true,
|
|
80
|
+
"resourceRead": true, "resourceWrite": true, "resourceList": true, "resourceCopy": true, "resourceDelete": true,
|
|
81
|
+
"resourceMove": true, "resourceResolve": true, "resourceMkdir": true, "resourceRequest": true, "fetchTurns": true,
|
|
82
|
+
"resolveSessionConfig": true, "sessionConfigCompletions": true, "completions": true,
|
|
83
|
+
}
|
|
84
|
+
// unsubscribe and dispatchAction are notifications, not commands.
|
|
85
|
+
notCommands := map[string]bool{"BaseParams": true, "PaginatedParams": true, "UnsubscribeParams": true, "DispatchActionParams": true}
|
|
86
|
+
for def := range schema.Defs {
|
|
87
|
+
if !strings.HasSuffix(def, "Params") || notCommands[def] {
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
method := strings.ToLower(def[:1]) + strings.TrimSuffix(def[1:], "Params")
|
|
91
|
+
if _, refused := unsupportedRequests[method]; !implemented[method] && !refused {
|
|
92
|
+
t.Errorf("spec command %q has no explicit policy: implement it or refuse it in unsupportedRequests", method)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|