File size: 27,797 Bytes
205131a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | import fs from "node:fs/promises";
import path from "node:path";
import { withTempHome } from "openclaw/plugin-sdk/test-env";
import { describe, expect, it } from "vitest";
import { runBuiltCli } from "./cli-json-stdout.test-support.js";
describe("cli json stdout contract", () => {
describe.each([
{ context: "ordinary fresh home", env: {}, reason: "never-asked" },
{ context: "automated fresh home", env: { CI: "1" }, reason: "automated-environment" },
{
context: "automation with an explicit endpoint",
env: {
CI: "1",
OPENCLAW_TELEMETRY_ENDPOINT: "https://telemetry.example.invalid/api/latest-version",
},
reason: "never-asked",
},
])("telemetry inspection in $context", ({ env, reason }) => {
it.each([
{ name: "piped stdout", tty: false, format: "JSON" },
{ name: "stubbed dual TTYs", tty: true, format: "JSON" },
{ name: "piped stdout", tty: false, format: "text" },
{ name: "stubbed dual TTYs", tty: true, format: "text" },
])("writes successful telemetry show $format to $name", async ({ tty, format }) => {
await withTempHome(
async (tempHome) => {
const preload = Buffer.from(
[
'import net from "node:net";',
'const denyNetwork = () => { throw new Error("TELEMETRY_NETWORK_FORBIDDEN"); };',
"net.Socket.prototype.connect = denyNetwork;",
"globalThis.fetch = async () => denyNetwork();",
...(tty
? [
'Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true });',
'Object.defineProperty(process.stderr, "isTTY", { value: true, configurable: true });',
]
: []),
].join("\n"),
).toString("base64");
// CI and the endpoint are named inputs, independent of the test runner's environment.
const result = runBuiltCli(
tempHome,
["telemetry", "show", ...(format === "JSON" ? ["--json"] : [])],
{
...env,
NODE_OPTIONS: `--import=data:text/javascript;base64,${preload}`,
OPENCLAW_CONFIG_PATH: path.join(tempHome, "missing-openclaw.json"),
OPENCLAW_STATE_DIR: path.join(tempHome, "isolated-state"),
...(tty ? { FORCE_COLOR: "1" } : {}),
},
{ inheritEnvironment: false },
);
expect(result.status, result.stderr).toBe(0);
const endpoint =
env.OPENCLAW_TELEMETRY_ENDPOINT ?? "https://telemetry.openclaw.ai/api/latest-version";
if (format === "JSON") {
expect(result.stdout, result.stderr).not.toContain("\u001B");
expect(result.stdout, result.stderr).not.toContain("\u0007");
const payload = JSON.parse(result.stdout);
expect(payload).toEqual({
featureStatsEnabled: false,
reason,
endpoint,
lastPingAt: null,
request:
reason === "automated-environment"
? null
: {
method: "GET",
userAgent: expect.stringMatching(/^openclaw\/[^ ]+ \(.+; gateway\)$/u),
},
});
expect(result.stdout).toBe(`${JSON.stringify(payload)}\n`);
} else {
// Human TTY output includes the startup banner before the inspection report.
const report = result.stdout.slice(result.stdout.indexOf("Feature stats:"));
const lines = report.trimEnd().split("\n");
expect(lines).toEqual([
"Feature stats: disabled",
`Reason: ${reason === "automated-environment" ? "disabled in an automated environment (CI is set)" : "consent has not been requested"}`,
`Endpoint: ${endpoint}`,
"Last ping: never",
...(reason === "automated-environment"
? ["Request: none (disabled in an automated environment (CI is set))"]
: [
`Request: GET ${endpoint}`,
expect.stringMatching(/^User-Agent: openclaw\/[^ ]+ \(.+; gateway\)$/u),
]),
]);
}
if (tty && format === "text") {
expect(result.stdout).toContain("OpenClaw");
expect(result.stderr).toContain("\u001B[?25h");
expect(result.stderr).not.toContain("TELEMETRY_NETWORK_FORBIDDEN");
} else {
expect(result.stderr).toBe("");
}
},
{ prefix: "openclaw-telemetry-json-success-e2e-" },
);
});
});
it("keeps `update status --json` stdout parseable even with legacy doctor preflight inputs", async () => {
await withTempHome(
async (tempHome) => {
const legacyDir = path.join(tempHome, ".clawdbot");
await fs.mkdir(legacyDir, { recursive: true });
await fs.writeFile(path.join(legacyDir, "clawdbot.json"), "{}", "utf8");
const result = runBuiltCli(tempHome, ["update", "status", "--json", "--timeout", "1"]);
expect(result.status).toBe(0);
const stdout = result.stdout.trim();
expect(stdout.length).toBeGreaterThan(0);
const parsed = JSON.parse(stdout) as unknown;
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
throw new Error(`Expected JSON object stdout, got: ${stdout}`);
}
expect(Object.keys(parsed).toSorted((a, b) => a.localeCompare(b))).toEqual([
"availability",
"channel",
"update",
]);
expect(stdout).not.toContain("Doctor warnings");
expect(stdout).not.toContain("Doctor changes");
expect(stdout).not.toContain("Config invalid");
},
{ prefix: "openclaw-json-e2e-" },
);
});
it("rejects an explicitly empty update status timeout before emitting JSON", async () => {
await withTempHome(
async (tempHome) => {
const result = runBuiltCli(tempHome, ["update", "status", "--json", "--timeout", ""]);
expect(result.status, result.stderr).toBe(1);
expect(JSON.parse(result.stdout)).toEqual({
ok: false,
error: {
type: "cli_error",
message: "--timeout must be a positive integer (seconds)",
},
});
expect(result.stderr).toContain("--timeout must be a positive integer (seconds)");
},
{ prefix: "openclaw-update-empty-timeout-e2e-" },
);
});
it.each([
{
name: "account validation in human mode",
args: ["channels", "capabilities", "--account", "ghost"],
message: "--account requires a specific --channel. Run openclaw channels list to choose one.",
human: true,
},
{
name: "account validation with JSON before its option",
args: ["channels", "capabilities", "--json", "--account", "ghost"],
message: "--account requires a specific --channel. Run openclaw channels list to choose one.",
},
{
name: "target validation with JSON after its option and explicit Commander routing",
args: ["channels", "capabilities", "--target", "channel:1", "--json"],
message: "--target requires a specific --channel. Run openclaw channels list to choose one.",
commander: true,
},
{
name: "unknown channel validation with JSON before its option",
args: ["channels", "capabilities", "--json", "--channel", "definitely-not-a-channel"],
message:
'Unknown channel "definitely-not-a-channel". Run `openclaw channels list --all` to see configured and installable channels.',
},
{
name: "account validation through dual-TTY finalization",
args: ["channels", "capabilities", "--account", "ghost", "--json"],
message: "--account requires a specific --channel. Run openclaw channels list to choose one.",
tty: true,
},
])(
"renders channels capabilities $name through the canonical failure owner",
async (testCase) => {
await withTempHome(
async (tempHome) => {
const preload = Buffer.from(
[
'import net from "node:net";',
'net.Socket.prototype.connect = function () { throw new Error("AUTOQA_NETWORK_FORBIDDEN"); };',
'globalThis.fetch = async () => { throw new Error("AUTOQA_NETWORK_FORBIDDEN"); };',
...("tty" in testCase
? [
'Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true });',
'Object.defineProperty(process.stderr, "isTTY", { value: true, configurable: true });',
]
: []),
].join("\n"),
).toString("base64");
const result = runBuiltCli(tempHome, testCase.args, {
NODE_OPTIONS: `--import=data:text/javascript;base64,${preload}`,
OPENCLAW_STATE_DIR: path.join(tempHome, "isolated-state"),
OPENCLAW_CONFIG_PATH: path.join(tempHome, "missing-openclaw.json"),
OPENCLAW_GATEWAY_PORT: "29871",
...("commander" in testCase ? { OPENCLAW_DISABLE_ROUTE_FIRST: "1" } : {}),
...("tty" in testCase ? { FORCE_COLOR: "1" } : {}),
});
expect(result.status, result.stderr).toBe(1);
if ("human" in testCase) {
expect(result.stdout).toBe("");
} else {
expect(result.stdout, result.stderr).not.toContain("\u001B");
expect(result.stdout, result.stderr).not.toContain("\u0007");
expect(JSON.parse(result.stdout)).toEqual({
ok: false,
error: { type: "cli_error", message: testCase.message },
});
}
expect(result.stderr).toContain(testCase.message);
expect(result.stderr).not.toContain("AUTOQA_NETWORK_FORBIDDEN");
if ("tty" in testCase) {
expect(result.stderr).toContain("\u001B[?25h");
}
},
{ prefix: "openclaw-channels-capabilities-failure-e2e-" },
);
},
);
it.each(["probe", "diagnostics"])(
"keeps the CLI alive until stalled channel capability %s reports its timeout",
async (stage) => {
await withTempHome(
async (tempHome) => {
const pluginDir = path.join(tempHome, "capability-plugin");
const workspace = path.join(tempHome, "workspace");
await fs.mkdir(pluginDir);
await fs.mkdir(workspace);
const id = "capability-fixture";
const meta = {
id,
label: "Capability fixture",
selectionLabel: "Capability fixture",
docsPath: "/channels/test",
blurb: "Synthetic channel",
};
const schema = {
type: "object",
additionalProperties: false,
properties: { enabled: { type: "boolean" } },
};
await fs.writeFile(
path.join(pluginDir, "package.json"),
JSON.stringify({
name: id,
version: "1.0.0",
type: "module",
openclaw: {
extensions: ["./index.js"],
setupEntry: "./index.js",
channel: meta,
},
}),
);
await fs.writeFile(
path.join(pluginDir, "openclaw.plugin.json"),
JSON.stringify({
id,
channels: [id],
configSchema: { type: "object", additionalProperties: false, properties: {} },
channelConfigs: { [id]: { schema } },
}),
);
await fs.writeFile(
path.join(pluginDir, "index.js"),
`export const plugin = {
id: ${JSON.stringify(id)}, meta: ${JSON.stringify(meta)},
capabilities: { chatTypes: ["direct"] },
configSchema: { schema: ${JSON.stringify(schema)} },
config: {
listAccountIds: () => ["default"],
resolveAccount: () => ({ accountId: "default", enabled: true }),
isConfigured: () => true, isEnabled: () => true,
},
status: {
async probeAccount() { return ${stage === "probe" ? "new Promise(() => {})" : "{ ok: true }"}; },
async buildCapabilitiesDiagnostics() { return ${stage === "diagnostics" ? "new Promise(() => {})" : "{ lines: [] }"}; },
},
};
export default { id: plugin.id, register(api) { api.registerChannel({ plugin }); } };`,
);
const configPath = path.join(tempHome, "openclaw.json");
await fs.writeFile(
configPath,
JSON.stringify({
agents: { defaults: { workspace } },
plugins: { load: { paths: [pluginDir] }, entries: { [id]: { enabled: true } } },
channels: { [id]: { enabled: true } },
logging: { level: "silent", consoleLevel: "silent" },
}),
);
const result = runBuiltCli(
tempHome,
["channels", "capabilities", "--json", "--timeout", "20"],
{
OPENCLAW_CONFIG_PATH: configPath,
OPENCLAW_STATE_DIR: path.join(tempHome, "isolated-state"),
OPENCLAW_DISABLE_BUNDLED_PLUGINS: "1",
},
{ inheritEnvironment: false },
);
expect(result.status, result.stderr).toBe(0);
const [report] = JSON.parse(result.stdout).channels;
expect(report.channel).toBe(id);
if (stage === "probe") {
expect(report.probe).toEqual({
ok: false,
timedOut: true,
error: "probe timed out after 20ms",
});
} else {
expect(report.probe).toEqual({ ok: true });
expect(report.diagnostics).toEqual({
lines: [{ text: "Diagnostics: timed out after 20ms", tone: "error" }],
details: { timedOut: true },
});
}
},
{ prefix: "openclaw-capabilities-timeout-e2e-" },
);
},
);
it("returns one canonical document for a command that previously failed on stderr only", async () => {
await withTempHome(
async (tempHome) => {
const missingArchive = path.join(tempHome, "missing-backup.tar.gz");
const result = runBuiltCli(tempHome, ["backup", "verify", missingArchive, "--json"]);
expect(result.status).toBe(1);
expect(JSON.parse(result.stdout)).toEqual({
ok: false,
error: {
type: "cli_error",
message: expect.stringContaining("missing-backup.tar.gz"),
},
});
},
{ prefix: "openclaw-json-failure-e2e-" },
);
});
it.each([
{
name: "secrets apply",
args: (tempHome: string) => [
"secrets",
"apply",
"--from",
path.join(tempHome, "missing-plan.json"),
"--json",
],
status: 1,
message: (tempHome: string) =>
`Secrets plan file not found: ${path.join(tempHome, "missing-plan.json")}`,
},
{
name: "secrets store get",
args: () => ["secrets", "store", "get", "MISSING_VALUE", "--json"],
status: 3,
message: () => 'Secret store entry "MISSING_VALUE" was not found.',
},
])("keeps $name failures machine-readable", async (testCase) => {
await withTempHome(
async (tempHome) => {
const result = runBuiltCli(tempHome, testCase.args(tempHome), {
OPENCLAW_STATE_DIR: path.join(tempHome, "isolated-state"),
});
expect(result.status, result.stderr).toBe(testCase.status);
expect(JSON.parse(result.stdout)).toEqual({
ok: false,
error: { type: "cli_error", message: testCase.message(tempHome) },
});
expect(result.stdout).not.toContain("[openclaw]");
},
{ prefix: "openclaw-secrets-json-failure-e2e-" },
);
});
it.each([
{ name: "qr", command: ["qr"] },
{ name: "clawbot qr", command: ["clawbot", "qr"] },
])("renders conflicting $name options as one canonical JSON document", async (testCase) => {
await withTempHome(
async (tempHome) => {
for (const conflict of [
{
args: ["--limited", "--voice-node"],
message: "Use either --limited or --voice-node, not both.",
},
{
args: ["--token", "test-token", "--password", "test-password"],
message: "Use either --token or --password, not both.",
},
]) {
const result = runBuiltCli(tempHome, [...testCase.command, "--json", ...conflict.args], {
OPENCLAW_CONFIG_PATH: path.join(tempHome, "missing-openclaw.json"),
OPENCLAW_STATE_DIR: path.join(tempHome, "isolated-state"),
});
expect(result.status, result.stderr).toBe(1);
expect(JSON.parse(result.stdout)).toEqual({
ok: false,
error: { type: "cli_error", message: conflict.message },
});
expect(result.stdout).not.toContain("[openclaw]");
expect(result.stderr).toContain(conflict.message);
}
},
{ prefix: "openclaw-qr-json-failure-e2e-" },
);
});
it.each([
{ name: "qr", command: ["qr"] },
{ name: "clawbot qr", command: ["clawbot", "qr"] },
])("keeps combined $name output flags as one JSON document on stdout", async ({ command }) => {
await withTempHome(
async (tempHome) => {
const configPath = path.join(tempHome, "openclaw.json");
await fs.writeFile(
configPath,
JSON.stringify({
gateway: {
bind: "custom",
customBindHost: "127.0.0.1",
auth: { mode: "token", token: "e2e-token" },
},
}),
);
for (const flags of [
["--setup-code-only", "--json"],
["--json", "--setup-code-only"],
]) {
const result = runBuiltCli(
tempHome,
[...command, ...flags],
{
OPENCLAW_CONFIG_PATH: configPath,
OPENCLAW_STATE_DIR: path.join(tempHome, "isolated-state"),
},
{ inheritEnvironment: false },
);
expect(result.status, result.stderr).toBe(0);
const payload = JSON.parse(result.stdout);
expect(typeof payload.setupCode).toBe("string");
expect(payload.gatewayUrl).toBe("ws://127.0.0.1:18789");
expect(result.stderr).not.toContain(payload.setupCode);
}
},
{ prefix: "openclaw-qr-setup-code-json-e2e-" },
);
});
it("renders sandbox explain validation failures as one canonical JSON document", async () => {
await withTempHome(
async (tempHome) => {
const result = runBuiltCli(tempHome, [
"sandbox",
"explain",
"--json",
"--agent",
"alpha",
"--session",
"agent:beta:main",
]);
expect(result.status, result.stderr).toBe(1);
expect(JSON.parse(result.stdout)).toEqual({
ok: false,
error: {
type: "cli_error",
message: 'Sandbox explain agent "alpha" does not match session agent "beta".',
},
});
expect(result.stderr).toContain(
'Sandbox explain agent "alpha" does not match session agent "beta".',
);
},
{ prefix: "openclaw-sandbox-json-failure-e2e-" },
);
});
it("returns one canonical document when docs search fails", async () => {
await withTempHome(
async (tempHome) => {
const preload = `data:text/javascript,${encodeURIComponent(
'globalThis.fetch = async () => { throw new Error("offline fixture"); };',
)}`;
const result = runBuiltCli(tempHome, ["docs", "offline", "--json"], {
NODE_OPTIONS: `--import=${preload}`,
});
expect(result.status).toBe(1);
expect(JSON.parse(result.stdout)).toEqual({
ok: false,
error: {
type: "cli_error",
message: "Docs search failed: offline fixture",
},
});
expect(result.stderr).toContain("Docs search failed: offline fixture");
},
{ prefix: "openclaw-docs-json-failure-e2e-" },
);
});
it("keeps Commander parse failures machine-readable in JSON mode", async () => {
await withTempHome(
async (tempHome) => {
const result = runBuiltCli(tempHome, [
"config",
"get",
"gateway.port",
"--json",
"--not-a-real-option",
]);
expect(result.status).toBe(1);
const payload = JSON.parse(result.stdout) as {
ok: boolean;
error: { type: string; message: string };
};
expect(payload).toMatchObject({
ok: false,
error: {
type: "cli_error",
message: expect.stringContaining("--not-a-real-option"),
},
});
expect(payload.error.message).not.toMatch(/^error:/i);
expect(result.stderr).toContain("--not-a-real-option");
},
{ prefix: "openclaw-json-parse-failure-e2e-" },
);
});
it.each([
{
name: "unknown root",
args: ["pairng"],
diagnostic: 'OpenClaw does not know the command "pairng".',
suggestion: "openclaw pairing",
},
{
name: "unknown nested command",
args: ["sessions", "lst"],
diagnostic: 'OpenClaw sessions has no command "lst".',
suggestion: "openclaw sessions list",
},
{
name: "unknown nested command with a later argument",
args: ["config", "gett", "gateway.port"],
diagnostic: 'OpenClaw config has no command "gett".',
suggestion: "openclaw config get",
},
{
name: "unknown root before help",
args: ["pairng", "--help"],
diagnostic: 'OpenClaw does not know the command "pairng".',
suggestion: "openclaw pairing",
},
])("renders $name as actionable guidance", async (testCase) => {
await withTempHome(
async (tempHome) => {
const result = runBuiltCli(tempHome, testCase.args);
expect(result.status).toBe(1);
expect(result.stdout).toBe("");
expect(result.stderr).toContain(testCase.diagnostic);
expect(result.stderr).toContain(`Did you mean this?\n ${testCase.suggestion}`);
expect(result.stderr.split(testCase.diagnostic)).toHaveLength(2);
expect(result.stderr.split(testCase.suggestion)).toHaveLength(2);
expect(result.stderr).not.toContain("The CLI command failed.");
expect(result.stderr).not.toContain("Could not start the CLI.");
expect(result.stderr).not.toContain("OPENCLAW_DEBUG");
expect(result.stderr).not.toContain("openclaw doctor");
if (testCase.args.includes("--help")) {
expect(result.stdout).not.toContain("Usage: openclaw [options] [command]");
}
},
{ prefix: "openclaw-unknown-command-e2e-" },
);
});
it.each([
{
name: "unknown root",
args: ["pairng", "--json"],
diagnostic: 'OpenClaw does not know the command "pairng".',
suggestion: "openclaw pairing",
},
{
name: "unknown nested command",
args: ["sessions", "lst", "--json"],
diagnostic: 'OpenClaw sessions has no command "lst".',
suggestion: "openclaw sessions list",
},
])("reports $name once with structured JSON guidance", async (testCase) => {
await withTempHome(
async (tempHome) => {
const result = runBuiltCli(tempHome, testCase.args);
expect(result.status).toBe(1);
const payload = JSON.parse(result.stdout) as {
ok: boolean;
error: { type: string; message: string };
};
expect(payload.ok).toBe(false);
expect(payload.error.type).toBe("cli_error");
expect(payload.error.message).toContain(testCase.diagnostic);
expect(payload.error.message).not.toMatch(/^error:/i);
expect(payload.error.message).toContain(`Did you mean this?\n ${testCase.suggestion}`);
expect(payload.error.message).not.toContain("OPENCLAW_DEBUG");
expect(payload.error.message).not.toContain("openclaw doctor");
expect(result.stderr).toContain(testCase.diagnostic);
expect(result.stderr).toContain(`Did you mean this?\n ${testCase.suggestion}`);
expect(result.stderr.split(testCase.diagnostic)).toHaveLength(2);
expect(result.stderr.split(testCase.suggestion)).toHaveLength(2);
expect(result.stderr).not.toContain("The CLI command failed.");
expect(result.stderr).not.toContain("Could not start the CLI.");
expect(result.stderr).not.toContain("OPENCLAW_DEBUG");
expect(result.stderr).not.toContain("openclaw doctor");
},
{ prefix: "openclaw-unknown-command-json-e2e-" },
);
});
it("keeps parse-error JSON free of terminal controls when color is forced", async () => {
await withTempHome(
async (tempHome) => {
const result = runBuiltCli(tempHome, ["sessions", "lst", "--json"], {
FORCE_COLOR: "1",
});
expect(result.status).toBe(1);
const payload = JSON.parse(result.stdout) as {
error: { message: string };
};
expect(payload.error.message).toBe(
'OpenClaw sessions has no command "lst".\nDid you mean this?\n openclaw sessions list\nTry: openclaw sessions --help\nDocs: https://docs.openclaw.ai/cli',
);
expect(payload.error.message).not.toContain("\u001B");
expect(payload.error.message).not.toContain("\u0007");
expect(result.stdout).not.toContain("\\u001b");
expect(result.stderr).toContain("\u001B[");
},
{ prefix: "openclaw-unknown-command-color-json-e2e-" },
);
});
it("returns structured Doctor lint output when llama.cpp is not bundled", async () => {
await withTempHome(
async (tempHome) => {
const bundledPluginsDir = path.join(tempHome, "packaged-extensions");
const memoryCoreDir = path.join(bundledPluginsDir, "memory-core");
await fs.mkdir(memoryCoreDir, { recursive: true });
await fs.writeFile(
path.join(memoryCoreDir, "doctor-health-api.js"),
[
"export function registerMemoryCoreDoctorChecks(host) {",
" host.registerHealthCheck({",
' id: "memory-core/managed-local-embedding-setup",',
' kind: "plugin",',
' source: "memory-core",',
' description: "packaged Memory Core readiness fixture",',
" async detect() { return []; },",
" });",
"}",
"",
].join("\n"),
"utf8",
);
const result = runBuiltCli(
tempHome,
[
"doctor",
"--lint",
"--only",
"memory-core/managed-local-embedding-setup",
"--severity-min",
"error",
"--json",
],
{
OPENCLAW_BUNDLED_PLUGINS_DIR: bundledPluginsDir,
OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR: "1",
},
);
expect(result.status, result.stderr).toBe(0);
expect(JSON.parse(result.stdout)).toMatchObject({
ok: true,
checksRun: 1,
findings: [],
});
},
{ prefix: "openclaw-doctor-packaged-json-e2e-" },
);
});
});
|