From aa90bd4dcd11c8a212cf341a67c8de6611d5198c Mon Sep 17 00:00:00 2001
From: mouldybread <38598858+mouldybread@users.noreply.github.com>
Date: Sat, 21 Nov 2026 10:06:58 +0800
Subject: [PATCH 1/2] Promote known recording failures into camera status
---
recording_intent_status_test.go | 116 +++++++++++++++++++-------------
templates/cameras.html | 9 +--
2 files changed, 75 insertions(+), 50 deletions(-)
diff --git a/recording_intent_status_test.go b/recording_intent_status_test.go
index d3b6962..36dffa4 100644
--- a/recording_intent_status_test.go
+++ b/recording_intent_status_test.go
@@ -1,52 +1,76 @@
package main
import (
- "bytes"
- "html/template"
- "strings"
- "testing"
+ "bytes"
+ "html/template"
+ "strings"
+ "testing"
)
-func TestCameraTemplateDescribesRecordingIntentNotHealth(t *testing.T) {
- tmpl, err := template.ParseFiles("templates/cameras.html")
- if err != nil {
- t.Fatal(err)
- }
- for _, tc := range []struct {
- name string
- enabled bool
- wantStatus string
- wantAction string
- absentAction string
- }{
- {"enabled", true, "Recording enabled", "Stop Recording", "Start Recording"},
- {"stopped", false, "Recording stopped", "Start Recording", "Stop Recording"},
- } {
- t.Run(tc.name, func(t *testing.T) {
- view := map[string]interface{}{
- "ID": "test", "Name": "Test camera", "RTSPUrl": "rtsp://example.invalid/live",
- "RecordDir": "/recordings/test", "DiskUsage": "0 B", "IsRecording": tc.enabled,
- "RecordingMode": ModeEventBased, "ModeDisplay": "Event Based", "RetentionDisplay": 7,
- }
- var out bytes.Buffer
- if err := tmpl.ExecuteTemplate(&out, "cameras.html", []map[string]interface{}{view}); err != nil {
- t.Fatal(err)
- }
- body := out.String()
- for _, want := range []string{
- ">" + tc.wantStatus + "",
- ">" + tc.wantAction + "",
- "Recording state reflects intent, not camera connectivity or successful footage capture.",
- } {
- if !strings.Contains(body, want) {
- t.Fatalf("rendered template missing %q", want)
- }
- }
- for _, absent := range []string{">Recording", ">Idle", ">" + tc.absentAction + ""} {
- if strings.Contains(body, absent) {
- t.Fatalf("rendered template retained unsupported status or action %q", absent)
- }
- }
- })
- }
+func TestCameraTemplateRecordingStatus(t *testing.T) {
+ tmpl,err:=template.ParseFiles("templates/cameras.html")
+ if err!=nil {t.Fatal(err)}
+ failure:=continuousRecordingNotice{Code:"upstream_rtsp_unavailable",Message:"Could not open upstream stream",Detail:"DESCRIBE 404",PublicationMessage:"Check recording storage",Retrying:true}
+ notRetrying:=failure;notRetrying.Retrying=false
+ for _,tc:=range []struct {
+ name string
+ enabled bool
+ mode RecordingMode
+ health continuousRecordingNotice
+ status,class string
+ failed bool
+ }{
+ {"continuous enabled",true,ModeContinuous,continuousRecordingNotice{},"Recording enabled","status-recording",false},
+ {"continuous failed retrying",true,ModeContinuous,failure,"Recording failed — retrying","status-failed recording",true},
+ {"continuous failed without retry claim",true,ModeContinuous,notRetrying,"Recording failed","status-failed recording",true},
+ {"stopped",false,ModeContinuous,continuousRecordingNotice{},"Recording stopped","status-idle",false},
+ {"stopped ignores stale failure",false,ModeContinuous,failure,"Recording stopped","status-idle",false},
+ {"event enabled unchanged",true,ModeEventBased,continuousRecordingNotice{},"Recording enabled","status-recording",false},
+ {"event ignores continuous failure",true,ModeEventBased,failure,"Recording enabled","status-recording",false},
+ {"no recording",false,ModeNoRecording,failure,"Recording stopped","status-idle",false},
+ } {t.Run(tc.name,func(t *testing.T){
+ view:=map[string]interface{}{
+ "ID":"test","Name":"Test camera","RTSPUrl":"rtsp://example.invalid/live",
+ "RecordDir":"/recordings/test","DiskUsage":"0 B","IsRecording":tc.enabled,
+ "RecordingMode":tc.mode,"ModeDisplay":string(tc.mode),"RetentionDisplay":7,"RecordingHealth":tc.health,
+ }
+ var out bytes.Buffer
+ if err:=tmpl.ExecuteTemplate(&out,"cameras.html",[]map[string]interface{}{view});err!=nil {t.Fatal(err)}
+ body:=out.String()
+ action,absentAction:="Start Recording","Stop Recording"
+ if tc.enabled {action,absentAction=absentAction,action}
+ for _,want:=range []string{`class="`+tc.class+`">`+tc.status+``,">"+action+""} {
+ if !strings.Contains(body,want) {t.Fatalf("missing %q in %s",want,body)}
+ }
+ for _,absent:=range []string{"Recording state reflects intent", "camera-status-explanation",">Recording",">Idle",">"+absentAction+""} {
+ if strings.Contains(body,absent) {t.Fatalf("unexpected %q",absent)}
+ }
+ if tc.failed {
+ for _,want:=range []string{"Recording setting: Enabled",tc.health.Message,tc.health.Detail,tc.health.PublicationMessage} {
+ if !strings.Contains(body,want) {t.Fatalf("missing failure context %q",want)}
+ }
+ if strings.Contains(body,">Recording enabled") {t.Fatal("failure masked by enabled primary status")}
+ } else {
+ for _,absent:=range []string{"Recording failed","camera-recording-error","Recording setting: Enabled"} {
+ if strings.Contains(body,absent) {t.Fatalf("unexpected failure context %q",absent)}
+ }
+ }
+ })}
+}
+
+func TestCameraTemplateRecordingRecoveryAndEscaping(t *testing.T) {
+ tmpl,err:=template.ParseFiles("templates/cameras.html");if err!=nil {t.Fatal(err)}
+ view:=map[string]interface{}{
+ "ID":"test","Name":"Test camera","RTSPUrl":"","RecordDir":"/recordings/test","DiskUsage":"0 B",
+ "IsRecording":true,"RecordingMode":ModeContinuous,"ModeDisplay":"Continuous","RetentionDisplay":7,
+ "RecordingHealth":continuousRecordingNotice{Code:"failed",Message:``,Detail:`
`,PublicationMessage:`