Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion extensions/cli/src/commands/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,77 @@ describe("remote command", () => {
expect(mockConsoleLog).not.toHaveBeenCalled();
});

it("should fetch tunnel and connect when id option is provided", async () => {
const agentId = "agent-789";

mockFetch
.mockResolvedValueOnce({
ok: true,
json: async () => ({ url: "ws://tunnel-url.com", port: 9090 }),
})
.mockResolvedValue({
ok: true,
json: async () => ({
id: "test-agent-id",
url: "ws://test-url.com",
port: 8080,
}),
});

await remote("test prompt", { id: agentId });

expect(mockFetch).toHaveBeenCalledWith(
new URL(`agents/${agentId}/tunnel`, mockEnv.env.apiBase),
expect.objectContaining({
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer test-token",
},
}),
);

expect(mockStartRemoteTUIChat.startRemoteTUIChat).toHaveBeenCalledWith(
"ws://tunnel-url.com",
"test prompt",
);
});

it("should output JSON without starting TUI when using --id with --start", async () => {
const agentId = "agent-456";
const tunnelResponse = { url: "ws://existing-tunnel.com", port: 7070 };

mockFetch.mockResolvedValueOnce({
ok: true,
json: async () => tunnelResponse,
});

await remote("test prompt", { id: agentId, start: true });

expect(mockFetch).toHaveBeenCalledWith(
new URL(`agents/${agentId}/tunnel`, mockEnv.env.apiBase),
expect.objectContaining({
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer test-token",
},
}),
);

expect(mockStartRemoteTUIChat.startRemoteTUIChat).not.toHaveBeenCalled();
expect(mockConsoleLog).toHaveBeenCalledWith(
JSON.stringify({
status: "success",
message: "Remote agent tunnel connection details",
url: tunnelResponse.url,
containerPort: tunnelResponse.port,
agentId,
mode: "existing_agent",
}),
);
});

it("should handle proper request body structure with all fields", async () => {
const testIdempotencyKey = "structured-test-key";

Expand Down Expand Up @@ -298,10 +369,10 @@ describe("remote command", () => {
repoUrl: "https://github.com/user/test-repo.git",
name: expect.stringMatching(/^devbox-\d+$/),
prompt: "test prompt",
idempotencyKey: undefined,
agent: undefined,
config: undefined,
});
expect(requestBody).not.toHaveProperty("idempotencyKey");
});

describe("start mode (-s / --start flag)", () => {
Expand Down
Loading
Loading