Skip to content

feat(notifications): show leave in the coordinators' morning e-mail - #404

Merged
lowicz merged 3 commits into
mainfrom
fm/oncall-leave-u-step5
Dec 3, 2026
Merged

lowicz merged 3 commits into
mainfrom
fm/oncall-leave-u-step5

Conversation

@lowicz

@lowicz lowicz commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Intent

The oncall project gained a new preference kind "U" (urlop, leave). The captain approved a 5-step plan; steps 1-4 (PRs 399, 400, 401, 403) are merged. This is the LAST STEP 5: the morning e-mail of the coordinators (T5, D10-A) says it where the duty is read: the role line, one action sentence, "Na urlopie" and the week ahead. The approved design and decisions are in ~/firstmate/data/oncall-leave-u-scout/report.md (section 4.5 T5 paragraph at line ~146, D10, 6.2 step 5, 9, 11), critique evidence in data/oncall-leave-u-scout/critique/. Leave is team-visible only as "urlop", never with a reason or note (D14).

What those report items say, so this stands without the report:

  • T5, morning e-mail of the coordinators (report 4.5). The role line says it: "- SECONDARY: Marek Nowak (na urlopie, bez zastępstwa)". One sentence asks for the action: "Marek Nowak ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę." Then "Na urlopie: Marek Nowak (do pt 11 gru)." and the week ahead: "Dyżury osób na urlopie w najbliższych 7 dniach: pt 11 gru PRIMARY, Marek Nowak."
  • D10, a duty on a leave day that nobody took over: the collision flow relies on someone acting; if nobody does, the day arrives and the app shows a person on leave as on duty. Chosen A: say it where the duty is read - the tag "na urlopie" and "bez zastępstwa" on the "Teraz" strip and the duty cards (shipped in step 1), and the role line and one action sentence in the morning e-mail (this step). Not chosen (D10-B): a reminder e-mail to coordinators before the duty day; no such e-mail is added.
  • Report 6.2, step 5: morning e-mail (T5). backend/src/oncall/domain/digest.py (DutyDigest gains leave today, holders on leave, and the seven-day list) and duty_digest in backend/src/oncall/notifications/templates.py; the pinned snapshot in tests/snapshots/ is regenerated with UPDATE_EMAIL_SNAPSHOTS=1. The e-mail stays Polish (tests/architecture/test_language.py).
  • Report 9 and 11 (the decision record and the assessment): D8 chose the team views T1, T3 and T5, T5 being the line in the coordinators' existing morning digest e-mail; before the assessment the e-mail named a person on leave as on duty, after it the role line says it, with the action sentence and the week ahead. The assessment's states for the digest: with nobody on leave on the days the digest covers there is no line at all (the digest stays as short as today); recipients are coordinators and admins, as today; the digest is recorded and sent in Polish.
  • D14, what counts as "urlop": chosen A - any whole day away from work. The word stays "urlop"; the team sees only "urlop", never a reason; the app does not ask for one.

What Changed

  • The coordinators' morning e-mail now shows leave:
    • A duty whose holder is on leave that day gets "(na urlopie, bez zastępstwa)" after the name.
    • If the duty is today, a separate sentence names the person and their roles and ends with "Zmień obsadę."
    • "Na urlopie" lists who is on leave today and until when. Another line lists the duties held by people on leave in the next 7 days.
    • With no leave to report, the e-mail stays the same as before. Leave notes are never shown.
  • To build this, the digest reads duties for at least 7 days ahead, plus current and future leave entries. Entries on back-to-back days count as one leave. The calendar uses the same code, moved to a shared leave_runs function.
  • Tests cover the digest, the leave query and the e-mail text, with a new HTML snapshot of an e-mail that shows leave. The Polish and English integration docs describe the new lines.

Risk Assessment

✅ Low: The change only adds read-only content to an existing e-mail that still goes to coordinators and admins only; the round 1 fix now reads just current or future leave entries without notes, one rule for joining entries is shared with the calendar, and the output matches every required T5/D10-A sentence.

Testing

