Skip to content

chore: fix rpc test not collected#137

Open
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/rpc-dead-code
Open

chore: fix rpc test not collected#137
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/rpc-dead-code

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

I noticed that python-rpc/worker.py tests were not running at all because it had a global test function which we deprecated.

This migrates it to test method under the WorkerEntrypoint class.

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm Bonk, and I've done a quick review of your PR.

This PR migrates the RPC test from a deprecated global test handler to a test method on the Default(WorkerEntrypoint) class, and fixes assert_equal to accept dict subclasses.

Issues

  1. Medium: Two test cases silently dropped. The old code tested that passing a lambda and a named def my_func to env.PythonRpc.identity() raises TypeError. These were removed without explanation. If they were dropped intentionally (e.g. the def inside with block was problematic), it would be good to note why — otherwise they should be kept.

with assertRaises(TypeError):
await env.PythonRpc.identity(js.RegExp.new("ab+c", "i"))
with assertRaises(TypeError):
await env.PythonRpc.identity({"test": (1, 2, 3)})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two test cases from the original code are missing here. The old version also verified that passing a lambda and a named function raises TypeError:

Suggested change
await env.PythonRpc.identity({"test": (1, 2, 3)})
with assertRaises(TypeError):
await env.PythonRpc.identity({"test": (1, 2, 3)})
with assertRaises(TypeError):
await env.PythonRpc.identity(lambda x: x + x)

The old code also had a def my_func case, but defining a function inside a with block is awkward. The lambda test alone covers this — though if the omission was intentional, a comment explaining why would be helpful.

@ask-bonk

ask-bonk Bot commented Jun 22, 2026

Copy link
Copy Markdown

I'm Bonk, and I've done a quick review of your PR.

This PR migrates the RPC test from a deprecated global test handler to a test method on the Default(WorkerEntrypoint) class, and fixes assert_equal to accept dict subclasses.

I found one actionable issue and posted a review comment on the PR:

  1. Medium: Two test cases silently dropped. The old code verified that passing a lambda and a named function (def my_func) to env.PythonRpc.identity() raises TypeError. These were removed in the migration without explanation. I posted a suggestion to restore at least the lambda test case at worker.py:293.

The rest of the changes (structural migration to class method, handler import removal, js_map[1] -> js_map["1"] key fix, assert_equal relaxation for dict subclasses) all look correct.

github run

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Hide Whitespace when reviewing. The diff is actually very small but looks big because of the whitespace.

"Expected the returned value from RPC to be a Python type."
assert isinstance(js_map, dict)
# js.Map ==> dict ==> js.Object
assert js_map["1"] == "one"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a breaking change we introduced in #112 (js.Map ==> js.Object)

# TODO: Support RegExp.
with assertRaises(TypeError):
await env.PythonRpc.identity(js.RegExp.new("ab+c", "i"))
with assertRaises(TypeError):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now support passing functions to rpc boundary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant