mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 10:08:40 +01:00
fix(tasks): describe the cleanup stats a finished job actually carries
`GET /tasks/status` failed response validation once a missing-ROMs cleanup had run: the task reports `platform_ids` while the schema still declared `platform_id`, and the missing-firmware cleanup had no schema at all. Both shapes are declared now, the generated types follow, and the task-by-id test checks a finished job of each kind. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9ta8rXUTP9aMdatPYKX4K
This commit is contained in:
@@ -53,13 +53,24 @@ class OrphanedResourcesCleanupStats(TypedDict):
|
||||
|
||||
|
||||
class MissingRomsCleanupStats(TypedDict):
|
||||
platform_id: int | None
|
||||
platform_ids: list[int] | None
|
||||
roms_found: int
|
||||
roms_deleted: int
|
||||
errors: int
|
||||
|
||||
|
||||
CleanupStats = Union[OrphanedResourcesCleanupStats, MissingRomsCleanupStats]
|
||||
class MissingFirmwareCleanupStats(TypedDict):
|
||||
platform_ids: list[int] | None
|
||||
firmware_found: int
|
||||
firmware_deleted: int
|
||||
errors: int
|
||||
|
||||
|
||||
CleanupStats = Union[
|
||||
OrphanedResourcesCleanupStats,
|
||||
MissingRomsCleanupStats,
|
||||
MissingFirmwareCleanupStats,
|
||||
]
|
||||
|
||||
|
||||
class CleanupTaskMeta(TypedDict):
|
||||
|
||||
@@ -6,6 +6,8 @@ from fastapi import status
|
||||
from rq.exceptions import NoSuchJobError
|
||||
|
||||
from handler.redis_handler import redis_client
|
||||
from tasks.manual.cleanup_missing_firmware import CleanupMissingFirmwareStats
|
||||
from tasks.manual.cleanup_missing_roms import CleanupMissingRomsStats
|
||||
from tasks.tasks import Task, TaskType
|
||||
|
||||
|
||||
@@ -411,6 +413,41 @@ class TestGetTasksStatus:
|
||||
class TestGetTaskById:
|
||||
"""Test suite for the get_task_by_id endpoint"""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"stats",
|
||||
[
|
||||
CleanupMissingRomsStats(platform_ids=[3], roms_found=2, roms_deleted=2),
|
||||
CleanupMissingFirmwareStats(firmware_found=1, firmware_deleted=1),
|
||||
],
|
||||
)
|
||||
@patch("endpoints.tasks.Job.fetch")
|
||||
def test_a_finished_cleanup_reports_its_stats(
|
||||
self, mock_job_fetch, client, access_token, stats
|
||||
):
|
||||
mock_job = Mock()
|
||||
for field in ("enqueued_at", "created_at", "started_at", "ended_at"):
|
||||
setattr(mock_job, field, Mock())
|
||||
getattr(mock_job, field).isoformat.return_value = "2023-01-01T00:00:00"
|
||||
mock_job.get_meta.return_value = {
|
||||
"task_key": "cleanup_missing_roms",
|
||||
"task_type": TaskType.CLEANUP,
|
||||
"cleanup_stats": stats.to_dict(),
|
||||
}
|
||||
mock_job.func_name = "tasks.tasks.run_task_by_name"
|
||||
mock_job.kwargs = {"name": "cleanup_missing_roms"}
|
||||
mock_job.get_status.return_value = "finished"
|
||||
mock_job.id = "cleanup-job"
|
||||
mock_job.result = stats.to_dict()
|
||||
mock_job_fetch.return_value = mock_job
|
||||
|
||||
response = client.get(
|
||||
"/api/tasks/cleanup-job",
|
||||
headers={"Authorization": f"Bearer {access_token}"},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["meta"]["cleanup_stats"] == stats.to_dict()
|
||||
|
||||
@patch("endpoints.tasks.Job.fetch")
|
||||
def test_get_task_by_id_success(self, mock_job_fetch, client, access_token):
|
||||
"""Test successful retrieval of a task by job ID"""
|
||||
|
||||
1
frontend/src/__generated__/index.ts
generated
1
frontend/src/__generated__/index.ts
generated
@@ -130,6 +130,7 @@ export type { MemoryCardVersionSchema } from './models/MemoryCardVersionSchema';
|
||||
export type { MetadataCoverageItem } from './models/MetadataCoverageItem';
|
||||
export type { MetadataMediaType } from './models/MetadataMediaType';
|
||||
export type { MetadataSourcesDict } from './models/MetadataSourcesDict';
|
||||
export type { MissingFirmwareCleanupStats } from './models/MissingFirmwareCleanupStats';
|
||||
export type { MissingRomsCleanupStats } from './models/MissingRomsCleanupStats';
|
||||
export type { MobyMetadataPlatform } from './models/MobyMetadataPlatform';
|
||||
export type { MusicGameFacetSchema } from './models/MusicGameFacetSchema';
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { MissingFirmwareCleanupStats } from './MissingFirmwareCleanupStats';
|
||||
import type { MissingRomsCleanupStats } from './MissingRomsCleanupStats';
|
||||
import type { OrphanedResourcesCleanupStats } from './OrphanedResourcesCleanupStats';
|
||||
export type CleanupTaskMeta = {
|
||||
cleanup_stats: (OrphanedResourcesCleanupStats | MissingRomsCleanupStats | null);
|
||||
cleanup_stats: (OrphanedResourcesCleanupStats | MissingRomsCleanupStats | MissingFirmwareCleanupStats | null);
|
||||
};
|
||||
|
||||
|
||||
11
frontend/src/__generated__/models/MissingFirmwareCleanupStats.ts
generated
Normal file
11
frontend/src/__generated__/models/MissingFirmwareCleanupStats.ts
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
/* generated using openapi-typescript-codegen -- do not edit */
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export type MissingFirmwareCleanupStats = {
|
||||
platform_ids: (Array<number> | null);
|
||||
firmware_found: number;
|
||||
firmware_deleted: number;
|
||||
errors: number;
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export type MissingRomsCleanupStats = {
|
||||
platform_id: (number | null);
|
||||
platform_ids: (Array<number> | null);
|
||||
roms_found: number;
|
||||
roms_deleted: number;
|
||||
errors: number;
|
||||
|
||||
Reference in New Issue
Block a user