From 6b99f6ee0ed31752c82e01818ede49e4fe460d33 Mon Sep 17 00:00:00 2001 From: Noel Date: Sat, 8 Aug 2026 17:34:43 +0200 Subject: [PATCH] test(actions): cover mixed-terminal run watch Signed-off-by: Noel --- modules/task/actions_run_watch_test.go | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/task/actions_run_watch_test.go b/modules/task/actions_run_watch_test.go index d9bbb08e..50713d0b 100644 --- a/modules/task/actions_run_watch_test.go +++ b/modules/task/actions_run_watch_test.go @@ -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", "")}