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(
|
function createRunner(
|
||||||
commandFn: (opts: CommandOptions, runtime: typeof defaultRuntime) => Promise<void>,
|
commandFn: (
|
||||||
|
opts: CommandOptions,
|
||||||
|
runtime: typeof defaultRuntime,
|
||||||
|
) => Promise<void>,
|
||||||
) {
|
) {
|
||||||
return async (opts: CommandOptions) => {
|
return async (opts: CommandOptions) => {
|
||||||
try {
|
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 ---
|
// --- Registration ---
|
||||||
|
|
||||||
export function registerSandboxCli(program: Command) {
|
export function registerSandboxCli(program: Command) {
|
||||||
|
|||||||
@@ -48,9 +48,13 @@ export function displayContainers(
|
|||||||
renderItem: (container, rt) => {
|
renderItem: (container, rt) => {
|
||||||
rt.log(` ${container.containerName}`);
|
rt.log(` ${container.containerName}`);
|
||||||
rt.log(` Status: ${formatStatus(container.running)}`);
|
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(` 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(` Session: ${container.sessionKey}`);
|
||||||
rt.log("");
|
rt.log("");
|
||||||
},
|
},
|
||||||
@@ -71,7 +75,9 @@ export function displayBrowsers(
|
|||||||
renderItem: (browser, rt) => {
|
renderItem: (browser, rt) => {
|
||||||
rt.log(` ${browser.containerName}`);
|
rt.log(` ${browser.containerName}`);
|
||||||
rt.log(` Status: ${formatStatus(browser.running)}`);
|
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}`);
|
rt.log(` CDP: ${browser.cdpPort}`);
|
||||||
if (browser.noVncPort) {
|
if (browser.noVncPort) {
|
||||||
rt.log(` noVNC: ${browser.noVncPort}`);
|
rt.log(` noVNC: ${browser.noVncPort}`);
|
||||||
|
|||||||
@@ -40,10 +40,14 @@ export type ContainerItem = {
|
|||||||
lastUsedAtMs: number;
|
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;
|
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;
|
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 {
|
import type {
|
||||||
SandboxBrowserInfo,
|
SandboxBrowserInfo,
|
||||||
@@ -82,11 +82,17 @@ function setupDefaultMocks() {
|
|||||||
mocks.clackConfirm.mockResolvedValue(true);
|
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));
|
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));
|
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +116,10 @@ describe("sandboxListCommand", () => {
|
|||||||
});
|
});
|
||||||
mocks.listSandboxContainers.mockResolvedValue([container1, container2]);
|
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, "📦 Sandbox Containers");
|
||||||
expectLogContains(runtime, container1.containerName);
|
expectLogContains(runtime, container1.containerName);
|
||||||
@@ -122,7 +131,10 @@ describe("sandboxListCommand", () => {
|
|||||||
const browser = createBrowser({ containerName: "browser-1" });
|
const browser = createBrowser({ containerName: "browser-1" });
|
||||||
mocks.listSandboxBrowsers.mockResolvedValue([browser]);
|
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, "🌐 Sandbox Browser Containers");
|
||||||
expectLogContains(runtime, browser.containerName);
|
expectLogContains(runtime, browser.containerName);
|
||||||
@@ -133,7 +145,10 @@ describe("sandboxListCommand", () => {
|
|||||||
const mismatchContainer = createContainer({ imageMatch: false });
|
const mismatchContainer = createContainer({ imageMatch: false });
|
||||||
mocks.listSandboxContainers.mockResolvedValue([mismatchContainer]);
|
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, "⚠️");
|
||||||
expectLogContains(runtime, "image mismatch");
|
expectLogContains(runtime, "image mismatch");
|
||||||
@@ -141,7 +156,10 @@ describe("sandboxListCommand", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should display message when no containers found", async () => {
|
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.");
|
expect(runtime.log).toHaveBeenCalledWith("No sandbox containers found.");
|
||||||
});
|
});
|
||||||
@@ -152,7 +170,10 @@ describe("sandboxListCommand", () => {
|
|||||||
const container = createContainer();
|
const container = createContainer();
|
||||||
mocks.listSandboxContainers.mockResolvedValue([container]);
|
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 loggedJson = runtime.log.mock.calls[0][0];
|
||||||
const parsed = JSON.parse(loggedJson);
|
const parsed = JSON.parse(loggedJson);
|
||||||
@@ -169,7 +190,10 @@ describe("sandboxListCommand", () => {
|
|||||||
new Error("Docker not available"),
|
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.");
|
expect(runtime.log).toHaveBeenCalledWith("No sandbox containers found.");
|
||||||
});
|
});
|
||||||
@@ -192,7 +216,10 @@ describe("sandboxRecreateCommand", () => {
|
|||||||
runtime as never,
|
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);
|
expect(runtime.exit).toHaveBeenCalledWith(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -202,7 +229,10 @@ describe("sandboxRecreateCommand", () => {
|
|||||||
runtime as never,
|
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);
|
expect(runtime.exit).toHaveBeenCalledWith(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -219,7 +249,9 @@ describe("sandboxRecreateCommand", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(mocks.removeSandboxContainer).toHaveBeenCalledTimes(1);
|
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 () => {
|
it("should filter by agent (exact + subkeys)", async () => {
|
||||||
@@ -234,8 +266,12 @@ describe("sandboxRecreateCommand", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(mocks.removeSandboxContainer).toHaveBeenCalledTimes(2);
|
expect(mocks.removeSandboxContainer).toHaveBeenCalledTimes(2);
|
||||||
expect(mocks.removeSandboxContainer).toHaveBeenCalledWith(agent.containerName);
|
expect(mocks.removeSandboxContainer).toHaveBeenCalledWith(
|
||||||
expect(mocks.removeSandboxContainer).toHaveBeenCalledWith(agentSub.containerName);
|
agent.containerName,
|
||||||
|
);
|
||||||
|
expect(mocks.removeSandboxContainer).toHaveBeenCalledWith(
|
||||||
|
agentSub.containerName,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should remove all when --all flag set", async () => {
|
it("should remove all when --all flag set", async () => {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { confirm as clackConfirm } from "@clack/prompts";
|
import { confirm as clackConfirm } from "@clack/prompts";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type SandboxBrowserInfo,
|
|
||||||
type SandboxContainerInfo,
|
|
||||||
listSandboxBrowsers,
|
listSandboxBrowsers,
|
||||||
listSandboxContainers,
|
listSandboxContainers,
|
||||||
removeSandboxBrowserContainer,
|
removeSandboxBrowserContainer,
|
||||||
removeSandboxContainer,
|
removeSandboxContainer,
|
||||||
|
type SandboxBrowserInfo,
|
||||||
|
type SandboxContainerInfo,
|
||||||
} from "../agents/sandbox.js";
|
} from "../agents/sandbox.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import {
|
import {
|
||||||
@@ -107,8 +107,9 @@ function validateRecreateOptions(
|
|||||||
runtime.exit(1);
|
runtime.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exclusiveCount = [opts.all, opts.session, opts.agent].filter(Boolean)
|
const exclusiveCount = [opts.all, opts.session, opts.agent].filter(
|
||||||
.length;
|
Boolean,
|
||||||
|
).length;
|
||||||
if (exclusiveCount > 1) {
|
if (exclusiveCount > 1) {
|
||||||
runtime.error("Please specify only one of: --all, --session, --agent");
|
runtime.error("Please specify only one of: --all, --session, --agent");
|
||||||
runtime.exit(1);
|
runtime.exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user