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.
This commit is contained in:
committed by
Peter Steinberger
parent
b0c97d6178
commit
7f02b62bba
@@ -58,7 +58,10 @@ Modifiers:
|
||||
};
|
||||
|
||||
function createRunner(
|
||||
commandFn: (opts: CommandOptions, runtime: typeof defaultRuntime) => Promise<void>,
|
||||
commandFn: (
|
||||
opts: CommandOptions,
|
||||
runtime: typeof defaultRuntime,
|
||||
) => Promise<void>,
|
||||
) {
|
||||
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) {
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -40,10 +40,14 @@ export type ContainerItem = {
|
||||
lastUsedAtMs: number;
|
||||
};
|
||||
|
||||
export function countRunning<T extends { running: boolean }>(items: T[]): number {
|
||||
export function countRunning<T extends { running: boolean }>(
|
||||
items: T[],
|
||||
): number {
|
||||
return items.filter((item) => item.running).length;
|
||||
}
|
||||
|
||||
export function countMismatches<T extends { imageMatch: boolean }>(items: T[]): number {
|
||||
export function countMismatches<T extends { imageMatch: boolean }>(
|
||||
items: T[],
|
||||
): number {
|
||||
return items.filter((item) => !item.imageMatch).length;
|
||||
}
|
||||
|
||||
@@ -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<typeof createMockRuntime>, text: string) {
|
||||
function expectLogContains(
|
||||
runtime: ReturnType<typeof createMockRuntime>,
|
||||
text: string,
|
||||
) {
|
||||
expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining(text));
|
||||
}
|
||||
|
||||
function expectErrorContains(runtime: ReturnType<typeof createMockRuntime>, text: string) {
|
||||
function expectErrorContains(
|
||||
runtime: ReturnType<typeof createMockRuntime>,
|
||||
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 <key>, or --agent <id>");
|
||||
expectErrorContains(
|
||||
runtime,
|
||||
"Please specify --all, --session <key>, or --agent <id>",
|
||||
);
|
||||
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 () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user