I ran the real app and worker against a throwaway PostgreSQL database and a local test mail server, and read the e-mails that arrived. The example from the intent matched word for word. With nobody on leave, the e-mail was identical to the one from the base commit. Weekends, duties taken over by someone else, the seven-day limit, private notes, people who left the team and days off all passed, and so did the related test files. I ran those tests with the project's Python because the installed uv is 0.12.22 and the project requires 0.13.10. Early runs failed because of my test setup: the mail server stalled on name lookups, and some script queries and expectations were wrong. I fixed these in the test scripts and reran every scenario; no product code changed. The logo is broken in the screenshots only because its web address was not being served. Screenshots, e-mail copies and a transcript are saved, and everything temporary was removed.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
A coordinator gets the example from the intent: Marek has SECONDARY and 11–19 on Thursday 10 December, PRIMARY on Friday, and leave until Friday. Role lines, action sentence, 'Na urlopie' and week ahe… ✅ pass live s2-spec-example.txt, s2-spec-example.png, s2-spec-example-narrow.png; transcript.txt section S2
Nobody on leave: the Thursday and Friday e-mails are identical (subject, text and HTML) to those from the base commit ✅ pass live transcript.txt section S1; s1-no-leave-thu.txt, s1-no-leave-thu.png and s1-no-leave-fri.txt
Only the coordinator and admin get the digest; a restarted worker sends no second digest and no extra reminder ✅ pass live transcript.txt sections S1 and S2
Trying to leak a private note: leave saved with a secret note never shows it in the digest e-mails or in the stored digest rows ✅ pass live transcript.txt section S2
Someone takes over the duty before the e-mail goes out: no mark and no action sentence for it, but the absent person is still listed under 'Na urlopie' ✅ pass live s3-takeover.txt; transcript.txt section S3
Only 11–19 is held by someone on leave: only that role is marked and named in the action sentence ✅ pass live s9-late-only.txt; transcript.txt section S9
'Nie mogę' entries and leave that ended yesterday change nothing in the e-mail ✅ pass live s4-unavailable-only.txt; transcript.txt section S4
The Friday e-mail covers the weekend: weekend holders on leave are marked, the action sentence covers only today, and back-to-back leave entries show one end date ✅ pass live s5-friday-weekend.txt, s5-friday-weekend.png; transcript.txt section S5
Seven-day limit: a duty on day 7 is listed, one on day 8 is not, and future leave adds no 'Na urlopie' or action sentence ✅ pass live s6-boundary.txt; transcript.txt section S6
Two people on leave: both are named with one 'Zmień obsadę'. A former member still holding a duty is included, and one with no duty is not named ✅ pass live s7-two-people.txt; transcript.txt section S7 (the 'former member with no duty' check is printed after S8)
Saturday: no digest and no leave reminder is sent ✅ pass live transcript.txt section S8

E-mail with the example from the intent

Same e-mail, narrow (500 px)

Friday e-mail covering the weekend

E-mail with nobody on leave

Evidence: Received example e-mail as plain text
Dyżury na dziś, 10 grudnia

Dziś (czw 10-12-2026) na dyżurze:
- PRIMARY: Anna Kowalska
- SECONDARY: Marek Nowak (na urlopie, bez zastępstwa)
- 11–19: Marek Nowak (na urlopie, bez zastępstwa)

Marek Nowak ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę.

Na urlopie: Marek Nowak (do pt 11 gru).
Dyżury osób na urlopie w najbliższych 7 dniach: pt 11 gru PRIMARY, Marek Nowak.

Aktualny grafik: http://localhost:8080/
Evidence: Transcript of all scenarios
Created demo accounts: admin, anna, marek, ola, piotr and viewer.
Admin id: 36e540fd-807b-4011-9cfc-4a434cdfa613
2026-12-03 02:18:07,922 INFO event=login attempt=f3161c2e login=admin outcome=signed_in source=local
2026-12-03 02:18:23,957 INFO event=login attempt=7aa2ef07 login=admin outcome=signed_in source=local
2026-12-03 02:18:33,099 INFO event=login attempt=bca99742 login=admin outcome=signed_in source=local
2026-12-03 02:18:42,223 INFO event=login attempt=f0ddfba0 login=admin outcome=signed_in source=local
2026-12-03 02:18:51,491 INFO event=login attempt=53723b1f login=admin outcome=signed_in source=local
2026-12-03 02:19:00,636 INFO event=login attempt=9819b09c login=admin outcome=signed_in source=local
2026-12-03 02:19:09,791 INFO event=login attempt=4e6fbbdd login=admin outcome=signed_in source=local
2026-12-03 02:19:18,843 INFO event=login attempt=9ea0fa18 login=admin outcome=signed_in source=local
2026-12-10|Thu|late_shift=Marek Nowak, primary=Anna Kowalska, secondary=Marek Nowak
2026-12-11|Fri|late_shift=Ola Wiśniewska, primary=Marek Nowak, secondary=Ola Wiśniewska
2026-12-12|Sat|primary=Ola Wiśniewska, secondary=Piotr Zieliński
2026-12-13|Sun|primary=Piotr Zieliński, secondary=Anna Kowalska
2026-12-14|Mon|late_shift=Marek Nowak, primary=Anna Kowalska, secondary=Marek Nowak
2026-12-15|Tue|late_shift=Ola Wiśniewska, primary=Marek Nowak, secondary=Ola Wiśniewska
2026-12-16|Wed|late_shift=Piotr Zieliński, primary=Ola Wiśniewska, secondary=Piotr Zieliński
2026-12-17|Thu|late_shift=Anna Kowalska, primary=Piotr Zieliński, secondary=Anna Kowalska
2026-12-18|Fri|late_shift=Marek Nowak, primary=Anna Kowalska, secondary=Marek Nowak
2026-12-19|Sat|primary=Marek Nowak, secondary=Ola Wiśniewska
2026-12-20|Sun|primary=Ola Wiśniewska, secondary=Piotr Zieliński
2026-12-21|Mon|late_shift=Anna Kowalska, primary=Piotr Zieliński, secondary=Anna Kowalska
2026-12-22|Tue|late_shift=Marek Nowak, primary=Anna Kowalska, secondary=Marek Nowak
2026-12-23|Wed|late_shift=Ola Wiśniewska, primary=Marek Nowak, secondary=Ola Wiśniewska

