Skip to content

Keep three tests off machine state - #2099

Merged
Mikola Lysenko (mikolalysenko) merged 2 commits into
mainfrom
bazel-stack/00-test-hygiene
Nov 17, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 2 commits into
mainfrom
bazel-stack/00-test-hygiene

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

No user-visible change.

Three test fixes in four files, +249 / -23, in two commits (the second answers the code review below). One line of product code changes: a constant of the updater becomes public and doc-hidden so that a test fixture can read it. No behaviour changes. The fixes came out of the Bazel work and none of them is about Bazel: each is about a test that passed or failed for a reason outside the code under test.

What it contains

crates/socket-patch-core/src/crawlers/maven_crawler.rs: a unit test counted the machine's caches.
project_mode_crawl_keeps_only_the_projects_graph wanted exactly 3 packages from a global crawl. A global crawl also reads the Coursier and Ivy caches that the process environment names (HOME, COURSIER_CACHE, the JVM option sources), which JvmEnv does not pin, so the count depended on the machine: with one package in a Coursier cache under HOME it is 4 and the test fails. The test now keeps the crawled packages whose path is under its own repository and compares them with the three expected purls exactly. It pins no process environment: the Maven repository is crawled before those caches and the first copy of a purl wins. It still fails if a global crawl is scoped to the project.

crates/socket-patch-cli/tests/prebuilt_common/mod.rs: the tests' patch service could serve a stand-in for a Go module without saying so.
source_dir picks the directory a Go module's archive is packed from by comparing each listed directory with the purl's <module>@<version>. Three things were wrong with the comparison:

  • Windows lists the module cache with \, a module path has /, so nothing matched there. The separator is now normalized.
  • The match was a bare text suffix, so the directory of a module on a longer host (sigs.k8s.io/x for k8s.io/x) was accepted. It now starts at a path-component boundary.
  • Go's module cache escapes upper-case letters (github.com/Azure is stored as github.com/!azure), so a purl with an upper-case letter never matched. The module path and the version are now escaped before comparing; the rule mirrors go_crawler::encode_module_path.

