From a6a9ff0043278433ebf1d4ab8809d6fbef39db24 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 10 Jun 2026 01:19:37 -0700 Subject: [PATCH] phase38: add dry-run action evidence gate --- .../core/ops/observation_bundle_test.go | 57 ++++++++++++++++++- seaweed-block/core/ops/observation_report.go | 14 ++++- seaweed-block/internal/docs/current-plan.md | 22 ++++--- 3 files changed, 80 insertions(+), 13 deletions(-) diff --git a/seaweed-block/core/ops/observation_bundle_test.go b/seaweed-block/core/ops/observation_bundle_test.go index abaa9968ff..36ce342586 100644 --- a/seaweed-block/core/ops/observation_bundle_test.go +++ b/seaweed-block/core/ops/observation_bundle_test.go @@ -412,25 +412,69 @@ func TestObservationBundle_CarriesUnsupportedLoopbackAttachIntoManagedStatus(t * if managed.Status != ManagedVolumeStatusBlocked || managed.ReasonCode != ReasonPublishTargetLoopbackCrossNode { t.Fatalf("managed=%+v", managed) } - if !hasManagedVolumeAction(managed.Actions, ManagedVolumeActionReinstallExternalISCSI) { + action := findManagedVolumeAction(managed.Actions, ManagedVolumeActionReinstallExternalISCSI) + if action == nil { t.Fatalf("missing external iSCSI dry-run action: %+v", managed.Actions) } + if action.Decision != ManagedVolumeActionDecisionAllowed || + action.Mode != ManagedVolumeActionModeDryRun || + action.SideEffectClass != ManagedVolumeSideEffectSafeK8S || + action.OwnerExecutor != "installer_or_operator" || + action.EvidenceRequired != "loopback_cross_node_evidence" { + t.Fatalf("unexpected external iSCSI action evaluation: %+v", *action) + } + + contract := ManagedVolumeOperatorContractFromProjection(managed) + operatorAction := findManagedVolumeOperatorAction(contract.AllowedActions, ManagedVolumeActionReinstallExternalISCSI) + if operatorAction == nil { + t.Fatalf("missing operator action: %+v", contract.AllowedActions) + } + if operatorAction.Decision != ManagedVolumeActionDecisionAllowed || + operatorAction.MutationAllowed || + operatorAction.EvidenceRequired != "loopback_cross_node_evidence" { + t.Fatalf("unexpected operator action contract: %+v", *operatorAction) + } + + snapshot := BuildOperatorFoundationSnapshot(cluster) + snapshotAction := findManagedVolumeOperatorAction(snapshot.Volumes[0].AllowedActions, ManagedVolumeActionReinstallExternalISCSI) + if snapshotAction == nil { + t.Fatalf("missing snapshot action: %+v", snapshot.Volumes[0].AllowedActions) + } + if snapshotAction.Decision != ManagedVolumeActionDecisionAllowed || + snapshotAction.MutationAllowed || + snapshot.Mutation.MutationAllowed { + t.Fatalf("unexpected snapshot action/boundary: action=%+v mutation=%+v", *snapshotAction, snapshot.Mutation) + } summary := RenderObservationReportSummary(cluster) for _, want := range []string{ "volume=pvc-loopback status=blocked pvc=default/demo-pvc primary=r1@m01 frontend=127.0.0.1:3260", "managed_volume=pvc-loopback status=blocked reason=publish_target_loopback_cross_node", "managed_volume_condition=Ready status=False reason=publish_target_loopback_cross_node severity=warning", - "managed_volume_action=safe_k8s.reinstall_external_iscsi mode=dry_run side_effect=safe_k8s executor=installer_or_operator", + "managed_volume_action=safe_k8s.reinstall_external_iscsi mode=dry_run side_effect=safe_k8s executor=installer_or_operator decision=allowed", + "managed_volume_action_evidence_required=safe_k8s.reinstall_external_iscsi loopback_cross_node_evidence", } { if !strings.Contains(summary, want) { t.Fatalf("summary missing %q:\n%s", want, summary) } } + explain := RenderObservationExplainText(cluster) + for _, want := range []string{ + "managed_volume_action safe_k8s.reinstall_external_iscsi mode=dry_run side_effect=safe_k8s executor=installer_or_operator decision=allowed", + "managed_volume_action_evidence_required safe_k8s.reinstall_external_iscsi loopback_cross_node_evidence", + } { + if !strings.Contains(explain, want) { + t.Fatalf("explain missing %q:\n%s", want, explain) + } + } + server := httptest.NewServer(NewObservationDashboardHandler(cluster)) defer server.Close() assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"reason_code": "publish_target_loopback_cross_node"`) + assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"decision": "allowed"`) + assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"mutation_allowed": false`) + assertDashboardEndpointContains(t, server.URL+"/"+ObservationOperatorSnapshotArtifact, `"evidence_required": "loopback_cross_node_evidence"`) assertDashboardEndpointContains(t, server.URL+"/"+ObservationReportTextArtifact, "managed_volume=pvc-loopback status=blocked reason=publish_target_loopback_cross_node") } @@ -833,6 +877,15 @@ func writeStatusEndpointUnreachableInventory(t *testing.T, dir string) { mustWriteInventory(t, inventoryDir, inventory) } +func findManagedVolumeOperatorAction(actions []ManagedVolumeOperatorAction, actionType string) *ManagedVolumeOperatorAction { + for i := range actions { + if actions[i].Type == actionType { + return &actions[i] + } + } + return nil +} + func mustWrite(t *testing.T, path, content string) { t.Helper() if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { diff --git a/seaweed-block/core/ops/observation_report.go b/seaweed-block/core/ops/observation_report.go index e4dd6703ad..e641052ee3 100644 --- a/seaweed-block/core/ops/observation_report.go +++ b/seaweed-block/core/ops/observation_report.go @@ -128,11 +128,21 @@ func renderManagedProjectionSummary(b *strings.Builder, managed ManagedVolumePro emptyAsDash(condition.Severity)) } for _, action := range managed.Actions { - fmt.Fprintf(b, "managed_volume_action=%s mode=%s side_effect=%s executor=%s\n", + fmt.Fprintf(b, "managed_volume_action=%s mode=%s side_effect=%s executor=%s decision=%s", emptyAsDash(action.Type), emptyAsDash(action.Mode), emptyAsDash(action.SideEffectClass), - emptyAsDash(action.OwnerExecutor)) + emptyAsDash(action.OwnerExecutor), + emptyAsDash(action.Decision)) + if action.DecisionReason != "" { + fmt.Fprintf(b, " reason=%s", action.DecisionReason) + } + b.WriteByte('\n') + if action.EvidenceRequired != "" { + fmt.Fprintf(b, "managed_volume_action_evidence_required=%s %s\n", + emptyAsDash(action.Type), + action.EvidenceRequired) + } } } diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index 6eda9656dc..b5c7634fdd 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -1,6 +1,6 @@ # Current Plan: Phase 38 - Lifecycle Action Model Executable Contract -Status: active, 18% complete. Started on 2026-06-09. +Status: active, 78% complete. Started on 2026-06-09. Branch: `phase33-testops-failure-hardening` @@ -145,16 +145,16 @@ TestOps/QA replay gate for rejected action evidence Goal: prove one non-mutating dry-run action is executable as a dry-run decision and still does not mutate the cluster. -Status: pending. +Status: dev-complete; QA/internal review pending. Acceptance: ```text -[ ] safe_k8s.reinstall_external_iscsi can evaluate allowed in dry-run mode -[ ] evaluation names preconditions, executor, invariant refs, evidence refs -[ ] no Helm release, Deployment, PVC/PV, image, iSCSI, multipath, or hostPath +[x] safe_k8s.reinstall_external_iscsi can evaluate allowed in dry-run mode +[x] evaluation names preconditions, executor, invariant refs, evidence refs +[x] no Helm release, Deployment, PVC/PV, image, iSCSI, multipath, or hostPath mutation occurs -[ ] report/dashboard/operator-snapshot agree on the dry-run boundary +[x] report/dashboard/operator-snapshot agree on the dry-run boundary ``` Verification: @@ -212,9 +212,13 @@ QA strict rerun or replay from clean bundle `authority.request_promotion` stays rejected with `policy_disabled`, and the rendered evidence names side-effect class, executor, evidence requirement, and `mutation_allowed=false`. +- 78%: D5 dev-complete. A cross-node loopback bundle now proves + `safe_k8s.reinstall_external_iscsi` evaluates `allowed` in `dry_run` mode + while the operator contract and snapshot keep `mutation_allowed=false`. + `summary.txt`, explain text, dashboard `/operator-snapshot.json`, and the + operator snapshot agree on the decision and required evidence. ## Next Step -Add D5 dry-run action evidence for `safe_k8s.reinstall_external_iscsi`: replay a -cross-node loopback bundle, prove the action evaluates `allowed` in dry-run -mode, and confirm no Kubernetes/storage mutation is performed or allowed. +Run the D6 close gate: scoped tests, Helm render/lint, diff hygiene, and QA +replay/strict validation for rejected and dry-run action evidence.