== S1 nobody on leave: digest byte-identical to the base commit's
   all mail: [('koord@example.com', 'Dyżury na dziś, 10 grudnia'), ('admin@example.com', 'Dyżury na dziś, 10 grudnia')]
   Dziś (czw 10-12-2026) na dyżurze:
   - PRIMARY: Anna Kowalska
   - SECONDARY: Marek Nowak
   - 11–19: Marek Nowak
   
   Aktualny grafik: http://localhost:8080/
   
   [PASS] thu new == base, for admin and coordinator
   [PASS] thu recipients
   all mail: [('koord@example.com', 'Dyżury od 11 do 13 grudnia'), ('admin@example.com', 'Dyżury od 11 do 13 grudnia')]
   Dyżury od pt 11-12-2026 do niedz 13-12-2026:
   
   pt 11-12-2026:
   - PRIMARY: Marek Nowak
   - SECONDARY: Ola Wiśniewska
   - 11–19: Ola Wiśniewska
   
   sob 12-12-2026:
   - PRIMARY: Ola Wiśniewska
   - SECONDARY: Piotr Zieliński
   - 11–19: brak dyżuru (dzień wolny)
   
   niedz 13-12-2026:
   - PRIMARY: Piotr Zieliński
   - SECONDARY: Anna Kowalska
   - 11–19: brak dyżuru (dzień wolny)
   
   Grafik na kolejne dni może się jeszcze zmienić.
   Aktualny grafik: http://localhost:8080/
   
   [PASS] fri new == base, for admin and coordinator
   [PASS] fri recipients

== S2 spec example: Marek SECONDARY + 11-19 on Thu 10 Dec, PRIMARY Fri 11, leave to 11; note never shown
   API leave Marek Nowak 2026-12-10 2026-12-11 -> 200 
   all mail: [('koord@example.com', 'Dyżury na dziś, 10 grudnia'), ('admin@example.com', 'Dyżury na dziś, 10 grudnia'), ('marek@example.com', 'Wpisano urlop w Twoim imieniu: 10-12-2026 – 11-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Marek Nowak'), ('admin@example.com', 'Urlop koliduje z dyżurem: Marek Nowak')]
   Dziś (czw 10-12-2026) na dyżurze:
   - PRIMARY: Anna Kowalska
   - SECONDARY: Marek Nowak (na urlopie, bez zastępstwa)
   - 11–19: Marek Nowak (na urlopie, bez zastępstwa)
   
   Marek Nowak ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę.
   
   Na urlopie: Marek Nowak (do pt 11 gru).
   Dyżury osób na urlopie w najbliższych 7 dniach: pt 11 gru PRIMARY, Marek Nowak.
   
   Aktualny grafik: http://localhost:8080/
   
   [PASS] text has: - SECONDARY: Marek Nowak (na urlopie, bez zastępstwa)
   [PASS] text has: - 11–19: Marek Nowak (na urlopie, bez zastępstwa)
   [PASS] text has: Marek Nowak ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę.
   [PASS] text has: Na urlopie: Marek Nowak (do pt 11 gru).
   [PASS] text has: Dyżury osób na urlopie w najbliższych 7 dniach: pt 11 gru PRIMARY, Marek Nowak.
   [PASS] Anna not marked
   [PASS] no note/reason in either digest (text, HTML, subject)
   mails with the note (all outside this change): [('marek@example.com', 'Wpisano urlop w Twoim imieniu: 10-12-2026 – 11-12-2026')]
   [PASS] digest only to admin+coordinator
   [PASS] stored outbox has no note
   [PASS] restarted worker sends no second digest/reminder

== S3 takeover: Ola takes Marek's SECONDARY before the digest; which moves the paired 11-19 too
   API leave Marek Nowak 2026-12-10 2026-12-11 -> 200 
   API override 2026-12-10 secondary Ola Wiśniewska -> 200 
   API override 2026-12-11 primary Piotr Zieliński -> 200 
   all mail: [('koord@example.com', 'Dyżury na dziś, 10 grudnia'), ('admin@example.com', 'Dyżury na dziś, 10 grudnia'), ('piotr@example.com', 'Zmiana przydziału: pt 11-12-2026 · PRIMARY'), ('marek@example.com', 'Zmiana przydziału: pt 11-12-2026 · PRIMARY'), ('ola@example.com', 'Zmiana przydziału: czw 10-12-2026 · SECONDARY i 11–19'), ('marek@example.com', 'Zmiana przydziału: czw 10-12-2026 · SECONDARY i 11–19'), ('marek@example.com', 'Wpisano urlop w Twoim imieniu: 10-12-2026 – 11-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Marek Nowak'), ('admin@example.com', 'Urlop koliduje z dyżurem: Marek Nowak')]
   Dziś (czw 10-12-2026) na dyżurze:
   - PRIMARY: Anna Kowalska
   - SECONDARY: Ola Wiśniewska
   - 11–19: Ola Wiśniewska
   
   Na urlopie: Marek Nowak (do pt 11 gru).
   
   Aktualny grafik: http://localhost:8080/
   
   [PASS] SECONDARY now Ola, unmarked
   [PASS] 11–19 moved with it, no plea, no mark; Marek still 'Na urlopie'
   [PASS] no week-ahead line

