Skip to content

Serve the plugin's README as a documentation page - #4

Merged
yurivibes merged 1 commit into
masterfrom
feat/plugin-docs
Nov 26, 2026
Merged

yurivibes merged 1 commit into
masterfrom
feat/plugin-docs

Conversation

@yurivibes

Copy link
Copy Markdown
Owner

What

  • New GET /docs: renders README.md (read at request time, resolved next to build_plugin.py) into a self-contained HTML page with the shared docs_page.py renderer (copied verbatim, plus its tests in tests/test_docs_page.py; only the import path was adjusted for the tests/ layout).
  • Response headers: text/html; charset=utf-8, CSP default-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 /health adds "docs": "/docs" only while README.md is readable.
  • Auth unchanged: /docs goes through the existing pairing-token check; /health stays the only open route.
  • README gains an Endpoints table (with /docs and the docs health 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; /health docs == "/docs" (with and without token); README path patched to a missing file → /health omits docs and /docs 404s.

/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.
@yurivibes
yurivibes merged commit bc5f577 into master Nov 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant