Phase 6b/7b: per-child decoded periods, separate brief blocks, idempotent calendar (AUD-119)

- Parse each child's own "Today" day widget for the timetable (FR-16); drop the
  school-wide week calendar's lesson grid and clean the leaked routine rows.
- Add the editable codes map (FR-17): subjects, rooms, teachers and period
  labels, seeded, an unknown code falls back to the raw code; `school codes` CLI.
- Brief: Finn's block first, then Harry's, four sections always present (FR-9);
  periods decoded into plain English; the undated tail is one counted line (FR-18).
- Calendar: write periods + work due + work overdue + major events, per child,
  on every pass. Identity is the stable per-item key, so a re-run never re-inserts
  (FR-8). morning-brief.sh now runs scan -> calendar push -> notify.
- Day-widget labels are 12-hour: 1-6 read as PM, fixing afternoon periods.

Proven live on .13: image 0.6.2-phase6b7b; both children's briefs decoded and
separate; 35 events in calendar.school; runs 2 and 3 of the scan added nothing.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-10-16 10:25:55 +11:00
parent 4950755b3d
commit 047af0f31d
40 changed files with 2049 additions and 160 deletions

View File

@@ -175,23 +175,20 @@ func TestParseCalendar(t *testing.T) {
if err != nil {
t.Fatalf("parseCalendar: %v", err)
}
if len(items) != 2 {
t.Fatalf("got %d items, want 2", len(items))
// The week calendar is school-wide, so its lesson grid is dropped: a
// child's own periods come from that child's day widget (FR-16). Only the
// real school event survives.
if len(items) != 1 {
t.Fatalf("got %d items, want 1 (the routine lesson is not a per-child period)", len(items))
}
if items[0].Type != TypeEvent {
t.Errorf("type = %q", items[0].Type)
}
if got := items[0].DueAt.Format("2006-01-02 15:04"); got != "2026-10-15 18:00" {
t.Errorf("event 1 time = %s", got)
t.Errorf("event time = %s", got)
}
if items[0].Title != "End of Year Concert - HALL - KSH" {
t.Errorf("event 1 title = %q", items[0].Title)
}
if items[1].Subject != "11HLEGB5" || items[1].Teacher != "LHT" {
t.Errorf("event 2 subject/teacher = %q/%q", items[1].Subject, items[1].Teacher)
}
if got := items[1].DueAt.Format("15:04"); got != "14:06" {
t.Errorf("event 2 time = %q", got)
t.Errorf("event title = %q", items[0].Title)
}
}
@@ -430,3 +427,87 @@ func TestParseReconcilesOverdueWithHome(t *testing.T) {
t.Fatal("Parse accepted a home page with no record of the child (FR-12)")
}
}
// dayWidgetFixture is the per-child "Today" widget Compass renders on a child's
// own profile page. The child is Finn (Year 7).
const dayWidgetFixture = `<html><body>
<div class="x-panel compass-day-calendar x-cal-panel" id="calendardaywidget-1055">
<div class="x-toolbar">Today</div>
<div class="calendardaywidget-1055-day-bd-evt-a x-cal-default calendar-event-93806 custom-event ext-cal-evt activity-type-1 ext-event-no-roll" style="left:0%;width:100%;top:95.8px;height:48.1px;">
<span class="ext-evt-bd" lang="en-GB">8:55: 1 - 7SCF - H14LAB - KNI</span>
</div>
<div class="calendardaywidget-1055-day-bd-evt-b x-cal-default calendar-event-93737 custom-event ext-cal-evt activity-type-1 ext-event-no-roll" style="left:50%;width:50%;top:145px;height:44px;">
<span class="ext-evt-bd" lang="en-GB">9:54: 2 - 7DESF - B1 - PSI</span>
</div>
<div class="calendardaywidget-1055-day-bd-evt-c x-cal-default calendar-event-93755 custom-event ext-cal-evt activity-type-1 ext-event-no-roll" style="left:0%;width:100%;top:321.6666666666667px;height:48px;">
<span class="ext-evt-bd" lang="en-GB">1:26: 4 - 7PEF - GYM4 - LTA</span>
</div>
</div>
</body></html>`
// TestParseDayWidgetIsPerChild proves FR-16: a child's periods come from that
// child's own day widget, and the school-wide week calendar's lesson grid is
// never stored against the child.
func TestParseDayWidgetIsPerChild(t *testing.T) {
loc := melbourne(t)
fetched := time.Date(2026, 10, 16, 7, 0, 0, 0, loc)
pages := []Page{
{Slug: PageChildProfile, URL: "https://nhs-vic.compass.education/Records/User.aspx?userId=4242", HTML: []byte(dayWidgetFixture), FetchedAt: fetched},
{Slug: PageCalendar, URL: "https://nhs-vic.compass.education/Organise/Calendar/", HTML: []byte(calendarFixture), FetchedAt: fetched},
}
items, err := Parse("Finn", pages, loc)
if err != nil {
t.Fatalf("Parse: %v", err)
}
leaked := 0
periods := 0
for _, it := range items {
if it.Subject == "11HLEGB5" {
leaked++
}
if it.SourcePage == PageChildProfile && it.Type == TypeEvent {
periods++
if it.DueAt == nil || it.DueAt.In(loc).Format("2006-01-02") != "2026-10-16" {
t.Errorf("period %q dated %v, want 2026-10-16", it.Title, it.DueAt)
}
if it.SourcePage != PageChildProfile {
t.Errorf("period %q source page = %q, want %q", it.Title, it.SourcePage, PageChildProfile)
}
}
}
if leaked != 0 {
t.Errorf("Finn's items carry %d Year 11 lesson(s) from the school-wide calendar", leaked)
}
if periods != 3 {
t.Errorf("Finn has %d periods, want 3", periods)
}
}
// TestDayWidgetParsesRoomAndTeacher proves the label is split into its parts so
// the brief can decode them.
func TestDayWidgetParsesRoomAndTeacher(t *testing.T) {
loc := melbourne(t)
fetched := time.Date(2026, 10, 16, 7, 0, 0, 0, loc)
items, found, err := parseDayWidget("Finn", Page{Slug: PageChildProfile, HTML: []byte(dayWidgetFixture), FetchedAt: fetched}, loc, fetched)
if err != nil || !found {
t.Fatalf("parseDayWidget: found=%v err=%v", found, err)
}
if len(items) != 3 {
t.Fatalf("got %d periods, want 3", len(items))
}
if items[0].Subject != "7SCF" {
t.Errorf("subject = %q", items[0].Subject)
}
if items[0].Title != "1 - 7SCF - H14LAB - KNI" {
t.Errorf("title = %q", items[0].Title)
}
if got := items[0].DueAt.In(loc).Format("15:04"); got != "08:55" {
t.Errorf("start = %q, want 08:55", got)
}
// The printed clock is 12-hour: the 1:26 period is 1:26 PM (the grid
// offset is the authority).
if got := items[2].DueAt.In(loc).Format("15:04"); got != "13:26" {
t.Errorf("afternoon start = %q, want 13:26", got)
}
}