When nothing matches, the service still archives the package_layout stand-in (a go.mod and the patched files, none of the module's own), because two tests of vendor_rerun_no_network_e2e hand over a Cargo home without the crate on purpose. It now prints one line that names the purl and the cache whenever it does so although a cache for that ecosystem was handed over.

crates/socket-patch-cli/tests/common/update_fixture.rs and crates/socket-patch-core/src/update/download.rs: the self-update fixture names a binary that is too large to serve.
make_served_binary serves the built socket-patch as the release payload, and the updater refuses an extracted binary above 256 MiB (MAX_BINARY_BYTES). A build above the cap failed every test that serves it with "exceeds the 268435456-byte cap", far from the cause (#2071 fixed one such build). The fixture now asserts the size of the bytes as served, which is the updater's own comparison on every platform, and says that the build carries too much debug info for the fixture. It reads the updater's constant, which is now #[doc(hidden)] pub, in place of a second hard-coded copy.

What it proves in CI

  • coverage (required, Linux) runs every test of the workspace that is neither ignored nor behind the docker-e2e feature: the Maven unit test, the self-update suites with the new assertion, and the six self-tests of prebuilt_common in each of the 72 CLI test targets that compile it without that feature.
  • The clippy job's second step, cargo check --workspace --all-targets --all-features, type-checks the changed code in every target, the six Docker ones included.
  • In the merge queue windows-compile-check type-checks the helper and its self-tests on Windows. It does not run them.
  • A dispatch of ci.yml with os=windows on the final head is where the self-tests and the Go fixture suites run on Windows: https://github.com/SocketDev/socket-patch/actions/runs/43962290418 (green: 48 jobs, none failed)
  • A dispatch of ci.yml with os=macos on the final head runs the same tests on a macOS runner: https://github.com/SocketDev/socket-patch/actions/runs/43962297386 (green: 56 jobs, none failed)
  • The path filters of gradle-compatibility.yml and bench.yml match, so those two workflows start on the pull request as well.

CI cannot show the Maven test's old failure: it needs a machine with a Coursier or Ivy cache in the home directory.

Checked locally (macOS arm64)

  • The Maven test under a planted Coursier cache with a foreign package and under one with a same-purl copy: it passes under both. With the path filter taken out, the foreign package fails it (4 purls against 3), which shows the planted cache is read. With a global crawl made scoped, it fails (2 against 3).
  • Each new self-test fails with its fix undone: the longer-host case returns the wrong module's directory without the boundary check, and the upper-case case gets the stand-in without the escaping.
  • With the updater's cap lowered to 1 MiB for one run, the fixture's assertion fires with the product's number and the new message.
  • The 72 CLI test targets that compile prebuilt_common and need no Docker, plus self_update_e2e, self_update_failures_e2e and update: 2893 passed, 194 ignored, 2 failed. The two failures are old-toolchain tests of e2e_vendor_cargo_build ('cargo': Bad CPU type in executable): that machine's rustup holds x86_64 toolchains it cannot execute, and they fail the same way on main.
  • cargo fmt --all -- --check, cargo clippy --locked --workspace --all-features -- -D warnings and cargo check --locked --workspace --all-targets --all-features pass.

What it changes for a user

Nothing. socket_patch_core::update::download::MAX_BINARY_BYTES becomes public and doc-hidden; its value and every use of it are unchanged.

Code review

/code-review high ran on the first commit and reported seven findings, none of them a product bug; the second commit answers all of them.

  • The Maven assertion had been loosened to a membership check, which a copy in the machine's own cache could satisfy and which no longer caught an extra or duplicate package (two findings, one proposing to pin the environment instead). Fixed with the path filter and the exact comparison described above; no environment is pinned.
  • The Go match was an unanchored suffix. Fixed: component boundary.
  • The Go match ignored case escaping. Fixed.
  • The silent fallback to the stand-in was left in place. A hard failure broke exactly the two tests that rely on the stand-in, so it is a printed notice instead.
  • The size assertion counted the 59-byte trailer on macOS, where none is appended. Fixed: it checks the bytes as served.
  • The cap was a duplicated constant and the remedy named only the dev profile. Fixed: the product constant is shared and the message is right for any profile.
  • Not changed, on purpose: the size assertion sits in make_served_binary, and 19 of the 31 tests that call it never have the updater extract the bytes (dry runs, checksum and download failures, refusals). An over-cap build fails those too, with the one clear message, because such a build cannot be served by this fixture at all.

What it leaves out

  • Nothing ran on Windows before this pull request was opened; the Windows dispatch above was the first run. On Windows every Go fixture whose module cache the service lists is now packed from the module's own directory in place of the stand-in.
  • The global crawl still reads the Coursier and Ivy caches of the process environment. That is the product's behaviour and is unchanged.
  • The two e2e_vendor_cargo_build tests that depend on which rustup toolchains a machine can execute are not fixed here.
  • No real-Bazel run: there is no Bazel code here.

🤖 Generated with Claude Code

Three test-only fixes. No product code changes.

A Maven crawler unit test counted the machine's caches.
`project_mode_crawl_keeps_only_the_projects_graph` wanted exactly 3
packages from a global crawl. A global crawl also reads the Coursier
and Ivy caches the process environment names (HOME, COURSIER_CACHE and
the JVM option sources), which `JvmEnv` does not pin, so the count
depended on the machine: with one package in a Coursier cache under
HOME it is 4 and the test fails. The test now looks up the three
packages of its own repository in the result. It still fails if a
global crawl is scoped to the project, because the package that
another project cached would be missing.

The CLI tests' patch service missed a Go module's directory on Windows.
`prebuilt_common::source_dir` picks the directory a Go module's archive
is packed from by comparing each listed directory, as text, with the
purl's `<module>@<version>`. A module path has a `/` in it and Windows
lists the module cache with `\`, so nothing matched and the service
served the stand-in of `package_layout` in silence: a `go.mod` and the
patched files, none of the module's own. The comparison now normalizes
the separator. A self-test passes `\`-separated and `\\?\`-prefixed
directories as text, so it fails without the fix on every platform.

The self-update fixture names a binary that is too large to serve.
`make_served_binary` serves the built `socket-patch` as the release
payload, and the updater refuses an extracted binary above 256 MiB
(`MAX_BINARY_BYTES`). A build above the cap failed every test that
serves it with "exceeds the 268435456-byte cap", far from the cause;
#2071 fixed one such build. The fixture now asserts the size first and
says which setting to change.

Checked on macOS arm64:

- The Maven test before and after the change, with HOME as it is, with
  an empty HOME and with a HOME that holds a one-package Coursier
  cache. Before, the third run fails with 4 != 3. After, all three
  pass, and so do the 72 tests of the module.
- The new self-test fails with the separator fix taken out (it gets
  the stand-in, `project/missing`) and passes with it in each of the
  78 test targets that compile `prebuilt_common`.
- Every test that is not ignored in the 72 of those targets that need
  no Docker and in the three targets that compile `update_fixture`
  (`self_update_e2e`, `self_update_failures_e2e`, `update`): 2623
  pass. Two old-toolchain tests of `e2e_vendor_cargo_build` fail the
  same way without this change on that machine, whose rustup holds an
  x86_64 toolchain it cannot execute.

Left out: nothing ran on Windows, where every Go fixture whose module
cache the service lists is now packed from the module's own directory
in place of the stand-in. That needs a Windows run of the CLI suites.
The global crawl still reads the Coursier and Ivy caches of the
process environment; that is the product's behaviour and is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- The Maven global-crawl assertion keeps only the packages whose path is
  under the test's own repository and compares them with the three
  expected purls exactly, so the machine's Coursier and Ivy caches cannot
  satisfy or break it and an extra or duplicate package is caught.
- The fixture server matches a Go module directory from a path-component
  boundary, so the directory of a module on a longer host (sigs.k8s.io/x
  for k8s.io/x) is no longer taken.
- It applies Go's case escaping to the module path and the version before
  comparing, so a purl with an upper-case letter finds its directory
  (github.com/Azure is github.com/!azure in the module cache).
- It prints one line naming the purl and the cache when it archives the
  package_layout stand-in although the test handed over a cache for that
  ecosystem; this stays a notice because two tests of
  vendor_rerun_no_network_e2e hand over a Cargo home without the crate on
  purpose.
- The served-binary size assertion checks the bytes as served, so the
  trailer counts only where it is appended and the check is the updater's
  own on every platform.
- That assertion reads the updater's MAX_BINARY_BYTES, now #[doc(hidden)]
  pub, in place of a second hard-coded copy, and its message names the
  cause for any profile.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 16, 2026 21:39
@cursor

cursor Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Changes are confined to tests and a doc-hidden public constant; updater limits and crawl logic are unchanged.

Overview
Test-only hardening so CI no longer depends on the developer machine’s caches or build shape.

Maven crawler — project_mode_crawl_keeps_only_the_projects_graph no longer asserts a fixed global crawl count (which could include Coursier/Ivy under HOME). It keeps packages whose paths lie under the test’s pinned repository and compares the exact expected PURLs.

Prebuilt fixture server — Go module lookup in source_dir is fixed: normalize \//, match module@version at a path-component boundary, and apply Go cache case escaping (! + lowercase). Handed-over caches are typed as (ecosystem, path); when a package falls back to package_layout but the test supplied a cache for that ecosystem, the fixture logs a one-line stand-in notice. Unit tests cover separators, longer host names, escaping, and notices.

Self-update fixture — make_served_binary asserts the served bytes stay within the updater cap, using the product’s MAX_BINARY_BYTES (now #[doc(hidden)] pub in download.rs) so oversized debug builds fail with an explicit fixture message instead of a downstream “exceeds cap” error.

No runtime product behavior changes beyond exposing that constant for tests.

Reviewed by Cursor Bugbot for commit b09019c. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief

What it does
Fixes three tests that passed or failed for reasons outside the code under test. The Maven crawler test no longer counts packages from the machine's Coursier/Ivy caches. The prebuilt fixture's Go module lookup now handles Windows separators, component boundaries and Go's ! case escaping, and prints a notice when it falls back to a stand-in. The self-update fixture asserts the served binary fits the updater's size cap.

Risk: low. Only test code changes, plus one product line: MAX_BINARY_BYTES becomes #[doc(hidden)] pub. Its value and uses are unchanged. Nothing changes for a user's install, build or CI.

Look here

  • [maven_crawler.rs:2751](https://github.com/SocketDev/socket-patch/blob/b09019c4d79b8489d69c7b8a2ee3409fad3765cc/crates/socket-patch-core/src/crawlers/maven_crawler.rs#L2751): filters to the pinned repo, then does an exact purl comparison (stricter than the old count)
  • prebuilt_common/mod.rs:531: is_go_module_dir (separator, boundary, case escaping)
  • prebuilt_common/mod.rs:567: stand-in notice, which is a notice and not a failure on purpose
  • update_fixture.rs:225: size assertion on the bytes as served
  • download.rs:33: the constant made public

Verified

  • Read the whole diff against main (610ba8d).
  • No conflict with main. CHANGELOG.md is untouched. No review threads are open.
  • purls() sorts, so the exact comparison is order-independent.
  • The \\?\ and \ cases normalize correctly.
  • The new self-tests cover boundary, escaping and separator.
  • ci-ok and clippy are green on b09019c4. The Windows and macOS dispatches linked in the description are green.

Changes I made: none.

Open questions: none.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 17, 2026
Merged via the queue into main with commit 68c642e Nov 17, 2026
186 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the bazel-stack/00-test-hygiene branch November 17, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants