Skip to content

Commit 880c993

Browse files
committed
ts: Use Stream abstraction instead of raw byte streams
1 parent 70628c6 commit 880c993

6 files changed

Lines changed: 232 additions & 153 deletions

File tree

typescript/acp.test.ts

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
CancelNotification,
2424
SessionNotification,
2525
PROTOCOL_VERSION,
26+
ndJsonStream,
2627
} from "./acp.js";
2728

2829
describe("Connection", () => {
@@ -82,14 +83,12 @@ describe("Connection", () => {
8283
// Set up connections
8384
const agentConnection = new ClientSideConnection(
8485
() => new TestClient(),
85-
clientToAgent.writable,
86-
agentToClient.readable,
86+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
8787
);
8888

8989
const clientConnection = new AgentSideConnection(
9090
() => new TestAgent(),
91-
agentToClient.writable,
92-
clientToAgent.readable,
91+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
9392
);
9493

9594
// Test error handling in client->agent direction
@@ -173,16 +172,15 @@ describe("Connection", () => {
173172
}
174173
}
175174

176-
new ClientSideConnection(
175+
// Set up connections
176+
const agentConnection = new ClientSideConnection(
177177
() => new TestClient(),
178-
clientToAgent.writable,
179-
agentToClient.readable,
178+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
180179
);
181180

182181
const clientConnection = new AgentSideConnection(
183182
() => new TestAgent(),
184-
agentToClient.writable,
185-
clientToAgent.readable,
183+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
186184
);
187185

188186
// Send multiple concurrent requests
@@ -285,14 +283,12 @@ describe("Connection", () => {
285283
// Set up connections
286284
const agentConnection = new ClientSideConnection(
287285
() => new TestClient(),
288-
clientToAgent.writable,
289-
agentToClient.readable,
286+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
290287
);
291288

292289
const clientConnection = new AgentSideConnection(
293290
() => new TestAgent(),
294-
agentToClient.writable,
295-
clientToAgent.readable,
291+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
296292
);
297293

298294
// Send requests in specific order
@@ -422,14 +418,12 @@ describe("Connection", () => {
422418
// Set up connections
423419
const agentConnection = new ClientSideConnection(
424420
testClient,
425-
clientToAgent.writable,
426-
agentToClient.readable,
421+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
427422
);
428423

429424
const clientConnection = new AgentSideConnection(
430425
testAgent,
431-
agentToClient.writable,
432-
clientToAgent.readable,
426+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
433427
);
434428

435429
// Send notifications
@@ -516,16 +510,15 @@ describe("Connection", () => {
516510
}
517511
}
518512

513+
// Set up connections
519514
const agentConnection = new ClientSideConnection(
520515
() => new TestClient(),
521-
clientToAgent.writable,
522-
agentToClient.readable,
516+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
523517
);
524518

525-
new AgentSideConnection(
519+
const clientConnection = new AgentSideConnection(
526520
() => new TestAgent(),
527-
agentToClient.writable,
528-
clientToAgent.readable,
521+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
529522
);
530523

531524
// Test initialize request
@@ -627,16 +620,15 @@ describe("Connection", () => {
627620
}
628621
}
629622

623+
// Set up connections
630624
const agentConnection = new ClientSideConnection(
631625
() => new TestClient(),
632-
clientToAgent.writable,
633-
agentToClient.readable,
626+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
634627
);
635628

636629
const clientConnection = new AgentSideConnection(
637630
() => new TestAgent(),
638-
agentToClient.writable,
639-
clientToAgent.readable,
631+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
640632
);
641633

642634
// Test agent calling client extension method
@@ -729,16 +721,15 @@ describe("Connection", () => {
729721
// Note: No extMethod or extNotification implemented
730722
}
731723

724+
// Set up connections
732725
const agentConnection = new ClientSideConnection(
733726
() => new TestClientWithoutExtensions(),
734-
clientToAgent.writable,
735-
agentToClient.readable,
727+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
736728
);
737729

738730
const clientConnection = new AgentSideConnection(
739731
() => new TestAgentWithoutExtensions(),
740-
agentToClient.writable,
741-
clientToAgent.readable,
732+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
742733
);
743734

744735
// Test that calling extension methods on connections without them throws method not found
@@ -857,16 +848,15 @@ describe("Connection", () => {
857848
}
858849
}
859850

851+
// Set up connections
860852
const agentConnection = new ClientSideConnection(
861853
() => new TestClient(),
862-
clientToAgent.writable,
863-
agentToClient.readable,
854+
ndJsonStream(clientToAgent.writable, agentToClient.readable),
864855
);
865856

866857
const clientConnection = new AgentSideConnection(
867858
() => new TestAgent(),
868-
agentToClient.writable,
869-
clientToAgent.readable,
859+
ndJsonStream(agentToClient.writable, clientToAgent.readable),
870860
);
871861

872862
// Test writeTextFile returns response with _meta

0 commit comments

Comments
 (0)