== S4 'nie mogę' alone, and leave that ended yesterday, change nothing
   API unavailable Marek Nowak 2026-12-10 2026-12-17 -> 200 
   API leave Anna Kowalska 2026-12-08 2026-12-09 -> 200 
   all mail: [('koord@example.com', 'Dyżury na dziś, 10 grudnia'), ('admin@example.com', 'Dyżury na dziś, 10 grudnia'), ('anna@example.com', 'Wpisano urlop w Twoim imieniu: 08-12-2026 – 09-12-2026'), ('marek@example.com', 'Zgłoszono dostępność w Twoim imieniu: 10-12-2026 – 17-12-2026'), ('koord@example.com', 'Niedostępność koliduje z dyżurem: Marek Nowak'), ('admin@example.com', 'Niedostępność koliduje z dyżurem: Marek Nowak')]
   Dziś (czw 10-12-2026) na dyżurze:
   - PRIMARY: Anna Kowalska
   - SECONDARY: Marek Nowak
   - 11–19: Marek Nowak
   
   Aktualny grafik: http://localhost:8080/
   
   [PASS] identical to no-leave digest

== S5 Friday digest covers the weekend; adjacent entries join; week-ahead boundary day 7 in, day 8 out
   API leave Piotr Zieliński 2026-12-12 2026-12-14 -> 200 
   API leave Anna Kowalska 2026-12-18 2026-12-18 -> 200 
   API leave Anna Kowalska 2026-12-19 2026-12-19 -> 200 
   API leave Ola Wiśniewska 2026-12-11 2026-12-13 -> 200 
   API leave Ola Wiśniewska 2026-12-14 2026-12-15 -> 200 
Anna Kowalska|2026-12-18|2026-12-18|leave
Anna Kowalska|2026-12-19|2026-12-19|leave
Ola Wiśniewska|2026-12-11|2026-12-13|leave
Ola Wiśniewska|2026-12-14|2026-12-15|leave
Piotr Zieliński|2026-12-12|2026-12-14|leave
2026-12-11|late_shift|Ola Wiśniewska
2026-12-11|primary|Marek Nowak
2026-12-11|secondary|Ola Wiśniewska
2026-12-12|primary|Ola Wiśniewska
2026-12-12|secondary|Piotr Zieliński
2026-12-13|primary|Piotr Zieliński
2026-12-13|secondary|Anna Kowalska
2026-12-14|late_shift|Marek Nowak
2026-12-14|primary|Anna Kowalska
2026-12-14|secondary|Marek Nowak
2026-12-15|late_shift|Ola Wiśniewska
2026-12-15|primary|Marek Nowak
2026-12-15|secondary|Ola Wiśniewska
2026-12-16|late_shift|Piotr Zieliński
2026-12-16|primary|Ola Wiśniewska
2026-12-16|secondary|Piotr Zieliński
2026-12-17|late_shift|Anna Kowalska
2026-12-17|primary|Piotr Zieliński
2026-12-17|secondary|Anna Kowalska
2026-12-18|late_shift|Marek Nowak
2026-12-18|primary|Anna Kowalska
2026-12-18|secondary|Marek Nowak
2026-12-19|primary|Marek Nowak
2026-12-19|secondary|Ola Wiśniewska
   all mail: [('koord@example.com', 'Dyżury od 11 do 13 grudnia'), ('admin@example.com', 'Dyżury od 11 do 13 grudnia'), ('ola@example.com', 'Wpisano urlop w Twoim imieniu: 14-12-2026 – 15-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Ola Wiśniewska'), ('admin@example.com', 'Urlop koliduje z dyżurem: Ola Wiśniewska'), ('ola@example.com', 'Wpisano urlop w Twoim imieniu: 11-12-2026 – 13-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Ola Wiśniewska'), ('admin@example.com', 'Urlop koliduje z dyżurem: Ola Wiśniewska'), ('anna@example.com', 'Wpisano urlop w Twoim imieniu: 19-12-2026 – 19-12-2026'), ('anna@example.com', 'Wpisano urlop w Twoim imieniu: 18-12-2026 – 18-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Anna Kowalska'), ('admin@example.com', 'Urlop koliduje z dyżurem: Anna Kowalska'), ('piotr@example.com', 'Wpisano urlop w Twoim imieniu: 12-12-2026 – 14-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Piotr Zieliński'), ('admin@example.com', 'Urlop koliduje z dyżurem: Piotr Zieliński')]
   Dyżury od pt 11-12-2026 do niedz 13-12-2026:
   
   pt 11-12-2026:
   - PRIMARY: Marek Nowak
   - SECONDARY: Ola Wiśniewska (na urlopie, bez zastępstwa)
   - 11–19: Ola Wiśniewska (na urlopie, bez zastępstwa)
   
   sob 12-12-2026:
   - PRIMARY: Ola Wiśniewska (na urlopie, bez zastępstwa)
   - SECONDARY: Piotr Zieliński (na urlopie, bez zastępstwa)
   - 11–19: brak dyżuru (dzień wolny)
   
   niedz 13-12-2026:
   - PRIMARY: Piotr Zieliński (na urlopie, bez zastępstwa)
   - SECONDARY: Anna Kowalska
   - 11–19: brak dyżuru (dzień wolny)
   
   Ola Wiśniewska ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę.
   
   Na urlopie: Ola Wiśniewska (do wt 15 gru).
   Dyżury osób na urlopie w najbliższych 7 dniach: sob 12 gru PRIMARY, Ola Wiśniewska; sob 12 gru SECONDARY, Piotr Zieliński; niedz 13 gru PRIMARY, Piotr Zieliński; wt 15 gru SECONDARY i 11–19, Ola Wiśniewska; pt 18 gru PRIMARY, Anna Kowalska.
   
   Grafik na kolejne dni może się jeszcze zmienić.
   Aktualny grafik: http://localhost:8080/
   
   [PASS] today plea: Ola only, SECONDARY i 11–19
   [PASS] weekend holders marked on their own lines
   [PASS] adjacent entries joined, Piotr not yet on leave
   [PASS] week ahead: 12,13,15,18 in; 19 out

