test(actions): cover mixed-terminal run watch

Signed-off-by: Noel <n@noeljackson.com>
This commit is contained in:
Noel 2026-08-08 17:34:43 +02:00
parent 59d8bbcde1
commit 6b99f6ee0e
No known key found for this signature in database
GPG key ID: ACB59B76E29853EA

View file

@ -100,6 +100,52 @@ func TestActionRunWatchNormalPollsFetchRunsOnly(t *testing.T) {
assert.Equal(t, []string{"binding", "transition", "transition", "summary"}, actionRunWatchEventTypes(events))
}
func TestActionRunWatchWaitsForEveryRunWhenOneIsAlreadyTerminal(t *testing.T) {
client := newScriptedActionRunWatchClient()
client.runs[1] = []*gitea.ActionWorkflowRun{
testActionRun(1, "in_progress", ""),
testActionRun(1, "in_progress", ""),
testActionRun(1, "completed", "success"),
}
client.runs[2] = []*gitea.ActionWorkflowRun{
testActionRun(2, "completed", "success"),
}
client.jobs[1] = [][]*gitea.ActionWorkflowJob{
{{ID: 10, Name: "core", Status: "in_progress"}},
{{ID: 10, Name: "core", Status: "completed", Conclusion: "success"}},
}
client.jobs[2] = [][]*gitea.ActionWorkflowJob{
{{ID: 20, Name: "supply-chain", Status: "completed", Conclusion: "success"}},
}
opts := testWatchOptions()
opts.RunIDs = []int64{1, 2}
events := make([]ActionRunWatchEvent, 0)
session := newActionRunWatchSession(client, "gitea", "tea", opts, func(event ActionRunWatchEvent) error {
events = append(events, event)
return nil
})
t0 := time.Date(2026, time.August, 3, 10, 0, 0, 0, time.UTC)
done, _, err := session.initialize(t.Context(), t0)
require.NoError(t, err)
assert.False(t, done, "a terminal run must not end the watch while another run is active")
done, _, err = session.poll(t.Context(), t0.Add(time.Minute))
require.NoError(t, err)
assert.False(t, done, "the watch must remain bound until every run is terminal")
assert.Equal(t, 1, client.runCalls[2], "terminal runs must not be fetched again")
assert.Equal(t, 1, client.jobCalls[2], "terminal runs must not have their jobs fetched again")
done, result, err := session.poll(t.Context(), t0.Add(2*time.Minute))
require.NoError(t, err)
assert.True(t, done)
assert.Equal(t, ActionRunWatchExitSuccess, result.ExitCode)
assert.Equal(t, []string{"binding", "binding", "transition", "summary"}, actionRunWatchEventTypes(events))
require.Len(t, events[len(events)-1].Runs, 2)
assert.Equal(t, int64(1), events[len(events)-1].Runs[0].RunID)
assert.Equal(t, int64(2), events[len(events)-1].Runs[1].RunID)
}
func TestActionRunWatchRefreshesClientBeforeEveryPoll(t *testing.T) {
initialClient := newScriptedActionRunWatchClient()
initialClient.runs[1] = []*gitea.ActionWorkflowRun{testActionRun(1, "queued", "")}