Skip to content

chore: add smoke tests for packages that have entropy patches#133

Open
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/test-entropy-patches
Open

chore: add smoke tests for packages that have entropy patches#133
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/test-entropy-patches

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

Since we are patching these packages. I think it should be useful for us to have test coverage so we don't suddenly break these packages. I found that in newer pydantic-core version (which is available in Python 3.14), our entropy patch doesn't work (#132). I believe these tests will allow us catching those errors when 1) we update Python versions, or when 2) those packages release a new version with breaking changes in entropy.

@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 adds smoke tests for packages that rely on entropy patches, verifying that they survive the workerd snapshot save/restore cycle. The structure follows existing conventions well. One issue stood out.

Comment on lines +13 to +32
import jiter
import pytest
import tiktoken._tiktoken
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.hashes import SHA256

RUST_PACKAGES = ["tiktoken._tiktoken", "cryptography.exceptions", "jiter"]


@pytest.mark.parametrize(
"order",
list(itertools.permutations(RUST_PACKAGES)),
ids=[
"->".join(m.split(".")[0] for m in perm)
for perm in itertools.permutations(RUST_PACKAGES)
],
)
def test_rust_import_permutations(order):
for module_name in order:
__import__(module_name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The top-level imports on lines 13-17 (import jiter, import tiktoken._tiktoken, from cryptography...) mean all three Rust packages are already in sys.modules before any test function runs. __import__() on an already-imported module is a no-op (it returns the cached module), so this parametrized test doesn't actually exercise different import orderings — every permutation does exactly the same thing.

If the goal is to verify that these packages survive the snapshot cycle (imported during snapshotting, usable after restore), the other tests in this file (test_tiktoken_import, test_cryptography_hashing, test_jiter_parse) already cover that. Consider either:

  1. Removing the permutation test since the other tests already cover snapshot survival, or
  2. Moving the Rust package imports out of module scope and into the test body using importlib with sys.modules cleanup if you truly want to test import ordering (though this may be impractical inside workerd).

As-is, the test passes but is misleading about what it validates.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good bot.

@ask-bonk

ask-bonk Bot commented Jun 19, 2026

Copy link
Copy Markdown

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

This PR adds smoke tests for packages that rely on entropy patches, verifying they survive the workerd snapshot save/restore cycle. The overall structure follows existing conventions well (matches the sdk test suite pattern).

I flagged one issue:

  1. test_rust_import_permutations doesn't test what it claims (test_rust_packages.py:22-32) — The three Rust packages are imported at module level (lines 13-17), so by the time the parametrized test runs, all modules are already cached in sys.modules. The __import__() calls are no-ops for every permutation. The other tests in the file (test_tiktoken_import, test_cryptography_hashing, test_jiter_parse) already cover the snapshot survival scenario, making the permutation test redundant and misleading.

github run



def test_aiohttp_http_websocket_import():
assert aiohttp.http_websocket is not None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this do anything? Why would this ever be none?

)
def test_rust_import_permutations(order):
for module_name in order:
__import__(module_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This all runs in the same runtime so it's useless.

Comment on lines +13 to +32
import jiter
import pytest
import tiktoken._tiktoken
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.hashes import SHA256

RUST_PACKAGES = ["tiktoken._tiktoken", "cryptography.exceptions", "jiter"]


@pytest.mark.parametrize(
"order",
list(itertools.permutations(RUST_PACKAGES)),
ids=[
"->".join(m.split(".")[0] for m in perm)
for perm in itertools.permutations(RUST_PACKAGES)
],
)
def test_rust_import_permutations(order):
for module_name in order:
__import__(module_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good bot.

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.

2 participants