== S6 seven-day boundary
   API leave Anna Kowalska 2026-12-17 2026-12-18 -> 200 
   API leave Marek Nowak 2026-12-17 2026-12-18 -> 200 
   all mail: [('koord@example.com', 'Dyżury na dziś, 10 grudnia'), ('admin@example.com', 'Dyżury na dziś, 10 grudnia'), ('marek@example.com', 'Wpisano urlop w Twoim imieniu: 17-12-2026 – 18-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Marek Nowak'), ('admin@example.com', 'Urlop koliduje z dyżurem: Marek Nowak'), ('anna@example.com', 'Wpisano urlop w Twoim imieniu: 17-12-2026 – 18-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Anna Kowalska'), ('admin@example.com', 'Urlop koliduje z dyżurem: Anna Kowalska')]
   Dziś (czw 10-12-2026) na dyżurze:
   - PRIMARY: Anna Kowalska
   - SECONDARY: Marek Nowak
   - 11–19: Marek Nowak
   
   Dyżury osób na urlopie w najbliższych 7 dniach: czw 17 gru SECONDARY i 11–19, Anna Kowalska.
   
   Aktualny grafik: http://localhost:8080/
   
   [PASS] day +7 (Thu 17) in, nothing for +8 (Fri 18), nobody 'Na urlopie' today

== S7 two people on leave today; former member still holding a duty
   API leave Marek Nowak 2026-12-10 2026-12-10 -> 200 
   API leave Anna Kowalska 2026-12-10 2027-01-04 -> 200 
   all mail: [('koord@example.com', 'Dyżury na dziś, 10 grudnia'), ('admin@example.com', 'Dyżury na dziś, 10 grudnia'), ('anna@example.com', 'Wpisano urlop w Twoim imieniu: 10-12-2026 – 04-01-2027'), ('koord@example.com', 'Urlop koliduje z dyżurem: Anna Kowalska'), ('admin@example.com', 'Urlop koliduje z dyżurem: Anna Kowalska'), ('marek@example.com', 'Wpisano urlop w Twoim imieniu: 10-12-2026 – 10-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Marek Nowak'), ('admin@example.com', 'Urlop koliduje z dyżurem: Marek Nowak')]
   Dziś (czw 10-12-2026) na dyżurze:
   - PRIMARY: Anna Kowalska (na urlopie, bez zastępstwa)
   - SECONDARY: Marek Nowak (na urlopie, bez zastępstwa)
   - 11–19: Marek Nowak (na urlopie, bez zastępstwa)
   
   Anna Kowalska ma dziś PRIMARY i jest na urlopie. Marek Nowak ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę.
   
   Na urlopie: Anna Kowalska (do pon 4 sty), Marek Nowak (do czw 10 gru).
   Dyżury osób na urlopie w najbliższych 7 dniach: niedz 13 gru SECONDARY, Anna Kowalska; pon 14 gru PRIMARY, Anna Kowalska; czw 17 gru SECONDARY i 11–19, Anna Kowalska.
   
   Aktualny grafik: http://localhost:8080/
   
   [PASS] both named, one Zmień obsadę

== S8 day off: no digest, so no leave mail on Sat 12 Dec
   API leave Piotr Zieliński 2026-12-12 2026-12-14 -> 200 
   [PASS] no digest, no reminder
   []
   [PASS] former member with no duty is not named

