The off-site copies of a removed app end 30 days after „delete backup data” — the box's half (felhom.eu R-1374 part 1; D72, D84)
gates / gates (push) Successful in 41s

Built, not released; no box has run it. felhom.eu `07-backup-architecture.md` §8.2f.
It does nothing without a hub that knows it: an older hub agrees to no id.

- The record: settings `offsite_ends` {app, removed_at, ends_at}. One writer
  (backup.StartOffsiteEnd), called by a removal only with „delete backup data”
  and by „Törlés 30 nap múlva” on the restore page. A second press changes
  nothing. No record, no deletion. Only on the hub-provisioned tier.
- The date is on the remove dialog before the press; the restore page shows
  „Törlésre kijelölve …” with „Mégis megtartom”, and one history line per
  carried-out end. An install of the same app deletes the record.
- The weekly window: after the guard has passed the policy's plan under the cap
  as before, it adds the snapshots whose app tags are ALL due records, that the
  hub agreed to and the box named in the same request; the result names them
  apart (removed_for_ended_apps). `_shares`, the box's own stacks and an
  installed app are never due.
- The report carries the pending records; the household gets one mail per
  press (offsite_end_scheduled), in both languages.

MinAgent unchanged (0.158.1). 143 parity fixtures gained the dialog's one new
script line (patched, not regenerated); one new parity case.
Tests TestD72_*, TestD84_*; 56 mutations seen red
(felhom.eu documentation/audits/build-release-4-2026-11-15/A/redproof-ctrl-*.txt).

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 14:09:47 +01:00
1 parent 591195fadd
commit f628cb5082
177 files changed
+3705 -164

No files matched your search

