Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 63 additions & 44 deletions src/lib/commands/onboard/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,81 @@

import { describe, expect, it } from "vitest";

import { toLegacyOnboardArgs } from "../../../../dist/lib/commands/onboard/common.js";
import { NOTICE_ACCEPT_FLAG } from "../../../../dist/lib/onboard/usage-notice.js";
import type { OnboardFlags } from "./common.js";
import { buildOnboardFlags, toLegacyOnboardArgs } from "../../../../dist/lib/commands/onboard/common";

const acceptFlagName = NOTICE_ACCEPT_FLAG.replace(/^--/, "");

describe("toLegacyOnboardArgs", () => {
it("should return an empty array when no flags are provided", () => {
const flags: OnboardFlags = {};
const args = toLegacyOnboardArgs(flags);
expect(args).toEqual([]);
});

it("should handle single boolean flags", () => {
expect(toLegacyOnboardArgs({ "non-interactive": true })).toEqual(["--non-interactive"]);
expect(toLegacyOnboardArgs({ resume: true })).toEqual(["--resume"]);
expect(toLegacyOnboardArgs({ fresh: true })).toEqual(["--fresh"]);
expect(toLegacyOnboardArgs({ "recreate-sandbox": true })).toEqual(["--recreate-sandbox"]);
expect(toLegacyOnboardArgs({ gpu: true })).toEqual(["--gpu"]);
expect(toLegacyOnboardArgs({ "no-gpu": true })).toEqual(["--no-gpu"]);
expect(toLegacyOnboardArgs({ yes: true })).toEqual(["--yes"]);
});

it("should not include boolean flags when they are false", () => {
expect(toLegacyOnboardArgs({ resume: false })).toEqual([]);
});

it("should handle string and numeric flags", () => {
expect(toLegacyOnboardArgs({ from: "./Dockerfile" })).toEqual(["--from", "./Dockerfile"]);
expect(toLegacyOnboardArgs({ name: "my-sandbox" })).toEqual(["--name", "my-sandbox"]);
expect(toLegacyOnboardArgs({ agent: "my-agent" })).toEqual(["--agent", "my-agent"]);
expect(toLegacyOnboardArgs({ "control-ui-port": 8080 })).toEqual(["--control-ui-port", "8080"]);
});

it("should handle the third-party software usage notice flag", () => {
expect(toLegacyOnboardArgs({ [acceptFlagName]: true })).toEqual([NOTICE_ACCEPT_FLAG]);
expect(toLegacyOnboardArgs({ [acceptFlagName]: false })).toEqual([]);
describe("onboard flags", () => {
it("buildOnboardFlags returns correct flags", () => {
const flags = buildOnboardFlags();
expect(flags).toBeDefined();
expect(flags["non-interactive"]).toBeDefined();
expect(flags["non-interactive"].type).toBe("boolean");
expect(flags.resume).toBeDefined();
expect(flags.resume.type).toBe("boolean");
expect(flags.resume.exclusive).toContain("fresh");
expect(flags.fresh).toBeDefined();
expect(flags.fresh.type).toBe("boolean");
expect(flags.fresh.exclusive).toContain("resume");
expect(flags["recreate-sandbox"]).toBeDefined();
expect(flags["recreate-sandbox"].type).toBe("boolean");
expect(flags.gpu).toBeDefined();
expect(flags.gpu.type).toBe("boolean");
expect(flags.gpu.exclusive).toContain("no-gpu");
expect(flags["no-gpu"]).toBeDefined();
expect(flags["no-gpu"].type).toBe("boolean");
expect(flags["no-gpu"].exclusive).toContain("gpu");
expect(flags.from).toBeDefined();
expect(flags.from.type).toBe("option");
expect(flags.name).toBeDefined();
expect(flags.name.type).toBe("option");
expect(flags.agent).toBeDefined();
expect(flags.agent.type).toBe("option");
expect(flags["control-ui-port"]).toBeDefined();
expect(flags["control-ui-port"].type).toBe("option");
expect(flags.yes).toBeDefined();
expect(flags.yes.type).toBe("boolean");
expect(flags.yes.char).toBe("y");
expect(flags["yes-i-accept-third-party-software"]).toBeDefined();
expect(flags["yes-i-accept-third-party-software"].type).toBe("boolean");
});

it("should process a combination of multiple flags correctly", () => {
const flags: OnboardFlags = {
it("toLegacyOnboardArgs constructs correct args", () => {
const flags = {
"non-interactive": true,
name: "combined-sandbox",
"control-ui-port": 9090,
resume: true,
"recreate-sandbox": true,
gpu: true,
from: "path/to/Dockerfile",
name: "my-sandbox",
agent: "my-agent",
"control-ui-port": 8080,
yes: true,
[acceptFlagName]: true,
"yes-i-accept-third-party-software": true,
};
const args = toLegacyOnboardArgs(flags);
expect(args).toEqual([
"--non-interactive",
"--resume",
"--recreate-sandbox",
"--gpu",
"--from",
"path/to/Dockerfile",
"--name",
"combined-sandbox",
"my-sandbox",
"--agent",
"my-agent",
"--control-ui-port",
"9090",
"8080",
"--yes",
NOTICE_ACCEPT_FLAG,
"--yes-i-accept-third-party-software",
]);
});

it("toLegacyOnboardArgs constructs correct args for mutually exclusive alternate flags", () => {
const flags = {
fresh: true,
"no-gpu": true,
};
const args = toLegacyOnboardArgs(flags);
expect(args).toEqual(["--fresh", "--no-gpu"]);
});
});
Loading