== S9 repeated single-role marks: only 11-19 is held by a person on leave
   API override 2026-12-10 secondary Ola Wiśniewska -> 200 
   API override 2026-12-10 late_shift Marek Nowak -> 200 
   API leave Marek Nowak 2026-12-10 2026-12-10 -> 200 
   all mail: [('koord@example.com', 'Dyżury na dziś, 10 grudnia'), ('admin@example.com', 'Dyżury na dziś, 10 grudnia'), ('marek@example.com', 'Wpisano urlop w Twoim imieniu: 10-12-2026 – 10-12-2026'), ('koord@example.com', 'Urlop koliduje z dyżurem: Marek Nowak'), ('admin@example.com', 'Urlop koliduje z dyżurem: Marek Nowak'), ('marek@example.com', 'Zmiana przydziału: czw 10-12-2026 · 11–19'), ('ola@example.com', 'Zmiana przydziału: czw 10-12-2026 · 11–19'), ('ola@example.com', 'Zmiana przydziału: czw 10-12-2026 · SECONDARY i 11–19'), ('marek@example.com', 'Zmiana przydziału: czw 10-12-2026 · SECONDARY i 11–19')]
   Dziś (czw 10-12-2026) na dyżurze:
   - PRIMARY: Anna Kowalska
   - SECONDARY: Ola Wiśniewska
   - 11–19: Marek Nowak (na urlopie, bez zastępstwa)
   
   Marek Nowak ma dziś 11–19 i jest na urlopie. Zmień obsadę.
   
   Na urlopie: Marek Nowak (do czw 10 gru).
   
   Aktualny grafik: http://localhost:8080/
   
   [PASS] one role marked and named
Evidence: Scenario script (uses drive.py and run_at.py beside it)
exec(open(__file__.replace("scenarios.py", "drive.py")).read())
TH, FR = "2026-12-10T08:30", "2026-12-11T08:30"
M, A, O, Pi = "Marek Nowak", "Anna Kowalska", "Ola Wiśniewska", "Piotr Zieliński"
newdb("seeded", "tmpl")
subprocess.run([PY, E + "/run_at.py", TH, "seed"], env=env("seeded"), check=True)
sql("seeded", "insert into users select (jsonb_populate_record(u, jsonb_build_object('id', gen_random_uuid(), 'username','koord','display_name','Koordynator','role','coordinator','email','koord@example.com'))).* from users u where username='admin'")
print(sql("seeded", "select service_date, to_char(service_date,'Dy'), string_agg(role||'='||assignee_name, ', ' order by role) from assignments group by 1 order by 1"))
BASE = sys.argv[4]

print("\n== S1 nobody on leave: digest byte-identical to the base commit's")
newdb("s1a", "seeded"); newdb("s1b", "seeded")
for at, n in ((TH, "thu"), (FR, "fri")):
    newdb("s1a", "seeded"); newdb("s1b", "seeded")
    new, old = worker("s1a", at), worker("s1b", at, src=BASE)
    show("s1-no-leave-" + n, new)
    k = lambda ms: sorted((m["To"][0]["Address"], m["Subject"], m["Text"], m["HTML"]) for m in ms)
    check(n + " new == base, for admin and coordinator", len(new) == 2 and k(new) == k(old))
    check(n + " recipients", sorted(m["To"][0]["Address"] for m in new) == ["admin@example.com", "koord@example.com"])

print("\n== S2 spec example: Marek SECONDARY + 11-19 on Thu 10 Dec, PRIMARY Fri 11, leave to 11; note never shown")
newdb("s2", "seeded")
with Api("s2", "2026-12-10T07:00") as api:
    api.mark("s2", M, "leave", "2026-12-10", "2026-12-11", "operacja kolana TAJNE")
ms = worker("s2", TH); t = show("s2-spec-example", ms)
for s in ("- SECONDARY: Marek Nowak (na urlopie, bez zastępstwa)\n", "- 11–19: Marek Nowak (na urlopie, bez zastępstwa)\n",
          "Marek Nowak ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę.", "Na urlopie: Marek Nowak (do pt 11 gru).",
          "Dyżury osób na urlopie w najbliższych 7 dniach: pt 11 gru PRIMARY, Marek Nowak."):
    check("text has: " + s.strip(), s in t)
check("Anna not marked", "- PRIMARY: Anna Kowalska\n" in t)
check("no note/reason in either digest (text, HTML, subject)", len(digests(ms)) == 2 and not any("TAJNE" in m["Text"] + m["HTML"] + m["Subject"] for m in digests(ms)))
print("   mails with the note (all outside this change):", [(m["To"][0]["Address"], m["Subject"]) for m in ms if "TAJNE" in m["Text"]])
d = digests(ms)
check("digest only to admin+coordinator", sorted(m["To"][0]["Address"] for m in d) == ["admin@example.com", "koord@example.com"])
check("stored outbox has no note", "TAJNE" not in sql("s2", "select string_agg(o::text,' ') from notification_outbox o where dedup_key like 'digest:%'"))
again = worker("s2", "2026-12-10T08:40"); check("restarted worker sends no second digest/reminder", not again)

print("\n== S3 takeover: Ola takes Marek's SECONDARY before the digest; which moves the paired 11-19 too")
newdb("s3", "seeded")
with Api("s3", "2026-12-10T07:00") as api:
    api.mark("s3", M, "leave", "2026-12-10", "2026-12-11")
    api.override("s3", "2026-12-10", "secondary", O)
    api.override("s3", "2026-12-11", "primary", Pi)
