Skip to content

added the missing tests (and verified they pass)#6170

Merged
masenf merged 4 commits intoreflex-dev:mainfrom
patrizzzz:my-contribution
May 8, 2026
Merged

added the missing tests (and verified they pass)#6170
masenf merged 4 commits intoreflex-dev:mainfrom
patrizzzz:my-contribution

Conversation

@patrizzzz
Copy link
Copy Markdown
Contributor

@patrizzzz patrizzzz commented Mar 11, 2026

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.

b. Describe your changes.

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 11, 2026

Greptile Summary

This PR replaces two no-op test stubs with real implementations: one for compile_state (covering both the no-running-loop and the running-loop code paths), and one for test_app_with_optional_endpoints (verifying upload route and static-files mount registration).

  • test_compiler_utils.py introduces CompileStateState and two tests that confirm compile_state resolves async computed vars in both event-loop contexts; the @pytest.mark.asyncio marker on the async test is redundant since the project runs with asyncio_mode = "auto".
  • test_app.py implements real route-presence assertions and correctly uses a monkeypatch-based upload_enabled fixture for safe cleanup; the upload_path variable should use config.prepend_backend_path(...) to stay accurate when backend_path is configured.

Confidence Score: 5/5

Safe to merge — both changed files are test-only additions with no production code impact.

The changes add real test coverage where stubs existed before. The route-path comparison and the redundant asyncio marker are minor nits that won't cause CI failures under default configuration, and no production logic is touched.

No files require special attention; both changed files are test-only.

Important Files Changed

Filename Overview
tests/units/compiler/test_compiler_utils.py Replaces a no-op stub with real tests for compile_state; covers both the no-loop and the running-loop code paths. @pytest.mark.asyncio is redundant given asyncio_mode = "auto" in pyproject.toml.
tests/units/test_app.py Implements the previously stubbed test_app_with_optional_endpoints with proper route assertions and a monkeypatch fixture for safe Upload.is_used cleanup. Route path comparison uses str(constants.Endpoint.UPLOAD) directly instead of config.prepend_backend_path(...), which could silently mismatch if backend_path is configured.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[compile_state called] --> B{Running event loop?}
    B -- No --> C[asyncio.run _resolve_delta]
    B -- Yes --> D[ThreadPoolExecutor]
    D --> E[asyncio.run in thread]
    C --> F[Return sorted state dict]
    E --> F

    G[test without loop] --> A
    H[test with loop] --> A
Loading

Reviews (2): Last reviewed commit: "Apply suggestion from @greptile-apps[bot..." | Re-trigger Greptile

Comment thread tests/units/test_app.py Outdated
Comment on lines +1697 to +1698
)
Upload.is_used = False
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.

Fragile cleanup – Upload.is_used not reset on test failure

Upload.is_used = False is placed after the with chdir(tmp_path): block without a try/finally guard. If either assert any(...) call on lines 1688–1696 raises an AssertionError, the cleanup line never executes and Upload.is_used is left as True for subsequent tests. Wrap the assertions in try/finally or, preferably, use the existing monkeypatch fixture for test-scoped teardown:

Suggested change
)
Upload.is_used = False
finally:
Upload.is_used = False

Or, restructure the test to use the monkeypatch fixture:

def test_app_with_optional_endpoints(tmp_path: Path, monkeypatch):
    from reflex.components.core.upload import Upload
    from starlette.routing import Mount, Route

    monkeypatch.setattr(Upload, "is_used", False)
    with chdir(tmp_path):
        app = App()
        monkeypatch.setattr(Upload, "is_used", True)
        app._add_optional_endpoints()
        ...

Using monkeypatch guarantees restoration to the original value regardless of how the test exits.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i suggest setting Upload.is_used with monkeypatch inside a fixture that this test depends on, that way the clean up and test logic are cleanly separated

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 call – that's cleaner. Here's how it would look:

Suggested change
)
Upload.is_used = False
@pytest.fixture
def upload_component(monkeypatch):
from reflex.components.core.upload import Upload
monkeypatch.setattr(Upload, "is_used", False)
yield Upload
def test_app_with_optional_endpoints(tmp_path: Path, upload_component):
from starlette.routing import Mount, Route
with chdir(tmp_path):
app = App()
upload_component.is_used = True
app._add_optional_endpoints()
assert app._api is not None
upload_path = str(constants.Endpoint.UPLOAD)
routes = list(app._api.routes)
assert any(
isinstance(r, Route)
and r.path == upload_path
and "POST" in getattr(r, "methods", set())
for r in routes
)
assert any(
isinstance(r, Mount) and r.path == upload_path and r.name == "uploaded_files"
for r in routes
)

The fixture ensures Upload.is_used is False initially and handles cleanup automatically, while the test logic stays focused on the actual behavior being tested.

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.

Actually, I can't provide this as an inline suggestion because:

  1. The fixture needs to be placed before the test function
  2. The comment is only on lines 1697-1698 (the function signature)
  3. Inline suggestions only modify the exact lines the comment is attached to

Here's the pattern you should use:

@pytest.fixture
def upload_enabled(monkeypatch):
    """Fixture that enables Upload and cleans up afterward."""
    from reflex.components.core.upload import Upload
    
    monkeypatch.setattr(Upload, "is_used", True)
    yield
    monkeypatch.setattr(Upload, "is_used", False)


def test_app_with_optional_endpoints(tmp_path: Path, upload_enabled):
    from reflex.components.core.upload import Upload
    from starlette.routing import Mount, Route

    with chdir(tmp_path):
        app = App()
        app._add_optional_endpoints()

        assert app._api is not None
        upload_path = str(constants.Endpoint.UPLOAD)
        routes = list(app._api.routes)

        assert any(
            isinstance(r, Route)
            and r.path == upload_path
            and "POST" in getattr(r, "methods", set())
            for r in routes
        )
        assert any(
            isinstance(r, Mount) and r.path == upload_path and r.name == "uploaded_files"
            for r in routes
        )

Place the upload_enabled fixture above the test function. The fixture handles both setup and teardown automatically, keeping the test logic clean.

Comment thread tests/units/compiler/test_compiler_utils.py
Copy link
Copy Markdown
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

thanks for adding the test cases

Comment thread tests/units/test_app.py Outdated
Comment on lines +1697 to +1698
)
Upload.is_used = False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i suggest setting Upload.is_used with monkeypatch inside a fixture that this test depends on, that way the clean up and test logic are cleanly separated

@masenf masenf requested a review from a team as a code owner May 7, 2026 20:14
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@masenf
Copy link
Copy Markdown
Collaborator

masenf commented May 7, 2026

@greptile-apps re-review

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 7, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing patrizzzz:my-contribution (f34e741) with main (2df5344)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@masenf masenf merged commit be03058 into reflex-dev:main May 8, 2026
67 of 69 checks passed
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