From e018616daf4c297d247aa9a30b4b2f1121406dbf Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Wed, 3 Jun 2026 20:02:59 -0600 Subject: [PATCH] Warn in the navbar when a drive's SMART health is failing. (#471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A failing SMART self-assessment predicts imminent drive failure, so it deserves a prominent warning. useDriveHealth() reads the assessment already present in smart_stats (pySMART reports PASS / FAIL / null) and flags any drive whose assessment is FAIL. Nav.js renders a red warning icon in its own always-on slot — like the power warning, and unlike the single-slot priority chain where a transient high temp could hide it. Frontend-only: the assessment field is already in the cached payload. Co-authored-by: Claude Opus 4.8 (1M context) --- app/src/components/Nav.js | 16 ++++++++ app/src/hooks/customHooks.js | 12 ++++++ app/src/hooks/customHooks.test.js | 65 ++++++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/app/src/components/Nav.js b/app/src/components/Nav.js index 707c3300..4d936534 100644 --- a/app/src/components/Nav.js +++ b/app/src/components/Nav.js @@ -6,6 +6,7 @@ import {DarkModeToggle, HotspotStatusIcon, useLocalStorage} from "./Common"; import {ShareButton} from "./Share"; import { useCPUTemperature, + useDriveHealth, useDriveTemperature, useIOStats, useLoad, @@ -197,6 +198,20 @@ export function NavBar() { driveTemperatureIcon = ; } + // A drive's SMART self-assessment is failing — imminent drive failure. + // Always displayed (like power); too important to hide behind a transient + // warning in the priority chain. + const {failingDevices, failing: driveFailing} = useDriveHealth(); + let driveHealthIcon; + if (driveFailing) { + const icon = ; + const link = {icon}; + const message = failingDevices.length === 1 + ? `Drive ${failingDevices[0]} is failing its SMART health check! Back up your data.` + : `Drives failing SMART health check: ${failingDevices.join(', ')}. Back up your data.`; + driveHealthIcon = ; + } + // Power issues, this is always displayed if detected. const {underVoltage, overCurrent} = usePowerStats(); let powerIcon; @@ -274,6 +289,7 @@ export function NavBar() { {apiDownIcon} {processingIcon} {upgradeIcon} + {driveHealthIcon} {powerIcon} {warningIcon} diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js index 78777c56..76be6078 100644 --- a/app/src/hooks/customHooks.js +++ b/app/src/hooks/customHooks.js @@ -1357,6 +1357,18 @@ export const useDriveTemperature = () => { } } +// Reports drives whose SMART self-assessment is failing, so the navbar can +// warn of an imminent drive failure. pySMART reports 'PASS', 'FAIL', or null +// (unknown); only 'FAIL' is a problem. +export const useDriveHealth = () => { + const {status} = React.useContext(StatusContext); + const drives = Array.isArray(status?.smart_stats?.drives) ? status.smart_stats.drives : []; + const failingDevices = drives + .filter((d) => d.assessment === 'FAIL') + .map((d) => d.device); + return {failingDevices, failing: failingDevices.length > 0}; +} + export const useLoad = () => { const {status} = React.useContext(StatusContext); let minute_1 = status?.load_stats?.minute_1; diff --git a/app/src/hooks/customHooks.test.js b/app/src/hooks/customHooks.test.js index 96bd73f6..f8cb1f60 100644 --- a/app/src/hooks/customHooks.test.js +++ b/app/src/hooks/customHooks.test.js @@ -1,7 +1,7 @@ import React from 'react'; import {act, renderHook} from '@testing-library/react'; import {render, screen} from '@testing-library/react'; -import {usePages, useDriveTemperature} from './customHooks'; +import {usePages, useDriveTemperature, useDriveHealth} from './customHooks'; import {QueryContext, StatusContext} from '../contexts/contexts'; import {Paginator} from '../components/Common'; @@ -162,6 +162,69 @@ describe('useDriveTemperature', () => { }); }); +describe('useDriveHealth', () => { + const makeStatusWrapper = (status) => ({children}) => ( + + {children} + + ); + + test('flags drives whose SMART assessment is FAIL', () => { + const status = { + smart_stats: { + drives: [ + {device: 'sda', assessment: 'PASS'}, + {device: 'sdb', assessment: 'FAIL'}, + ], + }, + }; + const {result} = renderHook(() => useDriveHealth(), + {wrapper: makeStatusWrapper(status)}); + expect(result.current.failing).toBe(true); + expect(result.current.failingDevices).toEqual(['sdb']); + }); + + test('reports every failing drive', () => { + const status = { + smart_stats: { + drives: [ + {device: 'sda', assessment: 'FAIL'}, + {device: 'sdb', assessment: 'FAIL'}, + ], + }, + }; + const {result} = renderHook(() => useDriveHealth(), + {wrapper: makeStatusWrapper(status)}); + expect(result.current.failingDevices).toEqual(['sda', 'sdb']); + }); + + test('does not warn when all drives PASS', () => { + const status = { + smart_stats: {drives: [{device: 'sda', assessment: 'PASS'}]}, + }; + const {result} = renderHook(() => useDriveHealth(), + {wrapper: makeStatusWrapper(status)}); + expect(result.current.failing).toBe(false); + expect(result.current.failingDevices).toEqual([]); + }); + + test('ignores drives with an unknown (null) assessment', () => { + const status = { + smart_stats: {drives: [{device: 'sda', assessment: null}]}, + }; + const {result} = renderHook(() => useDriveHealth(), + {wrapper: makeStatusWrapper(status)}); + expect(result.current.failing).toBe(false); + }); + + test('does not warn when smart_stats is absent', () => { + const {result} = renderHook(() => useDriveHealth(), + {wrapper: makeStatusWrapper({})}); + expect(result.current.failing).toBe(false); + expect(result.current.failingDevices).toEqual([]); + }); +}); + describe('Paginator rendering', () => { test('renders exactly totalPages numbered page links (no phantom trailing link)', () => { // 48 results at 24 per page -> 2 pages. If totalPages is 3, semantic-ui