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 { unexposePort } from "./unexpose";
5
6vi.mock("../lib/sdk", () => ({ configureSdk: vi.fn() }));
7vi.mock("../theme", () => ({
8 c: {
9 primary: (s: string | number) => String(s),
10 },
11}));
12vi.mock("consola", () => ({
13 default: { log: vi.fn(), success: vi.fn(), error: vi.fn() },
14}));
15vi.mock("@pocketenv/sdk", () => ({
16 Sandbox: { get: vi.fn(), configure: vi.fn() },
17}));
18
19describe("unexposePort", () => {
20 const mockExit = vi
21 .spyOn(process, "exit")
22 .mockImplementation(() => undefined as never);
23
24 beforeEach(() => {
25 vi.clearAllMocks();
26 });
27
28 it("unexposes a port and logs success", async () => {
29 const mockSandbox = {
30 unexpose: vi.fn().mockResolvedValue(undefined),
31 };
32 vi.mocked(Sandbox.get).mockResolvedValue(mockSandbox as any);
33
34 await unexposePort("my-sandbox", 3000);
35
36 expect(mockSandbox.unexpose).toHaveBeenCalledWith(3000);
37 expect(consola.success).toHaveBeenCalledWith(
38 expect.stringContaining("3000"),
39 );
40 });
41
42 it("logs error and exits on failure", async () => {
43 vi.mocked(Sandbox.get).mockRejectedValue(new Error("API error"));
44
45 await unexposePort("my-sandbox", 3000);
46
47 expect(consola.error).toHaveBeenCalledWith(
48 expect.stringContaining("Failed to unexpose port"),
49 );
50 expect(mockExit).toHaveBeenCalledWith(1);
51 });
52});