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.

feat(web): workspace ribbons say how many HTTP calls linked to another service, not how many were read (#4580)

Raghav Chamadiyaa0fecd04b420
diff --git a/packages/ui/__tests__/workspace/system-map.test.tsx b/packages/ui/__tests__/workspace/system-map.test.tsx
index 891c7b6da..57e893076 100644
--- a/packages/ui/__tests__/workspace/system-map.test.tsx
+++ b/packages/ui/__tests__/workspace/system-map.test.tsx
@@ -216,6 +216,20 @@ describe("SystemMapFindings", () => {
expect(screen.getByRole("button", { name: "Break the cycle" })).toBeInTheDocument();
expect(screen.queryByText(/no dependency cycles/i)).not.toBeInTheDocument();
});
+
+ it("never counts in-service calls as unmatched, even on an older artifact", () => {
+ const call = (reason: "no_provider" | "internal_only") => ({
+ repo: "a", file_path: "x.ts", contract_id: "GET /x", contract_type: "http", reason,
+ });
+ // Before in-service calls were split out, they sat in the unmatched list.
+ const diagnostics = {
+ unmatched_consumers: [call("no_provider"), call("internal_only"), call("internal_only")],
+ unmatched_by_reason: { no_provider: 1, internal_only: 2 },
+ } as never;
+ render(<SystemMapFindings {...base} conformance={conformance} breaking={breaking} diagnostics={diagnostics} />);
+ expect(screen.getByText(/1 call to a contract match no provider in the workspace/)).toBeInTheDocument();
+ expect(screen.queryByText(/inside their own service/)).not.toBeInTheDocument();
+ });
});
describe("resolveViewSelection", () => {
diff --git a/packages/ui/src/workspace/contract-facts.ts b/packages/ui/src/workspace/contract-facts.ts
index e8b9b9f67..4c0b4de16 100644
--- a/packages/ui/src/workspace/contract-facts.ts
+++ b/packages/ui/src/workspace/contract-facts.ts
@@ -8,7 +8,12 @@
*/
import { contractTypeLabel } from "./contract-type-label";
-import type { ContractSchema, SchemaField } from "@repowise-dev/types/workspace";
+import type {
+ ContractSchema,
+ ExtractionDiagnostics,
+ SchemaField,
+ UnmatchedConsumer,
+} from "@repowise-dev/types/workspace";
/**
* One detected contract, as both the workspace list and the detail endpoint
@@ -350,6 +355,35 @@ export function sortUnmatchedReasons<T extends { reason: string; count: number }
);
}
+/**
+ * Consumers served by their own service. An artifact written before these were
+ * split out lists them as unmatched with reason `internal_only`; both count.
+ */
+export function inServiceConsumers(
+ diag: Pick<ExtractionDiagnostics, "unmatched_consumers" | "in_service_consumers">,
+): UnmatchedConsumer[] {
+ return [
+ ...(diag.in_service_consumers ?? []),
+ ...diag.unmatched_consumers.filter((u) => u.reason === "internal_only"),
+ ];
+}
+
+/** Consumers that matched no provider, never counting in-service calls. */
+export function unmatchedOutsideService(
+ diag: Pick<ExtractionDiagnostics, "unmatched_consumers">,
+): UnmatchedConsumer[] {
+ return diag.unmatched_consumers.filter((u) => u.reason !== "internal_only");
+}
+
+/** `unmatched_by_reason` without `internal_only`, which an older artifact still counts there. */
+export function unmatchedReasonsOutsideService(
+ byReason: Record<string, number> | null | undefined,
+): Record<string, number> {
+ return Object.fromEntries(
+ Object.entries(byReason ?? {}).filter(([reason, n]) => n > 0 && reason !== "internal_only"),
+ );
+}
+
/** One consumer's unmatched state as a paragraph, with the concrete next step. */
export function unmatchedConsumerProse(reason: string | null, contract: ContractEntry): string {
const host = contractMetaString(contract.meta, "host");
diff --git a/packages/ui/src/workspace/system-map/system-map-findings.tsx b/packages/ui/src/workspace/system-map/system-map-findings.tsx
index 7e94b6813..2ad9896ff 100644
--- a/packages/ui/src/workspace/system-map/system-map-findings.tsx
+++ b/packages/ui/src/workspace/system-map/system-map-findings.tsx
@@ -16,6 +16,7 @@ import type {
SystemGraph,
} from "@repowise-dev/types/workspace";
import { OverviewSection } from "../../overview/section";
+import { unmatchedOutsideService, unmatchedReasonsOutsideService } from "../contract-facts";
import { AiPromptButton } from "../../health/ai-prompt-button";
import { AiPromptModal } from "../../health/ai-prompt-modal";
import { buildConformanceAiPrompt } from "../../health/ai-prompt-builder";
@@ -61,8 +62,9 @@ export function SystemMapFindings({
const totalCycles = conformance ? (conformance.total_cycles ?? conformance.cycle_count) : 0;
const violations = conformance?.violations ?? [];
const breakingCount = breaking?.breaking_count ?? 0;
- const unmatched = diagnostics?.unmatched_consumers.length ?? 0;
- const reasons = unmatchedReasonList(diagnostics?.unmatched_by_reason ?? {});
+ // In-service calls are served, so they are not findings.
+ const unmatched = diagnostics ? unmatchedOutsideService(diagnostics).length : 0;
+ const reasons = unmatchedReasonList(unmatchedReasonsOutsideService(diagnostics?.unmatched_by_reason));
// An all-clear needs both reports loaded and actually run; a missing report
// is not a clean one.
const clean =
diff --git a/packages/web/messages/en.json b/packages/web/messages/en.json
index 21b59d334..d7768b933 100644
--- a/packages/web/messages/en.json
+++ b/packages/web/messages/en.json
@@ -1656,7 +1656,7 @@
"unmatched": "Unmatched consumers",
"orphans": "Providers with no caller",
"orphansSub": "in this workspace; not the same as unused",
- "httpResolved": "HTTP calls resolved",
+ "httpRead": "HTTP calls read",
"httpUnresolved": "{count} located but not resolvable",
"httpSub": "of the client calls extraction located"
},
@@ -1903,9 +1903,16 @@
"contractLinksHint": "Consumer calls matched to the provider that serves them, across services.",
"unmatched": "Unmatched consumers",
"unmatchedSub": "calls with no provider in the workspace",
- "unmatchedHint": "Consumer contracts that matched no provider: missing, a third-party host, or inside the same service."
+ "unmatchedHint": "Consumer contracts that matched no provider: missing, or a third-party host. Calls a repository makes to its own service are served and not counted."
}
},
+ "linkCoverage": {
+ "label": "Linked to another service",
+ "sub": "{linked} of {seen} HTTP calls; {read} read",
+ "hint": "HTTP calls that matched a route another service serves, out of every call seen, counting one per file that calls out through code no dialect reads. Of the calls read, {readNotLinked} matched no other service in the workspace and {inService} are calls a repository makes to its own service, which need no link.",
+ "unmatchedHint": "Consumers that matched no provider in the workspace: missing, or a third-party host.",
+ "inServiceHint": "{count, plural, one {# call a repository makes to its own service is served and not counted here.} other {# calls a repository makes to its own service are served and not counted here.}}"
+ },
"loading": {
"workspace": "Loading workspace",
"settings": "Loading settings",
diff --git a/packages/web/messages/zh-CN.json b/packages/web/messages/zh-CN.json
index b7a8651b3..b549b2f23 100644
--- a/packages/web/messages/zh-CN.json
+++ b/packages/web/messages/zh-CN.json
@@ -1656,7 +1656,7 @@
"unmatched": "未匹配的消费方",
"orphans": "没有调用方的提供方",
"orphansSub": "仅限本工作区;与「未使用」不同",
- "httpResolved": "已解析的 HTTP 调用",
+ "httpRead": "已读取的 HTTP 调用",
"httpUnresolved": "定位到 {count} 个但无法解析",
"httpSub": "占提取定位到的客户端调用"
},
@@ -1903,9 +1903,16 @@
"contractLinksHint": "跨服务匹配到对应提供方的消费方调用。",
"unmatched": "未匹配的消费方",
"unmatchedSub": "工作区内没有提供方的调用",
- "unmatchedHint": "没有匹配到提供方的消费方契约:缺失、属于第三方主机,或位于同一服务内。"
+ "unmatchedHint": "没有匹配到提供方的消费方契约:缺失,或属于第三方主机。仓库对自身服务的调用已有提供方,不计入。"
}
},
+ "linkCoverage": {
+ "label": "关联到其他服务",
+ "sub": "{seen} 个 HTTP 调用中 {linked} 个已关联;已读取 {read} 个",
+ "hint": "匹配到其他服务所提供路由的 HTTP 调用,占所见全部调用的比例;通过任何方言都无法读取的代码对外调用的文件,每个计为一次。在已读取的调用中,{readNotLinked} 个没有匹配到工作区内的其他服务,{inService} 个是仓库对自身服务的调用,无需关联。",
+ "unmatchedHint": "在工作区内没有匹配到提供方的消费方:缺失,或属于第三方主机。",
+ "inServiceHint": "{count, plural, other {仓库对自身服务的 # 个调用已有提供方,不计入此处。}}"
+ },
"loading": {
"workspace": "正在加载工作区",
"settings": "正在加载设置",
diff --git a/packages/web/src/app/workspace/contracts/page.tsx b/packages/web/src/app/workspace/contracts/page.tsx
index 1c005fa60..5236bb8be 100644
--- a/packages/web/src/app/workspace/contracts/page.tsx
+++ b/packages/web/src/app/workspace/contracts/page.tsx
@@ -7,7 +7,11 @@ import { PageShell } from "@repowise-dev/ui/shared";
import { PageLede } from "@repowise-dev/ui/shared/page-lede";
import { OverviewSection } from "@repowise-dev/ui/overview";
import { StatRibbon, type RibbonStat } from "@repowise-dev/ui/stats/stat-ribbon";
-import { groupOrphanProviders } from "@repowise-dev/ui/workspace/contract-facts";
+import {
+ groupOrphanProviders,
+ unmatchedOutsideService,
+ unmatchedReasonsOutsideService,
+} from "@repowise-dev/ui/workspace/contract-facts";
import { MAX_PROMPT_ROWS } from "@repowise-dev/ui/workspace/contract-ai-prompt";
import { formatNumber } from "@repowise-dev/ui/lib/format";
import {
@@ -15,6 +19,7 @@ import {
getWorkspaceContracts,
getWorkspaceDiagnostics,
} from "@/lib/api/workspace";
+import { httpLinkedStat, unmatchedHint } from "@/lib/http-link-coverage";
import { BreakingChangesSection } from "./breaking-changes-section";
import { ContractDrawerProvider } from "./contract-drawer-host";
import { ContractListControls, ContractListPager } from "./contract-filters";
@@ -64,6 +69,7 @@ type Props = {
*/
export default async function ContractsPage({ searchParams }: Props) {
const t = await getTranslations("contracts");
+ const tLinks = await getTranslations("linkCoverage");
const sp = await searchParams;
const deepLink =
sp.contract && sp.repo && sp.file
@@ -130,18 +136,18 @@ export default async function ContractsPage({ searchParams }: Props) {
},
{
label: t("ribbon.unmatched"),
- value: diagnostics ? formatNumber(diagnostics.unmatched_consumers.length) : "",
+ value: diagnostics ? formatNumber(unmatchedOutsideService(diagnostics).length) : "",
sub: unmatchedReasonSub(t, diagnostics),
+ hint: diagnostics ? unmatchedHint(tLinks, diagnostics) : undefined,
},
{
label: t("ribbon.orphans"),
value: diagnostics ? formatNumber(diagnostics.orphan_providers.length) : "",
sub: t("ribbon.orphansSub"),
},
- {
- // Extraction reporting on its own recall: the denominator is calls a
- // dialect located, so it says nothing about calls nothing recognised.
- label: t("ribbon.httpResolved"),
+ // An artifact older than the linked count keeps the read share.
+ (diagnostics && httpLinkedStat(tLinks, diagnostics)) ?? {
+ label: t("ribbon.httpRead"),
value:
diagnostics?.http_consumer_coverage != null
? `${Math.floor(diagnostics.http_consumer_coverage * 100)}%`
@@ -285,8 +291,7 @@ function unmatchedReasonSub(
diagnostics: ExtractionDiagnostics | null,
): string {
if (!diagnostics) return "";
- const reasons = Object.entries(diagnostics.unmatched_by_reason ?? {})
- .filter(([, n]) => n > 0)
+ const reasons = Object.entries(unmatchedReasonsOutsideService(diagnostics.unmatched_by_reason))
.sort((a, b) => b[1] - a[1]);
if (reasons.length === 0) return t("reasons.everyMatched");
return reasons
diff --git a/packages/web/src/app/workspace/system-map/page.tsx b/packages/web/src/app/workspace/system-map/page.tsx
index 25274da23..9d48448b9 100644
--- a/packages/web/src/app/workspace/system-map/page.tsx
+++ b/packages/web/src/app/workspace/system-map/page.tsx
@@ -28,6 +28,7 @@ import { StatRibbon, type RibbonStat } from "@repowise-dev/ui/stats/stat-ribbon"
import { OverviewSection } from "@repowise-dev/ui/overview/section";
import { Skeleton } from "@repowise-dev/ui/ui/skeleton";
import { formatNumber } from "@repowise-dev/ui/lib/format";
+import { unmatchedOutsideService } from "@repowise-dev/ui/workspace/contract-facts";
import type { NodeArchitectureRole, SystemGraph, ConformanceReport } from "@/lib/api/types";
import {
useWorkspaceSystemGraph,
@@ -37,6 +38,7 @@ import {
useWorkspaceConformance,
useWorkspaceArchitecture,
} from "@/lib/hooks/use-workspace";
+import { httpLinkedStat } from "@/lib/http-link-coverage";
import { useRepoContracts } from "./use-repo-contracts";
const LENSES: readonly SystemMapLens[] = ["none", "blast", "breaking", "conformance", "core"];
@@ -56,6 +58,7 @@ function contractsHref(repo: string): string {
export default function SystemMapPage() {
const t = useTranslations("systemMap");
+ const tLinks = useTranslations("linkCoverage");
const router = useRouter();
const searchParams = useSearchParams();
@@ -203,7 +206,7 @@ export default function SystemMapPage() {
{graph && (
<Lede graph={graph} architecture={architecture} conformance={conformance} t={t} />
)}
- {graph && <StatRibbon stats={ribbon(t, graph, architecture)} LinkComponent={Link} />}
+ {graph && <StatRibbon stats={ribbon(t, tLinks, graph, architecture)} LinkComponent={Link} />}
<OverviewSection title={t("section.title")} description={t("section.description")}>
{isLoading ? (
@@ -422,6 +425,7 @@ function Lede({
function ribbon(
t: Translator,
+ tLinks: Translator,
graph: SystemGraph,
architecture: ReturnType<typeof useWorkspaceArchitecture>["data"],
): RibbonStat[] {
@@ -462,9 +466,10 @@ function ribbon(
: undefined,
hint: t("ribbon.contractLinksHint"),
},
- {
+ // An artifact older than the linked count keeps the unmatched stat.
+ (diag && httpLinkedStat(tLinks, diag)) ?? {
label: t("ribbon.unmatched"),
- value: diag ? formatNumber(diag.unmatched_consumers.length) : "–",
+ value: diag ? formatNumber(unmatchedOutsideService(diag).length) : "–",
sub: t("ribbon.unmatchedSub"),
hint: t("ribbon.unmatchedHint"),
},
diff --git a/packages/web/src/lib/http-link-coverage.test.ts b/packages/web/src/lib/http-link-coverage.test.ts
new file mode 100644
index 000000000..8d60c7077
--- /dev/null
+++ b/packages/web/src/lib/http-link-coverage.test.ts
@@ -0,0 +1,140 @@
+import { describe, expect, it } from "vitest";
+import type { ExtractionDiagnostics, UnmatchedConsumer } from "@repowise-dev/types/workspace";
+import {
+ inServiceConsumers,
+ unmatchedOutsideService,
+ unmatchedReasonsOutsideService,
+} from "@repowise-dev/ui/workspace/contract-facts";
+import { httpLinkCoverage, httpLinkedStat, percentOf, unmatchedHint } from "./http-link-coverage";
+
+function consumer(reason: UnmatchedConsumer["reason"], type = "http"): UnmatchedConsumer {
+ return { repo: "web", file_path: "a.ts", contract_id: "GET /x", contract_type: type, reason };
+}
+
+function diag(overrides: Partial<ExtractionDiagnostics> = {}): ExtractionDiagnostics {
+ return {
+ total_providers: 0,
+ total_consumers: 0,
+ total_links: 0,
+ weak_link_count: 0,
+ repo_breakdown: [
+ {
+ repo: "web",
+ providers_by_type: {},
+ consumers_by_type: { http: 300, grpc: 5 },
+ provider_count: 0,
+ consumer_count: 305,
+ providers_by_layer: {},
+ consumers_by_layer: {},
+ http_consumers_unresolved: 0,
+ },
+ {
+ repo: "api",
+ providers_by_type: {},
+ consumers_by_type: { http: 8 },
+ provider_count: 0,
+ consumer_count: 8,
+ providers_by_layer: {},
+ consumers_by_layer: {},
+ http_consumers_unresolved: 0,
+ },
+ ],
+ unmatched_consumers: [consumer("no_provider"), consumer("external_host")],
+ unmatched_by_reason: { no_provider: 1, external_host: 1 },
+ orphan_providers: [],
+ in_service_consumers: [consumer("internal_only"), consumer("internal_only", "grpc")],
+ providers_by_layer: {},
+ consumers_by_layer: {},
+ http_consumers_unresolved: 50,
+ http_consumer_coverage: 308 / 392,
+ http_consumers_linked: 235,
+ http_link_coverage: 235 / 392,
+ unrecognised_call_files: { web: 34 },
+ unrecognised_call_file_count: 34,
+ ...overrides,
+ };
+}
+
+const t = (key: string, values?: Record<string, string | number>) =>
+ values ? `${key} ${JSON.stringify(values)}` : key;
+
+describe("httpLinkCoverage", () => {
+ it("splits calls the way the CLI headline does", () => {
+ expect(httpLinkCoverage(diag())).toEqual({
+ seen: 392,
+ read: 308,
+ linked: 235,
+ inService: 1,
+ readNotLinked: 72,
+ });
+ });
+
+ it("is null on an artifact older than the linked count", () => {
+ expect(httpLinkCoverage(diag({ http_consumers_linked: undefined }))).toBeNull();
+ expect(httpLinkCoverage(diag({ http_consumers_linked: null }))).toBeNull();
+ });
+
+ it("is null on an artifact older than the network probe", () => {
+ expect(httpLinkCoverage(diag({ unrecognised_call_file_count: null }))).toBeNull();
+ });
+
+ it("is null when no call was seen, since 0 of 0 is not 100%", () => {
+ const empty = diag({
+ repo_breakdown: [],
+ http_consumers_unresolved: 0,
+ unrecognised_call_file_count: 0,
+ http_consumers_linked: 0,
+ });
+ expect(httpLinkCoverage(empty)).toBeNull();
+ });
+});
+
+describe("in-service calls on an older artifact", () => {
+ // Before the split, in-service consumers sat in the unmatched list.
+ const old = diag({
+ in_service_consumers: undefined,
+ unmatched_consumers: [consumer("no_provider"), consumer("internal_only")],
+ });
+
+ it("are counted as in-service", () => {
+ expect(inServiceConsumers(old)).toHaveLength(1);
+ });
+
+ it("are never counted as unmatched", () => {
+ expect(unmatchedOutsideService(old).map((u) => u.reason)).toEqual(["no_provider"]);
+ });
+
+ it("are dropped from the reason counts", () => {
+ expect(unmatchedReasonsOutsideService({ no_provider: 2, internal_only: 5, unlinked: 0 })).toEqual({
+ no_provider: 2,
+ });
+ });
+});
+
+describe("httpLinkedStat", () => {
+ it("reads linked over seen as a floored percent", () => {
+ const stat = httpLinkedStat(t, diag());
+ expect(stat?.value).toBe("59%");
+ expect(stat?.sub).toBe('sub {"linked":"235","seen":"392","read":"308"}');
+ });
+
+ it("is null when the counts are missing, so the page keeps its old stat", () => {
+ expect(httpLinkedStat(t, diag({ http_consumers_linked: undefined }))).toBeNull();
+ });
+});
+
+describe("percentOf", () => {
+ it("never rounds a near miss up to 100%", () => {
+ expect(percentOf(996, 1000)).toBe("99%");
+ });
+});
+
+describe("unmatchedHint", () => {
+ it("names the in-service calls when there are some", () => {
+ expect(unmatchedHint(t, diag())).toBe('unmatchedHint inServiceHint {"count":2}');
+ });
+
+ it("ends cleanly when there are none", () => {
+ expect(unmatchedHint(t, diag({ in_service_consumers: [] }))).toBe("unmatchedHint");
+ });
+});
diff --git a/packages/web/src/lib/http-link-coverage.ts b/packages/web/src/lib/http-link-coverage.ts
new file mode 100644
index 000000000..db80682ee
--- /dev/null
+++ b/packages/web/src/lib/http-link-coverage.ts
@@ -0,0 +1,80 @@
+import type { ExtractionDiagnostics } from "@repowise-dev/types/workspace";
+import type { RibbonStat } from "@repowise-dev/ui/stats/stat-ribbon";
+import { formatNumber } from "@repowise-dev/ui/lib/format";
+import { inServiceConsumers } from "@repowise-dev/ui/workspace/contract-facts";
+
+/** The `linkCoverage` message namespace; next-intl's `t` fits. */
+type Translator = (key: string, values?: Record<string, string | number>) => string;
+
+/**
+ * Where the workspace's HTTP client calls ended up, split the way the CLI
+ * headline reads: linked to another service, served inside their own service,
+ * and read but not linked to anything.
+ */
+export interface HttpLinkCoverage {
+ /** Calls read, plus located-but-unresolved, plus one per file no dialect reads. */
+ seen: number;
+ /** HTTP consumer contracts read, linked or not. */
+ read: number;
+ linked: number;
+ /** Calls a repo makes to its own service: served, so never a missing provider. */
+ inService: number;
+ /** Read calls that reached no other service and are not in-service. */
+ readNotLinked: number;
+}
+
+/**
+ * The linked / in-service / read split, or null when the artifact predates the
+ * linked count or the network probe, or saw no calls (0 of 0 is not 100%).
+ * Mirrors `ExtractionDiagnostics.http_calls_seen` in core.
+ */
+export function httpLinkCoverage(diag: ExtractionDiagnostics): HttpLinkCoverage | null {
+ const linked = diag.http_consumers_linked;
+ const missed = diag.unrecognised_call_file_count;
+ if (linked == null || missed == null) return null;
+ const read = diag.repo_breakdown.reduce((n, r) => n + (r.consumers_by_type.http ?? 0), 0);
+ const seen = read + (diag.http_consumers_unresolved ?? 0) + missed;
+ if (seen <= 0) return null;
+ const inService = inServiceConsumers(diag).filter((u) => u.contract_type === "http").length;
+ return {
+ seen,
+ read,
+ linked,
+ inService,
+ readNotLinked: Math.max(0, read - linked - inService),
+ };
+}
+
+/** Whole percent, floored like the CLI so 99.6% never reads as 100%. */
+export function percentOf(part: number, whole: number): string {
+ return `${Math.floor((part * 100) / whole)}%`;
+}
+
+/**
+ * The ribbon stat for the CLI headline "N of M linked to another service; K
+ * read". Null on an artifact without the counts, so the page keeps its old stat.
+ */
+export function httpLinkedStat(t: Translator, diag: ExtractionDiagnostics): RibbonStat | null {
+ const c = httpLinkCoverage(diag);
+ if (!c) return null;
+ return {
+ label: t("label"),
+ value: percentOf(c.linked, c.seen),
+ sub: t("sub", {
+ linked: formatNumber(c.linked),
+ seen: formatNumber(c.seen),
+ read: formatNumber(c.read),
+ }),
+ hint: t("hint", {
+ readNotLinked: formatNumber(c.readNotLinked),
+ inService: formatNumber(c.inService),
+ }),
+ };
+}
+
+/** What the unmatched count leaves out: the in-service calls, named only when there are some. */
+export function unmatchedHint(t: Translator, diag: ExtractionDiagnostics): string {
+ const inService = inServiceConsumers(diag).length;
+ const base = t("unmatchedHint");
+ return inService > 0 ? `${base} ${t("inServiceHint", { count: inService })}` : base;
+}