Skip to content

Implement mock captive portal server for frontend testing#428

Draft
hhvrc wants to merge 4 commits intodevelopfrom
feat/mock-portal
Draft

Implement mock captive portal server for frontend testing#428
hhvrc wants to merge 4 commits intodevelopfrom
feat/mock-portal

Conversation

@hhvrc
Copy link
Contributor

@hhvrc hhvrc commented Mar 6, 2026

No description provided.

hhvrc and others added 3 commits March 6, 2026 14:21
Go server at tools/mock-portal/ that simulates the OpenShock ESP32
captive portal for frontend development and testing — no DNS/DHCP/
file-hosting, only the HTTP API and WebSocket protocol.

- RFC 8908 captive portal API at GET /captive-portal/api
- WebSocket server at /ws (subprotocol: flatbuffers) with full
  FlatBuffers binary LocalToHub/HubToLocal protocol support
- All 19 LocalToHubMessage command types handled (WiFi, OTA, RF,
  EStop, account)
- In-memory device state with FlatBuffers HubConfig binary persistence
  (saved on every mutation, loaded on startup via --config flag)
- 40 random networks at startup via gofakeit: emoji, unicode, XSS,
  SQL injection, hidden, all auth modes, mesh configs, edge-case SSIDs
- Interactive stdin CLI: network management, mesh simulation,
  wifi-lost/got, scan trigger, error broadcast, disconnect-all,
  traffic spike, corrupt frames, scan-fail arming, chaos toggle
- ChaosEngine: 10 fault types fired randomly every 2-10s (disconnect,
  error, spike, corrupt, scan-fail, add/remove networks, RSSI flutter,
  IP flap, scan status burst); enabled via --chaos or 'chaos on'
- FlatBuffers Go bindings generated by scripts/generate_schemas.py

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hhvrc hhvrc requested review from LucHeart and Copilot March 6, 2026 21:37
@hhvrc hhvrc self-assigned this Mar 6, 2026
@github-project-automation github-project-automation bot moved this to Todo in Roadmap Mar 6, 2026
@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2026

⚠️ No Changeset found

Latest commit: e39c5b9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@hhvrc hhvrc moved this from Todo to In Review in Roadmap Mar 6, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a standalone Go-based mock captive portal server under tools/mock-portal/ to simulate the ESP32 captive-portal HTTP + FlatBuffers-over-WebSocket interface for frontend development/testing, including CLI-driven event injection and optional “chaos” fault mode. It also extends schema generation to produce Go FlatBuffers bindings into the mock-portal module.

Changes:

  • Introduce mock portal HTTP endpoints (/captive-portal/api, /ws) and FlatBuffers message builders/handlers for core WiFi/OTA/account/GPIO flows.
  • Add interactive CLI console utilities plus chaos/fault-injection engine for stressing the frontend.
  • Add a dedicated Go module (tools/mock-portal/go.mod) and extend scripts/generate_schemas.py to generate Go bindings into tools/mock-portal/fbs/.

Reviewed changes

