From faf719ca313f69b9ea3f30459a97a8a4b98a5f16 Mon Sep 17 00:00:00 2001 From: claude Date: Tue, 13 Oct 2026 18:58:35 +0200 Subject: [PATCH] Pipelines: a preview endpoint that draws and checks a graph while it is being built --- OpenBench/pipeline_views.py | 36 ++++++++++++++ OpenBench/tests_pipeline_views.py | 78 +++++++++++++++++++++++++++++++ OpenBench/urls.py | 1 + 3 files changed, 115 insertions(+) diff --git a/OpenBench/pipeline_views.py b/OpenBench/pipeline_views.py index 65ecec5..4f39470 100644 --- a/OpenBench/pipeline_views.py +++ b/OpenBench/pipeline_views.py @@ -556,6 +556,42 @@ def pipeline_check(request): return JsonResponse({ 'issues' : _check(graph) }) +MAX_PREVIEW_EDGES = 400 + +def _drawable(graph): + + """ Whether a graph is sound enough in shape to be laid out. Whatever else is + wrong with it, the editor still wants to see it, so that it can be fixed """ + + steps, edges = graph.get('steps'), graph.get('edges', []) + + return ( + isinstance(steps, dict) and 0 < len(steps) <= graphs.LIMIT_STEPS + and all(isinstance(step, dict) for step in steps.values()) + and isinstance(edges, list) and len(edges) <= MAX_PREVIEW_EDGES + and all(isinstance(edge, dict) for edge in edges) + ) + +@require_POST +def pipeline_preview(request): + + """ The flow of a graph as it is drawn on a run, and its checks, for the + editor to show while a pipeline is being built. Saves nothing """ + + if viewer(request) is None: + return JsonResponse({ 'error' : 'Not allowed' }, status=403) + + graph = _parse_graph(request.POST.get('graph')) + if graph is None: + return JsonResponse({ 'svg' : '', 'issues' : [graphs.issue('error', 'graph.invalid', 'The pipeline could not be read')] }) + + svg = '' + if _drawable(graph): + try: svg = drawing.render_svg(graph) + except Exception: svg = '' # A half built graph is not a reason for a 500 + + return JsonResponse({ 'svg' : svg, 'issues' : _named(_check(graph), graph) }) + def pipeline_test_fields(request, test_id): """ The settings of an existing SPRT or Games test, as the settings of a step """ diff --git a/OpenBench/tests_pipeline_views.py b/OpenBench/tests_pipeline_views.py index 6c951fd..0de3fb0 100644 --- a/OpenBench/tests_pipeline_views.py +++ b/OpenBench/tests_pipeline_views.py @@ -24,6 +24,7 @@ # The Pipeline pages, with a real ( test ) database and the real URL routing. As # in tests_pipelines.py, only the call out to Github is replaced. +import json import re from django.contrib.auth.models import User @@ -493,3 +494,80 @@ class ChipTests(PagesTestCase): page = self.client_for(self.user).get(url).content.decode() self.assertNotIn(''), self.user).json() + + self.assertIn('class="pl-graph"', data['svg']) + self.assertNotIn('