#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Mark the pipeline step that actually failed and retire stale test results (#7852)
Anthony Stirling3baba22f67f7
diff --git a/frontend/editor/src/portal/views/PipelineBuilder.test.tsx b/frontend/editor/src/portal/views/PipelineBuilder.test.tsxindex a9cccb83bb..3c680af40f 100644--- a/frontend/editor/src/portal/views/PipelineBuilder.test.tsx+++ b/frontend/editor/src/portal/views/PipelineBuilder.test.tsx@@ -34,6 +34,8 @@ const savePipeline = vi.fn();const deletePipeline = vi.fn();const triggerPipeline = vi.fn();const fetchRun = vi.fn();+const runPipelineTest = vi.fn();+const fetchRunOutput = vi.fn();vi.mock("@portal/api/pipelines", () => ({fetchPipeline: (id: string) => fetchPipeline(id),fetchTriggers: () => fetchTriggers(),@@ -41,6 +43,8 @@ vi.mock("@portal/api/pipelines", () => ({deletePipeline: (id: string) => deletePipeline(id),triggerPipeline: (id: string) => triggerPipeline(id),fetchRun: (runId: string) => fetchRun(runId),+ runPipelineTest: (...args: unknown[]) => runPipelineTest(...args),+ fetchRunOutput: (...args: unknown[]) => fetchRunOutput(...args),}));const uploadPipelineAsset = vi.fn();@@ -331,6 +335,8 @@ describe("PipelineBuilder", () => {deletePipeline.mockReset();triggerPipeline.mockReset();fetchRun.mockReset();+ runPipelineTest.mockReset();+ runPipelineTest.mockResolvedValue({ runId: "run-test-1" });fetchSources.mockReset();fetchPipeline.mockResolvedValue(POLICY);fetchTriggers.mockResolvedValue([]);@@ -889,6 +895,76 @@ describe("PipelineBuilder", () => {).toBeInTheDocument();});+ function twoStepPolicy(): Policy {+ return {+ ...POLICY,+ steps: [+ { operation: "/api/v1/misc/compress-pdf", parameters: {} },+ { operation: "/api/v1/misc/extract-images", parameters: {} },+ ] as unknown as Policy["steps"],+ };+ }++ async function runTestWith(view: Record<string, unknown>) {+ fetchRun.mockResolvedValue({+ runId: "run-test-1",+ stepCount: 2,+ outputs: [],+ error: null,+ ...view,+ });+ renderBuilder("/processor/pipelines/plc-1");+ await screen.findByText("portal.pipelines.builder.testRun");+ const picker = document.querySelector<HTMLInputElement>(+ 'input[type="file"][accept="application/pdf"]',+ );+ if (!picker) throw new Error("test-run file input not rendered");+ fireEvent.change(picker, {+ target: {+ files: [new File(["x"], "in.pdf", { type: "application/pdf" })],+ },+ });+ await waitFor(() => expect(runPipelineTest).toHaveBeenCalledTimes(1));+ }++ it("blames the step that actually failed, not the one after it", async () => {+ fetchPipeline.mockResolvedValue(twoStepPolicy());++ await runTestWith({ status: "FAILED", currentStep: 1, error: "boom" });++ await screen.findByLabelText("portal.pipelines.graph.showError");+ expect(screen.queryByText("portal.pipelines.graph.run.done")).toBeNull();+ });++ it("marks only the steps that finished before the one still running", async () => {+ fetchPipeline.mockResolvedValue(twoStepPolicy());++ await runTestWith({ status: "RUNNING", currentStep: 2 });++ await waitFor(() =>+ expect(+ screen.getAllByText("portal.pipelines.graph.run.done"),+ ).toHaveLength(1),+ );+ });++ it("retires a test result once the chain it ran against changes", async () => {+ fetchPipeline.mockResolvedValue(twoStepPolicy());++ await runTestWith({ status: "COMPLETED", currentStep: 2 });+ await waitFor(() =>+ expect(+ screen.getAllByText("portal.pipelines.graph.run.done"),+ ).toHaveLength(2),+ );++ await addTool("OCR");++ await waitFor(() =>+ expect(screen.queryByText("portal.pipelines.graph.run.done")).toBeNull(),+ );+ });+it("uploads a step's supporting file and saves it as an asset binding", async () => {renderBuilder("/processor/pipelines/new");diff --git a/frontend/editor/src/portal/views/PipelineBuilder.tsx b/frontend/editor/src/portal/views/PipelineBuilder.tsxindex f617eb5ce9..100c9a8f03 100644--- a/frontend/editor/src/portal/views/PipelineBuilder.tsx+++ b/frontend/editor/src/portal/views/PipelineBuilder.tsx@@ -725,6 +725,18 @@ export function PipelineBuilder() {}, [seeded, snapshot]);const dirty = baseline.current !== null && baseline.current !== snapshot;+ const stepsSignature = JSON.stringify(stepSnapshot);+ const testedStepsSignature = useRef<string | null>(null);+ useEffect(() => {+ if (+ testedStepsSignature.current !== null &&+ testedStepsSignature.current !== stepsSignature+ ) {+ testedStepsSignature.current = null;+ setTestRun(null);+ }+ }, [stepsSignature]);+// Each validity condition is defined exactly once here, then consumed both by the graph (which// flags each end) and by the blocker list below.const sourceChosen = input.sourceId !== "";@@ -956,6 +968,7 @@ export function PipelineBuilder() {if (testing) return;setTesting(true);setTestRun(null);+ testedStepsSignature.current = stepsSignature;setRunResult(null);try {const { steps: testSteps, assets } = buildTestSteps();@@ -1167,8 +1180,9 @@ export function PipelineBuilder() {// the cursor itself is whatever the run currently is.function stepRunState(index: number): GraphStepContent["runState"] {if (!testRun) return undefined;- if (index < testRun.currentStep) return "done";- if (index > testRun.currentStep) return undefined;+ const activeIndex = testRun.currentStep - 1;+ if (index < activeIndex) return "done";+ if (index > activeIndex) return undefined;if (testRun.status === "FAILED") return "failed";if (testRun.status === "COMPLETED") return "done";return "running";@@ -1205,7 +1219,10 @@ export function PipelineBuilder() {: testRun.status === "COMPLETED"? ("completed" as const): ("running" as const),- completedSteps: testRun.currentStep,+ completedSteps:+ testRun.status === "FAILED"+ ? Math.max(0, testRun.currentStep - 1)+ : testRun.currentStep,stepCount: testRun.stepCount,error: testRun.error,outputs: testRun.outputs ?? [],