t = show("s3-takeover", worker("s3", TH))
check("SECONDARY now Ola, unmarked", "- SECONDARY: Ola Wiśniewska\n" in t)
check("11–19 moved with it, no plea, no mark; Marek still 'Na urlopie'", "- 11–19: Ola Wiśniewska\n" in t and "Zmień obsadę" not in t and "bez zastępstwa" not in t and "Na urlopie: Marek Nowak (do pt 11 gru)." in t)
check("no week-ahead line", "najbliższych 7 dniach" not in t)

print("\n== S4 'nie mogę' alone, and leave that ended yesterday, change nothing")
newdb("s4", "seeded")
with Api("s4", "2026-12-08T07:00") as api:
    api.mark("s4", M, "unavailable", "2026-12-10", "2026-12-17", "prywatne")
    api.mark("s4", A, "leave", "2026-12-08", "2026-12-09")
t = show("s4-unavailable-only", worker("s4", TH))
check("identical to no-leave digest", t == open(E + "/s1-no-leave-thu.txt").read().split("\n\n", 1)[1])

print("\n== S5 Friday digest covers the weekend; adjacent entries join; week-ahead boundary day 7 in, day 8 out")
newdb("s5", "seeded")
with Api("s5", "2026-12-11T07:00") as api:
    api.mark("s5", Pi, "leave", "2026-12-12", "2026-12-14")  # weekend + Monday holder only
    api.mark("s5", A, "leave", "2026-12-18", "2026-12-18"); api.mark("s5", A, "leave", "2026-12-19", "2026-12-19")
    api.mark("s5", O, "leave", "2026-12-11", "2026-12-13"); api.mark("s5", O, "leave", "2026-12-14", "2026-12-15")
    r = sql("s5", "select m.display_name, starts_on, ends_on, kind from availability a join team_members m on m.id=member_id order by 1,2"); print(r)
    print(sql("s5", "select service_date, role, assignee_name from assignments where service_date between '2026-12-11' and '2026-12-19' order by 1,2"))
t = show("s5-friday-weekend", worker("s5", FR))
check("today plea: Ola only, SECONDARY i 11–19", "Ola Wiśniewska ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę." in t and t.count("ma dziś") == 1)
check("weekend holders marked on their own lines", all(x in t for x in ("- PRIMARY: Ola Wiśniewska (na urlopie, bez zastępstwa)", "- SECONDARY: Piotr Zieliński (na urlopie, bez zastępstwa)", "- PRIMARY: Piotr Zieliński (na urlopie, bez zastępstwa)", "- SECONDARY: Anna Kowalska\n")))
check("adjacent entries joined, Piotr not yet on leave", "Na urlopie: Ola Wiśniewska (do wt 15 gru)." in t)
check("week ahead: 12,13,15,18 in; 19 out", re.findall(r"(\d+) gru [PS1]", t.split("7 dniach:")[1]) == ["12", "12", "13", "15", "18"])

print("\n== S6 seven-day boundary")
newdb("s6", "seeded")
with Api("s6", "2026-12-10T07:00") as api:
    api.mark("s6", A, "leave", "2026-12-17", "2026-12-18"); api.mark("s6", M, "leave", "2026-12-17", "2026-12-18"); 
t = show("s6-boundary", worker("s6", TH))
check("day +7 (Thu 17) in, nothing for +8 (Fri 18), nobody 'Na urlopie' today", "czw 17 gru" in t and "18 gru" not in t and "Na urlopie:" not in t and "Zmień obsadę" not in t)

print("\n== S7 two people on leave today; former member still holding a duty")
newdb("s7", "seeded")
with Api("s7", "2026-12-10T07:00") as api:
    api.mark("s7", M, "leave", "2026-12-10", "2026-12-10"); api.mark("s7", A, "leave", "2026-12-10", "2027-01-04")
sql("s7", f"update team_members set active_until='2026-12-09' where display_name='{A}'")
sql("s7", f"insert into team_members(id,display_name,active_from,active_until,created_at) values (gen_random_uuid(),'Ewa Była','2025-01-01','2026-11-30',now())")
sql("s7", "insert into availability(id,member_id,kind,starts_on,ends_on,created_at) select gen_random_uuid(),id,'leave','2026-11-01','2026-12-31',now() from team_members where display_name='Ewa Była'")
t = show("s7-two-people", worker("s7", TH))
check("both named, one Zmień obsadę", "Anna Kowalska ma dziś PRIMARY i jest na urlopie. Marek Nowak ma dziś SECONDARY i 11–19 i jest na urlopie. Zmień obsadę." in t and t.count("Zmień obsadę") == 1)

print("\n== S8 day off: no digest, so no leave mail on Sat 12 Dec")
newdb("s8", "seeded")
with Api("s8", "2026-12-11T07:00") as api: api.mark("s8", Pi, "leave", "2026-12-12", "2026-12-14")
sql("s8", "delete from notification_outbox")
ms = worker("s8", "2026-12-12T08:30"); check("no digest, no reminder", not ms); print("  ", [m["Subject"] for m in ms])

newdb("s7b", "seeded")
check("former member with no duty is not named", "Ewa" not in t)

