Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bb53acb
fix(onboard): color preflight WARN/ERROR check lines (#6004)
jason-ma-nv Jun 30, 2026
b1096dd
fix(onboard): apply warnLine to bridge container start probe inconclu…
prekshivyas Jul 1, 2026
6f58de2
fix(onboard): route image-pull DNS warning through warnLine (#6004)
jason-ma-nv Jul 2, 2026
a7fbec4
Merge remote-tracking branch 'origin/main' into fix/6004-preflight-wa…
jason-ma-nv Jul 3, 2026
3c9cb0c
fix(onboard): color preflight WARN/ERROR by target stream via styleTe…
jason-ma-nv Jul 3, 2026
61a3ecc
fix(onboard): keep onboard.ts net-neutral under growth guardrail (#6004)
jason-ma-nv Jul 3, 2026
d004a26
fix(onboard): extract preflight severity messages so onboard.ts lines…
jason-ma-nv Jul 3, 2026
a3bbfe4
test(onboard): drop unused beforeEach import in terminal-style test (…
jason-ma-nv Jul 3, 2026
1bd7555
fix(onboard): color Docker-unreachable preflight
cv Jul 3, 2026
210c6a0
fix(onboard): tighten preflight severity helpers
cv Jul 3, 2026
7ee50d1
test(onboard): isolate severity regressions
cv Jul 3, 2026
bed601a
merge: refresh preflight severity fixes with main
cv Jul 3, 2026
e54e9c4
fix(onboard): complete stderr severity coverage
cv Jul 3, 2026
dc83915
merge: refresh preflight severity fixes with main
cv Jul 3, 2026
e074fd7
test(onboard): linearize stream restoration
cv Jul 3, 2026
5054368
fix(onboard): harden preflight severity output
apurvvkumaria Jul 4, 2026
ce84032
fix(onboard): color fatal CDI preflight
apurvvkumaria Jul 4, 2026
9e06a53
fix(onboard): color deferred gateway warning
apurvvkumaria Jul 4, 2026
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
100 changes: 98 additions & 2 deletions src/lib/cli/terminal-style.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

import { B, D, G, R, RD, YW } from "./terminal-style";
import {
B,
D,
failLine,
G,
infoLine,
okLine,
R,
RD,
severityLine,
warnLine,
YW,
} from "./terminal-style";

describe("terminal-style", () => {
it("exports terminal style strings", () => {
Expand All @@ -12,3 +24,87 @@
}
});
});

const ORIGINAL_STDOUT = {
isTTY: process.stdout.isTTY,
getColorDepth: process.stdout.getColorDepth,
};
const ORIGINAL_STDERR = {
isTTY: process.stderr.isTTY,
getColorDepth: process.stderr.getColorDepth,
};

// styleText decides color from the target stream's reported color depth
// (`getColorDepth()`), which is where a real terminal folds in isTTY, NO_COLOR,
// NODE_DISABLE_COLORS and FORCE_COLOR. Depth 1 = no color (what NO_COLOR / a
// redirected pipe / CI report); depth 24 = truecolor. Model both directly so
// each case is deterministic regardless of the worker's own TTY/env.
function stubStream(stream: NodeJS.WriteStream, isTTY: boolean, colorDepth: number): void {
Object.defineProperty(stream, "isTTY", { value: isTTY, configurable: true });
Object.defineProperty(stream, "getColorDepth", { value: () => colorDepth, configurable: true });
}

function restoreStream(
stream: NodeJS.WriteStream,
original: { isTTY: boolean | undefined; getColorDepth: unknown },
): void {
Object.defineProperty(stream, "isTTY", { value: original.isTTY, configurable: true });
Object.defineProperty(stream, "getColorDepth", {
value: original.getColorDepth,
configurable: true,
});
}

// styleText's `yellow`/`red`/`green` formats (as of Node 22.16) wrap text in
// SGR color codes with a `39` (default-foreground) reset.
const YELLOW = (s: string) => `\x1b[33m${s}\x1b[39m`;
const RED = (s: string) => `\x1b[31m${s}\x1b[39m`;
const GREEN = (s: string) => `\x1b[32m${s}\x1b[39m`;

describe("preflight severity lines (#6004)", () => {
afterEach(() => {
vi.unstubAllEnvs();
restoreStream(process.stdout, ORIGINAL_STDOUT);
restoreStream(process.stderr, ORIGINAL_STDERR);
});

it("colors warn/error from stderr — their real stream — not stdout (#6004)", () => {
// stdout redirected to a file, terminal still on stderr: warn/error must
// stay colored (they land on the color-capable stderr) while stdout-bound
// ok lines go plain. The old helpers colored from stdout and dropped these.
stubStream(process.stderr, true, 24);
stubStream(process.stdout, false, 1);
expect(warnLine("disk low")).toBe(` ${YELLOW("⚠ disk low")}`);
expect(failLine("docker down")).toBe(` ${RED("✗ docker down")}`);
expect(okLine("ready")).toBe(" ✓ ready");
});

it("drops warn/error color when stderr is redirected but stdout is a TTY (#6004)", () => {
// The inverse leak: stderr redirected to a log, stdout still a terminal.
// warn/error must go plain so no raw ANSI lands in the log; stdout-bound
// ok lines stay colored. The old helpers colored from stdout and leaked.
stubStream(process.stdout, true, 24);
stubStream(process.stderr, false, 1);
expect(warnLine("disk low")).toBe(" ⚠ disk low");
expect(failLine("docker down")).toBe(" ✗ docker down");
expect(okLine("ready")).toBe(` ${GREEN("✓ ready")}`);
});

it("emits plain text with no ANSI when the stream reports no color (NO_COLOR / CI)", () => {
// A real terminal under NO_COLOR reports color depth 1; redirected pipes
// and CI do the same. Assert the observable #6004 guarantee: no escapes.
vi.stubEnv("NO_COLOR", "1");
stubStream(process.stdout, true, 1);
stubStream(process.stderr, true, 1);
expect(warnLine("a")).toBe(" ⚠ a");
expect(failLine("b")).toBe(" ✗ b");
expect(okLine("c")).toBe(" ✓ c");
});

it("leaves info lines uncolored with no marker on any stream", () => {
stubStream(process.stdout, true, 24);
stubStream(process.stderr, true, 24);
expect(infoLine("hello")).toBe(" hello");
expect(severityLine("info", "hello")).toBe(" hello");
});
});
48 changes: 48 additions & 0 deletions src/lib/cli/terminal-style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { styleText } from "node:util";

const useColor = !process.env.NO_COLOR && !!process.stdout.isTTY;
const trueColor =
useColor && (process.env.COLORTERM === "truecolor" || process.env.COLORTERM === "24bit");
Expand All @@ -11,3 +13,49 @@ export const D = useColor ? "\x1b[2m" : "";
export const R = useColor ? "\x1b[0m" : "";
export const RD = useColor ? "\x1b[1;31m" : "";
export const YW = useColor ? "\x1b[1;33m" : "";

/**
* Semantic severity levels for onboard preflight output (#6004).
*
* `info` keeps the default terminal color; `ok`/`warn`/`error` add a colored
* marker so warnings and failures stand out in the lengthy preflight output.
*/
export type SeverityLevel = "info" | "ok" | "warn" | "error";

type SeverityStyle = {
marker: string;
format: "green" | "yellow" | "red" | null;
stream: NodeJS.WriteStream;
};

// The stream each level is written to decides its color. `ok`/`info` are
// emitted on stdout (`console.log`/`console.info`); `warn`/`error` on stderr
// (`console.warn`/`console.error`). `styleText({ stream })` then keys color off
// that stream's own capability and honors NO_COLOR / NODE_DISABLE_COLORS /
// FORCE_COLOR (#6004). This replaces the previous helpers, which colored from
// `process.stdout.isTTY` while printing to stderr — so redirecting either
// stream independently mis-styled the other (dropped color on `onboard >log`,
// leaked ANSI into `onboard 2>log`).
const SEVERITY_STYLES: Record<SeverityLevel, SeverityStyle> = {
info: { marker: "", format: null, stream: process.stdout },
ok: { marker: "✓ ", format: "green", stream: process.stdout },
warn: { marker: "⚠ ", format: "yellow", stream: process.stderr },
error: { marker: "✗ ", format: "red", stream: process.stderr },
};

/**
* Render one indented preflight line at `level`. The returned string is meant
* to be passed to the matching console method (`ok`/`info` → `console.log` /
* `console.info`; `warn` → `console.warn`; `error` → `console.error`) so its
* color decision matches the stream it lands on.
*/
export function severityLine(level: SeverityLevel, message: string): string {
const { marker, format, stream } = SEVERITY_STYLES[level];
const body = `${marker}${message}`;
return ` ${format ? styleText(format, body, { stream }) : body}`;
}

export const infoLine = (message: string): string => severityLine("info", message);
export const okLine = (message: string): string => severityLine("ok", message);
export const warnLine = (message: string): string => severityLine("warn", message);
export const failLine = (message: string): string => severityLine("error", message);
25 changes: 15 additions & 10 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ const sandboxCreateFailureDiagnostics: typeof import("./onboard/sandbox-create-f

import type { CurlProbeResult } from "./adapters/http/probe";
import type { AgentDefinition } from "./agent/defs";
import { failLine, warnLine } from "./cli/terminal-style";
import type { WebSearchConfig } from "./inference/web-search";
import {
hydrateMessagingChannelConfig,
Expand Down Expand Up @@ -1593,7 +1594,7 @@ type PreflightOptions = Pick<
// running bridge/DNS diagnostics that would be misleading.
function rejectUnsupportedContainerRuntime(host: ReturnType<typeof assessHost>): void {
if (isLinuxDockerDriverGatewayEnabled() && host.runtime === "podman") {
console.error(` ✗ ${cliDisplayName()} onboarding now uses OpenShell's Docker driver.`);
console.error(failLine(`${cliDisplayName()} onboarding now uses OpenShell's Docker driver.`));
console.error(` Podman is not supported for this ${cliDisplayName()} integration path.`);
console.error(" Switch to Docker Engine and rerun onboarding.");
process.exit(1);
Expand Down Expand Up @@ -1654,8 +1655,10 @@ async function preflight(
}
const detectedStr = detected.length > 0 ? detected.join(" / ") : "unknown";
console.warn(
` ⚠ Container runtime under-provisioned: ${detectedStr} detected ` +
`(recommended: ${preflightUtils.MIN_RECOMMENDED_DOCKER_CPUS} vCPU / ${preflightUtils.MIN_RECOMMENDED_DOCKER_MEM_GIB} GiB).`,
warnLine(
`Container runtime under-provisioned: ${detectedStr} detected ` +
`(recommended: ${preflightUtils.MIN_RECOMMENDED_DOCKER_CPUS} vCPU / ${preflightUtils.MIN_RECOMMENDED_DOCKER_MEM_GIB} GiB).`,
),
);
console.warn(" The sandbox build will be slow and may stall on default Colima settings.");
if (host.runtime === "colima") {
Expand Down Expand Up @@ -1910,8 +1913,10 @@ async function preflight(
const mem = getMemoryInfo();
if (mem) {
if (mem.totalMB < 12000) {
console.log(
` ⚠ Low memory detected (${mem.totalRamMB} MB RAM + ${mem.totalSwapMB} MB swap = ${mem.totalMB} MB total)`,
console.warn(
warnLine(
`Low memory detected (${mem.totalRamMB} MB RAM + ${mem.totalSwapMB} MB swap = ${mem.totalMB} MB total)`,
),
);

let proceedWithSwap: boolean = false;
Expand All @@ -1938,8 +1943,8 @@ async function preflight(
console.log(` ✓ Memory OK: ${mem.totalRamMB} MB RAM + ${mem.totalSwapMB} MB swap`);
}
} else {
console.log(` ⚠ Could not create swap: ${swapResult.reason}`);
console.log(" Sandbox creation may fail with OOM on low-memory systems.");
console.warn(warnLine(`Could not create swap: ${swapResult.reason}`));
console.warn(" Sandbox creation may fail with OOM on low-memory systems.");
}
}
} else {
Expand Down Expand Up @@ -3241,9 +3246,9 @@ async function createSandbox(
// cannot be verified via CLI yet — only gateway-level existence is checked).
for (const p of messagingProviders) {
if (!providerExistsInGateway(p)) {
console.error(` ⚠ Messaging provider '${p}' was not found in the gateway.`);
console.error(` The credential may not be available inside the sandbox.`);
console.error(
console.warn(warnLine(`Messaging provider '${p}' was not found in the gateway.`));
console.warn(` The credential may not be available inside the sandbox.`);
console.warn(
` To fix: openshell provider create --name ${p} --type generic --credential <KEY>`,
);
}
Expand Down
33 changes: 21 additions & 12 deletions src/lib/onboard/bridge-dns-preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* on the fatal reasons described in `[[isFatalContainerDnsProbeFailure]]`.
*/

import { failLine, warnLine } from "../cli/terminal-style";
import { cliDisplayName, cliName } from "./branding";

interface DaemonJsonDnsPatchOpts {
Expand Down Expand Up @@ -96,7 +97,7 @@ export function printDockerBridgeContainerStartFailure(
result: DockerBridgeContainerStartProbeResult,
host?: Pick<Host, "isWsl">,
): void {
console.error(" ✗ Docker could not start a bridge-network test container.");
console.error(failLine("Docker could not start a bridge-network test container."));
if (result.details) {
for (const line of String(result.details).split("\n").slice(-4)) {
if (line.trim()) console.error(` ${line.trim()}`);
Expand Down Expand Up @@ -170,7 +171,9 @@ export function assertDockerBridgeAndContainerDnsHealthy(host: Host, nonInteract
process.exit(1);
} else {
console.warn(
` ⚠ Bridge container start probe inconclusive (reason: ${bridgeStart.reason ?? "unknown"}).`,
warnLine(
`Bridge container start probe inconclusive (reason: ${bridgeStart.reason ?? "unknown"}).`,
),
);
if (bridgeStart.details) {
for (const line of String(bridgeStart.details).split("\n").slice(-3)) {
Expand Down Expand Up @@ -203,14 +206,16 @@ export function assertDockerBridgeAndContainerDnsHealthy(host: Host, nonInteract
if (!dnsIsFatal) {
if (dns.reason === "image_pull_failed") {
console.warn(
" ⚠ Container DNS probe inconclusive: docker couldn't pull the busybox test image.",
warnLine("Container DNS probe inconclusive: docker couldn't pull the busybox test image."),
);
console.warn(" This usually means the docker daemon itself can't reach Docker Hub,");
console.warn(
" but doesn't prove container DNS is broken — the sandbox build may still succeed.",
);
} else {
console.warn(` ⚠ Container DNS probe inconclusive (reason: ${dns.reason ?? "unknown"}).`);
console.warn(
warnLine(`Container DNS probe inconclusive (reason: ${dns.reason ?? "unknown"}).`),
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
if (dns.details) {
for (const line of String(dns.details).split("\n").slice(-3)) {
Expand Down Expand Up @@ -250,15 +255,15 @@ export function assertDockerBridgeAndContainerDnsHealthy(host: Host, nonInteract
process.exit(1);
}
if (dns.reason === "timeout" || dns.reason === "killed") {
console.error(" ✗ Container DNS probe did not complete.");
console.error(failLine("Container DNS probe did not complete."));
} else if (dns.reason === "image_pull_failed") {
console.error(" ✗ Docker could not resolve or pull the DNS probe image.");
console.error(failLine("Docker could not resolve or pull the DNS probe image."));
} else if (dns.reason === "resolution_failed") {
console.error(
" ✗ Container DNS server is reachable but rejected the query (NXDOMAIN/REFUSED).",
failLine("Container DNS server is reachable but rejected the query (NXDOMAIN/REFUSED)."),
);
} else {
console.error(" ✗ DNS resolution from inside a docker container failed.");
console.error(failLine("DNS resolution from inside a docker container failed."));
}
if (dns.details) {
for (const line of String(dns.details).split("\n").slice(-4)) {
Expand Down Expand Up @@ -397,7 +402,7 @@ export function assertHostDnsHealthy(host: Host, opts: AssertHostDnsHealthyOpts
return;
}
if (!isFatalHostDnsProbeFailure(result)) {
console.warn(` ⚠ Host DNS probe inconclusive (reason: ${result.reason ?? "unknown"}).`);
console.warn(warnLine(`Host DNS probe inconclusive (reason: ${result.reason ?? "unknown"}).`));
if (result.details) {
console.warn(` ${String(result.details).trim()}`);
}
Expand All @@ -408,11 +413,15 @@ export function assertHostDnsHealthy(host: Host, opts: AssertHostDnsHealthyOpts
}

if (result.reason === "timeout" || result.reason === "killed") {
console.error(` ✗ Host DNS probe did not complete (could not resolve ${result.hostname}).`);
console.error(
failLine(`Host DNS probe did not complete (could not resolve ${result.hostname}).`),
);
} else if (result.reason === "resolution_failed") {
console.error(` ✗ Host could not resolve ${result.hostname} (resolver answered, no record).`);
console.error(
failLine(`Host could not resolve ${result.hostname} (resolver answered, no record).`),
);
} else {
console.error(` ✗ Host DNS resolution failed (could not resolve ${result.hostname}).`);
console.error(failLine(`Host DNS resolution failed (could not resolve ${result.hostname}).`));
}
if (result.details) {
console.error(` ${String(result.details).trim()}`);
Expand Down
13 changes: 7 additions & 6 deletions src/lib/onboard/gateway-sandbox-reachability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os from "node:os";

import { dockerCapture, dockerRun } from "../adapters/docker/run";
import { failLine, warnLine } from "../cli/terminal-style";
import { GATEWAY_PORT } from "../core/ports";
import { cliDisplayName, cliName } from "./branding";
import {
Expand Down Expand Up @@ -406,7 +407,7 @@ export function formatSandboxBridgeUnreachableMessage(
const includeWslIntegrationHint = opts.isWsl ?? isRunningInWsl();
if (result.reason === "probe_unavailable") {
return [
" ⚠ Could not verify sandbox bridge reachability.",
warnLine("Could not verify sandbox bridge reachability."),
" This does not prove the gateway is unreachable; continuing.",
result.detail ? ` ${result.detail}` : undefined,
]
Expand All @@ -416,7 +417,7 @@ export function formatSandboxBridgeUnreachableMessage(

if (result.reason === "veth_unsupported") {
return [
" ✗ Docker could not create the sandbox bridge veth pair.",
failLine("Docker could not create the sandbox bridge veth pair."),
result.detail ? ` ${result.detail}` : undefined,
" This matches Jetson kernel/Docker bridge environments where veth creation returns `operation not supported`.",
` Update the host kernel/Docker bridge networking support, or run ${cliDisplayName()} on a host whose Docker bridge networking can create veth interfaces.`,
Expand All @@ -427,7 +428,7 @@ export function formatSandboxBridgeUnreachableMessage(

if (result.reason === "probe_timeout") {
return [
" ✗ Docker-driver sandbox bridge reachability probe timed out.",
failLine("Docker-driver sandbox bridge reachability probe timed out."),
result.detail ? ` ${result.detail}` : undefined,
` Restart Docker and check for stuck container/network operations before retrying \`${cliName()} onboard\`.`,
]
Expand All @@ -437,7 +438,7 @@ export function formatSandboxBridgeUnreachableMessage(

if (result.reason === "docker_daemon_unreachable") {
return [
" ✗ Docker daemon is not reachable for the sandbox bridge probe.",
failLine("Docker daemon is not reachable for the sandbox bridge probe."),
result.detail ? ` ${result.detail}` : undefined,
includeWslIntegrationHint ? ` ${DOCKER_DESKTOP_WSL_INTEGRATION_HINT}` : undefined,
" Restart the Docker daemon (e.g. `sudo systemctl restart docker`, or restart Docker Desktop/Colima)",
Expand All @@ -449,7 +450,7 @@ export function formatSandboxBridgeUnreachableMessage(

if (result.routeKind === "host_gateway") {
return [
` ✗ Sandbox containers cannot reach the gateway at ${HOST_INTERNAL_NAME}:${port}.`,
failLine(`Sandbox containers cannot reach the gateway at ${HOST_INTERNAL_NAME}:${port}.`),
" The probe used Docker's host-gateway route, matching Docker Desktop/VM-backed Docker.",
` Restart Docker and the OpenShell gateway, then re-run \`${cliName()} onboard\`.`,
].join("\n");
Expand All @@ -468,7 +469,7 @@ export function formatSandboxBridgeUnreachableMessage(
? `${HOST_INTERNAL_NAME}:${port} (${result.gatewayIp}:${port})`
: `${HOST_INTERNAL_NAME}:${port}`;
return [
` ✗ Sandbox containers cannot reach the gateway at ${target}.`,
failLine(`Sandbox containers cannot reach the gateway at ${target}.`),
" A host firewall may be blocking traffic from the OpenShell Docker bridge.",
" To allow it:",
allowCmd,
Expand Down
Loading
Loading