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,136 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/config"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/i18n"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
|
||||
)
|
||||
|
||||
// D72 / D84 (`09` §3 decisions 292, 309; `07-backup-architecture.md` §8.2f).
|
||||
// RED-PROOFS: felhom.eu/documentation/audits/build-release-4-2026-11-15/A/redproof-ctrl-press.txt.
|
||||
|
||||
func endsRouter(t *testing.T, transport string) (*Router, *settings.Settings) {
|
||||
t.Helper()
|
||||
r, _ := newR442Router(t, "deployed: true\nenv: {}\n")
|
||||
lg := log.New(io.Discard, "", 0)
|
||||
sett, err := settings.Load(filepath.Join(t.TempDir(), "settings.json"), lg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := sett.SetOffboxTarget(&settings.OffboxTarget{Enabled: true, Host: "h", User: "u", RepoPath: "/r", Transport: transport}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := &config.Config{}
|
||||
cfg.Paths.DataDir = t.TempDir()
|
||||
r.backupMgr = backup.NewManager(cfg, sett, lg)
|
||||
r.sett = sett
|
||||
return r, sett
|
||||
}
|
||||
|
||||
// THE DATE IS SHOWN BEFORE THE PRESS (D72): the dialog's data carries the day the off-site copies would be deleted —
|
||||
// today + 30 days, in the household's date form — only on a box where a press starts the clock.
|
||||
func TestD72_BackupDataCarriesTheEndDateBeforeThePress(t *testing.T) {
|
||||
get := func(r *Router, lang string) map[string]any {
|
||||
w := httptest.NewRecorder()
|
||||
r.getStackBackupData(w, httptest.NewRequest(http.MethodGet, "/api/stacks/app/backup-data?lang="+lang, nil), "app")
|
||||
var resp struct {
|
||||
OK bool `json:"ok"`
|
||||
Data map[string]any `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil || !resp.OK {
|
||||
t.Fatalf("backup-data: %s (%v)", w.Body.String(), err)
|
||||
}
|
||||
return resp.Data
|
||||
}
|
||||
r, sett := endsRouter(t, settings.TransportRclonePinned)
|
||||
want := time.Now().Add(settings.OffsiteEndAfter).Local()
|
||||
for _, lang := range []string{"hu", "en"} {
|
||||
got, _ := get(r, lang)["offsite_end_date"].(string)
|
||||
if got != i18n.FormatDate(lang, want) && got != i18n.FormatDate(lang, want.Add(-time.Minute)) {
|
||||
t.Errorf("[%s] offsite_end_date = %q, want %q (today + 30 days)", lang, got, i18n.FormatDate(lang, want))
|
||||
}
|
||||
}
|
||||
// reading the dialog's data writes NOTHING: the record is the press's, not the look's
|
||||
if n := len(sett.GetOffsiteEnds()); n != 0 {
|
||||
t.Fatalf("opening the dialog wrote %d end record(s)", n)
|
||||
}
|
||||
// the household's own NAS (no hub window): the dialog says nothing about off-site copies
|
||||
r2, _ := endsRouter(t, "")
|
||||
if v, has := get(r2, "hu")["offsite_end_date"]; has {
|
||||
t.Fatalf("a box without the hub's tier names an end date: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
// MUST-HOLD 1, at the handler: the end record is written ONLY when the household pressed „delete backup data”.
|
||||
// removeStack's success path needs Docker, so this reads the handler's source (as R-486/R-491 do): every call of
|
||||
// StartOffsiteEnd in removeStack sits inside an `if` whose condition names body.RemoveBackups — and there is one.
|
||||
// What the call then does is pinned on the real code in backup (TestD84_OnePressOneMail and the window tests).
|
||||
func TestD72_RemovalWritesTheEndRecordOnlyWithDeleteBackupData(t *testing.T) {
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "router.go", nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
calls, guarded := 0, 0
|
||||
for _, d := range f.Decls {
|
||||
fn, ok := d.(*ast.FuncDecl)
|
||||
if !ok || fn.Name.Name != "removeStack" || fn.Body == nil {
|
||||
continue
|
||||
}
|
||||
isCall := func(n ast.Node) bool {
|
||||
s, ok := n.(*ast.SelectorExpr)
|
||||
return ok && s.Sel.Name == "StartOffsiteEnd"
|
||||
}
|
||||
ast.Inspect(fn.Body, func(n ast.Node) bool {
|
||||
if isCall(n) {
|
||||
calls++
|
||||
}
|
||||
ifs, ok := n.(*ast.IfStmt)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
names := false
|
||||
ast.Inspect(ifs.Cond, func(c ast.Node) bool {
|
||||
if s, ok := c.(*ast.SelectorExpr); ok && s.Sel.Name == "RemoveBackups" {
|
||||
names = true
|
||||
}
|
||||
return true
|
||||
})
|
||||
if names {
|
||||
ast.Inspect(ifs.Body, func(b ast.Node) bool {
|
||||
if isCall(b) {
|
||||
guarded++
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
if calls != 1 || guarded != 1 {
|
||||
t.Fatalf("removeStack: %d call(s) of StartOffsiteEnd, %d inside `if … body.RemoveBackups …` — want exactly one, guarded: "+
|
||||
"a removal that KEEPS the backups must write no end record", calls, guarded)
|
||||
}
|
||||
raw, err := os.ReadFile("router.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n := strings.Count(string(raw), "StartOffsiteEnd("); n != 1 {
|
||||
t.Fatalf("router.go calls StartOffsiteEnd %d time(s) — the removal is its only caller here", n)
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
|
||||
cf "gitea.dooplex.hu/admin/felhom-controller/internal/cloudflare"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/config"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/i18n"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/integrations"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/metrics"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/notify"
|
||||
@@ -963,6 +964,10 @@ func (r *Router) getStackBackupData(w http.ResponseWriter, req *http.Request, na
|
||||
writeJSON(w, http.StatusNotFound, apiResponse{OK: false, Error: r.errText(req, err)})
|
||||
return
|
||||
}
|
||||
// D72: the date is on the dialog BEFORE the press. Only where a press would start the 30 days.
|
||||
if r.backupMgr != nil && r.backupMgr.OffsiteEndOffered() {
|
||||
resp.OffsiteEndDate = i18n.FormatDate(r.langFor(req), r.backupMgr.OffsiteEndDateIfPressedNow().Local())
|
||||
}
|
||||
writeJSON(w, http.StatusOK, apiResponse{OK: true, Data: resp})
|
||||
}
|
||||
|
||||
@@ -1101,6 +1106,19 @@ func (r *Router) removeStack(w http.ResponseWriter, req *http.Request, name stri
|
||||
if body.RemoveBackups {
|
||||
resp.BackupPathsRemoved = append(resp.BackupPathsRemoved, r.removeVerificationCopy(name)...)
|
||||
}
|
||||
// D72 / D84 (`07` §8.2f): „delete backup data” deletes the LOCAL backups now (above) and starts the 30 days of
|
||||
// the app's OFF-SITE copies: the end record, and the household's one mail. Never on a removal that kept the
|
||||
// backups; never on a box without the hub-provisioned tier (nothing would carry the deletion out).
|
||||
if body.RemoveBackups && r.backupMgr != nil {
|
||||
switch rec, created, serr := r.backupMgr.StartOffsiteEnd(name); {
|
||||
case errors.Is(serr, backup.ErrOffsiteEndNotOffered):
|
||||
r.dbg("removeStack: %s: no hub-provisioned off-site tier — no off-site end record", name)
|
||||
case serr != nil:
|
||||
r.logger.Printf("[WARN] [api] remove %s: its off-site end record was NOT written (%v) — its off-site copies stay; the Backups page offers „delete in 30 days”", name, serr)
|
||||
case created:
|
||||
r.logger.Printf("[INFO] [api] remove %s: its off-site copies end %s (D72)", name, rec.EndsAt)
|
||||
}
|
||||
}
|
||||
|
||||
// R-486 (v0.240.0): the app's backup preferences — and with them the Tier-2 RECORD that
|
||||
// tier2RecordedCopyDir needs — are forgotten ONLY when the customer asked for the backups to be
|
||||
|
||||
Reference in new issue
Block a user