Repository navigation
Serve the plugin's README as a documentation page - #4
Merged
Merged
Conversation
/health advertises "docs": "/docs" while README.md is readable. /docs needs the pairing token like every route but /health and is served as HTML under a strict CSP. docs_page.py is the shared renderer, copied verbatim from the plugin-docs spec.
yurivibes
added a commit
to yurivibes/MonkeyTester
that referenced
this pull request
Nov 26, 2026
## What - **/plugins:** when the plugin's `/health` reports `"docs": "/docs"`, its row's Details cell ends with a thin horizontal rule and a small **Documentation** link that opens in a new tab. The Address field and Save address are unchanged. - **`GET /plugins/docs/<name>`:** the viewer fetches the plugin's docs page with its saved token (`X-Plugin-Token`, or `X-Controller-Token` for the Mobile Controller) and serves it under a sandbox CSP. The URL and path come only from the viewer's own config plus the plugin's `/health`, never from the request. Limits: no redirects, `text/html` only, 2 MiB max, 10 s timeout. Failures return a 502 page with a link back to /plugins. - `/api/plugins` rows and `/api/config/controller` carry `docs: true/false`. - `PLUGIN_API.md` / `BUILD_PLUGIN_API.md` document the optional `docs` health field and `GET /docs`. ## Why The browser never talks to a plugin directly. The ESP32 plugins listen only on 127.0.0.1, and the Mac plugins need a token that a browser tab can't send. ## Paired PRs (add `GET /docs` to each plugin) - yurivibes/MonkeyTester-Plugin-Esp32#4 - yurivibes/MonkeyTester-Plugin-Server#4 - yurivibes/MonkeyTester-Plugin-Mobile-Controller#4 - yurivibes/MonkeyTester-Plugin-Build-Local#4 - yurivibes/MonkeyTester-Plugin-AI#5 A plugin shows the link only after its PR is deployed. Until then its row looks exactly as it does today. ## Tested - `python3 -m unittest discover -s tests -t .`: 634 tests OK, 18 new in `tests/test_plugin_docs.py` (proxy pass-through and CSP, token header, unknown name, invalid docs paths, redirect, non-HTML, oversize, offline, login redirect, status `docs`). - `node --check` on the plugins.html inline script. - Scratch instance with one fake plugin that has docs and one that doesn't: the link shows (in Details, under a rule) only for the first and opens the rendered page in a new tab.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
GET /docs: rendersREADME.md(read at request time, resolved next tobuild_plugin.py) into a self-contained HTML page with the shareddocs_page.pyrenderer (copied verbatim, plus its tests intests/test_docs_page.py; only the import path was adjusted for the tests/ layout).text/html; charset=utf-8, CSPdefault-src 'none'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none',nosniff,no-store. Missing README → 404 JSON (not_found).GET /healthadds"docs": "/docs"only while README.md is readable./docsgoes through the existing pairing-token check;/healthstays the only open route./docsand thedocshealth field) and a packaging note (launchd/systemd run from the checkout, the flake copies all tracked files, so README.md ships); SECURITY.md /health row updated.Why
Pairs with the MonkeyTester viewer PR that adds
/plugins/docs/<name>and a Documentation link on /plugins: the viewer fetches this page with the plugin's saved token and serves it to the browser under a sandbox CSP.How tested
python3 -m unittest discover -s tests -v→ Ran 95 tests, OK. New tests: /docs 200 + content type + CSP + README<h1>; /docs 401 without/with a wrong token; /healthdocs == "/docs"(with and without token); README path patched to a missing file → /health omitsdocsand /docs 404s.