test(conformance): the wisps-table cases check the row is still a wisp

runWispTableRowMintsNothing asserted 0 versions but never checked its own
precondition, that the wisps table still holds the row. Suppose a step
moved the row onto the issues plane through an update-shaped mint. That
mint would hit the new row's NULL participation_generation and be fenced,
so the count stayed 0 and the case passed without saying anything about
a wisps-table row.

- Add an InWispsTable hook to ParticipationGenerationFixture and bind it
  on dolt, embeddeddolt and uow as a raw wisps-table count. The
  wisps-table body now Fatals if the row is not in the wisps table after
  its steps. Each leg's KitIsWired test checks the hook. On http it
  stays nil with the other wisps-table hooks, whose cases are waived
  there.
- The dolt ClearWispFlag hook now bites. A bare store.UpdateIssue on a
  wisp goes through updateWisp, whose transaction versioned history never
  scopes. So WispFlagClearMintsNothing passed on dolt with or without the
  ec52d29030 fix, as that commit's message admits. The hook now runs the
  lone flag clear in a RunInTransaction with the events journal on: the
  journal-enabled shape the SquashWispRoot hook already uses.
- Both hooks go through a new withEventsJournal helper. It restores the
  store's previous journal setting rather than unconditionally setting it
  to false afterwards, which assumed the store started with the journal
  off.

Mutation-checked in throwaway worktrees:
- With version_history.go at ec52d29030^, dolt's WispFlagClearMintsNothing
  now fails ("read participation_generation for pg-flag-clear: sql: no
  rows in result set"). It used to pass there.
- Embedded ClearWispFlag rerouted as a flag-off persistence move followed
  by a flag-on title update: the case fails on the new precondition ("is
  not in the wisps table after flag-clear"). With the precondition
  disabled, the same probe passes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-10-18 05:16:01 +00:00
commit d17b716115
5 changed files with 85 additions and 21 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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()
}

View file

@ -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
},
}
}

View file

@ -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
},
}
}