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,71 @@
package offsiteapply
import (
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
)
// D72 / D84 (`07-backup-architecture.md` §8.2f): the window request carries the box's due end records, the answer
// carries what the hub agreed to — and only a GRANTED window carries an agreement.
// RED-PROOF: felhom.eu/documentation/audits/build-release-4-2026-11-15/A/redproof-ctrl-window.txt.
func TestD84_WindowClient_SendsTheClaimsAndReadsTheAgreement(t *testing.T) {
var gotPath string
var gotBody map[string]json.RawMessage
answer := `{"granted":true,"window_id":9,"newest_allowed":"2026-12-20T03:00:00Z","max_remove":10,"ended_allowed":["aa","bb"],"ended_refused":[{"app":"immich","reason":"the box's newest report lists the app as installed"}]}`
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotPath = r.URL.Path
b, _ := io.ReadAll(r.Body)
gotBody = map[string]json.RawMessage{}
_ = json.Unmarshal(b, &gotBody)
_, _ = w.Write([]byte(answer))
}))
defer srv.Close()
c := HubWindowClient{Registrar: HubRegistrar{HubURL: srv.URL, CustomerID: "c1", APIKey: "k"}}
claims := []backup.OffsiteEndedClaim{{App: "vikunja", RemovedAt: "2026-11-15T10:00:00Z", EndsAt: "2026-12-15T10:00:00Z", SnapshotIDs: []string{"aa", "bb", "cc"}}}
w, err := c.Open(context.Background(), 20, claims)
if err != nil {
t.Fatal(err)
}
if gotPath != "/api/v1/offsite/window-open/c1" || string(gotBody["count_before"]) != "20" {
t.Fatalf("request: path=%q body=%v", gotPath, gotBody)
}
var sent []backup.OffsiteEndedClaim
if err := json.Unmarshal(gotBody["ended"], &sent); err != nil || len(sent) != 1 || sent[0].App != "vikunja" || strings.Join(sent[0].SnapshotIDs, ",") != "aa,bb,cc" || sent[0].RemovedAt != "2026-11-15T10:00:00Z" {
t.Fatalf("the hub did not receive the claim: %s (%v)", gotBody["ended"], err)
}
if !w.Granted || w.ID != 9 || w.MaxRemove != 10 || strings.Join(w.EndedAllowed, ",") != "aa,bb" || len(w.EndedRefused) != 1 || w.EndedRefused[0].App != "immich" {
t.Fatalf("window = %+v, want the agreement (aa,bb) and the refusal of immich", w)
}
// With no due record the body is the one an older hub always saw: no `ended` key at all.
if _, err := c.Open(context.Background(), 20, nil); err != nil {
t.Fatal(err)
}
if _, has := gotBody["ended"]; has {
t.Fatalf("a request with no claim carries `ended`: %v", gotBody)
}
// A window that is NOT granted carries no agreement, whatever the answer holds.
answer = `{"granted":false,"reason":"not due","ended_allowed":["aa","bb"]}`
w2, err := c.Open(context.Background(), 20, claims)
if err != nil || w2.Granted || len(w2.EndedAllowed) != 0 {
t.Fatalf("not granted: %+v %v — an agreement without a window must not reach the box", w2, err)
}
// The close names the removed ids for the hub's audit.
answer = `{"closed":true}`
if err := c.Close(context.Background(), backup.OffsiteWindowResult{ID: 9, CountBefore: 20, CountAfter: 18, Removed: 2, Outcome: "pruned", RemovedForEndedApps: []string{"aa", "bb"}}); err != nil {
t.Fatal(err)
}
var removed []string
if err := json.Unmarshal(gotBody["removed_for_ended_apps"], &removed); err != nil || strings.Join(removed, ",") != "aa,bb" || gotPath != "/api/v1/offsite/window-close/c1" {
t.Fatalf("close: path=%q removed_for_ended_apps=%s", gotPath, gotBody["removed_for_ended_apps"])
}
}
+17 -7
View File
@@ -127,17 +127,25 @@ func (c HubRegistrar) MoveAside(ctx context.Context) (string, error) {
type HubWindowClient struct{ Registrar HubRegistrar }
func (c HubWindowClient) Open(ctx context.Context, countBefore int) (backup.OffsiteWindow, error) {
raw, err := c.Registrar.post(ctx, "window-open", map[string]int{"count_before": countBefore})
func (c HubWindowClient) Open(ctx context.Context, countBefore int, ended []backup.OffsiteEndedClaim) (backup.OffsiteWindow, error) {
// D72/D84: the due end records ride the same request; `ended` is left out when there is none, so the body an
// older hub sees is the one it always saw.
req := struct {
CountBefore int `json:"count_before"`
Ended []backup.OffsiteEndedClaim `json:"ended,omitempty"`
}{CountBefore: countBefore, Ended: ended}
raw, err := c.Registrar.post(ctx, "window-open", req)
if err != nil {
return backup.OffsiteWindow{}, err
}
var r struct {
Granted bool `json:"granted"`
WindowID int64 `json:"window_id"`
NewestAllowed string `json:"newest_allowed"`
MaxRemove int `json:"max_remove"`
Reason string `json:"reason"`
Granted bool `json:"granted"`
WindowID int64 `json:"window_id"`
NewestAllowed string `json:"newest_allowed"`
MaxRemove int `json:"max_remove"`
Reason string `json:"reason"`
EndedAllowed []string `json:"ended_allowed"`
EndedRefused []backup.OffsiteEndedRefusal `json:"ended_refused"`
}
if err := json.Unmarshal(raw, &r); err != nil {
return backup.OffsiteWindow{}, fmt.Errorf("hub window-open: malformed response")
@@ -149,6 +157,8 @@ func (c HubWindowClient) Open(ctx context.Context, countBefore int) (backup.Offs
return backup.OffsiteWindow{}, fmt.Errorf("hub window-open: bad newest_allowed")
}
w.NewestAllowed = t
// Only a GRANTED window carries an agreement.
w.EndedAllowed, w.EndedRefused = r.EndedAllowed, r.EndedRefused
}
return w, nil
}