Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
feat(ui): a steps-unavailable state in the opportunity drawer (#2732)
Raghav Chamadiya5b021bf32d86
diff --git a/packages/types/src/refactoring.ts b/packages/types/src/refactoring.tsindex 74e614fe5..68adfe527 100644--- a/packages/types/src/refactoring.ts+++ b/packages/types/src/refactoring.ts@@ -270,10 +270,18 @@ export interface RefactoringOpportunityDetailUnresolved {};}-export interface RefactoringOpportunityDetailResolved extends RefactoringOpportunity {+export interface RefactoringOpportunityDetailResolved+ extends Omit<RefactoringOpportunity, "steps_total"> {resolved: true;+ /**+ * `unavailable` when the opportunity resolved but its steps could not be+ * read: `steps` is empty and `steps_total` is null, while the row's own+ * `step_count` still says how many there are. Absent means available.+ */+ details_status?: "available" | "unavailable";steps: OpportunityStep[];- steps_total: number;+ /** Null only when `details_status` is `unavailable`. */+ steps_total: number | null;steps_emitted: number;steps_reduced_reason?: string;steps_next_cursor?: number;diff --git a/packages/ui/__tests__/refactoring/opportunity-drawer.test.tsx b/packages/ui/__tests__/refactoring/opportunity-drawer.test.tsxnew file mode 100644index 000000000..6c81edf5d--- /dev/null+++ b/packages/ui/__tests__/refactoring/opportunity-drawer.test.tsx@@ -0,0 +1,84 @@+/**+ * The drawer when an opportunity resolves but its steps do not load.+ *+ * A host that cannot read the steps still has the opportunity itself, so the+ * drawer keeps its facts and its triage control and says the steps are missing,+ * instead of an empty list under "The steps, in order".+ */++import { render, screen } from "@testing-library/react";+import { describe, expect, it } from "vitest";+import type { RefactoringOpportunityDetailResolved } from "@repowise-dev/types/refactoring";++import { OpportunityDrawer } from "../../src/refactoring/opportunity-drawer";++function detail(+ overrides: Partial<RefactoringOpportunityDetailResolved> = {},+): RefactoringOpportunityDetailResolved {+ return {+ resolved: true,+ opportunity_id: "refop2_drawer",+ refactoring_model_version: 2,+ status: "open",+ file_path: "packages/core/src/big.py",+ lead_biomarker: "nested_complexity",+ lead_refactoring_type: "split_file",+ addresses_primary_problem: true,+ effort_bucket: "M",+ confidence: "high",+ step_count: 7,+ mechanical_steps: 5,+ judgment_steps: 2,+ evidence_total: 0,+ affected_files_total: 1,+ recoverable_health: 1.4,+ rank_score: 1.45,+ rank_position: 1,+ queue_position: 1,+ rank_factors: {},+ why_ranked: [],+ steps: [],+ steps_total: 7,+ steps_emitted: 0,+ evidence: [],+ evidence_emitted: 0,+ evidence_truncated: false,+ affected_files: ["packages/core/src/big.py"],+ validation_profiles: [],+ plans: [],+ next_actions: [],+ ...overrides,+ };+}++function renderDrawer(d: RefactoringOpportunityDetailResolved) {+ render(+ <OpportunityDrawer+ detail={d}+ open+ onOpenChange={() => {}}+ onStatusChange={() => {}}+ onAiPrompt={() => {}}+ />,+ );+}++describe("OpportunityDrawer steps unavailable", () => {+ it("keeps triage and says the steps did not load", () => {+ renderDrawer(detail({ details_status: "unavailable", steps_total: null }));++ expect(screen.getByRole("radiogroup", { name: "Triage this opportunity" })).toBeTruthy();+ expect(screen.getByText(/The 7 steps for this opportunity could not be loaded/)).toBeTruthy();+ expect(screen.queryByText(/Showing 0 of/)).toBeNull();+ // The prompt is built from the steps, so it is not offered without them.+ expect(screen.queryByRole("button", { name: /Copy prompt/ })).toBeNull();+ });++ it("says nothing about missing steps when they loaded", () => {+ renderDrawer(detail({ details_status: "available", steps_total: 12, steps_emitted: 0 }));++ expect(screen.queryByText(/could not be loaded/)).toBeNull();+ expect(screen.getByText("Showing 0 of 12 steps.")).toBeTruthy();+ expect(screen.getByRole("button", { name: /Copy prompt/ })).toBeTruthy();+ });+});diff --git a/packages/ui/src/refactoring/opportunity-drawer.tsx b/packages/ui/src/refactoring/opportunity-drawer.tsxindex 3544634b9..ac84eda91 100644--- a/packages/ui/src/refactoring/opportunity-drawer.tsx+++ b/packages/ui/src/refactoring/opportunity-drawer.tsx@@ -164,6 +164,9 @@ function DrawerBody({const meta = typeMeta(detail.lead_refactoring_type || "");const name = detail.file_path.split("/").pop() ?? detail.file_path;const others = detail.affected_files.filter((f) => f !== detail.file_path);+ // The opportunity resolved but its steps did not load. Everything else in the+ // drawer, triage included, still describes a real opportunity.+ const stepsUnavailable = detail.details_status === "unavailable";const anyRelocated = detail.steps.some(isRelocated);const [pending, setPending] = React.useState<OpportunityStatus | null>(null);@@ -290,6 +293,12 @@ function DrawerBody({{detail.ordering_note ?? ORDERING_NOTE}</p>) : null}+ {stepsUnavailable ? (+ <p className="text-[12.5px] text-[var(--color-text-secondary)]">+ The {detail.step_count} step{detail.step_count === 1 ? "" : "s"} for this opportunity+ could not be loaded. Try again shortly, or ask for it by id below.+ </p>+ ) : null}<ol className="space-y-3">{detail.steps.map((step, i) => (<StepCard@@ -301,7 +310,7 @@ function DrawerBody({/>))}</ol>- {detail.steps_emitted < detail.steps_total ? (+ {detail.steps_total != null && detail.steps_emitted < detail.steps_total ? (<p className="mt-2 text-[11.5px] text-[var(--color-text-tertiary)]">Showing {detail.steps_emitted} of {detail.steps_total} steps.</p>@@ -408,7 +417,9 @@ function DrawerBody({</section></div>- {onAiPrompt ? (+ {/* The prompt carries the ordered steps; without them it would hand an+ agent an empty plan. */}+ {onAiPrompt && !stepsUnavailable ? (<div className="flex items-center gap-3 border-t border-[var(--color-border-default)] bg-[var(--color-bg-elevated)] px-5 py-3.5"><buttontype="button"