feat: the score says when a pillar stopped counting

A pillar can leave the set behind the number without anybody choosing it:
a window rolls past its floor, a module goes off, a source goes quiet. The
delta already refuses to narrate that as a health event, which stops a
false "you dropped six points" and puts nothing in its place. The level
moves, the panel shows a different number, and the cause is nowhere on the
surface. Under the adaptive minimum this matters more rather than less,
because compositions are smaller now and sit closer to their floors.

The report carries `compositionNotice` when today's set differs from the
last local day the account has a stored score for. Optional and nullable,
the additive shape the score's wire has used six times, so a payload
cached before it existed stays valid. It names what left and what joined
as pillar ids; the surfaces already own the labels, and the reason a
departed pillar stopped counting comes from that pillar's own row in the
same report rather than from a second vocabulary.

Two changes deliberately do not raise it. A method move and a recipe
change each already have their own note, and telling someone twice about
one event teaches them to ignore both.

The key is `health-score:v<version>:composition:<hash of the sorted set>`
and rides the existing dismissed-item ledger, so a dismissal holds until
the set moves again rather than until tomorrow. The read excludes today on
purpose: the row for today is written by the same request that computed
the report, so comparing against the newest row would find today's own
composition on the second load of the same page and the note would vanish
between two views of it.

This gives `HealthScoreRecord` its first production reader. Since it
shipped it has been written on every scored read and consumed by nothing
but backup and restore, which is the write-only shape the contributor
notes call a liability and which nothing in the gate can notice, because
every check proves one end. The round trip is proved against real
Postgres: raise the note, wipe the table, restore it through the admin
route, get the same note back, and hold the dismissal across it.

Rendering is one muted line on the score card and a card of its own on the
settings page, beside the recipe note rather than inside it. Deliberately
not a push.

Four fake Prisma clients gain the new read. They are doubles of a client
the reader really does call now; leaving them short and guarding the call
site instead would have been a shim for a caller that does not exist.
This commit is contained in:
Marc-André Bombeck committed 2026-08-30 16:16:57 +02:00
1 parent 319a75b02f
commit e4880dcdc1
28 files changed
+1384 -16

No files matched your search

@@ -0,0 +1,91 @@
/**
* The settings half of the composition note.
*
* Its subject is the one change on this page nobody made: the person did
* not touch the rows below it, the method did not move, and the number is
* different anyway. So the two things worth pinning are that it names the
* pillars in the reader's own language, and that it never borrows the
* recipe note's sentences — telling someone they changed something they did
* not change is worse than saying nothing, which is what shipped before.
*/
import { describe, expect, it } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { I18nProvider } from "@/lib/i18n/context";
import type { Locale } from "@/lib/i18n/config";
import type { ScorePillarId } from "@/lib/analytics/score/types";
import { ScoreCompositionNotice } from "../score-composition-notice";
function render(
props: { left: ScorePillarId[]; joined: ScorePillarId[] },
locale: Locale = "en",
): string {
return renderToStaticMarkup(
<I18nProvider initialLocale={locale}>
<ScoreCompositionNotice
left={props.left}
joined={props.joined}
onDismiss={() => {}}
/>
</I18nProvider>,
);
}
describe("a pillar that stopped counting on its own", () => {
it("names the pillar and says the number moved for that reason", () => {
const html = render({ left: ["SLEEP"], joined: [] });
expect(html).toContain('data-slot="score-composition-notice"');
expect(html).toContain("What counts changed on its own");
expect(html).toContain("Sleep");
expect(html).toContain("not because your health did");
});
it("never says the person changed anything", () => {
const html = render({ left: ["SLEEP"], joined: [] });
expect(html).not.toContain("You changed what counts");
expect(html).not.toContain("What counts is now yours to choose");
});
it("says nothing about a pillar that joined when none did", () => {
const html = render({ left: ["SLEEP"], joined: [] });
expect(html).not.toContain("Now counting toward your score");
});
});
describe("both directions at once", () => {
it("names what left and what arrived, each once", () => {
const html = render({ left: ["SLEEP"], joined: ["LIPIDS"] });
expect(html).toContain("Sleep");
expect(html).toContain("Lipids");
expect(html).toContain("Now counting toward your score");
});
});
describe("the reader's own language", () => {
it("carries the German copy with its umlauts", () => {
const html = render({ left: ["SLEEP"], joined: [] }, "de");
expect(html).toContain("Was zählt, hat sich von selbst geändert");
expect(html).not.toContain("What counts changed on its own");
});
it("keeps the Korean register the rest of the page uses", () => {
const html = render({ left: ["SLEEP"], joined: [] }, "ko");
expect(html).toContain("반영 항목이 저절로 바뀌었어요");
expect(html).not.toContain("What counts changed on its own");
});
});
describe("acknowledging it", () => {
it("offers the same dismiss the recipe note offers", () => {
const html = render({ left: ["SLEEP"], joined: [] });
expect(html).toContain('data-slot="score-composition-notice-dismiss"');
expect(html).toContain("Got it");
});
});