843b319f35
gates / gates (push) Successful in 14s
MinAgent: 0.131.0 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
78 lines
3.6 KiB
Go
78 lines
3.6 KiB
Go
package web
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/agentapi"
|
|
)
|
|
|
|
// R-517 — the whole-guest tile speaks from SUCCESSES per tier. The BIGNIGHT page read, after a local
|
|
// success and a failed PBS attempt on absent storage: "✗ · 0 B · PBS · Naprakész" and ticked
|
|
// "Távoli rendszermentés — külön hardveren".
|
|
|
|
var tvNow = time.Date(2026, 9, 14, 19, 15, 36, 0, time.UTC)
|
|
|
|
// RED-PROOF (run 2026-09-15, recorded in REPORT.md): with buildTierViews reading a tier's "success"
|
|
// from LastAttempt instead of LastSuccess, the shown backup lost its size and this failed at "the
|
|
// successful local backup is not the one shown: has=true size=0".
|
|
func TestBuildTierViews_BignightFailedPBSOnAbsentStorage(t *testing.T) {
|
|
v := &guestBackupView{}
|
|
tiers := []agentapi.TierBackupState{
|
|
{Target: "local", Primary: true, Storage: "present",
|
|
LastSuccess: &agentapi.BackupRecord{TargetID: "local", Success: true, SizeBytes: 8877619753, StartedAt: "2026-09-14T19:03:23Z"},
|
|
LastAttempt: &agentapi.TierAttempt{StartedAt: "2026-09-14T19:03:23Z", Success: true}},
|
|
{Target: "felhom-pbs", Storage: "absent",
|
|
LastAttempt: &agentapi.TierAttempt{StartedAt: "2026-09-14T19:09:59Z", Success: false, Error: "storage 'felhom-pbs' does not exist"}},
|
|
}
|
|
buildTierViews(v, tiers, map[string]int64{"local": 86400, "felhom-pbs": 604800}, tvNow)
|
|
|
|
if v.Offsite {
|
|
t.Fatalf("remote tick shown without a PBS success: %+v", v.Tiers)
|
|
}
|
|
if !v.HasBackup || v.SizeBytes != 8877619753 || v.Target != "Helyi tároló (local)" {
|
|
t.Fatalf("the successful local backup is not the one shown: has=%v size=%d target=%q", v.HasBackup, v.SizeBytes, v.Target)
|
|
}
|
|
if v.Due {
|
|
t.Fatalf("a current local success with an unprovisioned PBS tier must read up to date, got Due")
|
|
}
|
|
pbs := v.Tiers[1]
|
|
if !pbs.NotSetUp || pbs.HasSuccess || !pbs.FailedAfter {
|
|
t.Fatalf("pbs row wrong (want not set up, no success, failed attempt shown): %+v", pbs)
|
|
}
|
|
}
|
|
|
|
// A set-up PBS tier whose last attempt failed: ✗ under the last success, and not current if the
|
|
// success is outside the window → Due, no remote tick.
|
|
func TestBuildTierViews_PBSFailedUnderOldSuccess(t *testing.T) {
|
|
v := &guestBackupView{}
|
|
tiers := []agentapi.TierBackupState{
|
|
{Target: "local", Primary: true, Storage: "present",
|
|
LastSuccess: &agentapi.BackupRecord{Success: true, SizeBytes: 10, StartedAt: "2026-09-14T01:00:00Z"}},
|
|
{Target: "felhom-pbs", Storage: "present",
|
|
LastSuccess: &agentapi.BackupRecord{Success: true, SizeBytes: 20, StartedAt: "2026-08-20T01:00:00Z"},
|
|
LastAttempt: &agentapi.TierAttempt{StartedAt: "2026-09-14T02:00:00Z", Success: false}},
|
|
}
|
|
buildTierViews(v, tiers, map[string]int64{"local": 86400, "felhom-pbs": 604800}, tvNow)
|
|
pbs := v.Tiers[1]
|
|
if !pbs.HasSuccess || !pbs.FailedAfter || pbs.Current {
|
|
t.Fatalf("pbs row: want old success kept, failure shown under it, not current: %+v", pbs)
|
|
}
|
|
if v.Offsite || !v.Due {
|
|
t.Fatalf("want no remote tick and Due, got Offsite=%v Due=%v", v.Offsite, v.Due)
|
|
}
|
|
}
|
|
|
|
// After an agent restart the success is read back from storage: shown, size unknown.
|
|
func TestBuildTierViews_SuccessFromStorageAfterRestart(t *testing.T) {
|
|
v := &guestBackupView{}
|
|
tiers := []agentapi.TierBackupState{
|
|
{Target: "local", Primary: true, Storage: "present", LastSuccessSource: "storage",
|
|
LastSuccess: &agentapi.BackupRecord{Success: true, StartedAt: "2026-09-14T19:03:23Z"}},
|
|
}
|
|
buildTierViews(v, tiers, map[string]int64{"local": 86400}, tvNow)
|
|
if !v.HasBackup || v.Due || v.Tiers[0].SizeKnown {
|
|
t.Fatalf("after restart: want the local success shown, up to date, size unknown: %+v / due=%v", v.Tiers[0], v.Due)
|
|
}
|
|
}
|