Files
shopdb-flask/tests/test_plugins/test_endpoints_disk_health.py
cproudlock 534f179ee6 Make main the lean product a site receives
main was 16 days and 259 commits behind the line the product is actually built
on, at contract 0.30.0 against 0.35.0, with no per-PC credential code at all. It
was neither current nor curated - just stale. This brings it forward and, at the
same time, makes it mean something: main is what a receiving site installs, and
nothing else.

WHAT IT CARRIES. Twelve plugins - backups, computers, endpoints, guides,
knowledgebase, machines, network, notifications, printers, slides, tools,
warranty - plus applications, which is manifest-less core and always ships. The
only manifest dependency inside that set is endpoints on computers, and both are
in it, so the closure is self-contained.

WHAT IT DOES NOT. employees, geenforce, measuringtools, printedparts and usb
stay on the site line. So do the Windows installer tree, the VM rehearsal
helpers, the agent tooling config, one site's data loader, the internal audit
and findings records, and the planner spreadsheet. 1,135 tracked files against
1,438.

A REMOVAL THAT BREAKS THE APP IS NOT A REMOVAL, and two nearly shipped:

deploy/site-profile-universal.json still named all seventeen plugins. It is the
file docs/DEPLOY.md tells a site to provision from, so a fresh install would
have failed at `flask plugin apply-profile` with PluginError - the first thing a
receiving site does, broken by the branch meant to serve them. It now names the
twelve that exist, and its comment says the two must agree.

agent/ was never refreshed. Whoever populated this branch copied shopdb/,
plugins/, frontend/ and tests/ from the site line and left the agent tree at its
September state: 22 C# and PowerShell sources missing, including AgentCredentials,
EnrollmentService, AgentHttpFactory and the fleet-alert client, plus one file the
site line had deleted still present. The old tree is internally consistent, so it
compiles, and nothing in CI builds it - every gate was green over a server that
speaks enrollment and per-PC credentials to a bundled agent source that cannot.
Resynced whole.

DECISIONS THIS ENCODES, rather than defers:

- The plugin-authoring lab builds printedparts, whose manifest depends on
  employees, so it could not stay. The lab remains on the site line and main
  ships no build-along tutorial. That is a real loss for an adopting developer
  and is recorded here rather than discovered later.
- Recognition, Training and Recertification notifications are no longer seeded.
  Each splits one notification into a card per employee and renders a photo,
  which needs a plugin this branch does not bundle. Seeding them would offer an
  author a type that cannot resolve anybody. A site that installs employees gets
  them from that plugin's own seed.
- Windows/IIS is documented as the legacy path throughout, and the README leads
  with Docker, because that is what a receiving site gets.

The API description is regenerated for THIS branch - 347 paths and 483
operations, down from 415 and 573 - so the published contract describes what is
here rather than what the site line serves. docs/CONFIG.md lost the two
measuring-tool label keys the code no longer declares, which two lanes had
decided opposite ways.

Suite: 3124 passed, 6 skipped. Naming and style gates pass. The docs gates run
rather than skip, and every index line count is derived from the file it names.
2026-09-19 11:24:40 -04:00

109 lines
3.7 KiB
Python

"""Disk health rows: a dying drive must never render as a healthy one.
The agent reports drive health from two sources because neither covers the
fleet. MSFT_PhysicalDisk is the only one that reports NVMe - verified on a
two-NVMe box where the classic ATA SMART class returned zero instances while
both drives were present and healthy. Win32_DiskDrive covers ATA/SATA and hosts
where the Storage namespace is missing.
That means the panel can receive the same physical drive twice, from sources
that may disagree, plus rows where health could not be read at all. Every test
here pins a way this card could start showing a failing or unreadable drive as
fine, which is the only failure mode that matters: nobody investigates a disk
that looks healthy.
"""
from plugins.endpoints.api.routes import _diskhealth_rows
def _drive(deviceid, predictfailure, healthstatus='Healthy',
source='physicaldisk', model='Samsung SSD'):
return {
'deviceid': deviceid,
'model': model,
'mediatype': 'SSD',
'bustype': 'NVMe',
'healthstatus': healthstatus,
'predictfailure': predictfailure,
'source': source,
}
def test_a_failing_drive_sorts_above_healthy_ones():
"""On a multi-disk box the bad drive must not be below the fold."""
rows = _diskhealth_rows([
_drive('0', False),
_drive('1', True, healthstatus='Unhealthy'),
_drive('2', False),
])
assert [row['deviceid'] for row in rows] == ['1', '0', '2']
assert rows[0]['verdict'] == 'Failure predicted'
def test_a_drive_that_did_not_answer_reads_as_unknown_not_ok():
"""Null predictfailure is an unread drive, not a healthy one."""
rows = _diskhealth_rows([_drive('0', None, healthstatus='')])
assert rows[0]['verdict'] == 'Unknown'
assert rows[0]['healthstatus'] == 'Unknown'
def test_unknown_outranks_ok_so_silence_is_not_buried_under_health():
"""A drive that stopped answering is a weaker claim than one saying OK."""
rows = _diskhealth_rows([
_drive('0', False),
_drive('1', None),
])
assert [row['verdict'] for row in rows] == ['Unknown', 'OK']
def test_both_sources_survive_for_the_same_hardware():
"""Two disagreeing views of one drive is the signal, not noise.
Collapsing them would hide the case worth looking at: one source calling a
drive healthy while the other predicts failure.
"""
rows = _diskhealth_rows([
_drive('0', False, source='physicaldisk'),
_drive('0', True, healthstatus='Pred Fail', source='diskdrive'),
])
assert len(rows) == 2
assert {row['source'] for row in rows} == {'physicaldisk', 'diskdrive'}
assert rows[0]['verdict'] == 'Failure predicted'
def test_input_order_does_not_change_which_drive_is_shown_first():
"""The verdict ranking must decide the order, not arrival order."""
healthy = _drive('0', False)
failing = _drive('1', True)
forward = _diskhealth_rows([healthy, failing])
backward = _diskhealth_rows([failing, healthy])
assert forward == backward
assert forward[0]['deviceid'] == '1'
def test_an_nvme_drive_is_reported_rather_than_dropped():
"""The whole reason for the second source: ATA SMART returns nothing here."""
rows = _diskhealth_rows([_drive('0', False, source='physicaldisk')])
assert rows[0]['bustype'] == 'NVMe'
assert rows[0]['verdict'] == 'OK'
def test_a_malformed_payload_does_not_take_the_panel_down():
rows = _diskhealth_rows([_drive('0', False), 'not a dict', None])
assert len(rows) == 1
assert rows[0]['deviceid'] == '0'
def test_a_missing_or_wrong_shaped_payload_is_an_empty_panel():
assert _diskhealth_rows(None) == []
assert _diskhealth_rows({}) == []
assert _diskhealth_rows([]) == []