From d15ca0b18444005d2631d097b3d15c528d726b20 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Sat, 5 Oct 2024 11:51:11 +1300 Subject: [PATCH] fix: attemptToFindRunId would return timeout if called with an empty array --- src/return-dispatch.spec.ts | 16 ++++++++++++++++ src/return-dispatch.ts | 7 +++++++ src/types.ts | 7 ++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/return-dispatch.spec.ts b/src/return-dispatch.spec.ts index 483ab09..566849d 100644 --- a/src/return-dispatch.spec.ts +++ b/src/return-dispatch.spec.ts @@ -277,6 +277,22 @@ describe("return-dispatch", () => { assertNoneCalled(); }); + it("does nothing if called with an empty array", async () => { + const result = await attemptToFindRunId(new RegExp(testId), []); + if (result.success) { + expect.fail("result found when none expected"); + } + + // Behaviour + expect(result.success).toStrictEqual(false); + expect(result.reason).toStrictEqual("invalid input"); + expect(getWorkflowRunJobStepMock).not.toHaveBeenCalled(); + expect(fetchWorkflowRunUrlMock).not.toHaveBeenCalled(); + + // Logging + assertNoneCalled(); + }); + describe("server error retries", () => { beforeEach(() => { vi.spyOn( diff --git a/src/return-dispatch.ts b/src/return-dispatch.ts index 0800154..80f0ed8 100644 --- a/src/return-dispatch.ts +++ b/src/return-dispatch.ts @@ -42,6 +42,13 @@ export async function attemptToFindRunId( idRegex: RegExp, workflowRunIds: number[], ): Promise> { + if (workflowRunIds.length === 0) { + return { + success: false, + reason: "invalid input", + }; + } + let currentWorkflowRunIndex = 0; let currentFetchWorkflowRunJobStepsAttempt = 0; while (currentWorkflowRunIndex < workflowRunIds.length) { diff --git a/src/types.ts b/src/types.ts index a2de285..c863d05 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -export type Result = ResultSuccess | ResultTimeout; +export type Result = ResultSuccess | ResultTimeout | ResultInvalidInput; interface ResultSuccess { success: true; @@ -9,3 +9,8 @@ interface ResultTimeout { success: false; reason: "timeout"; } + +interface ResultInvalidInput { + success: false; + reason: "invalid input"; +}