38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import path from "node:path";
|
|
import type { AdapterEnvironmentCheck, AdapterEnvironmentTestResult } from "./types.js";
|
|
import { normalizeCommandValue } from "./server-utils-process.js";
|
|
|
|
export function summarizeStatus(checks: AdapterEnvironmentCheck[]): AdapterEnvironmentTestResult["status"] {
|
|
if (checks.some((check) => check.level === "error")) return "fail";
|
|
if (checks.some((check) => check.level === "warn")) return "warn";
|
|
return "pass";
|
|
}
|
|
|
|
export function isNonEmpty(value: unknown): value is string {
|
|
return typeof value === "string" && value.trim().length > 0;
|
|
}
|
|
|
|
export function firstNonEmptyLine(text: string): string {
|
|
return (
|
|
text
|
|
.split(/\r?\n/)
|
|
.map((line) => line.trim())
|
|
.find(Boolean) ?? ""
|
|
);
|
|
}
|
|
|
|
export function commandLooksLike(command: string, expected: string): boolean {
|
|
const normalized = normalizeCommandValue(command).replace(/\\/g, "/");
|
|
const base = path.posix.basename(normalized).toLowerCase();
|
|
return base === expected || base === `${expected}.cmd` || base === `${expected}.exe`;
|
|
}
|
|
|
|
export function summarizeProbeDetail(stdout: string, stderr: string, parsedError?: string | null): string | null {
|
|
const raw = parsedError?.trim() || firstNonEmptyLine(stderr) || firstNonEmptyLine(stdout);
|
|
if (!raw) return null;
|
|
const clean = raw.replace(/\s+/g, " ").trim();
|
|
const max = 240;
|
|
return clean.length > max ? `${clean.slice(0, max - 1)}…` : clean;
|
|
}
|
|
|