Skip to content

Commit 4d6666e

Browse files
committed
Update testing instructions
1 parent 8b9b3ca commit 4d6666e

File tree

2 files changed

+142
-68
lines changed

2 files changed

+142
-68
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
name: test-server
3+
description: E2E testing workflow for the RDoc live-reload server (rdoc --server)
4+
---
5+
6+
# Test Server
7+
8+
End-to-end testing workflow for the RDoc live-reload server. Use after modifying server code, templates, generators, or routing.
9+
10+
## Steps
11+
12+
### 1. Start the server
13+
14+
```bash
15+
bundle exec rdoc --server &
16+
SERVER_PID=$!
17+
sleep 2 # wait for TCP server to bind
18+
```
19+
20+
Or on a custom port:
21+
22+
```bash
23+
bundle exec rdoc --server=8080 &
24+
```
25+
26+
Default port is 4000.
27+
28+
### 2. Verify core endpoints
29+
30+
Run these curl checks against the running server:
31+
32+
```bash
33+
# Root → 200, HTML index page
34+
curl -s -o /dev/null -w '%{http_code}' http://localhost:4000/
35+
# Expected: 200
36+
37+
# Status endpoint → 200, JSON with last_change float
38+
curl -s http://localhost:4000/__status
39+
# Expected: {"last_change":1234567890.123}
40+
41+
# Class page → 200, HTML with live-reload script
42+
curl -s http://localhost:4000/RDoc.html | head -5
43+
# Expected: HTML containing class documentation
44+
45+
# CSS asset → 200, stylesheet
46+
curl -s -o /dev/null -w '%{http_code}' http://localhost:4000/css/rdoc.css
47+
# Expected: 200
48+
49+
# JS search index → 200, search data
50+
curl -s -o /dev/null -w '%{http_code}' http://localhost:4000/js/search_data.js
51+
# Expected: 200
52+
53+
# Missing page → 404, still has live-reload script
54+
curl -s -w '\n%{http_code}' http://localhost:4000/Missing.html | tail -1
55+
# Expected: 404
56+
57+
# Path traversal via asset route → 404 (blocked by expand_path check)
58+
curl -s -o /dev/null -w '%{http_code}' 'http://localhost:4000/css/../../etc/passwd'
59+
# Expected: 404
60+
```
61+
62+
### 3. Verify live-reload
63+
64+
HTML pages should contain the live-reload polling script:
65+
66+
```bash
67+
# Check for live-reload script in a class page
68+
curl -s http://localhost:4000/RDoc.html | grep 'var lastChange'
69+
# Expected: var lastChange = <float>;
70+
71+
# Check that 404 pages also get live-reload
72+
curl -s http://localhost:4000/Missing.html | grep 'var lastChange'
73+
# Expected: var lastChange = <float>;
74+
```
75+
76+
The script polls `/__status` and reloads when `data.last_change > lastChange`.
77+
78+
### 4. Verify file change detection
79+
80+
Confirm the server detects source file changes and invalidates its cache:
81+
82+
```bash
83+
# Record the current last_change timestamp
84+
BEFORE=$(curl -s http://localhost:4000/__status | grep -o '"last_change":[0-9.]*' | cut -d: -f2)
85+
86+
# Touch a source file to trigger the file watcher
87+
touch lib/rdoc.rb
88+
sleep 2 # watcher polls every 1 second
89+
90+
# Check that last_change has advanced
91+
AFTER=$(curl -s http://localhost:4000/__status | grep -o '"last_change":[0-9.]*' | cut -d: -f2)
92+
echo "before=$BEFORE after=$AFTER"
93+
# Expected: AFTER > BEFORE
94+
```
95+
96+
### 5. (Optional) Visual testing with Playwright CLI
97+
98+
For visual inspection of rendered pages, use Playwright CLI commands directly:
99+
100+
```bash
101+
# Install browsers (one-time)
102+
npx playwright install chromium
103+
104+
# Take a screenshot of the index page
105+
npx playwright screenshot http://localhost:4000/ /tmp/rdoc-index.png
106+
107+
# Take a screenshot of a specific class page
108+
npx playwright screenshot http://localhost:4000/RDoc.html /tmp/rdoc-class.png
109+
110+
# Full-page screenshot
111+
npx playwright screenshot --full-page http://localhost:4000/RDoc.html /tmp/rdoc-full.png
112+
```
113+
114+
Review the screenshots to verify layout, styling, and content rendering.
115+
116+
### 6. Stop the server
117+
118+
```bash
119+
kill $SERVER_PID 2>/dev/null
120+
```

AGENTS.md

