diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-19 15:24:51 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-19 15:24:51 -0500 |
| commit | 4ffa7417a359ef4eae09f61d7da4de06539462ca (patch) | |
| tree | b8eeb8aa5ec2344216c0f0cdcdcc82d0df307ce3 /playwright-py/scripts/detect_dev_servers.py | |
| parent | 11f5f003eef12bff9633ca8190e3c43c7dab6708 (diff) | |
| download | rulesets-4ffa7417a359ef4eae09f61d7da4de06539462ca.tar.gz rulesets-4ffa7417a359ef4eae09f61d7da4de06539462ca.zip | |
refactor(playwright): split into playwright-js + playwright-py variants
Rename `playwright-skill/` → `playwright-js/` and add `playwright-py/`
as a verbatim fork of Anthropic's official `webapp-testing` skill
(Apache-2.0). Cross-pollinate: each skill gains patterns and helpers
inspired by the other's strengths, with upstream semantics preserved.
## playwright-js (JS/TS stack)
Renamed from playwright-skill; upstream lackeyjb MIT content untouched.
New sections added (clearly marked, preserving upstream semantics):
- Static HTML vs Dynamic Webapp decision tree (core Anthropic methodology)
- Reconnaissance-Then-Action pattern (navigate → networkidle → inspect → act)
- Console Log Capture snippet (page.on console/pageerror/requestfailed)
Description updated to clarify JS/TS stack fit (React/Next/Vue/Svelte/Node)
and reference `/playwright-py` as the Python sibling.
## playwright-py (Python stack)
Verbatim fork of anthropics/skills/skills/webapp-testing; upstream SKILL.md
and bundled `scripts/with_server.py` + examples kept intact. New scripts
and examples added (all lackeyjb-style conveniences in Python):
Scripts:
scripts/detect_dev_servers.py Probe common localhost ports for HTTP
servers; outputs JSON of found services.
scripts/safe_actions.py safe_click, safe_type (retry-wrapped),
handle_cookie_banner (common selectors),
build_context_with_headers (env-var-
driven: PW_HEADER_NAME / PW_HEADER_VALUE /
PW_EXTRA_HEADERS='{…json…}').
Examples:
examples/login_flow.py Login form + wait_for_url.
examples/broken_links.py Scan visible external hrefs via HEAD.
examples/responsive_sweep.py Multi-viewport screenshots to /tmp.
SKILL.md gains 5 "Added:" sections documenting the new scripts, retry
helpers, env-header injection, and /tmp script discipline. Attribution
notes explicitly mark upstream vs local additions.
## Makefile
SKILLS: playwright-skill → playwright-js + playwright-py
deps target: extended Playwright step to install Python package +
Chromium via `python3 -m pip install --user playwright && python3 -m
playwright install chromium` when playwright-py/ is present. Idempotent
(detected via `python3 -c "import playwright"`).
## Usage
Both skills symlinked globally via `make install`. Invoke whichever
matches the project stack — cross-references in descriptions route you
to the right one. Run `make deps` once to install both runtimes.
Diffstat (limited to 'playwright-py/scripts/detect_dev_servers.py')
| -rw-r--r-- | playwright-py/scripts/detect_dev_servers.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/playwright-py/scripts/detect_dev_servers.py b/playwright-py/scripts/detect_dev_servers.py new file mode 100644 index 0000000..fb8b1ea --- /dev/null +++ b/playwright-py/scripts/detect_dev_servers.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +"""Probe common localhost ports for running HTTP dev servers. + +Outputs JSON: [{"port": N, "url": "http://localhost:N", "server": "<hint>"}, ...] + +Usage: + python detect_dev_servers.py + python detect_dev_servers.py --ports 3000,5173,8000 + python detect_dev_servers.py --host localhost --ports 8080 +""" + +import argparse +import json +import socket +import sys +import urllib.request + +DEFAULT_PORTS = [3000, 3001, 4200, 5000, 5173, 5500, 8000, 8080, 8888, 9000] + + +def is_port_open(host: str, port: int, timeout: float = 0.3) -> bool: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.settimeout(timeout) + try: + s.connect((host, port)) + return True + except (socket.timeout, ConnectionRefusedError, OSError): + return False + + +def probe_http(url: str, timeout: float = 0.5) -> str | None: + """Return a short hint about the server (e.g. its Server header), or None.""" + try: + req = urllib.request.Request(url, headers={"User-Agent": "detect_dev_servers"}) + with urllib.request.urlopen(req, timeout=timeout) as resp: + server = resp.headers.get("Server", "") + return server or "http" + except Exception: + return None + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--ports", + default=",".join(str(p) for p in DEFAULT_PORTS), + help="Comma-separated port list", + ) + parser.add_argument("--host", default="localhost") + args = parser.parse_args() + + try: + ports = [int(p.strip()) for p in args.ports.split(",") if p.strip()] + except ValueError as err: + print(f"ERROR: bad --ports value: {err}", file=sys.stderr) + return 2 + + results = [] + for port in ports: + if is_port_open(args.host, port): + url = f"http://{args.host}:{port}" + hint = probe_http(url) + if hint is not None: + results.append({"port": port, "url": url, "server": hint}) + + print(json.dumps(results, indent=2)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) |
