diff --git a/seaweed-block/core/recovery/recover_a_oracle_test.go b/seaweed-block/core/recovery/recover_a_oracle_test.go new file mode 100644 index 0000000000..fe987c4ba7 --- /dev/null +++ b/seaweed-block/core/recovery/recover_a_oracle_test.go @@ -0,0 +1,258 @@ +package recovery + +// Pure-function dual-oracle table test for the recover() semantics +// migration. Source: sw-block/design/recover-semantics-adjustment-plan.md +// §8.2 (QA-canonical handoff). +// +// This file is INTENTIONALLY decoupled from production types — no +// imports from core/transport, core/replication, or any other +// production-package. The state struct, oracle functions, and +// counterexample table all live test-local. Per §8.2.8 +// anti-discipline check #3: pure-function oracle test must NOT +// import production types. +// +// What this file proves: +// +// BandOracle (legacy recover(a,b)): walApplied ≥ frozen target Y ∧ +// baseDone. This is the existing CI gate; stays GREEN as the +// "this slice closed at band Y" semantic. +// +// RecoverAOracle (§IV.2.1 conjunct): baseDone ∧ PrimaryWalLegOk ∧ +// BarrierWitness with matching engine cut. AchievedLSN reported +// as witness, NOT compared against TargetLSN. Y is enumerator +// only. +// +// The 8-case counterexample table (§8.2.3) demonstrates the two +// oracles are mutually independent — Band-true does not imply +// RecoverA-true (cases #1/#6/#7), and Band-false does not imply +// RecoverA-false (case #8). This is the dual-oracle minimal +// expression: neither is implied by the other. +// +// Pinned by §IV.2 / §IV.2.1 / §I P8 (consensus); plan §8.1 + §8.2. + +import "testing" + +// RecoverState — state vector for dual-oracle table tests. Test-local +// data shape; not coupled to production types per §8.2.1. +type RecoverState struct { + Cursor uint64 // shipper cursor (last emitted LSN) + Head uint64 // primary's WAL head observed at oracle eval time + BaseDone bool // bitmap MarkBaseComplete fired + LiveClassEmitted bool // ever emitted SessionLive frame (PrimaryLiveTail seed) + WalApplied uint64 // replica's high-water (legacy semantic) + TargetLSN uint64 // session contract Y (audit-band only) + Barrier *BarrierWitness // nil if no handshake yet +} + +// BarrierWitness — handshake outcome at a specific engine cut. +// AchievedLSN is reported AS-OBSERVED at the cut (witness), not as +// a target-crossing verdict. +type BarrierWitness struct { + CutID uint64 // engine-authored CheckpointCutSeq + Achieved uint64 // replica-reported witness LSN at the cut + CutMatch bool // engine cut on req == replica's witness cut +} + +// BandOracle — legacy recover(a,b) closure: walApplied ≥ frozen target ∧ +// baseDone. Stays in CI as today's GREEN gate; explained as "this slice +// closed at band Y", NOT "recover(a) closure". +// +// Source: §8.2.2. +func BandOracle(s RecoverState) bool { + return s.BaseDone && s.WalApplied >= s.TargetLSN +} + +// RecoverAOracle — §IV.2.1 conjunct: baseDone ∧ PrimaryWalLegOk ∧ +// BarrierWitness. PrimaryWalLegOk = PrimaryDebtZero ∨ PrimaryLiveTail. +// Barrier witness must echo a matching engine cut; AchievedLSN reported +// as witness, NOT compared against TargetLSN. +// +// §IV.2(2) guard simplified at the unit layer to LiveClassEmitted; +// component-layer exercises the real guard. +// +// Source: §8.2.2. +func RecoverAOracle(s RecoverState) bool { + if !s.BaseDone { + return false + } + primaryDebtZero := s.Cursor == s.Head + primaryLiveTail := s.LiveClassEmitted // §IV.2(2) guard simplified for unit + walLegOk := primaryDebtZero || primaryLiveTail + if !walLegOk { + return false + } + if s.Barrier == nil { + return false + } + if !s.Barrier.CutMatch { + return false + } + return true +} + +// TestRecoverA_DualOracle_Counterexamples — §8.2.3 8-case table. +// +// Mutual independence demonstration: +// +// Band-true does NOT imply RecoverA-true: +// case #1 (FS-1): cursor