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
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:
1 parent
591195fadd
commit
f628cb5082
177 files changed
+3705
-164
No files matched your search
@@ -0,0 +1,171 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// D72 / D84 (`09` §3 decisions 292 and 309; `07-backup-architecture.md` §8.2f, part 1) — THE OFF-SITE END RECORD.
|
||||
//
|
||||
// When the household removes an app and presses „delete backup data”, the local backups go at once and the app's
|
||||
// OFF-SITE copies end 30 days later. This record is the whole of that promise on the box:
|
||||
//
|
||||
// NO RECORD = NO DELETION, EVER.
|
||||
//
|
||||
// It is written only by StartOffsiteEnd (the household's press), deleted by CancelOffsiteEnd („keep it after all”,
|
||||
// and every install of the same app), and moved to the short history by CompleteOffsiteEnd when a clean-up window
|
||||
// has removed the copies. Nothing else starts, moves or shortens the clock. It lives in settings.json, so it
|
||||
// survives a controller restart; a rebuilt guest has none, and then the copies stay (the safe direction).
|
||||
|
||||
// OffsiteEndAfter is how long the off-site copies of a removed app stay (D72: the number of a restore copy, D62).
|
||||
const OffsiteEndAfter = 30 * 24 * time.Hour
|
||||
|
||||
// OffsiteEnd is one pending end record.
|
||||
type OffsiteEnd struct {
|
||||
App string `json:"app"`
|
||||
RemovedAt string `json:"removed_at"` // RFC3339, the moment of the press
|
||||
EndsAt string `json:"ends_at"` // RFC3339, RemovedAt + OffsiteEndAfter
|
||||
}
|
||||
|
||||
// Removed and Ends parse the record's dates; a date that cannot be read is the zero time, and a record with a zero
|
||||
// date is never due (OffsiteEndDue).
|
||||
func (e OffsiteEnd) Removed() time.Time { t, _ := time.Parse(time.RFC3339, e.RemovedAt); return t }
|
||||
func (e OffsiteEnd) Ends() time.Time { t, _ := time.Parse(time.RFC3339, e.EndsAt); return t }
|
||||
|
||||
// Due reports whether the record's day has come by this box's clock. The HUB decides by its own clock whether it
|
||||
// agrees (`07` §8.2f part 4); this is only when the box starts to ask. The end is never earlier than
|
||||
// RemovedAt + OffsiteEndAfter, whatever EndsAt says (a hand-edited or damaged record cannot shorten the wait).
|
||||
func (e OffsiteEnd) Due(now time.Time) bool {
|
||||
removed, ends := e.Removed(), e.Ends()
|
||||
if removed.IsZero() || ends.IsZero() {
|
||||
return false
|
||||
}
|
||||
if min := removed.Add(OffsiteEndAfter); ends.Before(min) {
|
||||
ends = min
|
||||
}
|
||||
return !now.Before(ends)
|
||||
}
|
||||
|
||||
// OffsiteEndDone is one line of history: the off-site copies of App were removed by a clean-up window.
|
||||
type OffsiteEndDone struct {
|
||||
App string `json:"app"`
|
||||
RemovedAt string `json:"removed_at"`
|
||||
DeletedAt string `json:"deleted_at"` // RFC3339
|
||||
Snapshots int `json:"snapshots"`
|
||||
}
|
||||
|
||||
// maxOffsiteEndsDone bounds the history list.
|
||||
const maxOffsiteEndsDone = 20
|
||||
|
||||
// ValidOffsiteEndApp: a name an end record may carry. The shares pseudo-app (`_shares`), the tier's marker tag and
|
||||
// anything that is not a plain stack name are never eligible (`07` §8.2f, the edge-case table). Whether the name is
|
||||
// a PROTECTED infrastructure stack is the caller's check — settings does not know the stack list.
|
||||
func ValidOffsiteEndApp(app string) bool {
|
||||
return app != "" && app != "." && app != ".." && !strings.HasPrefix(app, "_") && app != "felhom-offbox" &&
|
||||
!strings.ContainsAny(app, "/\\ \t\n")
|
||||
}
|
||||
|
||||
// StartOffsiteEnd writes the end record for app at now. created is false when a record already exists: a second
|
||||
// press changes NOTHING — not the date, and the caller sends no second mail.
|
||||
func (s *Settings) StartOffsiteEnd(app string, now time.Time) (rec OffsiteEnd, created bool, err error) {
|
||||
if !ValidOffsiteEndApp(app) {
|
||||
return OffsiteEnd{}, false, fmt.Errorf("offsite end: %q is not an app a household removes", app)
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if cur, ok := s.OffsiteEnds[app]; ok {
|
||||
return cur, false, nil
|
||||
}
|
||||
now = now.UTC().Truncate(time.Second)
|
||||
rec = OffsiteEnd{App: app, RemovedAt: now.Format(time.RFC3339), EndsAt: now.Add(OffsiteEndAfter).Format(time.RFC3339)}
|
||||
if s.OffsiteEnds == nil {
|
||||
s.OffsiteEnds = map[string]OffsiteEnd{}
|
||||
}
|
||||
s.OffsiteEnds[app] = rec
|
||||
if err := s.save(); err != nil {
|
||||
delete(s.OffsiteEnds, app) // a record that is not on disk is not a record
|
||||
return OffsiteEnd{}, false, err
|
||||
}
|
||||
if s.log != nil {
|
||||
s.log.Printf("[INFO] [settings] off-site end record WRITTEN for %s: removed %s, its off-site copies end %s (D72)", app, rec.RemovedAt, rec.EndsAt)
|
||||
}
|
||||
return rec, true, nil
|
||||
}
|
||||
|
||||
// CancelOffsiteEnd deletes app's end record („keep it after all”, or an install of the same app). Returns whether a
|
||||
// record existed. why is for the log.
|
||||
func (s *Settings) CancelOffsiteEnd(app, why string) (bool, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
cur, ok := s.OffsiteEnds[app]
|
||||
if !ok {
|
||||
return false, nil
|
||||
}
|
||||
delete(s.OffsiteEnds, app)
|
||||
if err := s.save(); err != nil {
|
||||
s.OffsiteEnds[app] = cur
|
||||
return false, err
|
||||
}
|
||||
if s.log != nil {
|
||||
s.log.Printf("[INFO] [settings] off-site end record DELETED for %s (%s) — its off-site copies are kept (was: ends %s)", app, why, cur.EndsAt)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetOffsiteEnd returns app's pending end record.
|
||||
func (s *Settings) GetOffsiteEnd(app string) (OffsiteEnd, bool) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
e, ok := s.OffsiteEnds[app]
|
||||
return e, ok
|
||||
}
|
||||
|
||||
// GetOffsiteEnds returns the pending end records, by app name.
|
||||
func (s *Settings) GetOffsiteEnds() []OffsiteEnd {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
out := make([]OffsiteEnd, 0, len(s.OffsiteEnds))
|
||||
for _, e := range s.OffsiteEnds {
|
||||
out = append(out, e)
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].App < out[j].App })
|
||||
return out
|
||||
}
|
||||
|
||||
// CompleteOffsiteEnd moves app's record to the history after a clean-up window removed its copies. The record is
|
||||
// keyed on the app AND its removed_at (`07` §8.2f): a record that was deleted or written anew since the window read
|
||||
// it is NOT completed. Returns whether it was.
|
||||
func (s *Settings) CompleteOffsiteEnd(app, removedAt string, deletedAt time.Time, snapshots int) (bool, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
cur, ok := s.OffsiteEnds[app]
|
||||
if !ok || cur.RemovedAt != removedAt {
|
||||
return false, nil
|
||||
}
|
||||
delete(s.OffsiteEnds, app)
|
||||
prevDone := s.OffsiteEndsDone
|
||||
if snapshots > 0 {
|
||||
done := append([]OffsiteEndDone{{App: app, RemovedAt: removedAt, DeletedAt: deletedAt.UTC().Format(time.RFC3339), Snapshots: snapshots}}, s.OffsiteEndsDone...)
|
||||
if len(done) > maxOffsiteEndsDone {
|
||||
done = done[:maxOffsiteEndsDone]
|
||||
}
|
||||
s.OffsiteEndsDone = done
|
||||
}
|
||||
if err := s.save(); err != nil {
|
||||
s.OffsiteEnds[app], s.OffsiteEndsDone = cur, prevDone
|
||||
return false, err
|
||||
}
|
||||
if s.log != nil {
|
||||
s.log.Printf("[INFO] [settings] off-site end record COMPLETED for %s: %d snapshot(s) removed", app, snapshots)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetOffsiteEndsDone returns the history, newest first.
|
||||
func (s *Settings) GetOffsiteEndsDone() []OffsiteEndDone {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return append([]OffsiteEndDone(nil), s.OffsiteEndsDone...)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,11 @@ type Settings struct {
|
||||
// leaving the marker active would have Recover() start the broken app at the next controller
|
||||
// boot, hours later and quietly, which is the outcome the hold exists to prevent.
|
||||
RestoreHolds map[string]RestoreHold `json:"restore_holds,omitempty"`
|
||||
|
||||
// OffsiteEnds (D72/D84, `07` §8.2f) — the pending off-site end records, by app: no record, no deletion.
|
||||
// OffsiteEndsDone is the short history of ends a clean-up window has carried out. See offsite_ends.go.
|
||||
OffsiteEnds map[string]OffsiteEnd `json:"offsite_ends,omitempty"`
|
||||
OffsiteEndsDone []OffsiteEndDone `json:"offsite_ends_done,omitempty"`
|
||||
// UnhealthyStops (v0.269.0, decision 28) — when the box last stopped each app for a crash loop or an
|
||||
// out-of-memory storm (RFC3339). Survives the hold being lifted by Start, so a second stop within
|
||||
// 24 h is known to be a second one.
|
||||
|
||||
Reference in new issue
Block a user