# Handoff — Northline workshop signup site repair (Task 3, revised)

Requirements source: `inputs/brief.md` ("Workshop site acceptance brief"). I left the raw `site/` untouched. The first submission is kept unchanged in `output/original_submission/`.

## Deliverables
- `output/site/index.html`, `style.css`, `app.js`: the repaired site (revised).
- `output/site/server.py`: an unchanged copy of `site/server.py`. A Python comparison confirmed it is byte-for-byte identical. To run it: `cd output/site && python3 server.py`, then open http://127.0.0.1:8765. The `PORT` environment variable overrides the port.
- `output/test-evidence-submissions-v2.jsonl`: the records the trusted server stored during the browser re-test of the final code.
- `output/test-evidence-submissions.jsonl`: the records from the first submission's browser tests (Ada/3, Ben/8, Dee/1).
- `output/original_submission/`: the first submission (site, handoff and evidence), unchanged.
- `output/handoff.md`: this file. The change log is at the end.

## Defects found and fixes
| # | Defect in original `site/` | Evidence (browser, original site) | Fix |
|---|---|---|---|
| 1 | `app.js` posted to `/api/lead`, but the server only accepts `/api/leads` (`server.py` `do_POST`) | A valid signup (Ada Test / ada@example.test / 3 seats, 390 px) showed "Signup failed. Please check your details and try again." | Fetch URL changed to `/api/leads` |
| 2 | `calculateTotal` returned `subtotal * discount * 1.12` | 3 seats displayed **CAD 80.64** (expected 725.76) | Now `subtotal * (1 - discount) * 1.12`, rounded to cents, shown with `toFixed(2)` |
| 3 | The seat count was never validated in JS (`Number('')` gives 0, and fractional or out-of-range values were priced) | — | `parseSeats()` accepts only the digit strings 1–8. Otherwise the total shows "—" and a visible error appears on input and on submit |
| 4 | The browser's own validation could block a submit with no visible text message. Whitespace-only names passed `required` | — | Added `novalidate` to the form. JS validation matches the server rules (trimmed name not empty; email matches the same regex as `server.py`; integer seats 1–8) and puts error text in `#status` |
| 5 | Error responses from the server were not shown | — | The server's `error` JSON message is shown if the server returns 400 |
| 6 | `.shell{width:1120px}` and a fixed 2-column grid caused horizontal overflow | The browser reported `overflow: true` at 390 px | Shell is now `width:min(1120px, calc(100% - 32px))`. Grid columns use `minmax(0,…)`. Below 760 px there is one column, less padding and a 30 px h1 |
| 7 | Usability touches | — | Bold labels, controls at least 48 px tall, orange focus outline, button disabled while sending, `autocomplete` and `inputmode` attributes, and invalid fields marked with `aria-invalid="true"` plus a red border |

