the universal sandbox runtime for agents and humans.
pocketenv.io
sandbox
openclaw
agent
claude-code
vercel-sandbox
deno-sandbox
cloudflare-sandbox
atproto
sprites
daytona
1import { vi, describe, it, expect, beforeEach } from "vitest";
2import consola from "consola";
3import { Sandbox } from "@pocketenv/sdk";
4import start from "./start";
5
6vi.mock("../lib/sdk", () => ({ configureSdk: vi.fn() }));
7vi.mock("../lib/expandRepo", () => ({
8 expandRepo: vi.fn((repo: string) => repo),
9}));
10vi.mock("./ssh", () => ({ default: vi.fn().mockResolvedValue(undefined) }));
11vi.mock("consola", () => ({
12 default: { log: vi.fn(), success: vi.fn(), error: vi.fn() },
13}));
14vi.mock("@pocketenv/sdk", () => ({
15 Sandbox: { get: vi.fn(), configure: vi.fn() },
16}));
17
18import connectToSandbox from "./ssh";
19
20describe("start", () => {
21 beforeEach(() => {
22 vi.clearAllMocks();
23 });
24
25 it("starts a sandbox and logs success", async () => {
26 const mockSandbox = {
27 start: vi.fn().mockResolvedValue(undefined),
28 waitUntilRunning: vi.fn().mockResolvedValue(undefined),
29 };
30 vi.mocked(Sandbox.get).mockResolvedValue(mockSandbox as any);
31
32 await start("my-sandbox", {});
33
34 expect(Sandbox.get).toHaveBeenCalledWith("my-sandbox");
35 expect(mockSandbox.start).toHaveBeenCalledWith({
36 repo: undefined,
37 keepAlive: undefined,
38 });
39 expect(consola.success).toHaveBeenCalledWith(
40 expect.stringContaining("my-sandbox"),
41 );
42 });
43
44 it("connects via SSH when ssh option is set", async () => {
45 const mockSandbox = {
46 start: vi.fn().mockResolvedValue(undefined),
47 waitUntilRunning: vi.fn().mockResolvedValue(undefined),
48 };
49 vi.mocked(Sandbox.get).mockResolvedValue(mockSandbox as any);
50
51 await start("my-sandbox", { ssh: true });
52
53 expect(mockSandbox.waitUntilRunning).toHaveBeenCalledOnce();
54 expect(connectToSandbox).toHaveBeenCalledWith("my-sandbox");
55 expect(consola.success).not.toHaveBeenCalled();
56 });
57
58 it("expands repo URL when provided", async () => {
59 const { expandRepo } = await import("../lib/expandRepo");
60 const mockSandbox = {
61 start: vi.fn().mockResolvedValue(undefined),
62 };
63 vi.mocked(Sandbox.get).mockResolvedValue(mockSandbox as any);
64
65 await start("my-sandbox", { repo: "owner/repo" });
66
67 expect(expandRepo).toHaveBeenCalledWith("owner/repo");
68 });
69
70 it("logs error when start fails", async () => {
71 vi.mocked(Sandbox.get).mockRejectedValue(new Error("Not found"));
72
73 await start("my-sandbox", {});
74
75 expect(consola.error).toHaveBeenCalledWith("Failed to start sandbox");
76 });
77});