From 3b6562b4ac134c754c29f93ebc39306f3efb5ba7 Mon Sep 17 00:00:00 2001 From: Bolubillions1 Date: Sun, 18 Oct 2026 14:04:15 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20SW-022=20=E2=80=94=20Normalize=20shared?= =?UTF-8?q?=20diagnostic=20timeout=20result=20classifi=20(#125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/diagnostics/docker.ts | 53 ++++++++++++++++++++++++++++++++++++--- src/diagnostics/git.ts | 16 ++++++++++-- src/diagnostics/rust.ts | 28 +++++++++++++++++++-- 3 files changed, 90 insertions(+), 7 deletions(-) diff --git a/src/diagnostics/docker.ts b/src/diagnostics/docker.ts index cd720b2..a7997c6 100644 --- a/src/diagnostics/docker.ts +++ b/src/diagnostics/docker.ts @@ -1,6 +1,7 @@ import { classifyCommandResult, runCommand, + type CommandOutcome, type RunCommand, } from './process.js'; import type { @@ -23,6 +24,27 @@ function parseDockerVersion(output: string): string | null { return match?.[1] ?? null; } +function timeoutMessage(required: boolean): string { + return required + ? 'Docker is required but the Docker CLI timed out.' + : 'Docker CLI timed out; container-based workflows may be unavailable.'; +} + +function timeoutRemediation(): string { + return 'Check that `docker --version` responds promptly and retry the diagnostic.'; +} + +function classifiedMessage(outcome: CommandOutcome): string { + switch (outcome) { + case 'missing-executable': + return 'Docker CLI is not available; container-based workflows may be unavailable.'; + case 'timed-out': + return timeoutMessage(false); + default: + return 'Docker CLI could not be executed; container-based workflows may be unavailable.'; + } +} + export function createDockerDiagnostic( options: DockerDiagnosticOptions = {}, ): DiagnosticCheck { @@ -34,15 +56,26 @@ export function createDockerDiagnostic( label: 'Docker', run(): DiagnosticResult { const client = execute('docker', ['--version']); + const clientOutcome = classifyCommandResult(client); + + if (clientOutcome === 'timed-out') { + return { + id: 'docker', + label: 'Docker', + status: unavailableStatus(required), + message: timeoutMessage(required), + remediation: timeoutRemediation(), + }; + } - if (classifyCommandResult(client) !== 'ok') { + if (clientOutcome !== 'ok') { return { id: 'docker', label: 'Docker', status: unavailableStatus(required), message: required ? 'Docker is required but the Docker CLI is unavailable.' - : 'Docker CLI is not available; container-based workflows may be unavailable.', + : classifiedMessage(clientOutcome), remediation: 'Install Docker and ensure `docker` is available on PATH if your selected workflow requires containers.', }; @@ -66,8 +99,22 @@ export function createDockerDiagnostic( '--format', '{{.ServerVersion}}', ]); + const daemonOutcome = classifyCommandResult(daemon); + + if (daemonOutcome === 'timed-out') { + return { + id: 'docker', + label: 'Docker', + status: unavailableStatus(required), + message: required + ? `Docker ${version} is installed, but the Docker daemon timed out.` + : `Docker ${version} is installed, but the daemon timed out; container-based workflows may not run.`, + remediation: + 'Check that `docker info` responds promptly and retry the diagnostic.', + }; + } - if (daemon.error || daemon.status !== 0 || daemon.stdout.trim() === '') { + if (daemonOutcome !== 'ok' || daemon.stdout.trim() === '') { return { id: 'docker', label: 'Docker', diff --git a/src/diagnostics/git.ts b/src/diagnostics/git.ts index fd21109..3658dee 100644 --- a/src/diagnostics/git.ts +++ b/src/diagnostics/git.ts @@ -18,8 +18,20 @@ export function createGitDiagnostic( label: 'Git', run(): DiagnosticResult { const result = execute('git', ['--version']); + const outcome = classifyCommandResult(result); - if (classifyCommandResult(result) !== 'ok') { + if (outcome === 'timeout') { + return { + id: 'git', + label: 'Git', + status: 'fail', + message: 'Git timed out while reporting its version.', + remediation: + 'Check that `git --version` responds promptly and retry the diagnostic.', + }; + } + + if (outcome !== 'ok') { return { id: 'git', label: 'Git', @@ -36,7 +48,7 @@ export function createGitDiagnostic( id: 'git', label: 'Git', status: 'fail', - message: 'Git returned an unrecognized version.', + message: 'Git returned an unecognized version.', remediation: 'Verify `git --version` works and reinstall Git if necessary.', }; diff --git a/src/diagnostics/rust.ts b/src/diagnostics/rust.ts index cb8f3f0..2f0c7b4 100644 --- a/src/diagnostics/rust.ts +++ b/src/diagnostics/rust.ts @@ -26,8 +26,20 @@ export function createRustDiagnostic( label: 'Rust', run(): DiagnosticResult { const result = execute('rustc', ['--version']); + const outcome = classifyCommandResult(result); - if (classifyCommandResult(result) !== 'ok') { + if (outcome === 'timed-out') { + return { + id: 'rust', + label: 'Rust', + status: 'fail', + message: 'Rust timed out while reporting its version.', + remediation: + 'Check that `rustc --version` responds promptly and retry the diagnostic.', + }; + } + + if (outcome !== 'ok') { return { id: 'rust', label: 'Rust', @@ -81,8 +93,20 @@ export function createCargoDiagnostic( label: 'Cargo', run(): DiagnosticResult { const result = execute('cargo', ['--version']); + const outcome = classifyCommandResult(result); + + if (outcome === 'timed-out') { + return { + id: 'cargo', + label: 'Cargo', + status: 'fail', + message: 'Cargo timed out while reporting its version.', + remediation: + 'Check that `cargo --version` responds promptly and retry the diagnostic.', + }; + } - if (classifyCommandResult(result) !== 'ok') { + if (outcome !== 'ok') { return { id: 'cargo', label: 'Cargo',