From 67b0f2bb454aafc802e581a2e8e54b439af788a9 Mon Sep 17 00:00:00 2001 From: Ted H Date: Sat, 14 Nov 2026 16:44:36 -0500 Subject: [PATCH 1/5] worker: restrict dispatch during ledger recovery Agent: codex/gpt-6.1-terra --- apps/worker/jobs_members.go | 10 ++++++++ apps/worker/recovery_mode.go | 25 +++++++++++++++++++ apps/worker/recovery_mode_test.go | 29 ++++++++++++++++++++++ apps/worker/worker.go | 2 +- internal/db/outbox.go | 41 +++++++++++++++++++++++++++++++ internal/exits/exits.go | 24 ++++++++++++++++++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 apps/worker/recovery_mode.go create mode 100644 apps/worker/recovery_mode_test.go diff --git a/apps/worker/jobs_members.go b/apps/worker/jobs_members.go index 80d96e502..6cd97fb6c 100644 --- a/apps/worker/jobs_members.go +++ b/apps/worker/jobs_members.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "slices" "time" "github.com/TED-H-com/Freedom-VPN/internal/config" @@ -404,6 +405,15 @@ func memberRunner(services *membersruntime.Services) Runner { } func scheduleMemberWork(ctx context.Context, s *membersruntime.Services, name string, interval time.Duration) error { + if slices.Contains(recoveryWaitingTypes, name) { + var normal bool + if err := s.HTTP.Members.Pool.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM usage_ledger_state WHERE mode='normal')`).Scan(&normal); err != nil { + return err + } + if !normal { + return nil + } + } raw, e := canonjson.Marshal([]string{name, time.Now().UTC().Truncate(interval).Format(time.RFC3339)}) if e != nil { return e diff --git a/apps/worker/recovery_mode.go b/apps/worker/recovery_mode.go new file mode 100644 index 000000000..689190de0 --- /dev/null +++ b/apps/worker/recovery_mode.go @@ -0,0 +1,25 @@ +package worker + +// Recovery permits only work that can make restored state safe or converge it. +var recoveryAllowedTypes = []string{ + "member.entitlement_changed", "member.grant_revoked", "member.suspended", + "device.authorized", "device.revoked", "netbird.device_sync", "members.reconcile", + "billing.reconcile", "billing.inbox_received", + "node.staleness.sweep", "node.generation_hold.check", "node.peer.observe", + "node.resolver_documents.reconcile", "node.netbird_routes.reconcile", + "dns.publish", "dns.feed.refresh", +} + +const recoveryFilteredType = "node.publication_changed" + +var recoveryWithdrawalKinds = []string{ + "node.unpublish", "node.disable", "node.revoke", "node.retire", +} + +// These registered types wait until normal mode. Unlisted types also wait. +var recoveryWaitingTypes = []string{ + "devices.discover", "node.reconcile", "fleet.update_created", "fleet.first_sync_created", + "fleet.update_retry", "fleet.release_support_changed", "node.updated", "node.provision.requested", + "node.peer.discover", "release.verify", "policy.activated", "fup.evaluate", + "fup.member_generation_changed", "usage.projection_rebuild", "usage.retention_purge", +} diff --git a/apps/worker/recovery_mode_test.go b/apps/worker/recovery_mode_test.go new file mode 100644 index 000000000..ab8f1460f --- /dev/null +++ b/apps/worker/recovery_mode_test.go @@ -0,0 +1,29 @@ +package worker + +import "testing" + +func TestRecoveryModeT7_RegistrationCoverage(t *testing.T) { + groups := map[string][]string{ + "allowed": recoveryAllowedTypes, + "filtered": {recoveryFilteredType}, + "waiting": recoveryWaitingTypes, + } + membership := make(map[string]string) + for group, types := range groups { + for _, eventType := range types { + if previous, exists := membership[eventType]; exists { + t.Errorf("event %q occurs in %s and %s", eventType, previous, group) + } + membership[eventType] = group + } + } + registration, err := productionRegistration() + if err != nil { + t.Fatal(err) + } + for eventType := range registration.Jobs { + if _, exists := membership[eventType]; !exists { + t.Errorf("registered event %q has no recovery classification", eventType) + } + } +} diff --git a/apps/worker/worker.go b/apps/worker/worker.go index a1ba39e91..7be921532 100644 --- a/apps/worker/worker.go +++ b/apps/worker/worker.go @@ -105,7 +105,7 @@ func (d *Dispatcher) Run(ctx context.Context) error { return nil } func (d *Dispatcher) Once(ctx context.Context) (bool, error) { - events, e := db.ClaimOutbox(ctx, d.pool, d.name, 1, d.config.Lease) + events, e := db.ClaimOutboxByLedgerMode(ctx, d.pool, d.name, 1, d.config.Lease, recoveryAllowedTypes, recoveryFilteredType, recoveryWithdrawalKinds) if e != nil { return false, e } diff --git a/internal/db/outbox.go b/internal/db/outbox.go index 4021761a1..7de9a8091 100644 --- a/internal/db/outbox.go +++ b/internal/db/outbox.go @@ -85,6 +85,47 @@ func ClaimOutbox(ctx context.Context, pool *pgxpool.Pool, worker string, n int, return events, nil } +// ClaimOutboxByLedgerMode limits claims during ledger recovery without leasing +// rows that must wait. A missing ledger state is treated as restricted. +func ClaimOutboxByLedgerMode(ctx context.Context, pool *pgxpool.Pool, worker string, n int, leaseFor time.Duration, allowedTypes []string, filteredType string, allowedKinds []string) ([]ClaimedEvent, error) { + if worker == "" || n < 1 || n > 1000 || leaseFor < time.Millisecond || leaseFor > 24*time.Hour { + return nil, errors.New("invalid outbox claim") + } + token, err := uuid.NewV7() + if err != nil { + return nil, err + } + rows, err := pool.Query(ctx, `WITH candidates AS ( + SELECT id FROM outbox_events WHERE delivered_at IS NULL AND available_at<=clock_timestamp() + AND (lease_until IS NULL OR lease_until<=clock_timestamp()) + AND (EXISTS (SELECT 1 FROM usage_ledger_state WHERE mode='normal') + OR event_type=ANY($5::text[]) + OR (event_type=$6 AND EXISTS (SELECT 1 FROM operations WHERE id=CASE + WHEN jsonb_typeof(payload->'operation_id')='string' + AND pg_input_is_valid(payload->>'operation_id','uuid') + THEN (payload->>'operation_id')::uuid END AND kind=ANY($7::text[])))) + ORDER BY available_at,id FOR UPDATE SKIP LOCKED LIMIT $1 + ), claimed AS (UPDATE outbox_events e SET lease_owner=$2,lease_token=$3,lease_until=clock_timestamp()+$4::bigint*interval '1 millisecond',attempt=attempt+1 + FROM candidates c WHERE e.id=c.id + RETURNING e.id,e.aggregate_id,e.aggregate_type,e.aggregate_version::text,e.event_type,e.schema_version,e.payload,e.available_at,e.lease_until,e.attempt) SELECT * FROM claimed ORDER BY available_at,id`, n, worker, token, leaseFor.Milliseconds(), allowedTypes, filteredType, allowedKinds) + if err != nil { + return nil, MapError(err) + } + defer rows.Close() + var events []ClaimedEvent + for rows.Next() { + evt := ClaimedEvent{Worker: worker, LeaseToken: token} + if err := rows.Scan(&evt.ID, &evt.AggregateID, &evt.AggregateType, &evt.AggregateVersion, &evt.EventType, &evt.SchemaVersion, &evt.Payload, &evt.AvailableAt, &evt.LeaseUntil, &evt.Attempt); err != nil { + return nil, err + } + events = append(events, evt) + } + if err := rows.Err(); err != nil { + return nil, MapError(err) + } + return events, nil +} + // CompleteOutbox requires current, unexpired ownership and read-back evidence // already obtained by the caller. A late worker cannot complete a newer claim. func CompleteOutbox(ctx context.Context, pool *pgxpool.Pool, evt ClaimedEvent) error { diff --git a/internal/exits/exits.go b/internal/exits/exits.go index a4afe28a2..8aa90de59 100644 --- a/internal/exits/exits.go +++ b/internal/exits/exits.go @@ -656,6 +656,14 @@ func (s *Service) ExecuteOperation(ctx context.Context, opID uuid.UUID) (api.Ope return op, nil } + superseded, err := s.supersedeContradictoryPublication(ctx, opID, op.Resource.Id) + if err != nil { + return api.Operation{}, err + } + if superseded { + return nodes.GetOperation(ctx, s.pool, opID) + } + nodeID := op.Resource.Id switch string(op.Kind) { case nodes.OpKindPublish: @@ -672,6 +680,22 @@ func (s *Service) ExecuteOperation(ctx context.Context, opID uuid.UUID) (api.Ope } } +func (s *Service) supersedeContradictoryPublication(ctx context.Context, opID, nodeID uuid.UUID) (bool, error) { + var superseded bool + err := commandtx.InTx(ctx, s.pool, db.TxOptions{}, func(tx pgx.Tx) error { + tag, err := tx.Exec(ctx, `UPDATE operations SET status='superseded',completed_at=$3,resource_version=coalesce(resource_version,0)+1 + WHERE id=$1 AND status IN ('pending','running') AND EXISTS ( + SELECT 1 FROM exits WHERE node_id=$2 AND + ((operations.kind='node.publish' AND publication_intent<>'published') OR + (operations.kind IN ('node.unpublish','node.disable') AND publication_intent='published')))`, opID, nodeID, s.now().UTC()) + if err == nil { + superseded = tag.RowsAffected() == 1 + } + return err + }) + return superseded, err +} + // executePublish executes the ยง5.2 step 2-3 publish workflow: // 1. Ensures desired state is compiled at >= desired_generation. // 2. Confirms node's isolation (safety_status=passed), readiness, and policy ACK (applied_config_generation >= desired_generation). From 226c954bcc4d29618a6caf63fa63a876e9cb5690 Mon Sep 17 00:00:00 2001 From: Ted H Date: Sat, 14 Nov 2026 16:54:46 -0500 Subject: [PATCH 2/5] worker: test recovery dispatch and withdrawal ordering Agent: codex/gpt-6.1-terra --- apps/worker/recovery_mode_integration_test.go | 321 ++++++++++++++++++ internal/exits/exits.go | 15 +- .../exits/intent_guard_integration_test.go | 170 ++++++++++ .../recovery_withdrawal_integration_test.go | 111 ++++++ 4 files changed, 611 insertions(+), 6 deletions(-) create mode 100644 apps/worker/recovery_mode_integration_test.go create mode 100644 internal/exits/intent_guard_integration_test.go create mode 100644 internal/nodes/httpwire/recovery_withdrawal_integration_test.go diff --git a/apps/worker/recovery_mode_integration_test.go b/apps/worker/recovery_mode_integration_test.go new file mode 100644 index 000000000..7ab22721a --- /dev/null +++ b/apps/worker/recovery_mode_integration_test.go @@ -0,0 +1,321 @@ +//go:build integration + +package worker + +import ( + "context" + "encoding/json" + "reflect" + "testing" + "time" + + "github.com/TED-H-com/Freedom-VPN/internal/db" + "github.com/TED-H-com/Freedom-VPN/internal/db/dbtest" + memberscore "github.com/TED-H-com/Freedom-VPN/internal/members" + "github.com/TED-H-com/Freedom-VPN/internal/members/httpadapter" + membersruntime "github.com/TED-H-com/Freedom-VPN/internal/members/runtime" + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" +) + +func recoveryEvent(t *testing.T, pool *pgxpool.Pool, eventType string, payload any, at time.Time) uuid.UUID { + t.Helper() + raw, err := json.Marshal(payload) + if err != nil { + t.Fatal(err) + } + id := uuid.New() + err = db.InTx(t.Context(), pool, db.TxOptions{}, func(tx pgx.Tx) error { + return db.EnqueueOutbox(t.Context(), tx, db.OutboxEvent{ + ID: id, AggregateID: uuid.New(), AggregateType: "node", AggregateVersion: "1", + EventType: eventType, SchemaVersion: 1, Payload: raw, AvailableAt: at, + }) + }) + if err != nil { + t.Fatal(err) + } + return id +} + +func recoveryOperation(t *testing.T, pool *pgxpool.Pool, kind string) uuid.UUID { + t.Helper() + id := uuid.New() + if _, err := pool.Exec(t.Context(), `INSERT INTO operations(id,kind,principal,resource_type,resource_id) VALUES($1,$2,'TEST ONLY','node',$3)`, id, kind, uuid.New()); err != nil { + t.Fatal(err) + } + return id +} + +func recoverySetMode(t *testing.T, pool *pgxpool.Pool, mode string) { + t.Helper() + if _, err := pool.Exec(t.Context(), `UPDATE usage_ledger_state SET mode=$1`, mode); err != nil { + t.Fatal(err) + } +} + +func recoveryRemoveLedgerState(t *testing.T, pool *pgxpool.Pool) { + t.Helper() + // Exercise a missing singleton in this disposable database only. + if _, err := pool.Exec(t.Context(), `ALTER TABLE usage_ledger_state DISABLE TRIGGER usage_ledger_state_keep`); err != nil { + t.Fatal(err) + } + if _, err := pool.Exec(t.Context(), `DELETE FROM usage_ledger_state`); err != nil { + t.Fatal(err) + } +} + +func recoveryClaim(t *testing.T, pool *pgxpool.Pool) []db.ClaimedEvent { + t.Helper() + events, err := db.ClaimOutboxByLedgerMode(t.Context(), pool, "TEST ONLY recovery", 1000, time.Minute, recoveryAllowedTypes, recoveryFilteredType, recoveryWithdrawalKinds) + if err != nil { + t.Fatal(err) + } + return events +} + +func TestRecoveryModeT1_ClaimByMode(t *testing.T) { + pool := dbtest.New(t) + registration, err := productionRegistration() + if err != nil { + t.Fatal(err) + } + // This expected set is independent of the worker's classification. + allowed := map[string]bool{} + for _, eventType := range []string{ + "member.entitlement_changed", "member.grant_revoked", "member.suspended", "device.authorized", "device.revoked", "netbird.device_sync", "members.reconcile", + "billing.reconcile", "billing.inbox_received", "node.staleness.sweep", "node.generation_hold.check", "node.peer.observe", "node.resolver_documents.reconcile", + "node.netbird_routes.reconcile", "dns.publish", "dns.feed.refresh", + } { + allowed[eventType] = true + } + all, restricted := map[uuid.UUID]string{}, map[uuid.UUID]string{} + at := time.Now().Add(-time.Hour) + for eventType := range registration.Jobs { + if eventType == "node.publication_changed" { + continue + } + id := recoveryEvent(t, pool, eventType, map[string]any{}, at) + all[id] = eventType + if allowed[eventType] { + restricted[id] = eventType + } + } + // Include the planned type even when it is not yet registered. + if _, registered := registration.Jobs["node.netbird_routes.reconcile"]; !registered { + id := recoveryEvent(t, pool, "node.netbird_routes.reconcile", map[string]any{}, at) + all[id], restricted[id] = "node.netbird_routes.reconcile", "node.netbird_routes.reconcile" + } + for _, eventType := range []string{"node.revoked", "node.retired", "test.unknown"} { + all[recoveryEvent(t, pool, eventType, map[string]any{}, at)] = eventType + } + var withdrawalEvent, withdrawalOperation uuid.UUID + for _, kind := range []string{"node.publish", "node.unpublish", "node.disable", "node.revoke", "node.retire"} { + op := recoveryOperation(t, pool, kind) + id := recoveryEvent(t, pool, "node.publication_changed", map[string]any{"operation_id": op}, at) + if kind == "node.revoke" { + withdrawalEvent, withdrawalOperation = id, op + } + all[id] = kind + if kind != "node.publish" { + restricted[id] = kind + } + } + for _, mode := range []string{"normal", "frozen", "reconciling"} { + t.Run(mode, func(t *testing.T) { + recoverySetMode(t, pool, mode) + if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET lease_owner=NULL,lease_token=NULL,lease_until=NULL,attempt=0`); err != nil { + t.Fatal(err) + } + got := map[uuid.UUID]string{} + for _, event := range recoveryClaim(t, pool) { + got[event.ID] = all[event.ID] + } + want := restricted + if mode == "normal" { + want = all + } + if !reflect.DeepEqual(got, want) { + for id, name := range want { + if _, ok := got[id]; !ok { + t.Errorf("missing claim: %s", name) + } + } + for id, name := range got { + if _, ok := want[id]; !ok { + t.Errorf("unexpected claim: %s", name) + } + } + } + }) + } + t.Run("does_not_lock_ledger_or_operation", func(t *testing.T) { + if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET lease_owner=NULL,lease_token=NULL,lease_until=NULL WHERE id=$1`, withdrawalEvent); err != nil { + t.Fatal(err) + } + tx, err := pool.Begin(t.Context()) + if err != nil { + t.Fatal(err) + } + defer func() { _ = tx.Rollback(t.Context()) }() + if _, err := tx.Exec(t.Context(), `SELECT id FROM usage_ledger_state FOR UPDATE`); err != nil { + t.Fatal(err) + } + if _, err := tx.Exec(t.Context(), `SELECT id FROM operations WHERE id=$1 FOR UPDATE`, withdrawalOperation); err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second) + defer cancel() + events, err := db.ClaimOutboxByLedgerMode(ctx, pool, "TEST ONLY unlocked reads", 1, time.Minute, recoveryAllowedTypes, recoveryFilteredType, recoveryWithdrawalKinds) + if err != nil || len(events) != 1 || events[0].ID != withdrawalEvent { + t.Fatalf("claim with ledger and operation locked: events=%v err=%v", events, err) + } + }) + t.Run("missing_ledger_state", func(t *testing.T) { + recoveryRemoveLedgerState(t, pool) + if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET lease_owner=NULL,lease_token=NULL,lease_until=NULL,attempt=0`); err != nil { + t.Fatal(err) + } + got := map[uuid.UUID]string{} + for _, event := range recoveryClaim(t, pool) { + got[event.ID] = all[event.ID] + } + if !reflect.DeepEqual(got, restricted) { + t.Errorf("missing ledger state claimed %d events, want %d restricted events", len(got), len(restricted)) + } + }) +} + +func recoverySnapshots(t *testing.T, pool *pgxpool.Pool) map[uuid.UUID]string { + t.Helper() + rows, err := pool.Query(t.Context(), `SELECT id,to_jsonb(e)::text FROM outbox_events e ORDER BY id`) + if err != nil { + t.Fatal(err) + } + defer rows.Close() + result := map[uuid.UUID]string{} + for rows.Next() { + var id uuid.UUID + var row string + if err := rows.Scan(&id, &row); err != nil { + t.Fatal(err) + } + result[id] = row + } + if err := rows.Err(); err != nil { + t.Fatal(err) + } + return result +} + +func recoveryDispatcher(t *testing.T, pool *pgxpool.Pool, registry Registry) *Dispatcher { + t.Helper() + d, err := New(pool, registry, Config{Concurrency: 1, Attempts: 2, Lease: time.Minute, JobTimeout: time.Second, Poll: time.Millisecond, Backoff: time.Millisecond, MaxBackoff: time.Second}, nil, nil) + if err != nil { + t.Fatal(err) + } + return d +} + +func TestRecoveryModeT2_WaitingRowsUntouched(t *testing.T) { + pool := dbtest.New(t) + recoverySetMode(t, pool, "reconciling") + at := time.Now().Add(-time.Hour) + first := recoveryEvent(t, pool, "devices.discover", map[string]any{}, at) + for i, eventType := range recoveryWaitingTypes[1:] { + id := recoveryEvent(t, pool, eventType, map[string]any{}, at.Add(time.Duration(i+1)*time.Second)) + if eventType == "node.reconcile" { + if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET attempt=2,lease_owner='TEST ONLY',lease_token=$2,lease_until=clock_timestamp()-interval '1 minute',last_error_code='TEST_RETRY' WHERE id=$1`, id, uuid.New()); err != nil { + t.Fatal(err) + } + } + } + for _, eventType := range []string{"node.revoked", "node.retired", "test.unknown"} { + recoveryEvent(t, pool, eventType, map[string]any{}, at.Add(time.Minute)) + } + op := recoveryOperation(t, pool, "node.publish") + recoveryEvent(t, pool, "node.publication_changed", map[string]any{"operation_id": op}, at.Add(time.Minute)) + recoveryEvent(t, pool, "node.publication_changed", map[string]any{"operation_id": "invalid"}, at.Add(time.Minute)) + dead := recoveryEvent(t, pool, "test.dead", map[string]any{}, at.Add(time.Minute)) + if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET attempt=4,dead_lettered_at=clock_timestamp(),last_error_code='TEST_FAILURE',available_at='infinity' WHERE id=$1`, dead); err != nil { + t.Fatal(err) + } + before := recoverySnapshots(t, pool) + d := recoveryDispatcher(t, pool, Registry{}) + for i := 0; i < 20; i++ { + if worked, err := d.Once(t.Context()); err != nil || worked { + t.Fatalf("restricted dispatch %d: worked=%v err=%v", i, worked, err) + } + } + if after := recoverySnapshots(t, pool); !reflect.DeepEqual(before, after) { + t.Fatal("waiting outbox rows changed") + } + recoverySetMode(t, pool, "normal") + events, err := db.ClaimOutboxByLedgerMode(t.Context(), pool, "TEST ONLY normal", 1, time.Minute, recoveryAllowedTypes, recoveryFilteredType, recoveryWithdrawalKinds) + if err != nil || len(events) != 1 || events[0].ID != first || events[0].Attempt != 1 { + t.Fatalf("first normal claim: events=%v err=%v", events, err) + } +} + +func TestRecoveryModeT3_MalformedPublicationPayloads(t *testing.T) { + pool := dbtest.New(t) + recoverySetMode(t, pool, "reconciling") + for _, payload := range []map[string]any{{}, {"operation_id": "not-a-uuid"}, {"operation_id": 123}, {"operation_id": uuid.NewString()}} { + recoveryEvent(t, pool, "node.publication_changed", payload, time.Now().Add(-time.Minute)) + } + before := recoverySnapshots(t, pool) + if events := recoveryClaim(t, pool); len(events) != 0 { + t.Fatalf("malformed publication events claimed: %v", events) + } + if after := recoverySnapshots(t, pool); !reflect.DeepEqual(before, after) { + t.Fatal("malformed publication events changed") + } +} + +func TestRecoveryModeT4_NoHeadOfLineBlocking(t *testing.T) { + pool := dbtest.New(t) + recoverySetMode(t, pool, "reconciling") + at := time.Now().Add(-time.Hour) + for i := 0; i < 50; i++ { + recoveryEvent(t, pool, "devices.discover", map[string]any{"index": i}, at.Add(time.Duration(i)*time.Second)) + } + want := recoveryEvent(t, pool, "members.reconcile", map[string]any{}, at.Add(time.Minute)) + var claimed uuid.UUID + d := recoveryDispatcher(t, pool, Registry{"members.reconcile": func(_ context.Context, event db.ClaimedEvent) (string, error) { + claimed = event.ID + return "TEST ONLY receipt", nil + }}) + if worked, err := d.Once(t.Context()); err != nil || !worked || claimed != want { + t.Fatalf("allowed event behind waiting rows: worked=%v claimed=%s err=%v", worked, claimed, err) + } +} + +func TestRecoveryModeT6_MemberSchedule(t *testing.T) { + for _, mode := range []string{"reconciling", "normal", "missing"} { + t.Run(mode, func(t *testing.T) { + pool := dbtest.New(t) + if mode == "missing" { + recoveryRemoveLedgerState(t, pool) + } else { + recoverySetMode(t, pool, mode) + } + s := &membersruntime.Services{HTTP: httpadapter.Services{Members: &memberscore.Service{Pool: pool}}, ReconcileInterval: time.Hour, DeviceInterval: time.Hour} + if err := memberScheduleCycle(t.Context(), s); err != nil { + t.Fatal(err) + } + for _, eventType := range []string{"billing.reconcile", "members.reconcile", "devices.discover"} { + var count int + if err := pool.QueryRow(t.Context(), `SELECT count(*) FROM outbox_events WHERE event_type=$1`, eventType).Scan(&count); err != nil { + t.Fatal(err) + } + want := 1 + if mode != "normal" && eventType == "devices.discover" { + want = 0 + } + if count != want { + t.Errorf("%s: got %d rows, want %d", eventType, count, want) + } + } + }) + } +} diff --git a/internal/exits/exits.go b/internal/exits/exits.go index 8aa90de59..93d9ce8fb 100644 --- a/internal/exits/exits.go +++ b/internal/exits/exits.go @@ -656,12 +656,15 @@ func (s *Service) ExecuteOperation(ctx context.Context, opID uuid.UUID) (api.Ope return op, nil } - superseded, err := s.supersedeContradictoryPublication(ctx, opID, op.Resource.Id) - if err != nil { - return api.Operation{}, err - } - if superseded { - return nodes.GetOperation(ctx, s.pool, opID) + switch string(op.Kind) { + case nodes.OpKindPublish, nodes.OpKindUnpublish, nodes.OpKindDisable: + superseded, err := s.supersedeContradictoryPublication(ctx, opID, op.Resource.Id) + if err != nil { + return api.Operation{}, err + } + if superseded { + return nodes.GetOperation(ctx, s.pool, opID) + } } nodeID := op.Resource.Id diff --git a/internal/exits/intent_guard_integration_test.go b/internal/exits/intent_guard_integration_test.go new file mode 100644 index 000000000..31738bacb --- /dev/null +++ b/internal/exits/intent_guard_integration_test.go @@ -0,0 +1,170 @@ +//go:build integration + +package exits + +import ( + "testing" + "time" + + "github.com/TED-H-com/Freedom-VPN/internal/db" + "github.com/TED-H-com/Freedom-VPN/internal/db/dbtest" + "github.com/TED-H-com/Freedom-VPN/internal/nodes" + "github.com/TED-H-com/Freedom-VPN/pkg/api" + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" +) + +type intentGuardFixture struct { + t *testing.T + pool *pgxpool.Pool + nodes *nodes.Service + exits *Service + adapter *FakeNetBirdAdapter + node, incarnation uuid.UUID + exit, release uuid.UUID + now time.Time +} + +func newIntentGuardFixture(t *testing.T, initial api.PublicationIntent) *intentGuardFixture { + t.Helper() + f := &intentGuardFixture{t: t, pool: dbtest.New(t), adapter: NewFakeNetBirdAdapter(), now: time.Date(2026, 10, 29, 14, 0, 0, 0, time.UTC)} + clock := func() time.Time { return f.now } + f.nodes = nodes.NewService(f.pool, nodes.WithClock(clock)) + f.exits = NewService(f.pool, testExitsCompiler(t, f.pool, clock), f.adapter, WithClock(clock)) + f.node, f.incarnation, f.exit, f.release, _ = seedExitTestNode(t, t.Context(), f.pool, initial, "absent") + return f +} + +func (f *intentGuardFixture) set(intent api.PublicationIntent) api.Operation { + f.t.Helper() + _, etag, err := f.nodes.GetNode(f.t.Context(), f.node) + if err != nil { + f.t.Fatal(err) + } + op, _, err := f.exits.SetPublication(f.t.Context(), SetPublicationParams{ + NodeID: f.node, Principal: "admin@example.com", IdempotencyKey: uuid.New(), IfMatch: etag, + Request: api.PublicationRequest{PublicationIntent: intent, Reason: "TEST ONLY intent ordering"}, + }) + if err != nil { + f.t.Fatal(err) + } + return op +} + +func (f *intentGuardFixture) acknowledge() { + f.t.Helper() + detail, _, err := f.nodes.GetNode(f.t.Context(), f.node) + if err != nil { + f.t.Fatal(err) + } + f.now = f.now.Add(5 * time.Second) + submitAckObservation(f.t, f.t.Context(), f.nodes, f.pool, f.node, f.incarnation, f.release, f.now, uint64(detail.ConfigGeneration.Desired), true) +} + +func (f *intentGuardFixture) execute(id uuid.UUID) api.Operation { + f.t.Helper() + op, err := f.exits.ExecuteOperation(f.t.Context(), id) + if err != nil { + f.t.Fatal(err) + } + return op +} + +func (f *intentGuardFixture) observed() string { + f.t.Helper() + var observed string + if err := f.pool.QueryRow(f.t.Context(), `SELECT publication_observed FROM exits WHERE id=$1`, f.exit).Scan(&observed); err != nil { + f.t.Fatal(err) + } + return observed +} + +func TestRecoveryModeT5_PublicationIntentGuard(t *testing.T) { + t.Run("publish_then_unpublish", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentUnpublished) + publish := f.set(api.PublicationIntentPublished) + withdraw := f.set(api.PublicationIntentUnpublished) + if op := f.execute(withdraw.OperationId); op.Status != api.OperationStatusSucceeded && op.Status != api.OperationStatusPartiallySucceeded { + t.Fatalf("withdrawal did not complete: %s", op.Status) + } + if f.adapter.WithdrawCalls() != 1 || f.observed() != "withdrawn" { + t.Fatal("withdrawal was not observed") + } + // A current, ready observation makes an obsolete publish actionable if + // the intent check is missing. + f.acknowledge() + calls := f.adapter.PublishCalls() + if op := f.execute(publish.OperationId); op.Status != api.OperationStatusSuperseded { + t.Errorf("obsolete publish status=%s, want superseded", op.Status) + } + if f.adapter.PublishCalls() != calls || f.observed() != "withdrawn" { + t.Error("obsolete publish changed the withdrawn route") + } + }) + for _, intent := range []api.PublicationIntent{api.PublicationIntentUnpublished, api.PublicationIntentDisabled} { + t.Run(string(intent)+"_then_publish", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentPublished) + withdraw := f.set(intent) + publish := f.set(api.PublicationIntentPublished) + f.acknowledge() + if op := f.execute(publish.OperationId); op.Status != api.OperationStatusSucceeded { + t.Fatalf("current publish status=%s", op.Status) + } + if f.adapter.PublishCalls() != 1 { + t.Fatal("current publish did not reach adapter") + } + calls := f.adapter.WithdrawCalls() + if op := f.execute(withdraw.OperationId); op.Status != api.OperationStatusSuperseded { + t.Errorf("obsolete withdrawal status=%s, want superseded", op.Status) + } + if f.adapter.WithdrawCalls() != calls || f.observed() != "active" { + t.Error("obsolete withdrawal changed the published route") + } + }) + } + for _, kind := range []string{nodes.OpKindRevoke, nodes.OpKindRetire} { + t.Run(kind+"_with_published_intent", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentPublished) + var withdrawal api.Operation + err := db.InTx(t.Context(), f.pool, db.TxOptions{}, func(tx pgx.Tx) error { + var err error + withdrawal, err = nodes.CreateOperation(t.Context(), tx, nodes.CreateOperationParams{Kind: kind, Principal: "TEST ONLY", ResourceID: f.node, Now: f.now}) + return err + }) + if err != nil { + t.Fatal(err) + } + if op := f.execute(withdrawal.OperationId); op.Status == api.OperationStatusSuperseded || f.adapter.WithdrawCalls() != 1 { + t.Fatalf("%s status=%s withdrawals=%d", kind, op.Status, f.adapter.WithdrawCalls()) + } + }) + } + t.Run("current_publish", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentUnpublished) + publish := f.set(api.PublicationIntentPublished) + f.acknowledge() + if op := f.execute(publish.OperationId); op.Status != api.OperationStatusSucceeded || f.adapter.PublishCalls() != 1 { + t.Fatalf("current publish status=%s calls=%d", op.Status, f.adapter.PublishCalls()) + } + }) + t.Run("no_exit", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentUnpublished) + node := uuid.New() + if _, err := f.pool.Exec(t.Context(), `INSERT INTO nodes(id) VALUES($1)`, node); err != nil { + t.Fatal(err) + } + var publish api.Operation + if err := db.InTx(t.Context(), f.pool, db.TxOptions{}, func(tx pgx.Tx) error { + var err error + publish, err = nodes.CreateOperation(t.Context(), tx, nodes.CreateOperationParams{Kind: nodes.OpKindPublish, Principal: "TEST ONLY", ResourceID: node, Now: f.now}) + return err + }); err != nil { + t.Fatal(err) + } + superseded, err := f.exits.supersedeContradictoryPublication(t.Context(), publish.OperationId, node) + if err != nil || superseded { + t.Fatalf("no-exit guard: superseded=%v err=%v", superseded, err) + } + }) +} diff --git a/internal/nodes/httpwire/recovery_withdrawal_integration_test.go b/internal/nodes/httpwire/recovery_withdrawal_integration_test.go new file mode 100644 index 000000000..42b84bd57 --- /dev/null +++ b/internal/nodes/httpwire/recovery_withdrawal_integration_test.go @@ -0,0 +1,111 @@ +//go:build integration + +package httpwire_test + +import ( + "crypto/ed25519" + "crypto/rand" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/TED-H-com/Freedom-VPN/internal/exits" + "github.com/TED-H-com/Freedom-VPN/internal/nodes" + "github.com/TED-H-com/Freedom-VPN/internal/usage" + "github.com/TED-H-com/Freedom-VPN/pkg/api" + "github.com/google/uuid" +) + +func TestRecoveryModeT8_RevocationWithdrawal(t *testing.T) { + for _, freshObservation := range []bool{true, false} { + name := "without_post_freeze_observation" + if freshObservation { + name = "with_post_freeze_observation" + } + t.Run(name, func(t *testing.T) { + f, enrolled, cert, _, _ := publicationFixture(t) + adapter := exits.NewFakeNetBirdAdapter() + publish := f.publicationCommand(enrolled.NodeId, api.PublicationIntentPublished) + f.acknowledgePublication(enrolled, cert, true) + publisher := f.publicationDispatcher(adapter, 3) + f.publicationDispatch(publisher, publish.OperationId) + if op := f.publicationOperation(publish.OperationId); op.Status != api.OperationStatusSucceeded || adapter.PublishCalls() != 1 { + t.Fatalf("initial publication: status=%s calls=%d", op.Status, adapter.PublishCalls()) + } + var reportRaw []byte + if err := f.r.Pool.QueryRow(t.Context(), `SELECT report_payload FROM node_observations WHERE node_id=$1 ORDER BY received_at DESC,id DESC LIMIT 1`, enrolled.NodeId).Scan(&reportRaw); err != nil { + t.Fatal(err) + } + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet || (r.URL.Path != "/api/setup-keys" && r.URL.Path != "/api/groups") { + t.Errorf("unexpected identity request: %s %s", r.Method, r.URL.Path) + w.WriteHeader(http.StatusInternalServerError) + return + } + _, _ = io.WriteString(w, "[]") + })) + defer server.Close() + dispatcher, _ := f.identityWorker(server.URL, adapter) + _, key, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + t.Fatal(err) + } + ledger, err := usage.NewService(usage.Config{Pool: f.r.Pool, LedgerEpochSigner: usage.NewLedgerEpochSigner("TEST ONLY recovery", key)}) + if err != nil { + t.Fatal(err) + } + actor := nodes.SystemActorUUID.String() + if err := ledger.FreezeIngest(t.Context(), actor, "TEST ONLY restore"); err != nil { + t.Fatal(err) + } + if _, err := ledger.BeginRecovery(t.Context(), usage.RecoveryRequest{Actor: actor, Reason: "TEST ONLY restore", RestoredTo: time.Now().UTC().Add(-time.Hour)}); err != nil { + t.Fatal(err) + } + if freshObservation { + var report api.ObservationReport + if err := json.Unmarshal(reportRaw, &report); err != nil { + t.Fatal(err) + } + report.ReportId, report.ObservedAt = uuid.New(), time.Now().UTC() + decode[api.ObservationAccepted](t, f.call("POST", "/api/v1/agent/observations", report, cert, nil), http.StatusAccepted) + var fresh bool + if err := f.r.Pool.QueryRow(t.Context(), `SELECT EXISTS(SELECT 1 FROM node_observations o JOIN operations p ON p.resource_id=o.node_id AND p.principal=$2 WHERE o.report_id=$1 AND o.received_at>p.created_at)`, report.ReportId, usage.RestoreObservationPrincipal).Scan(&fresh); err != nil || !fresh { + t.Fatalf("post-freeze observation not recorded: fresh=%v err=%v", fresh, err) + } + } + revoke := f.revocationCommand(enrolled.NodeId, false) + withdrawals := adapter.WithdrawCalls() + drained := false + for i := 0; i < 100; i++ { + worked, err := dispatcher.Once(t.Context()) + if err != nil { + t.Fatal(err) + } + if !worked { + drained = true + break + } + } + if !drained { + t.Fatal("dispatcher did not reach an empty claim") + } + op := f.publicationOperation(revoke.OperationId) + if op.Status != api.OperationStatusSucceeded && op.Status != api.OperationStatusPartiallySucceeded { + t.Errorf("revoke status=%s, want succeeded or partially_succeeded", op.Status) + } + if adapter.WithdrawCalls() <= withdrawals { + t.Error("revoke did not withdraw the published route") + } + var mode, observed string + if err := f.r.Pool.QueryRow(t.Context(), `SELECT s.mode,e.publication_observed FROM usage_ledger_state s JOIN exits e ON e.node_id=$1`, enrolled.NodeId).Scan(&mode, &observed); err != nil { + t.Fatal(err) + } + if mode != "reconciling" || observed != "withdrawn" { + t.Errorf("mode=%s publication_observed=%s", mode, observed) + } + }) + } +} From e67e5132bff9cca5e21159d55af795b6ef2cc6b1 Mon Sep 17 00:00:00 2001 From: Ted H Date: Sat, 14 Nov 2026 17:06:17 -0500 Subject: [PATCH 3/5] worker: exercise malformed identifiers against operations Agent: codex/gpt-6.1-terra --- apps/worker/recovery_mode_integration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/worker/recovery_mode_integration_test.go b/apps/worker/recovery_mode_integration_test.go index 7ab22721a..c8410b03f 100644 --- a/apps/worker/recovery_mode_integration_test.go +++ b/apps/worker/recovery_mode_integration_test.go @@ -260,6 +260,8 @@ func TestRecoveryModeT2_WaitingRowsUntouched(t *testing.T) { func TestRecoveryModeT3_MalformedPublicationPayloads(t *testing.T) { pool := dbtest.New(t) recoverySetMode(t, pool, "reconciling") + // Keep the kind-filtered operation set nonempty so malformed IDs are evaluated. + recoveryOperation(t, pool, "node.revoke") for _, payload := range []map[string]any{{}, {"operation_id": "not-a-uuid"}, {"operation_id": 123}, {"operation_id": uuid.NewString()}} { recoveryEvent(t, pool, "node.publication_changed", payload, time.Now().Add(-time.Minute)) } From 2bf9f50250ec6228df948255e57f5d202e22a7ba Mon Sep 17 00:00:00 2001 From: Ted H Date: Sat, 14 Nov 2026 18:38:09 -0500 Subject: [PATCH 4/5] worker: cover normal mode in the claim lock test and frozen in the schedule test Agent: codex/gpt-6.1-sol --- apps/worker/recovery_mode_integration_test.go | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/worker/recovery_mode_integration_test.go b/apps/worker/recovery_mode_integration_test.go index c8410b03f..db653e2f1 100644 --- a/apps/worker/recovery_mode_integration_test.go +++ b/apps/worker/recovery_mode_integration_test.go @@ -171,6 +171,33 @@ func TestRecoveryModeT1_ClaimByMode(t *testing.T) { t.Fatalf("claim with ledger and operation locked: events=%v err=%v", events, err) } }) + t.Run("does_not_lock_ledger_in_normal_mode", func(t *testing.T) { + recoverySetMode(t, pool, "normal") + if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET lease_owner=NULL,lease_token=NULL,lease_until=NULL,attempt=0`); err != nil { + t.Fatal(err) + } + recoveryClaim(t, pool) + if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET lease_owner=NULL,lease_token=NULL,lease_until=NULL WHERE id=$1`, withdrawalEvent); err != nil { + t.Fatal(err) + } + tx, err := pool.Begin(t.Context()) + if err != nil { + t.Fatal(err) + } + defer func() { _ = tx.Rollback(t.Context()) }() + if _, err := tx.Exec(t.Context(), `SELECT id FROM usage_ledger_state FOR UPDATE`); err != nil { + t.Fatal(err) + } + if _, err := tx.Exec(t.Context(), `SELECT id FROM operations WHERE id=$1 FOR UPDATE`, withdrawalOperation); err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second) + defer cancel() + events, err := db.ClaimOutboxByLedgerMode(ctx, pool, "TEST ONLY unlocked reads", 1, time.Minute, recoveryAllowedTypes, recoveryFilteredType, recoveryWithdrawalKinds) + if err != nil || len(events) != 1 || events[0].ID != withdrawalEvent { + t.Fatalf("claim with ledger and operation locked: events=%v err=%v", events, err) + } + }) t.Run("missing_ledger_state", func(t *testing.T) { recoveryRemoveLedgerState(t, pool) if _, err := pool.Exec(t.Context(), `UPDATE outbox_events SET lease_owner=NULL,lease_token=NULL,lease_until=NULL,attempt=0`); err != nil { @@ -293,7 +320,7 @@ func TestRecoveryModeT4_NoHeadOfLineBlocking(t *testing.T) { } func TestRecoveryModeT6_MemberSchedule(t *testing.T) { - for _, mode := range []string{"reconciling", "normal", "missing"} { + for _, mode := range []string{"frozen", "reconciling", "normal", "missing"} { t.Run(mode, func(t *testing.T) { pool := dbtest.New(t) if mode == "missing" { From befaf969d0ab06736f335e03cf3e5e97cd758dbb Mon Sep 17 00:00:00 2001 From: Ted H Date: Sat, 14 Nov 2026 18:38:56 -0500 Subject: [PATCH 5/5] exits: supersede a failed publication operation that contradicts the intent Agent: codex/gpt-6.1-sol --- internal/exits/exits.go | 16 +++-- .../exits/intent_guard_integration_test.go | 68 ++++++++++++++++++- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/internal/exits/exits.go b/internal/exits/exits.go index 93d9ce8fb..492aeaa07 100644 --- a/internal/exits/exits.go +++ b/internal/exits/exits.go @@ -683,14 +683,22 @@ func (s *Service) ExecuteOperation(ctx context.Context, opID uuid.UUID) (api.Ope } } +// supersedeContradictoryPublication supersedes publication operations that contradict +// the current intent. A failed operation is one a retry would execute again; the +// schema lets failed change only to running, so superseding it takes two statements. func (s *Service) supersedeContradictoryPublication(ctx context.Context, opID, nodeID uuid.UUID) (bool, error) { + const contradiction = `EXISTS ( + SELECT 1 FROM exits WHERE node_id=$2 AND + ((operations.kind='node.publish' AND publication_intent<>'published') OR + (operations.kind IN ('node.unpublish','node.disable') AND publication_intent='published')))` var superseded bool err := commandtx.InTx(ctx, s.pool, db.TxOptions{}, func(tx pgx.Tx) error { + if _, err := tx.Exec(ctx, `UPDATE operations SET status='running',resource_version=coalesce(resource_version,0)+1 + WHERE id=$1 AND status='failed' AND `+contradiction, opID, nodeID); err != nil { + return err + } tag, err := tx.Exec(ctx, `UPDATE operations SET status='superseded',completed_at=$3,resource_version=coalesce(resource_version,0)+1 - WHERE id=$1 AND status IN ('pending','running') AND EXISTS ( - SELECT 1 FROM exits WHERE node_id=$2 AND - ((operations.kind='node.publish' AND publication_intent<>'published') OR - (operations.kind IN ('node.unpublish','node.disable') AND publication_intent='published')))`, opID, nodeID, s.now().UTC()) + WHERE id=$1 AND status IN ('pending','running') AND `+contradiction, opID, nodeID, s.now().UTC()) if err == nil { superseded = tag.RowsAffected() == 1 } diff --git a/internal/exits/intent_guard_integration_test.go b/internal/exits/intent_guard_integration_test.go index 31738bacb..a303ab055 100644 --- a/internal/exits/intent_guard_integration_test.go +++ b/internal/exits/intent_guard_integration_test.go @@ -3,6 +3,7 @@ package exits import ( + "errors" "testing" "time" @@ -123,6 +124,71 @@ func TestRecoveryModeT5_PublicationIntentGuard(t *testing.T) { } }) } + t.Run("failed_publish_then_unpublish", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentUnpublished) + publish := f.set(api.PublicationIntentPublished) + f.acknowledge() + f.adapter.SetPublishError(errors.New("TEST ONLY publish failure")) + if op := f.execute(publish.OperationId); op.Status != api.OperationStatusFailed { + t.Fatalf("publish failure status=%s, want failed", op.Status) + } + f.adapter.SetPublishError(nil) + withdraw := f.set(api.PublicationIntentUnpublished) + if op := f.execute(withdraw.OperationId); op.Status != api.OperationStatusSucceeded && op.Status != api.OperationStatusPartiallySucceeded { + t.Fatalf("withdrawal did not complete: %s", op.Status) + } + if f.observed() != "withdrawn" { + t.Fatal("withdrawal was not observed") + } + f.acknowledge() + calls := f.adapter.PublishCalls() + if op := f.execute(publish.OperationId); op.Status != api.OperationStatusSuperseded { + t.Errorf("obsolete failed publish status=%s, want superseded", op.Status) + } + if f.adapter.PublishCalls() != calls || f.observed() != "withdrawn" { + t.Error("obsolete failed publish changed the withdrawn route") + } + }) + t.Run("failed_unpublish_then_publish", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentPublished) + withdraw := f.set(api.PublicationIntentUnpublished) + f.adapter.SetWithdrawError(errors.New("TEST ONLY withdraw failure")) + if op := f.execute(withdraw.OperationId); op.Status != api.OperationStatusFailed { + t.Fatalf("withdraw failure status=%s, want failed", op.Status) + } + f.adapter.SetWithdrawError(nil) + publish := f.set(api.PublicationIntentPublished) + f.acknowledge() + if op := f.execute(publish.OperationId); op.Status != api.OperationStatusSucceeded { + t.Fatalf("current publish status=%s, want succeeded", op.Status) + } + calls := f.adapter.WithdrawCalls() + if op := f.execute(withdraw.OperationId); op.Status != api.OperationStatusSuperseded { + t.Errorf("obsolete failed withdrawal status=%s, want superseded", op.Status) + } + if f.adapter.WithdrawCalls() != calls || f.observed() != "active" { + t.Error("obsolete failed withdrawal changed the published route") + } + }) + t.Run("partially_succeeded_withdrawal_is_kept", func(t *testing.T) { + f := newIntentGuardFixture(t, api.PublicationIntentPublished) + withdraw := f.set(api.PublicationIntentUnpublished) + if op := f.execute(withdraw.OperationId); op.Status != api.OperationStatusPartiallySucceeded { + t.Fatalf("unconfirmed withdrawal status=%s, want partially_succeeded", op.Status) + } + f.set(api.PublicationIntentPublished) + superseded, err := f.exits.supersedeContradictoryPublication(t.Context(), withdraw.OperationId, f.node) + if err != nil || superseded { + t.Fatalf("partial withdrawal guard: superseded=%v err=%v", superseded, err) + } + op, err := nodes.GetOperation(t.Context(), f.pool, withdraw.OperationId) + if err != nil { + t.Fatal(err) + } + if op.Status != api.OperationStatusPartiallySucceeded { + t.Errorf("unconfirmed withdrawal status=%s, want partially_succeeded", op.Status) + } + }) for _, kind := range []string{nodes.OpKindRevoke, nodes.OpKindRetire} { t.Run(kind+"_with_published_intent", func(t *testing.T) { f := newIntentGuardFixture(t, api.PublicationIntentPublished) @@ -135,7 +201,7 @@ func TestRecoveryModeT5_PublicationIntentGuard(t *testing.T) { if err != nil { t.Fatal(err) } - if op := f.execute(withdrawal.OperationId); op.Status == api.OperationStatusSuperseded || f.adapter.WithdrawCalls() != 1 { + if op := f.execute(withdrawal.OperationId); (op.Status != api.OperationStatusSucceeded && op.Status != api.OperationStatusPartiallySucceeded) || f.adapter.WithdrawCalls() != 1 { t.Fatalf("%s status=%s withdrawals=%d", kind, op.Status, f.adapter.WithdrawCalls()) } })