hub: review fix 4 — the hub writes the household's receipt; a box cannot word it or flood it (D84)

offsite_end_scheduled bypasses the household's switches and went through the
ordinary customer leg: subject and body were the box's own sentence, and 50
invented subjects gave 50 mails.

- processReceipt: the details must name a checked app (app-name shape, not
  reserved) and two parsed dates; the mail is rendered only from the hub's
  bundle with that app and the parsed end date — never the box's message.
- The cooldown key is the checked app + the parsed time of the press.
- At most 5 receipts per household in 24 hours, counted in the hub's sent log;
  drops are said once a day; old receipt keys leave the cooldown map.
- Pinned: a blocked household and a household with no address get none.

Tests seen red before the fix; 12 mutations seen red, 3 after a redo
(documentation/audits/build-release-4-2026-11-15/A/redproof-review-4.txt).

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 14:46:27 +01:00
1 parent 875c339cf5
commit be272b7cf4
10 files changed
+455 -26

No files matched your search

@@ -1892,7 +1892,10 @@ part alone, exactly as before, and still raises `offsite_snapshots_vanished`.
**The mail (D84)** `[FACT — built, not released]`. At the press the box sends `offsite_end_scheduled`; the hub mails
it to the household's own notification address — once per press, in the household's language, whatever its group
switches say (a receipt: `notify.householdReceiptEvents`), and not to the operator. **A household with no
switches say (a receipt: `notify.householdReceiptEvents`), and not to the operator. **The hub writes the mail, not the
box** (review of 2026-11-15): subject and body come from the hub's own bundle, with an app name the hub checked and
the end date it parsed from the details; the box's sentence is never mailed. A household gets at most 5 receipts in
24 hours (counted in the hub's sent log); the rest are dropped and said once a day in the hub's log. **A household with no
notification address gets no mail: the page is all it has.** A blocked household gets none either.
**Edge cases, each with its rule and its test.**
@@ -1985,7 +1988,7 @@ final dot (`2026. 12. 15.`), so the Hungarian sentences have no dot after it.
| A press that is refused (the app is installed; no hub tier) | „Ennek az alkalmazásnak a távoli másolatait most nem lehet törlésre kijelölni.” | "The off-site copies of this app cannot be marked for deletion now." |
| A record that could not be saved | „Nem sikerült elmenteni. Próbáld újra.” | "This could not be saved. Try again." |
| **The mail — subject** | „[Felhom] Információ: {app}: a távoli másolatok törlésre kijelölve” | "[Felhom] Information: {app}: the off-site copies are marked for deletion" |
| **The mail — body** (inside the hub's ordinary household mail frame: greeting, server, time, level, type, sign-off) | „{app}: az alkalmazás távoli másolatai törlésre vannak kijelölve. Törlésük napja: {dátum} Addig a Mentések oldalon a „Mégis megtartom” gombbal visszavonhatod.” | "{app}: the off-site copies of this app are marked for deletion. They are deleted on: {date}. Until then you can take this back on the Backups page with the “Keep it after all” button." |
| **The mail — body** (the HUB's own sentence, `mail.receipt.offsite_end_scheduled`, inside the hub's ordinary household mail frame: greeting, server, time, level, type, sign-off; the box's event carries the same sentence for the event list only) | „{app}: az alkalmazás távoli másolatai törlésre vannak kijelölve. Törlésük napja: {dátum} Addig a Mentések oldalon a „Mégis megtartom” gombbal visszavonhatod.” | "{app}: the off-site copies of this app are marked for deletion. They are deleted on: {date}. Until then you can take this back on the Backups page with the “Keep it after all” button." |
No mail to the household at the deletion: it can do nothing with it (`08` §8.1). The operator's records are
`offsite_ended_app_removed` (info, per app, not mailed) and `offsite_ended_app_refused` (warning) — `08` §6.5.
@@ -0,0 +1,105 @@
FINDING 4 — offsite_end_scheduled let a box mail its household without limit and with its own words.
### RED: the new tests on the hub code before the fix (felhom.eu 875c339c)
=== RUN TestD84_Receipt_ABoxCannotFloodOrWordTheHouseholdsMail
d84_receipt_bounds_test.go:31: 50 mail(s) for receipts that name no app; subject="[Felhom] Információ: ANY WORDS THE BOX CHOOSES: pay at http://evil.example"
--- FAIL: TestD84_Receipt_ABoxCannotFloodOrWordTheHouseholdsMail (0.06s)
=== RUN TestD84_Receipt_IsBuiltFromCheckedDetailsOnly
d84_receipt_bounds_test.go:81: removed_at is not a time: a mail went out: "[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: ends_at is not a time: a mail went out: "[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: ends before it was removed: a mail went out: "[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: no details: a mail went out: "[Felhom] Információ: box words"
d84_receipt_bounds_test.go:81: a reserved name: a mail went out: "[Felhom] Információ: traefik: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: the shares: a mail went out: "[Felhom] Információ: _shares: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: no stack_name: a mail went out: "[Felhom] Információ: box words"
d84_receipt_bounds_test.go:81: details are not JSON: a mail went out: "[Felhom] Információ: box words"
d84_receipt_bounds_test.go:81: a sentence as the app name: a mail went out: "[Felhom] Információ: pay now at evil.example: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: markup as the app name: a mail went out: "[Felhom] Információ: <b>x</b>: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:89: the mail must carry the parsed end date and none of the box's text: [{to:customer@example.com subject:[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve body:Kedves Ügyfél!
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.49s)
=== RUN TestD84_Receipt_ABlockedHouseholdGetsNone
--- PASS: TestD84_Receipt_ABlockedHouseholdGetsNone (0.04s)
FAIL
FAIL gitea.dooplex.hu/admin/felhom-hub/internal/notify 0.613s
FAIL
(TestD84_Receipt_ABlockedHouseholdGetsNone passed before the fix too: the customer leg already skipped a blocked household. It is a pin, and it has its own mutation below.)
### After the fix: mutations
== MUTATION: the receipt goes through the ordinary customer leg again (the box's words, the box's subject)
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_ABoxCannotFloodOrWordTheHouseholdsMail (0.04s)
d84_receipt_bounds_test.go:38: 50 presses in one burst gave 0 mails, want the daily limit 5
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.48s)
d84_receipt_bounds_test.go:89: the mail must carry the parsed end date and none of the box's text: []
== MUTATION: no daily limit
*** NOT A RED-PROOF *** (mutant rc=1 built=False real rc=0)
FAIL gitea.dooplex.hu/admin/felhom-hub/internal/notify [build failed]
internal/notify/dispatcher.go:872:2: declared and not used: sentToday
== MUTATION: the limit trusts the sent log alone (a burst is faster than the log)
*** NOT A RED-PROOF *** (mutant rc=0 built=True real rc=0)
== MUTATION: the app name is not checked
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.40s)
d84_receipt_bounds_test.go:81: a sentence as the app name: a mail went out: "[Felhom] Információ: pay now at evil.example: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: the shares: a mail went out: "[Felhom] Információ: _shares: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: markup as the app name: a mail went out: "[Felhom] Információ: <b>x</b>: a távoli másolatok törlésre kijelölve"
== MUTATION: a reserved name gets a receipt
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.44s)
d84_receipt_bounds_test.go:81: a reserved name: a mail went out: "[Felhom] Információ: traefik: a távoli másolatok törlésre kijelölve"
== MUTATION: the dates are not checked
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.46s)
d84_receipt_bounds_test.go:81: removed_at is not a time: a mail went out: "[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: ends_at is not a time: a mail went out: "[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve"
d84_receipt_bounds_test.go:81: ends before it was removed: a mail went out: "[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve"
== MUTATION: an end before the press is accepted
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.49s)
d84_receipt_bounds_test.go:81: ends before it was removed: a mail went out: "[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve"
== MUTATION: the press's key is the app alone
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_OncePerPress (0.04s)
d84_receipt_test.go:97: three presses gave 2 mails, want 3: [{to:customer@example.com subject:[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve body:Kedves Ügyfél!
== MUTATION: the press's time is keyed as the box wrote it (another zone = another press)
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.47s)
d84_receipt_bounds_test.go:96: one press sent twice with a changed subject gave 2 mails
== MUTATION: a blocked household gets the receipt
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_ABlockedHouseholdGetsNone (0.04s)
d84_receipt_bounds_test.go:108: a blocked household was mailed: [{to:customer@example.com subject:[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve body:Kedves Ügyfél!
== MUTATION: old presses stay in the cooldown map (and count against today)
*** NOT A RED-PROOF *** (mutant rc=1 built=False real rc=0)
FAIL gitea.dooplex.hu/admin/felhom-hub/internal/notify [build failed]
internal/notify/dispatcher.go:879:9: declared and not used: at
== MUTATION: the mail's date is today, not the parsed end
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_IsBuiltFromCheckedDetailsOnly (0.47s)
d84_receipt_bounds_test.go:89: the mail must carry the parsed end date and none of the box's text: [{to:customer@example.com subject:[Felhom] Információ: vikunja: a távoli másolatok törlésre kijelölve body:Kedves Ügyfél!
--- FAIL: TestD84_Receipt_ReachesTheHouseholdWhateverItsSwitches (0.04s)
d84_receipt_test.go:54: the body lacks "2026. 12. 15.":
12 mutations, 3 not a red-proof
### the three mutations done again
== MUTATION: REDO (the first mutant did not compile): no daily limit
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_ABoxCannotFloodOrWordTheHouseholdsMail (0.07s)
d84_receipt_bounds_test.go:38: 50 presses in one burst gave 50 mails, want the daily limit 5
--- FAIL: TestD84_Receipt_TheDailyLimitSurvivesARestart (0.04s)
d84_receipt_bounds_test.go:168: after a restart the household got mail number 6 of the day (limit 5)
== MUTATION: REDO (the first mutant was built wrongly: it left the part it meant to remove; and the test that sees this one was added): the limit does not read the sent log (a restart gives five more)
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_TheDailyLimitSurvivesARestart (0.05s)
d84_receipt_bounds_test.go:168: after a restart the household got mail number 6 of the day (limit 5)
== MUTATION: REDO (the first mutant did not compile): old presses stay in the cooldown map (and count against today)
RED on the mutant, GREEN on the real file
--- FAIL: TestD84_Receipt_OldPressesLeaveTheCooldownMap (0.04s)
d84_receipt_bounds_test.go:133: 30 presses of yesterday must not count against today's limit: 0 mail(s)
3 mutations, 0 not a red-proof
NOT PROVEN, said plainly: the in-memory half of the limit (`inFlight >= receiptsPerDay`). In a test the events are
processed one after another, so the sent log is always written before the next one is judged and the log half
alone holds the limit. The memory half is for a burst processed in parallel; it stays in the code and is not claimed.