Skip to content

Commit

Permalink
fix: attemptToFindRunId would return timeout if called with an empty …
Browse files Browse the repository at this point in the history
…array
  • Loading branch information
Codex- committed Oct 4, 2024
1 parent 07dfb68 commit d15ca0b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/return-dispatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions src/return-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export async function attemptToFindRunId(
idRegex: RegExp,
workflowRunIds: number[],
): Promise<Result<{ id: number; url: string }>> {
if (workflowRunIds.length === 0) {
return {
success: false,
reason: "invalid input",
};
}

let currentWorkflowRunIndex = 0;
let currentFetchWorkflowRunJobStepsAttempt = 0;
while (currentWorkflowRunIndex < workflowRunIds.length) {
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Result<T> = ResultSuccess<T> | ResultTimeout;
export type Result<T> = ResultSuccess<T> | ResultTimeout | ResultInvalidInput;

interface ResultSuccess<T> {
success: true;
Expand All @@ -9,3 +9,8 @@ interface ResultTimeout {
success: false;
reason: "timeout";
}

interface ResultInvalidInput {
success: false;
reason: "invalid input";
}

0 comments on commit d15ca0b

Please sign in to comment.