Repository navigation
Conversation
The fallback for `--grid` without a version calls `find_best_driver_from_cache`, and that lookup matches cache entries with the shared `is_driver` matcher in `rust/src/lib.rs`. The matcher looks for the driver name plus the binary extension: `selenium-server` on Linux and `selenium-server.exe` on Windows. The cached artifact is `selenium-server-<version>.jar`, so the suffix match finds nothing on either platform. macOS uses a `contains` match, which is why the lookup works there. `GridManager` now overrides `is_driver` and accepts a file whose name starts with `selenium-server-` and ends with `.jar`. The shared matcher that every browser driver uses keeps its behaviour. Fixes SeleniumHQ#18391
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Code Review by Qodo
1. Nightly fallback can run a stable Grid jar
|
find_latest_from_cache returns the last file of a WalkDir walk sorted by file name, so the comparison is lexicographic. With grid/4.9.0 and grid/4.54.0 both cached, the string 4.9.0 sorts after 4.54.0, so the older jar wins. GridManager now overrides find_best_driver_from_cache. It collects the cached jars and compares the version in each parent directory as numbers. The shared lookup keeps its behaviour, and it still handles a jar outside a version-named directory. The new test caches 4.9.0 and 4.54.0 and asserts that 4.54.0 is returned. Fixes the review finding on SeleniumHQ#18392.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
I pushed 1023cda to answer the review finding. Change. Test. Gates on 1023cda (Windows 11, Rust 1.99.1):
The branch is ready for another review on 1023cda. |
|
Code review by qodo was updated up to the latest commit 1023cda |
|
One gap: the fallback also runs when a version is requested, so --grid 4.10.0 --offline silently returns a different cached jar. Can you disable fallback_driver_from_cache in GridManager::new when a version is given, and tighten grid_error_test to require DATAERR? |
version_from_dir_name parsed every dot-separated part as a number, so a 4.55.0-SNAPSHOT directory returned nothing and its jar was skipped. An offline nightly request then ran a stable jar from the cache. The directory name now yields the numeric parts plus a snapshot flag. A snapshot outranks a stable jar of the same numeric version. When the requested version is nightly, the newest cached snapshot wins over a newer stable jar. Four regression tests cover the ranking. Three of them fail on the previous commit.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit ca5ea7d |
A pinned Grid version now disables the cache fallback. An offline request for a version that is not cached returns DATAERR. It no longer returns a different cached jar. An empty version, "nightly", "canary" and "latest" name a moving target. These keep the fallback. The fallback also treats a resolved "-SNAPSHOT" version as a nightly request. Setup resolves a nightly request to a concrete snapshot version. If that download then fails, the fallback prefers a cached snapshot over a newer stable jar. Tighten grid_error_test to require the DATAERR exit code. Add a regression test for the resolved nightly fallback.
|
Addressed both review findings in 3d50151. A pinned version no longer uses the cache fallback (@titusfortner)
I tightened A resolved nightly version keeps its snapshot (qodo finding)
Local results
The new test fails without the snapshot fix, so it covers the finding. @titusfortner Could you review this again when you have a moment? Thanks. |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
bonigarcia
left a comment
There was a problem hiding this comment.
Thanks, the is_driver fix and the numeric ordering look right. A few changes before merging:
- (Medium) A plain
--gridcan return a nightly.bestranks snapshots with stable jars, so with4.54.0and4.55.0-SNAPSHOTcached, the fallback returns the snapshot. Online resolution excludes snapshots. The tie rule is also inverted:4.54.0-SNAPSHOTprecedes4.54.0. Please skip snapshots, including in the finalfind_latest_from_cachecall, and replace the two tests that expect the snapshot to win with one that expects the stable jar. - (Medium) I'd only fall back when no version is given.
latestisn't a supported Grid version:setup()never resolves it, so this turns an error into success with an arbitrary cached jar. Anightlyrequest can also return a stable jar, which isn't what was asked for.config.fallback_driver_from_cache = driver_version.is_empty()fixes both, stays within the scope of #18391, and lets you dropwant_snapshot,best_snapshotand the three nightly-request tests. An unexpired metadata entry or an exactx.y.z-SNAPSHOTversion still finds a cached nightly. One trade-off: on macOS the fallback currently works fornightly, so that would change. @titusfortner, does that match what you had in mind? - (Medium) Please test through the CLI. With a fake jar in a temp
--cache-path(no network needed):--grid --offlinereturns the jar, and--grid 4.10.0 --offlinewith only4.54.0cached returns an emptydriver_path. Please also givegrid_error_testa temp cache that already holds a jar; with a cold cache it passes without the fix. - (Low) An uncached pinned version doesn't return DATAERR with
--offline; it exits OK with an emptydriver_path. Ruby relies on that, so no code change is needed. - (Low)
--grid --driver-version 4.10.0bypasses the check, since the version is set afternew().
The offline fallback applies only when the request names no version, because a named version must resolve to that exact jar. An empty version is the only case that can use a cached jar. A request for nightly or latest no longer falls back, so the resolved snapshot case is gone. The fallback now skips SNAPSHOT directories in the version ranking and in the shared cache lookup. A plain request can no longer run a cached nightly build. Replace the nightly and snapshot ranking tests with one stable jar test. Add two CLI tests that use a temporary cache. Run grid_error_test against a warm cache.
|
Thanks. I pushed 9f50eae to address the three middle items. 1. Snapshots are skipped. The cache fallback now parses only stable version directories. It skips any directory name that ends with SNAPSHOT, in both the version ranking and the final 2. The fallback needs an empty version. 3. CLI coverage. 4. No code change. I confirmed that an uncached pinned version exits OK with an empty 5. Known gap. Gates on 9f50eae: Could you take another look when you have time? |
The offline cache fallback for Grid now runs only when no version is requested. Snapshot jars are skipped both in version-directory ranking and in the legacy lookup for jars outside a version-named directory, checking both the parent directory name and the jar file name. When --driver-version is supplied with --grid on the CLI, recompute the cache-fallback gate after applying the driver version so an explicit CLI driver version clears the gate instead of falling back to a cached jar.
|
Follow-up on item 5 in the review. It is fixed in
I also closed one edge case in the same pass. A jar can sit outside a version-named directory. The final Item 4 needs no code change, as you wrote. Gates on The PR body now describes the current rules and the current test list. Could you take another look when you have time? |
|
Thanks, all five points are addressed, and fixing the One small thing: in |
--browser and --driver take precedence over --grid when main selects a manager. The fallback gate now asks the manager, so a browser request keeps its cache fallback when --grid is also present.
|
Pushed 395338b. Change. Gates. The CI and CI - RBE workflows show |
| for jar in jars { | ||
| let Some(version) = jar.parent().and_then(version_from_dir_name) else { | ||
| continue; | ||
| }; |
There was a problem hiding this comment.
3. Offline grid can select a snapshot jar 🐞 Bug ≡ Correctness
find_best_driver_from_cache ranks jars by their numeric parent directory without checking the filename for SNAPSHOT. If a snapshot jar sits in a stable-version directory, the ranked path returns it before the legacy lookup's snapshot filename filter runs.
Agent Prompt
## Issue description
The ranked Grid cache lookup can return a snapshot jar from a numeric version directory because it checks only the directory name.
## Fix Focus Areas
- rust/src/grid.rs[311-359]
- rust/tests/grid_tests.rs[208-229]
## Recommended Fix
Exclude snapshot filenames from the ranked candidates, and verify that a jar in a numeric version directory names the same version as that directory. Add a regression test with a snapshot jar inside a stable-version directory.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Fixed in 36a6c04.
You are right. The ranked loop trusted the parent directory name. It never checked the jar file name, so a snapshot jar inside a stable-named directory could win. The legacy lookup already rejected that file name.
find_best_driver_from_cache now parses the version from the jar file name and requires it to equal the version in the parent directory. A snapshot file name does not parse as a numeric version, so the same guard skips it. A mismatched jar is also skipped.
grid_cache_fallback_skips_snapshot_jar_in_stable_dir_test caches grid/4.54.0/selenium-server-4.55.0-SNAPSHOT.jar and expects no result. grid_cache_fallback_requires_jar_name_to_match_dir_test caches a mismatched 4.54.0 entry beside a correct 4.53.0 entry, and expects the 4.53.0 jar.
Probe: with the guard stashed, cargo test --test grid_tests grid_cache_fallback reports 8 passed and 2 failed. With the guard, it reports 10 passed.
The name is safe to trust because get_driver_path_in_cache writes {GRID_RELEASE}-{driver_version}.{GRID_EXTENSION} inside a {driver_version} directory.
|
Code review by qodo was updated up to the latest commit 395338b |
Require the version parsed from the cached Grid jar file name to equal the numeric version parsed from its parent directory during ranked lookup. This rejects snapshot jars placed in stable directories and mismatched jars whose file name disagrees with their parent directory.
|
Pushed four follow-ups to Qodo findings: 36a6c04, b42da79, 898e12d and f970aed. 36a6c04. b42da79. Both scans start at the Grid cache directory, not the cache root. A matching jar in another cache directory is never returned. 898e12d. The legacy lookup covers only a jar outside a version-named directory. A jar inside one is handled by the ranked pass alone, so a mismatched jar cannot come back through the legacy path. f970aed. Comment text only. It states why the legacy pass skips version-named directories. Tests. Four new tests. Each one fails with its source change stashed and passes with it. Gates on f970aed. One Qodo item was a false positive. It said CI. The new head needs a maintainer approval for the fork workflows again, the same as each earlier head. The committer check passed, so the job reports as The fallback gate and the five review items are unchanged on this head. The PR body lists the file-name rule, the Grid-subtree scope, the legacy rule and all twelve fallback tests. |
| let cache_path = self.get_cache_path()?.unwrap_or_default(); | ||
| let jars = collect_files_from_cache(&cache_path, |entry| self.is_driver(entry)); |
There was a problem hiding this comment.
3. Grid can use another cache's server jar 🐞 Bug ≡ Correctness
find_best_driver_from_cache collects candidates from the entire cache root, while its ranked checks validate only the jar’s immediate parent and filename. With other/4.54.0/selenium-server-4.54.0.jar in that root, an unversioned Grid request can report that unrelated path as its driver when setup falls back.
Agent Prompt
## Issue description
The new Grid cache lookup can select a matching jar from a non-Grid subtree of the configured cache.
## Fix Focus Areas
- rust/src/grid.rs[327-367]
- rust/tests/grid_tests.rs[118-196]
## Recommended Fix
Scope both ranked and legacy scans to the `grid` cache subtree, preserving the supported legacy layout within that subtree. Add a test with a matching jar under another cache directory and no Grid jar.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Fixed in b42da79.
You are right. The ranked scan started at the cache root, so a jar under a sibling directory could match the name and version checks.
Both scans now resolve the Grid cache directory as the cache root joined with the manager's browser name. The ranked scan and the legacy lookup both use that path. The legacy layout within the Grid subtree still works, so a jar directly under grid is still considered.
grid_cache_fallback_ignores_jar_in_other_cache_dir_test puts other/4.54.0/selenium-server-4.54.0.jar in the cache root with no Grid jar, and expects no result.
Probe: with the scope change stashed, cargo test --test grid_tests grid_cache_fallback reports 10 passed and 1 failed. With the change, it reports 11 passed.
|
Code review by qodo was updated up to the latest commit 36a6c04 |
Resolve the Grid cache directory from the cache root and browser name. Use that subdirectory for both the ranked scan and the legacy fallback. Add a regression test to ensure jars in sibling cache directories are ignored.
| // while never returning a jar from a SNAPSHOT directory. | ||
| find_latest_from_cache(&grid_cache_path, |entry| { | ||
| self.is_driver(entry) | ||
| && !entry.path().parent().is_some_and(is_snapshot_dir) |
There was a problem hiding this comment.
3. Offline grid can return a mismatched jar 🐞 Bug ≡ Correctness
find_best_driver_from_cache rejects a jar whose filename version disagrees with its parent directory during ranking, but the legacy lookup does not enforce that check. If the cache contains only grid/4.54.0/selenium-server-4.9.0.jar, the legacy lookup returns that rejected jar and the offline CLI reports it as a successful fallback.
Agent Prompt
## Issue description
The legacy fallback accepts jars in version-named directories even when the jar version disagrees with the directory version, undoing the ranked lookup's validation.
## Fix Focus Areas
- rust/src/grid.rs[361-370]
- rust/tests/grid_tests.rs[360-384]
## Recommended Fix
Allow the legacy lookup only for jars outside version-named directories, while preserving the snapshot exclusions. Add a test with a mismatched jar as the only cached candidate and assert that no jar is returned.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Fixed in 898e12d.
You are right. The ranked pass enforced the file-name rule, and the legacy pass did not. A cache that held only the mismatched jar could still return it.
The legacy filter now also requires that the jar's parent is not a version-named directory. That is the only layout the legacy pass exists for. A jar inside a version-named directory is handled by the ranked pass alone.
grid_cache_fallback_ignores_mismatched_jar_in_version_dir_test puts only grid/4.54.0/selenium-server-4.9.0.jar in the cache, and expects no result.
Probe: with the change stashed, cargo test --test grid_tests grid_cache_fallback reports 11 passed and 1 failed. With the change, it reports 12 passed.
|
Code review by qodo was updated up to the latest commit b42da79 |
Reject jars inside version-named directories in the legacy cache fallback pass so mismatched jars are handled only by the ranked pass. Add a regression test for a mismatched jar in a version directory.
| fs::write( | ||
| mismatched_dir.join("selenium-server-4.9.0.jar"), | ||
| b"fake jar", | ||
| ) | ||
| .unwrap(); |
There was a problem hiding this comment.
3. Grid test file fails the repository formatter check 📘 Rule violation ⚙ Maintainability
The fs::write call in grid_cache_fallback_requires_jar_name_to_match_dir_test is split across
lines, but its arguments (mismatched_dir.join("selenium-server-4.9.0.jar"), b"fake jar") are 57
characters, under rustfmt's 60-character argument-width threshold, so rustfmt collapses it to one
line. The same-width call in grid_cache_fallback_ignores_jar_in_other_cache_dir_test
(fs::write(other_dir.join("selenium-server-4.54.0.jar"), b"fake jar").unwrap();) is already on one
line, so the two sites disagree and the split one is the one rustfmt would change. This fails the
cargo fmt -- --check gate the PR description says it passed.
Agent Prompt
Issue description
The `fs::write` call in the test `grid_cache_fallback_requires_jar_name_to_match_dir_test` in `rust/tests/grid_tests.rs` is split over several lines, but rustfmt keeps it on one line because its arguments are under the 60-character threshold. This breaks the repository formatter check.
Fix Focus Areas
- rust/tests/grid_tests.rs[366-370]
Recommended Fix
Replace the multi-line call with `fs::write(mismatched_dir.join("selenium-server-4.9.0.jar"), b"fake jar").unwrap();` on one line, matching the style of the `fs::write(other_dir.join(...))` call in `grid_cache_fallback_ignores_jar_in_other_cache_dir_test`. Then run `cargo fmt -- --check` to confirm.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Checked this one with rustfmt itself, and the claim does not hold.
cargo fmt --check and cargo fmt -- --check both exit 0 on the committed tree.
The current split is rustfmt's own output. I copied the test file, collapsed the call to one line as suggested, and ran rustfmt --edition 2024 --check on both copies. The copy as committed exits 0. The collapsed copy exits 1, and rustfmt asks for exactly the split form that is in the file:
- fs::write(mismatched_dir.join("selenium-server-4.9.0.jar"), b"fake jar").unwrap();
+ fs::write(
+ mismatched_dir.join("selenium-server-4.9.0.jar"),
+ b"fake jar",
+ )
+ .unwrap();
The call is the receiver of a method chain, so the chain width applies, not the 60-character argument width. Applying the suggested change would break the formatter gate.
| // while never returning a jar from a SNAPSHOT directory. | ||
| find_latest_from_cache(&grid_cache_path, |entry| { | ||
| self.is_driver(entry) | ||
| // The legacy pass covers only jars outside a version-named directory. |
There was a problem hiding this comment.
8. A legacy-pass comment restates the code it sits on 📘 Rule violation ⚙ Maintainability
The comment The legacy pass covers only jars outside a version-named directory. sits above the .and_then(version_from_dir_name).is_none() predicate and only paraphrases that check. It gives no rationale for why the legacy pass must exclude version-named directories, which is the detail a later reader would need before changing the filter.
Agent Prompt
Issue description
The comment above the legacy-pass predicate in `GridManager::find_best_driver_from_cache` in `rust/src/grid.rs` only restates the `version_from_dir_name(...).is_none()` check. It does not explain why version-named directories are excluded from the legacy pass, so a later reader could remove the exclusion without understanding the risk.
Fix Focus Areas
- rust/src/grid.rs[361-370]
Recommended Fix
Replace the comment with one that states the reason, for example: the ranked pass already validates jars in version-named directories against their file-name version, so the legacy pass must skip them to avoid returning an unvalidated jar from the same directory.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Fair point. The comment now gives the reason.
f970aed replaces it with:
// The ranked pass above already checks a jar in a version-named directory
// against its file-name version. The legacy pass must skip those
// directories, or it could return a jar the ranked pass rejected.
Comment text only. cargo fmt --check exits 0, and the 12 fallback tests still pass.
|
Code review by qodo was updated up to the latest commit 898e12d |
Explain that the ranked pass already checks jars in version-named directories, so the legacy pass must skip them to avoid returning a jar that the ranked pass rejected.
|
Code review by qodo was updated up to the latest commit f970aed |
|
Thanks, CI sets Please add |
|
Added I ran the full Pushed as 2c52a07. |
|
Code review by qodo was updated up to the latest commit 2c52a07 |
Summary
selenium-manager --gridwith no version falls back to the newest jar in the cache. That lookup fails on Linux and Windows, even when the jar is on disk.find_best_driver_from_cachematches cache files with the sharedis_drivermatcher. That matcher expects the driver name and the binary extension. For Grid, those areselenium-serveron Linux andselenium-server.exeon Windows. The cached file isselenium-server-<version>.jar, so the suffix match finds no file. macOS uses acontainsmatch, so the same lookup succeeds there.Fix
Two changes in
GridManager:is_drivernow accepts a regular file whose name starts withselenium-server-and ends with.jar.find_best_driver_from_cacheranks the cached jars by the version in the parent directory. It accepts a jar only when the version in the file name equals the version of that directory. It scans only the Grid cache directory.The fallback rules are:
nightlyorlatestnever uses a cached jar. An exact cached version still resolves through the normal cache path.The CLI applies
--driver-versionafter the manager is built. The CLI path now recomputes the fallback gate after it sets the version, so--grid --driver-version 4.10.0cannot return a different cached jar.The shared matcher and
find_latest_from_cachekeep their current behaviour, so no browser driver changes.Tests
The tests in
rust/tests/grid_tests.rsbuild a cache directory and callfind_best_driver_from_cache, or run the binary against a temporary--cache-path:grid_cache_fallback_finds_cached_jar_testfindsgrid/4.54.0/selenium-server-4.54.0.jar. This test fails on Windows and Linux without the change.grid_cache_fallback_ignores_other_files_testignoresselenium-serverandselenium-server.zipin the same directory.grid_cache_fallback_prefers_newest_version_testcaches4.9.0and4.54.0, and expects4.54.0.grid_cache_fallback_skips_snapshot_testcaches4.54.0,4.54.0-SNAPSHOTand4.55.0-SNAPSHOT, and expects the4.54.0jar.grid_cache_fallback_skips_snapshot_file_outside_version_dir_testputs a snapshot jar beside the version directories, and expects no result.grid_cache_fallback_skips_snapshot_jar_in_stable_dir_testputs a snapshot jar insidegrid/4.54.0, and expects no result.grid_cache_fallback_requires_jar_name_to_match_dir_testputsselenium-server-4.9.0.jaringrid/4.54.0beside a correct4.53.0jar, and expects the4.53.0jar.grid_cache_fallback_ignores_mismatched_jar_in_version_dir_testputs onlygrid/4.54.0/selenium-server-4.9.0.jarin the cache, and expects no result.grid_cache_fallback_ignores_jar_in_other_cache_dir_testputsother/4.54.0/selenium-server-4.54.0.jarin the cache root with no Grid jar, and expects no result.grid_cache_fallback_cli_offline_returns_cached_jar_testruns--grid --offlineagainst a temporary cache, and expects that jar.grid_cache_fallback_cli_pinned_version_ignores_cache_testruns--grid 4.10.0 --offlinewith only4.54.0cached, and expects an emptydriver_path.grid_cache_fallback_cli_driver_version_ignores_cache_testruns--grid --driver-version 4.10.0 --offlinewith only4.54.0cached, and expects an emptydriver_path.grid_error_testruns against a warm cache that holds a jar, and still expectsDATAERR.The tests need no network access and no Java, except
grid_error_test, which resolves a version online.Local results
On Windows 11 with Rust 1.99.1:
cargo fmt -- --checkexits 0.cargo test --test grid_tests grid_cache_fallbackpasses 12 tests.cargo test --test grid_tests grid_error_testpasses 2 tests.cargo test --libpasses 46 tests.cargo test --test cache_unit_testspasses 14 tests.cargo clippy --all-targets -- -D warningsreports lints that predate this branch in untouched files. This branch adds none in the changed lines.Manual check
I built the binary and ran it against a cache that holds only the jar:
The result reports
driver_pathas<tmp>/grid/4.54.0/selenium-server-4.54.0.jarand exits 0.Fixes #18391