Skip to content

Commit

Permalink
pam/gdmmodel-test: Do not use sub-sequences to send ordered commands
Browse files Browse the repository at this point in the history
As per a bubbletea issue sub-sequences of messages may not preserve the
order, so let's just handle them by appending the messages to the
commands we already have instead, so that there's no risk that the order
is not preserved and that the subsequence is executed when all the
remaining commands also are

See: charmbracelet/bubbletea#847
  • Loading branch information
3v1n0 committed Feb 27, 2025
1 parent d12da4b commit 7c986aa
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pam/internal/adapter/gdmmodel_uimodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,18 @@ func (m *gdmTestUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}()

case *gdmTestWaitForStageDone:
msgCommands := tea.Sequence(msg.commands...)
// FIXME: We can't just define msgCommands a sub-sequence as we used to
// do since that's unreliable, as per a bubbletea bug:
// - https://github.com/charmbracelet/bubbletea/issues/847
msgCommands := slices.Clone(msg.commands)
if len(msg.events) > 0 {
m.gdmHandler.appendPollResultEvents(msg.events...)
// If we've events as poll results, let's wait for a polling cycle to complete
msgCommands = tea.Sequence(tea.Tick(gdmPollFrequency, func(t time.Time) tea.Msg {
msgCommands = append([]tea.Cmd{tea.Tick(gdmPollFrequency, func(t time.Time) tea.Msg {
return nil
}), msgCommands)
})}, msgCommands...)
}
commands = append(commands, msgCommands)
commands = append(commands, msgCommands...)

case gdmTestSendAuthDataWhenReady:
doneMsg := gdmTestWaitForCommandsDone{seq: gdmTestSequentialMessages.Add(1)}
Expand Down

0 comments on commit 7c986aa

Please sign in to comment.