Copilot reviewed 85 out of 86 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tools/mock-portal/server/state.go In-memory state model for networks/config/account/GPIO used by the mock server.
tools/mock-portal/server/server.go HTTP mux + WebSocket accept loop, client pumps, broadcast helpers.
tools/mock-portal/server/networks.go Random-ish WiFi network generation helpers for scan payloads.
tools/mock-portal/server/handlers.go FlatBuffers command dispatch and handlers for WiFi/OTA/account/GPIO operations.
tools/mock-portal/server/config.go FlatBuffers HubConfig persistence (load/save) and autosave hook.
tools/mock-portal/server/cli/runner.go CLI read loop that routes commands into server command executor.
tools/mock-portal/server/cli/console.go Prompt-safe console writer/buffer for interleaving logs and user input.
tools/mock-portal/server/cli/ansi.go ANSI escape helpers used by the CLI console.
tools/mock-portal/server/chaos.go Chaos engine for random fault injection and network churn.
tools/mock-portal/server/builders.go FlatBuffers message builders for Hub→Local events/results.
tools/mock-portal/main.go Entrypoint wiring flags, config load, chaos start, HTTP serve, CLI goroutine.
tools/mock-portal/go.mod Defines the standalone Go module for the mock portal tool.
tools/mock-portal/go.sum Dependency checksums for the mock portal module.
tools/mock-portal/README.md Usage documentation, protocol notes, CLI/chaos descriptions, regen instructions.
scripts/generate_schemas.py Adds Go FlatBuffers generation output into tools/mock-portal/fbs/.
tools/mock-portal/fbs/OpenShock/Serialization/Types/WifiScanStatus.go Generated Go FlatBuffers types used by mock protocol.
tools/mock-portal/fbs/OpenShock/Serialization/Types/WifiNetworkEventType.go Generated Go FlatBuffers types used by mock protocol.
tools/mock-portal/fbs/OpenShock/Serialization/Types/WifiNetwork.go Generated Go FlatBuffers types used by mock protocol.
tools/mock-portal/fbs/OpenShock/Serialization/Types/WifiAuthMode.go Generated Go FlatBuffers types used by mock protocol.
tools/mock-portal/fbs/OpenShock/Serialization/Types/ShockerModelType.go Generated Go FlatBuffers types included from schemas.
tools/mock-portal/fbs/OpenShock/Serialization/Types/ShockerCommandType.go Generated Go FlatBuffers types included from schemas.
tools/mock-portal/fbs/OpenShock/Serialization/Types/SemVer.go Generated Go FlatBuffers types included from schemas.
tools/mock-portal/fbs/OpenShock/Serialization/Types/OtaUpdateProgressTask.go Generated Go FlatBuffers types included from schemas.
tools/mock-portal/fbs/OpenShock/Serialization/Types/FirmwareBootType.go Generated Go FlatBuffers types included from schemas.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiScanStatusMessage.go Generated Local (Hub↔Local) message bindings for WiFi scan status.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiScanCommand.go Generated Local command binding for WiFi scan.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiNetworkSaveCommand.go Generated Local command binding for saving WiFi credentials.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiNetworkForgetCommand.go Generated Local command binding for forgetting WiFi credentials.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiNetworkEvent.go Generated Local event binding for WiFi network events.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiNetworkDisconnectCommand.go Generated Local command binding for WiFi disconnect.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiNetworkConnectCommand.go Generated Local command binding for WiFi connect.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiLostIpEvent.go Generated Local event binding for IP loss.
tools/mock-portal/fbs/OpenShock/Serialization/Local/WifiGotIpEvent.go Generated Local event binding for IP acquisition.
tools/mock-portal/fbs/OpenShock/Serialization/Local/SetRfTxPinCommandResult.go Generated Local result binding for RF TX pin setting.
tools/mock-portal/fbs/OpenShock/Serialization/Local/SetRfTxPinCommand.go Generated Local command binding for RF TX pin setting.
tools/mock-portal/fbs/OpenShock/Serialization/Local/SetGPIOResultCode.go Generated Local enum for GPIO result codes.
tools/mock-portal/fbs/OpenShock/Serialization/Local/SetEstopPinCommandResult.go Generated Local result binding for E-Stop pin setting.
tools/mock-portal/fbs/OpenShock/Serialization/Local/SetEstopPinCommand.go Generated Local command binding for E-Stop pin setting.
tools/mock-portal/fbs/OpenShock/Serialization/Local/SetEstopEnabledCommandResult.go Generated Local result binding for E-Stop enable setting.
tools/mock-portal/fbs/OpenShock/Serialization/Local/SetEstopEnabledCommand.go Generated Local command binding for E-Stop enable setting.
tools/mock-portal/fbs/OpenShock/Serialization/Local/ReadyMessage.go Generated Local ReadyMessage binding used on connect.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateStartUpdateCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateSetUpdateChannelCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateSetRequireManualApprovalCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateSetIsEnabledCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateSetDomainCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateSetCheckIntervalCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateSetAllowBackendManagementCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateHandleUpdateRequestCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/OtaUpdateCheckForUpdatesCommand.go Generated Local OTA command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/LocalToHubMessagePayload.go Generated Local payload union enum for incoming commands.
tools/mock-portal/fbs/OpenShock/Serialization/Local/LocalToHubMessage.go Generated Local wrapper message for incoming commands.
tools/mock-portal/fbs/OpenShock/Serialization/Local/HubToLocalMessagePayload.go Generated Local payload union enum for outgoing events/results.
tools/mock-portal/fbs/OpenShock/Serialization/Local/HubToLocalMessage.go Generated Local wrapper message for outgoing events/results.
tools/mock-portal/fbs/OpenShock/Serialization/Local/ErrorMessage.go Generated Local error message binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/AccountUnlinkCommand.go Generated Local account unlink command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/AccountLinkResultCode.go Generated Local account link result enum binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/AccountLinkCommandResult.go Generated Local account link result message binding.
tools/mock-portal/fbs/OpenShock/Serialization/Local/AccountLinkCommand.go Generated Local account link command binding.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/TriggerType.go Generated Gateway schema bindings (not directly used by mock server code shown).
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/Trigger.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/ShockerCommandList.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/ShockerCommand.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/Pong.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/Ping.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/OtaUpdateStarted.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/OtaUpdateRequest.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/OtaUpdateProgress.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/OtaUpdateFailed.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/HubToGatewayMessagePayload.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/HubToGatewayMessage.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/GatewayToHubMessagePayload.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/GatewayToHubMessage.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Gateway/BootStatus.go Generated Gateway schema bindings.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/WiFiCredentials.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/WiFiConfig.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/SerialInputConfig.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/RFConfig.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/OtaUpdateStep.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/OtaUpdateConfig.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/OtaUpdateChannel.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/HubConfig.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/EStopConfig.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/CaptivePortalConfig.go Generated config schema bindings used for persistence.
tools/mock-portal/fbs/OpenShock/Serialization/Configuration/BackendConfig.go Generated config schema bindings used for persistence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Return nil from GenerateNetworks when count <= 0 to fix set-networks 0
- Seed gofakeit with time at startup for per-run randomness
- Write config file with 0600 permissions instead of 0644
- Restrict WebSocket CheckOrigin to localhost/127.0.0.1/::1
- Close WebSocket connection in writePump on write error to unblock readPump
- Apply OtaUpdateSetUpdateChannelCommand to state instead of no-op
- Run go mod tidy to remove // indirect from direct dependencies
- Fix README ReadyMessage description and SSID edge cases section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hhvrc hhvrc marked this pull request as draft March 6, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants