From bd8e05e48444422e5e197046fe93f2d0205eb1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 5 Oct 2026 07:58:47 +0200 Subject: [PATCH] fix(dashboard): drop a lead sentence only when it repeats the score as the score The lead filter dropped any sentence containing the score's digits, so a score of 52 threw out "You slept 7 h 52 min" and a resting heart rate of 52 bpm. A sentence now repeats the ring only when it names the score (in any shipped language, or as "out of 100") and carries the number on its own, not as part of a time, a decimal or a measurement with a unit. --- .../daily/__tests__/today-overview.test.ts | 31 +++++++++++++++++++ src/lib/daily/today-overview.ts | 23 +++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/lib/daily/__tests__/today-overview.test.ts b/src/lib/daily/__tests__/today-overview.test.ts index 7e047203e..db11291ec 100644 --- a/src/lib/daily/__tests__/today-overview.test.ts +++ b/src/lib/daily/__tests__/today-overview.test.ts @@ -149,6 +149,37 @@ describe("firstSubstantiveSentence", () => { ).toBe("Sleep dipped slightly last night."); }); + it("keeps a sentence where the score's digits are part of another figure", () => { + // Score 52, and a sleep duration that happens to end in 52 minutes. + expect( + firstSubstantiveSentence("You slept 7 h 52 min, a solid night.", 52), + ).toBe("You slept 7 h 52 min, a solid night."); + expect( + firstSubstantiveSentence("Your resting heart rate is 52 bpm.", 52), + ).toBe("Your resting heart rate is 52 bpm."); + expect( + firstSubstantiveSentence("You walked 52 minutes more than usual.", 52), + ).toBe("You walked 52 minutes more than usual."); + }); + + it("still skips the score sentence in every shipped language", () => { + for (const sentence of [ + "Your health score is 52.", + "Dein Gesundheitsscore heute liegt bei 52.", + "Tu puntuación de salud hoy es 52.", + "Ton score de santé aujourd'hui est de 52.", + "Il tuo punteggio di salute oggi è 52.", + "오늘 건강 점수는 52점이에요.", + "Twój dzisiejszy wynik zdrowia to 52.", + "You are at 52/100 today.", + ]) { + expect( + firstSubstantiveSentence(`${sentence} Sleep dipped last night.`, 52), + sentence, + ).toBe("Sleep dipped last night."); + } + }); + it("keeps decimals inside one sentence", () => { expect( firstSubstantiveSentence("You slept 7.5 hours, a solid night.", null), diff --git a/src/lib/daily/today-overview.ts b/src/lib/daily/today-overview.ts index df7a78d94..9f12c6731 100644 --- a/src/lib/daily/today-overview.ts +++ b/src/lib/daily/today-overview.ts @@ -221,11 +221,32 @@ export function isGreetingOnly(sentence: string): boolean { return words.length < MIN_CONTENT_WORDS; } +/** + * Words that name the health score in every shipped language, and the + * "out of 100" forms. A sentence repeats the ring only when it talks about + * the score; a figure that merely shares its digits ("7 h 52 min" next to a + * score of 52) is content. + */ +const SCORE_CONTEXT = + /(?