Skip to content

Commit 9a0b930

Browse files
committed
Keep one purl builder round-trip test
Each builder now round-trips through its parser with a literal + version, replacing the 14 deleted builder and round-trip tests with one that fails when a builder and its parser disagree. The pipenv probe's unused root parameter is named _root. Assisted-by: Claude Code:claude-opus-5-5
1 parent 7791a0e commit 9a0b930

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎crates/socket-patch-core/src/utils/pipenv.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn parse_major(output: &str) -> Option<u32> {
4242
/// when none is found, it does not answer within 10 s, exits non-zero or
4343
/// prints something unrecognizable. [`MAJOR_OVERRIDE_ENV`] short-circuits
4444
/// the probe.
45-
pub async fn installed_major(root: &Path) -> Option<u32> {
45+
pub async fn installed_major(_root: &Path) -> Option<u32> {
4646
if let Some(forced) = std::env::var(MAJOR_OVERRIDE_ENV)
4747
.ok()
4848
.and_then(|value| parse_override(&value))
@@ -56,7 +56,6 @@ pub async fn installed_major(root: &Path) -> Option<u32> {
5656
// NEUTRAL directory: with the scanned repository as cwd, Pipenv would read
5757
// its `.env`, `Pipfile` and `.venv` pointer — committed, attacker-shaped
5858
// inputs that must not influence (or slow down) a version check.
59-
let _ = root;
6059
command
6160
.arg("--version")
6261
.current_dir(std::env::temp_dir())

‎crates/socket-patch-core/src/utils/purl.rs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,46 @@ mod tests {
561561
);
562562
}
563563

564+
/// Each builder's spelling parses back to its parts, including a
565+
/// literal (already decoded) `+` version.
566+
#[test]
567+
fn builders_round_trip_through_their_parsers() {
568+
let version = "1.0.0+meta";
569+
assert_eq!(
570+
nv(parse_cargo_purl(&build_cargo_purl("wasi", version))),
571+
Some(("wasi".into(), version.into()))
572+
);
573+
assert_eq!(
574+
nv(parse_gem_purl(&build_gem_purl("rails", version))),
575+
Some(("rails".into(), version.into()))
576+
);
577+
assert_eq!(
578+
nv(parse_nuget_purl(&build_nuget_purl("Foo.Bar", version))),
579+
Some(("Foo.Bar".into(), version.into()))
580+
);
581+
assert_eq!(
582+
nv(parse_golang_purl(&build_golang_purl(
583+
"golang.org/x/text",
584+
version
585+
))),
586+
Some(("golang.org/x/text".into(), version.into()))
587+
);
588+
assert_eq!(
589+
nv3(parse_maven_purl(&build_maven_purl("org.x", "lib", version))),
590+
Some(("org.x".into(), "lib".into(), version.into()))
591+
);
592+
assert_eq!(
593+
nsv(parse_composer_purl(&build_composer_purl(
594+
"psr", "log", version
595+
))),
596+
Some((("psr".into(), "log".into()), version.into()))
597+
);
598+
assert_eq!(
599+
jsr_parts(&build_jsr_purl("@std", "path", version)),
600+
Some(("@std".into(), "path".into(), version.into()))
601+
);
602+
}
603+
564604
/// The namespace and name halves are decoded too — and the split runs on
565605
/// the ENCODED text, so an escaped separator stays INSIDE the component
566606
/// it was written in instead of creating a new one (the path-safety

0 commit comments

Comments
 (0)