From 73e89c3a7499a0db16b44734162eb0a522493276 Mon Sep 17 00:00:00 2001 From: James Brunton Date: Wed, 2 Sep 2026 10:57:08 +0100 Subject: [PATCH] Resolve duplicates between policies and pipelines --- frontend/editor/src/portal/api/pipelines.ts | 40 +++++-------------- .../editor/src/proprietary/policies/runs.ts | 2 +- .../editor/src/proprietary/policies/types.ts | 8 +++- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/frontend/editor/src/portal/api/pipelines.ts b/frontend/editor/src/portal/api/pipelines.ts index 2b18798d45..69dcb0d3fe 100644 --- a/frontend/editor/src/portal/api/pipelines.ts +++ b/frontend/editor/src/portal/api/pipelines.ts @@ -3,6 +3,11 @@ import { type SupportingFileBindings, type ToolApiStep, } from "@app/hooks/tools/shared/toolAutomation"; +import type { + PolicyRunView, + PolicyRunStatus, + RunOutputFile, +} from "@app/policies/types"; /** * Pipelines service layer: the backend contract. @@ -132,37 +137,10 @@ export interface TriggerInfo { supportedSourceTypes: string[]; } -export type PolicyRunStatus = - | "PENDING" - | "RUNNING" - | "WAITING_FOR_INPUT" - | "COMPLETED" - | "FAILED" - | "CANCELLED"; - -/** One file a run produced, downloadable via /api/v1/general/files/{fileId}. */ -export interface RunOutputFile { - fileId: string; - fileName: string | null; -} - -/** A run's current state. Mirrors the backend `PolicyRunView`. */ -export interface PolicyRunView { - runId: string; - policyId: string | null; - status: PolicyRunStatus; - currentStep: number; - stepCount: number; - /** Human-readable failure message; set when status is FAILED. */ - error: string | null; - errorCode: string | null; - /** - * Files the run produced, present once it completes. Whole-run, not per step: the backend keeps - * one flat list, so nothing here can be attributed to an individual step. - */ - outputs?: RunOutputFile[] | null; - createdAt: number; -} +// One run view for the whole app: the builder test-run poll and the catalogue runs list read the +// same backend PolicyRunView, so the type is defined once in the codec (imported above) and +// re-exported here for callers that reach it through the pipelines API. +export type { PolicyRunView, PolicyRunStatus, RunOutputFile }; /** GET /api/v1/policies/overview: KPI strip + one row per policy for the admin. */ export async function fetchPipelines(): Promise { diff --git a/frontend/editor/src/proprietary/policies/runs.ts b/frontend/editor/src/proprietary/policies/runs.ts index 74f1449259..8eac88b766 100644 --- a/frontend/editor/src/proprietary/policies/runs.ts +++ b/frontend/editor/src/proprietary/policies/runs.ts @@ -47,7 +47,7 @@ function activityAction(run: PolicyRunView): string { export function runsToActivity(runs: PolicyRunView[]): PolicyActivityItem[] { return runs.map((run) => ({ - doc: run.outputs[0]?.fileName ?? "Policy run", + doc: run.outputs?.[0]?.fileName ?? "Policy run", action: activityAction(run), time: relativeTime(run.createdAt), status: activityStatus(run), diff --git a/frontend/editor/src/proprietary/policies/types.ts b/frontend/editor/src/proprietary/policies/types.ts index 8e2cd16236..5adaabf5fe 100644 --- a/frontend/editor/src/proprietary/policies/types.ts +++ b/frontend/editor/src/proprietary/policies/types.ts @@ -70,6 +70,12 @@ export type PolicyRunStatus = | "FAILED" | "CANCELLED"; +/** One file a run produced, downloadable via /api/v1/general/files/{fileId}. */ +export interface RunOutputFile { + fileId: string; + fileName: string | null; +} + export interface PolicyRunView { runId: string; policyId: string | null; @@ -79,7 +85,7 @@ export interface PolicyRunView { error: string | null; errorCode?: string | null; errorSubscribed?: boolean | null; - outputs: { fileId: string; fileName: string }[]; + outputs?: RunOutputFile[] | null; /** Creation timestamp in epoch milliseconds. */ createdAt: number; }