Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(health): surface a fetch error in TestsReachingList (#2632)

Younes Berianeeb1d2ae31282
diff --git a/packages/ui/__tests__/health/inferred-tests.test.tsx b/packages/ui/__tests__/health/inferred-tests.test.tsx
index b955bb390..1b62d839f 100644
--- a/packages/ui/__tests__/health/inferred-tests.test.tsx
+++ b/packages/ui/__tests__/health/inferred-tests.test.tsx
@@ -281,4 +281,28 @@ describe("TestsReachingList", () => {
expect(container).toBeEmptyDOMElement();
});
+
+ it("shows an error state instead of the empty answer when the fetch rejects", async () => {
+ // A rejected fetch must not be mapped to the same sentence as a real
+ // "nothing reaches this file" answer: the reader needs to know the
+ // request failed, not that the file is untested.
+ render(
+ <TestsReachingList
+ filePath="src/a.py"
+ cacheKey="k6"
+ fetcher={async () => {
+ throw new Error("HTTP 500");
+ }}
+ />,
+ );
+
+ await waitFor(() =>
+ expect(
+ screen.getByText(/could not load which tests reach this file/i),
+ ).toBeInTheDocument(),
+ );
+ expect(
+ screen.queryByText(/No test in the repository calls into this file/),
+ ).not.toBeInTheDocument();
+ });
});
diff --git a/packages/ui/src/health/tests-reaching-list.tsx b/packages/ui/src/health/tests-reaching-list.tsx
index be1c5012e..be1076a93 100644
--- a/packages/ui/src/health/tests-reaching-list.tsx
+++ b/packages/ui/src/health/tests-reaching-list.tsx
@@ -44,15 +44,26 @@ export function TestsReachingList({
onSelect,
heading = true,
}: TestsReachingListProps) {
- const { data, isLoading } = useSWR<TestsReachingFile | null>(
+ const { data, error, isLoading } = useSWR<TestsReachingFile>(
fetcher ? `tests-reaching:${cacheKey}:${filePath}` : null,
- () => fetcher!(filePath).catch(() => null),
+ () => fetcher!(filePath),
{ revalidateOnFocus: false },
);
if (!fetcher) return null;
if (isLoading) return <Skeleton className="h-16 w-full max-w-[52ch] rounded-md" />;
+ if (error) {
+ return (
+ <div className="flex flex-col gap-1.5">
+ {heading ? <Heading>Tests reaching this file</Heading> : null}
+ <p className="max-w-[62ch] text-[13px] leading-relaxed text-[var(--color-text-secondary)] [text-wrap:pretty]">
+ Could not load which tests reach this file. Try again in a moment.
+ </p>
+ </div>
+ );
+ }
+
// A file nothing reaches is the honest answer, not an error, and it is the
// one the reader most needs: it is the whole left column of the chart.
if (!data || !data.reached || data.tests.length === 0) {