Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ export function trendHasAnySignal(weeks: SlopDuplicateTrendWeek[]): boolean {
return seriesHasSignal(weeks, "slop") || seriesHasSignal(weeks, "duplicate");
}

/** Most recent week with a non-null value for the given series (independent per series). */
export function latestWeekWithSignal(
weeks: SlopDuplicateTrendWeek[],
series: "slop" | "duplicate",
): SlopDuplicateTrendWeek | null {
for (let index = weeks.length - 1; index >= 0; index -= 1) {
const week = weeks[index];
if (!week) continue;
if (week.slopFlagRatePct !== null || week.duplicateFlagRatePct !== null) return week;
const value = series === "slop" ? week.slopFlagRatePct : week.duplicateFlagRatePct;
if (value !== null) return week;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";

import { SlopDuplicateTrendCard } from "@/components/site/app-panels/slop-duplicate-trend-card";
import type { MaintainerSlopDuplicateTrend } from "@/components/site/app-panels/slop-duplicate-trend-card-model";
import {
latestWeekWithSignal,
type MaintainerSlopDuplicateTrend,
} from "@/components/site/app-panels/slop-duplicate-trend-card-model";

function trend(
overrides: Partial<MaintainerSlopDuplicateTrend> = {},
Expand Down Expand Up @@ -86,4 +89,30 @@ describe("SlopDuplicateTrendCard", () => {
render(<SlopDuplicateTrendCard trend={trend({ stale: true })} />);
expect(screen.getByText(/stale snapshot/i)).toBeTruthy();
});

it("resolves each series' legend from its own latest signal-bearing week", () => {
// Most recent week has only duplicate signal; earlier week has slop (and band).
// Shared "latest any signal" would hide the slop band behind the null series.
const weeks = [
{
weekStart: "2026-06-02",
slopFlagRatePct: 18.5,
slopBandLabel: "elevated" as const,
duplicateFlagRatePct: null,
},
{
weekStart: "2026-06-09",
slopFlagRatePct: null,
slopBandLabel: null,
duplicateFlagRatePct: 40,
},
];

expect(latestWeekWithSignal(weeks, "slop")?.weekStart).toBe("2026-06-02");
expect(latestWeekWithSignal(weeks, "duplicate")?.weekStart).toBe("2026-06-09");

render(<SlopDuplicateTrendCard trend={trend({ weeks })} />);
expect(screen.getByText(/latest band: elevated/i)).toBeTruthy();
expect(screen.getByText(/latest: 40%/i)).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function SlopDuplicateTrendCard({ trend }: { trend: MaintainerSlopDuplica
const hasSignal = trendHasAnySignal(trend.weeks);
const hasSlop = seriesHasSignal(trend.weeks, "slop");
const hasDuplicate = seriesHasSignal(trend.weeks, "duplicate");
const latest = latestWeekWithSignal(trend.weeks);
const latestSlop = latestWeekWithSignal(trend.weeks, "slop");
const latestDuplicate = latestWeekWithSignal(trend.weeks, "duplicate");

return (
<AnalyticsCardShell
Expand All @@ -51,20 +52,20 @@ export function SlopDuplicateTrendCard({ trend }: { trend: MaintainerSlopDuplica
color="var(--mint)"
label="Slop flag rate"
detail={
latest?.slopBandLabel
? `latest band: ${latest.slopBandLabel}`
latestSlop?.slopBandLabel
? `latest band: ${latestSlop.slopBandLabel}`
: hasSlop
? `latest: ${formatTrendRatePct(latest?.slopFlagRatePct)}`
? `latest: ${formatTrendRatePct(latestSlop?.slopFlagRatePct)}`
: "no slop samples"
}
bandLabel={latest?.slopBandLabel}
bandLabel={latestSlop?.slopBandLabel}
/>
<LegendItem
color="var(--warning)"
label="Duplicate flag rate"
detail={
hasDuplicate
? `latest: ${formatTrendRatePct(latest?.duplicateFlagRatePct)}`
? `latest: ${formatTrendRatePct(latestDuplicate?.duplicateFlagRatePct)}`
: "no duplicate samples"
}
/>
Expand Down
Loading