From 67db47f00e20f5643bcab1cfd410d621bc10a7b2 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Sun, 8 Nov 2026 11:31:31 +0100 Subject: [PATCH 1/2] fix(web): suppress error notifications for missing details --- skills/detail-route-not-found/SKILL.md | 25 +++++++++++++++ .../Components/Pages/AgentDetail.razor | 4 +++ .../Components/Pages/CameraDetail.razor | 15 ++++++--- .../Components/Pages/PersonDetailPage.razor | 13 ++++++-- .../Components/Pages/AgentDetailTests.cs | 31 +++++++++++++++++++ .../Components/Pages/CameraDetailTests.cs | 16 ++++++++++ .../Components/Pages/PersonDetailPageTests.cs | 10 +++--- 7 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 skills/detail-route-not-found/SKILL.md diff --git a/skills/detail-route-not-found/SKILL.md b/skills/detail-route-not-found/SKILL.md new file mode 100644 index 0000000..c706e5b --- /dev/null +++ b/skills/detail-route-not-found/SKILL.md @@ -0,0 +1,25 @@ +--- +name: detail-route-not-found +description: Keep Heimdall detail pages consistent when an API object no longer exists. +--- + +# Missing objects on detail routes + +Use this workflow when a detail page already has an explicit “not found” state and an API read can return HTTP 404. Current routes covered are Agent (`AgentDetail.razor`), Camera (`CameraDetail.razor`), and Person (`PersonDetailPage.razor`). + +## Implementation + +- Keep the API client's normal `GetFromJsonAsync` behavior. A 404 raises `HttpRequestException` with `StatusCode == NotFound`; catch only that status in the initial detail load and leave the model null so the existing empty/not-found rendering appears. +- Preserve the generic error notification for all other failures. Do not treat unauthorized, server, timeout, or malformed-response errors as “not found”. +- Do not fetch dependent page data after the primary object is absent. In particular, Camera must not load events, recordings, snapshots, or start periodic refresh, and Person must not load faces, vehicles, or events. +- Keep authorization and API responses unchanged. The UI behavior handles stale links and objects deleted between navigation and load. + +## Acceptance + +1. Add a component test for each route with a synthetic UUID and an HTTP 404 response. +2. Assert the existing not-found state is rendered, no snackbar is shown, and no dependent API call is made. +3. Retain or add an unexpected HTTP failure check proving the generic notification still appears. +4. Run the focused Web tests and Web build. +5. Run the disposable Compose recipe from `skills/compose-disposable-recipe/SKILL.md`; verify all three routes through the app boundary using isolated synthetic data and record exact project/image cleanup evidence. + +The route-level checks require an authenticated synthetic account. Do not create or retain real people, cameras, Agents, or camera connection data for acceptance. diff --git a/src/Heimdall.Web/Components/Pages/AgentDetail.razor b/src/Heimdall.Web/Components/Pages/AgentDetail.razor index 9e731af..3ed2667 100644 --- a/src/Heimdall.Web/Components/Pages/AgentDetail.razor +++ b/src/Heimdall.Web/Components/Pages/AgentDetail.razor @@ -902,6 +902,10 @@ else _ = LoadUpdateInfoAsync(); } } + catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound) + { + // Un agent absent est rendu comme un état introuvable, pas comme une erreur inattendue. + } catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); } finally { _loading = false; } } diff --git a/src/Heimdall.Web/Components/Pages/CameraDetail.razor b/src/Heimdall.Web/Components/Pages/CameraDetail.razor index ff259ae..b50867c 100644 --- a/src/Heimdall.Web/Components/Pages/CameraDetail.razor +++ b/src/Heimdall.Web/Components/Pages/CameraDetail.razor @@ -372,12 +372,19 @@ else _eventRecordingEnabled = _camera.EventRecordingEnabled; } } + catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound) + { + // La vue dédiée affiche l'état introuvable pour une caméra supprimée ou inconnue. + } catch { Snackbar.Add(Text["CameraDetail_OperationFailed"], Severity.Error); } finally { _loading = false; } - await LoadEventsAsync(); - await LoadRecordingsAsync(); - await LoadLatestSnapshotAsync(); + if (_camera is not null) + { + await LoadEventsAsync(); + await LoadRecordingsAsync(); + await LoadLatestSnapshotAsync(); + } } private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged); @@ -389,7 +396,7 @@ else protected override async Task OnAfterRenderAsync(bool firstRender) { - if (firstRender && !_autoRefreshStarted) + if (firstRender && !_autoRefreshStarted && _camera is not null) { _autoRefreshStarted = true; await StartAutoRefresh(); diff --git a/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor b/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor index b767198..f5272c8 100644 --- a/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor +++ b/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor @@ -309,12 +309,19 @@ else { _person = await Api.GetPersonAsync(Id); } + catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound) + { + // La vue dédiée affiche l'état introuvable sans lancer les lectures associées. + } catch { Snackbar.Add(Text["PersonDetailPage_OperationFailed"], Severity.Error); } finally { _loading = false; } - await LoadFaces(); - await LoadVehicles(); - await LoadEvents(); + if (_person is not null) + { + await LoadFaces(); + await LoadVehicles(); + await LoadEvents(); + } } private async Task LoadFaces() diff --git a/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs index 84da926..64f8409 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs @@ -13,6 +13,37 @@ public class AgentDetailTests : PageTestBase { private static readonly Guid AgentId = Guid.NewGuid(); + [Fact] + public void AgentDetail_AgentIntrouvable_NAffichePasDErreur() + { + Handler.OnGet($"api/agents/{AgentId}", System.Net.HttpStatusCode.NotFound); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, AgentId)); + + cut.WaitForAssertion(() => + { + cut.Markup.ShouldContain("introuvable"); + Services.GetRequiredService().ShownSnackbars.ShouldBeEmpty(); + Handler.Requests.ShouldHaveSingleItem(); + }); + } + + [Fact] + public void AgentDetail_ErreurServeur_AfficheSnackbarErreur() + { + Handler.OnGet($"api/agents/{AgentId}", System.Net.HttpStatusCode.InternalServerError); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, AgentId)); + + cut.WaitForAssertion(() => + { + cut.Markup.ShouldContain("introuvable"); + Services.GetRequiredService().ShownSnackbars.ShouldNotBeEmpty(); + }); + } + private static AgentItem Agent() => new() { Id = AgentId, diff --git a/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs index f2cae1e..09faf78 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs @@ -28,6 +28,22 @@ public class CameraDetailTests : PageTestBase private void HandlerCamera(CameraItem camera) => Handler.OnGet("api/cameras/", camera); + [Fact] + public void CameraDetail_CameraIntrouvable_NAffichePasDErreurEtNeChargePasLesDetails() + { + Handler.OnGet("api/cameras/", System.Net.HttpStatusCode.NotFound); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, CameraId)); + + cut.WaitForAssertion(() => + { + cut.Markup.ShouldContain("introuvable"); + Services.GetRequiredService().ShownSnackbars.ShouldBeEmpty(); + Handler.Requests.ShouldHaveSingleItem(); + }); + } + [Fact] public async Task PlateAssociationConfirmation_PostsCameraPlateEventAndVehicleIds() { diff --git a/tests/Heimdall.Web.Tests/Components/Pages/PersonDetailPageTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/PersonDetailPageTests.cs index d20efbc..b5ae75d 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/PersonDetailPageTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/PersonDetailPageTests.cs @@ -98,14 +98,16 @@ public class PersonDetailPageTests : PageTestBase public void PersonDetail_PersonneIntrouvable_AfficheAlerte() { Handler.OnGet("api/persons/", System.Net.HttpStatusCode.NotFound); - Handler.OnGet($"api/persons/{PersonId}/faces", new List()); - Handler.OnGet("api/vehicles", new List()); - Handler.OnGet("api/events", new EventPageResult([], 0, 1, 50)); LoginAs(); var cut = RenderPage(p => p.Add(x => x.Id, PersonId)); - cut.WaitForAssertion(() => cut.Markup.ShouldContain("Personne introuvable")); + cut.WaitForAssertion(() => + { + cut.Markup.ShouldContain("Personne introuvable"); + Services.GetRequiredService().ShownSnackbars.ShouldBeEmpty(); + Handler.Requests.ShouldHaveSingleItem(); + }); } [Fact] -- 2.54.1 From bbb003edb771f2910eff4f4141b486e9b8e0b080 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Sun, 8 Nov 2026 12:22:02 +0100 Subject: [PATCH 2/2] fix(web): handle masked resources as missing details --- skills/detail-route-not-found/SKILL.md | 6 +++--- src/Heimdall.Web/Components/Pages/AgentDetail.razor | 7 +++++-- src/Heimdall.Web/Components/Pages/CameraDetail.razor | 7 +++++-- .../Components/Pages/AgentDetailTests.cs | 3 ++- .../Components/Pages/CameraDetailTests.cs | 3 ++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/skills/detail-route-not-found/SKILL.md b/skills/detail-route-not-found/SKILL.md index c706e5b..ecee02f 100644 --- a/skills/detail-route-not-found/SKILL.md +++ b/skills/detail-route-not-found/SKILL.md @@ -9,14 +9,14 @@ Use this workflow when a detail page already has an explicit “not found” sta ## Implementation -- Keep the API client's normal `GetFromJsonAsync` behavior. A 404 raises `HttpRequestException` with `StatusCode == NotFound`; catch only that status in the initial detail load and leave the model null so the existing empty/not-found rendering appears. -- Preserve the generic error notification for all other failures. Do not treat unauthorized, server, timeout, or malformed-response errors as “not found”. +- Keep the API client's normal `GetFromJsonAsync` behavior. A 404 raises `HttpRequestException` with `StatusCode == NotFound`. Agent and Camera resource-boundary checks intentionally return 403 for missing or out-of-scope records; treat that expected privacy response like the existing not-found rendering too. Person reads use 404. +- Preserve the generic error notification for unexpected failures. Do not treat 401, server, timeout, or malformed-response errors as “not found”. - Do not fetch dependent page data after the primary object is absent. In particular, Camera must not load events, recordings, snapshots, or start periodic refresh, and Person must not load faces, vehicles, or events. - Keep authorization and API responses unchanged. The UI behavior handles stale links and objects deleted between navigation and load. ## Acceptance -1. Add a component test for each route with a synthetic UUID and an HTTP 404 response. +1. Add a component test for each route with a synthetic UUID and its expected hidden/missing response (Agent/Camera 403, Person 404). 2. Assert the existing not-found state is rendered, no snackbar is shown, and no dependent API call is made. 3. Retain or add an unexpected HTTP failure check proving the generic notification still appears. 4. Run the focused Web tests and Web build. diff --git a/src/Heimdall.Web/Components/Pages/AgentDetail.razor b/src/Heimdall.Web/Components/Pages/AgentDetail.razor index 3ed2667..81c3faa 100644 --- a/src/Heimdall.Web/Components/Pages/AgentDetail.razor +++ b/src/Heimdall.Web/Components/Pages/AgentDetail.razor @@ -902,14 +902,17 @@ else _ = LoadUpdateInfoAsync(); } } - catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound) + catch (HttpRequestException ex) when (IsMissingOrHiddenResource(ex)) { - // Un agent absent est rendu comme un état introuvable, pas comme une erreur inattendue. + // Le filtre d'accès renvoie 403 pour masquer un agent absent ou non accessible. } catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); } finally { _loading = false; } } + private static bool IsMissingOrHiddenResource(HttpRequestException exception) => + exception.StatusCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden; + private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged); private async Task LoadMetricHistoryAsync(string range) diff --git a/src/Heimdall.Web/Components/Pages/CameraDetail.razor b/src/Heimdall.Web/Components/Pages/CameraDetail.razor index b50867c..1110c07 100644 --- a/src/Heimdall.Web/Components/Pages/CameraDetail.razor +++ b/src/Heimdall.Web/Components/Pages/CameraDetail.razor @@ -372,9 +372,9 @@ else _eventRecordingEnabled = _camera.EventRecordingEnabled; } } - catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound) + catch (HttpRequestException ex) when (IsMissingOrHiddenResource(ex)) { - // La vue dédiée affiche l'état introuvable pour une caméra supprimée ou inconnue. + // Le filtre d'accès renvoie 403 pour masquer une caméra absente ou non accessible. } catch { Snackbar.Add(Text["CameraDetail_OperationFailed"], Severity.Error); } finally { _loading = false; } @@ -387,6 +387,9 @@ else } } + private static bool IsMissingOrHiddenResource(HttpRequestException exception) => + exception.StatusCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden; + private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged); // L'auto-refresh démarre après le premier rendu : une boucle infinie diff --git a/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs index 64f8409..c1efe9e 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/AgentDetailTests.cs @@ -16,7 +16,8 @@ public class AgentDetailTests : PageTestBase [Fact] public void AgentDetail_AgentIntrouvable_NAffichePasDErreur() { - Handler.OnGet($"api/agents/{AgentId}", System.Net.HttpStatusCode.NotFound); + // ResourceAccessFilter deliberately returns 403 to hide missing agents. + Handler.OnGet($"api/agents/{AgentId}", System.Net.HttpStatusCode.Forbidden); LoginAs(); var cut = RenderPage(p => p.Add(x => x.Id, AgentId)); diff --git a/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs index 09faf78..63e7ddd 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/CameraDetailTests.cs @@ -31,7 +31,8 @@ public class CameraDetailTests : PageTestBase [Fact] public void CameraDetail_CameraIntrouvable_NAffichePasDErreurEtNeChargePasLesDetails() { - Handler.OnGet("api/cameras/", System.Net.HttpStatusCode.NotFound); + // ResourceAccessFilter deliberately returns 403 to hide missing cameras. + Handler.OnGet("api/cameras/", System.Net.HttpStatusCode.Forbidden); LoginAs(); var cut = RenderPage(p => p.Add(x => x.Id, CameraId)); -- 2.54.1