Repository navigation
Description
[agent] Found by the architecture refactor routine while running hosted mode under a patch mirror. Run on main at cfc870f with the binary built from it. Low priority: it needs an unusual mirror base, and the mirror is experimental.
Problem
Under a patch mirror, a rewriter that takes over an earlier hosted pin in place must not take over a source of the project's own that sits elsewhere on the mirror's host. CLI_CONTRACT.md (line 560): "Under a mirror a pin on the mirror's host must also sit under the mirror's base, so a fork of the same name and version in another repository of that host … stays the project's own source and is refused as any other foreign source is."
The check is origin::same_hosted_base (core origin.rs, lines 410 to 417). It does not know the mirror's base. It infers one from the new artifact URL, as everything before the first path segment that looks like a serve level: gopatch, or patch / patch-registry followed by an ecosystem (hosted_base_path, lines 384 to 395). When the base itself holds such a segment, the inferred base stops short:
| Mirror base | Base the check uses |
|---|---|
https://repo.example/artifactory/socket-patch |
/artifactory/socket-patch/ (right) |
https://repo.example/artifactory/gopatch |
/artifactory/: every repository of the host |
https://repo.example/gopatch |
none: the check passes for any URL |
So with a repository named gopatch, a direct-URL dependency of the project's own in another repository of the same host, with the same file name as the patched release, is read as an earlier Socket pin. The run replaces it with the patched upstream build and reports Patched 1 package. The fork is gone from the build, with no warning.
This is the second reader of one rule, and the first was already fixed. hosted_served_path had the same inference, and #2256 (e98feb7, "Address review: read the served path below the mirror base") changed it to take the configured base (mirror_base_depth, lines 343 to 354), with a unit test over the bases artifactory/gopatch and patch/npm (hosted_served_path_starts_below_the_mirror_base, line 1482). The test of same_hosted_base (an_earlier_pin_shares_the_base_of_a_mirrored_artifact, line 1432) covers only artifactory/socket-patch.
Evidence
A copy of that test over the same bases, never committed:
$ cargo test -p socket-patch-core --lib -- origin::tests::zz_probe
test origin::tests::zz_probe_a_fork_in_another_repository_is_not_an_earlier_pin ... FAILED
base https://repo.example/artifactory/gopatch: https://repo.example/artifactory/team-local/left-pad-1.3.0.tgz is read as an earlier pin (base read as Some("/artifactory/"))
base https://repo.example/artifactory/patch/npm: https://repo.example/artifactory/team-local/left-pad-1.3.0.tgz is read as an earlier pin (base read as Some("/artifactory/"))
base https://repo.example/gopatch: https://repo.example/team-local/left-pad-1.3.0.tgz is read as an earlier pin (base read as None)
The base https://repo.example/artifactory/socket-patch passes in the same loop.
End to end, with the benchmark harness as the patch API (socket-patch-bench serve bun/hosted --scale 0.02) and a local server answering the mirror's checks. The project's bun.lock holds the project's own tarball for the package, in another repository of the mirror's host:
"joya30": ["joya30@http://127.0.0.1:22000/artifactory/team-local/joya30-1.3.6.tgz", { … }, "sha512-…"]
$ SOCKET_PATCH_MIRROR_URL=http://127.0.0.1:22000/artifactory/socket-patch socket-patch scan
Switched 0 packages to hosted patches; rewrote 0 files.
No patches could be switched to hosted:
pkg:npm/joya30@1.3.6: no lockfile entry pinning it could be rewritten (see the warning below)
Warning: bun.lock entry `joya30` installs joya30@1.3.6 from a URL or local tarball, not the registry, and CANNOT be redirected — bun installs it from that spec, so that copy stays UNPATCHED; depend on the registry release to patch it
$ SOCKET_PATCH_MIRROR_URL=http://127.0.0.1:22000/artifactory/gopatch socket-patch scan
Switched 1 package to hosted patches; rewrote 1 file.
HIGH joya30@1.3.6 CVE-2024-10000
Patched 1 package, fixing 1 vulnerability (1 high).
$ grep joya30@ bun.lock
"joya30": ["joya30@http://127.0.0.1:22000/artifactory/gopatch/patch/npm/joya30/1.3.6/2520fbb3-…/7b72db4e-…/joya30-1.3.6.tgz", { … }
The same pair of runs for the other rewriters that call the check:
| Rewriter | The project's own source | base …/socket-patch |
base …/gopatch |
|---|---|---|---|
| Bun, yarn berry, Poetry, PDM (match by origin and file name) | <host>/artifactory/team-local/<file> |
skipped, unchanged |
applied, replaced |
uv, pylock.toml, Pipenv, Hatch (match by the patch server's path shape) |
<host>/artifactory/team-local/patch/pypi/<name>/<version>/<token>/<another uuid>/<file> |
skipped, unchanged |
applied, replaced |
For the second row the source has to be in the patch server's path shape, which only another mirror repository produces. When it names the uuid the run is granted, the unconfigured-host guard stops both bases first (redirect_pin_on_unconfigured_host).
Planned fix
Give same_hosted_base the base instead of having it guess: the run's patch-host list is where hosted_served_path already reads the mirror's base, so the check takes the same list (or the base travels with the reference the engine moved onto the mirror) and hosted_base_path is deleted. The callers are berry_hosted_pin_is_ours and is_prior_hosted_bun_spec (core patch/redirect/mod.rs, lines 6028 and 6736), is_prior_hosted_url (core utils/python_lock.rs, line 426) and replaceable_hosted_pin (core vendor/lock_inventory/pypi.rs, line 204). The test of same_hosted_base then runs over the four bases of hosted_served_path_starts_below_the_mirror_base.
Behavior change: under a mirror whose base holds a serve-level name, a source in another repository of the host is refused, as it already is under any other base. Nothing changes without a mirror.
Not checked: a real Artifactory repository named gopatch. How common such a base is, I can't tell from this repository; #2256 treated it as worth a fix and a test for the other reader.
Generated by Claude Code
Activity
refactor: #2321 and #2322 filed; the patch mirror ran