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(nav): links land where their label says (#1158)

Swati Ahuja6ddda0b27c3f
diff --git a/packages/ui/__tests__/lib/page-types.test.ts b/packages/ui/__tests__/lib/page-types.test.ts
index 6bbc91066..6881bc666 100644
--- a/packages/ui/__tests__/lib/page-types.test.ts
+++ b/packages/ui/__tests__/lib/page-types.test.ts
@@ -1,5 +1,6 @@
import { describe, it, expect } from "vitest";
import {
+ getPageTypeLabel,
isModelWrittenType,
isStubPage,
MODEL_WRITTEN_PAGE_TYPES,
@@ -58,3 +59,16 @@ describe("isStubPage", () => {
expect(isStubPage(undefined)).toBe(false);
});
});
+
+describe("getPageTypeLabel", () => {
+ it("calls a cycle page a cycle, the same word the tree uses", () => {
+ // The tree labels these "Cycle: generation/page_generator" via
+ // sccDisplayLabel. The filter chip said "SCC", so the one control for
+ // narrowing to them shared no word with the rows it selected.
+ expect(getPageTypeLabel("scc_page")).toBe("Cycle");
+ });
+
+ it("humanises an unknown type rather than rendering nothing", () => {
+ expect(getPageTypeLabel("not_a_page_type")).toBe("not a page type");
+ });
+});
diff --git a/packages/ui/src/commits/commits-lede.tsx b/packages/ui/src/commits/commits-lede.tsx
index 5e772ff92..d8d713844 100644
--- a/packages/ui/src/commits/commits-lede.tsx
+++ b/packages/ui/src/commits/commits-lede.tsx
@@ -46,7 +46,7 @@ export function CommitsLede({ stats, base, LinkComponent }: CommitsLedeProps) {
value: stats.fix_commit_count.toLocaleString(),
unit: `${fixPct}%`,
why: "Commits whose subject reads as a bug fix rather than new work.",
- href: `${base}/hotspots`,
+ href: `${base}/code-health?tab=triage`,
},
];
if (stats.agent_commit_count > 0) {
@@ -69,7 +69,7 @@ export function CommitsLede({ stats, base, LinkComponent }: CommitsLedeProps) {
// It has no 1.0 ceiling: k equally-changed files score log2(k), so this
// repo's 2.08 is roughly four files' worth of spread.
why: "Shannon entropy of a commit's churn across its files. Zero is a single file, and every extra bit is a doubling of how widely the change spread.",
- href: `${base}/coupling`,
+ href: `${base}/architecture?view=coupling`,
});
if (stats.high_cut != null) {
reads.push({
@@ -78,7 +78,7 @@ export function CommitsLede({ stats, base, LinkComponent }: CommitsLedeProps) {
value: stats.high_cut.toFixed(1),
unit: "out of 10",
why: "Score a commit has to clear to land in this repo's top tercile.",
- href: `${base}/risk`,
+ href: `${base}/code-health?tab=triage`,
});
}
diff --git a/packages/ui/src/dashboard/attention-href.ts b/packages/ui/src/dashboard/attention-href.ts
index 6da4f7add..d0e569f90 100644
--- a/packages/ui/src/dashboard/attention-href.ts
+++ b/packages/ui/src/dashboard/attention-href.ts
@@ -49,7 +49,7 @@ export function getDefaultHref(item: AttentionItem, prefix: string): string {
return target ? `${prefix}/owners?path=${encodeURIComponent(target)}` : `${prefix}/owners`;
case "ungoverned_hotspot":
// Target is the hotspot's file path → open its file entity page.
- return target ? fileEntityPath(prefix, target) : `${prefix}/code-health?tab=hotspots`;
+ return target ? fileEntityPath(prefix, target) : `${prefix}/code-health?tab=triage`;
case "dead_code":
return `${prefix}/code-health?tab=dead-code`;
default:
diff --git a/packages/ui/src/dashboard/hotspots-mini.tsx b/packages/ui/src/dashboard/hotspots-mini.tsx
index c1e1cc456..05abd738f 100644
--- a/packages/ui/src/dashboard/hotspots-mini.tsx
+++ b/packages/ui/src/dashboard/hotspots-mini.tsx
@@ -66,7 +66,7 @@ export function HotspotsMini({
</span>
</span>
<a
- href={`${prefix}/code-health?tab=hotspots`}
+ href={`${prefix}/code-health?tab=triage`}
className="text-[10px] text-[var(--color-accent-primary)] hover:underline font-normal"
>
View all
diff --git a/packages/ui/src/git/ownership-table.tsx b/packages/ui/src/git/ownership-table.tsx
index 38ce9b5f7..55cff923a 100644
--- a/packages/ui/src/git/ownership-table.tsx
+++ b/packages/ui/src/git/ownership-table.tsx
@@ -132,7 +132,7 @@ export function OwnershipTable({ entries, repoId, linkPrefix }: OwnershipTablePr
<RowActions
actions={[
{ icon: GitBranch, label: "Graph", href: `${prefix}/architecture?view=graph&node=${encodeURIComponent(entry.module_path)}` },
- { icon: Flame, label: "Hotspots", href: `${prefix}/code-health?tab=hotspots` },
+ { icon: Flame, label: "Hotspots", href: `${prefix}/code-health?tab=triage` },
]}
/>
)}
diff --git a/packages/ui/src/lib/page-types.ts b/packages/ui/src/lib/page-types.ts
index 04c096728..251716eef 100644
--- a/packages/ui/src/lib/page-types.ts
+++ b/packages/ui/src/lib/page-types.ts
@@ -26,7 +26,9 @@ export const PAGE_TYPE_CONFIG: Record<string, PageTypeConfig> = {
symbol_spotlight: { label: "Symbol", icon: Sparkles },
file_page: { label: "File", icon: FileText },
api_contract: { label: "API Contract", icon: FileCode },
- scc_page: { label: "SCC", icon: RefreshCw },
+ // "Cycle", not "SCC" — the tree labels these pages "Cycle: <path>", and the
+ // filter chip is the control that narrows to them, so it uses the same word.
+ scc_page: { label: "Cycle", icon: RefreshCw },
infra_page: { label: "Infra", icon: Server },
onboarding: { label: "Onboarding", icon: Compass },
};
diff --git a/packages/ui/src/owners/owner-directory.tsx b/packages/ui/src/owners/owner-directory.tsx
index f46a50b6e..6f70e64e7 100644
--- a/packages/ui/src/owners/owner-directory.tsx
+++ b/packages/ui/src/owners/owner-directory.tsx
@@ -136,7 +136,7 @@ export function OwnerDirectory({
summary.soleFilesInactive > 0
? `One author, no second reader. ${summary.soleFilesInactive.toLocaleString()} belong to someone who has not committed in ${INACTIVE_DAYS} days.`
: "One author and no second reader, though all of them belong to someone still active.",
- href: base ? `${base}/ownership` : "#",
+ href: base ? `${base}/owners` : "#",
});
}
if (summary.siloModules > 0) {
@@ -164,7 +164,7 @@ export function OwnerDirectory({
value: summary.deadLines.toLocaleString(),
unit: `${summary.deadOwners} ${summary.deadOwners === 1 ? "person" : "people"}`,
why: "Unreachable code still attributed to whoever wrote it.",
- href: base ? `${base}/dead-code` : "#",
+ href: base ? `${base}/code-health?tab=dead-code` : "#",
});
}
@@ -252,7 +252,7 @@ export function OwnerDirectory({
{...(base
? {
action: (
- <SectionLink href={`${base}/ownership`} LinkComponent={LinkComponent}>
+ <SectionLink href={`${base}/owners`} LinkComponent={LinkComponent}>
Ownership map
</SectionLink>
),
diff --git a/packages/ui/src/owners/owner-profile.tsx b/packages/ui/src/owners/owner-profile.tsx
index 235f509b9..4340fb6bf 100644
--- a/packages/ui/src/owners/owner-profile.tsx
+++ b/packages/ui/src/owners/owner-profile.tsx
@@ -125,7 +125,7 @@ export function OwnerProfileView({
value: owner.dead_code_files_owned.toLocaleString(),
unit: "files",
why: `${owner.dead_code_lines_owned.toLocaleString()} unreachable lines still attributed here. Usually the cheapest thing on this page to act on.`,
- href: `${base}/dead-code`,
+ href: `${base}/code-health?tab=dead-code`,
});
}
if (owner.silo_modules > 0) {
@@ -135,7 +135,7 @@ export function OwnerProfileView({
value: owner.silo_modules.toLocaleString(),
unit: owner.silo_modules === 1 ? "directory" : "directories",
why: "Top-level directories where this person owns more than 80% of the files, so a review has nobody obvious to route to.",
- href: `${base}/ownership`,
+ href: `${base}/owners`,
});
}
if (owner.agent_collab && owner.agent_collab.agent_commit_count > 0) {
@@ -287,7 +287,7 @@ function OwnershipFootprint({
title="Where the ownership sits"
description="Share is the fraction of each directory's files where this person wrote most of the surviving lines. Only top-level directories are attributed, so this is a coarse map rather than a per-module one."
action={
- <SectionLink href={`${base}/ownership`} LinkComponent={LinkComponent}>
+ <SectionLink href={`${base}/owners`} LinkComponent={LinkComponent}>
Ownership
</SectionLink>
}
diff --git a/packages/web/src/app/repos/[id]/code-health/trend/page.tsx b/packages/web/src/app/repos/[id]/code-health/trend/page.tsx
index fffdc28ca..9f04d250e 100644
--- a/packages/web/src/app/repos/[id]/code-health/trend/page.tsx
+++ b/packages/web/src/app/repos/[id]/code-health/trend/page.tsx
@@ -7,5 +7,5 @@ export default async function LegacyRedirect({
params: Promise<{ id: string }>;
}) {
const { id } = await params;
- redirect(`/repos/${id}/code-health?tab=trend`);
+ redirect(`/repos/${id}/code-health?tab=triage`);
}
diff --git a/packages/web/src/app/repos/[id]/commits/page.tsx b/packages/web/src/app/repos/[id]/commits/page.tsx
index 601e86241..1d5e65924 100644
--- a/packages/web/src/app/repos/[id]/commits/page.tsx
+++ b/packages/web/src/app/repos/[id]/commits/page.tsx
@@ -114,7 +114,7 @@ export default async function CommitsPage({
title="How the score behaves here"
description="Two views of the same model: where the cuts fall, and what commit shape lands you above them."
action={
- <SectionLink href={`${base}/risk`} LinkComponent={Link}>
+ <SectionLink href={`${base}/code-health?tab=triage`} LinkComponent={Link}>
Change risk
</SectionLink>
}
diff --git a/packages/web/src/app/repos/[id]/health/trend/page.tsx b/packages/web/src/app/repos/[id]/health/trend/page.tsx
index e737bea24..f0d6dbaaa 100644
--- a/packages/web/src/app/repos/[id]/health/trend/page.tsx
+++ b/packages/web/src/app/repos/[id]/health/trend/page.tsx
@@ -7,5 +7,5 @@ export default async function LegacyRedirect({
params: Promise<{ id: string }>;
}) {
const { id } = await params;
- redirect(`/repos/${id}/code-health?tab=trend`);
+ redirect(`/repos/${id}/code-health?tab=triage`);
}
diff --git a/packages/web/src/app/repos/[id]/hotspots/page.tsx b/packages/web/src/app/repos/[id]/hotspots/page.tsx
index 7e4437f25..f0d6dbaaa 100644
--- a/packages/web/src/app/repos/[id]/hotspots/page.tsx
+++ b/packages/web/src/app/repos/[id]/hotspots/page.tsx
@@ -7,5 +7,5 @@ export default async function LegacyRedirect({
params: Promise<{ id: string }>;
}) {
const { id } = await params;
- redirect(`/repos/${id}/code-health?tab=hotspots`);
+ redirect(`/repos/${id}/code-health?tab=triage`);
}
diff --git a/packages/web/src/app/repos/[id]/modules/[path]/page.tsx b/packages/web/src/app/repos/[id]/modules/[path]/page.tsx
index cf74f5308..6b79c463d 100644
--- a/packages/web/src/app/repos/[id]/modules/[path]/page.tsx
+++ b/packages/web/src/app/repos/[id]/modules/[path]/page.tsx
@@ -27,7 +27,7 @@ export default function ModuleHealthPage() {
return (
<ModuleDetailShell
- backHref={`/repos/${id}/code-health?tab=modules`}
+ backHref={`/repos/${id}/code-health?tab=triage`}
LinkComponent={Link}
>
{isLoading && (
@@ -52,7 +52,9 @@ export default function ModuleHealthPage() {
<ModuleHealthDetailView
module={data}
breadcrumb={[
- { label: "Modules", href: `/repos/${id}/code-health?tab=modules` },
+ // There is no Modules tab any more — it folded into the map's hub
+ // layer on the overview. Name where the link actually goes.
+ { label: "Code Health", href: `/repos/${id}/code-health?tab=triage` },
{ label: modulePath.split("/").pop() || modulePath },
]}
LinkComponent={Link}
diff --git a/packages/web/src/app/repos/[id]/overview/page.tsx b/packages/web/src/app/repos/[id]/overview/page.tsx
index de2f07914..191c433ba 100644
--- a/packages/web/src/app/repos/[id]/overview/page.tsx
+++ b/packages/web/src/app/repos/[id]/overview/page.tsx
@@ -422,7 +422,7 @@ export default async function OverviewPage({ params }: Props) {
title="Where the risk concentrates"
description="Ranked by prior bug fixes and change frequency, mined from full git history rather than from the code alone."
action={
- <SectionLink href={`${base}/code-health?tab=hotspots`} LinkComponent={Link}>
+ <SectionLink href={`${base}/code-health?tab=triage`} LinkComponent={Link}>
{`All ${formatNumber(stats.hotspot_count)} hotspots`}
</SectionLink>
}
diff --git a/packages/web/src/app/repos/[id]/search/loading.tsx b/packages/web/src/app/repos/[id]/search/loading.tsx
deleted file mode 100644
index 806027c41..000000000
--- a/packages/web/src/app/repos/[id]/search/loading.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { OwlLoader } from "@repowise-dev/ui/shared/owl-loader";
-
-export default function SearchLoading() {
- return <OwlLoader />;
-}
diff --git a/packages/web/src/app/repos/[id]/search/page.tsx b/packages/web/src/app/repos/[id]/search/page.tsx
deleted file mode 100644
index 821f8c398..000000000
--- a/packages/web/src/app/repos/[id]/search/page.tsx
+++ /dev/null
@@ -1,122 +0,0 @@
-"use client";
-
-import { useState } from "react";
-import { useParams } from "next/navigation";
-import { Search } from "lucide-react";
-import { SearchBar } from "@/components/search/search-bar";
-import { SearchResultCard } from "@/components/search/search-result-card";
-import { EmptyState } from "@repowise-dev/ui/shared/empty-state";
-import { Skeleton } from "@repowise-dev/ui/ui/skeleton";
-import { useSearch } from "@/lib/hooks/use-search";
-import { toFriendlyMessage } from "@repowise-dev/ui/lib/errors";
-
-type SearchType = "fulltext" | "semantic";
-
-export default function SearchPage() {
- const params = useParams<{ id: string }>();
- const id = params.id;
- const [query, setQuery] = useState("");
- const [searchType, setSearchType] = useState<SearchType>("semantic");
- const [scope, setScope] = useState<"repo" | "workspace">("repo");
-
- // Synthetic ws:<alias> IDs point at unindexed workspace entries — the
- // backend short-circuits search on those. Skip the repo_id filter and
- // gently fall back to workspace scope so the user still sees results.
- const isSynthetic = id?.startsWith("ws:");
- const effectiveRepoId =
- scope === "repo" && !isSynthetic ? id : undefined;
-
- const { results, isLoading, isTyping, error } = useSearch(query, {
- search_type: searchType,
- limit: 20,
- repo_id: effectiveRepoId,
- });
-
- const showResults = query.trim().length >= 2;
- const loading = (isLoading || isTyping) && showResults;
-
- return (
- <div className="p-4 sm:p-6 space-y-6 max-w-3xl">
- <div>
- <h1 className="text-xl font-semibold text-[var(--color-text-primary)] mb-1 flex items-center gap-2">
- <Search className="h-5 w-5 text-[var(--color-accent-primary)]" />
- Search
- </h1>
- <p className="text-sm text-[var(--color-text-secondary)]">
- Full-text and semantic search across {scope === "repo" ? "this repo" : "the whole workspace"}.
- </p>
- </div>
-
- <SearchBar
- query={query}
- onQueryChange={setQuery}
- searchType={searchType}
- onSearchTypeChange={setSearchType}
- />
-
- <div className="flex items-center gap-2 text-xs">
- <span className="text-[var(--color-text-tertiary)]">Scope:</span>
- <button
- type="button"
- onClick={() => setScope("repo")}
- disabled={isSynthetic}
- className={
- "rounded-md border px-2 py-1 transition-colors " +
- (scope === "repo" && !isSynthetic
- ? "border-[var(--color-accent-primary)] bg-[var(--color-accent-primary)]/10 text-[var(--color-text-primary)]"
- : "border-[var(--color-border-default)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-elevated)] disabled:opacity-50")
- }
- title={isSynthetic ? "This repo isn't indexed yet — workspace scope used." : undefined}
- >
- This repo
- </button>
- <button
- type="button"
- onClick={() => setScope("workspace")}
- className={
- "rounded-md border px-2 py-1 transition-colors " +
- (scope === "workspace" || isSynthetic
- ? "border-[var(--color-accent-primary)] bg-[var(--color-accent-primary)]/10 text-[var(--color-text-primary)]"
- : "border-[var(--color-border-default)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-elevated)]")
- }
- >
- Workspace
- </button>
- </div>
-
- {showResults && error && (
- <div className="rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-elevated)] p-4 text-sm text-[var(--color-outdated)]">
- Couldn&apos;t run search: {toFriendlyMessage(error)}
- </div>
- )}
-
- {!showResults ? (
- <EmptyState
- title="Start typing to search"
- description="Search across titles, content, and file paths."
- icon={<Search className="h-8 w-8" />}
- />
- ) : loading ? (
- <div className="space-y-3">
- {Array.from({ length: 5 }).map((_, i) => (
- <Skeleton key={i} className="h-20 w-full rounded-lg" />
- ))}
- </div>
- ) : results.length === 0 ? (
- <EmptyState
- title="No results"
- description={`No pages matched "${query}". Try different keywords or switch search mode.`}
- />
- ) : (
- <div className="space-y-3">
- <p className="text-xs text-[var(--color-text-tertiary)]">
- {results.length} result{results.length !== 1 ? "s" : ""} for &ldquo;{query}&rdquo;
- </p>
- {results.map((r) => (
- <SearchResultCard key={r.page_id} result={r} query={query} repoId={id} />
- ))}
- </div>
- )}
- </div>
- );
-}
diff --git a/packages/web/src/components/decisions/decision-detail.tsx b/packages/web/src/components/decisions/decision-detail.tsx
index 15577e706..a7add8855 100644
--- a/packages/web/src/components/decisions/decision-detail.tsx
+++ b/packages/web/src/components/decisions/decision-detail.tsx
@@ -56,7 +56,7 @@ export function DecisionDetail({ decision, repoId }: DecisionDetailProps) {
: "";
return `${prefix}/commits${qs}`;
},
- hotspotsHref: () => `${prefix}/code-health?tab=hotspots`,
+ hotspotsHref: () => `${prefix}/code-health?tab=triage`,
LinkComponent: Link,
};
diff --git a/packages/web/src/components/search/search-bar.tsx b/packages/web/src/components/search/search-bar.tsx
deleted file mode 100644
index 328d67a5a..000000000
--- a/packages/web/src/components/search/search-bar.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-"use client";
-
-import { Search } from "lucide-react";
-import { Input } from "@repowise-dev/ui/ui/input";
-import { cn } from "@/lib/utils/cn";
-
-type SearchType = "fulltext" | "semantic";
-
-interface SearchBarProps {
- query: string;
- onQueryChange: (q: string) => void;
- searchType: SearchType;
- onSearchTypeChange: (t: SearchType) => void;
- className?: string;
-}
-
-export function SearchBar({
- query,
- onQueryChange,
- searchType,
- onSearchTypeChange,
- className,
-}: SearchBarProps) {
- return (
- <div className={cn("flex items-center gap-2", className)}>
- <div className="relative flex-1">
- <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-[var(--color-text-tertiary)]" />
- <Input
- value={query}
- onChange={(e) => onQueryChange(e.target.value)}
- placeholder="Search wiki pages…"
- className="pl-9"
- autoFocus
- />
- </div>
- <div className="flex rounded-md border border-[var(--color-border-default)] overflow-hidden text-xs">
- {(["fulltext", "semantic"] as SearchType[]).map((t) => (
- <button
- key={t}
- onClick={() => onSearchTypeChange(t)}
- className={cn(
- "px-3 py-1.5 font-medium transition-colors capitalize",
- searchType === t
- ? "bg-[var(--color-accent-primary)] text-[var(--color-text-inverse)]"
- : "bg-transparent text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-elevated)]",
- )}
- >
- {t}
- </button>
- ))}
- </div>
- </div>
- );
-}
diff --git a/packages/web/src/components/search/search-result-card.tsx b/packages/web/src/components/search/search-result-card.tsx
deleted file mode 100644
index 68c074bdc..000000000
--- a/packages/web/src/components/search/search-result-card.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import Link from "next/link";
-import { Badge } from "@repowise-dev/ui/ui/badge";
-import { truncatePath } from "@repowise-dev/ui/lib/format";
-import { getPageTypeLabel } from "@repowise-dev/ui/lib/page-types";
-import { cn } from "@/lib/utils/cn";
-import { pageHref } from "@/lib/utils/page-href";
-import type { SearchResultResponse } from "@/lib/api/types";
-
-interface SearchResultCardProps {
- result: SearchResultResponse;
- query: string;
- repoId: string;
-}
-
-function highlightSnippet(snippet: string, query: string): React.ReactNode {
- if (!query.trim()) return snippet;
- const terms = query.trim().split(/\s+/).filter(Boolean);
- const escaped = terms.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
- const regex = new RegExp(`(${escaped})`, "gi");
- // split with capturing group yields alternating non-match / match / non-match ...
- const parts = snippet.split(regex);
- return parts.map((part, i) =>
- i % 2 === 1 ? (
- <strong key={i} className="text-[var(--color-text-primary)] font-semibold">
- {part}
- </strong>
- ) : (
- <span key={i}>{part}</span>
- ),
- );
-}
-
-export function SearchResultCard({ result, query, repoId }: SearchResultCardProps) {
- const href = pageHref(repoId, result.page_id);
-
- return (
- <Link
- href={href}
- className="block rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-4 hover:border-[var(--color-border-hover)] hover:bg-[var(--color-bg-elevated)] transition-colors"
- >
- <div className="flex items-start justify-between gap-2 mb-1.5">
- <h3 className="text-sm font-medium text-[var(--color-text-primary)] truncate" title={result.title}>
- {result.title}
- </h3>
- <div className="flex items-center gap-1.5 shrink-0">
- <Badge variant="default">{getPageTypeLabel(result.page_type)}</Badge>
- <span
- className={cn(
- "inline-flex items-center rounded border px-2 py-0.5 text-xs font-medium tabular-nums",
- result.score >= 0.8
- ? "border-[var(--color-success)]/20 bg-[var(--color-success)]/10 text-[var(--color-success)]"
- : result.score >= 0.5
- ? "border-[var(--color-warning)]/20 bg-[var(--color-warning)]/10 text-[var(--color-warning)]"
- : "border-[var(--color-border-default)] bg-transparent text-[var(--color-text-tertiary)]",
- )}
- >
- {Math.round(result.score * 100)}%
- </span>
- </div>
- </div>
- <p className="text-xs font-mono text-[var(--color-text-tertiary)] mb-2" title={result.target_path}>
- {truncatePath(result.target_path, 60)}
- </p>
- {result.snippet && (
- <p className="text-xs text-[var(--color-text-secondary)] line-clamp-2 leading-relaxed">
- {highlightSnippet(result.snippet, query)}
- </p>
- )}
- </Link>
- );
-}
diff --git a/packages/web/src/lib/route-links.test.ts b/packages/web/src/lib/route-links.test.ts
new file mode 100644
index 000000000..fb0f26fc8
--- /dev/null
+++ b/packages/web/src/lib/route-links.test.ts
@@ -0,0 +1,144 @@
+import { describe, expect, it } from "vitest";
+import { readdirSync, readFileSync, statSync } from "node:fs";
+import { join } from "node:path";
+
+/**
+ * Drift guard for links into routes that are only redirects.
+ *
+ * Sections get merged and their old routes stay behind as one-line redirect
+ * stubs, which is right — people have those URLs bookmarked. What is not right
+ * is our own navigation still pointing at them. Nothing errors: the click
+ * works, it just costs an extra hop, and the destination silently stops being
+ * the one the label promised. `/risk` with no tab lands on Code Health's
+ * Overview, so a link labelled "Review threshold" arrived somewhere that never
+ * mentions one.
+ *
+ * A sweep at the time this was written found eleven such links across six
+ * routes, every one of them from a stat or section heading that named
+ * something the destination did not show.
+ */
+
+const WEB_SRC = join(__dirname, "..");
+const UI_SRC = join(__dirname, "../../../ui/src");
+const ROUTES = join(WEB_SRC, "app/repos/[id]");
+
+/**
+ * Deep links we keep pointing at a redirect on purpose. `/wiki/{pageId}` is a
+ * documented permanent entry point, and the repo root is where a repo card is
+ * supposed to land.
+ */
+const DELIBERATE = new Set(["wiki"]);
+
+function walk(dir: string, out: string[] = []): string[] {
+ for (const entry of readdirSync(dir)) {
+ const p = join(dir, entry);
+ if (statSync(p).isDirectory()) walk(p, out);
+ else if (/\.tsx?$/.test(entry)) out.push(p);
+ }
+ return out;
+}
+
+/**
+ * Top-level route segments under `/repos/{id}` whose page only redirects.
+ *
+ * A stub has no JSX to return — that is what separates it from a real page
+ * that happens to redirect on one branch, such as an auth guard.
+ */
+function redirectOnlySegments(): Set<string> {
+ const out = new Set<string>();
+ for (const entry of readdirSync(ROUTES)) {
+ if (entry.startsWith("[")) continue;
+ const dir = join(ROUTES, entry);
+ if (!statSync(dir).isDirectory()) continue;
+ let page: string;
+ try {
+ page = readFileSync(join(dir, "page.tsx"), "utf8");
+ } catch {
+ continue;
+ }
+ if (page.includes("redirect") && !page.includes("return (")) out.add(entry);
+ }
+ return out;
+}
+
+/** Every `${base}/seg` or `/repos/${id}/seg` written on a line carrying an href. */
+function linkedSegments(files: string[]): Map<string, string[]> {
+ const pattern = /(?:\$\{[A-Za-z_][A-Za-z0-9_]*\}|\/repos\/\$\{[^}]+\})\/([a-z][a-z-]*)/g;
+ const found = new Map<string, string[]>();
+ for (const file of files) {
+ const lines = readFileSync(file, "utf8").split("\n");
+ lines.forEach((line, i) => {
+ if (!line.includes("href") && !line.includes("Href")) return;
+ for (const m of line.matchAll(pattern)) {
+ const seg = m[1]!;
+ const at = `${file}:${i + 1}`;
+ const seen = found.get(seg) ?? [];
+ if (!seen.includes(at)) seen.push(at);
+ found.set(seg, seen);
+ }
+ });
+ }
+ return found;
+}
+
+describe("route links", () => {
+ it("points at no route that is only a redirect", () => {
+ const stubs = redirectOnlySegments();
+ const linked = linkedSegments([...walk(WEB_SRC), ...walk(UI_SRC)]);
+
+ const offenders = [...linked.entries()]
+ .filter(([seg]) => stubs.has(seg) && !DELIBERATE.has(seg))
+ .map(([seg, at]) => `/${seg} <- ${at.join(", ")}`)
+ .sort();
+
+ expect(offenders).toEqual([]);
+ });
+
+ it("finds stubs and links at all, so a broken matcher cannot pass vacuously", () => {
+ expect(redirectOnlySegments().size).toBeGreaterThan(5);
+ expect(linkedSegments([...walk(WEB_SRC), ...walk(UI_SRC)]).size).toBeGreaterThan(10);
+ });
+
+ it("points at no Code Health tab that only survives as a legacy alias", () => {
+ const page = readFileSync(join(ROUTES, "code-health/page.tsx"), "utf8");
+
+ const tabs = new Set(
+ [...(page.match(/const TABS = \[([\s\S]*?)\] as const/)?.[1] ?? "").matchAll(/"([^"]+)"/g)].map(
+ (m) => m[1]!,
+ ),
+ );
+ const aliases = new Set(
+ [
+ ...(page.match(/const TAB_ALIASES[^{]*\{([\s\S]*?)\n\}/)?.[1] ?? "").matchAll(
+ /^\s*"?([a-z-]+)"?:/gm,
+ ),
+ ].map((m) => m[1]!),
+ );
+ // The parse has to have found something, or this passes on a rename.
+ expect(tabs.size).toBeGreaterThan(3);
+ expect(aliases.size).toBeGreaterThan(1);
+
+ const offenders: string[] = [];
+ for (const file of [...walk(WEB_SRC), ...walk(UI_SRC)]) {
+ readFileSync(file, "utf8")
+ .split("\n")
+ .forEach((line, i) => {
+ for (const m of line.matchAll(/code-health\?tab=([a-z-]+)/g)) {
+ const tab = m[1]!;
+ // An alias redirects, so the link works — it just lands somewhere
+ // other than the label promises. `?tab=modules` reads "Modules"
+ // and arrives at Overview.
+ if (!tabs.has(tab) && aliases.has(tab)) offenders.push(`?tab=${tab} <- ${file}:${i + 1}`);
+ }
+ });
+ }
+
+ expect(offenders.sort()).toEqual([]);
+ });
+
+ it("still recognises the deep links we keep on purpose", () => {
+ // If `/wiki` stops being a redirect this allowance is dead weight, and the
+ // set should shrink rather than quietly cover a real page.
+ expect(redirectOnlySegments().has("wiki")).toBe(true);
+ });
+});