fix(testing): harden Flutter test env against host-Python leakage - #6772
Open
FeodorFitsner wants to merge 2 commits into
Open
fix(testing): harden Flutter test env against host-Python leakage#6772FeodorFitsner wants to merge 2 commits into
FeodorFitsner wants to merge 2 commits into
Conversation
Follow-up to #6747, which stripped PYTHONPATH/PYTHONHOME from the `flutter test` subprocess so an IDE-injected debugger/sitecustomize path could not reach the interpreter embedded in the app under test. Two more host-Python knobs reach that interpreter the same way: * PYTHONEXECUTABLE - macOS framework builds use it to seed sys.executable, and a host value points at the IDE's interpreter, not the packaged app's. * PYTHONNOUSERSITE - user site-packages is opt-out, so leaving it unset lets a host ~/.local/lib/pythonX.Y/site-packages whose version matches the embedded interpreter leak in. It is now set rather than removed. The environment is built in a `_flutter_subprocess_env()` helper instead of inline at the call site, which gives the rationale one home and makes the part that is actually testable - which variables are dropped and which survive - unit-testable without launching Flutter. Adds the changelog entry #6747 shipped without.
Deploying flet-website-v2 with
|
| Latest commit: |
5561c64
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f3da3d3d.flet-website-v2.pages.dev |
| Branch Preview URL: | https://fix-flutter-test-env-hardeni.flet-website-v2.pages.dev |
The unit suite runs as `uv run --no-dev --group test`, whose environment has only pytest and pytest-asyncio - numpy, pillow and scikit-image live in the `dev` group. Importing `flet.testing.flet_test_app` therefore fails at collection in CI with `ModuleNotFoundError: No module named 'numpy'`, which is why no unit test imported that subtree before. Move the helper to `flet.utils.environment.without_host_python_config()`, a module with no dependencies beyond the stdlib, and have `flet_test_app` call it. The function never needed anything from `FletTestApp` - it is a pure transform over an environment mapping - and it now takes the mapping as an optional argument, so the tests exercise it without touching `os.environ`. Verified by importing the module with numpy/PIL/skimage blocked on the meta path, reproducing the CI environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #6747 (already merged as a7c7b5e), which stripped
PYTHONPATH/PYTHONHOMEfrom theflutter testsubprocess so an IDE-injected debugger/sitecustomizepath could not reach the interpreter embedded in the app under test.Two more host-Python knobs reach that interpreter through the same mechanism:
PYTHONEXECUTABLE- macOS framework builds use it to seedsys.executable; a host value points at the IDE's interpreter, not the packaged app's. Now removed.PYTHONNOUSERSITE- user site-packages is opt-out, so leaving it unset lets a host~/.local/lib/pythonX.Y/site-packageswhose version matches the embedded interpreter leak in exactly the way fix(testing): prevent host Python env from leaking into Flutter tests #6747 set out to prevent. Now set to1rather than removed.The environment is built in a
_flutter_subprocess_env()helper instead of inline at the call site. That gives the rationale one home, parallels_flutter_path_envinflet_cli.commands.test(which builds the env for the pytest subprocess), and makes the part that is actually testable - which variables are dropped and which survive - unit-testable without launching Flutter.PATH, and everyFLET_*andSERIOUS_PYTHON_*variable the native build phase needs, remain untouched.Also adds the changelog entry #6747 shipped without, credited to @PythBuster.
Test code
packages/flet/tests/test_flet_test_app_env.pycovers a host environment shaped like an IDE-launched pytest run:asserting the three variables are stripped,
PYTHONNOUSERSITE=1is set, the build variables survive verbatim, absent variables don't raise, andos.environitself is not mutated.uv run --group test pytest packages/flet/tests- 232 passed, 8 skipped.Type of change
Checklist
website/sidebars.ymlfor breaking changes, removals, and deprecations, if applicable.Additional details
Unverified by a real device run: the
PYTHONNOUSERSITE/PYTHONEXECUTABLEcases are reasoned from CPython's initialization behaviour rather than reproduced, since triggering them needs a host user site directory matching the embedded interpreter's version. The originalPYTHONPATHfailure in #6747 is direct evidence that this class of variable does reach the embedded interpreter.Separately, the entry for #6769 landed under
## 0.86.6instead of the unreleased## 0.86.7section - looks like a stale-branch merge artifact, left alone here.Summary by Sourcery
Prevent host Python configuration from leaking into the Flutter integration test app environment and add coverage and changelog entry for the behavior.
Bug Fixes:
flutter testsubprocess environment and disabling user site-packages.Enhancements:
flutter testsubprocess environment in a dedicated helper for clearer rationale and testability.Documentation:
Tests:
PYTHONNOUSERSITE, and does not mutateos.environ.