From 7f02b62bba60dcc2404cfb4509afb3633d3563e6 Mon Sep 17 00:00:00 2001 From: sheeek Date: Fri, 9 Jan 2026 10:13:00 +0100 Subject: [PATCH] style(sandbox): fix linting errors - Remove unused normalizeOptions function - Fix line length violations (format long lines) - Fix import order (alphabetical) - Format function signatures for readability All lint checks now passing. --- src/cli/sandbox-cli.ts | 13 ++---- src/commands/sandbox-display.ts | 12 ++++-- src/commands/sandbox-formatters.ts | 8 +++- src/commands/sandbox.test.ts | 66 +++++++++++++++++++++++------- src/commands/sandbox.ts | 9 ++-- 5 files changed, 75 insertions(+), 33 deletions(-) diff --git a/src/cli/sandbox-cli.ts b/src/cli/sandbox-cli.ts index 0f7317b8a..e03806dff 100644 --- a/src/cli/sandbox-cli.ts +++ b/src/cli/sandbox-cli.ts @@ -58,7 +58,10 @@ Modifiers: }; function createRunner( - commandFn: (opts: CommandOptions, runtime: typeof defaultRuntime) => Promise, + commandFn: ( + opts: CommandOptions, + runtime: typeof defaultRuntime, + ) => Promise, ) { return async (opts: CommandOptions) => { try { @@ -70,14 +73,6 @@ function createRunner( }; } -function normalizeOptions(opts: CommandOptions): CommandOptions { - const normalized: CommandOptions = {}; - for (const [key, value] of Object.entries(opts)) { - normalized[key] = typeof value === "boolean" ? value : value; - } - return normalized; -} - // --- Registration --- export function registerSandboxCli(program: Command) { diff --git a/src/commands/sandbox-display.ts b/src/commands/sandbox-display.ts index 0bda314f5..4ac8d897d 100644 --- a/src/commands/sandbox-display.ts +++ b/src/commands/sandbox-display.ts @@ -48,9 +48,13 @@ export function displayContainers( renderItem: (container, rt) => { rt.log(` ${container.containerName}`); rt.log(` Status: ${formatStatus(container.running)}`); - rt.log(` Image: ${container.image} ${formatImageMatch(container.imageMatch)}`); + rt.log( + ` Image: ${container.image} ${formatImageMatch(container.imageMatch)}`, + ); rt.log(` Age: ${formatAge(Date.now() - container.createdAtMs)}`); - rt.log(` Idle: ${formatAge(Date.now() - container.lastUsedAtMs)}`); + rt.log( + ` Idle: ${formatAge(Date.now() - container.lastUsedAtMs)}`, + ); rt.log(` Session: ${container.sessionKey}`); rt.log(""); }, @@ -71,7 +75,9 @@ export function displayBrowsers( renderItem: (browser, rt) => { rt.log(` ${browser.containerName}`); rt.log(` Status: ${formatStatus(browser.running)}`); - rt.log(` Image: ${browser.image} ${formatImageMatch(browser.imageMatch)}`); + rt.log( + ` Image: ${browser.image} ${formatImageMatch(browser.imageMatch)}`, + ); rt.log(` CDP: ${browser.cdpPort}`); if (browser.noVncPort) { rt.log(` noVNC: ${browser.noVncPort}`); diff --git a/src/commands/sandbox-formatters.ts b/src/commands/sandbox-formatters.ts index cc3eef865..82ae5a9ce 100644 --- a/src/commands/sandbox-formatters.ts +++ b/src/commands/sandbox-formatters.ts @@ -40,10 +40,14 @@ export type ContainerItem = { lastUsedAtMs: number; }; -export function countRunning(items: T[]): number { +export function countRunning( + items: T[], +): number { return items.filter((item) => item.running).length; } -export function countMismatches(items: T[]): number { +export function countMismatches( + items: T[], +): number { return items.filter((item) => !item.imageMatch).length; } diff --git a/src/commands/sandbox.test.ts b/src/commands/sandbox.test.ts index 8921d4b2b..63d54ed5d 100644 --- a/src/commands/sandbox.test.ts +++ b/src/commands/sandbox.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi, beforeEach } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import type { SandboxBrowserInfo, @@ -82,11 +82,17 @@ function setupDefaultMocks() { mocks.clackConfirm.mockResolvedValue(true); } -function expectLogContains(runtime: ReturnType, text: string) { +function expectLogContains( + runtime: ReturnType, + text: string, +) { expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining(text)); } -function expectErrorContains(runtime: ReturnType, text: string) { +function expectErrorContains( + runtime: ReturnType, + text: string, +) { expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining(text)); } @@ -110,7 +116,10 @@ describe("sandboxListCommand", () => { }); mocks.listSandboxContainers.mockResolvedValue([container1, container2]); - await sandboxListCommand({ browser: false, json: false }, runtime as never); + await sandboxListCommand( + { browser: false, json: false }, + runtime as never, + ); expectLogContains(runtime, "📦 Sandbox Containers"); expectLogContains(runtime, container1.containerName); @@ -122,7 +131,10 @@ describe("sandboxListCommand", () => { const browser = createBrowser({ containerName: "browser-1" }); mocks.listSandboxBrowsers.mockResolvedValue([browser]); - await sandboxListCommand({ browser: true, json: false }, runtime as never); + await sandboxListCommand( + { browser: true, json: false }, + runtime as never, + ); expectLogContains(runtime, "🌐 Sandbox Browser Containers"); expectLogContains(runtime, browser.containerName); @@ -133,7 +145,10 @@ describe("sandboxListCommand", () => { const mismatchContainer = createContainer({ imageMatch: false }); mocks.listSandboxContainers.mockResolvedValue([mismatchContainer]); - await sandboxListCommand({ browser: false, json: false }, runtime as never); + await sandboxListCommand( + { browser: false, json: false }, + runtime as never, + ); expectLogContains(runtime, "⚠️"); expectLogContains(runtime, "image mismatch"); @@ -141,7 +156,10 @@ describe("sandboxListCommand", () => { }); it("should display message when no containers found", async () => { - await sandboxListCommand({ browser: false, json: false }, runtime as never); + await sandboxListCommand( + { browser: false, json: false }, + runtime as never, + ); expect(runtime.log).toHaveBeenCalledWith("No sandbox containers found."); }); @@ -152,11 +170,14 @@ describe("sandboxListCommand", () => { const container = createContainer(); mocks.listSandboxContainers.mockResolvedValue([container]); - await sandboxListCommand({ browser: false, json: true }, runtime as never); + await sandboxListCommand( + { browser: false, json: true }, + runtime as never, + ); const loggedJson = runtime.log.mock.calls[0][0]; const parsed = JSON.parse(loggedJson); - + expect(parsed.containers).toHaveLength(1); expect(parsed.containers[0].containerName).toBe(container.containerName); expect(parsed.browsers).toHaveLength(0); @@ -169,7 +190,10 @@ describe("sandboxListCommand", () => { new Error("Docker not available"), ); - await sandboxListCommand({ browser: false, json: false }, runtime as never); + await sandboxListCommand( + { browser: false, json: false }, + runtime as never, + ); expect(runtime.log).toHaveBeenCalledWith("No sandbox containers found."); }); @@ -192,7 +216,10 @@ describe("sandboxRecreateCommand", () => { runtime as never, ); - expectErrorContains(runtime, "Please specify --all, --session , or --agent "); + expectErrorContains( + runtime, + "Please specify --all, --session , or --agent ", + ); expect(runtime.exit).toHaveBeenCalledWith(1); }); @@ -202,7 +229,10 @@ describe("sandboxRecreateCommand", () => { runtime as never, ); - expectErrorContains(runtime, "Please specify only one of: --all, --session, --agent"); + expectErrorContains( + runtime, + "Please specify only one of: --all, --session, --agent", + ); expect(runtime.exit).toHaveBeenCalledWith(1); }); }); @@ -219,7 +249,9 @@ describe("sandboxRecreateCommand", () => { ); expect(mocks.removeSandboxContainer).toHaveBeenCalledTimes(1); - expect(mocks.removeSandboxContainer).toHaveBeenCalledWith(match.containerName); + expect(mocks.removeSandboxContainer).toHaveBeenCalledWith( + match.containerName, + ); }); it("should filter by agent (exact + subkeys)", async () => { @@ -234,8 +266,12 @@ describe("sandboxRecreateCommand", () => { ); expect(mocks.removeSandboxContainer).toHaveBeenCalledTimes(2); - expect(mocks.removeSandboxContainer).toHaveBeenCalledWith(agent.containerName); - expect(mocks.removeSandboxContainer).toHaveBeenCalledWith(agentSub.containerName); + expect(mocks.removeSandboxContainer).toHaveBeenCalledWith( + agent.containerName, + ); + expect(mocks.removeSandboxContainer).toHaveBeenCalledWith( + agentSub.containerName, + ); }); it("should remove all when --all flag set", async () => { diff --git a/src/commands/sandbox.ts b/src/commands/sandbox.ts index dd2295ff6..058b0305f 100644 --- a/src/commands/sandbox.ts +++ b/src/commands/sandbox.ts @@ -1,12 +1,12 @@ import { confirm as clackConfirm } from "@clack/prompts"; import { - type SandboxBrowserInfo, - type SandboxContainerInfo, listSandboxBrowsers, listSandboxContainers, removeSandboxBrowserContainer, removeSandboxContainer, + type SandboxBrowserInfo, + type SandboxContainerInfo, } from "../agents/sandbox.js"; import type { RuntimeEnv } from "../runtime.js"; import { @@ -107,8 +107,9 @@ function validateRecreateOptions( runtime.exit(1); } - const exclusiveCount = [opts.all, opts.session, opts.agent].filter(Boolean) - .length; + const exclusiveCount = [opts.all, opts.session, opts.agent].filter( + Boolean, + ).length; if (exclusiveCount > 1) { runtime.error("Please specify only one of: --all, --session, --agent"); runtime.exit(1);