# Task 3 handoff — Northline Workshops signup site repair (rev 2, post-review)

## 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. Ships without a `submissions.jsonl` (clean start).
- `output/evidence/browser_submissions.jsonl` — actual records written by the browser tool's trusted server during browser tests: exactly the 3 valid signups (Ada 3 seats, Mobi 8 seats, Edge Case 8 seats); none of the invalid attempts created records.
- `output/original_submission/` — byte-for-byte snapshot of the first submission (site, handoff, scripts, evidence) preserved before review edits.
- `output/CHANGELOG.md` — review change log.
- Helper scripts (stdlib only, re-runnable): `test_server.py`, `verify_copy.py`, `preserve_evidence.py`, plus review helpers `snapshot_v1.py`, `review_merge_evidence.py`, `review_hash_compare.py`.

Raw inputs (`site/`, `inputs/`, `COMMON.md`, `PROMPT.md`) were not modified. `output/site/server.py` is byte-identical to `site/server.py` (SHA-256 `319965872ca22463e108abc187c320ae660c48814e9799af7b6df6ea31523bab`, checked by `verify_copy.py`). All page text, the title, and the dark-blue (`#152a45`) / orange (`#e78136`) identity are preserved. Review confirmed all four site files are byte-identical to the first submission (`review_hash_compare.py`).

## 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. Leading zeros ("08") are accepted as the integer 8, which the server also accepts and stores as `seats: 8` (verified in browser + stored record). Also added client-side nonempty-name (trimmed, so whitespace-only is rejected) 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 as 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 |

Review-pass additions (rev 2):

| Width | Check | Result |
|---|---|---|
| 390 | submit whitespace-only name "   " | "Please enter your name.", overflow false |
| 1280 | seats=4 (extra example beyond brief) | `CAD 967.68` (= 960 × 0.9 × 1.12), overflow false |
| 1280 | valid submit seats="08" (Edge Case) | success message, `CAD 1935.36`; trusted server stored `{"name":"Edge Case","email":"edge@example.test","seats":8}` |
| 390 | post-cleanup smoke load, seats=3 | `CAD 725.76`, 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, re-run during review.

**Persistence evidence:** `output/evidence/browser_submissions.jsonl` holds the 3 valid signups above and nothing else — all 8 invalid browser attempts (bad email, seats 9/2.5/0, blank name, whitespace name) created no records.

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; re-run twice during review)
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).
The script now backs up and restores any pre-existing `submissions.jsonl`; the restore path was explicitly tested during review ("pre-existing submissions.jsonl restored unchanged"). Test records are removed; the printed results are the evidence.

## Review outcome (rev 2)
- **Site code: no corrections needed.** All four files hash-identical to rev 1; calculations re-verified (Decimal + browser, including extra 4-seat case); all brief requirements re-checked against `inputs/brief.md`; endpoint, validation, mobile layout, identity preservation all supported by the evidence above.
- **Corrected: `test_server.py` data-safety defect.** The rev-1 script deleted any existing `submissions.jsonl` at start; during review this destroyed the Edge Case browser record before it could be preserved (it survived only because the rev-1 snapshot captured it first). Fixed to back up/restore pre-existing records; restore path tested.
- **Corrected: `preserve_evidence.py` robustness.** Rev-1 version crashed if no source file existed and overwrote the evidence file; now idempotent, appends with dedupe.
- Evidence file updated from 2 to 3 records (Edge Case added from the snapshot copy); delivered site re-cleaned.

## 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.
- `output/original_submission/site/` intentionally contains the `submissions.jsonl` that existed at snapshot time (Edge Case record) — it is an archived state, not the deliverable.

## 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.
