Skip to content

Commit 775f731

Browse files
authored
feat: Add --id option to connect to existing remote agents via tunnel (#7999)
1 parent e1c8878 commit 775f731

File tree

3 files changed

+300
-122
lines changed

3 files changed

+300
-122
lines changed

extensions/cli/src/commands/remote.test.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,77 @@ describe("remote command", () => {
145145
expect(mockConsoleLog).not.toHaveBeenCalled();
146146
});
147147

148+
it("should fetch tunnel and connect when id option is provided", async () => {
149+
const agentId = "agent-789";
150+
151+
mockFetch
152+
.mockResolvedValueOnce({
153+
ok: true,
154+
json: async () => ({ url: "ws://tunnel-url.com", port: 9090 }),
155+
})
156+
.mockResolvedValue({
157+
ok: true,
158+
json: async () => ({
159+
id: "test-agent-id",
160+
url: "ws://test-url.com",
161+
port: 8080,
162+
}),
163+
});
164+
165+
await remote("test prompt", { id: agentId });
166+
167+
expect(mockFetch).toHaveBeenCalledWith(
168+
new URL(`agents/${agentId}/tunnel`, mockEnv.env.apiBase),
169+
expect.objectContaining({
170+
method: "POST",
171+
headers: {
172+
"Content-Type": "application/json",
173+
Authorization: "Bearer test-token",
174+
},
175+
}),
176+
);
177+
178+
expect(mockStartRemoteTUIChat.startRemoteTUIChat).toHaveBeenCalledWith(
179+
"ws://tunnel-url.com",
180+
"test prompt",
181+
);
182+
});
183+
184+
it("should output JSON without starting TUI when using --id with --start", async () => {
185+
const agentId = "agent-456";
186+
const tunnelResponse = { url: "ws://existing-tunnel.com", port: 7070 };
187+
188+
mockFetch.mockResolvedValueOnce({
189+
ok: true,
190+
json: async () => tunnelResponse,
191+
});
192+
193+
await remote("test prompt", { id: agentId, start: true });
194+
195+
expect(mockFetch).toHaveBeenCalledWith(
196+
new URL(`agents/${agentId}/tunnel`, mockEnv.env.apiBase),
197+
expect.objectContaining({
198+
method: "POST",
199+
headers: {
200+
"Content-Type": "application/json",
201+
Authorization: "Bearer test-token",
202+
},
203+
}),
204+
);
205+
206+
expect(mockStartRemoteTUIChat.startRemoteTUIChat).not.toHaveBeenCalled();
207+
expect(mockConsoleLog).toHaveBeenCalledWith(
208+
JSON.stringify({
209+
status: "success",
210+
message: "Remote agent tunnel connection details",
211+
url: tunnelResponse.url,
212+
containerPort: tunnelResponse.port,
213+
agentId,
214+
mode: "existing_agent",
215+
}),
216+
);
217+
});
218+
148219
it("should handle proper request body structure with all fields", async () => {
149220
const testIdempotencyKey = "structured-test-key";
150221

@@ -298,10 +369,10 @@ describe("remote command", () => {
298369
repoUrl: "https://github.com/user/test-repo.git",
299370
name: expect.stringMatching(/^devbox-\d+$/),
300371
prompt: "test prompt",
301-
idempotencyKey: undefined,
302372
agent: undefined,
303373
config: undefined,
304374
});
375+
expect(requestBody).not.toHaveProperty("idempotencyKey");
305376
});
306377

307378
describe("start mode (-s / --start flag)", () => {

0 commit comments

Comments
 (0)