refactor(protocol): extract presentation contracts (#227)
* refactor(protocol): extract presentation contracts * docs(architecture): describe presentation contract ownership * test(protocol): check decoded same-peer switch types * test(protocol): isolate route validation cases
- commit
- be1cf92256b87ad8a550fa1859f00e291b031861
- author
- bnema · · 2026-08-28 11:44 UTC
- committer
- GitHub · · 2026-08-28 11:44 UTC
- parent
- 040f576
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown
117 files · +2183 -2059
M AGENTS.md +1 -1
| @@ -61,7 +61,7 @@ Before touching daemon teardown paths, read the lock-ordering notes at the top o | |||
| 61 | 61 | ||
| 62 | 62 | ## Wire protocol | |
| 63 | 63 | ||
| 64 | - | Wire payload types/codecs live in `internal/ports/frame.go` and `internal/ports/wire.go`. Connection framing lives in `internal/adapters/ipc/transport.go`. | |
| 64 | + | Semantic presentation and route values live in `internal/protocol`; session-control values live in `internal/ports/session_control.go`. Frame IDs and codecs live in `internal/ports/frame.go`, `internal/ports/wire.go`, `internal/ports/routes_wire.go`, and `internal/ports/wire_command.go`. Connection framing lives in `internal/adapters/ipc/transport.go`. | |
| 65 | 65 | ||
| 66 | 66 | - IPC frames on a connection are 4-byte big-endian length, 1 type byte, then payload. | |
| 67 | 67 | - Client message types occupy `1–13`, `15`, `32–33`, and `35` (`MsgParkedRouteRequest`); server types occupy `16–23`, `25–31`, `34`, and `36` (`MsgParkedRouteResponse`). Types `14` and `24` remain reserved. | |
M internal/adapters/dgram/network_sim_test.go +4 -3
| @@ -11,6 +11,7 @@ import ( | |||
| 11 | 11 | ||
| 12 | 12 | "github.com/bnema/vev/internal/domain" | |
| 13 | 13 | "github.com/bnema/vev/internal/ports" | |
| 14 | + | "github.com/bnema/vev/internal/protocol" | |
| 14 | 15 | pdgram "github.com/bnema/vev/pkg/dgram" | |
| 15 | 16 | ) | |
| 16 | 17 | ||
| @@ -452,7 +453,7 @@ func TestTransportFloodClassification(t *testing.T) { | |||
| 452 | 453 | } | |
| 453 | 454 | } | |
| 454 | 455 | b.mu.Unlock() | |
| 455 | - | primer := mustMarshalOutput(ports.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("primer")}) | |
| 456 | + | primer := mustMarshalOutput(protocol.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("primer")}) | |
| 456 | 457 | if err := a.SendAsync(ports.Frame{Type: ports.MsgOutput, Payload: primer}); err != nil { | |
| 457 | 458 | t.Fatal(err) | |
| 458 | 459 | } | |
| @@ -529,7 +530,7 @@ func TestTransportFloodClassification(t *testing.T) { | |||
| 529 | 530 | } | |
| 530 | 531 | }) | |
| 531 | 532 | for state := 1; state < outputCount; state++ { | |
| 532 | - | payload := mustMarshalOutput(ports.Output{ | |
| 533 | + | payload := mustMarshalOutput(protocol.Output{ | |
| 533 | 534 | Epoch: 1, | |
| 534 | 535 | Base: uint64(state), | |
| 535 | 536 | New: uint64(state + 1), | |
| @@ -854,7 +855,7 @@ func floodState(sender, receiver *Transport, link *simulatedLink) floodTransport | |||
| 854 | 855 | } | |
| 855 | 856 | ||
| 856 | 857 | func floodOutputPayload(baseState, mtu int) []byte { | |
| 857 | - | return mustMarshalOutput(ports.Output{ | |
| 858 | + | return mustMarshalOutput(protocol.Output{ | |
| 858 | 859 | Epoch: 1, | |
| 859 | 860 | Base: uint64(baseState), | |
| 860 | 861 | New: uint64(baseState + 1), | |
M internal/adapters/dgram/proxy_test.go +2 -1
| @@ -12,6 +12,7 @@ import ( | |||
| 12 | 12 | ||
| 13 | 13 | "github.com/bnema/vev/internal/domain" | |
| 14 | 14 | "github.com/bnema/vev/internal/ports" | |
| 15 | + | "github.com/bnema/vev/internal/protocol" | |
| 15 | 16 | ) | |
| 16 | 17 | ||
| 17 | 18 | type fakeTransport struct { | |
| @@ -105,7 +106,7 @@ func TestProxyRuntimeClampsDatagramHelloOutputWindowAndPreservesControl(t *testi | |||
| 105 | 106 | } | |
| 106 | 107 | ||
| 107 | 108 | input := ports.Frame{Type: ports.MsgInput, Payload: []byte("still flowing")} | |
| 108 | - | ack := ports.Frame{Type: ports.MsgAck, Payload: mustMarshalAck(ports.Ack{Epoch: 1, State: 7})} | |
| 109 | + | ack := ports.Frame{Type: ports.MsgAck, Payload: mustMarshalAck(protocol.Ack{Epoch: 1, State: 7})} | |
| 109 | 110 | client.recv <- recvResult{frame: input} | |
| 110 | 111 | client.recv <- recvResult{frame: ack} | |
| 111 | 112 | for _, want := range []ports.Frame{input, ack} { | |
M internal/adapters/dgram/transport_send_test.go +4 -3
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | pdgram "github.com/bnema/vev/pkg/dgram" | |
| 13 | 14 | "github.com/stretchr/testify/require" | |
| 14 | 15 | ) | |
| @@ -114,7 +115,7 @@ func TestOutputPacingSendsAtMostOneOversizedFramePerTick(t *testing.T) { | |||
| 114 | 115 | if err := a.SendAsync(ports.Frame{Type: ports.MsgOutput, Payload: []byte("prime")}); err != nil { | |
| 115 | 116 | t.Fatal(err) | |
| 116 | 117 | } | |
| 117 | - | large := mustMarshalOutput(ports.Output{Epoch: 1, Base: 1, New: 2, Size: domain.Size{Cols: 1, Rows: 1}, Data: make([]byte, 24*a.mtu)}) | |
| 118 | + | large := mustMarshalOutput(protocol.Output{Epoch: 1, Base: 1, New: 2, Size: domain.Size{Cols: 1, Rows: 1}, Data: make([]byte, 24*a.mtu)}) | |
| 118 | 119 | for range 2 { | |
| 119 | 120 | if err := a.SendAsync(ports.Frame{Type: ports.MsgOutput, Payload: large}); err != nil { | |
| 120 | 121 | t.Fatal(err) | |
| @@ -222,7 +223,7 @@ func TestOwnedSynchronousMaxSideEffectCompletesThroughConcurrentPacedWork(t *tes | |||
| 222 | 223 | } | |
| 223 | 224 | a.mu.Unlock() | |
| 224 | 225 | go a.resendPending() | |
| 225 | - | sideEffect := ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Data: make([]byte, 100*1024)})} | |
| 226 | + | sideEffect := ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Data: make([]byte, 100*1024)})} | |
| 226 | 227 | done := make(chan error, 1) | |
| 227 | 228 | go func() { done <- a.SendSynchronous(sideEffect) }() | |
| 228 | 229 | ||
| @@ -330,7 +331,7 @@ func TestCloseUnblocksQueuedSynchronousFrames(t *testing.T) { | |||
| 330 | 331 | frame ports.Frame | |
| 331 | 332 | }{ | |
| 332 | 333 | {name: "control", frame: ports.Frame{Type: ports.MsgPing}}, | |
| 333 | - | {name: "terminal side effect", frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Data: []byte("osc")})}}, | |
| 334 | + | {name: "terminal side effect", frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Data: []byte("osc")})}}, | |
| 334 | 335 | } | |
| 335 | 336 | for _, tt := range frames { | |
| 336 | 337 | t.Run(tt.name, func(t *testing.T) { | |
M internal/adapters/dgram/wire_test_helpers_test.go +6 -3
| @@ -1,8 +1,11 @@ | |||
| 1 | 1 | package dgram | |
| 2 | 2 | ||
| 3 | - | import "github.com/bnema/vev/internal/ports" | |
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | + | ) | |
| 4 | 7 | ||
| 5 | - | func mustMarshalOutput(m ports.Output) []byte { | |
| 8 | + | func mustMarshalOutput(m protocol.Output) []byte { | |
| 6 | 9 | payload, err := ports.MarshalOutput(m) | |
| 7 | 10 | if err != nil { | |
| 8 | 11 | panic(err) | |
| @@ -10,7 +13,7 @@ func mustMarshalOutput(m ports.Output) []byte { | |||
| 10 | 13 | return payload | |
| 11 | 14 | } | |
| 12 | 15 | ||
| 13 | - | func mustMarshalAck(m ports.Ack) []byte { | |
| 16 | + | func mustMarshalAck(m protocol.Ack) []byte { | |
| 14 | 17 | payload, err := ports.MarshalAck(m) | |
| 15 | 18 | if err != nil { | |
| 16 | 19 | panic(err) | |
M internal/adapters/ipc/transport_test.go +2 -1
| @@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | ||
| 14 | 14 | "github.com/bnema/vev/internal/domain" | |
| 15 | 15 | "github.com/bnema/vev/internal/ports" | |
| 16 | + | "github.com/bnema/vev/internal/protocol" | |
| 16 | 17 | ) | |
| 17 | 18 | ||
| 18 | 19 | func TestTransportSendRecvBothDirections(t *testing.T) { | |
| @@ -140,7 +141,7 @@ func TestTransportManySmallFramesBackToBack(t *testing.T) { | |||
| 140 | 141 | } | |
| 141 | 142 | // Vary a couple to prove ordering and content are both preserved. | |
| 142 | 143 | frames[7] = ports.Frame{Type: ports.MsgInput, Payload: ports.MarshalInput(ports.Input{Data: []byte("hop")})} | |
| 143 | - | frames[150] = ports.Frame{Type: ports.MsgResize, Payload: mustMarshalResize(ports.Resize{Size: domain.Size{Cols: 5, Rows: 6}})} | |
| 144 | + | frames[150] = ports.Frame{Type: ports.MsgResize, Payload: mustMarshalResize(protocol.Resize{Size: domain.Size{Cols: 5, Rows: 6}})} | |
| 144 | 145 | ||
| 145 | 146 | var wg sync.WaitGroup | |
| 146 | 147 | wg.Go(func() { | |
M internal/adapters/ipc/wire_test_helpers_test.go +5 -2
| @@ -1,8 +1,11 @@ | |||
| 1 | 1 | package ipc | |
| 2 | 2 | ||
| 3 | - | import "github.com/bnema/vev/internal/ports" | |
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | + | ) | |
| 4 | 7 | ||
| 5 | - | func mustMarshalResize(m ports.Resize) []byte { | |
| 8 | + | func mustMarshalResize(m protocol.Resize) []byte { | |
| 6 | 9 | payload, err := ports.MarshalResize(m) | |
| 7 | 10 | if err != nil { | |
| 8 | 11 | panic(err) | |
M internal/adapters/remote/preview.go +15 -14
| @@ -11,6 +11,7 @@ import ( | |||
| 11 | 11 | "github.com/bnema/vev/internal/adapters/sshstdio" | |
| 12 | 12 | "github.com/bnema/vev/internal/domain" | |
| 13 | 13 | "github.com/bnema/vev/internal/ports" | |
| 14 | + | "github.com/bnema/vev/internal/protocol" | |
| 14 | 15 | ) | |
| 15 | 16 | ||
| 16 | 17 | const ( | |
| @@ -39,11 +40,11 @@ func NewPreviewClient() ports.RemotePreviewClient { | |||
| 39 | 40 | return &PreviewClient{command: exec.CommandContext} | |
| 40 | 41 | } | |
| 41 | 42 | ||
| 42 | - | func (c *PreviewClient) Preview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (ports.RemotePreview, error) { | |
| 43 | - | request := ports.RemotePreviewRequest{Version: ports.RemotePreviewSchemaVersion, Target: target, Width: width, Height: height} | |
| 43 | + | func (c *PreviewClient) Preview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (protocol.RemotePreview, error) { | |
| 44 | + | request := protocol.RemotePreviewRequest{Version: protocol.RemotePreviewSchemaVersion, Target: target, Width: width, Height: height} | |
| 44 | 45 | payload := ports.MarshalRemotePreviewRequest(request) | |
| 45 | 46 | if payload == nil { | |
| 46 | - | return ports.RemotePreview{}, ports.ErrInvalidRemotePreviewRequest | |
| 47 | + | return protocol.RemotePreview{}, protocol.ErrInvalidRemotePreviewRequest | |
| 47 | 48 | } | |
| 48 | 49 | runCtx, cancel := context.WithTimeout(ctx, c.previewTimeout()) | |
| 49 | 50 | defer cancel() | |
| @@ -54,7 +55,7 @@ func (c *PreviewClient) Preview(ctx context.Context, target domain.RemoteSession | |||
| 54 | 55 | encoded := base64.RawURLEncoding.EncodeToString(payload) | |
| 55 | 56 | spec := sshstdio.BuildCommandForRemoteCommand(target.Endpoint, "vev", "_remote-preview", encoded) | |
| 56 | 57 | cmd := command(runCtx, spec.Path, spec.Args...) | |
| 57 | - | stdout := boundedBuffer{limit: ports.RemotePreviewMaxBytes} | |
| 58 | + | stdout := boundedBuffer{limit: protocol.RemotePreviewMaxBytes} | |
| 58 | 59 | stderr := boundedBuffer{limit: remotePreviewMaxDiagnostic} | |
| 59 | 60 | cmd.Stdout = &stdout | |
| 60 | 61 | cmd.Stderr = &stderr | |
| @@ -62,30 +63,30 @@ func (c *PreviewClient) Preview(ctx context.Context, target domain.RemoteSession | |||
| 62 | 63 | if err := cmd.Run(); err != nil { | |
| 63 | 64 | if ctxErr := runCtx.Err(); ctxErr != nil { | |
| 64 | 65 | if parentErr := ctx.Err(); parentErr != nil { | |
| 65 | - | return ports.RemotePreview{}, parentErr | |
| 66 | + | return protocol.RemotePreview{}, parentErr | |
| 66 | 67 | } | |
| 67 | - | return ports.RemotePreview{}, ports.ErrRemotePreviewTimeout | |
| 68 | + | return protocol.RemotePreview{}, protocol.ErrRemotePreviewTimeout | |
| 68 | 69 | } | |
| 69 | 70 | if stdout.overflow || stderr.overflow { | |
| 70 | - | return ports.RemotePreview{}, errRemotePreviewTooLarge | |
| 71 | + | return protocol.RemotePreview{}, errRemotePreviewTooLarge | |
| 71 | 72 | } | |
| 72 | 73 | if diagnostic := sanitizeCatalogDiagnostic(string(stderr.Bytes())); diagnostic != "" { | |
| 73 | - | return ports.RemotePreview{}, fmt.Errorf("%w: %v: %s", errRemotePreviewSSH, err, diagnostic) | |
| 74 | + | return protocol.RemotePreview{}, fmt.Errorf("%w: %v: %s", errRemotePreviewSSH, err, diagnostic) | |
| 74 | 75 | } | |
| 75 | - | return ports.RemotePreview{}, fmt.Errorf("%w: %v", errRemotePreviewSSH, err) | |
| 76 | + | return protocol.RemotePreview{}, fmt.Errorf("%w: %v", errRemotePreviewSSH, err) | |
| 76 | 77 | } | |
| 77 | 78 | if stdout.overflow || stderr.overflow { | |
| 78 | - | return ports.RemotePreview{}, errRemotePreviewTooLarge | |
| 79 | + | return protocol.RemotePreview{}, errRemotePreviewTooLarge | |
| 79 | 80 | } | |
| 80 | 81 | preview, err := ports.UnmarshalRemotePreview(stdout.Bytes()) | |
| 81 | 82 | if err != nil { | |
| 82 | - | return ports.RemotePreview{}, err | |
| 83 | + | return protocol.RemotePreview{}, err | |
| 83 | 84 | } | |
| 84 | - | if preview.Status != ports.RemotePreviewOK { | |
| 85 | - | return ports.RemotePreview{}, fmt.Errorf("remote preview unavailable: status %d", preview.Status) | |
| 85 | + | if preview.Status != protocol.RemotePreviewOK { | |
| 86 | + | return protocol.RemotePreview{}, fmt.Errorf("remote preview unavailable: status %d", preview.Status) | |
| 86 | 87 | } | |
| 87 | 88 | if preview.LifecycleID != target.LifecycleID || preview.TabID != target.LiveTabID { | |
| 88 | - | return ports.RemotePreview{}, errRemotePreviewIdentity | |
| 89 | + | return protocol.RemotePreview{}, errRemotePreviewIdentity | |
| 89 | 90 | } | |
| 90 | 91 | return preview, nil | |
| 91 | 92 | } | |
M internal/adapters/remote/preview_test.go +10 -9
| @@ -16,6 +16,7 @@ import ( | |||
| 16 | 16 | "github.com/bnema/vev/internal/adapters/sshstdio" | |
| 17 | 17 | "github.com/bnema/vev/internal/domain" | |
| 18 | 18 | "github.com/bnema/vev/internal/ports" | |
| 19 | + | "github.com/bnema/vev/internal/protocol" | |
| 19 | 20 | ) | |
| 20 | 21 | ||
| 21 | 22 | func previewClientTargetForTest() domain.RemoteSessionTarget { | |
| @@ -31,8 +32,8 @@ func TestRemotePreviewClientBuildsExactSSHCommandAndDecodesResponse(t *testing.T | |||
| 31 | 32 | Endpoint: "build@mule", DisplayOrigin: "mule", LifecycleID: lifecycle, | |
| 32 | 33 | SessionName: "work", LiveTabID: "tab-1", | |
| 33 | 34 | } | |
| 34 | - | want := ports.RemotePreview{ | |
| 35 | - | Version: ports.RemotePreviewSchemaVersion, Status: ports.RemotePreviewOK, | |
| 35 | + | want := protocol.RemotePreview{ | |
| 36 | + | Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, | |
| 36 | 37 | LifecycleID: lifecycle, TabID: target.LiveTabID, Revision: 7, Width: 1, Height: 1, | |
| 37 | 38 | Cells: []renderer.Cell{{Rune: 'x', Style: renderer.DefaultStyle()}}, | |
| 38 | 39 | } | |
| @@ -79,17 +80,17 @@ func TestRemotePreviewClientRejectsMismatchedResponseIdentity(t *testing.T) { | |||
| 79 | 80 | target := previewClientTargetForTest() | |
| 80 | 81 | var otherLifecycle domain.SessionLifecycleID | |
| 81 | 82 | otherLifecycle[0] = 2 | |
| 82 | - | valid := ports.RemotePreview{ | |
| 83 | - | Version: ports.RemotePreviewSchemaVersion, Status: ports.RemotePreviewOK, | |
| 83 | + | valid := protocol.RemotePreview{ | |
| 84 | + | Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, | |
| 84 | 85 | LifecycleID: target.LifecycleID, TabID: target.LiveTabID, Revision: 1, Width: 1, Height: 1, | |
| 85 | 86 | Cells: []renderer.Cell{{Rune: 'x', Style: renderer.DefaultStyle()}}, | |
| 86 | 87 | } | |
| 87 | 88 | tests := []struct { | |
| 88 | 89 | name string | |
| 89 | - | mutate func(*ports.RemotePreview) | |
| 90 | + | mutate func(*protocol.RemotePreview) | |
| 90 | 91 | }{ | |
| 91 | - | {name: "lifecycle ID", mutate: func(preview *ports.RemotePreview) { preview.LifecycleID = otherLifecycle }}, | |
| 92 | - | {name: "tab ID", mutate: func(preview *ports.RemotePreview) { preview.TabID = "tab-2" }}, | |
| 92 | + | {name: "lifecycle ID", mutate: func(preview *protocol.RemotePreview) { preview.LifecycleID = otherLifecycle }}, | |
| 93 | + | {name: "tab ID", mutate: func(preview *protocol.RemotePreview) { preview.TabID = "tab-2" }}, | |
| 93 | 94 | } | |
| 94 | 95 | for _, tt := range tests { | |
| 95 | 96 | t.Run(tt.name, func(t *testing.T) { | |
| @@ -120,7 +121,7 @@ func TestRemotePreviewClientRejectsMalformedResponse(t *testing.T) { | |||
| 120 | 121 | ||
| 121 | 122 | func TestRemotePreviewClientRejectsOversizedOutput(t *testing.T) { | |
| 122 | 123 | client := &PreviewClient{command: func(ctx context.Context, _ string, _ ...string) *exec.Cmd { | |
| 123 | - | return exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("head -c %d /dev/zero", ports.RemotePreviewMaxBytes+1)) | |
| 124 | + | return exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("head -c %d /dev/zero", protocol.RemotePreviewMaxBytes+1)) | |
| 124 | 125 | }} | |
| 125 | 126 | target := previewClientTargetForTest() | |
| 126 | 127 | _, err := client.Preview(context.Background(), target, 1, 1) | |
| @@ -145,7 +146,7 @@ func TestRemotePreviewClientReturnsInternalTimeoutSentinel(t *testing.T) { | |||
| 145 | 146 | }, | |
| 146 | 147 | } | |
| 147 | 148 | _, err := client.Preview(context.Background(), previewClientTargetForTest(), 1, 1) | |
| 148 | - | require.ErrorIs(t, err, ports.ErrRemotePreviewTimeout) | |
| 149 | + | require.ErrorIs(t, err, protocol.ErrRemotePreviewTimeout) | |
| 149 | 150 | } | |
| 150 | 151 | ||
| 151 | 152 | func TestRemotePreviewClientReturnsCallerCancellation(t *testing.T) { | |
M internal/app/final_acceptance_test.go +6 -5
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | "github.com/bnema/vev/internal/usecase/daemon" | |
| 12 | 13 | "github.com/stretchr/testify/require" | |
| 13 | 14 | ) | |
| @@ -46,7 +47,7 @@ func awaitAcceptanceCommand(t *testing.T, p *pump, requestID uint64) ports.Comma | |||
| 46 | 47 | return result | |
| 47 | 48 | } | |
| 48 | 49 | ||
| 49 | - | func awaitAcceptanceOutput(t *testing.T, p *pump, predicate func(ports.Output) bool) ports.Output { | |
| 50 | + | func awaitAcceptanceOutput(t *testing.T, p *pump, predicate func(protocol.Output) bool) protocol.Output { | |
| 50 | 51 | t.Helper() | |
| 51 | 52 | frame := awaitAcceptanceFrame(t, p, ports.MsgOutput, func(frame ports.Frame) bool { | |
| 52 | 53 | output, err := ports.UnmarshalOutput(frame.Payload) | |
| @@ -113,15 +114,15 @@ func TestAcceptanceTwoLocalAttachmentsKeepViewsOverTransports(t *testing.T) { | |||
| 113 | 114 | // The resize keeps its attachment-local output stream while recalculating | |
| 114 | 115 | // shared PTY/content geometry from the latest valid attachment claim; the | |
| 115 | 116 | // peer stream remains independent. | |
| 116 | - | resizePayload, err := ports.MarshalResize(ports.Resize{Size: domain.Size{Cols: 100, Rows: 30}}) | |
| 117 | + | resizePayload, err := ports.MarshalResize(protocol.Resize{Size: domain.Size{Cols: 100, Rows: 30}}) | |
| 117 | 118 | require.NoError(t, err) | |
| 118 | 119 | require.NoError(t, first.Send(ports.Frame{Type: ports.MsgResize, Payload: resizePayload})) | |
| 119 | - | resized := awaitAcceptanceOutput(t, firstPump, func(output ports.Output) bool { return output.Size == (domain.Size{Cols: 100, Rows: 30}) }) | |
| 120 | + | resized := awaitAcceptanceOutput(t, firstPump, func(output protocol.Output) bool { return output.Size == (domain.Size{Cols: 100, Rows: 30}) }) | |
| 120 | 121 | require.Equal(t, domain.Size{Cols: 100, Rows: 30}, resized.Size) | |
| 121 | 122 | assertNoTextAfterInput(t, secondPump, size, "FIRST_PANE_INPUT") | |
| 122 | 123 | ||
| 123 | 124 | require.NoError(t, first.Send(ports.Frame{Type: ports.MsgOutputResetRequest, Payload: ports.MarshalOutputResetRequest(ports.OutputResetRequest{})})) | |
| 124 | - | reset := awaitAcceptanceOutput(t, firstPump, func(output ports.Output) bool { return output.Base == 0 && output.Full }) | |
| 125 | + | reset := awaitAcceptanceOutput(t, firstPump, func(output protocol.Output) bool { return output.Base == 0 && output.Full }) | |
| 125 | 126 | require.True(t, reset.Full) | |
| 126 | 127 | assertNoTextAfterInput(t, secondPump, size, "FIRST_PANE_INPUT") | |
| 127 | 128 | ||
| @@ -173,6 +174,6 @@ func TestAcceptanceAttachedCommandUsesItsConnectionOnly(t *testing.T) { | |||
| 173 | 174 | ||
| 174 | 175 | drained: | |
| 175 | 176 | require.NoError(t, first.Send(ports.Frame{Type: ports.MsgOutputResetRequest, Payload: ports.MarshalOutputResetRequest(ports.OutputResetRequest{})})) | |
| 176 | - | awaitAcceptanceOutput(t, firstPump, func(output ports.Output) bool { return output.Full && output.Base == 0 }) | |
| 177 | + | awaitAcceptanceOutput(t, firstPump, func(output protocol.Output) bool { return output.Full && output.Base == 0 }) | |
| 177 | 178 | assertNoTextAfterInput(t, secondPump, size, "Commands") | |
| 178 | 179 | } | |
M internal/app/remote_final_acceptance_test.go +3 -2
| @@ -15,6 +15,7 @@ import ( | |||
| 15 | 15 | "github.com/bnema/vev/internal/domain" | |
| 16 | 16 | "github.com/bnema/vev/internal/ports" | |
| 17 | 17 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 18 | + | "github.com/bnema/vev/internal/protocol" | |
| 18 | 19 | "github.com/bnema/vev/internal/usecase/client" | |
| 19 | 20 | "github.com/stretchr/testify/require" | |
| 20 | 21 | ) | |
| @@ -78,7 +79,7 @@ func serveAcceptanceRemote(tr ports.Transport, target string, handoff ports.Atta | |||
| 78 | 79 | if outputs != nil { | |
| 79 | 80 | outputs <- string(data) | |
| 80 | 81 | } | |
| 81 | - | payload, err := ports.MarshalOutput(ports.Output{ | |
| 82 | + | payload, err := ports.MarshalOutput(protocol.Output{ | |
| 82 | 83 | Epoch: 1, New: 1, Full: true, Size: domain.Size{Cols: 80, Rows: 24}, Data: data, | |
| 83 | 84 | }) | |
| 84 | 85 | if err != nil { | |
| @@ -155,7 +156,7 @@ func TestAcceptanceRemoteDirectAndPickerUseOnlyRemoteTransports(t *testing.T) { | |||
| 155 | 156 | welcome, err := wireTransport.Recv() | |
| 156 | 157 | require.NoError(t, err) | |
| 157 | 158 | require.Equal(t, ports.MsgWelcome, welcome.Type) | |
| 158 | - | require.NoError(t, wireTransport.Send(ports.Frame{Type: ports.MsgTheme, Payload: ports.MarshalTheme(ports.Theme{})})) | |
| 159 | + | require.NoError(t, wireTransport.Send(ports.Frame{Type: ports.MsgTheme, Payload: ports.MarshalTheme(protocol.Theme{})})) | |
| 159 | 160 | attachTarget, err := wireTransport.Recv() | |
| 160 | 161 | require.NoError(t, err) | |
| 161 | 162 | target, err := ports.UnmarshalAttachTarget(attachTarget.Payload) | |
M internal/app/remote_preview.go +4 -3
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/adapters/ipc" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | 15 | // runRemotePreview is the hidden SSH-side carriage. The request is encoded in | |
| @@ -27,7 +28,7 @@ func runRemotePreview(ctx context.Context, encoded string) error { | |||
| 27 | 28 | if ctxErr := ctx.Err(); ctxErr != nil { | |
| 28 | 29 | return ctxErr | |
| 29 | 30 | } | |
| 30 | - | return writeRemotePreviewStatus(ports.RemotePreviewUnavailable) | |
| 31 | + | return writeRemotePreviewStatus(protocol.RemotePreviewUnavailable) | |
| 31 | 32 | } | |
| 32 | 33 | defer func() { _ = transport.Close() }() | |
| 33 | 34 | if err := transport.Send(ports.Frame{Type: ports.MsgRemotePreviewRequest, Payload: request}); err != nil { | |
| @@ -63,8 +64,8 @@ func runRemotePreview(ctx context.Context, encoded string) error { | |||
| 63 | 64 | } | |
| 64 | 65 | } | |
| 65 | 66 | ||
| 66 | - | func writeRemotePreviewStatus(status ports.RemotePreviewStatus) error { | |
| 67 | - | payload := ports.MarshalRemotePreview(ports.RemotePreview{Version: ports.RemotePreviewSchemaVersion, Status: status}) | |
| 67 | + | func writeRemotePreviewStatus(status protocol.RemotePreviewStatus) error { | |
| 68 | + | payload := ports.MarshalRemotePreview(protocol.RemotePreview{Version: protocol.RemotePreviewSchemaVersion, Status: status}) | |
| 68 | 69 | if payload == nil { | |
| 69 | 70 | return errors.New("vev: failed to encode remote preview status") | |
| 70 | 71 | } | |
M internal/app/run.go +8 -7
| @@ -46,6 +46,7 @@ import ( | |||
| 46 | 46 | "github.com/bnema/vev/internal/persist" | |
| 47 | 47 | "github.com/bnema/vev/internal/platform" | |
| 48 | 48 | "github.com/bnema/vev/internal/ports" | |
| 49 | + | "github.com/bnema/vev/internal/protocol" | |
| 49 | 50 | "github.com/bnema/vev/internal/usecase/client" | |
| 50 | 51 | "github.com/bnema/vev/internal/usecase/daemon" | |
| 51 | 52 | "github.com/bnema/vev/internal/usecase/recovery" | |
| @@ -892,10 +893,10 @@ func runAttachWithDeps(ctx context.Context, intent uint8, name, remoteTarget, ac | |||
| 892 | 893 | var remoteSelection *domain.RemoteSessionTarget | |
| 893 | 894 | var remoteEnvironmentPolicy ports.EnvironmentPolicy | |
| 894 | 895 | remoteDisplayOrigin := domain.RemoteDisplayOrigin(remoteTarget) | |
| 895 | - | routeOrigin := ports.RouteOriginLocal | |
| 896 | + | routeOrigin := protocol.RouteOriginLocal | |
| 896 | 897 | routeOriginKey := "local" | |
| 897 | 898 | if remoteTarget != "" { | |
| 898 | - | routeOrigin = ports.RouteOriginRemote | |
| 899 | + | routeOrigin = protocol.RouteOriginRemote | |
| 899 | 900 | routeOriginKey = remoteTarget | |
| 900 | 901 | if modeErr != nil { | |
| 901 | 902 | return modeErr | |
| @@ -939,7 +940,7 @@ func runAttachWithDeps(ctx context.Context, intent uint8, name, remoteTarget, ac | |||
| 939 | 940 | Intent: target.Intent, | |
| 940 | 941 | SessionName: target.Session, | |
| 941 | 942 | Remote: true, | |
| 942 | - | Origin: ports.RouteOriginDiscovery, | |
| 943 | + | Origin: protocol.RouteOriginDiscovery, | |
| 943 | 944 | OriginKey: target.Endpoint, | |
| 944 | 945 | RemoteTarget: selection, | |
| 945 | 946 | HostLabel: displayOrigin, | |
| @@ -968,7 +969,7 @@ func runAttachWithDeps(ctx context.Context, intent uint8, name, remoteTarget, ac | |||
| 968 | 969 | RemoteHostLearner: attachRememberLearner(deps, remoteTarget, log), | |
| 969 | 970 | AttachHandoff: handoff, | |
| 970 | 971 | Remote: true, | |
| 971 | - | Origin: ports.RouteOriginRemote, | |
| 972 | + | Origin: protocol.RouteOriginRemote, | |
| 972 | 973 | OriginKey: remoteTarget, | |
| 973 | 974 | }, client.AttachRequest{ | |
| 974 | 975 | Intent: intent, | |
| @@ -992,9 +993,9 @@ func runAttachWithDeps(ctx context.Context, intent uint8, name, remoteTarget, ac | |||
| 992 | 993 | RuntimeObserver: deps.runtimeObserver, | |
| 993 | 994 | AttachHandoff: handoff, | |
| 994 | 995 | Remote: false, | |
| 995 | - | Origin: ports.RouteOriginLocal, | |
| 996 | + | Origin: protocol.RouteOriginLocal, | |
| 996 | 997 | OriginKey: "local", | |
| 997 | - | }, client.AttachRequest{Intent: intent, SessionName: name, Origin: ports.RouteOriginLocal, OriginKey: "local"}) | |
| 998 | + | }, client.AttachRequest{Intent: intent, SessionName: name, Origin: protocol.RouteOriginLocal, OriginKey: "local"}) | |
| 998 | 999 | } | |
| 999 | 1000 | ||
| 1000 | 1001 | var handoffErr *client.AttachTargetError | |
| @@ -1013,7 +1014,7 @@ func runAttachWithDeps(ctx context.Context, intent uint8, name, remoteTarget, ac | |||
| 1013 | 1014 | handoffAttempts++ | |
| 1014 | 1015 | remoteTarget = handoffErr.Target.Endpoint | |
| 1015 | 1016 | remoteDisplayOrigin = domain.RemoteDisplayOrigin(remoteTarget) | |
| 1016 | - | routeOrigin = ports.RouteOriginDiscovery | |
| 1017 | + | routeOrigin = protocol.RouteOriginDiscovery | |
| 1017 | 1018 | routeOriginKey = remoteTarget | |
| 1018 | 1019 | name = handoffErr.Target.Session | |
| 1019 | 1020 | intent = handoffErr.Target.Intent | |
M internal/app/run_test.go +3 -2
| @@ -22,6 +22,7 @@ import ( | |||
| 22 | 22 | "github.com/bnema/vev/internal/persist" | |
| 23 | 23 | "github.com/bnema/vev/internal/ports" | |
| 24 | 24 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 25 | + | "github.com/bnema/vev/internal/protocol" | |
| 25 | 26 | "github.com/bnema/vev/internal/usecase/client" | |
| 26 | 27 | "github.com/bnema/vev/internal/usecase/daemon" | |
| 27 | 28 | "github.com/bnema/vev/pkg/kv" | |
| @@ -962,11 +963,11 @@ func TestRunAttachWithDepsLocalPickerHandoffAttachesSelectedRemote(t *testing.T) | |||
| 962 | 963 | runClient: func(_ context.Context, deps client.Dependencies, request client.AttachRequest) error { | |
| 963 | 964 | if deps.Remote { | |
| 964 | 965 | remoteCalls++ | |
| 965 | - | require.Equal(t, client.AttachRequest{Intent: ports.IntentAttach, SessionName: "picked", Remote: true, Origin: ports.RouteOriginDiscovery, OriginKey: "selected.example", HostLabel: "selected.example", EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned}, request) | |
| 966 | + | require.Equal(t, client.AttachRequest{Intent: ports.IntentAttach, SessionName: "picked", Remote: true, Origin: protocol.RouteOriginDiscovery, OriginKey: "selected.example", HostLabel: "selected.example", EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned}, request) | |
| 966 | 967 | return nil | |
| 967 | 968 | } | |
| 968 | 969 | localCalls++ | |
| 969 | - | require.Equal(t, client.AttachRequest{Intent: ports.IntentAttach, SessionName: "work", Origin: ports.RouteOriginLocal, OriginKey: "local"}, request) | |
| 970 | + | require.Equal(t, client.AttachRequest{Intent: ports.IntentAttach, SessionName: "work", Origin: protocol.RouteOriginLocal, OriginKey: "local"}, request) | |
| 970 | 971 | return &client.AttachTargetError{Target: ports.AttachTarget{Endpoint: "selected.example", Session: "picked", Intent: ports.IntentAttach}} | |
| 971 | 972 | }, | |
| 972 | 973 | }) | |
M internal/ports/frame.go +11 -147
| @@ -1,27 +1,9 @@ | |||
| 1 | 1 | package ports | |
| 2 | 2 | ||
| 3 | - | import ( | |
| 4 | - | "time" | |
| 5 | - | ||
| 6 | - | renderer "github.com/bnema/vev-vt" | |
| 7 | - | "github.com/bnema/vev/internal/domain" | |
| 8 | - | ) | |
| 9 | - | ||
| 10 | - | // HandshakeTimeout bounds every transport handshake from connect through the | |
| 11 | - | // first committed publication. | |
| 12 | - | const HandshakeTimeout = 15 * time.Second | |
| 13 | - | ||
| 14 | - | // ProtocolVersion is the current vev IPC wire protocol version. | |
| 15 | - | const ProtocolVersion uint16 = 37 | |
| 16 | - | ||
| 17 | 3 | // MaxFrameLen is the largest permitted frame length, including the type byte | |
| 18 | 4 | // and excluding the four-byte length prefix. | |
| 19 | 5 | const MaxFrameLen = 16 << 20 | |
| 20 | 6 | ||
| 21 | - | // MaxOutputDataLen is the largest decoded terminal byte stream that fits in | |
| 22 | - | // one Output frame after its type byte and wire metadata. | |
| 23 | - | const MaxOutputDataLen = MaxFrameLen - 1 - outputPayloadOverhead | |
| 24 | - | ||
| 25 | 7 | // MsgType identifies the kind of payload carried by a Frame. | |
| 26 | 8 | type MsgType uint8 | |
| 27 | 9 | ||
| @@ -48,18 +30,16 @@ const ( | |||
| 48 | 30 | MsgSamePeerSwitchRequest MsgType = 33 | |
| 49 | 31 | MsgParkedRouteRequest MsgType = 35 | |
| 50 | 32 | ||
| 51 | - | MsgWelcome MsgType = 16 | |
| 52 | - | MsgError MsgType = 17 | |
| 53 | - | MsgOutput MsgType = 18 | |
| 54 | - | MsgDetached MsgType = 19 | |
| 55 | - | MsgPong MsgType = 20 | |
| 56 | - | MsgSessions MsgType = 21 | |
| 57 | - | MsgCommandResult MsgType = 22 | |
| 58 | - | MsgNavigationAction MsgType = 23 | |
| 59 | - | MsgAttachTarget MsgType = 25 | |
| 60 | - | MsgRemotePreviewResponse MsgType = 26 | |
| 61 | - | // Route navigation metadata/control frames occupy the post-26 server range; | |
| 62 | - | // 14 and 24 remain reserved for compatibility with older peers. | |
| 33 | + | MsgWelcome MsgType = 16 | |
| 34 | + | MsgError MsgType = 17 | |
| 35 | + | MsgOutput MsgType = 18 | |
| 36 | + | MsgDetached MsgType = 19 | |
| 37 | + | MsgPong MsgType = 20 | |
| 38 | + | MsgSessions MsgType = 21 | |
| 39 | + | MsgCommandResult MsgType = 22 | |
| 40 | + | MsgNavigationAction MsgType = 23 | |
| 41 | + | MsgAttachTarget MsgType = 25 | |
| 42 | + | MsgRemotePreviewResponse MsgType = 26 | |
| 63 | 43 | MsgCommittedRouteIdentity MsgType = 27 | |
| 64 | 44 | MsgRecentRouteSnapshot MsgType = 28 | |
| 65 | 45 | MsgNavigateRecentRoute MsgType = 29 | |
| @@ -70,124 +50,8 @@ const ( | |||
| 70 | 50 | ) | |
| 71 | 51 | ||
| 72 | 52 | // Frame is the unit of exchange over a Transport: a typed, length-delimited | |
| 73 | - | // message. It lives in ports (rather than an ipc adapter) so usecases and | |
| 74 | - | // adapters can share it without either depending on a concrete transport | |
| 75 | - | // implementation. | |
| 53 | + | // message. | |
| 76 | 54 | type Frame struct { | |
| 77 | 55 | Type MsgType | |
| 78 | 56 | Payload []byte | |
| 79 | 57 | } | |
| 80 | - | ||
| 81 | - | // NavigationCapabilities advertises the bounded client routes available to a | |
| 82 | - | // directly attached daemon. | |
| 83 | - | type NavigationCapabilities uint8 | |
| 84 | - | ||
| 85 | - | const ( | |
| 86 | - | NavigationCapabilityHomePicker NavigationCapabilities = 1 << iota | |
| 87 | - | NavigationCapabilityBack | |
| 88 | - | ) | |
| 89 | - | ||
| 90 | - | // StartupOverlay selects the one startup overlay opened by a navigation route. | |
| 91 | - | type StartupOverlay uint8 | |
| 92 | - | ||
| 93 | - | const ( | |
| 94 | - | StartupOverlayNone StartupOverlay = iota | |
| 95 | - | StartupOverlaySessionPicker | |
| 96 | - | ) | |
| 97 | - | ||
| 98 | - | // NavigationAction is a server request for one bounded client route transition. | |
| 99 | - | type NavigationAction uint8 | |
| 100 | - | ||
| 101 | - | const ( | |
| 102 | - | NavigationOpenHomePicker NavigationAction = 1 | |
| 103 | - | NavigationBack NavigationAction = 2 | |
| 104 | - | ) | |
| 105 | - | ||
| 106 | - | // ParkedRouteLeaseID is an opaque capability minted by the attached daemon for | |
| 107 | - | // one home-picker excursion. It is bound server-side to the exact connection | |
| 108 | - | // generation and transport that received the navigation directive. | |
| 109 | - | type ParkedRouteLeaseID [16]byte | |
| 110 | - | ||
| 111 | - | func (id ParkedRouteLeaseID) IsZero() bool { return id == ParkedRouteLeaseID{} } | |
| 112 | - | ||
| 113 | - | // NavigationDirective requests one client-owned route transition. Opening the | |
| 114 | - | // home picker always carries a fresh lease; Back is sent by the transient home | |
| 115 | - | // route and therefore carries no lease. | |
| 116 | - | type NavigationDirective struct { | |
| 117 | - | Action NavigationAction | |
| 118 | - | LeaseID ParkedRouteLeaseID | |
| 119 | - | } | |
| 120 | - | ||
| 121 | - | // ParkedRouteAction advances one retained route through its one-shot lease. | |
| 122 | - | type ParkedRouteAction uint8 | |
| 123 | - | ||
| 124 | - | const ( | |
| 125 | - | ParkedRoutePrepare ParkedRouteAction = iota + 1 | |
| 126 | - | ParkedRouteResume | |
| 127 | - | ParkedRouteSwitch | |
| 128 | - | ) | |
| 129 | - | ||
| 130 | - | // ParkedRouteRequest prepares, resumes, or switches the retained authenticated | |
| 131 | - | // route. Target is present only for Switch and retains exact lifecycle/tab | |
| 132 | - | // authority from the home picker's remote catalogue row. | |
| 133 | - | type ParkedRouteRequest struct { | |
| 134 | - | RequestID uint64 | |
| 135 | - | LeaseID ParkedRouteLeaseID | |
| 136 | - | Action ParkedRouteAction | |
| 137 | - | Target *domain.RemoteSessionTarget | |
| 138 | - | } | |
| 139 | - | ||
| 140 | - | // ParkedRouteStatus is the explicit outcome for a retained-route request. | |
| 141 | - | type ParkedRouteStatus uint8 | |
| 142 | - | ||
| 143 | - | const ( | |
| 144 | - | ParkedRouteReady ParkedRouteStatus = iota + 1 | |
| 145 | - | ParkedRouteResumed | |
| 146 | - | ParkedRouteSwitched | |
| 147 | - | ParkedRouteRejected | |
| 148 | - | ParkedRouteExpired | |
| 149 | - | ParkedRouteStaleTarget | |
| 150 | - | ) | |
| 151 | - | ||
| 152 | - | // ParkedRouteResponse correlates one retained-route request with its outcome. | |
| 153 | - | type ParkedRouteResponse struct { | |
| 154 | - | RequestID uint64 | |
| 155 | - | Status ParkedRouteStatus | |
| 156 | - | } | |
| 157 | - | ||
| 158 | - | // RemotePreviewSchemaVersion is independent from the attachment IPC version. | |
| 159 | - | const RemotePreviewSchemaVersion uint16 = 1 | |
| 160 | - | ||
| 161 | - | // RemotePreviewStatus is a closed response taxonomy. Terminal contents are | |
| 162 | - | // never carried in an error response. | |
| 163 | - | type RemotePreviewStatus uint8 | |
| 164 | - | ||
| 165 | - | const ( | |
| 166 | - | RemotePreviewOK RemotePreviewStatus = iota | |
| 167 | - | RemotePreviewUnavailable | |
| 168 | - | RemotePreviewNoSuchTarget | |
| 169 | - | RemotePreviewStale | |
| 170 | - | RemotePreviewMalformed | |
| 171 | - | RemotePreviewTooLarge | |
| 172 | - | ) | |
| 173 | - | ||
| 174 | - | // RemotePreviewRequest asks the owning daemon for an in-memory live viewport. | |
| 175 | - | type RemotePreviewRequest struct { | |
| 176 | - | Version uint16 | |
| 177 | - | Target domain.RemoteSessionTarget | |
| 178 | - | Width uint16 | |
| 179 | - | Height uint16 | |
| 180 | - | } | |
| 181 | - | ||
| 182 | - | // RemotePreview is a bounded row-major styled-cell viewport. It is a | |
| 183 | - | // process-memory DTO and is never persisted, logged, or traced. | |
| 184 | - | type RemotePreview struct { | |
| 185 | - | Version uint16 | |
| 186 | - | Status RemotePreviewStatus | |
| 187 | - | LifecycleID domain.SessionLifecycleID | |
| 188 | - | TabID domain.TabStableID | |
| 189 | - | Revision uint64 | |
| 190 | - | Width uint16 | |
| 191 | - | Height uint16 | |
| 192 | - | Cells []renderer.Cell | |
| 193 | - | } | |
M internal/ports/frame_test.go +3 -1
| @@ -1,6 +1,8 @@ | |||
| 1 | 1 | package ports | |
| 2 | 2 | ||
| 3 | - | import "testing" | |
| 3 | + | import ( | |
| 4 | + | "testing" | |
| 5 | + | ) | |
| 4 | 6 | ||
| 5 | 7 | func TestProtocolVersion(t *testing.T) { | |
| 6 | 8 | if ProtocolVersion != 37 { | |
M internal/ports/mocks/remote_mock.go +8 -7
| @@ -10,6 +10,7 @@ import ( | |||
| 10 | 10 | ||
| 11 | 11 | "github.com/bnema/vev/internal/domain" | |
| 12 | 12 | "github.com/bnema/vev/internal/ports" | |
| 13 | + | "github.com/bnema/vev/internal/protocol" | |
| 13 | 14 | mock "github.com/stretchr/testify/mock" | |
| 14 | 15 | ) | |
| 15 | 16 | ||
| @@ -666,22 +667,22 @@ func (_m *MockRemotePreviewClient) EXPECT() *MockRemotePreviewClient_Expecter { | |||
| 666 | 667 | } | |
| 667 | 668 | ||
| 668 | 669 | // Preview provides a mock function for the type MockRemotePreviewClient | |
| 669 | - | func (_mock *MockRemotePreviewClient) Preview(ctx context.Context, target domain.RemoteSessionTarget, width uint16, height uint16) (ports.RemotePreview, error) { | |
| 670 | + | func (_mock *MockRemotePreviewClient) Preview(ctx context.Context, target domain.RemoteSessionTarget, width uint16, height uint16) (protocol.RemotePreview, error) { | |
| 670 | 671 | ret := _mock.Called(ctx, target, width, height) | |
| 671 | 672 | ||
| 672 | 673 | if len(ret) == 0 { | |
| 673 | 674 | panic("no return value specified for Preview") | |
| 674 | 675 | } | |
| 675 | 676 | ||
| 676 | - | var r0 ports.RemotePreview | |
| 677 | + | var r0 protocol.RemotePreview | |
| 677 | 678 | var r1 error | |
| 678 | - | if returnFunc, ok := ret.Get(0).(func(context.Context, domain.RemoteSessionTarget, uint16, uint16) (ports.RemotePreview, error)); ok { | |
| 679 | + | if returnFunc, ok := ret.Get(0).(func(context.Context, domain.RemoteSessionTarget, uint16, uint16) (protocol.RemotePreview, error)); ok { | |
| 679 | 680 | return returnFunc(ctx, target, width, height) | |
| 680 | 681 | } | |
| 681 | - | if returnFunc, ok := ret.Get(0).(func(context.Context, domain.RemoteSessionTarget, uint16, uint16) ports.RemotePreview); ok { | |
| 682 | + | if returnFunc, ok := ret.Get(0).(func(context.Context, domain.RemoteSessionTarget, uint16, uint16) protocol.RemotePreview); ok { | |
| 682 | 683 | r0 = returnFunc(ctx, target, width, height) | |
| 683 | 684 | } else { | |
| 684 | - | r0 = ret.Get(0).(ports.RemotePreview) | |
| 685 | + | r0 = ret.Get(0).(protocol.RemotePreview) | |
| 685 | 686 | } | |
| 686 | 687 | if returnFunc, ok := ret.Get(1).(func(context.Context, domain.RemoteSessionTarget, uint16, uint16) error); ok { | |
| 687 | 688 | r1 = returnFunc(ctx, target, width, height) | |
| @@ -733,12 +734,12 @@ func (_c *MockRemotePreviewClient_Preview_Call) Run(run func(ctx context.Context | |||
| 733 | 734 | return _c | |
| 734 | 735 | } | |
| 735 | 736 | ||
| 736 | - | func (_c *MockRemotePreviewClient_Preview_Call) Return(remotePreview ports.RemotePreview, err error) *MockRemotePreviewClient_Preview_Call { | |
| 737 | + | func (_c *MockRemotePreviewClient_Preview_Call) Return(remotePreview protocol.RemotePreview, err error) *MockRemotePreviewClient_Preview_Call { | |
| 737 | 738 | _c.Call.Return(remotePreview, err) | |
| 738 | 739 | return _c | |
| 739 | 740 | } | |
| 740 | 741 | ||
| 741 | - | func (_c *MockRemotePreviewClient_Preview_Call) RunAndReturn(run func(ctx context.Context, target domain.RemoteSessionTarget, width uint16, height uint16) (ports.RemotePreview, error)) *MockRemotePreviewClient_Preview_Call { | |
| 742 | + | func (_c *MockRemotePreviewClient_Preview_Call) RunAndReturn(run func(ctx context.Context, target domain.RemoteSessionTarget, width uint16, height uint16) (protocol.RemotePreview, error)) *MockRemotePreviewClient_Preview_Call { | |
| 742 | 743 | _c.Call.Return(run) | |
| 743 | 744 | return _c | |
| 744 | 745 | } | |
M internal/ports/navigation_test.go +45 -44
| @@ -5,22 +5,23 @@ import ( | |||
| 5 | 5 | "testing" | |
| 6 | 6 | ||
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 9 | "github.com/stretchr/testify/require" | |
| 9 | 10 | ) | |
| 10 | 11 | ||
| 11 | 12 | func TestNavigationDirectiveWireTable(t *testing.T) { | |
| 12 | - | lease := ParkedRouteLeaseID{1, 2, 3} | |
| 13 | + | lease := protocol.ParkedRouteLeaseID{1, 2, 3} | |
| 13 | 14 | tests := []struct { | |
| 14 | 15 | name string | |
| 15 | - | directive NavigationDirective | |
| 16 | + | directive protocol.NavigationDirective | |
| 16 | 17 | valid bool | |
| 17 | 18 | }{ | |
| 18 | - | {name: "open home", directive: NavigationDirective{Action: NavigationOpenHomePicker, LeaseID: lease}, valid: true}, | |
| 19 | - | {name: "back", directive: NavigationDirective{Action: NavigationBack}, valid: true}, | |
| 20 | - | {name: "open home without lease", directive: NavigationDirective{Action: NavigationOpenHomePicker}}, | |
| 21 | - | {name: "back with lease", directive: NavigationDirective{Action: NavigationBack, LeaseID: lease}}, | |
| 22 | - | {name: "zero", directive: NavigationDirective{}}, | |
| 23 | - | {name: "unknown", directive: NavigationDirective{Action: 3}}, | |
| 19 | + | {name: "open home", directive: protocol.NavigationDirective{Action: protocol.NavigationOpenHomePicker, LeaseID: lease}, valid: true}, | |
| 20 | + | {name: "back", directive: protocol.NavigationDirective{Action: protocol.NavigationBack}, valid: true}, | |
| 21 | + | {name: "open home without lease", directive: protocol.NavigationDirective{Action: protocol.NavigationOpenHomePicker}}, | |
| 22 | + | {name: "back with lease", directive: protocol.NavigationDirective{Action: protocol.NavigationBack, LeaseID: lease}}, | |
| 23 | + | {name: "zero", directive: protocol.NavigationDirective{}}, | |
| 24 | + | {name: "unknown", directive: protocol.NavigationDirective{Action: 3}}, | |
| 24 | 25 | } | |
| 25 | 26 | ||
| 26 | 27 | for _, tt := range tests { | |
| @@ -35,25 +36,25 @@ func TestNavigationDirectiveWireTable(t *testing.T) { | |||
| 35 | 36 | require.Equal(t, tt.directive, decoded) | |
| 36 | 37 | assertAllPrefixesFail(t, got, UnmarshalNavigationDirective) | |
| 37 | 38 | _, err = UnmarshalNavigationDirective(append(append([]byte(nil), got...), 0)) | |
| 38 | - | require.ErrorIs(t, err, ErrInvalidNavigation) | |
| 39 | + | require.ErrorIs(t, err, protocol.ErrInvalidNavigation) | |
| 39 | 40 | }) | |
| 40 | 41 | } | |
| 41 | 42 | } | |
| 42 | 43 | ||
| 43 | 44 | func TestParkedRouteWireRoundTripsStrictly(t *testing.T) { | |
| 44 | - | lease := ParkedRouteLeaseID{1, 2, 3} | |
| 45 | + | lease := protocol.ParkedRouteLeaseID{1, 2, 3} | |
| 45 | 46 | target := &domain.RemoteSessionTarget{ | |
| 46 | 47 | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: domain.SessionLifecycleID{4}, | |
| 47 | 48 | SessionName: "work", LiveTabID: "tab-1", | |
| 48 | 49 | } | |
| 49 | 50 | requests := []struct { | |
| 50 | 51 | name string | |
| 51 | - | value ParkedRouteRequest | |
| 52 | + | value protocol.ParkedRouteRequest | |
| 52 | 53 | golden string | |
| 53 | 54 | }{ | |
| 54 | - | {name: "prepare", value: ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: ParkedRoutePrepare}, golden: "0000000000000001" + "01020300000000000000000000000000" + "010001"}, | |
| 55 | - | {name: "resume", value: ParkedRouteRequest{RequestID: 2, LeaseID: lease, Action: ParkedRouteResume}}, | |
| 56 | - | {name: "switch", value: ParkedRouteRequest{RequestID: 3, LeaseID: lease, Action: ParkedRouteSwitch, Target: target}}, | |
| 55 | + | {name: "prepare", value: protocol.ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: protocol.ParkedRoutePrepare}, golden: "0000000000000001" + "01020300000000000000000000000000" + "010001"}, | |
| 56 | + | {name: "resume", value: protocol.ParkedRouteRequest{RequestID: 2, LeaseID: lease, Action: protocol.ParkedRouteResume}}, | |
| 57 | + | {name: "switch", value: protocol.ParkedRouteRequest{RequestID: 3, LeaseID: lease, Action: protocol.ParkedRouteSwitch, Target: target}}, | |
| 57 | 58 | } | |
| 58 | 59 | for _, tt := range requests { | |
| 59 | 60 | t.Run("request "+tt.name, func(t *testing.T) { | |
| @@ -74,15 +75,15 @@ func TestParkedRouteWireRoundTripsStrictly(t *testing.T) { | |||
| 74 | 75 | ||
| 75 | 76 | responses := []struct { | |
| 76 | 77 | name string | |
| 77 | - | value ParkedRouteResponse | |
| 78 | + | value protocol.ParkedRouteResponse | |
| 78 | 79 | golden string | |
| 79 | 80 | }{ | |
| 80 | - | {name: "ready", value: ParkedRouteResponse{RequestID: 1, Status: ParkedRouteReady}, golden: "000000000000000101"}, | |
| 81 | - | {name: "resumed", value: ParkedRouteResponse{RequestID: 2, Status: ParkedRouteResumed}}, | |
| 82 | - | {name: "switched", value: ParkedRouteResponse{RequestID: 3, Status: ParkedRouteSwitched}}, | |
| 83 | - | {name: "rejected", value: ParkedRouteResponse{RequestID: 4, Status: ParkedRouteRejected}}, | |
| 84 | - | {name: "expired", value: ParkedRouteResponse{RequestID: 5, Status: ParkedRouteExpired}}, | |
| 85 | - | {name: "stale target", value: ParkedRouteResponse{RequestID: 6, Status: ParkedRouteStaleTarget}}, | |
| 81 | + | {name: "ready", value: protocol.ParkedRouteResponse{RequestID: 1, Status: protocol.ParkedRouteReady}, golden: "000000000000000101"}, | |
| 82 | + | {name: "resumed", value: protocol.ParkedRouteResponse{RequestID: 2, Status: protocol.ParkedRouteResumed}}, | |
| 83 | + | {name: "switched", value: protocol.ParkedRouteResponse{RequestID: 3, Status: protocol.ParkedRouteSwitched}}, | |
| 84 | + | {name: "rejected", value: protocol.ParkedRouteResponse{RequestID: 4, Status: protocol.ParkedRouteRejected}}, | |
| 85 | + | {name: "expired", value: protocol.ParkedRouteResponse{RequestID: 5, Status: protocol.ParkedRouteExpired}}, | |
| 86 | + | {name: "stale target", value: protocol.ParkedRouteResponse{RequestID: 6, Status: protocol.ParkedRouteStaleTarget}}, | |
| 86 | 87 | } | |
| 87 | 88 | for _, tt := range responses { | |
| 88 | 89 | t.Run("response "+tt.name, func(t *testing.T) { | |
| @@ -102,15 +103,15 @@ func TestParkedRouteWireRoundTripsStrictly(t *testing.T) { | |||
| 102 | 103 | ||
| 103 | 104 | invalidRequests := []struct { | |
| 104 | 105 | name string | |
| 105 | - | value ParkedRouteRequest | |
| 106 | + | value protocol.ParkedRouteRequest | |
| 106 | 107 | }{ | |
| 107 | - | {name: "zero request ID", value: ParkedRouteRequest{LeaseID: lease, Action: ParkedRoutePrepare}}, | |
| 108 | - | {name: "zero lease", value: ParkedRouteRequest{RequestID: 1, Action: ParkedRoutePrepare}}, | |
| 109 | - | {name: "unknown action", value: ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: 99}}, | |
| 110 | - | {name: "prepare target", value: ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: ParkedRoutePrepare, Target: target}}, | |
| 111 | - | {name: "resume target", value: ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: ParkedRouteResume, Target: target}}, | |
| 112 | - | {name: "missing switch target", value: ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: ParkedRouteSwitch}}, | |
| 113 | - | {name: "invalid switch target", value: ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: ParkedRouteSwitch, Target: &domain.RemoteSessionTarget{}}}, | |
| 108 | + | {name: "zero request ID", value: protocol.ParkedRouteRequest{LeaseID: lease, Action: protocol.ParkedRoutePrepare}}, | |
| 109 | + | {name: "zero lease", value: protocol.ParkedRouteRequest{RequestID: 1, Action: protocol.ParkedRoutePrepare}}, | |
| 110 | + | {name: "unknown action", value: protocol.ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: 99}}, | |
| 111 | + | {name: "prepare target", value: protocol.ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: protocol.ParkedRoutePrepare, Target: target}}, | |
| 112 | + | {name: "resume target", value: protocol.ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: protocol.ParkedRouteResume, Target: target}}, | |
| 113 | + | {name: "missing switch target", value: protocol.ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: protocol.ParkedRouteSwitch}}, | |
| 114 | + | {name: "invalid switch target", value: protocol.ParkedRouteRequest{RequestID: 1, LeaseID: lease, Action: protocol.ParkedRouteSwitch, Target: &domain.RemoteSessionTarget{}}}, | |
| 114 | 115 | } | |
| 115 | 116 | for _, tt := range invalidRequests { | |
| 116 | 117 | t.Run("invalid request "+tt.name, func(t *testing.T) { | |
| @@ -119,11 +120,11 @@ func TestParkedRouteWireRoundTripsStrictly(t *testing.T) { | |||
| 119 | 120 | } | |
| 120 | 121 | for _, tt := range []struct { | |
| 121 | 122 | name string | |
| 122 | - | value ParkedRouteResponse | |
| 123 | + | value protocol.ParkedRouteResponse | |
| 123 | 124 | }{ | |
| 124 | - | {name: "zero request ID", value: ParkedRouteResponse{Status: ParkedRouteReady}}, | |
| 125 | - | {name: "zero status", value: ParkedRouteResponse{RequestID: 1}}, | |
| 126 | - | {name: "unknown status", value: ParkedRouteResponse{RequestID: 1, Status: 99}}, | |
| 125 | + | {name: "zero request ID", value: protocol.ParkedRouteResponse{Status: protocol.ParkedRouteReady}}, | |
| 126 | + | {name: "zero status", value: protocol.ParkedRouteResponse{RequestID: 1}}, | |
| 127 | + | {name: "unknown status", value: protocol.ParkedRouteResponse{RequestID: 1, Status: 99}}, | |
| 127 | 128 | } { | |
| 128 | 129 | t.Run("invalid response "+tt.name, func(t *testing.T) { | |
| 129 | 130 | require.Nil(t, MarshalParkedRouteResponse(tt.value)) | |
| @@ -141,22 +142,22 @@ func TestHelloNavigationValidationTable(t *testing.T) { | |||
| 141 | 142 | name string | |
| 142 | 143 | hello Hello | |
| 143 | 144 | valid bool | |
| 144 | - | capability NavigationCapabilities | |
| 145 | - | overlay StartupOverlay | |
| 145 | + | capability protocol.NavigationCapabilities | |
| 146 | + | overlay protocol.StartupOverlay | |
| 146 | 147 | wantPayload string | |
| 147 | 148 | }{ | |
| 148 | 149 | {name: "ordinary", hello: base, valid: true}, | |
| 149 | 150 | {name: "resume route", hello: Hello{Version: ProtocolVersion, Intent: IntentResume, Size: domain.Size{Cols: 80, Rows: 24}}, valid: true}, | |
| 150 | - | {name: "daemon-owned home picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: NavigationCapabilityHomePicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: true, capability: NavigationCapabilityHomePicker}, | |
| 151 | - | {name: "remote-target home picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Name: "work", Size: domain.Size{Cols: 80, Rows: 24}, RemoteTarget: remoteTarget, NavigationCapabilities: NavigationCapabilityHomePicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: true, capability: NavigationCapabilityHomePicker}, | |
| 152 | - | {name: "client-owned home picker rejected", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: NavigationCapabilityHomePicker}, valid: false}, | |
| 153 | - | {name: "daemon-owned back picker rejected", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: NavigationCapabilityBack, StartupOverlay: StartupOverlaySessionPicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: false}, | |
| 154 | - | {name: "remote-target back picker rejected", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Name: "work", Size: domain.Size{Cols: 80, Rows: 24}, RemoteTarget: remoteTarget, NavigationCapabilities: NavigationCapabilityBack, StartupOverlay: StartupOverlaySessionPicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: false}, | |
| 155 | - | {name: "back with startup picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: NavigationCapabilityBack, StartupOverlay: StartupOverlaySessionPicker}, valid: true, capability: NavigationCapabilityBack, overlay: StartupOverlaySessionPicker, wantPayload: "002502" + "00000000000000000000000000000000" + "0000000000000000" + "0000" + "00500018" + "00000000" + "0000" + "0000" + "00" + "00" + "00000000" + "00" + "00" + "00" + "0000" + "02010000"}, | |
| 156 | - | {name: "new rejects navigation", hello: Hello{Version: ProtocolVersion, Intent: IntentNew, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: NavigationCapabilityBack, StartupOverlay: StartupOverlaySessionPicker}, valid: false}, | |
| 151 | + | {name: "daemon-owned home picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: protocol.NavigationCapabilityHomePicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: true, capability: protocol.NavigationCapabilityHomePicker}, | |
| 152 | + | {name: "remote-target home picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Name: "work", Size: domain.Size{Cols: 80, Rows: 24}, RemoteTarget: remoteTarget, NavigationCapabilities: protocol.NavigationCapabilityHomePicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: true, capability: protocol.NavigationCapabilityHomePicker}, | |
| 153 | + | {name: "client-owned home picker rejected", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: protocol.NavigationCapabilityHomePicker}, valid: false}, | |
| 154 | + | {name: "daemon-owned back picker rejected", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: protocol.NavigationCapabilityBack, StartupOverlay: protocol.StartupOverlaySessionPicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: false}, | |
| 155 | + | {name: "remote-target back picker rejected", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Name: "work", Size: domain.Size{Cols: 80, Rows: 24}, RemoteTarget: remoteTarget, NavigationCapabilities: protocol.NavigationCapabilityBack, StartupOverlay: protocol.StartupOverlaySessionPicker, EnvironmentPolicy: EnvironmentPolicyDaemonOwned}, valid: false}, | |
| 156 | + | {name: "back with startup picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: protocol.NavigationCapabilityBack, StartupOverlay: protocol.StartupOverlaySessionPicker}, valid: true, capability: protocol.NavigationCapabilityBack, overlay: protocol.StartupOverlaySessionPicker, wantPayload: "002502" + "00000000000000000000000000000000" + "0000000000000000" + "0000" + "00500018" + "00000000" + "0000" + "0000" + "00" + "00" + "00000000" + "00" + "00" + "00" + "0000" + "02010000"}, | |
| 157 | + | {name: "new rejects navigation", hello: Hello{Version: ProtocolVersion, Intent: IntentNew, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: protocol.NavigationCapabilityBack, StartupOverlay: protocol.StartupOverlaySessionPicker}, valid: false}, | |
| 157 | 158 | {name: "unknown capability", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: 4}, valid: false}, | |
| 158 | - | {name: "back without picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: NavigationCapabilityBack}, valid: false}, | |
| 159 | - | {name: "picker without back", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, StartupOverlay: StartupOverlaySessionPicker}, valid: false}, | |
| 159 | + | {name: "back without picker", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, NavigationCapabilities: protocol.NavigationCapabilityBack}, valid: false}, | |
| 160 | + | {name: "picker without back", hello: Hello{Version: ProtocolVersion, Intent: IntentAttach, Size: domain.Size{Cols: 80, Rows: 24}, StartupOverlay: protocol.StartupOverlaySessionPicker}, valid: false}, | |
| 160 | 161 | } | |
| 161 | 162 | ||
| 162 | 163 | for _, tt := range tests { | |
M internal/ports/output_compression_test.go +6 -5
| @@ -6,10 +6,11 @@ import ( | |||
| 6 | 6 | "testing" | |
| 7 | 7 | ||
| 8 | 8 | "github.com/bnema/vev/internal/domain" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | ) | |
| 10 | 11 | ||
| 11 | 12 | func TestOutputCompression(t *testing.T) { | |
| 12 | - | full := Output{ | |
| 13 | + | full := protocol.Output{ | |
| 13 | 14 | Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 120, Rows: 40}, Full: true, | |
| 14 | 15 | Data: bytes.Repeat([]byte("\x1b[38;2;120;180;240mstyled viewport row\x1b[0m\r\n"), 128), | |
| 15 | 16 | } | |
| @@ -20,12 +21,12 @@ func TestOutputCompression(t *testing.T) { | |||
| 20 | 21 | ||
| 21 | 22 | for _, tt := range []struct { | |
| 22 | 23 | name string | |
| 23 | - | output Output | |
| 24 | + | output protocol.Output | |
| 24 | 25 | wantKind byte | |
| 25 | 26 | }{ | |
| 26 | 27 | {name: "large full snapshot", output: full, wantKind: outputCompressionZlib}, | |
| 27 | 28 | {name: "incremental output", output: incremental, wantKind: outputCompressionNone}, | |
| 28 | - | {name: "small full snapshot", output: Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("small")}, wantKind: outputCompressionNone}, | |
| 29 | + | {name: "small full snapshot", output: protocol.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("small")}, wantKind: outputCompressionNone}, | |
| 29 | 30 | } { | |
| 30 | 31 | t.Run(tt.name, func(t *testing.T) { | |
| 31 | 32 | payload, err := MarshalOutput(tt.output) | |
| @@ -47,7 +48,7 @@ func TestOutputCompression(t *testing.T) { | |||
| 47 | 48 | } | |
| 48 | 49 | ||
| 49 | 50 | func TestCompressedOutputRejectsMalformedPayloads(t *testing.T) { | |
| 50 | - | output := Output{ | |
| 51 | + | output := protocol.Output{ | |
| 51 | 52 | Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 120, Rows: 40}, Full: true, | |
| 52 | 53 | Data: bytes.Repeat([]byte("\x1b[31mcompressed\x1b[0m\r\n"), 256), | |
| 53 | 54 | } | |
| @@ -92,7 +93,7 @@ func TestCompressedOutputRejectsMalformedPayloads(t *testing.T) { | |||
| 92 | 93 | } | |
| 93 | 94 | ||
| 94 | 95 | func BenchmarkMarshalOutput(b *testing.B) { | |
| 95 | - | fixtures := map[string]Output{ | |
| 96 | + | fixtures := map[string]protocol.Output{ | |
| 96 | 97 | "empty-120x40": { | |
| 97 | 98 | Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 120, Rows: 40}, Full: true, | |
| 98 | 99 | Data: bytes.Repeat([]byte(" "), 120*40), | |
M internal/ports/remote.go +2 -1
| @@ -12,6 +12,7 @@ import ( | |||
| 12 | 12 | "unicode/utf8" | |
| 13 | 13 | ||
| 14 | 14 | "github.com/bnema/vev/internal/domain" | |
| 15 | + | "github.com/bnema/vev/internal/protocol" | |
| 15 | 16 | ) | |
| 16 | 17 | ||
| 17 | 18 | // RemoteTransportMode selects the transport used for remote attach after CLI parsing. | |
| @@ -57,7 +58,7 @@ type RemoteCatalogClient interface { | |||
| 57 | 58 | // RemotePreviewClient fetches one bounded, exact-target viewport without | |
| 58 | 59 | // attaching to or mutating the remote session. | |
| 59 | 60 | type RemotePreviewClient interface { | |
| 60 | - | Preview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (RemotePreview, error) | |
| 61 | + | Preview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (protocol.RemotePreview, error) | |
| 61 | 62 | } | |
| 62 | 63 | ||
| 63 | 64 | const ( | |
M internal/ports/remote_preview_hardening_test.go +15 -14
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | renderer "github.com/bnema/vev-vt" | |
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | ) | |
| 12 | 13 | ||
| 13 | 14 | const ( | |
| @@ -42,8 +43,8 @@ func TestRemotePreviewCodecGoldenRoundTrip(t *testing.T) { | |||
| 42 | 43 | if err != nil { | |
| 43 | 44 | t.Fatalf("UnmarshalRemotePreview() error = %v", err) | |
| 44 | 45 | } | |
| 45 | - | if got.Version != RemotePreviewSchemaVersion || got.Status != RemotePreviewOK { | |
| 46 | - | t.Fatalf("header = (%d, %d), want (%d, %d)", got.Version, got.Status, RemotePreviewSchemaVersion, RemotePreviewOK) | |
| 46 | + | if got.Version != protocol.RemotePreviewSchemaVersion || got.Status != protocol.RemotePreviewOK { | |
| 47 | + | t.Fatalf("header = (%d, %d), want (%d, %d)", got.Version, got.Status, protocol.RemotePreviewSchemaVersion, protocol.RemotePreviewOK) | |
| 47 | 48 | } | |
| 48 | 49 | var wantLifecycle domain.SessionLifecycleID | |
| 49 | 50 | for i := range wantLifecycle { | |
| @@ -86,19 +87,19 @@ func TestRemotePreviewCodecRejectsInvalidStatusFlagsAndRanges(t *testing.T) { | |||
| 86 | 87 | func TestRemotePreviewCodecRejectsWideCellBoundaryAndInvalidIDs(t *testing.T) { | |
| 87 | 88 | var lifecycle domain.SessionLifecycleID | |
| 88 | 89 | lifecycle[0] = 1 | |
| 89 | - | valid := RemotePreview{ | |
| 90 | - | Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, | |
| 90 | + | valid := protocol.RemotePreview{ | |
| 91 | + | Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, | |
| 91 | 92 | LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 2, Height: 1, | |
| 92 | 93 | Cells: []renderer.Cell{{Rune: '界'}, {Continuation: true}}, | |
| 93 | 94 | } | |
| 94 | 95 | if MarshalRemotePreview(valid) == nil { | |
| 95 | 96 | t.Fatal("valid wide-cell preview did not marshal") | |
| 96 | 97 | } | |
| 97 | - | for _, malformed := range []RemotePreview{ | |
| 98 | - | {Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 1, Height: 1, Cells: []renderer.Cell{{Rune: '界'}}}, | |
| 99 | - | {Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 2, Height: 1, Cells: []renderer.Cell{{Continuation: true}, {Rune: 'x'}}}, | |
| 100 | - | {Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 2, Height: 1, Cells: []renderer.Cell{{Rune: '界'}, {Continuation: true, Rune: 'x'}}}, | |
| 101 | - | {Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 2, Height: 2, Cells: []renderer.Cell{{Rune: 'x'}, {Rune: '界'}, {Continuation: true}, {Rune: 'y'}}}, | |
| 98 | + | for _, malformed := range []protocol.RemotePreview{ | |
| 99 | + | {Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 1, Height: 1, Cells: []renderer.Cell{{Rune: '界'}}}, | |
| 100 | + | {Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 2, Height: 1, Cells: []renderer.Cell{{Continuation: true}, {Rune: 'x'}}}, | |
| 101 | + | {Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 2, Height: 1, Cells: []renderer.Cell{{Rune: '界'}, {Continuation: true, Rune: 'x'}}}, | |
| 102 | + | {Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, LifecycleID: lifecycle, TabID: "tab-1", Revision: 1, Width: 2, Height: 2, Cells: []renderer.Cell{{Rune: 'x'}, {Rune: '界'}, {Continuation: true}, {Rune: 'y'}}}, | |
| 102 | 103 | } { | |
| 103 | 104 | if MarshalRemotePreview(malformed) != nil { | |
| 104 | 105 | t.Fatalf("malformed wide-cell preview marshaled: %#v", malformed.Cells) | |
| @@ -117,16 +118,16 @@ func TestRemotePreviewCodecRejectsWideCellBoundaryAndInvalidIDs(t *testing.T) { | |||
| 117 | 118 | } | |
| 118 | 119 | ||
| 119 | 120 | func TestRemotePreviewRejectsControlRunes(t *testing.T) { | |
| 120 | - | valid := RemotePreview{ | |
| 121 | - | Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, | |
| 121 | + | valid := protocol.RemotePreview{ | |
| 122 | + | Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, | |
| 122 | 123 | LifecycleID: previewTargetForTest().LifecycleID, TabID: "tab-1", Revision: 1, Width: 1, Height: 1, | |
| 123 | 124 | Cells: []renderer.Cell{{Rune: 'x'}}, | |
| 124 | 125 | } | |
| 125 | 126 | for _, control := range []rune{'\x01', '\x1b', '\x7f', '\u0085'} { | |
| 126 | 127 | preview := valid | |
| 127 | 128 | preview.Cells = []renderer.Cell{{Rune: control}} | |
| 128 | - | if err := ValidateRemotePreview(preview); err != ErrInvalidRemotePreview { | |
| 129 | - | t.Fatalf("control rune %U: ValidateRemotePreview() error = %v, want %v", control, err, ErrInvalidRemotePreview) | |
| 129 | + | if err := protocol.ValidateRemotePreview(preview); err != protocol.ErrInvalidRemotePreview { | |
| 130 | + | t.Fatalf("control rune %U: ValidateRemotePreview() error = %v, want %v", control, err, protocol.ErrInvalidRemotePreview) | |
| 130 | 131 | } | |
| 131 | 132 | if MarshalRemotePreview(preview) != nil { | |
| 132 | 133 | t.Fatalf("control rune %U was marshaled", control) | |
| @@ -137,7 +138,7 @@ func TestRemotePreviewRejectsControlRunes(t *testing.T) { | |||
| 137 | 138 | func TestRemotePreviewRequestRejectsOversizedNestedRouteData(t *testing.T) { | |
| 138 | 139 | target := previewTargetForTest() | |
| 139 | 140 | target.Endpoint = strings.Repeat("h", math.MaxUint16+1) | |
| 140 | - | request := RemotePreviewRequest{Version: RemotePreviewSchemaVersion, Target: target, Width: 20, Height: 5} | |
| 141 | + | request := protocol.RemotePreviewRequest{Version: protocol.RemotePreviewSchemaVersion, Target: target, Width: 20, Height: 5} | |
| 141 | 142 | if MarshalRemotePreviewRequest(request) != nil { | |
| 142 | 143 | t.Fatal("oversized endpoint was truncated and marshaled") | |
| 143 | 144 | } | |
M internal/ports/remote_preview_test.go +7 -6
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | 5 | ||
| 6 | 6 | renderer "github.com/bnema/vev-vt" | |
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 9 | ) | |
| 9 | 10 | ||
| 10 | 11 | func previewTargetForTest() domain.RemoteSessionTarget { | |
| @@ -19,8 +20,8 @@ func TestRemotePreviewCodecPreservesWideStyledCells(t *testing.T) { | |||
| 19 | 20 | style.Attrs = renderer.AttrUnderline | |
| 20 | 21 | style.HasForegroundRGB = true | |
| 21 | 22 | style.ForegroundRGB = renderer.RGB{R: 1, G: 2, B: 3} | |
| 22 | - | preview := RemotePreview{ | |
| 23 | - | Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, | |
| 23 | + | preview := protocol.RemotePreview{ | |
| 24 | + | Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, | |
| 24 | 25 | LifecycleID: previewTargetForTest().LifecycleID, TabID: "tab-1", Revision: 4, Width: 3, Height: 1, | |
| 25 | 26 | Cells: []renderer.Cell{{Rune: '界', Style: style}, {Continuation: true, Style: style}, {Rune: 'x', Style: style}}, | |
| 26 | 27 | } | |
| @@ -38,7 +39,7 @@ func TestRemotePreviewCodecPreservesWideStyledCells(t *testing.T) { | |||
| 38 | 39 | } | |
| 39 | 40 | ||
| 40 | 41 | func TestRemotePreviewCodecRejectsMalformedBoundsAndGarbage(t *testing.T) { | |
| 41 | - | preview := RemotePreview{Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, LifecycleID: previewTargetForTest().LifecycleID, TabID: "tab-1", Revision: 1, Width: 1, Height: 1, Cells: []renderer.Cell{{Rune: 'x'}}} | |
| 42 | + | preview := protocol.RemotePreview{Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, LifecycleID: previewTargetForTest().LifecycleID, TabID: "tab-1", Revision: 1, Width: 1, Height: 1, Cells: []renderer.Cell{{Rune: 'x'}}} | |
| 42 | 43 | payload := MarshalRemotePreview(preview) | |
| 43 | 44 | for i := 0; i < len(payload); i++ { | |
| 44 | 45 | if _, err := UnmarshalRemotePreview(payload[:i]); err == nil { | |
| @@ -49,7 +50,7 @@ func TestRemotePreviewCodecRejectsMalformedBoundsAndGarbage(t *testing.T) { | |||
| 49 | 50 | t.Fatal("trailing garbage unexpectedly decoded") | |
| 50 | 51 | } | |
| 51 | 52 | bad := preview | |
| 52 | - | bad.Width = RemotePreviewMaxWidth + 1 | |
| 53 | + | bad.Width = protocol.RemotePreviewMaxWidth + 1 | |
| 53 | 54 | if MarshalRemotePreview(bad) != nil { | |
| 54 | 55 | t.Fatal("oversized preview marshaled") | |
| 55 | 56 | } | |
| @@ -57,14 +58,14 @@ func TestRemotePreviewCodecRejectsMalformedBoundsAndGarbage(t *testing.T) { | |||
| 57 | 58 | ||
| 58 | 59 | func TestRemotePreviewRequestRejectsStoppedAndInvalidTargets(t *testing.T) { | |
| 59 | 60 | target := previewTargetForTest() | |
| 60 | - | request := RemotePreviewRequest{Version: RemotePreviewSchemaVersion, Target: target, Width: 20, Height: 5} | |
| 61 | + | request := protocol.RemotePreviewRequest{Version: protocol.RemotePreviewSchemaVersion, Target: target, Width: 20, Height: 5} | |
| 61 | 62 | if MarshalRemotePreviewRequest(request) == nil { | |
| 62 | 63 | t.Fatal("valid preview request did not marshal") | |
| 63 | 64 | } | |
| 64 | 65 | target.Stopped = true | |
| 65 | 66 | target.LiveTabID = "" | |
| 66 | 67 | target.StoppedTab = domain.NewOrdinalTabSelector(0, "", 1) | |
| 67 | - | if MarshalRemotePreviewRequest(RemotePreviewRequest{Version: RemotePreviewSchemaVersion, Target: target, Width: 20, Height: 5}) != nil { | |
| 68 | + | if MarshalRemotePreviewRequest(protocol.RemotePreviewRequest{Version: protocol.RemotePreviewSchemaVersion, Target: target, Width: 20, Height: 5}) != nil { | |
| 68 | 69 | t.Fatal("stopped preview request marshaled") | |
| 69 | 70 | } | |
| 70 | 71 | } | |
M internal/ports/routes_test.go +52 -46
| @@ -6,11 +6,12 @@ import ( | |||
| 6 | 6 | "testing" | |
| 7 | 7 | ||
| 8 | 8 | "github.com/bnema/vev/internal/domain" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | "github.com/stretchr/testify/require" | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| 12 | - | func testExactTarget() ExactSessionTarget { | |
| 13 | - | return ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1, 2, 3}, SessionName: "work"} | |
| 13 | + | func testExactTarget() protocol.ExactSessionTarget { | |
| 14 | + | return protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1, 2, 3}, SessionName: "work"} | |
| 14 | 15 | } | |
| 15 | 16 | ||
| 16 | 17 | func TestExactSessionTargetCodecIsStrict(t *testing.T) { | |
| @@ -26,8 +27,8 @@ func TestExactSessionTargetCodecIsStrict(t *testing.T) { | |||
| 26 | 27 | require.NoError(t, err) | |
| 27 | 28 | require.Equal(t, want, got) | |
| 28 | 29 | ||
| 29 | - | _, err = MarshalExactSessionTarget(ExactSessionTarget{SessionName: "work"}) | |
| 30 | - | require.ErrorIs(t, err, ErrInvalidRouteWire) | |
| 30 | + | _, err = MarshalExactSessionTarget(protocol.ExactSessionTarget{SessionName: "work"}) | |
| 31 | + | require.ErrorIs(t, err, protocol.ErrInvalidRouteWire) | |
| 31 | 32 | } | |
| 32 | 33 | ||
| 33 | 34 | func TestHelloExactTargetRoundTrip(t *testing.T) { | |
| @@ -57,7 +58,7 @@ func TestHelloExactTargetRoundTrip(t *testing.T) { | |||
| 57 | 58 | } | |
| 58 | 59 | ||
| 59 | 60 | func TestRoutePositionCodecIsStrict(t *testing.T) { | |
| 60 | - | want := RoutePosition{Target: testExactTarget(), ActiveTabID: "tab-2"} | |
| 61 | + | want := protocol.RoutePosition{Target: testExactTarget(), ActiveTabID: "tab-2"} | |
| 61 | 62 | encoded, err := MarshalRoutePosition(want) | |
| 62 | 63 | require.NoError(t, err) | |
| 63 | 64 | require.Equal(t, "010203000000000000000000000000000004776f726b00057461622d32", hex.EncodeToString(encoded)) | |
| @@ -69,14 +70,14 @@ func TestRoutePositionCodecIsStrict(t *testing.T) { | |||
| 69 | 70 | require.NoError(t, err) | |
| 70 | 71 | require.Equal(t, want, got) | |
| 71 | 72 | ||
| 72 | - | _, err = MarshalRoutePosition(RoutePosition{Target: testExactTarget()}) | |
| 73 | - | require.ErrorIs(t, err, ErrInvalidRouteWire) | |
| 74 | - | _, err = MarshalRoutePosition(RoutePosition{Target: testExactTarget(), ActiveTabID: "bad tab"}) | |
| 75 | - | require.ErrorIs(t, err, ErrInvalidRouteWire) | |
| 73 | + | _, err = MarshalRoutePosition(protocol.RoutePosition{Target: testExactTarget()}) | |
| 74 | + | require.ErrorIs(t, err, protocol.ErrInvalidRouteWire) | |
| 75 | + | _, err = MarshalRoutePosition(protocol.RoutePosition{Target: testExactTarget(), ActiveTabID: "bad tab"}) | |
| 76 | + | require.ErrorIs(t, err, protocol.ErrInvalidRouteWire) | |
| 76 | 77 | } | |
| 77 | 78 | ||
| 78 | 79 | func TestWelcomeCarriesCommittedRouteIdentity(t *testing.T) { | |
| 79 | - | identity := &CommittedRouteIdentity{Target: testExactTarget(), Ephemeral: true} | |
| 80 | + | identity := &protocol.CommittedRouteIdentity{Target: testExactTarget(), Ephemeral: true} | |
| 80 | 81 | want := Welcome{SessionID: "daemon-session", SessionName: "work", Ephemeral: true, CommittedIdentity: identity} | |
| 81 | 82 | ||
| 82 | 83 | got, err := UnmarshalWelcome(MarshalWelcome(want)) | |
| @@ -85,14 +86,14 @@ func TestWelcomeCarriesCommittedRouteIdentity(t *testing.T) { | |||
| 85 | 86 | } | |
| 86 | 87 | ||
| 87 | 88 | func TestWelcomeRejectsMismatchedCommittedIdentity(t *testing.T) { | |
| 88 | - | identity := &CommittedRouteIdentity{Target: testExactTarget()} | |
| 89 | + | identity := &protocol.CommittedRouteIdentity{Target: testExactTarget()} | |
| 89 | 90 | payload := MarshalWelcome(Welcome{SessionID: "daemon-session", SessionName: "other", CommittedIdentity: identity}) | |
| 90 | 91 | ||
| 91 | 92 | require.Nil(t, payload) | |
| 92 | 93 | } | |
| 93 | 94 | ||
| 94 | 95 | func TestCommittedRouteIdentityCodec(t *testing.T) { | |
| 95 | - | want := CommittedRouteIdentity{Target: testExactTarget(), Ephemeral: true} | |
| 96 | + | want := protocol.CommittedRouteIdentity{Target: testExactTarget(), Ephemeral: true} | |
| 96 | 97 | encoded, err := MarshalCommittedRouteIdentity(want) | |
| 97 | 98 | require.NoError(t, err) | |
| 98 | 99 | ||
| @@ -111,17 +112,17 @@ func TestCommittedRouteIdentityCodec(t *testing.T) { | |||
| 111 | 112 | require.Error(t, err) | |
| 112 | 113 | } | |
| 113 | 114 | ||
| 114 | - | func testRouteSnapshot() RecentRouteSnapshot { | |
| 115 | + | func testRouteSnapshot() protocol.RecentRouteSnapshot { | |
| 115 | 116 | activeTarget := testExactTarget() | |
| 116 | - | logsTarget := ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{4, 5, 6}, SessionName: "logs"} | |
| 117 | - | return RecentRouteSnapshot{ | |
| 117 | + | logsTarget := protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{4, 5, 6}, SessionName: "logs"} | |
| 118 | + | return protocol.RecentRouteSnapshot{ | |
| 118 | 119 | Generation: 9, | |
| 119 | - | Active: RouteRef{Key: 11, Generation: 3}, | |
| 120 | - | ActiveEntry: RecentRouteEntry{Key: 11, Generation: 3, Target: activeTarget, Name: "work", Kind: RouteKindLocal, Reachability: RouteReachabilityUnknown}, | |
| 121 | - | Previous: RouteRef{Key: 12, Generation: 4}, | |
| 122 | - | Home: RouteRef{Key: 11, Generation: 3}, | |
| 123 | - | Entries: []RecentRouteEntry{ | |
| 124 | - | {Key: 12, Generation: 4, Target: logsTarget, Name: "logs", HostLabel: "edge", Kind: RouteKindRemote, Attention: true, Reachability: RouteReachabilityUnknown}, | |
| 120 | + | Active: protocol.RouteRef{Key: 11, Generation: 3}, | |
| 121 | + | ActiveEntry: protocol.RecentRouteEntry{Key: 11, Generation: 3, Target: activeTarget, Name: "work", Kind: protocol.RouteKindLocal, Reachability: protocol.RouteReachabilityUnknown}, | |
| 122 | + | Previous: protocol.RouteRef{Key: 12, Generation: 4}, | |
| 123 | + | Home: protocol.RouteRef{Key: 11, Generation: 3}, | |
| 124 | + | Entries: []protocol.RecentRouteEntry{ | |
| 125 | + | {Key: 12, Generation: 4, Target: logsTarget, Name: "logs", HostLabel: "edge", Kind: protocol.RouteKindRemote, Attention: true, Reachability: protocol.RouteReachabilityUnknown}, | |
| 125 | 126 | }, | |
| 126 | 127 | } | |
| 127 | 128 | } | |
| @@ -142,36 +143,41 @@ func TestRecentRouteSnapshotCodecRoundTripAndBounds(t *testing.T) { | |||
| 142 | 143 | ||
| 143 | 144 | invalidCases := []struct { | |
| 144 | 145 | name string | |
| 145 | - | mutate func(*RecentRouteSnapshot) | |
| 146 | + | mutate func(*protocol.RecentRouteSnapshot) | |
| 146 | 147 | }{ | |
| 147 | - | {name: "missing previous reference", mutate: func(snapshot *RecentRouteSnapshot) { snapshot.Previous = RouteRef{Key: 99, Generation: 99} }}, | |
| 148 | - | {name: "missing active presentation", mutate: func(snapshot *RecentRouteSnapshot) { snapshot.ActiveEntry = RecentRouteEntry{} }}, | |
| 149 | - | {name: "route name differs from lifecycle target", mutate: func(snapshot *RecentRouteSnapshot) { snapshot.Entries[0].Name = "other" }}, | |
| 150 | - | {name: "entry is active", mutate: func(snapshot *RecentRouteSnapshot) { | |
| 148 | + | {name: "missing previous reference", mutate: func(snapshot *protocol.RecentRouteSnapshot) { | |
| 149 | + | snapshot.Previous = protocol.RouteRef{Key: 99, Generation: 99} | |
| 150 | + | }}, | |
| 151 | + | {name: "missing active presentation", mutate: func(snapshot *protocol.RecentRouteSnapshot) { snapshot.ActiveEntry = protocol.RecentRouteEntry{} }}, | |
| 152 | + | {name: "route name differs from lifecycle target", mutate: func(snapshot *protocol.RecentRouteSnapshot) { snapshot.Entries[0].Name = "other" }}, | |
| 153 | + | {name: "entry is active", mutate: func(snapshot *protocol.RecentRouteSnapshot) { | |
| 151 | 154 | snapshot.Entries = append(snapshot.Entries, snapshot.ActiveEntry) | |
| 152 | 155 | }}, | |
| 153 | - | {name: "duplicate entry", mutate: func(snapshot *RecentRouteSnapshot) { snapshot.Entries = append(snapshot.Entries, snapshot.Entries[0]) }}, | |
| 154 | - | {name: "too many entries", mutate: func(snapshot *RecentRouteSnapshot) { | |
| 155 | - | snapshot.Entries = make([]RecentRouteEntry, RouteSnapshotMaxEntries+1) | |
| 156 | + | {name: "duplicate entry", mutate: func(snapshot *protocol.RecentRouteSnapshot) { | |
| 157 | + | snapshot.Entries = append(snapshot.Entries, snapshot.Entries[0]) | |
| 158 | + | }}, | |
| 159 | + | {name: "too many entries", mutate: func(snapshot *protocol.RecentRouteSnapshot) { | |
| 160 | + | snapshot.Entries = make([]protocol.RecentRouteEntry, protocol.RouteSnapshotMaxEntries+1) | |
| 156 | 161 | for i := range snapshot.Entries { | |
| 157 | - | target := ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{byte(i + 1)}, SessionName: "x"} | |
| 158 | - | snapshot.Entries[i] = RecentRouteEntry{Key: uint64(i + 1), Generation: uint64(i + 1), Target: target, Name: "x", Kind: RouteKindLocal} | |
| 162 | + | target := protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{byte(i + 1)}, SessionName: "x"} | |
| 163 | + | snapshot.Entries[i] = protocol.RecentRouteEntry{Key: uint64(i + 1), Generation: uint64(i + 1), Target: target, Name: "x", Kind: protocol.RouteKindLocal} | |
| 159 | 164 | } | |
| 160 | 165 | }}, | |
| 161 | 166 | } | |
| 162 | 167 | for _, tc := range invalidCases { | |
| 163 | 168 | t.Run(tc.name, func(t *testing.T) { | |
| 164 | 169 | invalid := want | |
| 170 | + | invalid.Entries = append([]protocol.RecentRouteEntry(nil), want.Entries...) | |
| 165 | 171 | tc.mutate(&invalid) | |
| 166 | 172 | _, err := MarshalRecentRouteSnapshot(invalid) | |
| 167 | - | require.ErrorIs(t, err, ErrInvalidRouteWire) | |
| 173 | + | require.ErrorIs(t, err, protocol.ErrInvalidRouteWire) | |
| 168 | 174 | }) | |
| 169 | 175 | } | |
| 170 | 176 | } | |
| 171 | 177 | ||
| 172 | 178 | func TestRouteAttentionSubscriptionCodecIsStrict(t *testing.T) { | |
| 173 | - | want := RouteAttentionSubscription{Targets: []RouteAttentionTarget{{ | |
| 174 | - | Ref: RouteRef{Key: 7, Generation: 3}, | |
| 179 | + | want := protocol.RouteAttentionSubscription{Targets: []protocol.RouteAttentionTarget{{ | |
| 180 | + | Ref: protocol.RouteRef{Key: 7, Generation: 3}, | |
| 175 | 181 | Target: testExactTarget(), | |
| 176 | 182 | }}} | |
| 177 | 183 | encoded, err := MarshalRouteAttentionSubscription(want) | |
| @@ -185,15 +191,15 @@ func TestRouteAttentionSubscriptionCodecIsStrict(t *testing.T) { | |||
| 185 | 191 | require.NoError(t, err) | |
| 186 | 192 | require.Equal(t, want, got) | |
| 187 | 193 | ||
| 188 | - | _, err = MarshalRouteAttentionSubscription(RouteAttentionSubscription{Targets: []RouteAttentionTarget{ | |
| 194 | + | _, err = MarshalRouteAttentionSubscription(protocol.RouteAttentionSubscription{Targets: []protocol.RouteAttentionTarget{ | |
| 189 | 195 | want.Targets[0], want.Targets[0], | |
| 190 | 196 | }}) | |
| 191 | - | require.ErrorIs(t, err, ErrInvalidRouteWire) | |
| 197 | + | require.ErrorIs(t, err, protocol.ErrInvalidRouteWire) | |
| 192 | 198 | } | |
| 193 | 199 | ||
| 194 | 200 | func TestRecentRouteSnapshotRejectsOversizedFrameBeforeParsing(t *testing.T) { | |
| 195 | 201 | _, err := UnmarshalRecentRouteSnapshot(make([]byte, MaxFrameLen)) | |
| 196 | - | require.ErrorIs(t, err, ErrInvalidRouteWire) | |
| 202 | + | require.ErrorIs(t, err, protocol.ErrInvalidRouteWire) | |
| 197 | 203 | } | |
| 198 | 204 | ||
| 199 | 205 | func TestRouteLabelBoundsMatchRemoteDisplayOrigin(t *testing.T) { | |
| @@ -207,7 +213,7 @@ func TestRouteLabelBoundsMatchRemoteDisplayOrigin(t *testing.T) { | |||
| 207 | 213 | } | |
| 208 | 214 | for _, tt := range tests { | |
| 209 | 215 | t.Run(tt.name, func(t *testing.T) { | |
| 210 | - | err := ValidateRouteLabel(strings.Repeat("a", tt.length), false) | |
| 216 | + | err := protocol.ValidateRouteLabel(strings.Repeat("a", tt.length), false) | |
| 211 | 217 | if tt.wantErr { | |
| 212 | 218 | require.Error(t, err) | |
| 213 | 219 | return | |
| @@ -221,16 +227,16 @@ func TestRouteLabelsRejectTerminalUnsafeText(t *testing.T) { | |||
| 221 | 227 | values := []string{"line\nfeed", "\u2028line-separator", "\u2029paragraph-separator", "\x1b[31mred", "\u202eoverride", string([]byte{0xff, 0xfe})} | |
| 222 | 228 | for _, value := range values { | |
| 223 | 229 | t.Run("name/"+value, func(t *testing.T) { | |
| 224 | - | _, err := MarshalRecentRouteSnapshot(RecentRouteSnapshot{ | |
| 230 | + | _, err := MarshalRecentRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 225 | 231 | Generation: 1, | |
| 226 | - | Entries: []RecentRouteEntry{{Key: 1, Generation: 1, Target: ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: value}, Name: value, Kind: RouteKindLocal}}, | |
| 232 | + | Entries: []protocol.RecentRouteEntry{{Key: 1, Generation: 1, Target: protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: value}, Name: value, Kind: protocol.RouteKindLocal}}, | |
| 227 | 233 | }) | |
| 228 | 234 | require.Error(t, err) | |
| 229 | 235 | }) | |
| 230 | 236 | t.Run("host/"+value, func(t *testing.T) { | |
| 231 | - | _, err := MarshalRecentRouteSnapshot(RecentRouteSnapshot{ | |
| 237 | + | _, err := MarshalRecentRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 232 | 238 | Generation: 1, | |
| 233 | - | Entries: []RecentRouteEntry{{Key: 1, Generation: 1, Target: testExactTarget(), Name: "work", HostLabel: value, Kind: RouteKindRemote}}, | |
| 239 | + | Entries: []protocol.RecentRouteEntry{{Key: 1, Generation: 1, Target: testExactTarget(), Name: "work", HostLabel: value, Kind: protocol.RouteKindRemote}}, | |
| 234 | 240 | }) | |
| 235 | 241 | require.Error(t, err) | |
| 236 | 242 | }) | |
| @@ -238,7 +244,7 @@ func TestRouteLabelsRejectTerminalUnsafeText(t *testing.T) { | |||
| 238 | 244 | } | |
| 239 | 245 | ||
| 240 | 246 | func TestRouteActionAndFailureCodecsAreBounded(t *testing.T) { | |
| 241 | - | action := RouteNavigationAction{SnapshotGeneration: 9, Key: 7, Generation: 8} | |
| 247 | + | action := protocol.RouteNavigationAction{SnapshotGeneration: 9, Key: 7, Generation: 8} | |
| 242 | 248 | encoded, err := MarshalRouteNavigationAction(action) | |
| 243 | 249 | require.NoError(t, err) | |
| 244 | 250 | require.Equal(t, "000000000000000900000000000000070000000000000008", hex.EncodeToString(encoded)) | |
| @@ -249,7 +255,7 @@ func TestRouteActionAndFailureCodecsAreBounded(t *testing.T) { | |||
| 249 | 255 | require.NoError(t, err) | |
| 250 | 256 | require.Equal(t, action, got) | |
| 251 | 257 | ||
| 252 | - | failure := RouteNavigationFailure{Key: 7, Generation: 8, Code: RouteFailureStaleSelection} | |
| 258 | + | failure := protocol.RouteNavigationFailure{Key: 7, Generation: 8, Code: protocol.RouteFailureStaleSelection} | |
| 253 | 259 | encoded, err = MarshalRouteNavigationFailure(failure) | |
| 254 | 260 | require.NoError(t, err) | |
| 255 | 261 | require.Equal(t, "0000000000000007000000000000000801", hex.EncodeToString(encoded)) | |
| @@ -260,11 +266,11 @@ func TestRouteActionAndFailureCodecsAreBounded(t *testing.T) { | |||
| 260 | 266 | require.NoError(t, err) | |
| 261 | 267 | require.Equal(t, failure, gotFailure) | |
| 262 | 268 | ||
| 263 | - | for _, invalid := range []RouteNavigationAction{{}, {SnapshotGeneration: 1, Key: 1}, {SnapshotGeneration: 1, Generation: 1}, {Key: 1, Generation: 1}} { | |
| 269 | + | for _, invalid := range []protocol.RouteNavigationAction{{}, {SnapshotGeneration: 1, Key: 1}, {SnapshotGeneration: 1, Generation: 1}, {Key: 1, Generation: 1}} { | |
| 264 | 270 | _, err := MarshalRouteNavigationAction(invalid) | |
| 265 | 271 | require.Error(t, err) | |
| 266 | 272 | } | |
| 267 | - | for _, invalid := range []RouteNavigationFailure{{}, {Key: 1, Generation: 1}, {Key: 1, Generation: 1, Code: 255}} { | |
| 273 | + | for _, invalid := range []protocol.RouteNavigationFailure{{}, {Key: 1, Generation: 1}, {Key: 1, Generation: 1, Code: 255}} { | |
| 268 | 274 | _, err := MarshalRouteNavigationFailure(invalid) | |
| 269 | 275 | require.Error(t, err) | |
| 270 | 276 | } | |
M internal/ports/routes_wire.go +165 -167
| @@ -1,34 +1,32 @@ | |||
| 1 | 1 | package ports | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "errors" | |
| 5 | 4 | "fmt" | |
| 6 | 5 | ||
| 7 | 6 | "github.com/bnema/vev/internal/domain" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 8 | ) | |
| 9 | 9 | ||
| 10 | - | var ErrInvalidRouteWire = errors.New("invalid route wire message") | |
| 11 | - | ||
| 12 | 10 | func validateRouteString(value, field string, allowEmpty bool) error { | |
| 13 | - | if err := ValidateRouteLabel(value, allowEmpty); err != nil { | |
| 11 | + | if err := protocol.ValidateRouteLabel(value, allowEmpty); err != nil { | |
| 14 | 12 | return fmt.Errorf("%s: %w", field, err) | |
| 15 | 13 | } | |
| 16 | 14 | return nil | |
| 17 | 15 | } | |
| 18 | 16 | ||
| 19 | - | func marshalExactSessionTarget(w *payloadWriter, target ExactSessionTarget) { | |
| 17 | + | func marshalExactSessionTarget(w *payloadWriter, target protocol.ExactSessionTarget) { | |
| 20 | 18 | w.putBytes(target.LifecycleID[:]) | |
| 21 | 19 | w.putString(target.SessionName) | |
| 22 | 20 | } | |
| 23 | 21 | ||
| 24 | - | func marshalExactTargetSection(w *payloadWriter, target *ExactSessionTarget) { | |
| 22 | + | func marshalExactTargetSection(w *payloadWriter, target *protocol.ExactSessionTarget) { | |
| 25 | 23 | w.putBool(target != nil) | |
| 26 | 24 | if target != nil { | |
| 27 | 25 | marshalExactSessionTarget(w, *target) | |
| 28 | 26 | } | |
| 29 | 27 | } | |
| 30 | 28 | ||
| 31 | - | func unmarshalExactTargetSection(r *payloadReader) (*ExactSessionTarget, error) { | |
| 29 | + | func unmarshalExactTargetSection(r *payloadReader) (*protocol.ExactSessionTarget, error) { | |
| 32 | 30 | present, err := r.getBool() | |
| 33 | 31 | if err != nil { | |
| 34 | 32 | return nil, err | |
| @@ -57,27 +55,27 @@ func skipExactTargetSection(r *payloadReader) error { | |||
| 57 | 55 | return nil | |
| 58 | 56 | } | |
| 59 | 57 | ||
| 60 | - | func unmarshalExactSessionTarget(r *payloadReader) (ExactSessionTarget, error) { | |
| 61 | - | var target ExactSessionTarget | |
| 58 | + | func unmarshalExactSessionTarget(r *payloadReader) (protocol.ExactSessionTarget, error) { | |
| 59 | + | var target protocol.ExactSessionTarget | |
| 62 | 60 | lifecycle, err := r.getBytes(len(target.LifecycleID)) | |
| 63 | 61 | if err != nil { | |
| 64 | - | return ExactSessionTarget{}, err | |
| 62 | + | return protocol.ExactSessionTarget{}, err | |
| 65 | 63 | } | |
| 66 | 64 | copy(target.LifecycleID[:], lifecycle) | |
| 67 | 65 | if target.SessionName, err = r.getString(); err != nil { | |
| 68 | - | return ExactSessionTarget{}, err | |
| 66 | + | return protocol.ExactSessionTarget{}, err | |
| 69 | 67 | } | |
| 70 | 68 | if err := target.Validate(); err != nil { | |
| 71 | - | return ExactSessionTarget{}, fmt.Errorf("%w: exact target: %v", ErrInvalidRouteWire, err) | |
| 69 | + | return protocol.ExactSessionTarget{}, fmt.Errorf("%w: exact target: %v", protocol.ErrInvalidRouteWire, err) | |
| 72 | 70 | } | |
| 73 | 71 | return target, nil | |
| 74 | 72 | } | |
| 75 | 73 | ||
| 76 | 74 | // MarshalExactSessionTarget encodes the exact lifecycle/name pair used by | |
| 77 | 75 | // Hello and route-transition tests. | |
| 78 | - | func MarshalExactSessionTarget(target ExactSessionTarget) ([]byte, error) { | |
| 76 | + | func MarshalExactSessionTarget(target protocol.ExactSessionTarget) ([]byte, error) { | |
| 79 | 77 | if err := target.Validate(); err != nil { | |
| 80 | - | return nil, fmt.Errorf("%w: exact target: %v", ErrInvalidRouteWire, err) | |
| 78 | + | return nil, fmt.Errorf("%w: exact target: %v", protocol.ErrInvalidRouteWire, err) | |
| 81 | 79 | } | |
| 82 | 80 | w := payloadWriter{} | |
| 83 | 81 | marshalExactSessionTarget(&w, target) | |
| @@ -86,21 +84,21 @@ func MarshalExactSessionTarget(target ExactSessionTarget) ([]byte, error) { | |||
| 86 | 84 | ||
| 87 | 85 | // UnmarshalExactSessionTarget decodes one exact lifecycle/name pair and rejects | |
| 88 | 86 | // truncation, invalid identity, and trailing bytes. | |
| 89 | - | func UnmarshalExactSessionTarget(b []byte) (ExactSessionTarget, error) { | |
| 87 | + | func UnmarshalExactSessionTarget(b []byte) (protocol.ExactSessionTarget, error) { | |
| 90 | 88 | r := payloadReader{b: b} | |
| 91 | 89 | target, err := unmarshalExactSessionTarget(&r) | |
| 92 | 90 | if err != nil { | |
| 93 | - | return ExactSessionTarget{}, err | |
| 91 | + | return protocol.ExactSessionTarget{}, err | |
| 94 | 92 | } | |
| 95 | 93 | if err := r.done(); err != nil { | |
| 96 | - | return ExactSessionTarget{}, err | |
| 94 | + | return protocol.ExactSessionTarget{}, err | |
| 97 | 95 | } | |
| 98 | 96 | return target, nil | |
| 99 | 97 | } | |
| 100 | 98 | ||
| 101 | 99 | // MarshalSamePeerSwitchRequest encodes the strict in-band session switch | |
| 102 | 100 | // confirmation. The target is non-optional and carries no display origin. | |
| 103 | - | func MarshalSamePeerSwitchRequest(request SamePeerSwitchRequest) ([]byte, error) { | |
| 101 | + | func MarshalSamePeerSwitchRequest(request protocol.SamePeerSwitchRequest) ([]byte, error) { | |
| 104 | 102 | if err := request.Validate(); err != nil { | |
| 105 | 103 | return nil, err | |
| 106 | 104 | } | |
| @@ -112,32 +110,32 @@ func MarshalSamePeerSwitchRequest(request SamePeerSwitchRequest) ([]byte, error) | |||
| 112 | 110 | } | |
| 113 | 111 | ||
| 114 | 112 | // UnmarshalSamePeerSwitchRequest decodes one complete in-band switch request. | |
| 115 | - | func UnmarshalSamePeerSwitchRequest(b []byte) (SamePeerSwitchRequest, error) { | |
| 113 | + | func UnmarshalSamePeerSwitchRequest(b []byte) (protocol.SamePeerSwitchRequest, error) { | |
| 116 | 114 | r := payloadReader{b: b} | |
| 117 | - | var request SamePeerSwitchRequest | |
| 115 | + | var request protocol.SamePeerSwitchRequest | |
| 118 | 116 | var err error | |
| 119 | 117 | if request.RequestID, err = r.getUint64(); err != nil { | |
| 120 | - | return SamePeerSwitchRequest{}, err | |
| 118 | + | return protocol.SamePeerSwitchRequest{}, err | |
| 121 | 119 | } | |
| 122 | 120 | if request.Target, err = unmarshalExactSessionTarget(&r); err != nil { | |
| 123 | - | return SamePeerSwitchRequest{}, err | |
| 121 | + | return protocol.SamePeerSwitchRequest{}, err | |
| 124 | 122 | } | |
| 125 | 123 | preferred, err := r.getString() | |
| 126 | 124 | if err != nil { | |
| 127 | - | return SamePeerSwitchRequest{}, err | |
| 125 | + | return protocol.SamePeerSwitchRequest{}, err | |
| 128 | 126 | } | |
| 129 | 127 | request.PreferredTabID = domain.TabStableID(preferred) | |
| 130 | 128 | if err := r.done(); err != nil { | |
| 131 | - | return SamePeerSwitchRequest{}, err | |
| 129 | + | return protocol.SamePeerSwitchRequest{}, err | |
| 132 | 130 | } | |
| 133 | 131 | if err := request.Validate(); err != nil { | |
| 134 | - | return SamePeerSwitchRequest{}, err | |
| 132 | + | return protocol.SamePeerSwitchRequest{}, err | |
| 135 | 133 | } | |
| 136 | 134 | return request, nil | |
| 137 | 135 | } | |
| 138 | 136 | ||
| 139 | 137 | // MarshalSamePeerSwitchFailure encodes a bounded pre-commit rejection. | |
| 140 | - | func MarshalSamePeerSwitchFailure(failure SamePeerSwitchFailure) ([]byte, error) { | |
| 138 | + | func MarshalSamePeerSwitchFailure(failure protocol.SamePeerSwitchFailure) ([]byte, error) { | |
| 141 | 139 | if err := failure.Validate(); err != nil { | |
| 142 | 140 | return nil, err | |
| 143 | 141 | } | |
| @@ -148,37 +146,37 @@ func MarshalSamePeerSwitchFailure(failure SamePeerSwitchFailure) ([]byte, error) | |||
| 148 | 146 | } | |
| 149 | 147 | ||
| 150 | 148 | // UnmarshalSamePeerSwitchFailure decodes a complete bounded rejection. | |
| 151 | - | func UnmarshalSamePeerSwitchFailure(b []byte) (SamePeerSwitchFailure, error) { | |
| 149 | + | func UnmarshalSamePeerSwitchFailure(b []byte) (protocol.SamePeerSwitchFailure, error) { | |
| 152 | 150 | r := payloadReader{b: b} | |
| 153 | - | var failure SamePeerSwitchFailure | |
| 151 | + | var failure protocol.SamePeerSwitchFailure | |
| 154 | 152 | var err error | |
| 155 | 153 | if failure.RequestID, err = r.getUint64(); err != nil { | |
| 156 | - | return SamePeerSwitchFailure{}, err | |
| 154 | + | return protocol.SamePeerSwitchFailure{}, err | |
| 157 | 155 | } | |
| 158 | 156 | code, err := r.getUint8() | |
| 159 | 157 | if err != nil { | |
| 160 | - | return SamePeerSwitchFailure{}, err | |
| 158 | + | return protocol.SamePeerSwitchFailure{}, err | |
| 161 | 159 | } | |
| 162 | - | failure.Code = SamePeerSwitchFailureCode(code) | |
| 160 | + | failure.Code = protocol.SamePeerSwitchFailureCode(code) | |
| 163 | 161 | if err := r.done(); err != nil { | |
| 164 | - | return SamePeerSwitchFailure{}, err | |
| 162 | + | return protocol.SamePeerSwitchFailure{}, err | |
| 165 | 163 | } | |
| 166 | 164 | if err := failure.Validate(); err != nil { | |
| 167 | - | return SamePeerSwitchFailure{}, err | |
| 165 | + | return protocol.SamePeerSwitchFailure{}, err | |
| 168 | 166 | } | |
| 169 | 167 | return failure, nil | |
| 170 | 168 | } | |
| 171 | 169 | ||
| 172 | - | func validateCommittedRouteIdentity(identity CommittedRouteIdentity) error { | |
| 170 | + | func validateCommittedRouteIdentity(identity protocol.CommittedRouteIdentity) error { | |
| 173 | 171 | if err := identity.Validate(); err != nil { | |
| 174 | - | return fmt.Errorf("%w: committed identity: %v", ErrInvalidRouteWire, err) | |
| 172 | + | return fmt.Errorf("%w: committed identity: %v", protocol.ErrInvalidRouteWire, err) | |
| 175 | 173 | } | |
| 176 | 174 | return nil | |
| 177 | 175 | } | |
| 178 | 176 | ||
| 179 | 177 | // MarshalCommittedRouteIdentity encodes the daemon's committed exact session | |
| 180 | 178 | // identity without exposing transport or client-ledger details. | |
| 181 | - | func MarshalCommittedRouteIdentity(identity CommittedRouteIdentity) ([]byte, error) { | |
| 179 | + | func MarshalCommittedRouteIdentity(identity protocol.CommittedRouteIdentity) ([]byte, error) { | |
| 182 | 180 | if err := validateCommittedRouteIdentity(identity); err != nil { | |
| 183 | 181 | return nil, err | |
| 184 | 182 | } | |
| @@ -187,14 +185,14 @@ func MarshalCommittedRouteIdentity(identity CommittedRouteIdentity) ([]byte, err | |||
| 187 | 185 | return w.b, nil | |
| 188 | 186 | } | |
| 189 | 187 | ||
| 190 | - | func marshalCommittedRouteIdentityFields(w *payloadWriter, identity CommittedRouteIdentity) { | |
| 188 | + | func marshalCommittedRouteIdentityFields(w *payloadWriter, identity protocol.CommittedRouteIdentity) { | |
| 191 | 189 | marshalExactSessionTarget(w, identity.Target) | |
| 192 | 190 | w.putBool(identity.Ephemeral) | |
| 193 | 191 | } | |
| 194 | 192 | ||
| 195 | 193 | // marshalCommittedIdentitySection shares the standalone identity body and | |
| 196 | 194 | // validates embedded identities before Welcome serialization. | |
| 197 | - | func marshalCommittedIdentitySection(w *payloadWriter, identity *CommittedRouteIdentity) bool { | |
| 195 | + | func marshalCommittedIdentitySection(w *payloadWriter, identity *protocol.CommittedRouteIdentity) bool { | |
| 198 | 196 | w.putBool(identity != nil) | |
| 199 | 197 | if identity == nil { | |
| 200 | 198 | return true | |
| @@ -206,7 +204,7 @@ func marshalCommittedIdentitySection(w *payloadWriter, identity *CommittedRouteI | |||
| 206 | 204 | return true | |
| 207 | 205 | } | |
| 208 | 206 | ||
| 209 | - | func unmarshalCommittedIdentitySection(r *payloadReader) (*CommittedRouteIdentity, error) { | |
| 207 | + | func unmarshalCommittedIdentitySection(r *payloadReader) (*protocol.CommittedRouteIdentity, error) { | |
| 210 | 208 | present, err := r.getBool() | |
| 211 | 209 | if err != nil { | |
| 212 | 210 | return nil, err | |
| @@ -222,38 +220,38 @@ func unmarshalCommittedIdentitySection(r *payloadReader) (*CommittedRouteIdentit | |||
| 222 | 220 | if err != nil { | |
| 223 | 221 | return nil, err | |
| 224 | 222 | } | |
| 225 | - | identity := &CommittedRouteIdentity{Target: target, Ephemeral: ephemeral} | |
| 223 | + | identity := &protocol.CommittedRouteIdentity{Target: target, Ephemeral: ephemeral} | |
| 226 | 224 | if err := validateCommittedRouteIdentity(*identity); err != nil { | |
| 227 | 225 | return nil, err | |
| 228 | 226 | } | |
| 229 | 227 | return identity, nil | |
| 230 | 228 | } | |
| 231 | 229 | ||
| 232 | - | func UnmarshalCommittedRouteIdentity(b []byte) (CommittedRouteIdentity, error) { | |
| 230 | + | func UnmarshalCommittedRouteIdentity(b []byte) (protocol.CommittedRouteIdentity, error) { | |
| 233 | 231 | r := payloadReader{b: b} | |
| 234 | 232 | target, err := unmarshalExactSessionTarget(&r) | |
| 235 | 233 | if err != nil { | |
| 236 | - | return CommittedRouteIdentity{}, err | |
| 234 | + | return protocol.CommittedRouteIdentity{}, err | |
| 237 | 235 | } | |
| 238 | 236 | ephemeral, err := r.getBool() | |
| 239 | 237 | if err != nil { | |
| 240 | - | return CommittedRouteIdentity{}, err | |
| 238 | + | return protocol.CommittedRouteIdentity{}, err | |
| 241 | 239 | } | |
| 242 | 240 | if err := r.done(); err != nil { | |
| 243 | - | return CommittedRouteIdentity{}, err | |
| 241 | + | return protocol.CommittedRouteIdentity{}, err | |
| 244 | 242 | } | |
| 245 | - | identity := CommittedRouteIdentity{Target: target, Ephemeral: ephemeral} | |
| 243 | + | identity := protocol.CommittedRouteIdentity{Target: target, Ephemeral: ephemeral} | |
| 246 | 244 | if err := validateCommittedRouteIdentity(identity); err != nil { | |
| 247 | - | return CommittedRouteIdentity{}, err | |
| 245 | + | return protocol.CommittedRouteIdentity{}, err | |
| 248 | 246 | } | |
| 249 | 247 | return identity, nil | |
| 250 | 248 | } | |
| 251 | 249 | ||
| 252 | 250 | // MarshalRoutePosition encodes one exact session and its attachment-local tab | |
| 253 | 251 | // cursor. Route positions are mutable client memory, not attach authority. | |
| 254 | - | func MarshalRoutePosition(position RoutePosition) ([]byte, error) { | |
| 252 | + | func MarshalRoutePosition(position protocol.RoutePosition) ([]byte, error) { | |
| 255 | 253 | if err := position.Validate(); err != nil { | |
| 256 | - | return nil, fmt.Errorf("%w: route position: %v", ErrInvalidRouteWire, err) | |
| 254 | + | return nil, fmt.Errorf("%w: route position: %v", protocol.ErrInvalidRouteWire, err) | |
| 257 | 255 | } | |
| 258 | 256 | w := payloadWriter{} | |
| 259 | 257 | marshalExactSessionTarget(&w, position.Target) | |
| @@ -262,85 +260,85 @@ func MarshalRoutePosition(position RoutePosition) ([]byte, error) { | |||
| 262 | 260 | } | |
| 263 | 261 | ||
| 264 | 262 | // UnmarshalRoutePosition decodes one strict route-position payload. | |
| 265 | - | func UnmarshalRoutePosition(b []byte) (RoutePosition, error) { | |
| 263 | + | func UnmarshalRoutePosition(b []byte) (protocol.RoutePosition, error) { | |
| 266 | 264 | r := payloadReader{b: b} | |
| 267 | 265 | target, err := unmarshalExactSessionTarget(&r) | |
| 268 | 266 | if err != nil { | |
| 269 | - | return RoutePosition{}, err | |
| 267 | + | return protocol.RoutePosition{}, err | |
| 270 | 268 | } | |
| 271 | 269 | activeTabID, err := r.getString() | |
| 272 | 270 | if err != nil { | |
| 273 | - | return RoutePosition{}, err | |
| 271 | + | return protocol.RoutePosition{}, err | |
| 274 | 272 | } | |
| 275 | 273 | if err := r.done(); err != nil { | |
| 276 | - | return RoutePosition{}, err | |
| 274 | + | return protocol.RoutePosition{}, err | |
| 277 | 275 | } | |
| 278 | - | position := RoutePosition{Target: target, ActiveTabID: domain.TabStableID(activeTabID)} | |
| 276 | + | position := protocol.RoutePosition{Target: target, ActiveTabID: domain.TabStableID(activeTabID)} | |
| 279 | 277 | if err := position.Validate(); err != nil { | |
| 280 | - | return RoutePosition{}, fmt.Errorf("%w: route position: %v", ErrInvalidRouteWire, err) | |
| 278 | + | return protocol.RoutePosition{}, fmt.Errorf("%w: route position: %v", protocol.ErrInvalidRouteWire, err) | |
| 281 | 279 | } | |
| 282 | 280 | return position, nil | |
| 283 | 281 | } | |
| 284 | 282 | ||
| 285 | - | func validateRouteRef(ref RouteRef) error { | |
| 283 | + | func validateRouteRef(ref protocol.RouteRef) error { | |
| 286 | 284 | if err := ref.Validate(); err != nil { | |
| 287 | - | return fmt.Errorf("%w: route reference: %v", ErrInvalidRouteWire, err) | |
| 285 | + | return fmt.Errorf("%w: route reference: %v", protocol.ErrInvalidRouteWire, err) | |
| 288 | 286 | } | |
| 289 | 287 | return nil | |
| 290 | 288 | } | |
| 291 | 289 | ||
| 292 | - | func marshalRouteRef(w *payloadWriter, ref RouteRef) { | |
| 290 | + | func marshalRouteRef(w *payloadWriter, ref protocol.RouteRef) { | |
| 293 | 291 | w.putUint64(ref.Key) | |
| 294 | 292 | w.putUint64(ref.Generation) | |
| 295 | 293 | } | |
| 296 | 294 | ||
| 297 | - | func unmarshalRouteRef(r *payloadReader) (RouteRef, error) { | |
| 295 | + | func unmarshalRouteRef(r *payloadReader) (protocol.RouteRef, error) { | |
| 298 | 296 | key, err := r.getUint64() | |
| 299 | 297 | if err != nil { | |
| 300 | - | return RouteRef{}, err | |
| 298 | + | return protocol.RouteRef{}, err | |
| 301 | 299 | } | |
| 302 | 300 | generation, err := r.getUint64() | |
| 303 | 301 | if err != nil { | |
| 304 | - | return RouteRef{}, err | |
| 302 | + | return protocol.RouteRef{}, err | |
| 305 | 303 | } | |
| 306 | - | ref := RouteRef{Key: key, Generation: generation} | |
| 304 | + | ref := protocol.RouteRef{Key: key, Generation: generation} | |
| 307 | 305 | if err := validateRouteRef(ref); err != nil { | |
| 308 | - | return RouteRef{}, err | |
| 306 | + | return protocol.RouteRef{}, err | |
| 309 | 307 | } | |
| 310 | 308 | return ref, nil | |
| 311 | 309 | } | |
| 312 | 310 | ||
| 313 | - | func validateRecentRouteEntry(entry RecentRouteEntry) error { | |
| 311 | + | func validateRecentRouteEntry(entry protocol.RecentRouteEntry) error { | |
| 314 | 312 | if entry.Key == 0 || entry.Generation == 0 { | |
| 315 | - | return fmt.Errorf("%w: route entry identity is zero", ErrInvalidRouteWire) | |
| 313 | + | return fmt.Errorf("%w: route entry identity is zero", protocol.ErrInvalidRouteWire) | |
| 316 | 314 | } | |
| 317 | 315 | if err := entry.Target.Validate(); err != nil { | |
| 318 | - | return fmt.Errorf("%w: invalid route lifecycle target: %v", ErrInvalidRouteWire, err) | |
| 316 | + | return fmt.Errorf("%w: invalid route lifecycle target: %v", protocol.ErrInvalidRouteWire, err) | |
| 319 | 317 | } | |
| 320 | 318 | if entry.Name != entry.Target.SessionName { | |
| 321 | - | return fmt.Errorf("%w: route name does not match lifecycle target", ErrInvalidRouteWire) | |
| 319 | + | return fmt.Errorf("%w: route name does not match lifecycle target", protocol.ErrInvalidRouteWire) | |
| 322 | 320 | } | |
| 323 | 321 | if err := validateRouteString(entry.Name, "route name", false); err != nil { | |
| 324 | - | return fmt.Errorf("%w: %v", ErrInvalidRouteWire, err) | |
| 322 | + | return fmt.Errorf("%w: %v", protocol.ErrInvalidRouteWire, err) | |
| 325 | 323 | } | |
| 326 | 324 | if err := validateRouteString(entry.HostLabel, "route host label", true); err != nil { | |
| 327 | - | return fmt.Errorf("%w: %v", ErrInvalidRouteWire, err) | |
| 325 | + | return fmt.Errorf("%w: %v", protocol.ErrInvalidRouteWire, err) | |
| 328 | 326 | } | |
| 329 | - | if !entry.Kind.valid() { | |
| 330 | - | return fmt.Errorf("%w: invalid route kind", ErrInvalidRouteWire) | |
| 327 | + | if entry.Kind.Validate() != nil { | |
| 328 | + | return fmt.Errorf("%w: invalid route kind", protocol.ErrInvalidRouteWire) | |
| 331 | 329 | } | |
| 332 | - | if !entry.Reachability.valid() { | |
| 333 | - | return fmt.Errorf("%w: invalid route reachability", ErrInvalidRouteWire) | |
| 330 | + | if entry.Reachability.Validate() != nil { | |
| 331 | + | return fmt.Errorf("%w: invalid route reachability", protocol.ErrInvalidRouteWire) | |
| 334 | 332 | } | |
| 335 | 333 | return nil | |
| 336 | 334 | } | |
| 337 | 335 | ||
| 338 | - | func validateRecentRouteSnapshot(snapshot RecentRouteSnapshot) error { | |
| 339 | - | if len(snapshot.Entries) > RouteSnapshotMaxEntries { | |
| 340 | - | return fmt.Errorf("%w: too many route entries", ErrInvalidRouteWire) | |
| 336 | + | func validateRecentRouteSnapshot(snapshot protocol.RecentRouteSnapshot) error { | |
| 337 | + | if len(snapshot.Entries) > protocol.RouteSnapshotMaxEntries { | |
| 338 | + | return fmt.Errorf("%w: too many route entries", protocol.ErrInvalidRouteWire) | |
| 341 | 339 | } | |
| 342 | - | if snapshot.Generation == 0 && (len(snapshot.Entries) != 0 || snapshot.ActiveEntry != (RecentRouteEntry{})) { | |
| 343 | - | return fmt.Errorf("%w: non-empty snapshot has zero generation", ErrInvalidRouteWire) | |
| 340 | + | if snapshot.Generation == 0 && (len(snapshot.Entries) != 0 || snapshot.ActiveEntry != (protocol.RecentRouteEntry{})) { | |
| 341 | + | return fmt.Errorf("%w: non-empty snapshot has zero generation", protocol.ErrInvalidRouteWire) | |
| 344 | 342 | } | |
| 345 | 343 | if err := validateRouteRef(snapshot.Active); err != nil { | |
| 346 | 344 | return err | |
| @@ -351,55 +349,55 @@ func validateRecentRouteSnapshot(snapshot RecentRouteSnapshot) error { | |||
| 351 | 349 | if err := validateRouteRef(snapshot.Home); err != nil { | |
| 352 | 350 | return err | |
| 353 | 351 | } | |
| 354 | - | if snapshot.Active.empty() { | |
| 355 | - | if snapshot.ActiveEntry != (RecentRouteEntry{}) { | |
| 356 | - | return fmt.Errorf("%w: active presentation has no active route", ErrInvalidRouteWire) | |
| 352 | + | if snapshot.Active.IsZero() { | |
| 353 | + | if snapshot.ActiveEntry != (protocol.RecentRouteEntry{}) { | |
| 354 | + | return fmt.Errorf("%w: active presentation has no active route", protocol.ErrInvalidRouteWire) | |
| 357 | 355 | } | |
| 358 | 356 | } else { | |
| 359 | 357 | if err := validateRecentRouteEntry(snapshot.ActiveEntry); err != nil { | |
| 360 | 358 | return err | |
| 361 | 359 | } | |
| 362 | - | if snapshot.Active != (RouteRef{Key: snapshot.ActiveEntry.Key, Generation: snapshot.ActiveEntry.Generation}) { | |
| 363 | - | return fmt.Errorf("%w: active presentation does not match active route", ErrInvalidRouteWire) | |
| 360 | + | if snapshot.Active != (protocol.RouteRef{Key: snapshot.ActiveEntry.Key, Generation: snapshot.ActiveEntry.Generation}) { | |
| 361 | + | return fmt.Errorf("%w: active presentation does not match active route", protocol.ErrInvalidRouteWire) | |
| 364 | 362 | } | |
| 365 | 363 | } | |
| 366 | - | if !snapshot.Active.empty() && snapshot.Active == snapshot.Previous { | |
| 367 | - | return fmt.Errorf("%w: active and previous routes are identical", ErrInvalidRouteWire) | |
| 364 | + | if !snapshot.Active.IsZero() && snapshot.Active == snapshot.Previous { | |
| 365 | + | return fmt.Errorf("%w: active and previous routes are identical", protocol.ErrInvalidRouteWire) | |
| 368 | 366 | } | |
| 369 | - | refs := make(map[RouteRef]struct{}, len(snapshot.Entries)) | |
| 367 | + | refs := make(map[protocol.RouteRef]struct{}, len(snapshot.Entries)) | |
| 370 | 368 | for _, entry := range snapshot.Entries { | |
| 371 | - | if snapshot.Active == (RouteRef{Key: entry.Key, Generation: entry.Generation}) { | |
| 372 | - | return fmt.Errorf("%w: active route must be metadata-only", ErrInvalidRouteWire) | |
| 369 | + | if snapshot.Active == (protocol.RouteRef{Key: entry.Key, Generation: entry.Generation}) { | |
| 370 | + | return fmt.Errorf("%w: active route must be metadata-only", protocol.ErrInvalidRouteWire) | |
| 373 | 371 | } | |
| 374 | 372 | if err := validateRecentRouteEntry(entry); err != nil { | |
| 375 | 373 | return err | |
| 376 | 374 | } | |
| 377 | - | ref := RouteRef{Key: entry.Key, Generation: entry.Generation} | |
| 375 | + | ref := protocol.RouteRef{Key: entry.Key, Generation: entry.Generation} | |
| 378 | 376 | if _, exists := refs[ref]; exists { | |
| 379 | - | return fmt.Errorf("%w: duplicate route entry", ErrInvalidRouteWire) | |
| 377 | + | return fmt.Errorf("%w: duplicate route entry", protocol.ErrInvalidRouteWire) | |
| 380 | 378 | } | |
| 381 | 379 | refs[ref] = struct{}{} | |
| 382 | 380 | } | |
| 383 | 381 | for _, item := range []struct { | |
| 384 | 382 | name string | |
| 385 | - | ref RouteRef | |
| 383 | + | ref protocol.RouteRef | |
| 386 | 384 | }{ | |
| 387 | 385 | {name: "previous", ref: snapshot.Previous}, | |
| 388 | 386 | {name: "home", ref: snapshot.Home}, | |
| 389 | 387 | } { | |
| 390 | - | if item.ref.empty() || item.ref == snapshot.Active { | |
| 388 | + | if item.ref.IsZero() || item.ref == snapshot.Active { | |
| 391 | 389 | // Active is metadata-only and intentionally excluded from the | |
| 392 | 390 | // recent display entries. Home may point at active as well. | |
| 393 | 391 | continue | |
| 394 | 392 | } | |
| 395 | 393 | if _, exists := refs[item.ref]; !exists { | |
| 396 | - | return fmt.Errorf("%w: %s route reference is absent from snapshot", ErrInvalidRouteWire, item.name) | |
| 394 | + | return fmt.Errorf("%w: %s route reference is absent from snapshot", protocol.ErrInvalidRouteWire, item.name) | |
| 397 | 395 | } | |
| 398 | 396 | } | |
| 399 | 397 | return nil | |
| 400 | 398 | } | |
| 401 | 399 | ||
| 402 | - | func marshalRecentRouteEntry(w *payloadWriter, entry RecentRouteEntry) { | |
| 400 | + | func marshalRecentRouteEntry(w *payloadWriter, entry protocol.RecentRouteEntry) { | |
| 403 | 401 | w.putUint64(entry.Key) | |
| 404 | 402 | w.putUint64(entry.Generation) | |
| 405 | 403 | marshalExactSessionTarget(w, entry.Target) | |
| @@ -411,52 +409,52 @@ func marshalRecentRouteEntry(w *payloadWriter, entry RecentRouteEntry) { | |||
| 411 | 409 | w.putUint8(uint8(entry.Reachability)) | |
| 412 | 410 | } | |
| 413 | 411 | ||
| 414 | - | func unmarshalRecentRouteEntry(r *payloadReader) (RecentRouteEntry, error) { | |
| 415 | - | var entry RecentRouteEntry | |
| 412 | + | func unmarshalRecentRouteEntry(r *payloadReader) (protocol.RecentRouteEntry, error) { | |
| 413 | + | var entry protocol.RecentRouteEntry | |
| 416 | 414 | var err error | |
| 417 | 415 | if entry.Key, err = r.getUint64(); err != nil { | |
| 418 | - | return RecentRouteEntry{}, err | |
| 416 | + | return protocol.RecentRouteEntry{}, err | |
| 419 | 417 | } | |
| 420 | 418 | if entry.Generation, err = r.getUint64(); err != nil { | |
| 421 | - | return RecentRouteEntry{}, err | |
| 419 | + | return protocol.RecentRouteEntry{}, err | |
| 422 | 420 | } | |
| 423 | 421 | if entry.Target, err = unmarshalExactSessionTarget(r); err != nil { | |
| 424 | - | return RecentRouteEntry{}, err | |
| 422 | + | return protocol.RecentRouteEntry{}, err | |
| 425 | 423 | } | |
| 426 | 424 | if entry.Name, err = r.getString(); err != nil { | |
| 427 | - | return RecentRouteEntry{}, err | |
| 425 | + | return protocol.RecentRouteEntry{}, err | |
| 428 | 426 | } | |
| 429 | 427 | if entry.HostLabel, err = r.getString(); err != nil { | |
| 430 | - | return RecentRouteEntry{}, err | |
| 428 | + | return protocol.RecentRouteEntry{}, err | |
| 431 | 429 | } | |
| 432 | 430 | kind, err := r.getUint8() | |
| 433 | 431 | if err != nil { | |
| 434 | - | return RecentRouteEntry{}, err | |
| 432 | + | return protocol.RecentRouteEntry{}, err | |
| 435 | 433 | } | |
| 436 | - | entry.Kind = RouteKind(kind) | |
| 434 | + | entry.Kind = protocol.RouteKind(kind) | |
| 437 | 435 | if entry.Ephemeral, err = r.getBool(); err != nil { | |
| 438 | - | return RecentRouteEntry{}, err | |
| 436 | + | return protocol.RecentRouteEntry{}, err | |
| 439 | 437 | } | |
| 440 | 438 | if entry.Attention, err = r.getBool(); err != nil { | |
| 441 | - | return RecentRouteEntry{}, err | |
| 439 | + | return protocol.RecentRouteEntry{}, err | |
| 442 | 440 | } | |
| 443 | 441 | reachability, err := r.getUint8() | |
| 444 | 442 | if err != nil { | |
| 445 | - | return RecentRouteEntry{}, err | |
| 443 | + | return protocol.RecentRouteEntry{}, err | |
| 446 | 444 | } | |
| 447 | - | entry.Reachability = RouteReachability(reachability) | |
| 445 | + | entry.Reachability = protocol.RouteReachability(reachability) | |
| 448 | 446 | return entry, nil | |
| 449 | 447 | } | |
| 450 | 448 | ||
| 451 | 449 | // MarshalRecentRouteSnapshot encodes a complete bounded client route view. | |
| 452 | - | func MarshalRecentRouteSnapshot(snapshot RecentRouteSnapshot) ([]byte, error) { | |
| 450 | + | func MarshalRecentRouteSnapshot(snapshot protocol.RecentRouteSnapshot) ([]byte, error) { | |
| 453 | 451 | if err := validateRecentRouteSnapshot(snapshot); err != nil { | |
| 454 | 452 | return nil, err | |
| 455 | 453 | } | |
| 456 | 454 | w := payloadWriter{} | |
| 457 | 455 | w.putUint64(snapshot.Generation) | |
| 458 | 456 | marshalRouteRef(&w, snapshot.Active) | |
| 459 | - | if !snapshot.Active.empty() { | |
| 457 | + | if !snapshot.Active.IsZero() { | |
| 460 | 458 | marshalRecentRouteEntry(&w, snapshot.ActiveEntry) | |
| 461 | 459 | } | |
| 462 | 460 | marshalRouteRef(&w, snapshot.Previous) | |
| @@ -469,25 +467,25 @@ func MarshalRecentRouteSnapshot(snapshot RecentRouteSnapshot) ([]byte, error) { | |||
| 469 | 467 | // make this unreachable; it protects the wire contract if those bounds | |
| 470 | 468 | // change independently in a future protocol revision. | |
| 471 | 469 | if len(w.b) > MaxFrameLen-1 { | |
| 472 | - | return nil, fmt.Errorf("%w: route snapshot is too large", ErrInvalidRouteWire) | |
| 470 | + | return nil, fmt.Errorf("%w: route snapshot is too large", protocol.ErrInvalidRouteWire) | |
| 473 | 471 | } | |
| 474 | 472 | return w.b, nil | |
| 475 | 473 | } | |
| 476 | 474 | ||
| 477 | - | func validateRouteAttentionSubscription(subscription RouteAttentionSubscription) error { | |
| 478 | - | if len(subscription.Targets) > RouteSnapshotMaxEntries { | |
| 479 | - | return fmt.Errorf("%w: too many attention targets", ErrInvalidRouteWire) | |
| 475 | + | func validateRouteAttentionSubscription(subscription protocol.RouteAttentionSubscription) error { | |
| 476 | + | if len(subscription.Targets) > protocol.RouteSnapshotMaxEntries { | |
| 477 | + | return fmt.Errorf("%w: too many attention targets", protocol.ErrInvalidRouteWire) | |
| 480 | 478 | } | |
| 481 | - | refs := make(map[RouteRef]struct{}, len(subscription.Targets)) | |
| 479 | + | refs := make(map[protocol.RouteRef]struct{}, len(subscription.Targets)) | |
| 482 | 480 | for _, target := range subscription.Targets { | |
| 483 | - | if err := validateRouteRef(target.Ref); err != nil || target.Ref.empty() { | |
| 484 | - | return fmt.Errorf("%w: invalid attention route reference", ErrInvalidRouteWire) | |
| 481 | + | if err := validateRouteRef(target.Ref); err != nil || target.Ref.IsZero() { | |
| 482 | + | return fmt.Errorf("%w: invalid attention route reference", protocol.ErrInvalidRouteWire) | |
| 485 | 483 | } | |
| 486 | 484 | if err := target.Target.Validate(); err != nil { | |
| 487 | - | return fmt.Errorf("%w: invalid attention target: %v", ErrInvalidRouteWire, err) | |
| 485 | + | return fmt.Errorf("%w: invalid attention target: %v", protocol.ErrInvalidRouteWire, err) | |
| 488 | 486 | } | |
| 489 | 487 | if _, exists := refs[target.Ref]; exists { | |
| 490 | - | return fmt.Errorf("%w: duplicate attention route reference", ErrInvalidRouteWire) | |
| 488 | + | return fmt.Errorf("%w: duplicate attention route reference", protocol.ErrInvalidRouteWire) | |
| 491 | 489 | } | |
| 492 | 490 | refs[target.Ref] = struct{}{} | |
| 493 | 491 | } | |
| @@ -496,7 +494,7 @@ func validateRouteAttentionSubscription(subscription RouteAttentionSubscription) | |||
| 496 | 494 | ||
| 497 | 495 | // MarshalRouteAttentionSubscription encodes the bounded client mapping used | |
| 498 | 496 | // by the connected daemon to resolve live route-attention indicators. | |
| 499 | - | func MarshalRouteAttentionSubscription(subscription RouteAttentionSubscription) ([]byte, error) { | |
| 497 | + | func MarshalRouteAttentionSubscription(subscription protocol.RouteAttentionSubscription) ([]byte, error) { | |
| 500 | 498 | if err := validateRouteAttentionSubscription(subscription); err != nil { | |
| 501 | 499 | return nil, err | |
| 502 | 500 | } | |
| @@ -511,96 +509,96 @@ func MarshalRouteAttentionSubscription(subscription RouteAttentionSubscription) | |||
| 511 | 509 | ||
| 512 | 510 | // UnmarshalRouteAttentionSubscription decodes one strict bounded attention | |
| 513 | 511 | // mapping and rejects truncated, malformed, and trailing payloads. | |
| 514 | - | func UnmarshalRouteAttentionSubscription(b []byte) (RouteAttentionSubscription, error) { | |
| 512 | + | func UnmarshalRouteAttentionSubscription(b []byte) (protocol.RouteAttentionSubscription, error) { | |
| 515 | 513 | r := payloadReader{b: b} | |
| 516 | 514 | count, err := r.getUint8() | |
| 517 | 515 | if err != nil { | |
| 518 | - | return RouteAttentionSubscription{}, err | |
| 516 | + | return protocol.RouteAttentionSubscription{}, err | |
| 519 | 517 | } | |
| 520 | - | if int(count) > RouteSnapshotMaxEntries { | |
| 521 | - | return RouteAttentionSubscription{}, fmt.Errorf("%w: too many attention targets", ErrInvalidRouteWire) | |
| 518 | + | if int(count) > protocol.RouteSnapshotMaxEntries { | |
| 519 | + | return protocol.RouteAttentionSubscription{}, fmt.Errorf("%w: too many attention targets", protocol.ErrInvalidRouteWire) | |
| 522 | 520 | } | |
| 523 | - | subscription := RouteAttentionSubscription{Targets: make([]RouteAttentionTarget, 0, int(count))} | |
| 521 | + | subscription := protocol.RouteAttentionSubscription{Targets: make([]protocol.RouteAttentionTarget, 0, int(count))} | |
| 524 | 522 | for range int(count) { | |
| 525 | 523 | ref, err := unmarshalRouteRef(&r) | |
| 526 | 524 | if err != nil { | |
| 527 | - | return RouteAttentionSubscription{}, err | |
| 525 | + | return protocol.RouteAttentionSubscription{}, err | |
| 528 | 526 | } | |
| 529 | 527 | target, err := unmarshalExactSessionTarget(&r) | |
| 530 | 528 | if err != nil { | |
| 531 | - | return RouteAttentionSubscription{}, err | |
| 529 | + | return protocol.RouteAttentionSubscription{}, err | |
| 532 | 530 | } | |
| 533 | - | subscription.Targets = append(subscription.Targets, RouteAttentionTarget{Ref: ref, Target: target}) | |
| 531 | + | subscription.Targets = append(subscription.Targets, protocol.RouteAttentionTarget{Ref: ref, Target: target}) | |
| 534 | 532 | } | |
| 535 | 533 | if err := r.done(); err != nil { | |
| 536 | - | return RouteAttentionSubscription{}, err | |
| 534 | + | return protocol.RouteAttentionSubscription{}, err | |
| 537 | 535 | } | |
| 538 | 536 | if err := validateRouteAttentionSubscription(subscription); err != nil { | |
| 539 | - | return RouteAttentionSubscription{}, err | |
| 537 | + | return protocol.RouteAttentionSubscription{}, err | |
| 540 | 538 | } | |
| 541 | 539 | return subscription, nil | |
| 542 | 540 | } | |
| 543 | 541 | ||
| 544 | 542 | // UnmarshalRecentRouteSnapshot decodes and strictly validates one complete | |
| 545 | 543 | // immutable snapshot, including every referenced active/previous/home entry. | |
| 546 | - | func UnmarshalRecentRouteSnapshot(b []byte) (RecentRouteSnapshot, error) { | |
| 544 | + | func UnmarshalRecentRouteSnapshot(b []byte) (protocol.RecentRouteSnapshot, error) { | |
| 547 | 545 | if len(b) > MaxFrameLen-1 { | |
| 548 | - | return RecentRouteSnapshot{}, ErrInvalidRouteWire | |
| 546 | + | return protocol.RecentRouteSnapshot{}, protocol.ErrInvalidRouteWire | |
| 549 | 547 | } | |
| 550 | 548 | r := payloadReader{b: b} | |
| 551 | - | var snapshot RecentRouteSnapshot | |
| 549 | + | var snapshot protocol.RecentRouteSnapshot | |
| 552 | 550 | var err error | |
| 553 | 551 | if snapshot.Generation, err = r.getUint64(); err != nil { | |
| 554 | - | return RecentRouteSnapshot{}, err | |
| 552 | + | return protocol.RecentRouteSnapshot{}, err | |
| 555 | 553 | } | |
| 556 | 554 | if snapshot.Active, err = unmarshalRouteRef(&r); err != nil { | |
| 557 | - | return RecentRouteSnapshot{}, err | |
| 555 | + | return protocol.RecentRouteSnapshot{}, err | |
| 558 | 556 | } | |
| 559 | - | if !snapshot.Active.empty() { | |
| 557 | + | if !snapshot.Active.IsZero() { | |
| 560 | 558 | if snapshot.ActiveEntry, err = unmarshalRecentRouteEntry(&r); err != nil { | |
| 561 | - | return RecentRouteSnapshot{}, err | |
| 559 | + | return protocol.RecentRouteSnapshot{}, err | |
| 562 | 560 | } | |
| 563 | 561 | } | |
| 564 | 562 | if snapshot.Previous, err = unmarshalRouteRef(&r); err != nil { | |
| 565 | - | return RecentRouteSnapshot{}, err | |
| 563 | + | return protocol.RecentRouteSnapshot{}, err | |
| 566 | 564 | } | |
| 567 | 565 | if snapshot.Home, err = unmarshalRouteRef(&r); err != nil { | |
| 568 | - | return RecentRouteSnapshot{}, err | |
| 566 | + | return protocol.RecentRouteSnapshot{}, err | |
| 569 | 567 | } | |
| 570 | 568 | count, err := r.getUint8() | |
| 571 | 569 | if err != nil { | |
| 572 | - | return RecentRouteSnapshot{}, err | |
| 570 | + | return protocol.RecentRouteSnapshot{}, err | |
| 573 | 571 | } | |
| 574 | - | if int(count) > RouteSnapshotMaxEntries { | |
| 575 | - | return RecentRouteSnapshot{}, fmt.Errorf("%w: too many route entries", ErrInvalidRouteWire) | |
| 572 | + | if int(count) > protocol.RouteSnapshotMaxEntries { | |
| 573 | + | return protocol.RecentRouteSnapshot{}, fmt.Errorf("%w: too many route entries", protocol.ErrInvalidRouteWire) | |
| 576 | 574 | } | |
| 577 | 575 | if count != 0 { | |
| 578 | - | snapshot.Entries = make([]RecentRouteEntry, 0, int(count)) | |
| 576 | + | snapshot.Entries = make([]protocol.RecentRouteEntry, 0, int(count)) | |
| 579 | 577 | } | |
| 580 | 578 | for range int(count) { | |
| 581 | 579 | entry, err := unmarshalRecentRouteEntry(&r) | |
| 582 | 580 | if err != nil { | |
| 583 | - | return RecentRouteSnapshot{}, err | |
| 581 | + | return protocol.RecentRouteSnapshot{}, err | |
| 584 | 582 | } | |
| 585 | 583 | snapshot.Entries = append(snapshot.Entries, entry) | |
| 586 | 584 | } | |
| 587 | 585 | if err := r.done(); err != nil { | |
| 588 | - | return RecentRouteSnapshot{}, err | |
| 586 | + | return protocol.RecentRouteSnapshot{}, err | |
| 589 | 587 | } | |
| 590 | 588 | if err := validateRecentRouteSnapshot(snapshot); err != nil { | |
| 591 | - | return RecentRouteSnapshot{}, err | |
| 589 | + | return protocol.RecentRouteSnapshot{}, err | |
| 592 | 590 | } | |
| 593 | 591 | return snapshot, nil | |
| 594 | 592 | } | |
| 595 | 593 | ||
| 596 | - | func validateRouteNavigationAction(action RouteNavigationAction) error { | |
| 594 | + | func validateRouteNavigationAction(action protocol.RouteNavigationAction) error { | |
| 597 | 595 | if action.SnapshotGeneration == 0 || action.Key == 0 || action.Generation == 0 { | |
| 598 | - | return fmt.Errorf("%w: navigation action identity is zero", ErrInvalidRouteWire) | |
| 596 | + | return fmt.Errorf("%w: navigation action identity is zero", protocol.ErrInvalidRouteWire) | |
| 599 | 597 | } | |
| 600 | 598 | return nil | |
| 601 | 599 | } | |
| 602 | 600 | ||
| 603 | - | func MarshalRouteNavigationAction(action RouteNavigationAction) ([]byte, error) { | |
| 601 | + | func MarshalRouteNavigationAction(action protocol.RouteNavigationAction) ([]byte, error) { | |
| 604 | 602 | if err := validateRouteNavigationAction(action); err != nil { | |
| 605 | 603 | return nil, err | |
| 606 | 604 | } | |
| @@ -611,39 +609,39 @@ func MarshalRouteNavigationAction(action RouteNavigationAction) ([]byte, error) | |||
| 611 | 609 | return w.b, nil | |
| 612 | 610 | } | |
| 613 | 611 | ||
| 614 | - | func UnmarshalRouteNavigationAction(b []byte) (RouteNavigationAction, error) { | |
| 612 | + | func UnmarshalRouteNavigationAction(b []byte) (protocol.RouteNavigationAction, error) { | |
| 615 | 613 | r := payloadReader{b: b} | |
| 616 | - | var action RouteNavigationAction | |
| 614 | + | var action protocol.RouteNavigationAction | |
| 617 | 615 | var err error | |
| 618 | 616 | if action.SnapshotGeneration, err = r.getUint64(); err != nil { | |
| 619 | - | return RouteNavigationAction{}, err | |
| 617 | + | return protocol.RouteNavigationAction{}, err | |
| 620 | 618 | } | |
| 621 | 619 | if action.Key, err = r.getUint64(); err != nil { | |
| 622 | - | return RouteNavigationAction{}, err | |
| 620 | + | return protocol.RouteNavigationAction{}, err | |
| 623 | 621 | } | |
| 624 | 622 | if action.Generation, err = r.getUint64(); err != nil { | |
| 625 | - | return RouteNavigationAction{}, err | |
| 623 | + | return protocol.RouteNavigationAction{}, err | |
| 626 | 624 | } | |
| 627 | 625 | if err := r.done(); err != nil { | |
| 628 | - | return RouteNavigationAction{}, err | |
| 626 | + | return protocol.RouteNavigationAction{}, err | |
| 629 | 627 | } | |
| 630 | 628 | if err := validateRouteNavigationAction(action); err != nil { | |
| 631 | - | return RouteNavigationAction{}, err | |
| 629 | + | return protocol.RouteNavigationAction{}, err | |
| 632 | 630 | } | |
| 633 | 631 | return action, nil | |
| 634 | 632 | } | |
| 635 | 633 | ||
| 636 | - | func validateRouteNavigationFailure(failure RouteNavigationFailure) error { | |
| 634 | + | func validateRouteNavigationFailure(failure protocol.RouteNavigationFailure) error { | |
| 637 | 635 | if failure.Key == 0 || failure.Generation == 0 { | |
| 638 | - | return fmt.Errorf("%w: failure identity is zero", ErrInvalidRouteWire) | |
| 636 | + | return fmt.Errorf("%w: failure identity is zero", protocol.ErrInvalidRouteWire) | |
| 639 | 637 | } | |
| 640 | - | if !failure.Code.valid() { | |
| 641 | - | return fmt.Errorf("%w: invalid failure code", ErrInvalidRouteWire) | |
| 638 | + | if failure.Code.Validate() != nil { | |
| 639 | + | return fmt.Errorf("%w: invalid failure code", protocol.ErrInvalidRouteWire) | |
| 642 | 640 | } | |
| 643 | 641 | return nil | |
| 644 | 642 | } | |
| 645 | 643 | ||
| 646 | - | func MarshalRouteNavigationFailure(failure RouteNavigationFailure) ([]byte, error) { | |
| 644 | + | func MarshalRouteNavigationFailure(failure protocol.RouteNavigationFailure) ([]byte, error) { | |
| 647 | 645 | if err := validateRouteNavigationFailure(failure); err != nil { | |
| 648 | 646 | return nil, err | |
| 649 | 647 | } | |
| @@ -654,26 +652,26 @@ func MarshalRouteNavigationFailure(failure RouteNavigationFailure) ([]byte, erro | |||
| 654 | 652 | return w.b, nil | |
| 655 | 653 | } | |
| 656 | 654 | ||
| 657 | - | func UnmarshalRouteNavigationFailure(b []byte) (RouteNavigationFailure, error) { | |
| 655 | + | func UnmarshalRouteNavigationFailure(b []byte) (protocol.RouteNavigationFailure, error) { | |
| 658 | 656 | r := payloadReader{b: b} | |
| 659 | - | var failure RouteNavigationFailure | |
| 657 | + | var failure protocol.RouteNavigationFailure | |
| 660 | 658 | var err error | |
| 661 | 659 | if failure.Key, err = r.getUint64(); err != nil { | |
| 662 | - | return RouteNavigationFailure{}, err | |
| 660 | + | return protocol.RouteNavigationFailure{}, err | |
| 663 | 661 | } | |
| 664 | 662 | if failure.Generation, err = r.getUint64(); err != nil { | |
| 665 | - | return RouteNavigationFailure{}, err | |
| 663 | + | return protocol.RouteNavigationFailure{}, err | |
| 666 | 664 | } | |
| 667 | 665 | code, err := r.getUint8() | |
| 668 | 666 | if err != nil { | |
| 669 | - | return RouteNavigationFailure{}, err | |
| 667 | + | return protocol.RouteNavigationFailure{}, err | |
| 670 | 668 | } | |
| 671 | - | failure.Code = RouteFailureCode(code) | |
| 669 | + | failure.Code = protocol.RouteFailureCode(code) | |
| 672 | 670 | if err := r.done(); err != nil { | |
| 673 | - | return RouteNavigationFailure{}, err | |
| 671 | + | return protocol.RouteNavigationFailure{}, err | |
| 674 | 672 | } | |
| 675 | 673 | if err := validateRouteNavigationFailure(failure); err != nil { | |
| 676 | - | return RouteNavigationFailure{}, err | |
| 674 | + | return protocol.RouteNavigationFailure{}, err | |
| 677 | 675 | } | |
| 678 | 676 | return failure, nil | |
| 679 | 677 | } | |
M internal/ports/same_peer_switch_test.go +17 -8
| @@ -5,19 +5,20 @@ import ( | |||
| 5 | 5 | "testing" | |
| 6 | 6 | ||
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 9 | ) | |
| 9 | 10 | ||
| 10 | - | func samePeerSwitchTarget() ExactSessionTarget { | |
| 11 | + | func samePeerSwitchTarget() protocol.ExactSessionTarget { | |
| 11 | 12 | var lifecycle domain.SessionLifecycleID | |
| 12 | 13 | lifecycle[0] = 9 | |
| 13 | - | return ExactSessionTarget{LifecycleID: lifecycle, SessionName: "work"} | |
| 14 | + | return protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "work"} | |
| 14 | 15 | } | |
| 15 | 16 | ||
| 16 | 17 | func TestSamePeerSwitchWireStrict(t *testing.T) { | |
| 17 | - | request := SamePeerSwitchRequest{RequestID: 7, Target: samePeerSwitchTarget(), PreferredTabID: "tab-2"} | |
| 18 | + | request := protocol.SamePeerSwitchRequest{RequestID: 7, Target: samePeerSwitchTarget(), PreferredTabID: "tab-2"} | |
| 18 | 19 | requestWire := append([]byte{0, 0, 0, 0, 0, 0, 0, 7, 9}, make([]byte, 15)...) | |
| 19 | 20 | requestWire = append(requestWire, 0, 4, 'w', 'o', 'r', 'k', 0, 5, 't', 'a', 'b', '-', '2') | |
| 20 | - | failure := SamePeerSwitchFailure{RequestID: 7, Code: SamePeerSwitchStaleTarget} | |
| 21 | + | failure := protocol.SamePeerSwitchFailure{RequestID: 7, Code: protocol.SamePeerSwitchStaleTarget} | |
| 21 | 22 | ||
| 22 | 23 | for _, tt := range []struct { | |
| 23 | 24 | name string | |
| @@ -33,7 +34,11 @@ func TestSamePeerSwitchWireStrict(t *testing.T) { | |||
| 33 | 34 | decode: func(payload []byte) (any, error) { return UnmarshalSamePeerSwitchRequest(payload) }, | |
| 34 | 35 | assert: func(t *testing.T, decoded any) { | |
| 35 | 36 | t.Helper() | |
| 36 | - | if got := decoded.(SamePeerSwitchRequest); got != request { | |
| 37 | + | got, ok := decoded.(protocol.SamePeerSwitchRequest) | |
| 38 | + | if !ok { | |
| 39 | + | t.Fatalf("decoded type = %T, want protocol.SamePeerSwitchRequest", decoded) | |
| 40 | + | } | |
| 41 | + | if got != request { | |
| 37 | 42 | t.Fatalf("request = %+v, want %+v", got, request) | |
| 38 | 43 | } | |
| 39 | 44 | }, | |
| @@ -45,7 +50,11 @@ func TestSamePeerSwitchWireStrict(t *testing.T) { | |||
| 45 | 50 | decode: func(payload []byte) (any, error) { return UnmarshalSamePeerSwitchFailure(payload) }, | |
| 46 | 51 | assert: func(t *testing.T, decoded any) { | |
| 47 | 52 | t.Helper() | |
| 48 | - | if got := decoded.(SamePeerSwitchFailure); got != failure { | |
| 53 | + | got, ok := decoded.(protocol.SamePeerSwitchFailure) | |
| 54 | + | if !ok { | |
| 55 | + | t.Fatalf("decoded type = %T, want protocol.SamePeerSwitchFailure", decoded) | |
| 56 | + | } | |
| 57 | + | if got != failure { | |
| 49 | 58 | t.Fatalf("failure = %+v, want %+v", got, failure) | |
| 50 | 59 | } | |
| 51 | 60 | }, | |
| @@ -71,8 +80,8 @@ func TestSamePeerSwitchWireStrict(t *testing.T) { | |||
| 71 | 80 | } | |
| 72 | 81 | ||
| 73 | 82 | func TestSamePeerSwitchWireRejectsInvalidValues(t *testing.T) { | |
| 74 | - | valid := SamePeerSwitchRequest{RequestID: 1, Target: samePeerSwitchTarget()} | |
| 75 | - | for _, request := range []SamePeerSwitchRequest{ | |
| 83 | + | valid := protocol.SamePeerSwitchRequest{RequestID: 1, Target: samePeerSwitchTarget()} | |
| 84 | + | for _, request := range []protocol.SamePeerSwitchRequest{ | |
| 76 | 85 | {}, | |
| 77 | 86 | {RequestID: 1}, | |
| 78 | 87 | {RequestID: 1, Target: samePeerSwitchTarget(), PreferredTabID: "bad tab"}, | |
A internal/ports/session_control.go +323 -0
| @@ -0,0 +1,323 @@ | |||
| 1 | + | package ports | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "errors" | |
| 5 | + | "fmt" | |
| 6 | + | "math" | |
| 7 | + | "time" | |
| 8 | + | ||
| 9 | + | "github.com/bnema/vev/internal/domain" | |
| 10 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | + | ) | |
| 12 | + | ||
| 13 | + | // HandshakeTimeout bounds every transport handshake from connect through the | |
| 14 | + | // first committed publication. | |
| 15 | + | const HandshakeTimeout = 15 * time.Second | |
| 16 | + | ||
| 17 | + | // ProtocolVersion is the current vev IPC wire protocol version. | |
| 18 | + | const ProtocolVersion uint16 = 37 | |
| 19 | + | ||
| 20 | + | // ConnectionCapabilities describes transport behavior relevant to session | |
| 21 | + | // flow without naming a concrete carriage. | |
| 22 | + | type ConnectionCapabilities struct { | |
| 23 | + | OutputDataLimit int | |
| 24 | + | PreferredOutputWindow uint8 | |
| 25 | + | AsyncSend bool | |
| 26 | + | OwnedSynchronousSend bool | |
| 27 | + | LinkState bool | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | var ( | |
| 31 | + | ErrInvalidHello = errors.New("ports: invalid hello") | |
| 32 | + | ErrInvalidAttachTarget = errors.New("ports: invalid attach target") | |
| 33 | + | ErrInvalidEnvironmentPolicy = errors.New("ports: invalid environment policy") | |
| 34 | + | ErrInvalidClientNotice = errors.New("ports: invalid client notice") | |
| 35 | + | ErrInvalidDetached = errors.New("ports: invalid detached reason") | |
| 36 | + | ) | |
| 37 | + | ||
| 38 | + | const ( | |
| 39 | + | IntentEphemeral uint8 = 0 | |
| 40 | + | IntentNew uint8 = 1 | |
| 41 | + | IntentAttach uint8 = 2 | |
| 42 | + | IntentResume uint8 = 3 | |
| 43 | + | ) | |
| 44 | + | ||
| 45 | + | type EnvironmentPolicy uint8 | |
| 46 | + | ||
| 47 | + | const ( | |
| 48 | + | EnvironmentPolicyClientOwned EnvironmentPolicy = iota | |
| 49 | + | EnvironmentPolicyDaemonOwned | |
| 50 | + | ) | |
| 51 | + | ||
| 52 | + | const ( | |
| 53 | + | CapabilityResume uint32 = 1 << 0 | |
| 54 | + | CapabilityUDP uint32 = 1 << 1 | |
| 55 | + | CapabilityPredict uint32 = 1 << 2 | |
| 56 | + | ) | |
| 57 | + | ||
| 58 | + | const ( | |
| 59 | + | ErrVersionMismatch uint16 = 1 | |
| 60 | + | ErrNoSuchSession uint16 = 2 | |
| 61 | + | ErrNameTaken uint16 = 3 | |
| 62 | + | ErrServerShutdown uint16 = 4 | |
| 63 | + | ErrInvalidSessionName uint16 = 5 | |
| 64 | + | ErrUnknownCommand uint16 = 6 | |
| 65 | + | ErrNotScriptable uint16 = 7 | |
| 66 | + | ErrInvalidCommandArgs uint16 = 8 | |
| 67 | + | ErrNoSuchTarget uint16 = 9 | |
| 68 | + | ErrAmbiguousTarget uint16 = 10 | |
| 69 | + | ErrInternal uint16 = 255 | |
| 70 | + | ) | |
| 71 | + | ||
| 72 | + | const ( | |
| 73 | + | ReasonDetach uint8 = 0 | |
| 74 | + | ReasonSessionKilled uint8 = 1 | |
| 75 | + | ReasonServerShutdown uint8 = 2 | |
| 76 | + | ReasonReplaced uint8 = 3 | |
| 77 | + | ) | |
| 78 | + | ||
| 79 | + | // Hello is sent by the client immediately after connecting. | |
| 80 | + | type Hello struct { | |
| 81 | + | Version uint16 | |
| 82 | + | Intent uint8 | |
| 83 | + | ClientID [16]byte | |
| 84 | + | ResumeToken uint64 | |
| 85 | + | Name string | |
| 86 | + | Size domain.Size | |
| 87 | + | PixelWidth int | |
| 88 | + | PixelHeight int | |
| 89 | + | TermEnv string | |
| 90 | + | Cwd string | |
| 91 | + | TrueColor bool | |
| 92 | + | // KittyDirectGraphics is an explicit declaration that the client has | |
| 93 | + | // probed its direct outer terminal and it accepts Kitty graphics output. | |
| 94 | + | KittyDirectGraphics bool | |
| 95 | + | MaxOutputInFlight uint8 | |
| 96 | + | Env []string | |
| 97 | + | RemoteTarget *domain.RemoteSessionTarget | |
| 98 | + | ExactTarget *protocol.ExactSessionTarget | |
| 99 | + | PreferredTabID domain.TabStableID | |
| 100 | + | EnvironmentPolicy EnvironmentPolicy | |
| 101 | + | NavigationCapabilities protocol.NavigationCapabilities | |
| 102 | + | StartupOverlay protocol.StartupOverlay | |
| 103 | + | Remote bool | |
| 104 | + | } | |
| 105 | + | ||
| 106 | + | func (h Hello) Geometry() domain.Geometry { | |
| 107 | + | return domain.Geometry{Size: h.Size, PixelWidth: h.PixelWidth, PixelHeight: h.PixelHeight}.NormalizePixels() | |
| 108 | + | } | |
| 109 | + | ||
| 110 | + | type Input struct { | |
| 111 | + | InputSeq uint64 | |
| 112 | + | Data []byte | |
| 113 | + | } | |
| 114 | + | ||
| 115 | + | type ClientNotice struct{ Action uint8 } | |
| 116 | + | ||
| 117 | + | const ( | |
| 118 | + | ClientNoticeClipboardFallback uint8 = 1 | |
| 119 | + | ClientNoticeClipboardTooLarge uint8 = 2 | |
| 120 | + | ClientNoticeLinkDegraded uint8 = 3 | |
| 121 | + | ClientNoticeLinkConnected uint8 = 4 | |
| 122 | + | ) | |
| 123 | + | ||
| 124 | + | type Detach struct{} | |
| 125 | + | type Ping struct{} | |
| 126 | + | type Pong struct{} | |
| 127 | + | ||
| 128 | + | type Welcome struct { | |
| 129 | + | SessionID string | |
| 130 | + | SessionName string | |
| 131 | + | Ephemeral bool | |
| 132 | + | ResumeToken uint64 | |
| 133 | + | Capabilities uint32 | |
| 134 | + | CommittedIdentity *protocol.CommittedRouteIdentity | |
| 135 | + | } | |
| 136 | + | ||
| 137 | + | type ErrorMsg struct { | |
| 138 | + | Code uint16 | |
| 139 | + | Text string | |
| 140 | + | } | |
| 141 | + | ||
| 142 | + | type AttachTarget struct { | |
| 143 | + | Endpoint string | |
| 144 | + | Session string | |
| 145 | + | Intent uint8 | |
| 146 | + | RemoteTarget *domain.RemoteSessionTarget | |
| 147 | + | ExactTarget *protocol.ExactSessionTarget | |
| 148 | + | EnvironmentPolicy EnvironmentPolicy | |
| 149 | + | SamePeer bool | |
| 150 | + | } | |
| 151 | + | ||
| 152 | + | type Detached struct{ Reason uint8 } | |
| 153 | + | type List struct{} | |
| 154 | + | ||
| 155 | + | type Kill struct { | |
| 156 | + | Name string | |
| 157 | + | All bool | |
| 158 | + | } | |
| 159 | + | ||
| 160 | + | type SessionState uint8 | |
| 161 | + | ||
| 162 | + | const ( | |
| 163 | + | SessionUp SessionState = iota | |
| 164 | + | SessionDown | |
| 165 | + | SessionBroken | |
| 166 | + | ) | |
| 167 | + | ||
| 168 | + | type SessionInfo struct { | |
| 169 | + | SessionID string | |
| 170 | + | Name string | |
| 171 | + | State SessionState | |
| 172 | + | Ephemeral bool | |
| 173 | + | Tabs uint16 | |
| 174 | + | Attached bool | |
| 175 | + | } | |
| 176 | + | ||
| 177 | + | type Sessions struct{ Sessions []SessionInfo } | |
| 178 | + | type OutputResetRequest struct{} | |
| 179 | + | ||
| 180 | + | func validEnvironmentPolicy(policy EnvironmentPolicy) bool { | |
| 181 | + | return policy == EnvironmentPolicyClientOwned || policy == EnvironmentPolicyDaemonOwned | |
| 182 | + | } | |
| 183 | + | ||
| 184 | + | func validClientNoticeAction(action uint8) bool { | |
| 185 | + | switch action { | |
| 186 | + | case ClientNoticeClipboardFallback, ClientNoticeClipboardTooLarge, ClientNoticeLinkDegraded, ClientNoticeLinkConnected: | |
| 187 | + | return true | |
| 188 | + | default: | |
| 189 | + | return false | |
| 190 | + | } | |
| 191 | + | } | |
| 192 | + | ||
| 193 | + | func validDetachedReason(reason uint8) bool { | |
| 194 | + | switch reason { | |
| 195 | + | case ReasonDetach, ReasonSessionKilled, ReasonServerShutdown, ReasonReplaced: | |
| 196 | + | return true | |
| 197 | + | default: | |
| 198 | + | return false | |
| 199 | + | } | |
| 200 | + | } | |
| 201 | + | ||
| 202 | + | func ValidateEnvironmentPolicy(policy EnvironmentPolicy) error { | |
| 203 | + | if !validEnvironmentPolicy(policy) { | |
| 204 | + | return ErrInvalidEnvironmentPolicy | |
| 205 | + | } | |
| 206 | + | return nil | |
| 207 | + | } | |
| 208 | + | ||
| 209 | + | func ValidateClientNotice(m ClientNotice) error { | |
| 210 | + | if !validClientNoticeAction(m.Action) { | |
| 211 | + | return ErrInvalidClientNotice | |
| 212 | + | } | |
| 213 | + | return nil | |
| 214 | + | } | |
| 215 | + | ||
| 216 | + | func ValidateDetached(m Detached) error { | |
| 217 | + | if !validDetachedReason(m.Reason) { | |
| 218 | + | return ErrInvalidDetached | |
| 219 | + | } | |
| 220 | + | return nil | |
| 221 | + | } | |
| 222 | + | ||
| 223 | + | func validateHelloNavigation(h Hello) error { | |
| 224 | + | if h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 225 | + | if h.NavigationCapabilities != 0 || h.StartupOverlay != protocol.StartupOverlayNone { | |
| 226 | + | return protocol.ErrInvalidNavigation | |
| 227 | + | } | |
| 228 | + | return nil | |
| 229 | + | } | |
| 230 | + | return protocol.ValidateNavigation(h.NavigationCapabilities, h.StartupOverlay, h.RemoteTarget != nil || h.EnvironmentPolicy == EnvironmentPolicyDaemonOwned) | |
| 231 | + | } | |
| 232 | + | ||
| 233 | + | func ValidateHello(h Hello) error { | |
| 234 | + | if h.Intent != IntentEphemeral && h.Intent != IntentNew && h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 235 | + | return ErrInvalidHello | |
| 236 | + | } | |
| 237 | + | if err := protocol.ValidateGeometry(domain.Geometry{Size: h.Size, PixelWidth: h.PixelWidth, PixelHeight: h.PixelHeight}); err != nil { | |
| 238 | + | return fmt.Errorf("%w: geometry", ErrInvalidHello) | |
| 239 | + | } | |
| 240 | + | if !validEnvironmentPolicy(h.EnvironmentPolicy) { | |
| 241 | + | return ErrInvalidHello | |
| 242 | + | } | |
| 243 | + | if err := validateHelloNavigation(h); err != nil { | |
| 244 | + | return fmt.Errorf("%w: navigation: %w", ErrInvalidHello, err) | |
| 245 | + | } | |
| 246 | + | if len(h.Name) > math.MaxUint16 || len(h.TermEnv) > math.MaxUint16 || len(h.Cwd) > math.MaxUint16 || len(h.Env) > math.MaxUint32 { | |
| 247 | + | return ErrInvalidHello | |
| 248 | + | } | |
| 249 | + | for _, entry := range h.Env { | |
| 250 | + | if uint64(len(entry)) > math.MaxUint32 { | |
| 251 | + | return ErrInvalidHello | |
| 252 | + | } | |
| 253 | + | } | |
| 254 | + | if h.PreferredTabID != "" { | |
| 255 | + | if h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 256 | + | return ErrInvalidHello | |
| 257 | + | } | |
| 258 | + | if err := domain.ValidateTabStableID(h.PreferredTabID); err != nil { | |
| 259 | + | return fmt.Errorf("%w: preferred tab: %v", ErrInvalidHello, err) | |
| 260 | + | } | |
| 261 | + | } | |
| 262 | + | if h.ExactTarget != nil { | |
| 263 | + | if h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 264 | + | return ErrInvalidHello | |
| 265 | + | } | |
| 266 | + | if err := h.ExactTarget.Validate(); err != nil { | |
| 267 | + | return fmt.Errorf("%w: exact target: %v", ErrInvalidHello, err) | |
| 268 | + | } | |
| 269 | + | if h.Name != h.ExactTarget.SessionName { | |
| 270 | + | return ErrInvalidHello | |
| 271 | + | } | |
| 272 | + | if h.RemoteTarget != nil && (h.RemoteTarget.LifecycleID != h.ExactTarget.LifecycleID || h.RemoteTarget.SessionName != h.ExactTarget.SessionName) { | |
| 273 | + | return ErrInvalidHello | |
| 274 | + | } | |
| 275 | + | } | |
| 276 | + | if h.RemoteTarget == nil { | |
| 277 | + | return nil | |
| 278 | + | } | |
| 279 | + | if h.EnvironmentPolicy != EnvironmentPolicyDaemonOwned || (h.Intent != IntentAttach && h.Intent != IntentResume) { | |
| 280 | + | return ErrInvalidHello | |
| 281 | + | } | |
| 282 | + | if err := validateWireRemoteTarget(*h.RemoteTarget); err != nil { | |
| 283 | + | return fmt.Errorf("%w: remote target: %v", ErrInvalidHello, err) | |
| 284 | + | } | |
| 285 | + | if h.Name != h.RemoteTarget.SessionName { | |
| 286 | + | return ErrInvalidHello | |
| 287 | + | } | |
| 288 | + | return nil | |
| 289 | + | } | |
| 290 | + | ||
| 291 | + | func ValidateAttachTarget(m AttachTarget) error { | |
| 292 | + | if m.Session == "" || len(m.Endpoint) > math.MaxUint16 || len(m.Session) > math.MaxUint16 { | |
| 293 | + | return ErrInvalidAttachTarget | |
| 294 | + | } | |
| 295 | + | if err := domain.ValidateSessionName(m.Session); err != nil { | |
| 296 | + | return ErrInvalidAttachTarget | |
| 297 | + | } | |
| 298 | + | if m.Intent != IntentEphemeral && m.Intent != IntentNew && m.Intent != IntentAttach && m.Intent != IntentResume { | |
| 299 | + | return ErrInvalidAttachTarget | |
| 300 | + | } | |
| 301 | + | if m.Intent == IntentResume || !validEnvironmentPolicy(m.EnvironmentPolicy) { | |
| 302 | + | return ErrInvalidAttachTarget | |
| 303 | + | } | |
| 304 | + | if m.ExactTarget != nil && (m.ExactTarget.SessionName != m.Session || m.ExactTarget.Validate() != nil) { | |
| 305 | + | return ErrInvalidAttachTarget | |
| 306 | + | } | |
| 307 | + | if m.SamePeer && (m.Endpoint != "" || m.RemoteTarget != nil || m.ExactTarget == nil) { | |
| 308 | + | return ErrInvalidAttachTarget | |
| 309 | + | } | |
| 310 | + | if m.RemoteTarget == nil { | |
| 311 | + | return nil | |
| 312 | + | } | |
| 313 | + | if m.EnvironmentPolicy != EnvironmentPolicyDaemonOwned || m.Intent != IntentAttach { | |
| 314 | + | return ErrInvalidAttachTarget | |
| 315 | + | } | |
| 316 | + | if err := validateWireRemoteTarget(*m.RemoteTarget); err != nil { | |
| 317 | + | return fmt.Errorf("%w: remote target: %v", ErrInvalidAttachTarget, err) | |
| 318 | + | } | |
| 319 | + | if m.Endpoint != m.RemoteTarget.Endpoint || m.Session != m.RemoteTarget.SessionName { | |
| 320 | + | return ErrInvalidAttachTarget | |
| 321 | + | } | |
| 322 | + | return nil | |
| 323 | + | } | |
M internal/ports/wire.go +125 -601
| @@ -18,6 +18,7 @@ import ( | |||
| 18 | 18 | ||
| 19 | 19 | renderer "github.com/bnema/vev-vt" | |
| 20 | 20 | "github.com/bnema/vev/internal/domain" | |
| 21 | + | "github.com/bnema/vev/internal/protocol" | |
| 21 | 22 | ) | |
| 22 | 23 | ||
| 23 | 24 | // errShortPayload is returned when a payload ends before a required field | |
| @@ -53,338 +54,6 @@ var outputCompressorPool = sync.Pool{New: func() any { | |||
| 53 | 54 | return writer | |
| 54 | 55 | }} | |
| 55 | 56 | ||
| 56 | - | // ErrInvalidSize reports a terminal size that cannot be represented by the | |
| 57 | - | // protocol or would exceed the bounded screen area. | |
| 58 | - | var ErrInvalidSize = errors.New("ports: invalid terminal size") | |
| 59 | - | ||
| 60 | - | // ErrInvalidHello reports a malformed Hello semantic value. | |
| 61 | - | var ErrInvalidHello = errors.New("ports: invalid hello") | |
| 62 | - | ||
| 63 | - | // ErrInvalidOutput reports a malformed Output semantic value. | |
| 64 | - | var ErrInvalidOutput = errors.New("ports: invalid output") | |
| 65 | - | ||
| 66 | - | // ErrInvalidAck reports a malformed Ack semantic value. | |
| 67 | - | var ErrInvalidAck = errors.New("ports: invalid ack") | |
| 68 | - | ||
| 69 | - | // ErrInvalidAttachTarget reports a malformed attach target. | |
| 70 | - | var ErrInvalidAttachTarget = errors.New("ports: invalid attach target") | |
| 71 | - | ||
| 72 | - | // ErrInvalidNavigation reports an unknown or impossible navigation value. | |
| 73 | - | var ErrInvalidNavigation = errors.New("ports: invalid navigation") | |
| 74 | - | ||
| 75 | - | // Intent values carried by Hello, describing what the client wants to do. | |
| 76 | - | const ( | |
| 77 | - | IntentEphemeral uint8 = 0 | |
| 78 | - | IntentNew uint8 = 1 | |
| 79 | - | IntentAttach uint8 = 2 | |
| 80 | - | IntentResume uint8 = 3 | |
| 81 | - | ) | |
| 82 | - | ||
| 83 | - | // EnvironmentPolicy controls which side owns the environment used for future | |
| 84 | - | // PTY children. Direct CLI attaches keep the historical client-owned policy; | |
| 85 | - | // picker handoffs use daemon ownership so a local environment cannot leak into | |
| 86 | - | // a remote daemon. | |
| 87 | - | type EnvironmentPolicy uint8 | |
| 88 | - | ||
| 89 | - | const ( | |
| 90 | - | EnvironmentPolicyClientOwned EnvironmentPolicy = iota | |
| 91 | - | EnvironmentPolicyDaemonOwned | |
| 92 | - | ) | |
| 93 | - | ||
| 94 | - | func validEnvironmentPolicy(policy EnvironmentPolicy) bool { | |
| 95 | - | return policy == EnvironmentPolicyClientOwned || policy == EnvironmentPolicyDaemonOwned | |
| 96 | - | } | |
| 97 | - | ||
| 98 | - | func validNavigationCapabilities(capabilities NavigationCapabilities) bool { | |
| 99 | - | return capabilities&^(NavigationCapabilityHomePicker|NavigationCapabilityBack) == 0 | |
| 100 | - | } | |
| 101 | - | ||
| 102 | - | func validStartupOverlay(overlay StartupOverlay) bool { | |
| 103 | - | return overlay == StartupOverlayNone || overlay == StartupOverlaySessionPicker | |
| 104 | - | } | |
| 105 | - | ||
| 106 | - | // ValidateNavigation validates route capabilities independently of the rest of | |
| 107 | - | // the Hello payload. homePickerRoute indicates that the route may open its | |
| 108 | - | // home/session picker (for example, a remote target or daemon-owned route). | |
| 109 | - | func ValidateNavigation(capabilities NavigationCapabilities, overlay StartupOverlay, homePickerRoute bool) error { | |
| 110 | - | if !validNavigationCapabilities(capabilities) || !validStartupOverlay(overlay) { | |
| 111 | - | return ErrInvalidNavigation | |
| 112 | - | } | |
| 113 | - | home := capabilities&NavigationCapabilityHomePicker != 0 | |
| 114 | - | back := capabilities&NavigationCapabilityBack != 0 | |
| 115 | - | if (home && !homePickerRoute) || back != (overlay == StartupOverlaySessionPicker) { | |
| 116 | - | return ErrInvalidNavigation | |
| 117 | - | } | |
| 118 | - | if homePickerRoute && back { | |
| 119 | - | return ErrInvalidNavigation | |
| 120 | - | } | |
| 121 | - | return nil | |
| 122 | - | } | |
| 123 | - | ||
| 124 | - | func validateHelloNavigation(h Hello) error { | |
| 125 | - | if h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 126 | - | if h.NavigationCapabilities != 0 || h.StartupOverlay != StartupOverlayNone { | |
| 127 | - | return ErrInvalidNavigation | |
| 128 | - | } | |
| 129 | - | return nil | |
| 130 | - | } | |
| 131 | - | return ValidateNavigation(h.NavigationCapabilities, h.StartupOverlay, h.RemoteTarget != nil || h.EnvironmentPolicy == EnvironmentPolicyDaemonOwned) | |
| 132 | - | } | |
| 133 | - | ||
| 134 | - | // Capability bits advertised in Welcome. | |
| 135 | - | const ( | |
| 136 | - | CapabilityResume uint32 = 1 << 0 | |
| 137 | - | CapabilityUDP uint32 = 1 << 1 | |
| 138 | - | CapabilityPredict uint32 = 1 << 2 | |
| 139 | - | ) | |
| 140 | - | ||
| 141 | - | // ErrorMsg codes. | |
| 142 | - | const ( | |
| 143 | - | ErrVersionMismatch uint16 = 1 | |
| 144 | - | ErrNoSuchSession uint16 = 2 | |
| 145 | - | ErrNameTaken uint16 = 3 | |
| 146 | - | ErrServerShutdown uint16 = 4 | |
| 147 | - | ErrInvalidSessionName uint16 = 5 | |
| 148 | - | ErrUnknownCommand uint16 = 6 | |
| 149 | - | ErrNotScriptable uint16 = 7 | |
| 150 | - | ErrInvalidCommandArgs uint16 = 8 | |
| 151 | - | ErrNoSuchTarget uint16 = 9 | |
| 152 | - | ErrAmbiguousTarget uint16 = 10 | |
| 153 | - | ErrInternal uint16 = 255 | |
| 154 | - | ) | |
| 155 | - | ||
| 156 | - | // Detached reasons. | |
| 157 | - | const ( | |
| 158 | - | ReasonDetach uint8 = 0 | |
| 159 | - | ReasonSessionKilled uint8 = 1 | |
| 160 | - | ReasonServerShutdown uint8 = 2 | |
| 161 | - | ReasonReplaced uint8 = 3 | |
| 162 | - | ) | |
| 163 | - | ||
| 164 | - | // Hello is sent by the client immediately after connecting. | |
| 165 | - | type Hello struct { | |
| 166 | - | Version uint16 | |
| 167 | - | Intent uint8 | |
| 168 | - | ClientID [16]byte | |
| 169 | - | ResumeToken uint64 | |
| 170 | - | Name string | |
| 171 | - | Size domain.Size | |
| 172 | - | PixelWidth int | |
| 173 | - | PixelHeight int | |
| 174 | - | TermEnv string | |
| 175 | - | Cwd string | |
| 176 | - | TrueColor bool | |
| 177 | - | // KittyDirectGraphics is an explicit declaration that the client has | |
| 178 | - | // probed its direct outer terminal and it accepts Kitty graphics output. | |
| 179 | - | // Environment values are never sufficient to set this capability. | |
| 180 | - | KittyDirectGraphics bool | |
| 181 | - | // MaxOutputInFlight is the requested maximum number of unacknowledged | |
| 182 | - | // state-bearing output frames. | |
| 183 | - | MaxOutputInFlight uint8 | |
| 184 | - | // Env is the complete exported client environment for future PTY children. | |
| 185 | - | // Entries are opaque strings so their ordering and contents are preserved. | |
| 186 | - | Env []string | |
| 187 | - | // RemoteTarget is present only for a picker-selected remote attach. It is | |
| 188 | - | // carried through reconnects and is validated by the owning daemon before | |
| 189 | - | // it creates or publishes any session resources. | |
| 190 | - | RemoteTarget *domain.RemoteSessionTarget | |
| 191 | - | // ExactTarget is an optional lifecycle/name identity selected by the client | |
| 192 | - | // ledger. It is transport-neutral and never replaces the daemon's authority | |
| 193 | - | // to validate or commit the target. | |
| 194 | - | ExactTarget *ExactSessionTarget | |
| 195 | - | // PreferredTabID is a client-owned route cursor. The daemon treats it as an | |
| 196 | - | // attachment-local hint and falls back when the stable tab no longer exists. | |
| 197 | - | PreferredTabID domain.TabStableID | |
| 198 | - | EnvironmentPolicy EnvironmentPolicy | |
| 199 | - | NavigationCapabilities NavigationCapabilities | |
| 200 | - | StartupOverlay StartupOverlay | |
| 201 | - | // Remote identifies a direct remote carriage even when no exact picker | |
| 202 | - | // target is present. It is daemon-facing so remote rendering backends can | |
| 203 | - | // be disabled consistently for both direct and picker attaches. | |
| 204 | - | Remote bool | |
| 205 | - | } | |
| 206 | - | ||
| 207 | - | // Input carries raw bytes typed/pasted by the client, destined for the PTY. | |
| 208 | - | type Input struct { | |
| 209 | - | InputSeq uint64 | |
| 210 | - | Data []byte | |
| 211 | - | } | |
| 212 | - | ||
| 213 | - | // Geometry returns the complete controlling-terminal geometry carried by the | |
| 214 | - | // handshake. Pixel dimensions are optional as a pair. | |
| 215 | - | func (h Hello) Geometry() domain.Geometry { | |
| 216 | - | return domain.Geometry{Size: h.Size, PixelWidth: h.PixelWidth, PixelHeight: h.PixelHeight}.NormalizePixels() | |
| 217 | - | } | |
| 218 | - | ||
| 219 | - | // Resize notifies the daemon of a client-side terminal geometry change. | |
| 220 | - | type Resize struct { | |
| 221 | - | Size domain.Size | |
| 222 | - | PixelWidth int | |
| 223 | - | PixelHeight int | |
| 224 | - | } | |
| 225 | - | ||
| 226 | - | // Geometry returns the complete controlling-terminal geometry carried by the | |
| 227 | - | // resize message. Pixel dimensions are optional as a pair. | |
| 228 | - | func (m Resize) Geometry() domain.Geometry { | |
| 229 | - | return domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}.NormalizePixels() | |
| 230 | - | } | |
| 231 | - | ||
| 232 | - | // Theme reports the client's terminal foreground/background colors, ANSI | |
| 233 | - | // palette entries, and whether the client terminal supports truecolor. | |
| 234 | - | type Theme struct { | |
| 235 | - | HasForeground bool | |
| 236 | - | Foreground renderer.RGB | |
| 237 | - | HasBackground bool | |
| 238 | - | Background renderer.RGB | |
| 239 | - | TrueColor bool | |
| 240 | - | SchemeKnown bool | |
| 241 | - | Light bool | |
| 242 | - | PaletteKnown uint16 | |
| 243 | - | Palette [16]renderer.RGB | |
| 244 | - | } | |
| 245 | - | ||
| 246 | - | // ImagePush carries a clipboard image from a remote client, to be written to | |
| 247 | - | // a temp file and injected into the focused pane's PTY as a path (see | |
| 248 | - | // docs/superpowers/specs/2026-07-04-clipboard-image-transfer-design.md). | |
| 249 | - | type ImagePush struct { | |
| 250 | - | InputSeq uint64 | |
| 251 | - | Mime string | |
| 252 | - | Data []byte | |
| 253 | - | } | |
| 254 | - | ||
| 255 | - | // ClientNotice reports a fixed client-side event for daemon-rendered user | |
| 256 | - | // feedback. Action values are deliberately closed so a client cannot inject | |
| 257 | - | // arbitrary display text into a shared session. | |
| 258 | - | type ClientNotice struct { | |
| 259 | - | Action uint8 | |
| 260 | - | } | |
| 261 | - | ||
| 262 | - | const ( | |
| 263 | - | ClientNoticeClipboardFallback uint8 = 1 | |
| 264 | - | ClientNoticeClipboardTooLarge uint8 = 2 | |
| 265 | - | ClientNoticeLinkDegraded uint8 = 3 | |
| 266 | - | ClientNoticeLinkConnected uint8 = 4 | |
| 267 | - | ) | |
| 268 | - | ||
| 269 | - | func validClientNoticeAction(action uint8) bool { | |
| 270 | - | switch action { | |
| 271 | - | case ClientNoticeClipboardFallback, ClientNoticeClipboardTooLarge, ClientNoticeLinkDegraded, ClientNoticeLinkConnected: | |
| 272 | - | return true | |
| 273 | - | default: | |
| 274 | - | return false | |
| 275 | - | } | |
| 276 | - | } | |
| 277 | - | ||
| 278 | - | func validDetachedReason(reason uint8) bool { | |
| 279 | - | switch reason { | |
| 280 | - | case ReasonDetach, ReasonSessionKilled, ReasonServerShutdown, ReasonReplaced: | |
| 281 | - | return true | |
| 282 | - | default: | |
| 283 | - | return false | |
| 284 | - | } | |
| 285 | - | } | |
| 286 | - | ||
| 287 | - | // Detach asks the daemon to detach the current client without killing the | |
| 288 | - | // session. | |
| 289 | - | type Detach struct{} | |
| 290 | - | ||
| 291 | - | // Ping is a keepalive/liveness probe sent by either side. | |
| 292 | - | type Ping struct{} | |
| 293 | - | ||
| 294 | - | // Pong answers a Ping. | |
| 295 | - | type Pong struct{} | |
| 296 | - | ||
| 297 | - | // Ack acknowledges receipt/application of an output state in one output epoch. | |
| 298 | - | type Ack struct { | |
| 299 | - | Epoch uint64 | |
| 300 | - | State uint64 | |
| 301 | - | } | |
| 302 | - | ||
| 303 | - | // Welcome is the daemon's reply to a successful Hello. | |
| 304 | - | type Welcome struct { | |
| 305 | - | SessionID string | |
| 306 | - | SessionName string | |
| 307 | - | Ephemeral bool | |
| 308 | - | ResumeToken uint64 | |
| 309 | - | Capabilities uint32 | |
| 310 | - | CommittedIdentity *CommittedRouteIdentity | |
| 311 | - | } | |
| 312 | - | ||
| 313 | - | // ErrorMsg reports a protocol- or session-level failure to the client. | |
| 314 | - | type ErrorMsg struct { | |
| 315 | - | Code uint16 | |
| 316 | - | Text string | |
| 317 | - | } | |
| 318 | - | ||
| 319 | - | // Output carries one ordered output publication for an attachment. | |
| 320 | - | type Output struct { | |
| 321 | - | Epoch uint64 | |
| 322 | - | Base uint64 | |
| 323 | - | New uint64 | |
| 324 | - | Echo uint64 | |
| 325 | - | ViewRevision uint64 | |
| 326 | - | Size domain.Size | |
| 327 | - | Full bool | |
| 328 | - | Data []byte | |
| 329 | - | } | |
| 330 | - | ||
| 331 | - | // AttachTarget identifies the endpoint and exact session/tab selected for a | |
| 332 | - | // new attachment. Endpoint and Session remain the compatibility route fields; | |
| 333 | - | // RemoteTarget is the authoritative picker identity when non-nil. | |
| 334 | - | type AttachTarget struct { | |
| 335 | - | Endpoint string | |
| 336 | - | Session string | |
| 337 | - | Intent uint8 | |
| 338 | - | RemoteTarget *domain.RemoteSessionTarget | |
| 339 | - | ExactTarget *ExactSessionTarget | |
| 340 | - | EnvironmentPolicy EnvironmentPolicy | |
| 341 | - | SamePeer bool | |
| 342 | - | } | |
| 343 | - | ||
| 344 | - | // Detached tells a client it has been disconnected from its session and why. | |
| 345 | - | type Detached struct { | |
| 346 | - | Reason uint8 | |
| 347 | - | } | |
| 348 | - | ||
| 349 | - | // List asks the daemon to enumerate its live sessions. It carries no | |
| 350 | - | // fields; the request is fully described by its message type. | |
| 351 | - | type List struct{} | |
| 352 | - | ||
| 353 | - | // Kill asks the daemon to terminate one named session or all sessions. | |
| 354 | - | type Kill struct { | |
| 355 | - | Name string | |
| 356 | - | All bool | |
| 357 | - | } | |
| 358 | - | ||
| 359 | - | // SessionState is the client-visible lifecycle state of a session. | |
| 360 | - | type SessionState uint8 | |
| 361 | - | ||
| 362 | - | const ( | |
| 363 | - | SessionUp SessionState = iota | |
| 364 | - | SessionDown | |
| 365 | - | SessionBroken | |
| 366 | - | ) | |
| 367 | - | ||
| 368 | - | // SessionInfo describes one session in a Sessions listing. | |
| 369 | - | type SessionInfo struct { | |
| 370 | - | SessionID string | |
| 371 | - | Name string | |
| 372 | - | State SessionState | |
| 373 | - | Ephemeral bool | |
| 374 | - | Tabs uint16 | |
| 375 | - | Attached bool | |
| 376 | - | } | |
| 377 | - | ||
| 378 | - | // Sessions is the daemon's reply to a List, enumerating live sessions. | |
| 379 | - | type Sessions struct { | |
| 380 | - | Sessions []SessionInfo | |
| 381 | - | } | |
| 382 | - | ||
| 383 | - | // OutputResetRequest asks a remote output stream to rebase. | |
| 384 | - | type OutputResetRequest struct{} | |
| 385 | - | ||
| 386 | - | // SessionTabMeta describes one tab in a remote session's metadata snapshot. | |
| 387 | - | // ID is stable for the lifetime of its remote tab and ordered only for display. | |
| 388 | 57 | // payloadWriter builds a message payload by appending fields in wire order. | |
| 389 | 58 | type payloadWriter struct { | |
| 390 | 59 | b []byte | |
| @@ -521,7 +190,7 @@ func skipRemoteTargetSection(r *payloadReader) error { | |||
| 521 | 190 | if err != nil { | |
| 522 | 191 | return err | |
| 523 | 192 | } | |
| 524 | - | if !validEnvironmentPolicy(EnvironmentPolicy(policy)) { | |
| 193 | + | if ValidateEnvironmentPolicy(EnvironmentPolicy(policy)) != nil { | |
| 525 | 194 | return errInvalidEnum | |
| 526 | 195 | } | |
| 527 | 196 | return nil | |
| @@ -596,7 +265,7 @@ func unmarshalRemoteTargetSection(r *payloadReader) (*domain.RemoteSessionTarget | |||
| 596 | 265 | if err != nil { | |
| 597 | 266 | return nil, 0, err | |
| 598 | 267 | } | |
| 599 | - | if !validEnvironmentPolicy(EnvironmentPolicy(policy)) { | |
| 268 | + | if ValidateEnvironmentPolicy(EnvironmentPolicy(policy)) != nil { | |
| 600 | 269 | return nil, 0, errInvalidEnum | |
| 601 | 270 | } | |
| 602 | 271 | return target, EnvironmentPolicy(policy), nil | |
| @@ -753,141 +422,14 @@ func PeekHelloVersion(b []byte) (uint16, bool) { | |||
| 753 | 422 | ||
| 754 | 423 | // ValidateHello validates Hello semantics without retaining or allocating any | |
| 755 | 424 | // payload data. | |
| 756 | - | func ValidateHello(h Hello) error { | |
| 757 | - | if h.Intent != IntentEphemeral && h.Intent != IntentNew && h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 758 | - | return ErrInvalidHello | |
| 759 | - | } | |
| 760 | - | if err := ValidateGeometry(domain.Geometry{Size: h.Size, PixelWidth: h.PixelWidth, PixelHeight: h.PixelHeight}); err != nil { | |
| 761 | - | return fmt.Errorf("%w: geometry", ErrInvalidHello) | |
| 762 | - | } | |
| 763 | - | if !validEnvironmentPolicy(h.EnvironmentPolicy) { | |
| 764 | - | return ErrInvalidHello | |
| 765 | - | } | |
| 766 | - | if err := validateHelloNavigation(h); err != nil { | |
| 767 | - | return fmt.Errorf("%w: navigation: %w", ErrInvalidHello, err) | |
| 768 | - | } | |
| 769 | - | if len(h.Name) > math.MaxUint16 || len(h.TermEnv) > math.MaxUint16 || len(h.Cwd) > math.MaxUint16 || len(h.Env) > math.MaxUint32 { | |
| 770 | - | return ErrInvalidHello | |
| 771 | - | } | |
| 772 | - | for _, entry := range h.Env { | |
| 773 | - | if uint64(len(entry)) > math.MaxUint32 { | |
| 774 | - | return ErrInvalidHello | |
| 775 | - | } | |
| 776 | - | } | |
| 777 | - | if h.PreferredTabID != "" { | |
| 778 | - | if h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 779 | - | return ErrInvalidHello | |
| 780 | - | } | |
| 781 | - | if err := domain.ValidateTabStableID(h.PreferredTabID); err != nil { | |
| 782 | - | return fmt.Errorf("%w: preferred tab: %v", ErrInvalidHello, err) | |
| 783 | - | } | |
| 784 | - | } | |
| 785 | - | if h.ExactTarget != nil { | |
| 786 | - | if h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 787 | - | return ErrInvalidHello | |
| 788 | - | } | |
| 789 | - | if err := h.ExactTarget.Validate(); err != nil { | |
| 790 | - | return fmt.Errorf("%w: exact target: %v", ErrInvalidHello, err) | |
| 791 | - | } | |
| 792 | - | if h.Name != h.ExactTarget.SessionName { | |
| 793 | - | return ErrInvalidHello | |
| 794 | - | } | |
| 795 | - | if h.RemoteTarget != nil && (h.RemoteTarget.LifecycleID != h.ExactTarget.LifecycleID || h.RemoteTarget.SessionName != h.ExactTarget.SessionName) { | |
| 796 | - | return ErrInvalidHello | |
| 797 | - | } | |
| 798 | - | } | |
| 799 | - | if h.RemoteTarget == nil { | |
| 800 | - | if h.EnvironmentPolicy != EnvironmentPolicyClientOwned && h.EnvironmentPolicy != EnvironmentPolicyDaemonOwned { | |
| 801 | - | return ErrInvalidHello | |
| 802 | - | } | |
| 803 | - | return nil | |
| 804 | - | } | |
| 805 | - | if h.EnvironmentPolicy != EnvironmentPolicyDaemonOwned { | |
| 806 | - | return ErrInvalidHello | |
| 807 | - | } | |
| 808 | - | if h.Intent != IntentAttach && h.Intent != IntentResume { | |
| 809 | - | return ErrInvalidHello | |
| 810 | - | } | |
| 811 | - | if err := validateWireRemoteTarget(*h.RemoteTarget); err != nil { | |
| 812 | - | return fmt.Errorf("%w: remote target: %v", ErrInvalidHello, err) | |
| 813 | - | } | |
| 814 | - | if h.Name != h.RemoteTarget.SessionName { | |
| 815 | - | return ErrInvalidHello | |
| 816 | - | } | |
| 817 | - | return nil | |
| 818 | - | } | |
| 819 | 425 | ||
| 820 | 426 | // ValidateOutput validates the final output state before data allocation. | |
| 821 | - | func ValidateOutput(m Output) error { | |
| 822 | - | if m.Epoch == 0 { | |
| 823 | - | return ErrInvalidOutput | |
| 824 | - | } | |
| 825 | - | if m.New == 0 { | |
| 826 | - | if m.Base != 0 || m.Full { | |
| 827 | - | return ErrInvalidOutput | |
| 828 | - | } | |
| 829 | - | } else if (m.Base == 0 && !m.Full) || (m.Base != 0 && (m.Full || m.New != m.Base+1)) { | |
| 830 | - | return ErrInvalidOutput | |
| 831 | - | } | |
| 832 | - | if err := ValidateSize(m.Size); err != nil { | |
| 833 | - | return fmt.Errorf("%w: size", ErrInvalidOutput) | |
| 834 | - | } | |
| 835 | - | if uint64(len(m.Data)) > math.MaxUint32 || len(m.Data) > MaxOutputDataLen { | |
| 836 | - | return ErrInvalidOutput | |
| 837 | - | } | |
| 838 | - | return nil | |
| 839 | - | } | |
| 840 | 427 | ||
| 841 | 428 | // ValidateAck validates an epoch-scoped output acknowledgement. | |
| 842 | - | func ValidateAck(m Ack) error { | |
| 843 | - | if m.Epoch == 0 { | |
| 844 | - | return ErrInvalidAck | |
| 845 | - | } | |
| 846 | - | return nil | |
| 847 | - | } | |
| 848 | 429 | ||
| 849 | 430 | // ValidateAttachTarget validates a client-owned route handoff. An empty | |
| 850 | 431 | // Endpoint selects another session on the currently connected daemon; a | |
| 851 | 432 | // non-empty Endpoint selects a discovered remote daemon. | |
| 852 | - | func ValidateAttachTarget(m AttachTarget) error { | |
| 853 | - | if m.Session == "" || len(m.Endpoint) > math.MaxUint16 || len(m.Session) > math.MaxUint16 { | |
| 854 | - | return ErrInvalidAttachTarget | |
| 855 | - | } | |
| 856 | - | if err := domain.ValidateSessionName(m.Session); err != nil { | |
| 857 | - | return ErrInvalidAttachTarget | |
| 858 | - | } | |
| 859 | - | if m.Intent != IntentEphemeral && m.Intent != IntentNew && m.Intent != IntentAttach && m.Intent != IntentResume { | |
| 860 | - | return ErrInvalidAttachTarget | |
| 861 | - | } | |
| 862 | - | if m.Intent == IntentResume { | |
| 863 | - | return ErrInvalidAttachTarget | |
| 864 | - | } | |
| 865 | - | if !validEnvironmentPolicy(m.EnvironmentPolicy) { | |
| 866 | - | return ErrInvalidAttachTarget | |
| 867 | - | } | |
| 868 | - | if m.ExactTarget != nil && (m.ExactTarget.SessionName != m.Session || m.ExactTarget.Validate() != nil) { | |
| 869 | - | return ErrInvalidAttachTarget | |
| 870 | - | } | |
| 871 | - | if m.SamePeer && (m.Endpoint != "" || m.RemoteTarget != nil || m.ExactTarget == nil) { | |
| 872 | - | return ErrInvalidAttachTarget | |
| 873 | - | } | |
| 874 | - | if m.RemoteTarget == nil { | |
| 875 | - | return nil | |
| 876 | - | } | |
| 877 | - | if m.EnvironmentPolicy != EnvironmentPolicyDaemonOwned { | |
| 878 | - | return ErrInvalidAttachTarget | |
| 879 | - | } | |
| 880 | - | if m.Intent != IntentAttach { | |
| 881 | - | return ErrInvalidAttachTarget | |
| 882 | - | } | |
| 883 | - | if err := validateWireRemoteTarget(*m.RemoteTarget); err != nil { | |
| 884 | - | return fmt.Errorf("%w: remote target: %v", ErrInvalidAttachTarget, err) | |
| 885 | - | } | |
| 886 | - | if m.Endpoint != m.RemoteTarget.Endpoint || m.Session != m.RemoteTarget.SessionName { | |
| 887 | - | return ErrInvalidAttachTarget | |
| 888 | - | } | |
| 889 | - | return nil | |
| 890 | - | } | |
| 891 | 433 | ||
| 892 | 434 | func validateWireRemoteTarget(target domain.RemoteSessionTarget) error { | |
| 893 | 435 | if len(target.Endpoint) > math.MaxUint16 || len(target.DisplayOrigin) > math.MaxUint16 || len(target.SessionName) > math.MaxUint16 || len(target.LiveTabID) > math.MaxUint16 || len(target.StoppedTab.RawName) > math.MaxUint16 { | |
| @@ -1105,12 +647,12 @@ func UnmarshalHello(b []byte) (Hello, error) { | |||
| 1105 | 647 | if err != nil { | |
| 1106 | 648 | return Hello{}, err | |
| 1107 | 649 | } | |
| 1108 | - | h.NavigationCapabilities = NavigationCapabilities(capabilities) | |
| 650 | + | h.NavigationCapabilities = protocol.NavigationCapabilities(capabilities) | |
| 1109 | 651 | overlay, err := r.getUint8() | |
| 1110 | 652 | if err != nil { | |
| 1111 | 653 | return Hello{}, err | |
| 1112 | 654 | } | |
| 1113 | - | h.StartupOverlay = StartupOverlay(overlay) | |
| 655 | + | h.StartupOverlay = protocol.StartupOverlay(overlay) | |
| 1114 | 656 | if h.Remote, err = r.getBool(); err != nil { | |
| 1115 | 657 | return Hello{}, err | |
| 1116 | 658 | } | |
| @@ -1146,7 +688,7 @@ func UnmarshalInput(b []byte) (Input, error) { | |||
| 1146 | 688 | } | |
| 1147 | 689 | ||
| 1148 | 690 | // MarshalImagePush encodes m into an ImagePush message payload. | |
| 1149 | - | func MarshalImagePush(m ImagePush) []byte { | |
| 691 | + | func MarshalImagePush(m protocol.ImagePush) []byte { | |
| 1150 | 692 | w := payloadWriter{} | |
| 1151 | 693 | w.putUint64(m.InputSeq) | |
| 1152 | 694 | w.putString(m.Mime) | |
| @@ -1157,17 +699,17 @@ func MarshalImagePush(m ImagePush) []byte { | |||
| 1157 | 699 | // UnmarshalImagePush decodes an ImagePush message payload. After the fixed | |
| 1158 | 700 | // input sequence and length-prefixed mime string, the rest of the payload is | |
| 1159 | 701 | // data; there is no length prefix for it. | |
| 1160 | - | func UnmarshalImagePush(b []byte) (ImagePush, error) { | |
| 702 | + | func UnmarshalImagePush(b []byte) (protocol.ImagePush, error) { | |
| 1161 | 703 | r := payloadReader{b: b} | |
| 1162 | 704 | seq, err := r.getUint64() | |
| 1163 | 705 | if err != nil { | |
| 1164 | - | return ImagePush{}, err | |
| 706 | + | return protocol.ImagePush{}, err | |
| 1165 | 707 | } | |
| 1166 | 708 | mime, err := r.getString() | |
| 1167 | 709 | if err != nil { | |
| 1168 | - | return ImagePush{}, err | |
| 710 | + | return protocol.ImagePush{}, err | |
| 1169 | 711 | } | |
| 1170 | - | return ImagePush{InputSeq: seq, Mime: mime, Data: r.rest()}, nil | |
| 712 | + | return protocol.ImagePush{InputSeq: seq, Mime: mime, Data: r.rest()}, nil | |
| 1171 | 713 | } | |
| 1172 | 714 | ||
| 1173 | 715 | // MarshalClientNotice encodes a fixed one-byte client notice action. | |
| @@ -1183,7 +725,7 @@ func UnmarshalClientNotice(b []byte) (ClientNotice, error) { | |||
| 1183 | 725 | if err != nil { | |
| 1184 | 726 | return ClientNotice{}, err | |
| 1185 | 727 | } | |
| 1186 | - | if !validClientNoticeAction(action) { | |
| 728 | + | if ValidateClientNotice(ClientNotice{Action: action}) != nil { | |
| 1187 | 729 | return ClientNotice{}, errors.New("ports: unknown client notice action") | |
| 1188 | 730 | } | |
| 1189 | 731 | if err := r.done(); err != nil { | |
| @@ -1193,8 +735,8 @@ func UnmarshalClientNotice(b []byte) (ClientNotice, error) { | |||
| 1193 | 735 | } | |
| 1194 | 736 | ||
| 1195 | 737 | // MarshalResize encodes m into a Resize message payload. | |
| 1196 | - | func MarshalResize(m Resize) ([]byte, error) { | |
| 1197 | - | if err := ValidateGeometry(domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}); err != nil { | |
| 738 | + | func MarshalResize(m protocol.Resize) ([]byte, error) { | |
| 739 | + | if err := protocol.ValidateGeometry(domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}); err != nil { | |
| 1198 | 740 | return nil, err | |
| 1199 | 741 | } | |
| 1200 | 742 | w := payloadWriter{} | |
| @@ -1206,7 +748,7 @@ func MarshalResize(m Resize) ([]byte, error) { | |||
| 1206 | 748 | } | |
| 1207 | 749 | ||
| 1208 | 750 | // MarshalTheme encodes m into a 57-byte fixed-width Theme message payload. | |
| 1209 | - | func MarshalTheme(m Theme) []byte { | |
| 751 | + | func MarshalTheme(m protocol.Theme) []byte { | |
| 1210 | 752 | var flags uint8 | |
| 1211 | 753 | if m.HasForeground { | |
| 1212 | 754 | flags |= 0x01 | |
| @@ -1242,45 +784,45 @@ func MarshalTheme(m Theme) []byte { | |||
| 1242 | 784 | } | |
| 1243 | 785 | ||
| 1244 | 786 | // UnmarshalTheme decodes a 57-byte fixed-width Theme message payload. | |
| 1245 | - | func UnmarshalTheme(b []byte) (Theme, error) { | |
| 787 | + | func UnmarshalTheme(b []byte) (protocol.Theme, error) { | |
| 1246 | 788 | r := payloadReader{b: b} | |
| 1247 | 789 | flags, err := r.getUint8() | |
| 1248 | 790 | if err != nil { | |
| 1249 | - | return Theme{}, err | |
| 791 | + | return protocol.Theme{}, err | |
| 1250 | 792 | } | |
| 1251 | 793 | if flags&^uint8(0x1f) != 0 { | |
| 1252 | - | return Theme{}, errInvalidEnum | |
| 794 | + | return protocol.Theme{}, errInvalidEnum | |
| 1253 | 795 | } | |
| 1254 | 796 | fgR, err := r.getUint8() | |
| 1255 | 797 | if err != nil { | |
| 1256 | - | return Theme{}, err | |
| 798 | + | return protocol.Theme{}, err | |
| 1257 | 799 | } | |
| 1258 | 800 | fgG, err := r.getUint8() | |
| 1259 | 801 | if err != nil { | |
| 1260 | - | return Theme{}, err | |
| 802 | + | return protocol.Theme{}, err | |
| 1261 | 803 | } | |
| 1262 | 804 | fgB, err := r.getUint8() | |
| 1263 | 805 | if err != nil { | |
| 1264 | - | return Theme{}, err | |
| 806 | + | return protocol.Theme{}, err | |
| 1265 | 807 | } | |
| 1266 | 808 | bgR, err := r.getUint8() | |
| 1267 | 809 | if err != nil { | |
| 1268 | - | return Theme{}, err | |
| 810 | + | return protocol.Theme{}, err | |
| 1269 | 811 | } | |
| 1270 | 812 | bgG, err := r.getUint8() | |
| 1271 | 813 | if err != nil { | |
| 1272 | - | return Theme{}, err | |
| 814 | + | return protocol.Theme{}, err | |
| 1273 | 815 | } | |
| 1274 | 816 | bgB, err := r.getUint8() | |
| 1275 | 817 | if err != nil { | |
| 1276 | - | return Theme{}, err | |
| 818 | + | return protocol.Theme{}, err | |
| 1277 | 819 | } | |
| 1278 | 820 | paletteKnown, err := r.getUint16() | |
| 1279 | 821 | if err != nil { | |
| 1280 | - | return Theme{}, err | |
| 822 | + | return protocol.Theme{}, err | |
| 1281 | 823 | } | |
| 1282 | 824 | ||
| 1283 | - | m := Theme{ | |
| 825 | + | m := protocol.Theme{ | |
| 1284 | 826 | HasForeground: flags&0x01 != 0, | |
| 1285 | 827 | Foreground: renderer.RGB{R: fgR, G: fgG, B: fgB}, | |
| 1286 | 828 | HasBackground: flags&0x02 != 0, | |
| @@ -1292,50 +834,50 @@ func UnmarshalTheme(b []byte) (Theme, error) { | |||
| 1292 | 834 | } | |
| 1293 | 835 | for i := range m.Palette { | |
| 1294 | 836 | if m.Palette[i].R, err = r.getUint8(); err != nil { | |
| 1295 | - | return Theme{}, err | |
| 837 | + | return protocol.Theme{}, err | |
| 1296 | 838 | } | |
| 1297 | 839 | if m.Palette[i].G, err = r.getUint8(); err != nil { | |
| 1298 | - | return Theme{}, err | |
| 840 | + | return protocol.Theme{}, err | |
| 1299 | 841 | } | |
| 1300 | 842 | if m.Palette[i].B, err = r.getUint8(); err != nil { | |
| 1301 | - | return Theme{}, err | |
| 843 | + | return protocol.Theme{}, err | |
| 1302 | 844 | } | |
| 1303 | 845 | } | |
| 1304 | 846 | if err := r.done(); err != nil { | |
| 1305 | - | return Theme{}, err | |
| 847 | + | return protocol.Theme{}, err | |
| 1306 | 848 | } | |
| 1307 | 849 | return m, nil | |
| 1308 | 850 | } | |
| 1309 | 851 | ||
| 1310 | 852 | // UnmarshalResize decodes a Resize message payload. | |
| 1311 | - | func UnmarshalResize(b []byte) (Resize, error) { | |
| 853 | + | func UnmarshalResize(b []byte) (protocol.Resize, error) { | |
| 1312 | 854 | r := payloadReader{b: b} | |
| 1313 | 855 | cols, err := r.getUint16() | |
| 1314 | 856 | if err != nil { | |
| 1315 | - | return Resize{}, err | |
| 857 | + | return protocol.Resize{}, err | |
| 1316 | 858 | } | |
| 1317 | 859 | rows, err := r.getUint16() | |
| 1318 | 860 | if err != nil { | |
| 1319 | - | return Resize{}, err | |
| 861 | + | return protocol.Resize{}, err | |
| 1320 | 862 | } | |
| 1321 | 863 | pixelWidth, err := r.getUint16() | |
| 1322 | 864 | if err != nil { | |
| 1323 | - | return Resize{}, err | |
| 865 | + | return protocol.Resize{}, err | |
| 1324 | 866 | } | |
| 1325 | 867 | pixelHeight, err := r.getUint16() | |
| 1326 | 868 | if err != nil { | |
| 1327 | - | return Resize{}, err | |
| 869 | + | return protocol.Resize{}, err | |
| 1328 | 870 | } | |
| 1329 | 871 | if err := r.done(); err != nil { | |
| 1330 | - | return Resize{}, err | |
| 872 | + | return protocol.Resize{}, err | |
| 1331 | 873 | } | |
| 1332 | - | m := Resize{ | |
| 874 | + | m := protocol.Resize{ | |
| 1333 | 875 | Size: domain.Size{Cols: int(cols), Rows: int(rows)}, | |
| 1334 | 876 | PixelWidth: int(pixelWidth), | |
| 1335 | 877 | PixelHeight: int(pixelHeight), | |
| 1336 | 878 | } | |
| 1337 | - | if err := ValidateGeometry(domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}); err != nil { | |
| 1338 | - | return Resize{}, err | |
| 879 | + | if err := protocol.ValidateGeometry(domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}); err != nil { | |
| 880 | + | return protocol.Resize{}, err | |
| 1339 | 881 | } | |
| 1340 | 882 | return m, nil | |
| 1341 | 883 | } | |
| @@ -1383,8 +925,8 @@ func UnmarshalPong(b []byte) (Pong, error) { | |||
| 1383 | 925 | } | |
| 1384 | 926 | ||
| 1385 | 927 | // MarshalAck encodes m into an epoch/state Ack payload. | |
| 1386 | - | func MarshalAck(m Ack) ([]byte, error) { | |
| 1387 | - | if err := ValidateAck(m); err != nil { | |
| 928 | + | func MarshalAck(m protocol.Ack) ([]byte, error) { | |
| 929 | + | if err := protocol.ValidateAck(m); err != nil { | |
| 1388 | 930 | return nil, err | |
| 1389 | 931 | } | |
| 1390 | 932 | w := payloadWriter{} | |
| @@ -1394,21 +936,21 @@ func MarshalAck(m Ack) ([]byte, error) { | |||
| 1394 | 936 | } | |
| 1395 | 937 | ||
| 1396 | 938 | // UnmarshalAck decodes an epoch/state Ack payload. | |
| 1397 | - | func UnmarshalAck(b []byte) (Ack, error) { | |
| 939 | + | func UnmarshalAck(b []byte) (protocol.Ack, error) { | |
| 1398 | 940 | r := payloadReader{b: b} | |
| 1399 | - | var m Ack | |
| 941 | + | var m protocol.Ack | |
| 1400 | 942 | var err error | |
| 1401 | 943 | if m.Epoch, err = r.getUint64(); err != nil { | |
| 1402 | - | return Ack{}, err | |
| 944 | + | return protocol.Ack{}, err | |
| 1403 | 945 | } | |
| 1404 | 946 | if m.State, err = r.getUint64(); err != nil { | |
| 1405 | - | return Ack{}, err | |
| 947 | + | return protocol.Ack{}, err | |
| 1406 | 948 | } | |
| 1407 | 949 | if err := r.done(); err != nil { | |
| 1408 | - | return Ack{}, err | |
| 950 | + | return protocol.Ack{}, err | |
| 1409 | 951 | } | |
| 1410 | - | if err := ValidateAck(m); err != nil { | |
| 1411 | - | return Ack{}, err | |
| 952 | + | if err := protocol.ValidateAck(m); err != nil { | |
| 953 | + | return protocol.Ack{}, err | |
| 1412 | 954 | } | |
| 1413 | 955 | return m, nil | |
| 1414 | 956 | } | |
| @@ -1461,7 +1003,7 @@ func UnmarshalWelcome(b []byte) (Welcome, error) { | |||
| 1461 | 1003 | return Welcome{}, err | |
| 1462 | 1004 | } | |
| 1463 | 1005 | if m.CommittedIdentity != nil && (m.CommittedIdentity.Target.SessionName != m.SessionName || m.CommittedIdentity.Ephemeral != m.Ephemeral) { | |
| 1464 | - | return Welcome{}, fmt.Errorf("%w: committed identity does not match welcome", ErrInvalidRouteWire) | |
| 1006 | + | return Welcome{}, fmt.Errorf("%w: committed identity does not match welcome", protocol.ErrInvalidRouteWire) | |
| 1465 | 1007 | } | |
| 1466 | 1008 | if err := r.done(); err != nil { | |
| 1467 | 1009 | return Welcome{}, err | |
| @@ -1498,8 +1040,8 @@ func UnmarshalErrorMsg(b []byte) (ErrorMsg, error) { | |||
| 1498 | 1040 | // MarshalOutput encodes m into the epoch/base/new/echo/viewRevision/ | |
| 1499 | 1041 | // size/full/compression/decoded-length/data message layout. Compression is | |
| 1500 | 1042 | // limited to large, full snapshots and is retained only when it saves bytes. | |
| 1501 | - | func MarshalOutput(m Output) ([]byte, error) { | |
| 1502 | - | if err := ValidateOutput(m); err != nil { | |
| 1043 | + | func MarshalOutput(m protocol.Output) ([]byte, error) { | |
| 1044 | + | if err := protocol.ValidateOutput(m); err != nil { | |
| 1503 | 1045 | return nil, err | |
| 1504 | 1046 | } | |
| 1505 | 1047 | kind, data, err := compressOutputData(m) | |
| @@ -1521,7 +1063,7 @@ func MarshalOutput(m Output) ([]byte, error) { | |||
| 1521 | 1063 | return w.b, nil | |
| 1522 | 1064 | } | |
| 1523 | 1065 | ||
| 1524 | - | func compressOutputData(m Output) (byte, []byte, error) { | |
| 1066 | + | func compressOutputData(m protocol.Output) (byte, []byte, error) { | |
| 1525 | 1067 | if !m.Full || len(m.Data) < outputCompressionThreshold { | |
| 1526 | 1068 | return outputCompressionNone, m.Data, nil | |
| 1527 | 1069 | } | |
| @@ -1546,83 +1088,83 @@ func compressOutputData(m Output) (byte, []byte, error) { | |||
| 1546 | 1088 | ||
| 1547 | 1089 | // UnmarshalOutput strictly decodes one final Output payload. Header semantics | |
| 1548 | 1090 | // are validated before its bounded decoded data allocation. | |
| 1549 | - | func UnmarshalOutput(b []byte) (Output, error) { | |
| 1091 | + | func UnmarshalOutput(b []byte) (protocol.Output, error) { | |
| 1550 | 1092 | if len(b) > MaxFrameLen-1 { | |
| 1551 | - | return Output{}, ErrInvalidOutput | |
| 1093 | + | return protocol.Output{}, protocol.ErrInvalidOutput | |
| 1552 | 1094 | } | |
| 1553 | 1095 | if len(b) < outputPayloadOverhead { | |
| 1554 | - | return Output{}, errShortPayload | |
| 1096 | + | return protocol.Output{}, errShortPayload | |
| 1555 | 1097 | } | |
| 1556 | 1098 | r := payloadReader{b: b} | |
| 1557 | - | var m Output | |
| 1099 | + | var m protocol.Output | |
| 1558 | 1100 | var err error | |
| 1559 | 1101 | if m.Epoch, err = r.getUint64(); err != nil { | |
| 1560 | - | return Output{}, err | |
| 1102 | + | return protocol.Output{}, err | |
| 1561 | 1103 | } | |
| 1562 | 1104 | if m.Base, err = r.getUint64(); err != nil { | |
| 1563 | - | return Output{}, err | |
| 1105 | + | return protocol.Output{}, err | |
| 1564 | 1106 | } | |
| 1565 | 1107 | if m.New, err = r.getUint64(); err != nil { | |
| 1566 | - | return Output{}, err | |
| 1108 | + | return protocol.Output{}, err | |
| 1567 | 1109 | } | |
| 1568 | 1110 | if m.Echo, err = r.getUint64(); err != nil { | |
| 1569 | - | return Output{}, err | |
| 1111 | + | return protocol.Output{}, err | |
| 1570 | 1112 | } | |
| 1571 | 1113 | if m.ViewRevision, err = r.getUint64(); err != nil { | |
| 1572 | - | return Output{}, err | |
| 1114 | + | return protocol.Output{}, err | |
| 1573 | 1115 | } | |
| 1574 | 1116 | cols, err := r.getUint16() | |
| 1575 | 1117 | if err != nil { | |
| 1576 | - | return Output{}, err | |
| 1118 | + | return protocol.Output{}, err | |
| 1577 | 1119 | } | |
| 1578 | 1120 | rows, err := r.getUint16() | |
| 1579 | 1121 | if err != nil { | |
| 1580 | - | return Output{}, err | |
| 1122 | + | return protocol.Output{}, err | |
| 1581 | 1123 | } | |
| 1582 | 1124 | m.Size = domain.Size{Cols: int(cols), Rows: int(rows)} | |
| 1583 | 1125 | if m.Full, err = r.getBool(); err != nil { | |
| 1584 | - | return Output{}, err | |
| 1126 | + | return protocol.Output{}, err | |
| 1585 | 1127 | } | |
| 1586 | - | if err := ValidateOutput(m); err != nil { | |
| 1587 | - | return Output{}, err | |
| 1128 | + | if err := protocol.ValidateOutput(m); err != nil { | |
| 1129 | + | return protocol.Output{}, err | |
| 1588 | 1130 | } | |
| 1589 | 1131 | kind, err := r.getUint8() | |
| 1590 | 1132 | if err != nil { | |
| 1591 | - | return Output{}, err | |
| 1133 | + | return protocol.Output{}, err | |
| 1592 | 1134 | } | |
| 1593 | 1135 | decodedLen, err := r.getUint32() | |
| 1594 | 1136 | if err != nil { | |
| 1595 | - | return Output{}, err | |
| 1137 | + | return protocol.Output{}, err | |
| 1596 | 1138 | } | |
| 1597 | - | if int64(decodedLen) > int64(MaxOutputDataLen) { | |
| 1598 | - | return Output{}, ErrInvalidOutput | |
| 1139 | + | if int64(decodedLen) > int64(protocol.MaxOutputDataLen) { | |
| 1140 | + | return protocol.Output{}, protocol.ErrInvalidOutput | |
| 1599 | 1141 | } | |
| 1600 | 1142 | data, err := r.getLongBytes() | |
| 1601 | 1143 | if err != nil { | |
| 1602 | - | return Output{}, err | |
| 1144 | + | return protocol.Output{}, err | |
| 1603 | 1145 | } | |
| 1604 | 1146 | if err := r.done(); err != nil { | |
| 1605 | - | return Output{}, err | |
| 1147 | + | return protocol.Output{}, err | |
| 1606 | 1148 | } | |
| 1607 | 1149 | switch kind { | |
| 1608 | 1150 | case outputCompressionNone: | |
| 1609 | 1151 | if uint32(len(data)) != decodedLen { | |
| 1610 | - | return Output{}, ErrInvalidOutput | |
| 1152 | + | return protocol.Output{}, protocol.ErrInvalidOutput | |
| 1611 | 1153 | } | |
| 1612 | 1154 | m.Data = data | |
| 1613 | 1155 | case outputCompressionZlib: | |
| 1614 | 1156 | if !m.Full { | |
| 1615 | - | return Output{}, ErrInvalidOutput | |
| 1157 | + | return protocol.Output{}, protocol.ErrInvalidOutput | |
| 1616 | 1158 | } | |
| 1617 | 1159 | m.Data, err = decompressOutputData(data, int(decodedLen)) | |
| 1618 | 1160 | if err != nil { | |
| 1619 | - | return Output{}, ErrInvalidOutput | |
| 1161 | + | return protocol.Output{}, protocol.ErrInvalidOutput | |
| 1620 | 1162 | } | |
| 1621 | 1163 | default: | |
| 1622 | - | return Output{}, errInvalidEnum | |
| 1164 | + | return protocol.Output{}, errInvalidEnum | |
| 1623 | 1165 | } | |
| 1624 | - | if err := ValidateOutput(m); err != nil { | |
| 1625 | - | return Output{}, err | |
| 1166 | + | if err := protocol.ValidateOutput(m); err != nil { | |
| 1167 | + | return protocol.Output{}, err | |
| 1626 | 1168 | } | |
| 1627 | 1169 | return m, nil | |
| 1628 | 1170 | } | |
| @@ -1742,7 +1284,7 @@ func UnmarshalDetached(b []byte) (Detached, error) { | |||
| 1742 | 1284 | if err != nil { | |
| 1743 | 1285 | return Detached{}, err | |
| 1744 | 1286 | } | |
| 1745 | - | if !validDetachedReason(reason) { | |
| 1287 | + | if ValidateDetached(Detached{Reason: reason}) != nil { | |
| 1746 | 1288 | return Detached{}, errInvalidEnum | |
| 1747 | 1289 | } | |
| 1748 | 1290 | if err := r.done(); err != nil { | |
| @@ -1948,7 +1490,7 @@ func getPreviewStyle(r *payloadReader) (renderer.Style, error) { | |||
| 1948 | 1490 | return renderer.Style{}, err | |
| 1949 | 1491 | } | |
| 1950 | 1492 | if flags&0x80 != 0 { | |
| 1951 | - | return renderer.Style{}, ErrRemotePreviewUnsupportedStyle | |
| 1493 | + | return renderer.Style{}, protocol.ErrRemotePreviewUnsupportedStyle | |
| 1952 | 1494 | } | |
| 1953 | 1495 | attrs, err := r.getUint16() | |
| 1954 | 1496 | if err != nil { | |
| @@ -1989,8 +1531,8 @@ func getPreviewStyle(r *payloadReader) (renderer.Style, error) { | |||
| 1989 | 1531 | ForegroundRGB: fgrgb, BackgroundRGB: bgrgb, UnderlineColorRGB: ulrgb}, nil | |
| 1990 | 1532 | } | |
| 1991 | 1533 | ||
| 1992 | - | func MarshalRemotePreviewRequest(request RemotePreviewRequest) []byte { | |
| 1993 | - | if ValidateRemotePreviewRequest(request) != nil { | |
| 1534 | + | func MarshalRemotePreviewRequest(request protocol.RemotePreviewRequest) []byte { | |
| 1535 | + | if protocol.ValidateRemotePreviewRequest(request) != nil { | |
| 1994 | 1536 | return nil | |
| 1995 | 1537 | } | |
| 1996 | 1538 | w := payloadWriter{} | |
| @@ -2005,12 +1547,12 @@ func MarshalRemotePreviewRequest(request RemotePreviewRequest) []byte { | |||
| 2005 | 1547 | return w.b | |
| 2006 | 1548 | } | |
| 2007 | 1549 | ||
| 2008 | - | func UnmarshalRemotePreviewRequest(data []byte) (RemotePreviewRequest, error) { | |
| 2009 | - | if len(data) > RemotePreviewMaxBytes { | |
| 2010 | - | return RemotePreviewRequest{}, ErrInvalidRemotePreviewRequest | |
| 1550 | + | func UnmarshalRemotePreviewRequest(data []byte) (protocol.RemotePreviewRequest, error) { | |
| 1551 | + | if len(data) > protocol.RemotePreviewMaxBytes { | |
| 1552 | + | return protocol.RemotePreviewRequest{}, protocol.ErrInvalidRemotePreviewRequest | |
| 2011 | 1553 | } | |
| 2012 | 1554 | r := payloadReader{b: data} | |
| 2013 | - | var q RemotePreviewRequest | |
| 1555 | + | var q protocol.RemotePreviewRequest | |
| 2014 | 1556 | var err error | |
| 2015 | 1557 | if q.Version, err = r.getUint16(); err != nil { | |
| 2016 | 1558 | return q, err | |
| @@ -2043,7 +1585,7 @@ func UnmarshalRemotePreviewRequest(data []byte) (RemotePreviewRequest, error) { | |||
| 2043 | 1585 | if err := r.done(); err != nil { | |
| 2044 | 1586 | return q, err | |
| 2045 | 1587 | } | |
| 2046 | - | if err := ValidateRemotePreviewRequest(q); err != nil { | |
| 1588 | + | if err := protocol.ValidateRemotePreviewRequest(q); err != nil { | |
| 2047 | 1589 | return q, err | |
| 2048 | 1590 | } | |
| 2049 | 1591 | return q, nil | |
| @@ -2051,8 +1593,8 @@ func UnmarshalRemotePreviewRequest(data []byte) (RemotePreviewRequest, error) { | |||
| 2051 | 1593 | ||
| 2052 | 1594 | const previewCellWireSize = 4 + 1 + 1 + 2 + 2 + 2 + 1 + 2 + 3 + 3 + 3 | |
| 2053 | 1595 | ||
| 2054 | - | func MarshalRemotePreview(preview RemotePreview) []byte { | |
| 2055 | - | if ValidateRemotePreview(preview) != nil { | |
| 1596 | + | func MarshalRemotePreview(preview protocol.RemotePreview) []byte { | |
| 1597 | + | if protocol.ValidateRemotePreview(preview) != nil { | |
| 2056 | 1598 | return nil | |
| 2057 | 1599 | } | |
| 2058 | 1600 | w := payloadWriter{} | |
| @@ -2076,12 +1618,12 @@ func MarshalRemotePreview(preview RemotePreview) []byte { | |||
| 2076 | 1618 | return w.b | |
| 2077 | 1619 | } | |
| 2078 | 1620 | ||
| 2079 | - | func UnmarshalRemotePreview(data []byte) (RemotePreview, error) { | |
| 2080 | - | if len(data) > RemotePreviewMaxBytes { | |
| 2081 | - | return RemotePreview{}, ErrRemotePreviewTooLarge | |
| 1621 | + | func UnmarshalRemotePreview(data []byte) (protocol.RemotePreview, error) { | |
| 1622 | + | if len(data) > protocol.RemotePreviewMaxBytes { | |
| 1623 | + | return protocol.RemotePreview{}, protocol.ErrRemotePreviewTooLarge | |
| 2082 | 1624 | } | |
| 2083 | 1625 | r := payloadReader{b: data} | |
| 2084 | - | var p RemotePreview | |
| 1626 | + | var p protocol.RemotePreview | |
| 2085 | 1627 | var err error | |
| 2086 | 1628 | if p.Version, err = r.getUint16(); err != nil { | |
| 2087 | 1629 | return p, err | |
| @@ -2090,7 +1632,7 @@ func UnmarshalRemotePreview(data []byte) (RemotePreview, error) { | |||
| 2090 | 1632 | if err != nil { | |
| 2091 | 1633 | return p, err | |
| 2092 | 1634 | } | |
| 2093 | - | p.Status = RemotePreviewStatus(status) | |
| 1635 | + | p.Status = protocol.RemotePreviewStatus(status) | |
| 2094 | 1636 | id, err := r.getBytes(16) | |
| 2095 | 1637 | if err != nil { | |
| 2096 | 1638 | return p, err | |
| @@ -2114,8 +1656,8 @@ func UnmarshalRemotePreview(data []byte) (RemotePreview, error) { | |||
| 2114 | 1656 | if err != nil { | |
| 2115 | 1657 | return p, err | |
| 2116 | 1658 | } | |
| 2117 | - | if count > RemotePreviewMaxCells || uint64(count) > uint64(len(r.b)/previewCellWireSize) { | |
| 2118 | - | return p, ErrRemotePreviewTooLarge | |
| 1659 | + | if count > protocol.RemotePreviewMaxCells || uint64(count) > uint64(len(r.b)/previewCellWireSize) { | |
| 1660 | + | return p, protocol.ErrRemotePreviewTooLarge | |
| 2119 | 1661 | } | |
| 2120 | 1662 | if count != 0 { | |
| 2121 | 1663 | p.Cells = make([]renderer.Cell, 0, int(count)) | |
| @@ -2129,7 +1671,7 @@ func UnmarshalRemotePreview(data []byte) (RemotePreview, error) { | |||
| 2129 | 1671 | return p, e | |
| 2130 | 1672 | } | |
| 2131 | 1673 | if flags&^uint8(1) != 0 { | |
| 2132 | - | return p, ErrInvalidRemotePreview | |
| 1674 | + | return p, protocol.ErrInvalidRemotePreview | |
| 2133 | 1675 | } | |
| 2134 | 1676 | style, e := getPreviewStyle(&r) | |
| 2135 | 1677 | if e != nil { | |
| @@ -2141,18 +1683,18 @@ func UnmarshalRemotePreview(data []byte) (RemotePreview, error) { | |||
| 2141 | 1683 | if err := r.done(); err != nil { | |
| 2142 | 1684 | return p, err | |
| 2143 | 1685 | } | |
| 2144 | - | if err := ValidateRemotePreview(p); err != nil { | |
| 1686 | + | if err := protocol.ValidateRemotePreview(p); err != nil { | |
| 2145 | 1687 | return p, err | |
| 2146 | 1688 | } | |
| 2147 | 1689 | return p, nil | |
| 2148 | 1690 | } | |
| 2149 | 1691 | ||
| 2150 | 1692 | // MarshalNavigationDirective encodes one bounded navigation directive. | |
| 2151 | - | func MarshalNavigationDirective(directive NavigationDirective) []byte { | |
| 2152 | - | if directive.Action != NavigationOpenHomePicker && directive.Action != NavigationBack { | |
| 1693 | + | func MarshalNavigationDirective(directive protocol.NavigationDirective) []byte { | |
| 1694 | + | if directive.Action != protocol.NavigationOpenHomePicker && directive.Action != protocol.NavigationBack { | |
| 2153 | 1695 | return nil | |
| 2154 | 1696 | } | |
| 2155 | - | if directive.Action == NavigationOpenHomePicker && directive.LeaseID.IsZero() || directive.Action == NavigationBack && !directive.LeaseID.IsZero() { | |
| 1697 | + | if directive.Action == protocol.NavigationOpenHomePicker && directive.LeaseID.IsZero() || directive.Action == protocol.NavigationBack && !directive.LeaseID.IsZero() { | |
| 2156 | 1698 | return nil | |
| 2157 | 1699 | } | |
| 2158 | 1700 | w := payloadWriter{} | |
| @@ -2162,51 +1704,33 @@ func MarshalNavigationDirective(directive NavigationDirective) []byte { | |||
| 2162 | 1704 | } | |
| 2163 | 1705 | ||
| 2164 | 1706 | // UnmarshalNavigationDirective decodes one strict navigation directive. | |
| 2165 | - | func UnmarshalNavigationDirective(b []byte) (NavigationDirective, error) { | |
| 1707 | + | func UnmarshalNavigationDirective(b []byte) (protocol.NavigationDirective, error) { | |
| 2166 | 1708 | r := payloadReader{b: b} | |
| 2167 | 1709 | value, err := r.getUint8() | |
| 2168 | 1710 | if err != nil { | |
| 2169 | - | return NavigationDirective{}, ErrInvalidNavigation | |
| 1711 | + | return protocol.NavigationDirective{}, protocol.ErrInvalidNavigation | |
| 2170 | 1712 | } | |
| 2171 | - | lease, err := r.getBytes(len(ParkedRouteLeaseID{})) | |
| 1713 | + | lease, err := r.getBytes(len(protocol.ParkedRouteLeaseID{})) | |
| 2172 | 1714 | if err != nil { | |
| 2173 | - | return NavigationDirective{}, ErrInvalidNavigation | |
| 1715 | + | return protocol.NavigationDirective{}, protocol.ErrInvalidNavigation | |
| 2174 | 1716 | } | |
| 2175 | 1717 | if err := r.done(); err != nil { | |
| 2176 | - | return NavigationDirective{}, ErrInvalidNavigation | |
| 1718 | + | return protocol.NavigationDirective{}, protocol.ErrInvalidNavigation | |
| 2177 | 1719 | } | |
| 2178 | - | directive := NavigationDirective{Action: NavigationAction(value)} | |
| 1720 | + | directive := protocol.NavigationDirective{Action: protocol.NavigationAction(value)} | |
| 2179 | 1721 | copy(directive.LeaseID[:], lease) | |
| 2180 | 1722 | if MarshalNavigationDirective(directive) == nil { | |
| 2181 | - | return NavigationDirective{}, ErrInvalidNavigation | |
| 1723 | + | return protocol.NavigationDirective{}, protocol.ErrInvalidNavigation | |
| 2182 | 1724 | } | |
| 2183 | 1725 | return directive, nil | |
| 2184 | 1726 | } | |
| 2185 | 1727 | ||
| 2186 | 1728 | // ValidateParkedRouteRequest enforces the closed action/target shape before a | |
| 2187 | 1729 | // request reaches either side's route state machine. | |
| 2188 | - | func ValidateParkedRouteRequest(request ParkedRouteRequest) error { | |
| 2189 | - | if request.RequestID == 0 || request.LeaseID.IsZero() { | |
| 2190 | - | return ErrInvalidNavigation | |
| 2191 | - | } | |
| 2192 | - | switch request.Action { | |
| 2193 | - | case ParkedRoutePrepare, ParkedRouteResume: | |
| 2194 | - | if request.Target != nil { | |
| 2195 | - | return ErrInvalidNavigation | |
| 2196 | - | } | |
| 2197 | - | case ParkedRouteSwitch: | |
| 2198 | - | if request.Target == nil || validateWireRemoteTarget(*request.Target) != nil { | |
| 2199 | - | return ErrInvalidNavigation | |
| 2200 | - | } | |
| 2201 | - | default: | |
| 2202 | - | return ErrInvalidNavigation | |
| 2203 | - | } | |
| 2204 | - | return nil | |
| 2205 | - | } | |
| 2206 | 1730 | ||
| 2207 | 1731 | // MarshalParkedRouteRequest encodes one retained-route operation. | |
| 2208 | - | func MarshalParkedRouteRequest(request ParkedRouteRequest) []byte { | |
| 2209 | - | if ValidateParkedRouteRequest(request) != nil { | |
| 1732 | + | func MarshalParkedRouteRequest(request protocol.ParkedRouteRequest) []byte { | |
| 1733 | + | if protocol.ValidateParkedRouteRequest(request) != nil { | |
| 2210 | 1734 | return nil | |
| 2211 | 1735 | } | |
| 2212 | 1736 | w := payloadWriter{} | |
| @@ -2218,35 +1742,35 @@ func MarshalParkedRouteRequest(request ParkedRouteRequest) []byte { | |||
| 2218 | 1742 | } | |
| 2219 | 1743 | ||
| 2220 | 1744 | // UnmarshalParkedRouteRequest decodes one strict retained-route operation. | |
| 2221 | - | func UnmarshalParkedRouteRequest(b []byte) (ParkedRouteRequest, error) { | |
| 1745 | + | func UnmarshalParkedRouteRequest(b []byte) (protocol.ParkedRouteRequest, error) { | |
| 2222 | 1746 | r := payloadReader{b: b} | |
| 2223 | 1747 | requestID, err := r.getUint64() | |
| 2224 | 1748 | if err != nil { | |
| 2225 | - | return ParkedRouteRequest{}, ErrInvalidNavigation | |
| 1749 | + | return protocol.ParkedRouteRequest{}, protocol.ErrInvalidNavigation | |
| 2226 | 1750 | } | |
| 2227 | - | lease, err := r.getBytes(len(ParkedRouteLeaseID{})) | |
| 1751 | + | lease, err := r.getBytes(len(protocol.ParkedRouteLeaseID{})) | |
| 2228 | 1752 | if err != nil { | |
| 2229 | - | return ParkedRouteRequest{}, ErrInvalidNavigation | |
| 1753 | + | return protocol.ParkedRouteRequest{}, protocol.ErrInvalidNavigation | |
| 2230 | 1754 | } | |
| 2231 | 1755 | action, err := r.getUint8() | |
| 2232 | 1756 | if err != nil { | |
| 2233 | - | return ParkedRouteRequest{}, ErrInvalidNavigation | |
| 1757 | + | return protocol.ParkedRouteRequest{}, protocol.ErrInvalidNavigation | |
| 2234 | 1758 | } | |
| 2235 | 1759 | target, policy, err := unmarshalRemoteTargetSection(&r) | |
| 2236 | 1760 | if err != nil || policy != EnvironmentPolicyDaemonOwned || r.done() != nil { | |
| 2237 | - | return ParkedRouteRequest{}, ErrInvalidNavigation | |
| 1761 | + | return protocol.ParkedRouteRequest{}, protocol.ErrInvalidNavigation | |
| 2238 | 1762 | } | |
| 2239 | - | request := ParkedRouteRequest{RequestID: requestID, Action: ParkedRouteAction(action), Target: target} | |
| 1763 | + | request := protocol.ParkedRouteRequest{RequestID: requestID, Action: protocol.ParkedRouteAction(action), Target: target} | |
| 2240 | 1764 | copy(request.LeaseID[:], lease) | |
| 2241 | - | if ValidateParkedRouteRequest(request) != nil { | |
| 2242 | - | return ParkedRouteRequest{}, ErrInvalidNavigation | |
| 1765 | + | if protocol.ValidateParkedRouteRequest(request) != nil { | |
| 1766 | + | return protocol.ParkedRouteRequest{}, protocol.ErrInvalidNavigation | |
| 2243 | 1767 | } | |
| 2244 | 1768 | return request, nil | |
| 2245 | 1769 | } | |
| 2246 | 1770 | ||
| 2247 | 1771 | // MarshalParkedRouteResponse encodes one correlated retained-route outcome. | |
| 2248 | - | func MarshalParkedRouteResponse(response ParkedRouteResponse) []byte { | |
| 2249 | - | if response.RequestID == 0 || response.Status < ParkedRouteReady || response.Status > ParkedRouteStaleTarget { | |
| 1772 | + | func MarshalParkedRouteResponse(response protocol.ParkedRouteResponse) []byte { | |
| 1773 | + | if response.RequestID == 0 || response.Status < protocol.ParkedRouteReady || response.Status > protocol.ParkedRouteStaleTarget { | |
| 2250 | 1774 | return nil | |
| 2251 | 1775 | } | |
| 2252 | 1776 | w := payloadWriter{} | |
| @@ -2256,19 +1780,19 @@ func MarshalParkedRouteResponse(response ParkedRouteResponse) []byte { | |||
| 2256 | 1780 | } | |
| 2257 | 1781 | ||
| 2258 | 1782 | // UnmarshalParkedRouteResponse decodes one strict retained-route outcome. | |
| 2259 | - | func UnmarshalParkedRouteResponse(b []byte) (ParkedRouteResponse, error) { | |
| 1783 | + | func UnmarshalParkedRouteResponse(b []byte) (protocol.ParkedRouteResponse, error) { | |
| 2260 | 1784 | r := payloadReader{b: b} | |
| 2261 | 1785 | requestID, err := r.getUint64() | |
| 2262 | 1786 | if err != nil { | |
| 2263 | - | return ParkedRouteResponse{}, ErrInvalidNavigation | |
| 1787 | + | return protocol.ParkedRouteResponse{}, protocol.ErrInvalidNavigation | |
| 2264 | 1788 | } | |
| 2265 | 1789 | status, err := r.getUint8() | |
| 2266 | 1790 | if err != nil || r.done() != nil { | |
| 2267 | - | return ParkedRouteResponse{}, ErrInvalidNavigation | |
| 1791 | + | return protocol.ParkedRouteResponse{}, protocol.ErrInvalidNavigation | |
| 2268 | 1792 | } | |
| 2269 | - | response := ParkedRouteResponse{RequestID: requestID, Status: ParkedRouteStatus(status)} | |
| 1793 | + | response := protocol.ParkedRouteResponse{RequestID: requestID, Status: protocol.ParkedRouteStatus(status)} | |
| 2270 | 1794 | if MarshalParkedRouteResponse(response) == nil { | |
| 2271 | - | return ParkedRouteResponse{}, ErrInvalidNavigation | |
| 1795 | + | return protocol.ParkedRouteResponse{}, protocol.ErrInvalidNavigation | |
| 2272 | 1796 | } | |
| 2273 | 1797 | return response, nil | |
| 2274 | 1798 | } | |
M internal/ports/wire_final_test.go +11 -10
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | "testing" | |
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | ) | |
| 12 | 13 | ||
| 13 | 14 | func TestFinalProtocolVersionAndNoV21Hello(t *testing.T) { | |
| @@ -81,7 +82,7 @@ func TestFinalHelloSemanticValidation(t *testing.T) { | |||
| 81 | 82 | } | |
| 82 | 83 | ||
| 83 | 84 | func TestFinalResizeGoldenStrict(t *testing.T) { | |
| 84 | - | msg := Resize{Size: domain.Size{Cols: 80, Rows: 24}} | |
| 85 | + | msg := protocol.Resize{Size: domain.Size{Cols: 80, Rows: 24}} | |
| 85 | 86 | want := []byte{0, 80, 0, 24, 0, 0, 0, 0} | |
| 86 | 87 | got, err := MarshalResize(msg) | |
| 87 | 88 | if err != nil { | |
| @@ -97,14 +98,14 @@ func TestFinalResizeGoldenStrict(t *testing.T) { | |||
| 97 | 98 | assertAllPrefixesFail(t, got, UnmarshalResize) | |
| 98 | 99 | assertTrailingGarbageFails(t, got, UnmarshalResize) | |
| 99 | 100 | for _, size := range []domain.Size{{}, {Cols: 513, Rows: 512}} { | |
| 100 | - | if got, err := MarshalResize(Resize{Size: size}); err == nil || got != nil { | |
| 101 | + | if got, err := MarshalResize(protocol.Resize{Size: size}); err == nil || got != nil { | |
| 101 | 102 | t.Fatalf("MarshalResize(%+v) = (%x, %v), want nil payload and error", size, got, err) | |
| 102 | 103 | } | |
| 103 | 104 | } | |
| 104 | 105 | } | |
| 105 | 106 | ||
| 106 | 107 | func TestFinalOutputGoldenStrict(t *testing.T) { | |
| 107 | - | msg := Output{ | |
| 108 | + | msg := protocol.Output{ | |
| 108 | 109 | Epoch: 1, Base: 0, New: 7, Echo: 8, ViewRevision: 9, | |
| 109 | 110 | Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("ok"), | |
| 110 | 111 | } | |
| @@ -134,8 +135,8 @@ func TestFinalOutputGoldenStrict(t *testing.T) { | |||
| 134 | 135 | } | |
| 135 | 136 | ||
| 136 | 137 | func TestFinalOutputSemanticValidationBeforeDataAllocation(t *testing.T) { | |
| 137 | - | valid := Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true} | |
| 138 | - | for _, bad := range []Output{ | |
| 138 | + | valid := protocol.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true} | |
| 139 | + | for _, bad := range []protocol.Output{ | |
| 139 | 140 | {}, | |
| 140 | 141 | {Epoch: 1, Base: 0, New: 1, Size: valid.Size}, | |
| 141 | 142 | {Epoch: 1, Base: 0, New: 1, Full: true}, | |
| @@ -170,7 +171,7 @@ func TestFinalOutputSemanticValidationBeforeDataAllocation(t *testing.T) { | |||
| 170 | 171 | } | |
| 171 | 172 | ||
| 172 | 173 | func TestFinalAckGoldenStrict(t *testing.T) { | |
| 173 | - | msg := Ack{Epoch: 2, State: 7} | |
| 174 | + | msg := protocol.Ack{Epoch: 2, State: 7} | |
| 174 | 175 | want := []byte{0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 7} | |
| 175 | 176 | got, err := MarshalAck(msg) | |
| 176 | 177 | if err != nil { | |
| @@ -180,7 +181,7 @@ func TestFinalAckGoldenStrict(t *testing.T) { | |||
| 180 | 181 | t.Fatalf("Ack bytes = %x, want %x", got, want) | |
| 181 | 182 | } | |
| 182 | 183 | back, err := UnmarshalAck(got) | |
| 183 | - | if err != nil || back != (Ack{Epoch: 2, State: 7}) { | |
| 184 | + | if err != nil || back != (protocol.Ack{Epoch: 2, State: 7}) { | |
| 184 | 185 | t.Fatalf("Ack = %+v, error %v", back, err) | |
| 185 | 186 | } | |
| 186 | 187 | assertAllPrefixesFail(t, got, UnmarshalAck) | |
| @@ -188,7 +189,7 @@ func TestFinalAckGoldenStrict(t *testing.T) { | |||
| 188 | 189 | if _, err := UnmarshalAck(make([]byte, 16)); err == nil { | |
| 189 | 190 | t.Fatal("UnmarshalAck accepted zero epoch") | |
| 190 | 191 | } | |
| 191 | - | if got, err := MarshalAck(Ack{State: 7}); err == nil || got != nil { | |
| 192 | + | if got, err := MarshalAck(protocol.Ack{State: 7}); err == nil || got != nil { | |
| 192 | 193 | t.Fatalf("MarshalAck accepted zero epoch: payload=%x err=%v", got, err) | |
| 193 | 194 | } | |
| 194 | 195 | } | |
| @@ -231,7 +232,7 @@ func TestFinalAttachTargetGoldenStrict(t *testing.T) { | |||
| 231 | 232 | func TestAttachTargetExactTargetWireStrict(t *testing.T) { | |
| 232 | 233 | var lifecycle domain.SessionLifecycleID | |
| 233 | 234 | lifecycle[0] = 1 | |
| 234 | - | target := AttachTarget{Session: "work", Intent: IntentAttach, ExactTarget: &ExactSessionTarget{LifecycleID: lifecycle, SessionName: "work"}, SamePeer: true} | |
| 235 | + | target := AttachTarget{Session: "work", Intent: IntentAttach, ExactTarget: &protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "work"}, SamePeer: true} | |
| 235 | 236 | payload := MarshalAttachTarget(target) | |
| 236 | 237 | want := append([]byte{0, 0, 0, 4, 'w', 'o', 'r', 'k', IntentAttach, 0, 0, 1, 1}, make([]byte, 15)...) | |
| 237 | 238 | want = append(want, 0, 4, 'w', 'o', 'r', 'k', 1) | |
| @@ -245,7 +246,7 @@ func TestAttachTargetExactTargetWireStrict(t *testing.T) { | |||
| 245 | 246 | assertAllPrefixesFail(t, payload, UnmarshalAttachTarget) | |
| 246 | 247 | assertTrailingGarbageFails(t, payload, UnmarshalAttachTarget) | |
| 247 | 248 | mismatched := target | |
| 248 | - | mismatched.ExactTarget = &ExactSessionTarget{LifecycleID: lifecycle, SessionName: "other"} | |
| 249 | + | mismatched.ExactTarget = &protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "other"} | |
| 249 | 250 | if got := MarshalAttachTarget(mismatched); got != nil { | |
| 250 | 251 | t.Fatalf("MarshalAttachTarget accepted mismatched target: %x", got) | |
| 251 | 252 | } | |
M internal/ports/wire_test.go +17 -16
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | renderer "github.com/bnema/vev-vt" | |
| 11 | 11 | "github.com/bnema/vev/internal/domain" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | "github.com/stretchr/testify/require" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| @@ -243,15 +244,15 @@ func TestInputGoldenAndRoundTrip(t *testing.T) { | |||
| 243 | 244 | func TestImagePushGoldenAndRoundTrip(t *testing.T) { | |
| 244 | 245 | tests := []struct { | |
| 245 | 246 | name string | |
| 246 | - | msg ImagePush | |
| 247 | + | msg protocol.ImagePush | |
| 247 | 248 | want []byte | |
| 248 | 249 | }{ | |
| 249 | 250 | { | |
| 250 | 251 | name: "png data", | |
| 251 | - | msg: ImagePush{InputSeq: 7, Mime: "image/png", Data: []byte{0x01, 0x02, 0x03}}, | |
| 252 | + | msg: protocol.ImagePush{InputSeq: 7, Mime: "image/png", Data: []byte{0x01, 0x02, 0x03}}, | |
| 252 | 253 | want: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x01, 0x02, 0x03}, | |
| 253 | 254 | }, | |
| 254 | - | {name: "empty", msg: ImagePush{}, want: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | |
| 255 | + | {name: "empty", msg: protocol.ImagePush{}, want: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, | |
| 255 | 256 | } | |
| 256 | 257 | ||
| 257 | 258 | for _, tt := range tests { | |
| @@ -288,17 +289,17 @@ func TestThemeGoldenAndRoundTrip(t *testing.T) { | |||
| 288 | 289 | zeroes := make([]byte, 57) | |
| 289 | 290 | tests := []struct { | |
| 290 | 291 | name string | |
| 291 | - | msg Theme | |
| 292 | + | msg protocol.Theme | |
| 292 | 293 | want []byte | |
| 293 | 294 | }{ | |
| 294 | 295 | { | |
| 295 | 296 | name: "empty", | |
| 296 | - | msg: Theme{}, | |
| 297 | + | msg: protocol.Theme{}, | |
| 297 | 298 | want: zeroes, | |
| 298 | 299 | }, | |
| 299 | 300 | { | |
| 300 | 301 | name: "foreground only", | |
| 301 | - | msg: Theme{ | |
| 302 | + | msg: protocol.Theme{ | |
| 302 | 303 | HasForeground: true, | |
| 303 | 304 | Foreground: renderer.RGB{R: 10, G: 20, B: 30}, | |
| 304 | 305 | Background: renderer.RGB{R: 40, G: 50, B: 60}, | |
| @@ -307,14 +308,14 @@ func TestThemeGoldenAndRoundTrip(t *testing.T) { | |||
| 307 | 308 | }, | |
| 308 | 309 | { | |
| 309 | 310 | name: "light flag without known scheme", | |
| 310 | - | msg: Theme{ | |
| 311 | + | msg: protocol.Theme{ | |
| 311 | 312 | Light: true, | |
| 312 | 313 | }, | |
| 313 | 314 | want: append([]byte{0x10}, zeroes[1:]...), | |
| 314 | 315 | }, | |
| 315 | 316 | { | |
| 316 | 317 | name: "full palette", | |
| 317 | - | msg: Theme{ | |
| 318 | + | msg: protocol.Theme{ | |
| 318 | 319 | HasForeground: true, | |
| 319 | 320 | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 320 | 321 | HasBackground: true, | |
| @@ -356,7 +357,7 @@ func TestThemeGenerationClearedWireGoldenPreservesProtocolVersion(t *testing.T) | |||
| 356 | 357 | // A generation clear retains defaults/capabilities but has no palette bits. | |
| 357 | 358 | // This literal payload locks the existing 57-byte Theme layout while the | |
| 358 | 359 | // full definitive-palette golden above locks the final publication. | |
| 359 | - | cleared := Theme{ | |
| 360 | + | cleared := protocol.Theme{ | |
| 360 | 361 | HasForeground: true, | |
| 361 | 362 | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 362 | 363 | HasBackground: true, | |
| @@ -370,7 +371,7 @@ func TestThemeGenerationClearedWireGoldenPreservesProtocolVersion(t *testing.T) | |||
| 370 | 371 | } | |
| 371 | 372 | ||
| 372 | 373 | func TestResizeGoldenAndRoundTrip(t *testing.T) { | |
| 373 | - | msg := Resize{Size: domain.Size{Cols: 100, Rows: 40}} | |
| 374 | + | msg := protocol.Resize{Size: domain.Size{Cols: 100, Rows: 40}} | |
| 374 | 375 | want := []byte{0x00, 0x64, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00} | |
| 375 | 376 | ||
| 376 | 377 | got, err := MarshalResize(msg) | |
| @@ -440,8 +441,8 @@ func TestPongGoldenAndRoundTrip(t *testing.T) { | |||
| 440 | 441 | func TestMarshalWelcomeRejectsInvalidCommittedIdentity(t *testing.T) { | |
| 441 | 442 | got := MarshalWelcome(Welcome{ | |
| 442 | 443 | SessionName: "work", | |
| 443 | - | CommittedIdentity: &CommittedRouteIdentity{ | |
| 444 | - | Target: ExactSessionTarget{SessionName: "different"}, | |
| 444 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{ | |
| 445 | + | Target: protocol.ExactSessionTarget{SessionName: "different"}, | |
| 445 | 446 | }, | |
| 446 | 447 | }) | |
| 447 | 448 | require.Nil(t, got) | |
| @@ -452,8 +453,8 @@ func TestMarshalWelcomeRejectsCommittedIdentityMetadataMismatch(t *testing.T) { | |||
| 452 | 453 | SessionID: "session", | |
| 453 | 454 | SessionName: "work", | |
| 454 | 455 | Ephemeral: true, | |
| 455 | - | CommittedIdentity: &CommittedRouteIdentity{ | |
| 456 | - | Target: ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "work"}, | |
| 456 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{ | |
| 457 | + | Target: protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "work"}, | |
| 457 | 458 | Ephemeral: true, | |
| 458 | 459 | }, | |
| 459 | 460 | } | |
| @@ -675,7 +676,7 @@ func TestErrorMsgGoldenAndRoundTrip(t *testing.T) { | |||
| 675 | 676 | } | |
| 676 | 677 | ||
| 677 | 678 | func TestOutputGoldenAndRoundTrip(t *testing.T) { | |
| 678 | - | msg := Output{Epoch: 1, Base: 0, New: 2, Echo: 3, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("hello\n")} | |
| 679 | + | msg := protocol.Output{Epoch: 1, Base: 0, New: 2, Echo: 3, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("hello\n")} | |
| 679 | 680 | want := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x0a} | |
| 680 | 681 | ||
| 681 | 682 | got, err := MarshalOutput(msg) | |
| @@ -698,7 +699,7 @@ func TestOutputGoldenAndRoundTrip(t *testing.T) { | |||
| 698 | 699 | } | |
| 699 | 700 | ||
| 700 | 701 | func TestAckGoldenAndRoundTrip(t *testing.T) { | |
| 701 | - | msg := Ack{Epoch: 1, State: 0x0102030405060708} | |
| 702 | + | msg := protocol.Ack{Epoch: 1, State: 0x0102030405060708} | |
| 702 | 703 | want := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} | |
| 703 | 704 | ||
| 704 | 705 | got, err := MarshalAck(msg) | |
A internal/protocol/navigation.go +106 -0
| @@ -0,0 +1,106 @@ | |||
| 1 | + | package protocol | |
| 2 | + | ||
| 3 | + | import "github.com/bnema/vev/internal/domain" | |
| 4 | + | ||
| 5 | + | type NavigationCapabilities uint8 | |
| 6 | + | ||
| 7 | + | const ( | |
| 8 | + | NavigationCapabilityHomePicker NavigationCapabilities = 1 << iota | |
| 9 | + | NavigationCapabilityBack | |
| 10 | + | ) | |
| 11 | + | ||
| 12 | + | type StartupOverlay uint8 | |
| 13 | + | ||
| 14 | + | const ( | |
| 15 | + | StartupOverlayNone StartupOverlay = iota | |
| 16 | + | StartupOverlaySessionPicker | |
| 17 | + | ) | |
| 18 | + | ||
| 19 | + | type NavigationAction uint8 | |
| 20 | + | ||
| 21 | + | const ( | |
| 22 | + | NavigationOpenHomePicker NavigationAction = 1 | |
| 23 | + | NavigationBack NavigationAction = 2 | |
| 24 | + | ) | |
| 25 | + | ||
| 26 | + | type ParkedRouteLeaseID [16]byte | |
| 27 | + | ||
| 28 | + | func (id ParkedRouteLeaseID) IsZero() bool { return id == ParkedRouteLeaseID{} } | |
| 29 | + | ||
| 30 | + | type NavigationDirective struct { | |
| 31 | + | Action NavigationAction | |
| 32 | + | LeaseID ParkedRouteLeaseID | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | type ParkedRouteAction uint8 | |
| 36 | + | ||
| 37 | + | const ( | |
| 38 | + | ParkedRoutePrepare ParkedRouteAction = iota + 1 | |
| 39 | + | ParkedRouteResume | |
| 40 | + | ParkedRouteSwitch | |
| 41 | + | ) | |
| 42 | + | ||
| 43 | + | type ParkedRouteRequest struct { | |
| 44 | + | RequestID uint64 | |
| 45 | + | LeaseID ParkedRouteLeaseID | |
| 46 | + | Action ParkedRouteAction | |
| 47 | + | Target *domain.RemoteSessionTarget | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | type ParkedRouteStatus uint8 | |
| 51 | + | ||
| 52 | + | const ( | |
| 53 | + | ParkedRouteReady ParkedRouteStatus = iota + 1 | |
| 54 | + | ParkedRouteResumed | |
| 55 | + | ParkedRouteSwitched | |
| 56 | + | ParkedRouteRejected | |
| 57 | + | ParkedRouteExpired | |
| 58 | + | ParkedRouteStaleTarget | |
| 59 | + | ) | |
| 60 | + | ||
| 61 | + | type ParkedRouteResponse struct { | |
| 62 | + | RequestID uint64 | |
| 63 | + | Status ParkedRouteStatus | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | func validNavigationCapabilities(capabilities NavigationCapabilities) bool { | |
| 67 | + | return capabilities&^(NavigationCapabilityHomePicker|NavigationCapabilityBack) == 0 | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | func validStartupOverlay(overlay StartupOverlay) bool { | |
| 71 | + | return overlay == StartupOverlayNone || overlay == StartupOverlaySessionPicker | |
| 72 | + | } | |
| 73 | + | ||
| 74 | + | func ValidateNavigation(capabilities NavigationCapabilities, overlay StartupOverlay, homePickerRoute bool) error { | |
| 75 | + | if !validNavigationCapabilities(capabilities) || !validStartupOverlay(overlay) { | |
| 76 | + | return ErrInvalidNavigation | |
| 77 | + | } | |
| 78 | + | home := capabilities&NavigationCapabilityHomePicker != 0 | |
| 79 | + | back := capabilities&NavigationCapabilityBack != 0 | |
| 80 | + | if (home && !homePickerRoute) || back != (overlay == StartupOverlaySessionPicker) { | |
| 81 | + | return ErrInvalidNavigation | |
| 82 | + | } | |
| 83 | + | if homePickerRoute && back { | |
| 84 | + | return ErrInvalidNavigation | |
| 85 | + | } | |
| 86 | + | return nil | |
| 87 | + | } | |
| 88 | + | ||
| 89 | + | func ValidateParkedRouteRequest(request ParkedRouteRequest) error { | |
| 90 | + | if request.RequestID == 0 || request.LeaseID.IsZero() { | |
| 91 | + | return ErrInvalidNavigation | |
| 92 | + | } | |
| 93 | + | switch request.Action { | |
| 94 | + | case ParkedRoutePrepare, ParkedRouteResume: | |
| 95 | + | if request.Target != nil { | |
| 96 | + | return ErrInvalidNavigation | |
| 97 | + | } | |
| 98 | + | case ParkedRouteSwitch: | |
| 99 | + | if request.Target == nil || validateRemoteTarget(*request.Target) != nil { | |
| 100 | + | return ErrInvalidNavigation | |
| 101 | + | } | |
| 102 | + | default: | |
| 103 | + | return ErrInvalidNavigation | |
| 104 | + | } | |
| 105 | + | return nil | |
| 106 | + | } | |
R internal/ports/remote_preview.go → internal/protocol/preview.go +35 -1 renamed, 82% similar
| @@ -1,4 +1,4 @@ | |||
| 1 | - | package ports | |
| 1 | + | package protocol | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "errors" | |
| @@ -10,6 +10,40 @@ import ( | |||
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | ) | |
| 12 | 12 | ||
| 13 | + | // RemotePreviewSchemaVersion is independent from the attachment protocol version. | |
| 14 | + | const RemotePreviewSchemaVersion uint16 = 1 | |
| 15 | + | ||
| 16 | + | type RemotePreviewStatus uint8 | |
| 17 | + | ||
| 18 | + | const ( | |
| 19 | + | RemotePreviewOK RemotePreviewStatus = iota | |
| 20 | + | RemotePreviewUnavailable | |
| 21 | + | RemotePreviewNoSuchTarget | |
| 22 | + | RemotePreviewStale | |
| 23 | + | RemotePreviewMalformed | |
| 24 | + | RemotePreviewTooLarge | |
| 25 | + | ) | |
| 26 | + | ||
| 27 | + | type RemotePreviewRequest struct { | |
| 28 | + | Version uint16 | |
| 29 | + | Target domain.RemoteSessionTarget | |
| 30 | + | Width uint16 | |
| 31 | + | Height uint16 | |
| 32 | + | } | |
| 33 | + | ||
| 34 | + | // RemotePreview is a bounded row-major styled-cell viewport. It is never | |
| 35 | + | // persisted, logged, or traced. | |
| 36 | + | type RemotePreview struct { | |
| 37 | + | Version uint16 | |
| 38 | + | Status RemotePreviewStatus | |
| 39 | + | LifecycleID domain.SessionLifecycleID | |
| 40 | + | TabID domain.TabStableID | |
| 41 | + | Revision uint64 | |
| 42 | + | Width uint16 | |
| 43 | + | Height uint16 | |
| 44 | + | Cells []renderer.Cell | |
| 45 | + | } | |
| 46 | + | ||
| 13 | 47 | const ( | |
| 14 | 48 | RemotePreviewMaxWidth = 256 | |
| 15 | 49 | RemotePreviewMaxHeight = 128 | |
R internal/ports/routes.go → internal/protocol/routes.go +21 -3 renamed, 93% similar
| @@ -1,4 +1,4 @@ | |||
| 1 | - | package ports | |
| 1 | + | package protocol | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "errors" | |
| @@ -9,6 +9,10 @@ import ( | |||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | ) | |
| 11 | 11 | ||
| 12 | + | // ErrInvalidRouteWire preserves the public error classification used by | |
| 13 | + | // strict route codecs while route values live in the semantic protocol. | |
| 14 | + | var ErrInvalidRouteWire = errors.New("invalid route wire message") | |
| 15 | + | ||
| 12 | 16 | // RouteOrigin identifies how a client reached a daemon. The origin is client | |
| 13 | 17 | // composition metadata, not an authority granted to the daemon. | |
| 14 | 18 | type RouteOrigin uint8 | |
| @@ -181,10 +185,10 @@ type RouteAttentionSubscription struct { | |||
| 181 | 185 | Targets []RouteAttentionTarget | |
| 182 | 186 | } | |
| 183 | 187 | ||
| 184 | - | func (r RouteRef) empty() bool { return r.Key == 0 && r.Generation == 0 } | |
| 188 | + | func (r RouteRef) IsZero() bool { return r.Key == 0 && r.Generation == 0 } | |
| 185 | 189 | ||
| 186 | 190 | func (r RouteRef) Validate() error { | |
| 187 | - | if r.empty() { | |
| 191 | + | if r.IsZero() { | |
| 188 | 192 | return nil | |
| 189 | 193 | } | |
| 190 | 194 | if r.Key == 0 || r.Generation == 0 { | |
| @@ -266,6 +270,13 @@ func (c SamePeerSwitchFailureCode) valid() bool { | |||
| 266 | 270 | return c == SamePeerSwitchStaleTarget || c == SamePeerSwitchUnavailable | |
| 267 | 271 | } | |
| 268 | 272 | ||
| 273 | + | func (c SamePeerSwitchFailureCode) Validate() error { | |
| 274 | + | if !c.valid() { | |
| 275 | + | return ErrInvalidRouteWire | |
| 276 | + | } | |
| 277 | + | return nil | |
| 278 | + | } | |
| 279 | + | ||
| 269 | 280 | // SamePeerSwitchFailure leaves the source attachment unchanged. RequestID | |
| 270 | 281 | // rejects a delayed failure after a later user selection. | |
| 271 | 282 | type SamePeerSwitchFailure struct { | |
| @@ -307,6 +318,13 @@ func (c RouteFailureCode) valid() bool { | |||
| 307 | 318 | } | |
| 308 | 319 | } | |
| 309 | 320 | ||
| 321 | + | func (c RouteFailureCode) Validate() error { | |
| 322 | + | if !c.valid() { | |
| 323 | + | return ErrInvalidRouteWire | |
| 324 | + | } | |
| 325 | + | return nil | |
| 326 | + | } | |
| 327 | + | ||
| 310 | 328 | const ( | |
| 311 | 329 | // RouteSnapshotMaxEntries bounds one immutable publication and the amount | |
| 312 | 330 | // of work a receiver performs before returning to its transport loop. The | |
A internal/protocol/session.go +101 -0
| @@ -0,0 +1,101 @@ | |||
| 1 | + | // Package protocol defines vev's typed, transport-neutral client/daemon | |
| 2 | + | // contract. Binary framing and codecs live outside this package. | |
| 3 | + | package protocol | |
| 4 | + | ||
| 5 | + | import ( | |
| 6 | + | "errors" | |
| 7 | + | "fmt" | |
| 8 | + | "math" | |
| 9 | + | ||
| 10 | + | renderer "github.com/bnema/vev-vt" | |
| 11 | + | "github.com/bnema/vev/internal/domain" | |
| 12 | + | ) | |
| 13 | + | ||
| 14 | + | // MaxOutputDataLen is the largest decoded terminal byte stream accepted by one | |
| 15 | + | // output publication in protocol version 37. | |
| 16 | + | const MaxOutputDataLen = (16 << 20) - 55 | |
| 17 | + | ||
| 18 | + | var ( | |
| 19 | + | ErrInvalidSize = errors.New("ports: invalid terminal size") | |
| 20 | + | ErrInvalidOutput = errors.New("ports: invalid output") | |
| 21 | + | ErrInvalidAck = errors.New("ports: invalid ack") | |
| 22 | + | ErrInvalidNavigation = errors.New("ports: invalid navigation") | |
| 23 | + | ) | |
| 24 | + | ||
| 25 | + | type Resize struct { | |
| 26 | + | Size domain.Size | |
| 27 | + | PixelWidth int | |
| 28 | + | PixelHeight int | |
| 29 | + | } | |
| 30 | + | ||
| 31 | + | func (m Resize) Geometry() domain.Geometry { | |
| 32 | + | return domain.Geometry{Size: m.Size, PixelWidth: m.PixelWidth, PixelHeight: m.PixelHeight}.NormalizePixels() | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | type Theme struct { | |
| 36 | + | HasForeground bool | |
| 37 | + | Foreground renderer.RGB | |
| 38 | + | HasBackground bool | |
| 39 | + | Background renderer.RGB | |
| 40 | + | TrueColor bool | |
| 41 | + | SchemeKnown bool | |
| 42 | + | Light bool | |
| 43 | + | PaletteKnown uint16 | |
| 44 | + | Palette [16]renderer.RGB | |
| 45 | + | } | |
| 46 | + | ||
| 47 | + | type ImagePush struct { | |
| 48 | + | InputSeq uint64 | |
| 49 | + | Mime string | |
| 50 | + | Data []byte | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | type Ack struct { | |
| 54 | + | Epoch uint64 | |
| 55 | + | State uint64 | |
| 56 | + | } | |
| 57 | + | ||
| 58 | + | type Output struct { | |
| 59 | + | Epoch uint64 | |
| 60 | + | Base uint64 | |
| 61 | + | New uint64 | |
| 62 | + | Echo uint64 | |
| 63 | + | ViewRevision uint64 | |
| 64 | + | Size domain.Size | |
| 65 | + | Full bool | |
| 66 | + | Data []byte | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | func ValidateOutput(m Output) error { | |
| 70 | + | if m.Epoch == 0 { | |
| 71 | + | return ErrInvalidOutput | |
| 72 | + | } | |
| 73 | + | if m.New == 0 { | |
| 74 | + | if m.Base != 0 || m.Full { | |
| 75 | + | return ErrInvalidOutput | |
| 76 | + | } | |
| 77 | + | } else if (m.Base == 0 && !m.Full) || (m.Base != 0 && (m.Full || m.New != m.Base+1)) { | |
| 78 | + | return ErrInvalidOutput | |
| 79 | + | } | |
| 80 | + | if err := ValidateSize(m.Size); err != nil { | |
| 81 | + | return fmt.Errorf("%w: size", ErrInvalidOutput) | |
| 82 | + | } | |
| 83 | + | if uint64(len(m.Data)) > math.MaxUint32 || len(m.Data) > MaxOutputDataLen { | |
| 84 | + | return ErrInvalidOutput | |
| 85 | + | } | |
| 86 | + | return nil | |
| 87 | + | } | |
| 88 | + | ||
| 89 | + | func ValidateAck(m Ack) error { | |
| 90 | + | if m.Epoch == 0 { | |
| 91 | + | return ErrInvalidAck | |
| 92 | + | } | |
| 93 | + | return nil | |
| 94 | + | } | |
| 95 | + | ||
| 96 | + | func validateRemoteTarget(target domain.RemoteSessionTarget) error { | |
| 97 | + | if len(target.Endpoint) > math.MaxUint16 || len(target.DisplayOrigin) > math.MaxUint16 || len(target.SessionName) > math.MaxUint16 || len(target.LiveTabID) > math.MaxUint16 || len(target.StoppedTab.RawName) > math.MaxUint16 { | |
| 98 | + | return errors.New("remote target string too long") | |
| 99 | + | } | |
| 100 | + | return target.Validate() | |
| 101 | + | } | |
A internal/protocol/session_test.go +49 -0
| @@ -0,0 +1,49 @@ | |||
| 1 | + | package protocol | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "errors" | |
| 5 | + | "testing" | |
| 6 | + | ||
| 7 | + | renderer "github.com/bnema/vev-vt" | |
| 8 | + | "github.com/bnema/vev/internal/domain" | |
| 9 | + | "github.com/stretchr/testify/require" | |
| 10 | + | ) | |
| 11 | + | ||
| 12 | + | func TestOutputSemanticValidation(t *testing.T) { | |
| 13 | + | valid := Output{Epoch: 1, New: 1, Full: true, Size: domain.Size{Cols: 80, Rows: 24}} | |
| 14 | + | require.NoError(t, ValidateOutput(valid)) | |
| 15 | + | ||
| 16 | + | invalid := valid | |
| 17 | + | invalid.Epoch = 0 | |
| 18 | + | require.ErrorIs(t, ValidateOutput(invalid), ErrInvalidOutput) | |
| 19 | + | ||
| 20 | + | invalid = valid | |
| 21 | + | invalid.Data = make([]byte, MaxOutputDataLen+1) | |
| 22 | + | require.ErrorIs(t, ValidateOutput(invalid), ErrInvalidOutput) | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | func TestRouteAndPreviewSemanticValidation(t *testing.T) { | |
| 26 | + | require.Error(t, ValidateRouteLabel("\x1b[31m", false)) | |
| 27 | + | require.NoError(t, RouteRef{}.Validate()) | |
| 28 | + | require.Error(t, (RouteRef{Key: 1}).Validate()) | |
| 29 | + | ||
| 30 | + | target := domain.RemoteSessionTarget{ | |
| 31 | + | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: domain.SessionLifecycleID{1}, | |
| 32 | + | SessionName: "work", LiveTabID: "tab-1", | |
| 33 | + | } | |
| 34 | + | request := RemotePreviewRequest{Version: RemotePreviewSchemaVersion, Target: target, Width: 1, Height: 1} | |
| 35 | + | require.NoError(t, ValidateRemotePreviewRequest(request)) | |
| 36 | + | preview := RemotePreview{ | |
| 37 | + | Version: RemotePreviewSchemaVersion, Status: RemotePreviewOK, | |
| 38 | + | LifecycleID: target.LifecycleID, TabID: target.LiveTabID, Revision: 1, | |
| 39 | + | Width: 1, Height: 1, Cells: []renderer.Cell{{Rune: 'x'}}, | |
| 40 | + | } | |
| 41 | + | require.NoError(t, ValidateRemotePreview(preview)) | |
| 42 | + | preview.Cells[0].Rune = '\n' | |
| 43 | + | require.ErrorIs(t, ValidateRemotePreview(preview), ErrInvalidRemotePreview) | |
| 44 | + | } | |
| 45 | + | ||
| 46 | + | func TestPresentationErrorsPreserveClassification(t *testing.T) { | |
| 47 | + | require.True(t, errors.Is(ValidateAck(Ack{}), ErrInvalidAck)) | |
| 48 | + | require.True(t, errors.Is(ValidateParkedRouteRequest(ParkedRouteRequest{}), ErrInvalidNavigation)) | |
| 49 | + | } | |
R internal/ports/wire_size.go → internal/protocol/size.go +1 -1 renamed, 98% similar
| @@ -1,4 +1,4 @@ | |||
| 1 | - | package ports | |
| 1 | + | package protocol | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "math" | |
M internal/testutil/replaytest/replay.go +4 -3
| @@ -9,9 +9,10 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | - | func mustMarshalOutput(m ports.Output) []byte { | |
| 15 | + | func mustMarshalOutput(m protocol.Output) []byte { | |
| 15 | 16 | payload, err := ports.MarshalOutput(m) | |
| 16 | 17 | if err != nil { | |
| 17 | 18 | panic(err) | |
| @@ -20,8 +21,8 @@ func mustMarshalOutput(m ports.Output) []byte { | |||
| 20 | 21 | } | |
| 21 | 22 | ||
| 22 | 23 | var transcript = []ports.Frame{ | |
| 23 | - | {Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("\x1b[2J\x1b[Hone\r\ntwo")})}, | |
| 24 | - | {Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{Epoch: 1, Base: 1, New: 2, Echo: 7, Size: domain.Size{Cols: 80, Rows: 24}, Data: []byte("\x1b[2;1HTWO")})}, | |
| 24 | + | {Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("\x1b[2J\x1b[Hone\r\ntwo")})}, | |
| 25 | + | {Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{Epoch: 1, Base: 1, New: 2, Echo: 7, Size: domain.Size{Cols: 80, Rows: 24}, Data: []byte("\x1b[2;1HTWO")})}, | |
| 25 | 26 | } | |
| 26 | 27 | ||
| 27 | 28 | // Transcript returns a deep copy of the canonical replay transcript so an | |
M internal/usecase/client/client.go +67 -66
| @@ -23,6 +23,7 @@ import ( | |||
| 23 | 23 | "github.com/bnema/vev-vt/protocol/terminalquery" | |
| 24 | 24 | "github.com/bnema/vev/internal/domain" | |
| 25 | 25 | "github.com/bnema/vev/internal/ports" | |
| 26 | + | "github.com/bnema/vev/internal/protocol" | |
| 26 | 27 | "github.com/bnema/vev/internal/usecase/theme" | |
| 27 | 28 | ) | |
| 28 | 29 | ||
| @@ -55,7 +56,7 @@ func (e *DetachedError) Error() string { return "vev: " + e.Text } | |||
| 55 | 56 | // without relying on another OSC response. | |
| 56 | 57 | type terminalThemeState struct { | |
| 57 | 58 | mu sync.Mutex | |
| 58 | - | theme ports.Theme | |
| 59 | + | theme protocol.Theme | |
| 59 | 60 | } | |
| 60 | 61 | ||
| 61 | 62 | func (s *terminalThemeState) setTrueColor(enabled bool) { | |
| @@ -64,14 +65,14 @@ func (s *terminalThemeState) setTrueColor(enabled bool) { | |||
| 64 | 65 | s.mu.Unlock() | |
| 65 | 66 | } | |
| 66 | 67 | ||
| 67 | - | func (s *terminalThemeState) update(update func(*ports.Theme)) ports.Theme { | |
| 68 | + | func (s *terminalThemeState) update(update func(*protocol.Theme)) protocol.Theme { | |
| 68 | 69 | s.mu.Lock() | |
| 69 | 70 | defer s.mu.Unlock() | |
| 70 | 71 | update(&s.theme) | |
| 71 | 72 | return s.theme | |
| 72 | 73 | } | |
| 73 | 74 | ||
| 74 | - | func (s *terminalThemeState) snapshot() ports.Theme { | |
| 75 | + | func (s *terminalThemeState) snapshot() protocol.Theme { | |
| 75 | 76 | s.mu.Lock() | |
| 76 | 77 | defer s.mu.Unlock() | |
| 77 | 78 | return s.theme | |
| @@ -171,7 +172,7 @@ type Dependencies struct { | |||
| 171 | 172 | Remote bool | |
| 172 | 173 | // Origin is explicit composition metadata for the initial route. A zero | |
| 173 | 174 | // value is normalized to local for direct package callers and old tests. | |
| 174 | - | Origin ports.RouteOrigin | |
| 175 | + | Origin protocol.RouteOrigin | |
| 175 | 176 | OriginKey string | |
| 176 | 177 | } | |
| 177 | 178 | ||
| @@ -182,15 +183,15 @@ type AttachRequest struct { | |||
| 182 | 183 | Intent uint8 | |
| 183 | 184 | SessionName string | |
| 184 | 185 | Remote bool | |
| 185 | - | Origin ports.RouteOrigin | |
| 186 | + | Origin protocol.RouteOrigin | |
| 186 | 187 | OriginKey string | |
| 187 | 188 | RemoteTarget *domain.RemoteSessionTarget | |
| 188 | - | ExactTarget *ports.ExactSessionTarget | |
| 189 | + | ExactTarget *protocol.ExactSessionTarget | |
| 189 | 190 | PreferredTabID domain.TabStableID | |
| 190 | 191 | HostLabel string | |
| 191 | 192 | EnvironmentPolicy ports.EnvironmentPolicy | |
| 192 | - | NavigationCapabilities ports.NavigationCapabilities | |
| 193 | - | StartupOverlay ports.StartupOverlay | |
| 193 | + | NavigationCapabilities protocol.NavigationCapabilities | |
| 194 | + | StartupOverlay protocol.StartupOverlay | |
| 194 | 195 | } | |
| 195 | 196 | ||
| 196 | 197 | // attachRoute captures the dialer, request, and resume token needed to | |
| @@ -211,9 +212,9 @@ type Runner struct { | |||
| 211 | 212 | remoteHostLearner ports.RemoteHostLearner | |
| 212 | 213 | attachHandoff AttachHandoffFunc | |
| 213 | 214 | remote bool | |
| 214 | - | origin ports.RouteOrigin | |
| 215 | + | origin protocol.RouteOrigin | |
| 215 | 216 | ledger *routeLedger | |
| 216 | - | routeFailure *ports.RouteNavigationFailure | |
| 217 | + | routeFailure *protocol.RouteNavigationFailure | |
| 217 | 218 | ||
| 218 | 219 | inputMu sync.Mutex | |
| 219 | 220 | input *terminalInputPump | |
| @@ -360,7 +361,7 @@ func validateAttachRequest(request AttachRequest) error { | |||
| 360 | 361 | } | |
| 361 | 362 | } | |
| 362 | 363 | if request.OriginKey != "" { | |
| 363 | - | if err := ports.ValidateRouteLabel(request.OriginKey, false); err != nil { | |
| 364 | + | if err := protocol.ValidateRouteLabel(request.OriginKey, false); err != nil { | |
| 364 | 365 | return fmt.Errorf("vev: invalid route origin key: %w", err) | |
| 365 | 366 | } | |
| 366 | 367 | } | |
| @@ -378,7 +379,7 @@ func validateAttachRequest(request AttachRequest) error { | |||
| 378 | 379 | if err := (SessionTarget{Intent: request.Intent, SessionName: request.SessionName}).validate(); err != nil { | |
| 379 | 380 | return fmt.Errorf("vev: invalid session target: %w", err) | |
| 380 | 381 | } | |
| 381 | - | if err := ports.ValidateNavigation(request.NavigationCapabilities, request.StartupOverlay, request.RemoteTarget != nil || request.EnvironmentPolicy == ports.EnvironmentPolicyDaemonOwned); err != nil { | |
| 382 | + | if err := protocol.ValidateNavigation(request.NavigationCapabilities, request.StartupOverlay, request.RemoteTarget != nil || request.EnvironmentPolicy == ports.EnvironmentPolicyDaemonOwned); err != nil { | |
| 382 | 383 | return fmt.Errorf("vev: invalid navigation route: %w", err) | |
| 383 | 384 | } | |
| 384 | 385 | if request.RemoteTarget == nil { | |
| @@ -452,7 +453,7 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 452 | 453 | routeNavigationResumeFallback := false | |
| 453 | 454 | var routeNavigationSelection *routeNavigationSelection | |
| 454 | 455 | var routeNavigationFallback *attachRoute | |
| 455 | - | var routeNavigationAction *ports.RouteNavigationAction | |
| 456 | + | var routeNavigationAction *protocol.RouteNavigationAction | |
| 456 | 457 | backoff := defaultReconnectBackoff.initial | |
| 457 | 458 | themeState := &terminalThemeState{} | |
| 458 | 459 | var rememberOnce sync.Once | |
| @@ -513,8 +514,8 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 513 | 514 | } else { | |
| 514 | 515 | attemptRequest.Intent = ports.IntentAttach | |
| 515 | 516 | } | |
| 516 | - | attemptRequest.StartupOverlay = ports.StartupOverlayNone | |
| 517 | - | attemptRequest.NavigationCapabilities &^= ports.NavigationCapabilityBack | ports.NavigationCapabilityHomePicker | |
| 517 | + | attemptRequest.StartupOverlay = protocol.StartupOverlayNone | |
| 518 | + | attemptRequest.NavigationCapabilities &^= protocol.NavigationCapabilityBack | protocol.NavigationCapabilityHomePicker | |
| 518 | 519 | resumeToken = route.resumeToken | |
| 519 | 520 | returnResumeFallback = route.resumeToken != 0 | |
| 520 | 521 | remote = syncReconnectRemote(reconnect, attemptRequest.Remote || r.remote) | |
| @@ -524,8 +525,8 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 524 | 525 | dialer = homeRoute.dialer | |
| 525 | 526 | attemptRequest = homeRoute.request | |
| 526 | 527 | attemptRequest.Intent = ports.IntentAttach | |
| 527 | - | attemptRequest.NavigationCapabilities = ports.NavigationCapabilityBack | |
| 528 | - | attemptRequest.StartupOverlay = ports.StartupOverlaySessionPicker | |
| 528 | + | attemptRequest.NavigationCapabilities = protocol.NavigationCapabilityBack | |
| 529 | + | attemptRequest.StartupOverlay = protocol.StartupOverlaySessionPicker | |
| 529 | 530 | attemptRequest.RemoteTarget = nil | |
| 530 | 531 | attemptRequest.EnvironmentPolicy = ports.EnvironmentPolicyClientOwned | |
| 531 | 532 | attemptRequest.Remote = homeRoute.request.Remote || r.remote | |
| @@ -556,8 +557,8 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 556 | 557 | } | |
| 557 | 558 | request := cloneAttachRequest(homeRoute.request) | |
| 558 | 559 | request.Intent = ports.IntentAttach | |
| 559 | - | request.NavigationCapabilities = ports.NavigationCapabilityBack | |
| 560 | - | request.StartupOverlay = ports.StartupOverlaySessionPicker | |
| 560 | + | request.NavigationCapabilities = protocol.NavigationCapabilityBack | |
| 561 | + | request.StartupOverlay = protocol.StartupOverlaySessionPicker | |
| 561 | 562 | request.RemoteTarget = nil | |
| 562 | 563 | request.EnvironmentPolicy = ports.EnvironmentPolicyClientOwned | |
| 563 | 564 | request.Remote = false | |
| @@ -739,10 +740,10 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 739 | 740 | // Back is transient to the picker overlay. Re-derive the home-picker | |
| 740 | 741 | // capability from the selected route instead of trusting request | |
| 741 | 742 | // metadata, which may have been cleared after a daemon-side switch. | |
| 742 | - | attemptRequest.StartupOverlay = ports.StartupOverlayNone | |
| 743 | + | attemptRequest.StartupOverlay = protocol.StartupOverlayNone | |
| 743 | 744 | attemptRequest.NavigationCapabilities = 0 | |
| 744 | - | if homeRoute != nil && selection.selected.presentation.kind == ports.RouteKindRemote { | |
| 745 | - | attemptRequest.NavigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 745 | + | if homeRoute != nil && selection.selected.presentation.kind == protocol.RouteKindRemote { | |
| 746 | + | attemptRequest.NavigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 746 | 747 | } | |
| 747 | 748 | resumeToken = selection.selected.resumeToken | |
| 748 | 749 | routeNavigationPending = true | |
| @@ -754,7 +755,7 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 754 | 755 | } | |
| 755 | 756 | if result.action != 0 { | |
| 756 | 757 | switch result.action { | |
| 757 | - | case ports.NavigationOpenHomePicker: | |
| 758 | + | case protocol.NavigationOpenHomePicker: | |
| 758 | 759 | // The daemon only sends this action after accepting a Hello that | |
| 759 | 760 | // advertised Home support. The durable client-side prerequisite is | |
| 760 | 761 | // the captured route itself; request metadata may have been rebased by | |
| @@ -770,7 +771,7 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 770 | 771 | homeNavigationPending = true | |
| 771 | 772 | enterHomePicker() | |
| 772 | 773 | continue | |
| 773 | - | case ports.NavigationBack: | |
| 774 | + | case protocol.NavigationBack: | |
| 774 | 775 | // As with Home, the daemon accepted Back in Hello before sending | |
| 775 | 776 | // this action. The retained concrete route is the durable client | |
| 776 | 777 | // prerequisite; request metadata may have been rebased meanwhile. | |
| @@ -796,7 +797,7 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 796 | 797 | } | |
| 797 | 798 | routeRequest.Intent = ports.IntentAttach | |
| 798 | 799 | routeRequest.NavigationCapabilities = 0 | |
| 799 | - | routeRequest.StartupOverlay = ports.StartupOverlayNone | |
| 800 | + | routeRequest.StartupOverlay = protocol.StartupOverlayNone | |
| 800 | 801 | homeRoute = &attachRoute{dialer: dialer, request: routeRequest} | |
| 801 | 802 | } | |
| 802 | 803 | } | |
| @@ -832,9 +833,9 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 832 | 833 | nextRequest.ExactTarget = result.target.ExactTarget | |
| 833 | 834 | } | |
| 834 | 835 | if homeRoute != nil && (nextRequest.RemoteTarget != nil || nextRequest.EnvironmentPolicy == ports.EnvironmentPolicyDaemonOwned) { | |
| 835 | - | nextRequest.NavigationCapabilities |= ports.NavigationCapabilityHomePicker | |
| 836 | + | nextRequest.NavigationCapabilities |= protocol.NavigationCapabilityHomePicker | |
| 836 | 837 | } | |
| 837 | - | if attemptRequest.StartupOverlay == ports.StartupOverlaySessionPicker { | |
| 838 | + | if attemptRequest.StartupOverlay == protocol.StartupOverlaySessionPicker { | |
| 838 | 839 | returnRoute = nil | |
| 839 | 840 | returnResumeFallback = false | |
| 840 | 841 | } | |
| @@ -882,7 +883,7 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error) | |||
| 882 | 883 | if routeNavigationPending && routeNavigationFallback != nil { | |
| 883 | 884 | if routeNavigationAction != nil { | |
| 884 | 885 | action := *routeNavigationAction | |
| 885 | - | r.routeFailure = &ports.RouteNavigationFailure{Key: action.Key, Generation: action.Generation, Code: routeFailureCode(result.err)} | |
| 886 | + | r.routeFailure = &protocol.RouteNavigationFailure{Key: action.Key, Generation: action.Generation, Code: routeFailureCode(result.err)} | |
| 886 | 887 | routeNavigationAction = nil | |
| 887 | 888 | } | |
| 888 | 889 | route := *routeNavigationFallback | |
| @@ -1084,14 +1085,14 @@ type attachAttempt struct { | |||
| 1084 | 1085 | type attachResult struct { | |
| 1085 | 1086 | resumeToken uint64 | |
| 1086 | 1087 | sessionName string | |
| 1087 | - | committedIdentity *ports.CommittedRouteIdentity | |
| 1088 | - | routePosition *ports.RoutePosition | |
| 1088 | + | committedIdentity *protocol.CommittedRouteIdentity | |
| 1089 | + | routePosition *protocol.RoutePosition | |
| 1089 | 1090 | welcomed bool | |
| 1090 | 1091 | transportClosed bool | |
| 1091 | 1092 | target *ports.AttachTarget | |
| 1092 | - | action ports.NavigationAction | |
| 1093 | + | action protocol.NavigationAction | |
| 1093 | 1094 | homePickerTarget bool | |
| 1094 | - | routeAction *ports.RouteNavigationAction | |
| 1095 | + | routeAction *protocol.RouteNavigationAction | |
| 1095 | 1096 | err error | |
| 1096 | 1097 | } | |
| 1097 | 1098 | ||
| @@ -1213,7 +1214,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1213 | 1214 | themeState.setTrueColor(trueColor) | |
| 1214 | 1215 | exactTarget := request.ExactTarget | |
| 1215 | 1216 | if exactTarget == nil && request.RemoteTarget != nil { | |
| 1216 | - | exactTarget = &ports.ExactSessionTarget{ | |
| 1217 | + | exactTarget = &protocol.ExactSessionTarget{ | |
| 1217 | 1218 | LifecycleID: request.RemoteTarget.LifecycleID, | |
| 1218 | 1219 | SessionName: request.RemoteTarget.SessionName, | |
| 1219 | 1220 | } | |
| @@ -1257,8 +1258,8 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1257 | 1258 | }, transition); err != nil { | |
| 1258 | 1259 | return handshakeFailure("awaiting welcome", err) | |
| 1259 | 1260 | } | |
| 1260 | - | var committedIdentity *ports.CommittedRouteIdentity | |
| 1261 | - | var routePosition *ports.RoutePosition | |
| 1261 | + | var committedIdentity *protocol.CommittedRouteIdentity | |
| 1262 | + | var routePosition *protocol.RoutePosition | |
| 1262 | 1263 | result := func(welcomed bool, err error) attachResult { | |
| 1263 | 1264 | return attachResult{ | |
| 1264 | 1265 | resumeToken: resumeToken, | |
| @@ -1391,7 +1392,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1391 | 1392 | delete(timers, id) | |
| 1392 | 1393 | } | |
| 1393 | 1394 | } | |
| 1394 | - | publish := func(snapshot ports.Theme) error { | |
| 1395 | + | publish := func(snapshot protocol.Theme) error { | |
| 1395 | 1396 | frame := ports.Frame{Type: ports.MsgTheme, Payload: ports.MarshalTheme(snapshot)} | |
| 1396 | 1397 | // The initial cleared snapshot is sent before the sender exists. This | |
| 1397 | 1398 | // keeps the generation publication ordered before the first query and | |
| @@ -1417,7 +1418,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1417 | 1418 | return fmt.Errorf("publishing theme: %w", err) | |
| 1418 | 1419 | } | |
| 1419 | 1420 | case paletteActionPublishFinal: | |
| 1420 | - | themeState.update(func(current *ports.Theme) { *current = action.theme }) | |
| 1421 | + | themeState.update(func(current *protocol.Theme) { *current = action.theme }) | |
| 1421 | 1422 | if err := publish(action.theme); err != nil { | |
| 1422 | 1423 | return fmt.Errorf("publishing theme: %w", err) | |
| 1423 | 1424 | } | |
| @@ -1487,8 +1488,8 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1487 | 1488 | var nextSamePeerRequestID uint64 | |
| 1488 | 1489 | type parkedRoutePending struct { | |
| 1489 | 1490 | requestID uint64 | |
| 1490 | - | action ports.ParkedRouteAction | |
| 1491 | - | leaseID ports.ParkedRouteLeaseID | |
| 1491 | + | action protocol.ParkedRouteAction | |
| 1492 | + | leaseID protocol.ParkedRouteLeaseID | |
| 1492 | 1493 | fallbackTarget *ports.AttachTarget | |
| 1493 | 1494 | timer ports.Timer | |
| 1494 | 1495 | } | |
| @@ -1502,7 +1503,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1502 | 1503 | // Before the asynchronous sender starts, preserve transport ordering by | |
| 1503 | 1504 | // requesting the reset synchronously after the initial Theme publication. | |
| 1504 | 1505 | resetErr := sendHandshake(func() error { | |
| 1505 | - | payload, err := ports.MarshalResize(ports.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 1506 | + | payload, err := ports.MarshalResize(protocol.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 1506 | 1507 | if err != nil { | |
| 1507 | 1508 | return err | |
| 1508 | 1509 | } | |
| @@ -1628,7 +1629,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1628 | 1629 | return fmt.Errorf("reading terminal geometry for parked route: %w", err) | |
| 1629 | 1630 | } | |
| 1630 | 1631 | geometry = geometry.NormalizePixels() | |
| 1631 | - | payload, err := ports.MarshalResize(ports.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 1632 | + | payload, err := ports.MarshalResize(protocol.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 1632 | 1633 | if err != nil { | |
| 1633 | 1634 | return fmt.Errorf("encoding terminal size for parked route: %w", err) | |
| 1634 | 1635 | } | |
| @@ -1639,12 +1640,12 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1639 | 1640 | return context.Canceled | |
| 1640 | 1641 | } | |
| 1641 | 1642 | } | |
| 1642 | - | sendParkedRouteRequest := func(action ports.ParkedRouteAction, leaseID ports.ParkedRouteLeaseID, target *domain.RemoteSessionTarget) error { | |
| 1643 | + | sendParkedRouteRequest := func(action protocol.ParkedRouteAction, leaseID protocol.ParkedRouteLeaseID, target *domain.RemoteSessionTarget) error { | |
| 1643 | 1644 | if parkedPending != nil { | |
| 1644 | 1645 | return errors.New("vev: parked-route request already pending") | |
| 1645 | 1646 | } | |
| 1646 | 1647 | nextParkedRequestID++ | |
| 1647 | - | request := ports.ParkedRouteRequest{RequestID: nextParkedRequestID, LeaseID: leaseID, Action: action, Target: target} | |
| 1648 | + | request := protocol.ParkedRouteRequest{RequestID: nextParkedRequestID, LeaseID: leaseID, Action: action, Target: target} | |
| 1648 | 1649 | payload := ports.MarshalParkedRouteRequest(request) | |
| 1649 | 1650 | if payload == nil { | |
| 1650 | 1651 | return errors.New("vev: invalid parked-route request") | |
| @@ -1660,7 +1661,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1660 | 1661 | return context.Canceled | |
| 1661 | 1662 | } | |
| 1662 | 1663 | } | |
| 1663 | - | handleParkedPicker := func(leaseID ports.ParkedRouteLeaseID) (attachResult, bool) { | |
| 1664 | + | handleParkedPicker := func(leaseID protocol.ParkedRouteLeaseID) (attachResult, bool) { | |
| 1664 | 1665 | pickerCtx, cancelPicker := context.WithCancel(ctx) | |
| 1665 | 1666 | pickerDone := make(chan struct{}) | |
| 1666 | 1667 | go func() { | |
| @@ -1687,7 +1688,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1687 | 1688 | if err := sendParkedRouteSize(); err != nil { | |
| 1688 | 1689 | return welcomedResult(err), true | |
| 1689 | 1690 | } | |
| 1690 | - | if err := sendParkedRouteRequest(ports.ParkedRouteSwitch, leaseID, &target); err != nil { | |
| 1691 | + | if err := sendParkedRouteRequest(protocol.ParkedRouteSwitch, leaseID, &target); err != nil { | |
| 1691 | 1692 | return welcomedResult(fmt.Errorf("vev: switching parked route: %w", err)), true | |
| 1692 | 1693 | } | |
| 1693 | 1694 | fallback := *selection.target | |
| @@ -1704,7 +1705,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1704 | 1705 | if err := sendParkedRouteSize(); err != nil { | |
| 1705 | 1706 | return welcomedResult(err), true | |
| 1706 | 1707 | } | |
| 1707 | - | if err := sendParkedRouteRequest(ports.ParkedRouteResume, leaseID, nil); err != nil { | |
| 1708 | + | if err := sendParkedRouteRequest(protocol.ParkedRouteResume, leaseID, nil); err != nil { | |
| 1708 | 1709 | return welcomedResult(fmt.Errorf("vev: resuming parked route: %w", err)), true | |
| 1709 | 1710 | } | |
| 1710 | 1711 | return attachResult{}, false | |
| @@ -1725,7 +1726,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1725 | 1726 | return fmt.Errorf("reading terminal geometry for reconnect reconciliation: %w", serr) | |
| 1726 | 1727 | } | |
| 1727 | 1728 | geometry = geometry.NormalizePixels() | |
| 1728 | - | payload, err := ports.MarshalResize(ports.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 1729 | + | payload, err := ports.MarshalResize(protocol.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 1729 | 1730 | if err != nil { | |
| 1730 | 1731 | return fmt.Errorf("encoding terminal size for reconnect reconciliation: %w", err) | |
| 1731 | 1732 | } | |
| @@ -1761,8 +1762,8 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1761 | 1762 | } | |
| 1762 | 1763 | return nil | |
| 1763 | 1764 | } | |
| 1764 | - | sendRouteFailure := func(action ports.RouteNavigationAction, code ports.RouteFailureCode) error { | |
| 1765 | - | payload, err := ports.MarshalRouteNavigationFailure(ports.RouteNavigationFailure{ | |
| 1765 | + | sendRouteFailure := func(action protocol.RouteNavigationAction, code protocol.RouteFailureCode) error { | |
| 1766 | + | payload, err := ports.MarshalRouteNavigationFailure(protocol.RouteNavigationFailure{ | |
| 1766 | 1767 | Key: action.Key, | |
| 1767 | 1768 | Generation: action.Generation, | |
| 1768 | 1769 | Code: code, | |
| @@ -1861,7 +1862,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1861 | 1862 | } | |
| 1862 | 1863 | case event := <-paletteEvents: | |
| 1863 | 1864 | if event.kind == paletteEventScheme { | |
| 1864 | - | retained := themeState.update(func(current *ports.Theme) { | |
| 1865 | + | retained := themeState.update(func(current *protocol.Theme) { | |
| 1865 | 1866 | current.SchemeKnown = true | |
| 1866 | 1867 | current.Light = event.light | |
| 1867 | 1868 | }) | |
| @@ -1965,7 +1966,7 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1965 | 1966 | } | |
| 1966 | 1967 | nextSamePeerRequestID++ | |
| 1967 | 1968 | request := a.runner.ledger.samePeerHandoff(request, target) | |
| 1968 | - | payload, err := ports.MarshalSamePeerSwitchRequest(ports.SamePeerSwitchRequest{ | |
| 1969 | + | payload, err := ports.MarshalSamePeerSwitchRequest(protocol.SamePeerSwitchRequest{ | |
| 1969 | 1970 | RequestID: nextSamePeerRequestID, | |
| 1970 | 1971 | Target: *target.ExactTarget, | |
| 1971 | 1972 | PreferredTabID: request.PreferredTabID, | |
| @@ -1996,26 +1997,26 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 1996 | 1997 | pending := *parkedPending | |
| 1997 | 1998 | clearParkedPending() | |
| 1998 | 1999 | switch pending.action { | |
| 1999 | - | case ports.ParkedRoutePrepare: | |
| 2000 | - | if response.Status != ports.ParkedRouteReady { | |
| 2000 | + | case protocol.ParkedRoutePrepare: | |
| 2001 | + | if response.Status != protocol.ParkedRouteReady { | |
| 2001 | 2002 | fallback := welcomedResult(nil) | |
| 2002 | - | fallback.action = ports.NavigationOpenHomePicker | |
| 2003 | + | fallback.action = protocol.NavigationOpenHomePicker | |
| 2003 | 2004 | return fallback | |
| 2004 | 2005 | } | |
| 2005 | 2006 | if selection, done := handleParkedPicker(pending.leaseID); done { | |
| 2006 | 2007 | return selection | |
| 2007 | 2008 | } | |
| 2008 | - | case ports.ParkedRouteResume: | |
| 2009 | - | if response.Status != ports.ParkedRouteResumed { | |
| 2009 | + | case protocol.ParkedRouteResume: | |
| 2010 | + | if response.Status != protocol.ParkedRouteResumed { | |
| 2010 | 2011 | return welcomedResult(errors.New("vev: parked route could not resume")) | |
| 2011 | 2012 | } | |
| 2012 | 2013 | awaitParkedFull() | |
| 2013 | - | case ports.ParkedRouteSwitch: | |
| 2014 | + | case protocol.ParkedRouteSwitch: | |
| 2014 | 2015 | switch response.Status { | |
| 2015 | - | case ports.ParkedRouteSwitched: | |
| 2016 | + | case protocol.ParkedRouteSwitched: | |
| 2016 | 2017 | awaitParkedFull() | |
| 2017 | 2018 | continue | |
| 2018 | - | case ports.ParkedRouteStaleTarget: | |
| 2019 | + | case protocol.ParkedRouteStaleTarget: | |
| 2019 | 2020 | if transition != nil { | |
| 2020 | 2021 | transition.stop() | |
| 2021 | 2022 | } | |
| @@ -2038,12 +2039,12 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 2038 | 2039 | return welcomedResult(fmt.Errorf("vev: decoding navigation action: %w", derr)) | |
| 2039 | 2040 | } | |
| 2040 | 2041 | _, datagramRoute := transport.(ports.DatagramTransport) | |
| 2041 | - | if directive.Action == ports.NavigationOpenHomePicker && a.openHomePicker != nil && datagramRoute { | |
| 2042 | + | if directive.Action == protocol.NavigationOpenHomePicker && a.openHomePicker != nil && datagramRoute { | |
| 2042 | 2043 | stopForeground() | |
| 2043 | 2044 | if err := flushSender(); err != nil { | |
| 2044 | 2045 | return welcomedResult(fmt.Errorf("vev: parking remote foreground: %w", err)) | |
| 2045 | 2046 | } | |
| 2046 | - | if err := sendParkedRouteRequest(ports.ParkedRoutePrepare, directive.LeaseID, nil); err != nil { | |
| 2047 | + | if err := sendParkedRouteRequest(protocol.ParkedRoutePrepare, directive.LeaseID, nil); err != nil { | |
| 2047 | 2048 | return welcomedResult(fmt.Errorf("vev: preparing parked route: %w", err)) | |
| 2048 | 2049 | } | |
| 2049 | 2050 | continue | |
| @@ -2057,14 +2058,14 @@ func (a *attachAttempt) run(ctx context.Context) attachResult { | |||
| 2057 | 2058 | return welcomedResult(fmt.Errorf("vev: decoding route navigation action: %w", derr)) | |
| 2058 | 2059 | } | |
| 2059 | 2060 | if a.runner.ledger == nil { | |
| 2060 | - | if ferr := sendRouteFailure(action, ports.RouteFailureUnavailable); ferr != nil { | |
| 2061 | + | if ferr := sendRouteFailure(action, protocol.RouteFailureUnavailable); ferr != nil { | |
| 2061 | 2062 | return welcomedResult(ferr) | |
| 2062 | 2063 | } | |
| 2063 | 2064 | continue | |
| 2064 | 2065 | } | |
| 2065 | 2066 | _, valid, noOp := a.runner.ledger.navigationRecord(action) | |
| 2066 | 2067 | if !valid { | |
| 2067 | - | if ferr := sendRouteFailure(action, ports.RouteFailureStaleSelection); ferr != nil { | |
| 2068 | + | if ferr := sendRouteFailure(action, protocol.RouteFailureStaleSelection); ferr != nil { | |
| 2068 | 2069 | return welcomedResult(ferr) | |
| 2069 | 2070 | } | |
| 2070 | 2071 | continue | |
| @@ -2244,7 +2245,7 @@ func runSender(ctx context.Context, cancel context.CancelFunc, transport ports.T | |||
| 2244 | 2245 | if state == 0 { | |
| 2245 | 2246 | return true | |
| 2246 | 2247 | } | |
| 2247 | - | payload, err := ports.MarshalAck(ports.Ack{Epoch: epoch, State: state}) | |
| 2248 | + | payload, err := ports.MarshalAck(protocol.Ack{Epoch: epoch, State: state}) | |
| 2248 | 2249 | if err != nil { | |
| 2249 | 2250 | select { | |
| 2250 | 2251 | case errCh <- fmt.Errorf("encoding output ACK: %w", err): | |
| @@ -2802,7 +2803,7 @@ func (p *stdinPump) run() { | |||
| 2802 | 2803 | }, | |
| 2803 | 2804 | sendImage: func(mime string, data []byte) { | |
| 2804 | 2805 | inputSeq++ | |
| 2805 | - | send(ports.Frame{Type: ports.MsgImagePush, Payload: ports.MarshalImagePush(ports.ImagePush{InputSeq: inputSeq, Mime: mime, Data: data})}) | |
| 2806 | + | send(ports.Frame{Type: ports.MsgImagePush, Payload: ports.MarshalImagePush(protocol.ImagePush{InputSeq: inputSeq, Mime: mime, Data: data})}) | |
| 2806 | 2807 | }, | |
| 2807 | 2808 | next: coalescer.Scan, | |
| 2808 | 2809 | } | |
| @@ -2974,7 +2975,7 @@ func runResize(ctx context.Context, events <-chan domain.Geometry, out chan<- po | |||
| 2974 | 2975 | return | |
| 2975 | 2976 | } | |
| 2976 | 2977 | geometry = geometry.NormalizePixels() | |
| 2977 | - | payload, err := ports.MarshalResize(ports.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 2978 | + | payload, err := ports.MarshalResize(protocol.Resize{Size: geometry.Size, PixelWidth: geometry.PixelWidth, PixelHeight: geometry.PixelHeight}) | |
| 2978 | 2979 | if err != nil { | |
| 2979 | 2980 | log.Error("encoding terminal resize", "error", err) | |
| 2980 | 2981 | continue | |
M internal/usecase/client/client_test.go +100 -99
| @@ -18,6 +18,7 @@ import ( | |||
| 18 | 18 | "github.com/bnema/vev/internal/domain" | |
| 19 | 19 | "github.com/bnema/vev/internal/ports" | |
| 20 | 20 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 21 | + | "github.com/bnema/vev/internal/protocol" | |
| 21 | 22 | "github.com/bnema/vev/internal/usecase/client" | |
| 22 | 23 | ) | |
| 23 | 24 | ||
| @@ -436,8 +437,8 @@ func TestAttachPublishesCommittedRouteSnapshot(t *testing.T) { | |||
| 436 | 437 | {f: frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{ | |
| 437 | 438 | SessionID: "s1", | |
| 438 | 439 | SessionName: "main", | |
| 439 | - | CommittedIdentity: &ports.CommittedRouteIdentity{ | |
| 440 | - | Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "main"}, | |
| 440 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{ | |
| 441 | + | Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "main"}, | |
| 441 | 442 | }, | |
| 442 | 443 | }))}, | |
| 443 | 444 | {f: frameOf(ports.MsgDetached, ports.MarshalDetached(ports.Detached{Reason: ports.ReasonDetach}))}, | |
| @@ -446,13 +447,13 @@ func TestAttachPublishesCommittedRouteSnapshot(t *testing.T) { | |||
| 446 | 447 | err := runTestClient(context.Background(), attachTestDependencies(tr, term, realClock{}), client.AttachRequest{ | |
| 447 | 448 | Intent: ports.IntentAttach, | |
| 448 | 449 | SessionName: "main", | |
| 449 | - | Origin: ports.RouteOriginLocal, | |
| 450 | + | Origin: protocol.RouteOriginLocal, | |
| 450 | 451 | OriginKey: "local", | |
| 451 | 452 | }) | |
| 452 | 453 | require.NoError(t, err) | |
| 453 | 454 | ||
| 454 | - | var snapshot ports.RecentRouteSnapshot | |
| 455 | - | var subscription ports.RouteAttentionSubscription | |
| 455 | + | var snapshot protocol.RecentRouteSnapshot | |
| 456 | + | var subscription protocol.RouteAttentionSubscription | |
| 456 | 457 | foundSnapshot := false | |
| 457 | 458 | foundSubscription := false | |
| 458 | 459 | for _, frame := range tr.Sends() { | |
| @@ -486,26 +487,26 @@ func TestLocalOnlyHandoffBetweenLocalSessionsKeepsClientRunning(t *testing.T) { | |||
| 486 | 487 | welcome := func(name string, lifecycle domain.SessionLifecycleID) ports.Frame { | |
| 487 | 488 | return frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{ | |
| 488 | 489 | SessionID: name, SessionName: name, ResumeToken: 1, Capabilities: ports.CapabilityResume, | |
| 489 | - | CommittedIdentity: &ports.CommittedRouteIdentity{ | |
| 490 | - | Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 490 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{ | |
| 491 | + | Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 491 | 492 | }, | |
| 492 | 493 | })) | |
| 493 | 494 | } | |
| 494 | - | secondTarget := ports.ExactSessionTarget{LifecycleID: secondLifecycle, SessionName: "second"} | |
| 495 | + | secondTarget := protocol.ExactSessionTarget{LifecycleID: secondLifecycle, SessionName: "second"} | |
| 495 | 496 | first := &recordingTransport{recvs: []recvItem{ | |
| 496 | 497 | {f: welcome("first", firstLifecycle)}, | |
| 497 | 498 | {f: frameOf(ports.MsgAttachTarget, ports.MarshalAttachTarget(ports.AttachTarget{ | |
| 498 | 499 | Session: "second", Intent: ports.IntentAttach, ExactTarget: &secondTarget, | |
| 499 | 500 | EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, SamePeer: true, | |
| 500 | 501 | }))}, | |
| 501 | - | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(ports.CommittedRouteIdentity{Target: secondTarget}))}, | |
| 502 | + | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(protocol.CommittedRouteIdentity{Target: secondTarget}))}, | |
| 502 | 503 | {f: frameOf(ports.MsgDetached, ports.MarshalDetached(ports.Detached{Reason: ports.ReasonDetach}))}, | |
| 503 | 504 | }} | |
| 504 | 505 | dialer := &sequenceDialer{trs: []ports.Transport{first}} | |
| 505 | 506 | ||
| 506 | 507 | err := runTestClient(context.Background(), testDependencies(dialer, term, realClock{}, nil, nil), client.AttachRequest{ | |
| 507 | 508 | Intent: ports.IntentAttach, SessionName: "first", | |
| 508 | - | Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 509 | + | Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 509 | 510 | EnvironmentPolicy: ports.EnvironmentPolicyClientOwned, | |
| 510 | 511 | }) | |
| 511 | 512 | ||
| @@ -524,8 +525,8 @@ func TestAttachHelloPreservesCompleteAttachRequest(t *testing.T) { | |||
| 524 | 525 | request := client.AttachRequest{ | |
| 525 | 526 | Intent: ports.IntentAttach, SessionName: "work", Remote: true, | |
| 526 | 527 | RemoteTarget: target, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 527 | - | NavigationCapabilities: ports.NavigationCapabilityHomePicker, | |
| 528 | - | StartupOverlay: ports.StartupOverlayNone, | |
| 528 | + | NavigationCapabilities: protocol.NavigationCapabilityHomePicker, | |
| 529 | + | StartupOverlay: protocol.StartupOverlayNone, | |
| 529 | 530 | } | |
| 530 | 531 | tr := &recordingTransport{recvs: []recvItem{ | |
| 531 | 532 | {f: welcomeFrame(0)}, | |
| @@ -548,12 +549,12 @@ func TestStoppedLocalHandoffDialsReplacementTransport(t *testing.T) { | |||
| 548 | 549 | ||
| 549 | 550 | sourceLifecycle := domain.SessionLifecycleID{1} | |
| 550 | 551 | targetLifecycle := domain.SessionLifecycleID{2} | |
| 551 | - | target := ports.ExactSessionTarget{LifecycleID: targetLifecycle, SessionName: "stopped"} | |
| 552 | + | target := protocol.ExactSessionTarget{LifecycleID: targetLifecycle, SessionName: "stopped"} | |
| 552 | 553 | welcome := func(name string, lifecycle domain.SessionLifecycleID) ports.Frame { | |
| 553 | 554 | return frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{ | |
| 554 | 555 | SessionID: name, SessionName: name, ResumeToken: 1, Capabilities: ports.CapabilityResume, | |
| 555 | - | CommittedIdentity: &ports.CommittedRouteIdentity{ | |
| 556 | - | Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 556 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{ | |
| 557 | + | Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 557 | 558 | }, | |
| 558 | 559 | })) | |
| 559 | 560 | } | |
| @@ -572,7 +573,7 @@ func TestStoppedLocalHandoffDialsReplacementTransport(t *testing.T) { | |||
| 572 | 573 | ||
| 573 | 574 | err := runTestClient(context.Background(), testDependencies(dialer, term, realClock{}, nil, nil), client.AttachRequest{ | |
| 574 | 575 | Intent: ports.IntentAttach, SessionName: "source", | |
| 575 | - | Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 576 | + | Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 576 | 577 | EnvironmentPolicy: ports.EnvironmentPolicyClientOwned, | |
| 577 | 578 | }) | |
| 578 | 579 | ||
| @@ -589,7 +590,7 @@ func TestAcceptedHomeActionUsesCapturedRouteAfterRequestMetadataRebase(t *testin | |||
| 589 | 590 | welcome := func(name string, lifecycle domain.SessionLifecycleID) ports.Frame { | |
| 590 | 591 | return frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{ | |
| 591 | 592 | SessionID: name, SessionName: name, ResumeToken: 1, Capabilities: ports.CapabilityResume, | |
| 592 | - | CommittedIdentity: &ports.CommittedRouteIdentity{Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}}, | |
| 593 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}}, | |
| 593 | 594 | })) | |
| 594 | 595 | } | |
| 595 | 596 | remoteTarget := domain.RemoteSessionTarget{ | |
| @@ -605,7 +606,7 @@ func TestAcceptedHomeActionUsesCapturedRouteAfterRequestMetadataRebase(t *testin | |||
| 605 | 606 | }} | |
| 606 | 607 | remote := &recordingTransport{recvs: []recvItem{ | |
| 607 | 608 | {f: welcome("work", remoteLifecycle)}, | |
| 608 | - | {f: navigationDirectiveFrame(ports.NavigationOpenHomePicker)}, | |
| 609 | + | {f: navigationDirectiveFrame(protocol.NavigationOpenHomePicker)}, | |
| 609 | 610 | }} | |
| 610 | 611 | local2 := &recordingTransport{recvs: []recvItem{ | |
| 611 | 612 | {f: welcome("local", localLifecycle)}, | |
| @@ -615,10 +616,10 @@ func TestAcceptedHomeActionUsesCapturedRouteAfterRequestMetadataRebase(t *testin | |||
| 615 | 616 | remoteDialer := &sequenceDialer{trs: []ports.Transport{remote}} | |
| 616 | 617 | deps := testDependencies(localDialer, term, realClock{}, nil, nil) | |
| 617 | 618 | deps.AttachHandoff = func(ports.AttachTarget) (ports.Dialer, client.AttachRequest, error) { | |
| 618 | - | target := ports.ExactSessionTarget{LifecycleID: remoteLifecycle, SessionName: "work"} | |
| 619 | + | target := protocol.ExactSessionTarget{LifecycleID: remoteLifecycle, SessionName: "work"} | |
| 619 | 620 | return remoteDialer, client.AttachRequest{ | |
| 620 | 621 | Intent: ports.IntentAttach, SessionName: "work", Remote: true, | |
| 621 | - | Origin: ports.RouteOriginRemote, OriginKey: "remote", ExactTarget: &target, | |
| 622 | + | Origin: protocol.RouteOriginRemote, OriginKey: "remote", ExactTarget: &target, | |
| 622 | 623 | EnvironmentPolicy: ports.EnvironmentPolicyClientOwned, | |
| 623 | 624 | // Deliberately omit the copied Home capability. The accepted server | |
| 624 | 625 | // action remains valid because Runner retained the concrete home route. | |
| @@ -626,15 +627,15 @@ func TestAcceptedHomeActionUsesCapturedRouteAfterRequestMetadataRebase(t *testin | |||
| 626 | 627 | } | |
| 627 | 628 | ||
| 628 | 629 | require.NoError(t, runTestClient(context.Background(), deps, client.AttachRequest{ | |
| 629 | - | Intent: ports.IntentAttach, SessionName: "local", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 630 | + | Intent: ports.IntentAttach, SessionName: "local", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 630 | 631 | })) | |
| 631 | - | require.Equal(t, ports.StartupOverlaySessionPicker, helloFromSend(t, local2).StartupOverlay) | |
| 632 | + | require.Equal(t, protocol.StartupOverlaySessionPicker, helloFromSend(t, local2).StartupOverlay) | |
| 632 | 633 | } | |
| 633 | 634 | ||
| 634 | 635 | func hybridWelcomeFrame(name string, lifecycle domain.SessionLifecycleID) ports.Frame { | |
| 635 | 636 | return frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{ | |
| 636 | 637 | SessionID: name, SessionName: name, ResumeToken: 1, Capabilities: ports.CapabilityResume, | |
| 637 | - | CommittedIdentity: &ports.CommittedRouteIdentity{Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}}, | |
| 638 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}}, | |
| 638 | 639 | })) | |
| 639 | 640 | } | |
| 640 | 641 | ||
| @@ -661,15 +662,15 @@ func hybridPickerDependencies(localDialer ports.Dialer, term ports.Terminal, clo | |||
| 661 | 662 | selection := *target.RemoteTarget | |
| 662 | 663 | return dialer, client.AttachRequest{ | |
| 663 | 664 | Intent: ports.IntentAttach, SessionName: target.Session, Remote: true, | |
| 664 | - | Origin: ports.RouteOriginDiscovery, OriginKey: target.Endpoint, | |
| 665 | + | Origin: protocol.RouteOriginDiscovery, OriginKey: target.Endpoint, | |
| 665 | 666 | RemoteTarget: &selection, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 666 | 667 | }, nil | |
| 667 | 668 | } | |
| 668 | 669 | return deps | |
| 669 | 670 | } | |
| 670 | 671 | ||
| 671 | - | func hybridParkedRequestHandler(requests chan<- ports.ParkedRouteRequest, requestErrors chan<- error, signals map[ports.ParkedRouteAction]chan struct{}) func(ports.Frame) { | |
| 672 | - | once := make(map[ports.ParkedRouteAction]*sync.Once, len(signals)) | |
| 672 | + | func hybridParkedRequestHandler(requests chan<- protocol.ParkedRouteRequest, requestErrors chan<- error, signals map[protocol.ParkedRouteAction]chan struct{}) func(ports.Frame) { | |
| 673 | + | once := make(map[protocol.ParkedRouteAction]*sync.Once, len(signals)) | |
| 673 | 674 | for action := range signals { | |
| 674 | 675 | once[action] = &sync.Once{} | |
| 675 | 676 | } | |
| @@ -711,20 +712,20 @@ func TestHybridPickerSameHostSwitchReusesRemoteTransport(t *testing.T) { | |||
| 711 | 712 | localInitial := hybridLocalBootstrap(localLifecycle, sourceTarget) | |
| 712 | 713 | parkSent := make(chan struct{}) | |
| 713 | 714 | switchSent := make(chan struct{}) | |
| 714 | - | parkedRequests := make(chan ports.ParkedRouteRequest, 2) | |
| 715 | + | parkedRequests := make(chan protocol.ParkedRouteRequest, 2) | |
| 715 | 716 | parkedRequestErrors := make(chan error, 2) | |
| 716 | 717 | remote := &recordingTransport{recvs: []recvItem{ | |
| 717 | 718 | {f: hybridWelcomeFrame("source", remoteSourceLifecycle)}, | |
| 718 | - | {f: navigationDirectiveFrame(ports.NavigationOpenHomePicker)}, | |
| 719 | - | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(ports.ParkedRouteResponse{RequestID: 1, Status: ports.ParkedRouteReady})), wait: parkSent}, | |
| 720 | - | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(ports.CommittedRouteIdentity{Target: ports.ExactSessionTarget{LifecycleID: remoteTargetLifecycle, SessionName: "target"}})), wait: switchSent}, | |
| 721 | - | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(ports.ParkedRouteResponse{RequestID: 2, Status: ports.ParkedRouteSwitched}))}, | |
| 722 | - | {f: frameOf(ports.MsgOutput, mustMarshalOutput(ports.Output{Epoch: 2, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("target frame")}))}, | |
| 719 | + | {f: navigationDirectiveFrame(protocol.NavigationOpenHomePicker)}, | |
| 720 | + | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(protocol.ParkedRouteResponse{RequestID: 1, Status: protocol.ParkedRouteReady})), wait: parkSent}, | |
| 721 | + | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(protocol.CommittedRouteIdentity{Target: protocol.ExactSessionTarget{LifecycleID: remoteTargetLifecycle, SessionName: "target"}})), wait: switchSent}, | |
| 722 | + | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(protocol.ParkedRouteResponse{RequestID: 2, Status: protocol.ParkedRouteSwitched}))}, | |
| 723 | + | {f: frameOf(ports.MsgOutput, mustMarshalOutput(protocol.Output{Epoch: 2, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("target frame")}))}, | |
| 723 | 724 | {f: frameOf(ports.MsgDetached, ports.MarshalDetached(ports.Detached{Reason: ports.ReasonDetach}))}, | |
| 724 | 725 | }} | |
| 725 | - | remote.onSend = hybridParkedRequestHandler(parkedRequests, parkedRequestErrors, map[ports.ParkedRouteAction]chan struct{}{ | |
| 726 | - | ports.ParkedRoutePrepare: parkSent, | |
| 727 | - | ports.ParkedRouteSwitch: switchSent, | |
| 726 | + | remote.onSend = hybridParkedRequestHandler(parkedRequests, parkedRequestErrors, map[protocol.ParkedRouteAction]chan struct{}{ | |
| 727 | + | protocol.ParkedRoutePrepare: parkSent, | |
| 728 | + | protocol.ParkedRouteSwitch: switchSent, | |
| 728 | 729 | }) | |
| 729 | 730 | localPicker := &recordingTransport{recvs: []recvItem{ | |
| 730 | 731 | {f: hybridWelcomeFrame("local", localLifecycle)}, | |
| @@ -744,7 +745,7 @@ func TestHybridPickerSameHostSwitchReusesRemoteTransport(t *testing.T) { | |||
| 744 | 745 | deps := hybridPickerDependencies(localDialer, term, realClock{}, map[string]ports.Dialer{"remote": remoteDialer}) | |
| 745 | 746 | ||
| 746 | 747 | err := runTestClient(context.Background(), deps, client.AttachRequest{ | |
| 747 | - | Intent: ports.IntentAttach, SessionName: "local", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 748 | + | Intent: ports.IntentAttach, SessionName: "local", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 748 | 749 | }) | |
| 749 | 750 | ||
| 750 | 751 | require.NoError(t, err) | |
| @@ -755,8 +756,8 @@ func TestHybridPickerSameHostSwitchReusesRemoteTransport(t *testing.T) { | |||
| 755 | 756 | } | |
| 756 | 757 | prepareRequest := <-parkedRequests | |
| 757 | 758 | switchRequest := <-parkedRequests | |
| 758 | - | require.Equal(t, ports.ParkedRoutePrepare, prepareRequest.Action) | |
| 759 | - | require.Equal(t, ports.ParkedRouteSwitch, switchRequest.Action) | |
| 759 | + | require.Equal(t, protocol.ParkedRoutePrepare, prepareRequest.Action) | |
| 760 | + | require.Equal(t, protocol.ParkedRouteSwitch, switchRequest.Action) | |
| 760 | 761 | require.NotNil(t, switchRequest.Target) | |
| 761 | 762 | require.Equal(t, targetTarget, *switchRequest.Target) | |
| 762 | 763 | frames := remote.Sends() | |
| @@ -767,7 +768,7 @@ func TestHybridPickerSameHostSwitchReusesRemoteTransport(t *testing.T) { | |||
| 767 | 768 | } | |
| 768 | 769 | request, requestErr := ports.UnmarshalParkedRouteRequest(frame.Payload) | |
| 769 | 770 | require.NoError(t, requestErr) | |
| 770 | - | if request.Action == ports.ParkedRouteSwitch { | |
| 771 | + | if request.Action == protocol.ParkedRouteSwitch { | |
| 771 | 772 | switchIndex = i | |
| 772 | 773 | break | |
| 773 | 774 | } | |
| @@ -801,13 +802,13 @@ func TestHybridPickerExpiredSwitchFallsBackToNewDial(t *testing.T) { | |||
| 801 | 802 | parkedRequestErrors := make(chan error, 1) | |
| 802 | 803 | sourceRemote := &recordingTransport{recvs: []recvItem{ | |
| 803 | 804 | {f: hybridWelcomeFrame("source", sourceLifecycle)}, | |
| 804 | - | {f: navigationDirectiveFrame(ports.NavigationOpenHomePicker)}, | |
| 805 | - | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(ports.ParkedRouteResponse{RequestID: 1, Status: ports.ParkedRouteReady})), wait: prepareSent}, | |
| 806 | - | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(ports.ParkedRouteResponse{RequestID: 2, Status: ports.ParkedRouteExpired})), wait: switchSent}, | |
| 805 | + | {f: navigationDirectiveFrame(protocol.NavigationOpenHomePicker)}, | |
| 806 | + | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(protocol.ParkedRouteResponse{RequestID: 1, Status: protocol.ParkedRouteReady})), wait: prepareSent}, | |
| 807 | + | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(protocol.ParkedRouteResponse{RequestID: 2, Status: protocol.ParkedRouteExpired})), wait: switchSent}, | |
| 807 | 808 | }} | |
| 808 | - | sourceRemote.onSend = hybridParkedRequestHandler(nil, parkedRequestErrors, map[ports.ParkedRouteAction]chan struct{}{ | |
| 809 | - | ports.ParkedRoutePrepare: prepareSent, | |
| 810 | - | ports.ParkedRouteSwitch: switchSent, | |
| 809 | + | sourceRemote.onSend = hybridParkedRequestHandler(nil, parkedRequestErrors, map[protocol.ParkedRouteAction]chan struct{}{ | |
| 810 | + | protocol.ParkedRoutePrepare: prepareSent, | |
| 811 | + | protocol.ParkedRouteSwitch: switchSent, | |
| 811 | 812 | }) | |
| 812 | 813 | localPicker := &recordingTransport{recvs: []recvItem{ | |
| 813 | 814 | {f: hybridWelcomeFrame("local", localLifecycle)}, | |
| @@ -827,7 +828,7 @@ func TestHybridPickerExpiredSwitchFallsBackToNewDial(t *testing.T) { | |||
| 827 | 828 | deps := hybridPickerDependencies(localDialer, term, realClock{}, map[string]ports.Dialer{"remote": remoteDialer}) | |
| 828 | 829 | ||
| 829 | 830 | require.NoError(t, runTestClient(context.Background(), deps, client.AttachRequest{ | |
| 830 | - | Intent: ports.IntentAttach, SessionName: "local", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 831 | + | Intent: ports.IntentAttach, SessionName: "local", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 831 | 832 | })) | |
| 832 | 833 | select { | |
| 833 | 834 | case requestErr := <-parkedRequestErrors: | |
| @@ -878,12 +879,12 @@ func TestHybridPickerPrepareResponseTimeoutClosesRetainedTransport(t *testing.T) | |||
| 878 | 879 | remote := &recordingTransport{ | |
| 879 | 880 | recvs: []recvItem{ | |
| 880 | 881 | {f: hybridWelcomeFrame("work", remoteLifecycle)}, | |
| 881 | - | {f: navigationDirectiveFrame(ports.NavigationOpenHomePicker)}, | |
| 882 | + | {f: navigationDirectiveFrame(protocol.NavigationOpenHomePicker)}, | |
| 882 | 883 | }, | |
| 883 | 884 | stall: remoteClosed, | |
| 884 | 885 | } | |
| 885 | - | remote.onSend = hybridParkedRequestHandler(nil, nil, map[ports.ParkedRouteAction]chan struct{}{ | |
| 886 | - | ports.ParkedRoutePrepare: prepareSent, | |
| 886 | + | remote.onSend = hybridParkedRequestHandler(nil, nil, map[protocol.ParkedRouteAction]chan struct{}{ | |
| 887 | + | protocol.ParkedRoutePrepare: prepareSent, | |
| 887 | 888 | }) | |
| 888 | 889 | ||
| 889 | 890 | localDialer := &sequenceDialer{trs: []ports.Transport{localInitial}} | |
| @@ -899,7 +900,7 @@ func TestHybridPickerPrepareResponseTimeoutClosesRetainedTransport(t *testing.T) | |||
| 899 | 900 | result := make(chan error, 1) | |
| 900 | 901 | go func() { | |
| 901 | 902 | result <- runTestClient(ctx, deps, client.AttachRequest{ | |
| 902 | - | Intent: ports.IntentAttach, SessionName: "local", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 903 | + | Intent: ports.IntentAttach, SessionName: "local", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 903 | 904 | }) | |
| 904 | 905 | }() | |
| 905 | 906 | select { | |
| @@ -949,26 +950,26 @@ func TestHybridPickerBackResumesRetainedRemoteTransport(t *testing.T) { | |||
| 949 | 950 | parkedRequestErrors := make(chan error, 2) | |
| 950 | 951 | remote := &recordingTransport{recvs: []recvItem{ | |
| 951 | 952 | {f: hybridWelcomeFrame("work", remoteLifecycle)}, | |
| 952 | - | {f: navigationDirectiveFrame(ports.NavigationOpenHomePicker)}, | |
| 953 | - | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(ports.ParkedRouteResponse{RequestID: 1, Status: ports.ParkedRouteReady})), wait: parkSent}, | |
| 954 | - | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(ports.ParkedRouteResponse{RequestID: 2, Status: ports.ParkedRouteResumed})), wait: resumeSent}, | |
| 955 | - | {f: frameOf(ports.MsgOutput, mustMarshalOutput(ports.Output{Epoch: 1, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("source frame")}))}, | |
| 953 | + | {f: navigationDirectiveFrame(protocol.NavigationOpenHomePicker)}, | |
| 954 | + | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(protocol.ParkedRouteResponse{RequestID: 1, Status: protocol.ParkedRouteReady})), wait: parkSent}, | |
| 955 | + | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(protocol.ParkedRouteResponse{RequestID: 2, Status: protocol.ParkedRouteResumed})), wait: resumeSent}, | |
| 956 | + | {f: frameOf(ports.MsgOutput, mustMarshalOutput(protocol.Output{Epoch: 1, New: 1, Size: domain.Size{Cols: 80, Rows: 24}, Full: true, Data: []byte("source frame")}))}, | |
| 956 | 957 | {f: frameOf(ports.MsgDetached, ports.MarshalDetached(ports.Detached{Reason: ports.ReasonDetach}))}, | |
| 957 | 958 | }} | |
| 958 | - | remote.onSend = hybridParkedRequestHandler(nil, parkedRequestErrors, map[ports.ParkedRouteAction]chan struct{}{ | |
| 959 | - | ports.ParkedRoutePrepare: parkSent, | |
| 960 | - | ports.ParkedRouteResume: resumeSent, | |
| 959 | + | remote.onSend = hybridParkedRequestHandler(nil, parkedRequestErrors, map[protocol.ParkedRouteAction]chan struct{}{ | |
| 960 | + | protocol.ParkedRoutePrepare: parkSent, | |
| 961 | + | protocol.ParkedRouteResume: resumeSent, | |
| 961 | 962 | }) | |
| 962 | 963 | localPicker := &recordingTransport{recvs: []recvItem{ | |
| 963 | 964 | {f: hybridWelcomeFrame("local", localLifecycle)}, | |
| 964 | - | {f: navigationDirectiveFrame(ports.NavigationBack)}, | |
| 965 | + | {f: navigationDirectiveFrame(protocol.NavigationBack)}, | |
| 965 | 966 | }} | |
| 966 | 967 | localDialer := &sequenceDialer{trs: []ports.Transport{localInitial, localPicker}} | |
| 967 | 968 | remoteDialer := &sequenceDialer{trs: []ports.Transport{markedDatagramTransport{Transport: remote}}} | |
| 968 | 969 | deps := hybridPickerDependencies(localDialer, term, realClock{}, map[string]ports.Dialer{"remote": remoteDialer}) | |
| 969 | 970 | ||
| 970 | 971 | require.NoError(t, runTestClient(context.Background(), deps, client.AttachRequest{ | |
| 971 | - | Intent: ports.IntentAttach, SessionName: "local", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 972 | + | Intent: ports.IntentAttach, SessionName: "local", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 972 | 973 | })) | |
| 973 | 974 | select { | |
| 974 | 975 | case requestErr := <-parkedRequestErrors: | |
| @@ -1000,12 +1001,12 @@ func TestHybridPickerDifferentHostFallsBackToNewRemoteDial(t *testing.T) { | |||
| 1000 | 1001 | defer close(keepSourceOpen) | |
| 1001 | 1002 | sourceRemote := &recordingTransport{recvs: []recvItem{ | |
| 1002 | 1003 | {f: hybridWelcomeFrame("source", sourceLifecycle)}, | |
| 1003 | - | {f: navigationDirectiveFrame(ports.NavigationOpenHomePicker)}, | |
| 1004 | - | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(ports.ParkedRouteResponse{RequestID: 1, Status: ports.ParkedRouteReady})), wait: parkSent}, | |
| 1004 | + | {f: navigationDirectiveFrame(protocol.NavigationOpenHomePicker)}, | |
| 1005 | + | {f: frameOf(ports.MsgParkedRouteResponse, ports.MarshalParkedRouteResponse(protocol.ParkedRouteResponse{RequestID: 1, Status: protocol.ParkedRouteReady})), wait: parkSent}, | |
| 1005 | 1006 | {err: io.EOF, wait: keepSourceOpen}, | |
| 1006 | 1007 | }} | |
| 1007 | - | sourceRemote.onSend = hybridParkedRequestHandler(nil, parkedRequestErrors, map[ports.ParkedRouteAction]chan struct{}{ | |
| 1008 | - | ports.ParkedRoutePrepare: parkSent, | |
| 1008 | + | sourceRemote.onSend = hybridParkedRequestHandler(nil, parkedRequestErrors, map[protocol.ParkedRouteAction]chan struct{}{ | |
| 1009 | + | protocol.ParkedRoutePrepare: parkSent, | |
| 1009 | 1010 | }) | |
| 1010 | 1011 | localPicker := &recordingTransport{recvs: []recvItem{ | |
| 1011 | 1012 | {f: hybridWelcomeFrame("local", localLifecycle)}, | |
| @@ -1027,7 +1028,7 @@ func TestHybridPickerDifferentHostFallsBackToNewRemoteDial(t *testing.T) { | |||
| 1027 | 1028 | }) | |
| 1028 | 1029 | ||
| 1029 | 1030 | require.NoError(t, runTestClient(context.Background(), deps, client.AttachRequest{ | |
| 1030 | - | Intent: ports.IntentAttach, SessionName: "local", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 1031 | + | Intent: ports.IntentAttach, SessionName: "local", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 1031 | 1032 | })) | |
| 1032 | 1033 | select { | |
| 1033 | 1034 | case requestErr := <-parkedRequestErrors: | |
| @@ -1053,8 +1054,8 @@ func TestRouteNavigationPreservesRemoteHomePickerAcrossLocalReturn(t *testing.T) | |||
| 1053 | 1054 | SessionName: name, | |
| 1054 | 1055 | ResumeToken: token, | |
| 1055 | 1056 | Capabilities: ports.CapabilityResume, | |
| 1056 | - | CommittedIdentity: &ports.CommittedRouteIdentity{ | |
| 1057 | - | Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 1057 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{ | |
| 1058 | + | Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 1058 | 1059 | }, | |
| 1059 | 1060 | })) | |
| 1060 | 1061 | } | |
| @@ -1076,28 +1077,28 @@ func TestRouteNavigationPreservesRemoteHomePickerAcrossLocalReturn(t *testing.T) | |||
| 1076 | 1077 | }} | |
| 1077 | 1078 | local2 := &recordingTransport{recvs: []recvItem{ | |
| 1078 | 1079 | {f: welcome("test", localLifecycle, 11)}, | |
| 1079 | - | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(ports.CommittedRouteIdentity{ | |
| 1080 | - | Target: ports.ExactSessionTarget{LifecycleID: newLifecycle, SessionName: "new"}, | |
| 1080 | + | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(protocol.CommittedRouteIdentity{ | |
| 1081 | + | Target: protocol.ExactSessionTarget{LifecycleID: newLifecycle, SessionName: "new"}, | |
| 1081 | 1082 | }))}, | |
| 1082 | - | {f: frameOf(ports.MsgNavigateRecentRoute, mustMarshalRouteAction(ports.RouteNavigationAction{SnapshotGeneration: 4, Key: 2, Generation: 2}))}, | |
| 1083 | + | {f: frameOf(ports.MsgNavigateRecentRoute, mustMarshalRouteAction(protocol.RouteNavigationAction{SnapshotGeneration: 4, Key: 2, Generation: 2}))}, | |
| 1083 | 1084 | }} | |
| 1084 | 1085 | local3 := &recordingTransport{recvs: []recvItem{ | |
| 1085 | 1086 | {f: welcome("test", localLifecycle, 11)}, | |
| 1086 | - | {f: navigationDirectiveFrame(ports.NavigationBack)}, | |
| 1087 | + | {f: navigationDirectiveFrame(protocol.NavigationBack)}, | |
| 1087 | 1088 | }} | |
| 1088 | 1089 | remote1 := &recordingTransport{recvs: []recvItem{ | |
| 1089 | 1090 | {f: welcome("remote-manual", remoteLifecycle, 22)}, | |
| 1090 | - | {f: frameOf(ports.MsgNavigateRecentRoute, mustMarshalRouteAction(ports.RouteNavigationAction{SnapshotGeneration: 2, Key: 1, Generation: 1}))}, | |
| 1091 | + | {f: frameOf(ports.MsgNavigateRecentRoute, mustMarshalRouteAction(protocol.RouteNavigationAction{SnapshotGeneration: 2, Key: 1, Generation: 1}))}, | |
| 1091 | 1092 | }} | |
| 1092 | 1093 | remote2 := &recordingTransport{recvs: []recvItem{ | |
| 1093 | 1094 | {f: welcome("remote-manual", remoteLifecycle, 22)}, | |
| 1094 | - | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(ports.CommittedRouteIdentity{ | |
| 1095 | - | Target: ports.ExactSessionTarget{LifecycleID: remoteNewLifecycle, SessionName: "remote-new"}, | |
| 1095 | + | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(protocol.CommittedRouteIdentity{ | |
| 1096 | + | Target: protocol.ExactSessionTarget{LifecycleID: remoteNewLifecycle, SessionName: "remote-new"}, | |
| 1096 | 1097 | }))}, | |
| 1097 | - | {f: frameOf(ports.MsgRoutePosition, mustMarshalRoutePosition(ports.RoutePosition{ | |
| 1098 | - | Target: ports.ExactSessionTarget{LifecycleID: remoteNewLifecycle, SessionName: "remote-new"}, ActiveTabID: "tab-2", | |
| 1098 | + | {f: frameOf(ports.MsgRoutePosition, mustMarshalRoutePosition(protocol.RoutePosition{ | |
| 1099 | + | Target: protocol.ExactSessionTarget{LifecycleID: remoteNewLifecycle, SessionName: "remote-new"}, ActiveTabID: "tab-2", | |
| 1099 | 1100 | }))}, | |
| 1100 | - | {f: navigationDirectiveFrame(ports.NavigationOpenHomePicker)}, | |
| 1101 | + | {f: navigationDirectiveFrame(protocol.NavigationOpenHomePicker)}, | |
| 1101 | 1102 | }} | |
| 1102 | 1103 | remote3 := &recordingTransport{recvs: []recvItem{ | |
| 1103 | 1104 | {f: welcome("remote-new", remoteNewLifecycle, 22)}, | |
| @@ -1111,32 +1112,32 @@ func TestRouteNavigationPreservesRemoteHomePickerAcrossLocalReturn(t *testing.T) | |||
| 1111 | 1112 | require.Equal(t, remoteHandoff, target) | |
| 1112 | 1113 | return remoteDialer, client.AttachRequest{ | |
| 1113 | 1114 | Intent: ports.IntentAttach, SessionName: target.Session, Remote: true, | |
| 1114 | - | Origin: ports.RouteOriginDiscovery, OriginKey: target.Endpoint, | |
| 1115 | + | Origin: protocol.RouteOriginDiscovery, OriginKey: target.Endpoint, | |
| 1115 | 1116 | RemoteTarget: &remoteTarget, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 1116 | 1117 | }, nil | |
| 1117 | 1118 | } | |
| 1118 | 1119 | ||
| 1119 | 1120 | err := runTestClient(context.Background(), deps, client.AttachRequest{ | |
| 1120 | - | Intent: ports.IntentAttach, SessionName: "test", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 1121 | + | Intent: ports.IntentAttach, SessionName: "test", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 1121 | 1122 | }) | |
| 1122 | 1123 | remoteHello := helloFromSend(t, remote2) | |
| 1123 | 1124 | require.NoError(t, err) | |
| 1124 | 1125 | ||
| 1125 | - | require.Equal(t, ports.NavigationCapabilityHomePicker, remoteHello.NavigationCapabilities) | |
| 1126 | + | require.Equal(t, protocol.NavigationCapabilityHomePicker, remoteHello.NavigationCapabilities) | |
| 1126 | 1127 | remoteNewHello := helloFromSend(t, remote3) | |
| 1127 | 1128 | require.Equal(t, "remote-new", remoteNewHello.Name) | |
| 1128 | - | require.Equal(t, &ports.ExactSessionTarget{LifecycleID: remoteNewLifecycle, SessionName: "remote-new"}, remoteNewHello.ExactTarget) | |
| 1129 | + | require.Equal(t, &protocol.ExactSessionTarget{LifecycleID: remoteNewLifecycle, SessionName: "remote-new"}, remoteNewHello.ExactTarget) | |
| 1129 | 1130 | } | |
| 1130 | 1131 | ||
| 1131 | - | func navigationDirectiveFrame(action ports.NavigationAction) ports.Frame { | |
| 1132 | - | directive := ports.NavigationDirective{Action: action} | |
| 1133 | - | if action == ports.NavigationOpenHomePicker { | |
| 1134 | - | directive.LeaseID = ports.ParkedRouteLeaseID{1} | |
| 1132 | + | func navigationDirectiveFrame(action protocol.NavigationAction) ports.Frame { | |
| 1133 | + | directive := protocol.NavigationDirective{Action: action} | |
| 1134 | + | if action == protocol.NavigationOpenHomePicker { | |
| 1135 | + | directive.LeaseID = protocol.ParkedRouteLeaseID{1} | |
| 1135 | 1136 | } | |
| 1136 | 1137 | return frameOf(ports.MsgNavigationAction, ports.MarshalNavigationDirective(directive)) | |
| 1137 | 1138 | } | |
| 1138 | 1139 | ||
| 1139 | - | func mustMarshalCommittedIdentity(identity ports.CommittedRouteIdentity) []byte { | |
| 1140 | + | func mustMarshalCommittedIdentity(identity protocol.CommittedRouteIdentity) []byte { | |
| 1140 | 1141 | payload, err := ports.MarshalCommittedRouteIdentity(identity) | |
| 1141 | 1142 | if err != nil { | |
| 1142 | 1143 | panic(err) | |
| @@ -1144,7 +1145,7 @@ func mustMarshalCommittedIdentity(identity ports.CommittedRouteIdentity) []byte | |||
| 1144 | 1145 | return payload | |
| 1145 | 1146 | } | |
| 1146 | 1147 | ||
| 1147 | - | func mustMarshalRouteAction(action ports.RouteNavigationAction) []byte { | |
| 1148 | + | func mustMarshalRouteAction(action protocol.RouteNavigationAction) []byte { | |
| 1148 | 1149 | payload, err := ports.MarshalRouteNavigationAction(action) | |
| 1149 | 1150 | if err != nil { | |
| 1150 | 1151 | panic(err) | |
| @@ -1152,7 +1153,7 @@ func mustMarshalRouteAction(action ports.RouteNavigationAction) []byte { | |||
| 1152 | 1153 | return payload | |
| 1153 | 1154 | } | |
| 1154 | 1155 | ||
| 1155 | - | func mustMarshalRoutePosition(position ports.RoutePosition) []byte { | |
| 1156 | + | func mustMarshalRoutePosition(position protocol.RoutePosition) []byte { | |
| 1156 | 1157 | payload, err := ports.MarshalRoutePosition(position) | |
| 1157 | 1158 | if err != nil { | |
| 1158 | 1159 | panic(err) | |
| @@ -1256,7 +1257,7 @@ func TestAttachHappyPath(t *testing.T) { | |||
| 1256 | 1257 | tr.EXPECT().Send(isType(ports.MsgHello)).Return(nil).Once() | |
| 1257 | 1258 | unblock := scriptRecv(tr, | |
| 1258 | 1259 | recvItem{f: frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{SessionID: "s1", SessionName: "main"}))}, | |
| 1259 | - | recvItem{f: frameOf(ports.MsgOutput, mustMarshalOutput(ports.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Data: []byte("hello world")}))}, | |
| 1260 | + | recvItem{f: frameOf(ports.MsgOutput, mustMarshalOutput(protocol.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Data: []byte("hello world")}))}, | |
| 1260 | 1261 | recvItem{f: frameOf(ports.MsgDetached, ports.MarshalDetached(ports.Detached{Reason: ports.ReasonDetach}))}, | |
| 1261 | 1262 | ) | |
| 1262 | 1263 | defer unblock() | |
| @@ -1476,7 +1477,7 @@ func TestAttachForwardsResize(t *testing.T) { | |||
| 1476 | 1477 | tr.EXPECT().Send(isType(ports.MsgTheme)).Return(nil).Maybe() | |
| 1477 | 1478 | tr.EXPECT().Send(isType(ports.MsgHello)).Return(nil).Once() | |
| 1478 | 1479 | // The resize frame is forwarded via the sender goroutine. | |
| 1479 | - | gotResize := make(chan ports.Resize, 1) | |
| 1480 | + | gotResize := make(chan protocol.Resize, 1) | |
| 1480 | 1481 | tr.EXPECT().Send(isType(ports.MsgResize)).RunAndReturn(func(f ports.Frame) error { | |
| 1481 | 1482 | r, _ := ports.UnmarshalResize(f.Payload) | |
| 1482 | 1483 | gotResize <- r | |
| @@ -1739,16 +1740,16 @@ func TestReconnectRestoresLastPublishedRouteTab(t *testing.T) { | |||
| 1739 | 1740 | term := newRunTerminal() | |
| 1740 | 1741 | defer term.in.unblock() | |
| 1741 | 1742 | lifecycle := domain.SessionLifecycleID{7, 8, 9} | |
| 1742 | - | target := ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "work"} | |
| 1743 | + | target := protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "work"} | |
| 1743 | 1744 | welcome := func(token uint64) ports.Frame { | |
| 1744 | 1745 | return frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{ | |
| 1745 | 1746 | SessionID: "work", SessionName: "work", ResumeToken: token, Capabilities: ports.CapabilityResume, | |
| 1746 | - | CommittedIdentity: &ports.CommittedRouteIdentity{Target: target}, | |
| 1747 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{Target: target}, | |
| 1747 | 1748 | })) | |
| 1748 | 1749 | } | |
| 1749 | 1750 | tr1 := &recordingTransport{recvs: []recvItem{ | |
| 1750 | 1751 | {f: welcome(11)}, | |
| 1751 | - | {f: frameOf(ports.MsgRoutePosition, mustMarshalRoutePosition(ports.RoutePosition{Target: target, ActiveTabID: "tab-2"}))}, | |
| 1752 | + | {f: frameOf(ports.MsgRoutePosition, mustMarshalRoutePosition(protocol.RoutePosition{Target: target, ActiveTabID: "tab-2"}))}, | |
| 1752 | 1753 | {err: io.EOF}, | |
| 1753 | 1754 | }} | |
| 1754 | 1755 | tr2 := &recordingTransport{recvs: []recvItem{ | |
| @@ -1760,7 +1761,7 @@ func TestReconnectRestoresLastPublishedRouteTab(t *testing.T) { | |||
| 1760 | 1761 | result := make(chan error, 1) | |
| 1761 | 1762 | go func() { | |
| 1762 | 1763 | result <- runTestClient(context.Background(), testDependencies(dialer, term, clock, nil, nil), client.AttachRequest{ | |
| 1763 | - | Intent: ports.IntentAttach, SessionName: "work", Origin: ports.RouteOriginLocal, OriginKey: "local", | |
| 1764 | + | Intent: ports.IntentAttach, SessionName: "work", Origin: protocol.RouteOriginLocal, OriginKey: "local", | |
| 1764 | 1765 | }) | |
| 1765 | 1766 | }() | |
| 1766 | 1767 | clock.fireReconnect(t) | |
| @@ -1782,15 +1783,15 @@ func TestRemoteReconnectDropsStalePickerTargetAfterDaemonSessionSwitch(t *testin | |||
| 1782 | 1783 | welcome := func(name string, lifecycle domain.SessionLifecycleID, token uint64) ports.Frame { | |
| 1783 | 1784 | return frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{ | |
| 1784 | 1785 | SessionID: name, SessionName: name, ResumeToken: token, Capabilities: ports.CapabilityResume, | |
| 1785 | - | CommittedIdentity: &ports.CommittedRouteIdentity{ | |
| 1786 | - | Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 1786 | + | CommittedIdentity: &protocol.CommittedRouteIdentity{ | |
| 1787 | + | Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: name}, | |
| 1787 | 1788 | }, | |
| 1788 | 1789 | })) | |
| 1789 | 1790 | } | |
| 1790 | 1791 | tr1 := &recordingTransport{recvs: []recvItem{ | |
| 1791 | 1792 | {f: welcome("old", oldLifecycle, 11)}, | |
| 1792 | - | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(ports.CommittedRouteIdentity{ | |
| 1793 | - | Target: ports.ExactSessionTarget{LifecycleID: newLifecycle, SessionName: "new"}, | |
| 1793 | + | {f: frameOf(ports.MsgCommittedRouteIdentity, mustMarshalCommittedIdentity(protocol.CommittedRouteIdentity{ | |
| 1794 | + | Target: protocol.ExactSessionTarget{LifecycleID: newLifecycle, SessionName: "new"}, | |
| 1794 | 1795 | }))}, | |
| 1795 | 1796 | {err: io.EOF}, | |
| 1796 | 1797 | }} | |
| @@ -1804,7 +1805,7 @@ func TestRemoteReconnectDropsStalePickerTargetAfterDaemonSessionSwitch(t *testin | |||
| 1804 | 1805 | go func() { | |
| 1805 | 1806 | result <- runTestClient(context.Background(), testDependencies(dialer, term, clock, nil, nil), client.AttachRequest{ | |
| 1806 | 1807 | Intent: ports.IntentAttach, SessionName: "old", Remote: true, | |
| 1807 | - | Origin: ports.RouteOriginDiscovery, OriginKey: "remote", | |
| 1808 | + | Origin: protocol.RouteOriginDiscovery, OriginKey: "remote", | |
| 1808 | 1809 | RemoteTarget: remoteTarget, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 1809 | 1810 | }) | |
| 1810 | 1811 | }() | |
| @@ -1814,7 +1815,7 @@ func TestRemoteReconnectDropsStalePickerTargetAfterDaemonSessionSwitch(t *testin | |||
| 1814 | 1815 | reconnectHello := helloFromSend(t, tr2) | |
| 1815 | 1816 | require.Equal(t, ports.IntentResume, reconnectHello.Intent) | |
| 1816 | 1817 | require.Equal(t, "new", reconnectHello.Name) | |
| 1817 | - | require.Equal(t, &ports.ExactSessionTarget{LifecycleID: newLifecycle, SessionName: "new"}, reconnectHello.ExactTarget) | |
| 1818 | + | require.Equal(t, &protocol.ExactSessionTarget{LifecycleID: newLifecycle, SessionName: "new"}, reconnectHello.ExactTarget) | |
| 1818 | 1819 | require.Nil(t, reconnectHello.RemoteTarget) | |
| 1819 | 1820 | } | |
| 1820 | 1821 | ||
M internal/usecase/client/clipboard_intercept_internal_test.go +5 -4
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | "github.com/stretchr/testify/require" | |
| 10 | 10 | ||
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | 15 | // ciFakeReader is a directly-controllable ports.ClipboardReader for | |
| @@ -26,17 +27,17 @@ func (r *ciFakeReader) ReadImage(context.Context) (string, []byte, error) { | |||
| 26 | 27 | return r.mime, r.data, r.err | |
| 27 | 28 | } | |
| 28 | 29 | ||
| 29 | - | func newTestClipboardIntercept(reader ports.ClipboardReader) (*clipboardIntercept, *pasteCoalescer, *pcFakeClock, *pcCollector, *[]ports.ImagePush) { | |
| 30 | + | func newTestClipboardIntercept(reader ports.ClipboardReader) (*clipboardIntercept, *pasteCoalescer, *pcFakeClock, *pcCollector, *[]protocol.ImagePush) { | |
| 30 | 31 | clk := &pcFakeClock{} | |
| 31 | 32 | col := &pcCollector{} | |
| 32 | 33 | pc := newPasteCoalescer(clk, col.emit) | |
| 33 | - | var images []ports.ImagePush | |
| 34 | + | var images []protocol.ImagePush | |
| 34 | 35 | ci := &clipboardIntercept{ | |
| 35 | 36 | coalescer: pc, | |
| 36 | 37 | reader: reader, | |
| 37 | 38 | log: slog.New(slog.NewTextHandler(nil, &slog.HandlerOptions{Level: slog.LevelError + 1})), | |
| 38 | 39 | sendImage: func(mime string, data []byte) { | |
| 39 | - | images = append(images, ports.ImagePush{Mime: mime, Data: data}) | |
| 40 | + | images = append(images, protocol.ImagePush{Mime: mime, Data: data}) | |
| 40 | 41 | }, | |
| 41 | 42 | next: pc.Scan, | |
| 42 | 43 | } | |
| @@ -53,7 +54,7 @@ func TestClipboardInterceptCtrlVWithImageSendsNoPassthrough(t *testing.T) { | |||
| 53 | 54 | ci.Scan([]byte("b")) | |
| 54 | 55 | ||
| 55 | 56 | require.Equal(t, 1, reader.n, "clipboard must be read exactly once per Ctrl+V") | |
| 56 | - | require.Equal(t, []ports.ImagePush{{Mime: "image/png", Data: []byte("PNGDATA")}}, *images) | |
| 57 | + | require.Equal(t, []protocol.ImagePush{{Mime: "image/png", Data: []byte("PNGDATA")}}, *images) | |
| 57 | 58 | require.Equal(t, [][]byte{[]byte("a"), []byte("b")}, col.snapshot(), "0x16 itself must never reach the coalescer/pane") | |
| 58 | 59 | } | |
| 59 | 60 | ||
M internal/usecase/client/clipboard_intercept_test.go +4 -3
| @@ -14,6 +14,7 @@ import ( | |||
| 14 | 14 | "github.com/bnema/vev/internal/domain" | |
| 15 | 15 | "github.com/bnema/vev/internal/ports" | |
| 16 | 16 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 17 | + | "github.com/bnema/vev/internal/protocol" | |
| 17 | 18 | "github.com/bnema/vev/internal/usecase/client" | |
| 18 | 19 | ) | |
| 19 | 20 | ||
| @@ -22,7 +23,7 @@ import ( | |||
| 22 | 23 | // transport that captures every MsgInput/MsgImagePush send, and a Recv that | |
| 23 | 24 | // answers Welcome then, once triggered, Detached — mirroring the pattern used | |
| 24 | 25 | // by the OSC-color-response test elsewhere in this package. | |
| 25 | - | func runRemoteClipboardTest(t *testing.T, remote bool, clip ports.ClipboardReader, stdin []byte, triggerByte byte) (gotInput chan []byte, gotImage chan ports.ImagePush) { | |
| 26 | + | func runRemoteClipboardTest(t *testing.T, remote bool, clip ports.ClipboardReader, stdin []byte, triggerByte byte) (gotInput chan []byte, gotImage chan protocol.ImagePush) { | |
| 26 | 27 | t.Helper() | |
| 27 | 28 | var out bytes.Buffer | |
| 28 | 29 | var restoreCount int32 | |
| @@ -39,7 +40,7 @@ func runRemoteClipboardTest(t *testing.T, remote bool, clip ports.ClipboardReade | |||
| 39 | 40 | tm.EXPECT().ResizeEvents().Return(resizeCh).Maybe() | |
| 40 | 41 | ||
| 41 | 42 | gotInput = make(chan []byte, 8) | |
| 42 | - | gotImage = make(chan ports.ImagePush, 1) | |
| 43 | + | gotImage = make(chan protocol.ImagePush, 1) | |
| 43 | 44 | allowDetach := make(chan struct{}) | |
| 44 | 45 | ||
| 45 | 46 | tr := portsmocks.NewMockTransport(t) | |
| @@ -198,7 +199,7 @@ func TestRunRemoteClipboardFailureNotifiesDaemonAndWritesOutputVerbatim(t *testi | |||
| 198 | 199 | } | |
| 199 | 200 | } | |
| 200 | 201 | beforeOutput := out.String() | |
| 201 | - | transport.recv <- frameOf(ports.MsgOutput, mustMarshalOutput(ports.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("incremental")})) | |
| 202 | + | transport.recv <- frameOf(ports.MsgOutput, mustMarshalOutput(protocol.Output{Epoch: 1, Base: 0, New: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("incremental")})) | |
| 202 | 203 | transport.recv <- frameOf(ports.MsgDetached, ports.MarshalDetached(ports.Detached{Reason: ports.ReasonDetach})) | |
| 203 | 204 | ||
| 204 | 205 | select { | |
M internal/usecase/client/navigation_test.go +7 -6
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | 5 | ||
| 6 | 6 | "github.com/bnema/vev/internal/domain" | |
| 7 | 7 | "github.com/bnema/vev/internal/ports" | |
| 8 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 9 | "github.com/stretchr/testify/require" | |
| 9 | 10 | ) | |
| 10 | 11 | ||
| @@ -37,13 +38,13 @@ func TestValidateAttachRequestNavigationTable(t *testing.T) { | |||
| 37 | 38 | valid bool | |
| 38 | 39 | }{ | |
| 39 | 40 | {name: "ordinary route", request: AttachRequest{}, valid: true}, | |
| 40 | - | {name: "home picker without remote route", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "work", NavigationCapabilities: ports.NavigationCapabilityHomePicker}, valid: false}, | |
| 41 | - | {name: "home picker on daemon-owned remote route", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "work", Remote: true, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, NavigationCapabilities: ports.NavigationCapabilityHomePicker}, valid: true}, | |
| 42 | - | {name: "back on client-owned route", request: AttachRequest{StartupOverlay: ports.StartupOverlaySessionPicker, NavigationCapabilities: ports.NavigationCapabilityBack}, valid: true}, | |
| 43 | - | {name: "back on remote-target route", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "work", RemoteTarget: remoteRoute, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, StartupOverlay: ports.StartupOverlaySessionPicker, NavigationCapabilities: ports.NavigationCapabilityBack}, valid: false}, | |
| 41 | + | {name: "home picker without remote route", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "work", NavigationCapabilities: protocol.NavigationCapabilityHomePicker}, valid: false}, | |
| 42 | + | {name: "home picker on daemon-owned remote route", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "work", Remote: true, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, NavigationCapabilities: protocol.NavigationCapabilityHomePicker}, valid: true}, | |
| 43 | + | {name: "back on client-owned route", request: AttachRequest{StartupOverlay: protocol.StartupOverlaySessionPicker, NavigationCapabilities: protocol.NavigationCapabilityBack}, valid: true}, | |
| 44 | + | {name: "back on remote-target route", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "work", RemoteTarget: remoteRoute, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, StartupOverlay: protocol.StartupOverlaySessionPicker, NavigationCapabilities: protocol.NavigationCapabilityBack}, valid: false}, | |
| 44 | 45 | {name: "unknown capability", request: AttachRequest{NavigationCapabilities: 4}, valid: false}, | |
| 45 | - | {name: "back without startup picker", request: AttachRequest{NavigationCapabilities: ports.NavigationCapabilityBack}, valid: false}, | |
| 46 | - | {name: "startup picker without back", request: AttachRequest{StartupOverlay: ports.StartupOverlaySessionPicker}, valid: false}, | |
| 46 | + | {name: "back without startup picker", request: AttachRequest{NavigationCapabilities: protocol.NavigationCapabilityBack}, valid: false}, | |
| 47 | + | {name: "startup picker without back", request: AttachRequest{StartupOverlay: protocol.StartupOverlaySessionPicker}, valid: false}, | |
| 47 | 48 | } | |
| 48 | 49 | ||
| 49 | 50 | for _, tt := range tests { | |
M internal/usecase/client/output_state.go +2 -2
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | package client | |
| 2 | 2 | ||
| 3 | - | import "github.com/bnema/vev/internal/ports" | |
| 3 | + | import "github.com/bnema/vev/internal/protocol" | |
| 4 | 4 | ||
| 5 | 5 | // outputApplyState is the client-side dependency chain for one attachment. | |
| 6 | 6 | // State-bearing frames are accepted only when their epoch, base, and view | |
| @@ -12,7 +12,7 @@ type outputApplyState struct { | |||
| 12 | 12 | initialized bool | |
| 13 | 13 | } | |
| 14 | 14 | ||
| 15 | - | func (s outputApplyState) next(output ports.Output) (outputApplyState, bool) { | |
| 15 | + | func (s outputApplyState) next(output protocol.Output) (outputApplyState, bool) { | |
| 16 | 16 | if output.Epoch == 0 { | |
| 17 | 17 | return outputApplyState{}, false | |
| 18 | 18 | } | |
M internal/usecase/client/output_state_test.go +12 -12
| @@ -4,28 +4,28 @@ import ( | |||
| 4 | 4 | "testing" | |
| 5 | 5 | ||
| 6 | 6 | "github.com/bnema/vev/internal/domain" | |
| 7 | - | "github.com/bnema/vev/internal/ports" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 8 | ) | |
| 9 | 9 | ||
| 10 | 10 | func TestOutputApplyStateTransitions(t *testing.T) { | |
| 11 | - | full := ports.Output{Epoch: 1, Base: 0, New: 1, Full: true, ViewRevision: 2, Size: domain.Size{Cols: 80, Rows: 24}} | |
| 11 | + | full := protocol.Output{Epoch: 1, Base: 0, New: 1, Full: true, ViewRevision: 2, Size: domain.Size{Cols: 80, Rows: 24}} | |
| 12 | 12 | tests := []struct { | |
| 13 | 13 | name string | |
| 14 | 14 | state outputApplyState | |
| 15 | - | output ports.Output | |
| 15 | + | output protocol.Output | |
| 16 | 16 | accepted bool | |
| 17 | 17 | want outputApplyState | |
| 18 | 18 | }{ | |
| 19 | 19 | {name: "first full", output: full, accepted: true, want: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}}, | |
| 20 | - | {name: "first gap", output: ports.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 2}, accepted: false}, | |
| 21 | - | {name: "increment", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: ports.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 2}, accepted: true, want: outputApplyState{epoch: 1, state: 2, viewRevision: 2, initialized: true}}, | |
| 22 | - | {name: "base gap", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: ports.Output{Epoch: 1, Base: 0, New: 2, Full: true, ViewRevision: 2}, accepted: false}, | |
| 23 | - | {name: "revision gap", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: ports.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 3}, accepted: false}, | |
| 24 | - | {name: "handoff side effect crosses newer epoch replay gate", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: ports.Output{Epoch: 2, ViewRevision: 3}, accepted: true, want: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}}, | |
| 25 | - | {name: "handoff side effect crosses stale epoch replay gate", state: outputApplyState{epoch: 2, state: 4, viewRevision: 5, initialized: true}, output: ports.Output{Epoch: 1, ViewRevision: 2}, accepted: true, want: outputApplyState{epoch: 2, state: 4, viewRevision: 5, initialized: true}}, | |
| 26 | - | {name: "side effect cannot invent state", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: ports.Output{Epoch: 2, Base: 1}, accepted: false}, | |
| 27 | - | {name: "side effect cannot claim full replay", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: ports.Output{Epoch: 2, Full: true}, accepted: false}, | |
| 28 | - | {name: "new epoch reset", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: ports.Output{Epoch: 2, Base: 0, New: 1, Full: true, ViewRevision: 3}, accepted: true, want: outputApplyState{epoch: 2, state: 1, viewRevision: 3, initialized: true}}, | |
| 20 | + | {name: "first gap", output: protocol.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 2}, accepted: false}, | |
| 21 | + | {name: "increment", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: protocol.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 2}, accepted: true, want: outputApplyState{epoch: 1, state: 2, viewRevision: 2, initialized: true}}, | |
| 22 | + | {name: "base gap", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: protocol.Output{Epoch: 1, Base: 0, New: 2, Full: true, ViewRevision: 2}, accepted: false}, | |
| 23 | + | {name: "revision gap", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: protocol.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 3}, accepted: false}, | |
| 24 | + | {name: "handoff side effect crosses newer epoch replay gate", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: protocol.Output{Epoch: 2, ViewRevision: 3}, accepted: true, want: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}}, | |
| 25 | + | {name: "handoff side effect crosses stale epoch replay gate", state: outputApplyState{epoch: 2, state: 4, viewRevision: 5, initialized: true}, output: protocol.Output{Epoch: 1, ViewRevision: 2}, accepted: true, want: outputApplyState{epoch: 2, state: 4, viewRevision: 5, initialized: true}}, | |
| 26 | + | {name: "side effect cannot invent state", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: protocol.Output{Epoch: 2, Base: 1}, accepted: false}, | |
| 27 | + | {name: "side effect cannot claim full replay", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: protocol.Output{Epoch: 2, Full: true}, accepted: false}, | |
| 28 | + | {name: "new epoch reset", state: outputApplyState{epoch: 1, state: 1, viewRevision: 2, initialized: true}, output: protocol.Output{Epoch: 2, Base: 0, New: 1, Full: true, ViewRevision: 3}, accepted: true, want: outputApplyState{epoch: 2, state: 1, viewRevision: 3, initialized: true}}, | |
| 29 | 29 | } | |
| 30 | 30 | for _, tt := range tests { | |
| 31 | 31 | t.Run(tt.name, func(t *testing.T) { | |
M internal/usecase/client/palette_attach_generation_test.go +9 -8
| @@ -16,6 +16,7 @@ import ( | |||
| 16 | 16 | renderer "github.com/bnema/vev-vt" | |
| 17 | 17 | "github.com/bnema/vev/internal/domain" | |
| 18 | 18 | "github.com/bnema/vev/internal/ports" | |
| 19 | + | "github.com/bnema/vev/internal/protocol" | |
| 19 | 20 | ) | |
| 20 | 21 | ||
| 21 | 22 | // attachPaletteClock deliberately exposes each independently-created timer. | |
| @@ -115,8 +116,8 @@ func (*attachPaletteTerminalHarness) Flush() error { r | |||
| 115 | 116 | type attachPaletteTransport struct { | |
| 116 | 117 | mu sync.Mutex | |
| 117 | 118 | frames []ports.Frame | |
| 118 | - | themes []ports.Theme | |
| 119 | - | themeCh chan ports.Theme | |
| 119 | + | themes []protocol.Theme | |
| 120 | + | themeCh chan protocol.Theme | |
| 120 | 121 | inputCh chan ports.Input | |
| 121 | 122 | detached chan ports.Frame | |
| 122 | 123 | themeSendErr error | |
| @@ -125,7 +126,7 @@ type attachPaletteTransport struct { | |||
| 125 | 126 | ||
| 126 | 127 | func newAttachPaletteTransport() *attachPaletteTransport { | |
| 127 | 128 | return &attachPaletteTransport{ | |
| 128 | - | themeCh: make(chan ports.Theme, 16), | |
| 129 | + | themeCh: make(chan protocol.Theme, 16), | |
| 129 | 130 | inputCh: make(chan ports.Input, 16), | |
| 130 | 131 | detached: make(chan ports.Frame, 1), | |
| 131 | 132 | } | |
| @@ -168,10 +169,10 @@ func (t *attachPaletteTransport) Recv() (ports.Frame, error) { | |||
| 168 | 169 | return <-t.detached, nil | |
| 169 | 170 | } | |
| 170 | 171 | func (*attachPaletteTransport) Close() error { return nil } | |
| 171 | - | func (t *attachPaletteTransport) snapshots() []ports.Theme { | |
| 172 | + | func (t *attachPaletteTransport) snapshots() []protocol.Theme { | |
| 172 | 173 | t.mu.Lock() | |
| 173 | 174 | defer t.mu.Unlock() | |
| 174 | - | return append([]ports.Theme(nil), t.themes...) | |
| 175 | + | return append([]protocol.Theme(nil), t.themes...) | |
| 175 | 176 | } | |
| 176 | 177 | ||
| 177 | 178 | type attachPaletteHarness struct { | |
| @@ -228,7 +229,7 @@ func (h *attachPaletteHarness) nextWrite(t *testing.T) string { | |||
| 228 | 229 | t.Helper() | |
| 229 | 230 | return <-h.writer.wrote | |
| 230 | 231 | } | |
| 231 | - | func (h *attachPaletteHarness) nextTheme(t *testing.T) ports.Theme { | |
| 232 | + | func (h *attachPaletteHarness) nextTheme(t *testing.T) protocol.Theme { | |
| 232 | 233 | t.Helper() | |
| 233 | 234 | return <-h.transport.themeCh | |
| 234 | 235 | } | |
| @@ -428,7 +429,7 @@ func TestStdinPumpSameReadSchemeAndOldMarkerCannotAdvanceReplacement(t *testing. | |||
| 428 | 429 | defer cancel() | |
| 429 | 430 | ||
| 430 | 431 | coordinator := newPaletteGenerationCoordinator() | |
| 431 | - | coordinator.start(ports.Theme{}, false) | |
| 432 | + | coordinator.start(protocol.Theme{}, false) | |
| 432 | 433 | var activeGeneration atomic.Uint64 | |
| 433 | 434 | activeGeneration.Store(uint64(coordinator.current.id)) | |
| 434 | 435 | ||
| @@ -466,7 +467,7 @@ func TestStdinPumpSameReadSchemeAndOldMarkerCannotAdvanceReplacement(t *testing. | |||
| 466 | 467 | // This models attachAttempt handling the scheme event. The replacement is | |
| 467 | 468 | // draining, so a marker tagged with its ID would incorrectly start its | |
| 468 | 469 | // color batch before the real drain boundary arrives. | |
| 469 | - | coordinator.start(ports.Theme{SchemeKnown: true, Light: scheme.light}, true) | |
| 470 | + | coordinator.start(protocol.Theme{SchemeKnown: true, Light: scheme.light}, true) | |
| 470 | 471 | newID := coordinator.current.id | |
| 471 | 472 | activeGeneration.Store(uint64(newID)) | |
| 472 | 473 | close(schemeHandled) | |
M internal/usecase/client/palette_attach_test.go +2 -1
| @@ -14,6 +14,7 @@ import ( | |||
| 14 | 14 | renderer "github.com/bnema/vev-vt" | |
| 15 | 15 | "github.com/bnema/vev/internal/domain" | |
| 16 | 16 | "github.com/bnema/vev/internal/ports" | |
| 17 | + | "github.com/bnema/vev/internal/protocol" | |
| 17 | 18 | ) | |
| 18 | 19 | ||
| 19 | 20 | type paletteAttachClock struct{} | |
| @@ -78,7 +79,7 @@ func (t *paletteAttachTerminal) Flush() error { return n | |||
| 78 | 79 | type paletteAttachTransport struct { | |
| 79 | 80 | mu sync.Mutex | |
| 80 | 81 | sent []ports.Frame | |
| 81 | - | themes []ports.Theme | |
| 82 | + | themes []protocol.Theme | |
| 82 | 83 | finals int | |
| 83 | 84 | finalSet chan struct{} | |
| 84 | 85 | } | |
M internal/usecase/client/palette_generation.go +7 -7
| @@ -4,7 +4,7 @@ import ( | |||
| 4 | 4 | "time" | |
| 5 | 5 | ||
| 6 | 6 | renderer "github.com/bnema/vev-vt" | |
| 7 | - | "github.com/bnema/vev/internal/ports" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 8 | ) | |
| 9 | 9 | ||
| 10 | 10 | // Palette queries always have a DECRQM boundary. The first marker drains | |
| @@ -38,7 +38,7 @@ const ( | |||
| 38 | 38 | type paletteGeneration struct { | |
| 39 | 39 | id paletteGenerationID | |
| 40 | 40 | phase paletteGenerationPhase | |
| 41 | - | theme ports.Theme | |
| 41 | + | theme protocol.Theme | |
| 42 | 42 | expectedMarkers int | |
| 43 | 43 | awaitingLateDrainBoundary bool | |
| 44 | 44 | } | |
| @@ -83,7 +83,7 @@ type paletteGenerationAction struct { | |||
| 83 | 83 | kind paletteGenerationActionKind | |
| 84 | 84 | id paletteGenerationID | |
| 85 | 85 | bytes string | |
| 86 | - | theme ports.Theme | |
| 86 | + | theme protocol.Theme | |
| 87 | 87 | deadline time.Duration | |
| 88 | 88 | } | |
| 89 | 89 | ||
| @@ -93,7 +93,7 @@ type paletteGenerationCoordinator struct { | |||
| 93 | 93 | next paletteGenerationID | |
| 94 | 94 | current paletteGeneration | |
| 95 | 95 | active bool | |
| 96 | - | finalized ports.Theme | |
| 96 | + | finalized protocol.Theme | |
| 97 | 97 | } | |
| 98 | 98 | ||
| 99 | 99 | func newPaletteGenerationCoordinator() *paletteGenerationCoordinator { | |
| @@ -104,7 +104,7 @@ func newPaletteGenerationCoordinator() *paletteGenerationCoordinator { | |||
| 104 | 104 | // batch or a replacement drain. The retained foreground/background and | |
| 105 | 105 | // capability avoid a full neutral flash, while the accumulator begins with no | |
| 106 | 106 | // defaults or palette values so a definitive result never mixes generations. | |
| 107 | - | func (c *paletteGenerationCoordinator) start(retained ports.Theme, replacement bool) []paletteGenerationAction { | |
| 107 | + | func (c *paletteGenerationCoordinator) start(retained protocol.Theme, replacement bool) []paletteGenerationAction { | |
| 108 | 108 | actions := c.cancelCurrent() | |
| 109 | 109 | c.next++ | |
| 110 | 110 | id := c.next | |
| @@ -115,7 +115,7 @@ func (c *paletteGenerationCoordinator) start(retained ports.Theme, replacement b | |||
| 115 | 115 | c.current = paletteGeneration{ | |
| 116 | 116 | id: id, | |
| 117 | 117 | phase: generationCollecting, | |
| 118 | - | theme: ports.Theme{ | |
| 118 | + | theme: protocol.Theme{ | |
| 119 | 119 | TrueColor: retained.TrueColor, | |
| 120 | 120 | SchemeKnown: retained.SchemeKnown, | |
| 121 | 121 | Light: retained.Light, | |
| @@ -250,7 +250,7 @@ func (c *paletteGenerationCoordinator) palette(id paletteGenerationID, slot uint | |||
| 250 | 250 | c.handle(paletteGenerationEvent{id: id, kind: paletteEventPalette, slot: slot, rgb: rgb}) | |
| 251 | 251 | } | |
| 252 | 252 | ||
| 253 | - | func (c *paletteGenerationCoordinator) finalizedTheme() ports.Theme { return c.finalized } | |
| 253 | + | func (c *paletteGenerationCoordinator) finalizedTheme() protocol.Theme { return c.finalized } | |
| 254 | 254 | ||
| 255 | 255 | // paletteMarkerScanner consumes only complete DECRQM 2031 replies and retains | |
| 256 | 256 | // possible prefixes across reads, forwarding all ordinary input exactly once. | |
M internal/usecase/client/palette_generation_test.go +3 -3
| @@ -7,7 +7,7 @@ import ( | |||
| 7 | 7 | "github.com/stretchr/testify/require" | |
| 8 | 8 | ||
| 9 | 9 | renderer "github.com/bnema/vev-vt" | |
| 10 | - | "github.com/bnema/vev/internal/ports" | |
| 10 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 11 | ) | |
| 12 | 12 | ||
| 13 | 13 | // manualPaletteClock applies only declarative coordinator timer actions. Its | |
| @@ -52,8 +52,8 @@ func (c *manualPaletteClock) fireCompletion(g *paletteGenerationCoordinator, id | |||
| 52 | 52 | return g.handle(paletteGenerationEvent{id: id, kind: paletteEventCompletionDeadline}) | |
| 53 | 53 | } | |
| 54 | 54 | ||
| 55 | - | func generationTheme() ports.Theme { | |
| 56 | - | return ports.Theme{ | |
| 55 | + | func generationTheme() protocol.Theme { | |
| 56 | + | return protocol.Theme{ | |
| 57 | 57 | TrueColor: true, | |
| 58 | 58 | HasForeground: true, | |
| 59 | 59 | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
M internal/usecase/client/reconnect_toast_test.go +14 -13
| @@ -20,6 +20,7 @@ import ( | |||
| 20 | 20 | "github.com/bnema/vev/internal/domain" | |
| 21 | 21 | "github.com/bnema/vev/internal/ports" | |
| 22 | 22 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 23 | + | "github.com/bnema/vev/internal/protocol" | |
| 23 | 24 | ) | |
| 24 | 25 | ||
| 25 | 26 | type reconnectToastTerminalHarness struct { | |
| @@ -393,7 +394,7 @@ func TestProbingToastReconcilesDaemonOutputAndDismissal(t *testing.T) { | |||
| 393 | 394 | require.Contains(t, firstToast, "┌") | |
| 394 | 395 | require.Contains(t, firstToast, "probing UDP path") | |
| 395 | 396 | ||
| 396 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 397 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 397 | 398 | Epoch: 1, | |
| 398 | 399 | Base: 0, | |
| 399 | 400 | New: 2, | |
| @@ -412,7 +413,7 @@ func TestProbingToastReconcilesDaemonOutputAndDismissal(t *testing.T) { | |||
| 412 | 413 | ||
| 413 | 414 | beforeAwaitingReset := out.String() | |
| 414 | 415 | beforeStatelessFlushes := flushes.Load() | |
| 415 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 416 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 416 | 417 | Epoch: 1, | |
| 417 | 418 | Base: 0, | |
| 418 | 419 | New: 0, | |
| @@ -424,7 +425,7 @@ func TestProbingToastReconcilesDaemonOutputAndDismissal(t *testing.T) { | |||
| 424 | 425 | }, time.Second, time.Millisecond) | |
| 425 | 426 | ||
| 426 | 427 | afterStateless := out.String() | |
| 427 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 428 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 428 | 429 | Epoch: 1, | |
| 429 | 430 | Base: 2, | |
| 430 | 431 | New: 3, | |
| @@ -435,7 +436,7 @@ func TestProbingToastReconcilesDaemonOutputAndDismissal(t *testing.T) { | |||
| 435 | 436 | require.Contains(t, out.String(), "intervening incremental") | |
| 436 | 437 | require.Contains(t, afterStateless[len(beforeAwaitingReset):], "stateless side effect") | |
| 437 | 438 | ||
| 438 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 439 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 439 | 440 | Epoch: 2, | |
| 440 | 441 | Base: 0, | |
| 441 | 442 | New: 4, | |
| @@ -448,7 +449,7 @@ func TestProbingToastReconcilesDaemonOutputAndDismissal(t *testing.T) { | |||
| 448 | 449 | require.NotContains(t, out.String()[len(beforeAwaitingReset):], strings.Repeat(" ", reconnectToastBoundsFor(term.size, "probing UDP path").Width)) | |
| 449 | 450 | ||
| 450 | 451 | beforeIncrementFlushes := flushes.Load() | |
| 451 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 452 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 452 | 453 | Epoch: 2, | |
| 453 | 454 | Base: 4, | |
| 454 | 455 | New: 5, | |
| @@ -491,7 +492,7 @@ func TestActiveReconnectToastStageTransitionReconcilesBeforeRedraw(t *testing.T) | |||
| 491 | 492 | require.NotContains(t, out.String(), offlineMessage) | |
| 492 | 493 | ||
| 493 | 494 | beforeReset := out.String() | |
| 494 | - | for _, output := range []ports.Output{ | |
| 495 | + | for _, output := range []protocol.Output{ | |
| 495 | 496 | {Epoch: 1, Base: 1, New: 2, Size: domain.Size{Cols: 1, Rows: 1}, Data: []byte("first skipped increment")}, | |
| 496 | 497 | {Epoch: 1, Base: 2, New: 3, Size: domain.Size{Cols: 1, Rows: 1}, Data: []byte("second skipped increment")}, | |
| 497 | 498 | } { | |
| @@ -507,7 +508,7 @@ func TestActiveReconnectToastStageTransitionReconcilesBeforeRedraw(t *testing.T) | |||
| 507 | 508 | // Handoff cleanup is an ordered terminal side effect, not a replay state. | |
| 508 | 509 | // It must cross the outstanding reset gate, flush before the control handoff, | |
| 509 | 510 | // and must not manufacture an independent ACK. | |
| 510 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 511 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 511 | 512 | Epoch: 2, | |
| 512 | 513 | Size: domain.Size{Cols: 1, Rows: 1}, | |
| 513 | 514 | Data: []byte("handoff graphics cleanup"), | |
| @@ -518,7 +519,7 @@ func TestActiveReconnectToastStageTransitionReconcilesBeforeRedraw(t *testing.T) | |||
| 518 | 519 | require.False(t, sentAck, "state-independent cleanup must not be ACKed") | |
| 519 | 520 | ||
| 520 | 521 | beforeResetFlushes := flushes.Load() | |
| 521 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 522 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 522 | 523 | Epoch: 2, | |
| 523 | 524 | Base: 0, | |
| 524 | 525 | New: 4, | |
| @@ -533,7 +534,7 @@ func TestActiveReconnectToastStageTransitionReconcilesBeforeRedraw(t *testing.T) | |||
| 533 | 534 | requireAckedState(t, tr.sends, 2, 4) | |
| 534 | 535 | ||
| 535 | 536 | beforeIncrementFlushes := flushes.Load() | |
| 536 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 537 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 537 | 538 | Epoch: 2, | |
| 538 | 539 | Base: 4, | |
| 539 | 540 | New: 5, | |
| @@ -579,7 +580,7 @@ func requireSentFrame(t *testing.T, sends *reconnectToastSentFrames, description | |||
| 579 | 580 | } | |
| 580 | 581 | } | |
| 581 | 582 | ||
| 582 | - | func requireResize(t *testing.T, sends *reconnectToastSentFrames) ports.Resize { | |
| 583 | + | func requireResize(t *testing.T, sends *reconnectToastSentFrames) protocol.Resize { | |
| 583 | 584 | t.Helper() | |
| 584 | 585 | frame := requireSentFrame(t, sends, "Resize frame", func(frame ports.Frame) bool { | |
| 585 | 586 | return frame.Type == ports.MsgResize | |
| @@ -706,7 +707,7 @@ func TestLocalReconnectStatusFlushesDaemonOutputBeforeObservationAndAck(t *testi | |||
| 706 | 707 | require.Eventually(t, func() bool { return flushes.Load() > beforeStatus }, time.Second, time.Millisecond) | |
| 707 | 708 | beforeOutput := flushes.Load() | |
| 708 | 709 | ||
| 709 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 710 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 710 | 711 | Epoch: 1, | |
| 711 | 712 | Base: 0, | |
| 712 | 713 | New: 2, | |
| @@ -758,7 +759,7 @@ func TestLocalReconnectStatusTransitionsDoNotRequestAuthoritativeReset(t *testin | |||
| 758 | 759 | } | |
| 759 | 760 | ||
| 760 | 761 | const output = "local status output remains visible" | |
| 761 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 762 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 762 | 763 | Epoch: 1, | |
| 763 | 764 | Base: 0, | |
| 764 | 765 | New: 2, | |
| @@ -826,7 +827,7 @@ func TestReconnectOverlayRedrawFailureDoesNotObserveOrAckOutput(t *testing.T) { | |||
| 826 | 827 | tr.events <- ports.LinkEvent{State: ports.LinkStateProbing} | |
| 827 | 828 | requireReconnectToastOutput(t, out.completed) | |
| 828 | 829 | arm() | |
| 829 | - | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(ports.Output{ | |
| 830 | + | tr.recvCh <- reconnectToastRecv{frame: ports.Frame{Type: ports.MsgOutput, Payload: mustMarshalOutput(protocol.Output{ | |
| 830 | 831 | Epoch: 1, | |
| 831 | 832 | Base: 0, | |
| 832 | 833 | New: 2, | |
M internal/usecase/client/remote_attach_validation_test.go +2 -1
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | 11 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | 15 | func TestMalformedAttachRequestsNeverDial(t *testing.T) { | |
| @@ -19,7 +20,7 @@ func TestMalformedAttachRequestsNeverDial(t *testing.T) { | |||
| 19 | 20 | {name: "missing session name", request: AttachRequest{Intent: ports.IntentAttach}}, | |
| 20 | 21 | {name: "unsafe session name", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "bad name"}}, | |
| 21 | 22 | {name: "daemon-owned without remote", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "main", EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned}}, | |
| 22 | - | {name: "ephemeral with navigation capability", request: AttachRequest{Intent: ports.IntentEphemeral, NavigationCapabilities: ports.NavigationCapabilityHomePicker}}, | |
| 23 | + | {name: "ephemeral with navigation capability", request: AttachRequest{Intent: ports.IntentEphemeral, NavigationCapabilities: protocol.NavigationCapabilityHomePicker}}, | |
| 23 | 24 | } | |
| 24 | 25 | for _, tt := range tests { | |
| 25 | 26 | t.Run(tt.name, func(t *testing.T) { | |
M internal/usecase/client/routes.go +58 -57
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | ) | |
| 12 | 13 | ||
| 13 | 14 | // maxRouteLedgerEntries is the product history cap. It is deliberately | |
| @@ -36,11 +37,11 @@ type routeIdentity struct { | |||
| 36 | 37 | ||
| 37 | 38 | func (i routeIdentity) empty() bool { return i.key == 0 && i.generation == 0 } | |
| 38 | 39 | ||
| 39 | - | func (i routeIdentity) wire() ports.RouteRef { | |
| 40 | - | return ports.RouteRef{Key: uint64(i.key), Generation: uint64(i.generation)} | |
| 40 | + | func (i routeIdentity) wire() protocol.RouteRef { | |
| 41 | + | return protocol.RouteRef{Key: uint64(i.key), Generation: uint64(i.generation)} | |
| 41 | 42 | } | |
| 42 | 43 | ||
| 43 | - | func identityFromWire(ref ports.RouteRef) routeIdentity { | |
| 44 | + | func identityFromWire(ref protocol.RouteRef) routeIdentity { | |
| 44 | 45 | return routeIdentity{key: routeKey(ref.Key), generation: routeGeneration(ref.Generation)} | |
| 45 | 46 | } | |
| 46 | 47 | ||
| @@ -50,16 +51,16 @@ func identityFromWire(ref ports.RouteRef) routeIdentity { | |||
| 50 | 51 | type routePresentation struct { | |
| 51 | 52 | name string | |
| 52 | 53 | hostLabel string | |
| 53 | - | kind ports.RouteKind | |
| 54 | + | kind protocol.RouteKind | |
| 54 | 55 | ephemeral bool | |
| 55 | 56 | attention bool | |
| 56 | - | reachability ports.RouteReachability | |
| 57 | + | reachability protocol.RouteReachability | |
| 57 | 58 | } | |
| 58 | 59 | ||
| 59 | 60 | type routeCandidate struct { | |
| 60 | - | origin ports.RouteOrigin | |
| 61 | + | origin protocol.RouteOrigin | |
| 61 | 62 | originKey string | |
| 62 | - | target ports.ExactSessionTarget | |
| 63 | + | target protocol.ExactSessionTarget | |
| 63 | 64 | presentation routePresentation | |
| 64 | 65 | dialer ports.Dialer | |
| 65 | 66 | request AttachRequest | |
| @@ -69,9 +70,9 @@ type routeCandidate struct { | |||
| 69 | 70 | ||
| 70 | 71 | type routeRecord struct { | |
| 71 | 72 | identity routeIdentity | |
| 72 | - | origin ports.RouteOrigin | |
| 73 | + | origin protocol.RouteOrigin | |
| 73 | 74 | originKey string | |
| 74 | - | target ports.ExactSessionTarget | |
| 75 | + | target protocol.ExactSessionTarget | |
| 75 | 76 | presentation routePresentation | |
| 76 | 77 | dialer ports.Dialer | |
| 77 | 78 | request AttachRequest | |
| @@ -98,7 +99,7 @@ type routeLedger struct { | |||
| 98 | 99 | ||
| 99 | 100 | func newRouteLedger() *routeLedger { return &routeLedger{} } | |
| 100 | 101 | ||
| 101 | - | func cloneCommittedIdentity(identity *ports.CommittedRouteIdentity) *ports.CommittedRouteIdentity { | |
| 102 | + | func cloneCommittedIdentity(identity *protocol.CommittedRouteIdentity) *protocol.CommittedRouteIdentity { | |
| 102 | 103 | if identity == nil { | |
| 103 | 104 | return nil | |
| 104 | 105 | } | |
| @@ -106,7 +107,7 @@ func cloneCommittedIdentity(identity *ports.CommittedRouteIdentity) *ports.Commi | |||
| 106 | 107 | return &clone | |
| 107 | 108 | } | |
| 108 | 109 | ||
| 109 | - | func cloneRoutePosition(position *ports.RoutePosition) *ports.RoutePosition { | |
| 110 | + | func cloneRoutePosition(position *protocol.RoutePosition) *protocol.RoutePosition { | |
| 110 | 111 | if position == nil { | |
| 111 | 112 | return nil | |
| 112 | 113 | } | |
| @@ -114,13 +115,13 @@ func cloneRoutePosition(position *ports.RoutePosition) *ports.RoutePosition { | |||
| 114 | 115 | return &clone | |
| 115 | 116 | } | |
| 116 | 117 | ||
| 117 | - | func routeCandidateForAttach(request AttachRequest, identity ports.CommittedRouteIdentity, dialer ports.Dialer, resumeToken uint64) routeCandidate { | |
| 118 | + | func routeCandidateForAttach(request AttachRequest, identity protocol.CommittedRouteIdentity, dialer ports.Dialer, resumeToken uint64) routeCandidate { | |
| 118 | 119 | origin := normalizeRouteOrigin(request.Origin, request.Remote) | |
| 119 | 120 | originKey := normalizeRouteOriginKey(request.OriginKey, origin) | |
| 120 | - | kind := ports.RouteKindLocal | |
| 121 | + | kind := protocol.RouteKindLocal | |
| 121 | 122 | hostLabel := "" | |
| 122 | - | if request.Remote || request.RemoteTarget != nil || origin != ports.RouteOriginLocal { | |
| 123 | - | kind = ports.RouteKindRemote | |
| 123 | + | if request.Remote || request.RemoteTarget != nil || origin != protocol.RouteOriginLocal { | |
| 124 | + | kind = protocol.RouteKindRemote | |
| 124 | 125 | if request.RemoteTarget != nil { | |
| 125 | 126 | hostLabel = domain.RemoteDisplayOrigin(request.RemoteTarget.DisplayOrigin) | |
| 126 | 127 | } | |
| @@ -150,7 +151,7 @@ func routeCandidateForAttach(request AttachRequest, identity ports.CommittedRout | |||
| 150 | 151 | hostLabel: hostLabel, | |
| 151 | 152 | kind: kind, | |
| 152 | 153 | ephemeral: identity.Ephemeral, | |
| 153 | - | reachability: ports.RouteReachabilityReachable, | |
| 154 | + | reachability: protocol.RouteReachabilityReachable, | |
| 154 | 155 | }, | |
| 155 | 156 | dialer: dialer, | |
| 156 | 157 | request: request, | |
| @@ -158,7 +159,7 @@ func routeCandidateForAttach(request AttachRequest, identity ports.CommittedRout | |||
| 158 | 159 | } | |
| 159 | 160 | } | |
| 160 | 161 | ||
| 161 | - | func routeCandidateForCommittedIdentity(active routeRecord, identity ports.CommittedRouteIdentity) routeCandidate { | |
| 162 | + | func routeCandidateForCommittedIdentity(active routeRecord, identity protocol.CommittedRouteIdentity) routeCandidate { | |
| 162 | 163 | request := cloneAttachRequest(active.request) | |
| 163 | 164 | request.SessionName = identity.Target.SessionName | |
| 164 | 165 | request.ExactTarget = &identity.Target | |
| @@ -175,7 +176,7 @@ func routeCandidateForCommittedIdentity(active routeRecord, identity ports.Commi | |||
| 175 | 176 | hostLabel: active.presentation.hostLabel, | |
| 176 | 177 | kind: active.presentation.kind, | |
| 177 | 178 | ephemeral: identity.Ephemeral, | |
| 178 | - | reachability: ports.RouteReachabilityReachable, | |
| 179 | + | reachability: protocol.RouteReachabilityReachable, | |
| 179 | 180 | }, | |
| 180 | 181 | dialer: active.dialer, | |
| 181 | 182 | request: request, | |
| @@ -184,38 +185,38 @@ func routeCandidateForCommittedIdentity(active routeRecord, identity ports.Commi | |||
| 184 | 185 | } | |
| 185 | 186 | } | |
| 186 | 187 | ||
| 187 | - | func normalizeRouteOrigin(origin ports.RouteOrigin, remote bool) ports.RouteOrigin { | |
| 188 | + | func normalizeRouteOrigin(origin protocol.RouteOrigin, remote bool) protocol.RouteOrigin { | |
| 188 | 189 | if origin != 0 { | |
| 189 | 190 | return origin | |
| 190 | 191 | } | |
| 191 | 192 | if remote { | |
| 192 | - | return ports.RouteOriginRemote | |
| 193 | + | return protocol.RouteOriginRemote | |
| 193 | 194 | } | |
| 194 | - | return ports.RouteOriginLocal | |
| 195 | + | return protocol.RouteOriginLocal | |
| 195 | 196 | } | |
| 196 | 197 | ||
| 197 | - | func routeFailureCode(err error) ports.RouteFailureCode { | |
| 198 | + | func routeFailureCode(err error) protocol.RouteFailureCode { | |
| 198 | 199 | var protocolErr *ProtocolError | |
| 199 | 200 | if errors.As(err, &protocolErr) { | |
| 200 | 201 | switch protocolErr.Code { | |
| 201 | 202 | case ports.ErrNoSuchSession, ports.ErrNoSuchTarget: | |
| 202 | - | return ports.RouteFailureNoSuchRoute | |
| 203 | + | return protocol.RouteFailureNoSuchRoute | |
| 203 | 204 | } | |
| 204 | 205 | } | |
| 205 | 206 | if errors.Is(err, errRouteTargetChanged) { | |
| 206 | - | return ports.RouteFailureTargetChanged | |
| 207 | + | return protocol.RouteFailureTargetChanged | |
| 207 | 208 | } | |
| 208 | - | return ports.RouteFailureUnavailable | |
| 209 | + | return protocol.RouteFailureUnavailable | |
| 209 | 210 | } | |
| 210 | 211 | ||
| 211 | - | func normalizeRouteOriginKey(key string, origin ports.RouteOrigin) string { | |
| 212 | + | func normalizeRouteOriginKey(key string, origin protocol.RouteOrigin) string { | |
| 212 | 213 | if key != "" { | |
| 213 | 214 | return key | |
| 214 | 215 | } | |
| 215 | 216 | switch origin { | |
| 216 | - | case ports.RouteOriginLocal: | |
| 217 | + | case protocol.RouteOriginLocal: | |
| 217 | 218 | return "local" | |
| 218 | - | case ports.RouteOriginDiscovery: | |
| 219 | + | case protocol.RouteOriginDiscovery: | |
| 219 | 220 | return "discovery" | |
| 220 | 221 | default: | |
| 221 | 222 | return "remote" | |
| @@ -223,10 +224,10 @@ func normalizeRouteOriginKey(key string, origin ports.RouteOrigin) string { | |||
| 223 | 224 | } | |
| 224 | 225 | ||
| 225 | 226 | func validateRoutePresentation(p routePresentation) error { | |
| 226 | - | if err := ports.ValidateRouteLabel(p.name, false); err != nil { | |
| 227 | + | if err := protocol.ValidateRouteLabel(p.name, false); err != nil { | |
| 227 | 228 | return err | |
| 228 | 229 | } | |
| 229 | - | if err := ports.ValidateRouteLabel(p.hostLabel, true); err != nil { | |
| 230 | + | if err := protocol.ValidateRouteLabel(p.hostLabel, true); err != nil { | |
| 230 | 231 | return err | |
| 231 | 232 | } | |
| 232 | 233 | if err := p.kind.Validate(); err != nil { | |
| @@ -247,7 +248,7 @@ func (l *routeLedger) nextIdentityLocked() (routeIdentity, error) { | |||
| 247 | 248 | return routeIdentity{key: l.nextKey, generation: l.generation}, nil | |
| 248 | 249 | } | |
| 249 | 250 | ||
| 250 | - | func (l *routeLedger) findByTargetLocked(origin ports.RouteOrigin, originKey string, target ports.ExactSessionTarget) int { | |
| 251 | + | func (l *routeLedger) findByTargetLocked(origin protocol.RouteOrigin, originKey string, target protocol.ExactSessionTarget) int { | |
| 251 | 252 | for i := range l.entries { | |
| 252 | 253 | entry := l.entries[i] | |
| 253 | 254 | if entry.origin == origin && entry.originKey == originKey && entry.target == target { | |
| @@ -340,7 +341,7 @@ func (l *routeLedger) commitAttach(candidate routeCandidate) (routeIdentity, err | |||
| 340 | 341 | // commitCommittedIdentity snapshots the current active record and commits the | |
| 341 | 342 | // daemon's local transition under one lock. The active route, origin, dialer, | |
| 342 | 343 | // and attach request cannot be read from different ledger generations. | |
| 343 | - | func (l *routeLedger) commitCommittedIdentity(identity ports.CommittedRouteIdentity) (routeIdentity, error) { | |
| 344 | + | func (l *routeLedger) commitCommittedIdentity(identity protocol.CommittedRouteIdentity) (routeIdentity, error) { | |
| 344 | 345 | if err := identity.Validate(); err != nil { | |
| 345 | 346 | return routeIdentity{}, err | |
| 346 | 347 | } | |
| @@ -383,7 +384,7 @@ func (l *routeLedger) commitCommittedIdentity(identity ports.CommittedRouteIdent | |||
| 383 | 384 | // updateRoutePosition remembers a cursor only for the currently active exact | |
| 384 | 385 | // route. Delayed frames from a prior transition are valid wire messages but do | |
| 385 | 386 | // not mutate another route. | |
| 386 | - | func (l *routeLedger) updateRoutePosition(position ports.RoutePosition) error { | |
| 387 | + | func (l *routeLedger) updateRoutePosition(position protocol.RoutePosition) error { | |
| 387 | 388 | if err := position.Validate(); err != nil { | |
| 388 | 389 | return err | |
| 389 | 390 | } | |
| @@ -459,7 +460,7 @@ func (l *routeLedger) indexByIdentityLocked(identity routeIdentity) int { | |||
| 459 | 460 | return -1 | |
| 460 | 461 | } | |
| 461 | 462 | ||
| 462 | - | func (l *routeLedger) lookup(ref ports.RouteRef) (routeRecord, bool) { | |
| 463 | + | func (l *routeLedger) lookup(ref protocol.RouteRef) (routeRecord, bool) { | |
| 463 | 464 | identity := identityFromWire(ref) | |
| 464 | 465 | if identity.empty() { | |
| 465 | 466 | return routeRecord{}, false | |
| @@ -481,21 +482,21 @@ func cloneRouteRecord(entry routeRecord) routeRecord { | |||
| 481 | 482 | ||
| 482 | 483 | // attentionSubscription publishes only routes served by the active route's | |
| 483 | 484 | // daemon. Other route origins remain private to their owning daemon. | |
| 484 | - | func (l *routeLedger) attentionSubscription() ports.RouteAttentionSubscription { | |
| 485 | + | func (l *routeLedger) attentionSubscription() protocol.RouteAttentionSubscription { | |
| 485 | 486 | l.mu.RLock() | |
| 486 | 487 | defer l.mu.RUnlock() | |
| 487 | 488 | ||
| 488 | 489 | activeIndex := l.indexByIdentityLocked(l.active) | |
| 489 | 490 | if activeIndex < 0 { | |
| 490 | - | return ports.RouteAttentionSubscription{} | |
| 491 | + | return protocol.RouteAttentionSubscription{} | |
| 491 | 492 | } | |
| 492 | 493 | active := l.entries[activeIndex] | |
| 493 | - | subscription := ports.RouteAttentionSubscription{Targets: make([]ports.RouteAttentionTarget, 0, len(l.entries))} | |
| 494 | + | subscription := protocol.RouteAttentionSubscription{Targets: make([]protocol.RouteAttentionTarget, 0, len(l.entries))} | |
| 494 | 495 | for _, entry := range l.entries { | |
| 495 | 496 | if entry.identity == active.identity || entry.origin != active.origin || entry.originKey != active.originKey { | |
| 496 | 497 | continue | |
| 497 | 498 | } | |
| 498 | - | subscription.Targets = append(subscription.Targets, ports.RouteAttentionTarget{ | |
| 499 | + | subscription.Targets = append(subscription.Targets, protocol.RouteAttentionTarget{ | |
| 499 | 500 | Ref: entry.identity.wire(), | |
| 500 | 501 | Target: entry.target, | |
| 501 | 502 | }) | |
| @@ -503,8 +504,8 @@ func (l *routeLedger) attentionSubscription() ports.RouteAttentionSubscription { | |||
| 503 | 504 | return subscription | |
| 504 | 505 | } | |
| 505 | 506 | ||
| 506 | - | func (r routeRecord) snapshotEntry() ports.RecentRouteEntry { | |
| 507 | - | return ports.RecentRouteEntry{ | |
| 507 | + | func (r routeRecord) snapshotEntry() protocol.RecentRouteEntry { | |
| 508 | + | return protocol.RecentRouteEntry{ | |
| 508 | 509 | Key: uint64(r.identity.key), | |
| 509 | 510 | Generation: uint64(r.identity.generation), | |
| 510 | 511 | Target: r.target, | |
| @@ -517,11 +518,11 @@ func (r routeRecord) snapshotEntry() ports.RecentRouteEntry { | |||
| 517 | 518 | } | |
| 518 | 519 | } | |
| 519 | 520 | ||
| 520 | - | func (l *routeLedger) snapshot() ports.RecentRouteSnapshot { | |
| 521 | + | func (l *routeLedger) snapshot() protocol.RecentRouteSnapshot { | |
| 521 | 522 | l.mu.RLock() | |
| 522 | 523 | defer l.mu.RUnlock() | |
| 523 | 524 | ||
| 524 | - | snapshot := ports.RecentRouteSnapshot{ | |
| 525 | + | snapshot := protocol.RecentRouteSnapshot{ | |
| 525 | 526 | Generation: uint64(l.generation), | |
| 526 | 527 | Active: l.active.wire(), | |
| 527 | 528 | Previous: l.previous.wire(), | |
| @@ -530,7 +531,7 @@ func (l *routeLedger) snapshot() ports.RecentRouteSnapshot { | |||
| 530 | 531 | if len(l.entries) == 0 { | |
| 531 | 532 | return snapshot | |
| 532 | 533 | } | |
| 533 | - | snapshot.Entries = make([]ports.RecentRouteEntry, 0, len(l.entries)) | |
| 534 | + | snapshot.Entries = make([]protocol.RecentRouteEntry, 0, len(l.entries)) | |
| 534 | 535 | for _, entry := range l.entries { | |
| 535 | 536 | if entry.identity == l.active { | |
| 536 | 537 | snapshot.ActiveEntry = entry.snapshotEntry() | |
| @@ -548,7 +549,7 @@ func (l *routeLedger) samePeerHandoff(active AttachRequest, target ports.AttachT | |||
| 548 | 549 | origin := normalizeRouteOrigin(active.Origin, active.Remote) | |
| 549 | 550 | originKey := normalizeRouteOriginKey(active.OriginKey, origin) | |
| 550 | 551 | environmentPolicy := target.EnvironmentPolicy | |
| 551 | - | if origin == ports.RouteOriginLocal { | |
| 552 | + | if origin == protocol.RouteOriginLocal { | |
| 552 | 553 | environmentPolicy = ports.EnvironmentPolicyClientOwned | |
| 553 | 554 | } | |
| 554 | 555 | ||
| @@ -569,7 +570,7 @@ func (l *routeLedger) samePeerHandoff(active AttachRequest, target ports.AttachT | |||
| 569 | 570 | request.RemoteTarget = nil | |
| 570 | 571 | if request.EnvironmentPolicy != environmentPolicy && environmentPolicy == ports.EnvironmentPolicyClientOwned { | |
| 571 | 572 | request.NavigationCapabilities = 0 | |
| 572 | - | request.StartupOverlay = ports.StartupOverlayNone | |
| 573 | + | request.StartupOverlay = protocol.StartupOverlayNone | |
| 573 | 574 | } | |
| 574 | 575 | request.EnvironmentPolicy = environmentPolicy | |
| 575 | 576 | request.ExactTarget = target.ExactTarget | |
| @@ -587,25 +588,25 @@ func (l *routeLedger) samePeerHandoff(active AttachRequest, target ports.AttachT | |||
| 587 | 588 | request.RemoteTarget = nil | |
| 588 | 589 | if request.EnvironmentPolicy != environmentPolicy && environmentPolicy == ports.EnvironmentPolicyClientOwned { | |
| 589 | 590 | request.NavigationCapabilities = 0 | |
| 590 | - | request.StartupOverlay = ports.StartupOverlayNone | |
| 591 | + | request.StartupOverlay = protocol.StartupOverlayNone | |
| 591 | 592 | } | |
| 592 | 593 | request.EnvironmentPolicy = environmentPolicy | |
| 593 | 594 | return request | |
| 594 | 595 | } | |
| 595 | 596 | ||
| 596 | - | func (l *routeLedger) activeRef() ports.RouteRef { | |
| 597 | + | func (l *routeLedger) activeRef() protocol.RouteRef { | |
| 597 | 598 | l.mu.RLock() | |
| 598 | 599 | defer l.mu.RUnlock() | |
| 599 | 600 | return l.active.wire() | |
| 600 | 601 | } | |
| 601 | 602 | ||
| 602 | - | func (l *routeLedger) previousRef() ports.RouteRef { | |
| 603 | + | func (l *routeLedger) previousRef() protocol.RouteRef { | |
| 603 | 604 | l.mu.RLock() | |
| 604 | 605 | defer l.mu.RUnlock() | |
| 605 | 606 | return l.previous.wire() | |
| 606 | 607 | } | |
| 607 | 608 | ||
| 608 | - | func (l *routeLedger) homeRef() ports.RouteRef { | |
| 609 | + | func (l *routeLedger) homeRef() protocol.RouteRef { | |
| 609 | 610 | l.mu.RLock() | |
| 610 | 611 | defer l.mu.RUnlock() | |
| 611 | 612 | return l.home.wire() | |
| @@ -619,13 +620,13 @@ type routeTransitionPlan struct { | |||
| 619 | 620 | record routeRecord | |
| 620 | 621 | snapshotGeneration routeGeneration | |
| 621 | 622 | active routeIdentity | |
| 622 | - | origin ports.RouteOrigin | |
| 623 | + | origin protocol.RouteOrigin | |
| 623 | 624 | originKey string | |
| 624 | - | target ports.ExactSessionTarget | |
| 625 | + | target protocol.ExactSessionTarget | |
| 625 | 626 | } | |
| 626 | 627 | ||
| 627 | 628 | type routeTransitionCommit struct { | |
| 628 | - | identity ports.CommittedRouteIdentity | |
| 629 | + | identity protocol.CommittedRouteIdentity | |
| 629 | 630 | presentation routePresentation | |
| 630 | 631 | dialer ports.Dialer | |
| 631 | 632 | resumeToken uint64 | |
| @@ -650,11 +651,11 @@ type routeNavigationSelection struct { | |||
| 650 | 651 | // generation, and active identity under one read lock. The commit phase uses | |
| 651 | 652 | // the captured generation and active identity to reject interleavings that | |
| 652 | 653 | // changed the ledger while dialing. | |
| 653 | - | func (l *routeLedger) navigationSelection(action ports.RouteNavigationAction) (routeNavigationSelection, bool) { | |
| 654 | + | func (l *routeLedger) navigationSelection(action protocol.RouteNavigationAction) (routeNavigationSelection, bool) { | |
| 654 | 655 | if action.SnapshotGeneration == 0 || action.Key == 0 || action.Generation == 0 { | |
| 655 | 656 | return routeNavigationSelection{}, false | |
| 656 | 657 | } | |
| 657 | - | identity := identityFromWire(ports.RouteRef{Key: action.Key, Generation: action.Generation}) | |
| 658 | + | identity := identityFromWire(protocol.RouteRef{Key: action.Key, Generation: action.Generation}) | |
| 658 | 659 | l.mu.RLock() | |
| 659 | 660 | defer l.mu.RUnlock() | |
| 660 | 661 | if uint64(l.generation) != action.SnapshotGeneration { | |
| @@ -680,7 +681,7 @@ func (l *routeLedger) navigationSelection(action ports.RouteNavigationAction) (r | |||
| 680 | 681 | ||
| 681 | 682 | // navigationRecord validates that an action belongs to the latest complete | |
| 682 | 683 | // snapshot. The active route is metadata-only and selecting it is a no-op. | |
| 683 | - | func (l *routeLedger) navigationRecord(action ports.RouteNavigationAction) (routeRecord, bool, bool) { | |
| 684 | + | func (l *routeLedger) navigationRecord(action protocol.RouteNavigationAction) (routeRecord, bool, bool) { | |
| 684 | 685 | selection, ok := l.navigationSelection(action) | |
| 685 | 686 | return selection.selected, ok, selection.noOp | |
| 686 | 687 | } | |
| @@ -688,7 +689,7 @@ func (l *routeLedger) navigationRecord(action ports.RouteNavigationAction) (rout | |||
| 688 | 689 | // navigate resolves a captured key/generation, attempts resume before exact | |
| 689 | 690 | // attach, and commits only after the connector returns a matching identity. | |
| 690 | 691 | // A failed transition restores the prior live route and leaves history alone. | |
| 691 | - | func (l *routeLedger) navigate(ctx context.Context, action ports.RouteNavigationAction, connector routeTransitionConnector) error { | |
| 692 | + | func (l *routeLedger) navigate(ctx context.Context, action protocol.RouteNavigationAction, connector routeTransitionConnector) error { | |
| 692 | 693 | selection, ok := l.navigationSelection(action) | |
| 693 | 694 | if !ok { | |
| 694 | 695 | return errRouteStaleSelection | |
| @@ -704,7 +705,7 @@ func (l *routeLedger) navigate(ctx context.Context, action ports.RouteNavigation | |||
| 704 | 705 | if ctx == nil { | |
| 705 | 706 | return errors.New("route transition context is nil") | |
| 706 | 707 | } | |
| 707 | - | selected := ports.RouteRef{Key: action.Key, Generation: action.Generation} | |
| 708 | + | selected := protocol.RouteRef{Key: action.Key, Generation: action.Generation} | |
| 708 | 709 | plan := routeTransitionPlan{ | |
| 709 | 710 | identity: identityFromWire(selected), | |
| 710 | 711 | record: record, | |
M internal/usecase/client/routes_test.go +66 -65
| @@ -8,22 +8,23 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | "github.com/stretchr/testify/require" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | - | func routeTestTarget(index byte) ports.ExactSessionTarget { | |
| 15 | - | return ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{index + 1}, SessionName: "session-" + string(rune('a'+index%26)) + string(rune('0'+index/26))} | |
| 15 | + | func routeTestTarget(index byte) protocol.ExactSessionTarget { | |
| 16 | + | return protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{index + 1}, SessionName: "session-" + string(rune('a'+index%26)) + string(rune('0'+index/26))} | |
| 16 | 17 | } | |
| 17 | 18 | ||
| 18 | - | func routeTestCandidate(index byte, origin ports.RouteOrigin) routeCandidate { | |
| 19 | + | func routeTestCandidate(index byte, origin protocol.RouteOrigin) routeCandidate { | |
| 19 | 20 | target := routeTestTarget(index) | |
| 20 | 21 | return routeCandidate{ | |
| 21 | 22 | origin: origin, | |
| 22 | 23 | target: target, | |
| 23 | 24 | presentation: routePresentation{ | |
| 24 | 25 | name: target.SessionName, | |
| 25 | - | kind: ports.RouteKindLocal, | |
| 26 | - | reachability: ports.RouteReachabilityReachable, | |
| 26 | + | kind: protocol.RouteKindLocal, | |
| 27 | + | reachability: protocol.RouteReachabilityReachable, | |
| 27 | 28 | }, | |
| 28 | 29 | request: AttachRequest{ | |
| 29 | 30 | Intent: ports.IntentAttach, | |
| @@ -37,8 +38,8 @@ func TestRouteCandidateRetainsHostLabelWithoutDiscoveryTarget(t *testing.T) { | |||
| 37 | 38 | target := routeTestTarget(1) | |
| 38 | 39 | candidate := routeCandidateForAttach(AttachRequest{ | |
| 39 | 40 | Intent: ports.IntentAttach, SessionName: target.SessionName, Remote: true, | |
| 40 | - | Origin: ports.RouteOriginRemote, OriginKey: "user@remote", HostLabel: "remote", | |
| 41 | - | }, ports.CommittedRouteIdentity{Target: target}, nil, 0) | |
| 41 | + | Origin: protocol.RouteOriginRemote, OriginKey: "user@remote", HostLabel: "remote", | |
| 42 | + | }, protocol.CommittedRouteIdentity{Target: target}, nil, 0) | |
| 42 | 43 | ||
| 43 | 44 | require.Nil(t, candidate.request.RemoteTarget) | |
| 44 | 45 | require.Equal(t, "remote", candidate.request.HostLabel) | |
| @@ -49,7 +50,7 @@ func TestRouteLedgerBoundsAndImmutableSnapshot(t *testing.T) { | |||
| 49 | 50 | ledger := newRouteLedger() | |
| 50 | 51 | var keys []routeKey | |
| 51 | 52 | for i := byte(0); i < maxRouteLedgerEntries+8; i++ { | |
| 52 | - | candidate := routeTestCandidate(i, ports.RouteOriginLocal) | |
| 53 | + | candidate := routeTestCandidate(i, protocol.RouteOriginLocal) | |
| 53 | 54 | candidate.home = i == 0 | |
| 54 | 55 | identity, err := ledger.commit(candidate) | |
| 55 | 56 | require.NoError(t, err) | |
| @@ -61,11 +62,11 @@ func TestRouteLedgerBoundsAndImmutableSnapshot(t *testing.T) { | |||
| 61 | 62 | require.Len(t, snapshot.Entries, maxRouteLedgerEntries-1) | |
| 62 | 63 | require.Equal(t, uint64(keys[len(keys)-1]), snapshot.Active.Key) | |
| 63 | 64 | require.Equal(t, routeTestTarget(maxRouteLedgerEntries+7), snapshot.ActiveEntry.Target) | |
| 64 | - | require.Equal(t, snapshot.Active, ports.RouteRef{Key: snapshot.ActiveEntry.Key, Generation: snapshot.ActiveEntry.Generation}) | |
| 65 | + | require.Equal(t, snapshot.Active, protocol.RouteRef{Key: snapshot.ActiveEntry.Key, Generation: snapshot.ActiveEntry.Generation}) | |
| 65 | 66 | for _, entry := range snapshot.Entries { | |
| 66 | 67 | require.NoError(t, entry.Target.Validate()) | |
| 67 | 68 | require.Equal(t, entry.Name, entry.Target.SessionName) | |
| 68 | - | require.NotEqual(t, snapshot.Active, ports.RouteRef{Key: entry.Key, Generation: entry.Generation}) | |
| 69 | + | require.NotEqual(t, snapshot.Active, protocol.RouteRef{Key: entry.Key, Generation: entry.Generation}) | |
| 69 | 70 | } | |
| 70 | 71 | require.Equal(t, uint64(keys[len(keys)-2]), snapshot.Previous.Key) | |
| 71 | 72 | require.Equal(t, uint64(keys[0]), snapshot.Home.Key, "home is retained when older entries are evicted") | |
| @@ -79,7 +80,7 @@ func TestRouteLedgerBoundsAndImmutableSnapshot(t *testing.T) { | |||
| 79 | 80 | require.Equal(t, originalName, fresh.Entries[0].Name) | |
| 80 | 81 | ||
| 81 | 82 | old := ledger.activeRef() | |
| 82 | - | _, err := ledger.commit(routeTestCandidate(maxRouteLedgerEntries+9, ports.RouteOriginLocal)) | |
| 83 | + | _, err := ledger.commit(routeTestCandidate(maxRouteLedgerEntries+9, protocol.RouteOriginLocal)) | |
| 83 | 84 | require.NoError(t, err) | |
| 84 | 85 | require.NotEqual(t, old, ledger.activeRef()) | |
| 85 | 86 | require.Equal(t, old, ledger.previousRef(), "the old active route becomes the previous route") | |
| @@ -87,21 +88,21 @@ func TestRouteLedgerBoundsAndImmutableSnapshot(t *testing.T) { | |||
| 87 | 88 | ||
| 88 | 89 | func TestRouteLedgerRemembersTabsIndependentlyPerExactRoute(t *testing.T) { | |
| 89 | 90 | ledger := newRouteLedger() | |
| 90 | - | first := routeTestCandidate(1, ports.RouteOriginLocal) | |
| 91 | + | first := routeTestCandidate(1, protocol.RouteOriginLocal) | |
| 91 | 92 | firstIdentity, err := ledger.commit(first) | |
| 92 | 93 | require.NoError(t, err) | |
| 93 | 94 | firstRef := ledger.activeRef() | |
| 94 | 95 | firstSnapshotGeneration := ledger.snapshot().Generation | |
| 95 | - | require.NoError(t, ledger.updateRoutePosition(ports.RoutePosition{Target: first.target, ActiveTabID: "tab-first"})) | |
| 96 | + | require.NoError(t, ledger.updateRoutePosition(protocol.RoutePosition{Target: first.target, ActiveTabID: "tab-first"})) | |
| 96 | 97 | require.Equal(t, firstRef, ledger.activeRef(), "tab memory must not rotate route identity") | |
| 97 | 98 | require.Equal(t, firstSnapshotGeneration, ledger.snapshot().Generation, "tab memory must not stale navigation snapshots") | |
| 98 | 99 | ||
| 99 | - | second := routeTestCandidate(2, ports.RouteOriginRemote) | |
| 100 | + | second := routeTestCandidate(2, protocol.RouteOriginRemote) | |
| 100 | 101 | secondIdentity, err := ledger.commit(second) | |
| 101 | 102 | require.NoError(t, err) | |
| 102 | 103 | secondRef := ledger.activeRef() | |
| 103 | 104 | secondSnapshotGeneration := ledger.snapshot().Generation | |
| 104 | - | require.NoError(t, ledger.updateRoutePosition(ports.RoutePosition{Target: second.target, ActiveTabID: "tab-second"})) | |
| 105 | + | require.NoError(t, ledger.updateRoutePosition(protocol.RoutePosition{Target: second.target, ActiveTabID: "tab-second"})) | |
| 105 | 106 | require.Equal(t, secondRef, ledger.activeRef(), "tab memory must not rotate route identity") | |
| 106 | 107 | require.Equal(t, secondSnapshotGeneration, ledger.snapshot().Generation, "tab memory must not stale navigation snapshots") | |
| 107 | 108 | ||
| @@ -115,13 +116,13 @@ func TestRouteLedgerRemembersTabsIndependentlyPerExactRoute(t *testing.T) { | |||
| 115 | 116 | ||
| 116 | 117 | func TestRouteLedgerSamePeerHandoffRestoresRouteTab(t *testing.T) { | |
| 117 | 118 | ledger := newRouteLedger() | |
| 118 | - | first := routeTestCandidate(1, ports.RouteOriginLocal) | |
| 119 | + | first := routeTestCandidate(1, protocol.RouteOriginLocal) | |
| 119 | 120 | first.originKey = "local" | |
| 120 | 121 | _, err := ledger.commit(first) | |
| 121 | 122 | require.NoError(t, err) | |
| 122 | - | require.NoError(t, ledger.updateRoutePosition(ports.RoutePosition{Target: first.target, ActiveTabID: "tab-first"})) | |
| 123 | + | require.NoError(t, ledger.updateRoutePosition(protocol.RoutePosition{Target: first.target, ActiveTabID: "tab-first"})) | |
| 123 | 124 | ||
| 124 | - | second := routeTestCandidate(2, ports.RouteOriginLocal) | |
| 125 | + | second := routeTestCandidate(2, protocol.RouteOriginLocal) | |
| 125 | 126 | second.originKey = "local" | |
| 126 | 127 | _, err = ledger.commit(second) | |
| 127 | 128 | require.NoError(t, err) | |
| @@ -130,8 +131,8 @@ func TestRouteLedgerSamePeerHandoffRestoresRouteTab(t *testing.T) { | |||
| 130 | 131 | recreated.LifecycleID[0]++ | |
| 131 | 132 | for _, tt := range []struct { | |
| 132 | 133 | name string | |
| 133 | - | target ports.ExactSessionTarget | |
| 134 | - | wantExactTarget *ports.ExactSessionTarget | |
| 134 | + | target protocol.ExactSessionTarget | |
| 135 | + | wantExactTarget *protocol.ExactSessionTarget | |
| 135 | 136 | wantTab domain.TabStableID | |
| 136 | 137 | }{ | |
| 137 | 138 | {name: "matching lifecycle restores remembered tab", target: first.target, wantExactTarget: &first.target, wantTab: "tab-first"}, | |
| @@ -153,11 +154,11 @@ func TestRouteLedgerSamePeerHandoffRestoresRouteTab(t *testing.T) { | |||
| 153 | 154 | } | |
| 154 | 155 | ||
| 155 | 156 | func TestRouteLedgerSamePeerHandoffClearsDaemonOwnedNavigationForLocalRoutes(t *testing.T) { | |
| 156 | - | active := routeTestCandidate(2, ports.RouteOriginLocal) | |
| 157 | + | active := routeTestCandidate(2, protocol.RouteOriginLocal) | |
| 157 | 158 | active.originKey = "local" | |
| 158 | 159 | active.request.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |
| 159 | - | active.request.NavigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 160 | - | active.request.StartupOverlay = ports.StartupOverlaySessionPicker | |
| 160 | + | active.request.NavigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 161 | + | active.request.StartupOverlay = protocol.StartupOverlaySessionPicker | |
| 161 | 162 | ||
| 162 | 163 | for _, tt := range []struct { | |
| 163 | 164 | name string | |
| @@ -170,11 +171,11 @@ func TestRouteLedgerSamePeerHandoffClearsDaemonOwnedNavigationForLocalRoutes(t * | |||
| 170 | 171 | ledger := newRouteLedger() | |
| 171 | 172 | target := routeTestTarget(1) | |
| 172 | 173 | if tt.matched { | |
| 173 | - | stored := routeTestCandidate(1, ports.RouteOriginLocal) | |
| 174 | + | stored := routeTestCandidate(1, protocol.RouteOriginLocal) | |
| 174 | 175 | stored.originKey = "local" | |
| 175 | 176 | stored.request.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |
| 176 | - | stored.request.NavigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 177 | - | stored.request.StartupOverlay = ports.StartupOverlaySessionPicker | |
| 177 | + | stored.request.NavigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 178 | + | stored.request.StartupOverlay = protocol.StartupOverlaySessionPicker | |
| 178 | 179 | _, err := ledger.commit(stored) | |
| 179 | 180 | require.NoError(t, err) | |
| 180 | 181 | } | |
| @@ -186,7 +187,7 @@ func TestRouteLedgerSamePeerHandoffClearsDaemonOwnedNavigationForLocalRoutes(t * | |||
| 186 | 187 | ||
| 187 | 188 | require.Equal(t, ports.EnvironmentPolicyClientOwned, request.EnvironmentPolicy) | |
| 188 | 189 | require.Zero(t, request.NavigationCapabilities) | |
| 189 | - | require.Equal(t, ports.StartupOverlayNone, request.StartupOverlay) | |
| 190 | + | require.Equal(t, protocol.StartupOverlayNone, request.StartupOverlay) | |
| 190 | 191 | require.NoError(t, validateAttachRequest(request)) | |
| 191 | 192 | }) | |
| 192 | 193 | } | |
| @@ -194,7 +195,7 @@ func TestRouteLedgerSamePeerHandoffClearsDaemonOwnedNavigationForLocalRoutes(t * | |||
| 194 | 195 | ||
| 195 | 196 | func TestRouteLedgerSamePeerHandoffDropsOriginalRemoteTarget(t *testing.T) { | |
| 196 | 197 | ledger := newRouteLedger() | |
| 197 | - | work := routeTestCandidate(1, ports.RouteOriginRemote) | |
| 198 | + | work := routeTestCandidate(1, protocol.RouteOriginRemote) | |
| 198 | 199 | work.originKey = "remote" | |
| 199 | 200 | work.request.Remote = true | |
| 200 | 201 | work.request.OriginKey = "remote" | |
| @@ -206,7 +207,7 @@ func TestRouteLedgerSamePeerHandoffDropsOriginalRemoteTarget(t *testing.T) { | |||
| 206 | 207 | _, err := ledger.commit(work) | |
| 207 | 208 | require.NoError(t, err) | |
| 208 | 209 | ||
| 209 | - | agents := routeTestCandidate(2, ports.RouteOriginRemote) | |
| 210 | + | agents := routeTestCandidate(2, protocol.RouteOriginRemote) | |
| 210 | 211 | agents.originKey = "remote" | |
| 211 | 212 | agents.request.Remote = true | |
| 212 | 213 | agents.request.OriginKey = "remote" | |
| @@ -220,32 +221,32 @@ func TestRouteLedgerSamePeerHandoffDropsOriginalRemoteTarget(t *testing.T) { | |||
| 220 | 221 | }) | |
| 221 | 222 | ||
| 222 | 223 | require.True(t, request.Remote) | |
| 223 | - | require.Equal(t, ports.RouteOriginRemote, request.Origin) | |
| 224 | + | require.Equal(t, protocol.RouteOriginRemote, request.Origin) | |
| 224 | 225 | require.Equal(t, "remote", request.OriginKey) | |
| 225 | 226 | require.Nil(t, request.RemoteTarget) | |
| 226 | 227 | } | |
| 227 | 228 | ||
| 228 | 229 | func TestRouteAttentionSubscriptionIncludesOnlyActiveOriginRoutes(t *testing.T) { | |
| 229 | 230 | ledger := newRouteLedger() | |
| 230 | - | first := routeTestCandidate(0, ports.RouteOriginRemote) | |
| 231 | + | first := routeTestCandidate(0, protocol.RouteOriginRemote) | |
| 231 | 232 | first.originKey = "host-a" | |
| 232 | 233 | firstIdentity, err := ledger.commit(first) | |
| 233 | 234 | require.NoError(t, err) | |
| 234 | - | other := routeTestCandidate(1, ports.RouteOriginLocal) | |
| 235 | + | other := routeTestCandidate(1, protocol.RouteOriginLocal) | |
| 235 | 236 | _, err = ledger.commit(other) | |
| 236 | 237 | require.NoError(t, err) | |
| 237 | - | otherRemote := routeTestCandidate(2, ports.RouteOriginRemote) | |
| 238 | + | otherRemote := routeTestCandidate(2, protocol.RouteOriginRemote) | |
| 238 | 239 | otherRemote.originKey = "host-b" | |
| 239 | 240 | _, err = ledger.commit(otherRemote) | |
| 240 | 241 | require.NoError(t, err) | |
| 241 | - | active := routeTestCandidate(3, ports.RouteOriginRemote) | |
| 242 | + | active := routeTestCandidate(3, protocol.RouteOriginRemote) | |
| 242 | 243 | active.originKey = "host-a" | |
| 243 | 244 | _, err = ledger.commit(active) | |
| 244 | 245 | require.NoError(t, err) | |
| 245 | 246 | ||
| 246 | 247 | subscription := ledger.attentionSubscription() | |
| 247 | 248 | ||
| 248 | - | require.Equal(t, []ports.RouteAttentionTarget{{ | |
| 249 | + | require.Equal(t, []protocol.RouteAttentionTarget{{ | |
| 249 | 250 | Ref: firstIdentity.wire(), | |
| 250 | 251 | Target: first.target, | |
| 251 | 252 | }}, subscription.Targets) | |
| @@ -253,16 +254,16 @@ func TestRouteAttentionSubscriptionIncludesOnlyActiveOriginRoutes(t *testing.T) | |||
| 253 | 254 | ||
| 254 | 255 | func TestCommittedIdentityRenamesActiveRouteInPlace(t *testing.T) { | |
| 255 | 256 | ledger := newRouteLedger() | |
| 256 | - | original := routeTestCandidate(0, ports.RouteOriginLocal) | |
| 257 | - | original.target = ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "0"} | |
| 257 | + | original := routeTestCandidate(0, protocol.RouteOriginLocal) | |
| 258 | + | original.target = protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "0"} | |
| 258 | 259 | original.presentation.name = "0" | |
| 259 | 260 | original.request.SessionName = "0" | |
| 260 | 261 | identity, err := ledger.commit(original) | |
| 261 | 262 | require.NoError(t, err) | |
| 262 | 263 | before := ledger.snapshot() | |
| 263 | 264 | ||
| 264 | - | committed, err := ledger.commitCommittedIdentity(ports.CommittedRouteIdentity{ | |
| 265 | - | Target: ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "vps-infra"}, | |
| 265 | + | committed, err := ledger.commitCommittedIdentity(protocol.CommittedRouteIdentity{ | |
| 266 | + | Target: protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "vps-infra"}, | |
| 266 | 267 | Ephemeral: false, | |
| 267 | 268 | }) | |
| 268 | 269 | require.NoError(t, err) | |
| @@ -280,11 +281,11 @@ func TestCommittedIdentityRenamesActiveRouteInPlace(t *testing.T) { | |||
| 280 | 281 | ||
| 281 | 282 | func TestCommittedIdentityDoesNotReassignHomeRoute(t *testing.T) { | |
| 282 | 283 | ledger := newRouteLedger() | |
| 283 | - | home := routeTestCandidate(1, ports.RouteOriginLocal) | |
| 284 | + | home := routeTestCandidate(1, protocol.RouteOriginLocal) | |
| 284 | 285 | home.home = true | |
| 285 | 286 | homeIdentity, err := ledger.commit(home) | |
| 286 | 287 | require.NoError(t, err) | |
| 287 | - | committed, err := ledger.commitCommittedIdentity(ports.CommittedRouteIdentity{ | |
| 288 | + | committed, err := ledger.commitCommittedIdentity(protocol.CommittedRouteIdentity{ | |
| 288 | 289 | Target: routeTestTarget(2), | |
| 289 | 290 | Ephemeral: true, | |
| 290 | 291 | }) | |
| @@ -295,7 +296,7 @@ func TestCommittedIdentityDoesNotReassignHomeRoute(t *testing.T) { | |||
| 295 | 296 | require.True(t, ok) | |
| 296 | 297 | require.Equal(t, committed, active.identity) | |
| 297 | 298 | ||
| 298 | - | _, err = ledger.commit(routeTestCandidate(1, ports.RouteOriginLocal)) | |
| 299 | + | _, err = ledger.commit(routeTestCandidate(1, protocol.RouteOriginLocal)) | |
| 299 | 300 | require.NoError(t, err) | |
| 300 | 301 | require.True(t, mustRouteRecord(t, ledger, ledger.activeRef()).home, "upserting the home route must retain its marker") | |
| 301 | 302 | } | |
| @@ -309,7 +310,7 @@ func TestRouteLedgerConcurrentInitialAttachmentsKeepOneHome(t *testing.T) { | |||
| 309 | 310 | wg.Add(1) | |
| 310 | 311 | go func() { | |
| 311 | 312 | defer wg.Done() | |
| 312 | - | _, err := ledger.commitAttach(routeTestCandidate(i, ports.RouteOriginLocal)) | |
| 313 | + | _, err := ledger.commitAttach(routeTestCandidate(i, protocol.RouteOriginLocal)) | |
| 313 | 314 | errs <- err | |
| 314 | 315 | }() | |
| 315 | 316 | } | |
| @@ -333,22 +334,22 @@ func TestRouteLedgerConcurrentInitialAttachmentsKeepOneHome(t *testing.T) { | |||
| 333 | 334 | ||
| 334 | 335 | func TestRouteLedgerTransitionRejectsConcurrentCommit(t *testing.T) { | |
| 335 | 336 | ledger := newRouteLedger() | |
| 336 | - | selected, err := ledger.commit(routeTestCandidate(1, ports.RouteOriginLocal)) | |
| 337 | + | selected, err := ledger.commit(routeTestCandidate(1, protocol.RouteOriginLocal)) | |
| 337 | 338 | require.NoError(t, err) | |
| 338 | - | _, err = ledger.commit(routeTestCandidate(2, ports.RouteOriginLocal)) | |
| 339 | + | _, err = ledger.commit(routeTestCandidate(2, protocol.RouteOriginLocal)) | |
| 339 | 340 | require.NoError(t, err) | |
| 340 | 341 | selection, ok := ledger.navigationSelection(selected.wireNavigationAction(routeGeneration(ledger.snapshot().Generation))) | |
| 341 | 342 | require.True(t, ok) | |
| 342 | 343 | ||
| 343 | - | _, err = ledger.commit(routeTestCandidate(3, ports.RouteOriginLocal)) | |
| 344 | + | _, err = ledger.commit(routeTestCandidate(3, protocol.RouteOriginLocal)) | |
| 344 | 345 | require.NoError(t, err) | |
| 345 | - | candidate := routeTestCandidate(4, ports.RouteOriginLocal) | |
| 346 | + | candidate := routeTestCandidate(4, protocol.RouteOriginLocal) | |
| 346 | 347 | err = ledger.commitTransition(selected, selection.snapshotGeneration, selection.active, candidate) | |
| 347 | 348 | require.ErrorIs(t, err, errRouteStaleSelection) | |
| 348 | 349 | require.Equal(t, routeTestTarget(3), mustRouteRecord(t, ledger, ledger.activeRef()).target) | |
| 349 | 350 | } | |
| 350 | 351 | ||
| 351 | - | func mustRouteRecord(t *testing.T, ledger *routeLedger, ref ports.RouteRef) routeRecord { | |
| 352 | + | func mustRouteRecord(t *testing.T, ledger *routeLedger, ref protocol.RouteRef) routeRecord { | |
| 352 | 353 | t.Helper() | |
| 353 | 354 | record, ok := ledger.lookup(ref) | |
| 354 | 355 | require.True(t, ok) | |
| @@ -357,7 +358,7 @@ func mustRouteRecord(t *testing.T, ledger *routeLedger, ref ports.RouteRef) rout | |||
| 357 | 358 | ||
| 358 | 359 | func TestRouteLedgerUpsertChangesGenerationWithoutChangingOpaqueKey(t *testing.T) { | |
| 359 | 360 | ledger := newRouteLedger() | |
| 360 | - | candidate := routeTestCandidate(1, ports.RouteOriginRemote) | |
| 361 | + | candidate := routeTestCandidate(1, protocol.RouteOriginRemote) | |
| 361 | 362 | first, err := ledger.commit(candidate) | |
| 362 | 363 | require.NoError(t, err) | |
| 363 | 364 | ||
| @@ -387,7 +388,7 @@ type routeTestConnector struct { | |||
| 387 | 388 | attachCalls int | |
| 388 | 389 | restoreCalls int | |
| 389 | 390 | restoreErr error | |
| 390 | - | restoreTarget ports.ExactSessionTarget | |
| 391 | + | restoreTarget protocol.ExactSessionTarget | |
| 391 | 392 | } | |
| 392 | 393 | ||
| 393 | 394 | func (c *routeTestConnector) Resume(context.Context, routeRecord) (routeTransitionCommit, error) { | |
| @@ -410,11 +411,11 @@ func (c *routeTestConnector) Attach(_ context.Context, record routeRecord) (rout | |||
| 410 | 411 | return routeTransitionCommit{}, c.attachErr | |
| 411 | 412 | } | |
| 412 | 413 | return routeTransitionCommit{ | |
| 413 | - | identity: ports.CommittedRouteIdentity{Target: record.target}, | |
| 414 | + | identity: protocol.CommittedRouteIdentity{Target: record.target}, | |
| 414 | 415 | presentation: routePresentation{ | |
| 415 | 416 | name: record.presentation.name, | |
| 416 | 417 | kind: record.presentation.kind, | |
| 417 | - | reachability: ports.RouteReachabilityReachable, | |
| 418 | + | reachability: protocol.RouteReachabilityReachable, | |
| 418 | 419 | }, | |
| 419 | 420 | resumeToken: 123, | |
| 420 | 421 | }, nil | |
| @@ -422,12 +423,12 @@ func (c *routeTestConnector) Attach(_ context.Context, record routeRecord) (rout | |||
| 422 | 423 | ||
| 423 | 424 | func TestRouteLedgerNavigateResumesThenFallsBackAndRestoresOrigin(t *testing.T) { | |
| 424 | 425 | ledger := newRouteLedger() | |
| 425 | - | candidate := routeTestCandidate(2, ports.RouteOriginDiscovery) | |
| 426 | + | candidate := routeTestCandidate(2, protocol.RouteOriginDiscovery) | |
| 426 | 427 | candidate.originKey = "daemon-discovered" | |
| 427 | 428 | candidate.resumeToken = 77 | |
| 428 | 429 | identity, err := ledger.commit(candidate) | |
| 429 | 430 | require.NoError(t, err) | |
| 430 | - | _, err = ledger.commit(routeTestCandidate(4, ports.RouteOriginLocal)) | |
| 431 | + | _, err = ledger.commit(routeTestCandidate(4, protocol.RouteOriginLocal)) | |
| 431 | 432 | require.NoError(t, err) | |
| 432 | 433 | ||
| 433 | 434 | connector := &routeTestConnector{resumeErr: errRouteResumeUnavailable} | |
| @@ -440,18 +441,18 @@ func TestRouteLedgerNavigateResumesThenFallsBackAndRestoresOrigin(t *testing.T) | |||
| 440 | 441 | ||
| 441 | 442 | active, ok := ledger.lookup(ledger.activeRef()) | |
| 442 | 443 | require.True(t, ok) | |
| 443 | - | require.Equal(t, ports.RouteOriginDiscovery, active.origin) | |
| 444 | + | require.Equal(t, protocol.RouteOriginDiscovery, active.origin) | |
| 444 | 445 | require.Equal(t, "daemon-discovered", active.originKey) | |
| 445 | - | require.Equal(t, ports.RouteOriginDiscovery, active.request.Origin) | |
| 446 | + | require.Equal(t, protocol.RouteOriginDiscovery, active.request.Origin) | |
| 446 | 447 | require.Equal(t, candidate.target, active.target) | |
| 447 | 448 | require.Greater(t, active.identity.generation, identity.generation) | |
| 448 | 449 | } | |
| 449 | 450 | ||
| 450 | 451 | func TestRouteLedgerNavigateIsTransactionalOnFailureOrTargetChange(t *testing.T) { | |
| 451 | 452 | ledger := newRouteLedger() | |
| 452 | - | identity, err := ledger.commit(routeTestCandidate(3, ports.RouteOriginLocal)) | |
| 453 | + | identity, err := ledger.commit(routeTestCandidate(3, protocol.RouteOriginLocal)) | |
| 453 | 454 | require.NoError(t, err) | |
| 454 | - | _, err = ledger.commit(routeTestCandidate(5, ports.RouteOriginLocal)) | |
| 455 | + | _, err = ledger.commit(routeTestCandidate(5, protocol.RouteOriginLocal)) | |
| 455 | 456 | require.NoError(t, err) | |
| 456 | 457 | before := ledger.snapshot() | |
| 457 | 458 | action := identity.wireNavigationAction(routeGeneration(before.Generation)) | |
| @@ -475,7 +476,7 @@ func TestRouteLedgerNavigateIsTransactionalOnFailureOrTargetChange(t *testing.T) | |||
| 475 | 476 | ||
| 476 | 477 | func TestRouteLedgerNavigationRejectsStaleActionsAndActiveNoOp(t *testing.T) { | |
| 477 | 478 | ledger := newRouteLedger() | |
| 478 | - | active, err := ledger.commit(routeTestCandidate(6, ports.RouteOriginLocal)) | |
| 479 | + | active, err := ledger.commit(routeTestCandidate(6, protocol.RouteOriginLocal)) | |
| 479 | 480 | require.NoError(t, err) | |
| 480 | 481 | firstSnapshot := ledger.snapshot() | |
| 481 | 482 | before := ledger.snapshot() | |
| @@ -483,7 +484,7 @@ func TestRouteLedgerNavigationRejectsStaleActionsAndActiveNoOp(t *testing.T) { | |||
| 483 | 484 | require.NoError(t, ledger.navigate(context.Background(), active.wireNavigationAction(routeGeneration(firstSnapshot.Generation)), nil)) | |
| 484 | 485 | require.Equal(t, before, ledger.snapshot()) | |
| 485 | 486 | ||
| 486 | - | _, err = ledger.commit(routeTestCandidate(7, ports.RouteOriginLocal)) | |
| 487 | + | _, err = ledger.commit(routeTestCandidate(7, protocol.RouteOriginLocal)) | |
| 487 | 488 | require.NoError(t, err) | |
| 488 | 489 | stale := active.wireNavigationAction(routeGeneration(firstSnapshot.Generation)) | |
| 489 | 490 | connector := &routeTestConnector{} | |
| @@ -496,13 +497,13 @@ type mismatchingRouteConnector struct{ *routeTestConnector } | |||
| 496 | 497 | ||
| 497 | 498 | func (c mismatchingRouteConnector) Attach(_ context.Context, record routeRecord) (routeTransitionCommit, error) { | |
| 498 | 499 | return routeTransitionCommit{ | |
| 499 | - | identity: ports.CommittedRouteIdentity{Target: routeTestTarget(99)}, | |
| 500 | + | identity: protocol.CommittedRouteIdentity{Target: routeTestTarget(99)}, | |
| 500 | 501 | presentation: routePresentation{name: record.presentation.name, kind: record.presentation.kind}, | |
| 501 | 502 | }, nil | |
| 502 | 503 | } | |
| 503 | 504 | ||
| 504 | - | func (i routeIdentity) wireNavigationAction(snapshotGeneration routeGeneration) ports.RouteNavigationAction { | |
| 505 | - | return ports.RouteNavigationAction{SnapshotGeneration: uint64(snapshotGeneration), Key: uint64(i.key), Generation: uint64(i.generation)} | |
| 505 | + | func (i routeIdentity) wireNavigationAction(snapshotGeneration routeGeneration) protocol.RouteNavigationAction { | |
| 506 | + | return protocol.RouteNavigationAction{SnapshotGeneration: uint64(snapshotGeneration), Key: uint64(i.key), Generation: uint64(i.generation)} | |
| 506 | 507 | } | |
| 507 | 508 | ||
| 508 | 509 | func TestRouteLedgerConcurrentSnapshotsAndCommits(t *testing.T) { | |
| @@ -513,7 +514,7 @@ func TestRouteLedgerConcurrentSnapshotsAndCommits(t *testing.T) { | |||
| 513 | 514 | go func() { | |
| 514 | 515 | defer wg.Done() | |
| 515 | 516 | for i := byte(0); i < 20; i++ { | |
| 516 | - | _, _ = ledger.commit(routeTestCandidate(worker*20+i, ports.RouteOriginLocal)) | |
| 517 | + | _, _ = ledger.commit(routeTestCandidate(worker*20+i, protocol.RouteOriginLocal)) | |
| 517 | 518 | _ = ledger.snapshot() | |
| 518 | 519 | } | |
| 519 | 520 | }() | |
| @@ -524,7 +525,7 @@ func TestRouteLedgerConcurrentSnapshotsAndCommits(t *testing.T) { | |||
| 524 | 525 | ||
| 525 | 526 | func TestRouteLedgerSeparatesRemoteDaemonOrigins(t *testing.T) { | |
| 526 | 527 | ledger := newRouteLedger() | |
| 527 | - | firstCandidate := routeTestCandidate(40, ports.RouteOriginRemote) | |
| 528 | + | firstCandidate := routeTestCandidate(40, protocol.RouteOriginRemote) | |
| 528 | 529 | firstCandidate.originKey = "daemon-a" | |
| 529 | 530 | secondCandidate := firstCandidate | |
| 530 | 531 | secondCandidate.originKey = "daemon-b" | |
M internal/usecase/client/same_peer_switch.go +2 -2
| @@ -4,7 +4,7 @@ import ( | |||
| 4 | 4 | "context" | |
| 5 | 5 | "sync" | |
| 6 | 6 | ||
| 7 | - | "github.com/bnema/vev/internal/ports" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 8 | ) | |
| 9 | 9 | ||
| 10 | 10 | // samePeerInputGate holds raw input behind a requested in-band switch. It does | |
| @@ -20,7 +20,7 @@ type samePeerInputGate struct { | |||
| 20 | 20 | ||
| 21 | 21 | type samePeerSwitchPending struct { | |
| 22 | 22 | requestID uint64 | |
| 23 | - | target ports.ExactSessionTarget | |
| 23 | + | target protocol.ExactSessionTarget | |
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | 26 | func newSamePeerInputGate() *samePeerInputGate { | |
M internal/usecase/client/same_peer_switch_test.go +2 -1
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | 15 | func TestCloseAndDialAttachTargetSkipsSamePeerSwitch(t *testing.T) { | |
| @@ -33,7 +34,7 @@ func TestCloseAndDialAttachTargetSkipsSamePeerSwitch(t *testing.T) { | |||
| 33 | 34 | resultCh := make(chan attachResult, 1) | |
| 34 | 35 | go func() { resultCh <- attempt.run(ctx) }() | |
| 35 | 36 | ||
| 36 | - | exact := ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{7}, SessionName: "stopped"} | |
| 37 | + | exact := protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{7}, SessionName: "stopped"} | |
| 37 | 38 | target := ports.AttachTarget{ | |
| 38 | 39 | Session: "stopped", Intent: ports.IntentAttach, ExactTarget: &exact, | |
| 39 | 40 | EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
M internal/usecase/client/transport_observability_test.go +3 -2
| @@ -14,6 +14,7 @@ import ( | |||
| 14 | 14 | "github.com/bnema/vev/internal/domain" | |
| 15 | 15 | "github.com/bnema/vev/internal/ports" | |
| 16 | 16 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 17 | + | "github.com/bnema/vev/internal/protocol" | |
| 17 | 18 | "github.com/bnema/vev/internal/usecase/client" | |
| 18 | 19 | ) | |
| 19 | 20 | ||
| @@ -50,7 +51,7 @@ func TestBlockingRuntimeObserverDoesNotDelayTerminalFlushOrACK(t *testing.T) { | |||
| 50 | 51 | transport.EXPECT().Send(isType(ports.MsgAck)).Run(func(ports.Frame) { close(acked) }).Return(nil).Once() | |
| 51 | 52 | unblock := scriptRecv(transport, | |
| 52 | 53 | recvItem{f: frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{SessionID: "s1"}))}, | |
| 53 | - | recvItem{f: frameOf(ports.MsgOutput, mustMarshalOutput(ports.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("flush-before-observe"), New: 3}))}, | |
| 54 | + | recvItem{f: frameOf(ports.MsgOutput, mustMarshalOutput(protocol.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("flush-before-observe"), New: 3}))}, | |
| 54 | 55 | ) | |
| 55 | 56 | defer unblock() | |
| 56 | 57 | transport.EXPECT().Close().Return(nil).Once() | |
| @@ -90,7 +91,7 @@ func TestTerminalFlushBoundaryTransportObservability(t *testing.T) { | |||
| 90 | 91 | transport.EXPECT().Send(isType(ports.MsgTheme)).Return(nil).Maybe() | |
| 91 | 92 | unblock := scriptRecv(transport, | |
| 92 | 93 | recvItem{f: frameOf(ports.MsgWelcome, ports.MarshalWelcome(ports.Welcome{SessionID: "s1"}))}, | |
| 93 | - | recvItem{f: frameOf(ports.MsgOutput, mustMarshalOutput(ports.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("unchanged-by-observer"), New: 3}))}, | |
| 94 | + | recvItem{f: frameOf(ports.MsgOutput, mustMarshalOutput(protocol.Output{Epoch: 1, Size: domain.Size{Cols: 1, Rows: 1}, Full: true, Data: []byte("unchanged-by-observer"), New: 3}))}, | |
| 94 | 95 | recvItem{f: frameOf(ports.MsgDetached, ports.MarshalDetached(ports.Detached{Reason: ports.ReasonDetach}))}, | |
| 95 | 96 | ) | |
| 96 | 97 | defer unblock() | |
M internal/usecase/client/wire_external_test_helpers_test.go +5 -2
| @@ -1,8 +1,11 @@ | |||
| 1 | 1 | package client_test | |
| 2 | 2 | ||
| 3 | - | import "github.com/bnema/vev/internal/ports" | |
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | + | ) | |
| 4 | 7 | ||
| 5 | - | func mustMarshalOutput(m ports.Output) []byte { | |
| 8 | + | func mustMarshalOutput(m protocol.Output) []byte { | |
| 6 | 9 | payload, err := ports.MarshalOutput(m) | |
| 7 | 10 | if err != nil { | |
| 8 | 11 | panic(err) | |
M internal/usecase/client/wire_test_helpers_test.go +5 -2
| @@ -1,8 +1,11 @@ | |||
| 1 | 1 | package client | |
| 2 | 2 | ||
| 3 | - | import "github.com/bnema/vev/internal/ports" | |
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | + | ) | |
| 4 | 7 | ||
| 5 | - | func mustMarshalOutput(m ports.Output) []byte { | |
| 8 | + | func mustMarshalOutput(m protocol.Output) []byte { | |
| 6 | 9 | payload, err := ports.MarshalOutput(m) | |
| 7 | 10 | if err != nil { | |
| 8 | 11 | panic(err) | |
M internal/usecase/daemon/attachment_effect_gate_test.go +14 -13
| @@ -12,6 +12,7 @@ import ( | |||
| 12 | 12 | renderer "github.com/bnema/vev-vt" | |
| 13 | 13 | "github.com/bnema/vev/internal/domain" | |
| 14 | 14 | "github.com/bnema/vev/internal/ports" | |
| 15 | + | "github.com/bnema/vev/internal/protocol" | |
| 15 | 16 | "github.com/bnema/vev/internal/usecase/keys" | |
| 16 | 17 | ) | |
| 17 | 18 | ||
| @@ -611,7 +612,7 @@ func TestAttachmentEffectGateAdmittedActiveEffectsFinishBeforeReplacement(t *tes | |||
| 611 | 612 | }, | |
| 612 | 613 | { | |
| 613 | 614 | name: "theme", | |
| 614 | - | frame: ports.Frame{Type: ports.MsgTheme, Payload: ports.MarshalTheme(ports.Theme{ | |
| 615 | + | frame: ports.Frame{Type: ports.MsgTheme, Payload: ports.MarshalTheme(protocol.Theme{ | |
| 615 | 616 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 616 | 617 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 617 | 618 | })}, | |
| @@ -624,7 +625,7 @@ func TestAttachmentEffectGateAdmittedActiveEffectsFinishBeforeReplacement(t *tes | |||
| 624 | 625 | setup: func(_ *Daemon, _ *session, ac *attachedClient, _ *transactionalResizePTY) { | |
| 625 | 626 | ac.output.next = 3 | |
| 626 | 627 | }, | |
| 627 | - | frame: ports.Frame{Type: ports.MsgAck, Payload: mustMarshalAck(ports.Ack{Epoch: 1, State: 1})}, | |
| 628 | + | frame: ports.Frame{Type: ports.MsgAck, Payload: mustMarshalAck(protocol.Ack{Epoch: 1, State: 1})}, | |
| 628 | 629 | assert: func(t *testing.T, ac *attachedClient, _ *transactionalResizePTY) { | |
| 629 | 630 | ac.sendMu.Lock() | |
| 630 | 631 | defer ac.sendMu.Unlock() | |
| @@ -687,14 +688,14 @@ func TestAttachedRouteSnapshotIsAcceptedAsAnAttachmentValue(t *testing.T) { | |||
| 687 | 688 | token.lease = rc.attachmentLease(ac) | |
| 688 | 689 | ac.installTestAttachmentCapability(token) | |
| 689 | 690 | ||
| 690 | - | activeRef := ports.RouteRef{Key: 8, Generation: 4} | |
| 691 | + | activeRef := protocol.RouteRef{Key: 8, Generation: 4} | |
| 691 | 692 | activeTarget := testRouteTarget(source.name, 8) | |
| 692 | - | snapshot := ports.RecentRouteSnapshot{ | |
| 693 | + | snapshot := protocol.RecentRouteSnapshot{ | |
| 693 | 694 | Generation: 4, | |
| 694 | 695 | Active: activeRef, | |
| 695 | - | ActiveEntry: ports.RecentRouteEntry{Key: 8, Generation: 4, Target: activeTarget, Name: source.name, Kind: ports.RouteKindLocal}, | |
| 696 | + | ActiveEntry: protocol.RecentRouteEntry{Key: 8, Generation: 4, Target: activeTarget, Name: source.name, Kind: protocol.RouteKindLocal}, | |
| 696 | 697 | Home: activeRef, | |
| 697 | - | Entries: []ports.RecentRouteEntry{testRouteEntry(7, 3, "previous", 7, ports.RouteKindLocal)}, | |
| 698 | + | Entries: []protocol.RecentRouteEntry{testRouteEntry(7, 3, "previous", 7, protocol.RouteKindLocal)}, | |
| 698 | 699 | } | |
| 699 | 700 | payload, err := ports.MarshalRecentRouteSnapshot(snapshot) | |
| 700 | 701 | require.NoError(t, err) | |
| @@ -711,12 +712,12 @@ func TestAttachedNavigationCommandSendsResultAfterLocalTransition(t *testing.T) | |||
| 711 | 712 | d.mu.Lock() | |
| 712 | 713 | d.sessions[target.id] = target | |
| 713 | 714 | d.mu.Unlock() | |
| 714 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 715 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 715 | 716 | Generation: 2, | |
| 716 | - | Active: ports.RouteRef{Key: 2, Generation: 2}, | |
| 717 | - | ActiveEntry: testRouteEntry(2, 2, source.name, 2, ports.RouteKindLocal), | |
| 718 | - | Previous: ports.RouteRef{Key: 1, Generation: 1}, | |
| 719 | - | Entries: []ports.RecentRouteEntry{testRouteEntry(1, 1, "target", 1, ports.RouteKindLocal)}, | |
| 717 | + | Active: protocol.RouteRef{Key: 2, Generation: 2}, | |
| 718 | + | ActiveEntry: testRouteEntry(2, 2, source.name, 2, protocol.RouteKindLocal), | |
| 719 | + | Previous: protocol.RouteRef{Key: 1, Generation: 1}, | |
| 720 | + | Entries: []protocol.RecentRouteEntry{testRouteEntry(1, 1, "target", 1, protocol.RouteKindLocal)}, | |
| 720 | 721 | }) | |
| 721 | 722 | ||
| 722 | 723 | transport := &closeTrackingTransport{} | |
| @@ -744,7 +745,7 @@ func TestAttachedNavigationCommandSendsResultAfterLocalTransition(t *testing.T) | |||
| 744 | 745 | break | |
| 745 | 746 | } | |
| 746 | 747 | require.True(t, result.OK, result.Text) | |
| 747 | - | var action ports.RouteNavigationAction | |
| 748 | + | var action protocol.RouteNavigationAction | |
| 748 | 749 | for _, frame := range frames { | |
| 749 | 750 | if frame.Type != ports.MsgNavigateRecentRoute { | |
| 750 | 751 | continue | |
| @@ -752,7 +753,7 @@ func TestAttachedNavigationCommandSendsResultAfterLocalTransition(t *testing.T) | |||
| 752 | 753 | action, err = ports.UnmarshalRouteNavigationAction(frame.Payload) | |
| 753 | 754 | require.NoError(t, err) | |
| 754 | 755 | } | |
| 755 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 2, Key: 1, Generation: 1}, action) | |
| 756 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 2, Key: 1, Generation: 1}, action) | |
| 756 | 757 | require.False(t, transport.Closed(), "client navigation must not tear down the attachment") | |
| 757 | 758 | } | |
| 758 | 759 | ||
M internal/usecase/daemon/attachment_output.go +5 -4
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | renderer "github.com/bnema/vev-vt/ansi" | |
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | 15 | // attachmentOutput owns the terminal-output dependency chain and emitted | |
| @@ -32,7 +33,7 @@ type attachmentOutput struct { | |||
| 32 | 33 | forceSnapshot bool | |
| 33 | 34 | initialized bool | |
| 34 | 35 | lastCursor cursorOut | |
| 35 | - | lastRoutePosition ports.RoutePosition | |
| 36 | + | lastRoutePosition protocol.RoutePosition | |
| 36 | 37 | graphicsOutput *graphicsOutputState | |
| 37 | 38 | graphicsUnsupportedWarned atomic.Bool | |
| 38 | 39 | attachment *attachedClient | |
| @@ -139,7 +140,7 @@ func (o *attachmentOutput) prepareFrame(d *Daemon, state *capturedRenderState, f | |||
| 139 | 140 | } | |
| 140 | 141 | cursor := o.prepareCursorTail(desired, len(ansi.data) > 0) | |
| 141 | 142 | graphicsReset := reset || o.forceSnapshot || !o.initialized | |
| 142 | - | graphicsBudget := max(ports.MaxOutputDataLen-len(ansi.data)-len(cursor.data), 0) | |
| 143 | + | graphicsBudget := max(protocol.MaxOutputDataLen-len(ansi.data)-len(cursor.data), 0) | |
| 143 | 144 | preparedGraphics, err := graphicsOutputDataWithDaemonLimit(d, state, o.attachment, graphicsReset, graphicsBudget) | |
| 144 | 145 | if err != nil { | |
| 145 | 146 | return nil, err | |
| @@ -379,7 +380,7 @@ func (p *preparedOutput) currentLocked() bool { | |||
| 379 | 380 | } | |
| 380 | 381 | ||
| 381 | 382 | func marshalOutputState(data []byte, epoch, base, next, echoAck, viewRevision uint64, size domain.Size, full bool) (ports.Frame, error) { | |
| 382 | - | payload, err := ports.MarshalOutput(ports.Output{ | |
| 383 | + | payload, err := ports.MarshalOutput(protocol.Output{ | |
| 383 | 384 | Epoch: epoch, Base: base, New: next, Echo: echoAck, ViewRevision: viewRevision, | |
| 384 | 385 | Size: size, Full: full, Data: data, | |
| 385 | 386 | }) | |
| @@ -440,7 +441,7 @@ func (s *attachmentOutput) rebaseAttachment() { | |||
| 440 | 441 | return | |
| 441 | 442 | } | |
| 442 | 443 | s.rebase() | |
| 443 | - | s.lastRoutePosition = ports.RoutePosition{} | |
| 444 | + | s.lastRoutePosition = protocol.RoutePosition{} | |
| 444 | 445 | } | |
| 445 | 446 | ||
| 446 | 447 | // rebaseLocked is called while the attachment view lock is held. Publishing | |
M internal/usecase/daemon/attachment_output_test.go +3 -2
| @@ -10,6 +10,7 @@ import ( | |||
| 10 | 10 | "github.com/bnema/vev-vt/graphics" | |
| 11 | 11 | "github.com/bnema/vev/internal/domain" | |
| 12 | 12 | "github.com/bnema/vev/internal/ports" | |
| 13 | + | "github.com/bnema/vev/internal/protocol" | |
| 13 | 14 | "github.com/bnema/vev/internal/usecase/layout" | |
| 14 | 15 | "github.com/stretchr/testify/require" | |
| 15 | 16 | ) | |
| @@ -468,7 +469,7 @@ func TestAttachmentOutputRebaseRetiresAttachmentState(t *testing.T) { | |||
| 468 | 469 | output.next = 3 | |
| 469 | 470 | output.acked = 2 | |
| 470 | 471 | output.lastCursor = cursorOut{valid: true, row: 2, col: 3} | |
| 471 | - | output.lastRoutePosition = ports.RoutePosition{ActiveTabID: "tab"} | |
| 472 | + | output.lastRoutePosition = protocol.RoutePosition{ActiveTabID: "tab"} | |
| 472 | 473 | ||
| 473 | 474 | output.rebaseAttachment() | |
| 474 | 475 | ||
| @@ -477,7 +478,7 @@ func TestAttachmentOutputRebaseRetiresAttachmentState(t *testing.T) { | |||
| 477 | 478 | require.Zero(t, output.acked) | |
| 478 | 479 | require.True(t, output.forceSnapshot) | |
| 479 | 480 | require.Equal(t, cursorOut{valid: true, row: 2, col: 3}, output.lastCursor, "the forced frame will reassert cursor state") | |
| 480 | - | require.Equal(t, ports.RoutePosition{}, output.lastRoutePosition) | |
| 481 | + | require.Equal(t, protocol.RoutePosition{}, output.lastRoutePosition) | |
| 481 | 482 | } | |
| 482 | 483 | ||
| 483 | 484 | func TestAttachmentOutputDefaultsAndNormalizesWindow(t *testing.T) { | |
M internal/usecase/daemon/attachment_parking_test.go +2 -1
| @@ -7,6 +7,7 @@ import ( | |||
| 7 | 7 | "github.com/stretchr/testify/require" | |
| 8 | 8 | ||
| 9 | 9 | "github.com/bnema/vev/internal/ports" | |
| 10 | + | "github.com/bnema/vev/internal/protocol" | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| 12 | 13 | type resumeWelcomeFailureTransport struct { | |
| @@ -137,7 +138,7 @@ func TestSuccessfulResumeRejectsOldCredentialAfterWelcome(t *testing.T) { | |||
| 137 | 138 | sess, ac, err := d.route(helloResumeCapable(ports.IntentNew, "work", 0), oldTransport) | |
| 138 | 139 | require.NoError(t, err) | |
| 139 | 140 | oldToken := ac.resumeToken | |
| 140 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 141 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 141 | 142 | d.clientGone(sess, ac, oldTransport, false) | |
| 142 | 143 | ||
| 143 | 144 | resumedTransport := &closeTrackingTransport{} | |
M internal/usecase/daemon/attachment_render_test.go +2 -1
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | "github.com/stretchr/testify/require" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| @@ -285,7 +286,7 @@ func TestAttachmentResizeUsesLatestClaimedSessionGeometry(t *testing.T) { | |||
| 285 | 286 | token := sess.captureAttachmentCapability(ac, tr) | |
| 286 | 287 | d.handleAttachmentClientFrame(token, ports.Frame{ | |
| 287 | 288 | Type: ports.MsgResize, | |
| 288 | - | Payload: mustMarshalResize(ports.Resize{Size: size}), | |
| 289 | + | Payload: mustMarshalResize(protocol.Resize{Size: size}), | |
| 289 | 290 | }) | |
| 290 | 291 | } | |
| 291 | 292 | resize(second, secondTransport, domain.Size{Cols: 120, Rows: 50}) | |
M internal/usecase/daemon/attachment_route_identity_test.go +4 -3
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | ||
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | 8 | "github.com/bnema/vev/internal/ports" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | "github.com/stretchr/testify/require" | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| @@ -28,7 +29,7 @@ func TestAttachmentTransitionPublishesCommittedRouteIdentity(t *testing.T) { | |||
| 28 | 29 | token := source.captureAttachmentCapability(ac, transport) | |
| 29 | 30 | token.lease = rc.attachmentLease(ac) | |
| 30 | 31 | ac.installTestAttachmentCapability(token) | |
| 31 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 32 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 32 | 33 | ||
| 33 | 34 | target := &session{ | |
| 34 | 35 | sessionCore: sessionCore{ | |
| @@ -54,7 +55,7 @@ func TestAttachmentTransitionPublishesCommittedRouteIdentity(t *testing.T) { | |||
| 54 | 55 | require.NoError(t, err) | |
| 55 | 56 | d.deferAttachmentTransitionCleanups(transition) | |
| 56 | 57 | ||
| 57 | - | var identity ports.CommittedRouteIdentity | |
| 58 | + | var identity protocol.CommittedRouteIdentity | |
| 58 | 59 | found := false | |
| 59 | 60 | for _, frame := range transport.Sends() { | |
| 60 | 61 | if frame.Type != ports.MsgCommittedRouteIdentity { | |
| @@ -78,7 +79,7 @@ func TestAttachmentTransitionTearsDownAfterCommittedIdentitySendFailure(t *testi | |||
| 78 | 79 | token := source.captureAttachmentCapability(ac, transport) | |
| 79 | 80 | token.lease = rc.attachmentLease(ac) | |
| 80 | 81 | ac.installTestAttachmentCapability(token) | |
| 81 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 82 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 82 | 83 | ||
| 83 | 84 | target := &session{ | |
| 84 | 85 | sessionCore: sessionCore{ | |
M internal/usecase/daemon/client.go +19 -18
| @@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | ||
| 14 | 14 | "github.com/bnema/vev/internal/domain" | |
| 15 | 15 | "github.com/bnema/vev/internal/ports" | |
| 16 | + | "github.com/bnema/vev/internal/protocol" | |
| 16 | 17 | "github.com/bnema/vev/internal/usecase/keys" | |
| 17 | 18 | "github.com/bnema/vev/internal/usecase/mouse" | |
| 18 | 19 | themeui "github.com/bnema/vev/internal/usecase/theme" | |
| @@ -40,8 +41,8 @@ type attachedClient struct { | |||
| 40 | 41 | overlayOnce sync.Once | |
| 41 | 42 | clientID [16]byte | |
| 42 | 43 | terminalCapabilities ports.TerminalCapabilities | |
| 43 | - | navigationCapabilities ports.NavigationCapabilities | |
| 44 | - | startupOverlay ports.StartupOverlay | |
| 44 | + | navigationCapabilities protocol.NavigationCapabilities | |
| 45 | + | startupOverlay protocol.StartupOverlay | |
| 45 | 46 | // lifecycle is the sole authority for attachment capability publication, | |
| 46 | 47 | // effect admission, transition freeze/drain, and connection generation. | |
| 47 | 48 | lifecycle attachmentLifecycle | |
| @@ -86,15 +87,15 @@ type attachedClient struct { | |||
| 86 | 87 | linkMu sync.Mutex | |
| 87 | 88 | sendMu sync.Mutex | |
| 88 | 89 | routeMu sync.RWMutex | |
| 89 | - | routeSnapshot ports.RecentRouteSnapshot | |
| 90 | + | routeSnapshot protocol.RecentRouteSnapshot | |
| 90 | 91 | pendingRouteIdentity bool | |
| 91 | 92 | samePeerOfferMu sync.Mutex | |
| 92 | - | samePeerOffer *ports.ExactSessionTarget | |
| 93 | + | samePeerOffer *protocol.ExactSessionTarget | |
| 93 | 94 | parkedRouteMu sync.Mutex | |
| 94 | 95 | parkedRoute *parkedRouteLease | |
| 95 | 96 | parkedRouteOutput atomic.Bool | |
| 96 | 97 | parkedRouteFullPending atomic.Bool | |
| 97 | - | routeAttentionSubscription ports.RouteAttentionSubscription | |
| 98 | + | routeAttentionSubscription protocol.RouteAttentionSubscription | |
| 98 | 99 | // routeCreatedSession marks a session created by this attachment's route. | |
| 99 | 100 | // A handshake that never commits Welcome must tear down that exact empty | |
| 100 | 101 | // session, while an attachment routed to an existing session must not. | |
| @@ -336,8 +337,8 @@ func (ac *attachedClient) currentTransportIs(tr ports.Transport) bool { | |||
| 336 | 337 | ||
| 337 | 338 | // setRouteSnapshot records a client-owned route view and reports whether a | |
| 338 | 339 | // rename identity was deferred until that first usable publication. | |
| 339 | - | func (ac *attachedClient) setRouteSnapshot(snapshot ports.RecentRouteSnapshot) bool { | |
| 340 | - | snapshot.Entries = append([]ports.RecentRouteEntry(nil), snapshot.Entries...) | |
| 340 | + | func (ac *attachedClient) setRouteSnapshot(snapshot protocol.RecentRouteSnapshot) bool { | |
| 341 | + | snapshot.Entries = append([]protocol.RecentRouteEntry(nil), snapshot.Entries...) | |
| 341 | 342 | ac.routeMu.Lock() | |
| 342 | 343 | ac.routeSnapshot = snapshot | |
| 343 | 344 | replayPendingIdentity := snapshot.Generation != 0 && ac.pendingRouteIdentity | |
| @@ -361,22 +362,22 @@ func (ac *attachedClient) deferRouteIdentityUntilSnapshot() bool { | |||
| 361 | 362 | return true | |
| 362 | 363 | } | |
| 363 | 364 | ||
| 364 | - | func (ac *attachedClient) routeSnapshotCopy() ports.RecentRouteSnapshot { | |
| 365 | + | func (ac *attachedClient) routeSnapshotCopy() protocol.RecentRouteSnapshot { | |
| 365 | 366 | ac.routeMu.RLock() | |
| 366 | 367 | defer ac.routeMu.RUnlock() | |
| 367 | 368 | snapshot := ac.routeSnapshot | |
| 368 | - | snapshot.Entries = append([]ports.RecentRouteEntry(nil), snapshot.Entries...) | |
| 369 | + | snapshot.Entries = append([]protocol.RecentRouteEntry(nil), snapshot.Entries...) | |
| 369 | 370 | return snapshot | |
| 370 | 371 | } | |
| 371 | 372 | ||
| 372 | - | func (ac *attachedClient) setRouteAttentionSubscription(subscription ports.RouteAttentionSubscription) { | |
| 373 | - | subscription.Targets = append([]ports.RouteAttentionTarget(nil), subscription.Targets...) | |
| 373 | + | func (ac *attachedClient) setRouteAttentionSubscription(subscription protocol.RouteAttentionSubscription) { | |
| 374 | + | subscription.Targets = append([]protocol.RouteAttentionTarget(nil), subscription.Targets...) | |
| 374 | 375 | ac.routeMu.Lock() | |
| 375 | 376 | ac.routeAttentionSubscription = subscription | |
| 376 | 377 | ac.routeMu.Unlock() | |
| 377 | 378 | } | |
| 378 | 379 | ||
| 379 | - | func (ac *attachedClient) routeAttentionTarget(ref ports.RouteRef) (ports.ExactSessionTarget, bool) { | |
| 380 | + | func (ac *attachedClient) routeAttentionTarget(ref protocol.RouteRef) (protocol.ExactSessionTarget, bool) { | |
| 380 | 381 | ac.routeMu.RLock() | |
| 381 | 382 | defer ac.routeMu.RUnlock() | |
| 382 | 383 | for _, target := range ac.routeAttentionSubscription.Targets { | |
| @@ -384,7 +385,7 @@ func (ac *attachedClient) routeAttentionTarget(ref ports.RouteRef) (ports.ExactS | |||
| 384 | 385 | return target.Target, true | |
| 385 | 386 | } | |
| 386 | 387 | } | |
| 387 | - | return ports.ExactSessionTarget{}, false | |
| 388 | + | return protocol.ExactSessionTarget{}, false | |
| 388 | 389 | } | |
| 389 | 390 | ||
| 390 | 391 | func (ac *attachedClient) ackOutputState(epoch, state uint64) { | |
| @@ -613,8 +614,8 @@ type attachClientOptions struct { | |||
| 613 | 614 | maxOutputInFlight uint8 | |
| 614 | 615 | terminalCapabilities ports.TerminalCapabilities | |
| 615 | 616 | capabilitiesSet bool | |
| 616 | - | navigationCapabilities ports.NavigationCapabilities | |
| 617 | - | startupOverlay ports.StartupOverlay | |
| 617 | + | navigationCapabilities protocol.NavigationCapabilities | |
| 618 | + | startupOverlay protocol.StartupOverlay | |
| 618 | 619 | } | |
| 619 | 620 | ||
| 620 | 621 | func (d *Daemon) attachClient(sess *session, tr ports.Transport, sz domain.Size, opts attachClientOptions) (*attachedClient, error) { | |
| @@ -882,7 +883,7 @@ func (d *Daemon) firstPaintWithLease(sess *session, ac *attachedClient, lease *a | |||
| 882 | 883 | ||
| 883 | 884 | // detachIfCurrent clears the client iff ac is the current one, reporting | |
| 884 | 885 | ||
| 885 | - | func themeFromMessage(msg ports.Theme) themeui.Theme { | |
| 886 | + | func themeFromMessage(msg protocol.Theme) themeui.Theme { | |
| 886 | 887 | return themeui.Theme{ | |
| 887 | 888 | Foreground: msg.Foreground, | |
| 888 | 889 | Background: msg.Background, | |
| @@ -897,7 +898,7 @@ func themeFromMessage(msg ports.Theme) themeui.Theme { | |||
| 897 | 898 | } | |
| 898 | 899 | } | |
| 899 | 900 | ||
| 900 | - | func (d *Daemon) applyTheme(sess *session, ac *attachedClient, msg ports.Theme) { | |
| 901 | + | func (d *Daemon) applyTheme(sess *session, ac *attachedClient, msg protocol.Theme) { | |
| 901 | 902 | clientTheme := themeFromMessage(msg) | |
| 902 | 903 | ac.setClientTheme(clientTheme) | |
| 903 | 904 | ||
| @@ -907,7 +908,7 @@ func (d *Daemon) applyTheme(sess *session, ac *attachedClient, msg ports.Theme) | |||
| 907 | 908 | d.invalidateRender(sess, ac, true, "client.go") | |
| 908 | 909 | } | |
| 909 | 910 | ||
| 910 | - | func (d *Daemon) applyThemeForAttachment(effect *attachmentEffect, msg ports.Theme) { | |
| 911 | + | func (d *Daemon) applyThemeForAttachment(effect *attachmentEffect, msg protocol.Theme) { | |
| 911 | 912 | if !effect.current() { | |
| 912 | 913 | return | |
| 913 | 914 | } | |
M internal/usecase/daemon/client_frame_routing.go +6 -5
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | ||
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | 8 | "github.com/bnema/vev/internal/ports" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | "github.com/bnema/vev/internal/usecase/command" | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| @@ -169,15 +170,15 @@ func (d *Daemon) handleAttachmentClientFrame(capability attachmentCapability, f | |||
| 169 | 170 | } | |
| 170 | 171 | message := "route navigation failed" | |
| 171 | 172 | switch failure.Code { | |
| 172 | - | case ports.RouteFailureStaleSelection: | |
| 173 | + | case protocol.RouteFailureStaleSelection: | |
| 173 | 174 | message = "that recent route is no longer available" | |
| 174 | - | case ports.RouteFailureTargetChanged: | |
| 175 | + | case protocol.RouteFailureTargetChanged: | |
| 175 | 176 | message = "that recent route changed before attach" | |
| 176 | - | case ports.RouteFailureOriginUnavailable: | |
| 177 | + | case protocol.RouteFailureOriginUnavailable: | |
| 177 | 178 | message = "the original route is no longer available" | |
| 178 | - | case ports.RouteFailureUnavailable: | |
| 179 | + | case protocol.RouteFailureUnavailable: | |
| 179 | 180 | message = "the selected route is unavailable" | |
| 180 | - | case ports.RouteFailureNoSuchRoute: | |
| 181 | + | case protocol.RouteFailureNoSuchRoute: | |
| 181 | 182 | message = "that recent route no longer exists" | |
| 182 | 183 | } | |
| 183 | 184 | d.notify(effect.sess, domain.NoticeWarn, domain.NoticeSessionUnavailable, message, nil) | |
M internal/usecase/daemon/client_transport_errors.go +3 -1
| @@ -1,6 +1,8 @@ | |||
| 1 | 1 | package daemon | |
| 2 | 2 | ||
| 3 | - | import "github.com/bnema/vev/internal/ports" | |
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/vev/internal/ports" | |
| 5 | + | ) | |
| 4 | 6 | ||
| 5 | 7 | // clientGone detaches ac if it is still the session's current client. The | |
| 6 | 8 | // session remains registered and headless after the client is gone. | |
M internal/usecase/daemon/clipboard.go +7 -6
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | "os" | |
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | scopy "github.com/bnema/vev/internal/usecase/copy" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| @@ -26,14 +27,14 @@ var ( | |||
| 26 | 27 | clipPasteCloseMarker = []byte("\x1b[201~") | |
| 27 | 28 | ) | |
| 28 | 29 | ||
| 29 | - | func (d *Daemon) handleSequencedImagePushForAttachment(effect *attachmentEffect, _ uint64, ip ports.ImagePush) { | |
| 30 | + | func (d *Daemon) handleSequencedImagePushForAttachment(effect *attachmentEffect, _ uint64, ip protocol.ImagePush) { | |
| 30 | 31 | if !effect.current() { | |
| 31 | 32 | return | |
| 32 | 33 | } | |
| 33 | 34 | d.handleImagePushForAttachment(effect, ip) | |
| 34 | 35 | } | |
| 35 | 36 | ||
| 36 | - | func (d *Daemon) handleImagePushForAttachment(effect *attachmentEffect, ip ports.ImagePush) { | |
| 37 | + | func (d *Daemon) handleImagePushForAttachment(effect *attachmentEffect, ip protocol.ImagePush) { | |
| 37 | 38 | if len(ip.Data) == 0 || len(ip.Data) > maxImagePushSize || !effect.current() { | |
| 38 | 39 | return | |
| 39 | 40 | } | |
| @@ -55,7 +56,7 @@ func (d *Daemon) handleImagePushForAttachment(effect *attachmentEffect, ip ports | |||
| 55 | 56 | // failure is logged and the push is dropped: the client has already | |
| 56 | 57 | // consumed the Ctrl+V keystroke that triggered it, so there is nothing left | |
| 57 | 58 | // to re-trigger from here. | |
| 58 | - | func (d *Daemon) handleImagePush(sess *session, ip ports.ImagePush) { | |
| 59 | + | func (d *Daemon) handleImagePush(sess *session, ip protocol.ImagePush) { | |
| 59 | 60 | if len(ip.Data) == 0 { | |
| 60 | 61 | return | |
| 61 | 62 | } | |
| @@ -73,7 +74,7 @@ func (d *Daemon) handleImagePush(sess *session, ip ports.ImagePush) { | |||
| 73 | 74 | ||
| 74 | 75 | // writeClipboardImage writes ip's bytes to a new 0600 temp file and records | |
| 75 | 76 | // the path on sess for best-effort cleanup at session end (killSession). | |
| 76 | - | func (d *Daemon) writeClipboardImage(sess *session, ip ports.ImagePush) (string, error) { | |
| 77 | + | func (d *Daemon) writeClipboardImage(sess *session, ip protocol.ImagePush) (string, error) { | |
| 77 | 78 | path, err := d.createClipboardImage(ip) | |
| 78 | 79 | if err != nil { | |
| 79 | 80 | return "", err | |
| @@ -84,7 +85,7 @@ func (d *Daemon) writeClipboardImage(sess *session, ip ports.ImagePush) (string, | |||
| 84 | 85 | return path, nil | |
| 85 | 86 | } | |
| 86 | 87 | ||
| 87 | - | func (d *Daemon) writeClipboardImageForAttachment(effect *attachmentEffect, ip ports.ImagePush) (string, error) { | |
| 88 | + | func (d *Daemon) writeClipboardImageForAttachment(effect *attachmentEffect, ip protocol.ImagePush) (string, error) { | |
| 88 | 89 | path, err := d.createClipboardImage(ip) | |
| 89 | 90 | if err != nil { | |
| 90 | 91 | return "", err | |
| @@ -105,7 +106,7 @@ func (d *Daemon) writeClipboardImageForAttachment(effect *attachmentEffect, ip p | |||
| 105 | 106 | return path, nil | |
| 106 | 107 | } | |
| 107 | 108 | ||
| 108 | - | func (d *Daemon) createClipboardImage(ip ports.ImagePush) (string, error) { | |
| 109 | + | func (d *Daemon) createClipboardImage(ip protocol.ImagePush) (string, error) { | |
| 109 | 110 | dir := d.tempDir | |
| 110 | 111 | if dir == "" { | |
| 111 | 112 | dir = os.TempDir() | |
M internal/usecase/daemon/clipboard_test.go +7 -6
| @@ -18,6 +18,7 @@ import ( | |||
| 18 | 18 | "github.com/bnema/vev/internal/domain" | |
| 19 | 19 | "github.com/bnema/vev/internal/ports" | |
| 20 | 20 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 21 | + | "github.com/bnema/vev/internal/protocol" | |
| 21 | 22 | scopy "github.com/bnema/vev/internal/usecase/copy" | |
| 22 | 23 | ) | |
| 23 | 24 | ||
| @@ -47,7 +48,7 @@ func TestHandleImagePushWritesFileWithExactBytesAndMode0600(t *testing.T) { | |||
| 47 | 48 | d.tempDir = t.TempDir() | |
| 48 | 49 | ||
| 49 | 50 | data := []byte{0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a, 0x01, 0x02, 0x03} | |
| 50 | - | d.handleImagePush(sess, ports.ImagePush{Mime: "image/png", Data: data}) | |
| 51 | + | d.handleImagePush(sess, protocol.ImagePush{Mime: "image/png", Data: data}) | |
| 51 | 52 | ||
| 52 | 53 | injected := <-writes | |
| 53 | 54 | path := string(injected) | |
| @@ -73,7 +74,7 @@ func TestHandleImagePushInjectsPathWithoutBracketedPasteWrapping(t *testing.T) { | |||
| 73 | 74 | pane := sess.tabs[0].focusedPane() | |
| 74 | 75 | require.False(t, pane.screen.BracketedPasteMode()) | |
| 75 | 76 | ||
| 76 | - | d.handleImagePush(sess, ports.ImagePush{Mime: "image/png", Data: []byte("x")}) | |
| 77 | + | d.handleImagePush(sess, protocol.ImagePush{Mime: "image/png", Data: []byte("x")}) | |
| 77 | 78 | ||
| 78 | 79 | injected := <-writes | |
| 79 | 80 | require.False(t, hasBracketedPasteMarkers(injected), "path must not be wrapped when the pane is not in bracketed-paste mode") | |
| @@ -90,7 +91,7 @@ func TestHandleImagePushInjectsPathWithBracketedPasteWrapping(t *testing.T) { | |||
| 90 | 91 | pane.screen.Write([]byte("\x1b[?2004h")) | |
| 91 | 92 | require.True(t, pane.screen.BracketedPasteMode()) | |
| 92 | 93 | ||
| 93 | - | d.handleImagePush(sess, ports.ImagePush{Mime: "image/png", Data: []byte("x")}) | |
| 94 | + | d.handleImagePush(sess, protocol.ImagePush{Mime: "image/png", Data: []byte("x")}) | |
| 94 | 95 | ||
| 95 | 96 | injected := <-writes | |
| 96 | 97 | require.True(t, len(injected) > len(clipPasteOpenMarker)+len(clipPasteCloseMarker)) | |
| @@ -114,7 +115,7 @@ func TestHandleImagePushRejectsOversizedPayloadWithoutWritingOrInjecting(t *test | |||
| 114 | 115 | d.tempDir = dir | |
| 115 | 116 | ||
| 116 | 117 | huge := make([]byte, maxImagePushSize+1) | |
| 117 | - | d.handleImagePush(sess, ports.ImagePush{Mime: "image/png", Data: huge}) | |
| 118 | + | d.handleImagePush(sess, protocol.ImagePush{Mime: "image/png", Data: huge}) | |
| 118 | 119 | ||
| 119 | 120 | select { | |
| 120 | 121 | case w := <-writes: | |
| @@ -134,7 +135,7 @@ func TestHandleImagePushIgnoresEmptyPayload(t *testing.T) { | |||
| 134 | 135 | dir := t.TempDir() | |
| 135 | 136 | d.tempDir = dir | |
| 136 | 137 | ||
| 137 | - | d.handleImagePush(sess, ports.ImagePush{Mime: "image/png", Data: nil}) | |
| 138 | + | d.handleImagePush(sess, protocol.ImagePush{Mime: "image/png", Data: nil}) | |
| 138 | 139 | ||
| 139 | 140 | select { | |
| 140 | 141 | case w := <-writes: | |
| @@ -170,7 +171,7 @@ func TestKillSessionRemovesClipboardTempFiles(t *testing.T) { | |||
| 170 | 171 | // killSession requires the session to be registered in the daemon's | |
| 171 | 172 | // registry (newManualSessionWithPTYs already does this via d.sessions). | |
| 172 | 173 | ||
| 173 | - | d.handleImagePush(sess, ports.ImagePush{Mime: "image/png", Data: []byte("x")}) | |
| 174 | + | d.handleImagePush(sess, protocol.ImagePush{Mime: "image/png", Data: []byte("x")}) | |
| 174 | 175 | injected := <-writes | |
| 175 | 176 | path := string(injected) | |
| 176 | 177 | require.FileExists(t, path) | |
M internal/usecase/daemon/coderabbit_regression_test.go +6 -6
| @@ -350,9 +350,9 @@ func TestRemoteInactiveRouteRejectsReplacementDuringCatalogueRead(t *testing.T) | |||
| 350 | 350 | d.mu.Unlock() | |
| 351 | 351 | close(catalogue.release) | |
| 352 | 352 | ||
| 353 | - | var protocol *protoErr | |
| 354 | - | require.ErrorAs(t, <-result, &protocol) | |
| 355 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 353 | + | var protocolErr *protoErr | |
| 354 | + | require.ErrorAs(t, <-result, &protocolErr) | |
| 355 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 356 | 356 | require.Empty(t, catalogue.MetadataUpdates()) | |
| 357 | 357 | d.mu.Lock() | |
| 358 | 358 | defer d.mu.Unlock() | |
| @@ -443,9 +443,9 @@ func TestRemoteInactiveRouteRejectsTabAuthorityChangeDuringCatalogueRead(t *test | |||
| 443 | 443 | } | |
| 444 | 444 | close(catalogue.release) | |
| 445 | 445 | ||
| 446 | - | var protocol *protoErr | |
| 447 | - | require.ErrorAs(t, <-result, &protocol) | |
| 448 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 446 | + | var protocolErr *protoErr | |
| 447 | + | require.ErrorAs(t, <-result, &protocolErr) | |
| 448 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 449 | 449 | require.Empty(t, catalogue.MetadataUpdates()) | |
| 450 | 450 | d.mu.Lock() | |
| 451 | 451 | defer d.mu.Unlock() | |
M internal/usecase/daemon/config_test.go +2 -1
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | renderer "github.com/bnema/vev-vt" | |
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | "github.com/bnema/vev/internal/usecase/keys" | |
| 13 | 14 | themeui "github.com/bnema/vev/internal/usecase/theme" | |
| 14 | 15 | ) | |
| @@ -63,7 +64,7 @@ func TestApplyThemeCopiesTerminalPaletteAndHotReloadGatesIt(t *testing.T) { | |||
| 63 | 64 | clientPalette := [16]renderer.RGB{} | |
| 64 | 65 | clientPalette[1] = renderer.RGB{R: 1, G: 2, B: 3} | |
| 65 | 66 | clientPalette[12] = renderer.RGB{R: 4, G: 5, B: 6} | |
| 66 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 67 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 67 | 68 | HasForeground: true, | |
| 68 | 69 | Foreground: renderer.RGB{R: 7, G: 8, B: 9}, | |
| 69 | 70 | HasBackground: true, | |
M internal/usecase/daemon/daemon.go +4 -3
| @@ -17,6 +17,7 @@ import ( | |||
| 17 | 17 | ||
| 18 | 18 | "github.com/bnema/vev/internal/domain" | |
| 19 | 19 | "github.com/bnema/vev/internal/ports" | |
| 20 | + | "github.com/bnema/vev/internal/protocol" | |
| 20 | 21 | "github.com/bnema/vev/internal/usecase/keys" | |
| 21 | 22 | recoveryusecase "github.com/bnema/vev/internal/usecase/recovery" | |
| 22 | 23 | ) | |
| @@ -1286,7 +1287,7 @@ func (d *Daemon) handleHelloWithContext(handshakeCtx context.Context, timedOut < | |||
| 1286 | 1287 | failAttachment() | |
| 1287 | 1288 | return | |
| 1288 | 1289 | } | |
| 1289 | - | if ac.startupOverlay == ports.StartupOverlaySessionPicker { | |
| 1290 | + | if ac.startupOverlay == protocol.StartupOverlaySessionPicker { | |
| 1290 | 1291 | d.enterPicker(sess, ac) | |
| 1291 | 1292 | } | |
| 1292 | 1293 | postWelcomeTicket.End() | |
| @@ -1449,7 +1450,7 @@ func (d *Daemon) waitForTargetRestore(ctx context.Context, name string) error { | |||
| 1449 | 1450 | // route resolves a Hello to a session and a freshly attached client, creating | |
| 1450 | 1451 | // the session for ephemeral/new intents. Direct package callers retain the | |
| 1451 | 1452 | // daemon lifetime context; inbound handshakes use routeWithContext. | |
| 1452 | - | func (d *Daemon) validateExactSessionTargetLocked(target ports.ExactSessionTarget) error { | |
| 1453 | + | func (d *Daemon) validateExactSessionTargetLocked(target protocol.ExactSessionTarget) error { | |
| 1453 | 1454 | if sess := d.findByNameLocked(target.SessionName); sess != nil { | |
| 1454 | 1455 | if sess.incarnation != target.LifecycleID { | |
| 1455 | 1456 | return &protoErr{ports.ErrNoSuchSession, "session lifecycle has changed: " + target.SessionName} | |
| @@ -1463,7 +1464,7 @@ func (d *Daemon) validateExactSessionTargetLocked(target ports.ExactSessionTarge | |||
| 1463 | 1464 | return nil | |
| 1464 | 1465 | } | |
| 1465 | 1466 | ||
| 1466 | - | func (d *Daemon) validateExactSessionTarget(ctx context.Context, target ports.ExactSessionTarget) error { | |
| 1467 | + | func (d *Daemon) validateExactSessionTarget(ctx context.Context, target protocol.ExactSessionTarget) error { | |
| 1467 | 1468 | if err := target.Validate(); err != nil { | |
| 1468 | 1469 | return &protoErr{ports.ErrNoSuchSession, "invalid exact session target"} | |
| 1469 | 1470 | } | |
M internal/usecase/daemon/exact_route_test.go +14 -13
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | ||
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | 8 | "github.com/bnema/vev/internal/ports" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | "github.com/stretchr/testify/require" | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| @@ -15,7 +16,7 @@ func TestRouteExactSessionTargetSelectsLifecycle(t *testing.T) { | |||
| 15 | 16 | sess.ephemeral = false | |
| 16 | 17 | sess.incarnation = remoteLifecycleForTest() | |
| 17 | 18 | tr, _ := newCapturingTransport(t) | |
| 18 | - | target := ports.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 19 | + | target := protocol.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 19 | 20 | hello := ports.Hello{ | |
| 20 | 21 | Version: ports.ProtocolVersion, | |
| 21 | 22 | Intent: ports.IntentAttach, | |
| @@ -42,13 +43,13 @@ func TestRouteExactSessionTargetRejectsNameMismatch(t *testing.T) { | |||
| 42 | 43 | Intent: ports.IntentAttach, | |
| 43 | 44 | Name: "other", | |
| 44 | 45 | Size: domain.Size{Cols: 80, Rows: 24}, | |
| 45 | - | ExactTarget: &ports.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name}, | |
| 46 | + | ExactTarget: &protocol.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name}, | |
| 46 | 47 | } | |
| 47 | 48 | ||
| 48 | 49 | _, _, err := d.routeWithContext(context.Background(), hello, tr) | |
| 49 | - | var protocol *protoErr | |
| 50 | - | require.ErrorAs(t, err, &protocol) | |
| 51 | - | require.Equal(t, ports.ErrNoSuchSession, protocol.code) | |
| 50 | + | var protocolErr *protoErr | |
| 51 | + | require.ErrorAs(t, err, &protocolErr) | |
| 52 | + | require.Equal(t, ports.ErrNoSuchSession, protocolErr.code) | |
| 52 | 53 | } | |
| 53 | 54 | ||
| 54 | 55 | func TestLockedExactSessionTargetRejectsReplacement(t *testing.T) { | |
| @@ -56,7 +57,7 @@ func TestLockedExactSessionTargetRejectsReplacement(t *testing.T) { | |||
| 56 | 57 | sess := addControlSession(d, "work", "tab-1", "pane-1") | |
| 57 | 58 | sess.ephemeral = false | |
| 58 | 59 | sess.incarnation = remoteLifecycleForTest() | |
| 59 | - | target := ports.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 60 | + | target := protocol.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 60 | 61 | replacement := sess.incarnation | |
| 61 | 62 | replacement[0]++ | |
| 62 | 63 | sess.incarnation = replacement | |
| @@ -65,9 +66,9 @@ func TestLockedExactSessionTargetRejectsReplacement(t *testing.T) { | |||
| 65 | 66 | err := d.validateExactSessionTargetLocked(target) | |
| 66 | 67 | d.mu.Unlock() | |
| 67 | 68 | ||
| 68 | - | var protocol *protoErr | |
| 69 | - | require.ErrorAs(t, err, &protocol) | |
| 70 | - | require.Equal(t, ports.ErrNoSuchSession, protocol.code) | |
| 69 | + | var protocolErr *protoErr | |
| 70 | + | require.ErrorAs(t, err, &protocolErr) | |
| 71 | + | require.Equal(t, ports.ErrNoSuchSession, protocolErr.code) | |
| 71 | 72 | } | |
| 72 | 73 | ||
| 73 | 74 | func TestRouteExactSessionTargetRejectsLifecycleReplacement(t *testing.T) { | |
| @@ -83,11 +84,11 @@ func TestRouteExactSessionTargetRejectsLifecycleReplacement(t *testing.T) { | |||
| 83 | 84 | Intent: ports.IntentAttach, | |
| 84 | 85 | Name: sess.name, | |
| 85 | 86 | Size: domain.Size{Cols: 80, Rows: 24}, | |
| 86 | - | ExactTarget: &ports.ExactSessionTarget{LifecycleID: wrong, SessionName: sess.name}, | |
| 87 | + | ExactTarget: &protocol.ExactSessionTarget{LifecycleID: wrong, SessionName: sess.name}, | |
| 87 | 88 | } | |
| 88 | 89 | ||
| 89 | 90 | _, _, err := d.routeWithContext(context.Background(), hello, tr) | |
| 90 | - | var protocol *protoErr | |
| 91 | - | require.ErrorAs(t, err, &protocol) | |
| 92 | - | require.Equal(t, ports.ErrNoSuchSession, protocol.code) | |
| 91 | + | var protocolErr *protoErr | |
| 92 | + | require.ErrorAs(t, err, &protocolErr) | |
| 93 | + | require.Equal(t, ports.ErrNoSuchSession, protocolErr.code) | |
| 93 | 94 | } | |
M internal/usecase/daemon/graphics_output.go +3 -2
| @@ -16,6 +16,7 @@ import ( | |||
| 16 | 16 | "github.com/bnema/vev-vt/graphics" | |
| 17 | 17 | "github.com/bnema/vev/internal/domain" | |
| 18 | 18 | "github.com/bnema/vev/internal/ports" | |
| 19 | + | "github.com/bnema/vev/internal/protocol" | |
| 19 | 20 | "github.com/bnema/vev/internal/usecase/layout" | |
| 20 | 21 | themeui "github.com/bnema/vev/internal/usecase/theme" | |
| 21 | 22 | ) | |
| @@ -25,8 +26,8 @@ import ( | |||
| 25 | 26 | // attachment-local state is also the ownership boundary for Kitty IDs: raw | |
| 26 | 27 | // scene IDs are never sent to the outer terminal. | |
| 27 | 28 | const ( | |
| 28 | - | maxGraphicsRecordBytes = ports.MaxOutputDataLen | |
| 29 | - | maxGraphicsOutputBytes = ports.MaxOutputDataLen | |
| 29 | + | maxGraphicsRecordBytes = protocol.MaxOutputDataLen | |
| 30 | + | maxGraphicsOutputBytes = protocol.MaxOutputDataLen | |
| 30 | 31 | graphicsUploadChunkBytes = 128 << 10 | |
| 31 | 32 | ) | |
| 32 | 33 | ||
M internal/usecase/daemon/input_test.go +7 -6
| @@ -17,6 +17,7 @@ import ( | |||
| 17 | 17 | "github.com/bnema/vev/internal/domain" | |
| 18 | 18 | "github.com/bnema/vev/internal/ports" | |
| 19 | 19 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 20 | + | "github.com/bnema/vev/internal/protocol" | |
| 20 | 21 | scopy "github.com/bnema/vev/internal/usecase/copy" | |
| 21 | 22 | "github.com/bnema/vev/internal/usecase/keys" | |
| 22 | 23 | "github.com/bnema/vev/internal/usecase/layout" | |
| @@ -789,18 +790,18 @@ func TestPaletteBackSessionSendsClientPreviousRouteAction(t *testing.T) { | |||
| 789 | 790 | effect, admitted := ac.beginAttachmentEffect(token) | |
| 790 | 791 | require.True(t, admitted) | |
| 791 | 792 | defer effect.End() | |
| 792 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 793 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 793 | 794 | Generation: 3, | |
| 794 | - | Active: ports.RouteRef{Key: 3, Generation: 3}, | |
| 795 | - | Previous: ports.RouteRef{Key: 2, Generation: 2}, | |
| 796 | - | Entries: []ports.RecentRouteEntry{testRouteEntry(2, 2, "recent", 2, ports.RouteKindLocal)}, | |
| 795 | + | Active: protocol.RouteRef{Key: 3, Generation: 3}, | |
| 796 | + | Previous: protocol.RouteRef{Key: 2, Generation: 2}, | |
| 797 | + | Entries: []protocol.RecentRouteEntry{testRouteEntry(2, 2, "recent", 2, protocol.RouteKindLocal)}, | |
| 797 | 798 | }) | |
| 798 | 799 | ||
| 799 | 800 | require.NoError(t, d.backSessionForAttachment(effect)) | |
| 800 | 801 | frame := awaitFrame(t, sends, ports.MsgNavigateRecentRoute) | |
| 801 | 802 | action, err := ports.UnmarshalRouteNavigationAction(frame.Payload) | |
| 802 | 803 | require.NoError(t, err) | |
| 803 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 3, Key: 2, Generation: 2}, action) | |
| 804 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 3, Key: 2, Generation: 2}, action) | |
| 804 | 805 | } | |
| 805 | 806 | ||
| 806 | 807 | func TestBackSessionWithoutClientHistoryIsNoop(t *testing.T) { | |
| @@ -1088,7 +1089,7 @@ func TestCopyModeMouseHorizontalReverseDragUsesExactOSC52(t *testing.T) { | |||
| 1088 | 1089 | mustOutputData(t, sends) | |
| 1089 | 1090 | d.handleInput(sess, ac, []byte("\x1b[<0;2;2m")) | |
| 1090 | 1091 | d.handleInput(sess, ac, []byte("y")) | |
| 1091 | - | var msg ports.Output | |
| 1092 | + | var msg protocol.Output | |
| 1092 | 1093 | require.Eventually(t, func() bool { | |
| 1093 | 1094 | frame := awaitFrame(t, sends, ports.MsgOutput) | |
| 1094 | 1095 | var err error | |
M internal/usecase/daemon/move_lifecycle_test.go +1 -2
| @@ -4,9 +4,8 @@ import ( | |||
| 4 | 4 | "testing" | |
| 5 | 5 | "time" | |
| 6 | 6 | ||
| 7 | - | "github.com/stretchr/testify/require" | |
| 8 | - | ||
| 9 | 7 | "github.com/bnema/vev/internal/ports" | |
| 8 | + | "github.com/stretchr/testify/require" | |
| 10 | 9 | ) | |
| 11 | 10 | ||
| 12 | 11 | func awaitMoveTeardownState(t *testing.T, sess *session, reservations, waiters uint) { | |
M internal/usecase/daemon/output_state_sync_test.go +3 -2
| @@ -12,6 +12,7 @@ import ( | |||
| 12 | 12 | renderer "github.com/bnema/vev-vt/ansi" | |
| 13 | 13 | "github.com/bnema/vev/internal/domain" | |
| 14 | 14 | "github.com/bnema/vev/internal/ports" | |
| 15 | + | "github.com/bnema/vev/internal/protocol" | |
| 15 | 16 | "github.com/stretchr/testify/require" | |
| 16 | 17 | ) | |
| 17 | 18 | ||
| @@ -102,7 +103,7 @@ func TestDatagramAttachPipelinesRendererBeforeAck(t *testing.T) { | |||
| 102 | 103 | require.Equal(t, uint64(2), out.New) | |
| 103 | 104 | // Both states were emitted before the MsgAck; the ordered dependency chain | |
| 104 | 105 | // must therefore remain valid without waiting for renderer acknowledgement. | |
| 105 | - | tr.recv <- ports.Frame{Type: ports.MsgAck, Payload: mustMarshalAck(ports.Ack{Epoch: out.Epoch, State: out.New})} | |
| 106 | + | tr.recv <- ports.Frame{Type: ports.MsgAck, Payload: mustMarshalAck(protocol.Ack{Epoch: out.Epoch, State: out.New})} | |
| 106 | 107 | require.NoError(t, tr.Close()) | |
| 107 | 108 | d.runConnLoop(ac) | |
| 108 | 109 | ||
| @@ -197,7 +198,7 @@ func outputStateRow(row []renderer.Cell) string { | |||
| 197 | 198 | return string(runes) | |
| 198 | 199 | } | |
| 199 | 200 | ||
| 200 | - | func mustApplyOutput(t *testing.T, screen *vt.Screen, frame ports.Frame) ports.Output { | |
| 201 | + | func mustApplyOutput(t *testing.T, screen *vt.Screen, frame ports.Frame) protocol.Output { | |
| 201 | 202 | t.Helper() | |
| 202 | 203 | out, err := ports.UnmarshalOutput(frame.Payload) | |
| 203 | 204 | require.NoError(t, err) | |
M internal/usecase/daemon/overlay_runtime.go +4 -4
| @@ -6,7 +6,7 @@ import ( | |||
| 6 | 6 | "time" | |
| 7 | 7 | ||
| 8 | 8 | "github.com/bnema/vev/internal/domain" | |
| 9 | - | "github.com/bnema/vev/internal/ports" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 10 | 10 | scopy "github.com/bnema/vev/internal/usecase/copy" | |
| 11 | 11 | "github.com/bnema/vev/internal/usecase/notices" | |
| 12 | 12 | "github.com/bnema/vev/internal/usecase/palette" | |
| @@ -43,7 +43,7 @@ type overlayRuntime struct { | |||
| 43 | 43 | ||
| 44 | 44 | paletteMu sync.Mutex | |
| 45 | 45 | palette *palette.Model | |
| 46 | - | paletteRouteSnapshot ports.RecentRouteSnapshot | |
| 46 | + | paletteRouteSnapshot protocol.RecentRouteSnapshot | |
| 47 | 47 | paletteGeneration uint64 | |
| 48 | 48 | paletteHints palette.ContextualHints | |
| 49 | 49 | palettePreview string | |
| @@ -309,7 +309,7 @@ type overlayRenderSnapshot struct { | |||
| 309 | 309 | paletteHints *palette.ContextualHints | |
| 310 | 310 | palettePreview string | |
| 311 | 311 | paletteFeedback string | |
| 312 | - | paletteRouteSnapshot ports.RecentRouteSnapshot | |
| 312 | + | paletteRouteSnapshot protocol.RecentRouteSnapshot | |
| 313 | 313 | paletteLocked bool | |
| 314 | 314 | ||
| 315 | 315 | promptActive bool | |
| @@ -383,7 +383,7 @@ func (rt *overlayRuntime) SnapshotForRender() *overlayRenderSnapshot { | |||
| 383 | 383 | snap.palettePreview = rt.palettePreview | |
| 384 | 384 | snap.paletteFeedback = rt.paletteFeedback | |
| 385 | 385 | snap.paletteRouteSnapshot = rt.paletteRouteSnapshot | |
| 386 | - | snap.paletteRouteSnapshot.Entries = append([]ports.RecentRouteEntry(nil), rt.paletteRouteSnapshot.Entries...) | |
| 386 | + | snap.paletteRouteSnapshot.Entries = append([]protocol.RecentRouteEntry(nil), rt.paletteRouteSnapshot.Entries...) | |
| 387 | 387 | snap.paletteLocked = true | |
| 388 | 388 | } else { | |
| 389 | 389 | rt.paletteMu.Unlock() | |
M internal/usecase/daemon/palette.go +25 -24
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | renderer "github.com/bnema/vev-vt" | |
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | "github.com/bnema/vev/internal/usecase/command" | |
| 12 | 13 | "github.com/bnema/vev/internal/usecase/layout" | |
| 13 | 14 | "github.com/bnema/vev/internal/usecase/palette" | |
| @@ -61,7 +62,7 @@ func (d *Daemon) enterPalette(sess *session, ac *attachedClient) { | |||
| 61 | 62 | } | |
| 62 | 63 | ||
| 63 | 64 | type paletteSessionIdentity struct { | |
| 64 | - | kind ports.RouteKind | |
| 65 | + | kind protocol.RouteKind | |
| 65 | 66 | endpoint string | |
| 66 | 67 | lifecycle domain.SessionLifecycleID | |
| 67 | 68 | } | |
| @@ -73,11 +74,11 @@ type remotePalettePresentationIdentity struct { | |||
| 73 | 74 | } | |
| 74 | 75 | ||
| 75 | 76 | func localPaletteSessionIdentity(lifecycle domain.SessionLifecycleID) paletteSessionIdentity { | |
| 76 | - | return paletteSessionIdentity{kind: ports.RouteKindLocal, endpoint: "local", lifecycle: lifecycle} | |
| 77 | + | return paletteSessionIdentity{kind: protocol.RouteKindLocal, endpoint: "local", lifecycle: lifecycle} | |
| 77 | 78 | } | |
| 78 | 79 | ||
| 79 | 80 | func remotePaletteSessionIdentity(endpoint string, lifecycle domain.SessionLifecycleID) paletteSessionIdentity { | |
| 80 | - | return paletteSessionIdentity{kind: ports.RouteKindRemote, endpoint: endpoint, lifecycle: lifecycle} | |
| 81 | + | return paletteSessionIdentity{kind: protocol.RouteKindRemote, endpoint: endpoint, lifecycle: lifecycle} | |
| 81 | 82 | } | |
| 82 | 83 | ||
| 83 | 84 | func paletteRemoteDisplayOrigin(hostLabel string) string { | |
| @@ -88,19 +89,19 @@ func paletteRemoteDisplayOrigin(hostLabel string) string { | |||
| 88 | 89 | return origin | |
| 89 | 90 | } | |
| 90 | 91 | ||
| 91 | - | func paletteDaemonDisplayOrigin(snapshot ports.RecentRouteSnapshot, lifecycle domain.SessionLifecycleID) string { | |
| 92 | + | func paletteDaemonDisplayOrigin(snapshot protocol.RecentRouteSnapshot, lifecycle domain.SessionLifecycleID) string { | |
| 92 | 93 | active, ok := activeRouteEntryForLifecycle(snapshot, lifecycle) | |
| 93 | - | if !ok || active.Kind != ports.RouteKindRemote { | |
| 94 | + | if !ok || active.Kind != protocol.RouteKindRemote { | |
| 94 | 95 | return "" | |
| 95 | 96 | } | |
| 96 | 97 | return paletteRemoteDisplayOrigin(active.HostLabel) | |
| 97 | 98 | } | |
| 98 | 99 | ||
| 99 | - | func paletteRouteRepresentsDaemonSession(entry ports.RecentRouteEntry, daemonDisplayOrigin string) bool { | |
| 100 | - | if entry.Kind == ports.RouteKindLocal { | |
| 100 | + | func paletteRouteRepresentsDaemonSession(entry protocol.RecentRouteEntry, daemonDisplayOrigin string) bool { | |
| 101 | + | if entry.Kind == protocol.RouteKindLocal { | |
| 101 | 102 | return true | |
| 102 | 103 | } | |
| 103 | - | return entry.Kind == ports.RouteKindRemote && daemonDisplayOrigin != "" && | |
| 104 | + | return entry.Kind == protocol.RouteKindRemote && daemonDisplayOrigin != "" && | |
| 104 | 105 | paletteRemoteDisplayOrigin(entry.HostLabel) == daemonDisplayOrigin | |
| 105 | 106 | } | |
| 106 | 107 | ||
| @@ -113,7 +114,7 @@ func remotePaletteUnavailableReason(status remoteHostStatus, session ports.Remot | |||
| 113 | 114 | ||
| 114 | 115 | // paletteResults captures eligible named sessions before paletteMu so the | |
| 115 | 116 | // palette has an immutable lifecycle target without violating lock ordering. | |
| 116 | - | func (d *Daemon) paletteResults(current *session, commands []command.Command, routeSnapshot ports.RecentRouteSnapshot) []palette.Result { | |
| 117 | + | func (d *Daemon) paletteResults(current *session, commands []command.Command, routeSnapshot protocol.RecentRouteSnapshot) []palette.Result { | |
| 117 | 118 | d.mu.Lock() | |
| 118 | 119 | sessions := d.sessionsSnapshotLocked() | |
| 119 | 120 | stopped := make([]inactiveSession, 0, len(d.inactive)) | |
| @@ -154,7 +155,7 @@ func (d *Daemon) paletteResults(current *session, commands []command.Command, ro | |||
| 154 | 155 | if candidate == current { | |
| 155 | 156 | continue | |
| 156 | 157 | } | |
| 157 | - | target := ports.ExactSessionTarget{LifecycleID: snap.incarnation, SessionName: snap.name} | |
| 158 | + | target := protocol.ExactSessionTarget{LifecycleID: snap.incarnation, SessionName: snap.name} | |
| 158 | 159 | active = append(active, palette.NewActiveSessionResultWithDisplayOrigin(target, time.Unix(0, snap.createdAt), daemonDisplayOrigin)) | |
| 159 | 160 | } | |
| 160 | 161 | sort.Slice(active, func(i, j int) bool { | |
| @@ -165,7 +166,7 @@ func (d *Daemon) paletteResults(current *session, commands []command.Command, ro | |||
| 165 | 166 | sort.Slice(stopped, func(i, j int) bool { return stopped[i].name < stopped[j].name }) | |
| 166 | 167 | results = append(results, active...) | |
| 167 | 168 | for _, candidate := range stopped { | |
| 168 | - | target := ports.ExactSessionTarget{LifecycleID: candidate.incarnation, SessionName: candidate.name} | |
| 169 | + | target := protocol.ExactSessionTarget{LifecycleID: candidate.incarnation, SessionName: candidate.name} | |
| 169 | 170 | results = append(results, palette.NewStoppedSessionResultWithDisplayOrigin(target, time.Unix(0, candidate.createdAt), daemonDisplayOrigin)) | |
| 170 | 171 | represented[localPaletteSessionIdentity(target.LifecycleID)] = struct{}{} | |
| 171 | 172 | } | |
| @@ -210,12 +211,12 @@ func (d *Daemon) paletteResults(current *session, commands []command.Command, ro | |||
| 210 | 211 | if _, exists := represented[identity]; exists && paletteRouteRepresentsDaemonSession(entry, daemonDisplayOrigin) { | |
| 211 | 212 | continue | |
| 212 | 213 | } | |
| 213 | - | results = append(results, palette.NewRecentRouteResult(label, ports.RouteNavigationAction{ | |
| 214 | + | results = append(results, palette.NewRecentRouteResult(label, protocol.RouteNavigationAction{ | |
| 214 | 215 | SnapshotGeneration: routeSnapshot.Generation, | |
| 215 | 216 | Key: entry.Key, | |
| 216 | 217 | Generation: entry.Generation, | |
| 217 | 218 | })) | |
| 218 | - | if entry.Kind == ports.RouteKindLocal { | |
| 219 | + | if entry.Kind == protocol.RouteKindLocal { | |
| 219 | 220 | represented[identity] = struct{}{} | |
| 220 | 221 | continue | |
| 221 | 222 | } | |
| @@ -251,7 +252,7 @@ func (d *Daemon) refreshPalette(ac *attachedClient) { | |||
| 251 | 252 | model := rt.palette | |
| 252 | 253 | generation := rt.paletteGeneration | |
| 253 | 254 | routeSnapshot := rt.paletteRouteSnapshot | |
| 254 | - | routeSnapshot.Entries = append([]ports.RecentRouteEntry(nil), routeSnapshot.Entries...) | |
| 255 | + | routeSnapshot.Entries = append([]protocol.RecentRouteEntry(nil), routeSnapshot.Entries...) | |
| 255 | 256 | rt.paletteMu.Unlock() | |
| 256 | 257 | if model == nil { | |
| 257 | 258 | return | |
| @@ -266,7 +267,7 @@ func (d *Daemon) refreshPalette(ac *attachedClient) { | |||
| 266 | 267 | model.ReplaceResults(results) | |
| 267 | 268 | } | |
| 268 | 269 | ||
| 269 | - | func recentRouteHints(snapshot ports.RecentRouteSnapshot, args []string) palette.ContextualHints { | |
| 270 | + | func recentRouteHints(snapshot protocol.RecentRouteSnapshot, args []string) palette.ContextualHints { | |
| 270 | 271 | formatted := formatRecentRouteSnapshot(snapshot) | |
| 271 | 272 | names := make([]string, len(formatted)) | |
| 272 | 273 | for i, entry := range formatted { | |
| @@ -342,10 +343,10 @@ func (d *Daemon) handlePaletteInput(ac *attachedClient, data []byte, effects ... | |||
| 342 | 343 | var remoteKey domain.RemoteSessionKey | |
| 343 | 344 | var remoteUnavailableReason string | |
| 344 | 345 | var hasRemoteTarget bool | |
| 345 | - | var routeTarget ports.RouteNavigationAction | |
| 346 | + | var routeTarget protocol.RouteNavigationAction | |
| 346 | 347 | var hasRouteTarget bool | |
| 347 | 348 | var args []string | |
| 348 | - | var routeSnapshot ports.RecentRouteSnapshot | |
| 349 | + | var routeSnapshot protocol.RecentRouteSnapshot | |
| 349 | 350 | var generation uint64 | |
| 350 | 351 | var rawQuery string | |
| 351 | 352 | changed, cancel, execute := false, false, false | |
| @@ -419,7 +420,7 @@ func (d *Daemon) handlePaletteInput(ac *attachedClient, data []byte, effects ... | |||
| 419 | 420 | } | |
| 420 | 421 | if cmd.ContextHint == command.ContextHintRecentSessions { | |
| 421 | 422 | routeSnapshot = ac.overlays.paletteRouteSnapshot | |
| 422 | - | routeSnapshot.Entries = append([]ports.RecentRouteEntry(nil), routeSnapshot.Entries...) | |
| 423 | + | routeSnapshot.Entries = append([]protocol.RecentRouteEntry(nil), routeSnapshot.Entries...) | |
| 423 | 424 | } | |
| 424 | 425 | } else if target, ok := selected.RemoteSessionTarget(); ok { | |
| 425 | 426 | key, keyOK := selected.RemoteSessionKey() | |
| @@ -624,7 +625,7 @@ func (ac *attachedClient) clearPaletteLocked() remoteDiscoveryInstance { | |||
| 624 | 625 | model := ac.overlays.palette | |
| 625 | 626 | ac.overlays.paletteGeneration++ | |
| 626 | 627 | ac.overlays.palette = nil | |
| 627 | - | ac.overlays.paletteRouteSnapshot = ports.RecentRouteSnapshot{} | |
| 628 | + | ac.overlays.paletteRouteSnapshot = protocol.RecentRouteSnapshot{} | |
| 628 | 629 | ac.overlays.paletteHints = palette.ContextualHints{} | |
| 629 | 630 | ac.overlays.palettePreview = "" | |
| 630 | 631 | ac.overlays.paletteFeedback = "" | |
| @@ -679,7 +680,7 @@ type paletteExec struct { | |||
| 679 | 680 | sess *session | |
| 680 | 681 | attachment *session | |
| 681 | 682 | ac *attachedClient | |
| 682 | - | routeSnapshot ports.RecentRouteSnapshot | |
| 683 | + | routeSnapshot protocol.RecentRouteSnapshot | |
| 683 | 684 | actions daemonActionRunner | |
| 684 | 685 | effect *attachmentEffect | |
| 685 | 686 | redrawClosedPalette bool | |
| @@ -911,8 +912,8 @@ func (e paletteExec) RenameTabTo(name string) error { | |||
| 911 | 912 | } | |
| 912 | 913 | ||
| 913 | 914 | func (e paletteExec) OpenSessionPicker() error { | |
| 914 | - | if e.ac != nil && e.ac.navigationCapabilities&ports.NavigationCapabilityHomePicker != 0 && e.effect != nil { | |
| 915 | - | return e.d.sendNavigationActionForAttachment(e.effect, ports.NavigationOpenHomePicker) | |
| 915 | + | if e.ac != nil && e.ac.navigationCapabilities&protocol.NavigationCapabilityHomePicker != 0 && e.effect != nil { | |
| 916 | + | return e.d.sendNavigationActionForAttachment(e.effect, protocol.NavigationOpenHomePicker) | |
| 916 | 917 | } | |
| 917 | 918 | e.d.enterPicker(e.sess, e.ac) | |
| 918 | 919 | return nil | |
| @@ -945,14 +946,14 @@ func (e paletteExec) JumpRecentSession(rank int) error { | |||
| 945 | 946 | return command.ErrInvalidArguments | |
| 946 | 947 | } | |
| 947 | 948 | entry := e.routeSnapshot.Entries[rank-1] | |
| 948 | - | return e.NavigateRecentRoute(ports.RouteNavigationAction{ | |
| 949 | + | return e.NavigateRecentRoute(protocol.RouteNavigationAction{ | |
| 949 | 950 | SnapshotGeneration: e.routeSnapshot.Generation, | |
| 950 | 951 | Key: entry.Key, | |
| 951 | 952 | Generation: entry.Generation, | |
| 952 | 953 | }) | |
| 953 | 954 | } | |
| 954 | 955 | ||
| 955 | - | func (e paletteExec) NavigateRecentRoute(action ports.RouteNavigationAction) error { | |
| 956 | + | func (e paletteExec) NavigateRecentRoute(action protocol.RouteNavigationAction) error { | |
| 956 | 957 | if e.d.beforeRecentSessionHandoff != nil { | |
| 957 | 958 | e.d.beforeRecentSessionHandoff() | |
| 958 | 959 | } | |
M internal/usecase/daemon/palette_test.go +54 -53
| @@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | "github.com/bnema/vev/internal/domain" | |
| 14 | 14 | "github.com/bnema/vev/internal/ports" | |
| 15 | 15 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 16 | + | "github.com/bnema/vev/internal/protocol" | |
| 16 | 17 | "github.com/bnema/vev/internal/usecase/command" | |
| 17 | 18 | "github.com/bnema/vev/internal/usecase/palette" | |
| 18 | 19 | "github.com/bnema/vev/internal/usecase/picker" | |
| @@ -20,14 +21,14 @@ import ( | |||
| 20 | 21 | "github.com/bnema/vev/internal/usecase/ui" | |
| 21 | 22 | ) | |
| 22 | 23 | ||
| 23 | - | func testRecentRouteSnapshot() ports.RecentRouteSnapshot { | |
| 24 | - | return ports.RecentRouteSnapshot{ | |
| 24 | + | func testRecentRouteSnapshot() protocol.RecentRouteSnapshot { | |
| 25 | + | return protocol.RecentRouteSnapshot{ | |
| 25 | 26 | Generation: 1, | |
| 26 | - | Active: ports.RouteRef{Key: 1, Generation: 1}, | |
| 27 | - | ActiveEntry: testRouteEntry(1, 1, "current", 1, ports.RouteKindLocal), | |
| 28 | - | Entries: []ports.RecentRouteEntry{ | |
| 29 | - | testRouteEntry(2, 1, "recent", 2, ports.RouteKindLocal), | |
| 30 | - | testRouteEntry(3, 1, "older", 3, ports.RouteKindLocal), | |
| 27 | + | Active: protocol.RouteRef{Key: 1, Generation: 1}, | |
| 28 | + | ActiveEntry: testRouteEntry(1, 1, "current", 1, protocol.RouteKindLocal), | |
| 29 | + | Entries: []protocol.RecentRouteEntry{ | |
| 30 | + | testRouteEntry(2, 1, "recent", 2, protocol.RouteKindLocal), | |
| 31 | + | testRouteEntry(3, 1, "older", 3, protocol.RouteKindLocal), | |
| 31 | 32 | }, | |
| 32 | 33 | } | |
| 33 | 34 | } | |
| @@ -232,10 +233,10 @@ func TestPaletteEntryPublishesEligibleNamedSessionResults(t *testing.T) { | |||
| 232 | 233 | d.inactive["purging"] = inactiveSession{name: "purging", createdAt: 13, incarnation: domain.IncarnationID{4}, state: ports.SessionDown, purging: true} | |
| 233 | 234 | d.inactive["broken"] = inactiveSession{name: "broken", createdAt: 14, incarnation: domain.IncarnationID{5}, state: ports.SessionBroken} | |
| 234 | 235 | d.inactive["degraded"] = inactiveSession{name: "degraded", createdAt: 15, incarnation: domain.IncarnationID{6}, state: ports.SessionDown, record: domain.CatalogueRecord{DegradedReason: "checkpoint unavailable"}} | |
| 235 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1, Entries: []ports.RecentRouteEntry{ | |
| 236 | - | testRouteEntry(1, 1, "purging", 4, ports.RouteKindLocal), | |
| 237 | - | testRouteEntry(2, 1, "broken", 5, ports.RouteKindLocal), | |
| 238 | - | testRouteEntry(3, 1, "degraded", 6, ports.RouteKindLocal), | |
| 236 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1, Entries: []protocol.RecentRouteEntry{ | |
| 237 | + | testRouteEntry(1, 1, "purging", 4, protocol.RouteKindLocal), | |
| 238 | + | testRouteEntry(2, 1, "broken", 5, protocol.RouteKindLocal), | |
| 239 | + | testRouteEntry(3, 1, "degraded", 6, protocol.RouteKindLocal), | |
| 239 | 240 | }}) | |
| 240 | 241 | ||
| 241 | 242 | d.enterPalette(current, ac) | |
| @@ -374,7 +375,7 @@ func TestPaletteJRSActivatesOnlyExactContextualHint(t *testing.T) { | |||
| 374 | 375 | p, release := newBlockingPTY(t) | |
| 375 | 376 | defer release() | |
| 376 | 377 | d, sess, ac, sends := newManualSessionWithPTYs(t, p) | |
| 377 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1, Active: ports.RouteRef{Key: 1, Generation: 1}}) | |
| 378 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1, Active: protocol.RouteRef{Key: 1, Generation: 1}}) | |
| 378 | 379 | ||
| 379 | 380 | d.handleInput(sess, ac, []byte("\x1b ")) | |
| 380 | 381 | awaitFrame(t, sends, ports.MsgOutput) | |
| @@ -412,7 +413,7 @@ func TestPaletteJRSUsesEffectiveOverrideOnly(t *testing.T) { | |||
| 412 | 413 | actionFrame := awaitFrame(t, sends, ports.MsgNavigateRecentRoute) | |
| 413 | 414 | action, err := ports.UnmarshalRouteNavigationAction(actionFrame.Payload) | |
| 414 | 415 | require.NoError(t, err) | |
| 415 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 1, Key: 2, Generation: 1}, action) | |
| 416 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 1, Key: 2, Generation: 1}, action) | |
| 416 | 417 | require.Same(t, current, ac.currentSession()) | |
| 417 | 418 | require.False(t, ac.overlays.paletteActive()) | |
| 418 | 419 | ||
| @@ -447,7 +448,7 @@ func TestPaletteIncludesExactRemoteCatalogTargetBesideSameNameLocalSession(t *te | |||
| 447 | 448 | d.remoteCatalog.status["user@arch"] = remoteHostFresh | |
| 448 | 449 | d.remoteCatalog.mu.Unlock() | |
| 449 | 450 | ||
| 450 | - | results := d.paletteResults(current, nil, ports.RecentRouteSnapshot{}) | |
| 451 | + | results := d.paletteResults(current, nil, protocol.RecentRouteSnapshot{}) | |
| 451 | 452 | var matching []palette.Result | |
| 452 | 453 | for _, result := range results { | |
| 453 | 454 | if result.DisplayText() == "Switch to session vev" || result.DisplayText() == "Switch to session vev@arch" { | |
| @@ -472,18 +473,18 @@ func TestPaletteQualifiesDaemonSessionForRemoteAttachment(t *testing.T) { | |||
| 472 | 473 | target.ephemeral = false | |
| 473 | 474 | target.incarnation = domain.SessionLifecycleID{42} | |
| 474 | 475 | ||
| 475 | - | results := d.paletteResults(current, nil, ports.RecentRouteSnapshot{ | |
| 476 | + | results := d.paletteResults(current, nil, protocol.RecentRouteSnapshot{ | |
| 476 | 477 | Generation: 1, | |
| 477 | - | Active: ports.RouteRef{Key: 1, Generation: 1}, | |
| 478 | - | ActiveEntry: ports.RecentRouteEntry{ | |
| 478 | + | Active: protocol.RouteRef{Key: 1, Generation: 1}, | |
| 479 | + | ActiveEntry: protocol.RecentRouteEntry{ | |
| 479 | 480 | Key: 1, Generation: 1, | |
| 480 | - | Target: ports.ExactSessionTarget{LifecycleID: current.incarnation, SessionName: "current"}, | |
| 481 | - | Name: "current", HostLabel: "user@remote-host", Kind: ports.RouteKindRemote, | |
| 481 | + | Target: protocol.ExactSessionTarget{LifecycleID: current.incarnation, SessionName: "current"}, | |
| 482 | + | Name: "current", HostLabel: "user@remote-host", Kind: protocol.RouteKindRemote, | |
| 482 | 483 | }, | |
| 483 | - | Entries: []ports.RecentRouteEntry{{ | |
| 484 | + | Entries: []protocol.RecentRouteEntry{{ | |
| 484 | 485 | Key: 2, Generation: 1, | |
| 485 | - | Target: ports.ExactSessionTarget{LifecycleID: target.incarnation, SessionName: "target"}, | |
| 486 | - | Name: "target", HostLabel: "user@remote-host", Kind: ports.RouteKindRemote, | |
| 486 | + | Target: protocol.ExactSessionTarget{LifecycleID: target.incarnation, SessionName: "target"}, | |
| 487 | + | Name: "target", HostLabel: "user@remote-host", Kind: protocol.RouteKindRemote, | |
| 487 | 488 | }}, | |
| 488 | 489 | }) | |
| 489 | 490 | ||
| @@ -496,7 +497,7 @@ func TestPaletteQualifiesDaemonSessionForRemoteAttachment(t *testing.T) { | |||
| 496 | 497 | require.Len(t, matching, 1) | |
| 497 | 498 | got, ok := matching[0].SessionTarget() | |
| 498 | 499 | require.True(t, ok) | |
| 499 | - | require.Equal(t, ports.ExactSessionTarget{LifecycleID: target.incarnation, SessionName: "target"}, got) | |
| 500 | + | require.Equal(t, protocol.ExactSessionTarget{LifecycleID: target.incarnation, SessionName: "target"}, got) | |
| 500 | 501 | } | |
| 501 | 502 | ||
| 502 | 503 | func TestPaletteMatchesRecentRemoteRouteToCatalog(t *testing.T) { | |
| @@ -536,15 +537,15 @@ func TestPaletteMatchesRecentRemoteRouteToCatalog(t *testing.T) { | |||
| 536 | 537 | } | |
| 537 | 538 | d.remoteCatalog.mu.Unlock() | |
| 538 | 539 | ||
| 539 | - | results := d.paletteResults(current, nil, ports.RecentRouteSnapshot{ | |
| 540 | + | results := d.paletteResults(current, nil, protocol.RecentRouteSnapshot{ | |
| 540 | 541 | Generation: 2, | |
| 541 | - | Entries: []ports.RecentRouteEntry{{ | |
| 542 | + | Entries: []protocol.RecentRouteEntry{{ | |
| 542 | 543 | Key: 3, Generation: 1, | |
| 543 | - | Target: ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "vev"}, | |
| 544 | - | Name: "vev", HostLabel: "arch", Kind: ports.RouteKindRemote, | |
| 544 | + | Target: protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "vev"}, | |
| 545 | + | Name: "vev", HostLabel: "arch", Kind: protocol.RouteKindRemote, | |
| 545 | 546 | }}, | |
| 546 | 547 | }) | |
| 547 | - | var actions []ports.RouteNavigationAction | |
| 548 | + | var actions []protocol.RouteNavigationAction | |
| 548 | 549 | var catalogEndpoints []string | |
| 549 | 550 | for _, result := range results { | |
| 550 | 551 | if result.DisplayText() != "Switch to session vev@arch" { | |
| @@ -558,7 +559,7 @@ func TestPaletteMatchesRecentRemoteRouteToCatalog(t *testing.T) { | |||
| 558 | 559 | require.True(t, ok) | |
| 559 | 560 | catalogEndpoints = append(catalogEndpoints, target.Endpoint) | |
| 560 | 561 | } | |
| 561 | - | require.Equal(t, []ports.RouteNavigationAction{{ | |
| 562 | + | require.Equal(t, []protocol.RouteNavigationAction{{ | |
| 562 | 563 | SnapshotGeneration: 2, Key: 3, Generation: 1, | |
| 563 | 564 | }}, actions) | |
| 564 | 565 | require.ElementsMatch(t, test.wantCatalogEndpoints, catalogEndpoints) | |
| @@ -720,21 +721,21 @@ func TestPaletteResultsDeduplicateByLifecycleAndKeepEqualLabels(t *testing.T) { | |||
| 720 | 721 | local := addControlSession(d, "vev", "tab-2", "pane-2") | |
| 721 | 722 | local.ephemeral = false | |
| 722 | 723 | local.incarnation = domain.SessionLifecycleID{2} | |
| 723 | - | remoteOne := ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{21}, SessionName: "vev"} | |
| 724 | - | remoteTwo := ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{22}, SessionName: "vev"} | |
| 725 | - | snapshot := ports.RecentRouteSnapshot{ | |
| 724 | + | remoteOne := protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{21}, SessionName: "vev"} | |
| 725 | + | remoteTwo := protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{22}, SessionName: "vev"} | |
| 726 | + | snapshot := protocol.RecentRouteSnapshot{ | |
| 726 | 727 | Generation: 2, | |
| 727 | - | Entries: []ports.RecentRouteEntry{ | |
| 728 | - | {Key: 1, Generation: 1, Target: ports.ExactSessionTarget{LifecycleID: current.incarnation, SessionName: "hi"}, Name: "hi", Kind: ports.RouteKindLocal}, | |
| 729 | - | {Key: 2, Generation: 1, Target: ports.ExactSessionTarget{LifecycleID: local.incarnation, SessionName: "vev"}, Name: "vev", Kind: ports.RouteKindLocal}, | |
| 730 | - | {Key: 3, Generation: 1, Target: remoteOne, Name: "vev", HostLabel: "arch", Kind: ports.RouteKindRemote}, | |
| 731 | - | {Key: 4, Generation: 1, Target: remoteTwo, Name: "vev", HostLabel: "arch", Kind: ports.RouteKindRemote}, | |
| 728 | + | Entries: []protocol.RecentRouteEntry{ | |
| 729 | + | {Key: 1, Generation: 1, Target: protocol.ExactSessionTarget{LifecycleID: current.incarnation, SessionName: "hi"}, Name: "hi", Kind: protocol.RouteKindLocal}, | |
| 730 | + | {Key: 2, Generation: 1, Target: protocol.ExactSessionTarget{LifecycleID: local.incarnation, SessionName: "vev"}, Name: "vev", Kind: protocol.RouteKindLocal}, | |
| 731 | + | {Key: 3, Generation: 1, Target: remoteOne, Name: "vev", HostLabel: "arch", Kind: protocol.RouteKindRemote}, | |
| 732 | + | {Key: 4, Generation: 1, Target: remoteTwo, Name: "vev", HostLabel: "arch", Kind: protocol.RouteKindRemote}, | |
| 732 | 733 | }, | |
| 733 | 734 | } | |
| 734 | 735 | ||
| 735 | 736 | results := d.paletteResults(current, nil, snapshot) | |
| 736 | - | var sessionTargets []ports.ExactSessionTarget | |
| 737 | - | var routeActions []ports.RouteNavigationAction | |
| 737 | + | var sessionTargets []protocol.ExactSessionTarget | |
| 738 | + | var routeActions []protocol.RouteNavigationAction | |
| 738 | 739 | for _, result := range results { | |
| 739 | 740 | if target, ok := result.SessionTarget(); ok { | |
| 740 | 741 | sessionTargets = append(sessionTargets, target) | |
| @@ -743,8 +744,8 @@ func TestPaletteResultsDeduplicateByLifecycleAndKeepEqualLabels(t *testing.T) { | |||
| 743 | 744 | routeActions = append(routeActions, action) | |
| 744 | 745 | } | |
| 745 | 746 | } | |
| 746 | - | require.Equal(t, []ports.ExactSessionTarget{{LifecycleID: local.incarnation, SessionName: "vev"}}, sessionTargets) | |
| 747 | - | require.Equal(t, []ports.RouteNavigationAction{ | |
| 747 | + | require.Equal(t, []protocol.ExactSessionTarget{{LifecycleID: local.incarnation, SessionName: "vev"}}, sessionTargets) | |
| 748 | + | require.Equal(t, []protocol.RouteNavigationAction{ | |
| 748 | 749 | {SnapshotGeneration: 2, Key: 3, Generation: 1}, | |
| 749 | 750 | {SnapshotGeneration: 2, Key: 4, Generation: 1}, | |
| 750 | 751 | }, routeActions) | |
| @@ -781,12 +782,12 @@ func TestPaletteLifecycleTargetRejectsSameNameReplacement(t *testing.T) { | |||
| 781 | 782 | func TestPaletteFuzzyRemoteRecentRouteSendsExactNavigationAction(t *testing.T) { | |
| 782 | 783 | d, current, ac, sends, releases := newRecentNavigationTestSessions(t) | |
| 783 | 784 | defer releaseAll(releases) | |
| 784 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 785 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 785 | 786 | Generation: 9, | |
| 786 | - | Active: ports.RouteRef{Key: 1, Generation: 1}, | |
| 787 | - | ActiveEntry: testRouteEntry(1, 1, current.name, 1, ports.RouteKindLocal), | |
| 788 | - | Entries: []ports.RecentRouteEntry{{ | |
| 789 | - | Key: 8, Generation: 4, Target: testRouteTarget("logs", 8), Name: "logs", HostLabel: "edge", Kind: ports.RouteKindRemote, | |
| 787 | + | Active: protocol.RouteRef{Key: 1, Generation: 1}, | |
| 788 | + | ActiveEntry: testRouteEntry(1, 1, current.name, 1, protocol.RouteKindLocal), | |
| 789 | + | Entries: []protocol.RecentRouteEntry{{ | |
| 790 | + | Key: 8, Generation: 4, Target: testRouteTarget("logs", 8), Name: "logs", HostLabel: "edge", Kind: protocol.RouteKindRemote, | |
| 790 | 791 | }}, | |
| 791 | 792 | }) | |
| 792 | 793 | token := beginRecentRoutePaletteEffect(t, d, current, ac) | |
| @@ -798,7 +799,7 @@ func TestPaletteFuzzyRemoteRecentRouteSendsExactNavigationAction(t *testing.T) { | |||
| 798 | 799 | actionFrame := awaitFrame(t, sends, ports.MsgNavigateRecentRoute) | |
| 799 | 800 | action, err := ports.UnmarshalRouteNavigationAction(actionFrame.Payload) | |
| 800 | 801 | require.NoError(t, err) | |
| 801 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 9, Key: 8, Generation: 4}, action) | |
| 802 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 9, Key: 8, Generation: 4}, action) | |
| 802 | 803 | require.False(t, ac.overlays.paletteActive()) | |
| 803 | 804 | } | |
| 804 | 805 | ||
| @@ -830,7 +831,7 @@ func TestPaletteJRSUsesCapturedRankAfterMRUChanges(t *testing.T) { | |||
| 830 | 831 | actionFrame := awaitFrame(t, sends, ports.MsgNavigateRecentRoute) | |
| 831 | 832 | action, err := ports.UnmarshalRouteNavigationAction(actionFrame.Payload) | |
| 832 | 833 | require.NoError(t, err) | |
| 833 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 1, Key: 2, Generation: 1}, action) | |
| 834 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 1, Key: 2, Generation: 1}, action) | |
| 834 | 835 | require.Same(t, current, ac.currentSession()) | |
| 835 | 836 | require.False(t, ac.overlays.paletteActive()) | |
| 836 | 837 | } | |
| @@ -861,11 +862,11 @@ func TestPaletteJRSDoesNotRevalidateTargetInDaemon(t *testing.T) { | |||
| 861 | 862 | p, release := newBlockingPTY(t) | |
| 862 | 863 | defer release() | |
| 863 | 864 | d, sess, ac, sends := newManualSessionWithPTYs(t, p) | |
| 864 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 865 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 865 | 866 | Generation: 7, | |
| 866 | - | Active: ports.RouteRef{Key: 1, Generation: 1}, | |
| 867 | - | ActiveEntry: testRouteEntry(1, 1, sess.name, 1, ports.RouteKindLocal), | |
| 868 | - | Entries: []ports.RecentRouteEntry{testRouteEntry(9, 4, "captured", 9, ports.RouteKindLocal)}, | |
| 867 | + | Active: protocol.RouteRef{Key: 1, Generation: 1}, | |
| 868 | + | ActiveEntry: testRouteEntry(1, 1, sess.name, 1, protocol.RouteKindLocal), | |
| 869 | + | Entries: []protocol.RecentRouteEntry{testRouteEntry(9, 4, "captured", 9, protocol.RouteKindLocal)}, | |
| 869 | 870 | }) | |
| 870 | 871 | ||
| 871 | 872 | validated := make(chan struct{}) | |
| @@ -891,7 +892,7 @@ func TestPaletteJRSDoesNotRevalidateTargetInDaemon(t *testing.T) { | |||
| 891 | 892 | actionFrame := awaitFrame(t, sends, ports.MsgNavigateRecentRoute) | |
| 892 | 893 | action, err := ports.UnmarshalRouteNavigationAction(actionFrame.Payload) | |
| 893 | 894 | require.NoError(t, err) | |
| 894 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 7, Key: 9, Generation: 4}, action) | |
| 895 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 7, Key: 9, Generation: 4}, action) | |
| 895 | 896 | require.False(t, ac.overlays.paletteActive()) | |
| 896 | 897 | } | |
| 897 | 898 | ||
M internal/usecase/daemon/parked_route.go +52 -51
| @@ -8,12 +8,13 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | ) | |
| 12 | 13 | ||
| 13 | 14 | const parkedRouteLeaseTTL = 15 * time.Minute | |
| 14 | 15 | ||
| 15 | 16 | type parkedRouteLease struct { | |
| 16 | - | id ports.ParkedRouteLeaseID | |
| 17 | + | id protocol.ParkedRouteLeaseID | |
| 17 | 18 | generation uint64 | |
| 18 | 19 | transport transportSnapshot | |
| 19 | 20 | expiresAt time.Time | |
| @@ -24,14 +25,14 @@ type parkedRouteLease struct { | |||
| 24 | 25 | expired bool | |
| 25 | 26 | } | |
| 26 | 27 | ||
| 27 | - | func (lease *parkedRouteLease) matches(id ports.ParkedRouteLeaseID, generation uint64, transport transportSnapshot) bool { | |
| 28 | + | func (lease *parkedRouteLease) matches(id protocol.ParkedRouteLeaseID, generation uint64, transport transportSnapshot) bool { | |
| 28 | 29 | return lease != nil && lease.id == id && lease.generation == generation && lease.transport == transport | |
| 29 | 30 | } | |
| 30 | 31 | ||
| 31 | - | func newParkedRouteLeaseID() (ports.ParkedRouteLeaseID, error) { | |
| 32 | - | var id ports.ParkedRouteLeaseID | |
| 32 | + | func newParkedRouteLeaseID() (protocol.ParkedRouteLeaseID, error) { | |
| 33 | + | var id protocol.ParkedRouteLeaseID | |
| 33 | 34 | if _, err := io.ReadFull(rand.Reader, id[:]); err != nil { | |
| 34 | - | return ports.ParkedRouteLeaseID{}, err | |
| 35 | + | return protocol.ParkedRouteLeaseID{}, err | |
| 35 | 36 | } | |
| 36 | 37 | return id, nil | |
| 37 | 38 | } | |
| @@ -50,17 +51,17 @@ func stopParkedRouteLeaseLocked(lease *parkedRouteLease) { | |||
| 50 | 51 | } | |
| 51 | 52 | } | |
| 52 | 53 | ||
| 53 | - | func (d *Daemon) armParkedRoute(effect *attachmentEffect) (ports.ParkedRouteLeaseID, error) { | |
| 54 | + | func (d *Daemon) armParkedRoute(effect *attachmentEffect) (protocol.ParkedRouteLeaseID, error) { | |
| 54 | 55 | if !effect.current() { | |
| 55 | - | return ports.ParkedRouteLeaseID{}, errAttachmentTransition | |
| 56 | + | return protocol.ParkedRouteLeaseID{}, errAttachmentTransition | |
| 56 | 57 | } | |
| 57 | 58 | ac := effect.ac | |
| 58 | - | if ac == nil || ac.navigationCapabilities&ports.NavigationCapabilityHomePicker == 0 { | |
| 59 | - | return ports.ParkedRouteLeaseID{}, errAttachmentTransition | |
| 59 | + | if ac == nil || ac.navigationCapabilities&protocol.NavigationCapabilityHomePicker == 0 { | |
| 60 | + | return protocol.ParkedRouteLeaseID{}, errAttachmentTransition | |
| 60 | 61 | } | |
| 61 | 62 | id, err := newParkedRouteLeaseID() | |
| 62 | 63 | if err != nil { | |
| 63 | - | return ports.ParkedRouteLeaseID{}, err | |
| 64 | + | return protocol.ParkedRouteLeaseID{}, err | |
| 64 | 65 | } | |
| 65 | 66 | lease := &parkedRouteLease{ | |
| 66 | 67 | id: id, generation: effect.generation, transport: effect.transport, | |
| @@ -123,30 +124,30 @@ func (ac *attachedClient) clearParkedRoute() { | |||
| 123 | 124 | ac.parkedRouteMu.Unlock() | |
| 124 | 125 | } | |
| 125 | 126 | ||
| 126 | - | func (ac *attachedClient) parkedRouteStatus(token attachmentCapability, id ports.ParkedRouteLeaseID, now time.Time, suspended bool) ports.ParkedRouteStatus { | |
| 127 | + | func (ac *attachedClient) parkedRouteStatus(token attachmentCapability, id protocol.ParkedRouteLeaseID, now time.Time, suspended bool) protocol.ParkedRouteStatus { | |
| 127 | 128 | if ac == nil || !token.current() { | |
| 128 | - | return ports.ParkedRouteRejected | |
| 129 | + | return protocol.ParkedRouteRejected | |
| 129 | 130 | } | |
| 130 | 131 | ac.parkedRouteMu.Lock() | |
| 131 | 132 | defer ac.parkedRouteMu.Unlock() | |
| 132 | 133 | lease := ac.parkedRoute | |
| 133 | 134 | if !lease.matches(id, token.generation, token.transport) { | |
| 134 | - | return ports.ParkedRouteRejected | |
| 135 | + | return protocol.ParkedRouteRejected | |
| 135 | 136 | } | |
| 136 | 137 | if !now.Before(lease.expiresAt) { | |
| 137 | 138 | stopParkedRouteLeaseLocked(lease) | |
| 138 | 139 | ac.parkedRoute = nil | |
| 139 | 140 | ac.parkedRouteOutput.Store(false) | |
| 140 | 141 | ac.parkedRouteFullPending.Store(false) | |
| 141 | - | return ports.ParkedRouteExpired | |
| 142 | + | return protocol.ParkedRouteExpired | |
| 142 | 143 | } | |
| 143 | 144 | if lease.suspended != suspended { | |
| 144 | - | return ports.ParkedRouteRejected | |
| 145 | + | return protocol.ParkedRouteRejected | |
| 145 | 146 | } | |
| 146 | 147 | return 0 | |
| 147 | 148 | } | |
| 148 | 149 | ||
| 149 | - | func (ac *attachedClient) prepareParkedRoute(token attachmentCapability, id ports.ParkedRouteLeaseID, now time.Time) ports.ParkedRouteStatus { | |
| 150 | + | func (ac *attachedClient) prepareParkedRoute(token attachmentCapability, id protocol.ParkedRouteLeaseID, now time.Time) protocol.ParkedRouteStatus { | |
| 150 | 151 | if status := ac.parkedRouteStatus(token, id, now, false); status != 0 { | |
| 151 | 152 | return status | |
| 152 | 153 | } | |
| @@ -154,14 +155,14 @@ func (ac *attachedClient) prepareParkedRoute(token attachmentCapability, id port | |||
| 154 | 155 | defer ac.parkedRouteMu.Unlock() | |
| 155 | 156 | lease := ac.parkedRoute | |
| 156 | 157 | if !lease.matches(id, token.generation, token.transport) || lease.suspended { | |
| 157 | - | return ports.ParkedRouteRejected | |
| 158 | + | return protocol.ParkedRouteRejected | |
| 158 | 159 | } | |
| 159 | 160 | lease.suspended = true | |
| 160 | 161 | ac.parkedRouteOutput.Store(true) | |
| 161 | 162 | return 0 | |
| 162 | 163 | } | |
| 163 | 164 | ||
| 164 | - | func (ac *attachedClient) consumeParkedRoute(token attachmentCapability, id ports.ParkedRouteLeaseID, now time.Time) ports.ParkedRouteStatus { | |
| 165 | + | func (ac *attachedClient) consumeParkedRoute(token attachmentCapability, id protocol.ParkedRouteLeaseID, now time.Time) protocol.ParkedRouteStatus { | |
| 165 | 166 | if status := ac.parkedRouteStatus(token, id, now, true); status != 0 { | |
| 166 | 167 | return status | |
| 167 | 168 | } | |
| @@ -169,43 +170,43 @@ func (ac *attachedClient) consumeParkedRoute(token attachmentCapability, id port | |||
| 169 | 170 | defer ac.parkedRouteMu.Unlock() | |
| 170 | 171 | lease := ac.parkedRoute | |
| 171 | 172 | if !lease.matches(id, token.generation, token.transport) || !lease.suspended || lease.inFlight { | |
| 172 | - | return ports.ParkedRouteRejected | |
| 173 | + | return protocol.ParkedRouteRejected | |
| 173 | 174 | } | |
| 174 | 175 | stopParkedRouteLeaseLocked(lease) | |
| 175 | 176 | ac.parkedRoute = nil | |
| 176 | 177 | return 0 | |
| 177 | 178 | } | |
| 178 | 179 | ||
| 179 | - | func (ac *attachedClient) beginParkedRouteSwitch(token attachmentCapability, id ports.ParkedRouteLeaseID, now time.Time) ports.ParkedRouteStatus { | |
| 180 | + | func (ac *attachedClient) beginParkedRouteSwitch(token attachmentCapability, id protocol.ParkedRouteLeaseID, now time.Time) protocol.ParkedRouteStatus { | |
| 180 | 181 | if ac == nil || !token.current() { | |
| 181 | - | return ports.ParkedRouteRejected | |
| 182 | + | return protocol.ParkedRouteRejected | |
| 182 | 183 | } | |
| 183 | 184 | ac.parkedRouteMu.Lock() | |
| 184 | 185 | defer ac.parkedRouteMu.Unlock() | |
| 185 | 186 | lease := ac.parkedRoute | |
| 186 | 187 | if !lease.matches(id, token.generation, token.transport) || !lease.suspended || lease.inFlight { | |
| 187 | - | return ports.ParkedRouteRejected | |
| 188 | + | return protocol.ParkedRouteRejected | |
| 188 | 189 | } | |
| 189 | 190 | if lease.expired || !now.Before(lease.expiresAt) { | |
| 190 | 191 | stopParkedRouteLeaseLocked(lease) | |
| 191 | 192 | ac.parkedRoute = nil | |
| 192 | 193 | ac.parkedRouteOutput.Store(false) | |
| 193 | 194 | ac.parkedRouteFullPending.Store(false) | |
| 194 | - | return ports.ParkedRouteExpired | |
| 195 | + | return protocol.ParkedRouteExpired | |
| 195 | 196 | } | |
| 196 | 197 | lease.inFlight = true | |
| 197 | 198 | return 0 | |
| 198 | 199 | } | |
| 199 | 200 | ||
| 200 | - | func (ac *attachedClient) rejectParkedRouteSwitch(token attachmentCapability, id ports.ParkedRouteLeaseID, now time.Time) ports.ParkedRouteStatus { | |
| 201 | + | func (ac *attachedClient) rejectParkedRouteSwitch(token attachmentCapability, id protocol.ParkedRouteLeaseID, now time.Time) protocol.ParkedRouteStatus { | |
| 201 | 202 | if ac == nil { | |
| 202 | - | return ports.ParkedRouteRejected | |
| 203 | + | return protocol.ParkedRouteRejected | |
| 203 | 204 | } | |
| 204 | 205 | ac.parkedRouteMu.Lock() | |
| 205 | 206 | defer ac.parkedRouteMu.Unlock() | |
| 206 | 207 | lease := ac.parkedRoute | |
| 207 | 208 | if !lease.matches(id, token.generation, token.transport) || !lease.inFlight { | |
| 208 | - | return ports.ParkedRouteRejected | |
| 209 | + | return protocol.ParkedRouteRejected | |
| 209 | 210 | } | |
| 210 | 211 | lease.inFlight = false | |
| 211 | 212 | if lease.expired || !now.Before(lease.expiresAt) { | |
| @@ -213,20 +214,20 @@ func (ac *attachedClient) rejectParkedRouteSwitch(token attachmentCapability, id | |||
| 213 | 214 | ac.parkedRoute = nil | |
| 214 | 215 | ac.parkedRouteOutput.Store(false) | |
| 215 | 216 | ac.parkedRouteFullPending.Store(false) | |
| 216 | - | return ports.ParkedRouteExpired | |
| 217 | + | return protocol.ParkedRouteExpired | |
| 217 | 218 | } | |
| 218 | 219 | return 0 | |
| 219 | 220 | } | |
| 220 | 221 | ||
| 221 | - | func (ac *attachedClient) consumePublishedParkedRoute(previous, published attachmentCapability, id ports.ParkedRouteLeaseID) ports.ParkedRouteStatus { | |
| 222 | + | func (ac *attachedClient) consumePublishedParkedRoute(previous, published attachmentCapability, id protocol.ParkedRouteLeaseID) protocol.ParkedRouteStatus { | |
| 222 | 223 | if ac == nil || published.ac != ac || !published.current() { | |
| 223 | - | return ports.ParkedRouteRejected | |
| 224 | + | return protocol.ParkedRouteRejected | |
| 224 | 225 | } | |
| 225 | 226 | ac.parkedRouteMu.Lock() | |
| 226 | 227 | defer ac.parkedRouteMu.Unlock() | |
| 227 | 228 | lease := ac.parkedRoute | |
| 228 | 229 | if !lease.matches(id, previous.generation, previous.transport) || !lease.suspended || !lease.inFlight { | |
| 229 | - | return ports.ParkedRouteRejected | |
| 230 | + | return protocol.ParkedRouteRejected | |
| 230 | 231 | } | |
| 231 | 232 | // Expiry is checked when the request is admitted. Once publication starts, | |
| 232 | 233 | // the accepted request must commit atomically instead of turning a completed | |
| @@ -236,7 +237,7 @@ func (ac *attachedClient) consumePublishedParkedRoute(previous, published attach | |||
| 236 | 237 | return 0 | |
| 237 | 238 | } | |
| 238 | 239 | ||
| 239 | - | func parkedRouteResponseFrame(response ports.ParkedRouteResponse) (ports.Frame, error) { | |
| 240 | + | func parkedRouteResponseFrame(response protocol.ParkedRouteResponse) (ports.Frame, error) { | |
| 240 | 241 | payload := ports.MarshalParkedRouteResponse(response) | |
| 241 | 242 | if payload == nil { | |
| 242 | 243 | return ports.Frame{}, errAttachmentTransition | |
| @@ -244,7 +245,7 @@ func parkedRouteResponseFrame(response ports.ParkedRouteResponse) (ports.Frame, | |||
| 244 | 245 | return ports.Frame{Type: ports.MsgParkedRouteResponse, Payload: payload}, nil | |
| 245 | 246 | } | |
| 246 | 247 | ||
| 247 | - | func (d *Daemon) sendParkedRouteResponse(effect *attachmentEffect, response ports.ParkedRouteResponse) error { | |
| 248 | + | func (d *Daemon) sendParkedRouteResponse(effect *attachmentEffect, response protocol.ParkedRouteResponse) error { | |
| 248 | 249 | frame, err := parkedRouteResponseFrame(response) | |
| 249 | 250 | if err != nil { | |
| 250 | 251 | return err | |
| @@ -254,7 +255,7 @@ func (d *Daemon) sendParkedRouteResponse(effect *attachmentEffect, response port | |||
| 254 | 255 | ||
| 255 | 256 | // sendParkedRouteResponseLocked preserves response -> full-output ordering. | |
| 256 | 257 | // Caller holds ac.sendMu and keeps parkedRouteOutput set through this send. | |
| 257 | - | func (d *Daemon) sendParkedRouteResponseLocked(ac *attachedClient, expected transportSnapshot, response ports.ParkedRouteResponse) error { | |
| 258 | + | func (d *Daemon) sendParkedRouteResponseLocked(ac *attachedClient, expected transportSnapshot, response protocol.ParkedRouteResponse) error { | |
| 258 | 259 | frame, err := parkedRouteResponseFrame(response) | |
| 259 | 260 | if err != nil { | |
| 260 | 261 | return err | |
| @@ -283,7 +284,7 @@ func (d *Daemon) parkedRouteResponseFailed(effect *attachmentEffect) { | |||
| 283 | 284 | launch() | |
| 284 | 285 | } | |
| 285 | 286 | ||
| 286 | - | func (d *Daemon) respondParkedRoute(effect *attachmentEffect, response ports.ParkedRouteResponse) bool { | |
| 287 | + | func (d *Daemon) respondParkedRoute(effect *attachmentEffect, response protocol.ParkedRouteResponse) bool { | |
| 287 | 288 | if effect == nil || effect.ac == nil { | |
| 288 | 289 | return false | |
| 289 | 290 | } | |
| @@ -307,35 +308,35 @@ func (d *Daemon) respondParkedRoute(effect *attachmentEffect, response ports.Par | |||
| 307 | 308 | return true | |
| 308 | 309 | } | |
| 309 | 310 | ||
| 310 | - | func (d *Daemon) handleParkedRouteRequest(effect *attachmentEffect, request ports.ParkedRouteRequest) { | |
| 311 | - | if ports.ValidateParkedRouteRequest(request) != nil || !effect.current() || effect.ac == nil { | |
| 311 | + | func (d *Daemon) handleParkedRouteRequest(effect *attachmentEffect, request protocol.ParkedRouteRequest) { | |
| 312 | + | if protocol.ValidateParkedRouteRequest(request) != nil || !effect.current() || effect.ac == nil { | |
| 312 | 313 | return | |
| 313 | 314 | } | |
| 314 | 315 | capability := effect.capability() | |
| 315 | 316 | switch request.Action { | |
| 316 | - | case ports.ParkedRoutePrepare: | |
| 317 | + | case protocol.ParkedRoutePrepare: | |
| 317 | 318 | status := effect.ac.prepareParkedRoute(capability, request.LeaseID, d.clock.Now()) | |
| 318 | 319 | if status == 0 { | |
| 319 | - | status = ports.ParkedRouteReady | |
| 320 | + | status = protocol.ParkedRouteReady | |
| 320 | 321 | } | |
| 321 | - | d.respondParkedRoute(effect, ports.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) | |
| 322 | - | case ports.ParkedRouteResume: | |
| 322 | + | d.respondParkedRoute(effect, protocol.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) | |
| 323 | + | case protocol.ParkedRouteResume: | |
| 323 | 324 | d.resumeParkedRoute(effect, request) | |
| 324 | - | case ports.ParkedRouteSwitch: | |
| 325 | + | case protocol.ParkedRouteSwitch: | |
| 325 | 326 | d.switchParkedRoute(effect, request) | |
| 326 | 327 | } | |
| 327 | 328 | } | |
| 328 | 329 | ||
| 329 | - | func (d *Daemon) resumeParkedRoute(effect *attachmentEffect, request ports.ParkedRouteRequest) { | |
| 330 | + | func (d *Daemon) resumeParkedRoute(effect *attachmentEffect, request protocol.ParkedRouteRequest) { | |
| 330 | 331 | capability := effect.capability() | |
| 331 | 332 | status := effect.ac.consumeParkedRoute(capability, request.LeaseID, d.clock.Now()) | |
| 332 | 333 | if status != 0 { | |
| 333 | - | d.respondParkedRoute(effect, ports.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) | |
| 334 | + | d.respondParkedRoute(effect, protocol.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) | |
| 334 | 335 | return | |
| 335 | 336 | } | |
| 336 | 337 | ac := effect.ac | |
| 337 | 338 | ac.sendMu.Lock() | |
| 338 | - | err := d.sendParkedRouteResponseLocked(ac, effect.transport, ports.ParkedRouteResponse{RequestID: request.RequestID, Status: ports.ParkedRouteResumed}) | |
| 339 | + | err := d.sendParkedRouteResponseLocked(ac, effect.transport, protocol.ParkedRouteResponse{RequestID: request.RequestID, Status: protocol.ParkedRouteResumed}) | |
| 339 | 340 | if err == nil { | |
| 340 | 341 | ac.releaseParkedOutputLocked() | |
| 341 | 342 | } | |
| @@ -349,21 +350,21 @@ func (d *Daemon) resumeParkedRoute(effect *attachmentEffect, request ports.Parke | |||
| 349 | 350 | } | |
| 350 | 351 | } | |
| 351 | 352 | ||
| 352 | - | func (d *Daemon) rejectParkedRouteSwitch(effect *attachmentEffect, request ports.ParkedRouteRequest, fallback ports.ParkedRouteStatus) { | |
| 353 | + | func (d *Daemon) rejectParkedRouteSwitch(effect *attachmentEffect, request protocol.ParkedRouteRequest, fallback protocol.ParkedRouteStatus) { | |
| 353 | 354 | capability := effect.capability() | |
| 354 | 355 | status := effect.ac.rejectParkedRouteSwitch(capability, request.LeaseID, d.clock.Now()) | |
| 355 | 356 | if status == 0 { | |
| 356 | 357 | status = fallback | |
| 357 | 358 | } | |
| 358 | - | if d.respondParkedRoute(effect, ports.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) && status == ports.ParkedRouteExpired { | |
| 359 | + | if d.respondParkedRoute(effect, protocol.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) && status == protocol.ParkedRouteExpired { | |
| 359 | 360 | _ = effect.ac.closeCapturedTransport(effect.transport.transport) | |
| 360 | 361 | } | |
| 361 | 362 | } | |
| 362 | 363 | ||
| 363 | - | func (d *Daemon) switchParkedRoute(effect *attachmentEffect, request ports.ParkedRouteRequest) { | |
| 364 | + | func (d *Daemon) switchParkedRoute(effect *attachmentEffect, request protocol.ParkedRouteRequest) { | |
| 364 | 365 | capability := effect.capability() | |
| 365 | 366 | if status := effect.ac.beginParkedRouteSwitch(capability, request.LeaseID, d.clock.Now()); status != 0 { | |
| 366 | - | if d.respondParkedRoute(effect, ports.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) && status == ports.ParkedRouteExpired { | |
| 367 | + | if d.respondParkedRoute(effect, protocol.ParkedRouteResponse{RequestID: request.RequestID, Status: status}) && status == protocol.ParkedRouteExpired { | |
| 367 | 368 | _ = effect.ac.closeCapturedTransport(effect.transport.transport) | |
| 368 | 369 | } | |
| 369 | 370 | return | |
| @@ -374,13 +375,13 @@ func (d *Daemon) switchParkedRoute(effect *attachmentEffect, request ports.Parke | |||
| 374 | 375 | ctx = context.Background() | |
| 375 | 376 | } | |
| 376 | 377 | if err := d.waitForParkedTargetRestore(ctx, target.SessionName); err != nil { | |
| 377 | - | d.rejectParkedRouteSwitch(effect, request, ports.ParkedRouteStaleTarget) | |
| 378 | + | d.rejectParkedRouteSwitch(effect, request, protocol.ParkedRouteStaleTarget) | |
| 378 | 379 | return | |
| 379 | 380 | } | |
| 380 | 381 | ||
| 381 | 382 | transition, targetSession, err := d.transitionParkedRouteTarget(effect, target) | |
| 382 | 383 | if err != nil { | |
| 383 | - | d.rejectParkedRouteSwitch(effect, request, ports.ParkedRouteStaleTarget) | |
| 384 | + | d.rejectParkedRouteSwitch(effect, request, protocol.ParkedRouteStaleTarget) | |
| 384 | 385 | return | |
| 385 | 386 | } | |
| 386 | 387 | if status := effect.ac.consumePublishedParkedRoute(capability, transition.published, request.LeaseID); status != 0 { | |
| @@ -395,7 +396,7 @@ func (d *Daemon) switchParkedRoute(effect *attachmentEffect, request ports.Parke | |||
| 395 | 396 | freshCapability := fresh.capability() | |
| 396 | 397 | ac := effect.ac | |
| 397 | 398 | ac.sendMu.Lock() | |
| 398 | - | responseErr := d.sendParkedRouteResponseLocked(ac, freshCapability.transport, ports.ParkedRouteResponse{RequestID: request.RequestID, Status: ports.ParkedRouteSwitched}) | |
| 399 | + | responseErr := d.sendParkedRouteResponseLocked(ac, freshCapability.transport, protocol.ParkedRouteResponse{RequestID: request.RequestID, Status: protocol.ParkedRouteSwitched}) | |
| 399 | 400 | if responseErr == nil { | |
| 400 | 401 | ac.releaseParkedOutputLocked() | |
| 401 | 402 | } | |
M internal/usecase/daemon/parked_route_test.go +36 -35
| @@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | "github.com/bnema/vev/internal/domain" | |
| 14 | 14 | "github.com/bnema/vev/internal/ports" | |
| 15 | 15 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 16 | + | "github.com/bnema/vev/internal/protocol" | |
| 16 | 17 | ) | |
| 17 | 18 | ||
| 18 | 19 | type parkedRouteFailTransport struct{} | |
| @@ -61,31 +62,31 @@ func (c *parkedRouteClock) setNow(now time.Time) { | |||
| 61 | 62 | c.mu.Unlock() | |
| 62 | 63 | } | |
| 63 | 64 | ||
| 64 | - | func armAndPrepareParkedRoute(t *testing.T, d *Daemon, source *session, ac *attachedClient, sends chan ports.Frame) ports.ParkedRouteLeaseID { | |
| 65 | + | func armAndPrepareParkedRoute(t *testing.T, d *Daemon, source *session, ac *attachedClient, sends chan ports.Frame) protocol.ParkedRouteLeaseID { | |
| 65 | 66 | t.Helper() | |
| 66 | - | ac.navigationCapabilities |= ports.NavigationCapabilityHomePicker | |
| 67 | + | ac.navigationCapabilities |= protocol.NavigationCapabilityHomePicker | |
| 67 | 68 | token := source.captureAttachmentCapability(ac, ac.transport()) | |
| 68 | 69 | effect, admitted := ac.beginAttachmentEffect(token) | |
| 69 | 70 | require.True(t, admitted) | |
| 70 | - | require.NoError(t, d.sendNavigationActionForAttachment(effect, ports.NavigationOpenHomePicker)) | |
| 71 | + | require.NoError(t, d.sendNavigationActionForAttachment(effect, protocol.NavigationOpenHomePicker)) | |
| 71 | 72 | effect.End() | |
| 72 | 73 | directiveFrame := awaitFrame(t, sends, ports.MsgNavigationAction) | |
| 73 | 74 | directive, err := ports.UnmarshalNavigationDirective(directiveFrame.Payload) | |
| 74 | 75 | require.NoError(t, err) | |
| 75 | 76 | ||
| 76 | - | prepare := ports.ParkedRouteRequest{RequestID: 1, LeaseID: directive.LeaseID, Action: ports.ParkedRoutePrepare} | |
| 77 | + | prepare := protocol.ParkedRouteRequest{RequestID: 1, LeaseID: directive.LeaseID, Action: protocol.ParkedRoutePrepare} | |
| 77 | 78 | require.False(t, d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(prepare)})) | |
| 78 | 79 | readyFrame := awaitFrame(t, sends, ports.MsgParkedRouteResponse) | |
| 79 | 80 | ready, err := ports.UnmarshalParkedRouteResponse(readyFrame.Payload) | |
| 80 | 81 | require.NoError(t, err) | |
| 81 | - | require.Equal(t, ports.ParkedRouteResponse{RequestID: 1, Status: ports.ParkedRouteReady}, ready) | |
| 82 | + | require.Equal(t, protocol.ParkedRouteResponse{RequestID: 1, Status: protocol.ParkedRouteReady}, ready) | |
| 82 | 83 | return directive.LeaseID | |
| 83 | 84 | } | |
| 84 | 85 | ||
| 85 | 86 | func TestParkedRouteSwitchesExactLiveTargetOnRetainedTransport(t *testing.T) { | |
| 86 | 87 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 87 | 88 | defer releaseAll(releases) | |
| 88 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 89 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 89 | 90 | ||
| 90 | 91 | targetLifecycle := domain.SessionLifecycleID{7} | |
| 91 | 92 | target := &session{ | |
| @@ -97,7 +98,7 @@ func TestParkedRouteSwitchesExactLiveTargetOnRetainedTransport(t *testing.T) { | |||
| 97 | 98 | d.mu.Lock() | |
| 98 | 99 | d.sessions[target.id] = target | |
| 99 | 100 | d.mu.Unlock() | |
| 100 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 101 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 101 | 102 | ||
| 102 | 103 | leaseID := armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 103 | 104 | require.True(t, ac.parkedRouteOutput.Load()) | |
| @@ -106,7 +107,7 @@ func TestParkedRouteSwitchesExactLiveTargetOnRetainedTransport(t *testing.T) { | |||
| 106 | 107 | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: targetLifecycle, | |
| 107 | 108 | SessionName: "target", LiveTabID: domain.TabStableID(target.tabs[0].stableID), | |
| 108 | 109 | } | |
| 109 | - | switchRequest := ports.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: ports.ParkedRouteSwitch, Target: &targetRequest} | |
| 110 | + | switchRequest := protocol.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: protocol.ParkedRouteSwitch, Target: &targetRequest} | |
| 110 | 111 | require.False(t, d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(switchRequest)})) | |
| 111 | 112 | ||
| 112 | 113 | require.Same(t, target, ac.currentAttachmentSession()) | |
| @@ -114,7 +115,7 @@ func TestParkedRouteSwitchesExactLiveTargetOnRetainedTransport(t *testing.T) { | |||
| 114 | 115 | responseFrame := awaitFrame(t, sends, ports.MsgParkedRouteResponse) | |
| 115 | 116 | response, err := ports.UnmarshalParkedRouteResponse(responseFrame.Payload) | |
| 116 | 117 | require.NoError(t, err) | |
| 117 | - | require.Equal(t, ports.ParkedRouteResponse{RequestID: 2, Status: ports.ParkedRouteSwitched}, response) | |
| 118 | + | require.Equal(t, protocol.ParkedRouteResponse{RequestID: 2, Status: protocol.ParkedRouteSwitched}, response) | |
| 118 | 119 | } | |
| 119 | 120 | ||
| 120 | 121 | func TestParkedRouteSwitchAcceptedBeforeLeaseExpiryCommitsAtomically(t *testing.T) { | |
| @@ -122,7 +123,7 @@ func TestParkedRouteSwitchAcceptedBeforeLeaseExpiryCommitsAtomically(t *testing. | |||
| 122 | 123 | defer releaseAll(releases) | |
| 123 | 124 | clock := &parkedRouteClock{} | |
| 124 | 125 | d.clock = clock | |
| 125 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 126 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 126 | 127 | ||
| 127 | 128 | targetLifecycle := domain.SessionLifecycleID{7} | |
| 128 | 129 | target := &session{ | |
| @@ -134,7 +135,7 @@ func TestParkedRouteSwitchAcceptedBeforeLeaseExpiryCommitsAtomically(t *testing. | |||
| 134 | 135 | d.mu.Lock() | |
| 135 | 136 | d.sessions[target.id] = target | |
| 136 | 137 | d.mu.Unlock() | |
| 137 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 138 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 138 | 139 | ||
| 139 | 140 | leaseID := armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 140 | 141 | d.afterAttachmentEffectsFrozen = func() { | |
| @@ -145,21 +146,21 @@ func TestParkedRouteSwitchAcceptedBeforeLeaseExpiryCommitsAtomically(t *testing. | |||
| 145 | 146 | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: targetLifecycle, | |
| 146 | 147 | SessionName: "target", LiveTabID: domain.TabStableID(target.tabs[0].stableID), | |
| 147 | 148 | } | |
| 148 | - | switchRequest := ports.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: ports.ParkedRouteSwitch, Target: &targetRequest} | |
| 149 | + | switchRequest := protocol.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: protocol.ParkedRouteSwitch, Target: &targetRequest} | |
| 149 | 150 | d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(switchRequest)}) | |
| 150 | 151 | ||
| 151 | 152 | require.Same(t, target, ac.currentAttachmentSession()) | |
| 152 | 153 | responseFrame := awaitFrame(t, sends, ports.MsgParkedRouteResponse) | |
| 153 | 154 | response, err := ports.UnmarshalParkedRouteResponse(responseFrame.Payload) | |
| 154 | 155 | require.NoError(t, err) | |
| 155 | - | require.Equal(t, ports.ParkedRouteSwitched, response.Status) | |
| 156 | + | require.Equal(t, protocol.ParkedRouteSwitched, response.Status) | |
| 156 | 157 | } | |
| 157 | 158 | ||
| 158 | 159 | func TestParkedRouteRestoresExactStoppedTargetWithDaemonEnvironment(t *testing.T) { | |
| 159 | 160 | d := newTestDaemon(t, newFactory(t, newQuietPTY()), stubClock{}) | |
| 160 | 161 | d.baseEnv = []string{"OWNER=daemon"} | |
| 161 | 162 | source, ac, sends := addRemoteRefreshPickerOwner(t, d, "source") | |
| 162 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 163 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 163 | 164 | source.mu.Lock() | |
| 164 | 165 | source.env = []string{"OWNER=source"} | |
| 165 | 166 | source.mu.Unlock() | |
| @@ -175,7 +176,7 @@ func TestParkedRouteRestoresExactStoppedTargetWithDaemonEnvironment(t *testing.T | |||
| 175 | 176 | }, | |
| 176 | 177 | } | |
| 177 | 178 | d.mu.Unlock() | |
| 178 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 179 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 179 | 180 | ||
| 180 | 181 | leaseID := armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 181 | 182 | ||
| @@ -183,7 +184,7 @@ func TestParkedRouteRestoresExactStoppedTargetWithDaemonEnvironment(t *testing.T | |||
| 183 | 184 | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: lifecycle, | |
| 184 | 185 | SessionName: "stopped", Stopped: true, StoppedTab: domain.NewStableTabSelector("tab-b"), | |
| 185 | 186 | } | |
| 186 | - | switchRequest := ports.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: ports.ParkedRouteSwitch, Target: &target} | |
| 187 | + | switchRequest := protocol.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: protocol.ParkedRouteSwitch, Target: &target} | |
| 187 | 188 | d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(switchRequest)}) | |
| 188 | 189 | ||
| 189 | 190 | restored := ac.currentAttachmentSession() | |
| @@ -199,8 +200,8 @@ func TestParkedRouteRestoresExactStoppedTargetWithDaemonEnvironment(t *testing.T | |||
| 199 | 200 | func TestParkedRouteStaleTargetLeavesSourceResumable(t *testing.T) { | |
| 200 | 201 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 201 | 202 | defer releaseAll(releases) | |
| 202 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 203 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 203 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 204 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 204 | 205 | ||
| 205 | 206 | leaseID := armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 206 | 207 | ||
| @@ -208,21 +209,21 @@ func TestParkedRouteStaleTargetLeavesSourceResumable(t *testing.T) { | |||
| 208 | 209 | Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: domain.SessionLifecycleID{9}, | |
| 209 | 210 | SessionName: "missing", LiveTabID: "tab-1", | |
| 210 | 211 | } | |
| 211 | - | switchRequest := ports.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: ports.ParkedRouteSwitch, Target: &missing} | |
| 212 | + | switchRequest := protocol.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: protocol.ParkedRouteSwitch, Target: &missing} | |
| 212 | 213 | d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(switchRequest)}) | |
| 213 | 214 | staleFrame := awaitFrame(t, sends, ports.MsgParkedRouteResponse) | |
| 214 | 215 | stale, err := ports.UnmarshalParkedRouteResponse(staleFrame.Payload) | |
| 215 | 216 | require.NoError(t, err) | |
| 216 | - | require.Equal(t, ports.ParkedRouteStaleTarget, stale.Status) | |
| 217 | + | require.Equal(t, protocol.ParkedRouteStaleTarget, stale.Status) | |
| 217 | 218 | require.Same(t, source, ac.currentAttachmentSession()) | |
| 218 | 219 | require.True(t, ac.parkedRouteOutput.Load()) | |
| 219 | 220 | ||
| 220 | - | resume := ports.ParkedRouteRequest{RequestID: 3, LeaseID: leaseID, Action: ports.ParkedRouteResume} | |
| 221 | + | resume := protocol.ParkedRouteRequest{RequestID: 3, LeaseID: leaseID, Action: protocol.ParkedRouteResume} | |
| 221 | 222 | d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(resume)}) | |
| 222 | 223 | resumedFrame := awaitFrame(t, sends, ports.MsgParkedRouteResponse) | |
| 223 | 224 | resumed, err := ports.UnmarshalParkedRouteResponse(resumedFrame.Payload) | |
| 224 | 225 | require.NoError(t, err) | |
| 225 | - | require.Equal(t, ports.ParkedRouteResumed, resumed.Status) | |
| 226 | + | require.Equal(t, protocol.ParkedRouteResumed, resumed.Status) | |
| 226 | 227 | require.False(t, ac.parkedRouteOutput.Load()) | |
| 227 | 228 | outputFrame := awaitFrame(t, sends, ports.MsgOutput) | |
| 228 | 229 | output, err := ports.UnmarshalOutput(outputFrame.Payload) | |
| @@ -233,7 +234,7 @@ func TestParkedRouteStaleTargetLeavesSourceResumable(t *testing.T) { | |||
| 233 | 234 | func TestParkedRouteDoesNotReplayOneShotEffectsAfterResume(t *testing.T) { | |
| 234 | 235 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 235 | 236 | defer releaseAll(releases) | |
| 236 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 237 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 237 | 238 | ||
| 238 | 239 | leaseID := armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 239 | 240 | require.NoError(t, d.boundedSendOutputErr(ac, []byte("one-shot effect"))) | |
| @@ -243,7 +244,7 @@ func TestParkedRouteDoesNotReplayOneShotEffectsAfterResume(t *testing.T) { | |||
| 243 | 244 | default: | |
| 244 | 245 | } | |
| 245 | 246 | ||
| 246 | - | resume := ports.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: ports.ParkedRouteResume} | |
| 247 | + | resume := protocol.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: protocol.ParkedRouteResume} | |
| 247 | 248 | d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(resume)}) | |
| 248 | 249 | _ = awaitFrame(t, sends, ports.MsgParkedRouteResponse) | |
| 249 | 250 | outputFrame := awaitFrame(t, sends, ports.MsgOutput) | |
| @@ -261,19 +262,19 @@ func TestParkedRouteDoesNotReplayOneShotEffectsAfterResume(t *testing.T) { | |||
| 261 | 262 | func TestParkedRouteExpiredLeaseFailsClosed(t *testing.T) { | |
| 262 | 263 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 263 | 264 | defer releaseAll(releases) | |
| 264 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 265 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 265 | 266 | ||
| 266 | 267 | leaseID := armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 267 | 268 | ||
| 268 | 269 | ac.parkedRouteMu.Lock() | |
| 269 | 270 | ac.parkedRoute.expiresAt = d.clock.Now() | |
| 270 | 271 | ac.parkedRouteMu.Unlock() | |
| 271 | - | resume := ports.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: ports.ParkedRouteResume} | |
| 272 | + | resume := protocol.ParkedRouteRequest{RequestID: 2, LeaseID: leaseID, Action: protocol.ParkedRouteResume} | |
| 272 | 273 | d.handleAttachmentClientFrame(source.captureAttachmentCapability(ac, ac.transport()), ports.Frame{Type: ports.MsgParkedRouteRequest, Payload: ports.MarshalParkedRouteRequest(resume)}) | |
| 273 | 274 | responseFrame := awaitFrame(t, sends, ports.MsgParkedRouteResponse) | |
| 274 | 275 | response, err := ports.UnmarshalParkedRouteResponse(responseFrame.Payload) | |
| 275 | 276 | require.NoError(t, err) | |
| 276 | - | require.Equal(t, ports.ParkedRouteExpired, response.Status) | |
| 277 | + | require.Equal(t, protocol.ParkedRouteExpired, response.Status) | |
| 277 | 278 | require.Same(t, source, ac.currentAttachmentSession()) | |
| 278 | 279 | require.False(t, ac.parkedRouteOutput.Load()) | |
| 279 | 280 | } | |
| @@ -281,7 +282,7 @@ func TestParkedRouteExpiredLeaseFailsClosed(t *testing.T) { | |||
| 281 | 282 | func TestParkedRouteResumeRejectsSwitchInFlight(t *testing.T) { | |
| 282 | 283 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 283 | 284 | defer releaseAll(releases) | |
| 284 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 285 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 285 | 286 | leaseID := armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 286 | 287 | ||
| 287 | 288 | ac.parkedRouteMu.Lock() | |
| @@ -289,7 +290,7 @@ func TestParkedRouteResumeRejectsSwitchInFlight(t *testing.T) { | |||
| 289 | 290 | ac.parkedRouteMu.Unlock() | |
| 290 | 291 | status := ac.consumeParkedRoute(source.captureAttachmentCapability(ac, ac.transport()), leaseID, d.clock.Now()) | |
| 291 | 292 | ||
| 292 | - | require.Equal(t, ports.ParkedRouteRejected, status) | |
| 293 | + | require.Equal(t, protocol.ParkedRouteRejected, status) | |
| 293 | 294 | ac.parkedRouteMu.Lock() | |
| 294 | 295 | require.NotNil(t, ac.parkedRoute) | |
| 295 | 296 | ac.parkedRouteMu.Unlock() | |
| @@ -328,10 +329,10 @@ func TestParkedRouteLeaseExpiryClosesExactRetainedTransport(t *testing.T) { | |||
| 328 | 329 | func TestParkedRouteMalformedSwitchRequestsFailClosed(t *testing.T) { | |
| 329 | 330 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 330 | 331 | defer releaseAll(releases) | |
| 331 | - | leaseID := ports.ParkedRouteLeaseID{1} | |
| 332 | - | for _, request := range []ports.ParkedRouteRequest{ | |
| 333 | - | {RequestID: 1, LeaseID: leaseID, Action: ports.ParkedRouteSwitch}, | |
| 334 | - | {RequestID: 2, Action: ports.ParkedRouteSwitch, Target: &domain.RemoteSessionTarget{}}, | |
| 332 | + | leaseID := protocol.ParkedRouteLeaseID{1} | |
| 333 | + | for _, request := range []protocol.ParkedRouteRequest{ | |
| 334 | + | {RequestID: 1, LeaseID: leaseID, Action: protocol.ParkedRouteSwitch}, | |
| 335 | + | {RequestID: 2, Action: protocol.ParkedRouteSwitch, Target: &domain.RemoteSessionTarget{}}, | |
| 335 | 336 | {RequestID: 3, LeaseID: leaseID, Action: 99}, | |
| 336 | 337 | } { | |
| 337 | 338 | capability := source.captureAttachmentCapability(ac, ac.transport()) | |
| @@ -358,7 +359,7 @@ func TestParkedRouteResponseFailureDoesNotDrainItsOwnFrameEffect(t *testing.T) { | |||
| 358 | 359 | ||
| 359 | 360 | result := make(chan bool, 1) | |
| 360 | 361 | go func() { | |
| 361 | - | result <- d.respondParkedRoute(effect, ports.ParkedRouteResponse{RequestID: 1, Status: ports.ParkedRouteReady}) | |
| 362 | + | result <- d.respondParkedRoute(effect, protocol.ParkedRouteResponse{RequestID: 1, Status: protocol.ParkedRouteReady}) | |
| 362 | 363 | }() | |
| 363 | 364 | require.False(t, awaitTestValue(t, result, "parked-route send failure cleanup")) | |
| 364 | 365 | d.attachmentCleanupWg.Wait() | |
| @@ -367,7 +368,7 @@ func TestParkedRouteResponseFailureDoesNotDrainItsOwnFrameEffect(t *testing.T) { | |||
| 367 | 368 | func TestParkedRouteDetachClearsLeaseAndSuspension(t *testing.T) { | |
| 368 | 369 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 369 | 370 | defer releaseAll(releases) | |
| 370 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 371 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 371 | 372 | ||
| 372 | 373 | _ = armAndPrepareParkedRoute(t, d, source, ac, sends) | |
| 373 | 374 | require.True(t, ac.parkedRouteOutput.Load()) | |
M internal/usecase/daemon/picker.go +7 -6
| @@ -10,6 +10,7 @@ import ( | |||
| 10 | 10 | renderer "github.com/bnema/vev-vt" | |
| 11 | 11 | "github.com/bnema/vev/internal/domain" | |
| 12 | 12 | "github.com/bnema/vev/internal/ports" | |
| 13 | + | "github.com/bnema/vev/internal/protocol" | |
| 13 | 14 | "github.com/bnema/vev/internal/usecase/layout" | |
| 14 | 15 | "github.com/bnema/vev/internal/usecase/picker" | |
| 15 | 16 | "github.com/bnema/vev/internal/usecase/ui" | |
| @@ -377,14 +378,14 @@ func (d *Daemon) handlePickerInput(ac *attachedClient, data []byte, effects ...* | |||
| 377 | 378 | committing := (result.action == '\r' || result.action == '\n') && ok | |
| 378 | 379 | backNavigationSent := false | |
| 379 | 380 | if result.exit && !committing { | |
| 380 | - | back := ac.startupOverlay == ports.StartupOverlaySessionPicker && ac.navigationCapabilities&ports.NavigationCapabilityBack != 0 | |
| 381 | + | back := ac.startupOverlay == protocol.StartupOverlaySessionPicker && ac.navigationCapabilities&protocol.NavigationCapabilityBack != 0 | |
| 381 | 382 | if back { | |
| 382 | 383 | if len(effects) == 0 || effects[0] == nil { | |
| 383 | 384 | d.invalidateRender(sess, ac, true, "picker.go") | |
| 384 | 385 | return | |
| 385 | 386 | } | |
| 386 | 387 | effect := effects[0] | |
| 387 | - | if err := d.sendNavigationActionForAttachment(effect, ports.NavigationBack); err != nil { | |
| 388 | + | if err := d.sendNavigationActionForAttachment(effect, protocol.NavigationBack); err != nil { | |
| 388 | 389 | d.reportAttachmentError(sess, err) | |
| 389 | 390 | d.invalidateRender(sess, ac, true, "picker.go") | |
| 390 | 391 | return | |
| @@ -599,7 +600,7 @@ func remotePickerPreviewSize(size domain.Size) (uint16, uint16) { | |||
| 599 | 600 | if width <= 0 || height <= 0 { | |
| 600 | 601 | return 0, 0 | |
| 601 | 602 | } | |
| 602 | - | return uint16(min(width, ports.RemotePreviewMaxWidth)), uint16(min(height, ports.RemotePreviewMaxHeight)) | |
| 603 | + | return uint16(min(width, protocol.RemotePreviewMaxWidth)), uint16(min(height, protocol.RemotePreviewMaxHeight)) | |
| 603 | 604 | } | |
| 604 | 605 | ||
| 605 | 606 | func staticRemotePickerPreview(width, height uint16, message string) picker.Preview { | |
| @@ -887,7 +888,7 @@ func (d *Daemon) sendLocalAttachTargetForAttachment(effect *attachmentEffect, ta | |||
| 887 | 888 | d.mu.Lock() | |
| 888 | 889 | var targetSess *session | |
| 889 | 890 | var sessionName string | |
| 890 | - | var exactTarget *ports.ExactSessionTarget | |
| 891 | + | var exactTarget *protocol.ExactSessionTarget | |
| 891 | 892 | var matches bool | |
| 892 | 893 | if target.Name != "" { | |
| 893 | 894 | var stopped inactiveSession | |
| @@ -895,7 +896,7 @@ func (d *Daemon) sendLocalAttachTargetForAttachment(effect *attachmentEffect, ta | |||
| 895 | 896 | targetSess, stopped, stoppedTarget, matches = d.resolveNamedLifecycleTargetLocked(target) | |
| 896 | 897 | if stoppedTarget && matches { | |
| 897 | 898 | sessionName = stopped.name | |
| 898 | - | exactTarget = &ports.ExactSessionTarget{LifecycleID: stopped.incarnation, SessionName: sessionName} | |
| 899 | + | exactTarget = &protocol.ExactSessionTarget{LifecycleID: stopped.incarnation, SessionName: sessionName} | |
| 899 | 900 | } | |
| 900 | 901 | } else { | |
| 901 | 902 | targetSess = d.sessions[target.Session] | |
| @@ -904,7 +905,7 @@ func (d *Daemon) sendLocalAttachTargetForAttachment(effect *attachmentEffect, ta | |||
| 904 | 905 | if matches && targetSess != nil { | |
| 905 | 906 | targetSess.mu.Lock() | |
| 906 | 907 | sessionName = targetSess.name | |
| 907 | - | exactTarget = &ports.ExactSessionTarget{LifecycleID: targetSess.incarnation, SessionName: sessionName} | |
| 908 | + | exactTarget = &protocol.ExactSessionTarget{LifecycleID: targetSess.incarnation, SessionName: sessionName} | |
| 908 | 909 | targetSess.mu.Unlock() | |
| 909 | 910 | } | |
| 910 | 911 | d.mu.Unlock() | |
M internal/usecase/daemon/picker_test.go +5 -4
| @@ -16,6 +16,7 @@ import ( | |||
| 16 | 16 | "github.com/bnema/vev/internal/persist" | |
| 17 | 17 | "github.com/bnema/vev/internal/ports" | |
| 18 | 18 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 19 | + | "github.com/bnema/vev/internal/protocol" | |
| 19 | 20 | "github.com/bnema/vev/internal/usecase/layout" | |
| 20 | 21 | "github.com/bnema/vev/internal/usecase/picker" | |
| 21 | 22 | recoveryusecase "github.com/bnema/vev/internal/usecase/recovery" | |
| @@ -892,8 +893,8 @@ func TestPickerNavigationBackSendFailureKeepsPickerOpen(t *testing.T) { | |||
| 892 | 893 | const sendErr = "navigation back send failed" | |
| 893 | 894 | tr := &remotePickerSendErrorTransport{err: errors.New(sendErr)} | |
| 894 | 895 | ac.replaceTransport(tr) | |
| 895 | - | ac.startupOverlay = ports.StartupOverlaySessionPicker | |
| 896 | - | ac.navigationCapabilities = ports.NavigationCapabilityBack | |
| 896 | + | ac.startupOverlay = protocol.StartupOverlaySessionPicker | |
| 897 | + | ac.navigationCapabilities = protocol.NavigationCapabilityBack | |
| 897 | 898 | ac.overlays.pickerMu.Lock() | |
| 898 | 899 | ac.overlays.picker = picker.New(nil, picker.SelectionConfig{}) | |
| 899 | 900 | ac.overlays.pickerGeneration++ | |
| @@ -926,8 +927,8 @@ func TestPickerNavigationBackWithoutCallerTicketKeepsPickerOpen(t *testing.T) { | |||
| 926 | 927 | t.Run(tc.name, func(t *testing.T) { | |
| 927 | 928 | d, sess, ac, _, releases := newManualTabSession(t, 1) | |
| 928 | 929 | defer releases[0]() | |
| 929 | - | ac.startupOverlay = ports.StartupOverlaySessionPicker | |
| 930 | - | ac.navigationCapabilities = ports.NavigationCapabilityBack | |
| 930 | + | ac.startupOverlay = protocol.StartupOverlaySessionPicker | |
| 931 | + | ac.navigationCapabilities = protocol.NavigationCapabilityBack | |
| 931 | 932 | ac.overlays.pickerMu.Lock() | |
| 932 | 933 | ac.overlays.picker = picker.New([]picker.SessionView{{ID: sess.id, Name: sess.name, Tabs: []picker.TabEntry{{Name: "tab"}}, Active: 0}}, picker.SelectionConfig{}) | |
| 933 | 934 | ac.overlays.pickerGeneration++ | |
M internal/usecase/daemon/recent_route_presentation_test.go +5 -5
| @@ -3,7 +3,7 @@ package daemon | |||
| 3 | 3 | import ( | |
| 4 | 4 | "testing" | |
| 5 | 5 | ||
| 6 | - | "github.com/bnema/vev/internal/ports" | |
| 6 | + | "github.com/bnema/vev/internal/protocol" | |
| 7 | 7 | "github.com/bnema/vev/internal/usecase/command" | |
| 8 | 8 | "github.com/bnema/vev/internal/usecase/palette" | |
| 9 | 9 | "github.com/stretchr/testify/require" | |
| @@ -76,11 +76,11 @@ func TestFormatRecentRoutePresentations(t *testing.T) { | |||
| 76 | 76 | } | |
| 77 | 77 | ||
| 78 | 78 | func TestRecentSessionHintsAndRankedRenderingShareCanonicalLabels(t *testing.T) { | |
| 79 | - | snapshot := ports.RecentRouteSnapshot{ | |
| 79 | + | snapshot := protocol.RecentRouteSnapshot{ | |
| 80 | 80 | Generation: 1, | |
| 81 | - | Entries: []ports.RecentRouteEntry{ | |
| 82 | - | {Key: 1, Generation: 1, Target: testRouteTarget("logs", 1), Name: "logs", Kind: ports.RouteKindLocal, Attention: true}, | |
| 83 | - | testRouteEntry(2, 1, "logs", 2, ports.RouteKindLocal), | |
| 81 | + | Entries: []protocol.RecentRouteEntry{ | |
| 82 | + | {Key: 1, Generation: 1, Target: testRouteTarget("logs", 1), Name: "logs", Kind: protocol.RouteKindLocal, Attention: true}, | |
| 83 | + | testRouteEntry(2, 1, "logs", 2, protocol.RouteKindLocal), | |
| 84 | 84 | }, | |
| 85 | 85 | } | |
| 86 | 86 | ||
M internal/usecase/daemon/recent_route_snapshot.go +10 -10
| @@ -2,26 +2,26 @@ package daemon | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "github.com/bnema/vev/internal/domain" | |
| 5 | - | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | 6 | ) | |
| 7 | 7 | ||
| 8 | - | func activeRouteEntryForLifecycle(snapshot ports.RecentRouteSnapshot, lifecycle domain.SessionLifecycleID) (ports.RecentRouteEntry, bool) { | |
| 8 | + | func activeRouteEntryForLifecycle(snapshot protocol.RecentRouteSnapshot, lifecycle domain.SessionLifecycleID) (protocol.RecentRouteEntry, bool) { | |
| 9 | 9 | active := snapshot.ActiveEntry | |
| 10 | - | activeRef := ports.RouteRef{Key: active.Key, Generation: active.Generation} | |
| 10 | + | activeRef := protocol.RouteRef{Key: active.Key, Generation: active.Generation} | |
| 11 | 11 | if lifecycle == (domain.SessionLifecycleID{}) || active.Target.LifecycleID != lifecycle || snapshot.Active != activeRef { | |
| 12 | - | return ports.RecentRouteEntry{}, false | |
| 12 | + | return protocol.RecentRouteEntry{}, false | |
| 13 | 13 | } | |
| 14 | 14 | return active, true | |
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | - | func recentRoutePresentationsFromSnapshot(snapshot ports.RecentRouteSnapshot) []recentRoutePresentation { | |
| 17 | + | func recentRoutePresentationsFromSnapshot(snapshot protocol.RecentRouteSnapshot) []recentRoutePresentation { | |
| 18 | 18 | if snapshot.Entries == nil { | |
| 19 | 19 | return nil | |
| 20 | 20 | } | |
| 21 | 21 | out := make([]recentRoutePresentation, len(snapshot.Entries)) | |
| 22 | 22 | for i, entry := range snapshot.Entries { | |
| 23 | 23 | kind := recentRouteLocal | |
| 24 | - | if entry.Kind == ports.RouteKindRemote { | |
| 24 | + | if entry.Kind == protocol.RouteKindRemote { | |
| 25 | 25 | kind = recentRouteRemote | |
| 26 | 26 | } | |
| 27 | 27 | out[i] = recentRoutePresentation{ | |
| @@ -35,20 +35,20 @@ func recentRoutePresentationsFromSnapshot(snapshot ports.RecentRouteSnapshot) [] | |||
| 35 | 35 | return out | |
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | - | func formatRecentRouteSnapshot(snapshot ports.RecentRouteSnapshot) []recentRouteDisplay { | |
| 38 | + | func formatRecentRouteSnapshot(snapshot protocol.RecentRouteSnapshot) []recentRouteDisplay { | |
| 39 | 39 | return formatRecentRoutePresentations(recentRoutePresentationsFromSnapshot(snapshot)) | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | 42 | // formatRecentRouteSnapshotForAttachment resolves attention against this | |
| 43 | 43 | // daemon's live sessions. The client retains route ordering and presentation; | |
| 44 | 44 | // it subscribes only the exact routes this daemon serves. | |
| 45 | - | func (d *Daemon) formatRecentRouteSnapshotForAttachment(ac *attachedClient, snapshot ports.RecentRouteSnapshot) []recentRouteDisplay { | |
| 45 | + | func (d *Daemon) formatRecentRouteSnapshotForAttachment(ac *attachedClient, snapshot protocol.RecentRouteSnapshot) []recentRouteDisplay { | |
| 46 | 46 | presentations := recentRoutePresentationsFromSnapshot(snapshot) | |
| 47 | 47 | if d == nil || ac == nil { | |
| 48 | 48 | return formatRecentRoutePresentations(presentations) | |
| 49 | 49 | } | |
| 50 | 50 | for i, entry := range snapshot.Entries { | |
| 51 | - | target, ok := ac.routeAttentionTarget(ports.RouteRef{Key: entry.Key, Generation: entry.Generation}) | |
| 51 | + | target, ok := ac.routeAttentionTarget(protocol.RouteRef{Key: entry.Key, Generation: entry.Generation}) | |
| 52 | 52 | if ok { | |
| 53 | 53 | presentations[i].attention = d.routeHasAttention(target) | |
| 54 | 54 | } | |
| @@ -56,7 +56,7 @@ func (d *Daemon) formatRecentRouteSnapshotForAttachment(ac *attachedClient, snap | |||
| 56 | 56 | return formatRecentRoutePresentations(presentations) | |
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | - | func (d *Daemon) routeHasAttention(target ports.ExactSessionTarget) bool { | |
| 59 | + | func (d *Daemon) routeHasAttention(target protocol.ExactSessionTarget) bool { | |
| 60 | 60 | d.mu.Lock() | |
| 61 | 61 | sess := d.findByNameLocked(target.SessionName) | |
| 62 | 62 | d.mu.Unlock() | |
M internal/usecase/daemon/recent_route_snapshot_test.go +25 -24
| @@ -5,21 +5,22 @@ import ( | |||
| 5 | 5 | ||
| 6 | 6 | "github.com/bnema/vev/internal/domain" | |
| 7 | 7 | "github.com/bnema/vev/internal/ports" | |
| 8 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 9 | "github.com/stretchr/testify/require" | |
| 9 | 10 | ) | |
| 10 | 11 | ||
| 11 | 12 | func TestAttachmentStatusUsesClientRouteSnapshot(t *testing.T) { | |
| 12 | 13 | d, sess, ac, _ := newManualSessionWithPTYs(t, nil) | |
| 13 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 14 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 14 | 15 | Generation: 2, | |
| 15 | - | Active: ports.RouteRef{Key: 3, Generation: 2}, | |
| 16 | - | Entries: []ports.RecentRouteEntry{ | |
| 17 | - | {Key: 2, Generation: 1, Target: testRouteTarget("logs", 2), Name: "logs", HostLabel: "user@edge", Kind: ports.RouteKindRemote}, | |
| 18 | - | testRouteEntry(1, 1, "work", 1, ports.RouteKindLocal), | |
| 16 | + | Active: protocol.RouteRef{Key: 3, Generation: 2}, | |
| 17 | + | Entries: []protocol.RecentRouteEntry{ | |
| 18 | + | {Key: 2, Generation: 1, Target: testRouteTarget("logs", 2), Name: "logs", HostLabel: "user@edge", Kind: protocol.RouteKindRemote}, | |
| 19 | + | testRouteEntry(1, 1, "work", 1, protocol.RouteKindLocal), | |
| 19 | 20 | }, | |
| 20 | 21 | }) | |
| 21 | 22 | ||
| 22 | - | state := d.barStateForAttachmentPaletteHintsFor(sess, ac, "", nil, ports.RecentRouteSnapshot{}) | |
| 23 | + | state := d.barStateForAttachmentPaletteHintsFor(sess, ac, "", nil, protocol.RecentRouteSnapshot{}) | |
| 23 | 24 | ||
| 24 | 25 | require.Len(t, state.mru, 2) | |
| 25 | 26 | require.Equal(t, []string{"logs@edge", "work"}, []string{state.mru[0].name, state.mru[1].name}) | |
| @@ -40,21 +41,21 @@ func TestAttachmentStatusResolvesSubscribedRouteAttention(t *testing.T) { | |||
| 40 | 41 | sess.incarnation = domain.SessionLifecycleID{9} | |
| 41 | 42 | sess.tabs[0].attention = true | |
| 42 | 43 | sess.mu.Unlock() | |
| 43 | - | ref := ports.RouteRef{Key: 2, Generation: 1} | |
| 44 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 44 | + | ref := protocol.RouteRef{Key: 2, Generation: 1} | |
| 45 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 45 | 46 | Generation: 2, | |
| 46 | - | Active: ports.RouteRef{Key: 3, Generation: 2}, | |
| 47 | - | Entries: []ports.RecentRouteEntry{{Key: ref.Key, Generation: ref.Generation, Target: ports.ExactSessionTarget{LifecycleID: tt.targetID, SessionName: sess.name}, Name: sess.name, Kind: ports.RouteKindLocal}}, | |
| 47 | + | Active: protocol.RouteRef{Key: 3, Generation: 2}, | |
| 48 | + | Entries: []protocol.RecentRouteEntry{{Key: ref.Key, Generation: ref.Generation, Target: protocol.ExactSessionTarget{LifecycleID: tt.targetID, SessionName: sess.name}, Name: sess.name, Kind: protocol.RouteKindLocal}}, | |
| 48 | 49 | }) | |
| 49 | - | ac.setRouteAttentionSubscription(ports.RouteAttentionSubscription{Targets: []ports.RouteAttentionTarget{{ | |
| 50 | + | ac.setRouteAttentionSubscription(protocol.RouteAttentionSubscription{Targets: []protocol.RouteAttentionTarget{{ | |
| 50 | 51 | Ref: ref, | |
| 51 | - | Target: ports.ExactSessionTarget{ | |
| 52 | + | Target: protocol.ExactSessionTarget{ | |
| 52 | 53 | LifecycleID: tt.targetID, | |
| 53 | 54 | SessionName: sess.name, | |
| 54 | 55 | }, | |
| 55 | 56 | }}}) | |
| 56 | 57 | ||
| 57 | - | state := d.barStateForAttachmentPaletteHintsFor(sess, ac, "", nil, ports.RecentRouteSnapshot{}) | |
| 58 | + | state := d.barStateForAttachmentPaletteHintsFor(sess, ac, "", nil, protocol.RecentRouteSnapshot{}) | |
| 58 | 59 | ||
| 59 | 60 | require.Len(t, state.mru, 1) | |
| 60 | 61 | require.Equal(t, tt.attention, state.mru[0].attention) | |
| @@ -66,9 +67,9 @@ func TestRecentRouteSnapshotRepaintsWithoutDeferredIdentity(t *testing.T) { | |||
| 66 | 67 | d, sess, ac, sends := newManualSessionWithPTYs(t, nil) | |
| 67 | 68 | token := sess.captureAttachmentCapability(ac, ac.transport()) | |
| 68 | 69 | ac.installTestAttachmentCapability(token) | |
| 69 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 70 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 70 | 71 | ||
| 71 | - | payload, err := ports.MarshalRecentRouteSnapshot(ports.RecentRouteSnapshot{Generation: 2}) | |
| 72 | + | payload, err := ports.MarshalRecentRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 2}) | |
| 72 | 73 | require.NoError(t, err) | |
| 73 | 74 | require.False(t, d.handleAttachmentClientFrame(token, ports.Frame{Type: ports.MsgRecentRouteSnapshot, Payload: payload})) | |
| 74 | 75 | ||
| @@ -77,8 +78,8 @@ func TestRecentRouteSnapshotRepaintsWithoutDeferredIdentity(t *testing.T) { | |||
| 77 | 78 | ||
| 78 | 79 | func TestAttachmentRouteSnapshotCopiesPublishedEntries(t *testing.T) { | |
| 79 | 80 | _, _, ac, _ := newManualSessionWithPTYs(t, nil) | |
| 80 | - | entries := []ports.RecentRouteEntry{testRouteEntry(1, 2, "before", 1, ports.RouteKindLocal)} | |
| 81 | - | snapshot := ports.RecentRouteSnapshot{Generation: 3, Entries: entries} | |
| 81 | + | entries := []protocol.RecentRouteEntry{testRouteEntry(1, 2, "before", 1, protocol.RouteKindLocal)} | |
| 82 | + | snapshot := protocol.RecentRouteSnapshot{Generation: 3, Entries: entries} | |
| 82 | 83 | ac.setRouteSnapshot(snapshot) | |
| 83 | 84 | ||
| 84 | 85 | entries[0].Name = "after" | |
| @@ -102,16 +103,16 @@ func TestPaletteRecentRouteSelectionSendsTypedClientAction(t *testing.T) { | |||
| 102 | 103 | ||
| 103 | 104 | exec := paletteExec{ | |
| 104 | 105 | d: d, sess: source, attachment: source, ac: ac, | |
| 105 | - | routeSnapshot: ports.RecentRouteSnapshot{ | |
| 106 | + | routeSnapshot: protocol.RecentRouteSnapshot{ | |
| 106 | 107 | Generation: 4, | |
| 107 | - | Entries: []ports.RecentRouteEntry{testRouteEntry(2, 3, "remote", 2, ports.RouteKindRemote)}, | |
| 108 | + | Entries: []protocol.RecentRouteEntry{testRouteEntry(2, 3, "remote", 2, protocol.RouteKindRemote)}, | |
| 108 | 109 | }, | |
| 109 | 110 | effect: effect, | |
| 110 | 111 | } | |
| 111 | 112 | require.NoError(t, exec.JumpRecentSession(1)) | |
| 112 | 113 | ||
| 113 | 114 | frames := transport.Sends() | |
| 114 | - | var action ports.RouteNavigationAction | |
| 115 | + | var action protocol.RouteNavigationAction | |
| 115 | 116 | found := false | |
| 116 | 117 | for _, frame := range frames { | |
| 117 | 118 | if frame.Type != ports.MsgNavigateRecentRoute { | |
| @@ -123,14 +124,14 @@ func TestPaletteRecentRouteSelectionSendsTypedClientAction(t *testing.T) { | |||
| 123 | 124 | found = true | |
| 124 | 125 | } | |
| 125 | 126 | require.True(t, found) | |
| 126 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 4, Key: 2, Generation: 3}, action) | |
| 127 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 4, Key: 2, Generation: 3}, action) | |
| 127 | 128 | } | |
| 128 | 129 | ||
| 129 | 130 | func TestRecentRouteHintsRetainSnapshotSelectionIdentity(t *testing.T) { | |
| 130 | - | snapshot := ports.RecentRouteSnapshot{ | |
| 131 | + | snapshot := protocol.RecentRouteSnapshot{ | |
| 131 | 132 | Generation: 8, | |
| 132 | - | Entries: []ports.RecentRouteEntry{{ | |
| 133 | - | Key: 11, Generation: 7, Target: testRouteTarget("logs", 11), Name: "logs", HostLabel: "edge", Kind: ports.RouteKindRemote, | |
| 133 | + | Entries: []protocol.RecentRouteEntry{{ | |
| 134 | + | Key: 11, Generation: 7, Target: testRouteTarget("logs", 11), Name: "logs", HostLabel: "edge", Kind: protocol.RouteKindRemote, | |
| 134 | 135 | }}, | |
| 135 | 136 | } | |
| 136 | 137 | ||
M internal/usecase/daemon/remote_attach.go +12 -11
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | ||
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | 8 | "github.com/bnema/vev/internal/ports" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | ) | |
| 10 | 11 | ||
| 11 | 12 | // routeRemoteTargetWithContext is the exact-target branch for picker handoffs. | |
| @@ -27,8 +28,8 @@ func (d *Daemon) routeRemoteTargetWithContext(ctx context.Context, h ports.Hello | |||
| 27 | 28 | return nil, nil, &protoErr{ports.ErrNoSuchTarget, "remote target requires attach or resume"} | |
| 28 | 29 | } | |
| 29 | 30 | if err := d.waitForTargetRestore(ctx, target.SessionName); err != nil { | |
| 30 | - | var protocol *protoErr | |
| 31 | - | if errors.As(err, &protocol) && protocol.code == ports.ErrInternal { | |
| 31 | + | var protocolErr *protoErr | |
| 32 | + | if errors.As(err, &protocolErr) && protocolErr.code == ports.ErrInternal { | |
| 32 | 33 | return nil, nil, &protoErr{ports.ErrNoSuchTarget, "remote session is unavailable"} | |
| 33 | 34 | } | |
| 34 | 35 | return nil, nil, remoteTargetError(err) | |
| @@ -102,10 +103,10 @@ func (d *Daemon) resumeRemoteInactiveSessionLocked(target domain.RemoteSessionTa | |||
| 102 | 103 | return d.createSessionLockedWithModeAndInactiveFence(target.SessionName, false, cwd, geometry, env, &expected, validate, expected.tabNames) | |
| 103 | 104 | } | |
| 104 | 105 | ||
| 105 | - | func (d *Daemon) sendNavigationActionForAttachment(effect *attachmentEffect, action ports.NavigationAction) error { | |
| 106 | - | directive := ports.NavigationDirective{Action: action} | |
| 106 | + | func (d *Daemon) sendNavigationActionForAttachment(effect *attachmentEffect, action protocol.NavigationAction) error { | |
| 107 | + | directive := protocol.NavigationDirective{Action: action} | |
| 107 | 108 | armed := false | |
| 108 | - | if action == ports.NavigationOpenHomePicker { | |
| 109 | + | if action == protocol.NavigationOpenHomePicker { | |
| 109 | 110 | leaseID, err := d.armParkedRoute(effect) | |
| 110 | 111 | if err != nil { | |
| 111 | 112 | return err | |
| @@ -130,7 +131,7 @@ func (d *Daemon) sendNavigationActionForAttachment(effect *attachmentEffect, act | |||
| 130 | 131 | return nil | |
| 131 | 132 | } | |
| 132 | 133 | ||
| 133 | - | func (d *Daemon) sendRecentRouteNavigationActionForAttachment(effect *attachmentEffect, action ports.RouteNavigationAction) error { | |
| 134 | + | func (d *Daemon) sendRecentRouteNavigationActionForAttachment(effect *attachmentEffect, action protocol.RouteNavigationAction) error { | |
| 134 | 135 | payload, err := ports.MarshalRouteNavigationAction(action) | |
| 135 | 136 | if err != nil { | |
| 136 | 137 | return errAttachmentTransition | |
| @@ -143,8 +144,8 @@ func (d *Daemon) sendCommittedRouteIdentityForAttachment(effect *attachmentEffec | |||
| 143 | 144 | return errAttachmentTransition | |
| 144 | 145 | } | |
| 145 | 146 | effect.sess.mu.Lock() | |
| 146 | - | identity := ports.CommittedRouteIdentity{ | |
| 147 | - | Target: ports.ExactSessionTarget{LifecycleID: effect.sess.incarnation, SessionName: effect.sess.name}, | |
| 147 | + | identity := protocol.CommittedRouteIdentity{ | |
| 148 | + | Target: protocol.ExactSessionTarget{LifecycleID: effect.sess.incarnation, SessionName: effect.sess.name}, | |
| 148 | 149 | Ephemeral: effect.sess.ephemeral, | |
| 149 | 150 | } | |
| 150 | 151 | effect.sess.mu.Unlock() | |
| @@ -188,9 +189,9 @@ func (d *Daemon) remoteTargetMatchesSessionLocked(sess *session, target domain.R | |||
| 188 | 189 | } | |
| 189 | 190 | ||
| 190 | 191 | func remoteTargetError(err error) error { | |
| 191 | - | var protocol *protoErr | |
| 192 | - | if errors.As(err, &protocol) { | |
| 193 | - | return protocol | |
| 192 | + | var protocolErr *protoErr | |
| 193 | + | if errors.As(err, &protocolErr) { | |
| 194 | + | return protocolErr | |
| 194 | 195 | } | |
| 195 | 196 | if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { | |
| 196 | 197 | return err | |
M internal/usecase/daemon/remote_attach_test.go +3 -2
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | "github.com/bnema/vev/internal/usecase/picker" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| @@ -34,7 +35,7 @@ func TestLocalPickerOfferCarriesExactLifecycle(t *testing.T) { | |||
| 34 | 35 | require.Empty(t, got.Endpoint) | |
| 35 | 36 | require.Equal(t, ports.IntentAttach, got.Intent) | |
| 36 | 37 | require.True(t, got.SamePeer) | |
| 37 | - | require.Equal(t, &ports.ExactSessionTarget{LifecycleID: target.incarnation, SessionName: target.name}, got.ExactTarget) | |
| 38 | + | require.Equal(t, &protocol.ExactSessionTarget{LifecycleID: target.incarnation, SessionName: target.name}, got.ExactTarget) | |
| 38 | 39 | require.Same(t, source, ac.currentAttachmentSession(), "the source remains attached until the client confirms the switch") | |
| 39 | 40 | } | |
| 40 | 41 | ||
| @@ -66,7 +67,7 @@ func TestStoppedLocalPickerHandoffWaitsForClientClose(t *testing.T) { | |||
| 66 | 67 | target, err := ports.UnmarshalAttachTarget(handoff.Payload) | |
| 67 | 68 | require.NoError(t, err) | |
| 68 | 69 | require.False(t, target.SamePeer) | |
| 69 | - | require.Equal(t, &ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "stopped"}, target.ExactTarget) | |
| 70 | + | require.Equal(t, &protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "stopped"}, target.ExactTarget) | |
| 70 | 71 | require.Same(t, source, ac.currentAttachmentSession(), "the source remains attached until the client receives the handoff and closes") | |
| 71 | 72 | require.True(t, attachmentRegistered(source, ac)) | |
| 72 | 73 | } | |
M internal/usecase/daemon/remote_picker_test.go +7 -6
| @@ -17,6 +17,7 @@ import ( | |||
| 17 | 17 | "github.com/bnema/vev/internal/domain" | |
| 18 | 18 | "github.com/bnema/vev/internal/ports" | |
| 19 | 19 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 20 | + | "github.com/bnema/vev/internal/protocol" | |
| 20 | 21 | "github.com/bnema/vev/internal/usecase/picker" | |
| 21 | 22 | ) | |
| 22 | 23 | ||
| @@ -842,18 +843,18 @@ func TestRemotePickerResurrectsStoppedRemoteSessionWithoutTabMetadata(t *testing | |||
| 842 | 843 | func TestNavigationActionHandoffSendsBoundedAction(t *testing.T) { | |
| 843 | 844 | tests := []struct { | |
| 844 | 845 | name string | |
| 845 | - | action ports.NavigationAction | |
| 846 | + | action protocol.NavigationAction | |
| 846 | 847 | }{ | |
| 847 | - | {name: "home picker", action: ports.NavigationOpenHomePicker}, | |
| 848 | - | {name: "back", action: ports.NavigationBack}, | |
| 848 | + | {name: "home picker", action: protocol.NavigationOpenHomePicker}, | |
| 849 | + | {name: "back", action: protocol.NavigationBack}, | |
| 849 | 850 | } | |
| 850 | 851 | ||
| 851 | 852 | for _, tt := range tests { | |
| 852 | 853 | t.Run(tt.name, func(t *testing.T) { | |
| 853 | 854 | d := newRemotePickerDaemon(nil) | |
| 854 | 855 | sess, ac, sends := addRemoteRefreshPickerOwner(t, d, "local") | |
| 855 | - | if tt.action == ports.NavigationOpenHomePicker { | |
| 856 | - | ac.navigationCapabilities = ports.NavigationCapabilityHomePicker | |
| 856 | + | if tt.action == protocol.NavigationOpenHomePicker { | |
| 857 | + | ac.navigationCapabilities = protocol.NavigationCapabilityHomePicker | |
| 857 | 858 | } | |
| 858 | 859 | token := sess.captureAttachmentCapability(ac, ac.transport()) | |
| 859 | 860 | effect, admitted := ac.beginAttachmentEffect(token) | |
| @@ -865,7 +866,7 @@ func TestNavigationActionHandoffSendsBoundedAction(t *testing.T) { | |||
| 865 | 866 | directive, err := ports.UnmarshalNavigationDirective(frame.Payload) | |
| 866 | 867 | require.NoError(t, err) | |
| 867 | 868 | require.Equal(t, tt.action, directive.Action) | |
| 868 | - | if tt.action == ports.NavigationOpenHomePicker { | |
| 869 | + | if tt.action == protocol.NavigationOpenHomePicker { | |
| 869 | 870 | require.False(t, directive.LeaseID.IsZero()) | |
| 870 | 871 | } else { | |
| 871 | 872 | require.True(t, directive.LeaseID.IsZero()) | |
M internal/usecase/daemon/remote_preview.go +20 -19
| @@ -6,71 +6,72 @@ import ( | |||
| 6 | 6 | renderer "github.com/bnema/vev-vt" | |
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | 8 | "github.com/bnema/vev/internal/ports" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | ) | |
| 10 | 11 | ||
| 11 | 12 | func (d *Daemon) handleRemotePreview(tr ports.Transport, frame ports.Frame) error { | |
| 12 | 13 | defer func() { _ = tr.Close() }() | |
| 13 | 14 | request, err := ports.UnmarshalRemotePreviewRequest(frame.Payload) | |
| 14 | 15 | if err != nil { | |
| 15 | - | return d.sendRemotePreview(tr, ports.RemotePreview{Version: ports.RemotePreviewSchemaVersion, Status: ports.RemotePreviewMalformed}) | |
| 16 | + | return d.sendRemotePreview(tr, protocol.RemotePreview{Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewMalformed}) | |
| 16 | 17 | } | |
| 17 | 18 | preview, err := d.captureRemotePreview(request) | |
| 18 | 19 | if err != nil { | |
| 19 | - | status := ports.RemotePreviewUnavailable | |
| 20 | + | status := protocol.RemotePreviewUnavailable | |
| 20 | 21 | if errors.Is(err, errRemotePreviewNoSuchTarget) { | |
| 21 | - | status = ports.RemotePreviewNoSuchTarget | |
| 22 | + | status = protocol.RemotePreviewNoSuchTarget | |
| 22 | 23 | } | |
| 23 | - | preview = ports.RemotePreview{Version: ports.RemotePreviewSchemaVersion, Status: status} | |
| 24 | + | preview = protocol.RemotePreview{Version: protocol.RemotePreviewSchemaVersion, Status: status} | |
| 24 | 25 | } | |
| 25 | 26 | return d.sendRemotePreview(tr, preview) | |
| 26 | 27 | } | |
| 27 | 28 | ||
| 28 | - | func (d *Daemon) sendRemotePreview(tr ports.Transport, preview ports.RemotePreview) error { | |
| 29 | + | func (d *Daemon) sendRemotePreview(tr ports.Transport, preview protocol.RemotePreview) error { | |
| 29 | 30 | payload := ports.MarshalRemotePreview(preview) | |
| 30 | 31 | if payload == nil { | |
| 31 | - | payload = ports.MarshalRemotePreview(ports.RemotePreview{Version: ports.RemotePreviewSchemaVersion, Status: ports.RemotePreviewMalformed}) | |
| 32 | + | payload = ports.MarshalRemotePreview(protocol.RemotePreview{Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewMalformed}) | |
| 32 | 33 | } | |
| 33 | 34 | return d.boundedControlSend(tr, ports.Frame{Type: ports.MsgRemotePreviewResponse, Payload: payload}) | |
| 34 | 35 | } | |
| 35 | 36 | ||
| 36 | 37 | var errRemotePreviewNoSuchTarget = errors.New("daemon: remote preview target does not exist") | |
| 37 | 38 | ||
| 38 | - | func (d *Daemon) captureRemotePreview(request ports.RemotePreviewRequest) (ports.RemotePreview, error) { | |
| 39 | + | func (d *Daemon) captureRemotePreview(request protocol.RemotePreviewRequest) (protocol.RemotePreview, error) { | |
| 39 | 40 | target := request.Target | |
| 40 | 41 | d.mu.Lock() | |
| 41 | 42 | sess := d.findByNameLocked(target.SessionName) | |
| 42 | 43 | if sess == nil || sess.incarnation != target.LifecycleID { | |
| 43 | 44 | d.mu.Unlock() | |
| 44 | - | return ports.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 45 | + | return protocol.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 45 | 46 | } | |
| 46 | 47 | index, ok := remoteTargetTabIndexLocked(sess, target) | |
| 47 | 48 | d.mu.Unlock() | |
| 48 | 49 | if !ok { | |
| 49 | - | return ports.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 50 | + | return protocol.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 50 | 51 | } | |
| 51 | 52 | ||
| 52 | 53 | sess.mu.Lock() | |
| 53 | 54 | if index < 0 || index >= len(sess.tabs) { | |
| 54 | 55 | sess.mu.Unlock() | |
| 55 | - | return ports.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 56 | + | return protocol.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 56 | 57 | } | |
| 57 | 58 | tab := sess.tabs[index] | |
| 58 | 59 | if tab == nil || domain.TabStableID(tab.stableID) != target.LiveTabID { | |
| 59 | 60 | sess.mu.Unlock() | |
| 60 | - | return ports.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 61 | + | return protocol.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 61 | 62 | } | |
| 62 | 63 | sess.mu.Unlock() | |
| 63 | 64 | tab.mu.Lock() | |
| 64 | 65 | pane := tab.focusedPane() | |
| 65 | 66 | if pane == nil { | |
| 66 | 67 | tab.mu.Unlock() | |
| 67 | - | return ports.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 68 | + | return protocol.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 68 | 69 | } | |
| 69 | 70 | pane.mu.Lock() | |
| 70 | 71 | if pane.screen == nil { | |
| 71 | 72 | pane.mu.Unlock() | |
| 72 | 73 | tab.mu.Unlock() | |
| 73 | - | return ports.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 74 | + | return protocol.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 74 | 75 | } | |
| 75 | 76 | source := pane.screen.Frame.Clone() | |
| 76 | 77 | revision := pane.syncGen | |
| @@ -83,7 +84,7 @@ func (d *Daemon) captureRemotePreview(request ports.RemotePreviewRequest) (ports | |||
| 83 | 84 | width := min(int(request.Width), source.Width) | |
| 84 | 85 | height := min(int(request.Height), source.Height) | |
| 85 | 86 | if width <= 0 || height <= 0 { | |
| 86 | - | return ports.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 87 | + | return protocol.RemotePreview{}, errRemotePreviewNoSuchTarget | |
| 87 | 88 | } | |
| 88 | 89 | startY, endY := source.Height-height, source.Height | |
| 89 | 90 | if last := remotePreviewLastContentRow(source, width, startY, endY); last >= startY { | |
| @@ -101,9 +102,9 @@ func (d *Daemon) captureRemotePreview(request ports.RemotePreviewRequest) (ports | |||
| 101 | 102 | cells = append(cells, cell) | |
| 102 | 103 | } | |
| 103 | 104 | } | |
| 104 | - | preview := ports.RemotePreview{ | |
| 105 | - | Version: ports.RemotePreviewSchemaVersion, | |
| 106 | - | Status: ports.RemotePreviewOK, | |
| 105 | + | preview := protocol.RemotePreview{ | |
| 106 | + | Version: protocol.RemotePreviewSchemaVersion, | |
| 107 | + | Status: protocol.RemotePreviewOK, | |
| 107 | 108 | LifecycleID: target.LifecycleID, | |
| 108 | 109 | TabID: target.LiveTabID, | |
| 109 | 110 | Revision: revision, | |
| @@ -111,10 +112,10 @@ func (d *Daemon) captureRemotePreview(request ports.RemotePreviewRequest) (ports | |||
| 111 | 112 | Height: uint16(height), | |
| 112 | 113 | Cells: cells, | |
| 113 | 114 | } | |
| 114 | - | if err := ports.ValidateRemotePreview(preview); err != nil { | |
| 115 | + | if err := protocol.ValidateRemotePreview(preview); err != nil { | |
| 115 | 116 | // A crop must not split a wide cell. Return a safe unavailable response | |
| 116 | 117 | // instead of exposing a malformed cell stream. | |
| 117 | - | return ports.RemotePreview{}, err | |
| 118 | + | return protocol.RemotePreview{}, err | |
| 118 | 119 | } | |
| 119 | 120 | return preview, nil | |
| 120 | 121 | } | |
M internal/usecase/daemon/remote_preview_cache.go +22 -22
| @@ -9,7 +9,7 @@ import ( | |||
| 9 | 9 | "time" | |
| 10 | 10 | ||
| 11 | 11 | "github.com/bnema/vev/internal/domain" | |
| 12 | - | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 13 | 13 | ) | |
| 14 | 14 | ||
| 15 | 15 | const ( | |
| @@ -34,14 +34,14 @@ type remotePreviewCacheKey struct { | |||
| 34 | 34 | } | |
| 35 | 35 | ||
| 36 | 36 | type remotePreviewCacheEntry struct { | |
| 37 | - | Preview ports.RemotePreview | |
| 37 | + | Preview protocol.RemotePreview | |
| 38 | 38 | Fetched time.Time | |
| 39 | 39 | Used time.Time | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | 42 | type remotePreviewFlight struct { | |
| 43 | 43 | done chan struct{} | |
| 44 | - | preview ports.RemotePreview | |
| 44 | + | preview protocol.RemotePreview | |
| 45 | 45 | err error | |
| 46 | 46 | } | |
| 47 | 47 | ||
| @@ -53,7 +53,7 @@ type remotePreviewState struct { | |||
| 53 | 53 | slots chan struct{} | |
| 54 | 54 | } | |
| 55 | 55 | ||
| 56 | - | func cloneRemotePreview(preview ports.RemotePreview) ports.RemotePreview { | |
| 56 | + | func cloneRemotePreview(preview protocol.RemotePreview) protocol.RemotePreview { | |
| 57 | 57 | preview.Cells = slices.Clone(preview.Cells) | |
| 58 | 58 | return preview | |
| 59 | 59 | } | |
| @@ -82,24 +82,24 @@ func remotePreviewKeyFor(target domain.RemoteSessionTarget, width, height uint16 | |||
| 82 | 82 | } | |
| 83 | 83 | } | |
| 84 | 84 | ||
| 85 | - | func (d *Daemon) fetchRemotePreview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (ports.RemotePreview, error) { | |
| 85 | + | func (d *Daemon) fetchRemotePreview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (protocol.RemotePreview, error) { | |
| 86 | 86 | if d == nil || d.remotePreviewClient == nil { | |
| 87 | - | return ports.RemotePreview{}, errors.New("remote preview client unavailable") | |
| 87 | + | return protocol.RemotePreview{}, errors.New("remote preview client unavailable") | |
| 88 | 88 | } | |
| 89 | 89 | if ctx == nil { | |
| 90 | 90 | ctx = context.Background() | |
| 91 | 91 | } | |
| 92 | 92 | if err := ctx.Err(); err != nil { | |
| 93 | - | return ports.RemotePreview{}, err | |
| 93 | + | return protocol.RemotePreview{}, err | |
| 94 | 94 | } | |
| 95 | - | request := ports.RemotePreviewRequest{ | |
| 96 | - | Version: ports.RemotePreviewSchemaVersion, | |
| 95 | + | request := protocol.RemotePreviewRequest{ | |
| 96 | + | Version: protocol.RemotePreviewSchemaVersion, | |
| 97 | 97 | Target: target, | |
| 98 | 98 | Width: width, | |
| 99 | 99 | Height: height, | |
| 100 | 100 | } | |
| 101 | - | if err := ports.ValidateRemotePreviewRequest(request); err != nil { | |
| 102 | - | return ports.RemotePreview{}, err | |
| 101 | + | if err := protocol.ValidateRemotePreviewRequest(request); err != nil { | |
| 102 | + | return protocol.RemotePreview{}, err | |
| 103 | 103 | } | |
| 104 | 104 | ||
| 105 | 105 | key := remotePreviewKeyFor(target, width, height) | |
| @@ -139,7 +139,7 @@ func (d *Daemon) fetchRemotePreview(ctx context.Context, target domain.RemoteSes | |||
| 139 | 139 | ||
| 140 | 140 | if until, cooling := d.remotePreview.cooldowns[key]; cooling && now.Before(until) { | |
| 141 | 141 | d.remotePreview.mu.Unlock() | |
| 142 | - | return ports.RemotePreview{}, errRemotePreviewCooldown | |
| 142 | + | return protocol.RemotePreview{}, errRemotePreviewCooldown | |
| 143 | 143 | } | |
| 144 | 144 | if flight := d.remotePreview.flights[key]; flight != nil { | |
| 145 | 145 | d.remotePreview.mu.Unlock() | |
| @@ -160,12 +160,12 @@ func (d *Daemon) remotePreviewContext() context.Context { | |||
| 160 | 160 | return context.Background() | |
| 161 | 161 | } | |
| 162 | 162 | ||
| 163 | - | func waitRemotePreviewFlight(ctx context.Context, flight *remotePreviewFlight) (ports.RemotePreview, error) { | |
| 163 | + | func waitRemotePreviewFlight(ctx context.Context, flight *remotePreviewFlight) (protocol.RemotePreview, error) { | |
| 164 | 164 | select { | |
| 165 | 165 | case <-flight.done: | |
| 166 | 166 | return cloneRemotePreview(flight.preview), flight.err | |
| 167 | 167 | case <-ctx.Done(): | |
| 168 | - | return ports.RemotePreview{}, ctx.Err() | |
| 168 | + | return protocol.RemotePreview{}, ctx.Err() | |
| 169 | 169 | } | |
| 170 | 170 | } | |
| 171 | 171 | ||
| @@ -173,7 +173,7 @@ func waitRemotePreviewFlight(ctx context.Context, flight *remotePreviewFlight) ( | |||
| 173 | 173 | // while still publishing the refreshed result once the same-key flight finishes. | |
| 174 | 174 | // A completed flight is read from the cache without starting a second remote | |
| 175 | 175 | // request. | |
| 176 | - | func (d *Daemon) awaitRemotePreviewRefresh(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (ports.RemotePreview, error) { | |
| 176 | + | func (d *Daemon) awaitRemotePreviewRefresh(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (protocol.RemotePreview, error) { | |
| 177 | 177 | key := remotePreviewKeyFor(target, width, height) | |
| 178 | 178 | d.remotePreview.mu.Lock() | |
| 179 | 179 | flight := d.remotePreview.flights[key] | |
| @@ -188,20 +188,20 @@ func (d *Daemon) runRemotePreviewFlight(ctx context.Context, key remotePreviewCa | |||
| 188 | 188 | select { | |
| 189 | 189 | case d.remotePreview.slots <- struct{}{}: | |
| 190 | 190 | case <-ctx.Done(): | |
| 191 | - | d.finishRemotePreviewFlight(key, flight, ports.RemotePreview{}, ctx.Err()) | |
| 191 | + | d.finishRemotePreviewFlight(key, flight, protocol.RemotePreview{}, ctx.Err()) | |
| 192 | 192 | return | |
| 193 | 193 | } | |
| 194 | - | var preview ports.RemotePreview | |
| 194 | + | var preview protocol.RemotePreview | |
| 195 | 195 | var err error | |
| 196 | 196 | defer func() { | |
| 197 | 197 | if recovered := recover(); recovered != nil { | |
| 198 | 198 | err = fmt.Errorf("remote preview flight panicked: %v", recovered) | |
| 199 | - | preview = ports.RemotePreview{} | |
| 199 | + | preview = protocol.RemotePreview{} | |
| 200 | 200 | d.finishRemotePreviewFlight(key, flight, preview, err) | |
| 201 | 201 | panic(recovered) | |
| 202 | 202 | } | |
| 203 | 203 | if err != nil { | |
| 204 | - | preview = ports.RemotePreview{} | |
| 204 | + | preview = protocol.RemotePreview{} | |
| 205 | 205 | } | |
| 206 | 206 | d.finishRemotePreviewFlight(key, flight, preview, err) | |
| 207 | 207 | }() | |
| @@ -209,9 +209,9 @@ func (d *Daemon) runRemotePreviewFlight(ctx context.Context, key remotePreviewCa | |||
| 209 | 209 | ||
| 210 | 210 | preview, err = d.remotePreviewClient.Preview(ctx, target, width, height) | |
| 211 | 211 | if err == nil { | |
| 212 | - | if validationErr := ports.ValidateRemotePreview(preview); validationErr != nil { | |
| 212 | + | if validationErr := protocol.ValidateRemotePreview(preview); validationErr != nil { | |
| 213 | 213 | err = validationErr | |
| 214 | - | } else if preview.Status != ports.RemotePreviewOK { | |
| 214 | + | } else if preview.Status != protocol.RemotePreviewOK { | |
| 215 | 215 | err = fmt.Errorf("remote preview returned status %d", preview.Status) | |
| 216 | 216 | } else if preview.LifecycleID != target.LifecycleID || preview.TabID != target.LiveTabID { | |
| 217 | 217 | err = errors.New("remote preview identity changed") | |
| @@ -219,7 +219,7 @@ func (d *Daemon) runRemotePreviewFlight(ctx context.Context, key remotePreviewCa | |||
| 219 | 219 | } | |
| 220 | 220 | } | |
| 221 | 221 | ||
| 222 | - | func (d *Daemon) finishRemotePreviewFlight(key remotePreviewCacheKey, flight *remotePreviewFlight, preview ports.RemotePreview, err error) { | |
| 222 | + | func (d *Daemon) finishRemotePreviewFlight(key remotePreviewCacheKey, flight *remotePreviewFlight, preview protocol.RemotePreview, err error) { | |
| 223 | 223 | now := d.clock.Now() | |
| 224 | 224 | d.remotePreview.mu.Lock() | |
| 225 | 225 | for cooldownKey, until := range d.remotePreview.cooldowns { | |
M internal/usecase/daemon/remote_preview_cache_test.go +14 -13
| @@ -12,6 +12,7 @@ import ( | |||
| 12 | 12 | renderer "github.com/bnema/vev-vt" | |
| 13 | 13 | "github.com/bnema/vev/internal/domain" | |
| 14 | 14 | "github.com/bnema/vev/internal/ports" | |
| 15 | + | "github.com/bnema/vev/internal/protocol" | |
| 15 | 16 | "github.com/bnema/vev/internal/usecase/picker" | |
| 16 | 17 | ) | |
| 17 | 18 | ||
| @@ -37,7 +38,7 @@ func (c *remotePreviewTestClock) Advance(delta time.Duration) { | |||
| 37 | 38 | type remotePreviewTestClient struct { | |
| 38 | 39 | mu sync.Mutex | |
| 39 | 40 | calls int | |
| 40 | - | result ports.RemotePreview | |
| 41 | + | result protocol.RemotePreview | |
| 41 | 42 | err error | |
| 42 | 43 | started chan struct{} | |
| 43 | 44 | finished chan struct{} | |
| @@ -50,7 +51,7 @@ type remotePreviewTestClient struct { | |||
| 50 | 51 | finishedSignal bool | |
| 51 | 52 | } | |
| 52 | 53 | ||
| 53 | - | func (c *remotePreviewTestClient) Preview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (ports.RemotePreview, error) { | |
| 54 | + | func (c *remotePreviewTestClient) Preview(ctx context.Context, target domain.RemoteSessionTarget, width, height uint16) (protocol.RemotePreview, error) { | |
| 54 | 55 | c.mu.Lock() | |
| 55 | 56 | c.calls++ | |
| 56 | 57 | c.lastTarget = target | |
| @@ -69,7 +70,7 @@ func (c *remotePreviewTestClient) Preview(ctx context.Context, target domain.Rem | |||
| 69 | 70 | select { | |
| 70 | 71 | case <-release: | |
| 71 | 72 | case <-ctx.Done(): | |
| 72 | - | return ports.RemotePreview{}, ctx.Err() | |
| 73 | + | return protocol.RemotePreview{}, ctx.Err() | |
| 73 | 74 | } | |
| 74 | 75 | } | |
| 75 | 76 | } | |
| @@ -111,13 +112,13 @@ func remotePreviewCacheTarget() domain.RemoteSessionTarget { | |||
| 111 | 112 | } | |
| 112 | 113 | } | |
| 113 | 114 | ||
| 114 | - | func remotePreviewCacheResult(target domain.RemoteSessionTarget, revision uint64) ports.RemotePreview { | |
| 115 | + | func remotePreviewCacheResult(target domain.RemoteSessionTarget, revision uint64) protocol.RemotePreview { | |
| 115 | 116 | return remotePreviewCacheResultRune(target, revision, 'x') | |
| 116 | 117 | } | |
| 117 | 118 | ||
| 118 | - | func remotePreviewCacheResultRune(target domain.RemoteSessionTarget, revision uint64, value rune) ports.RemotePreview { | |
| 119 | - | return ports.RemotePreview{ | |
| 120 | - | Version: ports.RemotePreviewSchemaVersion, Status: ports.RemotePreviewOK, | |
| 119 | + | func remotePreviewCacheResultRune(target domain.RemoteSessionTarget, revision uint64, value rune) protocol.RemotePreview { | |
| 120 | + | return protocol.RemotePreview{ | |
| 121 | + | Version: protocol.RemotePreviewSchemaVersion, Status: protocol.RemotePreviewOK, | |
| 121 | 122 | LifecycleID: target.LifecycleID, TabID: target.LiveTabID, | |
| 122 | 123 | Revision: revision, Width: 1, Height: 1, | |
| 123 | 124 | Cells: []renderer.Cell{{Rune: value, Style: renderer.DefaultStyle()}}, | |
| @@ -136,7 +137,7 @@ func TestFetchRemotePreviewSingleFlightAndCopiesCache(t *testing.T) { | |||
| 136 | 137 | d.remotePreviewClient = client | |
| 137 | 138 | ||
| 138 | 139 | firstDone := make(chan struct{}) | |
| 139 | - | var first ports.RemotePreview | |
| 140 | + | var first protocol.RemotePreview | |
| 140 | 141 | var firstErr error | |
| 141 | 142 | go func() { | |
| 142 | 143 | first, firstErr = d.fetchRemotePreview(context.Background(), target, 1, 1) | |
| @@ -145,7 +146,7 @@ func TestFetchRemotePreviewSingleFlightAndCopiesCache(t *testing.T) { | |||
| 145 | 146 | <-client.started | |
| 146 | 147 | ||
| 147 | 148 | secondDone := make(chan struct{}) | |
| 148 | - | var second ports.RemotePreview | |
| 149 | + | var second protocol.RemotePreview | |
| 149 | 150 | var secondErr error | |
| 150 | 151 | go func() { | |
| 151 | 152 | second, secondErr = d.fetchRemotePreview(context.Background(), target, 1, 1) | |
| @@ -169,12 +170,12 @@ func TestFetchRemotePreviewSingleFlightAndCopiesCache(t *testing.T) { | |||
| 169 | 170 | func TestFetchRemotePreviewAdapterTimeoutAppliesCooldown(t *testing.T) { | |
| 170 | 171 | clock := &remotePreviewTestClock{now: time.Unix(250, 0)} | |
| 171 | 172 | target := remotePreviewCacheTarget() | |
| 172 | - | client := &remotePreviewTestClient{err: ports.ErrRemotePreviewTimeout} | |
| 173 | + | client := &remotePreviewTestClient{err: protocol.ErrRemotePreviewTimeout} | |
| 173 | 174 | d := newTestDaemon(t, nil, clock) | |
| 174 | 175 | d.remotePreviewClient = client | |
| 175 | 176 | ||
| 176 | 177 | _, firstErr := d.fetchRemotePreview(context.Background(), target, 1, 1) | |
| 177 | - | require.ErrorIs(t, firstErr, ports.ErrRemotePreviewTimeout) | |
| 178 | + | require.ErrorIs(t, firstErr, protocol.ErrRemotePreviewTimeout) | |
| 178 | 179 | _, secondErr := d.fetchRemotePreview(context.Background(), target, 1, 1) | |
| 179 | 180 | require.ErrorIs(t, secondErr, errRemotePreviewCooldown) | |
| 180 | 181 | require.Equal(t, 1, client.Calls()) | |
| @@ -482,7 +483,7 @@ func TestFetchRemotePreviewRejectsInvalidDimensionsBeforeRemoteIO(t *testing.T) | |||
| 482 | 483 | d := newTestDaemon(t, nil, clock) | |
| 483 | 484 | d.remotePreviewClient = client | |
| 484 | 485 | ||
| 485 | - | _, err := d.fetchRemotePreview(context.Background(), remotePreviewCacheTarget(), ports.RemotePreviewMaxWidth+1, 1) | |
| 486 | - | require.ErrorIs(t, err, ports.ErrInvalidRemotePreviewRequest) | |
| 486 | + | _, err := d.fetchRemotePreview(context.Background(), remotePreviewCacheTarget(), protocol.RemotePreviewMaxWidth+1, 1) | |
| 487 | + | require.ErrorIs(t, err, protocol.ErrInvalidRemotePreviewRequest) | |
| 487 | 488 | require.Zero(t, client.Calls()) | |
| 488 | 489 | } | |
M internal/usecase/daemon/remote_preview_capture_test.go +8 -8
| @@ -8,7 +8,7 @@ import ( | |||
| 8 | 8 | vt "github.com/bnema/vev-vt" | |
| 9 | 9 | renderer "github.com/bnema/vev-vt/ansi" | |
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | - | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 12 | ) | |
| 13 | 13 | ||
| 14 | 14 | func TestCaptureRemotePreviewUsesBottomRowsForShorterPreview(t *testing.T) { | |
| @@ -28,8 +28,8 @@ func TestCaptureRemotePreviewUsesBottomRowsForShorterPreview(t *testing.T) { | |||
| 28 | 28 | Endpoint: "arch", DisplayOrigin: "arch", LifecycleID: sess.incarnation, | |
| 29 | 29 | SessionName: "work", LiveTabID: "tab-1", | |
| 30 | 30 | } | |
| 31 | - | preview, err := d.captureRemotePreview(ports.RemotePreviewRequest{ | |
| 32 | - | Version: ports.RemotePreviewSchemaVersion, Target: target, Width: 1, Height: 2, | |
| 31 | + | preview, err := d.captureRemotePreview(protocol.RemotePreviewRequest{ | |
| 32 | + | Version: protocol.RemotePreviewSchemaVersion, Target: target, Width: 1, Height: 2, | |
| 33 | 33 | }) | |
| 34 | 34 | require.NoError(t, err) | |
| 35 | 35 | require.Equal(t, []rune{'b', 'c'}, []rune{preview.Cells[0].Rune, preview.Cells[1].Rune}) | |
| @@ -112,8 +112,8 @@ func TestCaptureRemotePreviewCompactsBlankTail(t *testing.T) { | |||
| 112 | 112 | Endpoint: "arch", DisplayOrigin: "arch", LifecycleID: sess.incarnation, | |
| 113 | 113 | SessionName: "work", LiveTabID: "tab-1", | |
| 114 | 114 | } | |
| 115 | - | preview, err := d.captureRemotePreview(ports.RemotePreviewRequest{ | |
| 116 | - | Version: ports.RemotePreviewSchemaVersion, Target: target, Width: test.width, Height: test.height, | |
| 115 | + | preview, err := d.captureRemotePreview(protocol.RemotePreviewRequest{ | |
| 116 | + | Version: protocol.RemotePreviewSchemaVersion, Target: target, Width: test.width, Height: test.height, | |
| 117 | 117 | }) | |
| 118 | 118 | require.NoError(t, err) | |
| 119 | 119 | require.Equal(t, test.wantHeight, preview.Height) | |
| @@ -156,13 +156,13 @@ func TestCaptureRemotePreviewDoesNotSplitWideRuneAtCropBoundary(t *testing.T) { | |||
| 156 | 156 | Endpoint: "arch", DisplayOrigin: "arch", LifecycleID: sess.incarnation, | |
| 157 | 157 | SessionName: "work", LiveTabID: "tab-1", | |
| 158 | 158 | } | |
| 159 | - | preview, err := d.captureRemotePreview(ports.RemotePreviewRequest{ | |
| 160 | - | Version: ports.RemotePreviewSchemaVersion, Target: target, Width: 2, Height: 1, | |
| 159 | + | preview, err := d.captureRemotePreview(protocol.RemotePreviewRequest{ | |
| 160 | + | Version: protocol.RemotePreviewSchemaVersion, Target: target, Width: 2, Height: 1, | |
| 161 | 161 | }) | |
| 162 | 162 | require.NoError(t, err) | |
| 163 | 163 | require.Equal(t, uint16(2), preview.Width) | |
| 164 | 164 | require.Equal(t, rune(' '), preview.Cells[1].Rune, "a crop cannot expose a dangling wide rune") | |
| 165 | 165 | require.False(t, preview.Cells[1].Continuation) | |
| 166 | 166 | require.True(t, preview.Cells[1].Style.Equal(style), "boundary replacement preserves the cell style") | |
| 167 | - | require.NoError(t, ports.ValidateRemotePreview(preview)) | |
| 167 | + | require.NoError(t, protocol.ValidateRemotePreview(preview)) | |
| 168 | 168 | } | |
M internal/usecase/daemon/remote_route_test.go +9 -9
| @@ -122,9 +122,9 @@ func TestFinishRouteAttachRollsBackCreatedSession(t *testing.T) { | |||
| 122 | 122 | // both success and error paths before returning. | |
| 123 | 123 | d.mu.Lock() | |
| 124 | 124 | _, err = d.finishRouteAttach(sess, &closeTrackingTransport{}, defaultSize, hello, true, true) | |
| 125 | - | var protocol *protoErr | |
| 126 | - | require.ErrorAs(t, err, &protocol) | |
| 127 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 125 | + | var protocolErr *protoErr | |
| 126 | + | require.ErrorAs(t, err, &protocolErr) | |
| 127 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 128 | 128 | d.mu.Lock() | |
| 129 | 129 | _, retained := d.sessions[sess.id] | |
| 130 | 130 | d.mu.Unlock() | |
| @@ -146,9 +146,9 @@ func TestFinishRouteAttachPreservesConcurrentAttachment(t *testing.T) { | |||
| 146 | 146 | RemoteTarget: &missing, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 147 | 147 | }, true, true) | |
| 148 | 148 | ||
| 149 | - | var protocol *protoErr | |
| 150 | - | require.ErrorAs(t, err, &protocol) | |
| 151 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 149 | + | var protocolErr *protoErr | |
| 150 | + | require.ErrorAs(t, err, &protocolErr) | |
| 151 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 152 | 152 | require.Same(t, sess, winner().currentAttachmentSession()) | |
| 153 | 153 | d.mu.Lock() | |
| 154 | 154 | require.Same(t, sess, d.sessions[sess.id]) | |
| @@ -217,7 +217,7 @@ func TestRouteRemoteTargetRejectsSameNameReplacement(t *testing.T) { | |||
| 217 | 217 | target := domain.RemoteSessionTarget{Endpoint: "arch", DisplayOrigin: "arch", LifecycleID: old, SessionName: "work", LiveTabID: "tab-new"} | |
| 218 | 218 | hello := ports.Hello{Version: ports.ProtocolVersion, Intent: ports.IntentAttach, Name: "work", Size: domain.Size{Cols: 80, Rows: 24}, RemoteTarget: &target, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned} | |
| 219 | 219 | _, _, err := d.routeWithContext(context.Background(), hello, tr) | |
| 220 | - | var protocol *protoErr | |
| 221 | - | require.ErrorAs(t, err, &protocol) | |
| 222 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 220 | + | var protocolErr *protoErr | |
| 221 | + | require.ErrorAs(t, err, &protocolErr) | |
| 222 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 223 | 223 | } | |
M internal/usecase/daemon/remote_stopped_route_test.go +16 -16
| @@ -30,9 +30,9 @@ func TestDaemonOwnedNoExactTargetRejectsNewAndEphemeral(t *testing.T) { | |||
| 30 | 30 | Env: []string{"UNTRUSTED=client"}, EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 31 | 31 | } | |
| 32 | 32 | _, _, err := d.route(hello, &closeTrackingTransport{}) | |
| 33 | - | var protocol *protoErr | |
| 34 | - | require.ErrorAs(t, err, &protocol) | |
| 35 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 33 | + | var protocolErr *protoErr | |
| 34 | + | require.ErrorAs(t, err, &protocolErr) | |
| 35 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 36 | 36 | d.mu.Lock() | |
| 37 | 37 | sessions := len(d.sessions) | |
| 38 | 38 | d.mu.Unlock() | |
| @@ -83,9 +83,9 @@ func TestRouteRemoteTargetRejectsLiveIntentForInactiveSession(t *testing.T) { | |||
| 83 | 83 | EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 84 | 84 | }, &closeTrackingTransport{}) | |
| 85 | 85 | ||
| 86 | - | var protocol *protoErr | |
| 87 | - | require.ErrorAs(t, err, &protocol) | |
| 88 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 86 | + | var protocolErr *protoErr | |
| 87 | + | require.ErrorAs(t, err, &protocolErr) | |
| 88 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 89 | 89 | d.mu.Lock() | |
| 90 | 90 | defer d.mu.Unlock() | |
| 91 | 91 | require.Empty(t, d.sessions) | |
| @@ -115,9 +115,9 @@ func TestRouteRemoteTargetMapsUnavailableInactiveStatesToNoSuchTarget(t *testing | |||
| 115 | 115 | EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 116 | 116 | }, &closeTrackingTransport{}) | |
| 117 | 117 | ||
| 118 | - | var protocol *protoErr | |
| 119 | - | require.ErrorAs(t, err, &protocol) | |
| 120 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 118 | + | var protocolErr *protoErr | |
| 119 | + | require.ErrorAs(t, err, &protocolErr) | |
| 120 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 121 | 121 | }) | |
| 122 | 122 | } | |
| 123 | 123 | } | |
| @@ -138,9 +138,9 @@ func TestRouteRemoteTargetMapsConcurrentInactiveResumeToNoSuchTarget(t *testing. | |||
| 138 | 138 | EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned, | |
| 139 | 139 | }, &closeTrackingTransport{}) | |
| 140 | 140 | ||
| 141 | - | var protocol *protoErr | |
| 142 | - | require.ErrorAs(t, err, &protocol) | |
| 143 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 141 | + | var protocolErr *protoErr | |
| 142 | + | require.ErrorAs(t, err, &protocolErr) | |
| 143 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 144 | 144 | } | |
| 145 | 145 | ||
| 146 | 146 | func TestRouteRemoteTargetPreservesInactiveResumeFailures(t *testing.T) { | |
| @@ -172,8 +172,8 @@ func TestRouteRemoteTargetPreservesInactiveResumeFailures(t *testing.T) { | |||
| 172 | 172 | ||
| 173 | 173 | err := route(d, newTarget(record)) | |
| 174 | 174 | require.ErrorIs(t, err, cause) | |
| 175 | - | var protocol *protoErr | |
| 176 | - | require.False(t, errors.As(err, &protocol)) | |
| 175 | + | var protocolErr *protoErr | |
| 176 | + | require.False(t, errors.As(err, &protocolErr)) | |
| 177 | 177 | }) | |
| 178 | 178 | ||
| 179 | 179 | t.Run("catalogue read", func(t *testing.T) { | |
| @@ -191,8 +191,8 @@ func TestRouteRemoteTargetPreservesInactiveResumeFailures(t *testing.T) { | |||
| 191 | 191 | ||
| 192 | 192 | err := route(d, newTarget(record)) | |
| 193 | 193 | require.ErrorIs(t, err, cause) | |
| 194 | - | var protocol *protoErr | |
| 195 | - | require.False(t, errors.As(err, &protocol)) | |
| 194 | + | var protocolErr *protoErr | |
| 195 | + | require.False(t, errors.As(err, &protocolErr)) | |
| 196 | 196 | }) | |
| 197 | 197 | } | |
| 198 | 198 | ||
M internal/usecase/daemon/render_coordinator_test.go +2 -1
| @@ -14,6 +14,7 @@ import ( | |||
| 14 | 14 | "github.com/bnema/vev/internal/domain" | |
| 15 | 15 | "github.com/bnema/vev/internal/ports" | |
| 16 | 16 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 17 | + | "github.com/bnema/vev/internal/protocol" | |
| 17 | 18 | "github.com/bnema/vev/internal/usecase/keys" | |
| 18 | 19 | "github.com/bnema/vev/internal/usecase/layout" | |
| 19 | 20 | ) | |
| @@ -1164,7 +1165,7 @@ func TestProducerInvalidations(t *testing.T) { | |||
| 1164 | 1165 | file: "client.go", | |
| 1165 | 1166 | name: "client theme application", | |
| 1166 | 1167 | run: func(t *testing.T, d *Daemon, sess *session, ac *attachedClient) { | |
| 1167 | - | d.applyTheme(sess, ac, ports.Theme{TrueColor: true}) | |
| 1168 | + | d.applyTheme(sess, ac, protocol.Theme{TrueColor: true}) | |
| 1168 | 1169 | }, | |
| 1169 | 1170 | }, | |
| 1170 | 1171 | { | |
M internal/usecase/daemon/render_pipeline.go +3 -2
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | renderer "github.com/bnema/vev-vt" | |
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | 8 | "github.com/bnema/vev/internal/ports" | |
| 9 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 10 | "github.com/bnema/vev/internal/usecase/layout" | |
| 10 | 11 | "github.com/bnema/vev/internal/usecase/notices" | |
| 11 | 12 | "github.com/bnema/vev/internal/usecase/palette" | |
| @@ -416,8 +417,8 @@ func (d *Daemon) emitFrame(entry *session, ac *attachedClient, state *capturedRe | |||
| 416 | 417 | } | |
| 417 | 418 | entry.core().mu.Lock() | |
| 418 | 419 | _, owned := entry.core().attachments[ac] | |
| 419 | - | position := ports.RoutePosition{ | |
| 420 | - | Target: ports.ExactSessionTarget{ | |
| 420 | + | position := protocol.RoutePosition{ | |
| 421 | + | Target: protocol.ExactSessionTarget{ | |
| 421 | 422 | LifecycleID: entry.core().incarnation, | |
| 422 | 423 | SessionName: entry.core().name, | |
| 423 | 424 | }, | |
M internal/usecase/daemon/resume_test.go +9 -9
| @@ -101,9 +101,9 @@ func TestTokenlessResumeIsRejectedBeforeNameRouting(t *testing.T) { | |||
| 101 | 101 | d := newTestDaemon(t, nil, stubClock{}) | |
| 102 | 102 | tr, _ := newCapturingTransport(t) | |
| 103 | 103 | _, _, err := d.route(helloResumeCapable(ports.IntentResume, "work", 0), tr) | |
| 104 | - | var protocol *protoErr | |
| 105 | - | require.ErrorAs(t, err, &protocol) | |
| 106 | - | require.Equal(t, ports.ErrNoSuchSession, protocol.code) | |
| 104 | + | var protocolErr *protoErr | |
| 105 | + | require.ErrorAs(t, err, &protocolErr) | |
| 106 | + | require.Equal(t, ports.ErrNoSuchSession, protocolErr.code) | |
| 107 | 107 | d.mu.Lock() | |
| 108 | 108 | sessionCount := len(d.sessions) | |
| 109 | 109 | d.mu.Unlock() | |
| @@ -126,9 +126,9 @@ func TestResumeRejectsMismatchedRemoteTargetBeforeOwnershipMutation(t *testing.T | |||
| 126 | 126 | resume.RemoteTarget = &target | |
| 127 | 127 | resume.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |
| 128 | 128 | _, _, err = d.route(resume, &closeTrackingTransport{}) | |
| 129 | - | var protocol *protoErr | |
| 130 | - | require.ErrorAs(t, err, &protocol) | |
| 131 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 129 | + | var protocolErr *protoErr | |
| 130 | + | require.ErrorAs(t, err, &protocolErr) | |
| 131 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 132 | 132 | require.Same(t, oldTransport, ac.transport()) | |
| 133 | 133 | d.mu.Lock() | |
| 134 | 134 | _, parked := d.parked[token] | |
| @@ -155,9 +155,9 @@ func TestParkedResumeRejectsMismatchedRemoteTargetBeforeClaim(t *testing.T) { | |||
| 155 | 155 | resume.RemoteTarget = &target | |
| 156 | 156 | resume.EnvironmentPolicy = ports.EnvironmentPolicyDaemonOwned | |
| 157 | 157 | _, _, err = d.route(resume, &closeTrackingTransport{}) | |
| 158 | - | var protocol *protoErr | |
| 159 | - | require.ErrorAs(t, err, &protocol) | |
| 160 | - | require.Equal(t, ports.ErrNoSuchTarget, protocol.code) | |
| 158 | + | var protocolErr *protoErr | |
| 159 | + | require.ErrorAs(t, err, &protocolErr) | |
| 160 | + | require.Equal(t, ports.ErrNoSuchTarget, protocolErr.code) | |
| 161 | 161 | d.mu.Lock() | |
| 162 | 162 | parked := d.parked[token] | |
| 163 | 163 | claimed := parked != nil && parked.claimed | |
M internal/usecase/daemon/route_identity_test_helpers_test.go +5 -5
| @@ -2,15 +2,15 @@ package daemon | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "github.com/bnema/vev/internal/domain" | |
| 5 | - | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | 6 | ) | |
| 7 | 7 | ||
| 8 | - | func testRouteTarget(name string, marker byte) ports.ExactSessionTarget { | |
| 9 | - | return ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{marker}, SessionName: name} | |
| 8 | + | func testRouteTarget(name string, marker byte) protocol.ExactSessionTarget { | |
| 9 | + | return protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{marker}, SessionName: name} | |
| 10 | 10 | } | |
| 11 | 11 | ||
| 12 | - | func testRouteEntry(key, generation uint64, name string, marker byte, kind ports.RouteKind) ports.RecentRouteEntry { | |
| 13 | - | return ports.RecentRouteEntry{ | |
| 12 | + | func testRouteEntry(key, generation uint64, name string, marker byte, kind protocol.RouteKind) protocol.RecentRouteEntry { | |
| 13 | + | return protocol.RecentRouteEntry{ | |
| 14 | 14 | Key: key, Generation: generation, Target: testRouteTarget(name, marker), | |
| 15 | 15 | Name: name, Kind: kind, | |
| 16 | 16 | } | |
M internal/usecase/daemon/route_position_test.go +5 -4
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | 10 | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | ) | |
| 12 | 13 | ||
| 13 | 14 | func TestRouteAppliesPreferredTabPerAttachment(t *testing.T) { | |
| @@ -28,7 +29,7 @@ func TestRouteAppliesPreferredTabPerAttachment(t *testing.T) { | |||
| 28 | 29 | sess.tabs = append(sess.tabs, second) | |
| 29 | 30 | sess.mu.Unlock() | |
| 30 | 31 | tr := &closeTrackingTransport{} | |
| 31 | - | target := ports.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 32 | + | target := protocol.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 32 | 33 | hello := ports.Hello{ | |
| 33 | 34 | Version: ports.ProtocolVersion, Intent: ports.IntentAttach, Name: sess.name, | |
| 34 | 35 | Size: defaultSize, ExactTarget: &target, PreferredTabID: test.preferred, | |
| @@ -78,7 +79,7 @@ func TestPaintPublishesChangedAttachmentRoutePosition(t *testing.T) { | |||
| 78 | 79 | sess.tabs = append(sess.tabs, second) | |
| 79 | 80 | sess.mu.Unlock() | |
| 80 | 81 | tr := &closeTrackingTransport{} | |
| 81 | - | target := ports.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 82 | + | target := protocol.ExactSessionTarget{LifecycleID: sess.incarnation, SessionName: sess.name} | |
| 82 | 83 | hello := ports.Hello{ | |
| 83 | 84 | Version: ports.ProtocolVersion, Intent: ports.IntentAttach, Name: sess.name, | |
| 84 | 85 | Size: defaultSize, ExactTarget: &target, EnvironmentPolicy: ports.EnvironmentPolicyClientOwned, | |
| @@ -93,7 +94,7 @@ func TestPaintPublishesChangedAttachmentRoutePosition(t *testing.T) { | |||
| 93 | 94 | sess.selectAttachmentTab(ac, "tab-2") | |
| 94 | 95 | d.paint(sess, ac, false, nil) | |
| 95 | 96 | ||
| 96 | - | var positions []ports.RoutePosition | |
| 97 | + | var positions []protocol.RoutePosition | |
| 97 | 98 | for _, frame := range tr.Sends() { | |
| 98 | 99 | if frame.Type != ports.MsgRoutePosition { | |
| 99 | 100 | continue | |
| @@ -102,7 +103,7 @@ func TestPaintPublishesChangedAttachmentRoutePosition(t *testing.T) { | |||
| 102 | 103 | require.NoError(t, err) | |
| 103 | 104 | positions = append(positions, position) | |
| 104 | 105 | } | |
| 105 | - | require.Equal(t, []ports.RoutePosition{ | |
| 106 | + | require.Equal(t, []protocol.RoutePosition{ | |
| 106 | 107 | {Target: target, ActiveTabID: "tab-1"}, | |
| 107 | 108 | {Target: target, ActiveTabID: "tab-2"}, | |
| 108 | 109 | }, positions) | |
M internal/usecase/daemon/same_peer_switch.go +10 -9
| @@ -3,9 +3,10 @@ package daemon | |||
| 3 | 3 | import ( | |
| 4 | 4 | "github.com/bnema/vev/internal/domain" | |
| 5 | 5 | "github.com/bnema/vev/internal/ports" | |
| 6 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | 7 | ) | |
| 7 | 8 | ||
| 8 | - | func (ac *attachedClient) offerSamePeerTarget(target ports.ExactSessionTarget) { | |
| 9 | + | func (ac *attachedClient) offerSamePeerTarget(target protocol.ExactSessionTarget) { | |
| 9 | 10 | ac.samePeerOfferMu.Lock() | |
| 10 | 11 | ac.samePeerOffer = &target | |
| 11 | 12 | ac.samePeerOfferMu.Unlock() | |
| @@ -20,7 +21,7 @@ func (ac *attachedClient) clearSamePeerOffer() { | |||
| 20 | 21 | // consumeSamePeerOffer linearizes the client confirmation with the daemon's | |
| 21 | 22 | // endpoint-empty offer. A client cannot select an arbitrary local session by | |
| 22 | 23 | // manufacturing this frame. | |
| 23 | - | func (ac *attachedClient) consumeSamePeerOffer(target ports.ExactSessionTarget) bool { | |
| 24 | + | func (ac *attachedClient) consumeSamePeerOffer(target protocol.ExactSessionTarget) bool { | |
| 24 | 25 | ac.samePeerOfferMu.Lock() | |
| 25 | 26 | defer ac.samePeerOfferMu.Unlock() | |
| 26 | 27 | if ac.samePeerOffer == nil || *ac.samePeerOffer != target { | |
| @@ -33,18 +34,18 @@ func (ac *attachedClient) consumeSamePeerOffer(target ports.ExactSessionTarget) | |||
| 33 | 34 | // switchSamePeerForAttachment commits one client-confirmed endpoint-empty | |
| 34 | 35 | // target. The request never names an endpoint: its authority is the current | |
| 35 | 36 | // authenticated attachment plus the target's exact lifecycle identity. | |
| 36 | - | func (d *Daemon) switchSamePeerForAttachment(effect *attachmentEffect, request ports.SamePeerSwitchRequest) { | |
| 37 | + | func (d *Daemon) switchSamePeerForAttachment(effect *attachmentEffect, request protocol.SamePeerSwitchRequest) { | |
| 37 | 38 | if err := request.Validate(); err != nil || !effect.current() || effect.sess == nil || effect.ac == nil { | |
| 38 | 39 | return | |
| 39 | 40 | } | |
| 40 | 41 | if !effect.ac.consumeSamePeerOffer(request.Target) { | |
| 41 | - | d.sendSamePeerSwitchFailure(effect, request.RequestID, ports.SamePeerSwitchStaleTarget) | |
| 42 | + | d.sendSamePeerSwitchFailure(effect, request.RequestID, protocol.SamePeerSwitchStaleTarget) | |
| 42 | 43 | return | |
| 43 | 44 | } | |
| 44 | 45 | ||
| 45 | 46 | target, targetTabIndex, ok := d.samePeerTarget(request) | |
| 46 | 47 | if !ok || target == effect.sess { | |
| 47 | - | d.sendSamePeerSwitchFailure(effect, request.RequestID, ports.SamePeerSwitchStaleTarget) | |
| 48 | + | d.sendSamePeerSwitchFailure(effect, request.RequestID, protocol.SamePeerSwitchStaleTarget) | |
| 48 | 49 | return | |
| 49 | 50 | } | |
| 50 | 51 | ||
| @@ -67,7 +68,7 @@ func (d *Daemon) switchSamePeerForAttachment(effect *attachmentEffect, request p | |||
| 67 | 68 | ready: true, | |
| 68 | 69 | }) | |
| 69 | 70 | if err != nil { | |
| 70 | - | d.sendSamePeerSwitchFailure(effect, request.RequestID, ports.SamePeerSwitchStaleTarget) | |
| 71 | + | d.sendSamePeerSwitchFailure(effect, request.RequestID, protocol.SamePeerSwitchStaleTarget) | |
| 71 | 72 | return | |
| 72 | 73 | } | |
| 73 | 74 | ||
| @@ -83,7 +84,7 @@ func (d *Daemon) switchSamePeerForAttachment(effect *attachmentEffect, request p | |||
| 83 | 84 | // samePeerTarget resolves the exact target and the client-owned tab cursor | |
| 84 | 85 | // under the daemon/session locks. A missing cursor deliberately falls back to | |
| 85 | 86 | // the target session's current default rather than leaking the source view. | |
| 86 | - | func (d *Daemon) samePeerTarget(request ports.SamePeerSwitchRequest) (*session, int, bool) { | |
| 87 | + | func (d *Daemon) samePeerTarget(request protocol.SamePeerSwitchRequest) (*session, int, bool) { | |
| 87 | 88 | d.mu.Lock() | |
| 88 | 89 | defer d.mu.Unlock() | |
| 89 | 90 | ||
| @@ -108,7 +109,7 @@ func (d *Daemon) samePeerTarget(request ports.SamePeerSwitchRequest) (*session, | |||
| 108 | 109 | return target, tabIndex, true | |
| 109 | 110 | } | |
| 110 | 111 | ||
| 111 | - | func (d *Daemon) sendSamePeerSwitchFailure(effect *attachmentEffect, requestID uint64, code ports.SamePeerSwitchFailureCode) { | |
| 112 | + | func (d *Daemon) sendSamePeerSwitchFailure(effect *attachmentEffect, requestID uint64, code protocol.SamePeerSwitchFailureCode) { | |
| 112 | 113 | if effect == nil || effect.ac == nil { | |
| 113 | 114 | return | |
| 114 | 115 | } | |
| @@ -121,7 +122,7 @@ func (d *Daemon) sendSamePeerSwitchFailure(effect *attachmentEffect, requestID u | |||
| 121 | 122 | } | |
| 122 | 123 | defer sender.End() | |
| 123 | 124 | } | |
| 124 | - | payload, err := ports.MarshalSamePeerSwitchFailure(ports.SamePeerSwitchFailure{RequestID: requestID, Code: code}) | |
| 125 | + | payload, err := ports.MarshalSamePeerSwitchFailure(protocol.SamePeerSwitchFailure{RequestID: requestID, Code: code}) | |
| 125 | 126 | if err != nil { | |
| 126 | 127 | return | |
| 127 | 128 | } | |
M internal/usecase/daemon/same_peer_switch_test.go +13 -12
| @@ -7,6 +7,7 @@ import ( | |||
| 7 | 7 | ||
| 8 | 8 | "github.com/bnema/vev/internal/domain" | |
| 9 | 9 | "github.com/bnema/vev/internal/ports" | |
| 10 | + | "github.com/bnema/vev/internal/protocol" | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| 12 | 13 | func TestPaletteSessionSelectionCompletesSamePeerSwitch(t *testing.T) { | |
| @@ -26,7 +27,7 @@ func TestPaletteSessionSelectionCompletesSamePeerSwitch(t *testing.T) { | |||
| 26 | 27 | d.mu.Lock() | |
| 27 | 28 | d.sessions[target.id] = target | |
| 28 | 29 | d.mu.Unlock() | |
| 29 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 30 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 30 | 31 | ||
| 31 | 32 | token := beginRecentRoutePaletteEffect(t, d, source, ac) | |
| 32 | 33 | d.handleInputForAttachment(token, []byte("\x1b ")) | |
| @@ -35,9 +36,9 @@ func TestPaletteSessionSelectionCompletesSamePeerSwitch(t *testing.T) { | |||
| 35 | 36 | targetFrame := awaitFrame(t, sends, ports.MsgAttachTarget) | |
| 36 | 37 | attachTarget, err := ports.UnmarshalAttachTarget(targetFrame.Payload) | |
| 37 | 38 | require.NoError(t, err) | |
| 38 | - | require.Equal(t, &ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "target"}, attachTarget.ExactTarget) | |
| 39 | + | require.Equal(t, &protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "target"}, attachTarget.ExactTarget) | |
| 39 | 40 | ||
| 40 | - | d.switchSamePeerForAttachment(token, ports.SamePeerSwitchRequest{ | |
| 41 | + | d.switchSamePeerForAttachment(token, protocol.SamePeerSwitchRequest{ | |
| 41 | 42 | RequestID: 1, Target: *attachTarget.ExactTarget, | |
| 42 | 43 | }) | |
| 43 | 44 | ||
| @@ -68,16 +69,16 @@ func TestSamePeerSwitchTransitionsExactTargetAndPreferredTab(t *testing.T) { | |||
| 68 | 69 | d.mu.Lock() | |
| 69 | 70 | d.sessions[target.id] = target | |
| 70 | 71 | d.mu.Unlock() | |
| 71 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 72 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 72 | 73 | ||
| 73 | 74 | token := source.captureAttachmentCapability(ac, ac.transport()) | |
| 74 | 75 | effect, admitted := ac.beginAttachmentEffect(token) | |
| 75 | 76 | require.True(t, admitted) | |
| 76 | 77 | defer effect.End() | |
| 77 | - | requestTarget := ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "target"} | |
| 78 | + | requestTarget := protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "target"} | |
| 78 | 79 | ac.offerSamePeerTarget(requestTarget) | |
| 79 | 80 | ||
| 80 | - | d.switchSamePeerForAttachment(effect, ports.SamePeerSwitchRequest{ | |
| 81 | + | d.switchSamePeerForAttachment(effect, protocol.SamePeerSwitchRequest{ | |
| 81 | 82 | RequestID: 1, | |
| 82 | 83 | Target: requestTarget, | |
| 83 | 84 | PreferredTabID: domain.TabStableID(target.tabs[1].stableID), | |
| @@ -88,13 +89,13 @@ func TestSamePeerSwitchTransitionsExactTargetAndPreferredTab(t *testing.T) { | |||
| 88 | 89 | identityFrame := awaitFrame(t, sends, ports.MsgCommittedRouteIdentity) | |
| 89 | 90 | identity, err := ports.UnmarshalCommittedRouteIdentity(identityFrame.Payload) | |
| 90 | 91 | require.NoError(t, err) | |
| 91 | - | require.Equal(t, ports.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "target"}, identity.Target) | |
| 92 | + | require.Equal(t, protocol.ExactSessionTarget{LifecycleID: lifecycle, SessionName: "target"}, identity.Target) | |
| 92 | 93 | } | |
| 93 | 94 | ||
| 94 | 95 | func TestFinishSendErrorDetachClearsSamePeerOffer(t *testing.T) { | |
| 95 | 96 | d, sess, ac, _, releases := newManualTabSession(t, 1) | |
| 96 | 97 | defer releaseAll(releases) | |
| 97 | - | ac.offerSamePeerTarget(ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "target"}) | |
| 98 | + | ac.offerSamePeerTarget(protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{1}, SessionName: "target"}) | |
| 98 | 99 | ||
| 99 | 100 | d.finishSendErrorDetach(sess, ac, ac.transport()) | |
| 100 | 101 | ||
| @@ -106,21 +107,21 @@ func TestFinishSendErrorDetachClearsSamePeerOffer(t *testing.T) { | |||
| 106 | 107 | func TestSamePeerSwitchRejectsStaleTargetWithoutMutation(t *testing.T) { | |
| 107 | 108 | d, source, ac, sends, releases := newManualTabSession(t, 1) | |
| 108 | 109 | defer releaseAll(releases) | |
| 109 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 110 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 110 | 111 | ||
| 111 | 112 | token := source.captureAttachmentCapability(ac, ac.transport()) | |
| 112 | 113 | effect, admitted := ac.beginAttachmentEffect(token) | |
| 113 | 114 | require.True(t, admitted) | |
| 114 | 115 | defer effect.End() | |
| 115 | 116 | ||
| 116 | - | d.switchSamePeerForAttachment(effect, ports.SamePeerSwitchRequest{ | |
| 117 | + | d.switchSamePeerForAttachment(effect, protocol.SamePeerSwitchRequest{ | |
| 117 | 118 | RequestID: 1, | |
| 118 | - | Target: ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{9}, SessionName: "missing"}, | |
| 119 | + | Target: protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{9}, SessionName: "missing"}, | |
| 119 | 120 | }) | |
| 120 | 121 | ||
| 121 | 122 | require.Same(t, source, ac.currentAttachmentSession()) | |
| 122 | 123 | failureFrame := awaitFrame(t, sends, ports.MsgSamePeerSwitchFailure) | |
| 123 | 124 | failure, err := ports.UnmarshalSamePeerSwitchFailure(failureFrame.Payload) | |
| 124 | 125 | require.NoError(t, err) | |
| 125 | - | require.Equal(t, ports.SamePeerSwitchFailure{RequestID: 1, Code: ports.SamePeerSwitchStaleTarget}, failure) | |
| 126 | + | require.Equal(t, protocol.SamePeerSwitchFailure{RequestID: 1, Code: protocol.SamePeerSwitchStaleTarget}, failure) | |
| 126 | 127 | } | |
M internal/usecase/daemon/session_back.go +2 -2
| @@ -2,7 +2,7 @@ package daemon | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "github.com/bnema/vev/internal/domain" | |
| 5 | - | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | 6 | ) | |
| 7 | 7 | ||
| 8 | 8 | // backSessionForAttachment delegates previous-route ownership to the client | |
| @@ -22,7 +22,7 @@ func (d *Daemon) backSessionForAttachment(effect *attachmentEffect) error { | |||
| 22 | 22 | if snapshot.Previous.Key == 0 || snapshot.Previous.Generation == 0 { | |
| 23 | 23 | return nil | |
| 24 | 24 | } | |
| 25 | - | return d.sendRecentRouteNavigationActionForAttachment(effect, ports.RouteNavigationAction{ | |
| 25 | + | return d.sendRecentRouteNavigationActionForAttachment(effect, protocol.RouteNavigationAction{ | |
| 26 | 26 | SnapshotGeneration: snapshot.Generation, | |
| 27 | 27 | Key: snapshot.Previous.Key, | |
| 28 | 28 | Generation: snapshot.Previous.Generation, | |
M internal/usecase/daemon/session_back_route_test.go +7 -6
| @@ -4,6 +4,7 @@ import ( | |||
| 4 | 4 | "testing" | |
| 5 | 5 | ||
| 6 | 6 | "github.com/bnema/vev/internal/ports" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 7 | 8 | "github.com/stretchr/testify/require" | |
| 8 | 9 | ) | |
| 9 | 10 | ||
| @@ -18,17 +19,17 @@ func TestBackSessionUsesClientPreviousRouteAfterSnapshotPublication(t *testing.T | |||
| 18 | 19 | effect, admitted := ac.beginAttachmentEffect(token) | |
| 19 | 20 | require.True(t, admitted) | |
| 20 | 21 | defer effect.End() | |
| 21 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 22 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 22 | 23 | Generation: 5, | |
| 23 | - | Active: ports.RouteRef{Key: 9, Generation: 5}, | |
| 24 | - | Previous: ports.RouteRef{Key: 7, Generation: 3}, | |
| 25 | - | Entries: []ports.RecentRouteEntry{testRouteEntry(7, 3, "previous", 7, ports.RouteKindLocal)}, | |
| 24 | + | Active: protocol.RouteRef{Key: 9, Generation: 5}, | |
| 25 | + | Previous: protocol.RouteRef{Key: 7, Generation: 3}, | |
| 26 | + | Entries: []protocol.RecentRouteEntry{testRouteEntry(7, 3, "previous", 7, protocol.RouteKindLocal)}, | |
| 26 | 27 | }) | |
| 27 | 28 | ||
| 28 | 29 | require.NoError(t, d.backSessionForAttachment(effect)) | |
| 29 | 30 | frames := transport.Sends() | |
| 30 | 31 | require.NotEmpty(t, frames) | |
| 31 | - | var action ports.RouteNavigationAction | |
| 32 | + | var action protocol.RouteNavigationAction | |
| 32 | 33 | found := false | |
| 33 | 34 | for _, frame := range frames { | |
| 34 | 35 | if frame.Type != ports.MsgNavigateRecentRoute { | |
| @@ -40,5 +41,5 @@ func TestBackSessionUsesClientPreviousRouteAfterSnapshotPublication(t *testing.T | |||
| 40 | 41 | found = true | |
| 41 | 42 | } | |
| 42 | 43 | require.True(t, found) | |
| 43 | - | require.Equal(t, ports.RouteNavigationAction{SnapshotGeneration: 5, Key: 7, Generation: 3}, action) | |
| 44 | + | require.Equal(t, protocol.RouteNavigationAction{SnapshotGeneration: 5, Key: 7, Generation: 3}, action) | |
| 44 | 45 | } | |
M internal/usecase/daemon/session_rename_purge_test.go +7 -6
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | "github.com/bnema/vev/internal/domain" | |
| 9 | 9 | "github.com/bnema/vev/internal/ports" | |
| 10 | 10 | portsmocks "github.com/bnema/vev/internal/ports/mocks" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 12 | ) | |
| 12 | 13 | ||
| 13 | 14 | func TestRenamePublishesCommittedRouteIdentityToAttachedClients(t *testing.T) { | |
| @@ -19,14 +20,14 @@ func TestRenamePublishesCommittedRouteIdentityToAttachedClients(t *testing.T) { | |||
| 19 | 20 | sess.mu.Unlock() | |
| 20 | 21 | token := sess.captureAttachmentCapability(ac, ac.transport()) | |
| 21 | 22 | ac.installTestAttachmentCapability(token) | |
| 22 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{Generation: 1}) | |
| 23 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{Generation: 1}) | |
| 23 | 24 | ||
| 24 | 25 | require.NoError(t, d.renameSession(sess, "vps-infra")) | |
| 25 | 26 | ||
| 26 | 27 | frame := awaitFrame(t, sends, ports.MsgCommittedRouteIdentity) | |
| 27 | 28 | identity, err := ports.UnmarshalCommittedRouteIdentity(frame.Payload) | |
| 28 | 29 | require.NoError(t, err) | |
| 29 | - | require.Equal(t, ports.ExactSessionTarget{ | |
| 30 | + | require.Equal(t, protocol.ExactSessionTarget{ | |
| 30 | 31 | LifecycleID: domain.IncarnationID{1}, | |
| 31 | 32 | SessionName: "vps-infra", | |
| 32 | 33 | }, identity.Target) | |
| @@ -46,11 +47,11 @@ func TestRenameDefersCommittedRouteIdentityUntilFirstRouteSnapshot(t *testing.T) | |||
| 46 | 47 | require.NoError(t, d.renameSession(sess, "vps-infra")) | |
| 47 | 48 | require.Empty(t, sends, "the route ledger must be published before its identity can be updated") | |
| 48 | 49 | ||
| 49 | - | activeRef := ports.RouteRef{Key: 1, Generation: 1} | |
| 50 | - | snapshot := ports.RecentRouteSnapshot{ | |
| 50 | + | activeRef := protocol.RouteRef{Key: 1, Generation: 1} | |
| 51 | + | snapshot := protocol.RecentRouteSnapshot{ | |
| 51 | 52 | Generation: 1, | |
| 52 | 53 | Active: activeRef, | |
| 53 | - | ActiveEntry: ports.RecentRouteEntry{Key: 1, Generation: 1, Target: testRouteTarget("0", 1), Name: "0", Kind: ports.RouteKindLocal}, | |
| 54 | + | ActiveEntry: protocol.RecentRouteEntry{Key: 1, Generation: 1, Target: testRouteTarget("0", 1), Name: "0", Kind: protocol.RouteKindLocal}, | |
| 54 | 55 | Home: activeRef, | |
| 55 | 56 | } | |
| 56 | 57 | payload, err := ports.MarshalRecentRouteSnapshot(snapshot) | |
| @@ -60,7 +61,7 @@ func TestRenameDefersCommittedRouteIdentityUntilFirstRouteSnapshot(t *testing.T) | |||
| 60 | 61 | frame := awaitFrame(t, sends, ports.MsgCommittedRouteIdentity) | |
| 61 | 62 | identity, err := ports.UnmarshalCommittedRouteIdentity(frame.Payload) | |
| 62 | 63 | require.NoError(t, err) | |
| 63 | - | require.Equal(t, ports.ExactSessionTarget{ | |
| 64 | + | require.Equal(t, protocol.ExactSessionTarget{ | |
| 64 | 65 | LifecycleID: domain.IncarnationID{1}, | |
| 65 | 66 | SessionName: "vps-infra", | |
| 66 | 67 | }, identity.Target) | |
M internal/usecase/daemon/status.go +6 -6
| @@ -8,7 +8,7 @@ import ( | |||
| 8 | 8 | ||
| 9 | 9 | renderer "github.com/bnema/vev-vt" | |
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | - | "github.com/bnema/vev/internal/ports" | |
| 11 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 12 | "github.com/bnema/vev/internal/usecase/command" | |
| 13 | 13 | "github.com/bnema/vev/internal/usecase/palette" | |
| 14 | 14 | themeui "github.com/bnema/vev/internal/usecase/theme" | |
| @@ -189,7 +189,7 @@ func (s *session) statusSegments(includeTerminalTitle bool) statusSnapshot { | |||
| 189 | 189 | } | |
| 190 | 190 | ||
| 191 | 191 | func (s *session) statusSegmentsFor(ac *attachedClient, includeTerminalTitle bool) statusSnapshot { | |
| 192 | - | var routeSnapshot ports.RecentRouteSnapshot | |
| 192 | + | var routeSnapshot protocol.RecentRouteSnapshot | |
| 193 | 193 | if ac != nil { | |
| 194 | 194 | routeSnapshot = ac.routeSnapshotCopy() | |
| 195 | 195 | } | |
| @@ -199,7 +199,7 @@ func (s *session) statusSegmentsFor(ac *attachedClient, includeTerminalTitle boo | |||
| 199 | 199 | presentation := recentRoutePresentation{name: s.name, ephemeral: s.ephemeral} | |
| 200 | 200 | if active, ok := activeRouteEntryForLifecycle(routeSnapshot, s.incarnation); ok { | |
| 201 | 201 | presentation.hostLabel = domain.RemoteDisplayOrigin(active.HostLabel) | |
| 202 | - | if active.Kind == ports.RouteKindRemote { | |
| 202 | + | if active.Kind == protocol.RouteKindRemote { | |
| 203 | 203 | presentation.kind = recentRouteRemote | |
| 204 | 204 | } | |
| 205 | 205 | } | |
| @@ -231,7 +231,7 @@ func tabDisplayName(tb *tab, index int) string { | |||
| 231 | 231 | return strconv.Itoa(index + 1) | |
| 232 | 232 | } | |
| 233 | 233 | ||
| 234 | - | func rankedRecentForHintsWithSnapshot(hints *palette.ContextualHints, snapshot ports.RecentRouteSnapshot) []rankedRecent { | |
| 234 | + | func rankedRecentForHintsWithSnapshot(hints *palette.ContextualHints, snapshot protocol.RecentRouteSnapshot) []rankedRecent { | |
| 235 | 235 | if hints == nil || hints.Kind != command.ContextHintRecentSessions { | |
| 236 | 236 | return nil | |
| 237 | 237 | } | |
| @@ -270,10 +270,10 @@ func (d *Daemon) barStateForPaletteHints(cur *session, statusFeedback string, hi | |||
| 270 | 270 | // attachment. Bar scripts remain local-session-only because | |
| 271 | 271 | // their existing execution contract depends on local tabs and PTYs. | |
| 272 | 272 | func (d *Daemon) barStateForAttachmentPaletteHints(cur *session, statusFeedback string, hints *palette.ContextualHints) barState { | |
| 273 | - | return d.barStateForAttachmentPaletteHintsFor(cur, nil, statusFeedback, hints, ports.RecentRouteSnapshot{}) | |
| 273 | + | return d.barStateForAttachmentPaletteHintsFor(cur, nil, statusFeedback, hints, protocol.RecentRouteSnapshot{}) | |
| 274 | 274 | } | |
| 275 | 275 | ||
| 276 | - | func (d *Daemon) barStateForAttachmentPaletteHintsFor(cur *session, ac *attachedClient, statusFeedback string, hints *palette.ContextualHints, capturedRouteSnapshot ports.RecentRouteSnapshot) barState { | |
| 276 | + | func (d *Daemon) barStateForAttachmentPaletteHintsFor(cur *session, ac *attachedClient, statusFeedback string, hints *palette.ContextualHints, capturedRouteSnapshot protocol.RecentRouteSnapshot) barState { | |
| 277 | 277 | routeSnapshot := capturedRouteSnapshot | |
| 278 | 278 | if routeSnapshot.Generation == 0 && ac != nil { | |
| 279 | 279 | routeSnapshot = ac.routeSnapshotCopy() | |
M internal/usecase/daemon/status_test.go +21 -20
| @@ -14,6 +14,7 @@ import ( | |||
| 14 | 14 | renderer "github.com/bnema/vev-vt/ansi" | |
| 15 | 15 | "github.com/bnema/vev/internal/domain" | |
| 16 | 16 | "github.com/bnema/vev/internal/ports" | |
| 17 | + | "github.com/bnema/vev/internal/protocol" | |
| 17 | 18 | "github.com/bnema/vev/internal/usecase/command" | |
| 18 | 19 | "github.com/bnema/vev/internal/usecase/layout" | |
| 19 | 20 | "github.com/bnema/vev/internal/usecase/palette" | |
| @@ -126,14 +127,14 @@ func TestStatusSegmentsResolvesActiveLifecyclePresentation(t *testing.T) { | |||
| 126 | 127 | ||
| 127 | 128 | sess.name = "vive" | |
| 128 | 129 | sess.incarnation = domain.SessionLifecycleID{1} | |
| 129 | - | ref := ports.RouteRef{Key: 1, Generation: 1} | |
| 130 | - | ac.setRouteSnapshot(ports.RecentRouteSnapshot{ | |
| 130 | + | ref := protocol.RouteRef{Key: 1, Generation: 1} | |
| 131 | + | ac.setRouteSnapshot(protocol.RecentRouteSnapshot{ | |
| 131 | 132 | Generation: 1, | |
| 132 | 133 | Active: ref, | |
| 133 | - | ActiveEntry: ports.RecentRouteEntry{ | |
| 134 | + | ActiveEntry: protocol.RecentRouteEntry{ | |
| 134 | 135 | Key: ref.Key, Generation: ref.Generation, | |
| 135 | - | Target: ports.ExactSessionTarget{LifecycleID: tt.routeLifecycle, SessionName: sess.name}, | |
| 136 | - | Name: "vive", HostLabel: "user@arch", Kind: ports.RouteKindRemote, | |
| 136 | + | Target: protocol.ExactSessionTarget{LifecycleID: tt.routeLifecycle, SessionName: sess.name}, | |
| 137 | + | Name: "vive", HostLabel: "user@arch", Kind: protocol.RouteKindRemote, | |
| 137 | 138 | }, | |
| 138 | 139 | }) | |
| 139 | 140 | ||
| @@ -466,7 +467,7 @@ func TestStatusApplyThemeStoresClientAndPropagatesScreens(t *testing.T) { | |||
| 466 | 467 | d, sess, ac, _ := newManualSessionWithPTYs(t, p1, p2) | |
| 467 | 468 | defer releasePTY1() | |
| 468 | 469 | defer releasePTY2() | |
| 469 | - | msg := ports.Theme{HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, SchemeKnown: true, Light: true} | |
| 470 | + | msg := protocol.Theme{HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, SchemeKnown: true, Light: true} | |
| 470 | 471 | ||
| 471 | 472 | d.applyTheme(sess, ac, msg) | |
| 472 | 473 | ||
| @@ -484,7 +485,7 @@ func TestApplyThemePropagatesToFloatingPane(t *testing.T) { | |||
| 484 | 485 | tb := testAttachmentTab(sess) | |
| 485 | 486 | floating := newPane("floating", nil, domain.Size{Cols: 20, Rows: 5}) | |
| 486 | 487 | installTestFloating(tb, floating, true) | |
| 487 | - | clientTheme := ports.Theme{ | |
| 488 | + | clientTheme := protocol.Theme{ | |
| 488 | 489 | HasForeground: true, | |
| 489 | 490 | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 490 | 491 | HasBackground: true, | |
| @@ -520,7 +521,7 @@ func TestApplyThemeForcedBuiltinThemePropagatesToChromeAndPanes(t *testing.T) { | |||
| 520 | 521 | defer releasePTY2() | |
| 521 | 522 | d.ApplyConfig(domain.Config{Theme: tc.mode}) | |
| 522 | 523 | ||
| 523 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 524 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 524 | 525 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 525 | 526 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 526 | 527 | TrueColor: true, SchemeKnown: true, Light: !tc.want.Light, | |
| @@ -575,7 +576,7 @@ func TestAutoThemeDetachClearsPaneColorScheme(t *testing.T) { | |||
| 575 | 576 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 576 | 577 | defer releasePTY() | |
| 577 | 578 | d.ApplyConfig(domain.Config{Theme: domain.ThemeAuto}) | |
| 578 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 579 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 579 | 580 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 580 | 581 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 581 | 582 | TrueColor: true, SchemeKnown: true, Light: true, | |
| @@ -592,7 +593,7 @@ func TestAttachClientClearsStaleColorSchemeOnReplacement(t *testing.T) { | |||
| 592 | 593 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 593 | 594 | defer releasePTY() | |
| 594 | 595 | d.ApplyConfig(domain.Config{Theme: domain.ThemeAuto}) | |
| 595 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 596 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 596 | 597 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 597 | 598 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 598 | 599 | TrueColor: true, SchemeKnown: true, Light: true, | |
| @@ -611,7 +612,7 @@ func TestForcedThemeDetachPreservesBuiltinOnPanes(t *testing.T) { | |||
| 611 | 612 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 612 | 613 | defer releasePTY() | |
| 613 | 614 | d.ApplyConfig(domain.Config{Theme: domain.ThemeDark}) | |
| 614 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 615 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 615 | 616 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 616 | 617 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 617 | 618 | TrueColor: true, SchemeKnown: true, Light: true, | |
| @@ -628,12 +629,12 @@ func TestApplyThemeAutoUnknownDoesNotClobberPaneColorScheme(t *testing.T) { | |||
| 628 | 629 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 629 | 630 | defer releasePTY() | |
| 630 | 631 | ||
| 631 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 632 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 632 | 633 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 633 | 634 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 634 | 635 | TrueColor: true, SchemeKnown: true, Light: true, | |
| 635 | 636 | }) | |
| 636 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 637 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 637 | 638 | HasForeground: true, Foreground: renderer.RGB{R: 7, G: 8, B: 9}, | |
| 638 | 639 | HasBackground: true, Background: renderer.RGB{R: 10, G: 11, B: 12}, | |
| 639 | 640 | TrueColor: true, | |
| @@ -703,7 +704,7 @@ func TestAttachClientClearsStaleScreenDefaultColors(t *testing.T) { | |||
| 703 | 704 | p, release := newBlockingPTY(t) | |
| 704 | 705 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 705 | 706 | defer release() | |
| 706 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 707 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 707 | 708 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 708 | 709 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 709 | 710 | }) | |
| @@ -723,7 +724,7 @@ func TestClientGoneResetsScreenDefaultColors(t *testing.T) { | |||
| 723 | 724 | p, release := newBlockingPTY(t) | |
| 724 | 725 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 725 | 726 | defer release() | |
| 726 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 727 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 727 | 728 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 728 | 729 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 729 | 730 | }) | |
| @@ -747,7 +748,7 @@ func TestDetachOnSendErrorResetsScreenDefaultColors(t *testing.T) { | |||
| 747 | 748 | p, release := newBlockingPTY(t) | |
| 748 | 749 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 749 | 750 | defer release() | |
| 750 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 751 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 751 | 752 | HasForeground: true, Foreground: renderer.RGB{R: 7, G: 8, B: 9}, | |
| 752 | 753 | HasBackground: true, Background: renderer.RGB{R: 10, G: 11, B: 12}, | |
| 753 | 754 | }) | |
| @@ -766,7 +767,7 @@ func TestDetachOnSendErrorParkPreservesScreenDefaultColors(t *testing.T) { | |||
| 766 | 767 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 767 | 768 | defer release() | |
| 768 | 769 | ac.resumeCapable = true | |
| 769 | - | d.applyTheme(sess, ac, ports.Theme{ | |
| 770 | + | d.applyTheme(sess, ac, protocol.Theme{ | |
| 770 | 771 | HasForeground: true, Foreground: renderer.RGB{R: 7, G: 8, B: 9}, | |
| 771 | 772 | HasBackground: true, Background: renderer.RGB{R: 10, G: 11, B: 12}, | |
| 772 | 773 | }) | |
| @@ -988,9 +989,9 @@ func TestBarStateForContextualRecentUsesClientSnapshot(t *testing.T) { | |||
| 988 | 989 | d, sess, ac, _ := newManualSessionWithPTYs(t, p) | |
| 989 | 990 | defer releasePTY() | |
| 990 | 991 | ||
| 991 | - | snapshot := ports.RecentRouteSnapshot{ | |
| 992 | + | snapshot := protocol.RecentRouteSnapshot{ | |
| 992 | 993 | Generation: 1, | |
| 993 | - | Entries: []ports.RecentRouteEntry{{Key: 2, Generation: 1, Target: testRouteTarget("captured", 2), Name: "captured", Kind: ports.RouteKindLocal, Attention: true}}, | |
| 994 | + | Entries: []protocol.RecentRouteEntry{{Key: 2, Generation: 1, Target: testRouteTarget("captured", 2), Name: "captured", Kind: protocol.RouteKindLocal, Attention: true}}, | |
| 994 | 995 | } | |
| 995 | 996 | hints := palette.ContextualHints{ | |
| 996 | 997 | Kind: command.ContextHintRecentSessions, | |
| @@ -1444,7 +1445,7 @@ func TestStatusCoalescesCreateSwitchAndResize(t *testing.T) { | |||
| 1444 | 1445 | frameInput([]byte("\x1b ")), | |
| 1445 | 1446 | frameInput([]byte("CNT\r")), | |
| 1446 | 1447 | frameInput([]byte("\x1b1")), | |
| 1447 | - | ports.Frame{Type: ports.MsgResize, Payload: mustMarshalResize(ports.Resize{Size: domain.Size{Cols: 22, Rows: 6}})}, | |
| 1448 | + | ports.Frame{Type: ports.MsgResize, Payload: mustMarshalResize(protocol.Resize{Size: domain.Size{Cols: 22, Rows: 6}})}, | |
| 1448 | 1449 | ) | |
| 1449 | 1450 | ||
| 1450 | 1451 | var hg sync.WaitGroup | |
M internal/usecase/daemon/theme_cache_test.go +2 -2
| @@ -7,7 +7,7 @@ import ( | |||
| 7 | 7 | ||
| 8 | 8 | renderer "github.com/bnema/vev-vt" | |
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | - | "github.com/bnema/vev/internal/ports" | |
| 10 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 11 | "github.com/bnema/vev/internal/usecase/layout" | |
| 12 | 12 | themeui "github.com/bnema/vev/internal/usecase/theme" | |
| 13 | 13 | ) | |
| @@ -26,7 +26,7 @@ func cacheTheme() themeui.Theme { | |||
| 26 | 26 | func TestThemeAccentHotReloadRebuildsAppliedSnapshot(t *testing.T) { | |
| 27 | 27 | d, sess, ac, _ := newManualSessionWithPTYs(t) | |
| 28 | 28 | raw := cacheTheme() | |
| 29 | - | d.applyTheme(sess, ac, ports.Theme{Foreground: raw.Foreground, Background: raw.Background, HasForeground: true, HasBackground: true, TrueColor: true, Palette: raw.Palette, PaletteKnown: raw.PaletteKnown}) | |
| 29 | + | d.applyTheme(sess, ac, protocol.Theme{Foreground: raw.Foreground, Background: raw.Background, HasForeground: true, HasBackground: true, TrueColor: true, Palette: raw.Palette, PaletteKnown: raw.PaletteKnown}) | |
| 30 | 30 | before := ac.getAppliedTheme() | |
| 31 | 31 | ||
| 32 | 32 | cfg := domain.Defaults() | |
M internal/usecase/daemon/theme_integration_test.go +3 -3
| @@ -7,12 +7,12 @@ import ( | |||
| 7 | 7 | ||
| 8 | 8 | renderer "github.com/bnema/vev-vt/ansi" | |
| 9 | 9 | "github.com/bnema/vev/internal/domain" | |
| 10 | - | "github.com/bnema/vev/internal/ports" | |
| 10 | + | "github.com/bnema/vev/internal/protocol" | |
| 11 | 11 | themeui "github.com/bnema/vev/internal/usecase/theme" | |
| 12 | 12 | ) | |
| 13 | 13 | ||
| 14 | - | func lifecycleTheme(foreground, background renderer.RGB, palette map[uint8]renderer.RGB) ports.Theme { | |
| 15 | - | out := ports.Theme{ | |
| 14 | + | func lifecycleTheme(foreground, background renderer.RGB, palette map[uint8]renderer.RGB) protocol.Theme { | |
| 15 | + | out := protocol.Theme{ | |
| 16 | 16 | Foreground: foreground, Background: background, | |
| 17 | 17 | HasForeground: true, HasBackground: true, TrueColor: true, | |
| 18 | 18 | SchemeKnown: true, | |
M internal/usecase/daemon/wire.go +6 -5
| @@ -4,14 +4,15 @@ package daemon | |||
| 4 | 4 | import ( | |
| 5 | 5 | "github.com/bnema/vev/internal/domain" | |
| 6 | 6 | "github.com/bnema/vev/internal/ports" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 7 | 8 | ) | |
| 8 | 9 | ||
| 9 | 10 | func frameWelcome(s *session, resumeToken uint64) (ports.Frame, error) { | |
| 10 | 11 | s.mu.Lock() | |
| 11 | - | var identity *ports.CommittedRouteIdentity | |
| 12 | + | var identity *protocol.CommittedRouteIdentity | |
| 12 | 13 | if s.incarnation != (domain.SessionLifecycleID{}) { | |
| 13 | - | identity = &ports.CommittedRouteIdentity{ | |
| 14 | - | Target: ports.ExactSessionTarget{LifecycleID: s.incarnation, SessionName: s.name}, | |
| 14 | + | identity = &protocol.CommittedRouteIdentity{ | |
| 15 | + | Target: protocol.ExactSessionTarget{LifecycleID: s.incarnation, SessionName: s.name}, | |
| 15 | 16 | Ephemeral: s.ephemeral, | |
| 16 | 17 | } | |
| 17 | 18 | } | |
| @@ -26,7 +27,7 @@ func frameWelcome(s *session, resumeToken uint64) (ports.Frame, error) { | |||
| 26 | 27 | w.ResumeToken = resumeToken | |
| 27 | 28 | payload := ports.MarshalWelcome(w) | |
| 28 | 29 | if payload == nil { | |
| 29 | - | return ports.Frame{}, ports.ErrInvalidRouteWire | |
| 30 | + | return ports.Frame{}, protocol.ErrInvalidRouteWire | |
| 30 | 31 | } | |
| 31 | 32 | return ports.Frame{Type: ports.MsgWelcome, Payload: payload}, nil | |
| 32 | 33 | } | |
| @@ -36,7 +37,7 @@ func frameError(code uint16, text string) ports.Frame { | |||
| 36 | 37 | } | |
| 37 | 38 | ||
| 38 | 39 | func frameOutputState(b []byte, baseState uint64, state uint64, echoAck uint64) (ports.Frame, error) { | |
| 39 | - | payload, err := ports.MarshalOutput(ports.Output{ | |
| 40 | + | payload, err := ports.MarshalOutput(protocol.Output{ | |
| 40 | 41 | Epoch: 1, Base: baseState, New: state, Echo: echoAck, | |
| 41 | 42 | Size: domain.Size{Cols: 1, Rows: 1}, Full: state != 0 && baseState == 0, Data: b, | |
| 42 | 43 | }) | |
M internal/usecase/daemon/wire_test_helpers_test.go +7 -4
| @@ -1,8 +1,11 @@ | |||
| 1 | 1 | package daemon | |
| 2 | 2 | ||
| 3 | - | import "github.com/bnema/vev/internal/ports" | |
| 3 | + | import ( | |
| 4 | + | "github.com/bnema/vev/internal/ports" | |
| 5 | + | "github.com/bnema/vev/internal/protocol" | |
| 6 | + | ) | |
| 4 | 7 | ||
| 5 | - | func mustMarshalOutput(m ports.Output) []byte { | |
| 8 | + | func mustMarshalOutput(m protocol.Output) []byte { | |
| 6 | 9 | payload, err := ports.MarshalOutput(m) | |
| 7 | 10 | if err != nil { | |
| 8 | 11 | panic(err) | |
| @@ -10,7 +13,7 @@ func mustMarshalOutput(m ports.Output) []byte { | |||
| 10 | 13 | return payload | |
| 11 | 14 | } | |
| 12 | 15 | ||
| 13 | - | func mustMarshalAck(m ports.Ack) []byte { | |
| 16 | + | func mustMarshalAck(m protocol.Ack) []byte { | |
| 14 | 17 | payload, err := ports.MarshalAck(m) | |
| 15 | 18 | if err != nil { | |
| 16 | 19 | panic(err) | |
| @@ -18,7 +21,7 @@ func mustMarshalAck(m ports.Ack) []byte { | |||
| 18 | 21 | return payload | |
| 19 | 22 | } | |
| 20 | 23 | ||
| 21 | - | func mustMarshalResize(m ports.Resize) []byte { | |
| 24 | + | func mustMarshalResize(m protocol.Resize) []byte { | |
| 22 | 25 | payload, err := ports.MarshalResize(m) | |
| 23 | 26 | if err != nil { | |
| 24 | 27 | panic(err) | |
M internal/usecase/palette/fuzzy_test.go +3 -3
| @@ -4,7 +4,7 @@ import ( | |||
| 4 | 4 | "testing" | |
| 5 | 5 | "time" | |
| 6 | 6 | ||
| 7 | - | "github.com/bnema/vev/internal/ports" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 8 | "github.com/bnema/vev/internal/usecase/command" | |
| 9 | 9 | "github.com/stretchr/testify/require" | |
| 10 | 10 | ) | |
| @@ -87,7 +87,7 @@ func TestFuzzyOrdersMixedResults(t *testing.T) { | |||
| 87 | 87 | wantText []string | |
| 88 | 88 | wantKinds []ResultKind | |
| 89 | 89 | wantPositions [][]int | |
| 90 | - | wantActiveTargets map[int]ports.ExactSessionTarget | |
| 90 | + | wantActiveTargets map[int]protocol.ExactSessionTarget | |
| 91 | 91 | }{ | |
| 92 | 92 | { | |
| 93 | 93 | name: "command shortcode precedes sessions and description matches", | |
| @@ -128,7 +128,7 @@ func TestFuzzyOrdersMixedResults(t *testing.T) { | |||
| 128 | 128 | wantText: []string{"AX", "Resume session aAlpha", "Resume session aBravo", "Switch to session aEcho", "Switch to session aEcho", "Switch to session aZulu"}, | |
| 129 | 129 | wantKinds: []ResultKind{ResultKindCommand, ResultKindStoppedSession, ResultKindStoppedSession, ResultKindActiveSession, ResultKindActiveSession, ResultKindActiveSession}, | |
| 130 | 130 | wantPositions: [][]int{{0}, {15}, {15}, {18}, {18}, {18}}, | |
| 131 | - | wantActiveTargets: map[int]ports.ExactSessionTarget{ | |
| 131 | + | wantActiveTargets: map[int]protocol.ExactSessionTarget{ | |
| 132 | 132 | 3: testExactTarget("aEcho", 4), 4: testExactTarget("aEcho", 5), 5: testExactTarget("aZulu", 3), | |
| 133 | 133 | }, | |
| 134 | 134 | }, | |
M internal/usecase/palette/result.go +11 -11
| @@ -4,7 +4,7 @@ import ( | |||
| 4 | 4 | "time" | |
| 5 | 5 | ||
| 6 | 6 | "github.com/bnema/vev/internal/domain" | |
| 7 | - | "github.com/bnema/vev/internal/ports" | |
| 7 | + | "github.com/bnema/vev/internal/protocol" | |
| 8 | 8 | "github.com/bnema/vev/internal/usecase/command" | |
| 9 | 9 | ) | |
| 10 | 10 | ||
| @@ -32,7 +32,7 @@ type Result struct { | |||
| 32 | 32 | type sessionPayload struct { | |
| 33 | 33 | display string | |
| 34 | 34 | createdAt time.Time | |
| 35 | - | target ports.ExactSessionTarget | |
| 35 | + | target protocol.ExactSessionTarget | |
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | type remoteSessionPayload struct { | |
| @@ -43,7 +43,7 @@ type remoteSessionPayload struct { | |||
| 43 | 43 | ||
| 44 | 44 | type routePayload struct { | |
| 45 | 45 | label string | |
| 46 | - | action ports.RouteNavigationAction | |
| 46 | + | action protocol.RouteNavigationAction | |
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | 49 | // NewCommandResult creates a static command palette target. | |
| @@ -52,13 +52,13 @@ func NewCommandResult(cmd command.Command) Result { | |||
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | 54 | // NewActiveSessionResult creates an immutable active named-session target. | |
| 55 | - | func NewActiveSessionResult(target ports.ExactSessionTarget, createdAt time.Time) Result { | |
| 55 | + | func NewActiveSessionResult(target protocol.ExactSessionTarget, createdAt time.Time) Result { | |
| 56 | 56 | return NewActiveSessionResultWithDisplayOrigin(target, createdAt, "") | |
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | 59 | // NewActiveSessionResultWithDisplayOrigin creates an active named-session target | |
| 60 | 60 | // qualified for presentation through a remote attachment origin. | |
| 61 | - | func NewActiveSessionResultWithDisplayOrigin(target ports.ExactSessionTarget, createdAt time.Time, displayOrigin string) Result { | |
| 61 | + | func NewActiveSessionResultWithDisplayOrigin(target protocol.ExactSessionTarget, createdAt time.Time, displayOrigin string) Result { | |
| 62 | 62 | return Result{ | |
| 63 | 63 | kind: ResultKindActiveSession, | |
| 64 | 64 | session: newSessionPayload(target, createdAt, displayOrigin), | |
| @@ -66,20 +66,20 @@ func NewActiveSessionResultWithDisplayOrigin(target ports.ExactSessionTarget, cr | |||
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | 68 | // NewStoppedSessionResult creates an immutable stopped named-session target. | |
| 69 | - | func NewStoppedSessionResult(target ports.ExactSessionTarget, createdAt time.Time) Result { | |
| 69 | + | func NewStoppedSessionResult(target protocol.ExactSessionTarget, createdAt time.Time) Result { | |
| 70 | 70 | return NewStoppedSessionResultWithDisplayOrigin(target, createdAt, "") | |
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | 73 | // NewStoppedSessionResultWithDisplayOrigin creates a stopped named-session target | |
| 74 | 74 | // qualified for presentation through a remote attachment origin. | |
| 75 | - | func NewStoppedSessionResultWithDisplayOrigin(target ports.ExactSessionTarget, createdAt time.Time, displayOrigin string) Result { | |
| 75 | + | func NewStoppedSessionResultWithDisplayOrigin(target protocol.ExactSessionTarget, createdAt time.Time, displayOrigin string) Result { | |
| 76 | 76 | return Result{ | |
| 77 | 77 | kind: ResultKindStoppedSession, | |
| 78 | 78 | session: newSessionPayload(target, createdAt, displayOrigin), | |
| 79 | 79 | } | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | - | func newSessionPayload(target ports.ExactSessionTarget, createdAt time.Time, displayOrigin string) sessionPayload { | |
| 82 | + | func newSessionPayload(target protocol.ExactSessionTarget, createdAt time.Time, displayOrigin string) sessionPayload { | |
| 83 | 83 | display := target.SessionName | |
| 84 | 84 | if displayOrigin != "" { | |
| 85 | 85 | display = domain.RemoteSessionDisplay(target.SessionName, displayOrigin) | |
| @@ -98,7 +98,7 @@ func NewRemoteSessionResult(key domain.RemoteSessionKey, target domain.RemoteSes | |||
| 98 | 98 | } | |
| 99 | 99 | ||
| 100 | 100 | // NewRecentRouteResult creates an immutable client-ledger route target. | |
| 101 | - | func NewRecentRouteResult(label string, action ports.RouteNavigationAction) Result { | |
| 101 | + | func NewRecentRouteResult(label string, action protocol.RouteNavigationAction) Result { | |
| 102 | 102 | return Result{kind: ResultKindRecentRoute, route: routePayload{label: label, action: action}} | |
| 103 | 103 | } | |
| 104 | 104 | ||
| @@ -163,7 +163,7 @@ func (r Result) SessionCreatedAt() (time.Time, bool) { | |||
| 163 | 163 | ||
| 164 | 164 | // SessionTarget returns the exact lifecycle UUID and name for local active and | |
| 165 | 165 | // stopped session results. | |
| 166 | - | func (r Result) SessionTarget() (ports.ExactSessionTarget, bool) { | |
| 166 | + | func (r Result) SessionTarget() (protocol.ExactSessionTarget, bool) { | |
| 167 | 167 | return r.session.target, r.kind == ResultKindActiveSession || r.kind == ResultKindStoppedSession | |
| 168 | 168 | } | |
| 169 | 169 | ||
| @@ -187,7 +187,7 @@ func (r Result) RemoteSessionUnavailableReason() (string, bool) { | |||
| 187 | 187 | ||
| 188 | 188 | // RouteNavigationAction returns the exact client-ledger target only for a | |
| 189 | 189 | // recent-route result. | |
| 190 | - | func (r Result) RouteNavigationAction() (ports.RouteNavigationAction, bool) { | |
| 190 | + | func (r Result) RouteNavigationAction() (protocol.RouteNavigationAction, bool) { | |
| 191 | 191 | return r.route.action, r.kind == ResultKindRecentRoute | |
| 192 | 192 | } | |
| 193 | 193 | ||
M internal/usecase/palette/result_test.go +4 -4
| @@ -5,13 +5,13 @@ import ( | |||
| 5 | 5 | "time" | |
| 6 | 6 | ||
| 7 | 7 | "github.com/bnema/vev/internal/domain" | |
| 8 | - | "github.com/bnema/vev/internal/ports" | |
| 8 | + | "github.com/bnema/vev/internal/protocol" | |
| 9 | 9 | "github.com/bnema/vev/internal/usecase/command" | |
| 10 | 10 | "github.com/stretchr/testify/require" | |
| 11 | 11 | ) | |
| 12 | 12 | ||
| 13 | - | func testExactTarget(name string, marker byte) ports.ExactSessionTarget { | |
| 14 | - | return ports.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{marker}, SessionName: name} | |
| 13 | + | func testExactTarget(name string, marker byte) protocol.ExactSessionTarget { | |
| 14 | + | return protocol.ExactSessionTarget{LifecycleID: domain.SessionLifecycleID{marker}, SessionName: name} | |
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | 17 | func TestResultKindsAndSessionLifecycleTargets(t *testing.T) { | |
| @@ -73,7 +73,7 @@ func TestResultKindsAndSessionLifecycleTargets(t *testing.T) { | |||
| 73 | 73 | } | |
| 74 | 74 | ||
| 75 | 75 | func TestRecentRouteResultCarriesExactNavigationAction(t *testing.T) { | |
| 76 | - | action := ports.RouteNavigationAction{SnapshotGeneration: 4, Key: 7, Generation: 3} | |
| 76 | + | action := protocol.RouteNavigationAction{SnapshotGeneration: 4, Key: 7, Generation: 3} | |
| 77 | 77 | result := NewRecentRouteResult("logs@edge", action) | |
| 78 | 78 | ||
| 79 | 79 | require.Equal(t, ResultKindRecentRoute, result.Kind()) | |
M scripts/remote-picker-harness/main.go +3 -2
| @@ -20,6 +20,7 @@ import ( | |||
| 20 | 20 | "github.com/bnema/vev/internal/adapters/sshstdio" | |
| 21 | 21 | "github.com/bnema/vev/internal/domain" | |
| 22 | 22 | "github.com/bnema/vev/internal/ports" | |
| 23 | + | "github.com/bnema/vev/internal/protocol" | |
| 23 | 24 | ) | |
| 24 | 25 | ||
| 25 | 26 | const ( | |
| @@ -660,7 +661,7 @@ func attachAndCheck(ctx context.Context, tr *harnessTransport, hello ports.Hello | |||
| 660 | 661 | return fmt.Errorf("welcome frame type %d", frame.Type) | |
| 661 | 662 | } | |
| 662 | 663 | tr.probe.recordControl(probeEventWelcome) | |
| 663 | - | if err := tr.Send(ports.Frame{Type: ports.MsgTheme, Payload: ports.MarshalTheme(ports.Theme{TrueColor: hello.TrueColor, SchemeKnown: true})}); err != nil { | |
| 664 | + | if err := tr.Send(ports.Frame{Type: ports.MsgTheme, Payload: ports.MarshalTheme(protocol.Theme{TrueColor: hello.TrueColor, SchemeKnown: true})}); err != nil { | |
| 664 | 665 | return fmt.Errorf("send initial theme: %w", err) | |
| 665 | 666 | } | |
| 666 | 667 | return nil | |
| @@ -756,7 +757,7 @@ func awaitRemotePickerPreview(ctx context.Context, tr *harnessTransport, marker | |||
| 756 | 757 | } | |
| 757 | 758 | } | |
| 758 | 759 | ||
| 759 | - | func remotePreviewContains(preview ports.RemotePreview, want string) bool { | |
| 760 | + | func remotePreviewContains(preview protocol.RemotePreview, want string) bool { | |
| 760 | 761 | var text strings.Builder | |
| 761 | 762 | for _, cell := range preview.Cells { | |
| 762 | 763 | if !cell.Continuation { | |
M scripts/remote-picker-harness/visual_probe.go +6 -5
| @@ -12,6 +12,7 @@ import ( | |||
| 12 | 12 | vt "github.com/bnema/vev-vt" | |
| 13 | 13 | "github.com/bnema/vev/internal/domain" | |
| 14 | 14 | "github.com/bnema/vev/internal/ports" | |
| 15 | + | "github.com/bnema/vev/internal/protocol" | |
| 15 | 16 | ) | |
| 16 | 17 | ||
| 17 | 18 | const ( | |
| @@ -38,7 +39,7 @@ type visualOutputState struct { | |||
| 38 | 39 | initialized bool | |
| 39 | 40 | } | |
| 40 | 41 | ||
| 41 | - | func (s visualOutputState) next(output ports.Output) (visualOutputState, bool) { | |
| 42 | + | func (s visualOutputState) next(output protocol.Output) (visualOutputState, bool) { | |
| 42 | 43 | if output.Epoch == 0 { | |
| 43 | 44 | return visualOutputState{}, false | |
| 44 | 45 | } | |
| @@ -102,7 +103,7 @@ type visualCheckpoint struct { | |||
| 102 | 103 | type visualOutputResult struct { | |
| 103 | 104 | Accepted bool | |
| 104 | 105 | StateBearing bool | |
| 105 | - | Ack ports.Ack | |
| 106 | + | Ack protocol.Ack | |
| 106 | 107 | event *probeEvent | |
| 107 | 108 | } | |
| 108 | 109 | ||
| @@ -180,13 +181,13 @@ func (p *visualProbe) recordControl(kind string) { | |||
| 180 | 181 | p.record(probeEvent{Kind: kind, Accepted: true}) | |
| 181 | 182 | } | |
| 182 | 183 | ||
| 183 | - | func (p *visualProbe) apply(output ports.Output) visualOutputResult { | |
| 184 | + | func (p *visualProbe) apply(output protocol.Output) visualOutputResult { | |
| 184 | 185 | if p == nil { | |
| 185 | 186 | return visualOutputResult{} | |
| 186 | 187 | } | |
| 187 | 188 | p.outputFrames++ | |
| 188 | 189 | p.outputBytes += len(output.Data) | |
| 189 | - | accepted := ports.ValidateOutput(output) == nil | |
| 190 | + | accepted := protocol.ValidateOutput(output) == nil | |
| 190 | 191 | next := visualOutputState{} | |
| 191 | 192 | if accepted { | |
| 192 | 193 | next, accepted = p.state.next(output) | |
| @@ -220,7 +221,7 @@ func (p *visualProbe) apply(output ports.Output) visualOutputResult { | |||
| 220 | 221 | p.checkpoints = append(p.checkpoints, checkpoint) | |
| 221 | 222 | result := visualOutputResult{Accepted: true, StateBearing: output.New != 0, event: event} | |
| 222 | 223 | if result.StateBearing { | |
| 223 | - | result.Ack = ports.Ack{Epoch: output.Epoch, State: output.New} | |
| 224 | + | result.Ack = protocol.Ack{Epoch: output.Epoch, State: output.New} | |
| 224 | 225 | } | |
| 225 | 226 | return result | |
| 226 | 227 | } | |
M scripts/remote-picker-harness/visual_probe_test.go +27 -26
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/vev/internal/domain" | |
| 11 | 11 | "github.com/bnema/vev/internal/ports" | |
| 12 | + | "github.com/bnema/vev/internal/protocol" | |
| 12 | 13 | "github.com/stretchr/testify/require" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| @@ -29,7 +30,7 @@ func (t *probeTestTransport) Send(frame ports.Frame) error { | |||
| 29 | 30 | func (*probeTestTransport) Recv() (ports.Frame, error) { return ports.Frame{}, errors.New("not used") } | |
| 30 | 31 | func (*probeTestTransport) Close() error { return nil } | |
| 31 | 32 | ||
| 32 | - | func probeTestOutput(t *testing.T, output ports.Output) ports.Frame { | |
| 33 | + | func probeTestOutput(t *testing.T, output protocol.Output) ports.Frame { | |
| 33 | 34 | t.Helper() | |
| 34 | 35 | payload, err := ports.MarshalOutput(output) | |
| 35 | 36 | if err != nil { | |
| @@ -43,19 +44,19 @@ func TestVisualProbePersistsFullAndIncrementalOutput(t *testing.T) { | |||
| 43 | 44 | probe := newVisualProbe(size) | |
| 44 | 45 | for _, tt := range []struct { | |
| 45 | 46 | name string | |
| 46 | - | output ports.Output | |
| 47 | + | output protocol.Output | |
| 47 | 48 | want string | |
| 48 | 49 | state uint64 | |
| 49 | 50 | }{ | |
| 50 | 51 | { | |
| 51 | 52 | name: "full", | |
| 52 | - | output: ports.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("full")}, | |
| 53 | + | output: protocol.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("full")}, | |
| 53 | 54 | want: "full", | |
| 54 | 55 | state: 1, | |
| 55 | 56 | }, | |
| 56 | 57 | { | |
| 57 | 58 | name: "incremental", | |
| 58 | - | output: ports.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 4, Size: size, Data: []byte(" incremental")}, | |
| 59 | + | output: protocol.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 4, Size: size, Data: []byte(" incremental")}, | |
| 59 | 60 | want: "full incremental", | |
| 60 | 61 | state: 2, | |
| 61 | 62 | }, | |
| @@ -87,7 +88,7 @@ func TestVisualProbePersistsFullAndIncrementalOutput(t *testing.T) { | |||
| 87 | 88 | func TestVisualProbeResizesToAcceptedOutput(t *testing.T) { | |
| 88 | 89 | probe := newVisualProbe(domain.Size{Cols: probeTestCols, Rows: probeTestRows}) | |
| 89 | 90 | outputSize := domain.Size{Cols: 48, Rows: 3} | |
| 90 | - | result := probe.apply(ports.Output{ | |
| 91 | + | result := probe.apply(protocol.Output{ | |
| 91 | 92 | Epoch: 1, New: 1, Full: true, ViewRevision: 1, Size: outputSize, Data: []byte("resized"), | |
| 92 | 93 | }) | |
| 93 | 94 | ||
| @@ -103,30 +104,30 @@ func TestVisualProbeRejectsOutputWithoutMutationOrAck(t *testing.T) { | |||
| 103 | 104 | size := domain.Size{Cols: probeTestCols, Rows: probeTestRows} | |
| 104 | 105 | for _, tt := range []struct { | |
| 105 | 106 | name string | |
| 106 | - | output ports.Output | |
| 107 | + | output protocol.Output | |
| 107 | 108 | }{ | |
| 108 | 109 | { | |
| 109 | 110 | name: "base gap", | |
| 110 | - | output: ports.Output{Epoch: 1, Base: 0, New: 3, Full: true, ViewRevision: 4, Size: size, Data: []byte("rejected")}, | |
| 111 | + | output: protocol.Output{Epoch: 1, Base: 0, New: 3, Full: true, ViewRevision: 4, Size: size, Data: []byte("rejected")}, | |
| 111 | 112 | }, | |
| 112 | 113 | { | |
| 113 | 114 | name: "revision gap", | |
| 114 | - | output: ports.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 5, Size: size, Data: []byte("rejected")}, | |
| 115 | + | output: protocol.Output{Epoch: 1, Base: 1, New: 2, ViewRevision: 5, Size: size, Data: []byte("rejected")}, | |
| 115 | 116 | }, | |
| 116 | 117 | { | |
| 117 | 118 | name: "stale epoch", | |
| 118 | - | output: ports.Output{Epoch: 0, Base: 1, New: 2, ViewRevision: 4, Size: size, Data: []byte("rejected")}, | |
| 119 | + | output: protocol.Output{Epoch: 0, Base: 1, New: 2, ViewRevision: 4, Size: size, Data: []byte("rejected")}, | |
| 119 | 120 | }, | |
| 120 | 121 | } { | |
| 121 | 122 | t.Run(tt.name, func(t *testing.T) { | |
| 122 | 123 | probe := newVisualProbe(size) | |
| 123 | - | first := ports.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("keep")} | |
| 124 | + | first := protocol.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("keep")} | |
| 124 | 125 | if result := probe.apply(first); !result.Accepted { | |
| 125 | 126 | t.Fatal("seed output was rejected") | |
| 126 | 127 | } | |
| 127 | 128 | beforeText, beforeState, beforeCheckpoints := probe.text(), probe.state, len(probe.checkpoints) | |
| 128 | 129 | result := probe.apply(tt.output) | |
| 129 | - | if result.Accepted || result.StateBearing || result.Ack != (ports.Ack{}) { | |
| 130 | + | if result.Accepted || result.StateBearing || result.Ack != (protocol.Ack{}) { | |
| 130 | 131 | t.Fatalf("result = %+v, want rejected output without ACK", result) | |
| 131 | 132 | } | |
| 132 | 133 | if got := probe.text(); got != beforeText { | |
| @@ -144,13 +145,13 @@ func TestVisualProbeRejectsOutputWithoutMutationOrAck(t *testing.T) { | |||
| 144 | 145 | ||
| 145 | 146 | func TestVisualProbeRejectsInvalidUninitializedSideEffects(t *testing.T) { | |
| 146 | 147 | size := domain.Size{Cols: probeTestCols, Rows: probeTestRows} | |
| 147 | - | for _, output := range []ports.Output{ | |
| 148 | + | for _, output := range []protocol.Output{ | |
| 148 | 149 | {Epoch: 1, Base: 1, Size: size, Data: []byte("invalid base")}, | |
| 149 | 150 | {Epoch: 1, Full: true, Size: size, Data: []byte("invalid full")}, | |
| 150 | 151 | } { | |
| 151 | 152 | probe := newVisualProbe(size) | |
| 152 | 153 | result := probe.apply(output) | |
| 153 | - | if result.Accepted || result.StateBearing || result.Ack != (ports.Ack{}) { | |
| 154 | + | if result.Accepted || result.StateBearing || result.Ack != (protocol.Ack{}) { | |
| 154 | 155 | t.Fatalf("result = %+v, want rejected uninitialized side effect", result) | |
| 155 | 156 | } | |
| 156 | 157 | require.Len(t, probe.events, 1) | |
| @@ -163,17 +164,17 @@ func TestVisualProbeSideEffectsApplyWithoutAck(t *testing.T) { | |||
| 163 | 164 | size := domain.Size{Cols: probeTestCols, Rows: probeTestRows} | |
| 164 | 165 | for _, tt := range []struct { | |
| 165 | 166 | name string | |
| 166 | - | seed *ports.Output | |
| 167 | - | effect ports.Output | |
| 167 | + | seed *protocol.Output | |
| 168 | + | effect protocol.Output | |
| 168 | 169 | }{ | |
| 169 | 170 | { | |
| 170 | 171 | name: "before state-bearing output", | |
| 171 | - | effect: ports.Output{Epoch: 1, Size: size, Data: []byte("side effect")}, | |
| 172 | + | effect: protocol.Output{Epoch: 1, Size: size, Data: []byte("side effect")}, | |
| 172 | 173 | }, | |
| 173 | 174 | { | |
| 174 | 175 | name: "after state-bearing output", | |
| 175 | - | seed: &ports.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("seed")}, | |
| 176 | - | effect: ports.Output{Epoch: 1, ViewRevision: 4, Size: size, Data: []byte(" side effect")}, | |
| 176 | + | seed: &protocol.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("seed")}, | |
| 177 | + | effect: protocol.Output{Epoch: 1, ViewRevision: 4, Size: size, Data: []byte(" side effect")}, | |
| 177 | 178 | }, | |
| 178 | 179 | } { | |
| 179 | 180 | t.Run(tt.name, func(t *testing.T) { | |
| @@ -183,7 +184,7 @@ func TestVisualProbeSideEffectsApplyWithoutAck(t *testing.T) { | |||
| 183 | 184 | } | |
| 184 | 185 | beforeState, beforeCheckpoints := probe.state, len(probe.checkpoints) | |
| 185 | 186 | result := probe.apply(tt.effect) | |
| 186 | - | if !result.Accepted || result.StateBearing || result.Ack != (ports.Ack{}) { | |
| 187 | + | if !result.Accepted || result.StateBearing || result.Ack != (protocol.Ack{}) { | |
| 187 | 188 | t.Fatalf("result = %+v, want accepted side effect without ACK", result) | |
| 188 | 189 | } | |
| 189 | 190 | if !strings.Contains(probe.text(), string(tt.effect.Data)) { | |
| @@ -203,24 +204,24 @@ func TestProcessOutputFrameACKsOnlyAcceptedStateBearingFrames(t *testing.T) { | |||
| 203 | 204 | size := domain.Size{Cols: probeTestCols, Rows: probeTestRows} | |
| 204 | 205 | for _, tt := range []struct { | |
| 205 | 206 | name string | |
| 206 | - | seed *ports.Output | |
| 207 | - | output ports.Output | |
| 207 | + | seed *protocol.Output | |
| 208 | + | output protocol.Output | |
| 208 | 209 | wantACKs int | |
| 209 | 210 | wantResets int | |
| 210 | 211 | }{ | |
| 211 | 212 | { | |
| 212 | 213 | name: "accepted full", | |
| 213 | - | output: ports.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("full")}, | |
| 214 | + | output: protocol.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("full")}, | |
| 214 | 215 | wantACKs: 1, | |
| 215 | 216 | }, | |
| 216 | 217 | { | |
| 217 | 218 | name: "accepted side effect", | |
| 218 | - | output: ports.Output{Epoch: 1, Size: size, Data: []byte("side effect")}, | |
| 219 | + | output: protocol.Output{Epoch: 1, Size: size, Data: []byte("side effect")}, | |
| 219 | 220 | }, | |
| 220 | 221 | { | |
| 221 | 222 | name: "rejected state", | |
| 222 | - | seed: &ports.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("seed")}, | |
| 223 | - | output: ports.Output{Epoch: 1, New: 3, Full: true, ViewRevision: 4, Size: size, Data: []byte("gap")}, | |
| 223 | + | seed: &protocol.Output{Epoch: 1, New: 1, Full: true, ViewRevision: 4, Size: size, Data: []byte("seed")}, | |
| 224 | + | output: protocol.Output{Epoch: 1, New: 3, Full: true, ViewRevision: 4, Size: size, Data: []byte("gap")}, | |
| 224 | 225 | wantResets: 1, | |
| 225 | 226 | }, | |
| 226 | 227 | } { | |
| @@ -307,7 +308,7 @@ func TestHarnessArtifactIsBoundedAndContainsOnlyMetadata(t *testing.T) { | |||
| 307 | 308 | artifact.registerProbe(probe) | |
| 308 | 309 | secret := "not-for-artifact" | |
| 309 | 310 | for state := uint64(1); state <= maxProbeEvents+1; state++ { | |
| 310 | - | output := ports.Output{Epoch: 1, Base: state - 1, New: state, Size: size, Data: []byte(secret)} | |
| 311 | + | output := protocol.Output{Epoch: 1, Base: state - 1, New: state, Size: size, Data: []byte(secret)} | |
| 311 | 312 | if state == 1 { | |
| 312 | 313 | output.Full = true | |
| 313 | 314 | } | |
M transport_replay_integration_test.go +3 -2
| @@ -11,6 +11,7 @@ import ( | |||
| 11 | 11 | "github.com/bnema/vev/internal/adapters/ipc" | |
| 12 | 12 | "github.com/bnema/vev/internal/adapters/sshstdio" | |
| 13 | 13 | "github.com/bnema/vev/internal/ports" | |
| 14 | + | "github.com/bnema/vev/internal/protocol" | |
| 14 | 15 | "github.com/bnema/vev/internal/testutil/replaytest" | |
| 15 | 16 | "github.com/stretchr/testify/require" | |
| 16 | 17 | ) | |
| @@ -53,7 +54,7 @@ func TestTransportReplayIntegration(t *testing.T) { | |||
| 53 | 54 | // SSH-stdio transports. The transports only carry frames; neither can infer | |
| 54 | 55 | // or alter the palette lifecycle. | |
| 55 | 56 | func TestThemeGenerationTransportSequences(t *testing.T) { | |
| 56 | - | cleared := ports.Theme{ | |
| 57 | + | cleared := protocol.Theme{ | |
| 57 | 58 | HasForeground: true, Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 58 | 59 | HasBackground: true, Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 59 | 60 | TrueColor: true, SchemeKnown: true, | |
| @@ -62,7 +63,7 @@ func TestThemeGenerationTransportSequences(t *testing.T) { | |||
| 62 | 63 | definitive := cleared | |
| 63 | 64 | definitive.Palette = palette | |
| 64 | 65 | definitive.PaletteKnown = 1<<2 | 1<<10 | |
| 65 | - | sequence := []ports.Theme{cleared, definitive} | |
| 66 | + | sequence := []protocol.Theme{cleared, definitive} | |
| 66 | 67 | ||
| 67 | 68 | tests := []struct { | |
| 68 | 69 | name string | |