All titles, copy, colours (#152a45 dark blue, #e78136 orange, #edf1f5 background) and fonts are unchanged. `index.html` is identical to the first submission (Python comparison). I added no framework, dependencies, external requests or tracking.

## Checks performed on the FINAL code (after the revision edit)
**Browser tool, `output/site/`, fresh browser for each run. Every run reported `overflow: false`.**

Calculator examples (from the brief):
| Seats | Expected | Displayed | Width |
|---|---|---|---|
| 1 | 268.80 | CAD 268.80 | 1280 (initial load) |
| 2 | 537.60 | CAD 537.60 | 390 |
| 3 | 725.76 | CAD 725.76 | 1280 |
| 8 | 1935.36 | CAD 1935.36 | 390 |

Arithmetic: 1 seat = 240 × 1.12 = 268.80; 2 = 480 × 1.12 = 537.60; 3 = 720 × 0.90 × 1.12 = 725.76; 8 = 1920 × 0.90 × 1.12 = 1935.36. A Python reference using the same formula printed the same four values.

Invalid submissions (each showed a visible error):
- 390 px: name "   ", email "not-an-email", seats blank → "Please enter your name. Please enter a valid email address. Seats must be a whole number from 1 to 8." Total showed "—".
- 390 px: seats 0 → seats error, total "—".
- 1280 px: seats -2 → seats error, total "—".
- 1280 px: seats 2.5 → seats error, total "—".
- 390 px: seats 9 → seats error, total "—".
- 1280 px: email "eve@example" (no TLD) → "Please enter a valid email address."

Valid submissions:
- 390 px: Fay Test / fay@example.test / 3 → "Thanks, Fay Test! Your workshop request for 3 seats is saved."
- 1280 px: Gus Test / gus@example.test / 8 → "Thanks, Gus Test! Your workshop request for 8 seats is saved."

Stored records: after these 8 runs (6 invalid, 2 valid), `submissions.jsonl` held exactly 2 lines (Fay/3, Gus/8). It is saved as `output/test-evidence-submissions-v2.jsonl`.

**Direct server-handler test (Python, no network).** `server.py` was copied to a temporary folder, and its `Handler` was given fake connection objects in place of a real port, because port binding is not permitted in this sandbox.
- `/api/leads` with a valid payload (1 seat or 8 seats) → `201 {"ok":true}`.
- `/api/lead` (the old URL) → `404`.
- Name "   ", email "bad", email "x@example", seats 0, -2, 9, 2.5, "2" (string) or null → `400 {"error":"Check name, email and seats (1-8)."}`.
- The temporary `submissions.jsonl` held only the 2 valid records. The temporary folder was then deleted.

This confirms the client's rules match the server's, and that the server rejects bad data even if the page's checks are bypassed.

## Limitations / assumptions
- The browser tool returns text, not screenshots. Layout checks cover horizontal overflow and visible text only, not visual appearance or contrast. I did not test real devices, other browsers or keyboard-only use.
- I did not inspect the `aria-invalid` attribute directly. The browser tool reports only values and validity, and the fix was made by reviewing the code.
- The server test drove `Handler` directly rather than over a real socket, so `ThreadingHTTPServer` start-up and the `PORT` override were not exercised. The trusted browser server did serve and store records successfully.
- Invalid input is blocked in the browser before any request is sent, so the client's display of server 400 messages has not been seen in a browser.
- Assumption: after a successful signup the form resets, so the total goes back to the 1-seat price (CAD 268.80) while the confirmation stays visible.
- Email checking deliberately matches the server's regex, which only checks that an address looks plausible.

## Estimated human time to finish
About 15–25 minutes (an estimate, not measured): look over the layout in real browsers and phones, run `python3 server.py` with a curl test, and decide whether the form should reset after success.

## Change log (revision vs `output/original_submission/`)
1. **Accessibility bug fixed (`app.js`).** v1 used `toggleAttribute('aria-invalid', …)`, which sets `aria-invalid=""`. Under the ARIA spec an empty value counts as `false`, so screen readers would not announce invalid fields. A new `markInvalid()` sets `aria-invalid="true"` or removes it, and submit-time validation now also marks the seats field.
2. **CSS selector (`style.css`).** `input[aria-invalid]` changed to `input[aria-invalid="true"]` to match.
3. **Re-verification gap closed.** v1 had not re-run the full invalid set after its last code edit. The full invalid set, the calculator examples and the valid submissions have now all been re-run on the final code (see above).
4. **New server-level evidence.** v1 said server behaviour was untested because port binding failed. A direct, socket-free `Handler` test now covers 201, 404 and the 400 cases. The v1 statement that there were no server-level results is replaced by this evidence.
5. **Evidence files.** The new records file is `test-evidence-submissions-v2.jsonl`. The v1 evidence is kept.

Checks that found no correction needed: the calculator results match all four brief examples; `server.py` is byte-identical to the input; the fetch path matches `server.py`; page text and colours are unchanged; no external resources were added.
