feat(transport): negotiate bounded automatic message chunking
This commit is contained in:
1 parent
474afb3484
commit
8acffac985
20 files changed
+1332
-38
No files matched your search
@@ -1157,6 +1157,72 @@ layer = "integration"
|
||||
status = "implemented"
|
||||
tests = ["test/integration/store/store_integration_test.go:TestIncidentDirtyResolutionIdempotencyAndRecurrence_HP_STORE_11"]
|
||||
|
||||
[[requirements]]
|
||||
id = "HP-CHUNK-01"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/packet_test.go:TestMessageRoundTripAndBoundaries_HP_CHUNK_01"]
|
||||
|
||||
[[requirements]]
|
||||
id = "HP-CHUNK-02"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/connection_test.go:TestNegotiationFallbackAndBackgroundPong_HP_CHUNK_02"]
|
||||
|
||||
[[requirements]]
|
||||
id = "HP-CHUNK-03"
|
||||
layer = "integration"
|
||||
status = "implemented"
|
||||
tests = ["test/integration/clientagent/websocket_limits_integration_test.go:TestChunkedStdinKeepsWriteSequence_HP_CHUNK_03"]
|
||||
|
||||
[[requirements]]
|
||||
id = "BH-CHUNK-01"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/packet_test.go:TestRejectMalformedPacketsWithoutAllocation_BH_CHUNK_01"]
|
||||
|
||||
[[requirements]]
|
||||
id = "BH-CHUNK-02"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/limits_test.go:TestLogicalSendCeilingBeforeAnyPacket_BH_CHUNK_02"]
|
||||
|
||||
[[requirements]]
|
||||
id = "BH-CHUNK-03"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/limits_test.go:TestMalformedWireClosesWithoutDelivery_BH_CHUNK_03"]
|
||||
|
||||
[[requirements]]
|
||||
id = "REC-CHUNK-01"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/packet_test.go:TestIndependentControlLaneAndDisconnect_REC_CHUNK_01"]
|
||||
|
||||
[[requirements]]
|
||||
id = "REC-CHUNK-02"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/connection_test.go:TestInterruptedPacketNeverDelivered_REC_CHUNK_02"]
|
||||
|
||||
[[requirements]]
|
||||
id = "RACE-CHUNK-01"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/connection_test.go:TestConcurrentLogicalWrites_RACE_CHUNK_01"]
|
||||
|
||||
[[requirements]]
|
||||
id = "RACE-CHUNK-02"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/server/session/chunk_writer_test.go:TestChunkedWriterPreemptionAndBarrier_RACE_CHUNK_02"]
|
||||
|
||||
[[requirements]]
|
||||
id = "RACE-CHUNK-03"
|
||||
layer = "unit"
|
||||
status = "implemented"
|
||||
tests = ["internal/agentwire/limits_test.go:TestCloseStopsBlockedReadPump_RACE_CHUNK_03"]
|
||||
|
||||
[[requirements]]
|
||||
id = "REC-WS-01"
|
||||
layer = "integration"
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
|
||||
"github.com/rvbox/rvbox/internal/agentproto"
|
||||
"github.com/rvbox/rvbox/internal/client/agent"
|
||||
@@ -99,10 +100,12 @@ func TestLargeScriptFitsLegacyReader_REC_WS_02(t *testing.T) {
|
||||
fixture := newFrameFixture(t)
|
||||
legacy := agentproto.DefaultLimits()
|
||||
legacy.MaxEnvelopeBytes = 32 << 10
|
||||
transport, err := agent.DialWebSocketWithLimits(ctx, "wss"+strings.TrimPrefix(fixture.server.URL, "https")+"/v1/agent", fixture.server.Client(), legacy)
|
||||
raw, _, err := websocket.Dial(ctx, "wss"+strings.TrimPrefix(fixture.server.URL, "https")+"/v1/agent", &websocket.DialOptions{HTTPClient: fixture.server.Client()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw.SetReadLimit(32 << 10)
|
||||
transport := legacyAgentTransport{raw}
|
||||
defer transport.Close()
|
||||
accepted, err := agent.Handshake(ctx, transport, fixture.hello, legacy)
|
||||
if err != nil {
|
||||
@@ -170,6 +173,46 @@ func bytesToSHA(value []byte) [sha256.Size]byte {
|
||||
return result
|
||||
}
|
||||
|
||||
func TestChunkedStdinKeepsWriteSequence_HP_CHUNK_03(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
fixture := newFrameFixture(t)
|
||||
transport, accepted := fixture.connect(t, ctx, &rvboxv1.ReconcileSnapshot{})
|
||||
dispatch := fixture.dispatch(t, ctx, transport, "more")
|
||||
data := bytes.Repeat([]byte("stdin"), 12000)
|
||||
request, err := domain.NewUUIDv7()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input := &rvboxv1.AppendStdinRequest{ClientId: fixture.hello.ClientId, IssueUuid: dispatch.IssueUuid,
|
||||
RequestId: request.String(), Data: data, AppendNewline: true}
|
||||
first, err := fixture.control.AppendStdin(ctx, input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
duplicate, err := fixture.control.AppendStdin(ctx, input)
|
||||
if err != nil || duplicate.WriteSeq != first.WriteSeq {
|
||||
t.Fatal("chunking changed stdin idempotency")
|
||||
}
|
||||
write := readFrame(t, ctx, transport).GetStdinWrite()
|
||||
if write == nil || write.WriteSeq != first.WriteSeq || !write.AppendNewline || !bytes.Equal(write.Data, data) {
|
||||
t.Fatal("chunking split a logical stdin write or changed its bytes")
|
||||
}
|
||||
if err := agent.SendCommandEvent(ctx, transport, accepted, &rvboxv1.CommandEvent{
|
||||
IssueUuid: dispatch.IssueUuid, EventSeq: 1, ObservedAt: timestamppb.Now(),
|
||||
Payload: &rvboxv1.CommandEvent_StdinAck{StdinAck: &rvboxv1.StdinAcknowledgement{WriteSeq: first.WriteSeq}},
|
||||
}, agentproto.DefaultLimits()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ack := readFrame(t, ctx, transport).GetEventAck(); ack == nil || ack.ThroughEventSeq != 1 {
|
||||
t.Fatal("logical stdin acknowledgement changed")
|
||||
}
|
||||
if pending, err := fixture.persistence.PendingStdin(ctx, fixture.hello.ClientId); err != nil || len(pending) != 0 {
|
||||
t.Fatalf("stdin intent did not drain: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type frameFixture struct {
|
||||
persistence *store.Store
|
||||
control *control.Service
|
||||
@@ -219,7 +262,7 @@ func (fixture *frameFixture) connect(t *testing.T, ctx context.Context, snapshot
|
||||
return transport, accepted
|
||||
}
|
||||
|
||||
func (fixture *frameFixture) dispatch(t *testing.T, ctx context.Context, transport *agent.WebSocketTransport, text string) *rvboxv1.CommandDispatch {
|
||||
func (fixture *frameFixture) dispatch(t *testing.T, ctx context.Context, transport agent.Transport, text string) *rvboxv1.CommandDispatch {
|
||||
t.Helper()
|
||||
if _, err := fixture.control.RunCommand(ctx, &rvboxv1.RunCommandRequest{TargetClientId: fixture.hello.ClientId,
|
||||
Spec: &rvboxv1.ExecutionSpec{ShellType: rvboxv1.ShellType_SHELL_CMD, Source: &rvboxv1.ExecutionSpec_CommandText{CommandText: text}},
|
||||
@@ -244,7 +287,7 @@ func (fixture *frameFixture) dispatch(t *testing.T, ctx context.Context, transpo
|
||||
return dispatch
|
||||
}
|
||||
|
||||
func readFrame(t *testing.T, ctx context.Context, transport *agent.WebSocketTransport) *rvboxv1.AgentEnvelope {
|
||||
func readFrame(t *testing.T, ctx context.Context, transport agent.Transport) *rvboxv1.AgentEnvelope {
|
||||
t.Helper()
|
||||
encoded, err := transport.Read(ctx)
|
||||
if err != nil {
|
||||
@@ -256,3 +299,19 @@ func readFrame(t *testing.T, ctx context.Context, transport *agent.WebSocketTran
|
||||
}
|
||||
return envelope
|
||||
}
|
||||
|
||||
// Deliberately omits subprotocol negotiation and the new wire wrapper.
|
||||
type legacyAgentTransport struct{ connection *websocket.Conn }
|
||||
|
||||
func (transport legacyAgentTransport) Read(ctx context.Context) ([]byte, error) {
|
||||
_, payload, err := transport.connection.Read(ctx)
|
||||
return payload, err
|
||||
}
|
||||
|
||||
func (transport legacyAgentTransport) Write(ctx context.Context, payload []byte) error {
|
||||
return transport.connection.Write(ctx, websocket.MessageBinary, payload)
|
||||
}
|
||||
|
||||
func (transport legacyAgentTransport) Close() error {
|
||||
return transport.connection.Close(websocket.StatusNormalClosure, "")
|
||||
}
|
||||
Reference in new issue
Block a user