Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fix durable APT drift receipts
rcourtman373b491484c9
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 5e5dca8666..fd20bb70ff 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -4439,12 +4439,19 @@ Task 09 now consumes that continuity end to end. A delayed terminal receipt isvalidated against its immutable identity/digest and the agent-attested durableterminal boundary, not the later query time. The server retains the laterquery receipt separately. Impossible observation/terminal chronology, a-future terminal timestamp, stale-at-completion evidence, before-state drift,-or a hostile envelope still fails closed. Callback loss and a reopened server-store reconcile both APT actions by query only; the original typed dispatch is-never resent. Legacy APT v1 terminal payloads that predate additive package--manager health facts remain structurally valid receipts, but their verified-claim is projected as health-unknown/inconclusive rather than confirmed.+future terminal timestamp, stale-at-completion evidence, an evidence-bearing+before-state mismatch, or a hostile envelope still fails closed. A legitimate+pre-mutation inventory or cache-fingerprint drift result remains terminal and+inconclusive: its newly observed `Before` value is not substituted for the+originally authorized expected value when validating the admitted request+digest. The generic receipt store continues to bind completion and replay to+the exact admitted attempt/action/operation/digest/agent identity, while the+drift observation records why mutation was refused and replan is required.+Callback loss and a reopened server store reconcile both APT actions by query+only; the original typed dispatch is never resent. Legacy APT v1 terminal+payloads that predate additive package-manager health facts remain+structurally valid receipts, but their verified claim is projected as health-+unknown/inconclusive rather than confirmed.For host updates, `MutationStarted` begins immediately before the fixed installcommand, not during metadata refresh or simulation. A fixed read-onlydiff --git a/internal/agentexec/apt_codec.go b/internal/agentexec/apt_codec.goindex cd564de72b..e16479c905 100644--- a/internal/agentexec/apt_codec.go+++ b/internal/agentexec/apt_codec.go@@ -132,11 +132,7 @@ func ValidateOperationQueryResultForIdentity(result operationreceipt.QueryResultif err != nil {return err}- req := HostUpdatePayload{RequestID: identity.AttemptID, ActionID: identity.ActionID, Operation: identity.OperationKind, OperationVersion: identity.OperationVersion, RequestDigest: identity.RequestDigest, ExpectedInventoryHash: payload.Before.InventoryHash}- if err := ValidateHostUpdatePayload(&req); err != nil {- return err- }- if err := ValidateHostUpdateResultForRequest(req, payload); err != nil {+ if err := ValidateHostUpdateReceiptForIdentity(identity, payload); err != nil {return err}return validateDurableAPTObservation(payload.Before.CheckedAt, payload.After.CheckedAt, result.Record.TerminalAt)@@ -148,11 +144,7 @@ func ValidateOperationQueryResultForIdentity(result operationreceipt.QueryResultif err != nil {return err}- req := HostStorageCleanupPayload{RequestID: identity.AttemptID, ActionID: identity.ActionID, Operation: identity.OperationKind, OperationVersion: identity.OperationVersion, RequestDigest: identity.RequestDigest, ExpectedFingerprint: payload.Before.Fingerprint}- if err := ValidateHostStorageCleanupPayload(&req); err != nil {- return err- }- if err := ValidateHostStorageCleanupResultForRequest(req, payload); err != nil {+ if err := ValidateHostStorageCleanupReceiptForIdentity(identity, payload); err != nil {return err}return validateDurableAPTObservation(payload.Before.CheckedAt, payload.After.CheckedAt, result.Record.TerminalAt)@@ -327,6 +319,35 @@ func ValidateHostUpdateResultForRequest(req HostUpdatePayload, result HostUpdatereturn nil}+// ValidateHostUpdateReceiptForIdentity validates a terminal result against the+// immutable identity admitted by the generic operation-receipt store. An+// inconclusive drift result intentionally reports the newly observed inventory+// in Before, so that observation must not be substituted for the originally+// authorized inventory when checking the admitted request digest. The store+// itself binds Complete and Query to the exact admitted identity. Evidence-+// bearing results additionally prove the original before-state by deriving the+// digest from their matching observation.+func ValidateHostUpdateReceiptForIdentity(identity operationreceipt.Identity, result HostUpdateResultPayload) error {+ normalized, err := operationreceipt.NormalizeIdentity(identity)+ if err != nil || normalized != identity {+ return operationreceipt.ErrBindingConflict+ }+ if identity.OperationKind != HostUpdateOperationInstall || identity.OperationVersion != HostAPTOperationVersion || result.RequestID != identity.AttemptID || result.ActionID != identity.ActionID {+ return operationreceipt.ErrBindingConflict+ }+ if err := ValidateHostUpdateResultPayload(&result); err != nil {+ return err+ }+ if result.Verification != HostUpdateVerificationVerified && result.Verification != HostUpdateVerificationFailed {+ return nil+ }+ req := HostUpdatePayload{RequestID: identity.AttemptID, ActionID: identity.ActionID, Operation: identity.OperationKind, OperationVersion: identity.OperationVersion, RequestDigest: identity.RequestDigest, ExpectedInventoryHash: result.Before.InventoryHash}+ if err := ValidateHostUpdatePayload(&req); err != nil {+ return err+ }+ return ValidateHostUpdateResultForRequest(req, result)+}+func ValidateHostUpdateResultForRequestAt(req HostUpdatePayload, result HostUpdateResultPayload, receivedAt time.Time) error {if err := ValidateHostUpdateResultForRequest(req, result); err != nil {return err@@ -352,6 +373,31 @@ func ValidateHostStorageCleanupResultForRequest(req HostStorageCleanupPayload, rreturn nil}+// ValidateHostStorageCleanupReceiptForIdentity is the cleanup counterpart to+// ValidateHostUpdateReceiptForIdentity. Fingerprint drift is terminal,+// inconclusive evidence and may report a different observed Before value while+// the generic store continues to bind the receipt to the admitted digest.+func ValidateHostStorageCleanupReceiptForIdentity(identity operationreceipt.Identity, result HostStorageCleanupResultPayload) error {+ normalized, err := operationreceipt.NormalizeIdentity(identity)+ if err != nil || normalized != identity {+ return operationreceipt.ErrBindingConflict+ }+ if identity.OperationKind != HostStorageCleanupOperationPackageCache || identity.OperationVersion != HostAPTOperationVersion || result.RequestID != identity.AttemptID || result.ActionID != identity.ActionID {+ return operationreceipt.ErrBindingConflict+ }+ if err := ValidateHostStorageCleanupResultPayload(&result); err != nil {+ return err+ }+ if result.Verification != HostStorageCleanupVerificationVerified && result.Verification != HostStorageCleanupVerificationFailed {+ return nil+ }+ req := HostStorageCleanupPayload{RequestID: identity.AttemptID, ActionID: identity.ActionID, Operation: identity.OperationKind, OperationVersion: identity.OperationVersion, RequestDigest: identity.RequestDigest, ExpectedFingerprint: result.Before.Fingerprint}+ if err := ValidateHostStorageCleanupPayload(&req); err != nil {+ return err+ }+ return ValidateHostStorageCleanupResultForRequest(req, result)+}+func ValidateHostStorageCleanupResultForRequestAt(req HostStorageCleanupPayload, result HostStorageCleanupResultPayload, receivedAt time.Time) error {if err := ValidateHostStorageCleanupResultForRequest(req, result); err != nil {return errdiff --git a/internal/agentexec/server_websocket_test.go b/internal/agentexec/server_websocket_test.goindex 9200f4f388..d150f7615f 100644--- a/internal/agentexec/server_websocket_test.go+++ b/internal/agentexec/server_websocket_test.go@@ -13,6 +13,7 @@ import ("time""github.com/gorilla/websocket"+ "github.com/rcourtman/pulse-go-rewrite/internal/operationreceipt""github.com/rcourtman/pulse-go-rewrite/internal/securityutil")@@ -23,6 +24,62 @@ type wsRawMessage struct {Payload *json.RawMessage `json:"payload,omitempty"`}+func TestOperationQueryInconclusiveAPTDriftPreservesAdmittedDigest(t *testing.T) {+ now := time.Now().UTC()+ updateReq := HostUpdatePayload{RequestID: "u-drift.dispatch.1", ActionID: "u-drift", Operation: HostUpdateOperationInstall, ExpectedInventoryHash: "sha256:" + strings.Repeat("a", 64)}+ if err := BindHostUpdatePayload(&updateReq); err != nil {+ t.Fatal(err)+ }+ updateIdentity := HostUpdateOperationIdentity("agent", updateReq)+ updateResult := HostUpdateResultPayload{+ RequestID: updateReq.RequestID, ActionID: updateReq.ActionID, ExecutionPhase: HostUpdatePhaseRefresh, Verification: HostUpdateVerificationInconclusive,+ Before: HostPackageUpdateSnapshot{Supported: true, Manager: "apt", InventoryHash: "sha256:" + strings.Repeat("b", 64), PendingCount: 2, CheckedAt: now.Add(-time.Second)},+ After: HostPackageUpdateSnapshot{Supported: true, Manager: "apt", InventoryHash: "sha256:" + strings.Repeat("b", 64), PendingCount: 2, CheckedAt: now},+ }+ updateRaw, err := json.Marshal(updateResult)+ if err != nil {+ t.Fatal(err)+ }++ cleanupReq := HostStorageCleanupPayload{RequestID: "c-drift.dispatch.1", ActionID: "c-drift", Operation: HostStorageCleanupOperationPackageCache, ExpectedFingerprint: "sha256:" + strings.Repeat("c", 64)}+ if err := BindHostStorageCleanupPayload(&cleanupReq); err != nil {+ t.Fatal(err)+ }+ cleanupIdentity := HostStorageCleanupOperationIdentity("agent", cleanupReq)+ cleanupResult := HostStorageCleanupResultPayload{+ RequestID: cleanupReq.RequestID, ActionID: cleanupReq.ActionID, ExecutionPhase: HostStorageCleanupPhasePreflight, Verification: HostStorageCleanupVerificationInconclusive,+ Before: HostStorageCleanupSnapshot{Supported: true, Provider: "apt-package-cache", Fingerprint: "sha256:" + strings.Repeat("d", 64), ReclaimableBytes: 10, CheckedAt: now.Add(-time.Second)},+ After: HostStorageCleanupSnapshot{Supported: true, Provider: "apt-package-cache", Fingerprint: "sha256:" + strings.Repeat("d", 64), ReclaimableBytes: 10, CheckedAt: now},+ }+ cleanupRaw, err := json.Marshal(cleanupResult)+ if err != nil {+ t.Fatal(err)+ }++ for _, tc := range []struct {+ name string+ identity operationreceipt.Identity+ kind string+ payload json.RawMessage+ }{+ {name: "update inventory drift", identity: updateIdentity, kind: HostUpdateReceiptKind, payload: updateRaw},+ {name: "cleanup fingerprint drift", identity: cleanupIdentity, kind: HostStorageCleanupReceiptKind, payload: cleanupRaw},+ } {+ t.Run(tc.name, func(t *testing.T) {+ record := operationreceipt.Record{Identity: tc.identity, State: operationreceipt.StateTerminal, AcceptedAt: now.Add(-3 * time.Second), StartedAt: now.Add(-2 * time.Second), TerminalAt: now.Add(time.Second), ResultKind: tc.kind, ResultVersion: HostAPTReceiptVersion, Result: tc.payload}+ query := operationreceipt.QueryResult{Version: operationreceipt.ProtocolVersion, Status: operationreceipt.QueryFoundTerminal, Record: &record}+ if err := ValidateOperationQueryResultForIdentity(query, tc.identity, now.Add(2*time.Second)); err != nil {+ t.Fatalf("bound inconclusive drift receipt rejected: %v", err)+ }+ tampered := tc.identity+ tampered.RequestDigest = "sha256:" + strings.Repeat("e", 64)+ if err := ValidateOperationQueryResultForIdentity(query, tampered, now.Add(2*time.Second)); err == nil {+ t.Fatal("wrong request digest accepted")+ }+ })+ }+}+func newWSServer(t *testing.T, s *Server) *httptest.Server {t.Helper()return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {diff --git a/internal/api/apt_workflows_colima_real_lab_test.go b/internal/api/apt_workflows_colima_real_lab_test.goindex 20f6c86167..1613d2c9bf 100644--- a/internal/api/apt_workflows_colima_real_lab_test.go+++ b/internal/api/apt_workflows_colima_real_lab_test.go@@ -13,6 +13,7 @@ import ("os""os/exec""path/filepath"+ "regexp""strings""sync""testing"@@ -155,7 +156,12 @@ func runRG09Distro(t *testing.T, runID, distro, image, agentBinary, scratchDir sws.Start()defer ws.Close()containerID := startRG09Agent(t, runID, distro, agentID, image, agentBinary, scratchDir, ws.Listener.Addr().(*net.TCPAddr).Port)- defer stopRG09Agent(containerID)+ defer func() {+ if t.Failed() {+ t.Logf("RG-09 %s agent failure diagnostic (redacted):\n%s", distro, rg09AgentFailureDiagnostic(containerID))+ }+ stopRG09Agent(containerID)+ }()waitForRG06Agent(t, server.Server, agentID)initialReport := waitForRG09Report(t, reportCh, func(report agentshost.Report) bool {@@ -508,6 +514,45 @@ func stopRG09Agent(containerID string) {}}+var rg09SensitiveLogValue = regexp.MustCompile(`(?i)((?:authorization|api[_-]?token|password|secret)["' ]*[:=]["' ]*)[^"'\s,}]+`)++func rg09AgentFailureDiagnostic(containerID string) string {+ output, err := exec.Command("docker", "--context", "colima", "logs", "--tail", "200", containerID).CombinedOutput()+ diagnostic := string(output)+ if err != nil {+ diagnostic += "\n[container log read failed]"+ }+ return rg09RedactAgentDiagnostic(diagnostic)+}++func rg09RedactAgentDiagnostic(value string) string {+ const maxDiagnosticBytes = 16 << 10+ if len(value) > maxDiagnosticBytes {+ value = value[len(value)-maxDiagnosticBytes:]+ }+ value = rg09SensitiveLogValue.ReplaceAllString(value, `${1}[REDACTED]`)+ for old, replacement := range map[string]string{+ "rg09-local-lab": "[REDACTED]",+ "pulse-rg09-fixture": "[fixture-package]",+ "/var/cache/apt": "[package-cache-path]",+ "apt-get": "[package-manager-command]",+ } {+ value = strings.ReplaceAll(value, old, replacement)+ }+ if len(value) > maxDiagnosticBytes {+ value = value[len(value)-maxDiagnosticBytes:]+ }+ return strings.TrimSpace(value)+}++func TestRG09AgentFailureDiagnosticIsBoundedAndRedacted(t *testing.T) {+ raw := strings.Repeat("x", 17<<10) + ` authorization: Bearer-value api_token=token-value rg09-local-lab pulse-rg09-fixture /var/cache/apt apt-get`+ got := rg09RedactAgentDiagnostic(raw)+ if len(got) > 16<<10 || strings.Contains(got, "Bearer-value") || strings.Contains(got, "token-value") || strings.Contains(got, "rg09-local-lab") || strings.Contains(got, "pulse-rg09-fixture") || strings.Contains(got, "/var/cache/apt") || strings.Contains(got, "apt-get") {+ t.Fatalf("failure diagnostic was not bounded and redacted: %q", got)+ }+}+func restartRG09Agent(t *testing.T, server *agentexec.Server, agentID, containerID string, reports <-chan agentshost.Report) {t.Helper()output, err := exec.Command("docker", "--context", "colima", "restart", containerID).CombinedOutput()diff --git a/internal/hostagent/commands.go b/internal/hostagent/commands.goindex d9359d93a4..fbba5287b5 100644--- a/internal/hostagent/commands.go+++ b/internal/hostagent/commands.go@@ -876,11 +876,7 @@ func hostOperationReceiptConfig() operationreceipt.Config {if len(result.Before.Packages) > 0 || len(result.After.Packages) > 0 || result.Before.Error != "" || result.After.Error != "" {return fmt.Errorf("host update receipt contains non-persistable detail")}- req := agentexec.HostUpdatePayload{RequestID: identity.AttemptID, ActionID: identity.ActionID, Operation: identity.OperationKind, OperationVersion: identity.OperationVersion, RequestDigest: identity.RequestDigest, ExpectedInventoryHash: result.Before.InventoryHash}- if err := agentexec.ValidateHostUpdatePayload(&req); err != nil {- return err- }- return agentexec.ValidateHostUpdateResultForRequest(req, result)+ return agentexec.ValidateHostUpdateReceiptForIdentity(identity, result)}},agentexec.HostStorageCleanupReceiptKind: {agentexec.HostAPTReceiptVersion: func(identity operationreceipt.Identity, payload json.RawMessage) error {result, err := agentexec.DecodeHostStorageCleanupResultPayload(payload)@@ -890,11 +886,7 @@ func hostOperationReceiptConfig() operationreceipt.Config {if result.Before.Error != "" || result.After.Error != "" {return fmt.Errorf("host cleanup receipt contains non-persistable detail")}- req := agentexec.HostStorageCleanupPayload{RequestID: identity.AttemptID, ActionID: identity.ActionID, Operation: identity.OperationKind, OperationVersion: identity.OperationVersion, RequestDigest: identity.RequestDigest, ExpectedFingerprint: result.Before.Fingerprint}- if err := agentexec.ValidateHostStorageCleanupPayload(&req); err != nil {- return err- }- return agentexec.ValidateHostStorageCleanupResultForRequest(req, result)+ return agentexec.ValidateHostStorageCleanupReceiptForIdentity(identity, result)}},agentexec.DockerContainerLifecycleReceiptKind: {agentexec.DockerContainerLifecycleReceiptVersion: func(identity operationreceipt.Identity, payload json.RawMessage) error {result, err := agentexec.DecodeDockerContainerLifecycleResultPayload(payload)diff --git a/internal/hostagent/commands_host_update_test.go b/internal/hostagent/commands_host_update_test.goindex f300a05246..ea9bf2a02a 100644--- a/internal/hostagent/commands_host_update_test.go+++ b/internal/hostagent/commands_host_update_test.go@@ -141,3 +141,59 @@ func TestCommandClientHandlesTypedHostUpdateWithoutExecuteCommand(t *testing.T)t.Fatal("command client did not stop")}}++func TestHostUpdateInventoryDriftReceiptCompletesAndReplaysWithAdmittedIdentity(t *testing.T) {+ receipts, err := operationreceipt.Open(filepath.Join(t.TempDir(), "receipts.db"), hostOperationReceiptConfig())+ if err != nil {+ t.Fatal(err)+ }+ defer receipts.Close()++ req := agentexec.HostUpdatePayload{RequestID: "drift.dispatch.1", ActionID: "drift", Operation: agentexec.HostUpdateOperationInstall, ExpectedInventoryHash: "sha256:" + strings.Repeat("a", 64)}+ if err := agentexec.BindHostUpdatePayload(&req); err != nil {+ t.Fatal(err)+ }+ identity := agentexec.HostUpdateOperationIdentity("agent-1", req)+ if _, admitted, err := receipts.Admit(identity); err != nil || !admitted {+ t.Fatalf("admit=%v err=%v", admitted, err)+ }+ if _, err := receipts.MarkStarted(identity); err != nil {+ t.Fatal(err)+ }+ now := time.Now().UTC()+ result := agentexec.HostUpdateResultPayload{+ RequestID: req.RequestID, ActionID: req.ActionID, ExecutionPhase: agentexec.HostUpdatePhaseRefresh, Verification: agentexec.HostUpdateVerificationInconclusive,+ Before: agentexec.HostPackageUpdateSnapshot{Supported: true, Manager: "apt", InventoryHash: "sha256:" + strings.Repeat("b", 64), PendingCount: 2, CheckedAt: now.Add(-time.Second)},+ After: agentexec.HostPackageUpdateSnapshot{Supported: true, Manager: "apt", InventoryHash: "sha256:" + strings.Repeat("b", 64), PendingCount: 2, CheckedAt: now},+ }+ raw, err := json.Marshal(result)+ if err != nil {+ t.Fatal(err)+ }+ envelope := operationreceipt.TerminalEnvelope{Kind: agentexec.HostUpdateReceiptKind, Version: agentexec.HostAPTReceiptVersion, Payload: raw}+ record, err := receipts.Complete(identity, envelope)+ if err != nil || record.State != operationreceipt.StateTerminal {+ t.Fatalf("complete record=%+v err=%v", record, err)+ }+ if replay, admitted, err := receipts.Admit(identity); err != nil || admitted || replay.State != operationreceipt.StateTerminal || string(replay.Result) != string(raw) {+ t.Fatalf("replay record=%+v admitted=%v err=%v", replay, admitted, err)+ }++ wrongRequest := result+ wrongRequest.RequestID = "other.dispatch.1"+ wrongRaw, _ := json.Marshal(wrongRequest)+ if _, err := receipts.Complete(identity, operationreceipt.TerminalEnvelope{Kind: agentexec.HostUpdateReceiptKind, Version: agentexec.HostAPTReceiptVersion, Payload: wrongRaw}); err == nil {+ t.Fatal("wrong request id accepted")+ }+ wrongAction := result+ wrongAction.ActionID = "other"+ wrongRaw, _ = json.Marshal(wrongAction)+ if _, err := receipts.Complete(identity, operationreceipt.TerminalEnvelope{Kind: agentexec.HostUpdateReceiptKind, Version: agentexec.HostAPTReceiptVersion, Payload: wrongRaw}); err == nil {+ t.Fatal("wrong action id accepted")+ }+ wrongDigest := identity+ wrongDigest.RequestDigest = "sha256:" + strings.Repeat("c", 64)+ if _, err := receipts.Complete(wrongDigest, envelope); err == nil {+ t.Fatal("wrong admitted request digest accepted")+ }+}diff --git a/internal/hostagent/commands_storage_cleanup_test.go b/internal/hostagent/commands_storage_cleanup_test.goindex 1072d3e12a..3892cc5b94 100644--- a/internal/hostagent/commands_storage_cleanup_test.go+++ b/internal/hostagent/commands_storage_cleanup_test.go@@ -112,3 +112,46 @@ func TestCommandClientHandlesTypedHostStorageCleanup(t *testing.T) {t.Fatal("command client did not stop")}}++func TestHostStorageCleanupFingerprintDriftReceiptCompletesAndReplaysWithAdmittedIdentity(t *testing.T) {+ receipts, err := operationreceipt.Open(filepath.Join(t.TempDir(), "receipts.db"), hostOperationReceiptConfig())+ if err != nil {+ t.Fatal(err)+ }+ defer receipts.Close()++ req := agentexec.HostStorageCleanupPayload{RequestID: "drift.dispatch.1", ActionID: "drift", Operation: agentexec.HostStorageCleanupOperationPackageCache, ExpectedFingerprint: "sha256:" + strings.Repeat("a", 64)}+ if err := agentexec.BindHostStorageCleanupPayload(&req); err != nil {+ t.Fatal(err)+ }+ identity := agentexec.HostStorageCleanupOperationIdentity("agent-1", req)+ if _, admitted, err := receipts.Admit(identity); err != nil || !admitted {+ t.Fatalf("admit=%v err=%v", admitted, err)+ }+ if _, err := receipts.MarkStarted(identity); err != nil {+ t.Fatal(err)+ }+ now := time.Now().UTC()+ result := agentexec.HostStorageCleanupResultPayload{+ RequestID: req.RequestID, ActionID: req.ActionID, ExecutionPhase: agentexec.HostStorageCleanupPhasePreflight, Verification: agentexec.HostStorageCleanupVerificationInconclusive,+ Before: agentexec.HostStorageCleanupSnapshot{Supported: true, Provider: "apt-package-cache", Fingerprint: "sha256:" + strings.Repeat("b", 64), ReclaimableBytes: 10, CheckedAt: now.Add(-time.Second)},+ After: agentexec.HostStorageCleanupSnapshot{Supported: true, Provider: "apt-package-cache", Fingerprint: "sha256:" + strings.Repeat("b", 64), ReclaimableBytes: 10, CheckedAt: now},+ }+ raw, err := json.Marshal(result)+ if err != nil {+ t.Fatal(err)+ }+ envelope := operationreceipt.TerminalEnvelope{Kind: agentexec.HostStorageCleanupReceiptKind, Version: agentexec.HostAPTReceiptVersion, Payload: raw}+ record, err := receipts.Complete(identity, envelope)+ if err != nil || record.State != operationreceipt.StateTerminal {+ t.Fatalf("complete record=%+v err=%v", record, err)+ }+ if replay, admitted, err := receipts.Admit(identity); err != nil || admitted || replay.State != operationreceipt.StateTerminal || string(replay.Result) != string(raw) {+ t.Fatalf("replay record=%+v admitted=%v err=%v", replay, admitted, err)+ }+ wrongDigest := identity+ wrongDigest.RequestDigest = "sha256:" + strings.Repeat("c", 64)+ if _, err := receipts.Complete(wrongDigest, envelope); err == nil {+ t.Fatal("wrong admitted request digest accepted")+ }+}