diff --git a/packages/api-client/src/client.ts b/packages/api-client/src/client.ts index 51597e79b4..a1f18267fd 100644 --- a/packages/api-client/src/client.ts +++ b/packages/api-client/src/client.ts @@ -275,4 +275,40 @@ export async function apiDelete( return handleResponse(res); } +/** A write's method and body, for the APIs built on `ApiRequest`. */ +export interface ApiRequestInit { + method: "POST" | "PUT"; + /** JSON text, so a host's own fetch wrapper can send it unchanged. */ + body?: string; +} + +/** + * The one request primitive the `create*Api` factories need: a path relative + * to the host's API base, its query already on it. A host with its own fetch + * layer (auth, timeouts, errors) passes its wrapper; this package passes + * `apiRequest`. + */ +export type ApiRequest = (path: string, init?: ApiRequestInit) => Promise; + +/** `ApiRequest` over this client's base URL, token and fetch. */ +export function apiRequest(path: string, init?: ApiRequestInit): Promise { + if (!init) return apiGet(path); + return init.method === "PUT" + ? apiPut(path, undefined, init) + : apiPost(path, undefined, init); +} + +/** *path* with the defined *params* as its query, encoded as `apiGet` encodes them. */ +export function withQuery( + path: string, + params: Record, +): string { + const query = new URLSearchParams(); + for (const [k, v] of Object.entries(params)) { + if (v !== undefined && v !== null) query.set(k, String(v)); + } + const text = query.toString(); + return text ? `${path}?${text}` : path; +} + export { buildHeaders }; diff --git a/packages/api-client/src/reports.test.ts b/packages/api-client/src/reports.test.ts new file mode 100644 index 0000000000..73c13172c6 --- /dev/null +++ b/packages/api-client/src/reports.test.ts @@ -0,0 +1,77 @@ +import { afterEach, describe, expect, it } from "vitest"; + +import { configureApiClient, createAdapterFetch, type ApiRequestInit } from "./client"; +import { + createFirstLookApi, + firstLookMarkdownPath, + getFirstLook, + getFirstLookPrompt, + markFirstLookItem, + rewriteFirstLook, +} from "./reports"; + +function serve() { + const sent: { url: string; method?: string | undefined; body?: string }[] = []; + configureApiClient({ + baseUrl: "http://127.0.0.1:7337", + fetch: createAdapterFetch(async (url, init) => { + sent.push({ + url: url.replace("http://127.0.0.1:7337", ""), + method: init.method, + ...(init.body !== undefined ? { body: init.body } : {}), + }); + return { status: 200, ok: true, headers: {}, text: "{}" }; + }), + }); + return sent; +} + +const ROOT = "/api/repos/r1/reports/first-look"; + +describe("repo report requests", () => { + afterEach(() => configureApiClient({ baseUrl: "" })); + + it("reads the report and its prompts with the flavor and target", async () => { + const sent = serve(); + await getFirstLook("r1", { flavor: "cursor" }); + await getFirstLookPrompt("r1", { section: "security" }, "generic"); + await getFirstLookPrompt("r1", null, "generic"); + expect(sent).toEqual([ + { url: `${ROOT}?flavor=cursor`, method: "GET" }, + { url: `${ROOT}/prompt?flavor=generic§ion=security`, method: "GET" }, + { url: `${ROOT}/prompt?flavor=generic`, method: "GET" }, + ]); + }); + + it("writes a mark and a rewrite", async () => { + const sent = serve(); + await markFirstLookItem("r1", "sec/1", { status: "done" }); + await rewriteFirstLook("r1", { flavor: "generic" }); + expect(sent).toEqual([ + { url: `${ROOT}/items/sec%2F1/mark`, method: "PUT", body: '{"status":"done"}' }, + { url: `${ROOT}/rewrite?flavor=generic`, method: "POST" }, + ]); + expect(firstLookMarkdownPath("r1")).toBe(`${ROOT}/export.md`); + }); + + it("builds a host's client over its own request and routes", async () => { + const calls: [string, ApiRequestInit | undefined][] = []; + const api = createFirstLookApi( + async (path: string, init?: ApiRequestInit) => { + calls.push([path, init]); + return {} as T; + }, + (id) => `/snapshots/${id}/report`, + ); + await api.getFirstLook("s1"); + await api.markFirstLookItem("s1", "a", { status: "ack", reason: "known" }); + expect(calls).toEqual([ + ["/snapshots/s1/report", undefined], + [ + "/snapshots/s1/report/items/a/mark", + { method: "PUT", body: '{"status":"ack","reason":"known"}' }, + ], + ]); + expect(api.firstLookMarkdownPath("s1")).toBe("/snapshots/s1/report/export.md"); + }); +}); diff --git a/packages/api-client/src/reports.ts b/packages/api-client/src/reports.ts index f4156c6621..6943cd2b6e 100644 --- a/packages/api-client/src/reports.ts +++ b/packages/api-client/src/reports.ts @@ -4,50 +4,50 @@ import type { FirstLookMarkResponse, FirstLookPage, } from "@repowise-dev/types/first-look"; -import { apiGet, apiPost, apiPut } from "./client"; +import { apiRequest, withQuery, type ApiRequest } from "./client"; -const firstLook = (repoId: string) => `/api/repos/${repoId}/reports/first-look`; +/** + * The repo report requests over *request*, under *base*: the report root for + * a repository (`/api/repos/{id}/reports/first-look` here). A host with its + * own fetch layer and routes builds its client from this, so paths, query + * names and types stay in one place. + */ +export function createFirstLookApi(request: ApiRequest, base: (repoId: string) => string) { + return { + /** The repo report now, each item's status against the first look, and the open items' prompt for `flavor`. */ + getFirstLook: (repoId: string, opts: { flavor?: AgentPromptFlavor } = {}) => + request(withQuery(base(repoId), { flavor: opts.flavor })), -/** The repo report now, each item's status against the first look, and the open items' prompt for `flavor`. */ -export async function getFirstLook( - repoId: string, - opts: { flavor?: AgentPromptFlavor } = {}, -): Promise { - return apiGet(firstLook(repoId), { flavor: opts.flavor }); -} + /** One item's prompt, one section's, or the whole report's (null), rendered by core for `flavor`. */ + getFirstLookPrompt: ( + repoId: string, + target: { item: string } | { section: string } | null, + flavor: AgentPromptFlavor, + ) => + request(withQuery(`${base(repoId)}/prompt`, { flavor, ...(target ?? {}) })), -/** One item's prompt, one section's, or the whole report's (null), rendered by core for `flavor`. */ -export async function getFirstLookPrompt( - repoId: string, - target: { item: string } | { section: string } | null, - flavor: AgentPromptFlavor, -): Promise { - return apiGet(`${firstLook(repoId)}/prompt`, { flavor, ...(target ?? {}) }); -} + /** Done, acknowledged, a false positive or snoozed: what `repowise mark` records. */ + markFirstLookItem: (repoId: string, itemId: string, body: FirstLookMarkRequest) => + request(`${base(repoId)}/items/${encodeURIComponent(itemId)}/mark`, { + method: "PUT", + body: JSON.stringify(body), + }), -/** Done, acknowledged, a false positive or snoozed: what `repowise mark` records. */ -export async function markFirstLookItem( - repoId: string, - itemId: string, - body: FirstLookMarkRequest, -): Promise { - return apiPut( - `${firstLook(repoId)}/items/${encodeURIComponent(itemId)}/mark`, - body, - ); -} + /** The report as a Markdown download, relative to the API base. */ + firstLookMarkdownPath: (repoId: string) => `${base(repoId)}/export.md`, -/** The report as a Markdown download, relative to the API base. */ -export function firstLookMarkdownPath(repoId: string): string { - return `${firstLook(repoId)}/export.md`; + /** Write the report again with the repository's model: one call. */ + rewriteFirstLook: (repoId: string, opts: { flavor?: AgentPromptFlavor } = {}) => + request(withQuery(`${base(repoId)}/rewrite`, { flavor: opts.flavor }), { + method: "POST", + }), + }; } -/** Write the report again with the repository's model: one call. */ -export async function rewriteFirstLook( - repoId: string, - opts: { flavor?: AgentPromptFlavor } = {}, -): Promise { - return apiPost(`${firstLook(repoId)}/rewrite`, undefined, undefined, { - flavor: opts.flavor, - }); -} +export const { + getFirstLook, + getFirstLookPrompt, + markFirstLookItem, + firstLookMarkdownPath, + rewriteFirstLook, +} = createFirstLookApi(apiRequest, (repoId) => `/api/repos/${repoId}/reports/first-look`); diff --git a/packages/api-client/src/runtime-evidence.test.ts b/packages/api-client/src/runtime-evidence.test.ts index 7c1dbca8c4..d16c7170c2 100644 --- a/packages/api-client/src/runtime-evidence.test.ts +++ b/packages/api-client/src/runtime-evidence.test.ts @@ -1,41 +1,65 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it } from "vitest"; -const apiGet = vi.fn(); -vi.mock("./client", () => ({ - apiGet: (...args: unknown[]) => apiGet(...args), -})); +import { configureApiClient, createAdapterFetch, type ApiRequest } from "./client"; +import { + createRuntimeEvidenceApi, + getEvidenceTests, + getMeasured, + getMeasuredFunctions, +} from "./runtime-evidence"; -import { getEvidenceTests, getMeasured, getMeasuredFunctions } from "./runtime-evidence"; +function serve() { + const sent: string[] = []; + configureApiClient({ + baseUrl: "http://127.0.0.1:7337", + fetch: createAdapterFetch(async (url) => { + sent.push(url.replace("http://127.0.0.1:7337", "")); + return { status: 200, ok: true, headers: {}, text: "{}" }; + }), + }); + return sent; +} describe("runtime evidence requests", () => { - beforeEach(() => { - apiGet.mockReset(); - apiGet.mockResolvedValue({}); - }); + afterEach(() => configureApiClient({ baseUrl: "" })); it("sends the run and limit under the server's names", async () => { + const sent = serve(); await getMeasured("repo", { runId: "r1", limit: 0 }); - expect(apiGet).toHaveBeenCalledWith("/api/repos/repo/evidence/measured", { - run_id: "r1", - limit: 0, - }); + expect(sent).toEqual(["/api/repos/repo/evidence/measured?run_id=r1&limit=0"]); }); it("asks for one function or one file", async () => { + const sent = serve(); await getMeasuredFunctions("repo", { symbolId: "src/a.py::f" }); - expect(apiGet).toHaveBeenLastCalledWith("/api/repos/repo/evidence/functions", { - symbol_id: "src/a.py::f", - file: undefined, - }); await getMeasuredFunctions("repo", { file: "src/a.py" }); - expect(apiGet).toHaveBeenLastCalledWith("/api/repos/repo/evidence/functions", { - symbol_id: undefined, - file: "src/a.py", - }); + expect(sent).toEqual([ + "/api/repos/repo/evidence/functions?symbol_id=src%2Fa.py%3A%3Af", + "/api/repos/repo/evidence/functions?file=src%2Fa.py", + ]); }); it("asks for the slowest tests with a limit", async () => { + const sent = serve(); await getEvidenceTests("repo", { limit: 10 }); - expect(apiGet).toHaveBeenCalledWith("/api/repos/repo/evidence/tests", { limit: 10 }); + await getEvidenceTests("repo"); + expect(sent).toEqual(["/api/repos/repo/evidence/tests?limit=10", "/api/repos/repo/evidence/tests"]); + }); + + it("builds a host's client over its own request and routes", async () => { + const paths: string[] = []; + const request: ApiRequest = async (path: string) => { + paths.push(path); + return {} as T; + }; + const api = createRuntimeEvidenceApi(request, (id) => `/snapshots/${id}/evidence`); + await api.getEvidenceStatus("s1"); + await api.listEvidenceRuns("s1"); + await api.getMeasured("s1", { limit: 5 }); + expect(paths).toEqual([ + "/snapshots/s1/evidence/status", + "/snapshots/s1/evidence/runs", + "/snapshots/s1/evidence/measured?limit=5", + ]); }); }); diff --git a/packages/api-client/src/runtime-evidence.ts b/packages/api-client/src/runtime-evidence.ts index c02a6ae459..df108cf8b3 100644 --- a/packages/api-client/src/runtime-evidence.ts +++ b/packages/api-client/src/runtime-evidence.ts @@ -9,7 +9,7 @@ import type { MeasuredResponse, SuiteCostResponse, } from "@repowise-dev/types/runtime-evidence"; -import { apiGet } from "./client"; +import { apiRequest, withQuery, type ApiRequest } from "./client"; export type { EvidenceRunSummary, @@ -28,46 +28,53 @@ export type { SuiteCostResponse, } from "@repowise-dev/types/runtime-evidence"; -/** The newest run of every workload, and whether anything is ranked. */ -export async function getEvidenceStatus(repoId: string): Promise { - return apiGet(`/api/repos/${repoId}/evidence/status`); -} +/** + * The runtime-evidence requests over *request*, under *base*: the evidence + * root for a repository (`/api/repos/{id}/evidence` here). A host with its own + * fetch layer and routes builds its client from this, so paths, query names + * and types stay in one place. + */ +export function createRuntimeEvidenceApi(request: ApiRequest, base: (repoId: string) => string) { + return { + /** The newest run of every workload, and whether anything is ranked. */ + getEvidenceStatus: (repoId: string) => + request(`${base(repoId)}/status`), -/** Every stored run, newest first. */ -export async function listEvidenceRuns(repoId: string): Promise { - return apiGet(`/api/repos/${repoId}/evidence/runs`); -} + /** Every stored run, newest first. */ + listEvidenceRuns: (repoId: string) => request(`${base(repoId)}/runs`), -/** Each workload's newest run with its ranked functions; `runId` keeps one run. */ -export async function getMeasured( - repoId: string, - opts: { - runId?: string; - /** Rows per run, 0-100; the server defaults to 10. */ - limit?: number; - } = {}, -): Promise { - return apiGet(`/api/repos/${repoId}/evidence/measured`, { - run_id: opts.runId, - limit: opts.limit, - }); -} + /** Each workload's newest run with its ranked functions; `runId` keeps one run. */ + getMeasured: ( + repoId: string, + opts: { + runId?: string; + /** Rows per run, 0-100; the server defaults to 10. */ + limit?: number; + } = {}, + ) => + request( + withQuery(`${base(repoId)}/measured`, { run_id: opts.runId, limit: opts.limit }), + ), -/** The measured view of one function or of every function in a file. */ -export async function getMeasuredFunctions( - repoId: string, - target: { symbolId: string; file?: never } | { file: string; symbolId?: never }, -): Promise { - return apiGet(`/api/repos/${repoId}/evidence/functions`, { - symbol_id: target.symbolId, - file: target.file, - }); -} + /** The measured view of one function or of every function in a file. */ + getMeasuredFunctions: ( + repoId: string, + target: { symbolId: string; file?: never } | { file: string; symbolId?: never }, + ) => + request( + withQuery(`${base(repoId)}/functions`, { symbol_id: target.symbolId, file: target.file }), + ), -/** The slowest timed tests and the test time per production file, from stored JUnit timings. */ -export async function getEvidenceTests( - repoId: string, - opts: { limit?: number } = {}, -): Promise { - return apiGet(`/api/repos/${repoId}/evidence/tests`, { limit: opts.limit }); + /** The slowest timed tests and the test time per production file, from stored JUnit timings. */ + getEvidenceTests: (repoId: string, opts: { limit?: number } = {}) => + request(withQuery(`${base(repoId)}/tests`, { limit: opts.limit })), + }; } + +export const { + getEvidenceStatus, + listEvidenceRuns, + getMeasured, + getMeasuredFunctions, + getEvidenceTests, +} = createRuntimeEvidenceApi(apiRequest, (repoId) => `/api/repos/${repoId}/evidence`); diff --git a/packages/types/src/health.ts b/packages/types/src/health.ts index 0c7634eac5..882544688c 100644 --- a/packages/types/src/health.ts +++ b/packages/types/src/health.ts @@ -414,7 +414,8 @@ export interface PerformanceOpportunityFix { } export interface PerformanceOpportunityEvidence { - finding_id: string; + /** Null for a measured hotspot, which comes from runtime evidence, not a static finding. */ + finding_id: string | null; file_path: string; biomarker_type: string; function_name: string | null; diff --git a/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx b/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx index e9a904f5de..6d83ab3d48 100644 --- a/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx +++ b/packages/ui/__tests__/decisions/decision-agent-prompts.test.tsx @@ -140,6 +140,23 @@ describe("DecisionAgentHero", () => { expect(screen.getByRole("button", { name: "Copy prompt for your agent" })).toBeInTheDocument(); }); + it("tells the host which prompt was copied", async () => { + Object.assign(navigator, { clipboard: { writeText: vi.fn(async () => undefined) } }); + const onCopy = vi.fn(); + render( + , + ); + + fireEvent.click(screen.getByRole("button", { name: "Copy prompt for your agent" })); + await waitFor(() => expect(onCopy.mock.calls).toEqual([["prompt"]])); + fireEvent.click(screen.getByRole("button", { name: "Review all records" })); + await waitFor(() => expect(onCopy.mock.calls).toEqual([["prompt"], ["review_all"]])); + }); + it("hides the whole-queue button when the host has no text for it", () => { const none = render(); expect(screen.queryByRole("button", { name: "Review all records" })).toBeNull(); diff --git a/packages/ui/__tests__/health/performance-view.test.tsx b/packages/ui/__tests__/health/performance-view.test.tsx index 6d97daa980..d3e8951950 100644 --- a/packages/ui/__tests__/health/performance-view.test.tsx +++ b/packages/ui/__tests__/health/performance-view.test.tsx @@ -832,6 +832,45 @@ describe("PerformanceView measured hotspot drawer", () => { }); }); +describe("PerformanceView measured hotspot with no static finding", () => { + it("renders an evidence row whose finding_id is null", async () => { + const measurement = 'Measured: rank 2 of repo code in entry_point "cli serve" (8% self), 1d old'; + const hotspot = opportunity({ + opportunity_id: "perf2_hotspot_null", + biomarker_type: "measured_hotspot", + boundary_kind: null, + intervention_symbol: "src/b.py::serve", + observations_total: 0, + evidence: [ + { + finding_id: null, + file_path: "src/b.py", + biomarker_type: "measured_hotspot", + function_name: "serve", + line_start: null, + line_end: null, + reason: measurement, + path: [], + provenance: "measured", + }, + ], + }); + const one = page({ items: [hotspot], total: 1, next_offset: null }); + render( + one, + getPerformanceOpportunity: undefined, + getMeasuredFunctions: undefined, + })} + />, + ); + await openFirstRow(); + expect(await screen.findByText("Runs that measured it")).toBeTruthy(); + expect(screen.getByText(measurement)).toBeTruthy(); + }); +}); + describe("PerformanceView drawer siblings", () => { it("names a preferred sibling's fix as the stronger one", async () => { const withSiblings = page({ diff --git a/packages/ui/__tests__/report/first-look-report.test.tsx b/packages/ui/__tests__/report/first-look-report.test.tsx index 3ae0078de2..06adc33fd9 100644 --- a/packages/ui/__tests__/report/first-look-report.test.tsx +++ b/packages/ui/__tests__/report/first-look-report.test.tsx @@ -137,6 +137,32 @@ function renderReport(props: Partial[0]> = {} afterEach(() => vi.restoreAllMocks()); +describe("FirstLookReport, sections it could not collect", () => { + const unavailable = { ownership: "No checkout to read history from.", coverage: "No coverage report stored." }; + + it("names each one with its reason and links the ones the shell has a page for", () => { + renderReport({ report: report({ unavailable }) }); + const block = screen.getByRole("heading", { name: "Not in this report" }).closest("section")!; + expect(within(block).getByText("No checkout to read history from.")).toBeInTheDocument(); + expect(within(block).getByText("No coverage report stored.")).toBeInTheDocument(); + expect(within(block).getAllByRole("link").map((a) => a.getAttribute("href"))).toEqual(["/r/ownership"]); + }); + + it("takes the host's page for a section", () => { + renderReport({ + report: report({ unavailable }), + unavailableHref: (section) => (section === "coverage" ? "/host/coverage" : null), + }); + const block = screen.getByRole("heading", { name: "Not in this report" }).closest("section")!; + expect(within(block).getAllByRole("link").map((a) => a.getAttribute("href"))).toEqual(["/host/coverage"]); + }); + + it("adds nothing when every section was read", () => { + renderReport(); + expect(screen.queryByRole("heading", { name: "Not in this report" })).toBeNull(); + }); +}); + describe("FirstLookReport", () => { it("reads as one document: strip, Start here, then sections in report order", () => { const { container } = renderReport(); diff --git a/packages/ui/__tests__/savings/savings-page.test.tsx b/packages/ui/__tests__/savings/savings-page.test.tsx index b320d039e9..637ea1f3d6 100644 --- a/packages/ui/__tests__/savings/savings-page.test.tsx +++ b/packages/ui/__tests__/savings/savings-page.test.tsx @@ -240,6 +240,40 @@ describe("SavingsPageBody, partial states", () => { }); }); +describe("RepowiseUsage, host body", () => { + it("shows the host's own spend in place of the token figures and grouping", () => { + renderBody({ + savings: undefined, + usage: { + summary: spend, + rows: undefined, + grouping: "operation", + onGroupingChange: () => {}, + children:

Ledger: 12 credits

, + }, + }); + expect(screen.getByText(copy.usageTitle)).toBeTruthy(); + expect(screen.getByText("Ledger: 12 credits")).toBeTruthy(); + expect(screen.queryByText(copy.inputTokens)).toBeNull(); + expect(screen.queryByRole("radiogroup", { name: copy.usageGroupLabel })).toBeNull(); + }); + + it("keeps the token figures when a conditional body renders false", () => { + const hasLedger = false; + renderBody({ + usage: { + summary: spend, + rows, + grouping: "operation", + onGroupingChange: () => {}, + children: hasLedger &&

Ledger

, + }, + }); + expect(screen.getAllByText(copy.inputTokens).length).toBeGreaterThan(0); + expect(screen.getByRole("radiogroup", { name: copy.usageGroupLabel })).toBeTruthy(); + }); +}); + describe("SavingsPageBody, empty states", () => { it("fresh: nothing recorded and no spend", () => { renderBody({ diff --git a/packages/ui/src/decisions/decision-agent-prompts.tsx b/packages/ui/src/decisions/decision-agent-prompts.tsx index fb63b864a6..62c60c792e 100644 --- a/packages/ui/src/decisions/decision-agent-prompts.tsx +++ b/packages/ui/src/decisions/decision-agent-prompts.tsx @@ -104,6 +104,12 @@ export interface DecisionAgentHeroProps { readOnlyNote?: string; /** Lines of the prompt shown in the preview well. */ previewLines?: number; + /** + * Called when the person clicks a copy button: `prompt` for the main one, + * `review_all` for the secondary. Lets a host count the handoff without + * reading the button's label. + */ + onCopy?: (which: "prompt" | "review_all") => void; className?: string; } @@ -143,6 +149,7 @@ export function DecisionAgentHero({ reviewAll, readOnlyNote, previewLines = 6, + onCopy, className, }: DecisionAgentHeroProps) { const headingId = React.useId(); @@ -173,6 +180,8 @@ export function DecisionAgentHero({ setResult(ok ? "copied" : "failed"); if (timer.current) clearTimeout(timer.current); timer.current = setTimeout(() => setResult(null), 2400); + // After the copy and its feedback, so a host callback that throws cannot stop either. + onCopy?.("prompt"); }; return ( @@ -213,7 +222,13 @@ export function DecisionAgentHero({ {result === "copied" ? : } {copyLabel} - + {reviewAll?.text ? ( + reviewAll.text} + label={reviewAll.label} + onClick={() => onCopy?.("review_all")} + /> + ) : null} {handoff} {result === "copied" ? copiedLabel : result === "failed" ? failedLabel : ""} diff --git a/packages/ui/src/report/first-look/copy.ts b/packages/ui/src/report/first-look/copy.ts index 3f7060c3e1..69e74df5b8 100644 --- a/packages/ui/src/report/first-look/copy.ts +++ b/packages/ui/src/report/first-look/copy.ts @@ -50,6 +50,10 @@ export interface FirstLookCopy { countOf: (n: string, total: string) => string; /** "{n} more in the app". */ moreInApp: (n: string) => string; + /** Heading over the sections the report could not collect. */ + notInReport: string; + /** "Open Security", the link to an uncollected section's page. */ + openSection: (title: string) => string; linesCovered: string; branchesCovered: string; /** Compact table headings. */ @@ -152,6 +156,8 @@ export const FIRST_LOOK_COPY_EN: FirstLookCopy = { copyItemPrompt: "Copy prompt for this item", countOf: (n, total) => `${n} of ${total}`, moreInApp: (n) => `${n} more in the app`, + notInReport: "Not in this report", + openSection: (title) => `Open ${title}`, linesCovered: "lines covered", branchesCovered: "branches covered", table: { diff --git a/packages/ui/src/report/first-look/first-look-report.tsx b/packages/ui/src/report/first-look/first-look-report.tsx index b8aa5b188e..051e6c20fe 100644 --- a/packages/ui/src/report/first-look/first-look-report.tsx +++ b/packages/ui/src/report/first-look/first-look-report.tsx @@ -17,6 +17,7 @@ import { FIRST_LOOK_COPY_EN, type FirstLookCopy } from "./copy"; import { PAIRED, isClosed, progress, resolvedBySection, stripValue, type Progress } from "./living"; import { ReportSection, + sectionHref, sectionIcon, type FirstLookHrefFor, type LinkLike, @@ -30,6 +31,12 @@ export interface FirstLookReportProps { /** The living report: rebuilt from the index, compared with the first look. */ report: FirstLookLivingReport; hrefFor: FirstLookHrefFor; + /** + * The page for a section the report could not collect (`report.unavailable`). + * Omitted, the section's route key goes through `hrefFor`; null leaves the + * line without a link. + */ + unavailableHref?: (section: string) => string | null; /** Where the top bar's back link goes. */ overviewHref: string; /** The prompt for an item, a section, or the whole report (null). */ @@ -196,6 +203,58 @@ function Footer({ ); } +/** + * The sections the report could not collect, each with core's reason, so an + * absent section never reads as "nothing found". Nothing when all were read. + */ +function Unavailable({ + report, + copy, + title, + href, + Link, +}: { + report: FirstLookLivingReport; + copy: FirstLookCopy; + title: (key: string) => string; + href: (section: string) => string | null; + Link: LinkLike; +}) { + const entries = Object.entries(report.unavailable ?? {}); + if (!entries.length) return null; + return ( +
+

+ {copy.notInReport} +

+
    + {entries.map(([key, reason]) => { + const name = title(key); + const to = href(key); + return ( +
  • + {name} + {reason} + {to ? ( + + {copy.openSection(name)} + + + ) : null} +
  • + ); + })} +
+
+ ); +} + type Rewrite = { onRewrite: () => void; cost: number | null; running: boolean } | null; /** Who wrote the wording, and the way to have the model write it again. */ @@ -250,6 +309,7 @@ function Toast({ message }: { message: string | null }) { export function FirstLookReport({ report, hrefFor, + unavailableHref, overviewHref, loadPrompt, promptFlavor = "generic", @@ -345,6 +405,13 @@ export function FirstLookReport({ {report.sections.map((s) => (paired && PAIRED.includes(s.key) ? null : renderSection(s.key)))} {paired ?
{PAIRED.map(renderSection)}
: null} + sectionHref(key, hrefFor))} + Link={Link} + />