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;