From 24f1d4b44e2b6fa36fcd13f85f2fdda42731e31b Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 29 Aug 2026 15:57:05 -0400 Subject: [PATCH] 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) --- backend/endpoints/responses/platform.py | 7 ++++--- backend/tests/endpoints/test_platform.py | 12 ++++++------ frontend/src/v2/components/Gallery/FirmwareTab.vue | 5 ++--- frontend/src/v2/views/Gallery/Platform.vue | 6 ++++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/backend/endpoints/responses/platform.py b/backend/endpoints/responses/platform.py index 44cd42326..42fdb72de 100644 --- a/backend/endpoints/responses/platform.py +++ b/backend/endpoints/responses/platform.py @@ -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]: diff --git a/backend/tests/endpoints/test_platform.py b/backend/tests/endpoints/test_platform.py index 12a858c44..86f6f376c 100644 --- a/backend/tests/endpoints/test_platform.py +++ b/backend/tests/endpoints/test_platform.py @@ -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 diff --git a/frontend/src/v2/components/Gallery/FirmwareTab.vue b/frontend/src/v2/components/Gallery/FirmwareTab.vue index 2296c681d..2cc26bd1e 100644 --- a/frontend/src/v2/components/Gallery/FirmwareTab.vue +++ b/frontend/src/v2/components/Gallery/FirmwareTab.vue @@ -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) { diff --git a/frontend/src/v2/views/Gallery/Platform.vue b/frontend/src/v2/views/Gallery/Platform.vue index c550f5b9e..01053bf5d 100644 --- a/frontend/src/v2/views/Gallery/Platform.vue +++ b/frontend/src/v2/views/Gallery/Platform.vue @@ -139,10 +139,12 @@ const platformStats = computed(() => { }, { 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;