print("\n== S9 repeated single-role marks: only 11-19 is held by a person on leave")
newdb("s9", "seeded")
with Api("s9", "2026-12-10T07:00") as api:
    api.override("s9", "2026-12-10", "secondary", O); api.override("s9", "2026-12-10", "late_shift", M)
    api.mark("s9", M, "leave", "2026-12-10", "2026-12-10")
t = show("s9-late-only", worker("s9", TH))
check("one role marked and named", "- SECONDARY: Ola Wiśniewska\n" in t and "Marek Nowak ma dziś 11–19 i jest na urlopie. Zmień obsadę." in t)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ backend/src/oncall/domain/digest.py:103 - The new member read is heavy and runs on every worker poll, even after the digest has been sent. notification_cycle calls scan_digest every worker_poll_seconds (5 s by default, config.py:201). From hour 8 to midnight on a working day, send_daily_digest builds the full digest each time. Duplicates are dropped only later, by dedup_key in enqueue_duty_digest, and the 'no SMTP host' exit (triggers.py:937) also comes after the build. Before this change the only read was duties_in_force, which has a short cache on PostgreSQL. Now members_for_range (infrastructure/sqlalchemy/calendar.py:116) also runs. It has no date filter on availability, loads every kind of entry ever written with its notes, and joins two collections (availability x eligibility), so rows multiply. Example: 20 people x 200 entries x 3 eligibility periods = 12,000 joined ORM rows every 5 s for 16 hours, on the event loop the worker's other tasks share. It grows for ever, because availability entries are kept. Smallest fix: give DigestTeam a narrow read that returns only leave entries with ends_on >= working_day (later adjacent entries are still needed to join a run), without eligibility, notes or authors.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
A coordinator gets the example from the intent: Marek has SECONDARY and 11–19 on Thursday 10 December, PRIMARY on Friday, and leave until Friday. Role lines, action sentence, 'Na urlopie' and week ahe… ✅ pass live s2-spec-example.txt, s2-spec-example.png, s2-spec-example-narrow.png; transcript.txt section S2
Nobody on leave: the Thursday and Friday e-mails are identical (subject, text and HTML) to those from the base commit ✅ pass live transcript.txt section S1; s1-no-leave-thu.txt, s1-no-leave-thu.png and s1-no-leave-fri.txt
Only the coordinator and admin get the digest; a restarted worker sends no second digest and no extra reminder ✅ pass live transcript.txt sections S1 and S2
Trying to leak a private note: leave saved with a secret note never shows it in the digest e-mails or in the stored digest rows ✅ pass live transcript.txt section S2
Someone takes over the duty before the e-mail goes out: no mark and no action sentence for it, but the absent person is still listed under 'Na urlopie' ✅ pass live s3-takeover.txt; transcript.txt section S3
Only 11–19 is held by someone on leave: only that role is marked and named in the action sentence ✅ pass live s9-late-only.txt; transcript.txt section S9
'Nie mogę' entries and leave that ended yesterday change nothing in the e-mail ✅ pass live s4-unavailable-only.txt; transcript.txt section S4
The Friday e-mail covers the weekend: weekend holders on leave are marked, the action sentence covers only today, and back-to-back leave entries show one end date ✅ pass live s5-friday-weekend.txt, s5-friday-weekend.png; transcript.txt section S5
Seven-day limit: a duty on day 7 is listed, one on day 8 is not, and future leave adds no 'Na urlopie' or action sentence ✅ pass live s6-boundary.txt; transcript.txt section S6
Two people on leave: both are named with one 'Zmień obsadę'. A former member still holding a duty is included, and one with no duty is not named ✅ pass live s7-two-people.txt; transcript.txt section S7 (the 'former member with no duty' check is printed after S8)
Saturday: no digest and no leave reminder is sent ✅ pass live transcript.txt section S8
  • alembic upgrade head on an empty, throwaway PostgreSQL 18.7 container
  • .venv/bin/python drive script scenarios.py <pg> <smtp> <web> <base src>: leave and duty changes went in through the real HTTP API, and the real worker sent the e-mails to a local Mailpit server. The product's clock was set to 10, 11 and 12 December 2026 (and 8 December for entering some leave)
  • Ran the base commit 81a93d5 worker and the new worker on copies of the same database with no leave, then compared the e-mails
  • Looked at Chromium screenshots of the received HTML e-mails at 760 px and 500 px wide
  • .venv/bin/python -m pytest -q tests/test_digest.py tests/test_digest_leave_entries.py tests/test_email_templates.py tests/architecture/test_language.py (exit 0)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A duty whose holder has a leave entry on its day is one nobody took over.
The digest marks it on the role line ("na urlopie, bez zastępstwa"), asks
for the change in one sentence when it is one of today's duties, names who
is on leave today with the last day of the leave, and lists the duties of
people on leave in the seven days ahead. Without leave it reads as before.

The digest reads leave through the calendar's own leave runs, now a method
of the member, and the template takes the digest itself.
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@lowicz
lowicz merged commit 6ea9bf6 into main Dec 3, 2026
18 checks passed
@lowicz
lowicz deleted the fm/oncall-leave-u-step5 branch December 3, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant