Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions wynd/src/wynd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.

Expand Down
42 changes: 42 additions & 0 deletions wynd/tests/test_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]]
9 changes: 9 additions & 0 deletions wynd/tests/test_passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
]
Loading