diff --git a/wynd/src/wynd/cli.py b/wynd/src/wynd/cli.py index e5f706e..b6912f5 100644 --- a/wynd/src/wynd/cli.py +++ b/wynd/src/wynd/cli.py @@ -245,6 +245,13 @@ def run_wrangler(flow: str) -> int: "and compatibility_flags in the Wrangler config." ) return 1 + if flow == "dev" and dev_remote(args): + error( + "wynd dev --remote is not supported for Python Workers. Use remote " + "bindings instead: " + "https://developers.cloudflare.com/workers/development-testing/#remote-bindings" + ) + return 1 try: project = load_selected_project() @@ -284,6 +291,17 @@ def run_wrangler(flow: str) -> int: return code +def dev_remote(args: list[str]) -> bool: + """Whether `args` turn on wrangler dev's --remote, as Wrangler reads it: + a bare -r or --remote unless `false` follows, or a value of exactly `true`.""" + flags = args[: args.index("--")] if "--" in args else args + following = [*flags[1:], None] + return any( + (arg in ("--remote", "-r") and after != "false") or arg == "--remote=true" + for arg, after in zip(flags, following, strict=True) + ) + + def restage(cwd: Path, config: str | None, mode: str | None) -> None: """Stage an edited config again, so the running wrangler dev reloads. diff --git a/wynd/tests/test_dev.py b/wynd/tests/test_dev.py index ca0cb1f..0865d5d 100644 --- a/wynd/tests/test_dev.py +++ b/wynd/tests/test_dev.py @@ -495,3 +495,45 @@ def test_flags_that_change_the_target_are_refused( assert "compatibility_date" in capsys.readouterr().err assert tools.uv() == [] assert tools.wrangler() == [] + + +@pytest.mark.parametrize( + "flags", + [ + ["--remote"], + ["-r"], + ["--port", "8787", "--remote"], + ["--remote", "--port", "8787"], + ["--remote=true"], + ["--remote", "true"], + ], +) +def test_dev_remote_is_refused( + tools: Tools, + project: Path, + capsys: pytest.CaptureFixture[str], + flags: list[str], +) -> None: + assert main(["dev", *flags]) == 1 + + assert "remote bindings" in capsys.readouterr().err + assert tools.uv() == [] + assert tools.wrangler() == [] + + +@pytest.mark.parametrize( + "flags", + [ + ["--remote", "false"], + ["-r", "false"], + ["--remote=false"], + ["--remote=1"], + ["--", "--remote"], + ], +) +def test_dev_remote_turned_off_runs_wrangler( + tools: Tools, project: Path, flags: list[str] +) -> None: + assert main(["dev", *flags]) == 0 + + assert tools.wrangler() == [["dev", *flags, "--config", staged_path(project)]] diff --git a/wynd/tests/test_passthrough.py b/wynd/tests/test_passthrough.py index 4503b30..54970bc 100644 --- a/wynd/tests/test_passthrough.py +++ b/wynd/tests/test_passthrough.py @@ -40,3 +40,12 @@ def test_missing_npx_names_nodejs( assert main(["whoami"]) == 1 assert "Node.js" in capsys.readouterr().err + + +def test_remote_is_left_to_wrangler_outside_dev(tools: Tools) -> None: + args = ["d1", "execute", "db", "--remote"] + + assert main(args) == 0 + assert [call["args"] for call in tools.calls("npx")] == [ + ["--yes", "wrangler@4.129.0", *args] + ]