# Task 3 handoff — Northline Workshops signup site repair

## Deliverables
- `output/site/` — repaired working copy (`index.html`, `style.css`, `app.js`, `server.py`). Run with `python3 server.py` from that directory, then open http://127.0.0.1:8765 (per `inputs/brief.md`, opening paragraph; `PORT` env var overrides). No dependencies, frameworks, external services or tracking added.
- `output/evidence/browser_submissions.jsonl` — the actual `submissions.jsonl` written by the browser tool's trusted server during the browser tests (exactly the 2 valid signups; no invalid records).
- `output/test_server.py`, `output/verify_copy.py`, `output/preserve_evidence.py` — stdlib-only scripts used for the checks below (re-runnable).

Raw inputs (`site/`, `inputs/`, `COMMON.md`, `PROMPT.md`) were not modified. `output/site/server.py` is byte-identical to `site/server.py` (SHA-256 `319965872ca2…523bab`, checked by `verify_copy.py`). All page text, the title, and the dark-blue (`#152a45`) / orange (`#e78136`) identity are preserved.

## Bugs found and fixes
1. **Wrong price formula** — original `site/app.js` `calculateTotal` returned `subtotal * discount * 1.12` (the discounted-away slice; 0 for 1–2 seats). Fixed to `subtotal * (1 - discount) * 1.12` with 10% off for 3+ seats and 12% tax after discount, per `inputs/brief.md` ("Calculator: CAD 240 per seat…"). Browser baseline of the original showed `CAD 80.64` for 3 seats; repaired shows `CAD 725.76`.
2. **Wrong endpoint** — original `site/app.js` POSTed to `/api/lead`; `site/server.py` `do_POST` only accepts `/api/leads` (404 otherwise). Fixed to `/api/leads`. Browser baseline: a valid signup on the original showed "Signup failed…"; repaired shows "Thanks! Your workshop request is saved."
3. **No seat validation** — blank/0/negative/fractional/9+ seats produced `CAD NaN` or wrong totals and were submitted. Added strict `parseSeats` (digits only, integer 1–8): invalid input shows `CAD —` in the total, and submit shows "Seats must be a whole number from 1 to 8." without sending a request. Also added client-side nonempty-name and email checks using the same email pattern as `site/server.py`, so invalid submissions show a visible error (`#status`, `role="status"` kept) and create no record.
4. **Mobile overflow** — `site/style.css` `.shell{width:1120px}` overflowed at 390 px (browser baseline: `overflow: true`). Fixed with `max-width:1120px; width:calc(100% - 32px)`, `min-width:0` grid children, and a ≤800 px media query switching to one column with smaller paddings/headings.
5. Minor HTML-only additions (content unchanged): `novalidate` on the form so the JS shows the custom errors above (native `required/min/max/step` attributes kept), `name`/`autocomplete`/`inputmode` attributes, `aria-describedby` linking seats to the total. `server.py` untouched.

## Checks actually performed

### Browser checks (browser tool; fresh page per check; trusted server implements the original POST /api/leads)
Repaired site, `overflow` flag reported by the tool:

| Width | Check | Result |
|---|---|---|
| 1280 | initial load, 1 seat | `CAD 268.80`, overflow **false** |
| 390 | initial load, 1 seat | `CAD 268.80`, overflow **false** |
| 1280 | seats=2 / 3 / 8 | `CAD 537.60` / `CAD 725.76` / `CAD 1935.36`, overflow false |
| 1280 | valid submit (Ada Test, ada@example.test, 3) | "Thanks! Your workshop request is saved.", total `CAD 725.76`, overflow false |
| 390 | valid submit (Mobi Test, mobi@example.test, 8) | "Thanks! Your workshop request is saved.", total `CAD 1935.36`, overflow false |
| 1280 | submit bad email `not-an-email` | "Please enter a valid email address.", no success, overflow false |
| 390 | submit seats=9 (valid name/email) | "Seats must be a whole number from 1 to 8.", total `CAD —`, overflow false |
| 1280 | submit seats=2.5 | same seats error, `CAD —`, overflow false |
| 390 | submit blank name | "Please enter your name.", overflow false |
| 1280 | submit seats=0 | seats error, `CAD —`, overflow false |
| 390 | calculator only: seats blank / −1 / 9 | `CAD —` each, overflow false |

All four brief examples match: 1=268.80, 2=537.60, 3=725.76, 8=1935.36 (`inputs/brief.md`, Calculator sentence). Independently recomputed with Python `Decimal` (`verify_copy.py`): all pass.

**Persistence evidence:** after the browser session, `output/site/submissions.jsonl` contained exactly the two valid signups and none of the five invalid attempts — preserved at `output/evidence/browser_submissions.jsonl`, then removed so the delivered site starts clean.

Original site baselines (browser tool, `site/`): 390 px load reported overflow **true**; 3 seats showed `CAD 80.64`; a valid desktop submit showed "Signup failed. Please check your details and try again."

### Direct server-logic checks (`output/test_server.py`, exit 0, all 14 cases pass)
The sandbox forbids socket binding (`PermissionError` on `bind`), so `Handler.do_POST` from the supplied `server.py` was invoked directly with simulated request bodies/headers (no sockets):
- 3 valid payloads (seats 1, 3, 8) → **201** `{"ok":true}`, each appended to `submissions.jsonl`; stored records equalled exactly the valid payloads.
- 10 invalid payloads (empty name, whitespace name, `not-an-email`, `a@b`, seats 0, −1, 9, 2.5, string `"3"`, missing seats) → **400** `{"error":"Check name, email and seats (1-8)."}`, **no records written**.
- Old endpoint `/api/lead` → **404** (confirms the original bug).
Test records were deleted afterwards; the printed results above are the evidence.

## Limitations (precise)
- Could not run `python3 server.py` as a live listening process: the execution sandbox denies socket binding (verified: `PermissionError: [Errno 1] Operation not permitted`). Live HTTP POST behavior was exercised only via the browser tool's trusted server (stated by the tool to implement the original `/api/leads`); the supplied handler code itself was tested via direct invocation, not over a socket. A human should do one 30-second live smoke test.
- Browser tool reports visible text, control values and an overflow boolean — not screenshots or pixel measurements. Widths checked: 390 and 1280 only (the tool's two options); intermediate widths not individually tested, though the layout is fluid up to 1120 px.
- No real touch device or screen-reader testing; `aria-live` status region retained and labels remain associated via `for`/`id`.
- Assumption: `novalidate` + JS validation was chosen so invalid submissions show the brief-required visible error text instead of native bubbles; constraint attributes are kept for semantics. The brief does not mandate native validation UI.
- Fake `@example.test` addresses used throughout, per the brief; no email is sent.

## Estimated human time to finish
~10–15 minutes (estimate, not measured): review the diff, run the live-server smoke test (`python3 server.py`, one valid + one invalid signup, check `submissions.jsonl`), and eyeball the page at a few intermediate widths.
