import path from "node:path"; import { describe, expect, it } from "vitest"; import { formatCliCommand } from "./command-format.js"; import { applyCliProfileEnv, parseCliProfileArgs } from "./profile.js";
describe("formatCliCommand", () => {
it.each([
{
name: "no profile is set",
cmd: "openclaw doctor --fix",
env: {},
expected: "openclaw doctor --fix",
},
{
name: "profile is default",
cmd: "openclaw doctor --fix",
env: { OPENCLAW_PROFILE: "default" },
expected: "openclaw doctor --fix",
},
{
name: "profile is Default (case-insensitive)",
cmd: "openclaw doctor --fix",
env: { OPENCLAW_PROFILE: "Default" },
expected: "openclaw doctor --fix",
},
{
name: "profile is invalid",
cmd: "openclaw doctor --fix",
env: { OPENCLAW_PROFILE: "bad profile" },
expected: "openclaw doctor --fix",
},
{
name: "--profile is already present",
cmd: "openclaw --profile work doctor --fix",
env: { OPENCLAW_PROFILE: "work" },
expected: "openclaw --profile work doctor --fix",
},
{
name: "--dev is already present",
cmd: "openclaw --dev doctor",
env: { OPENCLAW_PROFILE: "dev" },
expected: "openclaw --dev doctor",
},
])("returns command unchanged when $name", ({ cmd, env, expected }) => {
expect(formatCliCommand(cmd, env)).toBe(expected);
});
it("inserts --profile flag when profile is set", () => {
expect(formatCliCommand("openclaw doctor --fix", { OPENCLAW_PROFILE: "work" })).toBe( "openclaw --profile work doctor --fix",
);
});
it("trims whitespace from profile", () => {
expect(formatCliCommand("openclaw doctor --fix", { OPENCLAW_PROFILE: " jbopenclaw " })).toBe( "openclaw --profile jbopenclaw doctor --fix",
);
});
it("handles command with no args after openclaw", () => {
expect(formatCliCommand("openclaw", { OPENCLAW_PROFILE: "test" })).toBe( "openclaw --profile test",
);
});
it("inserts --container when a container hint is set", () => {
expect(
formatCliCommand("openclaw gateway status --deep", { OPENCLAW_CONTAINER_HINT: "demo" }),
).toBe("openclaw --container demo gateway status --deep");
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.