@@ -0,0 +1,155 @@
package settings
import (
"io"
"log"
"path/filepath"
"testing"
"time"
)
// D72 / D84 (`09` §3 decisions 292, 309; `07-backup-architecture.md` §8.2f part 1): the off-site end record.
// RED-PROOFS: felhom.eu/documentation/audits/build-release-4-2026-11-15/A/redproof-ctrl-record.txt.
func endsSettings(t *testing.T) (*Settings, string) {
t.Helper()
p := filepath.Join(t.TempDir(), "settings.json")
s, err := Load(p, log.New(io.Discard, "", 0))
if err != nil {
t.Fatal(err)
}
return s, p
}
// The record: removed_at is the press, ends_at is 30 days later, and it is on DISK — a controller restart reads it
// back. (A record that lives only in memory would be lost at the next update, and the copies would stay for ever.)
func TestD72_EndRecord_IsWrittenAndSurvivesARestart(t *testing.T) {
s, path := endsSettings(t)
press := time.Date(2026, 11, 15, 10, 30, 0, 0, time.UTC)
rec, created, err := s.StartOffsiteEnd("vikunja", press)
if err != nil || !created {
t.Fatalf("created=%v err=%v", created, err)
}
if rec.RemovedAt != "2026-11-15T10:30:00Z" || rec.EndsAt != "2026-12-15T10:30:00Z" {
t.Fatalf("record = %+v, want removed 2026-11-15T10:30:00Z and ends exactly 30 days later", rec)
}
again, err := Load(path, log.New(io.Discard, "", 0))
if err != nil {
t.Fatal(err)
}
got, ok := again.GetOffsiteEnd("vikunja")
if !ok || got != rec {
t.Fatalf("after a restart the record is %+v ok=%v, want %+v", got, ok, rec)
}
if n := len(again.GetOffsiteEnds()); n != 1 {
t.Fatalf("records after a restart: %d", n)
}
}
// TWO PRESSES FOR THE SAME APP: one record, and the second press changes nothing — not earlier, not later.
func TestD72_EndRecord_ASecondPressChangesNothing(t *testing.T) {
s, _ := endsSettings(t)
press := time.Date(2026, 11, 15, 10, 30, 0, 0, time.UTC)
first, _, _ := s.StartOffsiteEnd("vikunja", press)
for _, at := range []time.Time{press.Add(-10 * 24 * time.Hour), press.Add(10 * 24 * time.Hour)} {
rec, created, err := s.StartOffsiteEnd("vikunja", at)
if err != nil || created || rec != first {
t.Fatalf("a second press at %s: created=%v rec=%+v err=%v — want the first record unchanged (%+v)", at, created, rec, err, first)
}
}
if got, _ := s.GetOffsiteEnd("vikunja"); got != first {
t.Fatalf("stored record moved: %+v, want %+v", got, first)
}
if n := len(s.GetOffsiteEnds()); n != 1 {
t.Fatalf("two presses left %d records", n)
}
}
// „Keep it after all” (and an install) deletes the record; a second one finds none.
func TestD72_EndRecord_CancelDeletesIt(t *testing.T) {
s, path := endsSettings(t)
_, _, _ = s.StartOffsiteEnd("vikunja", time.Now())
if ok, err := s.CancelOffsiteEnd("vikunja", "test"); err != nil || !ok {
t.Fatalf("cancel: ok=%v err=%v", ok, err)
}
if _, ok := s.GetOffsiteEnd("vikunja"); ok {
t.Fatal("the record is still there after the take-back")
}
again, _ := Load(path, log.New(io.Discard, "", 0))
if _, ok := again.GetOffsiteEnd("vikunja"); ok {
t.Fatal("the take-back was not written to disk: a restart brings the record back")
}
if ok, _ := s.CancelOffsiteEnd("vikunja", "test"); ok {
t.Fatal("a second take-back reported a record")
}
}
// The record is keyed on the app AND its removed_at: a window that read an OLD record must not complete a record
// written anew since (removed, taken back, removed again). And an end with no snapshot leaves no history line.
func TestD72_EndRecord_CompleteNeedsTheSameRecord(t *testing.T) {
s, _ := endsSettings(t)
old, _, _ := s.StartOffsiteEnd("vikunja", time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC))
_, _ = s.CancelOffsiteEnd("vikunja", "test")
cur, _, _ := s.StartOffsiteEnd("vikunja", time.Date(2026, 11, 1, 0, 0, 0, 0, time.UTC))
if done, err := s.CompleteOffsiteEnd("vikunja", old.RemovedAt, time.Now(), 5); err != nil || done {
t.Fatalf("an old window completed a NEW record: done=%v err=%v", done, err)
}
if got, ok := s.GetOffsiteEnd("vikunja"); !ok || got != cur {
t.Fatalf("the new record is gone or changed: %+v ok=%v", got, ok)
}
at := time.Date(2026, 12, 6, 3, 0, 0, 0, time.UTC)
if done, err := s.CompleteOffsiteEnd("vikunja", cur.RemovedAt, at, 5); err != nil || !done {
t.Fatalf("complete: done=%v err=%v", done, err)
}
if _, ok := s.GetOffsiteEnd("vikunja"); ok {
t.Fatal("a completed record is still pending")
}
h := s.GetOffsiteEndsDone()
if len(h) != 1 || h[0].App != "vikunja" || h[0].Snapshots != 5 || h[0].DeletedAt != "2026-12-06T03:00:00Z" {
t.Fatalf("history = %+v", h)
}
// nothing was deleted → no history line
e, _, _ := s.StartOffsiteEnd("kimai", time.Now())
if done, _ := s.CompleteOffsiteEnd("kimai", e.RemovedAt, at, 0); !done || len(s.GetOffsiteEndsDone()) != 1 {
t.Fatalf("an end with no snapshot must close with no history line: %+v", s.GetOffsiteEndsDone())
}
}
// When a record is DUE by this box's clock: on or after ends_at — and never before removed_at + 30 days, whatever
// the record's ends_at says. Dates that cannot be read are never due.
func TestD72_EndRecord_Due(t *testing.T) {
removed := time.Date(2026, 11, 15, 10, 0, 0, 0, time.UTC)
ok := OffsiteEnd{App: "a", RemovedAt: removed.Format(time.RFC3339), EndsAt: removed.Add(OffsiteEndAfter).Format(time.RFC3339)}
for _, c := range []struct {
name string
e OffsiteEnd
now time.Time
want bool
}{
{"one second before the end", ok, removed.Add(OffsiteEndAfter - time.Second), false},
{"at the end", ok, removed.Add(OffsiteEndAfter), true},
{"a week after the end (the box was off)", ok, removed.Add(OffsiteEndAfter + 7*24*time.Hour), true},
{"an ends_at EARLIER than 30 days after the removal does not shorten the wait",
OffsiteEnd{App: "a", RemovedAt: removed.Format(time.RFC3339), EndsAt: removed.Add(time.Hour).Format(time.RFC3339)}, removed.Add(29 * 24 * time.Hour), false},
{"…and is due at the 30 days", OffsiteEnd{App: "a", RemovedAt: removed.Format(time.RFC3339), EndsAt: removed.Add(time.Hour).Format(time.RFC3339)}, removed.Add(OffsiteEndAfter), true},
{"no removed_at", OffsiteEnd{App: "a", EndsAt: removed.Format(time.RFC3339)}, removed.Add(400 * 24 * time.Hour), false},
{"an ends_at that cannot be read", OffsiteEnd{App: "a", RemovedAt: removed.Format(time.RFC3339), EndsAt: "soon"}, removed.Add(400 * 24 * time.Hour), false},
} {
if got := c.e.Due(c.now); got != c.want {
t.Errorf("%s: Due = %v, want %v", c.name, got, c.want)
}
}
}
// The shares pseudo-app, the tier's marker and anything that is not a plain stack name never get a record.
func TestD72_EndRecord_ReservedNamesGetNone(t *testing.T) {
s, _ := endsSettings(t)
for _, app := range []string{"_shares", "felhom-offbox", "", ".", "..", "a/b", "a b", "_anything"} {
if _, created, err := s.StartOffsiteEnd(app, time.Now()); err == nil || created {
t.Errorf("%q got an end record (created=%v err=%v)", app, created, err)
}
}
if n := len(s.GetOffsiteEnds()); n != 0 {
t.Fatalf("%d record(s) written for reserved names", n)
}
}