fix(platform): make firmware_count mean what rom_count means

firmware_count skipped rows flagged as missing while its sibling
rom_count counted every row, so the two fields answered the same
question differently.

Count every firmware row instead, and filter for usable BIOS in the
InfoPanel that presents the stat. The firmware list ships with the
schema, so the caller already has what it needs to decide.

rom_count keeps counting missing ROMs on purpose: the gallery and nav
gate on rom_count > 0, so excluding them would hide the platforms whose
missing ROMs still need cleaning up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-08-29 15:57:05 -04:00
parent 841a7a2f9f
commit 24f1d4b44e
4 changed files with 16 additions and 14 deletions

View File

@@ -46,12 +46,13 @@ class PlatformSchema(BaseModel):
def display_name(self) -> str:
return self.custom_name or self.name
# Missing entries stay in `firmware` so they can be cleaned up, but they
# aren't usable BIOS, so they don't count.
# Counts every row, missing ones included, so it means the same as
# `rom_count`. Callers that want only usable BIOS filter `firmware`,
# which ships with this schema.
@computed_field # type: ignore
@property
def firmware_count(self) -> int:
return len([f for f in self.firmware if not f.missing_from_fs])
return len(self.firmware)
@field_validator("firmware")
def sort_files(cls, v: list[FirmwareSchema]) -> list[FirmwareSchema]:

View File

@@ -178,11 +178,12 @@ def test_update_platform_description_requires_write_scope(client, platform):
assert response.status_code == status.HTTP_401_UNAUTHORIZED
def test_firmware_count_excludes_missing_firmware(
def test_firmware_count_matches_the_rows_it_ships(
client, access_token, platform, firmware, missing_firmware
):
"""A platform whose only BIOS file was deleted from disk shouldn't still
advertise it (issue #4075)."""
"""`firmware_count` means the same as `rom_count`: every row, missing
ones included. Deciding what counts as usable BIOS is the caller's job,
and the rows ship alongside the count so it can."""
response = client.get(
f"/api/platforms/{platform.id}",
headers={"Authorization": f"Bearer {access_token}"},
@@ -190,7 +191,6 @@ def test_firmware_count_excludes_missing_firmware(
assert response.status_code == status.HTTP_200_OK
body = response.json()
assert body["firmware_count"] == 1
# The rows themselves still ship so the Firmware tab can strike them
# through and offer a cleanup.
assert body["firmware_count"] == 2
assert len(body["firmware"]) == 2
assert sum(1 for f in body["firmware"] if f["missing_from_fs"]) == 1

View File

@@ -168,13 +168,12 @@ function onDeleted(deletedIds: number[]) {
// `firmware_count` is a readonly derived field on PlatformSchema —
// patched locally so the InfoPanel stat reacts instantly; a future
// refetch reconciles. It counts only firmware present on disk, matching
// what the server derives.
// refetch reconciles.
function syncFirmware(next: FirmwareSchema[]) {
const updated: Platform = {
...props.platform,
firmware: next,
firmware_count: next.filter((f) => !f.missing_from_fs).length,
firmware_count: next.length,
};
platformsStore.update(updated);
if (galleryRoms.currentPlatform?.id === updated.id) {

View File

@@ -139,10 +139,12 @@ const platformStats = computed<StatRow[]>(() => {
},
{ label: t("platform.on-disk"), value: formatBytes(p.fs_size_bytes ?? 0) },
];
if (p.firmware_count) {
// Firmware whose file is gone can't be booted, so it isn't worth a stat.
const usableFirmware = (p.firmware ?? []).filter((f) => !f.missing_from_fs);
if (usableFirmware.length) {
rows.push({
label: t("common.firmware"),
value: String(p.firmware_count),
value: String(usableFirmware.length),
});
}
return rows;