mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-03-17 02:43:09 +00:00
feat: migrate browser automation from Playwright MCP to CLI, fix headless setting
Major changes across 21 files (755 additions, 196 deletions): Browser Automation Migration: - Add versioned project migration system (prompts.py) with content-based detection and section-level regex replacement for coding/testing prompts - Migrate STEP 5 (browser verification) and BROWSER AUTOMATION sections in coding prompt template to use playwright-cli commands - Migrate STEP 2 and AVAILABLE TOOLS sections in testing prompt template - Migration auto-runs at agent startup (autonomous_agent_demo.py), copies playwright-cli skill, scaffolds .playwright/cli.config.json, updates .gitignore, and stamps .migration_version file - Add playwright-cli command validation to security allowlist (security.py) with tests for allowed subcommands and blocked eval/run-code Headless Browser Setting Fix: - Add _apply_playwright_headless() to process_manager.py that reads/updates .playwright/cli.config.json before agent subprocess launch - Remove dead PLAYWRIGHT_HEADLESS env var that was never consumed - Settings UI toggle now correctly controls visible browser window Playwright CLI Auto-Install: - Add ensurePlaywrightCli() to lib/cli.js for npm global entry point - Add playwright-cli detection + npm install to start.bat, start.sh, start_ui.bat, start_ui.sh for all startup paths Other Improvements: - Add project folder path tooltip to ProjectSelector.tsx dropdown items - Remove legacy Playwright MCP server configuration from client.py - Update CLAUDE.md with playwright-cli skill documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@ from security import (
|
||||
validate_chmod_command,
|
||||
validate_init_script,
|
||||
validate_pkill_command,
|
||||
validate_playwright_command,
|
||||
validate_project_command,
|
||||
)
|
||||
|
||||
@@ -923,6 +924,70 @@ pkill_processes:
|
||||
return passed, failed
|
||||
|
||||
|
||||
def test_playwright_cli_validation():
|
||||
"""Test playwright-cli subcommand validation."""
|
||||
print("\nTesting playwright-cli validation:\n")
|
||||
passed = 0
|
||||
failed = 0
|
||||
|
||||
# Test cases: (command, should_be_allowed, description)
|
||||
test_cases = [
|
||||
# Allowed cases
|
||||
("playwright-cli screenshot", True, "screenshot allowed"),
|
||||
("playwright-cli snapshot", True, "snapshot allowed"),
|
||||
("playwright-cli click e5", True, "click with ref"),
|
||||
("playwright-cli open http://localhost:3000", True, "open URL"),
|
||||
("playwright-cli -s=agent-1 click e5", True, "session flag with click"),
|
||||
("playwright-cli close", True, "close browser"),
|
||||
("playwright-cli goto http://localhost:3000/page", True, "goto URL"),
|
||||
("playwright-cli fill e3 'test value'", True, "fill form field"),
|
||||
("playwright-cli console", True, "console messages"),
|
||||
# Blocked cases
|
||||
("playwright-cli run-code 'await page.evaluate(() => {})'", False, "run-code blocked"),
|
||||
("playwright-cli eval 'document.title'", False, "eval blocked"),
|
||||
("playwright-cli -s=test eval 'document.title'", False, "eval with session flag blocked"),
|
||||
]
|
||||
|
||||
for cmd, should_allow, description in test_cases:
|
||||
allowed, reason = validate_playwright_command(cmd)
|
||||
if allowed == should_allow:
|
||||
print(f" PASS: {cmd!r} ({description})")
|
||||
passed += 1
|
||||
else:
|
||||
expected = "allowed" if should_allow else "blocked"
|
||||
actual = "allowed" if allowed else "blocked"
|
||||
print(f" FAIL: {cmd!r} ({description})")
|
||||
print(f" Expected: {expected}, Got: {actual}")
|
||||
if reason:
|
||||
print(f" Reason: {reason}")
|
||||
failed += 1
|
||||
|
||||
# Integration test: verify through the security hook
|
||||
print("\n Integration tests (via security hook):\n")
|
||||
|
||||
# playwright-cli screenshot should be allowed
|
||||
input_data = {"tool_name": "Bash", "tool_input": {"command": "playwright-cli screenshot"}}
|
||||
result = asyncio.run(bash_security_hook(input_data))
|
||||
if result.get("decision") != "block":
|
||||
print(" PASS: playwright-cli screenshot allowed via hook")
|
||||
passed += 1
|
||||
else:
|
||||
print(f" FAIL: playwright-cli screenshot should be allowed: {result.get('reason')}")
|
||||
failed += 1
|
||||
|
||||
# playwright-cli run-code should be blocked
|
||||
input_data = {"tool_name": "Bash", "tool_input": {"command": "playwright-cli run-code 'code'"}}
|
||||
result = asyncio.run(bash_security_hook(input_data))
|
||||
if result.get("decision") == "block":
|
||||
print(" PASS: playwright-cli run-code blocked via hook")
|
||||
passed += 1
|
||||
else:
|
||||
print(" FAIL: playwright-cli run-code should be blocked via hook")
|
||||
failed += 1
|
||||
|
||||
return passed, failed
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 70)
|
||||
print(" SECURITY HOOK TESTS")
|
||||
@@ -991,6 +1056,11 @@ def main():
|
||||
passed += pkill_passed
|
||||
failed += pkill_failed
|
||||
|
||||
# Test playwright-cli validation
|
||||
pw_passed, pw_failed = test_playwright_cli_validation()
|
||||
passed += pw_passed
|
||||
failed += pw_failed
|
||||
|
||||
# Commands that SHOULD be blocked
|
||||
# Note: blocklisted commands (sudo, shutdown, dd, aws) are tested in
|
||||
# test_blocklist_enforcement(). chmod validation is tested in
|
||||
@@ -1012,6 +1082,9 @@ def main():
|
||||
# Shell injection attempts
|
||||
"$(echo pkill) node",
|
||||
'eval "pkill node"',
|
||||
# playwright-cli dangerous subcommands
|
||||
"playwright-cli run-code 'await page.goto(\"http://evil.com\")'",
|
||||
"playwright-cli eval 'document.cookie'",
|
||||
]
|
||||
|
||||
for cmd in dangerous:
|
||||
@@ -1077,6 +1150,12 @@ def main():
|
||||
"/usr/local/bin/node app.js",
|
||||
# Combined chmod and init.sh (integration test for both validators)
|
||||
"chmod +x init.sh && ./init.sh",
|
||||
# Playwright CLI allowed commands
|
||||
"playwright-cli open http://localhost:3000",
|
||||
"playwright-cli screenshot",
|
||||
"playwright-cli snapshot",
|
||||
"playwright-cli click e5",
|
||||
"playwright-cli -s=agent-1 close",
|
||||
]
|
||||
|
||||
for cmd in safe:
|
||||
|
||||
Reference in New Issue
Block a user