From d62d346151cd93589210514b5d025e83ccdca2ed Mon Sep 17 00:00:00 2001 From: OmO Orchestrator Date: Fri, 20 Nov 2026 04:51:57 -0500 Subject: [PATCH] fix(healthpost): water-floor interop needs distinct reporters + honest device-local tally label The waterborne->water-floor interop fired on a single resident tapping Report diarrhea 5x (count>=5), letting one person raise everyone's water ration - contradicting Tunnel Safety's distinct-reporter corroboration standard. Added countDistinctSymptomReporters (distinct authorPubkeys) and gated the action on >=3 DISTINCT residents. Relabeled the tally 'Symptom tally (this device)' since symptom reports stay local (not synced). Follow-up: seed a demo outbreak (foreign-signed diarrhea reports) so it is cold-demoable single-device. --- .../healthpost/SymptomTallyDashboard.test.tsx | 24 +++++++++++++----- .../healthpost/SymptomTallyDashboard.tsx | 22 +++++++++++----- .../healthpost/healthpostEvents.test.ts | 24 +++++++++++++++++- src/miniapps/healthpost/healthpostEvents.ts | 25 +++++++++++++++++++ 4 files changed, 82 insertions(+), 13 deletions(-) diff --git a/src/miniapps/healthpost/SymptomTallyDashboard.test.tsx b/src/miniapps/healthpost/SymptomTallyDashboard.test.tsx index bb8d5ca..bb8ad62 100644 --- a/src/miniapps/healthpost/SymptomTallyDashboard.test.tsx +++ b/src/miniapps/healthpost/SymptomTallyDashboard.test.tsx @@ -5,8 +5,18 @@ import userEvent from "@testing-library/user-event"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { db } from "../../lib/db.ts"; import { init } from "../../lib/identity.ts"; -import { readAll } from "../../lib/eventlog.ts"; +import { appendEntry, readAll } from "../../lib/eventlog.ts"; +import { buildForeignSignedEntry } from "../../admin/seedEvents.ts"; import { postSymptomReport } from "./healthpostEvents.ts"; + +async function seedForeignDiarrhea(keyByte: number, lamportTs: number): Promise { + const entry = await buildForeignSignedEntry( + new Uint8Array(32).fill(keyByte), + { type: "healthpost.symptomReport", symptom: "diarrhea" }, + lamportTs, + ); + await appendEntry(entry); +} import { SymptomTallyDashboard } from "./SymptomTallyDashboard.tsx"; afterEach(cleanup); @@ -67,9 +77,11 @@ describe("SymptomTallyDashboard (QA happy path - seeded reports)", () => { }); describe("SymptomTallyDashboard - waterborne interop (Health -> Fair Share)", () => { - it("offers raising the Fair Share water floor when diarrhea reports cluster, and appends a signed fairshare.floor", async () => { + it("offers the water floor only after >=3 DISTINCT residents report diarrhea, then appends a signed fairshare.floor", async () => { const user = userEvent.setup(); - for (let i = 0; i < 5; i += 1) await postSymptomReport("diarrhea"); + await seedForeignDiarrhea(11, 101); + await seedForeignDiarrhea(12, 102); + await seedForeignDiarrhea(13, 103); render(); @@ -90,11 +102,11 @@ describe("SymptomTallyDashboard - waterborne interop (Health -> Fair Share)", () expect((floors[0]!.payload as { resource: string }).resource).toBe("water"); }); - it("does not offer the water-floor action below the diarrhea cluster threshold", async () => { - await postSymptomReport("diarrhea"); + it("does NOT offer the water floor for one resident's repeated reports (anti-inflation)", async () => { + for (let i = 0; i < 5; i += 1) await postSymptomReport("diarrhea"); render(); await waitFor(() => - expect(screen.getByTestId("healthpost-symptom-count-diarrhea")).toHaveTextContent("1"), + expect(screen.getByTestId("healthpost-symptom-count-diarrhea")).toHaveTextContent("5"), ); expect(screen.queryByTestId("healthpost-waterborne-interop")).not.toBeInTheDocument(); }); diff --git a/src/miniapps/healthpost/SymptomTallyDashboard.tsx b/src/miniapps/healthpost/SymptomTallyDashboard.tsx index 7b53c89..8081245 100644 --- a/src/miniapps/healthpost/SymptomTallyDashboard.tsx +++ b/src/miniapps/healthpost/SymptomTallyDashboard.tsx @@ -7,7 +7,11 @@ import { } from "../../lib/healthpostTally.ts"; import { useEventLogEntries } from "../../shell/useEventLogEntries.ts"; import { postFairshareFloor } from "../../lib/fairshare.ts"; -import { extractSymptomReports, postSymptomReport } from "./healthpostEvents.ts"; +import { + countDistinctSymptomReporters, + extractSymptomReports, + postSymptomReport, +} from "./healthpostEvents.ts"; import styles from "./SymptomTallyDashboard.module.css"; /** Protective per-resident water floor a clinician can set when diarrhea reports @@ -15,6 +19,11 @@ import styles from "./SymptomTallyDashboard.module.css"; * rehydration. A fixed policy default, never a modeled/forecast value. */ const OUTBREAK_WATER_FLOOR_PER_AGENT = 25; +/** Distinct resident identities that must independently report diarrhea before + * the water-floor action is offered - one person re-tapping can never raise + * everyone's water ration (mirrors Tunnel Safety's distinct-reporter gate). */ +const MIN_DISTINCT_DIARRHEA_REPORTERS = 3; + const SYMPTOM_LABEL: Record = { fever: "Fever", cough: "Cough", @@ -47,7 +56,7 @@ export function SymptomTallyDashboard() { const [floorSubmitting, setFloorSubmitting] = useState(false); const [floorStatus, setFloorStatus] = useState(); - const diarrheaRow = tally.bySymptom.find((row) => row.symptom === "diarrhea"); + const distinctDiarrheaReporters = countDistinctSymptomReporters(entries, "diarrhea"); async function handleRaiseWaterFloor() { setFloorSubmitting(true); @@ -74,7 +83,7 @@ export function SymptomTallyDashboard() { return (
-

Community symptom tally

+

Symptom tally (this device)

{tally.totalReports === 0 ? (

@@ -115,14 +124,15 @@ export function SymptomTallyDashboard() { ))} - {diarrheaRow && diarrheaRow.dispatchPriority !== "routine" && ( + {distinctDiarrheaReporters >= MIN_DISTINCT_DIARRHEA_REPORTERS && (

- {diarrheaRow.count} diarrhea reports can signal a waterborne problem. Raising the Fair - Share water floor guarantees every resident enough water for oral rehydration. + {distinctDiarrheaReporters} different residents have independently reported diarrhea - + a corroborated waterborne-outbreak signal. Raising the Fair Share water floor + guarantees every resident enough water for oral rehydration.