Repository navigation
Do not scan vendored packages that refuse to import on our floor - #8252
Conversation
tests/test_python39_compatibility.py is a hard gate in Core CI and it is currently red on main for every open PR: studio/backend/vendor/truststore/_api.py:30: str | bytes (type alias) studio/backend/vendor/truststore/_api.py:31: str | bytes | ... (type alias) Those unions cannot be reached on 3.9. truststore/__init__.py raises ImportError below 3.10, and its only caller wraps the import in try/except, so the package is gone before _api.py is ever loaded. Skip files under a package whose __init__ declares a floor above ours, keyed on the guard rather than the path so unguarded code added to the same vendor directory is still scanned.
ada6416 to
4a2e261
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ada6416ed6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if "__pycache__" not in p.parts and "node_modules" not in p.parts | ||
| if "__pycache__" not in p.parts | ||
| and "node_modules" not in p.parts | ||
| and not any(d in p.parents for d in skip) |
There was a problem hiding this comment.
Keep the guarded initializer in the floor-syntax scan
When a guarded package's own __init__.py uses syntax newer than the declared floor, guarded_floor() can parse it on the current CI interpreter and this predicate then excludes the initializer itself. The version guard cannot protect such syntax because Python must compile __init__.py before executing the guard; for example, adding a match statement after the 3.10 guard makes this test scan no files while importing on 3.9 fails before the ImportError. Exclude only descendants of the guarded package, while retaining its initializer in the parse/compile checks.
Useful? React with 👍 / 👎.
| if "__pycache__" not in p.parts and "node_modules" not in p.parts | ||
| if "__pycache__" not in p.parts | ||
| and "node_modules" not in p.parts | ||
| and not any(d in p.parents for d in skip) |
There was a problem hiding this comment.
Check guarded descendants on their supported floor
On Python 3.10 and later the truststore guard does not raise, so every descendant remains reachable and must at least parse on the package's guarded floor. Excluding the entire directory from every package_files() consumer means a future vendored child that requires 3.11 syntax—or does not compile at all—passes both the declared-floor parser and test_every_packaged_module_compiles, yet Studio's native-TLS import fails on supported Python 3.10. Scan descendants using their detected guarded floor rather than omitting them wholesale.
Useful? React with 👍 / 👎.
The red
tests/test_python39_compatibility.pyruns as thepython floor compatibility (HARD GATE)step inconsolidated-tests-ci.yml. On current main it fails on all threeCorematrices, so every open PR is red through no fault of its own:Two tests fail:
test_studio_evaluated_unions_do_not_growandtest_no_pep604_unions_are_evaluated_on_the_declared_floor. The files arrived with #8108 as vendored third-party code.Why it is a false positive
studio/backend/vendor/truststore/__init__.pyopens withso
_api.pycannot be reached on our 3.9 floor: the package raises before that module loads. The sole caller,studio/backend/utils/native_tls.py:79, wrapsimport truststoreintry/except Exception: pass, so the raise is already handled. The unions the gate is pointing at can never evaluate.The change
package_files()now skips files under a package whose__init__.pydeclares a floor above ours.The exemption is keyed on the guard, not on the path. A blanket
vendor/exclusion would have been shorter, but it would silently stop scanning any unguarded code later dropped into the same directory, and it would keep the exemption alive if upstream ever removes the version guard, at which point the unions really would be reachable and the gate should go red again.The guard must both compare
version_infoagainst a tuple above our floor and actuallyraise. Awarnings.warnunder the same condition still imports, so it does not exempt.Verification
2 failed, 2 passedbefore,8 passedafter, plus four tests covering the exemption itself. Three mutations, each run with cleared bytecode:package_filesraiseruff checkclean;scripts/run_ruff_format.pyunder the pinned ruff 0.6.9 touches only the added lines.