MCPcopy Create free account
hub / github.com/coder/agentapi / newTestPair

Function newTestPair

x/acpio/acpio_test.go:56–82  ·  view source on GitHub ↗

newTestPair creates an ACPAgentIO connected to a testAgent via pipes.

(t *testing.T, agent *testAgent)

Source from the content-addressed store, hash-verified

54
55// newTestPair creates an ACPAgentIO connected to a testAgent via pipes.
56func newTestPair(t *testing.T, agent *testAgent) *acpio.ACPAgentIO {
57 t.Helper()
58
59 // Two pipe pairs: client writes → agent reads, agent writes → client reads.
60 clientToAgentR, clientToAgentW := io.Pipe()
61 agentToClientR, agentToClientW := io.Pipe()
62
63 // Client side: peerInput=clientToAgentW (writes to agent), peerOutput=agentToClientR (reads from agent)
64 // Agent side: peerInput=agentToClientW (writes to client), peerOutput=clientToAgentR (reads from client)
65 asc := acp.NewAgentSideConnection(agent, agentToClientW, clientToAgentR)
66 agent.SetAgentConnection(asc)
67
68 agentIO, err := acpio.NewWithPipes(
69 context.Background(),
70 clientToAgentW, agentToClientR,
71 nil,
72 func() (string, error) { return os.TempDir(), nil },
73 )
74 require.NoError(t, err)
75
76 t.Cleanup(func() {
77 _ = clientToAgentW.Close()
78 _ = agentToClientW.Close()
79 })
80
81 return agentIO
82}
83
84// chunkCollector collects chunks from SetOnChunk in a thread-safe way
85// and provides a method to wait for a specific number of chunks.

Calls 3

NewWithPipesFunction · 0.92
SetAgentConnectionMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected