From 2dc85f4c08a8abe2a449da3a09bdff9a124e8e37 Mon Sep 17 00:00:00 2001 From: Prince Pal <107296821+princepal9120@users.noreply.github.com> Date: Wed, 22 Apr 2026 00:40:52 +0530 Subject: [PATCH] fix(import): mark skipped resources as partial progress (#2095) * fix(import): mark skipped resources as partial progress * test(import): cover phase status edge cases --- packages/api/src/service/import.test.ts | 57 ++++++++++++++++++++++++- packages/api/src/service/import.ts | 16 ++++--- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/packages/api/src/service/import.test.ts b/packages/api/src/service/import.test.ts index 057916700..b554379e9 100644 --- a/packages/api/src/service/import.test.ts +++ b/packages/api/src/service/import.test.ts @@ -2,7 +2,11 @@ import { describe, expect, test } from "bun:test"; import { allPlans } from "@openstatus/db/src/schema/plan/config"; import type { Limits } from "@openstatus/db/src/schema/plan/schema"; import type { ImportSummary } from "@openstatus/importers"; -import { addLimitWarnings, clampPeriodicity } from "./import"; +import { + addLimitWarnings, + clampPeriodicity, + computePhaseStatus, +} from "./import"; function makeSummary(overrides?: Partial): ImportSummary { return { @@ -362,6 +366,57 @@ describe("addLimitWarnings", () => { }); }); +describe("computePhaseStatus", () => { + test("returns completed for empty resources", () => { + expect(computePhaseStatus([])).toBe("completed"); + }); + + test("returns completed when all resources are created", () => { + expect( + computePhaseStatus([ + { sourceId: "1", name: "A", status: "created" }, + { sourceId: "2", name: "B", status: "created" }, + ]), + ).toBe("completed"); + }); + + test("returns completed when all resources are skipped", () => { + expect( + computePhaseStatus([ + { sourceId: "1", name: "A", status: "skipped" }, + { sourceId: "2", name: "B", status: "skipped" }, + ]), + ).toBe("completed"); + }); + + test("returns partial when some resources are skipped", () => { + expect( + computePhaseStatus([ + { sourceId: "1", name: "A", status: "created" }, + { sourceId: "2", name: "B", status: "skipped" }, + ]), + ).toBe("partial"); + }); + + test("returns partial when some resources fail", () => { + expect( + computePhaseStatus([ + { sourceId: "1", name: "A", status: "created" }, + { sourceId: "2", name: "B", status: "failed" }, + ]), + ).toBe("partial"); + }); + + test("returns failed when all resources fail", () => { + expect( + computePhaseStatus([ + { sourceId: "1", name: "A", status: "failed" }, + { sourceId: "2", name: "B", status: "failed" }, + ]), + ).toBe("failed"); + }); +}); + describe("clampPeriodicity", () => { const freePlan = allPlans.free.limits.periodicity as string[]; const starterPlan = allPlans.starter.limits.periodicity as string[]; diff --git a/packages/api/src/service/import.ts b/packages/api/src/service/import.ts index cc4fb0e8a..312093286 100644 --- a/packages/api/src/service/import.ts +++ b/packages/api/src/service/import.ts @@ -416,14 +416,20 @@ export function clampPeriodicity(requested: string, allowed: string[]): string { // Phase writers // --------------------------------------------------------------------------- -function computePhaseStatus( +export function computePhaseStatus( resources: ResourceResult[], ): PhaseResult["status"] { if (resources.length === 0) return "completed"; + const allFailed = resources.every((r) => r.status === "failed"); if (allFailed) return "failed"; + const hasFailed = resources.some((r) => r.status === "failed"); - if (hasFailed) return "partial"; + const hasSkipped = resources.some((r) => r.status === "skipped"); + const allSkipped = resources.every((r) => r.status === "skipped"); + + if (hasFailed || (hasSkipped && !allSkipped)) return "partial"; + return "completed"; } @@ -476,7 +482,7 @@ async function writePagePhase( resource.openstatusId = existingPageId; resource.status = "skipped"; - phase.status = "completed"; + phase.status = computePhaseStatus(phase.resources); return existingPageId; } @@ -490,7 +496,7 @@ async function writePagePhase( if (existingBySlug) { resource.openstatusId = existingBySlug.id; resource.status = "skipped"; - phase.status = "completed"; + phase.status = computePhaseStatus(phase.resources); return existingBySlug.id; } @@ -514,7 +520,7 @@ async function writePagePhase( resource.openstatusId = inserted.id; resource.status = "created"; - phase.status = "completed"; + phase.status = computePhaseStatus(phase.resources); return inserted.id; } -- knotmirror 0.0.1