wip: re-review fixes
2 files changed,
+87
−36
internal/calendar/keymail_signin_test.go+38 −0internal/calendartest/rhythm_browser_test.go+49 −36
CI failed — run details
CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/calendartest/ ./internal/calendar/
=== fmt ===
=== spacing ===
go tool fiesta spacing -skip tokens.css internal/calendar/static
=== test ===
go test ./...
ok amadan.net/oficina/calendar/cmd/calendar (cached)
? amadan.net/oficina/calendar/cmd/calendar-contract [no test files]
ok amadan.net/oficina/calendar/internal/calendar 28.527s
? amadan.net/oficina/calendar/internal/calendar/icons [no test files]
? amadan.net/oficina/calendar/internal/calendar/keymailtest [no test files]
? amadan.net/oficina/calendar/internal/calendar/seal [no test files]
? amadan.net/oficina/calendar/internal/calendar/teamstate [no test files]
ok amadan.net/oficina/calendar/internal/calendartest 3.883s
--- FAIL: TestNoFileExceedsTheLineCap (0.01s)
guards_test.go:92: internal/calendar/keymail_signin_test.go is 338 lines, cap is 300 — split it
FAIL
FAIL amadan.net/oficina/calendar/internal/guardstest 0.098s
? amadan.net/oficina/calendar/scripts/writeestilo [no test files]
FAIL
make: *** [Makefile:87: test] Error 1
amadan: step test failed: exit status 2
amadan: job failed at step test — its output is above, not at the tail of this log
diff --git a/internal/calendar/keymail_signin_test.go b/internal/calendar/keymail_signin_test.go| index 0ba594a..112effe 100644 |
| --- a/internal/calendar/keymail_signin_test.go |
| +++ b/internal/calendar/keymail_signin_test.go |
| @@ -13,6 +13,7 @@ import ( |
| "net/http/httptest" |
| "net/url" |
| "os" |
| + "os/exec" |
| "path/filepath" |
| "regexp" |
| "strings" |
| @@ -29,6 +30,10 @@ import ( |
| // query is answered NXDOMAIN and only the Keymail fixtures a test |
| // registers answer HTTPS (keymailtest). |
| func TestMain(m *testing.M) { |
| + if os.Getenv(asDeployedEnv) == "1" { |
| + // TestAuthIsBuiltAsDeployed's child: no fixtures, no list. |
| + os.Exit(m.Run()) |
| + } |
| SetKeymailServersForTest([]string{keymailHost}) |
| restore, err := keymailtest.Install() |
| if err != nil { |
| @@ -297,3 +302,36 @@ func TestKeymailRefusalIsTheDoor(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +const asDeployedEnv = "CALENDAR_TEST_AUTH_AS_DEPLOYED" |
| + |
| +// TestAuthIsBuiltAsDeployed: every other test here lists its Keymail |
| +// fixture's host (SetKeymailServersForTest), so auth takes its |
| +// listed-servers path. A deployment lists none, and from rastrillo |
| +// v0.45.0 that path builds a public-address-only client from |
| +// http.DefaultTransport. This builds the app that way, in a child |
| +// process with neither the list nor keymailtest's transport, and opens |
| +// the door. |
| +func TestAuthIsBuiltAsDeployed(t *testing.T) { |
| + if os.Getenv(asDeployedEnv) != "1" { |
| + cmd := exec.Command(os.Args[0], "-test.run=^TestAuthIsBuiltAsDeployed$", "-test.count=1") |
| + cmd.Env = append(os.Environ(), asDeployedEnv+"=1") |
| + if out, err := cmd.CombinedOutput(); err != nil { |
| + t.Fatalf("built as deployed: %v\n%s", err, out) |
| + } |
| + return |
| + } |
| + if keymailTestServers != nil { |
| + t.Fatal("the child lists Keymail servers; it is meant to be built as deployed") |
| + } |
| + a, err := New(Config{DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: "https://calendar.example.test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil))}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { a.Close() }) |
| + rec := httptest.NewRecorder() |
| + a.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "https://calendar.example.test/signin", nil)) |
| + if rec.Code != http.StatusOK { |
| + t.Fatalf("GET /signin: %d", rec.Code) |
| + } |
| +} |
diff --git a/internal/calendartest/rhythm_browser_test.go b/internal/calendartest/rhythm_browser_test.go| index 926148b..ee90283 100644 |
| --- a/internal/calendartest/rhythm_browser_test.go |
| +++ b/internal/calendartest/rhythm_browser_test.go |
| @@ -11,6 +11,7 @@ import ( |
| "os" |
| "path/filepath" |
| "regexp" |
| + "strings" |
| "testing" |
| "time" |
| @@ -94,29 +95,36 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| // Each screen is read at a desktop width and again at a phone's. |
| // With a path, it is loaded first, once, and must still be at that |
| // path when read: a lost session lands on the sign-in door, whose |
| - // rhythm is not this page's. Without one, the page the last step |
| - // landed on is read. ready is a selector only that screen draws, |
| - // and main must hold at least blocks elements, so a page that drew |
| - // nothing cannot pass by having nothing to measure. |
| + // rhythm is not this page's. A path written "~prefix" is the page |
| + // the last step landed on, which must be under prefix. ready is a |
| + // selector only that screen draws, its main h1 must read heading |
| + // (an error page at the same address has its own), and main must |
| + // hold at least blocks elements, so a page that drew nothing cannot |
| + // pass by having nothing to measure. |
| grids := []string{"[cal-month]", "[cal-grid]", "[cal-week-scroll]"} |
| - audit := func(name, path, ready string, blocks int) { |
| + audit := func(name, path, ready string, blocks int, heading string) { |
| t.Helper() |
| + landed := strings.HasPrefix(path, "~") |
| for i, width := range []int64{1280, 390} { |
| var found []rhythm.Finding |
| - var at string |
| + var at, h1 string |
| var drawn int |
| actions := []chromedp.Action[chromedp.Void]{deviceMetrics(width, 900)} |
| - if i == 0 && path != "" { |
| + if i == 0 && !landed { |
| actions = append(actions, chromedp.Navigate(rig.Origin+path)) |
| } |
| actions = append(actions, |
| chromedp.WaitVisible(chromedp.CSS(ready)), |
| evalInto(&at, `location.pathname + location.search`), |
| + evalInto(&h1, `(document.querySelector('main h1') || {}).textContent || ''`), |
| evalInto(&drawn, `document.querySelectorAll('main *').length`), |
| evalInto(&found, rhythm.Expression("main", rhythm.Options{Skip: grids}))) |
| run(name, actions...) |
| - if path != "" && at != path { |
| - t.Fatalf("%s: the browser is at %s, not %s", name, at, path) |
| + if landed && !strings.HasPrefix(at, path[1:]) || !landed && at != path { |
| + t.Fatalf("%s: the browser is at %s, not %s", name, at, strings.TrimPrefix(path, "~")) |
| + } |
| + if strings.TrimSpace(h1) != heading { |
| + t.Fatalf("%s: the page's heading is %q, not %q", name, h1, heading) |
| } |
| if drawn < blocks { |
| t.Fatalf("%s at %dpx: main holds %d elements, want at least %d", name, width, drawn, blocks) |
| @@ -127,7 +135,7 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| } |
| } |
| - audit("the sign-in door", "/signin", `input[name="address"]`, 3) |
| + audit("the sign-in door", "/signin", `input[name="address"]`, 3, "Sign in to Calendar") |
| run("sign in", setCookie(rig.Origin, session)) |
| @@ -156,26 +164,31 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| } |
| series := fmt.Sprintf("/events/%d", weekly.ID) |
| - for _, view := range []string{"/day/2026-09-02", "/week/2026-09-02", "/month/2026-09", "/agenda?from=2026-09-02"} { |
| - audit(view, view, `main [cal-view-tabs], main nav, main h1`, 6) |
| + for _, view := range []struct{ path, ready, heading string }{ |
| + {"/day/2026-09-02", `main [cal-grid]`, "Wednesday 2 September"}, |
| + {"/week/2026-09-02", `main [cal-week-scroll]`, "Week of 31 August 2026"}, |
| + {"/month/2026-09", `main [cal-month]`, "September 2026"}, |
| + {"/agenda?from=2026-09-02", `main[cal-view] [cal-day-chips]`, "Agenda"}, |
| + } { |
| + audit(view.path, view.path, view.ready, 40, view.heading) |
| } |
| - audit("a new event", "/events/new", `input[name="title"]`, 8) |
| - audit("editing an event", event+"/edit", `input[name="title"]`, 8) |
| - audit("an event", event, `form[action$="/reminders"]`, 8) |
| - audit("deleting an event", event+"/delete", `main form[action$="/delete"]`, 4) |
| - audit("a repeating event", series, `form[action$="/reminders"]`, 8) |
| - audit("deleting a repeating event", series+"/delete", `main form[action$="/delete"]`, 4) |
| - audit("settings", "/settings", `main form`, 8) |
| - audit("reminders", "/reminders", `main h1`, 3) |
| - audit("calendars", "/calendars", `main [cal-dot]`, 4) |
| - audit("sharing a calendar", "/calendars/1/share", `form[cal-feed-new]`, 4) |
| + audit("a new event", "/events/new", `input[name="title"]`, 40, "New event") |
| + audit("editing an event", event+"/edit", `input[name="title"]`, 40, "Edit event") |
| + audit("an event", event, `form[action$="/reminders"]`, 20, "Standup") |
| + audit("deleting an event", event+"/delete", `main form[action$="/delete"]`, 4, "Delete “Standup”?") |
| + audit("a repeating event", series, `form[action$="/reminders"]`, 20, "Weekly review") |
| + audit("deleting a repeating event", series+"/delete", `main form[action$="/delete"] fieldset`, 15, "Delete “Weekly review”?") |
| + audit("settings", "/settings", `main form`, 100, "Settings") |
| + audit("reminders", "/reminders", `main [rst-empty] a[href="/settings"], main [cal-notices]`, 6, "Reminders") |
| + audit("calendars", "/calendars", `main [cal-dot]`, 12, "Calendars") |
| + audit("sharing a calendar", "/calendars/1/share", `form[cal-feed-new]`, 12, "Team") |
| run("make a subscription link", |
| chromedp.Navigate(rig.Origin+"/calendars/1/share"), |
| chromedp.WaitVisible(chromedp.CSS(`form[cal-feed-new] button`)), |
| chromedp.Click(chromedp.CSS(`form[cal-feed-new] button`)), |
| chromedp.WaitVisible(chromedp.CSS(`main [rst-list], main ul`))) |
| - audit("sharing a calendar, with a link", "", `form[cal-feed-new]`, 6) |
| - audit("import", "/import", `main form input[type=file]`, 6) |
| + audit("sharing a calendar, with a link", "~/calendars/1/share?token=", `form[cal-feed-new]`, 20, "Team") |
| + audit("import", "/import", `main form input[type=file]`, 20, "Import a calendar") |
| ics := filepath.Join(t.TempDir(), "one.ics") |
| if err := os.WriteFile(ics, []byte("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//test//EN\r\nBEGIN:VEVENT\r\nUID:one@test\r\nDTSTAMP:20260901T000000Z\r\nDTSTART:20260904T100000Z\r\nDTEND:20260904T110000Z\r\nSUMMARY:Imported\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"), 0o600); err != nil { |
| t.Fatal(err) |
| @@ -186,27 +199,27 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| chromedp.SetUploadFiles(`input[type=file]`, []string{ics}), |
| chromedp.Click(chromedp.CSS(`form[action="/import"] button[type=submit]`)), |
| chromedp.WaitNotPresent(chromedp.CSS(`form[action="/import"] input[type=file]`))) |
| - audit("import done", "", `main h1`, 3) |
| - audit("booking pages", "/settings/booking", `main [cal-book-page]`, 6) |
| - audit("a new booking page", "/settings/booking/new", `main form`, 8) |
| - audit("a page that is not there", "/events/999999", `main`, 1) |
| + audit("import done", "~/import", `main [rst-page-header]`, 10, "Imported") |
| + audit("booking pages", "/settings/booking", `main [cal-book-page]`, 20, "Booking pages") |
| + audit("a new booking page", "/settings/booking/new", `main form`, 30, "New booking page") |
| + audit("a page that is not there", "/events/999999", `main h1`, 4, "We can’t find that page") |
| // The stranger's side: the page, a day's slots, a slot's details, |
| // the hold, then the mailed link: confirm, manage, reschedule, |
| // cancel. |
| public := "/book/paul/" + page.Code + "?zone=UTC" |
| - audit("the booking page", public, `[cal-book-days] a`, 6) |
| + audit("the booking page", public, `[cal-book-days] a`, 100, "Quick chat") |
| var day string |
| run("a booking day", evalInto(&day, `document.querySelector('[cal-book-days] a').getAttribute('href')`)) |
| - audit("a booking day", day, `[cal-book-slot]`, 6) |
| + audit("a booking day", day, `[cal-book-slot]`, 100, "Quick chat") |
| run("a slot", chromedp.Click(chromedp.CSS(`[cal-book-slot]`)), chromedp.WaitVisible(chromedp.CSS(`[cal-book-details] input[name="name"]`))) |
| - audit("a slot's details", "", `[cal-book-details]`, 8) |
| + audit("a slot's details", "~/book/paul/"+page.Code, `[cal-book-details] input[name="name"]`, 60, "Quick chat") |
| run("hold it", |
| chromedp.SendKeys(chromedp.CSS(`#name`), "Doc"), |
| chromedp.SendKeys(chromedp.CSS(`#address`), "doc@example.com"), |
| chromedp.Click(chromedp.CSS(`[cal-book-details] button[type=submit]`)), |
| chromedp.WaitNotPresent(chromedp.CSS(`[cal-book-details]`))) |
| - audit("the hold, sent", "", `main h1`, 3) |
| + audit("the hold, sent", "~/book/paul/"+page.Code, `main [rst-page-header-sub]`, 8, "Check your mail") |
| mail, err := app.LastMailForTest() |
| if err != nil { |
| t.Fatal(err) |
| @@ -215,16 +228,16 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| if manage == "" { |
| t.Fatalf("no manage link in the hold mail") |
| } |
| - audit("the hold, to confirm", manage, `form[action$="/confirm"]`, 4) |
| + audit("the hold, to confirm", manage, `form[action$="/confirm"]`, 10, "Confirm your booking") |
| run("confirm it", |
| chromedp.Click(chromedp.CSS(`form[action$="/confirm"] button`)), |
| chromedp.WaitVisible(chromedp.CSS(`[cal-book-manage-actions]`))) |
| - audit("a booking", "", `[cal-book-manage-actions]`, 6) |
| - audit("rescheduling a booking", manage+"/reschedule", `main h1`, 4) |
| + audit("a booking", "~"+manage+"/confirm", `[cal-book-manage-actions]`, 12, "Quick chat") |
| + audit("rescheduling a booking", manage+"/reschedule", `[cal-book-days] a`, 100, "Quick chat") |
| run("cancel it", |
| chromedp.Navigate(rig.Origin+manage), |
| chromedp.WaitVisible(chromedp.CSS(`form[action$="/cancel"] button`)), |
| chromedp.Click(chromedp.CSS(`form[action$="/cancel"] button`)), |
| chromedp.WaitNotPresent(chromedp.CSS(`form[action$="/cancel"]`))) |
| - audit("a cancelled booking", "", `main h1`, 3) |
| + audit("a cancelled booking", "~"+manage+"/cancel", `main p`, 6, "Quick chat") |
| } |