feat: apply terminal reconciliation cleanup
This commit is contained in:
@@ -154,6 +154,40 @@ func TestTerminalCleanupTombstonesAndConflicts_BH_CLIENT_02(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscardServerConfirmedTerminalDropsPendingEvents_HP_CLIENT_10(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
store := openTestStore(t, ctx, filepath.Join(t.TempDir(), "spool"), DefaultTombstoneLimit)
|
||||
issue := testUUID(t, "019c46f1-1d02-7000-8000-000000000013")
|
||||
command := testCommand(issue, []byte("server-confirmed terminal"))
|
||||
now := time.Date(2026, time.September, 6, 12, 0, 0, 0, time.UTC)
|
||||
if _, err := store.AcceptCommand(ctx, command, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := store.AppendEvent(ctx, issue, EventInput{Kind: 1, Compression: 1, Payload: []byte("unacknowledged local terminal output"), CreatedAt: now}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.MarkTerminal(ctx, issue, 5); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.DiscardTerminal(ctx, issue, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pending, err := store.PendingEvents(ctx, issue); err != nil || len(pending) != 0 {
|
||||
t.Fatalf("discarded command pending events = %#v, %v", pending, err)
|
||||
}
|
||||
snapshot, err := store.ReconcileSnapshot(ctx)
|
||||
if err != nil || len(snapshot.GetRetainedCommands()) != 1 || !snapshot.GetRetainedCommands()[0].GetTombstoned() {
|
||||
t.Fatalf("discarded command snapshot = %#v, %v", snapshot, err)
|
||||
}
|
||||
if err := store.DiscardTerminal(ctx, issue, now.Add(time.Second)); err != nil {
|
||||
t.Fatalf("repeated discard = %v", err)
|
||||
}
|
||||
if _, err := store.AcceptCommand(ctx, command, now); !errors.Is(err, ErrAlreadyExecuted) {
|
||||
t.Fatalf("duplicate after discard error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func openTestStore(t *testing.T, ctx context.Context, directory string, tombstoneLimit uint64) *Store {
|
||||
t.Helper()
|
||||
store, err := Open(ctx, Options{DataDir: directory, BusyTimeout: time.Second, TombstoneLimit: tombstoneLimit})
|
||||
|
||||
Reference in New Issue
Block a user