Skip to content

Commit d15ca0b

Browse files
committed
fix: attemptToFindRunId would return timeout if called with an empty array
1 parent 07dfb68 commit d15ca0b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/return-dispatch.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ describe("return-dispatch", () => {
277277
assertNoneCalled();
278278
});
279279

280+
it("does nothing if called with an empty array", async () => {
281+
const result = await attemptToFindRunId(new RegExp(testId), []);
282+
if (result.success) {
283+
expect.fail("result found when none expected");
284+
}
285+
286+
// Behaviour
287+
expect(result.success).toStrictEqual(false);
288+
expect(result.reason).toStrictEqual("invalid input");
289+
expect(getWorkflowRunJobStepMock).not.toHaveBeenCalled();
290+
expect(fetchWorkflowRunUrlMock).not.toHaveBeenCalled();
291+
292+
// Logging
293+
assertNoneCalled();
294+
});
295+
280296
describe("server error retries", () => {
281297
beforeEach(() => {
282298
vi.spyOn(

src/return-dispatch.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export async function attemptToFindRunId(
4242
idRegex: RegExp,
4343
workflowRunIds: number[],
4444
): Promise<Result<{ id: number; url: string }>> {
45+
if (workflowRunIds.length === 0) {
46+
return {
47+
success: false,
48+
reason: "invalid input",
49+
};
50+
}
51+
4552
let currentWorkflowRunIndex = 0;
4653
let currentFetchWorkflowRunJobStepsAttempt = 0;
4754
while (currentWorkflowRunIndex < workflowRunIds.length) {

src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type Result<T> = ResultSuccess<T> | ResultTimeout;
1+
export type Result<T> = ResultSuccess<T> | ResultTimeout | ResultInvalidInput;
22

33
interface ResultSuccess<T> {
44
success: true;
@@ -9,3 +9,8 @@ interface ResultTimeout {
99
success: false;
1010
reason: "timeout";
1111
}
12+
13+
interface ResultInvalidInput {
14+
success: false;
15+
reason: "invalid input";
16+
}

0 commit comments

Comments
 (0)