R-899: a daytime press never cancels the night's whole-guest backup (operator ruling 2026-10-08, option A); press sends trigger=manual
gates / gates (push) Successful in 1m3s
gates / gates (push) Successful in 1m3s
Unreleased; ships with tomorrow's release. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
@@ -64,6 +64,21 @@ func targetQuery(target string) string {
|
||||
return "?target=" + url.QueryEscape(target)
|
||||
}
|
||||
|
||||
// backupStartQuery is targetQuery plus `trigger=manual` for a household press (R-899).
|
||||
func backupStartQuery(target string, manual bool) string {
|
||||
q := url.Values{}
|
||||
if target != "" {
|
||||
q.Set("target", target)
|
||||
}
|
||||
if manual {
|
||||
q.Set("trigger", "manual")
|
||||
}
|
||||
if len(q) == 0 {
|
||||
return ""
|
||||
}
|
||||
return "?" + q.Encode()
|
||||
}
|
||||
|
||||
// BackupDueFor reports whether THIS TIER is due. A fresh backup on another tier must not satisfy it
|
||||
// — that filtering happens agent-side (latestSuccessfulBackupForTarget); this just asks per tier.
|
||||
func (c *Client) BackupDueFor(ctx context.Context, target string) (DueResponse, error) {
|
||||
@@ -80,8 +95,15 @@ func (c *Client) BackupDueFor(ctx context.Context, target string) (DueResponse,
|
||||
|
||||
// StartBackupFor enqueues a backup of this guest ON THE GIVEN TIER.
|
||||
func (c *Client) StartBackupFor(ctx context.Context, target string) (BackupResponse, error) {
|
||||
return c.StartBackupForTrigger(ctx, target, false)
|
||||
}
|
||||
|
||||
// StartBackupForTrigger is StartBackupFor that also says whether this is a household press (R-899): a press
|
||||
// carries `trigger=manual`, and an agent that knows it does not start the night's OS leg after it. An older
|
||||
// agent ignores the parameter (it reads only `target`), so the request is safe against any agent.
|
||||
func (c *Client) StartBackupForTrigger(ctx context.Context, target string, manual bool) (BackupResponse, error) {
|
||||
var out BackupResponse
|
||||
body, err := c.post(ctx, "/backup"+targetQuery(target), struct{}{})
|
||||
body, err := c.post(ctx, "/backup"+backupStartQuery(target, manual), struct{}{})
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
|
||||
@@ -272,15 +272,7 @@ func (c *Client) BackupDue(ctx context.Context) (DueResponse, error) {
|
||||
|
||||
// StartBackup enqueues a backup of this guest (the agent vzdump) and returns the job to poll.
|
||||
func (c *Client) StartBackup(ctx context.Context) (BackupResponse, error) {
|
||||
var out BackupResponse
|
||||
body, err := c.post(ctx, "/backup", struct{}{})
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
if err := json.Unmarshal(body, &out); err != nil {
|
||||
return out, fmt.Errorf("agentapi: decode POST /backup: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
return c.StartBackupForTrigger(ctx, "", false)
|
||||
}
|
||||
|
||||
// BackupStatus reports the current/last backup job phase for this guest.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package agentapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// R-899: a household press tells the agent so (`trigger=manual`), and nothing else does — the agent runs the
|
||||
// night's OS leg only after a backup that is not a press. The request the agent RECEIVES is asserted.
|
||||
func TestR899_PressCarriesTriggerManual(t *testing.T) {
|
||||
var got []string
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("POST /backup", func(w http.ResponseWriter, r *http.Request) {
|
||||
got = append(got, r.URL.RawQuery)
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
_, _ = w.Write([]byte(`{"ok":true,"data":{"vmid":9201,"job_id":"backup-9201-2","phase":"running"}}`))
|
||||
})
|
||||
s := httptest.NewTLSServer(mux)
|
||||
defer s.Close()
|
||||
c := clientFor(t, s, strings.TrimPrefix(s.URL, "https://"))
|
||||
ctx := context.Background()
|
||||
|
||||
if _, err := c.StartBackup(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := c.StartBackupFor(ctx, "local"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := c.StartBackupForTrigger(ctx, "local", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := c.StartBackupForTrigger(ctx, "", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"", "target=local", "target=local&trigger=manual", "trigger=manual"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("queries = %q, want %q", got, want)
|
||||
}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("query %d = %q, want %q (all: %q)", i, got[i], want[i], got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user