Repository navigation
feat(gui): serve a browser frontend over loopback - #582
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: LargeModGames/spotatui/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (25)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThis pull request adds a feature-gated browser GUI. It embeds frontend assets, serves them from a loopback server, and connects the page to the application through a WebSocket protocol and bridge. It adds GUI runtime startup and CI coverage. ChangesBrowser GUI frontend
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~60 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant User
participant spotatui-gui
participant run_gui
participant spawn_listener
participant run_socket
participant Browser
spotatui-gui->>run_gui: start GUI entry point
run_gui->>spawn_listener: start loopback listener
run_gui->>Browser: open page URL with launch code
Browser->>spawn_listener: request page and WebSocket connection
spawn_listener->>run_socket: admit WebSocket and pass socket
run_socket->>Browser: send hello and resync snapshot
Browser->>run_socket: send client action or quit message
run_socket->>run_gui: forward client message through inbox
Merge Risk: ⚪ Minimal · up to This adds a browser frontend behind the off-by-default Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The new browser frontend has meaningful local security boundaries. Its request and credential checks limit exposure, but cross-user protection differs by platform, and a failed connection can consume the one-time launch code before a session starts. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
722e673 to
9dc4641
Compare
|
@coderabbitai review |
|
spotatui-gui now boots like the terminal UI (the same lock, boot and frontend runtime), serves the embedded page on 127.0.0.1:<random port> and opens the browser at a one-time launch code. The server checks Host and Origin against DNS rebinding and cross-site pages, trades the single-use code (60 s) for a session token in the WebSocket subprotocol, and sends no-store, nosniff, no-referrer and a strict CSP. Each socket gets a hello, a full resync, and then every channel whose display revision moves (route, status, theme, playback, devices, queue) plus a 250 ms position tick; page actions go through App::apply on the tick loop. The process quits on Ctrl-C, a quit from the page, or a minute with no page. A fresh profile still needs one terminal run for the first-launch setup. build.rs embeds gui/dist when it exists. A new CI leg builds the GUI without tui.
…tup errors On Linux the server refuses a loopback connection whose socket belongs to another user (read from /proc/net/tcp), because another user can read the launch URL from the browser's command line. One deadline covers the whole answer to a plain request and the socket handshake, not only the head. The position tick allows 20 ms of timer jitter, so a 250 ms tick loop does not drop every other tick. A windowed Windows build started without a console shows its startup error in a message box. New tests: the rebinding case on the Host check, a head that never ends, a lagging socket's resync, and the Linux peer lookup.
run_gui now shares start_logging with run_cli, so SPOTATUI_LOG and a bare --debug set its level and every GUI log starts with the version, platform and feature header.
9dc4641 to
9ad7622
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
# Summary This adds the browser side of `spotatui-gui`: TypeScript types generated from the Rust wire types, and a React page in `gui/` that talks to the loopback server from the PR below. The page is a placeholder that exercises the bridge and the CI gates. It is not a design, and the designed screens will replace it. What changed: 1. `Action`, the types it carries and the GUI protocol types derive `ts_rs::TS` under `cfg_attr(all(test, feature = "gui"), ...)`. `ts-rs` is a dev-dependency pinned to `=12.0.1`, so no shipped binary changes. The protocol enum `Message` is now `ServerMessage`. 2. `typescript_bindings_are_written_to_the_frontend_source_tree` rewrites `gui/src/bindings/` with `u64` as `number`, and fails when two exported types share a name or any file contains `bigint`. The `gui` test row in `ci.yml` fails when the committed files drift. 3. `gui/` is Vite + React + TypeScript: a queue list and a now-playing bar (art, title, artists, a progress bar interpolated from the tick, Previous, Play/Pause, Next), coloured from the theme channel. 4. `gui/src/connection.ts` trades the launch code for the session token and keeps the token in `localStorage`. It reconnects 1 s after a drop that followed a hello. A close before hello shows "This page is no longer connected to spotatui." 5. The new `gui.yml` runs `npm ci`, `lint`, `format:check`, `typecheck`, vitest and the build on every PR, with no paths filter. 6. `Cargo.toml` excludes `/gui/` from the published crate. The pattern is anchored, so `src/gui` stays in. 7. The page's `Content-Security-Policy` allows `http:` images, since many Subsonic servers serve cover art over http. Deliberate behaviour changes a user can see: Only builds with the `gui` feature change. It is off by default and no release ships it. 1. With `gui/dist` built, `spotatui-gui` serves this page instead of the "built without its frontend" answer. 2. A closed tab reopened at the same address reconnects to the running spotatui. Each run issues its own token. # Testing The suites ran on the top of the stack (`feat/gui-onboarding`), which contains this PR: - `cargo fmt --all -- --check`: clean. - `cargo clippy --locked -- -D warnings` on slim, headless, headless-streaming, mcp-only, ai-dj-only, default, the `gui` leg and the five-sources set with `audio-viz-cpal`: all `Finished`, no warnings. - `cargo test --locked`, `0 failed` on every leg: slim `1253 passed`, headless `851 passed`, mcp-only `1377 passed`, ai-dj-only `1530 passed` (the four dead-code warnings in `infra/dj` test helpers predate this stack), default `1630 passed`, `gui` leg `1369 passed`. - Bindings drift after the `gui` leg test: `git status --porcelain gui/src/bindings` prints nothing. - In `gui/`: `npm ci` (`found 0 vulnerabilities`), `npm run lint`, `npm run format:check` (`All matched files use Prettier code style!`), `npm run typecheck`, `npm test` (`Tests 21 passed (21)`), `npm run build` (`✓ built`). On this PR's own head: `cargo clippy --locked -- -D warnings` on slim, headless, default and the `gui` leg: clean. `cargo test --no-default-features --features telemetry,tui gates`: `ok. 10 passed`. `bash tools/check_gates_ratchet.sh` against the PR below: `ok`. # Additional notes Part 6 of 7 of a stack (#578 to #584). Base: #582. Not verified here: no CI job embeds the built page into the binary (the `gui` leg builds without `gui/dist`), so serving it rests on a manual run on Windows. `npm ci` has only run on Windows, and `gui.yml` is the lockfile's first Linux install. No browser on macOS or Linux was tried. Trade-offs and follow-ups: - `ts-rs` compiles on every test leg, though only the `gui` leg uses it. A Dependabot bump of it fails the drift step until the bindings are regenerated, by design. - `typescript` is pinned `~6.0` because `typescript-eslint` accepts `<6.1.0`. - Dependabot has no npm entry for `gui/` yet. - The queue list skips Spotify queue episodes. --- <sub>💬 Questions or want to chat with other contributors? Join the [spotatui Discord](https://spotatui.com/discord).</sub> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a web-based GUI for viewing the playback queue and now-playing details, with playback controls and theme support. * Added automatic reconnection and connection status feedback. * **Quality Improvements** * Added automated checks for the GUI, including linting, formatting, type checks, tests, and builds. * Enabled checks to detect outdated frontend bindings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
spotatui-guiwas a placeholder that exited. It now boots like the terminal UI (the same instance lock,bootandprepare_frontend), serves an embedded page and a WebSocket on127.0.0.1, and opens the browser at it.What changed:
src/gui/server.rs: a loopback server onhttparseandtokio_tungstenite::accept_hdr_async. It checksHost,OriginandSec-Fetch-Siteagainst DNS rebinding and cross-site pages, sendsno-store,nosniffand a strict CSP, and bounds each request and handshake at 5 s./#code=<code>. The code is single-use, lives 60 s and is traded for a session token inhello. On Linux the server also refuses loopback peers of other users (/proc/net/tcp).src/gui/protocol.rsandsrc/gui/bridge.rs:ClientMessagein (actionthroughApp::apply,quit),Messageout:hello, a resync, then each channel whose display revision moved (route, status, theme, playback, devices, queue) and a positiontickabout every 250 ms.src/runtime/gui.rs: a tick loop without a terminal. It boots withno_update: trueand quits on Ctrl-C, aquitfrom the page, or a minute with no page.build.rsembedsgui/dist. Without it/answers 503 with a build hint.src/bin/spotatui-gui.rscallsrun_gui. A windowed release build on Windows with no console shows its startup error in a message box.src/infra/loopback.rsshares the token helpers with the MCP control socket.guileg inci.yml(check, clippy, test), the third leg withouttui.Deliberate behaviour changes a user can see:
guiis off by default and no release enables it.spotatui-guiruns instead of exiting, and refuses to start beside another spotatui UI.spotatuifirst.Testing
The suites ran on the top of the stack (
feat/gui-onboarding), which contains this PR:cargo fmt --all -- --check: clean.cargo clippy --locked -- -D warningson slim, headless, headless-streaming, mcp-only, ai-dj-only, default, theguileg and the five-sources set withaudio-viz-cpal: allFinished, no warnings.cargo test --locked,0 failedon every leg: slim1253 passed, headless851 passed, mcp-only1377 passed, ai-dj-only1530 passed(the four dead-code warnings ininfra/djtest helpers predate this stack), default1630 passed,guileg1369 passed.On this PR's own head:
cargo clippy --locked -- -D warningson slim, headless, default and theguileg (--no-default-features --features telemetry,gui,streaming,discord-rpc,self-update,scripting,mcp-server,mpris): clean.cargo test --no-default-features --features telemetry,tui gates:ok. 10 passed.bash tools/check_gates_ratchet.shagainst the PR below:ok.Additional notes
Part 5 of 7 of a stack (#578 to #584). Base: #581.
Rebased onto #574 and #577. Beyond mechanical merges, the last commit makes
run_guiopen its log through the samestart_loggingasrun_cli:SPOTATUI_LOG, a bare--debug(the crash notice asks for it), and the startup header.Not verified here: the Linux peer check and the MPRIS build without
tuirun only in theguiCI leg, and no CI job buildsguion macOS. A live pass on Windows ran against the top of the stack before the rebase. This layer alone ships no page.Residual risk: the launch code sits in the browser's command line while it starts. macOS has no peer check, so another local user there could race it. A private redirect file would keep the code out of argv, but snap-confined browsers cannot read one.
Source,Party,Search,Lyrics,ArtistandLibraryhave revisions but no message yet. The next PR adds the page, and the top PR moves the first-launch questions into it.💬 Questions or want to chat with other contributors? Join the spotatui Discord.
Summary by CodeRabbit
New Features
Improvements