diff --git a/_bmad-output/implementation-artifacts/1-3-wifi-hotspot-and-captive-portal-form.md b/_bmad-output/implementation-artifacts/1-3-wifi-hotspot-and-captive-portal-form.md index 0972e80..142fe13 100644 --- a/_bmad-output/implementation-artifacts/1-3-wifi-hotspot-and-captive-portal-form.md +++ b/_bmad-output/implementation-artifacts/1-3-wifi-hotspot-and-captive-portal-form.md @@ -1,6 +1,6 @@ # Story 1.3: WiFi Hotspot & Captive Portal Form -Status: ready-for-dev +Status: review ## Story @@ -20,44 +20,44 @@ So that I can configure the device without a keyboard or monitor. ## Tasks / Subtasks -- [ ] Task 1: Implement `wifi.start_ap()` in `src/planemapper/provisioning/wifi.py` (AC: #1, #4) - - [ ] 1.1 Import `ProvisioningError` from `planemapper.provisioning` - - [ ] 1.2 Write the hostapd config to `/etc/hostapd/hostapd.conf` before calling the subprocess - - [ ] 1.3 Call `subprocess.run(["hostapd", "/etc/hostapd/hostapd.conf", ...], check=False)` and inspect `result.returncode` explicitly - - [ ] 1.4 Call `subprocess.run(["dnsmasq", "--no-daemon", ...], check=False)` and inspect `result.returncode` explicitly - - [ ] 1.5 Log `log.error(...)` before raising `ProvisioningError` on any non-zero return code - - [ ] 1.6 Annotate the function signature: `def start_ap() -> None` +- [x] Task 1: Implement `wifi.start_ap()` in `src/planemapper/provisioning/wifi.py` (AC: #1, #4) + - [x] 1.1 Import `ProvisioningError` from `planemapper.provisioning` + - [x] 1.2 Write the hostapd config to `/etc/hostapd/hostapd.conf` before calling the subprocess + - [x] 1.3 Call `subprocess.run(["hostapd", "/etc/hostapd/hostapd.conf", ...], check=False)` and inspect `result.returncode` explicitly + - [x] 1.4 Call `subprocess.run(["dnsmasq", "--no-daemon", ...], check=False)` and inspect `result.returncode` explicitly + - [x] 1.5 Log `log.error(...)` before raising `ProvisioningError` on any non-zero return code + - [x] 1.6 Annotate the function signature: `def start_ap() -> None` -- [ ] Task 2: Implement `wifi.stop_ap()` in `src/planemapper/provisioning/wifi.py` (AC: #1) - - [ ] 2.1 Stop `hostapd` and `dnsmasq` processes (e.g. `subprocess.run(["pkill", "-f", "hostapd"], check=False)`) - - [ ] 2.2 Log at INFO level when AP is stopped - - [ ] 2.3 Annotate: `def stop_ap() -> None` +- [x] Task 2: Implement `wifi.stop_ap()` in `src/planemapper/provisioning/wifi.py` (AC: #1) + - [x] 2.1 Stop `hostapd` and `dnsmasq` processes (e.g. `subprocess.run(["pkill", "-f", "hostapd"], check=False)`) + - [x] 2.2 Log at INFO level when AP is stopped + - [x] 2.3 Annotate: `def stop_ap() -> None` -- [ ] Task 3: Implement the Flask app in `src/planemapper/provisioning/portal.py` (AC: #2, #3) - - [ ] 3.1 Create a Flask app instance; import `ProvisioningError` from `planemapper.provisioning` - - [ ] 3.2 Implement `GET /` — serve the setup form HTML inline (no templates dir needed for MVP): location field, coverage radius field with default `100`, WiFi SSID field, WiFi password field, a "Find location" button (separate action), and a "Set up device" submit button - - [ ] 3.3 Implement `GET /generate_204` → redirect to `/` (Android captive portal probe) - - [ ] 3.4 Implement `GET /hotspot-detect.html` → redirect to `/` (iOS captive portal probe) - - [ ] 3.5 Implement `GET /ncsi.txt` → redirect to `/` (Windows captive portal probe) - - [ ] 3.6 Add `@app.errorhandler(404)` wildcard redirect → `/` so any unrecognised URL served by Flask goes to the portal form - - [ ] 3.7 Annotate all route functions with return type `str | Response` +- [x] Task 3: Implement the Flask app in `src/planemapper/provisioning/portal.py` (AC: #2, #3) + - [x] 3.1 Create a Flask app instance; import `ProvisioningError` from `planemapper.provisioning` + - [x] 3.2 Implement `GET /` — serve the setup form HTML inline (no templates dir needed for MVP): location field, coverage radius field with default `100`, WiFi SSID field, WiFi password field, a "Find location" button (separate action), and a "Set up device" submit button + - [x] 3.3 Implement `GET /generate_204` → redirect to `/` (Android captive portal probe) + - [x] 3.4 Implement `GET /hotspot-detect.html` → redirect to `/` (iOS captive portal probe) + - [x] 3.5 Implement `GET /ncsi.txt` → redirect to `/` (Windows captive portal probe) + - [x] 3.6 Add `@app.errorhandler(404)` wildcard redirect → `/` so any unrecognised URL served by Flask goes to the portal form + - [x] 3.7 Annotate all route functions with return type `str | Response` -- [ ] Task 4: Update `provision.py` `main()` to call `wifi.start_ap()` inside the provisioning loop (AC: #4) - - [ ] 4.1 Import `wifi` from `planemapper.provisioning` - - [ ] 4.2 Call `wifi.start_ap()` at the start of the provisioning sequence inside the existing `while not provisioned` loop - - [ ] 4.3 Ensure the existing `except ProvisioningError` handler catches failures from `wifi.start_ap()`, logs the error, and resets to portal state via `reset_to_portal_state()` (or equivalent) +- [x] Task 4: Update `provision.py` `main()` to call `wifi.start_ap()` inside the provisioning loop (AC: #4) + - [x] 4.1 Import `wifi` from `planemapper.provisioning` + - [x] 4.2 Call `wifi.start_ap()` at the start of the provisioning sequence inside the existing `while not provisioned` loop + - [x] 4.3 Ensure the existing `except ProvisioningError` handler catches failures from `wifi.start_ap()`, logs the error, and resets to portal state via `reset_to_portal_state()` (or equivalent) -- [ ] Task 5: Write tests (AC: #1, #2, #3, #4) - - [ ] 5.1 In `tests/provisioning/test_provision_loop.py` — add a test that patches `subprocess.run` to return a non-zero exit code, calls `wifi.start_ap()`, and asserts `ProvisioningError` is raised - - [ ] 5.2 In `tests/provisioning/test_provision_loop.py` — add a test that a `ProvisioningError` raised during the provisioning loop is caught, logged at ERROR, and the loop continues (does not crash) - - [ ] 5.3 Create `tests/provisioning/test_portal.py` — test `GET /` returns 200 with a form containing location, radius, SSID, password fields and a "Find location" button using Flask test client (`app.test_client()`) - - [ ] 5.4 In `tests/provisioning/test_portal.py` — test `GET /generate_204`, `GET /hotspot-detect.html`, `GET /ncsi.txt` each return a redirect (3xx) to `/` - - [ ] 5.5 In `tests/provisioning/test_portal.py` — test that a request to an unknown route (e.g. `GET /unknown-path`) returns a redirect to `/` +- [x] Task 5: Write tests (AC: #1, #2, #3, #4) + - [x] 5.1 In `tests/provisioning/test_provision_loop.py` — add a test that patches `subprocess.run` to return a non-zero exit code, calls `wifi.start_ap()`, and asserts `ProvisioningError` is raised + - [x] 5.2 In `tests/provisioning/test_provision_loop.py` — add a test that a `ProvisioningError` raised during the provisioning loop is caught, logged at ERROR, and the loop continues (does not crash) + - [x] 5.3 Create `tests/provisioning/test_portal.py` — test `GET /` returns 200 with a form containing location, radius, SSID, password fields and a "Find location" button using Flask test client (`app.test_client()`) + - [x] 5.4 In `tests/provisioning/test_portal.py` — test `GET /generate_204`, `GET /hotspot-detect.html`, `GET /ncsi.txt` each return a redirect (3xx) to `/` + - [x] 5.5 In `tests/provisioning/test_portal.py` — test that a request to an unknown route (e.g. `GET /unknown-path`) returns a redirect to `/` -- [ ] Task 6: Run quality gates - - [ ] 6.1 `pytest tests/` — all tests pass, 0 failures - - [ ] 6.2 `ruff check .` — zero violations - - [ ] 6.3 `ruff format --check .` — no formatting issues +- [x] Task 6: Run quality gates + - [x] 6.1 `pytest tests/` — all tests pass, 0 failures + - [x] 6.2 `ruff check .` — zero violations + - [x] 6.3 `ruff format --check .` — no formatting issues ## Dev Notes diff --git a/_bmad-output/implementation-artifacts/sprint-status.yaml b/_bmad-output/implementation-artifacts/sprint-status.yaml index 8ebbfe6..5261df1 100644 --- a/_bmad-output/implementation-artifacts/sprint-status.yaml +++ b/_bmad-output/implementation-artifacts/sprint-status.yaml @@ -46,7 +46,7 @@ development_status: epic-1: in-progress 1-1-project-scaffold-and-verified-entry-points: done 1-2-configuration-read-write-wipe: done - 1-3-wifi-hotspot-and-captive-portal-form: ready-for-dev + 1-3-wifi-hotspot-and-captive-portal-form: review 1-4-location-resolution-icao-and-address: backlog 1-5-provisioning-execution-tile-download-cache-validation-and-wifi-kill: backlog epic-1-retrospective: optional diff --git a/src/planemapper/provision.py b/src/planemapper/provision.py index 783c610..f2057c0 100644 --- a/src/planemapper/provision.py +++ b/src/planemapper/provision.py @@ -1,8 +1,28 @@ import logging +from planemapper.provisioning import ProvisioningError, wifi + log = logging.getLogger(__name__) +def _reset_to_portal_state() -> None: + log.info("Resetting to portal state") + try: + wifi.stop_ap() + except Exception: + pass + + def main() -> None: logging.basicConfig(level=logging.INFO) - log.info("not implemented") + provisioned = False + while not provisioned: + try: + wifi.start_ap() + # Portal runs here (Story 1.3+ wires Flask app) + # Provisioning sequence continues in Story 1.5 + log.info("Provisioning sequence started") + provisioned = True # placeholder — full sequence wired in 1.5 + except ProvisioningError as e: + log.error("Provisioning failed: %s", e) + _reset_to_portal_state() diff --git a/src/planemapper/provisioning/portal.py b/src/planemapper/provisioning/portal.py index d352c7e..4d080ba 100644 --- a/src/planemapper/provisioning/portal.py +++ b/src/planemapper/provisioning/portal.py @@ -1 +1,53 @@ -# stub +import logging + +from flask import Flask, redirect, url_for +from werkzeug.wrappers import Response + +log = logging.getLogger(__name__) + +app = Flask(__name__) + +_FORM_HTML = """ + +