diff --git a/backend/conformance/dualwrite_participation_generation_contract.go b/backend/conformance/dualwrite_participation_generation_contract.go index 0739504d5..e1e283380 100644 --- a/backend/conformance/dualwrite_participation_generation_contract.go +++ b/backend/conformance/dualwrite_participation_generation_contract.go @@ -111,6 +111,10 @@ type ParticipationGenerationFixture struct { // ParticipationGeneration reads issues.participation_generation for id, // returning nil for SQL NULL. ParticipationGeneration func(ctx context.Context, id string) (*int64, error) + // InWispsTable reports whether the wisps table holds a row for id: the + // precondition the wisps-table cases check, so they cannot pass on a row + // that a step moved to the issues table. + InWispsTable func(ctx context.Context, id string) (bool, error) } // RunParticipationGenerationCreateWithFlagOnStampsAValue pins design @@ -375,8 +379,8 @@ func RunParticipationGenerationUnflaggedWispCreateMintsNothing(t *testing.T, ctx } // runWispTableRowMintsNothing is the body the three wisps-table cases share: -// with the flag on, every step succeeds on id and id ends with no -// issue_versions row. +// with the flag on, every step succeeds on id, the wisps table still holds id +// afterwards, and id ends with no issue_versions row. func runWispTableRowMintsNothing(t *testing.T, ctx context.Context, fixture ParticipationGenerationFixture, how string, steps ...func(context.Context, string) error) { t.Helper() if err := fixture.SetFlag(ctx, true); err != nil { @@ -390,6 +394,17 @@ func runWispTableRowMintsNothing(t *testing.T, ctx context.Context, fixture Part "the mutation", i+1, how, id, err) } } + // The precondition, checked after the steps rather than assumed: a step + // that moved the row to the issues table would leave a NULL + // participation_generation there, the update-shaped mint would be fenced + // as legacy, and the zero count below would hold without saying anything + // about a wisps-table row. + if inWisps, err := fixture.InWispsTable(ctx, id); err != nil { + t.Fatalf("checking whether the wisps table holds %s: %v", id, err) + } else if !inWisps { + t.Fatalf("%s is not in the wisps table after %s — this case pins that a wisps-table row mints "+ + "nothing, and cannot say so about a row a step moved out of that table", id, how) + } count, err := fixture.VersionRowCount(ctx, id) if err != nil { t.Fatalf("counting version rows for %s: %v", id, err) diff --git a/internal/httpclient/served_participation_generation_test.go b/internal/httpclient/served_participation_generation_test.go index 31272fa51..fed38636d 100644 --- a/internal/httpclient/served_participation_generation_test.go +++ b/internal/httpclient/served_participation_generation_test.go @@ -33,8 +33,8 @@ import ( // seed, so it goes through the reference store (the harness rule in // served_harness_test.go). // -// ClearWispFlag, SquashWispRoot and CreateUnflaggedWisp stay nil, and the -// cases that need them stay unwired, along with the one whose subject is a +// ClearWispFlag, SquashWispRoot, CreateUnflaggedWisp and InWispsTable stay nil, +// and the cases that need them stay unwired, along with the one whose subject is a // no-history issues-table create. None of those mutations has a form on this // wire; see participationGenerationWireGapWaiverReason in // internal/storage/leg_contract_wiring_test.go. CreateNoHistoryIssue is bound, diff --git a/internal/storage/dolt/dualwrite_participation_generation_contract_test.go b/internal/storage/dolt/dualwrite_participation_generation_contract_test.go index d022a8536..5380b4db2 100644 --- a/internal/storage/dolt/dualwrite_participation_generation_contract_test.go +++ b/internal/storage/dolt/dualwrite_participation_generation_contract_test.go @@ -122,6 +122,9 @@ func TestParticipationGenerationFixtureKitIsWired(t *testing.T) { if fixture.ParticipationGeneration == nil { t.Error("ParticipationGenerationFixture.ParticipationGeneration is nil") } + if fixture.InWispsTable == nil { + t.Error("ParticipationGenerationFixture.InWispsTable is nil") + } } func newDoltParticipationGenerationFixture(t *testing.T, prefix string) (conformance.ParticipationGenerationFixture, context.Context, func()) { @@ -249,26 +252,28 @@ func buildParticipationGenerationFixture(store *DoltStore, configurer storage.Ve return err }, ClearWispFlag: func(ctx context.Context, id string) error { - // This leg's store-level wisp update runs in a transaction - // versioned history does not scope, so it never reaches the mint; - // SquashWispRoot below is the case that does on this leg. - return store.UpdateIssue(ctx, id, map[string]any{"wisp": false}, "actor") + // The flag clear alone, in the journal-enabled transaction shape + // (withEventsJournal), so it reaches the mint on this leg. A bare + // store.UpdateIssue would go through updateWisp, whose transaction + // versioned history never scopes, and the case would pass whatever + // the fence did. + return withEventsJournal(store, func() error { + return store.RunInTransaction(ctx, "clear wisp flag "+id, func(tx storage.Transaction) error { + return tx.UpdateIssue(ctx, id, map[string]any{"wisp": false}, "actor") + }) + }) }, SquashWispRoot: func(ctx context.Context, id string) error { // bd mol squash's own shape: the root's close and its flag clear - // in the one transaction the squash commits. With the events - // journal off, RunInTransaction runs wisp writes on a separate - // ignored-table transaction versioned history never scopes, so - // the squash would never reach the mint this case pins; a - // journal-enabled workspace pins both planes to the one regular, - // scoped transaction. Take that shape for this one transaction. - store.SetEventsJournalEnabled(true) - defer store.SetEventsJournalEnabled(false) - return store.RunInTransaction(ctx, "squash "+id, func(tx storage.Transaction) error { - if err := tx.CloseIssue(ctx, id, "squashed", "actor", ""); err != nil { - return err - } - return tx.UpdateIssue(ctx, id, map[string]any{"wisp": false}, "actor") + // in the one transaction the squash commits, in the + // journal-enabled shape that reaches the mint (withEventsJournal). + return withEventsJournal(store, func() error { + return store.RunInTransaction(ctx, "squash "+id, func(tx storage.Transaction) error { + if err := tx.CloseIssue(ctx, id, "squashed", "actor", ""); err != nil { + return err + } + return tx.UpdateIssue(ctx, id, map[string]any{"wisp": false}, "actor") + }) }) }, CreateUnflaggedWisp: func(ctx context.Context, id string) error { @@ -312,5 +317,29 @@ func buildParticipationGenerationFixture(store *DoltStore, configurer storage.Ve } return &gen.Int64, nil }, + InWispsTable: func(ctx context.Context, id string) (bool, error) { + var rows int + if err := store.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM wisps WHERE id = ?`, id). + Scan(&rows); err != nil { + return false, err + } + return rows > 0, nil + }, } } + +// withEventsJournal runs fn with store's events journal on and then restores +// whatever setting the store had before, rather than assuming it was off. +// +// With the journal off, RunInTransaction runs wisp writes on a separate +// ignored-table transaction that versioned history never scopes, and a lone +// store.UpdateIssue on a wisp (updateWisp) opens a transaction it never scopes +// either, so neither reaches the mint the wisps-table cases pin. A +// journal-enabled workspace pins both planes to the one regular, scoped +// transaction, which is the shape that reaches it. +func withEventsJournal(store *DoltStore, fn func() error) error { + previous := store.eventsJournalEnabled.Load() + store.SetEventsJournalEnabled(true) + defer store.SetEventsJournalEnabled(previous) + return fn() +} diff --git a/internal/storage/embeddeddolt/dualwrite_participation_generation_contract_test.go b/internal/storage/embeddeddolt/dualwrite_participation_generation_contract_test.go index 140e23f71..6c2b5aa88 100644 --- a/internal/storage/embeddeddolt/dualwrite_participation_generation_contract_test.go +++ b/internal/storage/embeddeddolt/dualwrite_participation_generation_contract_test.go @@ -116,6 +116,9 @@ func TestParticipationGenerationFixtureKitIsWired(t *testing.T) { if fixture.ParticipationGeneration == nil { t.Error("ParticipationGenerationFixture.ParticipationGeneration is nil") } + if fixture.InWispsTable == nil { + t.Error("ParticipationGenerationFixture.InWispsTable is nil") + } } func newEmbeddedParticipationGenerationFixture(t *testing.T, te *testEnv, prefix string) conformance.ParticipationGenerationFixture { @@ -222,5 +225,12 @@ func newEmbeddedParticipationGenerationFixture(t *testing.T, te *testEnv, prefix } return &gen.Int64, nil }, + InWispsTable: func(ctx context.Context, id string) (bool, error) { + var rows int + if err := kit.QueryScalar(ctx, "SELECT COUNT(*) FROM wisps WHERE id = ?", []any{id}, &rows); err != nil { + return false, err + } + return rows > 0, nil + }, } } diff --git a/internal/storage/uow/dualwrite_participation_generation_contract_test.go b/internal/storage/uow/dualwrite_participation_generation_contract_test.go index 7bd1902bc..13fa89e27 100644 --- a/internal/storage/uow/dualwrite_participation_generation_contract_test.go +++ b/internal/storage/uow/dualwrite_participation_generation_contract_test.go @@ -108,6 +108,9 @@ func TestParticipationGenerationFixtureKitIsWired(t *testing.T) { if fixture.ParticipationGeneration == nil { t.Error("ParticipationGenerationFixture.ParticipationGeneration is nil") } + if fixture.InWispsTable == nil { + t.Error("ParticipationGenerationFixture.InWispsTable is nil") + } } func newUOWParticipationGenerationFixture(t *testing.T, ctx context.Context, prefix string) conformance.ParticipationGenerationFixture { @@ -231,5 +234,12 @@ func newUOWParticipationGenerationFixture(t *testing.T, ctx context.Context, pre } return &gen, nil }, + InWispsTable: func(ctx context.Context, id string) (bool, error) { + var rows int + if err := kit.QueryScalar(ctx, "SELECT COUNT(*) FROM wisps WHERE id = ?", []any{id}, &rows); err != nil { + return false, err + } + return rows > 0, nil + }, } }