Skip to content

Commit 3723675

Browse files
committed
fix: call rerun pipeline with actual task arguments
1 parent e19e404 commit 3723675

File tree

4 files changed

+317
-20
lines changed

4 files changed

+317
-20
lines changed

src/components/PipelineRun/components/RerunPipelineButton.test.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {
2222
mockIsAuthorized,
2323
mockGetToken,
2424
mockFetch,
25+
mockUseExecutionDataOptional,
2526
} = vi.hoisted(() => ({
2627
navigateMock: vi.fn(),
2728
notifyMock: vi.fn(),
@@ -31,6 +32,7 @@ const {
3132
mockIsAuthorized: vi.fn(),
3233
mockGetToken: vi.fn(),
3334
mockFetch: vi.fn(),
35+
mockUseExecutionDataOptional: vi.fn(),
3436
}));
3537

3638
// Set up mocks
@@ -67,6 +69,10 @@ vi.mock("@/utils/submitPipeline", () => ({
6769
submitPipelineRun: mockSubmitPipelineRun,
6870
}));
6971

72+
vi.mock("@/providers/ExecutionDataProvider", () => ({
73+
useExecutionDataOptional: mockUseExecutionDataOptional,
74+
}));
75+
7076
const testOrigin = import.meta.env.VITE_BASE_URL || "http://localhost:3000";
7177

7278
Object.defineProperty(window, "location", {
@@ -108,6 +114,7 @@ describe("<RerunPipelineButton/>", () => {
108114
mockIsAuthorized.mockReturnValue(true);
109115
mockGetToken.mockReturnValue("mock-token");
110116
mockAwaitAuthorization.mockClear();
117+
mockUseExecutionDataOptional.mockReturnValue(undefined);
111118
});
112119

113120
afterEach(async () => {
@@ -334,4 +341,81 @@ describe("<RerunPipelineButton/>", () => {
334341
);
335342
});
336343
});
344+
345+
test("passes taskArguments from execution data to submitPipelineRun", async () => {
346+
const mockTaskArguments = {
347+
input_param: "test_value",
348+
another_param: "another_value",
349+
};
350+
351+
mockUseExecutionDataOptional.mockReturnValue({
352+
rootDetails: {
353+
task_spec: {
354+
arguments: mockTaskArguments,
355+
},
356+
},
357+
});
358+
359+
mockSubmitPipelineRun.mockImplementation(async (_, __, { onSuccess }) => {
360+
onSuccess({ id: 456 });
361+
});
362+
363+
await act(async () => {
364+
renderWithProviders(
365+
<RerunPipelineButton componentSpec={componentSpec} />,
366+
);
367+
});
368+
369+
const rerunButton = screen.getByTestId("rerun-pipeline-button");
370+
371+
await act(async () => {
372+
fireEvent.click(rerunButton);
373+
});
374+
375+
await waitFor(() => {
376+
expect(mockSubmitPipelineRun).toHaveBeenCalledWith(
377+
componentSpec,
378+
expect.any(String),
379+
expect.objectContaining({
380+
taskArguments: mockTaskArguments,
381+
authorizationToken: "mock-token",
382+
onSuccess: expect.any(Function),
383+
onError: expect.any(Function),
384+
}),
385+
);
386+
});
387+
});
388+
389+
test("passes undefined taskArguments when execution data is not available", async () => {
390+
mockUseExecutionDataOptional.mockReturnValue(undefined);
391+
392+
mockSubmitPipelineRun.mockImplementation(async (_, __, { onSuccess }) => {
393+
onSuccess({ id: 789 });
394+
});
395+
396+
await act(async () => {
397+
renderWithProviders(
398+
<RerunPipelineButton componentSpec={componentSpec} />,
399+
);
400+
});
401+
402+
const rerunButton = screen.getByTestId("rerun-pipeline-button");
403+
404+
await act(async () => {
405+
fireEvent.click(rerunButton);
406+
});
407+
408+
await waitFor(() => {
409+
expect(mockSubmitPipelineRun).toHaveBeenCalledWith(
410+
componentSpec,
411+
expect.any(String),
412+
expect.objectContaining({
413+
taskArguments: undefined,
414+
authorizationToken: "mock-token",
415+
onSuccess: expect.any(Function),
416+
onError: expect.any(Function),
417+
}),
418+
);
419+
});
420+
});
337421
});

src/components/PipelineRun/components/RerunPipelineButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useAwaitAuthorization } from "@/components/shared/Authentication/useAwa
99
import TooltipButton from "@/components/shared/Buttons/TooltipButton";
1010
import useToastNotification from "@/hooks/useToastNotification";
1111
import { useBackend } from "@/providers/BackendProvider";
12+
import { useExecutionDataOptional } from "@/providers/ExecutionDataProvider";
1213
import { APP_ROUTES } from "@/routes/router";
1314
import type { PipelineRun } from "@/types/pipelineRun";
1415
import type { ComponentSpec } from "@/utils/componentSpec";
@@ -24,6 +25,7 @@ export const RerunPipelineButton = ({
2425
const { backendUrl } = useBackend();
2526
const navigate = useNavigate();
2627
const notify = useToastNotification();
28+
const executionData = useExecutionDataOptional();
2729

2830
const { awaitAuthorization, isAuthorized } = useAwaitAuthorization();
2931
const { getToken } = useAuthLocalStorage();
@@ -59,6 +61,7 @@ export const RerunPipelineButton = ({
5961

6062
return new Promise<PipelineRun>((resolve, reject) => {
6163
submitPipelineRun(componentSpec, backendUrl, {
64+
taskArguments: executionData?.rootDetails?.task_spec.arguments,
6265
authorizationToken,
6366
onSuccess: resolve,
6467
onError: reject,

0 commit comments

Comments
 (0)