Lines changed: 22 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,34 @@ When making changes to theme CSS or templates (e.g., Darkfish or Aliki themes):
353353
1. **Start the live-reloading server**: Run `bundle exec rdoc --server` (or `bundle exec rake rdoc:server`)
354354
2. **Make changes**: Edit files in `lib/rdoc/generator/template/<theme>/` or source code
355355
3. **Browser auto-refreshes**: The server detects file changes and refreshes the browser automatically
356-
4. **Investigate with Playwright**: Ask the AI assistant to take screenshots and inspect the documentation visually
357-
- Example: "Navigate to the docs at localhost:4000 and screenshot the RDoc module page"
358-
- See "Playwright MCP for Testing Generated Documentation" section below for details
356+
4. **Verify with `/test-server`**: Use the test-server skill for endpoint checks, live-reload verification, and optional Playwright screenshots
359357
5. **Lint changes** (if modified):
360358
- ERB templates: `npx @herb-tools/linter "lib/rdoc/generator/template/**/*.rhtml"`
361359
- CSS files: `npm run lint:css -- --fix`
362360

363361
**Note:** The server watches source files, not template files. If you modify `.rhtml` templates or CSS in the template directory, restart the server to pick up those changes.
364362

363+
## Visual Testing with Playwright CLI
364+
365+
Use `npx playwright` to take screenshots of generated documentation — works with both the live-reload server and static `_site/` output.
366+
367+
```bash
368+
# Install browsers (one-time)
369+
npx playwright install chromium
370+
371+
# Screenshot a live server page
372+
npx playwright screenshot http://localhost:4000/RDoc.html /tmp/rdoc-class.png
373+
374+
# Screenshot static output (start a file server first)
375+
cd _site && python3 -m http.server 8000 &
376+
npx playwright screenshot http://localhost:8000/index.html /tmp/rdoc-index.png
377+
378+
# Full-page screenshot
379+
npx playwright screenshot --full-page http://localhost:4000/RDoc.html /tmp/rdoc-full.png
380+
```
381+
382+
For server-specific E2E testing (endpoint checks, live-reload verification, file change detection), use the `/test-server` skill.
383+
365384
## Notes for AI Agents
366385

367386
1. **Always run tests** after making changes: `bundle exec rake`
@@ -373,68 +392,3 @@ When making changes to theme CSS or templates (e.g., Darkfish or Aliki themes):
373392
4. **Use `rake rerdoc`** to regenerate documentation (not just `rdoc`)
374393
5. **Verify generated files** with `rake verify_generated`
375394
6. **Don't edit generated files** directly (in `lib/rdoc/markdown/` and `lib/rdoc/rd/`)
376-
377-
## Playwright MCP for Testing Generated Documentation
378-
379-
The Playwright MCP server enables visual inspection and interaction with generated HTML documentation. This is useful for verifying CSS styling, layout issues, and overall appearance.
380-
381-
**MCP Server:** `@playwright/mcp` (Microsoft's official browser automation server)
382-
383-
### Setup
384-
385-
The Playwright MCP server can be used with any MCP-compatible AI tool (Claude Code, Cursor, GitHub Copilot, OpenAI Agents, etc.).
386-
387-
**Claude Code:**
388-
389-
```bash
390-
/plugin playwright
391-
```
392-
393-
**Other MCP-compatible tools:**
394-
395-
```bash
396-
npx @playwright/mcp@latest
397-
```
398-
399-
Configure your tool to connect to this MCP server. Playwright launches its own browser instance automatically - no manual browser setup or extensions required.
400-
401-
### Troubleshooting: Chrome Remote Debugging Blocked
402-
403-
If you encounter `DevTools remote debugging is disallowed by the system admin`, Chrome's debugging is blocked by the machine's policy. Use Firefox instead:
404-
405-
```bash
406-
# Install Firefox for Playwright
407-
npx playwright install firefox
408-
409-
# Add Playwright MCP with Firefox to your project (creates/updates .mcp.json)
410-
claude mcp add playwright --scope project -- npx -y @playwright/mcp@latest --browser firefox
411-
```
412-
413-
Restart Claude Code after running these commands.
414-
415-
### Testing Generated Documentation
416-
417-
The easiest way to test documentation is with the live-reloading server:
418-
419-
```bash
420-
bundle exec rdoc --server
421-
# Or: bundle exec rake rdoc:server
422-
```
423-
424-
This starts a server at `http://localhost:4000` that auto-refreshes on file changes.
425-
426-
Alternatively, for testing static output:
427-
428-
```bash
429-
bundle exec rake rerdoc
430-
cd _site && python3 -m http.server 8000
431-
```
432-
433-
Then ask the AI assistant to inspect the documentation. It will use the appropriate Playwright tools (`browser_navigate`, `browser_snapshot`, `browser_take_screenshot`, etc.) based on your request.
434-
435-
**Example requests:**
436-
437-
- "Navigate to `http://localhost:4000` and take a screenshot"
438-
- "Take a screenshot of the RDoc module page"
439-
- "Check if code blocks are rendering properly on the Markup page"
440-
- "Compare the index page before and after my CSS changes"

0 commit comments

Comments
 (0)