项目文件夹

文件
Sarath S Menon 05d6eb8c3e refactor(run): replace heredoc stdin with -c flag (#188)
* fix(js): auto-wrap top-level return expressions in an IIFE

Agents naturally write js() calls with top-level `return`, which is a
syntax error in Runtime.evaluate. js() now detects `return ` and wraps
the expression in an IIFE so both styles work without callers needing
to know the CDP constraint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(run): replace heredoc stdin with -c flag

Drops the <<'PY' heredoc pattern entirely. Agents now pass code via
`browser-harness -c "..."`, which is simpler to construct programmatically
and avoids heredoc quoting pitfalls.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 15:53:37 +05:30

29 行
886 B
Python

import sys
from io import StringIO
from unittest.mock import patch
import run
def test_c_flag_executes_code():
stdout = StringIO()
with patch.object(sys, "argv", ["browser-harness", "-c", "print('hello from -c')"]), \
patch("run.ensure_daemon"), \
patch("run.print_update_banner"), \
patch("sys.stdout", stdout):
run.main()
assert stdout.getvalue().strip() == "hello from -c"
def test_c_flag_does_not_read_stdin():
stdin_read = []
fake_stdin = StringIO("should not be read")
fake_stdin.read = lambda: stdin_read.append(True) or ""
with patch.object(sys, "argv", ["browser-harness", "-c", "x = 1"]), \
patch("run.ensure_daemon"), \
patch("run.print_update_banner"), \
patch("sys.stdin", fake_stdin):
run.main()
assert not stdin_read, "stdin should not be read when -c is passed"