fix(i18n): say what the Coach reads of older lab results when the lookback has no limit

The no-limit option promised every lab result, and the German detail
sentence ended on a dangling clause. The Coach keeps the latest value
of the most recently measured markers and, for a marker asked about,
its five previous results with older ones summarised per year for ten
years; years before that are only counted. Every language now says
that in complete sentences, with the two numbers pinned to the lab
history constants.
This commit is contained in:
Marc-André Bombeck committed 2026-10-22 18:21:58 +02:00
1 parent 3354631a85
commit e78d5f86a6
12 files changed
+73 -24

No files matched your search

@@ -151,7 +151,7 @@ describe("<SourcesRail>", () => {
// `allTime` is the default: the sentence carries the numbers the
// readers use (`history-reach.ts`).
expect(html).toContain(
"Everything you recorded: 12 months in daily detail, older readings as monthly values up to 10 years back, and every lab result, older ones summarised per year.",
"Without a limit, the Coach reads 12 months of readings in daily detail and older readings as monthly values up to 10 years back. For lab results it reads the latest value of the most recently measured markers and, for a marker you ask about, its 5 previous results, with older ones summarised per year up to 10 years back; earlier years are only counted.",
);
expect(html).not.toContain("stay visible");
});
@@ -21,9 +21,17 @@ vi.mock("@/lib/tz/resolver", () => ({
resolveUserTimezone: () => Promise.resolve("UTC"),
}));
import { locales } from "@/lib/i18n/config";
import { getServerTranslator } from "@/lib/i18n/server-translator";
import {
LAB_HISTORY_MAX_YEARS,
LAB_HISTORY_RECENT_POINTS,
} from "@/lib/ai/coach/labs-snapshot";
import {
COACH_ALL_TIME_TABLE_DAYS,
COACH_DAILY_DETAIL_DAYS,
COACH_LAB_HISTORY_YEARS,
COACH_LAB_RECENT_POINTS,
COACH_HISTORY_WINDOWS,
HISTORY_REACH_DAYS,
UNBOUNDED_REACH,
@@ -122,13 +130,43 @@ describe("the numbers the settings text states", () => {
});
expect(lookbackText("lastYear").detailParams).toEqual({ months: 12 });
expect(lookbackText("allTime")).toEqual({
// "12 months in detail, every lab result": the option says what it
// "12 months in detail, longer for labs": the option says what it
// reads, not "All" (#1263).
optionParams: { months: 12 },
detailKey: "detailAll",
detailParams: { dailyMonths: 12, years: 10 },
detailParams: { dailyMonths: 12, years: 10, labRecent: 5, labYears: 10 },
});
});
it("states the lab history the named-marker read actually carries", () => {
expect(COACH_LAB_RECENT_POINTS).toBe(LAB_HISTORY_RECENT_POINTS);
expect(COACH_LAB_HISTORY_YEARS).toBe(LAB_HISTORY_MAX_YEARS);
});
it("words the no-limit detail as a complete sentence that claims no more than is read", () => {
const { detailParams } = lookbackText("allTime");
for (const locale of locales) {
const { t } = getServerTranslator(locale);
const option = t("insights.coach.lookback.option.allTime", {
months: 12,
});
const detail = t("insights.coach.lookback.detailAll", detailParams);
// Every number reaches the sentence, none stays a raw placeholder.
expect(detail, locale).not.toMatch(/\{\w+\}/);
for (const n of ["12", "10", "5"]) expect(detail, locale).toContain(n);
// Ends as a sentence, not on a dangling clause.
expect(detail.trim(), locale).toMatch(/[.。]$|요\.?$/);
// "every lab result" was a claim the bounded history does not keep.
expect(`${option} ${detail}`, locale).not.toMatch(
/every lab|all lab|alle Laborwerte|toutes les analyses|todos los análisis|tutti gli esami|wszystkie wyniki|모든 검사|alle labuitslagen|todos os exames/i,
);
}
const de = getServerTranslator("de").t(
"insights.coach.lookback.detailAll",
detailParams,
);
expect(de).toContain("pro Jahr zusammengefasst");
});
});
describe("a history beyond the limit", () => {
+14 -3
View File
@@ -163,8 +163,17 @@ export const COACH_DAILY_DETAIL_DAYS = 365;
/** How far back an all-time table reaches, as monthly values. */
export const COACH_ALL_TIME_TABLE_DAYS = 3_650;
// Lab results are not held to a window of their own: without a limit the
// Coach reads all of them, summarised per marker (`labs-snapshot.ts`, #1263).
// Lab results are not held to a window of their own (#1263). Without a limit
// the snapshot carries the latest value of the most recently measured
// markers; a read for one named marker adds its previous results in full and
// older ones summarised per year (`labs-snapshot.ts`). The two numbers the
// sentence states are pinned to that module's constants by the test.
/** Earlier results a named-marker read lists in full (`LAB_HISTORY_RECENT_POINTS`). */
export const COACH_LAB_RECENT_POINTS = 5;
/** Years of per-year lab summaries before years are only counted (`LAB_HISTORY_MAX_YEARS`). */
export const COACH_LAB_HISTORY_YEARS = 10;
/** The i18n key and parameters describing one lookback option. */
export function lookbackText(window: CoachDefaultWindow): {
@@ -176,13 +185,15 @@ export function lookbackText(window: CoachDefaultWindow): {
if (days === null) {
const dailyMonths = Math.round(COACH_DAILY_DETAIL_DAYS / 30.4);
// The option names what "no limit" actually reads (#1263): the dense
// readings in daily detail for a year, the lab results in full.
// readings in daily detail for a year, the lab results further back.
return {
optionParams: { months: dailyMonths },
detailKey: "detailAll",
detailParams: {
dailyMonths,
years: Math.round(COACH_ALL_TIME_TABLE_DAYS / 365),
labRecent: COACH_LAB_RECENT_POINTS,
labYears: COACH_LAB_HISTORY_YEARS,
},
};
}